223 lines
6.6 KiB
TypeScript
Raw Normal View History

2021-06-04 14:10:34 +03:00
/**
*
* 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
2021-08-31 12:19:36 +03:00
* Aqua version: 0.2.0-SNAPSHOT
2021-06-04 14:10:34 +03:00
*
*/
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
import { RequestFlowBuilder } from '@fluencelabs/fluence/dist/api.unstable';
import { RequestFlow } from '@fluencelabs/fluence/dist/internal/RequestFlow';
// Services
//Srv
//defaultId = "srv"
//add_alias: (alias: string, service_id: string) => void
//create: (blueprint_id: string) => string
//get_interface: (service_id: string) => {function_signatures:{arguments:string[][];name:string;output_types:string[]}[];record_types:{fields:string[][];id:number;name:string}[]}
//list: () => {blueprint_id:string;id:string;owner_id:string}[]
//remove: (service_id: string) => void
//resolve_alias: (alias: string) => string
//END Srv
//Peer
//defaultId = "peer"
//connect: (id: string, multiaddrs: string[] | null) => boolean
//get_contact: (peer: string) => {addresses:string[];peer_id:string}
//identify: () => {external_addresses:string[]}
//is_connected: (peer: string) => boolean
//timestamp_ms: () => number
//timestamp_sec: () => number
//END Peer
//OpH
//defaultId = "opa"
//identity: (s: string) => string
//END OpH
//Op
//defaultId = "op"
//array: (a: string, b: string | null, c: string | null, d: string | null) => string[]
//array_length: (array: string[]) => number
//bytes_from_b58: (b: string) => number[]
//bytes_to_b58: (bs: number[]) => string
//concat: (a: string[], b: string[] | null, c: string[] | null, d: string[] | null) => string[]
//concat_strings: (a: string, b: string) => string
//identity: (s: string | null) => string | null
//noop: () => void
//sha256_string: (s: string) => string
//string_from_b58: (b: string) => string
//string_to_b58: (s: string) => string
//END Op
//Kademlia
//defaultId = "kad"
//merge: (target: string, left: string[], right: string[], count: number | null) => string[]
//neighborhood: (key: string, already_hashed: boolean | null, count: number | null) => string[]
//END Kademlia
//Script
//defaultId = "script"
//add: (air_script: string, interval: string | null) => string
//list: () => {failures:number;id:string;interval:string;owner:string;src:string}
//remove: (script_id: string) => boolean
//END Script
//Dist
//defaultId = "dist"
//add_blueprint: (blueprint: {dependencies:string[];name:string}) => string
//add_module: (wasm_b56_content: number[], conf: {name:string}) => string
//add_module_from_vault: (path: string, config: {name:string}) => string
//default_module_config: (module_name: string) => {name:string}
//get_interface: (module_id: string) => {function_signatures:{arguments:string[][];name:string;output_types:string[]}[];record_types:{fields:string[][];id:number;name:string}[]}
//list_blueprints: () => {dependencies:string[];id:string;name:string}[]
//list_modules: () => {config:{name:string};hash:string;name:string}[]
//make_blueprint: (name: string, dependencies: string[]) => {dependencies:string[];name:string}
//make_module_config: (name: string, mem_pages_count: number | null, logger_enabled: boolean | null, preopened_files: string[] | null, envs: string[][] | null, mapped_dirs: string[][] | null, mounted_binaries: string[][] | null, logging_mask: number | null) => {name:string}
//END Dist
// Functions
2021-06-04 14:10:34 +03:00
2021-06-15 13:14:39 +03:00
export async function a(client: FluenceClient, b: string, config?: {ttl?: number}): Promise<string> {
2021-06-04 14:10:34 +03:00
let request: RequestFlow;
const promise = new Promise<string>((resolve, reject) => {
2021-07-13 17:30:12 +03:00
const r = new RequestFlowBuilder()
2021-06-04 14:10:34 +03:00
.disableInjections()
.withRawScript(
`
(xor
(seq
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "b") [] b)
)
(call %init_peer_id% ("opa" "identity") [b] c)
)
(xor
(call %init_peer_id% ("callbackSrv" "response") [c])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
)
)
2021-06-18 15:15:34 +03:00
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
2021-06-04 14:10:34 +03:00
)
`,
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return client.relayPeerId!;
});
h.on('getDataSrv', 'b', () => {return b;});
h.onEvent('callbackSrv', 'response', (args) => {
2021-07-28 16:24:07 +03:00
const [res] = args;
2021-06-04 14:10:34 +03:00
resolve(res);
});
h.onEvent('errorHandlingSrv', 'error', (args) => {
// assuming error is the single argument
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject('Request timed out for a');
})
2021-07-23 11:57:44 +03:00
if(config && config.ttl) {
2021-07-13 17:30:12 +03:00
r.withTTL(config.ttl)
}
request = r.build();
2021-06-04 14:10:34 +03:00
});
await client.initiateFlow(request!);
return promise;
}
2021-06-15 13:14:39 +03:00
export async function d(client: FluenceClient, e: string, config?: {ttl?: number}): Promise<string> {
2021-06-04 14:10:34 +03:00
let request: RequestFlow;
const promise = new Promise<string>((resolve, reject) => {
2021-07-13 17:30:12 +03:00
const r = new RequestFlowBuilder()
2021-06-04 14:10:34 +03:00
.disableInjections()
.withRawScript(
`
(xor
(seq
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "e") [] e)
)
(call %init_peer_id% ("opa" "identity") [e] c)
)
(xor
2021-06-07 17:23:27 +03:00
(call %init_peer_id% ("callbackSrv" "response") [c])
2021-06-04 14:10:34 +03:00
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
)
)
2021-06-18 15:15:34 +03:00
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
2021-06-04 14:10:34 +03:00
)
`,
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return client.relayPeerId!;
});
h.on('getDataSrv', 'e', () => {return e;});
h.onEvent('callbackSrv', 'response', (args) => {
2021-07-28 16:24:07 +03:00
const [res] = args;
2021-06-04 14:10:34 +03:00
resolve(res);
});
h.onEvent('errorHandlingSrv', 'error', (args) => {
// assuming error is the single argument
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject('Request timed out for d');
})
2021-07-23 11:57:44 +03:00
if(config && config.ttl) {
2021-07-13 17:30:12 +03:00
r.withTTL(config.ttl)
}
request = r.build();
2021-06-04 14:10:34 +03:00
});
await client.initiateFlow(request!);
return promise;
}