fix(types): self-contained typings + stringToName bigint (pre-publish 4.2.0)#15
Conversation
Found by a clean consumer-install test (npm pack -> install -> use under Node/Bun/TS), pre-publish for the still-unreleased 4.2.0: - stringToName was typed `: BigInt` (the wrapper object type) but returns a `bigint` primitive at runtime; every TS consumer hit "Type 'BigInt' is not assignable to type 'bigint'". Now `bigint`. - binToJson's `buffer` param was the ambient Node `Buffer` global, so the rolled-up .d.ts failed to type-check under TS's default skipLibCheck:false without @types/node. Changed to `Uint8Array` (Buffer is a Uint8Array — callers passing Buffers are unaffected, runtime unchanged). The published types are now self-contained. - .gitignore: ignore *.tgz (pack artifacts). Verified: clean `npm i <tarball>` then Node ESM/CJS, Bun ESM/CJS, and tsc (nodenext) with both `types:[]`+skipLibCheck:false and a realistic @types/node config — all green. Native binaries unchanged.
There was a problem hiding this comment.
Pull request overview
Pre-publish type fixes for the unpublished 4.2.0-f7d5b45. Corrects stringToName return type from the BigInt wrapper to the bigint primitive (matches runtime), and changes binToJson's buffer parameter from Node's ambient Buffer to Uint8Array so the shipped .d.ts is self-contained and type-checks without @types/node. The Buffer extends Uint8Array relationship keeps the change backward-compatible for existing callers.
Changes:
- Fix
stringToNametyping:BigInt→bigintin source, built JS/CJS JSDoc, and rolled-up.d.ts/.d.cts. - Loosen
binToJsonparameter toUint8Arrayto drop the implicit@types/nodedependency from published types. - Update CHANGELOG with the fixes and add
*.tgzto.gitignoreto excludenpm packartifacts.
Reviewed changes
Copilot reviewed 2 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| lib/abieos.ts | Source: bigint return type and Uint8Array parameter, with updated JSDoc. |
| dist/abieos.ts | Built TS mirror of the source fix. |
| dist/abieos.js | ESM bundle JSDoc updated to reflect new types. |
| dist/abieos.cjs | CJS bundle JSDoc updated to reflect new types. |
| dist/_tsup-dts-rollup.d.ts | Rolled-up ESM typings: bigint return, Uint8Array param. |
| dist/_tsup-dts-rollup.d.cts | Rolled-up CJS typings: bigint return, Uint8Array param. |
| CHANGELOG.md | Documents the two type fixes under "Fixed". |
| .gitignore | Ignores *.tgz pack artifacts. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Code Review
This pull request updates the stringToName return type from the BigInt wrapper object to the bigint primitive and changes the binToJson parameter from Buffer to Uint8Array to provide self-contained typings. While these changes resolve TypeScript assignment issues, a critical feedback point notes that the native C++ implementation still strictly validates for a Buffer. This creates a runtime mismatch where passing a plain Uint8Array (as permitted by the new types) will cause the native module to throw a TypeError.
| * @throws {Error} If parsing fails or an error occurs in the native module. | ||
| */ | ||
| public binToJson(contractName: string, type: string, buffer: Buffer): any { | ||
| public binToJson(contractName: string, type: string, buffer: Uint8Array): any { |
There was a problem hiding this comment.
The TypeScript signature for binToJson has been updated to accept Uint8Array to achieve self-contained typings. However, the native implementation in src/main.cpp (line 160) still strictly validates the input using info[2].IsBuffer(). This creates a runtime type mismatch: TypeScript will allow passing a plain Uint8Array, but the native module will throw a TypeError at runtime in Node.js. To fully support Uint8Array and maintain the 'self-contained' goal, the native code should be updated to accept Napi::TypedArray or Napi::Uint8Array instead of strictly Napi::Buffer.
Addresses gemini high-priority review on PR #15: the TS signature was widened to `Uint8Array` but src/main.cpp still required `IsBuffer()`, so passing a plain Uint8Array (which the type now permits) threw a runtime TypeError — the type would lie. - main.cpp: accept Buffer OR any TypedArray; resolve bytes via the view's ArrayBuffer honouring ByteOffset (Node Buffers/Uint8Arrays are often pooled slices). Buffer fast-path unchanged. - Error message updated to "(string contractName, string type, Uint8Array|Buffer data)"; the string-input guard test updated to match (it still correctly rejects non-bytes input). - Tests: binToJson with a plain Uint8Array and with an offset view. - Rebuilt + verified locally on Windows (Node 62/62, 100% coverage, Bun: Buffer/Uint8Array/offset all round-trip). win32 prebuilt refreshed; linux-x64 + darwin universal2 will be refreshed from the CI artifacts of this branch (native changed on every platform).
The binToJson native change (81100ae) altered every platform binary, so all five prebuilts are regenerated from the green CI artifacts of run 26041585003 (Linux/Windows/macOS universal2 + Bun all passed, incl. the new plain-Uint8Array and offset-view tests; coverage 100%). Single consistent provenance: lib/+dist/ win32-x64, linux-x64, darwin-arm64, darwin-x64, and the generic abieos.node fallback. Verified locally: Node 62/62 and Bun Uint8Array round-trip against the CI win32 binary; npm pack = 16 files, no stray artifacts.
|
@gemini-code-assist Good catch — high-priority and correct. The TS signature said
Validated on CI run 26041585003 (Linux 22/24/25 + Windows MinGW + macOS universal2 + Bun, coverage 100%): the new Uint8Array/offset tests pass on every platform. The |
|
Thanks for the update and for providing the details on the CI validation and the specific fixes implemented. The changes to |
Summary
Pre-publish quality fixes for the still-unpublished
4.2.0-f7d5b45, found by a real consumer-perspective test:npm pack→npm install <tarball>into a clean project outside the repo → use the package by name under Node, Bun and TypeScript.Two genuine defects in the shipped
.d.tswere found and fixed:stringToName(): BigInt→bigint— it was typed as theBigIntwrapper/constructor type but returns abigintprimitive at runtime (the consumer test'stypeof === 'bigint'confirms). Every TypeScript consumer hitType 'BigInt' is not assignable to type 'bigint'. Config-independent bug.binToJson(buffer: Buffer)→binToJson(buffer: Uint8Array)— the public signature leaked the ambient NodeBufferglobal, so the rolled-up_tsup-dts-rollup.d.tsfailed to type-check under TypeScript's defaultskipLibCheck: falsewithout@types/node.Buffer extends Uint8Array, so every existing caller passing aBufferstill type-checks (param position;Bufferis assignable toUint8Array), and the runtime is type-erased (unchanged — the native binding still receives whatever bytes are passed). The published types are now self-contained (no@types/noderequirement).Native binaries are untouched (types-only change).
.gitignorenow ignores*.tgz(pack artifacts).Verification (clean tarball install, off-repo)
nodenext)types:[]+skipLibCheck:falseand realistic@types/nodedist/+meta, all 5 platform binaries present, exports map resolves (import→abieos.js,require→abieos.cjs,types→abieos.d.ts).tsc --noEmitclean,npm test60/60.Known gap: Deno (unverified, not a defect)
Deno is README-marketed but could not be locally verified pre-publish: Deno's npm resolution wants
npm:@eosrio/node-abieos(registry) ordeno install, and rejects npm'sfile:tarball install — this is Deno's model, not a node-abieos issue. The native-load mechanism is identical to Bun's (GetModuleHandle(NULL)host-redirect, verified working), so Deno is expected to work once published. Recommend verifying post-publish via the existingexamples/deno-abieos-testagainst the publishednpm:specifier.mastercurrently sits at the PR #14 merge, which ships these type defects. Do not tag ornpm publish4.2.0-f7d5b45until this PR merges. After merge, 4.2.0 is publish-ready.