Update compiler

This commit is contained in:
Akim Mamedov 2023-11-19 00:33:39 +07:00
parent 327375fcbe
commit f8650dbe23
9 changed files with 391 additions and 1824 deletions

View File

@ -20,11 +20,11 @@
"base64-js": "1.5.1"
},
"devDependencies": {
"@fluencelabs/aqua-api": "0.12.2",
"@fluencelabs/aqua-api": "0.12.4-main-cee4448-2196-1",
"@fluencelabs/aqua-lib": "0.6.0",
"@fluencelabs/aqua-to-js": "workspace:*",
"@fluencelabs/js-client": "workspace:*",
"@fluencelabs/registry": "0.8.7",
"@fluencelabs/registry": "0.8.8-1",
"@fluencelabs/trust-graph": "3.1.2",
"ts-node": "10.9.1"
}

View File

@ -3,7 +3,7 @@
/**
*
* This file is generated using:
* @fluencelabs/aqua-api version: 0.12.0
* @fluencelabs/aqua-api version: 0.12.4-main-cee4448-2196-1
* @fluencelabs/aqua-to-js version: 0.2.0
* If you find any bugs in generated AIR, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
* If you find any bugs in generated JS/TS, please write an issue on GitHub: https://github.com/fluencelabs/js-client/issues
@ -14,30 +14,32 @@ import type { IFluenceClient as IFluenceClient$$, ParticleContext as ParticleCon
// Making aliases to reduce chance of accidental name collision
import {
v5_callFunction as callFunction$$,
v5_registerService as registerService$$,
FluencePeer as FluencePeer$$
v5_registerService as registerService$$
} from '@fluencelabs/js-client';
// Functions
export const test_script = `
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(xor
(xor
(call -relay- ("op" "noop") [])
(fail %last_error%)
(xor
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(xor
(call -relay- ("op" "noop") [])
(fail :error:)
)
)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 0])
(call %init_peer_id% ("callbackSrv" "response") [])
)
(call %init_peer_id% ("errorHandlingSrv" "error") [:error: 0])
)
`;
export type testParams = [config?: {ttl?: number}] | [peer: IFluenceClient$$, config?: {ttl?: number}];
export type TestParams = [config?: {ttl?: number}] | [peer: IFluenceClient$$, config?: {ttl?: number}];
export type TestResult = Promise<void>;
export function test(...args: testParams): TestResult {
export function test(...args: TestParams): TestResult {
return callFunction$$(
args,
{

View File

@ -3,7 +3,7 @@
/**
*
* This file is generated using:
* @fluencelabs/aqua-api version: 0.12.0
* @fluencelabs/aqua-api version: 0.12.4-main-cee4448-2196-1
* @fluencelabs/aqua-to-js version: 0.2.0
* If you find any bugs in generated AIR, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
* If you find any bugs in generated JS/TS, please write an issue on GitHub: https://github.com/fluencelabs/js-client/issues
@ -14,8 +14,7 @@ import type { IFluenceClient as IFluenceClient$$, ParticleContext as ParticleCon
// Making aliases to reduce chance of accidental name collision
import {
v5_callFunction as callFunction$$,
v5_registerService as registerService$$,
FluencePeer as FluencePeer$$
v5_registerService as registerService$$
} from '@fluencelabs/js-client';
// Services
@ -321,14 +320,14 @@ export function registerHelloWorld(...args: any[]) {
// Functions
export const resourceTest_script = `
(seq
(xor
(seq
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "label") [] -label-arg-)
)
(xor
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "label") [] -label-arg-)
)
(new $resource_id
(seq
(seq
@ -340,193 +339,327 @@ export const resourceTest_script = `
(call -relay- ("registry" "get_key_bytes") [-label-arg- [] ret [] ""] ret-0)
(xor
(call %init_peer_id% ("sig" "sign") [ret-0] ret-1)
(fail %last_error%)
(fail :error:)
)
)
(xor
(match ret-1.$.success false
(ap ret-1.$.error.[0] $error)
)
(new $successful
(seq
(seq
(seq
(seq
(seq
(seq
(ap ret-1.$.signature ret-1_flat)
(call -relay- ("registry" "get_key_id") [-label-arg- %init_peer_id%] ret-2)
)
(call -relay- ("op" "string_to_b58") [ret-2] ret-3)
)
(call -relay- ("kad" "neighborhood") [ret-3 [] []] ret-4)
)
(par
(fold ret-4 n-0
(par
(xor
(xor
(seq
(seq
(seq
(call n-0 ("peer" "timestamp_sec") [] ret-5)
(call n-0 ("trust-graph" "get_weight") [%init_peer_id% ret-5] ret-6)
)
(call n-0 ("registry" "register_key") [-label-arg- [] ret [] "" ret-1_flat.$.[0] ret-6 ret-5] ret-7)
)
(xor
(seq
(match ret-7.$.success true
(ap true $successful)
)
(new $-ephemeral-stream-
(new #-ephemeral-canon-
(canon -relay- $-ephemeral-stream- #-ephemeral-canon-)
)
)
)
(seq
(ap ret-7.$.error $error)
(new $-ephemeral-stream-
(new #-ephemeral-canon-
(canon -relay- $-ephemeral-stream- #-ephemeral-canon-)
)
)
)
)
)
(null)
)
(fail %last_error%)
)
(next n-0)
)
(never)
)
(null)
)
(new -if-else-error-
(new -else-error-
(new -if-error-
(xor
(match ret-1.$.success false
(ap ret-1.$.error.[0] $error)
)
(new $status
(new $result-1
(seq
(seq
(seq
(par
(seq
(seq
(seq
(call -relay- ("math" "sub") [1 1] sub)
(new $successful_test
(seq
(seq
(seq
(call -relay- ("math" "add") [sub 1] successful_incr)
(fold $successful successful_fold_var
(seq
(seq
(ap successful_fold_var $successful_test)
(canon -relay- $successful_test #successful_iter_canon)
)
(xor
(match #successful_iter_canon.length successful_incr
(null)
)
(next successful_fold_var)
)
)
(never)
)
)
(canon -relay- $successful_test #successful_result_canon)
)
(ap #successful_result_canon successful_gate)
)
)
)
(call -relay- ("math" "sub") [1 1] sub-0)
)
(ap "ok" $status)
)
(seq
(call -relay- ("peer" "timeout") [6000 "timeout"] ret-8)
(ap ret-8 $status)
)
)
(new $status_test
(seq
(seq
(seq
(call -relay- ("math" "add") [0 1] status_incr)
(fold $status status_fold_var
(seq
(seq
(ap status_fold_var $status_test)
(canon -relay- $status_test #status_iter_canon)
)
(xor
(match #status_iter_canon.length status_incr
(null)
)
(next status_fold_var)
)
)
(never)
)
)
(canon -relay- $status_test #status_result_canon)
)
(ap #status_result_canon status_gate)
)
)
)
(xor
(match status_gate.$.[0] "ok"
(ap true $result-1)
)
(ap false $result-1)
)
)
(new $result-1_test
(seq
(ap :error: -if-error-)
(xor
(match :error:.$.error_code 10001
(new $successful
(seq
(seq
(seq
(call -relay- ("math" "add") [0 1] result-1_incr)
(fold $result-1 result-1_fold_var
(seq
(seq
(seq
(ap result-1_fold_var $result-1_test)
(canon -relay- $result-1_test #result-1_iter_canon)
)
(xor
(match #result-1_iter_canon.length result-1_incr
(null)
)
(next result-1_fold_var)
(ap ret-1.$.signature ret-1_flat)
(call -relay- ("registry" "get_key_id") [-label-arg- %init_peer_id%] ret-2)
)
(call -relay- ("op" "string_to_b58") [ret-2] ret-3)
)
(call -relay- ("kad" "neighborhood") [ret-3 [] []] ret-4)
)
(par
(fold ret-4 n-0
(par
(xor
(xor
(seq
(seq
(seq
(call n-0 ("peer" "timestamp_sec") [] ret-5)
(call n-0 ("trust-graph" "get_weight") [%init_peer_id% ret-5] ret-6)
)
(call n-0 ("registry" "register_key") [-label-arg- [] ret [] "" ret-1_flat.$.[0] ret-6 ret-5] ret-7)
)
(new -if-else-error-
(new -else-error-
(new -if-error-
(xor
(seq
(match ret-7.$.success true
(ap true $successful)
)
(new $-ephemeral-stream-
(new #-ephemeral-canon-
(canon -relay- $-ephemeral-stream- #-ephemeral-canon-)
)
)
)
(seq
(ap :error: -if-error-)
(xor
(seq
(match :error:.$.error_code 10001
(ap ret-7.$.error $error)
)
(new $-ephemeral-stream-
(new #-ephemeral-canon-
(canon -relay- $-ephemeral-stream- #-ephemeral-canon-)
)
)
)
(seq
(seq
(seq
(ap :error: -else-error-)
(xor
(seq
(match :error:.$.error_code 10001
(ap -if-error- -if-else-error-)
)
(new $-ephemeral-stream-
(new #-ephemeral-canon-
(canon -relay- $-ephemeral-stream- #-ephemeral-canon-)
)
)
)
(seq
(ap -else-error- -if-else-error-)
(new $-ephemeral-stream-
(new #-ephemeral-canon-
(canon -relay- $-ephemeral-stream- #-ephemeral-canon-)
)
)
)
)
)
(fail -if-else-error-)
)
(new $-ephemeral-stream-
(new #-ephemeral-canon-
(canon -relay- $-ephemeral-stream- #-ephemeral-canon-)
)
)
)
)
)
)
)
)
)
)
(null)
)
(fail :error:)
)
(next n-0)
)
(never)
)
(null)
)
)
(new $status
(new $result-1
(seq
(seq
(seq
(par
(seq
(new $successful_test
(seq
(seq
(fold $successful successful_fold_var
(seq
(seq
(ap successful_fold_var $successful_test)
(canon -relay- $successful_test #successful_iter_canon)
)
(xor
(match #successful_iter_canon.length 1
(null)
)
(next successful_fold_var)
)
)
(never)
)
(canon -relay- $successful_test #successful_result_canon)
)
(ap #successful_result_canon successful_gate)
)
)
(ap "ok" $status)
)
(seq
(call -relay- ("peer" "timeout") [6000 "timeout"] ret-8)
(ap ret-8 $status)
)
)
(new $status_test
(seq
(seq
(fold $status status_fold_var
(seq
(seq
(ap status_fold_var $status_test)
(canon -relay- $status_test #status_iter_canon)
)
(xor
(match #status_iter_canon.length 1
(null)
)
(next status_fold_var)
)
)
(never)
)
(canon -relay- $status_test #status_result_canon)
)
(ap #status_result_canon status_gate)
)
)
)
(new -if-else-error-
(new -else-error-
(new -if-error-
(xor
(match status_gate.$.[0] "ok"
(ap true $result-1)
)
(seq
(ap :error: -if-error-)
(xor
(match :error:.$.error_code 10001
(ap false $result-1)
)
(seq
(seq
(ap :error: -else-error-)
(xor
(match :error:.$.error_code 10001
(ap -if-error- -if-else-error-)
)
(ap -else-error- -if-else-error-)
)
)
(fail -if-else-error-)
)
)
)
)
)
)
)
)
(new $result-1_test
(seq
(seq
(fold $result-1 result-1_fold_var
(seq
(seq
(ap result-1_fold_var $result-1_test)
(canon -relay- $result-1_test #result-1_iter_canon)
)
(xor
(match #result-1_iter_canon.length 1
(null)
)
(next result-1_fold_var)
)
)
(never)
)
(canon -relay- $result-1_test #result-1_result_canon)
)
(ap #result-1_result_canon result-1_gate)
)
)
)
)
)
)
(new -if-else-error-
(new -else-error-
(new -if-error-
(xor
(match result-1_gate.$.[0] false
(ap "resource wasn't created: timeout exceeded" $error)
)
(seq
(ap :error: -if-error-)
(xor
(match :error:.$.error_code 10001
(ap ret-2 $resource_id)
)
(seq
(seq
(ap :error: -else-error-)
(xor
(seq
(match :error:.$.error_code 10001
(ap -if-error- -if-else-error-)
)
(new $-ephemeral-stream-
(new #-ephemeral-canon-
(canon -relay- $-ephemeral-stream- #-ephemeral-canon-)
)
)
)
(seq
(ap -else-error- -if-else-error-)
(new $-ephemeral-stream-
(new #-ephemeral-canon-
(canon -relay- $-ephemeral-stream- #-ephemeral-canon-)
)
)
)
)
)
(fail -if-else-error-)
)
)
)
)
(never)
)
)
(canon -relay- $result-1_test #result-1_result_canon)
)
(ap #result-1_result_canon result-1_gate)
)
)
)
(seq
(seq
(ap :error: -else-error-)
(xor
(seq
(match :error:.$.error_code 10001
(ap -if-error- -if-else-error-)
)
(new $-ephemeral-stream-
(new #-ephemeral-canon-
(canon -relay- $-ephemeral-stream- #-ephemeral-canon-)
)
)
)
(seq
(ap -else-error- -if-else-error-)
(new $-ephemeral-stream-
(new #-ephemeral-canon-
(canon -relay- $-ephemeral-stream- #-ephemeral-canon-)
)
)
)
)
)
(fail -if-else-error-)
)
)
)
)
(xor
(match result-1_gate.$.[0] false
(ap "resource wasn't created: timeout exceeded" $error)
)
(ap ret-2 $resource_id)
)
)
)
)
)
(fail %last_error%)
(fail :error:)
)
)
(canon %init_peer_id% $resource_id #-resource_id-fix-0)
@ -534,22 +667,22 @@ export const resourceTest_script = `
(ap #-resource_id-fix-0 -resource_id-flat-0)
)
)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 0])
)
(canon %init_peer_id% $error #error_canon)
)
(canon %init_peer_id% $error #error_canon)
(call %init_peer_id% ("callbackSrv" "response") [-resource_id-flat-0 #error_canon])
)
(call %init_peer_id% ("callbackSrv" "response") [-resource_id-flat-0 #error_canon])
(call %init_peer_id% ("errorHandlingSrv" "error") [:error: 0])
)
`;
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 function resourceTest(...args: resourceTestParams): ResourceTestResult {
export function resourceTest(...args: ResourceTestParams): ResourceTestResult {
return callFunction$$(
args,
{
@ -600,23 +733,23 @@ export function resourceTest(...args: resourceTestParams): ResourceTestResult {
}
export const helloTest_script = `
(seq
(xor
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(xor
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("hello-world" "hello") ["Fluence user"] ret)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 0])
)
(call %init_peer_id% ("callbackSrv" "response") [ret])
)
(call %init_peer_id% ("callbackSrv" "response") [ret])
(call %init_peer_id% ("errorHandlingSrv" "error") [:error: 0])
)
`;
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 function helloTest(...args: helloTestParams): HelloTestResult {
export function helloTest(...args: HelloTestParams): HelloTestResult {
return callFunction$$(
args,
{
@ -652,35 +785,35 @@ export function helloTest(...args: helloTestParams): HelloTestResult {
}
export const callHappy_script = `
(seq
(xor
(seq
(seq
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "a") [] -a-arg-)
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "a") [] -a-arg-)
)
(call %init_peer_id% ("getDataSrv" "b") [] -b-arg-)
)
(call %init_peer_id% ("getDataSrv" "b") [] -b-arg-)
(call %init_peer_id% ("getDataSrv" "c") [] -c-arg-)
)
(call %init_peer_id% ("getDataSrv" "c") [] -c-arg-)
)
(xor
(xor
(call %init_peer_id% ("callbackSrv" "d") ["abc"] init_call_res0)
(fail %last_error%)
(fail :error:)
)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 0])
)
(call %init_peer_id% ("callbackSrv" "response") [init_call_res0])
)
(call %init_peer_id% ("callbackSrv" "response") [init_call_res0])
(call %init_peer_id% ("errorHandlingSrv" "error") [:error: 0])
)
`;
export type callHappyParams = [a: string, b: number, c: number, d: (arg0: string, callParams: ParticleContext$$) => number | Promise<number>, config?: {ttl?: number}] | [peer: IFluenceClient$$, a: string, b: number, c: number, d: (arg0: string, callParams: ParticleContext$$) => number | Promise<number>, config?: {ttl?: number}];
export type CallHappyParams = [a: string, b: number, c: number, d: (arg0: string, callParams: ParticleContext$$) => number | Promise<number>, config?: {ttl?: number}] | [peer: IFluenceClient$$, a: string, b: number, c: number, d: (arg0: string, callParams: ParticleContext$$) => number | Promise<number>, config?: {ttl?: number}];
export type CallHappyResult = Promise<number>;
export function callHappy(...args: callHappyParams): CallHappyResult {
export function callHappy(...args: CallHappyParams): CallHappyResult {
return callFunction$$(
args,
{
@ -750,41 +883,41 @@ export function callHappy(...args: callHappyParams): CallHappyResult {
}
export const demo_calculation_script = `
(seq
(xor
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "service_id") [] -service_id-arg-)
)
(xor
(seq
(seq
(seq
(seq
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "service_id") [] -service_id-arg-)
)
(call %init_peer_id% (-service_id-arg- "test_logs") [])
(call %init_peer_id% (-service_id-arg- "add") [10] ret)
)
(call %init_peer_id% (-service_id-arg- "multiply") [5] ret-0)
(call %init_peer_id% (-service_id-arg- "add") [10] ret)
)
(call %init_peer_id% (-service_id-arg- "subtract") [8] ret-1)
(call %init_peer_id% (-service_id-arg- "multiply") [5] ret-0)
)
(call %init_peer_id% (-service_id-arg- "divide") [6] ret-2)
(call %init_peer_id% (-service_id-arg- "subtract") [8] ret-1)
)
(call %init_peer_id% (-service_id-arg- "state") [] ret-3)
(call %init_peer_id% (-service_id-arg- "divide") [6] ret-2)
)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 0])
(call %init_peer_id% (-service_id-arg- "state") [] ret-3)
)
(call %init_peer_id% ("callbackSrv" "response") [ret-3])
)
(call %init_peer_id% ("callbackSrv" "response") [ret-3])
(call %init_peer_id% ("errorHandlingSrv" "error") [:error: 0])
)
`;
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 function demo_calculation(...args: demo_calculationParams): Demo_calculationResult {
export function demo_calculation(...args: Demo_calculationParams): Demo_calculationResult {
return callFunction$$(
args,
{
@ -825,44 +958,44 @@ export function demo_calculation(...args: demo_calculationParams): Demo_calculat
}
export const marineTest_script = `
(seq
(xor
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "wasm64") [] -wasm64-arg-)
)
(xor
(seq
(seq
(seq
(seq
(seq
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "wasm64") [] -wasm64-arg-)
)
(call %init_peer_id% ("single_module_srv" "create") [-wasm64-arg-] ret)
(call %init_peer_id% (ret.$.service_id.[0] "test_logs") [])
)
(call %init_peer_id% (ret.$.service_id.[0] "add") [10] ret-0)
(call %init_peer_id% (ret.$.service_id.[0] "test_logs") [])
)
(call %init_peer_id% (ret.$.service_id.[0] "multiply") [5] ret-1)
(call %init_peer_id% (ret.$.service_id.[0] "add") [10] ret-0)
)
(call %init_peer_id% (ret.$.service_id.[0] "subtract") [8] ret-2)
(call %init_peer_id% (ret.$.service_id.[0] "multiply") [5] ret-1)
)
(call %init_peer_id% (ret.$.service_id.[0] "divide") [6] ret-3)
(call %init_peer_id% (ret.$.service_id.[0] "subtract") [8] ret-2)
)
(call %init_peer_id% (ret.$.service_id.[0] "state") [] ret-4)
(call %init_peer_id% (ret.$.service_id.[0] "divide") [6] ret-3)
)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 0])
(call %init_peer_id% (ret.$.service_id.[0] "state") [] ret-4)
)
(call %init_peer_id% ("callbackSrv" "response") [ret-4])
)
(call %init_peer_id% ("callbackSrv" "response") [ret-4])
(call %init_peer_id% ("errorHandlingSrv" "error") [:error: 0])
)
`;
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>;
export function marineTest(...args: marineTestParams): MarineTestResult {
export function marineTest(...args: MarineTestParams): MarineTestResult {
return callFunction$$(
args,
{

View File

@ -18,7 +18,7 @@
"ts-pattern": "5.0.5"
},
"devDependencies": {
"@fluencelabs/aqua-api": "0.12.0",
"@fluencelabs/aqua-api": "0.12.4-main-cee4448-2196-1",
"@fluencelabs/aqua-lib": "0.7.3",
"@fluencelabs/interfaces": "workspace:*",
"@fluencelabs/js-client": "workspace:^",

View File

@ -17,51 +17,4 @@ import {
v5_registerService as registerService$$
} from '@fluencelabs/js-client';
// 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; }>;
list: (callParams: ParticleContext$$) => string[] | Promise<string[]>;
remove: (service_id: string, callParams: ParticleContext$$) => { error: string | null; success: boolean; } | Promise<{ error: string | null; success: boolean; }>;
}
export function registerSrv(service: SrvDef): void;
export function registerSrv(serviceId: string, service: SrvDef): void;
export function registerSrv(peer: IFluenceClient$$, service: SrvDef): void;
export function registerSrv(peer: IFluenceClient$$, serviceId: string, service: SrvDef): void;
export interface CalcServiceDef {
add: (num: number, callParams: ParticleContext$$) => number | Promise<number>;
clear_state: (callParams: ParticleContext$$) => void | Promise<void>;
divide: (num: number, callParams: ParticleContext$$) => number | Promise<number>;
multiply: (num: number, callParams: ParticleContext$$) => number | Promise<number>;
state: (callParams: ParticleContext$$) => number | Promise<number>;
subtract: (num: number, callParams: ParticleContext$$) => number | Promise<number>;
test_logs: (callParams: ParticleContext$$) => void | Promise<void>;
}
export function registerCalcService(serviceId: string, service: CalcServiceDef): void;
export function registerCalcService(peer: IFluenceClient$$, serviceId: string, service: CalcServiceDef): void;
export interface HelloWorldDef {
hello: (str: string, callParams: ParticleContext$$) => string | Promise<string>;
}
export function registerHelloWorld(service: HelloWorldDef): void;
export function registerHelloWorld(serviceId: string, service: HelloWorldDef): void;
export function registerHelloWorld(peer: IFluenceClient$$, service: HelloWorldDef): void;
export function registerHelloWorld(peer: IFluenceClient$$, serviceId: string, service: HelloWorldDef): void;
// Functions
export type ResourceTestResultType = [string | null, string[]]
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 HelloTestResult = Promise<string>;
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 MarineTestResult = Promise<number>;

View File

@ -17,747 +17,4 @@ import {
v5_registerService as registerService$$
} from '@fluencelabs/js-client';
// Services
export function registerSrv(...args) {
registerService$$(
args,
{
"defaultServiceId": "single_module_srv",
"functions": {
"fields": {
"create": {
"domain": {
"fields": {
"wasm_b64_content": {
"name": "string",
"tag": "scalar"
}
},
"tag": "labeledProduct"
},
"codomain": {
"items": [
{
"name": "ServiceCreationResult",
"fields": {
"error": {
"type": {
"name": "string",
"tag": "scalar"
},
"tag": "option"
},
"service_id": {
"type": {
"name": "string",
"tag": "scalar"
},
"tag": "option"
},
"success": {
"name": "bool",
"tag": "scalar"
}
},
"tag": "struct"
}
],
"tag": "unlabeledProduct"
},
"tag": "arrow"
},
"list": {
"domain": {
"tag": "nil"
},
"codomain": {
"items": [
{
"type": {
"name": "string",
"tag": "scalar"
},
"tag": "array"
}
],
"tag": "unlabeledProduct"
},
"tag": "arrow"
},
"remove": {
"domain": {
"fields": {
"service_id": {
"name": "string",
"tag": "scalar"
}
},
"tag": "labeledProduct"
},
"codomain": {
"items": [
{
"name": "RemoveResult",
"fields": {
"error": {
"type": {
"name": "string",
"tag": "scalar"
},
"tag": "option"
},
"success": {
"name": "bool",
"tag": "scalar"
}
},
"tag": "struct"
}
],
"tag": "unlabeledProduct"
},
"tag": "arrow"
}
},
"tag": "labeledProduct"
}
}
);
}
export function registerCalcService(...args) {
registerService$$(
args,
{
"functions": {
"fields": {
"add": {
"domain": {
"fields": {
"num": {
"name": "f64",
"tag": "scalar"
}
},
"tag": "labeledProduct"
},
"codomain": {
"items": [
{
"name": "f64",
"tag": "scalar"
}
],
"tag": "unlabeledProduct"
},
"tag": "arrow"
},
"clear_state": {
"domain": {
"tag": "nil"
},
"codomain": {
"tag": "nil"
},
"tag": "arrow"
},
"divide": {
"domain": {
"fields": {
"num": {
"name": "f64",
"tag": "scalar"
}
},
"tag": "labeledProduct"
},
"codomain": {
"items": [
{
"name": "f64",
"tag": "scalar"
}
],
"tag": "unlabeledProduct"
},
"tag": "arrow"
},
"multiply": {
"domain": {
"fields": {
"num": {
"name": "f64",
"tag": "scalar"
}
},
"tag": "labeledProduct"
},
"codomain": {
"items": [
{
"name": "f64",
"tag": "scalar"
}
],
"tag": "unlabeledProduct"
},
"tag": "arrow"
},
"state": {
"domain": {
"tag": "nil"
},
"codomain": {
"items": [
{
"name": "f64",
"tag": "scalar"
}
],
"tag": "unlabeledProduct"
},
"tag": "arrow"
},
"subtract": {
"domain": {
"fields": {
"num": {
"name": "f64",
"tag": "scalar"
}
},
"tag": "labeledProduct"
},
"codomain": {
"items": [
{
"name": "f64",
"tag": "scalar"
}
],
"tag": "unlabeledProduct"
},
"tag": "arrow"
},
"test_logs": {
"domain": {
"tag": "nil"
},
"codomain": {
"tag": "nil"
},
"tag": "arrow"
}
},
"tag": "labeledProduct"
}
}
);
}
export function registerHelloWorld(...args) {
registerService$$(
args,
{
"defaultServiceId": "hello-world",
"functions": {
"fields": {
"hello": {
"domain": {
"fields": {
"str": {
"name": "string",
"tag": "scalar"
}
},
"tag": "labeledProduct"
},
"codomain": {
"items": [
{
"name": "string",
"tag": "scalar"
}
],
"tag": "unlabeledProduct"
},
"tag": "arrow"
}
},
"tag": "labeledProduct"
}
}
);
}
// Functions
export const resourceTest_script = `
(seq
(seq
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "label") [] label)
)
(xor
(new $resource_id
(seq
(seq
(seq
(call %init_peer_id% ("peer" "timestamp_sec") [] t)
(xor
(seq
(seq
(call -relay- ("registry" "get_key_bytes") [label [] t [] ""] bytes)
(xor
(call %init_peer_id% ("sig" "sign") [bytes] result)
(fail %last_error%)
)
)
(xor
(match result.$.success false
(ap result.$.error.[0] $error)
)
(new $successful
(seq
(seq
(seq
(seq
(seq
(seq
(ap result.$.signature result_flat)
(call -relay- ("registry" "get_key_id") [label %init_peer_id%] id)
)
(call -relay- ("op" "string_to_b58") [id] k)
)
(call -relay- ("kad" "neighborhood") [k [] []] nodes)
)
(par
(fold nodes n-0
(par
(xor
(xor
(seq
(seq
(seq
(call n-0 ("peer" "timestamp_sec") [] t-0)
(call n-0 ("trust-graph" "get_weight") [%init_peer_id% t-0] weight)
)
(call n-0 ("registry" "register_key") [label [] t [] "" result_flat.$.[0] weight t-0] result-0)
)
(xor
(seq
(match result-0.$.success true
(ap true $successful)
)
(new $-ephemeral-stream-
(new #-ephemeral-canon-
(canon -relay- $-ephemeral-stream- #-ephemeral-canon-)
)
)
)
(seq
(ap result-0.$.error $error)
(new $-ephemeral-stream-
(new #-ephemeral-canon-
(canon -relay- $-ephemeral-stream- #-ephemeral-canon-)
)
)
)
)
)
(null)
)
(fail %last_error%)
)
(next n-0)
)
(never)
)
(null)
)
)
(new $status
(new $result-1
(seq
(seq
(seq
(par
(seq
(seq
(seq
(call -relay- ("math" "sub") [1 1] sub)
(new $successful_test
(seq
(seq
(seq
(call -relay- ("math" "add") [sub 1] successful_incr)
(fold $successful successful_fold_var
(seq
(seq
(ap successful_fold_var $successful_test)
(canon -relay- $successful_test #successful_iter_canon)
)
(xor
(match #successful_iter_canon.length successful_incr
(null)
)
(next successful_fold_var)
)
)
(never)
)
)
(canon -relay- $successful_test #successful_result_canon)
)
(ap #successful_result_canon successful_gate)
)
)
)
(call -relay- ("math" "sub") [1 1] sub-0)
)
(ap "ok" $status)
)
(call -relay- ("peer" "timeout") [6000 "timeout"] $status)
)
(new $status_test
(seq
(seq
(seq
(call -relay- ("math" "add") [0 1] status_incr)
(fold $status status_fold_var
(seq
(seq
(ap status_fold_var $status_test)
(canon -relay- $status_test #status_iter_canon)
)
(xor
(match #status_iter_canon.length status_incr
(null)
)
(next status_fold_var)
)
)
(never)
)
)
(canon -relay- $status_test #status_result_canon)
)
(ap #status_result_canon status_gate)
)
)
)
(xor
(match status_gate.$.[0] "ok"
(ap true $result-1)
)
(ap false $result-1)
)
)
(new $result-1_test
(seq
(seq
(seq
(call -relay- ("math" "add") [0 1] result-1_incr)
(fold $result-1 result-1_fold_var
(seq
(seq
(ap result-1_fold_var $result-1_test)
(canon -relay- $result-1_test #result-1_iter_canon)
)
(xor
(match #result-1_iter_canon.length result-1_incr
(null)
)
(next result-1_fold_var)
)
)
(never)
)
)
(canon -relay- $result-1_test #result-1_result_canon)
)
(ap #result-1_result_canon result-1_gate)
)
)
)
)
)
)
(xor
(match result-1_gate.$.[0] false
(ap "resource wasn't created: timeout exceeded" $error)
)
(ap id $resource_id)
)
)
)
)
)
(fail %last_error%)
)
)
(canon %init_peer_id% $resource_id #-resource_id-fix-0)
)
(ap #-resource_id-fix-0 -resource_id-flat-0)
)
)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 0])
)
)
(canon %init_peer_id% $error #error_canon)
)
(call %init_peer_id% ("callbackSrv" "response") [-resource_id-flat-0 #error_canon])
)
`;
export function resourceTest(...args) {
return callFunction$$(
args,
{
"functionName": "resourceTest",
"arrow": {
"domain": {
"fields": {
"label": {
"name": "string",
"tag": "scalar"
}
},
"tag": "labeledProduct"
},
"codomain": {
"items": [
{
"type": {
"name": "string",
"tag": "scalar"
},
"tag": "option"
},
{
"type": {
"name": "string",
"tag": "scalar"
},
"tag": "array"
}
],
"tag": "unlabeledProduct"
},
"tag": "arrow"
},
"names": {
"relay": "-relay-",
"getDataSrv": "getDataSrv",
"callbackSrv": "callbackSrv",
"responseSrv": "callbackSrv",
"responseFnName": "response",
"errorHandlingSrv": "errorHandlingSrv",
"errorFnName": "error"
}
},
resourceTest_script
);
}
export const helloTest_script = `
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(xor
(call %init_peer_id% ("hello-world" "hello") ["Fluence user"] hello)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 0])
)
)
(call %init_peer_id% ("callbackSrv" "response") [hello])
)
`;
export function helloTest(...args) {
return callFunction$$(
args,
{
"functionName": "helloTest",
"arrow": {
"domain": {
"fields": {},
"tag": "labeledProduct"
},
"codomain": {
"items": [
{
"name": "string",
"tag": "scalar"
}
],
"tag": "unlabeledProduct"
},
"tag": "arrow"
},
"names": {
"relay": "-relay-",
"getDataSrv": "getDataSrv",
"callbackSrv": "callbackSrv",
"responseSrv": "callbackSrv",
"responseFnName": "response",
"errorHandlingSrv": "errorHandlingSrv",
"errorFnName": "error"
}
},
helloTest_script
);
}
export const demo_calculation_script = `
(seq
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "service_id") [] service_id)
)
(xor
(seq
(seq
(seq
(seq
(seq
(call %init_peer_id% (service_id "test_logs") [])
(call %init_peer_id% (service_id "add") [10])
)
(call %init_peer_id% (service_id "multiply") [5])
)
(call %init_peer_id% (service_id "subtract") [8])
)
(call %init_peer_id% (service_id "divide") [6])
)
(call %init_peer_id% (service_id "state") [] res)
)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 0])
)
)
(call %init_peer_id% ("callbackSrv" "response") [res])
)
`;
export function demo_calculation(...args) {
return callFunction$$(
args,
{
"functionName": "demo_calculation",
"arrow": {
"domain": {
"fields": {
"service_id": {
"name": "string",
"tag": "scalar"
}
},
"tag": "labeledProduct"
},
"codomain": {
"items": [
{
"name": "f64",
"tag": "scalar"
}
],
"tag": "unlabeledProduct"
},
"tag": "arrow"
},
"names": {
"relay": "-relay-",
"getDataSrv": "getDataSrv",
"callbackSrv": "callbackSrv",
"responseSrv": "callbackSrv",
"responseFnName": "response",
"errorHandlingSrv": "errorHandlingSrv",
"errorFnName": "error"
}
},
demo_calculation_script
);
}
export const marineTest_script = `
(seq
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "wasm64") [] wasm64)
)
(xor
(seq
(seq
(seq
(seq
(seq
(seq
(call %init_peer_id% ("single_module_srv" "create") [wasm64] serviceResult)
(call %init_peer_id% (serviceResult.$.service_id.[0] "test_logs") [])
)
(call %init_peer_id% (serviceResult.$.service_id.[0] "add") [10])
)
(call %init_peer_id% (serviceResult.$.service_id.[0] "multiply") [5])
)
(call %init_peer_id% (serviceResult.$.service_id.[0] "subtract") [8])
)
(call %init_peer_id% (serviceResult.$.service_id.[0] "divide") [6])
)
(call %init_peer_id% (serviceResult.$.service_id.[0] "state") [] res)
)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 0])
)
)
(call %init_peer_id% ("callbackSrv" "response") [res])
)
`;
export function marineTest(...args) {
return callFunction$$(
args,
{
"functionName": "marineTest",
"arrow": {
"domain": {
"fields": {
"wasm64": {
"name": "string",
"tag": "scalar"
}
},
"tag": "labeledProduct"
},
"codomain": {
"items": [
{
"name": "f64",
"tag": "scalar"
}
],
"tag": "unlabeledProduct"
},
"tag": "arrow"
},
"names": {
"relay": "-relay-",
"getDataSrv": "getDataSrv",
"callbackSrv": "callbackSrv",
"responseSrv": "callbackSrv",
"responseFnName": "response",
"errorHandlingSrv": "errorHandlingSrv",
"errorFnName": "error"
}
},
marineTest_script
);
}

View File

@ -17,785 +17,4 @@ import {
v5_registerService as registerService$$
} from '@fluencelabs/js-client';
// 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; }>;
list: (callParams: ParticleContext$$) => string[] | Promise<string[]>;
remove: (service_id: string, callParams: ParticleContext$$) => { error: string | null; success: boolean; } | Promise<{ error: string | null; success: boolean; }>;
}
export function registerSrv(service: SrvDef): void;
export function registerSrv(serviceId: string, service: SrvDef): void;
export function registerSrv(peer: IFluenceClient$$, service: SrvDef): void;
export function registerSrv(peer: IFluenceClient$$, serviceId: string, service: SrvDef): void;
export function registerSrv(...args: any[]) {
registerService$$(
args,
{
"defaultServiceId": "single_module_srv",
"functions": {
"fields": {
"create": {
"domain": {
"fields": {
"wasm_b64_content": {
"name": "string",
"tag": "scalar"
}
},
"tag": "labeledProduct"
},
"codomain": {
"items": [
{
"name": "ServiceCreationResult",
"fields": {
"error": {
"type": {
"name": "string",
"tag": "scalar"
},
"tag": "option"
},
"service_id": {
"type": {
"name": "string",
"tag": "scalar"
},
"tag": "option"
},
"success": {
"name": "bool",
"tag": "scalar"
}
},
"tag": "struct"
}
],
"tag": "unlabeledProduct"
},
"tag": "arrow"
},
"list": {
"domain": {
"tag": "nil"
},
"codomain": {
"items": [
{
"type": {
"name": "string",
"tag": "scalar"
},
"tag": "array"
}
],
"tag": "unlabeledProduct"
},
"tag": "arrow"
},
"remove": {
"domain": {
"fields": {
"service_id": {
"name": "string",
"tag": "scalar"
}
},
"tag": "labeledProduct"
},
"codomain": {
"items": [
{
"name": "RemoveResult",
"fields": {
"error": {
"type": {
"name": "string",
"tag": "scalar"
},
"tag": "option"
},
"success": {
"name": "bool",
"tag": "scalar"
}
},
"tag": "struct"
}
],
"tag": "unlabeledProduct"
},
"tag": "arrow"
}
},
"tag": "labeledProduct"
}
}
);
}
export interface CalcServiceDef {
add: (num: number, callParams: ParticleContext$$) => number | Promise<number>;
clear_state: (callParams: ParticleContext$$) => void | Promise<void>;
divide: (num: number, callParams: ParticleContext$$) => number | Promise<number>;
multiply: (num: number, callParams: ParticleContext$$) => number | Promise<number>;
state: (callParams: ParticleContext$$) => number | Promise<number>;
subtract: (num: number, callParams: ParticleContext$$) => number | Promise<number>;
test_logs: (callParams: ParticleContext$$) => void | Promise<void>;
}
export function registerCalcService(serviceId: string, service: CalcServiceDef): void;
export function registerCalcService(peer: IFluenceClient$$, serviceId: string, service: CalcServiceDef): void;
export function registerCalcService(...args: any[]) {
registerService$$(
args,
{
"functions": {
"fields": {
"add": {
"domain": {
"fields": {
"num": {
"name": "f64",
"tag": "scalar"
}
},
"tag": "labeledProduct"
},
"codomain": {
"items": [
{
"name": "f64",
"tag": "scalar"
}
],
"tag": "unlabeledProduct"
},
"tag": "arrow"
},
"clear_state": {
"domain": {
"tag": "nil"
},
"codomain": {
"tag": "nil"
},
"tag": "arrow"
},
"divide": {
"domain": {
"fields": {
"num": {
"name": "f64",
"tag": "scalar"
}
},
"tag": "labeledProduct"
},
"codomain": {
"items": [
{
"name": "f64",
"tag": "scalar"
}
],
"tag": "unlabeledProduct"
},
"tag": "arrow"
},
"multiply": {
"domain": {
"fields": {
"num": {
"name": "f64",
"tag": "scalar"
}
},
"tag": "labeledProduct"
},
"codomain": {
"items": [
{
"name": "f64",
"tag": "scalar"
}
],
"tag": "unlabeledProduct"
},
"tag": "arrow"
},
"state": {
"domain": {
"tag": "nil"
},
"codomain": {
"items": [
{
"name": "f64",
"tag": "scalar"
}
],
"tag": "unlabeledProduct"
},
"tag": "arrow"
},
"subtract": {
"domain": {
"fields": {
"num": {
"name": "f64",
"tag": "scalar"
}
},
"tag": "labeledProduct"
},
"codomain": {
"items": [
{
"name": "f64",
"tag": "scalar"
}
],
"tag": "unlabeledProduct"
},
"tag": "arrow"
},
"test_logs": {
"domain": {
"tag": "nil"
},
"codomain": {
"tag": "nil"
},
"tag": "arrow"
}
},
"tag": "labeledProduct"
}
}
);
}
export interface HelloWorldDef {
hello: (str: string, callParams: ParticleContext$$) => string | Promise<string>;
}
export function registerHelloWorld(service: HelloWorldDef): void;
export function registerHelloWorld(serviceId: string, service: HelloWorldDef): void;
export function registerHelloWorld(peer: IFluenceClient$$, service: HelloWorldDef): void;
export function registerHelloWorld(peer: IFluenceClient$$, serviceId: string, service: HelloWorldDef): void;
export function registerHelloWorld(...args: any[]) {
registerService$$(
args,
{
"defaultServiceId": "hello-world",
"functions": {
"fields": {
"hello": {
"domain": {
"fields": {
"str": {
"name": "string",
"tag": "scalar"
}
},
"tag": "labeledProduct"
},
"codomain": {
"items": [
{
"name": "string",
"tag": "scalar"
}
],
"tag": "unlabeledProduct"
},
"tag": "arrow"
}
},
"tag": "labeledProduct"
}
}
);
}
// Functions
export const resourceTest_script = `
(seq
(seq
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "label") [] label)
)
(xor
(new $resource_id
(seq
(seq
(seq
(call %init_peer_id% ("peer" "timestamp_sec") [] t)
(xor
(seq
(seq
(call -relay- ("registry" "get_key_bytes") [label [] t [] ""] bytes)
(xor
(call %init_peer_id% ("sig" "sign") [bytes] result)
(fail %last_error%)
)
)
(xor
(match result.$.success false
(ap result.$.error.[0] $error)
)
(new $successful
(seq
(seq
(seq
(seq
(seq
(seq
(ap result.$.signature result_flat)
(call -relay- ("registry" "get_key_id") [label %init_peer_id%] id)
)
(call -relay- ("op" "string_to_b58") [id] k)
)
(call -relay- ("kad" "neighborhood") [k [] []] nodes)
)
(par
(fold nodes n-0
(par
(xor
(xor
(seq
(seq
(seq
(call n-0 ("peer" "timestamp_sec") [] t-0)
(call n-0 ("trust-graph" "get_weight") [%init_peer_id% t-0] weight)
)
(call n-0 ("registry" "register_key") [label [] t [] "" result_flat.$.[0] weight t-0] result-0)
)
(xor
(seq
(match result-0.$.success true
(ap true $successful)
)
(new $-ephemeral-stream-
(new #-ephemeral-canon-
(canon -relay- $-ephemeral-stream- #-ephemeral-canon-)
)
)
)
(seq
(ap result-0.$.error $error)
(new $-ephemeral-stream-
(new #-ephemeral-canon-
(canon -relay- $-ephemeral-stream- #-ephemeral-canon-)
)
)
)
)
)
(null)
)
(fail %last_error%)
)
(next n-0)
)
(never)
)
(null)
)
)
(new $status
(new $result-1
(seq
(seq
(seq
(par
(seq
(seq
(seq
(call -relay- ("math" "sub") [1 1] sub)
(new $successful_test
(seq
(seq
(seq
(call -relay- ("math" "add") [sub 1] successful_incr)
(fold $successful successful_fold_var
(seq
(seq
(ap successful_fold_var $successful_test)
(canon -relay- $successful_test #successful_iter_canon)
)
(xor
(match #successful_iter_canon.length successful_incr
(null)
)
(next successful_fold_var)
)
)
(never)
)
)
(canon -relay- $successful_test #successful_result_canon)
)
(ap #successful_result_canon successful_gate)
)
)
)
(call -relay- ("math" "sub") [1 1] sub-0)
)
(ap "ok" $status)
)
(call -relay- ("peer" "timeout") [6000 "timeout"] $status)
)
(new $status_test
(seq
(seq
(seq
(call -relay- ("math" "add") [0 1] status_incr)
(fold $status status_fold_var
(seq
(seq
(ap status_fold_var $status_test)
(canon -relay- $status_test #status_iter_canon)
)
(xor
(match #status_iter_canon.length status_incr
(null)
)
(next status_fold_var)
)
)
(never)
)
)
(canon -relay- $status_test #status_result_canon)
)
(ap #status_result_canon status_gate)
)
)
)
(xor
(match status_gate.$.[0] "ok"
(ap true $result-1)
)
(ap false $result-1)
)
)
(new $result-1_test
(seq
(seq
(seq
(call -relay- ("math" "add") [0 1] result-1_incr)
(fold $result-1 result-1_fold_var
(seq
(seq
(ap result-1_fold_var $result-1_test)
(canon -relay- $result-1_test #result-1_iter_canon)
)
(xor
(match #result-1_iter_canon.length result-1_incr
(null)
)
(next result-1_fold_var)
)
)
(never)
)
)
(canon -relay- $result-1_test #result-1_result_canon)
)
(ap #result-1_result_canon result-1_gate)
)
)
)
)
)
)
(xor
(match result-1_gate.$.[0] false
(ap "resource wasn't created: timeout exceeded" $error)
)
(ap id $resource_id)
)
)
)
)
)
(fail %last_error%)
)
)
(canon %init_peer_id% $resource_id #-resource_id-fix-0)
)
(ap #-resource_id-fix-0 -resource_id-flat-0)
)
)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 0])
)
)
(canon %init_peer_id% $error #error_canon)
)
(call %init_peer_id% ("callbackSrv" "response") [-resource_id-flat-0 #error_canon])
)
`;
export type ResourceTestResultType = [string | null, string[]]
export type ResourceTestParams = [label: string, config?: {ttl?: number}] | [peer: IFluenceClient$$, label: string, config?: {ttl?: number}];
export type ResourceTestResult = Promise<ResourceTestResultType>;
export function resourceTest(...args: resourceTestParams): ResourceTestResult {
return callFunction$$(
args,
{
"functionName": "resourceTest",
"arrow": {
"domain": {
"fields": {
"label": {
"name": "string",
"tag": "scalar"
}
},
"tag": "labeledProduct"
},
"codomain": {
"items": [
{
"type": {
"name": "string",
"tag": "scalar"
},
"tag": "option"
},
{
"type": {
"name": "string",
"tag": "scalar"
},
"tag": "array"
}
],
"tag": "unlabeledProduct"
},
"tag": "arrow"
},
"names": {
"relay": "-relay-",
"getDataSrv": "getDataSrv",
"callbackSrv": "callbackSrv",
"responseSrv": "callbackSrv",
"responseFnName": "response",
"errorHandlingSrv": "errorHandlingSrv",
"errorFnName": "error"
}
},
resourceTest_script
);
}
export const helloTest_script = `
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(xor
(call %init_peer_id% ("hello-world" "hello") ["Fluence user"] hello)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 0])
)
)
(call %init_peer_id% ("callbackSrv" "response") [hello])
)
`;
export type HelloTestParams = [config?: {ttl?: number}] | [peer: IFluenceClient$$, config?: {ttl?: number}];
export type HelloTestResult = Promise<string>;
export function helloTest(...args: helloTestParams): HelloTestResult {
return callFunction$$(
args,
{
"functionName": "helloTest",
"arrow": {
"domain": {
"fields": {},
"tag": "labeledProduct"
},
"codomain": {
"items": [
{
"name": "string",
"tag": "scalar"
}
],
"tag": "unlabeledProduct"
},
"tag": "arrow"
},
"names": {
"relay": "-relay-",
"getDataSrv": "getDataSrv",
"callbackSrv": "callbackSrv",
"responseSrv": "callbackSrv",
"responseFnName": "response",
"errorHandlingSrv": "errorHandlingSrv",
"errorFnName": "error"
}
},
helloTest_script
);
}
export const demo_calculation_script = `
(seq
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "service_id") [] service_id)
)
(xor
(seq
(seq
(seq
(seq
(seq
(call %init_peer_id% (service_id "test_logs") [])
(call %init_peer_id% (service_id "add") [10])
)
(call %init_peer_id% (service_id "multiply") [5])
)
(call %init_peer_id% (service_id "subtract") [8])
)
(call %init_peer_id% (service_id "divide") [6])
)
(call %init_peer_id% (service_id "state") [] res)
)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 0])
)
)
(call %init_peer_id% ("callbackSrv" "response") [res])
)
`;
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 function demo_calculation(...args: demo_calculationParams): Demo_calculationResult {
return callFunction$$(
args,
{
"functionName": "demo_calculation",
"arrow": {
"domain": {
"fields": {
"service_id": {
"name": "string",
"tag": "scalar"
}
},
"tag": "labeledProduct"
},
"codomain": {
"items": [
{
"name": "f64",
"tag": "scalar"
}
],
"tag": "unlabeledProduct"
},
"tag": "arrow"
},
"names": {
"relay": "-relay-",
"getDataSrv": "getDataSrv",
"callbackSrv": "callbackSrv",
"responseSrv": "callbackSrv",
"responseFnName": "response",
"errorHandlingSrv": "errorHandlingSrv",
"errorFnName": "error"
}
},
demo_calculation_script
);
}
export const marineTest_script = `
(seq
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "wasm64") [] wasm64)
)
(xor
(seq
(seq
(seq
(seq
(seq
(seq
(call %init_peer_id% ("single_module_srv" "create") [wasm64] serviceResult)
(call %init_peer_id% (serviceResult.$.service_id.[0] "test_logs") [])
)
(call %init_peer_id% (serviceResult.$.service_id.[0] "add") [10])
)
(call %init_peer_id% (serviceResult.$.service_id.[0] "multiply") [5])
)
(call %init_peer_id% (serviceResult.$.service_id.[0] "subtract") [8])
)
(call %init_peer_id% (serviceResult.$.service_id.[0] "divide") [6])
)
(call %init_peer_id% (serviceResult.$.service_id.[0] "state") [] res)
)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 0])
)
)
(call %init_peer_id% ("callbackSrv" "response") [res])
)
`;
export type MarineTestParams = [wasm64: string, config?: {ttl?: number}] | [peer: IFluenceClient$$, wasm64: string, config?: {ttl?: number}];
export type MarineTestResult = Promise<number>;
export function marineTest(...args: marineTestParams): MarineTestResult {
return callFunction$$(
args,
{
"functionName": "marineTest",
"arrow": {
"domain": {
"fields": {
"wasm64": {
"name": "string",
"tag": "scalar"
}
},
"tag": "labeledProduct"
},
"codomain": {
"items": [
{
"name": "f64",
"tag": "scalar"
}
],
"tag": "unlabeledProduct"
},
"tag": "arrow"
},
"names": {
"relay": "-relay-",
"getDataSrv": "getDataSrv",
"callbackSrv": "callbackSrv",
"responseSrv": "callbackSrv",
"responseFnName": "response",
"errorHandlingSrv": "errorHandlingSrv",
"errorFnName": "error"
}
},
marineTest_script
);
}

View File

@ -40,7 +40,7 @@ ${func.script}\`;
${typeGenerator.funcType(func)}
export function ${func.funcDef.functionName}(${typeGenerator.type(
"...args",
`${func.funcDef.functionName}Params`,
`${capitalize(func.funcDef.functionName)}Params`,
)})${typeGenerator.type(
"",
`${capitalize(func.funcDef.functionName)}Result`,

27
pnpm-lock.yaml generated
View File

@ -61,8 +61,8 @@ importers:
version: 1.5.1
devDependencies:
'@fluencelabs/aqua-api':
specifier: 0.12.2
version: 0.12.2
specifier: 0.12.4-main-cee4448-2196-1
version: 0.12.4-main-cee4448-2196-1
'@fluencelabs/aqua-lib':
specifier: 0.6.0
version: 0.6.0
@ -73,8 +73,8 @@ importers:
specifier: workspace:*
version: link:../../core/js-client
'@fluencelabs/registry':
specifier: 0.8.7
version: 0.8.7
specifier: 0.8.8-1
version: 0.8.8-1
'@fluencelabs/trust-graph':
specifier: 3.1.2
version: 3.1.2
@ -167,8 +167,8 @@ importers:
version: 5.0.5
devDependencies:
'@fluencelabs/aqua-api':
specifier: 0.12.0
version: 0.12.0
specifier: 0.12.4-main-cee4448-2196-1
version: 0.12.4-main-cee4448-2196-1
'@fluencelabs/aqua-lib':
specifier: 0.7.3
version: 0.7.3
@ -3677,12 +3677,8 @@ packages:
resolution: {integrity: sha512-NCC3zz2+nvYd+Ckfh87rA47zfu2QsQpvc6k1yzTk+b9KzRj0wkGa8LSoGOXN6Zv4lRf/EIoZ80biDh9HOI+RNQ==}
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
/@fluencelabs/aqua-api@0.12.0:
resolution: {integrity: sha512-8D1SfmBDm0mmg3tuYrlpU8L6+bRlCSVRkhlU4CXMJFSMiVMrSF2WV+KFTP4GcOB3N4pNOONEwHMQo4xNWwzGhg==}
dev: true
/@fluencelabs/aqua-api@0.12.2:
resolution: {integrity: sha512-B0Op0h5IxpaXuReKAmu0vql9n7/r8exmDednJo65NI41bX3gY0ZQxuOq7eyhKTtvevK28hs8asQtx1gPnfevzA==}
/@fluencelabs/aqua-api@0.12.4-main-cee4448-2196-1:
resolution: {registry: https://registry.npmjs.org/, tarball: https://npm.fluence.dev/@fluencelabs/aqua-api/-/aqua-api-0.12.4-main-cee4448-2196-1.tgz}
dev: true
/@fluencelabs/aqua-api@0.9.3:
@ -3723,6 +3719,13 @@ packages:
'@fluencelabs/trust-graph': 0.4.1
dev: true
/@fluencelabs/registry@0.8.8-1:
resolution: {integrity: sha512-zdkn/JiMXAozn43/nrF+Cvq6/heSIUS1e3tOb8AFRMoI2Czd3o8p6fEwdJwa7QE8IkD1NOln/C/bWUVwfEDi9w==}
dependencies:
'@fluencelabs/aqua-lib': 0.7.0
'@fluencelabs/trust-graph': 0.4.1
dev: true
/@fluencelabs/spell@0.5.20:
resolution: {integrity: sha512-QFbknWwALLUWMzpWkFt34McuwTz9xwQuiPP1zXqhPqVZ1J6g8F3gwHHtzgHFW5Z7WrRmwsL+IQtFJy8YZubhDw==}
dev: true