Skip to content

Commit

Permalink
bump dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
osipov-mit committed Dec 3, 2024
1 parent 80e5e3c commit 09d2ba6
Show file tree
Hide file tree
Showing 7 changed files with 899 additions and 780 deletions.
4 changes: 2 additions & 2 deletions js/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
"sails-js": "./build/app.js"
},
"devDependencies": {
"@inquirer/prompts": "^7.0.0",
"@inquirer/prompts": "^7.1.0",
"commander": "^12.1.0",
"inquirer": "^12.0.0",
"inquirer": "^12.1.0",
"sails-js": "workspace:*",
"sails-js-parser": "workspace:*",
"sails-js-util": "workspace:^"
Expand Down
2 changes: 1 addition & 1 deletion js/cli/src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
"gear-js": "0.38.3",
"polkadot-api": "13.2.1",
"sails-js": "0.3.0",
"typescript": "^5.6.2"
"typescript": "^5.7.2"
}
}
75 changes: 37 additions & 38 deletions js/cli/src/generate/service-gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,65 +33,67 @@ export class ServiceGenerator extends BaseGenerator {
}

public generate(className = 'Program') {
const _classFromUpperLetter = className[0].toUpperCase() + className.slice(1);
const $ = this._out;
const _classNameTitled = className[0].toUpperCase() + className.slice(1);

this._out
.import('@gear-js/api', 'GearApi')
$.import('@gear-js/api', 'GearApi')
.import(`@polkadot/types`, `TypeRegistry`)
.import('sails-js', 'TransactionBuilder')
.block(`export class ${_classFromUpperLetter}`, () => {
this._out.line(`public readonly registry: TypeRegistry`);
.block(`export class ${_classNameTitled}`, () => {
$.line(`public readonly registry: TypeRegistry`);

for (const service of this._program.services) {
this._out.line(
$.line(
`public readonly ${toLowerCaseFirst(service.name)}: ${
service.name === _classFromUpperLetter ? service.name + 'Service' : service.name
service.name === _classNameTitled ? service.name + 'Service' : service.name
}`,
);
}

this._out
.line()
.block(`constructor(public api: GearApi, public programId?: ${HEX_STRING_TYPE})`, () => {
this._out
.block(`const types: Record<string, any> =`, () => {
for (const [name, type] of Object.entries(this.scaleTypes)) {
this._out.line(`${name}: ${JSON.stringify(type)},`, false);
}
})
$.line()
.block(`constructor(public api: GearApi, private _programId?: ${HEX_STRING_TYPE})`, () => {
$.block(`const types: Record<string, any> =`, () => {
for (const [name, type] of Object.entries(this.scaleTypes)) {
$.line(`${name}: ${JSON.stringify(type)},`, false);
}
})
.line()
.line(`this.registry = new TypeRegistry()`)
.line(`this.registry.setKnownTypes({ types })`)
.line(`this.registry.register(types)`)
.line();

for (const service of this._program.services) {
this._out.line(`this.${toLowerCaseFirst(service.name)} = new ${service.name}(this)`);
$.line(`this.${toLowerCaseFirst(service.name)} = new ${service.name}(this)`);
}
})
.line()
.block(`public get programId(): ${HEX_STRING_TYPE}`, () => {
$.line('if (!this._programId) throw new Error(`Program ID is not set`)').line('return this._programId');
})
.line();
this.generateProgramConstructor();
});
this.generateServices(_classFromUpperLetter);
this.generateServices(_classNameTitled);
}

private generateProgramConstructor() {
if (!this._program.ctor || this._program.ctor.funcs.length === 0) return;

const $ = this._out;

for (const { name, params, docs } of this._program.ctor.funcs) {
const args = this.getArgs(params);

const ctorDocs = formatDocs(docs);

this._out
.lines(ctorDocs, false)
$.lines(ctorDocs, false)
.block(
`${getFuncName(name)}CtorFromCode(code: Uint8Array | Buffer${
args !== null ? ', ' + args : ''
}): TransactionBuilder<null>`,
() => {
this._out
.line(`const builder = new TransactionBuilder<null>(`, false)
$.line(`const builder = new TransactionBuilder<null>(`, false)
.increaseIndent()
.line(`this.api,`, false)
.line(`this.registry,`, false)
Expand All @@ -111,7 +113,7 @@ export class ServiceGenerator extends BaseGenerator {
.reduceIndent()
.line(`)`)
.line()
.line('this.programId = builder.programId')
.line('this._programId = builder.programId')
.line('return builder');
},
)
Expand All @@ -120,8 +122,7 @@ export class ServiceGenerator extends BaseGenerator {
.block(
`${getFuncName(name)}CtorFromCodeId(codeId: ${HEX_STRING_TYPE}${args !== null ? ', ' + args : ''})`,
() => {
this._out
.line(`const builder = new TransactionBuilder<null>(`, false)
$.line(`const builder = new TransactionBuilder<null>(`, false)
.increaseIndent()
.line(`this.api,`, false)
.line(`this.registry,`, false)
Expand All @@ -141,7 +142,7 @@ export class ServiceGenerator extends BaseGenerator {
.reduceIndent()
.line(`)`)
.line()
.line('this.programId = builder.programId')
.line('this._programId = builder.programId')
.line('return builder');
},
);
Expand Down Expand Up @@ -181,7 +182,7 @@ export class ServiceGenerator extends BaseGenerator {
.line(`payload,`, false)
.line(`value: value || 0,`, false)
.line(`gasLimit: this._program.api.blockGasLimit.toBigInt(),`, false)
.line(`at: atBlock || null,`, false)
.line(`at: atBlock,`, false)
.reduceIndent()
.line(`})`)
.line(
Expand Down Expand Up @@ -221,9 +222,9 @@ export class ServiceGenerator extends BaseGenerator {
}

private generateSubscriptions(service: ISailsService) {
const $ = this._out;
if (service.events.length > 0) {
this._out
.import('sails-js', 'getServiceNamePrefix')
$.import('sails-js', 'getServiceNamePrefix')
.import('sails-js', 'getFnNamePrefix')
.import('sails-js', 'ZERO_ADDRESS');
}
Expand All @@ -232,21 +233,19 @@ export class ServiceGenerator extends BaseGenerator {
const decodeMethod = event.def ? getPayloadMethod(getScaleCodecDef(event.def)) : PayloadMethod.toJSON;
const jsType = event.def ? this.getType(event.def, decodeMethod) : 'null';

this._out
.line()
$.line()
.lines(formatDocs(event.docs), false)
.block(
`public subscribeTo${event.name}Event(callback: (data: ${jsType}) => void | Promise<void>): Promise<() => void>`,
() => {
this._out
.line(
`return this._program.api.gearEvents.subscribeToGearEvent('UserMessageSent', ({ data: { message } }) => {`,
)
$.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(`return`);
},
)
.line()
Expand All @@ -255,9 +254,9 @@ export class ServiceGenerator extends BaseGenerator {
`if (getServiceNamePrefix(payload) === '${service.name}' && getFnNamePrefix(payload) === '${event.name}')`,
() => {
if (jsType === 'null') {
this._out.line(`callback(null)`);
$.line(`callback(null)`);
} else {
this._out.line(
$.line(
`callback(this._program.registry.createType('(String, String, ${getScaleCodecDef(
event.def,
true,
Expand Down
6 changes: 3 additions & 3 deletions js/example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
"private": true,
"type": "module",
"dependencies": {
"@gear-js/api": "0.38.3",
"@polkadot/api": "13.2.1",
"@gear-js/api": "0.40.0",
"@polkadot/api": "15.0.1",
"sails-js": "0.3.0"
},
"devDependencies": {
"typescript": "^5.6.2"
"typescript": "^5.7.2"
},
"scripts": {
"build": "tsc"
Expand Down
6 changes: 3 additions & 3 deletions js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
"sails-js-util": "0.0.1"
},
"devDependencies": {
"@gear-js/api": "0.38.3",
"@polkadot/api": "13.2.1",
"@polkadot/types": "13.2.1",
"@gear-js/api": "0.40.0",
"@polkadot/api": "15.0.1",
"@polkadot/types": "15.0.1",
"jest": "^29.7.0"
},
"files": [
Expand Down
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,26 @@
"js/example"
],
"devDependencies": {
"@eslint/js": "^9.12.0",
"@rollup/plugin-commonjs": "^28.0.0",
"@eslint/js": "^9.16.0",
"@rollup/plugin-commonjs": "^28.0.1",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.3.0",
"@rollup/plugin-typescript": "^12.1.0",
"@types/jest": "^29.5.13",
"@types/node": "^22.7.5",
"@rollup/plugin-typescript": "^12.1.1",
"@types/jest": "^29.5.14",
"@types/node": "^22.10.1",
"babel-jest": "^29.7.0",
"eslint": "^9.12.0",
"globals": "^15.10.0",
"eslint": "^9.16.0",
"globals": "^15.13.0",
"jest": "^29.7.0",
"lerna": "^8.1.8",
"prettier": "^3.3.3",
"rollup": "^4.24.0",
"lerna": "^8.1.9",
"prettier": "^3.4.1",
"rollup": "^4.28.0",
"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.6.2",
"typescript-eslint": "^8.8.1"
"typescript": "^5.7.2",
"typescript-eslint": "^8.17.0"
},
"scripts": {
"build:sails": "lerna run build --scope=sails-js",
Expand Down
Loading

0 comments on commit 09d2ba6

Please sign in to comment.