From d510c64f36d8efb65f32eb1c19979594f5a297d2 Mon Sep 17 00:00:00 2001 From: folex <0xdxdy@gmail.com> Date: Thu, 9 Sep 2021 17:38:35 +0300 Subject: [PATCH] Debug overload --- .../aqua/aqua/process_files.aqua | 2 - .../aqua/src/process_files.ts | 150 +++++++++--------- .../aqua-ipfs-integration/nodejs/demo.ts | 5 +- .../nodejs/package-lock.json | 101 ++++++++++++ .../aqua-ipfs-integration/nodejs/package.json | 4 +- .../aqua-ipfs-integration/nodejs/provider.ts | 2 + 6 files changed, 183 insertions(+), 81 deletions(-) diff --git a/aqua-examples/aqua-ipfs-integration/aqua/aqua/process_files.aqua b/aqua-examples/aqua-ipfs-integration/aqua/aqua/process_files.aqua index 827f699..538cb5d 100644 --- a/aqua-examples/aqua-ipfs-integration/aqua/aqua/process_files.aqua +++ b/aqua-examples/aqua-ipfs-integration/aqua/aqua/process_files.aqua @@ -1,5 +1,3 @@ -module ProcessFiles declares * - data SizeResult: size: u32 success: bool diff --git a/aqua-examples/aqua-ipfs-integration/aqua/src/process_files.ts b/aqua-examples/aqua-ipfs-integration/aqua/src/process_files.ts index 7271c5c..ad6c65b 100644 --- a/aqua-examples/aqua-ipfs-integration/aqua/src/process_files.ts +++ b/aqua-examples/aqua-ipfs-integration/aqua/src/process_files.ts @@ -1,95 +1,93 @@ /** * * 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 ProcessFilesDef { - file_size: ( - file_path: string, - callParams: CallParams<"file_path"> - ) => { error: string; size: number; success: boolean }; - write_file_size: ( - size: number, - callParams: CallParams<"size"> - ) => { error: string; path: string; success: boolean }; -} + export interface ProcessFilesDef { + file_size: (file_path: string, callParams: CallParams<'file_path'>) => {error:string;size:number;success:boolean}; +write_file_size: (size: number, callParams: CallParams<'size'>) => {error:string;path:string;success:boolean}; + } -export function registerProcessFiles( - serviceId: string, - service: ProcessFilesDef -): void; -export function registerProcessFiles( - peer: FluencePeer, - serviceId: string, - service: ProcessFilesDef -): void; -export function registerProcessFiles(...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; + export function registerProcessFiles(serviceId: string, service: ProcessFilesDef): void; +export function registerProcessFiles(peer: FluencePeer, serviceId: string, service: ProcessFilesDef): void; + export function registerProcessFiles(...args: any) { + let peer: FluencePeer; + let serviceId: any; + let service: any; + if (args[0] instanceof FluencePeer) { + peer = args[0]; + } else { + peer = FluencePeer.default; } - if (req.fnName === "file_size") { - const callParams = { - ...req.particleContext, - tetraplets: { - file_path: req.tetraplets[0], - }, - }; - resp.retCode = ResultCodes.success; - resp.result = service.file_size(req.args[0], callParams); + 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]; } - if (req.fnName === "write_file_size") { - const callParams = { - ...req.particleContext, - tetraplets: { - size: req.tetraplets[0], - }, - }; - resp.retCode = ResultCodes.success; - resp.result = service.write_file_size(req.args[0], callParams); - } + peer.internals.callServiceHandler.use((req, resp, next) => { + if (req.serviceId !== serviceId) { + next(); + return; + } + + + if (req.fnName === 'file_size') { + + const callParams = { + ...req.particleContext, + tetraplets: { + file_path: req.tetraplets[0] + }, + }; + resp.retCode = ResultCodes.success; + resp.result = service.file_size(req.args[0], callParams) - next(); - }); -} + } + + + + if (req.fnName === 'write_file_size') { + + const callParams = { + ...req.particleContext, + tetraplets: { + size: req.tetraplets[0] + }, + }; + resp.retCode = ResultCodes.success; + resp.result = service.write_file_size(req.args[0], callParams) + + } + + + next(); + }); + } + // Functions + diff --git a/aqua-examples/aqua-ipfs-integration/nodejs/demo.ts b/aqua-examples/aqua-ipfs-integration/nodejs/demo.ts index 307e097..a6cc4cd 100644 --- a/aqua-examples/aqua-ipfs-integration/nodejs/demo.ts +++ b/aqua-examples/aqua-ipfs-integration/nodejs/demo.ts @@ -32,9 +32,10 @@ import { import { globSource, urlSource } from "ipfs-http-client"; async function main(environment: Node[]) { - // setLogLevel('DEBUG'); + setLogLevel('DEBUG'); let providerHost = environment[0]; - let providerClient = new FluencePeer(); + console.dir(providerHost); + let providerClient = FluencePeer.default; await providerClient.init({ connectTo: providerHost }); console.log("📘 uploading .wasm to node %s", providerHost.multiaddr); let path = globSource("../service/artifacts/process_files.wasm"); diff --git a/aqua-examples/aqua-ipfs-integration/nodejs/package-lock.json b/aqua-examples/aqua-ipfs-integration/nodejs/package-lock.json index df645fe..159fb32 100644 --- a/aqua-examples/aqua-ipfs-integration/nodejs/package-lock.json +++ b/aqua-examples/aqua-ipfs-integration/nodejs/package-lock.json @@ -42,6 +42,21 @@ } } }, + "@cspotcode/source-map-consumer": { + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/@cspotcode/source-map-consumer/-/source-map-consumer-0.8.0.tgz", + "integrity": "sha512-41qniHzTU8yAGbCp04ohlmSrZf8bkf/iJsl3V0dRGsQN/5GFfx+LbCSsCpp2gqrqjTVg/K6O8ycoV35JIwAzAg==", + "dev": true + }, + "@cspotcode/source-map-support": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.6.1.tgz", + "integrity": "sha512-DX3Z+T5dt1ockmPdobJS/FAsQPW4V4SrWEhD2iYQT2Cb2tQsiMnYxrcUH9By/Z3B+v0S5LMBkQtV/XOBbpLEOg==", + "dev": true, + "requires": { + "@cspotcode/source-map-consumer": "0.8.0" + } + }, "@fluencelabs/aqua-lib": { "version": "0.1.14", "resolved": "https://registry.npmjs.org/@fluencelabs/aqua-lib/-/aqua-lib-0.1.14.tgz", @@ -3362,6 +3377,30 @@ "@stablelib/wipe": "^1.0.1" } }, + "@tsconfig/node10": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.8.tgz", + "integrity": "sha512-6XFfSQmMgq0CFLY1MslA/CPUfhIL919M1rMsa5lP2P097N2Wd1sSX0tx1u4olM16fLNhtHZpRhedZJphNJqmZg==", + "dev": true + }, + "@tsconfig/node12": { + "version": "1.0.9", + "resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.9.tgz", + "integrity": "sha512-/yBMcem+fbvhSREH+s14YJi18sp7J9jpuhYByADT2rypfajMZZN4WQ6zBGgBKp53NKmqI36wFYDb3yaMPurITw==", + "dev": true + }, + "@tsconfig/node14": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.1.tgz", + "integrity": "sha512-509r2+yARFfHHE7T6Puu2jjkoycftovhXRqW328PDXTVGKihlb1P8Z9mMZH04ebyajfRY7dedfGynlrFHJUQCg==", + "dev": true + }, + "@tsconfig/node16": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.2.tgz", + "integrity": "sha512-eZxlbI8GZscaGS7kkc/trHTT5xgrjH3/1n2JDwusC9iahPKWMRvRjJSAN5mCXviuTGQ/lHnhvv8Q1YTpnfz9gA==", + "dev": true + }, "@types/long": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/@types/long/-/long-4.0.1.tgz", @@ -3403,6 +3442,18 @@ "get-iterator": "^1.0.2" } }, + "acorn": { + "version": "8.5.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.5.0.tgz", + "integrity": "sha512-yXbYeFy+jUuYd3/CDcg2NkIYE991XYX/bje7LmjJigUciaeO1JR4XxXgCIV1/Zc/dRuFEyw1L0pbA+qynJkW5Q==", + "dev": true + }, + "acorn-walk": { + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.2.0.tgz", + "integrity": "sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==", + "dev": true + }, "aggregate-error": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/aggregate-error/-/aggregate-error-3.1.0.tgz", @@ -3432,6 +3483,12 @@ "native-abort-controller": "^1.0.3" } }, + "arg": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", + "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", + "dev": true + }, "asn1": { "version": "0.2.4", "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.4.tgz", @@ -3676,6 +3733,12 @@ "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" }, + "create-require": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", + "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", + "dev": true + }, "cross-spawn": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", @@ -3715,6 +3778,12 @@ "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" }, + "diff": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", + "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", + "dev": true + }, "dns-over-http-resolver": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/dns-over-http-resolver/-/dns-over-http-resolver-1.2.3.tgz", @@ -5243,6 +5312,12 @@ "multiaddr": "^10.0.0" } }, + "make-error": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", + "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", + "dev": true + }, "merge-options": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/merge-options/-/merge-options-3.0.4.tgz", @@ -5919,6 +5994,26 @@ "utf8-byte-length": "^1.0.1" } }, + "ts-node": { + "version": "10.2.1", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.2.1.tgz", + "integrity": "sha512-hCnyOyuGmD5wHleOQX6NIjJtYVIO8bPP8F2acWkB4W06wdlkgyvJtubO/I9NkI88hCFECbsEgoLc0VNkYmcSfw==", + "dev": true, + "requires": { + "@cspotcode/source-map-support": "0.6.1", + "@tsconfig/node10": "^1.0.7", + "@tsconfig/node12": "^1.0.7", + "@tsconfig/node14": "^1.0.0", + "@tsconfig/node16": "^1.0.2", + "acorn": "^8.4.1", + "acorn-walk": "^8.1.1", + "arg": "^4.1.0", + "create-require": "^1.1.0", + "diff": "^4.0.1", + "make-error": "^1.1.1", + "yn": "3.1.1" + } + }, "tunnel-agent": { "version": "0.6.0", "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", @@ -6037,6 +6132,12 @@ "version": "1.1.0", "resolved": "https://registry.npmjs.org/xsalsa20/-/xsalsa20-1.1.0.tgz", "integrity": "sha512-zd3ytX2cm+tcSndRU+krm0eL4TMMpZE7evs5hLRAoOy6gviqLfe3qOlkjF3i5SeAkQUCeJk0lJZrEU56kHRfWw==" + }, + "yn": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", + "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", + "dev": true } } } diff --git a/aqua-examples/aqua-ipfs-integration/nodejs/package.json b/aqua-examples/aqua-ipfs-integration/nodejs/package.json index e29e8f5..824e326 100644 --- a/aqua-examples/aqua-ipfs-integration/nodejs/package.json +++ b/aqua-examples/aqua-ipfs-integration/nodejs/package.json @@ -9,7 +9,8 @@ "start:local": "node dist/demo.js local", "prestart:remote": "npm run build", "start:remote": "node dist/demo.js krasnodar", - "start": "npm run start:remote" + "start": "npm run start:remote", + "run": "node -r ts-node/register demo.ts" }, "keywords": [ "fluence", @@ -34,6 +35,7 @@ "multiaddr": "^10.0.0" }, "devDependencies": { + "ts-node": "^10.2.1", "typescript": "^3.9.5" } } diff --git a/aqua-examples/aqua-ipfs-integration/nodejs/provider.ts b/aqua-examples/aqua-ipfs-integration/nodejs/provider.ts index 5f7f3ef..068a0de 100644 --- a/aqua-examples/aqua-ipfs-integration/nodejs/provider.ts +++ b/aqua-examples/aqua-ipfs-integration/nodejs/provider.ts @@ -14,6 +14,8 @@ export async function provideFile( ): Promise<{ file: AddResult; swarmAddr: string; rpcAddr: string }> { const relayPeerId = provider.connectionInfo.connectedRelay!; let swarmAddr; + console.log("provider:"); + console.dir(provider); let result = await get_external_swarm_multiaddr( provider, provider.connectionInfo.connectedRelay!,