trying instanceof fix

This commit is contained in:
Pavel Murygin 2021-09-09 21:44:12 +03:00
parent 12b1860374
commit aa303b798f
15 changed files with 1521 additions and 1467 deletions

View File

@ -77,9 +77,9 @@
}
},
"@fluencelabs/fluence": {
"version": "0.11.0",
"resolved": "https://registry.npmjs.org/@fluencelabs/fluence/-/fluence-0.11.0.tgz",
"integrity": "sha512-HfUS8eLwfviiJhqsrHnOnRxO20TbdahPreP6AkBXQaEpWeRew6vxAd0Dn+xdzy6KCJ4W9GOKLcgtPfqquIO2Pg==",
"version": "0.10.4-fix-null-check-416.0",
"resolved": "https://registry.npmjs.org/@fluencelabs/fluence/-/fluence-0.10.4-fix-null-check-416.0.tgz",
"integrity": "sha512-/aZ58z62lj2Esnt8ZDKTJjZCVqmCAZ5O2F8zei4KeKoqm+eyd8XVHFkjRK3PJDSli5pM7TcjJIGJoLFWsU+9iQ==",
"requires": {
"@chainsafe/libp2p-noise": "4.0.0",
"@fluencelabs/avm": "0.14.4",
@ -3143,9 +3143,9 @@
}
},
"ws": {
"version": "7.5.4",
"resolved": "https://registry.npmjs.org/ws/-/ws-7.5.4.tgz",
"integrity": "sha512-zP9z6GXm6zC27YtspwH99T3qTG7bBFv2VIkeHstMLrLlDJuzA7tQ5ls3OJ1hOGGCzTQPniNJoHXIAOS0Jljohg=="
"version": "7.5.5",
"resolved": "https://registry.npmjs.org/ws/-/ws-7.5.5.tgz",
"integrity": "sha512-BAkMFcAzl8as1G/hArkxOxq3G7pjUqQ3gzYbLL0/5zNkph70e+lCoxBGnm6AW1+/aiNeV4fnKqZ8m4GZewmH2w=="
},
"xml2js": {
"version": "0.4.23",

View File

@ -6,7 +6,8 @@
"scripts": {
"postinstall": "../service/scripts/build.sh && npm run build",
"compile-aqua": "aqua -i aqua -o src",
"build": "npm run compile-aqua && tsc"
"_build": "npm run compile-aqua && tsc",
"build": "tsc"
},
"keywords": [
"fluence",
@ -22,7 +23,7 @@
"license": "MIT",
"dependencies": {
"@fluencelabs/aqua-ipfs": "0.4.2",
"@fluencelabs/fluence": "0.11.0",
"@fluencelabs/fluence": "0.10.4-fix-null-check-416.0",
"@fluencelabs/aqua-lib": "0.1.14",
"@fluencelabs/fluence-network-environment": "1.0.10",
"ipfs-http-client": "^50.1.2",

View File

@ -1,50 +1,57 @@
/**
*
* This file is auto-generated. Do not edit manually: changes may be erased.
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
* If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
* Aqua version: 0.3.0-224
*
*/
import { FluencePeer } from '@fluencelabs/fluence';
import { FluencePeer } from "@fluencelabs/fluence";
import {
ResultCodes,
RequestFlow,
RequestFlowBuilder,
CallParams,
} from '@fluencelabs/fluence/dist/internal/compilerSupport/v1';
ResultCodes,
RequestFlow,
RequestFlowBuilder,
CallParams,
} from "@fluencelabs/fluence/dist/internal/compilerSupport/v1";
// Services
// Functions
export function set_timeout(node: string, timeout_sec: number, config?: {ttl?: number}) : Promise<void>;
export function set_timeout(peer: FluencePeer, node: string, timeout_sec: number, config?: {ttl?: number}) : Promise<void>;
export function set_timeout(...args: any) {
let peer: FluencePeer;
let node: any;
let timeout_sec: any;
let config: any;
if (args[0] instanceof FluencePeer) {
peer = args[0];
node = args[1];
timeout_sec = args[2];
config = args[3];
} else {
peer = FluencePeer.default;
node = args[0];
timeout_sec = args[1];
config = args[2];
}
let request: RequestFlow;
const promise = new Promise<void>((resolve, reject) => {
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
export function set_timeout(
node: string,
timeout_sec: number,
config?: { ttl?: number }
): Promise<void>;
export function set_timeout(
peer: FluencePeer,
node: string,
timeout_sec: number,
config?: { ttl?: number }
): Promise<void>;
export function set_timeout(...args: any) {
let peer: FluencePeer;
let node: any;
let timeout_sec: any;
let config: any;
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
node = args[1];
timeout_sec = args[2];
config = args[3];
} else {
peer = FluencePeer.default;
node = args[0];
timeout_sec = args[1];
config = args[2];
}
let request: RequestFlow;
const promise = new Promise<void>((resolve, reject) => {
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
(xor
(seq
(seq
@ -71,69 +78,90 @@ config = args[2];
)
)
`,
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return peer.connectionInfo.connectedRelay ;
});
h.on('getDataSrv', 'node', () => {return node;});
h.on('getDataSrv', 'timeout_sec', () => {return timeout_sec;});
h.onEvent('callbackSrv', 'response', (args) => {
});
`
)
.configHandler((h) => {
h.on("getDataSrv", "-relay-", () => {
return peer.connectionInfo.connectedRelay;
});
h.on("getDataSrv", "node", () => {
return node;
});
h.on("getDataSrv", "timeout_sec", () => {
return timeout_sec;
});
h.onEvent("callbackSrv", "response", (args) => {});
h.onEvent('errorHandlingSrv', 'error', (args) => {
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject('Request timed out for set_timeout');
})
if(config && config.ttl) {
r.withTTL(config.ttl)
}
request = r.build();
});
peer.internals.initiateFlow(request!);
return Promise.race([promise, Promise.resolve()]);
h.onEvent("errorHandlingSrv", "error", (args) => {
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject("Request timed out for set_timeout");
});
if (config && config.ttl) {
r.withTTL(config.ttl);
}
request = r.build();
});
peer.internals.initiateFlow(request!);
return Promise.race([promise, Promise.resolve()]);
}
export function get_and_cache(
node: string,
cid: string,
from: string,
error: (
arg0: string,
arg1: string,
callParams: CallParams<"arg0" | "arg1">
) => void,
config?: { ttl?: number }
): Promise<string | null>;
export function get_and_cache(
peer: FluencePeer,
node: string,
cid: string,
from: string,
error: (
arg0: string,
arg1: string,
callParams: CallParams<"arg0" | "arg1">
) => void,
config?: { ttl?: number }
): Promise<string | null>;
export function get_and_cache(...args: any) {
let peer: FluencePeer;
let node: any;
let cid: any;
let from: any;
let error: any;
let config: any;
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
node = args[1];
cid = args[2];
from = args[3];
error = args[4];
config = args[5];
} else {
peer = FluencePeer.default;
node = args[0];
cid = args[1];
from = args[2];
error = args[3];
config = args[4];
}
export function get_and_cache(node: string, cid: string, from: string, error: (arg0: string, arg1: string, callParams: CallParams<'arg0' | 'arg1'>) => void, config?: {ttl?: number}) : Promise<string | null>;
export function get_and_cache(peer: FluencePeer, node: string, cid: string, from: string, error: (arg0: string, arg1: string, callParams: CallParams<'arg0' | 'arg1'>) => void, config?: {ttl?: number}) : Promise<string | null>;
export function get_and_cache(...args: any) {
let peer: FluencePeer;
let node: any;
let cid: any;
let from: any;
let error: any;
let config: any;
if (args[0] instanceof FluencePeer) {
peer = args[0];
node = args[1];
cid = args[2];
from = args[3];
error = args[4];
config = args[5];
} else {
peer = FluencePeer.default;
node = args[0];
cid = args[1];
from = args[2];
error = args[3];
config = args[4];
}
let request: RequestFlow;
const promise = new Promise<string | null>((resolve, reject) => {
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
let request: RequestFlow;
const promise = new Promise<string | null>((resolve, reject) => {
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
(xor
(seq
(seq
@ -215,89 +243,110 @@ config = args[4];
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 7])
)
`,
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return peer.connectionInfo.connectedRelay ;
});
h.on('getDataSrv', 'node', () => {return node;});
h.on('getDataSrv', 'cid', () => {return cid;});
h.on('getDataSrv', 'from', () => {return from;});
`
)
.configHandler((h) => {
h.on("getDataSrv", "-relay-", () => {
return peer.connectionInfo.connectedRelay;
});
h.on("getDataSrv", "node", () => {
return node;
});
h.on("getDataSrv", "cid", () => {
return cid;
});
h.on("getDataSrv", "from", () => {
return from;
});
h.use((req, resp, next) => {
if(req.serviceId === 'callbackSrv' && req.fnName === 'error') {
const callParams = {
...req.particleContext,
tetraplets: {
arg0: req.tetraplets[0],arg1: req.tetraplets[1]
},
};
resp.retCode = ResultCodes.success;
error(req.args[0], req.args[1], callParams); resp.result = {}
h.use((req, resp, next) => {
if (req.serviceId === "callbackSrv" && req.fnName === "error") {
const callParams = {
...req.particleContext,
tetraplets: {
arg0: req.tetraplets[0],
arg1: req.tetraplets[1],
},
};
resp.retCode = ResultCodes.success;
error(req.args[0], req.args[1], callParams);
resp.result = {};
}
next();
});
}
next();
});
h.onEvent('callbackSrv', 'response', (args) => {
let [opt] = args;
if (Array.isArray(opt)) {
if (opt.length === 0) { resolve(null); }
opt = opt[0];
}
return resolve(opt);
});
h.onEvent("callbackSrv", "response", (args) => {
let [opt] = args;
if (Array.isArray(opt)) {
if (opt.length === 0) {
resolve(null);
}
opt = opt[0];
}
return resolve(opt);
});
h.onEvent('errorHandlingSrv', 'error', (args) => {
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject('Request timed out for get_and_cache');
})
if(config && config.ttl) {
r.withTTL(config.ttl)
}
request = r.build();
});
peer.internals.initiateFlow(request!);
return promise;
h.onEvent("errorHandlingSrv", "error", (args) => {
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject("Request timed out for get_and_cache");
});
if (config && config.ttl) {
r.withTTL(config.ttl);
}
request = r.build();
});
peer.internals.initiateFlow(request!);
return promise;
}
export function get_from(
node: string,
cid: string,
from: string,
config?: { ttl?: number }
): Promise<{ error: string; path: string; success: boolean }>;
export function get_from(
peer: FluencePeer,
node: string,
cid: string,
from: string,
config?: { ttl?: number }
): Promise<{ error: string; path: string; success: boolean }>;
export function get_from(...args: any) {
let peer: FluencePeer;
let node: any;
let cid: any;
let from: any;
let config: any;
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
node = args[1];
cid = args[2];
from = args[3];
config = args[4];
} else {
peer = FluencePeer.default;
node = args[0];
cid = args[1];
from = args[2];
config = args[3];
}
export function get_from(node: string, cid: string, from: string, config?: {ttl?: number}) : Promise<{error:string;path:string;success:boolean}>;
export function get_from(peer: FluencePeer, node: string, cid: string, from: string, config?: {ttl?: number}) : Promise<{error:string;path:string;success:boolean}>;
export function get_from(...args: any) {
let peer: FluencePeer;
let node: any;
let cid: any;
let from: any;
let config: any;
if (args[0] instanceof FluencePeer) {
peer = args[0];
node = args[1];
cid = args[2];
from = args[3];
config = args[4];
} else {
peer = FluencePeer.default;
node = args[0];
cid = args[1];
from = args[2];
config = args[3];
}
let request: RequestFlow;
const promise = new Promise<{error:string;path:string;success:boolean}>((resolve, reject) => {
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
let request: RequestFlow;
const promise = new Promise<{
error: string;
path: string;
success: boolean;
}>((resolve, reject) => {
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
(xor
(seq
(seq
@ -333,62 +382,77 @@ config = args[3];
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
)
`,
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return peer.connectionInfo.connectedRelay ;
});
h.on('getDataSrv', 'node', () => {return node;});
h.on('getDataSrv', 'cid', () => {return cid;});
h.on('getDataSrv', 'from', () => {return from;});
h.onEvent('callbackSrv', 'response', (args) => {
const [res] = args;
resolve(res);
});
`
)
.configHandler((h) => {
h.on("getDataSrv", "-relay-", () => {
return peer.connectionInfo.connectedRelay;
});
h.on("getDataSrv", "node", () => {
return node;
});
h.on("getDataSrv", "cid", () => {
return cid;
});
h.on("getDataSrv", "from", () => {
return from;
});
h.onEvent("callbackSrv", "response", (args) => {
const [res] = args;
resolve(res);
});
h.onEvent('errorHandlingSrv', 'error', (args) => {
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject('Request timed out for get_from');
})
if(config && config.ttl) {
r.withTTL(config.ttl)
}
request = r.build();
});
peer.internals.initiateFlow(request!);
return promise;
h.onEvent("errorHandlingSrv", "error", (args) => {
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject("Request timed out for get_from");
});
if (config && config.ttl) {
r.withTTL(config.ttl);
}
request = r.build();
});
peer.internals.initiateFlow(request!);
return promise;
}
export function get_local_api_multiaddr(
node: string,
config?: { ttl?: number }
): Promise<{ error: string; multiaddr: string; success: boolean }>;
export function get_local_api_multiaddr(
peer: FluencePeer,
node: string,
config?: { ttl?: number }
): Promise<{ error: string; multiaddr: string; success: boolean }>;
export function get_local_api_multiaddr(...args: any) {
let peer: FluencePeer;
let node: any;
let config: any;
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
node = args[1];
config = args[2];
} else {
peer = FluencePeer.default;
node = args[0];
config = args[1];
}
export function get_local_api_multiaddr(node: string, config?: {ttl?: number}) : Promise<{error:string;multiaddr:string;success:boolean}>;
export function get_local_api_multiaddr(peer: FluencePeer, node: string, config?: {ttl?: number}) : Promise<{error:string;multiaddr:string;success:boolean}>;
export function get_local_api_multiaddr(...args: any) {
let peer: FluencePeer;
let node: any;
let config: any;
if (args[0] instanceof FluencePeer) {
peer = args[0];
node = args[1];
config = args[2];
} else {
peer = FluencePeer.default;
node = args[0];
config = args[1];
}
let request: RequestFlow;
const promise = new Promise<{error:string;multiaddr:string;success:boolean}>((resolve, reject) => {
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
let request: RequestFlow;
const promise = new Promise<{
error: string;
multiaddr: string;
success: boolean;
}>((resolve, reject) => {
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
(xor
(seq
(seq
@ -418,60 +482,71 @@ config = args[1];
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
)
`,
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return peer.connectionInfo.connectedRelay ;
});
h.on('getDataSrv', 'node', () => {return node;});
h.onEvent('callbackSrv', 'response', (args) => {
const [res] = args;
resolve(res);
});
`
)
.configHandler((h) => {
h.on("getDataSrv", "-relay-", () => {
return peer.connectionInfo.connectedRelay;
});
h.on("getDataSrv", "node", () => {
return node;
});
h.onEvent("callbackSrv", "response", (args) => {
const [res] = args;
resolve(res);
});
h.onEvent('errorHandlingSrv', 'error', (args) => {
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject('Request timed out for get_local_api_multiaddr');
})
if(config && config.ttl) {
r.withTTL(config.ttl)
}
request = r.build();
});
peer.internals.initiateFlow(request!);
return promise;
h.onEvent("errorHandlingSrv", "error", (args) => {
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject("Request timed out for get_local_api_multiaddr");
});
if (config && config.ttl) {
r.withTTL(config.ttl);
}
request = r.build();
});
peer.internals.initiateFlow(request!);
return promise;
}
export function get_external_swarm_multiaddr(
node: string,
config?: { ttl?: number }
): Promise<{ error: string; multiaddr: string; success: boolean }>;
export function get_external_swarm_multiaddr(
peer: FluencePeer,
node: string,
config?: { ttl?: number }
): Promise<{ error: string; multiaddr: string; success: boolean }>;
export function get_external_swarm_multiaddr(...args: any) {
let peer: FluencePeer;
let node: any;
let config: any;
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
node = args[1];
config = args[2];
} else {
peer = FluencePeer.default;
node = args[0];
config = args[1];
}
export function get_external_swarm_multiaddr(node: string, config?: {ttl?: number}) : Promise<{error:string;multiaddr:string;success:boolean}>;
export function get_external_swarm_multiaddr(peer: FluencePeer, node: string, config?: {ttl?: number}) : Promise<{error:string;multiaddr:string;success:boolean}>;
export function get_external_swarm_multiaddr(...args: any) {
let peer: FluencePeer;
let node: any;
let config: any;
if (args[0] instanceof FluencePeer) {
peer = args[0];
node = args[1];
config = args[2];
} else {
peer = FluencePeer.default;
node = args[0];
config = args[1];
}
let request: RequestFlow;
const promise = new Promise<{error:string;multiaddr:string;success:boolean}>((resolve, reject) => {
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
let request: RequestFlow;
const promise = new Promise<{
error: string;
multiaddr: string;
success: boolean;
}>((resolve, reject) => {
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
(xor
(seq
(seq
@ -501,63 +576,76 @@ config = args[1];
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
)
`,
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return peer.connectionInfo.connectedRelay ;
});
h.on('getDataSrv', 'node', () => {return node;});
h.onEvent('callbackSrv', 'response', (args) => {
const [res] = args;
resolve(res);
});
`
)
.configHandler((h) => {
h.on("getDataSrv", "-relay-", () => {
return peer.connectionInfo.connectedRelay;
});
h.on("getDataSrv", "node", () => {
return node;
});
h.onEvent("callbackSrv", "response", (args) => {
const [res] = args;
resolve(res);
});
h.onEvent('errorHandlingSrv', 'error', (args) => {
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject('Request timed out for get_external_swarm_multiaddr');
})
if(config && config.ttl) {
r.withTTL(config.ttl)
}
request = r.build();
});
peer.internals.initiateFlow(request!);
return promise;
h.onEvent("errorHandlingSrv", "error", (args) => {
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject("Request timed out for get_external_swarm_multiaddr");
});
if (config && config.ttl) {
r.withTTL(config.ttl);
}
request = r.build();
});
peer.internals.initiateFlow(request!);
return promise;
}
export function put(
node: string,
path: string,
config?: { ttl?: number }
): Promise<{ error: string; hash: string; success: boolean }>;
export function put(
peer: FluencePeer,
node: string,
path: string,
config?: { ttl?: number }
): Promise<{ error: string; hash: string; success: boolean }>;
export function put(...args: any) {
let peer: FluencePeer;
let node: any;
let path: any;
let config: any;
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
node = args[1];
path = args[2];
config = args[3];
} else {
peer = FluencePeer.default;
node = args[0];
path = args[1];
config = args[2];
}
export function put(node: string, path: string, config?: {ttl?: number}) : Promise<{error:string;hash:string;success:boolean}>;
export function put(peer: FluencePeer, node: string, path: string, config?: {ttl?: number}) : Promise<{error:string;hash:string;success:boolean}>;
export function put(...args: any) {
let peer: FluencePeer;
let node: any;
let path: any;
let config: any;
if (args[0] instanceof FluencePeer) {
peer = args[0];
node = args[1];
path = args[2];
config = args[3];
} else {
peer = FluencePeer.default;
node = args[0];
path = args[1];
config = args[2];
}
let request: RequestFlow;
const promise = new Promise<{error:string;hash:string;success:boolean}>((resolve, reject) => {
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
let request: RequestFlow;
const promise = new Promise<{
error: string;
hash: string;
success: boolean;
}>((resolve, reject) => {
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
(xor
(seq
(seq
@ -590,61 +678,74 @@ config = args[2];
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
)
`,
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return peer.connectionInfo.connectedRelay ;
});
h.on('getDataSrv', 'node', () => {return node;});
h.on('getDataSrv', 'path', () => {return path;});
h.onEvent('callbackSrv', 'response', (args) => {
const [res] = args;
resolve(res);
});
`
)
.configHandler((h) => {
h.on("getDataSrv", "-relay-", () => {
return peer.connectionInfo.connectedRelay;
});
h.on("getDataSrv", "node", () => {
return node;
});
h.on("getDataSrv", "path", () => {
return path;
});
h.onEvent("callbackSrv", "response", (args) => {
const [res] = args;
resolve(res);
});
h.onEvent('errorHandlingSrv', 'error', (args) => {
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject('Request timed out for put');
})
if(config && config.ttl) {
r.withTTL(config.ttl)
}
request = r.build();
});
peer.internals.initiateFlow(request!);
return promise;
h.onEvent("errorHandlingSrv", "error", (args) => {
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject("Request timed out for put");
});
if (config && config.ttl) {
r.withTTL(config.ttl);
}
request = r.build();
});
peer.internals.initiateFlow(request!);
return promise;
}
export function get_external_api_multiaddr(
node: string,
config?: { ttl?: number }
): Promise<{ error: string; multiaddr: string; success: boolean }>;
export function get_external_api_multiaddr(
peer: FluencePeer,
node: string,
config?: { ttl?: number }
): Promise<{ error: string; multiaddr: string; success: boolean }>;
export function get_external_api_multiaddr(...args: any) {
let peer: FluencePeer;
let node: any;
let config: any;
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
node = args[1];
config = args[2];
} else {
peer = FluencePeer.default;
node = args[0];
config = args[1];
}
export function get_external_api_multiaddr(node: string, config?: {ttl?: number}) : Promise<{error:string;multiaddr:string;success:boolean}>;
export function get_external_api_multiaddr(peer: FluencePeer, node: string, config?: {ttl?: number}) : Promise<{error:string;multiaddr:string;success:boolean}>;
export function get_external_api_multiaddr(...args: any) {
let peer: FluencePeer;
let node: any;
let config: any;
if (args[0] instanceof FluencePeer) {
peer = args[0];
node = args[1];
config = args[2];
} else {
peer = FluencePeer.default;
node = args[0];
config = args[1];
}
let request: RequestFlow;
const promise = new Promise<{error:string;multiaddr:string;success:boolean}>((resolve, reject) => {
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
let request: RequestFlow;
const promise = new Promise<{
error: string;
multiaddr: string;
success: boolean;
}>((resolve, reject) => {
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
(xor
(seq
(seq
@ -674,33 +775,34 @@ config = args[1];
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
)
`,
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return peer.connectionInfo.connectedRelay ;
});
h.on('getDataSrv', 'node', () => {return node;});
h.onEvent('callbackSrv', 'response', (args) => {
const [res] = args;
resolve(res);
});
`
)
.configHandler((h) => {
h.on("getDataSrv", "-relay-", () => {
return peer.connectionInfo.connectedRelay;
});
h.on("getDataSrv", "node", () => {
return node;
});
h.onEvent("callbackSrv", "response", (args) => {
const [res] = args;
resolve(res);
});
h.onEvent('errorHandlingSrv', 'error', (args) => {
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject('Request timed out for get_external_api_multiaddr');
})
if(config && config.ttl) {
r.withTTL(config.ttl)
}
request = r.build();
});
peer.internals.initiateFlow(request!);
return promise;
h.onEvent("errorHandlingSrv", "error", (args) => {
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject("Request timed out for get_external_api_multiaddr");
});
if (config && config.ttl) {
r.withTTL(config.ttl);
}
request = r.build();
});
peer.internals.initiateFlow(request!);
return promise;
}

View File

@ -1,107 +1,111 @@
/**
*
* This file is auto-generated. Do not edit manually: changes may be erased.
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
* If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
* Aqua version: 0.3.0-224
*
*/
import { FluencePeer } from '@fluencelabs/fluence';
import { FluencePeer } from "@fluencelabs/fluence";
import {
ResultCodes,
RequestFlow,
RequestFlowBuilder,
CallParams,
} from '@fluencelabs/fluence/dist/internal/compilerSupport/v1';
ResultCodes,
RequestFlow,
RequestFlowBuilder,
CallParams,
} from "@fluencelabs/fluence/dist/internal/compilerSupport/v1";
// Services
export interface StringOpDef {
array: (s: string, callParams: CallParams<'s'>) => string[];
}
export function registerStringOp(service: StringOpDef): void;
export function registerStringOp(serviceId: string, service: StringOpDef): void;
export function registerStringOp(peer: FluencePeer, service: StringOpDef): void;
export function registerStringOp(peer: FluencePeer, serviceId: string, service: StringOpDef): void;
export function registerStringOp(...args: any) {
let peer: FluencePeer;
let serviceId: any;
let service: any;
if (args[0] instanceof FluencePeer) {
peer = args[0];
} else {
peer = FluencePeer.default;
}
if (typeof args[0] === 'string') {
serviceId = args[0];
} else if (typeof args[1] === 'string') {
serviceId = args[1];
}
else {
serviceId = "op"
export interface StringOpDef {
array: (s: string, callParams: CallParams<"s">) => string[];
}
if (!(args[0] instanceof FluencePeer) && typeof args[0] === 'object') {
service = args[0];
} else if (typeof args[1] === 'object') {
service = args[1];
} else {
service = args[2];
export function registerStringOp(service: StringOpDef): void;
export function registerStringOp(serviceId: string, service: StringOpDef): void;
export function registerStringOp(peer: FluencePeer, service: StringOpDef): void;
export function registerStringOp(
peer: FluencePeer,
serviceId: string,
service: StringOpDef
): void;
export function registerStringOp(...args: any) {
let peer: FluencePeer;
let serviceId: any;
let service: any;
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
} else {
peer = FluencePeer.default;
}
if (typeof args[0] === "string") {
serviceId = args[0];
} else if (typeof args[1] === "string") {
serviceId = args[1];
} else {
serviceId = "op";
}
if (!FluencePeer.isInstance(args[0]) && typeof args[0] === "object") {
service = args[0];
} else if (typeof args[1] === "object") {
service = args[1];
} else {
service = args[2];
}
peer.internals.callServiceHandler.use((req, resp, next) => {
if (req.serviceId !== serviceId) {
next();
return;
}
peer.internals.callServiceHandler.use((req, resp, next) => {
if (req.serviceId !== serviceId) {
next();
return;
}
if (req.fnName === 'array') {
const callParams = {
...req.particleContext,
tetraplets: {
s: req.tetraplets[0]
},
};
resp.retCode = ResultCodes.success;
resp.result = service.array(req.args[0], callParams)
if (req.fnName === "array") {
const callParams = {
...req.particleContext,
tetraplets: {
s: req.tetraplets[0],
},
};
resp.retCode = ResultCodes.success;
resp.result = service.array(req.args[0], callParams);
}
}
next();
});
}
next();
});
}
// Functions
export function add_blueprint(module_hash: string, config?: {ttl?: number}) : Promise<string>;
export function add_blueprint(peer: FluencePeer, module_hash: string, config?: {ttl?: number}) : Promise<string>;
export function add_blueprint(...args: any) {
let peer: FluencePeer;
let module_hash: any;
let config: any;
if (args[0] instanceof FluencePeer) {
peer = args[0];
module_hash = args[1];
config = args[2];
} else {
peer = FluencePeer.default;
module_hash = args[0];
config = args[1];
}
let request: RequestFlow;
const promise = new Promise<string>((resolve, reject) => {
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
export function add_blueprint(
module_hash: string,
config?: { ttl?: number }
): Promise<string>;
export function add_blueprint(
peer: FluencePeer,
module_hash: string,
config?: { ttl?: number }
): Promise<string>;
export function add_blueprint(...args: any) {
let peer: FluencePeer;
let module_hash: any;
let config: any;
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
module_hash = args[1];
config = args[2];
} else {
peer = FluencePeer.default;
module_hash = args[0];
config = args[1];
}
let request: RequestFlow;
const promise = new Promise<string>((resolve, reject) => {
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
(xor
(seq
(seq
@ -128,75 +132,104 @@ config = args[1];
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
)
`,
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return peer.connectionInfo.connectedRelay ;
});
h.on('getDataSrv', 'module_hash', () => {return module_hash;});
h.onEvent('callbackSrv', 'response', (args) => {
const [res] = args;
resolve(res);
});
`
)
.configHandler((h) => {
h.on("getDataSrv", "-relay-", () => {
return peer.connectionInfo.connectedRelay;
});
h.on("getDataSrv", "module_hash", () => {
return module_hash;
});
h.onEvent("callbackSrv", "response", (args) => {
const [res] = args;
resolve(res);
});
h.onEvent('errorHandlingSrv', 'error', (args) => {
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject('Request timed out for add_blueprint');
})
if(config && config.ttl) {
r.withTTL(config.ttl)
}
request = r.build();
});
peer.internals.initiateFlow(request!);
return promise;
h.onEvent("errorHandlingSrv", "error", (args) => {
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject("Request timed out for add_blueprint");
});
if (config && config.ttl) {
r.withTTL(config.ttl);
}
request = r.build();
});
peer.internals.initiateFlow(request!);
return promise;
}
export function put_file_size(
relay: string,
cid: string,
ipfs: string,
service_id: string,
logSize: (arg0: number, callParams: CallParams<"arg0">) => void,
error: (
arg0: string,
arg1: string,
callParams: CallParams<"arg0" | "arg1">
) => void,
config?: { ttl?: number }
): Promise<{ error: string; hash: string; success: boolean } | null>;
export function put_file_size(
peer: FluencePeer,
relay: string,
cid: string,
ipfs: string,
service_id: string,
logSize: (arg0: number, callParams: CallParams<"arg0">) => void,
error: (
arg0: string,
arg1: string,
callParams: CallParams<"arg0" | "arg1">
) => void,
config?: { ttl?: number }
): Promise<{ error: string; hash: string; success: boolean } | null>;
export function put_file_size(...args: any) {
let peer: FluencePeer;
let relay: any;
let cid: any;
let ipfs: any;
let service_id: any;
let logSize: any;
let error: any;
let config: any;
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
relay = args[1];
cid = args[2];
ipfs = args[3];
service_id = args[4];
logSize = args[5];
error = args[6];
config = args[7];
} else {
peer = FluencePeer.default;
relay = args[0];
cid = args[1];
ipfs = args[2];
service_id = args[3];
logSize = args[4];
error = args[5];
config = args[6];
}
export function put_file_size(relay: string, cid: string, ipfs: string, service_id: string, logSize: (arg0: number, callParams: CallParams<'arg0'>) => void, error: (arg0: string, arg1: string, callParams: CallParams<'arg0' | 'arg1'>) => void, config?: {ttl?: number}) : Promise<{error:string;hash:string;success:boolean} | null>;
export function put_file_size(peer: FluencePeer, relay: string, cid: string, ipfs: string, service_id: string, logSize: (arg0: number, callParams: CallParams<'arg0'>) => void, error: (arg0: string, arg1: string, callParams: CallParams<'arg0' | 'arg1'>) => void, config?: {ttl?: number}) : Promise<{error:string;hash:string;success:boolean} | null>;
export function put_file_size(...args: any) {
let peer: FluencePeer;
let relay: any;
let cid: any;
let ipfs: any;
let service_id: any;
let logSize: any;
let error: any;
let config: any;
if (args[0] instanceof FluencePeer) {
peer = args[0];
relay = args[1];
cid = args[2];
ipfs = args[3];
service_id = args[4];
logSize = args[5];
error = args[6];
config = args[7];
} else {
peer = FluencePeer.default;
relay = args[0];
cid = args[1];
ipfs = args[2];
service_id = args[3];
logSize = args[4];
error = args[5];
config = args[6];
}
let request: RequestFlow;
const promise = new Promise<{error:string;hash:string;success:boolean} | null>((resolve, reject) => {
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
let request: RequestFlow;
const promise = new Promise<{
error: string;
hash: string;
success: boolean;
} | null>((resolve, reject) => {
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
(xor
(seq
(seq
@ -319,104 +352,119 @@ config = args[6];
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 10])
)
`,
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return peer.connectionInfo.connectedRelay ;
});
h.on('getDataSrv', 'relay', () => {return relay;});
h.on('getDataSrv', 'cid', () => {return cid;});
h.on('getDataSrv', 'ipfs', () => {return ipfs;});
h.on('getDataSrv', 'service_id', () => {return service_id;});
`
)
.configHandler((h) => {
h.on("getDataSrv", "-relay-", () => {
return peer.connectionInfo.connectedRelay;
});
h.on("getDataSrv", "relay", () => {
return relay;
});
h.on("getDataSrv", "cid", () => {
return cid;
});
h.on("getDataSrv", "ipfs", () => {
return ipfs;
});
h.on("getDataSrv", "service_id", () => {
return service_id;
});
h.use((req, resp, next) => {
if(req.serviceId === 'callbackSrv' && req.fnName === 'logSize') {
const callParams = {
...req.particleContext,
tetraplets: {
arg0: req.tetraplets[0]
},
};
resp.retCode = ResultCodes.success;
logSize(req.args[0], callParams); resp.result = {}
h.use((req, resp, next) => {
if (req.serviceId === "callbackSrv" && req.fnName === "logSize") {
const callParams = {
...req.particleContext,
tetraplets: {
arg0: req.tetraplets[0],
},
};
resp.retCode = ResultCodes.success;
logSize(req.args[0], callParams);
resp.result = {};
}
next();
});
}
next();
});
h.use((req, resp, next) => {
if (req.serviceId === "callbackSrv" && req.fnName === "error") {
const callParams = {
...req.particleContext,
tetraplets: {
arg0: req.tetraplets[0],
arg1: req.tetraplets[1],
},
};
resp.retCode = ResultCodes.success;
error(req.args[0], req.args[1], callParams);
resp.result = {};
}
next();
});
h.use((req, resp, next) => {
if(req.serviceId === 'callbackSrv' && req.fnName === 'error') {
const callParams = {
...req.particleContext,
tetraplets: {
arg0: req.tetraplets[0],arg1: req.tetraplets[1]
},
};
resp.retCode = ResultCodes.success;
error(req.args[0], req.args[1], callParams); resp.result = {}
h.onEvent("callbackSrv", "response", (args) => {
let [opt] = args;
if (Array.isArray(opt)) {
if (opt.length === 0) {
resolve(null);
}
opt = opt[0];
}
return resolve(opt);
});
}
next();
});
h.onEvent('callbackSrv', 'response', (args) => {
let [opt] = args;
if (Array.isArray(opt)) {
if (opt.length === 0) { resolve(null); }
opt = opt[0];
}
return resolve(opt);
});
h.onEvent('errorHandlingSrv', 'error', (args) => {
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject('Request timed out for put_file_size');
})
if(config && config.ttl) {
r.withTTL(config.ttl)
}
request = r.build();
});
peer.internals.initiateFlow(request!);
return promise;
h.onEvent("errorHandlingSrv", "error", (args) => {
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject("Request timed out for put_file_size");
});
if (config && config.ttl) {
r.withTTL(config.ttl);
}
request = r.build();
});
peer.internals.initiateFlow(request!);
return promise;
}
export function remove_service(
relay: string,
service_id: string,
config?: { ttl?: number }
): Promise<boolean>;
export function remove_service(
peer: FluencePeer,
relay: string,
service_id: string,
config?: { ttl?: number }
): Promise<boolean>;
export function remove_service(...args: any) {
let peer: FluencePeer;
let relay: any;
let service_id: any;
let config: any;
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
relay = args[1];
service_id = args[2];
config = args[3];
} else {
peer = FluencePeer.default;
relay = args[0];
service_id = args[1];
config = args[2];
}
export function remove_service(relay: string, service_id: string, config?: {ttl?: number}) : Promise<boolean>;
export function remove_service(peer: FluencePeer, relay: string, service_id: string, config?: {ttl?: number}) : Promise<boolean>;
export function remove_service(...args: any) {
let peer: FluencePeer;
let relay: any;
let service_id: any;
let config: any;
if (args[0] instanceof FluencePeer) {
peer = args[0];
relay = args[1];
service_id = args[2];
config = args[3];
} else {
peer = FluencePeer.default;
relay = args[0];
service_id = args[1];
config = args[2];
}
let request: RequestFlow;
const promise = new Promise<boolean>((resolve, reject) => {
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
let request: RequestFlow;
const promise = new Promise<boolean>((resolve, reject) => {
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
(xor
(seq
(seq
@ -449,64 +497,75 @@ config = args[2];
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
)
`,
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return peer.connectionInfo.connectedRelay ;
});
h.on('getDataSrv', 'relay', () => {return relay;});
h.on('getDataSrv', 'service_id', () => {return service_id;});
h.onEvent('callbackSrv', 'response', (args) => {
const [res] = args;
resolve(res);
});
`
)
.configHandler((h) => {
h.on("getDataSrv", "-relay-", () => {
return peer.connectionInfo.connectedRelay;
});
h.on("getDataSrv", "relay", () => {
return relay;
});
h.on("getDataSrv", "service_id", () => {
return service_id;
});
h.onEvent("callbackSrv", "response", (args) => {
const [res] = args;
resolve(res);
});
h.onEvent('errorHandlingSrv', 'error', (args) => {
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject('Request timed out for remove_service');
})
if(config && config.ttl) {
r.withTTL(config.ttl)
}
request = r.build();
});
peer.internals.initiateFlow(request!);
return promise;
h.onEvent("errorHandlingSrv", "error", (args) => {
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject("Request timed out for remove_service");
});
if (config && config.ttl) {
r.withTTL(config.ttl);
}
request = r.build();
});
peer.internals.initiateFlow(request!);
return promise;
}
export function add_module(
name: string,
path: string,
config?: { ttl?: number }
): Promise<string>;
export function add_module(
peer: FluencePeer,
name: string,
path: string,
config?: { ttl?: number }
): Promise<string>;
export function add_module(...args: any) {
let peer: FluencePeer;
let name: any;
let path: any;
let config: any;
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
name = args[1];
path = args[2];
config = args[3];
} else {
peer = FluencePeer.default;
name = args[0];
path = args[1];
config = args[2];
}
export function add_module(name: string, path: string, config?: {ttl?: number}) : Promise<string>;
export function add_module(peer: FluencePeer, name: string, path: string, config?: {ttl?: number}) : Promise<string>;
export function add_module(...args: any) {
let peer: FluencePeer;
let name: any;
let path: any;
let config: any;
if (args[0] instanceof FluencePeer) {
peer = args[0];
name = args[1];
path = args[2];
config = args[3];
} else {
peer = FluencePeer.default;
name = args[0];
path = args[1];
config = args[2];
}
let request: RequestFlow;
const promise = new Promise<string>((resolve, reject) => {
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
let request: RequestFlow;
const promise = new Promise<string>((resolve, reject) => {
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
(xor
(seq
(seq
@ -530,70 +589,93 @@ config = args[2];
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
)
`,
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return peer.connectionInfo.connectedRelay ;
});
h.on('getDataSrv', 'name', () => {return name;});
h.on('getDataSrv', 'path', () => {return path;});
h.onEvent('callbackSrv', 'response', (args) => {
const [res] = args;
resolve(res);
});
`
)
.configHandler((h) => {
h.on("getDataSrv", "-relay-", () => {
return peer.connectionInfo.connectedRelay;
});
h.on("getDataSrv", "name", () => {
return name;
});
h.on("getDataSrv", "path", () => {
return path;
});
h.onEvent("callbackSrv", "response", (args) => {
const [res] = args;
resolve(res);
});
h.onEvent('errorHandlingSrv', 'error', (args) => {
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject('Request timed out for add_module');
})
if(config && config.ttl) {
r.withTTL(config.ttl)
}
request = r.build();
});
peer.internals.initiateFlow(request!);
return promise;
h.onEvent("errorHandlingSrv", "error", (args) => {
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject("Request timed out for add_module");
});
if (config && config.ttl) {
r.withTTL(config.ttl);
}
request = r.build();
});
peer.internals.initiateFlow(request!);
return promise;
}
export function deploy_service(
relay: string,
cid: string,
ipfs: string,
error: (
arg0: string,
arg1: string,
callParams: CallParams<"arg0" | "arg1">
) => void,
config?: { ttl?: number }
): Promise<string | null>;
export function deploy_service(
peer: FluencePeer,
relay: string,
cid: string,
ipfs: string,
error: (
arg0: string,
arg1: string,
callParams: CallParams<"arg0" | "arg1">
) => void,
config?: { ttl?: number }
): Promise<string | null>;
export function deploy_service(...args: any) {
let peer: FluencePeer;
let relay: any;
let cid: any;
let ipfs: any;
let error: any;
let config: any;
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
relay = args[1];
cid = args[2];
ipfs = args[3];
error = args[4];
config = args[5];
} else {
peer = FluencePeer.default;
relay = args[0];
cid = args[1];
ipfs = args[2];
error = args[3];
config = args[4];
}
export function deploy_service(relay: string, cid: string, ipfs: string, error: (arg0: string, arg1: string, callParams: CallParams<'arg0' | 'arg1'>) => void, config?: {ttl?: number}) : Promise<string | null>;
export function deploy_service(peer: FluencePeer, relay: string, cid: string, ipfs: string, error: (arg0: string, arg1: string, callParams: CallParams<'arg0' | 'arg1'>) => void, config?: {ttl?: number}) : Promise<string | null>;
export function deploy_service(...args: any) {
let peer: FluencePeer;
let relay: any;
let cid: any;
let ipfs: any;
let error: any;
let config: any;
if (args[0] instanceof FluencePeer) {
peer = args[0];
relay = args[1];
cid = args[2];
ipfs = args[3];
error = args[4];
config = args[5];
} else {
peer = FluencePeer.default;
relay = args[0];
cid = args[1];
ipfs = args[2];
error = args[3];
config = args[4];
}
let request: RequestFlow;
const promise = new Promise<string | null>((resolve, reject) => {
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
let request: RequestFlow;
const promise = new Promise<string | null>((resolve, reject) => {
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
(xor
(seq
(seq
@ -670,56 +752,63 @@ config = args[4];
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 5])
)
`,
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return peer.connectionInfo.connectedRelay ;
});
h.on('getDataSrv', 'relay', () => {return relay;});
h.on('getDataSrv', 'cid', () => {return cid;});
h.on('getDataSrv', 'ipfs', () => {return ipfs;});
`
)
.configHandler((h) => {
h.on("getDataSrv", "-relay-", () => {
return peer.connectionInfo.connectedRelay;
});
h.on("getDataSrv", "relay", () => {
return relay;
});
h.on("getDataSrv", "cid", () => {
return cid;
});
h.on("getDataSrv", "ipfs", () => {
return ipfs;
});
h.use((req, resp, next) => {
if(req.serviceId === 'callbackSrv' && req.fnName === 'error') {
const callParams = {
...req.particleContext,
tetraplets: {
arg0: req.tetraplets[0],arg1: req.tetraplets[1]
},
};
resp.retCode = ResultCodes.success;
error(req.args[0], req.args[1], callParams); resp.result = {}
h.use((req, resp, next) => {
if (req.serviceId === "callbackSrv" && req.fnName === "error") {
const callParams = {
...req.particleContext,
tetraplets: {
arg0: req.tetraplets[0],
arg1: req.tetraplets[1],
},
};
resp.retCode = ResultCodes.success;
error(req.args[0], req.args[1], callParams);
resp.result = {};
}
next();
});
}
next();
});
h.onEvent('callbackSrv', 'response', (args) => {
let [opt] = args;
if (Array.isArray(opt)) {
if (opt.length === 0) { resolve(null); }
opt = opt[0];
}
return resolve(opt);
});
h.onEvent("callbackSrv", "response", (args) => {
let [opt] = args;
if (Array.isArray(opt)) {
if (opt.length === 0) {
resolve(null);
}
opt = opt[0];
}
return resolve(opt);
});
h.onEvent('errorHandlingSrv', 'error', (args) => {
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject('Request timed out for deploy_service');
})
if(config && config.ttl) {
r.withTTL(config.ttl)
}
request = r.build();
});
peer.internals.initiateFlow(request!);
return promise;
h.onEvent("errorHandlingSrv", "error", (args) => {
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject("Request timed out for deploy_service");
});
if (config && config.ttl) {
r.withTTL(config.ttl);
}
request = r.build();
});
peer.internals.initiateFlow(request!);
return promise;
}

View File

@ -40,7 +40,7 @@ export function registerProcessFiles(...args: any) {
let peer: FluencePeer;
let serviceId: any;
let service: any;
if (args[0] instanceof FluencePeer) {
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
} else {
peer = FluencePeer.default;
@ -52,7 +52,7 @@ export function registerProcessFiles(...args: any) {
serviceId = args[1];
}
if (!(args[0] instanceof FluencePeer) && typeof args[0] === "object") {
if (!FluencePeer.isInstance(args[0]) && typeof args[0] === "object") {
service = args[0];
} else if (typeof args[1] === "object") {
service = args[1];

View File

@ -1281,36 +1281,28 @@
}
}
},
"@fluencelabs/aqua-ipfs-ts": {
"version": "0.4.2",
"resolved": "https://registry.npmjs.org/@fluencelabs/aqua-ipfs-ts/-/aqua-ipfs-ts-0.4.2.tgz",
"integrity": "sha512-xuK65UqZdMdVpZULFu8S4IPBjKi7GMnxKLnOdTGGqGP1ULzFOMU2qm9QwNs2OFwFyJYDNQ9Nq3Zg5sqc6Q28yw==",
"requires": {
"@fluencelabs/fluence": "^0.10.0"
}
},
"@fluencelabs/aqua-lib": {
"version": "0.1.14",
"resolved": "https://registry.npmjs.org/@fluencelabs/aqua-lib/-/aqua-lib-0.1.14.tgz",
"integrity": "sha512-H2Q4gIvociUxc4J2mwmH0D+mrU2N2Z+enKCHgBCanMVEE2wZDsZ80GTbDKsQjEq+gpqbnJIk8lJBYW6lyvLJTg=="
},
"@fluencelabs/avm": {
"version": "0.14.3",
"resolved": "https://registry.npmjs.org/@fluencelabs/avm/-/avm-0.14.3.tgz",
"integrity": "sha512-HCRIn8WHshHDkZmoW9ITnEzdr+XcZBo9SjlcbKHd8+ls1LkX4SiGe2tKh3QQwtmJ6xFh9TypTwjWeDYCGIw7JA==",
"version": "0.14.4",
"resolved": "https://registry.npmjs.org/@fluencelabs/avm/-/avm-0.14.4.tgz",
"integrity": "sha512-XyR+1H5k0CAc+mDHOkl81viX8XeW1Yqbw793xbsfUfju5bUb/hqk+gHv3q8lAFdbrCG5P45gdOT08a5RNODZaQ==",
"requires": {
"base64-js": "1.5.1"
}
},
"@fluencelabs/fluence": {
"version": "0.10.1",
"resolved": "https://registry.npmjs.org/@fluencelabs/fluence/-/fluence-0.10.1.tgz",
"integrity": "sha512-xAtZh6B9IIQiDflwNhf4dIvjNX6vFddDvU27fGiDuhiXs92k/dQ6ks3yWL0tqsceSbkz4w7r2vQMfDq6gWkdgg==",
"version": "0.10.4-fix-null-check-416.0",
"resolved": "https://registry.npmjs.org/@fluencelabs/fluence/-/fluence-0.10.4-fix-null-check-416.0.tgz",
"integrity": "sha512-/aZ58z62lj2Esnt8ZDKTJjZCVqmCAZ5O2F8zei4KeKoqm+eyd8XVHFkjRK3PJDSli5pM7TcjJIGJoLFWsU+9iQ==",
"requires": {
"@chainsafe/libp2p-noise": "4.0.0",
"@fluencelabs/avm": "0.14.3",
"@fluencelabs/avm": "0.14.4",
"async": "3.2.0",
"base64-js": "1.3.1",
"base64-js": "1.5.1",
"bs58": "4.0.1",
"cids": "0.8.1",
"it-length-prefixed": "3.0.1",
@ -1321,6 +1313,7 @@
"libp2p-websockets": "0.16.1",
"loglevel": "1.7.0",
"multiaddr": "10.0.0",
"noble-ed25519": "^1.2.5",
"peer-id": "0.15.3",
"uuid": "8.3.0"
},
@ -1330,11 +1323,6 @@
"resolved": "https://registry.npmjs.org/async/-/async-3.2.0.tgz",
"integrity": "sha512-TR2mEZFVOj2pLStYxLht7TyfuRzaydfpxr3k9RpHIzMgw7A64dzsdqCxH1WJyQdoe8T10nDXd9wnEigmiuHIZw=="
},
"base64-js": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.3.1.tgz",
"integrity": "sha512-mLQ4i2QO1ytvGWFWmcngKO//JXAQueZvwEKtjgQFM4jIK0kU+ytMfplL8j+n5mspOfjHwoAg+9yhb7BwAHm36g=="
},
"loglevel": {
"version": "1.7.0",
"resolved": "https://registry.npmjs.org/loglevel/-/loglevel-1.7.0.tgz",
@ -1357,7 +1345,7 @@
"requires": {
"@fluencelabs/aqua-ipfs": "0.4.2",
"@fluencelabs/aqua-lib": "0.1.14",
"@fluencelabs/fluence": "0.10.1",
"@fluencelabs/fluence": "0.10.4-fix-null-check-416.0",
"@fluencelabs/fluence-network-environment": "1.0.10",
"ipfs-http-client": "^50.1.2",
"it-all": "^1.0.5",
@ -1386,25 +1374,6 @@
"uint8arrays": "^2.0.5"
},
"dependencies": {
"bl": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/bl/-/bl-5.0.0.tgz",
"integrity": "sha512-8vxFNZ0pflFfi0WXA3WQXlj6CaMEwsmh63I1CNp0q+wWv8sD0ARx1KovSQd0l2GkwrMIOyedq0EF1FxI+RCZLQ==",
"requires": {
"buffer": "^6.0.3",
"inherits": "^2.0.4",
"readable-stream": "^3.4.0"
}
},
"buffer": {
"version": "6.0.3",
"resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz",
"integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==",
"requires": {
"base64-js": "^1.3.1",
"ieee754": "^1.2.1"
}
},
"it-length-prefixed": {
"version": "5.0.3",
"resolved": "https://registry.npmjs.org/it-length-prefixed/-/it-length-prefixed-5.0.3.tgz",
@ -1415,39 +1384,6 @@
"varint": "^6.0.0"
}
},
"peer-id": {
"version": "0.15.3",
"resolved": "https://registry.npmjs.org/peer-id/-/peer-id-0.15.3.tgz",
"integrity": "sha512-pass5tk6Fbaz7PTD/3fJg2KWqaproHY0B0Ki8GQMEuMjkoLRcS2Vqt9yy6ob/+8uGBmWjRLtbMhaLV4HTyMDfw==",
"requires": {
"class-is": "^1.1.0",
"libp2p-crypto": "^0.19.0",
"minimist": "^1.2.5",
"multiformats": "^9.4.5",
"protobufjs": "^6.10.2",
"uint8arrays": "^3.0.0"
},
"dependencies": {
"class-is": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/class-is/-/class-is-1.1.0.tgz",
"integrity": "sha512-rhjH9AG1fvabIDoGRVH587413LPjTZgmDF9fOFCbFJQV4yuocX1mHxxvXI4g3cGwbVY9wAYIoKlg1N79frJKQw=="
},
"minimist": {
"version": "1.2.5",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw=="
},
"uint8arrays": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/uint8arrays/-/uint8arrays-3.0.0.tgz",
"integrity": "sha512-HRCx0q6O9Bfbp+HHSfQQKD7wU70+lydKVt4EghkdOvlK/NlrF90z+eXV34mUd48rNvVJXwkrMSPpCATkct8fJA==",
"requires": {
"multiformats": "^9.4.2"
}
}
}
},
"varint": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/varint/-/varint-6.0.0.tgz",
@ -1928,9 +1864,9 @@
"integrity": "sha512-H2Q4gIvociUxc4J2mwmH0D+mrU2N2Z+enKCHgBCanMVEE2wZDsZ80GTbDKsQjEq+gpqbnJIk8lJBYW6lyvLJTg=="
},
"@fluencelabs/avm": {
"version": "0.14.3",
"resolved": "https://registry.npmjs.org/@fluencelabs/avm/-/avm-0.14.3.tgz",
"integrity": "sha512-HCRIn8WHshHDkZmoW9ITnEzdr+XcZBo9SjlcbKHd8+ls1LkX4SiGe2tKh3QQwtmJ6xFh9TypTwjWeDYCGIw7JA==",
"version": "0.14.4",
"resolved": "https://registry.npmjs.org/@fluencelabs/avm/-/avm-0.14.4.tgz",
"integrity": "sha512-XyR+1H5k0CAc+mDHOkl81viX8XeW1Yqbw793xbsfUfju5bUb/hqk+gHv3q8lAFdbrCG5P45gdOT08a5RNODZaQ==",
"requires": {
"base64-js": "1.5.1"
},
@ -1943,14 +1879,14 @@
}
},
"@fluencelabs/fluence": {
"version": "0.10.1",
"resolved": "https://registry.npmjs.org/@fluencelabs/fluence/-/fluence-0.10.1.tgz",
"integrity": "sha512-xAtZh6B9IIQiDflwNhf4dIvjNX6vFddDvU27fGiDuhiXs92k/dQ6ks3yWL0tqsceSbkz4w7r2vQMfDq6gWkdgg==",
"version": "0.10.4-fix-null-check-416.0",
"resolved": "https://registry.npmjs.org/@fluencelabs/fluence/-/fluence-0.10.4-fix-null-check-416.0.tgz",
"integrity": "sha512-/aZ58z62lj2Esnt8ZDKTJjZCVqmCAZ5O2F8zei4KeKoqm+eyd8XVHFkjRK3PJDSli5pM7TcjJIGJoLFWsU+9iQ==",
"requires": {
"@chainsafe/libp2p-noise": "4.0.0",
"@fluencelabs/avm": "0.14.3",
"@fluencelabs/avm": "0.14.4",
"async": "3.2.0",
"base64-js": "1.3.1",
"base64-js": "1.5.1",
"bs58": "4.0.1",
"cids": "0.8.1",
"it-length-prefixed": "3.0.1",
@ -1961,8 +1897,16 @@
"libp2p-websockets": "0.16.1",
"loglevel": "1.7.0",
"multiaddr": "10.0.0",
"noble-ed25519": "^1.2.5",
"peer-id": "0.15.3",
"uuid": "8.3.0"
},
"dependencies": {
"base64-js": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz",
"integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA=="
}
}
},
"@fluencelabs/fluence-network-environment": {
@ -2938,6 +2882,13 @@
"node-fetch": "npm:@achingbrain/node-fetch@^2.6.4",
"react-native-fetch-api": "^2.0.0",
"stream-to-it": "^0.2.2"
},
"dependencies": {
"node-fetch": {
"version": "npm:@achingbrain/node-fetch@2.6.7",
"resolved": "https://registry.npmjs.org/@achingbrain/node-fetch/-/node-fetch-2.6.7.tgz",
"integrity": "sha512-iTASGs+HTFK5E4ZqcMsHmeJ4zodyq8L38lZV33jwqcBJYoUt3HjN4+ot+O9/0b+ke8ddE7UgOtVuZN/OkV19/g=="
}
}
},
"it-take": {
@ -3074,6 +3025,13 @@
"node-fetch": "npm:@achingbrain/node-fetch@^2.6.4",
"react-native-fetch-api": "^2.0.0",
"stream-to-it": "^0.2.2"
},
"dependencies": {
"node-fetch": {
"version": "npm:@achingbrain/node-fetch@2.6.7",
"resolved": "https://registry.npmjs.org/@achingbrain/node-fetch/-/node-fetch-2.6.7.tgz",
"integrity": "sha512-iTASGs+HTFK5E4ZqcMsHmeJ4zodyq8L38lZV33jwqcBJYoUt3HjN4+ot+O9/0b+ke8ddE7UgOtVuZN/OkV19/g=="
}
}
},
"multiaddr": {
@ -3234,6 +3192,13 @@
"node-fetch": "npm:@achingbrain/node-fetch@^2.6.4",
"react-native-fetch-api": "^2.0.0",
"stream-to-it": "^0.2.2"
},
"dependencies": {
"node-fetch": {
"version": "npm:@achingbrain/node-fetch@2.6.7",
"resolved": "https://registry.npmjs.org/@achingbrain/node-fetch/-/node-fetch-2.6.7.tgz",
"integrity": "sha512-iTASGs+HTFK5E4ZqcMsHmeJ4zodyq8L38lZV33jwqcBJYoUt3HjN4+ot+O9/0b+ke8ddE7UgOtVuZN/OkV19/g=="
}
}
},
"multiaddr": {
@ -3781,9 +3746,9 @@
"integrity": "sha512-EElupuWhHVStUgUY+OfTJIS2MZed96lDrAXzJUuqiiqLnIKoBRqtX1ZG2oR0bGDsSppmz83MtzCeKLZ9TVAUxQ=="
},
"it-merge": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/it-merge/-/it-merge-1.0.2.tgz",
"integrity": "sha512-bp+h4X3tQ83/a2MvaeP4nRi+52z2AO2y8tf2OzDdaSXKMC0n0gVtHrJUDaE+kiIkBiUtTt1hp7vJHMM0VtCfGA==",
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/it-merge/-/it-merge-1.0.3.tgz",
"integrity": "sha512-FTIcv8VGOkSnq5WGoepN+ag/DVdSVZk7pALuduxyGlErH7uzcvZD3IXHXY47ViptHQFbga2rU9SPlFmC7ttRBA==",
"requires": {
"it-pushable": "^1.4.0"
}
@ -4478,6 +4443,11 @@
"resolved": "https://registry.npmjs.org/netmask/-/netmask-2.0.2.tgz",
"integrity": "sha512-dBpDMdxv9Irdq66304OLfEmQ9tbNRFnFTuZiLo+bD+r332bBmMJ8GBLXklIXXgxd3+v9+KUnZaUR5PJMa75Gsg=="
},
"noble-ed25519": {
"version": "1.2.5",
"resolved": "https://registry.npmjs.org/noble-ed25519/-/noble-ed25519-1.2.5.tgz",
"integrity": "sha512-7vst+4UhM5QU3jJ3pUqPMKBCOePrxBojmoQa59qcSnYvjFF/T4jqb4WISlfslcWyBw7G5H9V/acpcAxMd8DzUQ=="
},
"node-addon-api": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-2.0.2.tgz",
@ -4980,9 +4950,9 @@
}
},
"ws": {
"version": "7.5.4",
"resolved": "https://registry.npmjs.org/ws/-/ws-7.5.4.tgz",
"integrity": "sha512-zP9z6GXm6zC27YtspwH99T3qTG7bBFv2VIkeHstMLrLlDJuzA7tQ5ls3OJ1hOGGCzTQPniNJoHXIAOS0Jljohg=="
"version": "7.5.5",
"resolved": "https://registry.npmjs.org/ws/-/ws-7.5.5.tgz",
"integrity": "sha512-BAkMFcAzl8as1G/hArkxOxq3G7pjUqQ3gzYbLL0/5zNkph70e+lCoxBGnm6AW1+/aiNeV4fnKqZ8m4GZewmH2w=="
},
"xml2js": {
"version": "0.4.23",
@ -7841,7 +7811,8 @@
"binary-extensions": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz",
"integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA=="
"integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==",
"optional": true
},
"bindings": {
"version": "1.5.0",
@ -8366,6 +8337,7 @@
"version": "3.5.2",
"resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.2.tgz",
"integrity": "sha512-ekGhOnNVPgT77r4K/U3GDhu+FQ2S8TnK/s2KbIGXi0SZWuwkZ2QNyfWdZW+TVfn84DpEP7rLeCt2UI6bJ8GwbQ==",
"optional": true,
"requires": {
"anymatch": "~3.1.2",
"braces": "~3.0.2",
@ -8377,148 +8349,6 @@
"readdirp": "~3.6.0"
}
},
"chokidar-cli": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/chokidar-cli/-/chokidar-cli-2.1.0.tgz",
"integrity": "sha512-6n21AVpW6ywuEPoxJcLXMA2p4T+SLjWsXKny/9yTWFz0kKxESI3eUylpeV97LylING/27T/RVTY0f2/0QaWq9Q==",
"dev": true,
"requires": {
"chokidar": "^3.2.3",
"lodash.debounce": "^4.0.8",
"lodash.throttle": "^4.1.1",
"yargs": "^13.3.0"
},
"dependencies": {
"ansi-regex": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz",
"integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==",
"dev": true
},
"camelcase": {
"version": "5.3.1",
"resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz",
"integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==",
"dev": true
},
"cliui": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/cliui/-/cliui-5.0.0.tgz",
"integrity": "sha512-PYeGSEmmHM6zvoef2w8TPzlrnNpXIjTipYK780YswmIP9vjxmd6Y2a3CB2Ks6/AU8NHjZugXvo8w3oWM2qnwXA==",
"dev": true,
"requires": {
"string-width": "^3.1.0",
"strip-ansi": "^5.2.0",
"wrap-ansi": "^5.1.0"
}
},
"emoji-regex": {
"version": "7.0.3",
"resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-7.0.3.tgz",
"integrity": "sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA==",
"dev": true
},
"find-up": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz",
"integrity": "sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg==",
"dev": true,
"requires": {
"locate-path": "^3.0.0"
}
},
"is-fullwidth-code-point": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz",
"integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=",
"dev": true
},
"locate-path": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/locate-path/-/locate-path-3.0.0.tgz",
"integrity": "sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A==",
"dev": true,
"requires": {
"p-locate": "^3.0.0",
"path-exists": "^3.0.0"
}
},
"p-locate": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/p-locate/-/p-locate-3.0.0.tgz",
"integrity": "sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ==",
"dev": true,
"requires": {
"p-limit": "^2.0.0"
}
},
"path-exists": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz",
"integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=",
"dev": true
},
"string-width": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz",
"integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==",
"dev": true,
"requires": {
"emoji-regex": "^7.0.1",
"is-fullwidth-code-point": "^2.0.0",
"strip-ansi": "^5.1.0"
}
},
"strip-ansi": {
"version": "5.2.0",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz",
"integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==",
"dev": true,
"requires": {
"ansi-regex": "^4.1.0"
}
},
"wrap-ansi": {
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-5.1.0.tgz",
"integrity": "sha512-QC1/iN/2/RPVJ5jYK8BGttj5z83LmSKmvbvrXPNCLZSEb32KKVDJDl/MOt2N01qU2H/FkzEa9PKto1BqDjtd7Q==",
"dev": true,
"requires": {
"ansi-styles": "^3.2.0",
"string-width": "^3.0.0",
"strip-ansi": "^5.0.0"
}
},
"yargs": {
"version": "13.3.2",
"resolved": "https://registry.npmjs.org/yargs/-/yargs-13.3.2.tgz",
"integrity": "sha512-AX3Zw5iPruN5ie6xGRIDgqkT+ZhnRlZMLMHAs8tg7nRruy2Nb+i5o9bwghAogtM08q1dpr2LVoS8KSTMYpWXUw==",
"dev": true,
"requires": {
"cliui": "^5.0.0",
"find-up": "^3.0.0",
"get-caller-file": "^2.0.1",
"require-directory": "^2.1.1",
"require-main-filename": "^2.0.0",
"set-blocking": "^2.0.0",
"string-width": "^3.0.0",
"which-module": "^2.0.0",
"y18n": "^4.0.0",
"yargs-parser": "^13.1.2"
}
},
"yargs-parser": {
"version": "13.1.2",
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-13.1.2.tgz",
"integrity": "sha512-3lbsNRf/j+A4QuSZfDRA7HRSfWrzO0YjqTJd5kjAq37Zep1CEgaYmrH9Q3GwPiB9cHyd1Y1UwggGhJGoxipbzg==",
"dev": true,
"requires": {
"camelcase": "^5.0.0",
"decamelize": "^1.2.0"
}
}
}
},
"chownr": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/chownr/-/chownr-2.0.0.tgz",
@ -13256,6 +13086,7 @@
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz",
"integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==",
"optional": true,
"requires": {
"binary-extensions": "^2.0.0"
}
@ -13827,9 +13658,9 @@
"integrity": "sha512-EElupuWhHVStUgUY+OfTJIS2MZed96lDrAXzJUuqiiqLnIKoBRqtX1ZG2oR0bGDsSppmz83MtzCeKLZ9TVAUxQ=="
},
"it-merge": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/it-merge/-/it-merge-1.0.2.tgz",
"integrity": "sha512-bp+h4X3tQ83/a2MvaeP4nRi+52z2AO2y8tf2OzDdaSXKMC0n0gVtHrJUDaE+kiIkBiUtTt1hp7vJHMM0VtCfGA==",
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/it-merge/-/it-merge-1.0.3.tgz",
"integrity": "sha512-FTIcv8VGOkSnq5WGoepN+ag/DVdSVZk7pALuduxyGlErH7uzcvZD3IXHXY47ViptHQFbga2rU9SPlFmC7ttRBA==",
"requires": {
"it-pushable": "^1.4.0"
}
@ -16064,12 +15895,6 @@
"lodash._reinterpolate": "^3.0.0"
}
},
"lodash.throttle": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/lodash.throttle/-/lodash.throttle-4.1.1.tgz",
"integrity": "sha1-wj6RtxAkKscMN/HhzaknTMOb8vQ=",
"dev": true
},
"lodash.truncate": {
"version": "4.4.2",
"resolved": "https://registry.npmjs.org/lodash.truncate/-/lodash.truncate-4.4.2.tgz",
@ -16944,6 +16769,11 @@
}
}
},
"noble-ed25519": {
"version": "1.2.5",
"resolved": "https://registry.npmjs.org/noble-ed25519/-/noble-ed25519-1.2.5.tgz",
"integrity": "sha512-7vst+4UhM5QU3jJ3pUqPMKBCOePrxBojmoQa59qcSnYvjFF/T4jqb4WISlfslcWyBw7G5H9V/acpcAxMd8DzUQ=="
},
"node-addon-api": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-2.0.2.tgz",
@ -19613,6 +19443,7 @@
"version": "3.6.0",
"resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz",
"integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==",
"optional": true,
"requires": {
"picomatch": "^2.2.1"
}

View File

@ -4,7 +4,7 @@
"private": true,
"dependencies": {
"@fluencelabs/ipfs-execution-aqua": "file:../aqua",
"@fluencelabs/fluence": "0.11.0",
"@fluencelabs/fluence": "0.10.4-fix-null-check-416.0",
"@fluencelabs/fluence-network-environment": "1.0.10",
"@fluencelabs/aqua-lib": "0.1.14",
"@testing-library/jest-dom": "^5.14.1",

View File

@ -4,8 +4,8 @@ import { TextWithLabel } from "./TextInput";
export const ConnectedInfo = () => {
const selfPeerId = useRecoilValue(selfPeerIdState);
const client = useRecoilValue(isConnectedState);
if (client === null) {
const isConnected = useRecoilValue(isConnectedState);
if (!isConnected) {
return <></>;
}

View File

@ -23,6 +23,8 @@ import { decapsulateP2P, fromOption } from "./util";
export const relayNodes = [krasnodar[0], krasnodar[1], krasnodar[2]];
const requestRpcAddr = async () => {
const tmp = FluencePeer.default as any;
console.dir(tmp);
let result = await get_external_api_multiaddr(
FluencePeer.default.connectionInfo.connectedRelay!
);
@ -40,9 +42,9 @@ export const useClientConnect = () => {
const connect = async (relayPeerId: string) => {
try {
await FluencePeer.default.init({ connectTo: relayPeerId });
setIsConnected(true);
setRelay(FluencePeer.default.connectionInfo.connectedRelay);
setSelfPeerId(FluencePeer.default.connectionInfo.selfPeerId);
setIsConnected(true);
const addr = await requestRpcAddr();
setRpcAddr(addr!);
} catch (err) {

View File

@ -1,47 +1,52 @@
/**
*
* This file is auto-generated. Do not edit manually: changes may be erased.
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
* If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
* Aqua version: 0.3.0-222
*
*/
import { FluencePeer } from '@fluencelabs/fluence';
import { FluencePeer } from "@fluencelabs/fluence";
import {
ResultCodes,
RequestFlow,
RequestFlowBuilder,
CallParams,
} from '@fluencelabs/fluence/dist/internal/compilerSupport/v1';
ResultCodes,
RequestFlow,
RequestFlowBuilder,
CallParams,
} from "@fluencelabs/fluence/dist/internal/compilerSupport/v1";
// Services
// Functions
export function getRelayTime(relayPeerId: string, config?: {ttl?: number}) : Promise<number>;
export function getRelayTime(peer: FluencePeer, relayPeerId: string, config?: {ttl?: number}) : Promise<number>;
export function getRelayTime(...args) {
let peer: FluencePeer;
let relayPeerId;
let config;
if (args[0] instanceof FluencePeer) {
peer = args[0];
relayPeerId = args[1];
config = args[2];
} else {
peer = FluencePeer.default;
relayPeerId = args[0];
config = args[1];
}
let request: RequestFlow;
const promise = new Promise<number>((resolve, reject) => {
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
export function getRelayTime(
relayPeerId: string,
config?: { ttl?: number }
): Promise<number>;
export function getRelayTime(
peer: FluencePeer,
relayPeerId: string,
config?: { ttl?: number }
): Promise<number>;
export function getRelayTime(...args) {
let peer: FluencePeer;
let relayPeerId;
let config;
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
relayPeerId = args[1];
config = args[2];
} else {
peer = FluencePeer.default;
relayPeerId = args[0];
config = args[1];
}
let request: RequestFlow;
const promise = new Promise<number>((resolve, reject) => {
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
(xor
(seq
(seq
@ -71,33 +76,34 @@ config = args[1];
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
)
`,
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return peer.connectionInfo.connectedRelay ;
});
h.on('getDataSrv', 'relayPeerId', () => {return relayPeerId;});
h.onEvent('callbackSrv', 'response', (args) => {
const [res] = args;
resolve(res);
});
`
)
.configHandler((h) => {
h.on("getDataSrv", "-relay-", () => {
return peer.connectionInfo.connectedRelay;
});
h.on("getDataSrv", "relayPeerId", () => {
return relayPeerId;
});
h.onEvent("callbackSrv", "response", (args) => {
const [res] = args;
resolve(res);
});
h.onEvent('errorHandlingSrv', 'error', (args) => {
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject('Request timed out for getRelayTime');
})
if(config && config.ttl) {
r.withTTL(config.ttl)
}
request = r.build();
});
peer.internals.initiateFlow(request!);
return promise;
h.onEvent("errorHandlingSrv", "error", (args) => {
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject("Request timed out for getRelayTime");
});
if (config && config.ttl) {
r.withTTL(config.ttl);
}
request = r.build();
});
peer.internals.initiateFlow(request!);
return promise;
}

View File

@ -1,105 +1,112 @@
/**
*
* This file is auto-generated. Do not edit manually: changes may be erased.
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
* If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
* Aqua version: 0.3.0-222
*
*/
import { FluencePeer } from '@fluencelabs/fluence';
import { FluencePeer } from "@fluencelabs/fluence";
import {
ResultCodes,
RequestFlow,
RequestFlowBuilder,
CallParams,
} from '@fluencelabs/fluence/dist/internal/compilerSupport/v1';
ResultCodes,
RequestFlow,
RequestFlowBuilder,
CallParams,
} from "@fluencelabs/fluence/dist/internal/compilerSupport/v1";
// Services
export interface HelloWorldDef {
hello: (str: string, callParams: CallParams<'str'>) => void;
}
export function registerHelloWorld(service: HelloWorldDef): void;
export function registerHelloWorld(serviceId: string, service: HelloWorldDef): void;
export function registerHelloWorld(peer: FluencePeer, service: HelloWorldDef): void;
export function registerHelloWorld(peer: FluencePeer, serviceId: string, service: HelloWorldDef): void;
export function registerHelloWorld(...args) {
let peer: FluencePeer;
let serviceId;
let service;
if (args[0] instanceof FluencePeer) {
peer = args[0];
} else {
peer = FluencePeer.default;
}
if (typeof args[0] === 'string') {
serviceId = args[0];
} else if (typeof args[1] === 'string') {
serviceId = args[1];
}
else {
serviceId = "hello-world"
export interface HelloWorldDef {
hello: (str: string, callParams: CallParams<"str">) => void;
}
if (!(args[0] instanceof FluencePeer) && typeof args[0] === 'object') {
service = args[0];
} else if (typeof args[1] === 'object') {
service = args[1];
} else {
service = args[2];
export function registerHelloWorld(service: HelloWorldDef): void;
export function registerHelloWorld(
serviceId: string,
service: HelloWorldDef
): void;
export function registerHelloWorld(
peer: FluencePeer,
service: HelloWorldDef
): void;
export function registerHelloWorld(
peer: FluencePeer,
serviceId: string,
service: HelloWorldDef
): void;
export function registerHelloWorld(...args) {
let peer: FluencePeer;
let serviceId;
let service;
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
} else {
peer = FluencePeer.default;
}
if (typeof args[0] === "string") {
serviceId = args[0];
} else if (typeof args[1] === "string") {
serviceId = args[1];
} else {
serviceId = "hello-world";
}
if (!FluencePeer.isInstance(args[0]) && typeof args[0] === "object") {
service = args[0];
} else if (typeof args[1] === "object") {
service = args[1];
} else {
service = args[2];
}
peer.internals.callServiceHandler.use((req, resp, next) => {
if (req.serviceId !== serviceId) {
next();
return;
}
peer.internals.callServiceHandler.use((req, resp, next) => {
if (req.serviceId !== serviceId) {
next();
return;
}
if (req.fnName === 'hello') {
const callParams = {
...req.particleContext,
tetraplets: {
str: req.tetraplets[0]
},
};
resp.retCode = ResultCodes.success;
service.hello(req.args[0], callParams); resp.result = {}
if (req.fnName === "hello") {
const callParams = {
...req.particleContext,
tetraplets: {
str: req.tetraplets[0],
},
};
resp.retCode = ResultCodes.success;
service.hello(req.args[0], callParams);
resp.result = {};
}
}
next();
});
}
next();
});
}
// Functions
export function sayHello(config?: {ttl?: number}) : Promise<void>;
export function sayHello(peer: FluencePeer, config?: {ttl?: number}) : Promise<void>;
export function sayHello(...args) {
let peer: FluencePeer;
let config;
if (args[0] instanceof FluencePeer) {
peer = args[0];
config = args[1];
} else {
peer = FluencePeer.default;
config = args[0];
}
let request: RequestFlow;
const promise = new Promise<void>((resolve, reject) => {
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
export function sayHello(config?: { ttl?: number }): Promise<void>;
export function sayHello(
peer: FluencePeer,
config?: { ttl?: number }
): Promise<void>;
export function sayHello(...args) {
let peer: FluencePeer;
let config;
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
config = args[1];
} else {
peer = FluencePeer.default;
config = args[0];
}
let request: RequestFlow;
const promise = new Promise<void>((resolve, reject) => {
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
(xor
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
@ -108,32 +115,29 @@ export function registerHelloWorld(peer: FluencePeer, serviceId: string, service
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
)
`,
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return peer.connectionInfo.connectedRelay ;
});
h.onEvent('callbackSrv', 'response', (args) => {
});
`
)
.configHandler((h) => {
h.on("getDataSrv", "-relay-", () => {
return peer.connectionInfo.connectedRelay;
});
h.onEvent('errorHandlingSrv', 'error', (args) => {
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject('Request timed out for sayHello');
})
if(config && config.ttl) {
r.withTTL(config.ttl)
}
request = r.build();
});
peer.internals.initiateFlow(request!);
return Promise.race([promise, Promise.resolve()]);
h.onEvent("callbackSrv", "response", (args) => {});
h.onEvent("errorHandlingSrv", "error", (args) => {
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject("Request timed out for sayHello");
});
if (config && config.ttl) {
r.withTTL(config.ttl);
}
request = r.build();
});
peer.internals.initiateFlow(request!);
return Promise.race([promise, Promise.resolve()]);
}

View File

@ -37,7 +37,7 @@ export function registerCalc(...args) {
let peer: FluencePeer;
let serviceId;
let service;
if (args[0] instanceof FluencePeer) {
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
} else {
peer = FluencePeer.default;
@ -51,7 +51,7 @@ export function registerCalc(...args) {
serviceId = "calc";
}
if (!(args[0] instanceof FluencePeer) && typeof args[0] === "object") {
if (!FluencePeer.isInstance(args[0]) && typeof args[0] === "object") {
service = args[0];
} else if (typeof args[1] === "object") {
service = args[1];

View File

@ -1,45 +1,46 @@
/**
*
* This file is auto-generated. Do not edit manually: changes may be erased.
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
* If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
* Aqua version: 0.3.0-222
*
*/
import { FluencePeer } from '@fluencelabs/fluence';
import { FluencePeer } from "@fluencelabs/fluence";
import {
ResultCodes,
RequestFlow,
RequestFlowBuilder,
CallParams,
} from '@fluencelabs/fluence/dist/internal/compilerSupport/v1';
ResultCodes,
RequestFlow,
RequestFlowBuilder,
CallParams,
} from "@fluencelabs/fluence/dist/internal/compilerSupport/v1";
// Services
// Functions
export function demoCalculation(config?: {ttl?: number}) : Promise<number>;
export function demoCalculation(peer: FluencePeer, config?: {ttl?: number}) : Promise<number>;
export function demoCalculation(...args) {
let peer: FluencePeer;
let config;
if (args[0] instanceof FluencePeer) {
peer = args[0];
config = args[1];
} else {
peer = FluencePeer.default;
config = args[0];
}
let request: RequestFlow;
const promise = new Promise<number>((resolve, reject) => {
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
export function demoCalculation(config?: { ttl?: number }): Promise<number>;
export function demoCalculation(
peer: FluencePeer,
config?: { ttl?: number }
): Promise<number>;
export function demoCalculation(...args) {
let peer: FluencePeer;
let config;
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
config = args[1];
} else {
peer = FluencePeer.default;
config = args[0];
}
let request: RequestFlow;
const promise = new Promise<number>((resolve, reject) => {
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
(xor
(seq
(seq
@ -90,33 +91,32 @@ import {
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
)
`,
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return peer.connectionInfo.connectedRelay ;
});
h.onEvent('callbackSrv', 'response', (args) => {
const [res] = args;
resolve(res);
});
`
)
.configHandler((h) => {
h.on("getDataSrv", "-relay-", () => {
return peer.connectionInfo.connectedRelay;
});
h.onEvent('errorHandlingSrv', 'error', (args) => {
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject('Request timed out for demoCalculation');
})
if(config && config.ttl) {
r.withTTL(config.ttl)
}
request = r.build();
});
peer.internals.initiateFlow(request!);
return promise;
h.onEvent("callbackSrv", "response", (args) => {
const [res] = args;
resolve(res);
});
h.onEvent("errorHandlingSrv", "error", (args) => {
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject("Request timed out for demoCalculation");
});
if (config && config.ttl) {
r.withTTL(config.ttl);
}
request = r.build();
});
peer.internals.initiateFlow(request!);
return promise;
}

View File

@ -38,7 +38,7 @@ export function registerHelloPeer(...args: any) {
let peer: FluencePeer;
let serviceId: any;
let service: any;
if (args[0] instanceof FluencePeer) {
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
} else {
peer = FluencePeer.default;
@ -52,7 +52,7 @@ export function registerHelloPeer(...args: any) {
serviceId = "HelloPeer";
}
if (!(args[0] instanceof FluencePeer) && typeof args[0] === "object") {
if (!FluencePeer.isInstance(args[0]) && typeof args[0] === "object") {
service = args[0];
} else if (typeof args[1] === "object") {
service = args[1];
@ -99,7 +99,7 @@ export function sayHello(...args: any) {
let targetPeerId: any;
let targetRelayPeerId: any;
let config: any;
if (args[0] instanceof FluencePeer) {
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
targetPeerId = args[1];
targetRelayPeerId = args[2];

View File

@ -1,167 +1,183 @@
/**
*
* This file is auto-generated. Do not edit manually: changes may be erased.
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
* If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
* Aqua version: 0.3.0-224
*
*/
import { FluencePeer } from '@fluencelabs/fluence';
import { FluencePeer } from "@fluencelabs/fluence";
import {
ResultCodes,
RequestFlow,
RequestFlowBuilder,
CallParams,
} from '@fluencelabs/fluence/dist/internal/compilerSupport/v1';
ResultCodes,
RequestFlow,
RequestFlowBuilder,
CallParams,
} from "@fluencelabs/fluence/dist/internal/compilerSupport/v1";
// Services
export interface HelloWorldDef {
hello: (from: string, callParams: CallParams<'from'>) => {msg:string;reply:string};
}
export function registerHelloWorld(serviceId: string, service: HelloWorldDef): void;
export function registerHelloWorld(peer: FluencePeer, serviceId: string, service: HelloWorldDef): void;
export function registerHelloWorld(...args: any) {
let peer: FluencePeer;
let serviceId: any;
let service: any;
if (args[0] instanceof FluencePeer) {
peer = args[0];
} else {
peer = FluencePeer.default;
}
if (typeof args[0] === 'string') {
serviceId = args[0];
} else if (typeof args[1] === 'string') {
serviceId = args[1];
}
if (!(args[0] instanceof FluencePeer) && typeof args[0] === 'object') {
service = args[0];
} else if (typeof args[1] === 'object') {
service = args[1];
} else {
service = args[2];
}
peer.internals.callServiceHandler.use((req, resp, next) => {
if (req.serviceId !== serviceId) {
next();
return;
}
if (req.fnName === 'hello') {
const callParams = {
...req.particleContext,
tetraplets: {
from: req.tetraplets[0]
},
};
resp.retCode = ResultCodes.success;
resp.result = service.hello(req.args[0], callParams)
}
next();
});
}
export interface HelloPeerDef {
hello: (message: string, callParams: CallParams<'message'>) => string;
}
export function registerHelloPeer(service: HelloPeerDef): void;
export function registerHelloPeer(serviceId: string, service: HelloPeerDef): void;
export function registerHelloPeer(peer: FluencePeer, service: HelloPeerDef): void;
export function registerHelloPeer(peer: FluencePeer, serviceId: string, service: HelloPeerDef): void;
export function registerHelloPeer(...args: any) {
let peer: FluencePeer;
let serviceId: any;
let service: any;
if (args[0] instanceof FluencePeer) {
peer = args[0];
} else {
peer = FluencePeer.default;
}
if (typeof args[0] === 'string') {
serviceId = args[0];
} else if (typeof args[1] === 'string') {
serviceId = args[1];
}
else {
serviceId = "HelloPeer"
export interface HelloWorldDef {
hello: (
from: string,
callParams: CallParams<"from">
) => { msg: string; reply: string };
}
if (!(args[0] instanceof FluencePeer) && typeof args[0] === 'object') {
service = args[0];
} else if (typeof args[1] === 'object') {
service = args[1];
} else {
service = args[2];
export function registerHelloWorld(
serviceId: string,
service: HelloWorldDef
): void;
export function registerHelloWorld(
peer: FluencePeer,
serviceId: string,
service: HelloWorldDef
): void;
export function registerHelloWorld(...args: any) {
let peer: FluencePeer;
let serviceId: any;
let service: any;
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
} else {
peer = FluencePeer.default;
}
if (typeof args[0] === "string") {
serviceId = args[0];
} else if (typeof args[1] === "string") {
serviceId = args[1];
}
if (!FluencePeer.isInstance(args[0]) && typeof args[0] === "object") {
service = args[0];
} else if (typeof args[1] === "object") {
service = args[1];
} else {
service = args[2];
}
peer.internals.callServiceHandler.use((req, resp, next) => {
if (req.serviceId !== serviceId) {
next();
return;
}
peer.internals.callServiceHandler.use((req, resp, next) => {
if (req.serviceId !== serviceId) {
next();
return;
}
if (req.fnName === 'hello') {
const callParams = {
...req.particleContext,
tetraplets: {
message: req.tetraplets[0]
},
};
resp.retCode = ResultCodes.success;
resp.result = service.hello(req.args[0], callParams)
if (req.fnName === "hello") {
const callParams = {
...req.particleContext,
tetraplets: {
from: req.tetraplets[0],
},
};
resp.retCode = ResultCodes.success;
resp.result = service.hello(req.args[0], callParams);
}
}
next();
});
}
next();
});
}
export interface HelloPeerDef {
hello: (message: string, callParams: CallParams<"message">) => string;
}
export function registerHelloPeer(service: HelloPeerDef): void;
export function registerHelloPeer(
serviceId: string,
service: HelloPeerDef
): void;
export function registerHelloPeer(
peer: FluencePeer,
service: HelloPeerDef
): void;
export function registerHelloPeer(
peer: FluencePeer,
serviceId: string,
service: HelloPeerDef
): void;
export function registerHelloPeer(...args: any) {
let peer: FluencePeer;
let serviceId: any;
let service: any;
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
} else {
peer = FluencePeer.default;
}
if (typeof args[0] === "string") {
serviceId = args[0];
} else if (typeof args[1] === "string") {
serviceId = args[1];
} else {
serviceId = "HelloPeer";
}
if (!FluencePeer.isInstance(args[0]) && typeof args[0] === "object") {
service = args[0];
} else if (typeof args[1] === "object") {
service = args[1];
} else {
service = args[2];
}
peer.internals.callServiceHandler.use((req, resp, next) => {
if (req.serviceId !== serviceId) {
next();
return;
}
if (req.fnName === "hello") {
const callParams = {
...req.particleContext,
tetraplets: {
message: req.tetraplets[0],
},
};
resp.retCode = ResultCodes.success;
resp.result = service.hello(req.args[0], callParams);
}
next();
});
}
// Functions
export function sayHello(targetPeerId: string, targetRelayPeerId: string, config?: {ttl?: number}) : Promise<string>;
export function sayHello(peer: FluencePeer, targetPeerId: string, targetRelayPeerId: string, config?: {ttl?: number}) : Promise<string>;
export function sayHello(...args: any) {
let peer: FluencePeer;
let targetPeerId: any;
let targetRelayPeerId: any;
let config: any;
if (args[0] instanceof FluencePeer) {
peer = args[0];
targetPeerId = args[1];
targetRelayPeerId = args[2];
config = args[3];
} else {
peer = FluencePeer.default;
targetPeerId = args[0];
targetRelayPeerId = args[1];
config = args[2];
}
let request: RequestFlow;
const promise = new Promise<string>((resolve, reject) => {
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
export function sayHello(
targetPeerId: string,
targetRelayPeerId: string,
config?: { ttl?: number }
): Promise<string>;
export function sayHello(
peer: FluencePeer,
targetPeerId: string,
targetRelayPeerId: string,
config?: { ttl?: number }
): Promise<string>;
export function sayHello(...args: any) {
let peer: FluencePeer;
let targetPeerId: any;
let targetRelayPeerId: any;
let config: any;
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
targetPeerId = args[1];
targetRelayPeerId = args[2];
config = args[3];
} else {
peer = FluencePeer.default;
targetPeerId = args[0];
targetRelayPeerId = args[1];
config = args[2];
}
let request: RequestFlow;
const promise = new Promise<string>((resolve, reject) => {
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
(xor
(seq
(seq
@ -215,34 +231,37 @@ config = args[2];
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
)
`,
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return peer.connectionInfo.connectedRelay ;
});
h.on('getDataSrv', 'targetPeerId', () => {return targetPeerId;});
h.on('getDataSrv', 'targetRelayPeerId', () => {return targetRelayPeerId;});
h.onEvent('callbackSrv', 'response', (args) => {
const [res] = args;
resolve(res);
});
`
)
.configHandler((h) => {
h.on("getDataSrv", "-relay-", () => {
return peer.connectionInfo.connectedRelay;
});
h.on("getDataSrv", "targetPeerId", () => {
return targetPeerId;
});
h.on("getDataSrv", "targetRelayPeerId", () => {
return targetRelayPeerId;
});
h.onEvent("callbackSrv", "response", (args) => {
const [res] = args;
resolve(res);
});
h.onEvent('errorHandlingSrv', 'error', (args) => {
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject('Request timed out for sayHello');
})
if(config && config.ttl) {
r.withTTL(config.ttl)
}
request = r.build();
});
peer.internals.initiateFlow(request!);
return promise;
h.onEvent("errorHandlingSrv", "error", (args) => {
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject("Request timed out for sayHello");
});
if (config && config.ttl) {
r.withTTL(config.ttl);
}
request = r.build();
});
peer.internals.initiateFlow(request!);
return promise;
}