mirror of
https://github.com/fluencelabs/fluence-js.git
synced 2025-06-20 11:26:30 +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,257 +13,279 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
type SimpleTypes = ScalarType | OptionType | ArrayType | StructType | TopType | BottomType | NilType;
|
||||
|
||||
export type NonArrowType = SimpleTypes | ProductType<SimpleTypes>;
|
||||
export type SimpleTypes =
|
||||
| ScalarType
|
||||
| OptionType
|
||||
| ArrayType
|
||||
| StructType
|
||||
| TopType
|
||||
| BottomType
|
||||
| NilType;
|
||||
|
||||
export type NonArrowType = SimpleTypes | ProductType;
|
||||
|
||||
export type TopType = {
|
||||
/**
|
||||
* Type descriptor. Used for pattern-matching
|
||||
*/
|
||||
tag: 'topType';
|
||||
/**
|
||||
* Type descriptor. Used for pattern-matching
|
||||
*/
|
||||
tag: "topType";
|
||||
};
|
||||
|
||||
export type BottomType = {
|
||||
/**
|
||||
* Type descriptor. Used for pattern-matching
|
||||
*/
|
||||
tag: 'bottomType';
|
||||
/**
|
||||
* Type descriptor. Used for pattern-matching
|
||||
*/
|
||||
tag: "bottomType";
|
||||
};
|
||||
|
||||
export type OptionType = {
|
||||
/**
|
||||
* Type descriptor. Used for pattern-matching
|
||||
*/
|
||||
tag: 'option';
|
||||
/**
|
||||
* Type descriptor. Used for pattern-matching
|
||||
*/
|
||||
tag: "option";
|
||||
|
||||
/**
|
||||
* Underlying type of the option
|
||||
*/
|
||||
type: NonArrowType;
|
||||
/**
|
||||
* Underlying type of the option
|
||||
*/
|
||||
type: SimpleTypes;
|
||||
};
|
||||
|
||||
export type NilType = {
|
||||
/**
|
||||
* Type descriptor. Used for pattern-matching
|
||||
*/
|
||||
tag: 'nil';
|
||||
/**
|
||||
* Type descriptor. Used for pattern-matching
|
||||
*/
|
||||
tag: "nil";
|
||||
};
|
||||
|
||||
export type ArrayType = {
|
||||
/**
|
||||
* Type descriptor. Used for pattern-matching
|
||||
*/
|
||||
tag: 'array';
|
||||
/**
|
||||
* Type descriptor. Used for pattern-matching
|
||||
*/
|
||||
tag: "array";
|
||||
|
||||
/**
|
||||
* Type of array elements
|
||||
*/
|
||||
type: NonArrowType;
|
||||
/**
|
||||
* Type of array elements
|
||||
*/
|
||||
type: SimpleTypes;
|
||||
};
|
||||
|
||||
/**
|
||||
* All possible scalar type names
|
||||
*/
|
||||
export type ScalarNames =
|
||||
| 'u8'
|
||||
| 'u16'
|
||||
| 'u32'
|
||||
| 'u64'
|
||||
| 'i8'
|
||||
| 'i16'
|
||||
| 'i32'
|
||||
| 'i64'
|
||||
| 'f32'
|
||||
| 'f64'
|
||||
| 'bool'
|
||||
| 'string';
|
||||
| "u8"
|
||||
| "u16"
|
||||
| "u32"
|
||||
| "u64"
|
||||
| "i8"
|
||||
| "i16"
|
||||
| "i32"
|
||||
| "i64"
|
||||
| "f32"
|
||||
| "f64"
|
||||
| "bool"
|
||||
| "string";
|
||||
|
||||
export type ScalarType = {
|
||||
/**
|
||||
* Type descriptor. Used for pattern-matching
|
||||
*/
|
||||
tag: 'scalar';
|
||||
/**
|
||||
* Type descriptor. Used for pattern-matching
|
||||
*/
|
||||
tag: "scalar";
|
||||
|
||||
/**
|
||||
* Name of the scalar type
|
||||
*/
|
||||
name: ScalarNames;
|
||||
/**
|
||||
* Name of the scalar type
|
||||
*/
|
||||
name: ScalarNames;
|
||||
};
|
||||
|
||||
export type StructType = {
|
||||
/**
|
||||
* Type descriptor. Used for pattern-matching
|
||||
*/
|
||||
tag: 'struct';
|
||||
/**
|
||||
* Type descriptor. Used for pattern-matching
|
||||
*/
|
||||
tag: "struct";
|
||||
|
||||
/**
|
||||
* Struct name
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* Struct name
|
||||
*/
|
||||
name: string;
|
||||
|
||||
/**
|
||||
* Struct fields
|
||||
*/
|
||||
fields: { [key: string]: NonArrowType };
|
||||
/**
|
||||
* Struct fields
|
||||
*/
|
||||
fields: { [key: string]: SimpleTypes };
|
||||
};
|
||||
|
||||
export type LabeledProductType<T> = {
|
||||
/**
|
||||
* Type descriptor. Used for pattern-matching
|
||||
*/
|
||||
tag: 'labeledProduct';
|
||||
export type LabeledProductType<
|
||||
T extends
|
||||
| SimpleTypes
|
||||
| ArrowType<LabeledProductType<SimpleTypes> | UnlabeledProductType> =
|
||||
| SimpleTypes
|
||||
| ArrowType<LabeledProductType<SimpleTypes> | UnlabeledProductType>,
|
||||
K extends { [key: string]: T } = { [key: string]: T },
|
||||
> = {
|
||||
/**
|
||||
* Type descriptor. Used for pattern-matching
|
||||
*/
|
||||
tag: "labeledProduct";
|
||||
|
||||
/**
|
||||
* Labelled product fields
|
||||
*/
|
||||
fields: { [key: string]: T };
|
||||
/**
|
||||
* Labelled product fields
|
||||
*/
|
||||
fields: K;
|
||||
};
|
||||
|
||||
export type UnlabeledProductType<T> = {
|
||||
export type UnlabeledProductType<T extends Array<SimpleTypes> = SimpleTypes[]> =
|
||||
{
|
||||
/**
|
||||
* Type descriptor. Used for pattern-matching
|
||||
*/
|
||||
tag: 'unlabeledProduct';
|
||||
tag: "unlabeledProduct";
|
||||
|
||||
/**
|
||||
* Items in unlabelled product
|
||||
*/
|
||||
items: Array<T>;
|
||||
};
|
||||
items: T;
|
||||
};
|
||||
|
||||
export type ProductType<T> = UnlabeledProductType<T> | LabeledProductType<T> | NilType;
|
||||
export type ProductType = UnlabeledProductType | LabeledProductType;
|
||||
|
||||
/**
|
||||
* ArrowType is a profunctor pointing its domain to codomain.
|
||||
* Profunctor means variance: Arrow is contravariant on domain, and variant on codomain.
|
||||
*/
|
||||
export type ArrowType<T> = {
|
||||
/**
|
||||
* Type descriptor. Used for pattern-matching
|
||||
*/
|
||||
tag: 'arrow';
|
||||
export type ArrowType<T extends LabeledProductType | UnlabeledProductType> = {
|
||||
/**
|
||||
* Type descriptor. Used for pattern-matching
|
||||
*/
|
||||
tag: "arrow";
|
||||
|
||||
/**
|
||||
* Where this Arrow is defined
|
||||
*/
|
||||
domain: ProductType<T>;
|
||||
/**
|
||||
* Where this Arrow is defined
|
||||
*/
|
||||
domain: T | NilType;
|
||||
|
||||
/**
|
||||
* Where this Arrow points to
|
||||
*/
|
||||
codomain: UnlabeledProductType<NonArrowType> | NilType;
|
||||
/**
|
||||
* Where this Arrow points to
|
||||
*/
|
||||
codomain: UnlabeledProductType | NilType;
|
||||
};
|
||||
|
||||
/**
|
||||
* Arrow which domain contains only non-arrow types
|
||||
*/
|
||||
export type ArrowWithoutCallbacks = ArrowType<NonArrowType>;
|
||||
export type ArrowWithoutCallbacks = ArrowType<
|
||||
UnlabeledProductType | LabeledProductType<SimpleTypes>
|
||||
>;
|
||||
|
||||
/**
|
||||
* Arrow which domain does can contain both non-arrow types and arrows (which themselves cannot contain arrows)
|
||||
*/
|
||||
export type ArrowWithCallbacks = ArrowType<NonArrowType | ArrowWithoutCallbacks>;
|
||||
export type ArrowWithCallbacks = ArrowType<LabeledProductType>;
|
||||
|
||||
export interface FunctionCallConstants {
|
||||
/**
|
||||
* The name of the relay variable
|
||||
*/
|
||||
relay: string;
|
||||
/**
|
||||
* The name of the relay variable
|
||||
*/
|
||||
relay: string;
|
||||
|
||||
/**
|
||||
* The name of the serviceId used load variables at the beginning of the script
|
||||
*/
|
||||
getDataSrv: string;
|
||||
/**
|
||||
* The name of the serviceId used load variables at the beginning of the script
|
||||
*/
|
||||
getDataSrv: string;
|
||||
|
||||
/**
|
||||
* The name of serviceId is used to execute callbacks for the current particle
|
||||
*/
|
||||
callbackSrv: string;
|
||||
/**
|
||||
* The name of serviceId is used to execute callbacks for the current particle
|
||||
*/
|
||||
callbackSrv: string;
|
||||
|
||||
/**
|
||||
* The name of the serviceId which is called to propagate return value to the generated function caller
|
||||
*/
|
||||
responseSrv: string;
|
||||
/**
|
||||
* The name of the serviceId which is called to propagate return value to the generated function caller
|
||||
*/
|
||||
responseSrv: string;
|
||||
|
||||
/**
|
||||
* The name of the functionName which is called to propagate return value to the generated function caller
|
||||
*/
|
||||
responseFnName: string;
|
||||
/**
|
||||
* The name of the functionName which is called to propagate return value to the generated function caller
|
||||
*/
|
||||
responseFnName: string;
|
||||
|
||||
/**
|
||||
* The name of the serviceId which is called to report errors to the generated function caller
|
||||
*/
|
||||
errorHandlingSrv: string;
|
||||
/**
|
||||
* The name of the serviceId which is called to report errors to the generated function caller
|
||||
*/
|
||||
errorHandlingSrv: string;
|
||||
|
||||
/**
|
||||
* The name of the functionName which is called to report errors to the generated function caller
|
||||
*/
|
||||
errorFnName: string;
|
||||
/**
|
||||
* The name of the functionName which is called to report errors to the generated function caller
|
||||
*/
|
||||
errorFnName: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Definition of function (`func` instruction) generated by the Aqua compiler
|
||||
*/
|
||||
export interface FunctionCallDef {
|
||||
/**
|
||||
* The name of the function in Aqua language
|
||||
*/
|
||||
functionName: string;
|
||||
/**
|
||||
* The name of the function in Aqua language
|
||||
*/
|
||||
functionName: string;
|
||||
|
||||
/**
|
||||
* Underlying arrow which represents function in aqua
|
||||
*/
|
||||
arrow: ArrowWithCallbacks;
|
||||
/**
|
||||
* Underlying arrow which represents function in aqua
|
||||
*/
|
||||
arrow: ArrowType<
|
||||
LabeledProductType<SimpleTypes | ArrowType<UnlabeledProductType>>
|
||||
>;
|
||||
|
||||
/**
|
||||
* Names of the different entities used in generated air script
|
||||
*/
|
||||
names: FunctionCallConstants;
|
||||
/**
|
||||
* Names of the different entities used in generated air script
|
||||
*/
|
||||
names: FunctionCallConstants;
|
||||
}
|
||||
|
||||
/**
|
||||
* Definition of service registration function (`service` instruction) generated by the Aqua compiler
|
||||
*/
|
||||
export interface ServiceDef {
|
||||
/**
|
||||
* Default service id. If the service has no default id the value should be undefined
|
||||
*/
|
||||
defaultServiceId?: string;
|
||||
/**
|
||||
* Default service id. If the service has no default id the value should be undefined
|
||||
*/
|
||||
defaultServiceId?: string;
|
||||
|
||||
/**
|
||||
* List of functions which the service consists of
|
||||
*/
|
||||
functions: LabeledProductType<ArrowWithoutCallbacks> | NilType;
|
||||
/**
|
||||
* List of functions which the service consists of
|
||||
*/
|
||||
functions:
|
||||
| LabeledProductType<ArrowType<LabeledProductType<SimpleTypes>>>
|
||||
| NilType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Options to configure Aqua function execution
|
||||
*/
|
||||
export interface FnConfig {
|
||||
/**
|
||||
* Sets the TTL (time to live) for particle responsible for the function execution
|
||||
* If the option is not set the default TTL from FluencePeer config is used
|
||||
*/
|
||||
ttl?: number;
|
||||
/**
|
||||
* Sets the TTL (time to live) for particle responsible for the function execution
|
||||
* If the option is not set the default TTL from FluencePeer config is used
|
||||
*/
|
||||
ttl?: number;
|
||||
}
|
||||
|
||||
export const getArgumentTypes = (
|
||||
def: FunctionCallDef,
|
||||
def: FunctionCallDef,
|
||||
): {
|
||||
[key: string]: NonArrowType | ArrowWithoutCallbacks;
|
||||
[key: string]: NonArrowType | ArrowWithoutCallbacks;
|
||||
} => {
|
||||
if (def.arrow.domain.tag !== 'labeledProduct') {
|
||||
throw new Error('Should be impossible');
|
||||
}
|
||||
if (def.arrow.domain.tag !== "labeledProduct") {
|
||||
throw new Error("Should be impossible");
|
||||
}
|
||||
|
||||
return def.arrow.domain.fields;
|
||||
return def.arrow.domain.fields;
|
||||
};
|
||||
|
||||
export const isReturnTypeVoid = (def: FunctionCallDef): boolean => {
|
||||
if (def.arrow.codomain.tag === 'nil') {
|
||||
return true;
|
||||
}
|
||||
if (def.arrow.codomain.tag === "nil") {
|
||||
return true;
|
||||
}
|
||||
|
||||
return def.arrow.codomain.items.length == 0;
|
||||
return def.arrow.codomain.items.length === 0;
|
||||
};
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/**
|
||||
* Copyright 2023 Fluence Labs Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -13,72 +13,88 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { IFluenceInternalApi } from '../fluenceClient.js';
|
||||
import { FnConfig, FunctionCallDef, ServiceDef } from './aquaTypeDefinitions.js';
|
||||
|
||||
import { JSONValue } from "../commonTypes.js";
|
||||
import { IFluenceInternalApi } from "../fluenceClient.js";
|
||||
|
||||
import {
|
||||
FnConfig,
|
||||
FunctionCallDef,
|
||||
ServiceDef,
|
||||
} from "./aquaTypeDefinitions.js";
|
||||
|
||||
/**
|
||||
* Type for callback passed as aqua function argument
|
||||
*/
|
||||
export type ArgCallbackFunction = (
|
||||
...args: JSONValue[]
|
||||
) => JSONValue | Promise<JSONValue>;
|
||||
|
||||
/**
|
||||
* Arguments passed to Aqua function
|
||||
*/
|
||||
export type PassedArgs = { [key: string]: any };
|
||||
export type PassedArgs = { [key: string]: JSONValue | ArgCallbackFunction };
|
||||
|
||||
/**
|
||||
* Arguments for callAquaFunction function
|
||||
*/
|
||||
export interface CallAquaFunctionArgs {
|
||||
/**
|
||||
* Peer to call the function on
|
||||
*/
|
||||
peer: IFluenceInternalApi;
|
||||
/**
|
||||
* Peer to call the function on
|
||||
*/
|
||||
peer: IFluenceInternalApi;
|
||||
|
||||
/**
|
||||
* Function definition
|
||||
*/
|
||||
def: FunctionCallDef;
|
||||
/**
|
||||
* Function definition
|
||||
*/
|
||||
def: FunctionCallDef;
|
||||
|
||||
/**
|
||||
* Air script used by the aqua function
|
||||
*/
|
||||
script: string;
|
||||
/**
|
||||
* Air script used by the aqua function
|
||||
*/
|
||||
script: string;
|
||||
|
||||
/**
|
||||
* Function configuration
|
||||
*/
|
||||
config: FnConfig;
|
||||
/**
|
||||
* Function configuration
|
||||
*/
|
||||
config: FnConfig;
|
||||
|
||||
/**
|
||||
* Arguments to pass to the function
|
||||
*/
|
||||
args: PassedArgs;
|
||||
/**
|
||||
* Arguments to pass to the function
|
||||
*/
|
||||
args: PassedArgs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call a function from Aqua script
|
||||
*/
|
||||
export type CallAquaFunctionType = (args: CallAquaFunctionArgs) => Promise<unknown>;
|
||||
export type CallAquaFunctionType = (
|
||||
args: CallAquaFunctionArgs,
|
||||
) => Promise<unknown>;
|
||||
|
||||
/**
|
||||
* Arguments for registerService function
|
||||
*/
|
||||
export interface RegisterServiceArgs {
|
||||
/**
|
||||
* Peer to register the service on
|
||||
*/
|
||||
peer: IFluenceInternalApi;
|
||||
/**
|
||||
* Peer to register the service on
|
||||
*/
|
||||
peer: IFluenceInternalApi;
|
||||
|
||||
/**
|
||||
* Service definition
|
||||
*/
|
||||
def: ServiceDef;
|
||||
/**
|
||||
* Service definition
|
||||
*/
|
||||
def: ServiceDef;
|
||||
|
||||
/**
|
||||
* Service id
|
||||
*/
|
||||
serviceId: string | undefined;
|
||||
/**
|
||||
* Service id
|
||||
*/
|
||||
serviceId: string | undefined;
|
||||
|
||||
/**
|
||||
* Service implementation
|
||||
*/
|
||||
service: any;
|
||||
/**
|
||||
* Service implementation
|
||||
*/
|
||||
service: unknown;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user