Fix comments

This commit is contained in:
Akim Mamedov 2023-11-16 17:49:28 +07:00
parent 6ab6e9d636
commit e647ab0f2d
7 changed files with 28 additions and 71 deletions

View File

@ -23,8 +23,6 @@
"@fluencelabs/interfaces": "workspace:*",
"@fluencelabs/js-client": "workspace:^",
"@fluencelabs/registry": "0.8.7",
"@fluencelabs/spell": "0.5.20",
"@fluencelabs/trust-graph": "0.4.7",
"vitest": "0.34.6",
"zod": "3.22.4"
}

View File

@ -120,10 +120,7 @@ export function typeToTs(t: NonArrowType | ArrowType): string {
return [name, typeToTs(type)];
});
// JS-client argument
if (domain.tag !== "unlabeledProduct") {
args.push(["callParams", `ParticleContext$$`]);
}
args.push(["callParams", `ParticleContext$$`]);
const funcArgs = args
.map(([name, type]) => {

View File

@ -27,7 +27,6 @@ import {
aqua2ts,
ts2aqua,
wrapFunction,
wrapServiceFunction,
} from "./compilerSupport/conversions.js";
import { ServiceImpl } from "./compilerSupport/types.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
*/
export const v5_callFunction = async (
args: (JSONValue | ((...args: JSONValue[]) => JSONValue))[],
args: (JSONValue | ServiceImpl[string])[],
def: FunctionCallDef,
script: string,
): Promise<unknown> => {
@ -75,9 +74,7 @@ export const v5_callFunction = async (
);
}
const callArgs = Object.fromEntries<
JSONValue | ((...args: JSONValue[]) => JSONValue)
>(
const callArgs = Object.fromEntries<JSONValue | ServiceImpl[string]>(
args.slice(0, argCount).map((arg, i) => {
const argSchema = functionArgs[argNames[i]];
@ -160,7 +157,7 @@ export const v5_registerService = (args: unknown[], def: ServiceDef): void => {
const wrappedServiceImpl = Object.fromEntries(
Object.entries(serviceImpl).map(([name, func]) => {
return [name, wrapServiceFunction(func, serviceSchema[name])];
return [name, wrapFunction(func, serviceSchema[name])];
}),
);

View File

@ -17,7 +17,6 @@
import { JSONValue } from "@fluencelabs/interfaces";
import { FluencePeer } from "../jsPeer/FluencePeer.js";
import { ParticleContext } from "../jsServiceHost/interfaces.js";
import { logger } from "../util/logger.js";
import { ArgCallbackFunction } from "../util/testUtils.js";
@ -74,16 +73,7 @@ export const callAquaFunction = async ({
let service: ServiceDescription;
if (typeof argVal === "function") {
service = userHandlerService(
"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);
},
);
service = userHandlerService("callbackSrv", name, argVal);
} else {
service = injectValueService("getDataSrv", name, argVal);
}

View File

@ -15,15 +15,17 @@
*/
import {
ArrowWithCallbacks,
ArrowType,
ArrowWithoutCallbacks,
JSONValue,
LabeledProductType,
NonArrowSimpleType,
SimpleTypes,
} from "@fluencelabs/interfaces";
import { ParticleContext } from "../jsServiceHost/interfaces.js";
import { MaybePromise } from "./types.js";
import { ServiceImpl } from "./types.js";
export function aqua2ts(
value: JSONValue,
@ -123,30 +125,9 @@ export function ts2aqua(
}
export const wrapFunction = (
value: (...args: JSONValue[]) => JSONValue,
schema: ArrowWithoutCallbacks,
): ((...args: JSONValue[]) => JSONValue) => {
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>) => {
value: ServiceImpl[string],
schema: ArrowWithoutCallbacks | ArrowType<LabeledProductType<SimpleTypes>>,
): ServiceImpl[string] => {
return async (...args) => {
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
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 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) => {
return aqua2ts(arg, schemaArgs[i]);
});
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);
};
};

View File

@ -28,6 +28,7 @@ import { Subject, Subscribable } from "rxjs";
import { ClientPeer, makeClientPeerConfig } from "../clientPeer/ClientPeer.js";
import { ClientConfig, RelayOptions } from "../clientPeer/types.js";
import { callAquaFunction } from "../compilerSupport/callFunction.js";
import { ServiceImpl } from "../compilerSupport/types.js";
import { IConnection } from "../connection/interfaces.js";
import { DEFAULT_CONFIG, FluencePeer } from "../jsPeer/FluencePeer.js";
import { CallServiceResultType } from "../jsServiceHost/interfaces.js";
@ -76,9 +77,7 @@ interface FunctionInfo {
/**
* Type for callback passed as aqua function argument
*/
export type ArgCallbackFunction = (
...args: JSONValue[]
) => JSONValue | Promise<JSONValue>;
export type ArgCallbackFunction = ServiceImpl[string];
/**
* Arguments passed to Aqua function

18
pnpm-lock.yaml generated
View File

@ -176,17 +176,11 @@ importers:
specifier: workspace:*
version: link:../interfaces
'@fluencelabs/js-client':
specifier: 0.4.3
specifier: workspace:^
version: link:../js-client
'@fluencelabs/registry':
specifier: 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:
specifier: 0.34.6
version: 0.34.6
@ -3731,10 +3725,6 @@ packages:
'@fluencelabs/trust-graph': 0.4.1
dev: true
/@fluencelabs/spell@0.5.20:
resolution: {integrity: sha512-QFbknWwALLUWMzpWkFt34McuwTz9xwQuiPP1zXqhPqVZ1J6g8F3gwHHtzgHFW5Z7WrRmwsL+IQtFJy8YZubhDw==}
dev: true
/@fluencelabs/threads@2.0.0:
resolution: {integrity: sha512-dgYpZg55OcEmop1U3G2bFKEJXg2avjXWYfWsdPlkSbHOHguaRifvr5bgwIYTg1wxoPGcn0jegcjKKwrY0qrV+g==}
dependencies:
@ -3754,12 +3744,6 @@ packages:
'@fluencelabs/aqua-lib': 0.7.3
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:
resolution: {integrity: sha512-HpyHtiomh09wv6/83z+bhbkqVngIUdqNGEXRTIPg4sArVPMZ9UCXBrkQsHDRqdMUx0lBAcgB3IjlbdhkwHGaXA==}
dependencies: