mirror of
https://github.com/fluencelabs/fluence-js.git
synced 2025-03-15 15:30:49 +00:00
fix eslint rules
This commit is contained in:
parent
af0ee77223
commit
3432968cd4
53
.eslintrc.js
53
.eslintrc.js
@ -1,37 +1,24 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
'env': {
|
env: {
|
||||||
'browser': true,
|
browser: true,
|
||||||
'es2021': true,
|
es2021: true,
|
||||||
'node': true
|
node: true,
|
||||||
},
|
},
|
||||||
'extends': [
|
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
|
||||||
'eslint:recommended',
|
parser: '@typescript-eslint/parser',
|
||||||
'plugin:@typescript-eslint/recommended'
|
parserOptions: {
|
||||||
],
|
ecmaVersion: 13,
|
||||||
'parser': '@typescript-eslint/parser',
|
sourceType: 'module',
|
||||||
'parserOptions': {
|
},
|
||||||
'ecmaVersion': 13,
|
plugins: ['@typescript-eslint', 'simple-import-sort'],
|
||||||
'sourceType': 'module'
|
rules: {
|
||||||
|
indent: ['off'],
|
||||||
|
'linebreak-style': ['error', 'unix'],
|
||||||
|
quotes: ['error', 'single', { avoidEscape: true }],
|
||||||
|
semi: ['error', 'always'],
|
||||||
|
'no-empty-function': 'off',
|
||||||
|
'@typescript-eslint/no-empty-function': ['off'],
|
||||||
|
'simple-import-sort/imports': 'error',
|
||||||
|
'simple-import-sort/exports': 'error',
|
||||||
},
|
},
|
||||||
'plugins': [
|
|
||||||
'@typescript-eslint'
|
|
||||||
],
|
|
||||||
'rules': {
|
|
||||||
'indent': [
|
|
||||||
'error',
|
|
||||||
4
|
|
||||||
],
|
|
||||||
'linebreak-style': [
|
|
||||||
'error',
|
|
||||||
'unix'
|
|
||||||
],
|
|
||||||
'quotes': [
|
|
||||||
'error',
|
|
||||||
'single'
|
|
||||||
],
|
|
||||||
'semi': [
|
|
||||||
'error',
|
|
||||||
'always'
|
|
||||||
]
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
17
package-lock.json
generated
17
package-lock.json
generated
@ -32,6 +32,7 @@
|
|||||||
"@typescript-eslint/eslint-plugin": "^5.7.0",
|
"@typescript-eslint/eslint-plugin": "^5.7.0",
|
||||||
"@typescript-eslint/parser": "^5.7.0",
|
"@typescript-eslint/parser": "^5.7.0",
|
||||||
"eslint": "^8.4.1",
|
"eslint": "^8.4.1",
|
||||||
|
"eslint-plugin-simple-import-sort": "^7.0.0",
|
||||||
"jest": "^26.6.3",
|
"jest": "^26.6.3",
|
||||||
"js-base64": "^3.7.2",
|
"js-base64": "^3.7.2",
|
||||||
"ts-jest": "^26.5.4",
|
"ts-jest": "^26.5.4",
|
||||||
@ -3048,6 +3049,15 @@
|
|||||||
"url": "https://opencollective.com/eslint"
|
"url": "https://opencollective.com/eslint"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/eslint-plugin-simple-import-sort": {
|
||||||
|
"version": "7.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/eslint-plugin-simple-import-sort/-/eslint-plugin-simple-import-sort-7.0.0.tgz",
|
||||||
|
"integrity": "sha512-U3vEDB5zhYPNfxT5TYR7u01dboFZp+HNpnGhkDB2g/2E4wZ/g1Q9Ton8UwCLfRV9yAKyYqDh62oHOamvkFxsvw==",
|
||||||
|
"dev": true,
|
||||||
|
"peerDependencies": {
|
||||||
|
"eslint": ">=5.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/eslint-scope": {
|
"node_modules/eslint-scope": {
|
||||||
"version": "7.1.0",
|
"version": "7.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.1.0.tgz",
|
||||||
@ -11691,6 +11701,13 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"eslint-plugin-simple-import-sort": {
|
||||||
|
"version": "7.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/eslint-plugin-simple-import-sort/-/eslint-plugin-simple-import-sort-7.0.0.tgz",
|
||||||
|
"integrity": "sha512-U3vEDB5zhYPNfxT5TYR7u01dboFZp+HNpnGhkDB2g/2E4wZ/g1Q9Ton8UwCLfRV9yAKyYqDh62oHOamvkFxsvw==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {}
|
||||||
|
},
|
||||||
"eslint-scope": {
|
"eslint-scope": {
|
||||||
"version": "7.1.0",
|
"version": "7.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.1.0.tgz",
|
||||||
|
@ -43,6 +43,7 @@
|
|||||||
"@typescript-eslint/eslint-plugin": "^5.7.0",
|
"@typescript-eslint/eslint-plugin": "^5.7.0",
|
||||||
"@typescript-eslint/parser": "^5.7.0",
|
"@typescript-eslint/parser": "^5.7.0",
|
||||||
"eslint": "^8.4.1",
|
"eslint": "^8.4.1",
|
||||||
|
"eslint-plugin-simple-import-sort": "^7.0.0",
|
||||||
"jest": "^26.6.3",
|
"jest": "^26.6.3",
|
||||||
"js-base64": "^3.7.2",
|
"js-base64": "^3.7.2",
|
||||||
"ts-jest": "^26.5.4",
|
"ts-jest": "^26.5.4",
|
||||||
|
@ -14,18 +14,19 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import Websockets from 'libp2p-websockets';
|
import { NOISE } from '@chainsafe/libp2p-noise';
|
||||||
import Mplex from 'libp2p-mplex';
|
|
||||||
import Lib2p2Peer from 'libp2p';
|
|
||||||
import { decode, encode } from 'it-length-prefixed';
|
import { decode, encode } from 'it-length-prefixed';
|
||||||
import pipe from 'it-pipe';
|
import pipe from 'it-pipe';
|
||||||
import * as log from 'loglevel';
|
import Lib2p2Peer from 'libp2p';
|
||||||
import { Particle } from './Particle';
|
|
||||||
import { NOISE } from '@chainsafe/libp2p-noise';
|
|
||||||
import PeerId from 'peer-id';
|
|
||||||
import { Multiaddr } from 'multiaddr';
|
|
||||||
import { all as allow_all } from 'libp2p-websockets/src/filters';
|
|
||||||
import { Connection } from 'libp2p-interfaces/src/topology';
|
import { Connection } from 'libp2p-interfaces/src/topology';
|
||||||
|
import Mplex from 'libp2p-mplex';
|
||||||
|
import Websockets from 'libp2p-websockets';
|
||||||
|
import { all as allow_all } from 'libp2p-websockets/src/filters';
|
||||||
|
import * as log from 'loglevel';
|
||||||
|
import { Multiaddr } from 'multiaddr';
|
||||||
|
import PeerId from 'peer-id';
|
||||||
|
|
||||||
|
import { Particle } from './Particle';
|
||||||
|
|
||||||
export const PROTOCOL_NAME = '/fluence/particle/2.0.0';
|
export const PROTOCOL_NAME = '/fluence/particle/2.0.0';
|
||||||
|
|
||||||
@ -128,7 +129,7 @@ export class FluenceConnection {
|
|||||||
public async connect() {
|
public async connect() {
|
||||||
await this._lib2p2Peer.start();
|
await this._lib2p2Peer.start();
|
||||||
|
|
||||||
log.debug(`dialing to the node with client's address: ` + this._lib2p2Peer.peerId.toB58String());
|
log.debug(`dialing to the node with client's address: ${this._lib2p2Peer.peerId.toB58String()}`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this._connection = await this._lib2p2Peer.dial(this._relayAddress);
|
this._connection = await this._lib2p2Peer.dial(this._relayAddress);
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
/* eslint-disable sort-imports */
|
||||||
/*
|
/*
|
||||||
* Copyright 2021 Fluence Labs Limited
|
* Copyright 2021 Fluence Labs Limited
|
||||||
*
|
*
|
||||||
@ -14,27 +15,20 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import { AirInterpreter, InterpreterResult, LogLevel } from '@fluencelabs/avm';
|
||||||
AirInterpreter,
|
|
||||||
CallRequestsArray,
|
|
||||||
CallResultsArray,
|
|
||||||
InterpreterResult,
|
|
||||||
LogLevel,
|
|
||||||
CallServiceResult as AvmCallServiceResult,
|
|
||||||
} from '@fluencelabs/avm';
|
|
||||||
import { Multiaddr } from 'multiaddr';
|
|
||||||
import { CallServiceData, CallServiceResult, GenericCallServiceHandler, ResultCodes } from './commonTypes';
|
|
||||||
import { CallServiceHandler as LegacyCallServiceHandler } from './compilerSupport/LegacyCallServiceHandler';
|
|
||||||
import { PeerIdB58 } from './commonTypes';
|
|
||||||
import { FluenceConnection } from './FluenceConnection';
|
|
||||||
import { Particle, ParticleExecutionStage, ParticleQueueItem } from './Particle';
|
|
||||||
import { KeyPair } from './KeyPair';
|
|
||||||
import { createInterpreter, dataToString } from './utils';
|
|
||||||
import { filter, pipe, Subject, tap } from 'rxjs';
|
|
||||||
import { RequestFlow } from './compilerSupport/v1';
|
|
||||||
import log from 'loglevel';
|
import log from 'loglevel';
|
||||||
|
import { Multiaddr } from 'multiaddr';
|
||||||
|
import { filter, pipe, Subject, tap } from 'rxjs';
|
||||||
|
|
||||||
import { BuiltInServiceContext, builtInServices } from './builtInServices';
|
import { BuiltInServiceContext, builtInServices } from './builtInServices';
|
||||||
import { instanceOf } from 'ts-pattern';
|
import { CallServiceData, CallServiceResult, GenericCallServiceHandler, ResultCodes } from './commonTypes';
|
||||||
|
import { PeerIdB58 } from './commonTypes';
|
||||||
|
import { CallServiceHandler as LegacyCallServiceHandler } from './compilerSupport/LegacyCallServiceHandler';
|
||||||
|
import { RequestFlow } from './compilerSupport/v1';
|
||||||
|
import { FluenceConnection } from './FluenceConnection';
|
||||||
|
import { KeyPair } from './KeyPair';
|
||||||
|
import { Particle, ParticleExecutionStage, ParticleQueueItem } from './Particle';
|
||||||
|
import { createInterpreter, dataToString } from './utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Node of the Fluence network specified as a pair of node's multiaddr and it's peer id
|
* Node of the Fluence network specified as a pair of node's multiaddr and it's peer id
|
||||||
@ -111,12 +105,12 @@ export interface PeerStatus {
|
|||||||
/**
|
/**
|
||||||
* Is the peer initialized or not
|
* Is the peer initialized or not
|
||||||
*/
|
*/
|
||||||
isInitialized: Boolean;
|
isInitialized: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is the peer connected to network or not
|
* Is the peer connected to network or not
|
||||||
*/
|
*/
|
||||||
isConnected: Boolean;
|
isConnected: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Peer's identification in the Fluence network
|
* The Peer's identification in the Fluence network
|
||||||
@ -186,7 +180,7 @@ export class FluencePeer {
|
|||||||
|
|
||||||
if (config?.connectTo) {
|
if (config?.connectTo) {
|
||||||
let connectToMultiAddr: Multiaddr;
|
let connectToMultiAddr: Multiaddr;
|
||||||
let fromNode = (config.connectTo as any).multiaddr;
|
const fromNode = (config.connectTo as any).multiaddr;
|
||||||
if (fromNode) {
|
if (fromNode) {
|
||||||
connectToMultiAddr = new Multiaddr(fromNode);
|
connectToMultiAddr = new Multiaddr(fromNode);
|
||||||
} else {
|
} else {
|
||||||
@ -415,7 +409,7 @@ export class FluencePeer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _createParticlesProcessingQueue() {
|
private _createParticlesProcessingQueue() {
|
||||||
let particlesQueue = new Subject<ParticleQueueItem>();
|
const particlesQueue = new Subject<ParticleQueueItem>();
|
||||||
let prevData: Uint8Array = Buffer.from([]);
|
let prevData: Uint8Array = Buffer.from([]);
|
||||||
|
|
||||||
particlesQueue
|
particlesQueue
|
||||||
@ -450,7 +444,7 @@ export class FluencePeer {
|
|||||||
// execute call requests if needed
|
// execute call requests if needed
|
||||||
// and put particle with the results back to queue
|
// and put particle with the results back to queue
|
||||||
if (result.callRequests.length > 0) {
|
if (result.callRequests.length > 0) {
|
||||||
for (let [key, cr] of result.callRequests) {
|
for (const [key, cr] of result.callRequests) {
|
||||||
const req = {
|
const req = {
|
||||||
fnName: cr.functionName,
|
fnName: cr.functionName,
|
||||||
args: cr.arguments,
|
args: cr.arguments,
|
||||||
@ -547,7 +541,7 @@ export class FluencePeer {
|
|||||||
|
|
||||||
private _stopParticleProcessing() {
|
private _stopParticleProcessing() {
|
||||||
// do not hang if the peer has been stopped while some of the timeouts are still being executed
|
// do not hang if the peer has been stopped while some of the timeouts are still being executed
|
||||||
for (let item of this._timeouts) {
|
for (const item of this._timeouts) {
|
||||||
clearTimeout(item);
|
clearTimeout(item);
|
||||||
}
|
}
|
||||||
this._particleQueues.clear();
|
this._particleQueues.clear();
|
||||||
@ -581,8 +575,8 @@ function serviceFnKey(serviceId: string, fnName: string) {
|
|||||||
|
|
||||||
function registerDefaultServices(peer: FluencePeer, context: BuiltInServiceContext) {
|
function registerDefaultServices(peer: FluencePeer, context: BuiltInServiceContext) {
|
||||||
const ctx = builtInServices(context);
|
const ctx = builtInServices(context);
|
||||||
for (let serviceId in ctx) {
|
for (const serviceId in ctx) {
|
||||||
for (let fnName in ctx[serviceId]) {
|
for (const fnName in ctx[serviceId]) {
|
||||||
const h = ctx[serviceId][fnName];
|
const h = ctx[serviceId][fnName];
|
||||||
peer.internals.regHandler.common(serviceId, fnName, h);
|
peer.internals.regHandler.common(serviceId, fnName, h);
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,8 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as PeerId from 'peer-id';
|
|
||||||
import { keys } from 'libp2p-crypto';
|
import { keys } from 'libp2p-crypto';
|
||||||
|
import * as PeerId from 'peer-id';
|
||||||
|
|
||||||
export class KeyPair {
|
export class KeyPair {
|
||||||
/**
|
/**
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
/* eslint-disable sort-imports */
|
||||||
/*
|
/*
|
||||||
* Copyright 2020 Fluence Labs Limited
|
* Copyright 2020 Fluence Labs Limited
|
||||||
*
|
*
|
||||||
@ -14,10 +15,11 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
|
||||||
import { fromByteArray, toByteArray } from 'base64-js';
|
|
||||||
import { CallResultsArray, LogLevel } from '@fluencelabs/avm';
|
import { CallResultsArray, LogLevel } from '@fluencelabs/avm';
|
||||||
|
import { fromByteArray, toByteArray } from 'base64-js';
|
||||||
import log from 'loglevel';
|
import log from 'loglevel';
|
||||||
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
|
|
||||||
import { ParticleContext } from './commonTypes';
|
import { ParticleContext } from './commonTypes';
|
||||||
import { dataToString } from './utils';
|
import { dataToString } from './utils';
|
||||||
|
|
||||||
@ -88,17 +90,16 @@ export class Particle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
toString(): string {
|
toString(): string {
|
||||||
const particle = this;
|
|
||||||
const payload = {
|
const payload = {
|
||||||
action: 'Particle',
|
action: 'Particle',
|
||||||
id: particle.id,
|
id: this.id,
|
||||||
init_peer_id: particle.initPeerId,
|
init_peer_id: this.initPeerId,
|
||||||
timestamp: particle.timestamp,
|
timestamp: this.timestamp,
|
||||||
ttl: particle.ttl,
|
ttl: this.ttl,
|
||||||
script: particle.script,
|
script: this.script,
|
||||||
// TODO: copy signature from a particle after signatures will be implemented on nodes
|
// TODO: copy signature from a particle after signatures will be implemented on nodes
|
||||||
signature: [],
|
signature: [],
|
||||||
data: fromByteArray(particle.data),
|
data: fromByteArray(this.data),
|
||||||
};
|
};
|
||||||
|
|
||||||
return JSON.stringify(payload);
|
return JSON.stringify(payload);
|
||||||
|
@ -15,9 +15,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { CallServiceResult } from '@fluencelabs/avm';
|
import { CallServiceResult } from '@fluencelabs/avm';
|
||||||
import { encode, decode } from 'bs58';
|
import { decode, encode } from 'bs58';
|
||||||
import { PeerIdB58 } from 'src';
|
|
||||||
import { GenericCallServiceHandler, ResultCodes } from './commonTypes';
|
import { GenericCallServiceHandler, PeerIdB58, ResultCodes } from './commonTypes';
|
||||||
import { KeyPair } from './KeyPair';
|
import { KeyPair } from './KeyPair';
|
||||||
|
|
||||||
const success = (result: any): CallServiceResult => {
|
const success = (result: any): CallServiceResult => {
|
||||||
@ -70,7 +70,7 @@ export function builtInServices(context: BuiltInServiceContext): {
|
|||||||
const str = incorrectArgIndices.join(', ');
|
const str = incorrectArgIndices.join(', ');
|
||||||
return error(`All arguments of 'concat' must be arrays: arguments ${str} are not`);
|
return error(`All arguments of 'concat' must be arrays: arguments ${str} are not`);
|
||||||
} else {
|
} else {
|
||||||
return success([].concat.apply([], req.args));
|
return success([].concat(...req.args));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
/* eslint-disable @typescript-eslint/ban-types */
|
||||||
/*
|
/*
|
||||||
* Copyright 2021 Fluence Labs Limited
|
* Copyright 2021 Fluence Labs Limited
|
||||||
*
|
*
|
||||||
@ -27,6 +28,7 @@ export const callLegacyCallServiceHandler = (
|
|||||||
): CallServiceResult => {
|
): CallServiceResult => {
|
||||||
// trying particle-specific handler
|
// trying particle-specific handler
|
||||||
if (particleSpecificHandler !== undefined) {
|
if (particleSpecificHandler !== undefined) {
|
||||||
|
// eslint-disable-next-line no-var
|
||||||
var res = particleSpecificHandler.execute(req);
|
var res = particleSpecificHandler.execute(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,11 +14,11 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { CallServiceHandler } from './LegacyCallServiceHandler';
|
|
||||||
import { Particle } from '../Particle';
|
import { Particle } from '../Particle';
|
||||||
|
import { CallServiceHandler } from './LegacyCallServiceHandler';
|
||||||
|
|
||||||
export { FluencePeer } from '../FluencePeer';
|
|
||||||
export { CallParams, ResultCodes } from '../commonTypes';
|
export { CallParams, ResultCodes } from '../commonTypes';
|
||||||
|
export { FluencePeer } from '../FluencePeer';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated This class exists to glue legacy RequestFlowBuilder api with restructured async FluencePeer.
|
* @deprecated This class exists to glue legacy RequestFlowBuilder api with restructured async FluencePeer.
|
||||||
@ -43,8 +43,8 @@ export class RequestFlowBuilder {
|
|||||||
private _timeout: () => void = () => {};
|
private _timeout: () => void = () => {};
|
||||||
|
|
||||||
build(): RequestFlow {
|
build(): RequestFlow {
|
||||||
let h = new CallServiceHandler();
|
const h = new CallServiceHandler();
|
||||||
for (let c of this._configs) {
|
for (const c of this._configs) {
|
||||||
c(h);
|
c(h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,12 +16,13 @@
|
|||||||
|
|
||||||
import { SecurityTetraplet } from '@fluencelabs/avm';
|
import { SecurityTetraplet } from '@fluencelabs/avm';
|
||||||
import { match } from 'ts-pattern';
|
import { match } from 'ts-pattern';
|
||||||
|
|
||||||
import { CallParams, Fluence, FluencePeer } from '../../index';
|
import { CallParams, Fluence, FluencePeer } from '../../index';
|
||||||
import { CallServiceData, GenericCallServiceHandler, CallServiceResult, ResultCodes } from '../commonTypes';
|
import { CallServiceData, CallServiceResult, GenericCallServiceHandler, ResultCodes } from '../commonTypes';
|
||||||
import { Particle } from '../Particle';
|
import { Particle } from '../Particle';
|
||||||
|
|
||||||
export { FluencePeer } from '../FluencePeer';
|
|
||||||
export { CallParams } from '../commonTypes';
|
export { CallParams } from '../commonTypes';
|
||||||
|
export { FluencePeer } from '../FluencePeer';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the Aqua Option type
|
* Represents the Aqua Option type
|
||||||
@ -227,7 +228,7 @@ export function callFunction(rawFnArgs: Array<any>, def: FunctionCallDef, script
|
|||||||
const fn = async (req: CallServiceData): Promise<CallServiceResult> => {
|
const fn = async (req: CallServiceData): Promise<CallServiceResult> => {
|
||||||
const args = convertArgsFromReqToUserCall(req, callbackDef.callback.argDefs);
|
const args = convertArgsFromReqToUserCall(req, callbackDef.callback.argDefs);
|
||||||
// arg is function at this point
|
// arg is function at this point
|
||||||
const result = await arg.apply(null, args);
|
const result = await arg(...args);
|
||||||
let res;
|
let res;
|
||||||
switch (callbackDef.callback.returnType.tag) {
|
switch (callbackDef.callback.returnType.tag) {
|
||||||
case 'void':
|
case 'void':
|
||||||
@ -366,6 +367,7 @@ export function registerService(args: any[], def: ServiceDef) {
|
|||||||
// Checking for missing keys
|
// Checking for missing keys
|
||||||
const requiredKeys = def.functions.map((x) => x.functionName);
|
const requiredKeys = def.functions.map((x) => x.functionName);
|
||||||
const incorrectServiceDefinitions = requiredKeys.filter((f) => !(f in service));
|
const incorrectServiceDefinitions = requiredKeys.filter((f) => !(f in service));
|
||||||
|
// eslint-disable-next-line no-extra-boolean-cast
|
||||||
if (!!incorrectServiceDefinitions.length) {
|
if (!!incorrectServiceDefinitions.length) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Error registering service ${serviceId}: missing functions: ` +
|
`Error registering service ${serviceId}: missing functions: ` +
|
||||||
@ -373,14 +375,14 @@ export function registerService(args: any[], def: ServiceDef) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let singleFunction of def.functions) {
|
for (const singleFunction of def.functions) {
|
||||||
// The function has type of (arg1, arg2, arg3, ... , callParams) => CallServiceResultType | void
|
// The function has type of (arg1, arg2, arg3, ... , callParams) => CallServiceResultType | void
|
||||||
// Account for the fact that user service might be defined as a class - .bind(...)
|
// Account for the fact that user service might be defined as a class - .bind(...)
|
||||||
const userDefinedHandler = service[singleFunction.functionName].bind(service);
|
const userDefinedHandler = service[singleFunction.functionName].bind(service);
|
||||||
|
|
||||||
peer.internals.regHandler.common(serviceId, singleFunction.functionName, async (req) => {
|
peer.internals.regHandler.common(serviceId, singleFunction.functionName, async (req) => {
|
||||||
const args = convertArgsFromReqToUserCall(req, singleFunction.argDefs);
|
const args = convertArgsFromReqToUserCall(req, singleFunction.argDefs);
|
||||||
const rawResult = await userDefinedHandler.apply(null, args);
|
const rawResult = await userDefinedHandler(...args);
|
||||||
const result = match(singleFunction.returnType)
|
const result = match(singleFunction.returnType)
|
||||||
.with({ tag: 'primitive' }, () => rawResult)
|
.with({ tag: 'primitive' }, () => rawResult)
|
||||||
.with({ tag: 'optional' }, () => tsToAquaOpt(rawResult))
|
.with({ tag: 'optional' }, () => tsToAquaOpt(rawResult))
|
||||||
@ -434,7 +436,7 @@ const extractCallParams = (
|
|||||||
req: CallServiceData,
|
req: CallServiceData,
|
||||||
argDefs: Array<ArgDef<OptionalType | PrimitiveType>>,
|
argDefs: Array<ArgDef<OptionalType | PrimitiveType>>,
|
||||||
): CallParams<any> => {
|
): CallParams<any> => {
|
||||||
let tetraplets: { [key in string]: SecurityTetraplet[] } = {};
|
const tetraplets: { [key in string]: SecurityTetraplet[] } = {};
|
||||||
for (let i = 0; i < req.args.length; i++) {
|
for (let i = 0; i < req.args.length; i++) {
|
||||||
if (argDefs[i]) {
|
if (argDefs[i]) {
|
||||||
tetraplets[argDefs[i].name] = req.tetraplets[i];
|
tetraplets[argDefs[i].name] = req.tetraplets[i];
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
import { AirInterpreter, LogLevel as AvmLogLevel } from '@fluencelabs/avm';
|
import { AirInterpreter, LogLevel as AvmLogLevel } from '@fluencelabs/avm';
|
||||||
import log from 'loglevel';
|
import log from 'loglevel';
|
||||||
|
|
||||||
import { CallServiceData, CallServiceResult, CallServiceResultType, ResultCodes } from './commonTypes';
|
import { CallServiceData, CallServiceResult, CallServiceResultType, ResultCodes } from './commonTypes';
|
||||||
import { AvmLoglevel, FluencePeer } from './FluencePeer';
|
import { AvmLoglevel, FluencePeer } from './FluencePeer';
|
||||||
import { Particle, ParticleExecutionStage } from './Particle';
|
import { Particle, ParticleExecutionStage } from './Particle';
|
||||||
@ -53,7 +54,7 @@ export const MakeServiceCall = (fn: (args: any[]) => CallServiceResultType) => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const handleTimeout = (fn: Function) => (stage: ParticleExecutionStage) => {
|
export const handleTimeout = (fn: () => void) => (stage: ParticleExecutionStage) => {
|
||||||
if (stage.stage === 'expired') {
|
if (stage.stage === 'expired') {
|
||||||
fn();
|
fn();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user