mirror of
https://github.com/fluencelabs/fluence-js.git
synced 2025-05-16 03:11:20 +00:00
Fix tests
This commit is contained in:
parent
d6eb91b76f
commit
942a203d4a
@ -9,16 +9,13 @@
|
|||||||
* If you find any bugs in generated JS/TS, please write an issue on GitHub: https://github.com/fluencelabs/js-client/issues
|
* If you find any bugs in generated JS/TS, please write an issue on GitHub: https://github.com/fluencelabs/js-client/issues
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
import type {
|
import type { IFluenceClient as IFluenceClient$$, ParticleContext as ParticleContext$$ } from '@fluencelabs/js-client';
|
||||||
IFluenceClient as IFluenceClient$$,
|
|
||||||
ParticleContext as ParticleContext$$,
|
|
||||||
} from "@fluencelabs/js-client";
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
v5_callFunction as callFunction$$,
|
v5_callFunction as callFunction$$,
|
||||||
v5_registerService as registerService$$,
|
v5_registerService as registerService$$,
|
||||||
FluencePeer as FluencePeer$$,
|
FluencePeer as FluencePeer$$
|
||||||
} from "@fluencelabs/js-client";
|
} from '@fluencelabs/js-client';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {import("@fluencelabs/js-client").NonArrowSimpleType} NonArrowSimpleType
|
* @typedef {import("@fluencelabs/js-client").NonArrowSimpleType} NonArrowSimpleType
|
||||||
@ -33,36 +30,40 @@ import {
|
|||||||
export function aqua2ts(value, schema) {
|
export function aqua2ts(value, schema) {
|
||||||
if (schema.tag === "nil") {
|
if (schema.tag === "nil") {
|
||||||
return null;
|
return null;
|
||||||
} else if (schema.tag === "option") {
|
}
|
||||||
|
else if (schema.tag === "option") {
|
||||||
if (!Array.isArray(value)) {
|
if (!Array.isArray(value)) {
|
||||||
throw new Error("Bad schema");
|
throw new Error("Bad schema");
|
||||||
}
|
}
|
||||||
if (value.length === 0) {
|
if (value.length === 0) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return aqua2ts(value[0], schema.type);
|
return aqua2ts(value[0], schema.type);
|
||||||
}
|
}
|
||||||
} else if (
|
}
|
||||||
schema.tag === "scalar" ||
|
else if (schema.tag === "scalar" ||
|
||||||
schema.tag === "bottomType" ||
|
schema.tag === "bottomType" ||
|
||||||
schema.tag === "topType"
|
schema.tag === "topType") {
|
||||||
) {
|
|
||||||
return value;
|
return value;
|
||||||
} else if (schema.tag === "array") {
|
}
|
||||||
|
else if (schema.tag === "array") {
|
||||||
if (!Array.isArray(value)) {
|
if (!Array.isArray(value)) {
|
||||||
throw new Error("Bad schema");
|
throw new Error("Bad schema");
|
||||||
}
|
}
|
||||||
return value.map((y) => {
|
return value.map((y) => {
|
||||||
return aqua2ts(y, schema.type);
|
return aqua2ts(y, schema.type);
|
||||||
});
|
});
|
||||||
} else if (schema.tag === "unlabeledProduct") {
|
}
|
||||||
|
else if (schema.tag === "unlabeledProduct") {
|
||||||
if (!Array.isArray(value)) {
|
if (!Array.isArray(value)) {
|
||||||
throw new Error("Bad schema");
|
throw new Error("Bad schema");
|
||||||
}
|
}
|
||||||
return value.map((y, i) => {
|
return value.map((y, i) => {
|
||||||
return aqua2ts(y, schema.items[i]);
|
return aqua2ts(y, schema.items[i]);
|
||||||
});
|
});
|
||||||
} else if (schema.tag === "struct" || schema.tag === "labeledProduct") {
|
}
|
||||||
|
else if (schema.tag === "struct" || schema.tag === "labeledProduct") {
|
||||||
if (typeof value !== "object" || value == null || Array.isArray(value)) {
|
if (typeof value !== "object" || value == null || Array.isArray(value)) {
|
||||||
throw new Error("Bad schema");
|
throw new Error("Bad schema");
|
||||||
}
|
}
|
||||||
@ -70,7 +71,8 @@ export function aqua2ts(value, schema) {
|
|||||||
const val = aqua2ts(value[key], type);
|
const val = aqua2ts(value[key], type);
|
||||||
return { ...agg, [key]: val };
|
return { ...agg, [key]: val };
|
||||||
}, {});
|
}, {});
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
throw new Error("Unexpected tag: " + JSON.stringify(schema));
|
throw new Error("Unexpected tag: " + JSON.stringify(schema));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -83,32 +85,32 @@ export function aqua2ts(value, schema) {
|
|||||||
export function ts2aqua(value, schema) {
|
export function ts2aqua(value, schema) {
|
||||||
if (schema.tag === "nil") {
|
if (schema.tag === "nil") {
|
||||||
return null;
|
return null;
|
||||||
} else if (schema.tag === "option") {
|
|
||||||
if (!Array.isArray(value)) {
|
|
||||||
throw new Error("Bad schema");
|
|
||||||
}
|
}
|
||||||
return value === null ? [] : [ts2aqua(value, schema.type)];
|
else if (schema.tag === "option") {
|
||||||
} else if (
|
return value == null ? [] : [ts2aqua(value, schema.type)];
|
||||||
schema.tag === "scalar" ||
|
}
|
||||||
|
else if (schema.tag === "scalar" ||
|
||||||
schema.tag === "bottomType" ||
|
schema.tag === "bottomType" ||
|
||||||
schema.tag === "topType"
|
schema.tag === "topType") {
|
||||||
) {
|
|
||||||
return value;
|
return value;
|
||||||
} else if (schema.tag === "array") {
|
}
|
||||||
|
else if (schema.tag === "array") {
|
||||||
if (!Array.isArray(value)) {
|
if (!Array.isArray(value)) {
|
||||||
throw new Error("Bad schema");
|
throw new Error("Bad schema");
|
||||||
}
|
}
|
||||||
return value.map((y) => {
|
return value.map((y) => {
|
||||||
return ts2aqua(y, schema.type);
|
return ts2aqua(y, schema.type);
|
||||||
});
|
});
|
||||||
} else if (schema.tag === "unlabeledProduct") {
|
}
|
||||||
|
else if (schema.tag === "unlabeledProduct") {
|
||||||
if (!Array.isArray(value)) {
|
if (!Array.isArray(value)) {
|
||||||
throw new Error("Bad schema");
|
throw new Error("Bad schema");
|
||||||
}
|
}
|
||||||
return value.map((y, i) => {
|
return value.map((y, i) => {
|
||||||
return ts2aqua(y, schema.items[i]);
|
return ts2aqua(y, schema.items[i]);
|
||||||
});
|
});
|
||||||
} else if (schema.tag === "struct" || schema.tag === "labeledProduct") {
|
}
|
||||||
|
else if (schema.tag === "struct" || schema.tag === "labeledProduct") {
|
||||||
if (typeof value !== "object" || value == null || Array.isArray(value)) {
|
if (typeof value !== "object" || value == null || Array.isArray(value)) {
|
||||||
throw new Error("Bad schema");
|
throw new Error("Bad schema");
|
||||||
}
|
}
|
||||||
@ -116,11 +118,14 @@ export function ts2aqua(value, schema) {
|
|||||||
const val = ts2aqua(value[key], type);
|
const val = ts2aqua(value[key], type);
|
||||||
return { ...agg, [key]: val };
|
return { ...agg, [key]: val };
|
||||||
}, {});
|
}, {});
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
throw new Error("Unexpected tag: " + JSON.stringify(schema));
|
throw new Error("Unexpected tag: " + JSON.stringify(schema));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Functions
|
// Functions
|
||||||
export const test_script = `
|
export const test_script = `
|
||||||
(seq
|
(seq
|
||||||
@ -135,11 +140,13 @@ export const test_script = `
|
|||||||
)
|
)
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export function test(config?: { ttl?: number }): Promise<void>;
|
export function test(
|
||||||
|
config?: {ttl?: number}
|
||||||
|
): Promise<void>;
|
||||||
|
|
||||||
export function test(
|
export function test(
|
||||||
peer: IFluenceClient$$,
|
peer: IFluenceClient$$,
|
||||||
config?: { ttl?: number },
|
config?: {ttl?: number}
|
||||||
): Promise<void>;
|
): Promise<void>;
|
||||||
|
|
||||||
export async function test(...args: any[]) {
|
export async function test(...args: any[]) {
|
||||||
@ -151,22 +158,23 @@ export async function test(...args: any[]) {
|
|||||||
args = args.slice(1);
|
args = args.slice(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const callArgs = Object.fromEntries(
|
|
||||||
args.slice(0, argCount).map((arg, i) => [argNames[i], arg]),
|
|
||||||
);
|
|
||||||
|
|
||||||
const params = {
|
const callArgs = Object.fromEntries(args.slice(0, argCount).map((arg, i) => [argNames[i], arg]));
|
||||||
|
|
||||||
|
const params = ({
|
||||||
peer,
|
peer,
|
||||||
args: callArgs,
|
args: callArgs,
|
||||||
config: args[argCount],
|
config: args[argCount]
|
||||||
};
|
});
|
||||||
|
|
||||||
const result = await callFunction$$({
|
const result = await callFunction$$({
|
||||||
script: test_script,
|
script: test_script,
|
||||||
...params,
|
...params,
|
||||||
});
|
});
|
||||||
|
|
||||||
return aqua2ts(result, {
|
return aqua2ts(result,
|
||||||
tag: "nil",
|
{
|
||||||
});
|
"tag": "nil"
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
@ -9,16 +9,13 @@
|
|||||||
* If you find any bugs in generated JS/TS, please write an issue on GitHub: https://github.com/fluencelabs/js-client/issues
|
* If you find any bugs in generated JS/TS, please write an issue on GitHub: https://github.com/fluencelabs/js-client/issues
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
import type {
|
import type { IFluenceClient as IFluenceClient$$, ParticleContext as ParticleContext$$ } from '@fluencelabs/js-client';
|
||||||
IFluenceClient as IFluenceClient$$,
|
|
||||||
ParticleContext as ParticleContext$$,
|
|
||||||
} from "@fluencelabs/js-client";
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
v5_callFunction as callFunction$$,
|
v5_callFunction as callFunction$$,
|
||||||
v5_registerService as registerService$$,
|
v5_registerService as registerService$$,
|
||||||
FluencePeer as FluencePeer$$,
|
FluencePeer as FluencePeer$$
|
||||||
} from "@fluencelabs/js-client";
|
} from '@fluencelabs/js-client';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {import("@fluencelabs/js-client").NonArrowSimpleType} NonArrowSimpleType
|
* @typedef {import("@fluencelabs/js-client").NonArrowSimpleType} NonArrowSimpleType
|
||||||
@ -33,36 +30,40 @@ import {
|
|||||||
export function aqua2ts(value, schema) {
|
export function aqua2ts(value, schema) {
|
||||||
if (schema.tag === "nil") {
|
if (schema.tag === "nil") {
|
||||||
return null;
|
return null;
|
||||||
} else if (schema.tag === "option") {
|
}
|
||||||
|
else if (schema.tag === "option") {
|
||||||
if (!Array.isArray(value)) {
|
if (!Array.isArray(value)) {
|
||||||
throw new Error("Bad schema");
|
throw new Error("Bad schema");
|
||||||
}
|
}
|
||||||
if (value.length === 0) {
|
if (value.length === 0) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return aqua2ts(value[0], schema.type);
|
return aqua2ts(value[0], schema.type);
|
||||||
}
|
}
|
||||||
} else if (
|
}
|
||||||
schema.tag === "scalar" ||
|
else if (schema.tag === "scalar" ||
|
||||||
schema.tag === "bottomType" ||
|
schema.tag === "bottomType" ||
|
||||||
schema.tag === "topType"
|
schema.tag === "topType") {
|
||||||
) {
|
|
||||||
return value;
|
return value;
|
||||||
} else if (schema.tag === "array") {
|
}
|
||||||
|
else if (schema.tag === "array") {
|
||||||
if (!Array.isArray(value)) {
|
if (!Array.isArray(value)) {
|
||||||
throw new Error("Bad schema");
|
throw new Error("Bad schema");
|
||||||
}
|
}
|
||||||
return value.map((y) => {
|
return value.map((y) => {
|
||||||
return aqua2ts(y, schema.type);
|
return aqua2ts(y, schema.type);
|
||||||
});
|
});
|
||||||
} else if (schema.tag === "unlabeledProduct") {
|
}
|
||||||
|
else if (schema.tag === "unlabeledProduct") {
|
||||||
if (!Array.isArray(value)) {
|
if (!Array.isArray(value)) {
|
||||||
throw new Error("Bad schema");
|
throw new Error("Bad schema");
|
||||||
}
|
}
|
||||||
return value.map((y, i) => {
|
return value.map((y, i) => {
|
||||||
return aqua2ts(y, schema.items[i]);
|
return aqua2ts(y, schema.items[i]);
|
||||||
});
|
});
|
||||||
} else if (schema.tag === "struct" || schema.tag === "labeledProduct") {
|
}
|
||||||
|
else if (schema.tag === "struct" || schema.tag === "labeledProduct") {
|
||||||
if (typeof value !== "object" || value == null || Array.isArray(value)) {
|
if (typeof value !== "object" || value == null || Array.isArray(value)) {
|
||||||
throw new Error("Bad schema");
|
throw new Error("Bad schema");
|
||||||
}
|
}
|
||||||
@ -70,7 +71,8 @@ export function aqua2ts(value, schema) {
|
|||||||
const val = aqua2ts(value[key], type);
|
const val = aqua2ts(value[key], type);
|
||||||
return { ...agg, [key]: val };
|
return { ...agg, [key]: val };
|
||||||
}, {});
|
}, {});
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
throw new Error("Unexpected tag: " + JSON.stringify(schema));
|
throw new Error("Unexpected tag: " + JSON.stringify(schema));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -83,32 +85,32 @@ export function aqua2ts(value, schema) {
|
|||||||
export function ts2aqua(value, schema) {
|
export function ts2aqua(value, schema) {
|
||||||
if (schema.tag === "nil") {
|
if (schema.tag === "nil") {
|
||||||
return null;
|
return null;
|
||||||
} else if (schema.tag === "option") {
|
|
||||||
if (!Array.isArray(value)) {
|
|
||||||
throw new Error("Bad schema");
|
|
||||||
}
|
}
|
||||||
return value === null ? [] : [ts2aqua(value, schema.type)];
|
else if (schema.tag === "option") {
|
||||||
} else if (
|
return value == null ? [] : [ts2aqua(value, schema.type)];
|
||||||
schema.tag === "scalar" ||
|
}
|
||||||
|
else if (schema.tag === "scalar" ||
|
||||||
schema.tag === "bottomType" ||
|
schema.tag === "bottomType" ||
|
||||||
schema.tag === "topType"
|
schema.tag === "topType") {
|
||||||
) {
|
|
||||||
return value;
|
return value;
|
||||||
} else if (schema.tag === "array") {
|
}
|
||||||
|
else if (schema.tag === "array") {
|
||||||
if (!Array.isArray(value)) {
|
if (!Array.isArray(value)) {
|
||||||
throw new Error("Bad schema");
|
throw new Error("Bad schema");
|
||||||
}
|
}
|
||||||
return value.map((y) => {
|
return value.map((y) => {
|
||||||
return ts2aqua(y, schema.type);
|
return ts2aqua(y, schema.type);
|
||||||
});
|
});
|
||||||
} else if (schema.tag === "unlabeledProduct") {
|
}
|
||||||
|
else if (schema.tag === "unlabeledProduct") {
|
||||||
if (!Array.isArray(value)) {
|
if (!Array.isArray(value)) {
|
||||||
throw new Error("Bad schema");
|
throw new Error("Bad schema");
|
||||||
}
|
}
|
||||||
return value.map((y, i) => {
|
return value.map((y, i) => {
|
||||||
return ts2aqua(y, schema.items[i]);
|
return ts2aqua(y, schema.items[i]);
|
||||||
});
|
});
|
||||||
} else if (schema.tag === "struct" || schema.tag === "labeledProduct") {
|
}
|
||||||
|
else if (schema.tag === "struct" || schema.tag === "labeledProduct") {
|
||||||
if (typeof value !== "object" || value == null || Array.isArray(value)) {
|
if (typeof value !== "object" || value == null || Array.isArray(value)) {
|
||||||
throw new Error("Bad schema");
|
throw new Error("Bad schema");
|
||||||
}
|
}
|
||||||
@ -116,53 +118,34 @@ export function ts2aqua(value, schema) {
|
|||||||
const val = ts2aqua(value[key], type);
|
const val = ts2aqua(value[key], type);
|
||||||
return { ...agg, [key]: val };
|
return { ...agg, [key]: val };
|
||||||
}, {});
|
}, {});
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
throw new Error("Unexpected tag: " + JSON.stringify(schema));
|
throw new Error("Unexpected tag: " + JSON.stringify(schema));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Services
|
// Services
|
||||||
export interface SrvDef {
|
export interface SrvDef {
|
||||||
create: (
|
create: (wasm_b64_content: string, callParams: ParticleContext$$) => { error: string | null; service_id: string | null; success: boolean; } | Promise<{ error: string | null; service_id: string | null; success: boolean; }>;
|
||||||
wasm_b64_content: string,
|
|
||||||
callParams: ParticleContext$$,
|
|
||||||
) =>
|
|
||||||
| { error: string | null; service_id: string | null; success: boolean }
|
|
||||||
| Promise<{
|
|
||||||
error: string | null;
|
|
||||||
service_id: string | null;
|
|
||||||
success: boolean;
|
|
||||||
}>;
|
|
||||||
list: (callParams: ParticleContext$$) => string[] | Promise<string[]>;
|
list: (callParams: ParticleContext$$) => string[] | Promise<string[]>;
|
||||||
remove: (
|
remove: (service_id: string, callParams: ParticleContext$$) => { error: string | null; success: boolean; } | Promise<{ error: string | null; success: boolean; }>;
|
||||||
service_id: string,
|
|
||||||
callParams: ParticleContext$$,
|
|
||||||
) =>
|
|
||||||
| { error: string | null; success: boolean }
|
|
||||||
| Promise<{ error: string | null; success: boolean }>;
|
|
||||||
}
|
}
|
||||||
export function registerSrv(service: SrvDef): void;
|
export function registerSrv(service: SrvDef): void;
|
||||||
export function registerSrv(serviceId: string, service: SrvDef): void;
|
export function registerSrv(serviceId: string, service: SrvDef): void;
|
||||||
export function registerSrv(peer: IFluenceClient$$, service: SrvDef): void;
|
export function registerSrv(peer: IFluenceClient$$, service: SrvDef): void;
|
||||||
export function registerSrv(
|
export function registerSrv(peer: IFluenceClient$$, serviceId: string, service: SrvDef): void;
|
||||||
peer: IFluenceClient$$,
|
|
||||||
serviceId: string,
|
|
||||||
service: SrvDef,
|
|
||||||
): void;
|
|
||||||
export function registerSrv(...args: any[]) {
|
export function registerSrv(...args: any[]) {
|
||||||
const service = args.pop();
|
const service = args.pop();
|
||||||
const defaultServiceId = "single_module_srv";
|
const defaultServiceId = "single_module_srv";
|
||||||
|
|
||||||
const params =
|
const params = args[0] instanceof FluencePeer$$ ? ({
|
||||||
args[0] instanceof FluencePeer$$
|
|
||||||
? {
|
|
||||||
peer: args[0],
|
peer: args[0],
|
||||||
serviceId: args[1] ?? defaultServiceId,
|
serviceId: args[1] ?? defaultServiceId
|
||||||
}
|
}) : ({
|
||||||
: {
|
|
||||||
peer: undefined,
|
peer: undefined,
|
||||||
serviceId: args[0] ?? defaultServiceId,
|
serviceId: args[0] ?? defaultServiceId
|
||||||
};
|
});
|
||||||
|
|
||||||
if (params.serviceId == null) {
|
if (params.serviceId == null) {
|
||||||
throw new Error("Service ID is not provided");
|
throw new Error("Service ID is not provided");
|
||||||
@ -170,51 +153,32 @@ export function registerSrv(...args: any[]) {
|
|||||||
|
|
||||||
registerService$$({
|
registerService$$({
|
||||||
service,
|
service,
|
||||||
...params,
|
...params
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CalcServiceDef {
|
export interface CalcServiceDef {
|
||||||
divide: (
|
divide: (num: number, callParams: ParticleContext$$) => number | Promise<number>;
|
||||||
num: number,
|
|
||||||
callParams: ParticleContext$$,
|
|
||||||
) => number | Promise<number>;
|
|
||||||
clear_state: (callParams: ParticleContext$$) => void | Promise<void>;
|
clear_state: (callParams: ParticleContext$$) => void | Promise<void>;
|
||||||
test_logs: (callParams: ParticleContext$$) => void | Promise<void>;
|
test_logs: (callParams: ParticleContext$$) => void | Promise<void>;
|
||||||
multiply: (
|
multiply: (num: number, callParams: ParticleContext$$) => number | Promise<number>;
|
||||||
num: number,
|
|
||||||
callParams: ParticleContext$$,
|
|
||||||
) => number | Promise<number>;
|
|
||||||
add: (num: number, callParams: ParticleContext$$) => number | Promise<number>;
|
add: (num: number, callParams: ParticleContext$$) => number | Promise<number>;
|
||||||
state: (callParams: ParticleContext$$) => number | Promise<number>;
|
state: (callParams: ParticleContext$$) => number | Promise<number>;
|
||||||
subtract: (
|
subtract: (num: number, callParams: ParticleContext$$) => number | Promise<number>;
|
||||||
num: number,
|
|
||||||
callParams: ParticleContext$$,
|
|
||||||
) => number | Promise<number>;
|
|
||||||
}
|
}
|
||||||
export function registerCalcService(
|
export function registerCalcService(serviceId: string, service: CalcServiceDef): void;
|
||||||
serviceId: string,
|
export function registerCalcService(peer: IFluenceClient$$, serviceId: string, service: CalcServiceDef): void;
|
||||||
service: CalcServiceDef,
|
|
||||||
): void;
|
|
||||||
export function registerCalcService(
|
|
||||||
peer: IFluenceClient$$,
|
|
||||||
serviceId: string,
|
|
||||||
service: CalcServiceDef,
|
|
||||||
): void;
|
|
||||||
export function registerCalcService(...args: any[]) {
|
export function registerCalcService(...args: any[]) {
|
||||||
const service = args.pop();
|
const service = args.pop();
|
||||||
const defaultServiceId = undefined;
|
const defaultServiceId = undefined;
|
||||||
|
|
||||||
const params =
|
const params = args[0] instanceof FluencePeer$$ ? ({
|
||||||
args[0] instanceof FluencePeer$$
|
|
||||||
? {
|
|
||||||
peer: args[0],
|
peer: args[0],
|
||||||
serviceId: args[1] ?? defaultServiceId,
|
serviceId: args[1] ?? defaultServiceId
|
||||||
}
|
}) : ({
|
||||||
: {
|
|
||||||
peer: undefined,
|
peer: undefined,
|
||||||
serviceId: args[0] ?? defaultServiceId,
|
serviceId: args[0] ?? defaultServiceId
|
||||||
};
|
});
|
||||||
|
|
||||||
if (params.serviceId == null) {
|
if (params.serviceId == null) {
|
||||||
throw new Error("Service ID is not provided");
|
throw new Error("Service ID is not provided");
|
||||||
@ -222,44 +186,28 @@ export function registerCalcService(...args: any[]) {
|
|||||||
|
|
||||||
registerService$$({
|
registerService$$({
|
||||||
service,
|
service,
|
||||||
...params,
|
...params
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface HelloWorldDef {
|
export interface HelloWorldDef {
|
||||||
hello: (
|
hello: (str: string, callParams: ParticleContext$$) => string | Promise<string>;
|
||||||
str: string,
|
|
||||||
callParams: ParticleContext$$,
|
|
||||||
) => string | Promise<string>;
|
|
||||||
}
|
}
|
||||||
export function registerHelloWorld(service: HelloWorldDef): void;
|
export function registerHelloWorld(service: HelloWorldDef): void;
|
||||||
export function registerHelloWorld(
|
export function registerHelloWorld(serviceId: string, service: HelloWorldDef): void;
|
||||||
serviceId: string,
|
export function registerHelloWorld(peer: IFluenceClient$$, service: HelloWorldDef): void;
|
||||||
service: HelloWorldDef,
|
export function registerHelloWorld(peer: IFluenceClient$$, serviceId: string, service: HelloWorldDef): void;
|
||||||
): void;
|
|
||||||
export function registerHelloWorld(
|
|
||||||
peer: IFluenceClient$$,
|
|
||||||
service: HelloWorldDef,
|
|
||||||
): void;
|
|
||||||
export function registerHelloWorld(
|
|
||||||
peer: IFluenceClient$$,
|
|
||||||
serviceId: string,
|
|
||||||
service: HelloWorldDef,
|
|
||||||
): void;
|
|
||||||
export function registerHelloWorld(...args: any[]) {
|
export function registerHelloWorld(...args: any[]) {
|
||||||
const service = args.pop();
|
const service = args.pop();
|
||||||
const defaultServiceId = "hello-world";
|
const defaultServiceId = "hello-world";
|
||||||
|
|
||||||
const params =
|
const params = args[0] instanceof FluencePeer$$ ? ({
|
||||||
args[0] instanceof FluencePeer$$
|
|
||||||
? {
|
|
||||||
peer: args[0],
|
peer: args[0],
|
||||||
serviceId: args[1] ?? defaultServiceId,
|
serviceId: args[1] ?? defaultServiceId
|
||||||
}
|
}) : ({
|
||||||
: {
|
|
||||||
peer: undefined,
|
peer: undefined,
|
||||||
serviceId: args[0] ?? defaultServiceId,
|
serviceId: args[0] ?? defaultServiceId
|
||||||
};
|
});
|
||||||
|
|
||||||
if (params.serviceId == null) {
|
if (params.serviceId == null) {
|
||||||
throw new Error("Service ID is not provided");
|
throw new Error("Service ID is not provided");
|
||||||
@ -267,10 +215,11 @@ export function registerHelloWorld(...args: any[]) {
|
|||||||
|
|
||||||
registerService$$({
|
registerService$$({
|
||||||
service,
|
service,
|
||||||
...params,
|
...params
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Functions
|
// Functions
|
||||||
export const resourceTest_script = `
|
export const resourceTest_script = `
|
||||||
(seq
|
(seq
|
||||||
@ -495,17 +444,17 @@ export const resourceTest_script = `
|
|||||||
)
|
)
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export type ResourceTestResult = [string | null, string[]];
|
export type ResourceTestResult = [string | null, string[]]
|
||||||
|
|
||||||
export function resourceTest(
|
export function resourceTest(
|
||||||
label: string,
|
label: string,
|
||||||
config?: { ttl?: number },
|
config?: {ttl?: number}
|
||||||
): Promise<ResourceTestResult>;
|
): Promise<ResourceTestResult>;
|
||||||
|
|
||||||
export function resourceTest(
|
export function resourceTest(
|
||||||
peer: IFluenceClient$$,
|
peer: IFluenceClient$$,
|
||||||
label: string,
|
label: string,
|
||||||
config?: { ttl?: number },
|
config?: {ttl?: number}
|
||||||
): Promise<ResourceTestResult>;
|
): Promise<ResourceTestResult>;
|
||||||
|
|
||||||
export async function resourceTest(...args: any[]) {
|
export async function resourceTest(...args: any[]) {
|
||||||
@ -517,40 +466,41 @@ export async function resourceTest(...args: any[]) {
|
|||||||
args = args.slice(1);
|
args = args.slice(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const callArgs = Object.fromEntries(
|
|
||||||
args.slice(0, argCount).map((arg, i) => [argNames[i], arg]),
|
|
||||||
);
|
|
||||||
|
|
||||||
const params = {
|
const callArgs = Object.fromEntries(args.slice(0, argCount).map((arg, i) => [argNames[i], arg]));
|
||||||
|
|
||||||
|
const params = ({
|
||||||
peer,
|
peer,
|
||||||
args: callArgs,
|
args: callArgs,
|
||||||
config: args[argCount],
|
config: args[argCount]
|
||||||
};
|
});
|
||||||
|
|
||||||
const result = await callFunction$$({
|
const result = await callFunction$$({
|
||||||
script: resourceTest_script,
|
script: resourceTest_script,
|
||||||
...params,
|
...params,
|
||||||
});
|
});
|
||||||
|
|
||||||
return aqua2ts(result, {
|
return aqua2ts(result,
|
||||||
items: [
|
|
||||||
{
|
{
|
||||||
type: {
|
"items": [
|
||||||
name: "string",
|
{
|
||||||
tag: "scalar",
|
"type": {
|
||||||
|
"name": "string",
|
||||||
|
"tag": "scalar"
|
||||||
},
|
},
|
||||||
tag: "option",
|
"tag": "option"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: {
|
"type": {
|
||||||
name: "string",
|
"name": "string",
|
||||||
tag: "scalar",
|
"tag": "scalar"
|
||||||
},
|
|
||||||
tag: "array",
|
|
||||||
},
|
},
|
||||||
|
"tag": "array"
|
||||||
|
}
|
||||||
],
|
],
|
||||||
tag: "unlabeledProduct",
|
"tag": "unlabeledProduct"
|
||||||
});
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export const helloTest_script = `
|
export const helloTest_script = `
|
||||||
@ -566,11 +516,13 @@ export const helloTest_script = `
|
|||||||
)
|
)
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export function helloTest(config?: { ttl?: number }): Promise<string>;
|
export function helloTest(
|
||||||
|
config?: {ttl?: number}
|
||||||
|
): Promise<string>;
|
||||||
|
|
||||||
export function helloTest(
|
export function helloTest(
|
||||||
peer: IFluenceClient$$,
|
peer: IFluenceClient$$,
|
||||||
config?: { ttl?: number },
|
config?: {ttl?: number}
|
||||||
): Promise<string>;
|
): Promise<string>;
|
||||||
|
|
||||||
export async function helloTest(...args: any[]) {
|
export async function helloTest(...args: any[]) {
|
||||||
@ -582,25 +534,26 @@ export async function helloTest(...args: any[]) {
|
|||||||
args = args.slice(1);
|
args = args.slice(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const callArgs = Object.fromEntries(
|
|
||||||
args.slice(0, argCount).map((arg, i) => [argNames[i], arg]),
|
|
||||||
);
|
|
||||||
|
|
||||||
const params = {
|
const callArgs = Object.fromEntries(args.slice(0, argCount).map((arg, i) => [argNames[i], arg]));
|
||||||
|
|
||||||
|
const params = ({
|
||||||
peer,
|
peer,
|
||||||
args: callArgs,
|
args: callArgs,
|
||||||
config: args[argCount],
|
config: args[argCount]
|
||||||
};
|
});
|
||||||
|
|
||||||
const result = await callFunction$$({
|
const result = await callFunction$$({
|
||||||
script: helloTest_script,
|
script: helloTest_script,
|
||||||
...params,
|
...params,
|
||||||
});
|
});
|
||||||
|
|
||||||
return aqua2ts(result, {
|
return aqua2ts(result,
|
||||||
name: "string",
|
{
|
||||||
tag: "scalar",
|
"name": "string",
|
||||||
});
|
"tag": "scalar"
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export const callHappy_script = `
|
export const callHappy_script = `
|
||||||
@ -633,7 +586,7 @@ export function callHappy(
|
|||||||
b: number,
|
b: number,
|
||||||
c: number,
|
c: number,
|
||||||
d: (arg0: string) => number | Promise<number>,
|
d: (arg0: string) => number | Promise<number>,
|
||||||
config?: { ttl?: number },
|
config?: {ttl?: number}
|
||||||
): Promise<number>;
|
): Promise<number>;
|
||||||
|
|
||||||
export function callHappy(
|
export function callHappy(
|
||||||
@ -642,7 +595,7 @@ export function callHappy(
|
|||||||
b: number,
|
b: number,
|
||||||
c: number,
|
c: number,
|
||||||
d: (arg0: string) => number | Promise<number>,
|
d: (arg0: string) => number | Promise<number>,
|
||||||
config?: { ttl?: number },
|
config?: {ttl?: number}
|
||||||
): Promise<number>;
|
): Promise<number>;
|
||||||
|
|
||||||
export async function callHappy(...args: any[]) {
|
export async function callHappy(...args: any[]) {
|
||||||
@ -654,25 +607,26 @@ export async function callHappy(...args: any[]) {
|
|||||||
args = args.slice(1);
|
args = args.slice(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const callArgs = Object.fromEntries(
|
|
||||||
args.slice(0, argCount).map((arg, i) => [argNames[i], arg]),
|
|
||||||
);
|
|
||||||
|
|
||||||
const params = {
|
const callArgs = Object.fromEntries(args.slice(0, argCount).map((arg, i) => [argNames[i], arg]));
|
||||||
|
|
||||||
|
const params = ({
|
||||||
peer,
|
peer,
|
||||||
args: callArgs,
|
args: callArgs,
|
||||||
config: args[argCount],
|
config: args[argCount]
|
||||||
};
|
});
|
||||||
|
|
||||||
const result = await callFunction$$({
|
const result = await callFunction$$({
|
||||||
script: callHappy_script,
|
script: callHappy_script,
|
||||||
...params,
|
...params,
|
||||||
});
|
});
|
||||||
|
|
||||||
return aqua2ts(result, {
|
return aqua2ts(result,
|
||||||
name: "f64",
|
{
|
||||||
tag: "scalar",
|
"name": "f64",
|
||||||
});
|
"tag": "scalar"
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export const demo_calculation_script = `
|
export const demo_calculation_script = `
|
||||||
@ -708,13 +662,13 @@ export const demo_calculation_script = `
|
|||||||
|
|
||||||
export function demo_calculation(
|
export function demo_calculation(
|
||||||
service_id: string,
|
service_id: string,
|
||||||
config?: { ttl?: number },
|
config?: {ttl?: number}
|
||||||
): Promise<number>;
|
): Promise<number>;
|
||||||
|
|
||||||
export function demo_calculation(
|
export function demo_calculation(
|
||||||
peer: IFluenceClient$$,
|
peer: IFluenceClient$$,
|
||||||
service_id: string,
|
service_id: string,
|
||||||
config?: { ttl?: number },
|
config?: {ttl?: number}
|
||||||
): Promise<number>;
|
): Promise<number>;
|
||||||
|
|
||||||
export async function demo_calculation(...args: any[]) {
|
export async function demo_calculation(...args: any[]) {
|
||||||
@ -726,25 +680,26 @@ export async function demo_calculation(...args: any[]) {
|
|||||||
args = args.slice(1);
|
args = args.slice(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const callArgs = Object.fromEntries(
|
|
||||||
args.slice(0, argCount).map((arg, i) => [argNames[i], arg]),
|
|
||||||
);
|
|
||||||
|
|
||||||
const params = {
|
const callArgs = Object.fromEntries(args.slice(0, argCount).map((arg, i) => [argNames[i], arg]));
|
||||||
|
|
||||||
|
const params = ({
|
||||||
peer,
|
peer,
|
||||||
args: callArgs,
|
args: callArgs,
|
||||||
config: args[argCount],
|
config: args[argCount]
|
||||||
};
|
});
|
||||||
|
|
||||||
const result = await callFunction$$({
|
const result = await callFunction$$({
|
||||||
script: demo_calculation_script,
|
script: demo_calculation_script,
|
||||||
...params,
|
...params,
|
||||||
});
|
});
|
||||||
|
|
||||||
return aqua2ts(result, {
|
return aqua2ts(result,
|
||||||
name: "f64",
|
{
|
||||||
tag: "scalar",
|
"name": "f64",
|
||||||
});
|
"tag": "scalar"
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export const marineTest_script = `
|
export const marineTest_script = `
|
||||||
@ -783,13 +738,13 @@ export const marineTest_script = `
|
|||||||
|
|
||||||
export function marineTest(
|
export function marineTest(
|
||||||
wasm64: string,
|
wasm64: string,
|
||||||
config?: { ttl?: number },
|
config?: {ttl?: number}
|
||||||
): Promise<number>;
|
): Promise<number>;
|
||||||
|
|
||||||
export function marineTest(
|
export function marineTest(
|
||||||
peer: IFluenceClient$$,
|
peer: IFluenceClient$$,
|
||||||
wasm64: string,
|
wasm64: string,
|
||||||
config?: { ttl?: number },
|
config?: {ttl?: number}
|
||||||
): Promise<number>;
|
): Promise<number>;
|
||||||
|
|
||||||
export async function marineTest(...args: any[]) {
|
export async function marineTest(...args: any[]) {
|
||||||
@ -801,23 +756,24 @@ export async function marineTest(...args: any[]) {
|
|||||||
args = args.slice(1);
|
args = args.slice(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const callArgs = Object.fromEntries(
|
|
||||||
args.slice(0, argCount).map((arg, i) => [argNames[i], arg]),
|
|
||||||
);
|
|
||||||
|
|
||||||
const params = {
|
const callArgs = Object.fromEntries(args.slice(0, argCount).map((arg, i) => [argNames[i], arg]));
|
||||||
|
|
||||||
|
const params = ({
|
||||||
peer,
|
peer,
|
||||||
args: callArgs,
|
args: callArgs,
|
||||||
config: args[argCount],
|
config: args[argCount]
|
||||||
};
|
});
|
||||||
|
|
||||||
const result = await callFunction$$({
|
const result = await callFunction$$({
|
||||||
script: marineTest_script,
|
script: marineTest_script,
|
||||||
...params,
|
...params,
|
||||||
});
|
});
|
||||||
|
|
||||||
return aqua2ts(result, {
|
return aqua2ts(result,
|
||||||
name: "f64",
|
{
|
||||||
tag: "scalar",
|
"name": "f64",
|
||||||
});
|
"tag": "scalar"
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
import { Fluence, type ClientConfig } from "@fluencelabs/js-client";
|
import { Fluence, type ClientConfig } from "@fluencelabs/js-client";
|
||||||
import { fromByteArray } from "base64-js";
|
import { fromByteArray } from "base64-js";
|
||||||
|
|
||||||
import { test as particleTest } from "./_aqua/finalize_particle.js";
|
// import { test as particleTest } from "./_aqua/finalize_particle.js";
|
||||||
import {
|
import {
|
||||||
registerHelloWorld,
|
registerHelloWorld,
|
||||||
helloTest,
|
helloTest,
|
||||||
@ -90,11 +90,12 @@ export const runTest = async (): Promise<TestResult> => {
|
|||||||
|
|
||||||
console.log("running marine test...");
|
console.log("running marine test...");
|
||||||
const marine = await marineTest(wasm);
|
const marine = await marineTest(wasm);
|
||||||
|
console.log("marine test finished, result: ", marine);
|
||||||
|
|
||||||
console.log("running particle test...");
|
console.log("running particle test...");
|
||||||
await particleTest();
|
|
||||||
|
|
||||||
console.log("marine test finished, result: ", marine);
|
// TODO: Currently this behavior will timeout after TTL bcs this function don't call 'responseSrc'. Will be attended in the next updates
|
||||||
|
//await particleTest();
|
||||||
|
|
||||||
const returnVal = {
|
const returnVal = {
|
||||||
hello,
|
hello,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user