mirror of
https://github.com/fluencelabs/examples
synced 2024-12-04 19:20:17 +00:00
trying to compiler aqua directly in the project with the code
This commit is contained in:
parent
10554299d9
commit
29daa3078a
3855
aqua-examples/aqua-ipfs-integration/web/package-lock.json
generated
3855
aqua-examples/aqua-ipfs-integration/web/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -3,7 +3,6 @@
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@fluencelabs/ipfs-execution-aqua": "file:../aqua",
|
||||
"@fluencelabs/fluence": "0.11.0",
|
||||
"@fluencelabs/fluence-network-environment": "1.0.10",
|
||||
"@fluencelabs/aqua-lib": "0.1.14",
|
||||
@ -27,7 +26,8 @@
|
||||
"start": "react-scripts start",
|
||||
"build": "react-scripts build",
|
||||
"test": "react-scripts test",
|
||||
"eject": "react-scripts eject"
|
||||
"eject": "react-scripts eject",
|
||||
"compile-aqua": "aqua --import . -i ./aqua/ -o ./src/_aqua"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": [
|
||||
@ -48,6 +48,9 @@
|
||||
]
|
||||
},
|
||||
"devDependencies": {
|
||||
"node-sass": "^6.0.1"
|
||||
"@fluencelabs/aqua": "^0.3.0-225",
|
||||
"node-sass": "^6.0.1",
|
||||
"@fluencelabs/aqua-ipfs": "0.4.2",
|
||||
"@fluencelabs/aqua-lib": "0.1.14"
|
||||
}
|
||||
}
|
||||
|
706
aqua-examples/aqua-ipfs-integration/web/src/_aqua/exports.ts
Normal file
706
aqua-examples/aqua-ipfs-integration/web/src/_aqua/exports.ts
Normal file
@ -0,0 +1,706 @@
|
||||
/**
|
||||
*
|
||||
* This file is auto-generated. Do not edit manually: changes may be erased.
|
||||
* 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-225
|
||||
*
|
||||
*/
|
||||
import { FluencePeer } from '@fluencelabs/fluence';
|
||||
import {
|
||||
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(
|
||||
`
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||
(call %init_peer_id% ("getDataSrv" "node") [] node)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "timeout_sec") [] timeout_sec)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(call node ("aqua-ipfs" "set_timeout") [timeout_sec])
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||
)
|
||||
)
|
||||
)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 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) => {
|
||||
|
||||
});
|
||||
|
||||
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 (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(
|
||||
`
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||
(call %init_peer_id% ("getDataSrv" "node") [] node)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "cid") [] cid)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "from") [] from)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(seq
|
||||
(call node ("aqua-ipfs" "get_from") [cid from] get)
|
||||
(xor
|
||||
(match get.$.success! true
|
||||
(xor
|
||||
(seq
|
||||
(call node ("aqua-ipfs" "put") [get.$.path!] put)
|
||||
(xor
|
||||
(match put.$.success! true
|
||||
(xor
|
||||
(ap put.$.hash! $localCid)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||
)
|
||||
)
|
||||
)
|
||||
(par
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "error") ["Ipfs.put failed" put.$.error!])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||
)
|
||||
)
|
||||
(null)
|
||||
)
|
||||
)
|
||||
)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||
)
|
||||
)
|
||||
)
|
||||
(par
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "error") ["Ipfs.get failed" get.$.error!])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
|
||||
)
|
||||
)
|
||||
(null)
|
||||
)
|
||||
)
|
||||
)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 5])
|
||||
)
|
||||
)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "response") [$localCid])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 6])
|
||||
)
|
||||
)
|
||||
(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;});
|
||||
|
||||
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.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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
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(
|
||||
`
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||
(call %init_peer_id% ("getDataSrv" "node") [] node)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "cid") [] cid)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "from") [] from)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(call node ("aqua-ipfs" "get_from") [cid from] result)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||
)
|
||||
)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "response") [result])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 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', '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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
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(
|
||||
`
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||
(call %init_peer_id% ("getDataSrv" "node") [] node)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(call node ("aqua-ipfs" "get_local_api_multiaddr") [] result)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||
)
|
||||
)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "response") [result])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 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.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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
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(
|
||||
`
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||
(call %init_peer_id% ("getDataSrv" "node") [] node)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(call node ("aqua-ipfs" "get_external_swarm_multiaddr") [] result)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||
)
|
||||
)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "response") [result])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 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.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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
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(
|
||||
`
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||
(call %init_peer_id% ("getDataSrv" "node") [] node)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "path") [] path)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(call node ("aqua-ipfs" "put") [path] result)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||
)
|
||||
)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "response") [result])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 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);
|
||||
});
|
||||
|
||||
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 (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(
|
||||
`
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||
(call %init_peer_id% ("getDataSrv" "node") [] node)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(call node ("aqua-ipfs" "get_external_api_multiaddr") [] result)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||
)
|
||||
)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "response") [result])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 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.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;
|
||||
}
|
||||
|
725
aqua-examples/aqua-ipfs-integration/web/src/_aqua/process.ts
Normal file
725
aqua-examples/aqua-ipfs-integration/web/src/_aqua/process.ts
Normal file
@ -0,0 +1,725 @@
|
||||
/**
|
||||
*
|
||||
* This file is auto-generated. Do not edit manually: changes may be erased.
|
||||
* 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-225
|
||||
*
|
||||
*/
|
||||
import { FluencePeer } from '@fluencelabs/fluence';
|
||||
import {
|
||||
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"
|
||||
}
|
||||
|
||||
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 === 'array') {
|
||||
|
||||
const callParams = {
|
||||
...req.particleContext,
|
||||
tetraplets: {
|
||||
s: req.tetraplets[0]
|
||||
},
|
||||
};
|
||||
resp.retCode = ResultCodes.success;
|
||||
resp.result = service.array(req.args[0], callParams)
|
||||
|
||||
}
|
||||
|
||||
|
||||
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(
|
||||
`
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||
(call %init_peer_id% ("getDataSrv" "module_hash") [] module_hash)
|
||||
)
|
||||
(call %init_peer_id% ("op" "concat_strings") ["hash:" module_hash] prefixed_hash)
|
||||
)
|
||||
(call %init_peer_id% ("op" "array") [prefixed_hash] dependencies)
|
||||
)
|
||||
(call %init_peer_id% ("dist" "make_blueprint") ["process_files" dependencies] blueprint)
|
||||
)
|
||||
(call %init_peer_id% ("dist" "add_blueprint") [blueprint] blueprint_id)
|
||||
)
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "response") [blueprint_id])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 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);
|
||||
});
|
||||
|
||||
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 (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(
|
||||
`
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||
(call %init_peer_id% ("getDataSrv" "relay") [] relay)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "cid") [] cid)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "ipfs") [] ipfs)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "service_id") [] service_id)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(seq
|
||||
(call relay ("aqua-ipfs" "get_from") [cid ipfs] get)
|
||||
(xor
|
||||
(match get.$.success! true
|
||||
(xor
|
||||
(seq
|
||||
(call relay (service_id "file_size") [get.$.path!] size)
|
||||
(xor
|
||||
(match size.$.success! true
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(par
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "logSize") [size.$.size!])
|
||||
(seq
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
)
|
||||
)
|
||||
(null)
|
||||
)
|
||||
(call relay (service_id "write_file_size") [size.$.size!] write)
|
||||
)
|
||||
(xor
|
||||
(match write.$.success! true
|
||||
(xor
|
||||
(call relay ("aqua-ipfs" "put") [write.$.path!] $result)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||
)
|
||||
)
|
||||
)
|
||||
(par
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "error") ["ProcessFiles.write_file_size failed" write.$.error!])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||
)
|
||||
)
|
||||
(null)
|
||||
)
|
||||
)
|
||||
)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
|
||||
)
|
||||
)
|
||||
)
|
||||
(par
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "error") ["ProcessFiles.file_size failed" size.$.error!])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 5])
|
||||
)
|
||||
)
|
||||
(null)
|
||||
)
|
||||
)
|
||||
)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 6])
|
||||
)
|
||||
)
|
||||
)
|
||||
(par
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "error") ["Ipfs.get_from failed" get.$.error!])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 7])
|
||||
)
|
||||
)
|
||||
(null)
|
||||
)
|
||||
)
|
||||
)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 8])
|
||||
)
|
||||
)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "response") [$result])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 9])
|
||||
)
|
||||
)
|
||||
(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;});
|
||||
|
||||
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();
|
||||
});
|
||||
|
||||
|
||||
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.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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
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(
|
||||
`
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||
(call %init_peer_id% ("getDataSrv" "relay") [] relay)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "service_id") [] service_id)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(call relay ("srv" "remove") [service_id])
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||
)
|
||||
)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "response") [true])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 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);
|
||||
});
|
||||
|
||||
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 (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(
|
||||
`
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||
(call %init_peer_id% ("getDataSrv" "name") [] name)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "path") [] path)
|
||||
)
|
||||
(call %init_peer_id% ("dist" "default_module_config") [name] config)
|
||||
)
|
||||
(call %init_peer_id% ("dist" "add_module_from_vault") [path config] module_hash)
|
||||
)
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "response") [module_hash])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||
)
|
||||
)
|
||||
(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);
|
||||
});
|
||||
|
||||
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 (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(
|
||||
`
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||
(call %init_peer_id% ("getDataSrv" "relay") [] relay)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "cid") [] cid)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "ipfs") [] ipfs)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(seq
|
||||
(call relay ("aqua-ipfs" "get_from") [cid ipfs] get_result)
|
||||
(xor
|
||||
(match get_result.$.success! true
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call relay ("dist" "default_module_config") ["process_files"] config)
|
||||
(call relay ("dist" "add_module_from_vault") [get_result.$.path! config] module_hash)
|
||||
)
|
||||
(call relay ("op" "concat_strings") ["hash:" module_hash] prefixed_hash)
|
||||
)
|
||||
(call relay ("op" "array") [prefixed_hash] dependencies)
|
||||
)
|
||||
(call relay ("dist" "make_blueprint") ["process_files" dependencies] blueprint)
|
||||
)
|
||||
(call relay ("dist" "add_blueprint") [blueprint] blueprint_id)
|
||||
)
|
||||
(call relay ("srv" "create") [blueprint_id] $service_id)
|
||||
)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||
)
|
||||
)
|
||||
)
|
||||
(par
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "error") ["Ipfs.get_from failed" get_result.$.error!])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||
)
|
||||
)
|
||||
(null)
|
||||
)
|
||||
)
|
||||
)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||
)
|
||||
)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "response") [$service_id])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 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;});
|
||||
|
||||
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.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;
|
||||
}
|
||||
|
@ -1,12 +1,9 @@
|
||||
import { FluencePeer } from "@fluencelabs/fluence";
|
||||
import { krasnodar } from "@fluencelabs/fluence-network-environment";
|
||||
import { useSetRecoilState, useRecoilValue, useRecoilState } from "recoil";
|
||||
import {
|
||||
deploy_service,
|
||||
put_file_size,
|
||||
remove_service,
|
||||
get_external_api_multiaddr,
|
||||
} from "@fluencelabs/ipfs-execution-aqua";
|
||||
import { deploy_service, put_file_size, remove_service } from "./_aqua/process";
|
||||
import { get_external_api_multiaddr } from "./_aqua/exports";
|
||||
|
||||
import {
|
||||
isConnectedState,
|
||||
rpcAddrState,
|
||||
|
Loading…
Reference in New Issue
Block a user