From 12f4070e1e5ca08c67edafc50d59060e924c312d Mon Sep 17 00:00:00 2001 From: Zewasik Date: Thu, 17 Oct 2024 20:06:21 +0300 Subject: [PATCH 1/2] add prettier to project format of required files --- .github/workflows/ci-js.yml | 28 ++--- .github/workflows/ci.yml | 2 +- js/.prettierrc => .prettierrc | 0 Makefile | 2 +- js/cli/src/generate/format.ts | 10 +- js/cli/src/generate/index.ts | 5 +- js/cli/src/generate/service-gen.ts | 176 ++++++++++++++--------------- js/cli/src/generate/types-gen.ts | 10 +- js/example/src/lib.ts | 157 ++++++++++++++++++------- js/parser/src/visitor.ts | 5 +- js/src/primitives/index.ts | 4 +- package.json | 4 +- yarn.lock | 10 ++ 13 files changed, 253 insertions(+), 160 deletions(-) rename js/.prettierrc => .prettierrc (100%) diff --git a/.github/workflows/ci-js.yml b/.github/workflows/ci-js.yml index 07664dda..5b1b8ab9 100644 --- a/.github/workflows/ci-js.yml +++ b/.github/workflows/ci-js.yml @@ -1,4 +1,4 @@ -name: "CI-CD sails-js" +name: 'CI-CD sails-js' on: pull_request: @@ -29,38 +29,38 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: "Install: NodeJS 20.x" + - name: 'Install: NodeJS 20.x' uses: actions/setup-node@v4 with: node-version: 20.x - - name: "Install: dependencies" + - name: 'Install: dependencies' run: yarn install - - name: "Install: binaryen" + - 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" + - name: 'Prepare: build all' run: yarn build - - name: "Prepare: fmt" - run: yarn fmt + - name: 'Prepare: fmt' + run: yarn lint - - name: "Prepare: download Gear node" + - name: 'Prepare: download Gear node' run: | wget -O ./gear https://github.com/gear-tech/gear/releases/download/v1.5.0-1/gear chmod +x gear - - name: "Prepare: run Gear node" + - name: 'Prepare: run Gear node' run: nohup ./gear --dev --execution=wasm --tmp --unsafe-rpc-external --rpc-methods Unsafe --rpc-cors all & - - name: "Prepare: sleep 3 min" + - name: 'Prepare: sleep 3 min' run: sleep 180 - - name: "Test: run" + - name: 'Test: run' run: yarn test publish-to-npm: @@ -76,16 +76,16 @@ jobs: with: node-version: 20.x - - name: "Prepare: install dependencies" + - name: 'Prepare: install dependencies' run: yarn install - - name: "Install: binaryen" + - 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" + - name: 'Prepare: build all' run: yarn build - name: Publish diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 395caf64..1a6df3c1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,7 +2,7 @@ name: CI (Rust) on: push: - branches: [ master ] + branches: [master] pull_request: env: diff --git a/js/.prettierrc b/.prettierrc similarity index 100% rename from js/.prettierrc rename to .prettierrc diff --git a/Makefile b/Makefile index 010724f6..3ba7690a 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ precommit: fmt clippy test precommit-js: @yarn install @yarn build - @yarn fmt + @yarn lint fmt: @__GEAR_WASM_BUILDER_NO_FEATURES_TRACKING=1 cargo fmt --all -- --check diff --git a/js/cli/src/generate/format.ts b/js/cli/src/generate/format.ts index 74fb54ab..e7ce98ab 100644 --- a/js/cli/src/generate/format.ts +++ b/js/cli/src/generate/format.ts @@ -1,11 +1,11 @@ export function formatDocs(docs: string): string[] { - if (!docs) return [] - const result = new Array() + if (!docs) return []; + const result = new Array(); - const lines = docs.split("\n") + const lines = docs.split('\n'); for (const line of lines) { - result.push(` * ${line.trim()}`) + result.push(` * ${line.trim()}`); } - return ["/**", ...result, "*/"] + return ['/**', ...result, '*/']; } diff --git a/js/cli/src/generate/index.ts b/js/cli/src/generate/index.ts index 5df39cf3..df536cf5 100644 --- a/js/cli/src/generate/index.ts +++ b/js/cli/src/generate/index.ts @@ -13,7 +13,10 @@ export class ProjectBuilder { private isProject: boolean = true; private isAutomaricOverride: boolean = false; - constructor(private sails: Sails, private name: string = 'Program') {} + constructor( + private sails: Sails, + private name: string = 'Program', + ) {} private async canCreateFile(filePath: string): Promise { if (this.isAutomaricOverride || !existsSync(filePath)) { diff --git a/js/cli/src/generate/service-gen.ts b/js/cli/src/generate/service-gen.ts index c269e310..43f33ba7 100644 --- a/js/cli/src/generate/service-gen.ts +++ b/js/cli/src/generate/service-gen.ts @@ -81,7 +81,7 @@ export class ServiceGenerator extends BaseGenerator { for (const { name, params, docs } of this._program.ctor.funcs) { const args = this.getArgs(params); - const ctorDocs = formatDocs(docs) + const ctorDocs = formatDocs(docs); this._out .lines(ctorDocs, false) @@ -167,56 +167,56 @@ export class ServiceGenerator extends BaseGenerator { const returnType = this.getType(def, decodeMethod); this._out - .line() - .lines(formatDocs(docs), false) - .block(this.getFuncSignature(name, params, returnType, isQuery), () => { - if (isQuery) { - this._out - .line(createPayload(service.name, name, params)) - .import('@gear-js/api', 'decodeAddress') - .line(`const reply = await this._program.api.message.calculateReply({`, false) - .increaseIndent() - .line(`destination: this._program.programId,`, false) - .line(`origin: originAddress ? decodeAddress(originAddress) : ZERO_ADDRESS,`, false) - .line(`payload,`, false) - .line(`value: value || 0,`, false) - .line(`gasLimit: this._program.api.blockGasLimit.toBigInt(),`, false) - .line(`at: atBlock || null,`, false) - .reduceIndent() - .line(`})`) - .line( - "if (!reply.code.isSuccess) throw new Error(this._program.registry.createType('String', reply.payload).toString())", - ) - .line( - `const result = this._program.registry.createType('(String, String, ${returnScaleType})', reply.payload)`, - ) - .line(`return result[2].${decodeMethod}() as unknown as ${returnType}`); - } else { - this._out - .line(`if (!this._program.programId) throw new Error('Program ID is not set')`) - .line(`return new TransactionBuilder<${returnType}>(`, false) - .increaseIndent() - .line(`this._program.api,`, false) - .line(`this._program.registry,`, false) - .line(`'send_message',`, false) - .line( - params.length === 0 - ? `['${service.name}', '${name}'],` - : `['${service.name}', '${name}', ${params.map(({ name }) => name).join(', ')}],`, - false, - ) - .line( - params.length === 0 - ? `'(String, String)',` - : `'(String, String, ${params.map(({ def }) => getScaleCodecDef(def)).join(', ')})',`, - false, - ) - .line(`'${returnScaleType}',`, false) - .line(`this._program.programId`, false) - .reduceIndent() - .line(`)`); - } - }); + .line() + .lines(formatDocs(docs), false) + .block(this.getFuncSignature(name, params, returnType, isQuery), () => { + if (isQuery) { + this._out + .line(createPayload(service.name, name, params)) + .import('@gear-js/api', 'decodeAddress') + .line(`const reply = await this._program.api.message.calculateReply({`, false) + .increaseIndent() + .line(`destination: this._program.programId,`, false) + .line(`origin: originAddress ? decodeAddress(originAddress) : ZERO_ADDRESS,`, false) + .line(`payload,`, false) + .line(`value: value || 0,`, false) + .line(`gasLimit: this._program.api.blockGasLimit.toBigInt(),`, false) + .line(`at: atBlock || null,`, false) + .reduceIndent() + .line(`})`) + .line( + "if (!reply.code.isSuccess) throw new Error(this._program.registry.createType('String', reply.payload).toString())", + ) + .line( + `const result = this._program.registry.createType('(String, String, ${returnScaleType})', reply.payload)`, + ) + .line(`return result[2].${decodeMethod}() as unknown as ${returnType}`); + } else { + this._out + .line(`if (!this._program.programId) throw new Error('Program ID is not set')`) + .line(`return new TransactionBuilder<${returnType}>(`, false) + .increaseIndent() + .line(`this._program.api,`, false) + .line(`this._program.registry,`, false) + .line(`'send_message',`, false) + .line( + params.length === 0 + ? `['${service.name}', '${name}'],` + : `['${service.name}', '${name}', ${params.map(({ name }) => name).join(', ')}],`, + false, + ) + .line( + params.length === 0 + ? `'(String, String)',` + : `'(String, String, ${params.map(({ def }) => getScaleCodecDef(def)).join(', ')})',`, + false, + ) + .line(`'${returnScaleType}',`, false) + .line(`this._program.programId`, false) + .reduceIndent() + .line(`)`); + } + }); } } @@ -233,43 +233,43 @@ export class ServiceGenerator extends BaseGenerator { const jsType = event.def ? this.getType(event.def, decodeMethod) : 'null'; this._out - .line() - .lines(formatDocs(event.docs), false) - .block( - `public subscribeTo${event.name}Event(callback: (data: ${jsType}) => void | Promise): Promise<() => void>`, - () => { - this._out - .line( - `return this._program.api.gearEvents.subscribeToGearEvent('UserMessageSent', ({ data: { message } }) => {`, - ) - .increaseIndent() - .block( - `if (!message.source.eq(this._program.programId) || !message.destination.eq(ZERO_ADDRESS))`, - () => { - this._out.line(`return`); - }, - ) - .line() - .line(`const payload = message.payload.toHex()`) - .block( - `if (getServiceNamePrefix(payload) === '${service.name}' && getFnNamePrefix(payload) === '${event.name}')`, - () => { - if (jsType === 'null') { - this._out.line(`callback(null)`); - } else { - this._out.line( - `callback(this._program.registry.createType('(String, String, ${getScaleCodecDef( - event.def, - true, - )})', message.payload)[2].${decodeMethod}() as unknown as ${jsType})`, - ); - } - }, - ) - .reduceIndent() - .line(`})`); - }, - ); + .line() + .lines(formatDocs(event.docs), false) + .block( + `public subscribeTo${event.name}Event(callback: (data: ${jsType}) => void | Promise): Promise<() => void>`, + () => { + this._out + .line( + `return this._program.api.gearEvents.subscribeToGearEvent('UserMessageSent', ({ data: { message } }) => {`, + ) + .increaseIndent() + .block( + `if (!message.source.eq(this._program.programId) || !message.destination.eq(ZERO_ADDRESS))`, + () => { + this._out.line(`return`); + }, + ) + .line() + .line(`const payload = message.payload.toHex()`) + .block( + `if (getServiceNamePrefix(payload) === '${service.name}' && getFnNamePrefix(payload) === '${event.name}')`, + () => { + if (jsType === 'null') { + this._out.line(`callback(null)`); + } else { + this._out.line( + `callback(this._program.registry.createType('(String, String, ${getScaleCodecDef( + event.def, + true, + )})', message.payload)[2].${decodeMethod}() as unknown as ${jsType})`, + ); + } + }, + ) + .reduceIndent() + .line(`})`); + }, + ); } } diff --git a/js/cli/src/generate/types-gen.ts b/js/cli/src/generate/types-gen.ts index a57d4851..915d0da5 100644 --- a/js/cli/src/generate/types-gen.ts +++ b/js/cli/src/generate/types-gen.ts @@ -16,7 +16,7 @@ export class TypesGenerator extends BaseGenerator { public generate() { this._out.line('declare global {').increaseIndent(); for (const { name, def, docs } of this._program.types) { - this._out.lines(formatDocs(docs), false) + this._out.lines(formatDocs(docs), false); if (def.isStruct) { this.generateStruct(name, def); @@ -39,9 +39,7 @@ export class TypesGenerator extends BaseGenerator { return this._out .block(`export interface ${name}`, () => { for (const field of def.asStruct.fields) { - this._out - .lines(formatDocs(field.docs), false) - .line(`${field.name}: ${this.getType(field.def)}`); + this._out.lines(formatDocs(field.docs), false).line(`${field.name}: ${this.getType(field.def)}`); } }) .line(); @@ -52,8 +50,8 @@ export class TypesGenerator extends BaseGenerator { this._out.line(`export type ${typeName} = `, false).increaseIndent(); for (const [i, variant] of def.variants.entries()) { this._out - .lines(formatDocs(variant.docs), false) - .line(`| ${this.getEnumFieldString(variant)}`, i === def.variants.length - 1); + .lines(formatDocs(variant.docs), false) + .line(`| ${this.getEnumFieldString(variant)}`, i === def.variants.length - 1); } this._out.reduceIndent().line(); } else { diff --git a/js/example/src/lib.ts b/js/example/src/lib.ts index 3c314e7d..49de19e7 100644 --- a/js/example/src/lib.ts +++ b/js/example/src/lib.ts @@ -1,4 +1,14 @@ -import { NonZeroU32, ActorId, H256, TransactionBuilder, getServiceNamePrefix, getFnNamePrefix, ZERO_ADDRESS, H160, NonZeroU8 } from 'sails-js'; +import { + NonZeroU32, + ActorId, + H256, + TransactionBuilder, + getServiceNamePrefix, + getFnNamePrefix, + ZERO_ADDRESS, + H160, + NonZeroU8, +} from 'sails-js'; import { GearApi, decodeAddress } from '@gear-js/api'; import { TypeRegistry } from '@polkadot/types'; @@ -10,7 +20,7 @@ export interface DoThatParam { p3: ManyVariants; } -export type ManyVariants = +export type ManyVariants = | { one: null } | { two: number } | { three: number | string | bigint | null } @@ -28,13 +38,25 @@ export class Program { public readonly references: References; public readonly thisThat: ThisThat; - constructor(public api: GearApi, public programId?: `0x${string}`) { + constructor( + public api: GearApi, + public programId?: `0x${string}`, + ) { const types: Record = { - ReferenceCount: "(u32)", - DoThatParam: {"p1":"u32","p2":"[u8;32]","p3":"ManyVariants"}, - ManyVariants: {"_enum":{"One":"Null","Two":"u32","Three":"Option","Four":{"a":"u32","b":"Option"},"Five":"(String, H256)","Six":"(u32)"}}, - TupleStruct: "(bool)", - } + ReferenceCount: '(u32)', + DoThatParam: { p1: 'u32', p2: '[u8;32]', p3: 'ManyVariants' }, + ManyVariants: { + _enum: { + One: 'Null', + Two: 'u32', + Three: 'Option', + Four: { a: 'u32', b: 'Option' }, + Five: '(String, H256)', + Six: '(u32)', + }, + }, + TupleStruct: '(bool)', + }; this.registry = new TypeRegistry(); this.registry.setKnownTypes({ types }); @@ -76,7 +98,11 @@ export class Program { this.programId = builder.programId; return builder; } - newCtorFromCode(code: Uint8Array | Buffer, counter: number | null, dog_position: [number, number] | null): TransactionBuilder { + newCtorFromCode( + code: Uint8Array | Buffer, + counter: number | null, + dog_position: [number, number] | null, + ): TransactionBuilder { const builder = new TransactionBuilder( this.api, this.registry, @@ -119,7 +145,7 @@ export class Counter { ['Counter', 'Add', value], '(String, String, u32)', 'u32', - this._program.programId + this._program.programId, ); } @@ -132,11 +158,15 @@ export class Counter { ['Counter', 'Sub', value], '(String, String, u32)', 'u32', - this._program.programId + this._program.programId, ); } - public async value(originAddress?: string, value?: number | string | bigint, atBlock?: `0x${string}`): Promise { + public async value( + originAddress?: string, + value?: number | string | bigint, + atBlock?: `0x${string}`, + ): Promise { const payload = this._program.registry.createType('(String, String)', ['Counter', 'Value']).toHex(); const reply = await this._program.api.message.calculateReply({ destination: this._program.programId, @@ -152,27 +182,35 @@ export class Counter { } public subscribeToAddedEvent(callback: (data: number) => void | Promise): Promise<() => void> { - return this._program.api.gearEvents.subscribeToGearEvent('UserMessageSent', ({ data: { message } }) => {; + return this._program.api.gearEvents.subscribeToGearEvent('UserMessageSent', ({ data: { message } }) => { if (!message.source.eq(this._program.programId) || !message.destination.eq(ZERO_ADDRESS)) { return; } const payload = message.payload.toHex(); if (getServiceNamePrefix(payload) === 'Counter' && getFnNamePrefix(payload) === 'Added') { - callback(this._program.registry.createType('(String, String, u32)', message.payload)[2].toNumber() as unknown as number); + callback( + this._program.registry + .createType('(String, String, u32)', message.payload)[2] + .toNumber() as unknown as number, + ); } }); } public subscribeToSubtractedEvent(callback: (data: number) => void | Promise): Promise<() => void> { - return this._program.api.gearEvents.subscribeToGearEvent('UserMessageSent', ({ data: { message } }) => {; + return this._program.api.gearEvents.subscribeToGearEvent('UserMessageSent', ({ data: { message } }) => { if (!message.source.eq(this._program.programId) || !message.destination.eq(ZERO_ADDRESS)) { return; } const payload = message.payload.toHex(); if (getServiceNamePrefix(payload) === 'Counter' && getFnNamePrefix(payload) === 'Subtracted') { - callback(this._program.registry.createType('(String, String, u32)', message.payload)[2].toNumber() as unknown as number); + callback( + this._program.registry + .createType('(String, String, u32)', message.payload)[2] + .toNumber() as unknown as number, + ); } }); } @@ -190,7 +228,7 @@ export class Dog { ['Dog', 'MakeSound'], '(String, String)', 'String', - this._program.programId + this._program.programId, ); } @@ -203,11 +241,15 @@ export class Dog { ['Dog', 'Walk', dx, dy], '(String, String, i32, i32)', 'Null', - this._program.programId + this._program.programId, ); } - public async avgWeight(originAddress?: string, value?: number | string | bigint, atBlock?: `0x${string}`): Promise { + public async avgWeight( + originAddress?: string, + value?: number | string | bigint, + atBlock?: `0x${string}`, + ): Promise { const payload = this._program.registry.createType('(String, String)', ['Dog', 'AvgWeight']).toHex(); const reply = await this._program.api.message.calculateReply({ destination: this._program.programId, @@ -222,7 +264,11 @@ export class Dog { return result[2].toNumber() as unknown as number; } - public async position(originAddress?: string, value?: number | string | bigint, atBlock?: `0x${string}`): Promise<[number, number]> { + public async position( + originAddress?: string, + value?: number | string | bigint, + atBlock?: `0x${string}`, + ): Promise<[number, number]> { const payload = this._program.registry.createType('(String, String)', ['Dog', 'Position']).toHex(); const reply = await this._program.api.message.calculateReply({ destination: this._program.programId, @@ -238,7 +284,7 @@ export class Dog { } public subscribeToBarkedEvent(callback: (data: null) => void | Promise): Promise<() => void> { - return this._program.api.gearEvents.subscribeToGearEvent('UserMessageSent', ({ data: { message } }) => {; + return this._program.api.gearEvents.subscribeToGearEvent('UserMessageSent', ({ data: { message } }) => { if (!message.source.eq(this._program.programId) || !message.destination.eq(ZERO_ADDRESS)) { return; } @@ -250,15 +296,21 @@ export class Dog { }); } - public subscribeToWalkedEvent(callback: (data: { from: [number, number]; to: [number, number] }) => void | Promise): Promise<() => void> { - return this._program.api.gearEvents.subscribeToGearEvent('UserMessageSent', ({ data: { message } }) => {; + public subscribeToWalkedEvent( + callback: (data: { from: [number, number]; to: [number, number] }) => void | Promise, + ): Promise<() => void> { + return this._program.api.gearEvents.subscribeToGearEvent('UserMessageSent', ({ data: { message } }) => { if (!message.source.eq(this._program.programId) || !message.destination.eq(ZERO_ADDRESS)) { return; } const payload = message.payload.toHex(); if (getServiceNamePrefix(payload) === 'Dog' && getFnNamePrefix(payload) === 'Walked') { - callback(this._program.registry.createType('(String, String, {"from":"(i32, i32)","to":"(i32, i32)"})', message.payload)[2].toJSON() as unknown as { from: [number, number]; to: [number, number] }); + callback( + this._program.registry + .createType('(String, String, {"from":"(i32, i32)","to":"(i32, i32)"})', message.payload)[2] + .toJSON() as unknown as { from: [number, number]; to: [number, number] }, + ); } }); } @@ -276,7 +328,7 @@ export class PingPong { ['PingPong', 'Ping', input], '(String, String, String)', 'Result', - this._program.programId + this._program.programId, ); } } @@ -293,7 +345,7 @@ export class References { ['References', 'Add', v], '(String, String, u32)', 'u32', - this._program.programId + this._program.programId, ); } @@ -306,7 +358,7 @@ export class References { ['References', 'AddByte', byte], '(String, String, u8)', 'Vec', - this._program.programId + this._program.programId, ); } @@ -319,7 +371,7 @@ export class References { ['References', 'GuessNum', number], '(String, String, u8)', 'Result', - this._program.programId + this._program.programId, ); } @@ -332,7 +384,7 @@ export class References { ['References', 'Incr'], '(String, String)', 'ReferenceCount', - this._program.programId + this._program.programId, ); } @@ -345,11 +397,15 @@ export class References { ['References', 'SetNum', number], '(String, String, u8)', 'Result', - this._program.programId + this._program.programId, ); } - public async baked(originAddress?: string, value?: number | string | bigint, atBlock?: `0x${string}`): Promise { + public async baked( + originAddress?: string, + value?: number | string | bigint, + atBlock?: `0x${string}`, + ): Promise { const payload = this._program.registry.createType('(String, String)', ['References', 'Baked']).toHex(); const reply = await this._program.api.message.calculateReply({ destination: this._program.programId, @@ -364,7 +420,11 @@ export class References { return result[2].toString() as unknown as string; } - public async lastByte(originAddress?: string, value?: number | string | bigint, atBlock?: `0x${string}`): Promise { + public async lastByte( + originAddress?: string, + value?: number | string | bigint, + atBlock?: `0x${string}`, + ): Promise { const payload = this._program.registry.createType('(String, String)', ['References', 'LastByte']).toHex(); const reply = await this._program.api.message.calculateReply({ destination: this._program.programId, @@ -379,7 +439,11 @@ export class References { return result[2].toJSON() as unknown as number | null; } - public async message(originAddress?: string, value?: number | string | bigint, atBlock?: `0x${string}`): Promise { + public async message( + originAddress?: string, + value?: number | string | bigint, + atBlock?: `0x${string}`, + ): Promise { const payload = this._program.registry.createType('(String, String)', ['References', 'Message']).toHex(); const reply = await this._program.api.message.calculateReply({ destination: this._program.programId, @@ -407,11 +471,16 @@ export class ThisThat { ['ThisThat', 'DoThat', param], '(String, String, DoThatParam)', 'Result<([u8;32], u32), (String)>', - this._program.programId + this._program.programId, ); } - public doThis(p1: number, p2: string, p3: [H160 | null, NonZeroU8], p4: TupleStruct): TransactionBuilder<[string, number]> { + public doThis( + p1: number, + p2: string, + p3: [H160 | null, NonZeroU8], + p4: TupleStruct, + ): TransactionBuilder<[string, number]> { if (!this._program.programId) throw new Error('Program ID is not set'); return new TransactionBuilder<[string, number]>( this._program.api, @@ -420,7 +489,7 @@ export class ThisThat { ['ThisThat', 'DoThis', p1, p2, p3, p4], '(String, String, u32, String, (Option, u8), TupleStruct)', '(String, u32)', - this._program.programId + this._program.programId, ); } @@ -433,11 +502,15 @@ export class ThisThat { ['ThisThat', 'Noop'], '(String, String)', 'Null', - this._program.programId + this._program.programId, ); } - public async that(originAddress?: string, value?: number | string | bigint, atBlock?: `0x${string}`): Promise<{ ok: string } | { err: string }> { + public async that( + originAddress?: string, + value?: number | string | bigint, + atBlock?: `0x${string}`, + ): Promise<{ ok: string } | { err: string }> { const payload = this._program.registry.createType('(String, String)', ['ThisThat', 'That']).toHex(); const reply = await this._program.api.message.calculateReply({ destination: this._program.programId, @@ -452,7 +525,11 @@ export class ThisThat { return result[2].toJSON() as unknown as { ok: string } | { err: string }; } - public async this(originAddress?: string, value?: number | string | bigint, atBlock?: `0x${string}`): Promise { + public async this( + originAddress?: string, + value?: number | string | bigint, + atBlock?: `0x${string}`, + ): Promise { const payload = this._program.registry.createType('(String, String)', ['ThisThat', 'This']).toHex(); const reply = await this._program.api.message.calculateReply({ destination: this._program.programId, @@ -466,4 +543,4 @@ export class ThisThat { const result = this._program.registry.createType('(String, String, u32)', reply.payload); return result[2].toNumber() as unknown as number; } -} \ No newline at end of file +} diff --git a/js/parser/src/visitor.ts b/js/parser/src/visitor.ts index 837200e3..1bb8efb4 100644 --- a/js/parser/src/visitor.ts +++ b/js/parser/src/visitor.ts @@ -2,7 +2,10 @@ export class Base { protected offset: number; public readonly rawPtr: number; - constructor(public ptr: number, memory: WebAssembly.Memory) { + constructor( + public ptr: number, + memory: WebAssembly.Memory, + ) { const rawPtrBuf = new Uint8Array(memory.buffer.slice(ptr, ptr + 4)); const rawPtrDv = new DataView(rawPtrBuf.buffer, 0); this.rawPtr = rawPtrDv.getUint32(0, true); diff --git a/js/src/primitives/index.ts b/js/src/primitives/index.ts index 37b6d7a4..b5d54c31 100644 --- a/js/src/primitives/index.ts +++ b/js/src/primitives/index.ts @@ -1,2 +1,2 @@ -export * from "./non-zero.js" -export * from "./hash.js" +export * from './non-zero.js'; +export * from './hash.js'; diff --git a/package.json b/package.json index f54b7ea6..6fab48e3 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "globals": "^15.10.0", "jest": "^29.7.0", "lerna": "^8.1.8", + "prettier": "^3.3.3", "rollup": "^4.24.0", "rollup-plugin-peer-deps-external": "^2.2.4", "rollup-plugin-typescript2": "^0.36.0", @@ -45,7 +46,8 @@ "version": "lerna version --no-private", "test": "lerna run test --scope=sails-js", "publish": "lerna publish from-package --no-private", - "fmt": "npx eslint js/**/src/**/*.ts", + "lint": "eslint js/**/src/**/*.ts", + "format": "prettier --write \"js/**/src/**/*.ts\"", "clean": "lerna clean && rm -rf js/cli/build js/{parser,.,types}/lib" } } diff --git a/yarn.lock b/yarn.lock index 797b359d..11673204 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7547,6 +7547,15 @@ __metadata: languageName: node linkType: hard +"prettier@npm:^3.3.3": + version: 3.3.3 + resolution: "prettier@npm:3.3.3" + bin: + prettier: bin/prettier.cjs + checksum: 10c0/b85828b08e7505716324e4245549b9205c0cacb25342a030ba8885aba2039a115dbcf75a0b7ca3b37bc9d101ee61fab8113fc69ca3359f2a226f1ecc07ad2e26 + languageName: node + linkType: hard + "pretty-format@npm:^29.0.0, pretty-format@npm:^29.7.0": version: 29.7.0 resolution: "pretty-format@npm:29.7.0" @@ -8131,6 +8140,7 @@ __metadata: globals: "npm:^15.10.0" jest: "npm:^29.7.0" lerna: "npm:^8.1.8" + prettier: "npm:^3.3.3" rollup: "npm:^4.24.0" rollup-plugin-peer-deps-external: "npm:^2.2.4" rollup-plugin-typescript2: "npm:^0.36.0" From db1a580c2b822d94329ce54b24374de11f00482b Mon Sep 17 00:00:00 2001 From: Zewasik Date: Mon, 21 Oct 2024 13:58:36 +0300 Subject: [PATCH 2/2] minor changes --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 3ba7690a..8726375e 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,7 @@ precommit: fmt clippy test precommit-js: @yarn install @yarn build + @yarn format @yarn lint fmt: