Skip to content

fix(types): self-contained typings + stringToName bigint (pre-publish 4.2.0)#15

Merged
igorls merged 3 commits into
masterfrom
fix/consumer-types
May 18, 2026
Merged

fix(types): self-contained typings + stringToName bigint (pre-publish 4.2.0)#15
igorls merged 3 commits into
masterfrom
fix/consumer-types

Conversation

@igorls

@igorls igorls commented May 18, 2026

Copy link
Copy Markdown
Member

Summary

Pre-publish quality fixes for the still-unpublished 4.2.0-f7d5b45, found by a real consumer-perspective test: npm packnpm 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.ts were found and fixed:

  1. stringToName(): BigIntbigint — it was typed as the BigInt wrapper/constructor type but returns a bigint primitive at runtime (the consumer test's typeof === 'bigint' confirms). Every TypeScript consumer hit Type 'BigInt' is not assignable to type 'bigint'. Config-independent bug.

  2. binToJson(buffer: Buffer)binToJson(buffer: Uint8Array) — the public signature leaked the ambient Node Buffer global, so the rolled-up _tsup-dts-rollup.d.ts failed to type-check under TypeScript's default skipLibCheck: false without @types/node. ⚠️ This is a public-API signature change, but intentionally backward-compatible: Buffer extends Uint8Array, so every existing caller passing a Buffer still type-checks (param position; Buffer is assignable to Uint8Array), 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/node requirement).

Native binaries are untouched (types-only change). .gitignore now ignores *.tgz (pack artifacts).

Verification (clean tarball install, off-repo)

Runtime ESM CJS Result
Node 24.15 (win32-x64) round-trip + errors + singleton
Bun 1.3.14 (win32-x64) delay-load host-redirect holds
TypeScript 6 (nodenext) types:[]+skipLibCheck:false and realistic @types/node
  • Zero-build install (621 ms), only dist/+meta, all 5 platform binaries present, exports map resolves (importabieos.js, requireabieos.cjs, typesabieos.d.ts).
  • Repo: tsc --noEmit clean, npm test 60/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) or deno install, and rejects npm's file: 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 existing examples/deno-abieos-test against the published npm: specifier.

⚠️ Publish gate

master currently sits at the PR #14 merge, which ships these type defects. Do not tag or npm publish 4.2.0-f7d5b45 until this PR merges. After merge, 4.2.0 is publish-ready.

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.
Copilot AI review requested due to automatic review settings May 18, 2026 01:55

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 stringToName typing: BigIntbigint in source, built JS/CJS JSDoc, and rolled-up .d.ts/.d.cts.
  • Loosen binToJson parameter to Uint8Array to drop the implicit @types/node dependency from published types.
  • Update CHANGELOG with the fixes and add *.tgz to .gitignore to exclude npm pack artifacts.

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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread lib/abieos.ts
* @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 {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

igorls added 2 commits May 18, 2026 11:58
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.
@igorls

igorls commented May 18, 2026

Copy link
Copy Markdown
Member Author

@gemini-code-assist Good catch — high-priority and correct. The TS signature said Uint8Array but src/main.cpp still required IsBuffer(), so a plain Uint8Array would have thrown a runtime TypeError. Fixed in 81100ae:

  • BinToJsonWrapped now accepts a Buffer or any TypedArray, resolving bytes via the view's ArrayBuffer honouring ByteOffset (Node Buffers/Uint8Arrays are commonly pooled slices). Buffer fast-path unchanged.
  • Regression tests added: binToJson with a plain Uint8Array, and with a non-zero byteOffset view — both round-trip.
  • All five platform prebuilts regenerated from CI (c0c400f) since the native changed everywhere.

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 Uint8Array type is now truthful at runtime.

@gemini-code-assist

Copy link
Copy Markdown

Thanks for the update and for providing the details on the CI validation and the specific fixes implemented. The changes to BinToJsonWrapped in src/main.cpp to support Uint8Array (including handling byteOffset) correctly align the native implementation with the updated TypeScript signatures. The addition of regression tests for plain Uint8Array and offset views is excellent practice and ensures robustness for these type-safe changes. Everything looks solid for the 4.2.0 release.

@igorls igorls merged commit fa27e8d into master May 18, 2026
7 checks passed
@igorls igorls deleted the fix/consumer-types branch May 18, 2026 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants