diff --git a/package.json b/package.json index de15caf..3f51c7a 100644 --- a/package.json +++ b/package.json @@ -65,13 +65,13 @@ "mitata": "^0.1.11", "prettier": "^3.3.3", "protobufjs": "^7.3.2", - "typescript": "^5.5.4", + "typescript": "^5.7.3", "unbuild": "^3.0.0-rc.7", "vite-tsconfig-paths": "^5.0.1", "vitest": "^2.0.5" }, "peerDependencies": { - "typescript": "^5.5.4" + "typescript": "^5.7.3" }, "peerDependenciesMeta": { "typescript": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8f2684b..a68653e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -20,10 +20,10 @@ importers: version: 1.1.4 '@types/node': specifier: ^22.1.0 - version: 22.3.0 + version: 22.10.6 '@vitest/coverage-v8': specifier: ^2.0.5 - version: 2.0.5(vitest@2.0.5(@types/node@22.3.0)) + version: 2.0.5(vitest@2.0.5(@types/node@22.10.6)) automd: specifier: ^0.3.8 version: 0.3.8(magicast@0.3.4) @@ -44,7 +44,7 @@ importers: version: 9.9.0(jiti@2.0.0-beta.3) eslint-config-unjs: specifier: ^0.3.2 - version: 0.3.2(eslint@9.9.0(jiti@2.0.0-beta.3))(typescript@5.5.4) + version: 0.3.2(eslint@9.9.0(jiti@2.0.0-beta.3))(typescript@5.7.3) jiti: specifier: ^2.0.0-beta.3 version: 2.0.0-beta.3 @@ -58,17 +58,17 @@ importers: specifier: ^7.3.2 version: 7.3.2 typescript: - specifier: ^5.5.4 - version: 5.5.4 + specifier: ^5.7.3 + version: 5.7.3 unbuild: specifier: ^3.0.0-rc.7 - version: 3.0.0-rc.7(typescript@5.5.4) + version: 3.0.0-rc.7(typescript@5.7.3) vite-tsconfig-paths: specifier: ^5.0.1 - version: 5.0.1(typescript@5.5.4)(vite@5.4.1(@types/node@22.3.0)) + version: 5.0.1(typescript@5.7.3)(vite@5.4.1(@types/node@22.10.6)) vitest: specifier: ^2.0.5 - version: 2.0.5(@types/node@22.3.0) + version: 2.0.5(@types/node@22.10.6) packages: @@ -776,8 +776,8 @@ packages: '@types/mdast@3.0.15': resolution: {integrity: sha512-LnwD+mUEfxWMa1QpDraczIn6k0Ee3SMicuYSSzS6ZYl2gKS09EClnJYGd8Du6rfc5r/GZEk5o1mRb8TaTj03sQ==} - '@types/node@22.3.0': - resolution: {integrity: sha512-nrWpWVaDZuaVc5X84xJ0vNrLvomM205oQyLsRt7OHNZbSHslcWsvgFR7O7hire2ZonjLrWBbedmotmIlJDVd6g==} + '@types/node@22.10.6': + resolution: {integrity: sha512-qNiuwC4ZDAUNcY47xgaSuS92cjf8JbSUoaKS77bmLG1rU7MlATVSiw/IlrjtIyyskXBZ8KkNfjK/P5na7rgXbQ==} '@types/normalize-package-data@2.4.4': resolution: {integrity: sha512-37i+OaWTh9qeK4LSHPsyRC7NahnGotNuZvjLSgcPzblpHB3rrCJxAOgI5gCdKm7coonsaX1Of0ILiTcnZjbfxA==} @@ -2431,8 +2431,8 @@ packages: typescript: optional: true - typescript@5.5.4: - resolution: {integrity: sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==} + typescript@5.7.3: + resolution: {integrity: sha512-84MVSjMEHP+FQRPy3pX9sTVV/INIex71s9TL2Gm5FG/WG1SqXeKyZ0k7/blY/4FdOzI12CBy1vGc4og/eus0fw==} engines: {node: '>=14.17'} hasBin: true @@ -2448,8 +2448,8 @@ packages: typescript: optional: true - undici-types@6.18.2: - resolution: {integrity: sha512-5ruQbENj95yDYJNS3TvcaxPMshV7aizdv/hWYjGIKoANWKjhWNBsr2YEuYZKodQulB1b8l7ILOuDQep3afowQQ==} + undici-types@6.20.0: + resolution: {integrity: sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==} unicorn-magic@0.1.0: resolution: {integrity: sha512-lRfVq8fE8gz6QMBuDM6a+LO3IAzTi05H6gCVaUpir2E1Rwpo4ZUog45KpNXKC/Mn3Yb9UDuHumeFTo9iV/D9FQ==} @@ -3125,9 +3125,9 @@ snapshots: dependencies: '@types/unist': 2.0.11 - '@types/node@22.3.0': + '@types/node@22.10.6': dependencies: - undici-types: 6.18.2 + undici-types: 6.20.0 '@types/normalize-package-data@2.4.4': {} @@ -3135,34 +3135,34 @@ snapshots: '@types/unist@2.0.11': {} - '@typescript-eslint/eslint-plugin@7.18.0(@typescript-eslint/parser@7.18.0(eslint@9.9.0(jiti@2.0.0-beta.3))(typescript@5.5.4))(eslint@9.9.0(jiti@2.0.0-beta.3))(typescript@5.5.4)': + '@typescript-eslint/eslint-plugin@7.18.0(@typescript-eslint/parser@7.18.0(eslint@9.9.0(jiti@2.0.0-beta.3))(typescript@5.7.3))(eslint@9.9.0(jiti@2.0.0-beta.3))(typescript@5.7.3)': dependencies: '@eslint-community/regexpp': 4.11.0 - '@typescript-eslint/parser': 7.18.0(eslint@9.9.0(jiti@2.0.0-beta.3))(typescript@5.5.4) + '@typescript-eslint/parser': 7.18.0(eslint@9.9.0(jiti@2.0.0-beta.3))(typescript@5.7.3) '@typescript-eslint/scope-manager': 7.18.0 - '@typescript-eslint/type-utils': 7.18.0(eslint@9.9.0(jiti@2.0.0-beta.3))(typescript@5.5.4) - '@typescript-eslint/utils': 7.18.0(eslint@9.9.0(jiti@2.0.0-beta.3))(typescript@5.5.4) + '@typescript-eslint/type-utils': 7.18.0(eslint@9.9.0(jiti@2.0.0-beta.3))(typescript@5.7.3) + '@typescript-eslint/utils': 7.18.0(eslint@9.9.0(jiti@2.0.0-beta.3))(typescript@5.7.3) '@typescript-eslint/visitor-keys': 7.18.0 eslint: 9.9.0(jiti@2.0.0-beta.3) graphemer: 1.4.0 ignore: 5.3.2 natural-compare: 1.4.0 - ts-api-utils: 1.3.0(typescript@5.5.4) + ts-api-utils: 1.3.0(typescript@5.7.3) optionalDependencies: - typescript: 5.5.4 + typescript: 5.7.3 transitivePeerDependencies: - supports-color - '@typescript-eslint/parser@7.18.0(eslint@9.9.0(jiti@2.0.0-beta.3))(typescript@5.5.4)': + '@typescript-eslint/parser@7.18.0(eslint@9.9.0(jiti@2.0.0-beta.3))(typescript@5.7.3)': dependencies: '@typescript-eslint/scope-manager': 7.18.0 '@typescript-eslint/types': 7.18.0 - '@typescript-eslint/typescript-estree': 7.18.0(typescript@5.5.4) + '@typescript-eslint/typescript-estree': 7.18.0(typescript@5.7.3) '@typescript-eslint/visitor-keys': 7.18.0 debug: 4.3.6 eslint: 9.9.0(jiti@2.0.0-beta.3) optionalDependencies: - typescript: 5.5.4 + typescript: 5.7.3 transitivePeerDependencies: - supports-color @@ -3171,21 +3171,21 @@ snapshots: '@typescript-eslint/types': 7.18.0 '@typescript-eslint/visitor-keys': 7.18.0 - '@typescript-eslint/type-utils@7.18.0(eslint@9.9.0(jiti@2.0.0-beta.3))(typescript@5.5.4)': + '@typescript-eslint/type-utils@7.18.0(eslint@9.9.0(jiti@2.0.0-beta.3))(typescript@5.7.3)': dependencies: - '@typescript-eslint/typescript-estree': 7.18.0(typescript@5.5.4) - '@typescript-eslint/utils': 7.18.0(eslint@9.9.0(jiti@2.0.0-beta.3))(typescript@5.5.4) + '@typescript-eslint/typescript-estree': 7.18.0(typescript@5.7.3) + '@typescript-eslint/utils': 7.18.0(eslint@9.9.0(jiti@2.0.0-beta.3))(typescript@5.7.3) debug: 4.3.6 eslint: 9.9.0(jiti@2.0.0-beta.3) - ts-api-utils: 1.3.0(typescript@5.5.4) + ts-api-utils: 1.3.0(typescript@5.7.3) optionalDependencies: - typescript: 5.5.4 + typescript: 5.7.3 transitivePeerDependencies: - supports-color '@typescript-eslint/types@7.18.0': {} - '@typescript-eslint/typescript-estree@7.18.0(typescript@5.5.4)': + '@typescript-eslint/typescript-estree@7.18.0(typescript@5.7.3)': dependencies: '@typescript-eslint/types': 7.18.0 '@typescript-eslint/visitor-keys': 7.18.0 @@ -3194,18 +3194,18 @@ snapshots: is-glob: 4.0.3 minimatch: 9.0.5 semver: 7.6.3 - ts-api-utils: 1.3.0(typescript@5.5.4) + ts-api-utils: 1.3.0(typescript@5.7.3) optionalDependencies: - typescript: 5.5.4 + typescript: 5.7.3 transitivePeerDependencies: - supports-color - '@typescript-eslint/utils@7.18.0(eslint@9.9.0(jiti@2.0.0-beta.3))(typescript@5.5.4)': + '@typescript-eslint/utils@7.18.0(eslint@9.9.0(jiti@2.0.0-beta.3))(typescript@5.7.3)': dependencies: '@eslint-community/eslint-utils': 4.4.0(eslint@9.9.0(jiti@2.0.0-beta.3)) '@typescript-eslint/scope-manager': 7.18.0 '@typescript-eslint/types': 7.18.0 - '@typescript-eslint/typescript-estree': 7.18.0(typescript@5.5.4) + '@typescript-eslint/typescript-estree': 7.18.0(typescript@5.7.3) eslint: 9.9.0(jiti@2.0.0-beta.3) transitivePeerDependencies: - supports-color @@ -3216,7 +3216,7 @@ snapshots: '@typescript-eslint/types': 7.18.0 eslint-visitor-keys: 3.4.3 - '@vitest/coverage-v8@2.0.5(vitest@2.0.5(@types/node@22.3.0))': + '@vitest/coverage-v8@2.0.5(vitest@2.0.5(@types/node@22.10.6))': dependencies: '@ampproject/remapping': 2.3.0 '@bcoe/v8-coverage': 0.2.3 @@ -3230,7 +3230,7 @@ snapshots: std-env: 3.7.0 test-exclude: 7.0.1 tinyrainbow: 1.2.0 - vitest: 2.0.5(@types/node@22.3.0) + vitest: 2.0.5(@types/node@22.10.6) transitivePeerDependencies: - supports-color @@ -3753,15 +3753,15 @@ snapshots: escape-string-regexp@4.0.0: {} - eslint-config-unjs@0.3.2(eslint@9.9.0(jiti@2.0.0-beta.3))(typescript@5.5.4): + eslint-config-unjs@0.3.2(eslint@9.9.0(jiti@2.0.0-beta.3))(typescript@5.7.3): dependencies: '@eslint/js': 9.9.0 eslint: 9.9.0(jiti@2.0.0-beta.3) eslint-plugin-markdown: 5.1.0(eslint@9.9.0(jiti@2.0.0-beta.3)) eslint-plugin-unicorn: 53.0.0(eslint@9.9.0(jiti@2.0.0-beta.3)) globals: 15.9.0 - typescript: 5.5.4 - typescript-eslint: 7.18.0(eslint@9.9.0(jiti@2.0.0-beta.3))(typescript@5.5.4) + typescript: 5.7.3 + typescript-eslint: 7.18.0(eslint@9.9.0(jiti@2.0.0-beta.3))(typescript@5.7.3) transitivePeerDependencies: - supports-color @@ -4302,7 +4302,7 @@ snapshots: mkdirp@1.0.4: {} - mkdist@1.5.4(typescript@5.5.4): + mkdist@1.5.4(typescript@5.7.3): dependencies: autoprefixer: 10.4.20(postcss@8.4.41) citty: 0.1.6 @@ -4318,7 +4318,7 @@ snapshots: postcss-nested: 6.2.0(postcss@8.4.41) semver: 7.6.3 optionalDependencies: - typescript: 5.5.4 + typescript: 5.7.3 mlly@1.7.1: dependencies: @@ -4667,7 +4667,7 @@ snapshots: '@protobufjs/path': 1.1.2 '@protobufjs/pool': 1.1.0 '@protobufjs/utf8': 1.1.0 - '@types/node': 22.3.0 + '@types/node': 22.10.6 long: 5.2.3 punycode@2.3.1: {} @@ -4714,11 +4714,11 @@ snapshots: reusify@1.0.4: {} - rollup-plugin-dts@6.1.1(rollup@4.20.0)(typescript@5.5.4): + rollup-plugin-dts@6.1.1(rollup@4.20.0)(typescript@5.7.3): dependencies: magic-string: 0.30.11 rollup: 4.20.0 - typescript: 5.5.4 + typescript: 5.7.3 optionalDependencies: '@babel/code-frame': 7.24.7 @@ -4887,13 +4887,13 @@ snapshots: dependencies: is-number: 7.0.0 - ts-api-utils@1.3.0(typescript@5.5.4): + ts-api-utils@1.3.0(typescript@5.7.3): dependencies: - typescript: 5.5.4 + typescript: 5.7.3 - tsconfck@3.1.1(typescript@5.5.4): + tsconfck@3.1.1(typescript@5.7.3): optionalDependencies: - typescript: 5.5.4 + typescript: 5.7.3 tslib@2.6.3: {} @@ -4905,22 +4905,22 @@ snapshots: type-fest@0.8.1: {} - typescript-eslint@7.18.0(eslint@9.9.0(jiti@2.0.0-beta.3))(typescript@5.5.4): + typescript-eslint@7.18.0(eslint@9.9.0(jiti@2.0.0-beta.3))(typescript@5.7.3): dependencies: - '@typescript-eslint/eslint-plugin': 7.18.0(@typescript-eslint/parser@7.18.0(eslint@9.9.0(jiti@2.0.0-beta.3))(typescript@5.5.4))(eslint@9.9.0(jiti@2.0.0-beta.3))(typescript@5.5.4) - '@typescript-eslint/parser': 7.18.0(eslint@9.9.0(jiti@2.0.0-beta.3))(typescript@5.5.4) - '@typescript-eslint/utils': 7.18.0(eslint@9.9.0(jiti@2.0.0-beta.3))(typescript@5.5.4) + '@typescript-eslint/eslint-plugin': 7.18.0(@typescript-eslint/parser@7.18.0(eslint@9.9.0(jiti@2.0.0-beta.3))(typescript@5.7.3))(eslint@9.9.0(jiti@2.0.0-beta.3))(typescript@5.7.3) + '@typescript-eslint/parser': 7.18.0(eslint@9.9.0(jiti@2.0.0-beta.3))(typescript@5.7.3) + '@typescript-eslint/utils': 7.18.0(eslint@9.9.0(jiti@2.0.0-beta.3))(typescript@5.7.3) eslint: 9.9.0(jiti@2.0.0-beta.3) optionalDependencies: - typescript: 5.5.4 + typescript: 5.7.3 transitivePeerDependencies: - supports-color - typescript@5.5.4: {} + typescript@5.7.3: {} ufo@1.5.4: {} - unbuild@3.0.0-rc.7(typescript@5.5.4): + unbuild@3.0.0-rc.7(typescript@5.7.3): dependencies: '@rollup/plugin-alias': 5.1.0(rollup@4.20.0) '@rollup/plugin-commonjs': 26.0.1(rollup@4.20.0) @@ -4936,24 +4936,24 @@ snapshots: hookable: 5.5.3 jiti: 2.0.0-beta.3 magic-string: 0.30.11 - mkdist: 1.5.4(typescript@5.5.4) + mkdist: 1.5.4(typescript@5.7.3) mlly: 1.7.1 pathe: 1.1.2 pkg-types: 1.1.3 pretty-bytes: 6.1.1 rollup: 4.20.0 - rollup-plugin-dts: 6.1.1(rollup@4.20.0)(typescript@5.5.4) + rollup-plugin-dts: 6.1.1(rollup@4.20.0)(typescript@5.7.3) scule: 1.3.0 ufo: 1.5.4 untyped: 1.4.2 optionalDependencies: - typescript: 5.5.4 + typescript: 5.7.3 transitivePeerDependencies: - sass - supports-color - vue-tsc - undici-types@6.18.2: {} + undici-types@6.20.0: {} unicorn-magic@0.1.0: {} @@ -4992,13 +4992,13 @@ snapshots: spdx-correct: 3.2.0 spdx-expression-parse: 3.0.1 - vite-node@2.0.5(@types/node@22.3.0): + vite-node@2.0.5(@types/node@22.10.6): dependencies: cac: 6.7.14 debug: 4.3.6 pathe: 1.1.2 tinyrainbow: 1.2.0 - vite: 5.4.1(@types/node@22.3.0) + vite: 5.4.1(@types/node@22.10.6) transitivePeerDependencies: - '@types/node' - less @@ -5010,27 +5010,27 @@ snapshots: - supports-color - terser - vite-tsconfig-paths@5.0.1(typescript@5.5.4)(vite@5.4.1(@types/node@22.3.0)): + vite-tsconfig-paths@5.0.1(typescript@5.7.3)(vite@5.4.1(@types/node@22.10.6)): dependencies: debug: 4.3.6 globrex: 0.1.2 - tsconfck: 3.1.1(typescript@5.5.4) + tsconfck: 3.1.1(typescript@5.7.3) optionalDependencies: - vite: 5.4.1(@types/node@22.3.0) + vite: 5.4.1(@types/node@22.10.6) transitivePeerDependencies: - supports-color - typescript - vite@5.4.1(@types/node@22.3.0): + vite@5.4.1(@types/node@22.10.6): dependencies: esbuild: 0.21.5 postcss: 8.4.41 rollup: 4.20.0 optionalDependencies: - '@types/node': 22.3.0 + '@types/node': 22.10.6 fsevents: 2.3.3 - vitest@2.0.5(@types/node@22.3.0): + vitest@2.0.5(@types/node@22.10.6): dependencies: '@ampproject/remapping': 2.3.0 '@vitest/expect': 2.0.5 @@ -5048,11 +5048,11 @@ snapshots: tinybench: 2.9.0 tinypool: 1.0.0 tinyrainbow: 1.2.0 - vite: 5.4.1(@types/node@22.3.0) - vite-node: 2.0.5(@types/node@22.3.0) + vite: 5.4.1(@types/node@22.10.6) + vite-node: 2.0.5(@types/node@22.10.6) why-is-node-running: 2.3.0 optionalDependencies: - '@types/node': 22.3.0 + '@types/node': 22.10.6 transitivePeerDependencies: - less - lightningcss diff --git a/src/compiler/generators.ts b/src/compiler/generators.ts index da9d244..dc04195 100644 --- a/src/compiler/generators.ts +++ b/src/compiler/generators.ts @@ -708,7 +708,8 @@ export function generateStructFieldMethods( const d = f.createGetAccessorDeclaration( [], - name, + // Avoid generating invalid "get constructor()" + name === "constructor" ? `$${name}` : name, [], jsTypeReference, createExpressionBlock(expressions, true), @@ -840,7 +841,7 @@ export function generateStructFieldMethods( members.push( f.createSetAccessorDeclaration( [], - name, + name === "constructor" ? `$${name}` : name, parameters, createExpressionBlock(expressions, false), ), diff --git a/src/serialization/index.ts b/src/serialization/index.ts index 1b4e249..82a140c 100644 --- a/src/serialization/index.ts +++ b/src/serialization/index.ts @@ -23,6 +23,7 @@ export { export { type ListCtor, type StructCtor, + type _Pointer, AnyPointerList, BoolList, CompositeList, diff --git a/src/serialization/message.ts b/src/serialization/message.ts index 028c7af..4f51633 100644 --- a/src/serialization/message.ts +++ b/src/serialization/message.ts @@ -216,7 +216,10 @@ export function initMessage( let buf = src; if (isArrayBufferView(buf)) { - buf = buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength); + buf = buf.buffer.slice( + buf.byteOffset, + buf.byteOffset + buf.byteLength, + ) as ArrayBuffer; } if (packed) buf = unpack(buf); diff --git a/src/serialization/pointers/index.ts b/src/serialization/pointers/index.ts index 0dc24a9..a90b34a 100644 --- a/src/serialization/pointers/index.ts +++ b/src/serialization/pointers/index.ts @@ -5,7 +5,7 @@ export { Interface } from "./interface"; export { Orphan } from "./orphan"; export { Text } from "./text"; export { Void, VOID } from "./void"; -export { Pointer, PointerType } from "./pointer"; +export { Pointer, PointerType, type _Pointer } from "./pointer"; export { type _StructCtor, Struct, type StructCtor } from "./struct"; // Utils diff --git a/src/serialization/pointers/list/list.ts b/src/serialization/pointers/list/list.ts index 217b9e8..288d5fb 100644 --- a/src/serialization/pointers/list/list.ts +++ b/src/serialization/pointers/list/list.ts @@ -263,37 +263,39 @@ export class List extends Pointer implements Array { return this; } - keys(): IterableIterator { + keys(): ArrayIterator { const length = this.length; return Array.from({ length }, (_, i) => i)[Symbol.iterator](); } - values(): IterableIterator { - const length = this.length; - let i = 0; - return { - [Symbol.iterator]: () => this.values(), - next: () => { - if (i < length) { - return { value: this.at(i++), done: false }; - } - return { value: undefined, done: true }; - }, - }; - } - - entries(): IterableIterator<[number, T]> { - const length = this.length; - let i = 0; - return { - [Symbol.iterator]: () => this.entries(), - next: () => { - if (i < length) { - return { value: [i, this.at(i++)], done: false }; - } - return { value: undefined, done: true }; - }, - }; + values(): ArrayIterator { + return this.toArray().values(); + // const length = this.length; + // let i = 0; + // return { + // [Symbol.iterator]: () => this.values(), + // next: () => { + // if (i < length) { + // return { value: this.at(i++), done: false }; + // } + // return { value: undefined, done: true }; + // }, + // }; + } + + entries(): ArrayIterator<[number, T]> { + return this.toArray().entries(); + // const length = this.length; + // let i = 0; + // return { + // [Symbol.iterator]: () => this.entries(), + // next: () => { + // if (i < length) { + // return { value: [i, this.at(i++)], done: false }; + // } + // return { value: undefined, done: true }; + // }, + // }; } flat(this: A, depth?: D): FlatArray[] { @@ -356,7 +358,7 @@ export class List extends Pointer implements Array { return Array.prototype[Symbol.unscopables]; } - [Symbol.iterator](): IterableIterator { + [Symbol.iterator](): ArrayIterator { return this.values(); } diff --git a/test/compiler/utils.ts b/test/compiler/utils.ts index 1cba9a9..2603bdb 100644 --- a/test/compiler/utils.ts +++ b/test/compiler/utils.ts @@ -4,5 +4,8 @@ import * as path from "node:path"; export function readFileBuffer(filePath: string): ArrayBuffer { const b = readFileSync(path.join(__dirname, "../../", filePath)); - return b.buffer.slice(b.byteOffset, b.byteOffset + b.byteLength); + return b.buffer.slice( + b.byteOffset, + b.byteOffset + b.byteLength, + ) as ArrayBuffer; } diff --git a/test/fixtures/test-import.ts b/test/fixtures/test-import.ts index d81c328..98813ef 100644 --- a/test/fixtures/test-import.ts +++ b/test/fixtures/test-import.ts @@ -1,6 +1,6 @@ // This file has been automatically generated by capnp-es. import * as $ from "capnp-es"; -import { TestEnum, TestAllTypes, TestDefaults, TestAnyPointer, TestAnyOthers, TestOutOfOrder, TestUnion, TestUnnamedUnion, TestUnionInUnion, TestGroups, TestInterleavedGroups, TestUnionDefaults, TestNestedTypes, TestNestedTypes_NestedEnum, TestNestedTypes_NestedStruct, TestNestedTypes_NestedStruct_NestedEnum, TestUsing, TestLists, TestLists_Struct0, TestLists_Struct1, TestLists_Struct8, TestLists_Struct16, TestLists_Struct32, TestLists_Struct64, TestLists_StructP, TestLists_Struct0c, TestLists_Struct1c, TestLists_Struct8c, TestLists_Struct16c, TestLists_Struct32c, TestLists_Struct64c, TestLists_StructPc, TestFieldZeroIsBit, TestListDefaults, TestLateUnion, TestOldVersion, TestNewVersion, TestOldUnionVersion, TestNewUnionVersion, TestStructUnion, TestStructUnion_SomeStruct, TestPrintInlineStructs, TestPrintInlineStructs_InlineStruct, TestWholeFloatDefault, TestGenerics, TestGenerics_Inner, TestGenerics_Inner2, TestGenerics_Inner2_DeepNest, TestGenerics_UseAliases, TestGenericsWrapper, TestGenericsWrapper2, TestGenericsUnion, TestUseGenerics, TestEmptyStruct, TestConstants, TestAnyPointerConstants, TestPipeline_Box, TestPipeline_AnyBox, TestTailCallee_TailResult, TestMembrane_Result, TestContainMembrane, TestTransferCap, TestTransferCap_Element, TestSturdyRef, TestSturdyRefHostId, TestSturdyRefObjectId, TestSturdyRefObjectId_Tag, TestProvisionId, TestRecipientId, TestThirdPartyCapId, TestJoinResult, TestNameAnnotation, TestNameAnnotation_BadlyNamedEnum, TestNameAnnotation_NestedStruct, TestNameAnnotation_NestedStruct_DeeplyNestedEnum } from "./test.js"; +import { TestEnum, TestAllTypes, TestDefaults, TestAnyPointer, TestAnyOthers, TestOutOfOrder, TestUnion, TestUnnamedUnion, TestUnionInUnion, TestGroups, TestInterleavedGroups, TestUnionDefaults, TestNestedTypes, TestNestedTypes_NestedEnum, TestNestedTypes_NestedStruct, TestNestedTypes_NestedStruct_NestedEnum, TestUsing, TestLists, TestLists_Struct0, TestLists_Struct1, TestLists_Struct8, TestLists_Struct16, TestLists_Struct32, TestLists_Struct64, TestLists_StructP, TestLists_Struct0c, TestLists_Struct1c, TestLists_Struct8c, TestLists_Struct16c, TestLists_Struct32c, TestLists_Struct64c, TestLists_StructPc, TestFieldZeroIsBit, TestListDefaults, TestLateUnion, TestOldVersion, TestNewVersion, TestOldUnionVersion, TestNewUnionVersion, TestStructUnion, TestStructUnion_SomeStruct, TestPrintInlineStructs, TestPrintInlineStructs_InlineStruct, TestWholeFloatDefault, TestGenerics, TestGenerics_Inner, TestGenerics_Inner2, TestGenerics_Inner2_DeepNest, TestGenerics_UseAliases, TestGenericsWrapper, TestGenericsWrapper2, TestGenericsUnion, TestUseGenerics, TestEmptyStruct, TestConstants, TestAnyPointerConstants, TestPipeline_Box, TestPipeline_AnyBox, TestTailCallee_TailResult, TestMembrane_Result, TestContainMembrane, TestContructorName, TestTransferCap, TestTransferCap_Element, TestSturdyRef, TestSturdyRefHostId, TestSturdyRefObjectId, TestSturdyRefObjectId_Tag, TestProvisionId, TestRecipientId, TestThirdPartyCapId, TestJoinResult, TestNameAnnotation, TestNameAnnotation_BadlyNamedEnum, TestNameAnnotation_NestedStruct, TestNameAnnotation_NestedStruct_DeeplyNestedEnum } from "./test.js"; export const _capnpFileId = BigInt("0xf36d7b330303c66e"); export class TestImport extends $.Struct { static readonly _capnp = { diff --git a/test/fixtures/test-import2.ts b/test/fixtures/test-import2.ts index e68069e..4d68fcc 100644 --- a/test/fixtures/test-import2.ts +++ b/test/fixtures/test-import2.ts @@ -2,7 +2,7 @@ import * as $ from "capnp-es"; import { Node, Node_Parameter, Node_NestedNode, Field, Enumerant, Superclass, Method, Type, Brand, Brand_Scope, Brand_Binding, Value, Annotation, ElementSize } from "capnp-es/capnp/schema"; import { TestImport } from "./test-import.js"; -import { TestEnum, TestAllTypes, TestDefaults, TestAnyPointer, TestAnyOthers, TestOutOfOrder, TestUnion, TestUnnamedUnion, TestUnionInUnion, TestGroups, TestInterleavedGroups, TestUnionDefaults, TestNestedTypes, TestNestedTypes_NestedEnum, TestNestedTypes_NestedStruct, TestNestedTypes_NestedStruct_NestedEnum, TestUsing, TestLists, TestLists_Struct0, TestLists_Struct1, TestLists_Struct8, TestLists_Struct16, TestLists_Struct32, TestLists_Struct64, TestLists_StructP, TestLists_Struct0c, TestLists_Struct1c, TestLists_Struct8c, TestLists_Struct16c, TestLists_Struct32c, TestLists_Struct64c, TestLists_StructPc, TestFieldZeroIsBit, TestListDefaults, TestLateUnion, TestOldVersion, TestNewVersion, TestOldUnionVersion, TestNewUnionVersion, TestStructUnion, TestStructUnion_SomeStruct, TestPrintInlineStructs, TestPrintInlineStructs_InlineStruct, TestWholeFloatDefault, TestGenerics, TestGenerics_Inner, TestGenerics_Inner2, TestGenerics_Inner2_DeepNest, TestGenerics_UseAliases, TestGenericsWrapper, TestGenericsWrapper2, TestGenericsUnion, TestUseGenerics, TestEmptyStruct, TestConstants, TestAnyPointerConstants, TestPipeline_Box, TestPipeline_AnyBox, TestTailCallee_TailResult, TestMembrane_Result, TestContainMembrane, TestTransferCap, TestTransferCap_Element, TestSturdyRef, TestSturdyRefHostId, TestSturdyRefObjectId, TestSturdyRefObjectId_Tag, TestProvisionId, TestRecipientId, TestThirdPartyCapId, TestJoinResult, TestNameAnnotation, TestNameAnnotation_BadlyNamedEnum, TestNameAnnotation_NestedStruct, TestNameAnnotation_NestedStruct_DeeplyNestedEnum } from "./test.js"; +import { TestEnum, TestAllTypes, TestDefaults, TestAnyPointer, TestAnyOthers, TestOutOfOrder, TestUnion, TestUnnamedUnion, TestUnionInUnion, TestGroups, TestInterleavedGroups, TestUnionDefaults, TestNestedTypes, TestNestedTypes_NestedEnum, TestNestedTypes_NestedStruct, TestNestedTypes_NestedStruct_NestedEnum, TestUsing, TestLists, TestLists_Struct0, TestLists_Struct1, TestLists_Struct8, TestLists_Struct16, TestLists_Struct32, TestLists_Struct64, TestLists_StructP, TestLists_Struct0c, TestLists_Struct1c, TestLists_Struct8c, TestLists_Struct16c, TestLists_Struct32c, TestLists_Struct64c, TestLists_StructPc, TestFieldZeroIsBit, TestListDefaults, TestLateUnion, TestOldVersion, TestNewVersion, TestOldUnionVersion, TestNewUnionVersion, TestStructUnion, TestStructUnion_SomeStruct, TestPrintInlineStructs, TestPrintInlineStructs_InlineStruct, TestWholeFloatDefault, TestGenerics, TestGenerics_Inner, TestGenerics_Inner2, TestGenerics_Inner2_DeepNest, TestGenerics_UseAliases, TestGenericsWrapper, TestGenericsWrapper2, TestGenericsUnion, TestUseGenerics, TestEmptyStruct, TestConstants, TestAnyPointerConstants, TestPipeline_Box, TestPipeline_AnyBox, TestTailCallee_TailResult, TestMembrane_Result, TestContainMembrane, TestContructorName, TestTransferCap, TestTransferCap_Element, TestSturdyRef, TestSturdyRefHostId, TestSturdyRefObjectId, TestSturdyRefObjectId_Tag, TestProvisionId, TestRecipientId, TestThirdPartyCapId, TestJoinResult, TestNameAnnotation, TestNameAnnotation_BadlyNamedEnum, TestNameAnnotation_NestedStruct, TestNameAnnotation_NestedStruct_DeeplyNestedEnum } from "./test.js"; export const _capnpFileId = BigInt("0xc64a3bf0338a124a"); export class TestImport2 extends $.Struct { static readonly _capnp = { diff --git a/test/fixtures/test.capnp b/test/fixtures/test.capnp index f0fc8bb..9be274c 100644 --- a/test/fixtures/test.capnp +++ b/test/fixtures/test.capnp @@ -878,6 +878,10 @@ struct TestContainMembrane { list @1 :List(TestMembrane.Thing); } +struct TestContructorName { + constructor @0 :Text; +} + struct TestTransferCap { list @0 :List(Element); struct Element { diff --git a/test/fixtures/test.ts b/test/fixtures/test.ts index ce352eb..4c5ba93 100644 --- a/test/fixtures/test.ts +++ b/test/fixtures/test.ts @@ -7406,6 +7406,22 @@ export class TestContainMembrane extends $.Struct { return "TestContainMembrane_" + super.toString(); } } +export class TestContructorName extends $.Struct { + static readonly _capnp = { + displayName: "TestContructorName", + id: "c16f644772532755", + size: new $.ObjectSize(0, 1) + }; + get $constructor(): string { + return $.utils.getText(0, this); + } + set $constructor(value: string) { + $.utils.setText(0, value, this); + } + toString(): string { + return "TestContructorName_" + super.toString(); + } +} export class TestTransferCap_Element extends $.Struct { static readonly _capnp = { displayName: "Element", diff --git a/test/integration/rpc.spec.ts b/test/integration/rpc.spec.ts index 1dbc9aa..152637a 100644 --- a/test/integration/rpc.spec.ts +++ b/test/integration/rpc.spec.ts @@ -86,6 +86,7 @@ describe("rpc", () => { const [, result] = await Promise.all([server(), client()]); t.equal( + // @ts-expect-error bufferToHex(result), "[2a ae 6c 35 c9 4f cf b4 15 db e9 5f 40 8b 9c e9 1e e8 46 ed]", ); diff --git a/test/integration/test.spec.ts b/test/integration/test.spec.ts index 97c8ebc..7ecd52d 100644 --- a/test/integration/test.spec.ts +++ b/test/integration/test.spec.ts @@ -102,3 +102,13 @@ test("TestAllTypes", () => { allTypes._initEnumList(2).set(1, T.TestEnum.FOO); t.equal(allTypes.enumList.get(1), T.TestEnum.FOO); }); + +test("TestConstructorName", () => { + const m = new capnp.Message(); + const cls = m.initRoot(T.TestContructorName); + + t.equal(cls.$constructor, ""); + cls.$constructor = "hello"; + t.equal(cls.$constructor, "hello"); + t.doesNotThrow(() => m.toArrayBuffer()); +}); diff --git a/test/runtime/mask.spec.ts b/test/runtime/mask.spec.ts index 341ca8a..501ab23 100644 --- a/test/runtime/mask.spec.ts +++ b/test/runtime/mask.spec.ts @@ -163,7 +163,10 @@ function makeMaskTest( ) { test(name, () => { for (const { mask, val } of testData) { - compareBuffers(fn(val).buffer, new Uint8Array(mask).buffer); + compareBuffers( + fn(val).buffer as ArrayBuffer, + new Uint8Array(mask).buffer, + ); } }); } @@ -171,7 +174,7 @@ function makeMaskTest( test("getBitMask()", () => { for (const { bitOffset, mask, val } of BIT_MASKS) { compareBuffers( - getBitMask(val, bitOffset).buffer, + getBitMask(val, bitOffset).buffer as ArrayBuffer, new Uint8Array(mask).buffer, ); } diff --git a/test/utils.ts b/test/utils.ts index 2ee1ba0..9c1af2d 100644 --- a/test/utils.ts +++ b/test/utils.ts @@ -86,5 +86,8 @@ export function logBench(suite: Suite): Suite { export function readFileBuffer(filePath: string): ArrayBuffer { const b = readFileSync(path.join(__dirname, "../", filePath)); - return b.buffer.slice(b.byteOffset, b.byteOffset + b.byteLength); + return b.buffer.slice( + b.byteOffset, + b.byteOffset + b.byteLength, + ) as ArrayBuffer; }