mirror of
https://github.com/fluencelabs/fluence-js.git
synced 2025-06-25 05:41:35 +00:00
feat(js-client)!: Adding strictes eslint and ts config to all packages [fixes DXJ-464] (#355)
* introduce eslint * Fix all eslint errors * Eslint fix and some touches * Fix tests * Fix misc errors * change semver * change semver #2 * Fix path * Fix path #2 * freeze lock file in CI * fix package install * Fix formatting of surrounding files * Add empty prettier config * Fix formatting * Fix build errors * Remove unused deps * remove changelog from formatting * deps cleanup * make resource importers async * Refactor * Fix error message * remove comment * more refactoring * Update packages/core/js-client/src/compilerSupport/registerService.ts Co-authored-by: shamsartem <shamsartem@gmail.com> * refactoring * refactoring fix * optimize import * Update packages/@tests/smoke/node/src/index.ts Co-authored-by: shamsartem <shamsartem@gmail.com> * Revert package * Fix pnpm lock * Lint-fix * Fix CI * Update tests * Fix build * Fix import * Use forked threads dep * Use fixed version * Update threads * Fix lint * Fix test * Fix test * Add polyfill for assert * Add subpath import * Fix tests * Fix deps --------- Co-authored-by: shamsartem <shamsartem@gmail.com>
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/**
|
||||
* Copyright 2023 Fluence Labs Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -13,97 +13,112 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { CallResultsArray, InterpreterResult, RunParameters } from '@fluencelabs/avm';
|
||||
import { IStartable, JSONArray, JSONObject, CallParameters } from '../util/commonTypes.js';
|
||||
// @ts-ignore
|
||||
import type { WorkerImplementation } from 'threads/dist/types/master';
|
||||
|
||||
import {
|
||||
CallResultsArray,
|
||||
InterpreterResult,
|
||||
RunParameters,
|
||||
} from "@fluencelabs/avm";
|
||||
import { JSONObject, JSONValue, JSONArray } from "@fluencelabs/interfaces";
|
||||
import type { Worker as WorkerImplementation } from "threads/master";
|
||||
|
||||
import { IStartable, CallParameters } from "../util/commonTypes.js";
|
||||
|
||||
/**
|
||||
* Contract for marine host implementations. Marine host is responsible for creating calling and removing marine services
|
||||
*/
|
||||
export interface IMarineHost extends IStartable {
|
||||
/**
|
||||
* Creates marine service from the given module and service id
|
||||
*/
|
||||
createService(serviceModule: ArrayBuffer | SharedArrayBuffer, serviceId: string): Promise<void>;
|
||||
/**
|
||||
* Creates marine service from the given module and service id
|
||||
*/
|
||||
createService(
|
||||
serviceModule: ArrayBuffer | SharedArrayBuffer,
|
||||
serviceId: string,
|
||||
): Promise<void>;
|
||||
|
||||
/**
|
||||
* Removes marine service with the given service id
|
||||
*/
|
||||
removeService(serviceId: string): Promise<void>;
|
||||
/**
|
||||
* Removes marine service with the given service id
|
||||
*/
|
||||
removeService(serviceId: string): Promise<void>;
|
||||
|
||||
/**
|
||||
* Returns true if any service with the specified service id is registered
|
||||
*/
|
||||
hasService(serviceId: string): Promise<boolean>;
|
||||
/**
|
||||
* Returns true if any service with the specified service id is registered
|
||||
*/
|
||||
hasService(serviceId: string): Promise<boolean>;
|
||||
|
||||
/**
|
||||
* Calls the specified function of the specified service with the given arguments
|
||||
*/
|
||||
callService(
|
||||
serviceId: string,
|
||||
functionName: string,
|
||||
args: JSONArray | JSONObject,
|
||||
callParams: CallParameters,
|
||||
): Promise<unknown>;
|
||||
/**
|
||||
* Calls the specified function of the specified service with the given arguments
|
||||
*/
|
||||
callService(
|
||||
serviceId: string,
|
||||
functionName: string,
|
||||
args: JSONArray | JSONObject,
|
||||
callParams: CallParameters,
|
||||
): Promise<JSONValue>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface for different implementations of AVM runner
|
||||
*/
|
||||
export interface IAvmRunner extends IStartable {
|
||||
/**
|
||||
* Run AVM interpreter with the specified parameters
|
||||
*/
|
||||
run(
|
||||
runParams: RunParameters,
|
||||
air: string,
|
||||
prevData: Uint8Array,
|
||||
data: Uint8Array,
|
||||
callResults: CallResultsArray,
|
||||
): Promise<InterpreterResult | Error>;
|
||||
/**
|
||||
* Run AVM interpreter with the specified parameters
|
||||
*/
|
||||
run(
|
||||
runParams: RunParameters,
|
||||
air: string,
|
||||
prevData: Uint8Array,
|
||||
data: Uint8Array,
|
||||
callResults: CallResultsArray,
|
||||
): Promise<InterpreterResult | Error>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface for something which can hold a value
|
||||
*/
|
||||
export interface IValueLoader<T> {
|
||||
getValue(): T;
|
||||
getValue(): T;
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface for something which can load wasm files
|
||||
*/
|
||||
export interface IWasmLoader extends IValueLoader<ArrayBuffer | SharedArrayBuffer>, IStartable {}
|
||||
export interface IWasmLoader
|
||||
extends IValueLoader<ArrayBuffer | SharedArrayBuffer>,
|
||||
IStartable {}
|
||||
|
||||
/**
|
||||
* Interface for something which can thread.js based worker
|
||||
*/
|
||||
export interface IWorkerLoader extends IValueLoader<WorkerImplementation>, IStartable {}
|
||||
export interface IWorkerLoader
|
||||
extends IValueLoader<WorkerImplementation | Promise<WorkerImplementation>>,
|
||||
IStartable {}
|
||||
|
||||
/**
|
||||
* Lazy loader for some value. Value is loaded only when `start` method is called
|
||||
*/
|
||||
export class LazyLoader<T> implements IStartable, IValueLoader<T> {
|
||||
private value: T | null = null;
|
||||
private value: T | null = null;
|
||||
|
||||
constructor(private loadValue: () => Promise<T> | T) {}
|
||||
constructor(private loadValue: () => Promise<T> | T) {}
|
||||
|
||||
getValue(): T {
|
||||
if (this.value == null) {
|
||||
throw new Error('Value has not been loaded. Call `start` method to load the value.');
|
||||
}
|
||||
|
||||
return this.value;
|
||||
getValue(): T {
|
||||
if (this.value == null) {
|
||||
throw new Error(
|
||||
"Value has not been loaded. Call `start` method to load the value.",
|
||||
);
|
||||
}
|
||||
|
||||
async start() {
|
||||
if (this.value !== null) {
|
||||
return;
|
||||
}
|
||||
return this.value;
|
||||
}
|
||||
|
||||
this.value = await this.loadValue();
|
||||
async start() {
|
||||
if (this.value !== null) {
|
||||
return;
|
||||
}
|
||||
|
||||
async stop() {}
|
||||
this.value = await this.loadValue();
|
||||
}
|
||||
|
||||
async stop() {}
|
||||
}
|
||||
|
Reference in New Issue
Block a user