mirror of
https://github.com/fluencelabs/fluence-js.git
synced 2025-05-11 08:57:13 +00:00
Review fixes
This commit is contained in:
parent
22a0cc27d6
commit
56620ab6fa
@ -28,7 +28,7 @@ import {
|
|||||||
aqua2js,
|
aqua2js,
|
||||||
SchemaValidationError,
|
SchemaValidationError,
|
||||||
js2aqua,
|
js2aqua,
|
||||||
wrapFunction,
|
wrapJsFunction,
|
||||||
} 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";
|
||||||
@ -103,7 +103,7 @@ export const v5_callFunction = async (
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return [argName, wrapFunction(arg, argSchema)];
|
return [argName, wrapJsFunction(arg, argSchema)];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof arg === "function") {
|
if (typeof arg === "function") {
|
||||||
@ -204,7 +204,7 @@ export const v5_registerService = (
|
|||||||
// Wrapping service impl to convert their args ts -> aqua and backwards
|
// Wrapping service impl to convert their args ts -> aqua and backwards
|
||||||
const wrappedServiceImpl = Object.fromEntries(
|
const wrappedServiceImpl = Object.fromEntries(
|
||||||
Object.entries(serviceImpl).map(([name, func]) => {
|
Object.entries(serviceImpl).map(([name, func]) => {
|
||||||
return [name, wrapFunction(func, serviceSchema[name])];
|
return [name, wrapJsFunction(func, serviceSchema[name])];
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -202,7 +202,9 @@ export function js2aqua(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const wrapFunction = (
|
// Wrapping function, converting its arguments to aqua before call and back to js after call.
|
||||||
|
// It makes callbacks and service functions defined by user operate on js types seamlessly
|
||||||
|
export const wrapJsFunction = (
|
||||||
func: ServiceImpl[string],
|
func: ServiceImpl[string],
|
||||||
schema:
|
schema:
|
||||||
| ArrowWithoutCallbacks
|
| ArrowWithoutCallbacks
|
||||||
|
@ -68,13 +68,15 @@ const parseWithSchema = <T extends z.ZodTypeAny>(
|
|||||||
): [z.infer<T>, null] | [null, string] => {
|
): [z.infer<T>, null] | [null, string] => {
|
||||||
const result = schema.safeParse(req.args, {
|
const result = schema.safeParse(req.args, {
|
||||||
errorMap: (issue, ctx) => {
|
errorMap: (issue, ctx) => {
|
||||||
if (issue.code === z.ZodIssueCode.invalid_type) {
|
if (
|
||||||
if (issue.path.length === 1 && typeof issue.path[0] === "number") {
|
issue.code === z.ZodIssueCode.invalid_type &&
|
||||||
const [arg] = issue.path;
|
issue.path.length === 1 &&
|
||||||
return {
|
typeof issue.path[0] === "number"
|
||||||
message: `Argument ${arg} expected to be of type ${issue.expected}, Got ${issue.received}`,
|
) {
|
||||||
};
|
const [arg] = issue.path;
|
||||||
}
|
return {
|
||||||
|
message: `Argument ${arg} expected to be of type ${issue.expected}, Got ${issue.received}`,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (issue.code === z.ZodIssueCode.too_big) {
|
if (issue.code === z.ZodIssueCode.too_big) {
|
||||||
@ -340,8 +342,7 @@ export const builtInServices: Record<
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
concat_strings: withSchema(z.array(z.string()))((args) => {
|
concat_strings: withSchema(z.array(z.string()))((args) => {
|
||||||
const res = "".concat(...args);
|
return success(args.join(""));
|
||||||
return success(res);
|
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -19,6 +19,8 @@ import { PeerIdB58 } from "@fluencelabs/interfaces";
|
|||||||
|
|
||||||
import { ParticleContext } from "../jsServiceHost/interfaces.js";
|
import { ParticleContext } from "../jsServiceHost/interfaces.js";
|
||||||
|
|
||||||
|
// Helpers for validating service function
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A predicate of call params for sig service's sign method which determines whether signing operation is allowed or not
|
* A predicate of call params for sig service's sign method which determines whether signing operation is allowed or not
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user