mirror of
https://github.com/fluencelabs/fluence-js.git
synced 2025-06-27 06:41:32 +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");
|
||||
@ -14,57 +14,94 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { ArrowWithoutCallbacks, NonArrowType, ProductType } from '@fluencelabs/interfaces';
|
||||
import { readFile } from 'fs/promises';
|
||||
import path from 'path';
|
||||
import assert from "assert";
|
||||
import { readFile } from "fs/promises";
|
||||
import path from "path";
|
||||
|
||||
import {
|
||||
ArrowType,
|
||||
ArrowWithoutCallbacks,
|
||||
JSONValue,
|
||||
LabeledProductType,
|
||||
NilType,
|
||||
SimpleTypes,
|
||||
UnlabeledProductType,
|
||||
} from "@fluencelabs/interfaces";
|
||||
|
||||
export interface PackageJson {
|
||||
name: string;
|
||||
version: string;
|
||||
devDependencies: {
|
||||
['@fluencelabs/aqua-api']: string
|
||||
}
|
||||
name: string;
|
||||
version: string;
|
||||
devDependencies: {
|
||||
["@fluencelabs/aqua-api"]: string;
|
||||
};
|
||||
}
|
||||
|
||||
export async function getPackageJsonContent(): Promise<PackageJson> {
|
||||
const content = await readFile(new URL(path.join('..', 'package.json'), import.meta.url), 'utf-8');
|
||||
return JSON.parse(content);
|
||||
const content = await readFile(
|
||||
new URL(path.join("..", "package.json"), import.meta.url),
|
||||
"utf-8",
|
||||
);
|
||||
|
||||
// TODO: Add validation here
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
return JSON.parse(content) as PackageJson;
|
||||
}
|
||||
|
||||
export function getFuncArgs(domain: ProductType<NonArrowType | ArrowWithoutCallbacks>): [string, NonArrowType | ArrowWithoutCallbacks][] {
|
||||
if (domain.tag === 'labeledProduct') {
|
||||
return Object.entries(domain.fields).map(([label, type]) => [label, type]);
|
||||
} else if (domain.tag === 'unlabeledProduct') {
|
||||
return domain.items.map((type, index) => ['arg' + index, type]);
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
export function getFuncArgs(
|
||||
domain:
|
||||
| LabeledProductType<SimpleTypes | ArrowType<UnlabeledProductType>>
|
||||
| UnlabeledProductType
|
||||
| NilType,
|
||||
): [string, SimpleTypes | ArrowWithoutCallbacks][] {
|
||||
if (domain.tag === "labeledProduct") {
|
||||
return Object.entries(domain.fields).map(([label, type]) => {
|
||||
return [label, type];
|
||||
});
|
||||
} else if (domain.tag === "unlabeledProduct") {
|
||||
return domain.items.map((type, index) => {
|
||||
return ["arg" + index, type];
|
||||
});
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
export function recursiveRenameLaquaProps(obj: unknown): unknown {
|
||||
if (typeof obj !== 'object' || obj === null) return obj;
|
||||
export function recursiveRenameLaquaProps(obj: JSONValue): unknown {
|
||||
if (typeof obj !== "object" || obj === null) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
if (Array.isArray(obj)) {
|
||||
return obj.map(item => recursiveRenameLaquaProps(item));
|
||||
if (Array.isArray(obj)) {
|
||||
return obj.map((item) => {
|
||||
return recursiveRenameLaquaProps(item);
|
||||
});
|
||||
}
|
||||
|
||||
return Object.getOwnPropertyNames(obj).reduce((acc, prop) => {
|
||||
let accessProp = prop;
|
||||
|
||||
if (prop.includes("Laqua_js")) {
|
||||
// Last part of the property separated by "_" is a correct name
|
||||
const refinedProperty = prop.split("_").pop();
|
||||
|
||||
if (refinedProperty == null) {
|
||||
throw new Error(`Bad property name: ${prop}.`);
|
||||
}
|
||||
|
||||
if (refinedProperty in obj) {
|
||||
accessProp = refinedProperty;
|
||||
}
|
||||
}
|
||||
|
||||
return Object.getOwnPropertyNames(obj).reduce((acc, prop) => {
|
||||
let accessProp = prop;
|
||||
if (prop.includes('Laqua_js')) {
|
||||
// Last part of the property separated by "_" is a correct name
|
||||
const refinedProperty = prop.split('_').pop()!;
|
||||
if (refinedProperty in obj) {
|
||||
accessProp = refinedProperty;
|
||||
}
|
||||
}
|
||||
assert(accessProp in obj);
|
||||
|
||||
return {
|
||||
...acc,
|
||||
[accessProp]: recursiveRenameLaquaProps(obj[accessProp as keyof typeof obj])
|
||||
};
|
||||
}, {});
|
||||
return {
|
||||
...acc,
|
||||
[accessProp]: recursiveRenameLaquaProps(obj[accessProp]),
|
||||
};
|
||||
}, {});
|
||||
}
|
||||
|
||||
export function capitalize(str: string) {
|
||||
return str.slice(0, 1).toUpperCase() + str.slice(1);
|
||||
}
|
||||
return str.slice(0, 1).toUpperCase() + str.slice(1);
|
||||
}
|
||||
|
Reference in New Issue
Block a user