Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(js): update dependencies #709

Merged
merged 2 commits into from
Dec 4, 2024
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: 3 additions & 2 deletions js/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# CHANGELOG

## 0.3.1 (draft)
## 0.3.1

### Compatibility
- Sails-RS v0.6.3
- Sails-RS v0.7.0

### Changes
- Setup automated releases in https://github.com/gear-tech/sails/pull/608
- Update dependencies in https://github.com/gear-tech/sails/pull/709
6 changes: 3 additions & 3 deletions js/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sails-js-cli",
"version": "0.1.3",
"version": "0.3.1",
"preferGlobal": true,
"type": "module",
"license": "GPL-3.0",
Expand All @@ -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
4 changes: 2 additions & 2 deletions 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.3",
"polkadot-api": "13.2.1",
"sails-js": "0.3.0",
"typescript": "^5.6.2"
"sails-js": "0.3.1",
"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
2 changes: 1 addition & 1 deletion js/config.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"sails-rs": "0.6.3"
"sails-rs": "0.7.0"
}
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
8 changes: 4 additions & 4 deletions js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sails-js",
"version": "0.3.0",
"version": "0.3.1",
"description": "Parser and typescript code generator from Sails IDL files",
"preferGlobal": true,
"type": "module",
Expand Down 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
2 changes: 1 addition & 1 deletion js/parser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sails-js-parser",
"version": "0.1.0",
"version": "0.3.1",
"description": "Sails-IDL parser for TypeScript",
"main": "lib/cjs/index.cjs",
"module": "lib/index.js",
Expand Down
2 changes: 1 addition & 1 deletion js/types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sails-js-types",
"version": "0.0.1",
"version": "0.3.1",
"description": "Common types for sails-js libraries",
"types": "lib/index.d.ts",
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion js/util/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sails-js-util",
"version": "0.0.1",
"version": "0.3.1",
"type": "module",
"main": "lib/cjs/index.cjs",
"module": "lib/index.js",
Expand Down
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sails",
"version": "0.2.0",
"version": "0.3.1",
"private": true,
"repository": "[email protected]:gear-tech/sails.git",
"author": "Gear Technologies",
Expand All @@ -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