From 357726a95984c407c3fdac4600d642c8799a8964 Mon Sep 17 00:00:00 2001 From: Akim Mamedov Date: Wed, 15 Nov 2023 23:07:09 +0700 Subject: [PATCH] Fix condition --- .../aqua/src/_aqua/finalize_particle.ts | 108 ------------------ packages/@tests/aqua/src/_aqua/smoke_test.ts | 108 ------------------ .../src/compilerSupport/callFunction.ts | 2 +- 3 files changed, 1 insertion(+), 217 deletions(-) diff --git a/packages/@tests/aqua/src/_aqua/finalize_particle.ts b/packages/@tests/aqua/src/_aqua/finalize_particle.ts index 3bde711f..b58d118b 100644 --- a/packages/@tests/aqua/src/_aqua/finalize_particle.ts +++ b/packages/@tests/aqua/src/_aqua/finalize_particle.ts @@ -17,114 +17,6 @@ import { FluencePeer as FluencePeer$$ } from '@fluencelabs/js-client'; -/** - * @typedef {import("@fluencelabs/js-client").NonArrowSimpleType} NonArrowSimpleType - * @typedef {import("@fluencelabs/js-client").JSONValue} JSONValue - */ -/** - * Convert value from its representation in aqua language to representation in typescript - * @param {JSONValue} value - value as represented in aqua - * @param {NonArrowSimpleType} schema - definition of the aqua schema - * @returns {JSONValue} value represented in typescript - */ -export function aqua2ts(value, schema) { - if (schema.tag === "nil") { - return null; - } - else if (schema.tag === "option") { - if (!Array.isArray(value)) { - throw new Error("Bad schema"); - } - if (value.length === 0) { - return null; - } - else { - return aqua2ts(value[0], schema.type); - } - } - else if (schema.tag === "scalar" || - schema.tag === "bottomType" || - schema.tag === "topType") { - return value; - } - else if (schema.tag === "array") { - if (!Array.isArray(value)) { - throw new Error("Bad schema"); - } - return value.map((y) => { - return aqua2ts(y, schema.type); - }); - } - else if (schema.tag === "unlabeledProduct") { - if (!Array.isArray(value)) { - throw new Error("Bad schema"); - } - return value.map((y, i) => { - return aqua2ts(y, schema.items[i]); - }); - } - else if (schema.tag === "struct" || schema.tag === "labeledProduct") { - if (typeof value !== "object" || value == null || Array.isArray(value)) { - throw new Error("Bad schema"); - } - return Object.entries(schema.fields).reduce((agg, [key, type]) => { - const val = aqua2ts(value[key], type); - return { ...agg, [key]: val }; - }, {}); - } - else { - throw new Error("Unexpected tag: " + JSON.stringify(schema)); - } -} -/** - * Convert value from its typescript representation to representation in aqua - * @param value {JSONValue} the value as represented in typescript - * @param schema {NonArrowSimpleType} - definition of the aqua type - * @returns {JSONValue} represented in aqua - */ -export function ts2aqua(value, schema) { - if (schema.tag === "nil") { - return null; - } - else if (schema.tag === "option") { - return value == null ? [] : [ts2aqua(value, schema.type)]; - } - else if (schema.tag === "scalar" || - schema.tag === "bottomType" || - schema.tag === "topType") { - return value; - } - else if (schema.tag === "array") { - if (!Array.isArray(value)) { - throw new Error("Bad schema"); - } - return value.map((y) => { - return ts2aqua(y, schema.type); - }); - } - else if (schema.tag === "unlabeledProduct") { - if (!Array.isArray(value)) { - throw new Error("Bad schema"); - } - return value.map((y, i) => { - return ts2aqua(y, schema.items[i]); - }); - } - else if (schema.tag === "struct" || schema.tag === "labeledProduct") { - if (typeof value !== "object" || value == null || Array.isArray(value)) { - throw new Error("Bad schema"); - } - return Object.entries(schema.fields).reduce((agg, [key, type]) => { - const val = ts2aqua(value[key], type); - return { ...agg, [key]: val }; - }, {}); - } - else { - throw new Error("Unexpected tag: " + JSON.stringify(schema)); - } -} - - // Functions export const test_script = ` diff --git a/packages/@tests/aqua/src/_aqua/smoke_test.ts b/packages/@tests/aqua/src/_aqua/smoke_test.ts index 90383dc6..e63f3a69 100644 --- a/packages/@tests/aqua/src/_aqua/smoke_test.ts +++ b/packages/@tests/aqua/src/_aqua/smoke_test.ts @@ -17,114 +17,6 @@ import { FluencePeer as FluencePeer$$ } from '@fluencelabs/js-client'; -/** - * @typedef {import("@fluencelabs/js-client").NonArrowSimpleType} NonArrowSimpleType - * @typedef {import("@fluencelabs/js-client").JSONValue} JSONValue - */ -/** - * Convert value from its representation in aqua language to representation in typescript - * @param {JSONValue} value - value as represented in aqua - * @param {NonArrowSimpleType} schema - definition of the aqua schema - * @returns {JSONValue} value represented in typescript - */ -export function aqua2ts(value, schema) { - if (schema.tag === "nil") { - return null; - } - else if (schema.tag === "option") { - if (!Array.isArray(value)) { - throw new Error("Bad schema"); - } - if (value.length === 0) { - return null; - } - else { - return aqua2ts(value[0], schema.type); - } - } - else if (schema.tag === "scalar" || - schema.tag === "bottomType" || - schema.tag === "topType") { - return value; - } - else if (schema.tag === "array") { - if (!Array.isArray(value)) { - throw new Error("Bad schema"); - } - return value.map((y) => { - return aqua2ts(y, schema.type); - }); - } - else if (schema.tag === "unlabeledProduct") { - if (!Array.isArray(value)) { - throw new Error("Bad schema"); - } - return value.map((y, i) => { - return aqua2ts(y, schema.items[i]); - }); - } - else if (schema.tag === "struct" || schema.tag === "labeledProduct") { - if (typeof value !== "object" || value == null || Array.isArray(value)) { - throw new Error("Bad schema"); - } - return Object.entries(schema.fields).reduce((agg, [key, type]) => { - const val = aqua2ts(value[key], type); - return { ...agg, [key]: val }; - }, {}); - } - else { - throw new Error("Unexpected tag: " + JSON.stringify(schema)); - } -} -/** - * Convert value from its typescript representation to representation in aqua - * @param value {JSONValue} the value as represented in typescript - * @param schema {NonArrowSimpleType} - definition of the aqua type - * @returns {JSONValue} represented in aqua - */ -export function ts2aqua(value, schema) { - if (schema.tag === "nil") { - return null; - } - else if (schema.tag === "option") { - return value == null ? [] : [ts2aqua(value, schema.type)]; - } - else if (schema.tag === "scalar" || - schema.tag === "bottomType" || - schema.tag === "topType") { - return value; - } - else if (schema.tag === "array") { - if (!Array.isArray(value)) { - throw new Error("Bad schema"); - } - return value.map((y) => { - return ts2aqua(y, schema.type); - }); - } - else if (schema.tag === "unlabeledProduct") { - if (!Array.isArray(value)) { - throw new Error("Bad schema"); - } - return value.map((y, i) => { - return ts2aqua(y, schema.items[i]); - }); - } - else if (schema.tag === "struct" || schema.tag === "labeledProduct") { - if (typeof value !== "object" || value == null || Array.isArray(value)) { - throw new Error("Bad schema"); - } - return Object.entries(schema.fields).reduce((agg, [key, type]) => { - const val = ts2aqua(value[key], type); - return { ...agg, [key]: val }; - }, {}); - } - else { - throw new Error("Unexpected tag: " + JSON.stringify(schema)); - } -} - - // Services export interface SrvDef { create: (wasm_b64_content: string, callParams: ParticleContext$$) => { error: string | null; service_id: string | null; success: boolean; } | Promise<{ error: string | null; service_id: string | null; success: boolean; }>; diff --git a/packages/core/js-client/src/compilerSupport/callFunction.ts b/packages/core/js-client/src/compilerSupport/callFunction.ts index dcc164ce..acefb8fc 100644 --- a/packages/core/js-client/src/compilerSupport/callFunction.ts +++ b/packages/core/js-client/src/compilerSupport/callFunction.ts @@ -91,7 +91,7 @@ export const callAquaFunction = async ({ registerParticleScopeService(peer, particle, service); } - if (fireAndForget) { + if (!fireAndForget) { registerParticleScopeService(peer, particle, responseService(resolve)); }