mirror of
https://github.com/fluencelabs/fluence-js.git
synced 2024-12-05 02:10:18 +00:00
node version
This commit is contained in:
parent
1053bee152
commit
620af63d93
@ -8,19 +8,17 @@
|
||||
"node": ">=10",
|
||||
"pnpm": ">=3"
|
||||
},
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"test": "ts-node src/index.ts"
|
||||
"_test": "node --loader ts-node/esm ./src/index.ts"
|
||||
},
|
||||
"repository": "https://github.com/fluencelabs/fluence-js",
|
||||
"author": "Fluence Labs",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@fluencelabs/fluence": "workspace:*",
|
||||
"@fluencelabs/js-client.api": "workspace:*",
|
||||
"@fluencelabs/js-client.node": "workspace:*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "16.11.59",
|
||||
"typescript": "4.6.4"
|
||||
}
|
||||
"devDependencies": {}
|
||||
}
|
122
packages/@tests/smoke_node/src/_aqua/smoke_test.ts
Normal file
122
packages/@tests/smoke_node/src/_aqua/smoke_test.ts
Normal file
@ -0,0 +1,122 @@
|
||||
/**
|
||||
*
|
||||
* 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.7.2-314
|
||||
*
|
||||
*/
|
||||
import type { IFluencePeer, CallParams } from '@fluencelabs/js-client.api';
|
||||
import { callFunction$$, registerService$$ } from '@fluencelabs/js-client.api';
|
||||
|
||||
// Services
|
||||
|
||||
export interface PeerDef {
|
||||
timestamp_ms: (callParams: CallParams<null>) => number | Promise<number>;
|
||||
}
|
||||
export function registerPeer(service: PeerDef): void;
|
||||
export function registerPeer(serviceId: string, service: PeerDef): void;
|
||||
export function registerPeer(peer: IFluencePeer, service: PeerDef): void;
|
||||
export function registerPeer(peer: IFluencePeer, serviceId: string, service: PeerDef): void;
|
||||
|
||||
export function registerPeer(...args: any) {
|
||||
registerService$$(args, {
|
||||
defaultServiceId: 'peer',
|
||||
functions: {
|
||||
tag: 'labeledProduct',
|
||||
fields: {
|
||||
timestamp_ms: {
|
||||
tag: 'arrow',
|
||||
domain: {
|
||||
tag: 'nil',
|
||||
},
|
||||
codomain: {
|
||||
tag: 'unlabeledProduct',
|
||||
items: [
|
||||
{
|
||||
tag: 'scalar',
|
||||
name: 'u64',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// Functions
|
||||
|
||||
export function getRelayTime(relayPeerId: string, config?: { ttl?: number }): Promise<number>;
|
||||
|
||||
export function getRelayTime(peer: IFluencePeer, relayPeerId: string, config?: { ttl?: number }): Promise<number>;
|
||||
|
||||
export function getRelayTime(...args: any) {
|
||||
let script = `
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||
(call %init_peer_id% ("getDataSrv" "relayPeerId") [] relayPeerId)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(seq
|
||||
(call relayPeerId ("peer" "timestamp_ms") [] ts)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||
)
|
||||
)
|
||||
)
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "response") [ts])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||
)
|
||||
)
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||
)
|
||||
`;
|
||||
return callFunction$$(
|
||||
args,
|
||||
{
|
||||
functionName: 'getRelayTime',
|
||||
arrow: {
|
||||
tag: 'arrow',
|
||||
domain: {
|
||||
tag: 'labeledProduct',
|
||||
fields: {
|
||||
relayPeerId: {
|
||||
tag: 'scalar',
|
||||
name: 'string',
|
||||
},
|
||||
},
|
||||
},
|
||||
codomain: {
|
||||
tag: 'unlabeledProduct',
|
||||
items: [
|
||||
{
|
||||
tag: 'scalar',
|
||||
name: 'u64',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
names: {
|
||||
relay: '-relay-',
|
||||
getDataSrv: 'getDataSrv',
|
||||
callbackSrv: 'callbackSrv',
|
||||
responseSrv: 'callbackSrv',
|
||||
responseFnName: 'response',
|
||||
errorHandlingSrv: 'errorHandlingSrv',
|
||||
errorFnName: 'error',
|
||||
},
|
||||
},
|
||||
script,
|
||||
);
|
||||
}
|
@ -1,23 +1,24 @@
|
||||
import "@fluencelabs/js-client.node";
|
||||
import { Fluence } from "@fluencelabs/fluence";
|
||||
import '@fluencelabs/js-client.node';
|
||||
import { Fluence } from '@fluencelabs/js-client.api';
|
||||
import { getRelayTime } from './_aqua/smoke_test.js';
|
||||
|
||||
const peer = Fluence.getPeer();
|
||||
|
||||
const main = async () => {
|
||||
await peer.start({});
|
||||
const peerId = peer.getStatus().peerId;
|
||||
if (!peerId) {
|
||||
throw new Error("Peer id is null");
|
||||
}
|
||||
console.log("peer id is: ", peerId);
|
||||
await peer.stop();
|
||||
const relay = {
|
||||
multiaddr: '/ip4/127.0.0.1/tcp/4310/ws/p2p/12D3KooWKEprYXUXqoV5xSBeyqrWLpQLLH4PXfvVkDJtmcqmh5V3',
|
||||
peerId: '12D3KooWKEprYXUXqoV5xSBeyqrWLpQLLH4PXfvVkDJtmcqmh5V3',
|
||||
};
|
||||
|
||||
main()
|
||||
.then(() => console.log("done"))
|
||||
.catch((err) => console.error(err))
|
||||
.finally(() => {
|
||||
if (peer) {
|
||||
peer.stop();
|
||||
}
|
||||
export const main = async () => {
|
||||
console.log('starting fluence...');
|
||||
await Fluence.start({
|
||||
connectTo: relay,
|
||||
});
|
||||
console.log('started fluence');
|
||||
|
||||
console.log('getting relay time...');
|
||||
const res = await getRelayTime(relay.peerId);
|
||||
console.log('got relay time, ', res);
|
||||
|
||||
console.log('stopping fluence...');
|
||||
await Fluence.stop();
|
||||
console.log('stopped fluence...');
|
||||
};
|
||||
|
@ -1 +0,0 @@
|
||||
/dist/
|
@ -8,6 +8,13 @@
|
||||
"node": ">=10",
|
||||
"pnpm": ">=3"
|
||||
},
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts"
|
||||
}
|
||||
},
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "tsc"
|
||||
},
|
||||
@ -15,12 +22,9 @@
|
||||
"author": "Fluence Labs",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@fluencelabs/js-peer": "workspace:*"
|
||||
"@fluencelabs/js-peer": "workspace:*",
|
||||
"@fluencelabs/avm": "0.35.3",
|
||||
"@fluencelabs/marine-js": "0.3.42"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "16.11.59",
|
||||
"@types/jest": "28.1.0",
|
||||
"jest": "28.1.0",
|
||||
"ts-jest": "28.0.2",
|
||||
}
|
||||
"devDependencies": {}
|
||||
}
|
@ -1,8 +1,9 @@
|
||||
import { MarineBackgroundRunner } from '@fluencelabs/marine.background-runner';
|
||||
import { MarineBasedAvmRunner } from '@fluencelabs/js-peer/dist/avm';
|
||||
import { marineLogFunction } from '@fluencelabs/js-peer/dist/utils';
|
||||
import { FluencePeer } from '@fluencelabs/js-peer/dist/FluencePeer';
|
||||
import { InlinedWorkerLoader, WasmNpmLoader } from '@fluencelabs/marine.deps-loader.node';
|
||||
import { FluencePeer } from '@fluencelabs/js-peer/dist/js-peer/FluencePeer.js';
|
||||
import { MarineBasedAvmRunner } from '@fluencelabs/js-peer/dist/js-peer/avm.js';
|
||||
import { MarineBackgroundRunner } from '@fluencelabs/js-peer/dist/marine/worker';
|
||||
import { marineLogFunction } from '@fluencelabs/js-peer/dist/js-peer/utils.js';
|
||||
import { WasmLoaderFromNpm } from '@fluencelabs/js-peer/dist/marine/deps-loader/node.js';
|
||||
import { WorkerLoader } from '@fluencelabs/js-peer/dist/marine/worker-script/workerLoader.js';
|
||||
|
||||
export const defaultNames = {
|
||||
avm: {
|
||||
@ -16,9 +17,9 @@ export const defaultNames = {
|
||||
};
|
||||
|
||||
export const makeDefaultPeer = () => {
|
||||
const workerLoader = new InlinedWorkerLoader();
|
||||
const controlModuleLoader = new WasmNpmLoader(defaultNames.marine.package, defaultNames.marine.file);
|
||||
const avmModuleLoader = new WasmNpmLoader(defaultNames.avm.package, defaultNames.avm.file);
|
||||
const workerLoader = new WorkerLoader();
|
||||
const controlModuleLoader = new WasmLoaderFromNpm(defaultNames.marine.package, defaultNames.marine.file);
|
||||
const avmModuleLoader = new WasmLoaderFromNpm(defaultNames.avm.package, defaultNames.avm.file);
|
||||
|
||||
const marine = new MarineBackgroundRunner(workerLoader, controlModuleLoader, marineLogFunction);
|
||||
const avm = new MarineBasedAvmRunner(marine, avmModuleLoader, undefined);
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { FluencePeer } from '@fluencelabs/js-peer/dist/js-peer/FluencePeer';
|
||||
import { MarineBasedAvmRunner } from '@fluencelabs/js-peer/dist/js-peer/avm';
|
||||
import { FluencePeer } from '@fluencelabs/js-peer/dist/js-peer/FluencePeer.js';
|
||||
import { MarineBasedAvmRunner } from '@fluencelabs/js-peer/dist/js-peer/avm.js';
|
||||
import { MarineBackgroundRunner } from '@fluencelabs/js-peer/dist/marine/worker';
|
||||
import { checkConnection, marineLogFunction } from '@fluencelabs/js-peer/dist/js-peer/utils';
|
||||
import { InlinedWorkerLoader, InlinedWasmLoader } from '@fluencelabs/js-peer/dist/marine/deps-loader/common';
|
||||
import { checkConnection, marineLogFunction } from '@fluencelabs/js-peer/dist/js-peer/utils.js';
|
||||
import { InlinedWorkerLoader, InlinedWasmLoader } from '@fluencelabs/js-peer/dist/marine/deps-loader/common.js';
|
||||
|
||||
export const makeDefaultPeer = () => {
|
||||
const workerLoader = new InlinedWorkerLoader('___worker___');
|
||||
|
@ -0,0 +1,10 @@
|
||||
import { LazyLoader } from '../../interfaces/index.js';
|
||||
|
||||
import type { WorkerImplementation } from 'threads/dist/types/master';
|
||||
import { Worker } from 'threads';
|
||||
|
||||
export class WorkerLoader extends LazyLoader<WorkerImplementation> {
|
||||
constructor() {
|
||||
super(() => new Worker('./'));
|
||||
}
|
||||
}
|
20
pnpm-lock.yaml
generated
20
pnpm-lock.yaml
generated
@ -49,6 +49,14 @@ importers:
|
||||
devDependencies:
|
||||
'@fluencelabs/js-client.web.standalone': link:../../../client/js-client.web.standalone
|
||||
|
||||
packages/@tests/smoke_node:
|
||||
specifiers:
|
||||
'@fluencelabs/js-client.api': workspace:*
|
||||
'@fluencelabs/js-client.node': workspace:*
|
||||
dependencies:
|
||||
'@fluencelabs/js-client.api': link:../../client/api
|
||||
'@fluencelabs/js-client.node': link:../../client/js-client.node
|
||||
|
||||
packages/@tests/smoke_web:
|
||||
specifiers:
|
||||
'@fluencelabs/js-peer': workspace:*
|
||||
@ -63,6 +71,16 @@ importers:
|
||||
dependencies:
|
||||
'@fluencelabs/interface': link:../../core/interface
|
||||
|
||||
packages/client/js-client.node:
|
||||
specifiers:
|
||||
'@fluencelabs/avm': 0.35.3
|
||||
'@fluencelabs/js-peer': workspace:*
|
||||
'@fluencelabs/marine-js': 0.3.42
|
||||
dependencies:
|
||||
'@fluencelabs/avm': 0.35.3
|
||||
'@fluencelabs/js-peer': link:../../core/js-peer
|
||||
'@fluencelabs/marine-js': 0.3.42
|
||||
|
||||
packages/client/js-client.web.standalone:
|
||||
specifiers:
|
||||
'@fluencelabs/avm': 0.35.3
|
||||
@ -2095,7 +2113,6 @@ packages:
|
||||
|
||||
/@fluencelabs/avm/0.35.3:
|
||||
resolution: {integrity: sha512-Y5mPPCmAUUKc5CDO12IL8mGEreWa7maVdX0MWCAH4+GvfLPFN1FxOMSKRYEtvkyVEL88pc9pd8cm5IRCBkFthg==}
|
||||
dev: true
|
||||
|
||||
/@fluencelabs/connection/0.2.0_node-fetch@3.3.0:
|
||||
resolution: {integrity: sha512-0jTRI1h/j/fR2VaLIlcIm6VoP3j2jL2lI6/OaYaOnwGXmI6CbZWHNeq9eaKWycT9B1vpN9wHu0Vi7vH3pFplhg==}
|
||||
@ -2257,7 +2274,6 @@ packages:
|
||||
dependencies:
|
||||
'@wasmer/wasi': 0.12.0
|
||||
'@wasmer/wasmfs': 0.12.0
|
||||
dev: true
|
||||
|
||||
/@fluencelabs/marine-js/0.3.44:
|
||||
resolution: {integrity: sha512-DbI/x0bRv44oqfMZJlIkVhzZByXhmnOoxpco/cglk5aAvslOSDdRssf3bZADqqUQggGdtISOZcYPM+a4tirYLQ==}
|
||||
|
Loading…
Reference in New Issue
Block a user