mirror of
https://github.com/fluencelabs/fluence-js.git
synced 2025-05-10 16:37:12 +00:00
Review fixes
This commit is contained in:
parent
22a0cc27d6
commit
56620ab6fa
@ -28,7 +28,7 @@ import {
|
||||
aqua2js,
|
||||
SchemaValidationError,
|
||||
js2aqua,
|
||||
wrapFunction,
|
||||
wrapJsFunction,
|
||||
} from "./compilerSupport/conversions.js";
|
||||
import { ServiceImpl } from "./compilerSupport/types.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") {
|
||||
@ -204,7 +204,7 @@ export const v5_registerService = (
|
||||
// Wrapping service impl to convert their args ts -> aqua and backwards
|
||||
const wrappedServiceImpl = Object.fromEntries(
|
||||
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],
|
||||
schema:
|
||||
| ArrowWithoutCallbacks
|
||||
|
@ -68,13 +68,15 @@ const parseWithSchema = <T extends z.ZodTypeAny>(
|
||||
): [z.infer<T>, null] | [null, string] => {
|
||||
const result = schema.safeParse(req.args, {
|
||||
errorMap: (issue, ctx) => {
|
||||
if (issue.code === z.ZodIssueCode.invalid_type) {
|
||||
if (issue.path.length === 1 && typeof issue.path[0] === "number") {
|
||||
const [arg] = issue.path;
|
||||
return {
|
||||
message: `Argument ${arg} expected to be of type ${issue.expected}, Got ${issue.received}`,
|
||||
};
|
||||
}
|
||||
if (
|
||||
issue.code === z.ZodIssueCode.invalid_type &&
|
||||
issue.path.length === 1 &&
|
||||
typeof issue.path[0] === "number"
|
||||
) {
|
||||
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) {
|
||||
@ -340,8 +342,7 @@ export const builtInServices: Record<
|
||||
}),
|
||||
|
||||
concat_strings: withSchema(z.array(z.string()))((args) => {
|
||||
const res = "".concat(...args);
|
||||
return success(res);
|
||||
return success(args.join(""));
|
||||
}),
|
||||
},
|
||||
|
||||
|
@ -19,6 +19,8 @@ import { PeerIdB58 } from "@fluencelabs/interfaces";
|
||||
|
||||
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
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user