mirror of
https://github.com/fluencelabs/fluence-js.git
synced 2025-05-15 02:41:19 +00:00
Fix comments
This commit is contained in:
parent
6ab6e9d636
commit
e647ab0f2d
@ -23,8 +23,6 @@
|
|||||||
"@fluencelabs/interfaces": "workspace:*",
|
"@fluencelabs/interfaces": "workspace:*",
|
||||||
"@fluencelabs/js-client": "workspace:^",
|
"@fluencelabs/js-client": "workspace:^",
|
||||||
"@fluencelabs/registry": "0.8.7",
|
"@fluencelabs/registry": "0.8.7",
|
||||||
"@fluencelabs/spell": "0.5.20",
|
|
||||||
"@fluencelabs/trust-graph": "0.4.7",
|
|
||||||
"vitest": "0.34.6",
|
"vitest": "0.34.6",
|
||||||
"zod": "3.22.4"
|
"zod": "3.22.4"
|
||||||
}
|
}
|
||||||
|
@ -120,10 +120,7 @@ export function typeToTs(t: NonArrowType | ArrowType): string {
|
|||||||
return [name, typeToTs(type)];
|
return [name, typeToTs(type)];
|
||||||
});
|
});
|
||||||
|
|
||||||
// JS-client argument
|
|
||||||
if (domain.tag !== "unlabeledProduct") {
|
|
||||||
args.push(["callParams", `ParticleContext$$`]);
|
args.push(["callParams", `ParticleContext$$`]);
|
||||||
}
|
|
||||||
|
|
||||||
const funcArgs = args
|
const funcArgs = args
|
||||||
.map(([name, type]) => {
|
.map(([name, type]) => {
|
||||||
|
@ -27,7 +27,6 @@ import {
|
|||||||
aqua2ts,
|
aqua2ts,
|
||||||
ts2aqua,
|
ts2aqua,
|
||||||
wrapFunction,
|
wrapFunction,
|
||||||
wrapServiceFunction,
|
|
||||||
} from "./compilerSupport/conversions.js";
|
} from "./compilerSupport/conversions.js";
|
||||||
import { ServiceImpl } from "./compilerSupport/types.js";
|
import { ServiceImpl } from "./compilerSupport/types.js";
|
||||||
import { FluencePeer } from "./jsPeer/FluencePeer.js";
|
import { FluencePeer } from "./jsPeer/FluencePeer.js";
|
||||||
@ -43,7 +42,7 @@ import { callAquaFunction, Fluence, registerService } from "./index.js";
|
|||||||
* @param script - air script with function execution logic generated by the Aqua compiler
|
* @param script - air script with function execution logic generated by the Aqua compiler
|
||||||
*/
|
*/
|
||||||
export const v5_callFunction = async (
|
export const v5_callFunction = async (
|
||||||
args: (JSONValue | ((...args: JSONValue[]) => JSONValue))[],
|
args: (JSONValue | ServiceImpl[string])[],
|
||||||
def: FunctionCallDef,
|
def: FunctionCallDef,
|
||||||
script: string,
|
script: string,
|
||||||
): Promise<unknown> => {
|
): Promise<unknown> => {
|
||||||
@ -75,9 +74,7 @@ export const v5_callFunction = async (
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const callArgs = Object.fromEntries<
|
const callArgs = Object.fromEntries<JSONValue | ServiceImpl[string]>(
|
||||||
JSONValue | ((...args: JSONValue[]) => JSONValue)
|
|
||||||
>(
|
|
||||||
args.slice(0, argCount).map((arg, i) => {
|
args.slice(0, argCount).map((arg, i) => {
|
||||||
const argSchema = functionArgs[argNames[i]];
|
const argSchema = functionArgs[argNames[i]];
|
||||||
|
|
||||||
@ -160,7 +157,7 @@ export const v5_registerService = (args: unknown[], def: ServiceDef): void => {
|
|||||||
|
|
||||||
const wrappedServiceImpl = Object.fromEntries(
|
const wrappedServiceImpl = Object.fromEntries(
|
||||||
Object.entries(serviceImpl).map(([name, func]) => {
|
Object.entries(serviceImpl).map(([name, func]) => {
|
||||||
return [name, wrapServiceFunction(func, serviceSchema[name])];
|
return [name, wrapFunction(func, serviceSchema[name])];
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
import { JSONValue } from "@fluencelabs/interfaces";
|
import { JSONValue } from "@fluencelabs/interfaces";
|
||||||
|
|
||||||
import { FluencePeer } from "../jsPeer/FluencePeer.js";
|
import { FluencePeer } from "../jsPeer/FluencePeer.js";
|
||||||
import { ParticleContext } from "../jsServiceHost/interfaces.js";
|
|
||||||
import { logger } from "../util/logger.js";
|
import { logger } from "../util/logger.js";
|
||||||
import { ArgCallbackFunction } from "../util/testUtils.js";
|
import { ArgCallbackFunction } from "../util/testUtils.js";
|
||||||
|
|
||||||
@ -74,16 +73,7 @@ export const callAquaFunction = async ({
|
|||||||
let service: ServiceDescription;
|
let service: ServiceDescription;
|
||||||
|
|
||||||
if (typeof argVal === "function") {
|
if (typeof argVal === "function") {
|
||||||
service = userHandlerService(
|
service = userHandlerService("callbackSrv", name, argVal);
|
||||||
"callbackSrv",
|
|
||||||
name,
|
|
||||||
(...args: [...JSONValue[], ParticleContext]) => {
|
|
||||||
// Impossible to extract all element except the last one and coerce type
|
|
||||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
||||||
const jsonArgs = args.slice(0, args.length - 1) as JSONValue[];
|
|
||||||
return argVal(jsonArgs);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
service = injectValueService("getDataSrv", name, argVal);
|
service = injectValueService("getDataSrv", name, argVal);
|
||||||
}
|
}
|
||||||
|
@ -15,15 +15,17 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import {
|
||||||
ArrowWithCallbacks,
|
ArrowType,
|
||||||
ArrowWithoutCallbacks,
|
ArrowWithoutCallbacks,
|
||||||
JSONValue,
|
JSONValue,
|
||||||
|
LabeledProductType,
|
||||||
NonArrowSimpleType,
|
NonArrowSimpleType,
|
||||||
|
SimpleTypes,
|
||||||
} from "@fluencelabs/interfaces";
|
} from "@fluencelabs/interfaces";
|
||||||
|
|
||||||
import { ParticleContext } from "../jsServiceHost/interfaces.js";
|
import { ParticleContext } from "../jsServiceHost/interfaces.js";
|
||||||
|
|
||||||
import { MaybePromise } from "./types.js";
|
import { ServiceImpl } from "./types.js";
|
||||||
|
|
||||||
export function aqua2ts(
|
export function aqua2ts(
|
||||||
value: JSONValue,
|
value: JSONValue,
|
||||||
@ -123,30 +125,9 @@ export function ts2aqua(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const wrapFunction = (
|
export const wrapFunction = (
|
||||||
value: (...args: JSONValue[]) => JSONValue,
|
value: ServiceImpl[string],
|
||||||
schema: ArrowWithoutCallbacks,
|
schema: ArrowWithoutCallbacks | ArrowType<LabeledProductType<SimpleTypes>>,
|
||||||
): ((...args: JSONValue[]) => JSONValue) => {
|
): ServiceImpl[string] => {
|
||||||
return (...args) => {
|
|
||||||
const schemaArgs =
|
|
||||||
schema.codomain.tag === "nil" ? [] : schema.codomain.items;
|
|
||||||
|
|
||||||
const tsArgs = args.map((arg, i) => {
|
|
||||||
return aqua2ts(arg, schemaArgs[i]);
|
|
||||||
});
|
|
||||||
|
|
||||||
const result = value(...tsArgs);
|
|
||||||
return ts2aqua(result, schema.codomain);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export const wrapServiceFunction = (
|
|
||||||
value: (
|
|
||||||
...args: [...JSONValue[], ParticleContext]
|
|
||||||
) => MaybePromise<JSONValue>,
|
|
||||||
schema: ArrowWithCallbacks,
|
|
||||||
): ((
|
|
||||||
...args: [...JSONValue[], ParticleContext]
|
|
||||||
) => MaybePromise<JSONValue>) => {
|
|
||||||
return async (...args) => {
|
return async (...args) => {
|
||||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||||
const jsonArgs = args.slice(0, args.length - 1) as JSONValue[];
|
const jsonArgs = args.slice(0, args.length - 1) as JSONValue[];
|
||||||
@ -154,13 +135,24 @@ export const wrapServiceFunction = (
|
|||||||
const context = args[args.length - 1] as ParticleContext;
|
const context = args[args.length - 1] as ParticleContext;
|
||||||
|
|
||||||
const schemaArgs =
|
const schemaArgs =
|
||||||
schema.codomain.tag === "nil" ? [] : schema.codomain.items;
|
schema.domain.tag === "nil"
|
||||||
|
? []
|
||||||
|
: schema.domain.tag === "unlabeledProduct"
|
||||||
|
? schema.domain.items
|
||||||
|
: Object.values(schema.domain.fields);
|
||||||
|
|
||||||
const tsArgs = jsonArgs.map((arg, i) => {
|
const tsArgs = jsonArgs.map((arg, i) => {
|
||||||
return aqua2ts(arg, schemaArgs[i]);
|
return aqua2ts(arg, schemaArgs[i]);
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = await value(...tsArgs, context);
|
const result = await value(...tsArgs, context);
|
||||||
return ts2aqua(result, schema.codomain);
|
|
||||||
|
const valueSchema =
|
||||||
|
schema.codomain.tag === "unlabeledProduct" &&
|
||||||
|
schema.codomain.items.length === 1
|
||||||
|
? schema.codomain.items[0]
|
||||||
|
: schema.codomain;
|
||||||
|
|
||||||
|
return ts2aqua(result, valueSchema);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -28,6 +28,7 @@ import { Subject, Subscribable } from "rxjs";
|
|||||||
import { ClientPeer, makeClientPeerConfig } from "../clientPeer/ClientPeer.js";
|
import { ClientPeer, makeClientPeerConfig } from "../clientPeer/ClientPeer.js";
|
||||||
import { ClientConfig, RelayOptions } from "../clientPeer/types.js";
|
import { ClientConfig, RelayOptions } from "../clientPeer/types.js";
|
||||||
import { callAquaFunction } from "../compilerSupport/callFunction.js";
|
import { callAquaFunction } from "../compilerSupport/callFunction.js";
|
||||||
|
import { ServiceImpl } from "../compilerSupport/types.js";
|
||||||
import { IConnection } from "../connection/interfaces.js";
|
import { IConnection } from "../connection/interfaces.js";
|
||||||
import { DEFAULT_CONFIG, FluencePeer } from "../jsPeer/FluencePeer.js";
|
import { DEFAULT_CONFIG, FluencePeer } from "../jsPeer/FluencePeer.js";
|
||||||
import { CallServiceResultType } from "../jsServiceHost/interfaces.js";
|
import { CallServiceResultType } from "../jsServiceHost/interfaces.js";
|
||||||
@ -76,9 +77,7 @@ interface FunctionInfo {
|
|||||||
/**
|
/**
|
||||||
* Type for callback passed as aqua function argument
|
* Type for callback passed as aqua function argument
|
||||||
*/
|
*/
|
||||||
export type ArgCallbackFunction = (
|
export type ArgCallbackFunction = ServiceImpl[string];
|
||||||
...args: JSONValue[]
|
|
||||||
) => JSONValue | Promise<JSONValue>;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Arguments passed to Aqua function
|
* Arguments passed to Aqua function
|
||||||
|
18
pnpm-lock.yaml
generated
18
pnpm-lock.yaml
generated
@ -176,17 +176,11 @@ importers:
|
|||||||
specifier: workspace:*
|
specifier: workspace:*
|
||||||
version: link:../interfaces
|
version: link:../interfaces
|
||||||
'@fluencelabs/js-client':
|
'@fluencelabs/js-client':
|
||||||
specifier: 0.4.3
|
specifier: workspace:^
|
||||||
version: link:../js-client
|
version: link:../js-client
|
||||||
'@fluencelabs/registry':
|
'@fluencelabs/registry':
|
||||||
specifier: 0.8.7
|
specifier: 0.8.7
|
||||||
version: 0.8.7
|
version: 0.8.7
|
||||||
'@fluencelabs/spell':
|
|
||||||
specifier: 0.5.20
|
|
||||||
version: 0.5.20
|
|
||||||
'@fluencelabs/trust-graph':
|
|
||||||
specifier: 0.4.7
|
|
||||||
version: 0.4.7
|
|
||||||
vitest:
|
vitest:
|
||||||
specifier: 0.34.6
|
specifier: 0.34.6
|
||||||
version: 0.34.6
|
version: 0.34.6
|
||||||
@ -3731,10 +3725,6 @@ packages:
|
|||||||
'@fluencelabs/trust-graph': 0.4.1
|
'@fluencelabs/trust-graph': 0.4.1
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/@fluencelabs/spell@0.5.20:
|
|
||||||
resolution: {integrity: sha512-QFbknWwALLUWMzpWkFt34McuwTz9xwQuiPP1zXqhPqVZ1J6g8F3gwHHtzgHFW5Z7WrRmwsL+IQtFJy8YZubhDw==}
|
|
||||||
dev: true
|
|
||||||
|
|
||||||
/@fluencelabs/threads@2.0.0:
|
/@fluencelabs/threads@2.0.0:
|
||||||
resolution: {integrity: sha512-dgYpZg55OcEmop1U3G2bFKEJXg2avjXWYfWsdPlkSbHOHguaRifvr5bgwIYTg1wxoPGcn0jegcjKKwrY0qrV+g==}
|
resolution: {integrity: sha512-dgYpZg55OcEmop1U3G2bFKEJXg2avjXWYfWsdPlkSbHOHguaRifvr5bgwIYTg1wxoPGcn0jegcjKKwrY0qrV+g==}
|
||||||
dependencies:
|
dependencies:
|
||||||
@ -3754,12 +3744,6 @@ packages:
|
|||||||
'@fluencelabs/aqua-lib': 0.7.3
|
'@fluencelabs/aqua-lib': 0.7.3
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/@fluencelabs/trust-graph@0.4.7:
|
|
||||||
resolution: {integrity: sha512-e4TxWimUh9GBWjqSO8WGsSqjZfyIs6f39/8Pzfo6PCcNoSf8FPaaO817Pw4FmAXYEKR1IalIUX3CDdym3NlHWw==}
|
|
||||||
dependencies:
|
|
||||||
'@fluencelabs/aqua-lib': 0.7.3
|
|
||||||
dev: true
|
|
||||||
|
|
||||||
/@fluencelabs/trust-graph@3.1.2:
|
/@fluencelabs/trust-graph@3.1.2:
|
||||||
resolution: {integrity: sha512-HpyHtiomh09wv6/83z+bhbkqVngIUdqNGEXRTIPg4sArVPMZ9UCXBrkQsHDRqdMUx0lBAcgB3IjlbdhkwHGaXA==}
|
resolution: {integrity: sha512-HpyHtiomh09wv6/83z+bhbkqVngIUdqNGEXRTIPg4sArVPMZ9UCXBrkQsHDRqdMUx0lBAcgB3IjlbdhkwHGaXA==}
|
||||||
dependencies:
|
dependencies:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user