/** * Copyright 2023 Fluence Labs Limited * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { JSONValue } from "@fluencelabs/interfaces"; import { IConnection } from "../connection/interfaces.js"; import { IJsServiceHost } from "../jsServiceHost/interfaces.js"; import { KeyPair } from "../keypair/index.js"; import { IMarineHost } from "../marine/interfaces.js"; import { IParticle } from "../particle/interfaces.js"; import { Sig } from "../services/Sig.js"; import { Srv } from "../services/SingleModuleSrv.js"; import { Tracing } from "../services/Tracing.js"; export type PeerConfig = { /** * Sets the default TTL for all particles originating from the peer with no TTL specified. * If the originating particle's TTL is defined then that value will be used * If the option is not set default TTL will be 7000 */ defaultTtlMs: number; /** * Enables\disabled various debugging features */ debug: { /** * If set to true, newly initiated particle ids will be printed to console. * Useful to see what particle id is responsible for aqua function */ printParticleId: boolean; }; }; export declare const DEFAULT_CONFIG: PeerConfig; /** * This class implements the Fluence protocol for javascript-based environments. * It provides all the necessary features to communicate with Fluence network */ export declare abstract class FluencePeer { protected readonly config: PeerConfig; protected readonly keyPair: KeyPair; protected readonly marineHost: IMarineHost; protected readonly jsServiceHost: IJsServiceHost; protected readonly connection: IConnection; constructor(config: PeerConfig, keyPair: KeyPair, marineHost: IMarineHost, jsServiceHost: IJsServiceHost, connection: IConnection); getPeerId(): string; start(): Promise; /** * Un-initializes the peer: stops all the underlying workflows, stops the Aqua VM * and disconnects from the Fluence network */ stop(): Promise; /** * Registers marine service within the Fluence peer from wasm file. * Following helper functions can be used to load wasm files: * * loadWasmFromFileSystem * * loadWasmFromNpmPackage * * loadWasmFromServer * @param wasm - buffer with the wasm file for service * @param serviceId - the service id by which the service can be accessed in aqua */ registerMarineService(wasm: ArrayBuffer | SharedArrayBuffer, serviceId: string): Promise; /** * Removes the specified marine service from the Fluence peer * @param serviceId - the service id to remove */ removeMarineService(serviceId: string): Promise; /** * @private Is not intended to be used manually. Subject to change */ get internals(): { getServices: () => { sig: Sig; srv: Srv; tracing: Tracing; }; getRelayPeerId: () => string; parseAst: (air: string) => Promise<{ success: boolean; data: unknown; }>; createNewParticle: (script: string, ttl?: number) => Promise; /** * Initiates a new particle execution starting from local peer * @param particle - particle to start execution of * @param onSuccess - callback which is called when particle execution succeed * @param onError - callback which is called when particle execution fails * @param fireAndForget - determines whether particle has fire-and-forget behavior */ initiateParticle: (particle: IParticle, onSuccess: (result: JSONValue) => void, onError: (error: Error) => void, fireAndForget?: boolean) => void; /** * Register Call Service handler functions */ regHandler: { /** * Register handler for all particles */ common: (serviceId: string, fnName: string, handler: import("../jsServiceHost/interfaces.js").GenericCallServiceHandler) => void; /** * Register handler which will be called only for particle with the specific id */ forParticle: (particleId: string, serviceId: string, fnName: string, handler: import("../jsServiceHost/interfaces.js").GenericCallServiceHandler) => void; }; }; private _incomingParticles; private timeouts; private _particleSourceSubscription?; private _incomingParticlePromise?; private _classServices; private isInitialized; private printParticleId; private _initServices; private sendParticleToRelay; private execCallRequests; private execCallRequest; private mapParticleGroup; private startParticleProcessing; private expireParticle; private decodeAvmData; private stopParticleProcessing; }