mirror of
https://github.com/fluencelabs/fluence-js.git
synced 2025-06-14 16:41:21 +00:00
Bug fix
This commit is contained in:
@ -50,19 +50,19 @@ export function registerHelloWorld(peer: IFluenceClient$$, serviceId: string, se
|
||||
// Functions
|
||||
export type ResourceTestResultType = [string | null, string[]]
|
||||
|
||||
export type resourceTestParams = [label: string, config?: {ttl?: number}] | [peer: IFluenceClient$$, label: string, config?: {ttl?: number}];
|
||||
export type ResourceTestParams = [label: string, config?: {ttl?: number}] | [peer: IFluenceClient$$, label: string, config?: {ttl?: number}];
|
||||
|
||||
export type ResourceTestResult = Promise<ResourceTestResultType>;
|
||||
|
||||
export type helloTestParams = [config?: {ttl?: number}] | [peer: IFluenceClient$$, config?: {ttl?: number}];
|
||||
export type HelloTestParams = [config?: {ttl?: number}] | [peer: IFluenceClient$$, config?: {ttl?: number}];
|
||||
|
||||
export type HelloTestResult = Promise<string>;
|
||||
|
||||
export type demo_calculationParams = [service_id: string, config?: {ttl?: number}] | [peer: IFluenceClient$$, service_id: string, config?: {ttl?: number}];
|
||||
export type Demo_calculationParams = [service_id: string, config?: {ttl?: number}] | [peer: IFluenceClient$$, service_id: string, config?: {ttl?: number}];
|
||||
|
||||
export type Demo_calculationResult = Promise<number>;
|
||||
|
||||
export type marineTestParams = [wasm64: string, config?: {ttl?: number}] | [peer: IFluenceClient$$, wasm64: string, config?: {ttl?: number}];
|
||||
export type MarineTestParams = [wasm64: string, config?: {ttl?: number}] | [peer: IFluenceClient$$, wasm64: string, config?: {ttl?: number}];
|
||||
|
||||
export type MarineTestResult = Promise<number>;
|
||||
|
||||
|
@ -542,7 +542,7 @@ export const resourceTest_script = `
|
||||
|
||||
export type ResourceTestResultType = [string | null, string[]]
|
||||
|
||||
export type resourceTestParams = [label: string, config?: {ttl?: number}] | [peer: IFluenceClient$$, label: string, config?: {ttl?: number}];
|
||||
export type ResourceTestParams = [label: string, config?: {ttl?: number}] | [peer: IFluenceClient$$, label: string, config?: {ttl?: number}];
|
||||
|
||||
export type ResourceTestResult = Promise<ResourceTestResultType>;
|
||||
|
||||
@ -609,7 +609,7 @@ export const helloTest_script = `
|
||||
)
|
||||
`;
|
||||
|
||||
export type helloTestParams = [config?: {ttl?: number}] | [peer: IFluenceClient$$, config?: {ttl?: number}];
|
||||
export type HelloTestParams = [config?: {ttl?: number}] | [peer: IFluenceClient$$, config?: {ttl?: number}];
|
||||
|
||||
export type HelloTestResult = Promise<string>;
|
||||
|
||||
@ -679,7 +679,7 @@ export const demo_calculation_script = `
|
||||
)
|
||||
`;
|
||||
|
||||
export type demo_calculationParams = [service_id: string, config?: {ttl?: number}] | [peer: IFluenceClient$$, service_id: string, config?: {ttl?: number}];
|
||||
export type Demo_calculationParams = [service_id: string, config?: {ttl?: number}] | [peer: IFluenceClient$$, service_id: string, config?: {ttl?: number}];
|
||||
|
||||
export type Demo_calculationResult = Promise<number>;
|
||||
|
||||
@ -757,7 +757,7 @@ export const marineTest_script = `
|
||||
)
|
||||
`;
|
||||
|
||||
export type marineTestParams = [wasm64: string, config?: {ttl?: number}] | [peer: IFluenceClient$$, wasm64: string, config?: {ttl?: number}];
|
||||
export type MarineTestParams = [wasm64: string, config?: {ttl?: number}] | [peer: IFluenceClient$$, wasm64: string, config?: {ttl?: number}];
|
||||
|
||||
export type MarineTestResult = Promise<number>;
|
||||
|
||||
|
@ -86,7 +86,9 @@ export class TSTypeGenerator implements TypeGenerator {
|
||||
return [
|
||||
argsDesc.join("\n"),
|
||||
resTypeDesc ?? "",
|
||||
`export type ${funcDef.functionName}Params = ${functionOverloadArgsType};`,
|
||||
`export type ${capitalize(
|
||||
funcDef.functionName,
|
||||
)}Params = ${functionOverloadArgsType};`,
|
||||
`export type ${capitalize(
|
||||
funcDef.functionName,
|
||||
)}Result = Promise<${resType}>;\n`,
|
||||
|
@ -25,6 +25,7 @@ import type {
|
||||
import { CallAquaFunctionConfig } from "./compilerSupport/callFunction.js";
|
||||
import {
|
||||
aqua2ts,
|
||||
SchemaValidationError,
|
||||
ts2aqua,
|
||||
wrapFunction,
|
||||
} from "./compilerSupport/conversions.js";
|
||||
@ -37,10 +38,11 @@ const isAquaConfig = (
|
||||
config: JSONValue | ServiceImpl[string] | undefined,
|
||||
): config is CallAquaFunctionConfig => {
|
||||
return (
|
||||
typeof config === "object" &&
|
||||
config !== null &&
|
||||
!Array.isArray(config) &&
|
||||
["undefined", "number"].includes(typeof config["ttl"])
|
||||
config === undefined ||
|
||||
(typeof config === "object" &&
|
||||
config !== null &&
|
||||
!Array.isArray(config) &&
|
||||
["undefined", "number"].includes(typeof config["ttl"]))
|
||||
);
|
||||
};
|
||||
|
||||
@ -60,14 +62,17 @@ export const v5_callFunction = async (
|
||||
def: FunctionCallDef,
|
||||
script: string,
|
||||
): Promise<unknown> => {
|
||||
const [peer, ...rest] = args;
|
||||
const [peerOrArg, ...rest] = args;
|
||||
|
||||
if (!(peer instanceof FluencePeer)) {
|
||||
await v5_callFunction([getDefaultPeer(), ...rest], def, script);
|
||||
if (!(peerOrArg instanceof FluencePeer)) {
|
||||
await v5_callFunction([getDefaultPeer(), peerOrArg, ...rest], def, script);
|
||||
return;
|
||||
}
|
||||
|
||||
const argNames = Object.keys(def.arrow);
|
||||
const argNames = Object.keys(
|
||||
def.arrow.domain.tag === "nil" ? [] : def.arrow.domain.fields,
|
||||
);
|
||||
|
||||
const schemaArgCount = argNames.length;
|
||||
|
||||
type FunctionArg = SimpleTypes | ArrowWithoutCallbacks;
|
||||
@ -88,7 +93,12 @@ export const v5_callFunction = async (
|
||||
|
||||
if (argSchema.tag === "arrow") {
|
||||
if (typeof arg !== "function") {
|
||||
throw new Error("Argument and schema don't match");
|
||||
throw new SchemaValidationError(
|
||||
[argNames[i]],
|
||||
argSchema,
|
||||
"function",
|
||||
arg,
|
||||
);
|
||||
}
|
||||
|
||||
const wrappedFunction = wrapFunction(arg, argSchema);
|
||||
@ -97,7 +107,12 @@ export const v5_callFunction = async (
|
||||
}
|
||||
|
||||
if (typeof arg === "function") {
|
||||
throw new Error("Argument and schema don't match");
|
||||
throw new SchemaValidationError(
|
||||
[argNames[i]],
|
||||
argSchema,
|
||||
"non-function value",
|
||||
arg,
|
||||
);
|
||||
}
|
||||
|
||||
return [
|
||||
@ -111,7 +126,7 @@ export const v5_callFunction = async (
|
||||
def.arrow.codomain.tag === "nil" || def.arrow.codomain.items.length === 0;
|
||||
|
||||
const params = {
|
||||
peer,
|
||||
peer: peerOrArg,
|
||||
args: callArgs,
|
||||
config,
|
||||
};
|
||||
|
@ -28,12 +28,12 @@ import { ParticleContext } from "../jsServiceHost/interfaces.js";
|
||||
|
||||
import { ServiceImpl } from "./types.js";
|
||||
|
||||
class SchemaValidationError extends Error {
|
||||
export class SchemaValidationError extends Error {
|
||||
constructor(
|
||||
public path: string[],
|
||||
schema: NonArrowSimpleType,
|
||||
schema: NonArrowSimpleType | ArrowWithoutCallbacks,
|
||||
expected: string,
|
||||
provided: JSONValue,
|
||||
provided: JSONValue | ServiceImpl[string],
|
||||
) {
|
||||
const given =
|
||||
provided === null
|
||||
|
Reference in New Issue
Block a user