mirror of
https://github.com/fluencelabs/fluence-js.git
synced 2025-06-11 15:11:21 +00:00
Take one down, patch it around,
127 little bug in the code...
This commit is contained in:
@ -19,6 +19,7 @@
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@fluencelabs/js-client.api": "workspace:*",
|
||||
"@fluencelabs/interface": "workspace:*",
|
||||
"@fluencelabs/fluence-network-environment": "1.0.13"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
@ -6,8 +6,7 @@
|
||||
* Aqua version: 0.7.2-314
|
||||
*
|
||||
*/
|
||||
import type { IFluencePeer } from '@fluencelabs/js-peer/dist/interfaces';
|
||||
import type { CallParams } from '@fluencelabs/js-peer/dist/interfaces/commonTypes';
|
||||
import type { IFluencePeer, CallParams } from '@fluencelabs/interface';
|
||||
import { callFunction$$, registerService$$ } from '@fluencelabs/js-client.api/dist/compilerSupport/v4';
|
||||
|
||||
// Services
|
||||
|
@ -29,8 +29,8 @@
|
||||
"repository": "https://github.com/fluencelabs/fluence-js",
|
||||
"author": "Fluence Labs",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"@fluencelabs/js-peer": "workspace:*"
|
||||
}
|
||||
"dependencies": {
|
||||
"@fluencelabs/interface": "workspace:*"
|
||||
},
|
||||
"devDependencies": {}
|
||||
}
|
||||
|
@ -14,15 +14,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { IFluencePeer, isFluencePeer } from '@fluencelabs/js-peer/dist/interfaces/index';
|
||||
import { FnConfig, FunctionCallDef, ServiceDef } from '@fluencelabs/js-peer/dist/js-peer/compilerSupport/interface';
|
||||
import { registerServiceImpl } from '@fluencelabs/js-peer/dist/js-peer/compilerSupport/registerService';
|
||||
import { callFunctionImpl, getArgumentTypes } from '@fluencelabs/js-peer/dist/js-peer/compilerSupport/callFunction';
|
||||
import type { IFluencePeer, CallParams, FnConfig, FunctionCallDef, ServiceDef } from '@fluencelabs/interface';
|
||||
import { getArgumentTypes } from '@fluencelabs/interface';
|
||||
import { isFluencePeer } from '@fluencelabs/interface';
|
||||
|
||||
import { getDefaultPeer } from '../index.js';
|
||||
|
||||
export type { IFluencePeer } from '@fluencelabs/js-peer/dist/interfaces/index';
|
||||
export type { CallParams } from '@fluencelabs/js-peer/dist/interfaces/commonTypes';
|
||||
export type { IFluencePeer, CallParams } from '@fluencelabs/interface';
|
||||
|
||||
export {
|
||||
ArrayType,
|
||||
@ -44,9 +42,7 @@ export {
|
||||
StructType,
|
||||
TopType,
|
||||
UnlabeledProductType,
|
||||
} from '@fluencelabs/js-peer/dist/js-peer/compilerSupport/interface';
|
||||
export { callFunctionImpl } from '@fluencelabs/js-peer/dist/js-peer/compilerSupport/callFunction';
|
||||
export { registerServiceImpl } from '@fluencelabs/js-peer/dist/js-peer/compilerSupport/registerService';
|
||||
} from '@fluencelabs/interface';
|
||||
|
||||
/**
|
||||
* Convenience function to support Aqua `func` generation backend
|
||||
@ -58,7 +54,12 @@ export { registerServiceImpl } from '@fluencelabs/js-peer/dist/js-peer/compilerS
|
||||
*/
|
||||
export const callFunction = async (rawFnArgs: Array<any>, def: FunctionCallDef, script: string): Promise<unknown> => {
|
||||
const { args, peer, config } = await extractFunctionArgs(rawFnArgs, def);
|
||||
return callFunctionImpl(def, script, config || {}, peer, args);
|
||||
return peer.compilerSupport.callFunction({
|
||||
args,
|
||||
def,
|
||||
script,
|
||||
config: config || {},
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
@ -70,8 +71,11 @@ export const callFunction = async (rawFnArgs: Array<any>, def: FunctionCallDef,
|
||||
*/
|
||||
export const registerService = async (args: any[], def: ServiceDef): Promise<unknown> => {
|
||||
const { peer, service, serviceId } = await extractServiceArgs(args, def.defaultServiceId);
|
||||
|
||||
return registerServiceImpl(peer, def, serviceId, service);
|
||||
return peer.compilerSupport.registerService({
|
||||
def,
|
||||
service,
|
||||
serviceId,
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -38,6 +38,4 @@ export {
|
||||
UnlabeledProductType as UnlabeledProductType$$,
|
||||
callFunction as callFunction$$,
|
||||
registerService as registerService$$,
|
||||
registerServiceImpl as registerServiceImpl$$,
|
||||
callFunctionImpl as callFunctionImpl$$,
|
||||
} from './v3';
|
||||
|
@ -1,5 +1,4 @@
|
||||
import type { IFluencePeer } from '@fluencelabs/js-peer/dist/interfaces/index.js';
|
||||
import type { PeerConfig } from '@fluencelabs/js-peer/dist/interfaces/peerConfig';
|
||||
import type { IFluencePeer, PeerConfig } from '@fluencelabs/interface';
|
||||
|
||||
const getPeerFromGlobalThis = (): IFluencePeer | undefined => {
|
||||
// @ts-ignore
|
||||
|
29
packages/core/interface/package.json
Normal file
29
packages/core/interface/package.json
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
"name": "@fluencelabs/interface",
|
||||
"version": "0.1.0",
|
||||
"description": "Interfaces",
|
||||
"main": "./dist/index.js",
|
||||
"typings": "./dist/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts"
|
||||
}
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10",
|
||||
"pnpm": ">=3"
|
||||
},
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "tsc"
|
||||
},
|
||||
"repository": "https://github.com/fluencelabs/fluence-js",
|
||||
"author": "Fluence Labs",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"@multiformats/multiaddr": "11.3.0",
|
||||
"@fluencelabs/avm": "0.35.3"
|
||||
}
|
||||
}
|
@ -236,3 +236,23 @@ export interface FnConfig {
|
||||
*/
|
||||
ttl?: number;
|
||||
}
|
||||
|
||||
export const getArgumentTypes = (
|
||||
def: FunctionCallDef,
|
||||
): {
|
||||
[key: string]: NonArrowType | ArrowWithoutCallbacks;
|
||||
} => {
|
||||
if (def.arrow.domain.tag !== 'labeledProduct') {
|
||||
throw new Error('Should be impossible');
|
||||
}
|
||||
|
||||
return def.arrow.domain.fields;
|
||||
};
|
||||
|
||||
export const isReturnTypeVoid = (def: FunctionCallDef): boolean => {
|
||||
if (def.arrow.codomain.tag === 'nil') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return def.arrow.codomain.items.length == 0;
|
||||
};
|
@ -1,6 +1,48 @@
|
||||
import { SecurityTetraplet } from '@fluencelabs/avm';
|
||||
import type { MultiaddrInput } from '@multiformats/multiaddr';
|
||||
import type { PeerIdB58 } from './commonTypes';
|
||||
// import { KeyPair } from '../keypair';
|
||||
import { FnConfig, FunctionCallDef, ServiceDef } from './compilerSupport';
|
||||
export * from './compilerSupport';
|
||||
|
||||
/**
|
||||
* Peer ID's id as a base58 string (multihash/CIDv0).
|
||||
*/
|
||||
export type PeerIdB58 = string;
|
||||
|
||||
/**
|
||||
* Additional information about a service call
|
||||
* @typeparam ArgName
|
||||
*/
|
||||
export interface CallParams<ArgName extends string | null> {
|
||||
/**
|
||||
* The identifier of particle which triggered the call
|
||||
*/
|
||||
particleId: string;
|
||||
|
||||
/**
|
||||
* The peer id which created the particle
|
||||
*/
|
||||
initPeerId: PeerIdB58;
|
||||
|
||||
/**
|
||||
* Particle's timestamp when it was created
|
||||
*/
|
||||
timestamp: number;
|
||||
|
||||
/**
|
||||
* Time to live in milliseconds. The time after the particle should be expired
|
||||
*/
|
||||
ttl: number;
|
||||
|
||||
/**
|
||||
* Particle's signature
|
||||
*/
|
||||
signature?: string;
|
||||
|
||||
/**
|
||||
* Security tetraplets
|
||||
*/
|
||||
tetraplets: ArgName extends string ? Record<ArgName, SecurityTetraplet[]> : Record<string, never>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Node of the Fluence network specified as a pair of node's multiaddr and it's peer id
|
||||
@ -104,3 +146,84 @@ export interface PeerConfig {
|
||||
// marineLogLevel?: LogLevel;
|
||||
// };
|
||||
}
|
||||
|
||||
/**
|
||||
* Information about Fluence Peer connection.
|
||||
* Represented as object with the following keys:
|
||||
* - `isInitialized`: Is the peer initialized or not.
|
||||
* - `peerId`: Peer Id of the peer. Null if the peer is not initialized
|
||||
* - `isConnected`: Is the peer connected to network or not
|
||||
* - `relayPeerId`: Peer Id of the relay the peer is connected to. If the connection is direct relayPeerId is null
|
||||
* - `isDirect`: True if the peer is connected to the network directly (not through relay)
|
||||
*/
|
||||
export type PeerStatus =
|
||||
| {
|
||||
isInitialized: false;
|
||||
peerId: null;
|
||||
isConnected: false;
|
||||
relayPeerId: null;
|
||||
}
|
||||
| {
|
||||
isInitialized: true;
|
||||
peerId: PeerIdB58;
|
||||
isConnected: false;
|
||||
relayPeerId: null;
|
||||
}
|
||||
| {
|
||||
isInitialized: true;
|
||||
peerId: PeerIdB58;
|
||||
isConnected: true;
|
||||
relayPeerId: PeerIdB58;
|
||||
}
|
||||
| {
|
||||
isInitialized: true;
|
||||
peerId: PeerIdB58;
|
||||
isConnected: true;
|
||||
isDirect: true;
|
||||
relayPeerId: null;
|
||||
};
|
||||
|
||||
export interface IFluencePeer {
|
||||
start(config?: PeerConfig): Promise<void>;
|
||||
stop(): Promise<void>;
|
||||
getStatus(): PeerStatus;
|
||||
|
||||
// TODO: come up with a working interface for
|
||||
// - particle creation
|
||||
// - particle initialization
|
||||
// - service registration
|
||||
internals: any;
|
||||
compilerSupport: {
|
||||
callFunction: (args: CallFunctionArgs) => Promise<unknown>;
|
||||
registerService: (args: RegisterServiceArgs) => void;
|
||||
};
|
||||
}
|
||||
|
||||
export interface CallFunctionArgs {
|
||||
def: FunctionCallDef;
|
||||
script: string;
|
||||
config: FnConfig;
|
||||
args: { [key: string]: any };
|
||||
}
|
||||
|
||||
export interface RegisterServiceArgs {
|
||||
def: ServiceDef;
|
||||
serviceId: string | undefined;
|
||||
service: any;
|
||||
}
|
||||
|
||||
export const asFluencePeer = (fluencePeerCandidate: unknown): IFluencePeer => {
|
||||
if (isFluencePeer(fluencePeerCandidate)) {
|
||||
return fluencePeerCandidate;
|
||||
}
|
||||
|
||||
throw new Error('');
|
||||
};
|
||||
|
||||
export const isFluencePeer = (fluencePeerCandidate: unknown): fluencePeerCandidate is IFluencePeer => {
|
||||
if (fluencePeerCandidate && (fluencePeerCandidate as any).__isFluenceAwesome) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"extends": "../../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist",
|
||||
"moduleResolution": "node"
|
@ -21,6 +21,7 @@
|
||||
"author": "Fluence Labs",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@fluencelabs/interface": "workspace:*",
|
||||
"@fluencelabs/avm": "0.31.10",
|
||||
"@fluencelabs/marine-js": "0.3.44",
|
||||
"multiformats": "11.0.1",
|
||||
@ -58,7 +59,6 @@
|
||||
"@fluencelabs/aqua-api": "0.9.1-373",
|
||||
"@fluencelabs/aqua-lib": "0.6.0",
|
||||
"@fluencelabs/fluence-network-environment": "1.0.13",
|
||||
"@multiformats/multiaddr": "11.3.0",
|
||||
"@types/bs58": "4.0.1",
|
||||
"@types/platform": "1.3.4",
|
||||
"@types/uuid": "8.3.2",
|
@ -1,4 +1,4 @@
|
||||
import { aqua2ts, ts2aqua } from '../../../compilerSupport/conversions.js';
|
||||
import { aqua2ts, ts2aqua } from '../conversions';
|
||||
|
||||
const i32 = { tag: 'scalar', name: 'i32' } as const;
|
||||
|
@ -1,5 +1,12 @@
|
||||
import { ArrowWithoutCallbacks, FnConfig, FunctionCallDef, NonArrowType } from './interface.js';
|
||||
import { IFluencePeer } from '../../interfaces/index';
|
||||
import {
|
||||
ArrowWithoutCallbacks,
|
||||
FnConfig,
|
||||
FunctionCallDef,
|
||||
NonArrowType,
|
||||
getArgumentTypes,
|
||||
isReturnTypeVoid,
|
||||
} from '@fluencelabs/interface';
|
||||
import { IFluencePeer } from '@fluencelabs/interface';
|
||||
|
||||
import {
|
||||
injectRelayService,
|
||||
@ -81,23 +88,3 @@ export function callFunctionImpl(
|
||||
|
||||
return promise;
|
||||
}
|
||||
|
||||
const isReturnTypeVoid = (def: FunctionCallDef): boolean => {
|
||||
if (def.arrow.codomain.tag === 'nil') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return def.arrow.codomain.items.length == 0;
|
||||
};
|
||||
|
||||
export const getArgumentTypes = (
|
||||
def: FunctionCallDef,
|
||||
): {
|
||||
[key: string]: NonArrowType | ArrowWithoutCallbacks;
|
||||
} => {
|
||||
if (def.arrow.domain.tag !== 'labeledProduct') {
|
||||
throw new Error('Should be impossible');
|
||||
}
|
||||
|
||||
return def.arrow.domain.fields;
|
||||
};
|
@ -1,7 +1,7 @@
|
||||
import { jsonify } from '../utils.js';
|
||||
import { jsonify } from '../js-peer/utils.js';
|
||||
import { match } from 'ts-pattern';
|
||||
import { ArrowType, ArrowWithoutCallbacks, NonArrowType } from './interface.js';
|
||||
import { CallServiceData } from '../../interfaces/commonTypes.js';
|
||||
import { ArrowType, ArrowWithoutCallbacks, NonArrowType } from '@fluencelabs/interface';
|
||||
import { CallServiceData } from '../interfaces/commonTypes.js';
|
||||
|
||||
/**
|
||||
* Convert value from its representation in aqua language to representation in typescript
|
@ -1,5 +1,5 @@
|
||||
import type { IFluencePeer } from '../../interfaces/index';
|
||||
import { ServiceDef } from './interface.js';
|
||||
import { IFluencePeer } from '@fluencelabs/interface';
|
||||
import { ServiceDef } from '@fluencelabs/interface';
|
||||
import { registerGlobalService, userHandlerService } from './services.js';
|
||||
|
||||
export const registerServiceImpl = (
|
@ -1,12 +1,12 @@
|
||||
import { SecurityTetraplet } from '@fluencelabs/avm';
|
||||
import { match } from 'ts-pattern';
|
||||
|
||||
import { Particle } from '../Particle.js';
|
||||
import { CallParams, CallServiceData, GenericCallServiceHandler, ResultCodes } from '../../interfaces/commonTypes.js';
|
||||
import { IFluencePeer } from '../../interfaces/index';
|
||||
import { Particle } from '../js-peer/Particle.js';
|
||||
import { CallServiceData, GenericCallServiceHandler, ResultCodes } from '../interfaces/commonTypes.js';
|
||||
import { IFluencePeer, CallParams } from '@fluencelabs/interface';
|
||||
|
||||
import { aquaArgs2Ts, responseServiceValue2ts, returnType2Aqua, ts2aqua } from './conversions.js';
|
||||
import { ArrowWithoutCallbacks, FunctionCallConstants, FunctionCallDef, NonArrowType } from './interface.js';
|
||||
import { ArrowWithoutCallbacks, FunctionCallConstants, FunctionCallDef, NonArrowType } from '@fluencelabs/interface';
|
||||
|
||||
export interface ServiceDescription {
|
||||
serviceId: string;
|
@ -13,7 +13,8 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { FluenceConnection, ParticleHandler, PeerIdB58 } from '../interfaces/index.js';
|
||||
import { PeerIdB58 } from '@fluencelabs/interface';
|
||||
import { FluenceConnection, ParticleHandler } from '../interfaces/index.js';
|
||||
import { pipe } from 'it-pipe';
|
||||
import { encode, decode } from 'it-length-prefixed';
|
||||
import type { PeerId } from '@libp2p/interface-peer-id';
|
||||
@ -82,7 +83,6 @@ export class RelayConnection extends FluenceConnection {
|
||||
connectionEncryption: [noise()],
|
||||
});
|
||||
|
||||
|
||||
const relayMultiaddr = multiaddr(options.relayAddress);
|
||||
const relayPeerId = relayMultiaddr.getPeerId();
|
||||
if (relayPeerId === null) {
|
||||
@ -158,7 +158,6 @@ export class RelayConnection extends FluenceConnection {
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
log.debug(`dialing to the node with client's address: ` + this._lib2p2Peer.peerId.toString());
|
||||
|
||||
try {
|
@ -14,48 +14,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { SecurityTetraplet } from '@fluencelabs/avm';
|
||||
|
||||
/**
|
||||
* Peer ID's id as a base58 string (multihash/CIDv0).
|
||||
*/
|
||||
export type PeerIdB58 = string;
|
||||
|
||||
/**
|
||||
* Additional information about a service call
|
||||
* @typeparam ArgName
|
||||
*/
|
||||
export interface CallParams<ArgName extends string | null> {
|
||||
/**
|
||||
* The identifier of particle which triggered the call
|
||||
*/
|
||||
particleId: string;
|
||||
|
||||
/**
|
||||
* The peer id which created the particle
|
||||
*/
|
||||
initPeerId: PeerIdB58;
|
||||
|
||||
/**
|
||||
* Particle's timestamp when it was created
|
||||
*/
|
||||
timestamp: number;
|
||||
|
||||
/**
|
||||
* Time to live in milliseconds. The time after the particle should be expired
|
||||
*/
|
||||
ttl: number;
|
||||
|
||||
/**
|
||||
* Particle's signature
|
||||
*/
|
||||
signature?: string;
|
||||
|
||||
/**
|
||||
* Security tetraplets
|
||||
*/
|
||||
tetraplets: ArgName extends string ? Record<ArgName, SecurityTetraplet[]> : Record<string, never>;
|
||||
}
|
||||
import type { PeerIdB58 } from '@fluencelabs/interface';
|
||||
import type { SecurityTetraplet } from '@fluencelabs/avm';
|
||||
|
||||
export enum ResultCodes {
|
||||
success = 0,
|
@ -14,79 +14,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import type { PeerIdB58 } from '@fluencelabs/interface';
|
||||
import type { JSONArray, JSONObject, LogLevel } from '@fluencelabs/marine-js/dist/types';
|
||||
import type { RunParameters, CallResultsArray, InterpreterResult } from '@fluencelabs/avm';
|
||||
import type { WorkerImplementation } from 'threads/dist/types/master';
|
||||
import { PeerConfig } from './peerConfig';
|
||||
|
||||
export type PeerIdB58 = string;
|
||||
|
||||
export type ParticleHandler = (particle: string) => void;
|
||||
|
||||
/**
|
||||
* Information about Fluence Peer connection.
|
||||
* Represented as object with the following keys:
|
||||
* - `isInitialized`: Is the peer initialized or not.
|
||||
* - `peerId`: Peer Id of the peer. Null if the peer is not initialized
|
||||
* - `isConnected`: Is the peer connected to network or not
|
||||
* - `relayPeerId`: Peer Id of the relay the peer is connected to. If the connection is direct relayPeerId is null
|
||||
* - `isDirect`: True if the peer is connected to the network directly (not through relay)
|
||||
*/
|
||||
export type PeerStatus =
|
||||
| {
|
||||
isInitialized: false;
|
||||
peerId: null;
|
||||
isConnected: false;
|
||||
relayPeerId: null;
|
||||
}
|
||||
| {
|
||||
isInitialized: true;
|
||||
peerId: PeerIdB58;
|
||||
isConnected: false;
|
||||
relayPeerId: null;
|
||||
}
|
||||
| {
|
||||
isInitialized: true;
|
||||
peerId: PeerIdB58;
|
||||
isConnected: true;
|
||||
relayPeerId: PeerIdB58;
|
||||
}
|
||||
| {
|
||||
isInitialized: true;
|
||||
peerId: PeerIdB58;
|
||||
isConnected: true;
|
||||
isDirect: true;
|
||||
relayPeerId: null;
|
||||
};
|
||||
|
||||
export interface IFluencePeer {
|
||||
start(config?: PeerConfig): Promise<void>;
|
||||
stop(): Promise<void>;
|
||||
getStatus(): PeerStatus;
|
||||
|
||||
// TODO: come up with a working interface for
|
||||
// - particle creation
|
||||
// - particle initialization
|
||||
// - service registration
|
||||
internals: any;
|
||||
}
|
||||
|
||||
export const asFluencePeer = (fluencePeerCandidate: unknown): IFluencePeer => {
|
||||
if (isFluencePeer(fluencePeerCandidate)) {
|
||||
return fluencePeerCandidate;
|
||||
}
|
||||
|
||||
throw new Error('');
|
||||
};
|
||||
|
||||
export const isFluencePeer = (fluencePeerCandidate: unknown): fluencePeerCandidate is IFluencePeer => {
|
||||
if (fluencePeerCandidate && (fluencePeerCandidate as any).__isFluenceAwesome) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Base class for connectivity layer to Fluence Network
|
||||
*/
|
@ -16,7 +16,7 @@
|
||||
import 'buffer';
|
||||
|
||||
import { RelayConnection } from '../connection/index.js';
|
||||
import { FluenceConnection, IAvmRunner, IFluencePeer, IMarine, PeerStatus } from '../interfaces/index.js';
|
||||
import { FluenceConnection, IAvmRunner, IMarine } from '../interfaces/index.js';
|
||||
import { KeyPair } from '../keypair/index.js';
|
||||
import {
|
||||
CallServiceData,
|
||||
@ -24,7 +24,16 @@ import {
|
||||
GenericCallServiceHandler,
|
||||
ResultCodes,
|
||||
} from '../interfaces/commonTypes.js';
|
||||
import { PeerIdB58 } from '../interfaces/commonTypes.js';
|
||||
import {
|
||||
PeerIdB58,
|
||||
CallParams,
|
||||
PeerConfig,
|
||||
ConnectionOption,
|
||||
IFluencePeer,
|
||||
PeerStatus,
|
||||
CallFunctionArgs,
|
||||
RegisterServiceArgs,
|
||||
} from '@fluencelabs/interface';
|
||||
import { Particle, ParticleExecutionStage, ParticleQueueItem } from './Particle.js';
|
||||
import { throwIfNotSupported, dataToString, jsonify, isString, ServiceError } from './utils.js';
|
||||
import { concatMap, filter, pipe, Subject, tap } from 'rxjs';
|
||||
@ -39,8 +48,9 @@ import { JSONValue } from '@fluencelabs/avm';
|
||||
import { LogLevel } from '@fluencelabs/marine-js/dist/types';
|
||||
import { NodeUtils, Srv } from './builtins/SingleModuleSrv.js';
|
||||
import { registerNodeUtils } from './_aqua/node-utils.js';
|
||||
import { ConnectionOption, PeerConfig } from '../interfaces/peerConfig.js';
|
||||
import type { MultiaddrInput } from '@multiformats/multiaddr';
|
||||
import { callFunctionImpl } from '../compilerSupport/callFunction.js';
|
||||
import { registerServiceImpl } from '../compilerSupport/registerService.js';
|
||||
|
||||
const DEFAULT_TTL = 7000;
|
||||
|
||||
@ -222,6 +232,16 @@ export class FluencePeer implements IFluencePeer {
|
||||
}
|
||||
|
||||
// internal api
|
||||
get compilerSupport() {
|
||||
return {
|
||||
callFunction: (args: CallFunctionArgs): Promise<unknown> => {
|
||||
return callFunctionImpl(args.def, args.script, args.config, this, args.args);
|
||||
},
|
||||
registerService: (args: RegisterServiceArgs): void => {
|
||||
return registerServiceImpl(this, args.def, args.serviceId, args.service);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @private Is not intended to be used manually. Subject to change
|
@ -1,5 +1,6 @@
|
||||
import { CallParams } from '@fluencelabs/interface';
|
||||
import { toUint8Array } from 'js-base64';
|
||||
import { CallParams, CallServiceData } from '../../../interfaces/commonTypes.js';
|
||||
import { CallServiceData } from '../../../interfaces/commonTypes.js';
|
||||
import { builtInServices } from '../../builtins/common.js';
|
||||
import { KeyPair } from '../../../keypair/index.js';
|
||||
import { Sig, defaultSigGuard } from '../../builtins/Sig.js';
|
@ -5,8 +5,8 @@ import { FluencePeer, PeerConfig2 as PeerConfig } from '../FluencePeer.js';
|
||||
import { Particle } from '../Particle.js';
|
||||
import { MakeServiceCall } from '../utils.js';
|
||||
import { avmModuleLoader, controlModuleLoader } from '../utilsForNode.js';
|
||||
import { ServiceDef } from '../compilerSupport/interface.js';
|
||||
import { callFunctionImpl } from '../compilerSupport/callFunction.js';
|
||||
import { ServiceDef } from '@fluencelabs/interface';
|
||||
import { callFunctionImpl } from '../../compilerSupport/callFunction.js';
|
||||
|
||||
import { marineLogFunction } from '../utils.js';
|
||||
import { MarineBackgroundRunner } from '../../marine/worker/index.js';
|
@ -6,8 +6,8 @@
|
||||
* Aqua version: 0.7.7-362
|
||||
*
|
||||
*/
|
||||
import { CallParams } from '../../interfaces/commonTypes.js';
|
||||
import { registerServiceImpl } from '../compilerSupport/registerService.js';
|
||||
import { CallParams } from '@fluencelabs/interface';
|
||||
import { registerServiceImpl } from '../../compilerSupport/registerService.js';
|
||||
import { FluencePeer } from '../FluencePeer.js';
|
||||
|
||||
// Services
|
@ -6,8 +6,8 @@
|
||||
* Aqua version: 0.7.7-362
|
||||
*
|
||||
*/
|
||||
import { CallParams } from '../../interfaces/commonTypes.js';
|
||||
import { registerServiceImpl } from '../compilerSupport/registerService.js';
|
||||
import { CallParams } from '@fluencelabs/interface';
|
||||
import { registerServiceImpl } from '../../compilerSupport/registerService.js';
|
||||
import { FluencePeer } from '../FluencePeer.js';
|
||||
|
||||
// Services
|
@ -6,8 +6,8 @@
|
||||
* Aqua version: 0.7.7-362
|
||||
*
|
||||
*/
|
||||
import { CallParams } from '../../interfaces/commonTypes.js';
|
||||
import { registerServiceImpl } from '../compilerSupport/registerService.js';
|
||||
import { CallParams } from '@fluencelabs/interface';
|
||||
import { registerServiceImpl } from '../../compilerSupport/registerService.js';
|
||||
import { FluencePeer } from '../FluencePeer.js';
|
||||
|
||||
// Services
|
@ -1,4 +1,4 @@
|
||||
import { CallParams, PeerIdB58 } from '../../interfaces/commonTypes.js';
|
||||
import { CallParams, PeerIdB58 } from '@fluencelabs/interface';
|
||||
import { KeyPair } from '../../keypair/index.js';
|
||||
import { SigDef } from '../_aqua/services.js';
|
||||
import { allowOnlyParticleOriginatedAt, allowServiceFn, and, or, SecurityGuard } from './securityGuard.js';
|
@ -2,7 +2,7 @@ import { v4 as uuidv4 } from 'uuid';
|
||||
import { SrvDef } from '../_aqua/single-module-srv.js';
|
||||
import { NodeUtilsDef } from '../_aqua/node-utils.js';
|
||||
import { FluencePeer } from '../FluencePeer.js';
|
||||
import { CallParams } from '../../interfaces/commonTypes.js';
|
||||
import { CallParams } from '@fluencelabs/interface';
|
||||
import { Buffer } from 'buffer';
|
||||
import { allowOnlyParticleOriginatedAt, SecurityGuard } from './securityGuard.js';
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { SecurityTetraplet } from '@fluencelabs/avm';
|
||||
import { CallParams, PeerIdB58 } from '../../interfaces/commonTypes.js';
|
||||
import { CallParams, PeerIdB58 } from '@fluencelabs/interface';
|
||||
|
||||
type ArgName = string | null;
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { PeerIdB58 } from '@fluencelabs/interface';
|
||||
import { FluenceConnection, ParticleHandler } from '../interfaces/index.js';
|
||||
import { keyPairFromBase64Sk } from '../keypair/index.js';
|
||||
import { PeerIdB58 } from '../interfaces/commonTypes.js';
|
||||
import { FluencePeer } from './FluencePeer.js';
|
||||
import { MarineBackgroundRunner } from '../marine/worker/index.js';
|
||||
import { avmModuleLoader, controlModuleLoader } from './utilsForNode';
|
9
packages/core/js-peer/tsconfig.json
Normal file
9
packages/core/js-peer/tsconfig.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"extends": "../../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist",
|
||||
"moduleResolution": "node"
|
||||
},
|
||||
"include": ["src/**/*"],
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
39
pnpm-lock.yaml
generated
39
pnpm-lock.yaml
generated
@ -18,22 +18,24 @@ importers:
|
||||
specifiers:
|
||||
'@fluencelabs/aqua': 0.9.1-374
|
||||
'@fluencelabs/fluence-network-environment': 1.0.13
|
||||
'@fluencelabs/interface': workspace:*
|
||||
'@fluencelabs/js-client.api': workspace:*
|
||||
'@fluencelabs/js-peer': workspace:*
|
||||
http-server: 14.1.1
|
||||
dependencies:
|
||||
'@fluencelabs/fluence-network-environment': 1.0.13
|
||||
'@fluencelabs/interface': link:../../core/interface
|
||||
'@fluencelabs/js-client.api': link:../../client/api
|
||||
devDependencies:
|
||||
'@fluencelabs/aqua': 0.9.1-374_4kllvqvlnb5b3k2borritadfgq
|
||||
'@fluencelabs/js-peer': link:../../core
|
||||
'@fluencelabs/js-peer': link:../../core/js-peer
|
||||
http-server: 14.1.1
|
||||
|
||||
packages/client/api:
|
||||
specifiers:
|
||||
'@fluencelabs/js-peer': workspace:*
|
||||
devDependencies:
|
||||
'@fluencelabs/js-peer': link:../../core
|
||||
'@fluencelabs/interface': workspace:*
|
||||
dependencies:
|
||||
'@fluencelabs/interface': link:../../core/interface
|
||||
|
||||
packages/client/js-client.web.standalone:
|
||||
specifiers:
|
||||
@ -52,7 +54,7 @@ importers:
|
||||
vite-plugin-replace: 0.1.1
|
||||
vite-tsconfig-paths: 4.0.3
|
||||
dependencies:
|
||||
'@fluencelabs/js-peer': link:../../core
|
||||
'@fluencelabs/js-peer': link:../../core/js-peer
|
||||
buffer: 6.0.3
|
||||
process: 0.11.10
|
||||
devDependencies:
|
||||
@ -74,7 +76,15 @@ importers:
|
||||
devDependencies:
|
||||
'@types/node': 16.11.59
|
||||
|
||||
packages/core:
|
||||
packages/core/interface:
|
||||
specifiers:
|
||||
'@fluencelabs/avm': 0.35.3
|
||||
'@multiformats/multiaddr': 11.3.0
|
||||
devDependencies:
|
||||
'@fluencelabs/avm': 0.35.3
|
||||
'@multiformats/multiaddr': 11.3.0
|
||||
|
||||
packages/core/js-peer:
|
||||
specifiers:
|
||||
'@chainsafe/libp2p-noise': 11.0.0
|
||||
'@fluencelabs/aqua': 0.7.7-362
|
||||
@ -82,6 +92,7 @@ importers:
|
||||
'@fluencelabs/aqua-lib': 0.6.0
|
||||
'@fluencelabs/avm': 0.31.10
|
||||
'@fluencelabs/fluence-network-environment': 1.0.13
|
||||
'@fluencelabs/interface': workspace:*
|
||||
'@fluencelabs/marine-js': 0.3.44
|
||||
'@libp2p/crypto': 1.0.8
|
||||
'@libp2p/interface-connection': 3.0.8
|
||||
@ -120,6 +131,7 @@ importers:
|
||||
dependencies:
|
||||
'@chainsafe/libp2p-noise': 11.0.0
|
||||
'@fluencelabs/avm': 0.31.10
|
||||
'@fluencelabs/interface': link:../interface
|
||||
'@fluencelabs/marine-js': 0.3.44
|
||||
'@libp2p/crypto': 1.0.8_uint8arraylist@2.4.3
|
||||
'@libp2p/interface-connection': 3.0.8
|
||||
@ -545,13 +557,12 @@ packages:
|
||||
|
||||
/@chainsafe/is-ip/2.0.1:
|
||||
resolution: {integrity: sha512-nqSJ8u2a1Rv9FYbyI8qpDhTYujaKEyLknNrTejLYoSWmdeg+2WB7R6BZqPZYfrJzDxVi3rl6ZQuoaEvpKRZWgQ==}
|
||||
dev: false
|
||||
|
||||
/@chainsafe/libp2p-noise/11.0.0:
|
||||
resolution: {integrity: sha512-NEl5aIv6muz9OL+dsa3INEU89JX0NViBxOy7NwwG8eNRPUDHo5E3ZTMSHXQpVx1K/ofoNS4ANO9xwezY6ss5GA==}
|
||||
engines: {node: '>=16.0.0', npm: '>=7.0.0'}
|
||||
dependencies:
|
||||
'@libp2p/crypto': 1.0.8_uint8arraylist@2.4.3
|
||||
'@libp2p/crypto': 1.0.11_uint8arraylist@2.4.3
|
||||
'@libp2p/interface-connection-encrypter': 3.0.6
|
||||
'@libp2p/interface-keys': 1.0.7
|
||||
'@libp2p/interface-metrics': 4.0.5
|
||||
@ -2052,7 +2063,7 @@ packages:
|
||||
resolution: {integrity: sha512-CRJmqwNQhDC51sQ9lf6EqEY8HuywwymMVffL2kIYI5ts5k+6gvIXzoSxLf3V3o+OxcroXG4KG0uGxxAi5DUXSA==}
|
||||
engines: {node: '>=16.0.0', npm: '>=7.0.0'}
|
||||
dependencies:
|
||||
'@libp2p/crypto': 1.0.8_uint8arraylist@2.4.3
|
||||
'@libp2p/crypto': 1.0.11_uint8arraylist@2.4.3
|
||||
'@libp2p/interface-keys': 1.0.7
|
||||
'@libp2p/interface-peer-id': 2.0.1
|
||||
'@libp2p/peer-id': 2.0.1
|
||||
@ -2214,7 +2225,6 @@ packages:
|
||||
varint: 6.0.0
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
dev: false
|
||||
|
||||
/@noble/ed25519/1.7.1:
|
||||
resolution: {integrity: sha512-Rk4SkJFaXZiznFyC/t77Q0NKS4FL7TLJJsVG2V2oiEq3kJVeTdxysEe/yRWSpnWMe808XRDJ+VFh5pt/FN5plw==}
|
||||
@ -3084,7 +3094,6 @@ packages:
|
||||
engines: {node: '>=10.16.0'}
|
||||
dependencies:
|
||||
streamsearch: 1.1.0
|
||||
dev: false
|
||||
|
||||
/byte-access/1.0.1:
|
||||
resolution: {integrity: sha512-GKYa+lvxnzhgHWj9X+LCsQ4s2/C5uvib573eAOiQKywXMkzFFErY2+yQdzmdE5iWVpmqecsRx3bOtOY4/1eINw==}
|
||||
@ -3433,7 +3442,6 @@ packages:
|
||||
undici: 5.16.0
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
dev: false
|
||||
|
||||
/domexception/2.0.1:
|
||||
resolution: {integrity: sha512-yxJ2mFy/sibVQlu5qHjOkf9J3K6zgmCxgJ94u2EdvDOV09H+32LtRswEcUsmUWN72pVLOEnTSRaIVVzVQgS0dg==}
|
||||
@ -6409,7 +6417,7 @@ packages:
|
||||
engines: {node: '>=16.0.0', npm: '>=7.0.0'}
|
||||
dependencies:
|
||||
'@achingbrain/nat-port-mapper': 1.0.7
|
||||
'@libp2p/crypto': 1.0.8_uint8arraylist@2.4.3
|
||||
'@libp2p/crypto': 1.0.11_uint8arraylist@2.4.3
|
||||
'@libp2p/interface-address-manager': 2.0.4
|
||||
'@libp2p/interface-connection': 3.0.8
|
||||
'@libp2p/interface-connection-encrypter': 3.0.6
|
||||
@ -6739,7 +6747,6 @@ packages:
|
||||
/multiformats/11.0.1:
|
||||
resolution: {integrity: sha512-atWruyH34YiknSdL5yeIir00EDlJRpHzELYQxG7Iy29eCyL+VrZHpPrX5yqlik3jnuqpLpRKVZ0SGVb9UzKaSA==}
|
||||
engines: {node: '>=16.0.0', npm: '>=7.0.0'}
|
||||
dev: false
|
||||
|
||||
/multiformats/9.6.5:
|
||||
resolution: {integrity: sha512-vMwf/FUO+qAPvl3vlSZEgEVFY/AxeZq5yg761ScF3CZsXgmTi/HGkicUiNN0CI4PW8FiY2P0OLklOcmQjdQJhw==}
|
||||
@ -6866,7 +6873,6 @@ packages:
|
||||
undici: '*'
|
||||
dependencies:
|
||||
undici: 5.16.0
|
||||
dev: false
|
||||
|
||||
/natural-compare/1.4.0:
|
||||
resolution: {integrity: sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==}
|
||||
@ -7704,7 +7710,6 @@ packages:
|
||||
/streamsearch/1.1.0:
|
||||
resolution: {integrity: sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==}
|
||||
engines: {node: '>=10.0.0'}
|
||||
dev: false
|
||||
|
||||
/string-length/4.0.2:
|
||||
resolution: {integrity: sha512-+l6rNN5fYHNhZZy41RXsYptCjA2Igmq4EG7kZAYFQI1E1VTXarr6ZPXBg6eq7Y6eK4FEhY6AJlyuFIb/v/S0VQ==}
|
||||
@ -8160,14 +8165,12 @@ packages:
|
||||
engines: {node: '>=16.0.0', npm: '>=7.0.0'}
|
||||
dependencies:
|
||||
multiformats: 11.0.1
|
||||
dev: false
|
||||
|
||||
/undici/5.16.0:
|
||||
resolution: {integrity: sha512-KWBOXNv6VX+oJQhchXieUznEmnJMqgXMbs0xxH2t8q/FUAWSJvOSr/rMaZKnX5RIVq7JDn0JbP4BOnKG2SGXLQ==}
|
||||
engines: {node: '>=12.18'}
|
||||
dependencies:
|
||||
busboy: 1.6.0
|
||||
dev: false
|
||||
|
||||
/union/0.5.0:
|
||||
resolution: {integrity: sha512-N6uOhuW6zO95P3Mel2I2zMsbsanvvtgn6jVqJv4vbVcz/JN0OkL9suomjQGmWtxJQXOCqUJvquc1sMeNz/IwlA==}
|
||||
|
Reference in New Issue
Block a user