Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/ci-js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,17 @@ jobs:
run: yarn install

- name: "Install: binaryen"
working-directory: /usr
run: |
sudo wget -c https://github.com/WebAssembly/binaryen/releases/download/$BINARYEN_VERSION/binaryen-$BINARYEN_VERSION-x86_64-linux.tar.gz -O - | sudo tar -xz -C .
sudo cp binaryen-$BINARYEN_VERSION/bin/wasm-opt /usr/bin/

- name: "Prepare: build all"
run: yarn build

- name: "Prepare: fmt"
run: yarn fmt

- name: "Prepare: download Gear node"
run: |
wget -O ./gear https://github.com/gear-tech/gear/releases/download/build/gear
Expand Down Expand Up @@ -76,6 +80,7 @@ jobs:
run: yarn install

- name: "Install: binaryen"
working-directory: /usr
run: |
sudo wget -c https://github.com/WebAssembly/binaryen/releases/download/$BINARYEN_VERSION/binaryen-$BINARYEN_VERSION-x86_64-linux.tar.gz -O - | sudo tar -xz -C .
sudo cp binaryen-$BINARYEN_VERSION/bin/wasm-opt /usr/bin/
Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
precommit: fmt clippy test

precommit-js:
@yarn install
@yarn build
@yarn fmt

fmt:
@__GEAR_WASM_BUILDER_NO_FEATURES_TRACKING=1 cargo fmt --all -- --check

Expand Down
17 changes: 17 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import globals from 'globals';
import pluginJs from '@eslint/js';
import tseslint from 'typescript-eslint';

export default [
{ files: ['js/**/src/**/*.{ts}'] },
{ languageOptions: { globals: { ...globals.browser, ...globals.node } } },
pluginJs.configs.recommended,
...tseslint.configs.recommended,
{
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-this-alias': 'off',
'no-unexpected-multiline': 'off',
},
},
];
2 changes: 1 addition & 1 deletion js/cli/src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"versions": {
"gear-js": "0.38.2",
"polkadot-api": "12.0.1",
"sails-js": "0.1.10",
"sails-js": "0.2.0",
"typescript": "^5.5.4"
}
}
2 changes: 0 additions & 2 deletions js/cli/src/generate/output.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { writeFileSync } from 'fs';

export class Output {
private _rows: string[] = [];
private _firstRows: string[] = [];
Expand Down
2 changes: 1 addition & 1 deletion js/example/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const main = async () => {
const { blockHash: blockHashPing, msgId: msgIdPing, txHash: txHashPing, response } = await pingBuilder.signAndSend();

console.log(
`\nPing message sent. \p\tBlock hash: ${blockHashPing}, \n\ttx hash: ${txHashPing}, \n\tmessage id: ${msgIdPing}`,
`\nPing message sent. \n\tBlock hash: ${blockHashPing}, \n\ttx hash: ${txHashPing}, \n\tmessage id: ${msgIdPing}`,
);
const reply = await response();
console.log(`\nProgram replied: \n\t${JSON.stringify(reply)}`);
Expand Down
2 changes: 0 additions & 2 deletions js/parser/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,6 @@ export class SailsIdlParser implements ISailsIdlParser {
}

private handleAcceptError(errorCode: number) {
const view = new DataView(this._memory.buffer);

if (errorCode > 0) {
throw new Error(`Error code: ${errorCode}`);
}
Expand Down
10 changes: 5 additions & 5 deletions js/src/sails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ interface ISailsServiceFuncParams {
/** ### Encode payload to hex string */
readonly encodePayload: (...args: any[]) => HexString;
/** ### Decode payload from hex string */
readonly decodePayload: <T extends any = any>(bytes: HexString) => T;
readonly decodePayload: <T = any>(bytes: HexString) => T;
/** ### Decode function result */
readonly decodeResult: <T extends any = any>(result: HexString) => T;
readonly decodeResult: <T = any>(result: HexString) => T;
}

type SailsServiceQuery = ISailsServiceFuncParams &
Expand Down Expand Up @@ -158,7 +158,7 @@ export class Sails {
const params = func.params.map((p) => ({ name: p.name, type: getScaleCodecDef(p.def), typeDef: p.def }));
const returnType = getScaleCodecDef(func.def);
if (func.isQuery) {
queries[func.name] = (async <T extends any = any>(
queries[func.name] = (async <T = any>(
origin: string,
value: bigint = 0n,
atBlock?: HexString,
Expand Down Expand Up @@ -191,7 +191,7 @@ export class Sails {
return result[2].toJSON() as T;
}) as SailsServiceQuery;
} else {
funcs[func.name] = (<T extends any = any>(...args: any): TransactionBuilder<T> => {
funcs[func.name] = (<T = any>(...args: any): TransactionBuilder<T> => {
if (!this._api) {
throw new Error('API is not set. Use .setApi method to set API instance');
}
Expand Down Expand Up @@ -273,7 +273,7 @@ export class Sails {
const data = this.registry.createType(`(String, String, ${typeStr})`, payload);
return data[2].toJSON();
},
subscribe: <T extends any = any>(cb: (eventData: T) => void | Promise<void>): Promise<() => void> => {
subscribe: <T = any>(cb: (eventData: T) => void | Promise<void>): Promise<() => void> => {
if (!this._api) {
throw new Error('API is not set. Use .setApi method to set API instance');
}
Expand Down
2 changes: 1 addition & 1 deletion js/types/src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ export interface ISailsFuncParam {
readonly def: ISailsTypeDef;
}

export interface ISailsServiceEvent extends ISailsEnumVariant {}
export type ISailsServiceEvent = ISailsEnumVariant;
4 changes: 2 additions & 2 deletions js/types/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ export interface ISailsEnumVariant extends IWithDefEntity {
readonly name: string;
}

export interface ISailsOptionalDef extends IWithDefEntity {}
export type ISailsOptionalDef = IWithDefEntity;

export interface ISailsResultDef {
readonly ok: IWithDefEntity;
readonly err: IWithDefEntity;
}

export interface ISailsVecDef extends IWithDefEntity {}
export type ISailsVecDef = IWithDefEntity;

export interface ISailsMapDef {
readonly key: IWithDefEntity;
Expand Down
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,25 @@
"js/example"
],
"devDependencies": {
"@eslint/js": "^9.10.0",
"@rollup/plugin-commonjs": "^26.0.1",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-typescript": "^11.1.6",
"@types/jest": "^29.5.12",
"@types/node": "^22.5.3",
"babel-jest": "^29.7.0",
"eslint": "^9.10.0",
"globals": "^15.9.0",
"jest": "^29.7.0",
"lerna": "^8.1.8",
"rollup": "^4.21.2",
"rollup-plugin-peer-deps-external": "^2.2.4",
"rollup-plugin-typescript2": "^0.36.0",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.2",
"typescript": "^5.5.4"
"typescript": "^5.5.4",
"typescript-eslint": "^8.5.0"
},
"scripts": {
"build:sails": "lerna run build --scope=sails-js",
Expand All @@ -40,6 +44,7 @@
"build": "lerna run build --no-private",
"version": "lerna version --no-private",
"test": "lerna run test --scope=sails-js",
"publish": "lerna publish from-package --no-private"
"publish": "lerna publish from-package --no-private",
"fmt": "npx eslint js/**/src/**/*.ts"
}
}
Loading