@cratestack/cbor-node 0.17.1 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -31,7 +31,7 @@ dependency on `@cratestack/ts-types` required at runtime, since it's checked via
31
31
 
32
32
  CBOR has a real `null` (RFC 8949 §3.3, simple value 22, byte `0xf6`). `cratestack-codec-cbor`'s
33
33
  underlying `minicbor-serde` backend has a documented quirk where a bare Rust unit type `()`
34
- encodes as the CBOR *empty array* marker (`0x80`) instead — this package's `encode` translates
34
+ encodes as the CBOR _empty array_ marker (`0x80`) instead — this package's `encode` translates
35
35
  every JSON `null` (top-level or nested inside an object/array) through the code path that
36
36
  produces real CBOR null, matching `CborCodec`'s own `Option::None` behavior byte-for-byte. See
37
37
  `crates/cratestack-cbor-napi/src/json_value.rs` for the detail.
@@ -46,25 +46,26 @@ into a catchable exception instead of aborting the Node process.
46
46
 
47
47
  Single-item encode/decode only — no CBOR-seq/streaming support (that's a separate concern; see
48
48
  epic #285). Since issue #746, `@cratestack/cbor` (this package's Node half, via the umbrella
49
- `@cratestack/cbor` re-export) **is** the default codec for a generated TypeScript RPC client —
50
- `--no-native-cbor` (`TypeScriptGeneratorConfig::native_cbor: false`) falls back to the
51
- pure-TypeScript `jsonRpcCodec`, needed on platforms this package doesn't ship a napi binary for
52
- (`win32-arm64` — see `napi.targets` in `package.json`). REST-transport
53
- generated clients are unaffected either way: the REST runtime has no codec seam at all.
49
+ `@cratestack/cbor` re-export) **is** the codec of every generated TypeScript RPC client; the
50
+ generator's `--no-native-cbor` JSON fallback was removed. A client can still put JSON on the wire
51
+ by passing `codec: jsonRpcCodec`, but the generated runtime imports `@cratestack/cbor` at the
52
+ top level, so the package must load: on a platform this package ships no napi binary for
53
+ (`win32-arm64` — see `napi.targets` in `package.json`) a generated RPC client does not work.
54
+ REST-transport generated clients are unaffected: the REST runtime has no codec seam at all.
54
55
 
55
56
  ## Supported platforms
56
57
 
57
58
  `napi.targets` in `package.json` is the source of truth; as of cratestack#850 it is:
58
59
 
59
- | Platform | Target triple | npm platform package |
60
- | --- | --- | --- |
61
- | macOS x64 | `x86_64-apple-darwin` | `@cratestack/cbor-node-darwin-x64` |
62
- | macOS arm64 | `aarch64-apple-darwin` | `@cratestack/cbor-node-darwin-arm64` |
63
- | Linux x64 (glibc) | `x86_64-unknown-linux-gnu` | `@cratestack/cbor-node-linux-x64-gnu` |
64
- | Linux arm64 (glibc) | `aarch64-unknown-linux-gnu` | `@cratestack/cbor-node-linux-arm64-gnu` |
65
- | Linux x64 (musl / Alpine) | `x86_64-unknown-linux-musl` | `@cratestack/cbor-node-linux-x64-musl` |
60
+ | Platform | Target triple | npm platform package |
61
+ | --------------------------- | ---------------------------- | ---------------------------------------- |
62
+ | macOS x64 | `x86_64-apple-darwin` | `@cratestack/cbor-node-darwin-x64` |
63
+ | macOS arm64 | `aarch64-apple-darwin` | `@cratestack/cbor-node-darwin-arm64` |
64
+ | Linux x64 (glibc) | `x86_64-unknown-linux-gnu` | `@cratestack/cbor-node-linux-x64-gnu` |
65
+ | Linux arm64 (glibc) | `aarch64-unknown-linux-gnu` | `@cratestack/cbor-node-linux-arm64-gnu` |
66
+ | Linux x64 (musl / Alpine) | `x86_64-unknown-linux-musl` | `@cratestack/cbor-node-linux-x64-musl` |
66
67
  | Linux arm64 (musl / Alpine) | `aarch64-unknown-linux-musl` | `@cratestack/cbor-node-linux-arm64-musl` |
67
- | Windows x64 | `x86_64-pc-windows-msvc` | `@cratestack/cbor-node-win32-x64-msvc` |
68
+ | Windows x64 | `x86_64-pc-windows-msvc` | `@cratestack/cbor-node-win32-x64-msvc` |
68
69
 
69
70
  Both musl binaries are load-tested in CI, not just built: each `build-cbor-node` musl leg runs on
70
71
  the runner architecture it targets and, before uploading anything, loads the `.node` it just
@@ -76,8 +77,9 @@ Still **not** covered: `win32-arm64`. There is also no wasm/wasi fallback — th
76
77
  `native.mjs` loader contains a `wasm32-wasi` branch, but nothing publishes a `.wasi.cjs` or a
77
78
  `@cratestack/cbor-node-wasm32-wasi` package, so that branch can only ever add another
78
79
  `Cannot find module` to the error chain. On an unsupported platform the loader raises the generic
79
- *"Cannot find native binding. npm has a bug related to optional dependencies…"* error, which
80
- blames npm rather than naming the real cause; `--no-native-cbor` is the escape hatch.
80
+ _"Cannot find native binding. npm has a bug related to optional dependencies…"_ error, which
81
+ blames npm rather than naming the real cause. There is no escape hatch: the generator's
82
+ `--no-native-cbor` fallback was removed, so `win32-arm64` is unsupported for generated RPC clients.
81
83
 
82
84
  The per-platform packages above are an optimisation, not a requirement: this package's own tarball
83
85
  bundles every `.node` binary (`files: ["*.node"]`), and the loader tries the bundled
package/dist/index.d.ts CHANGED
@@ -17,4 +17,29 @@ export declare const cborCodec: {
17
17
  decode(bytes: Uint8Array): unknown;
18
18
  };
19
19
  export default cborCodec;
20
+ /** Which side of an op a body belongs to. */
21
+ export type CompactDirection = "request" | "response";
22
+ /**
23
+ * The compact-wire-key tables of one client (`docs/design/compact-wire-keys.md`):
24
+ * swaps schema field names for integer keys on the wire and back. Pure
25
+ * functions of bytes; a bad input throws a catchable `Error`.
26
+ */
27
+ export interface CompactKeys {
28
+ /** Named CBOR bytes to compact CBOR bytes. */
29
+ toCompact(named: Uint8Array, op: string, direction: CompactDirection): Uint8Array;
30
+ /** Compact CBOR bytes back to named CBOR bytes. */
31
+ fromCompact(compact: Uint8Array, op: string, direction: CompactDirection): Uint8Array;
32
+ /** Named JSON text to compact JSON text (keys become decimal strings). */
33
+ toCompactJson(named: string, op: string, direction: CompactDirection): string;
34
+ /** Compact JSON text back to named JSON text. */
35
+ fromCompactJson(compact: string, op: string, direction: CompactDirection): string;
36
+ /** The `Cratestack-Contract` header value of the op's current contract. */
37
+ selector(op: string): string | undefined;
38
+ }
39
+ /**
40
+ * Builds the {@link CompactKeys} of a generated client's key-table artifact
41
+ * (its `KEY_TABLES`). Async for call-site parity with
42
+ * `@cratestack/cbor-web`; the native addon needs no initialization.
43
+ */
44
+ export declare function createCompactKeys(tables: Uint8Array): Promise<CompactKeys>;
20
45
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAWA;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,SAAS;;kBAEN,OAAO,GAAG,QAAQ;kBAalB,UAAU,GAAG,OAAO;CAGN,CAAC;eAEhB,SAAS"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAeA;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,SAAS;;kBAEN,OAAO,GAAG,QAAQ;kBAalB,UAAU,GAAG,OAAO;CAGN,CAAC;eAEhB,SAAS;AAExB,6CAA6C;AAC7C,MAAM,MAAM,gBAAgB,GAAG,SAAS,GAAG,UAAU,CAAC;AAEtD;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC1B,8CAA8C;IAC9C,SAAS,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,gBAAgB,GAAG,UAAU,CAAC;IAClF,mDAAmD;IACnD,WAAW,CAAC,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,gBAAgB,GAAG,UAAU,CAAC;IACtF,0EAA0E;IAC1E,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,gBAAgB,GAAG,MAAM,CAAC;IAC9E,iDAAiD;IACjD,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,gBAAgB,GAAG,MAAM,CAAC;IAClF,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;CAC1C;AAED;;;;GAIG;AACH,wBAAsB,iBAAiB,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,WAAW,CAAC,CAYhF"}
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { decode as decodeNative, encode as encodeNative } from "../native.mjs";
1
+ import { decode as decodeNative, encode as encodeNative, CompactKeys as NativeCompactKeys, } from "../native.mjs";
2
2
  /**
3
3
  * CBOR codec backed by `cratestack-codec-cbor`'s Rust `CborCodec` (via the
4
4
  * native N-API binding built from `crates/cratestack-cbor-napi`) —
@@ -32,4 +32,21 @@ export const cborCodec = {
32
32
  },
33
33
  };
34
34
  export default cborCodec;
35
+ /**
36
+ * Builds the {@link CompactKeys} of a generated client's key-table artifact
37
+ * (its `KEY_TABLES`). Async for call-site parity with
38
+ * `@cratestack/cbor-web`; the native addon needs no initialization.
39
+ */
40
+ export async function createCompactKeys(tables) {
41
+ const keys = NativeCompactKeys.fromTables(tables);
42
+ return {
43
+ // `new Uint8Array(...)` re-wraps for the same typed-array-generics
44
+ // reason as `cborCodec.encode` above.
45
+ toCompact: (named, op, direction) => new Uint8Array(keys.toCompact(named, op, direction)),
46
+ fromCompact: (compact, op, direction) => new Uint8Array(keys.fromCompact(compact, op, direction)),
47
+ toCompactJson: (named, op, direction) => keys.toCompactJson(named, op, direction),
48
+ fromCompactJson: (compact, op, direction) => keys.fromCompactJson(compact, op, direction),
49
+ selector: (op) => keys.selector(op) ?? undefined,
50
+ };
51
+ }
35
52
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,eAAe,CAAC;AAE/E;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,WAAW,EAAE,kBAAkB;IAC/B,MAAM,CAAC,KAAc;QACnB,qEAAqE;QACrE,mEAAmE;QACnE,sEAAsE;QACtE,qEAAqE;QACrE,oEAAoE;QACpE,+DAA+D;QAC/D,+DAA+D;QAC/D,wDAAwD;QACxD,mEAAmE;QACnE,kDAAkD;QAClD,OAAO,IAAI,UAAU,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;IAC7C,CAAC;IACD,MAAM,CAAC,KAAiB;QACtB,OAAO,YAAY,CAAC,KAAK,CAAC,CAAC;IAC7B,CAAC;CAC2B,CAAC;AAE/B,eAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,OAAO,EACL,MAAM,IAAI,YAAY,EACtB,MAAM,IAAI,YAAY,EACtB,WAAW,IAAI,iBAAiB,GACjC,MAAM,eAAe,CAAC;AAEvB;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,WAAW,EAAE,kBAAkB;IAC/B,MAAM,CAAC,KAAc;QACnB,qEAAqE;QACrE,mEAAmE;QACnE,sEAAsE;QACtE,qEAAqE;QACrE,oEAAoE;QACpE,+DAA+D;QAC/D,+DAA+D;QAC/D,wDAAwD;QACxD,mEAAmE;QACnE,kDAAkD;QAClD,OAAO,IAAI,UAAU,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;IAC7C,CAAC;IACD,MAAM,CAAC,KAAiB;QACtB,OAAO,YAAY,CAAC,KAAK,CAAC,CAAC;IAC7B,CAAC;CAC2B,CAAC;AAE/B,eAAe,SAAS,CAAC;AAuBzB;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,MAAkB;IACxD,MAAM,IAAI,GAAG,iBAAiB,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IAClD,OAAO;QACL,mEAAmE;QACnE,sCAAsC;QACtC,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,EAAE,EAAE,SAAS,CAAC,CAAC;QACzF,WAAW,EAAE,CAAC,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,CACtC,IAAI,UAAU,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,EAAE,EAAE,SAAS,CAAC,CAAC;QAC1D,aAAa,EAAE,CAAC,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,EAAE,EAAE,SAAS,CAAC;QACjF,eAAe,EAAE,CAAC,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,CAAC,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,EAAE,EAAE,SAAS,CAAC;QACzF,QAAQ,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,SAAS;KACjD,CAAC;AACJ,CAAC"}
package/native.d.mts CHANGED
@@ -9,6 +9,28 @@
9
9
  */
10
10
  export declare const __napiBindingTarget: 'native' | 'wasm32-wasi' | 'wasm32-wasip1'
11
11
 
12
+ /**
13
+ * The key tables of one client: swaps field names for integer keys on
14
+ * the wire and back. `direction` is `"request"` or `"response"`.
15
+ */
16
+ export declare class CompactKeys {
17
+ /** Loads the generated key-table artifact. */
18
+ static fromTables(tables: Uint8Array): CompactKeys
19
+ /** Named CBOR bytes to compact CBOR bytes. */
20
+ toCompact(named: Uint8Array, op: string, direction: string): Uint8Array
21
+ /** Compact CBOR bytes back to named CBOR bytes. */
22
+ fromCompact(compact: Uint8Array, op: string, direction: string): Uint8Array
23
+ /** Named JSON text to compact JSON text (decimal-string keys). */
24
+ toCompactJson(named: string, op: string, direction: string): string
25
+ /** Compact JSON text back to named JSON text. */
26
+ fromCompactJson(compact: string, op: string, direction: string): string
27
+ /**
28
+ * The `Cratestack-Contract` header value of `op`'s current contract,
29
+ * or `undefined` for an op the tables lack.
30
+ */
31
+ selector(op: string): string | null
32
+ }
33
+
12
34
  /**
13
35
  * `"application/cbor"`, mirrored from `CborCodec::CONTENT_TYPE`.
14
36
  * Exposed as a function (rather than duplicating the literal on the
package/native.mjs CHANGED
@@ -9,8 +9,13 @@ const { readFileSync } = require('fs')
9
9
  let nativeBinding = null
10
10
  // Which artifact actually loaded. The WASI fallback chain overwrites it with
11
11
  // the flavor it resolved; the late native retry below leaves it alone because
12
- // it only runs while no WASI candidate has been loaded.
12
+ // it only runs while no WASI candidate has been loaded. The take-over check
13
+ // after the load-failure block can also set it.
13
14
  let __napiLoadedBindingTarget = 'native'
15
+ // What this loader's own `requireNative()` calls returned. The check after
16
+ // the load-failure block compares it with `nativeBinding` to tell a binding
17
+ // this loader loaded from one that code outside it put in its place.
18
+ let __napiRequiredNativeBinding = null
14
19
  const loadErrors = []
15
20
 
16
21
  const isMusl = () => {
@@ -92,8 +97,8 @@ function requireNative() {
92
97
  try {
93
98
  const binding = require('@cratestack/cbor-node-android-arm64')
94
99
  const bindingPackageVersion = require('@cratestack/cbor-node-android-arm64/package.json').version
95
- if (bindingPackageVersion !== '0.17.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
96
- throw new Error(`Native binding package version mismatch, expected 0.17.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
100
+ if (bindingPackageVersion !== '0.18.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
101
+ throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
97
102
  }
98
103
  return binding
99
104
  } catch (e) {
@@ -108,8 +113,8 @@ function requireNative() {
108
113
  try {
109
114
  const binding = require('@cratestack/cbor-node-android-arm-eabi')
110
115
  const bindingPackageVersion = require('@cratestack/cbor-node-android-arm-eabi/package.json').version
111
- if (bindingPackageVersion !== '0.17.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
112
- throw new Error(`Native binding package version mismatch, expected 0.17.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
116
+ if (bindingPackageVersion !== '0.18.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
117
+ throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
113
118
  }
114
119
  return binding
115
120
  } catch (e) {
@@ -129,8 +134,8 @@ function requireNative() {
129
134
  try {
130
135
  const binding = require('@cratestack/cbor-node-win32-x64-gnu')
131
136
  const bindingPackageVersion = require('@cratestack/cbor-node-win32-x64-gnu/package.json').version
132
- if (bindingPackageVersion !== '0.17.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
133
- throw new Error(`Native binding package version mismatch, expected 0.17.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
137
+ if (bindingPackageVersion !== '0.18.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
138
+ throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
134
139
  }
135
140
  return binding
136
141
  } catch (e) {
@@ -145,8 +150,8 @@ function requireNative() {
145
150
  try {
146
151
  const binding = require('@cratestack/cbor-node-win32-x64-msvc')
147
152
  const bindingPackageVersion = require('@cratestack/cbor-node-win32-x64-msvc/package.json').version
148
- if (bindingPackageVersion !== '0.17.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
149
- throw new Error(`Native binding package version mismatch, expected 0.17.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
153
+ if (bindingPackageVersion !== '0.18.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
154
+ throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
150
155
  }
151
156
  return binding
152
157
  } catch (e) {
@@ -162,8 +167,8 @@ function requireNative() {
162
167
  try {
163
168
  const binding = require('@cratestack/cbor-node-win32-ia32-msvc')
164
169
  const bindingPackageVersion = require('@cratestack/cbor-node-win32-ia32-msvc/package.json').version
165
- if (bindingPackageVersion !== '0.17.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
166
- throw new Error(`Native binding package version mismatch, expected 0.17.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
170
+ if (bindingPackageVersion !== '0.18.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
171
+ throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
167
172
  }
168
173
  return binding
169
174
  } catch (e) {
@@ -178,8 +183,8 @@ function requireNative() {
178
183
  try {
179
184
  const binding = require('@cratestack/cbor-node-win32-arm64-msvc')
180
185
  const bindingPackageVersion = require('@cratestack/cbor-node-win32-arm64-msvc/package.json').version
181
- if (bindingPackageVersion !== '0.17.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
182
- throw new Error(`Native binding package version mismatch, expected 0.17.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
186
+ if (bindingPackageVersion !== '0.18.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
187
+ throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
183
188
  }
184
189
  return binding
185
190
  } catch (e) {
@@ -197,8 +202,8 @@ function requireNative() {
197
202
  try {
198
203
  const binding = require('@cratestack/cbor-node-darwin-universal')
199
204
  const bindingPackageVersion = require('@cratestack/cbor-node-darwin-universal/package.json').version
200
- if (bindingPackageVersion !== '0.17.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
201
- throw new Error(`Native binding package version mismatch, expected 0.17.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
205
+ if (bindingPackageVersion !== '0.18.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
206
+ throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
202
207
  }
203
208
  return binding
204
209
  } catch (e) {
@@ -213,8 +218,8 @@ function requireNative() {
213
218
  try {
214
219
  const binding = require('@cratestack/cbor-node-darwin-x64')
215
220
  const bindingPackageVersion = require('@cratestack/cbor-node-darwin-x64/package.json').version
216
- if (bindingPackageVersion !== '0.17.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
217
- throw new Error(`Native binding package version mismatch, expected 0.17.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
221
+ if (bindingPackageVersion !== '0.18.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
222
+ throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
218
223
  }
219
224
  return binding
220
225
  } catch (e) {
@@ -229,8 +234,8 @@ function requireNative() {
229
234
  try {
230
235
  const binding = require('@cratestack/cbor-node-darwin-arm64')
231
236
  const bindingPackageVersion = require('@cratestack/cbor-node-darwin-arm64/package.json').version
232
- if (bindingPackageVersion !== '0.17.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
233
- throw new Error(`Native binding package version mismatch, expected 0.17.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
237
+ if (bindingPackageVersion !== '0.18.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
238
+ throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
234
239
  }
235
240
  return binding
236
241
  } catch (e) {
@@ -249,8 +254,8 @@ function requireNative() {
249
254
  try {
250
255
  const binding = require('@cratestack/cbor-node-freebsd-x64')
251
256
  const bindingPackageVersion = require('@cratestack/cbor-node-freebsd-x64/package.json').version
252
- if (bindingPackageVersion !== '0.17.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
253
- throw new Error(`Native binding package version mismatch, expected 0.17.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
257
+ if (bindingPackageVersion !== '0.18.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
258
+ throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
254
259
  }
255
260
  return binding
256
261
  } catch (e) {
@@ -265,8 +270,24 @@ function requireNative() {
265
270
  try {
266
271
  const binding = require('@cratestack/cbor-node-freebsd-arm64')
267
272
  const bindingPackageVersion = require('@cratestack/cbor-node-freebsd-arm64/package.json').version
268
- if (bindingPackageVersion !== '0.17.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
269
- throw new Error(`Native binding package version mismatch, expected 0.17.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
273
+ if (bindingPackageVersion !== '0.18.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
274
+ throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
275
+ }
276
+ return binding
277
+ } catch (e) {
278
+ loadErrors.push(e)
279
+ }
280
+ } else if (process.arch === 'ppc64') {
281
+ try {
282
+ return require('./cratestack-cbor-node.freebsd-ppc64.node')
283
+ } catch (e) {
284
+ loadErrors.push(e)
285
+ }
286
+ try {
287
+ const binding = require('@cratestack/cbor-node-freebsd-ppc64')
288
+ const bindingPackageVersion = require('@cratestack/cbor-node-freebsd-ppc64/package.json').version
289
+ if (bindingPackageVersion !== '0.18.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
290
+ throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
270
291
  }
271
292
  return binding
272
293
  } catch (e) {
@@ -286,8 +307,8 @@ function requireNative() {
286
307
  try {
287
308
  const binding = require('@cratestack/cbor-node-linux-x64-musl')
288
309
  const bindingPackageVersion = require('@cratestack/cbor-node-linux-x64-musl/package.json').version
289
- if (bindingPackageVersion !== '0.17.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
290
- throw new Error(`Native binding package version mismatch, expected 0.17.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
310
+ if (bindingPackageVersion !== '0.18.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
311
+ throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
291
312
  }
292
313
  return binding
293
314
  } catch (e) {
@@ -302,8 +323,8 @@ function requireNative() {
302
323
  try {
303
324
  const binding = require('@cratestack/cbor-node-linux-x64-gnu')
304
325
  const bindingPackageVersion = require('@cratestack/cbor-node-linux-x64-gnu/package.json').version
305
- if (bindingPackageVersion !== '0.17.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
306
- throw new Error(`Native binding package version mismatch, expected 0.17.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
326
+ if (bindingPackageVersion !== '0.18.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
327
+ throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
307
328
  }
308
329
  return binding
309
330
  } catch (e) {
@@ -320,8 +341,8 @@ function requireNative() {
320
341
  try {
321
342
  const binding = require('@cratestack/cbor-node-linux-arm64-musl')
322
343
  const bindingPackageVersion = require('@cratestack/cbor-node-linux-arm64-musl/package.json').version
323
- if (bindingPackageVersion !== '0.17.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
324
- throw new Error(`Native binding package version mismatch, expected 0.17.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
344
+ if (bindingPackageVersion !== '0.18.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
345
+ throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
325
346
  }
326
347
  return binding
327
348
  } catch (e) {
@@ -336,8 +357,8 @@ function requireNative() {
336
357
  try {
337
358
  const binding = require('@cratestack/cbor-node-linux-arm64-gnu')
338
359
  const bindingPackageVersion = require('@cratestack/cbor-node-linux-arm64-gnu/package.json').version
339
- if (bindingPackageVersion !== '0.17.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
340
- throw new Error(`Native binding package version mismatch, expected 0.17.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
360
+ if (bindingPackageVersion !== '0.18.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
361
+ throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
341
362
  }
342
363
  return binding
343
364
  } catch (e) {
@@ -354,8 +375,8 @@ function requireNative() {
354
375
  try {
355
376
  const binding = require('@cratestack/cbor-node-linux-arm-musleabihf')
356
377
  const bindingPackageVersion = require('@cratestack/cbor-node-linux-arm-musleabihf/package.json').version
357
- if (bindingPackageVersion !== '0.17.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
358
- throw new Error(`Native binding package version mismatch, expected 0.17.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
378
+ if (bindingPackageVersion !== '0.18.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
379
+ throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
359
380
  }
360
381
  return binding
361
382
  } catch (e) {
@@ -370,8 +391,8 @@ function requireNative() {
370
391
  try {
371
392
  const binding = require('@cratestack/cbor-node-linux-arm-gnueabihf')
372
393
  const bindingPackageVersion = require('@cratestack/cbor-node-linux-arm-gnueabihf/package.json').version
373
- if (bindingPackageVersion !== '0.17.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
374
- throw new Error(`Native binding package version mismatch, expected 0.17.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
394
+ if (bindingPackageVersion !== '0.18.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
395
+ throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
375
396
  }
376
397
  return binding
377
398
  } catch (e) {
@@ -388,8 +409,8 @@ function requireNative() {
388
409
  try {
389
410
  const binding = require('@cratestack/cbor-node-linux-loong64-musl')
390
411
  const bindingPackageVersion = require('@cratestack/cbor-node-linux-loong64-musl/package.json').version
391
- if (bindingPackageVersion !== '0.17.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
392
- throw new Error(`Native binding package version mismatch, expected 0.17.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
412
+ if (bindingPackageVersion !== '0.18.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
413
+ throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
393
414
  }
394
415
  return binding
395
416
  } catch (e) {
@@ -404,8 +425,8 @@ function requireNative() {
404
425
  try {
405
426
  const binding = require('@cratestack/cbor-node-linux-loong64-gnu')
406
427
  const bindingPackageVersion = require('@cratestack/cbor-node-linux-loong64-gnu/package.json').version
407
- if (bindingPackageVersion !== '0.17.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
408
- throw new Error(`Native binding package version mismatch, expected 0.17.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
428
+ if (bindingPackageVersion !== '0.18.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
429
+ throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
409
430
  }
410
431
  return binding
411
432
  } catch (e) {
@@ -422,8 +443,8 @@ function requireNative() {
422
443
  try {
423
444
  const binding = require('@cratestack/cbor-node-linux-riscv64-musl')
424
445
  const bindingPackageVersion = require('@cratestack/cbor-node-linux-riscv64-musl/package.json').version
425
- if (bindingPackageVersion !== '0.17.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
426
- throw new Error(`Native binding package version mismatch, expected 0.17.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
446
+ if (bindingPackageVersion !== '0.18.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
447
+ throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
427
448
  }
428
449
  return binding
429
450
  } catch (e) {
@@ -438,8 +459,8 @@ function requireNative() {
438
459
  try {
439
460
  const binding = require('@cratestack/cbor-node-linux-riscv64-gnu')
440
461
  const bindingPackageVersion = require('@cratestack/cbor-node-linux-riscv64-gnu/package.json').version
441
- if (bindingPackageVersion !== '0.17.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
442
- throw new Error(`Native binding package version mismatch, expected 0.17.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
462
+ if (bindingPackageVersion !== '0.18.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
463
+ throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
443
464
  }
444
465
  return binding
445
466
  } catch (e) {
@@ -455,8 +476,8 @@ function requireNative() {
455
476
  try {
456
477
  const binding = require('@cratestack/cbor-node-linux-ppc64-gnu')
457
478
  const bindingPackageVersion = require('@cratestack/cbor-node-linux-ppc64-gnu/package.json').version
458
- if (bindingPackageVersion !== '0.17.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
459
- throw new Error(`Native binding package version mismatch, expected 0.17.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
479
+ if (bindingPackageVersion !== '0.18.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
480
+ throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
460
481
  }
461
482
  return binding
462
483
  } catch (e) {
@@ -471,8 +492,8 @@ function requireNative() {
471
492
  try {
472
493
  const binding = require('@cratestack/cbor-node-linux-s390x-gnu')
473
494
  const bindingPackageVersion = require('@cratestack/cbor-node-linux-s390x-gnu/package.json').version
474
- if (bindingPackageVersion !== '0.17.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
475
- throw new Error(`Native binding package version mismatch, expected 0.17.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
495
+ if (bindingPackageVersion !== '0.18.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
496
+ throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
476
497
  }
477
498
  return binding
478
499
  } catch (e) {
@@ -491,8 +512,8 @@ function requireNative() {
491
512
  try {
492
513
  const binding = require('@cratestack/cbor-node-openharmony-arm64')
493
514
  const bindingPackageVersion = require('@cratestack/cbor-node-openharmony-arm64/package.json').version
494
- if (bindingPackageVersion !== '0.17.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
495
- throw new Error(`Native binding package version mismatch, expected 0.17.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
515
+ if (bindingPackageVersion !== '0.18.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
516
+ throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
496
517
  }
497
518
  return binding
498
519
  } catch (e) {
@@ -507,8 +528,8 @@ function requireNative() {
507
528
  try {
508
529
  const binding = require('@cratestack/cbor-node-openharmony-x64')
509
530
  const bindingPackageVersion = require('@cratestack/cbor-node-openharmony-x64/package.json').version
510
- if (bindingPackageVersion !== '0.17.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
511
- throw new Error(`Native binding package version mismatch, expected 0.17.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
531
+ if (bindingPackageVersion !== '0.18.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
532
+ throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
512
533
  }
513
534
  return binding
514
535
  } catch (e) {
@@ -523,8 +544,8 @@ function requireNative() {
523
544
  try {
524
545
  const binding = require('@cratestack/cbor-node-openharmony-arm')
525
546
  const bindingPackageVersion = require('@cratestack/cbor-node-openharmony-arm/package.json').version
526
- if (bindingPackageVersion !== '0.17.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
527
- throw new Error(`Native binding package version mismatch, expected 0.17.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
547
+ if (bindingPackageVersion !== '0.18.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
548
+ throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
528
549
  }
529
550
  return binding
530
551
  } catch (e) {
@@ -588,6 +609,7 @@ const forceWasi =
588
609
 
589
610
  if (!forceWasi) {
590
611
  nativeBinding = requireNative()
612
+ __napiRequiredNativeBinding = nativeBinding
591
613
  }
592
614
 
593
615
  if (!nativeBinding || forceWasi) {
@@ -664,8 +686,8 @@ if (!nativeBinding || forceWasi) {
664
686
  if (!candidateFailed) {
665
687
  if (process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
666
688
  const bindingPackageVersion = require('@cratestack/cbor-node-wasm32-wasi/package.json').version
667
- if (bindingPackageVersion !== '0.17.1') {
668
- throw new Error(`WASI binding package version mismatch, expected 0.17.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
689
+ if (bindingPackageVersion !== '0.18.0') {
690
+ throw new Error(`WASI binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
669
691
  }
670
692
  }
671
693
  wasiBinding = require('@cratestack/cbor-node-wasm32-wasi')
@@ -689,6 +711,7 @@ if (!nativeBinding || forceWasi) {
689
711
  !__napiWasiFlavorRequested
690
712
  ) {
691
713
  nativeBinding = requireNative()
714
+ __napiRequiredNativeBinding = nativeBinding
692
715
  }
693
716
  if ((forceWasiError || __napiWasiFlavorRequested) && !wasiBindingLoaded) {
694
717
  const error = new Error(
@@ -716,7 +739,42 @@ if (!nativeBinding) {
716
739
  throw new Error(`Failed to load native binding`)
717
740
  }
718
741
 
719
- const { contentType, decode, encode } = nativeBinding
742
+ // A package can patch its own fallback in front of the load-failure check
743
+ // above, e.g. a WebContainer download through `napi-postinstall/fallback`.
744
+ // That fallback swaps `nativeBinding` for a generated WASI loader, which has
745
+ // already stamped its own flavor, while the target above still says 'native'.
746
+ // Take that flavor over, or the CommonJS stamp throws a conflict and the ESM
747
+ // export reports the wrong artifact. Three limits keep the conflict check:
748
+ // - only a binding this loader did not load itself, so a native addon whose
749
+ // `#[napi(module_exports)]` hook claims the name is still rejected;
750
+ // - only an own data property, read through its descriptor, so no addon
751
+ // getter runs here, and it must read back the same, as the stamp reads it;
752
+ // - only a flavor in `__napiWasiFlavors`, the ones this loader's own WASI
753
+ // chain can report ('wasm32-wasi' for a package without a WASI target).
754
+ // This is metadata and never fails a load: a throwing Proxy trap keeps 'native'.
755
+ if (
756
+ __napiLoadedBindingTarget === 'native' &&
757
+ nativeBinding !== __napiRequiredNativeBinding
758
+ ) {
759
+ try {
760
+ const __napiBindingTargetDescriptor = Object.getOwnPropertyDescriptor(
761
+ nativeBinding,
762
+ '__napiBindingTarget',
763
+ )
764
+ if (
765
+ __napiBindingTargetDescriptor &&
766
+ __napiWasiFlavors.indexOf(__napiBindingTargetDescriptor.value) !== -1 &&
767
+ nativeBinding.__napiBindingTarget === __napiBindingTargetDescriptor.value
768
+ ) {
769
+ __napiLoadedBindingTarget = __napiBindingTargetDescriptor.value
770
+ }
771
+ } catch {
772
+ // keep 'native'
773
+ }
774
+ }
775
+
776
+ const { CompactKeys, contentType, decode, encode } = nativeBinding
777
+ export { CompactKeys }
720
778
  export { contentType }
721
779
  export { decode }
722
780
  export { encode }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cratestack/cbor-node",
3
- "version": "0.17.1",
3
+ "version": "0.18.0",
4
4
  "description": "Native N-API CBOR codec for CrateStack's generated TypeScript clients, wrapping the framework's own cratestack-codec-cbor Rust crate (crates/cratestack-cbor-napi) for byte-identical wire behavior with the server and Rust client.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -60,8 +60,8 @@
60
60
  "prepublishOnly": "napi prepublish -t npm --skip-optional-publish"
61
61
  },
62
62
  "devDependencies": {
63
- "@cratestack/ts-types": "0.17.1",
64
- "@napi-rs/cli": "^3.10.8",
63
+ "@cratestack/ts-types": "0.18.0",
64
+ "@napi-rs/cli": "^3.10.9",
65
65
  "typescript": "^7.0.2",
66
66
  "vitest": "^5.0.5"
67
67
  },
@@ -69,12 +69,12 @@
69
69
  "node": ">=24"
70
70
  },
71
71
  "optionalDependencies": {
72
- "@cratestack/cbor-node-darwin-x64": "0.17.1",
73
- "@cratestack/cbor-node-darwin-arm64": "0.17.1",
74
- "@cratestack/cbor-node-linux-x64-gnu": "0.17.1",
75
- "@cratestack/cbor-node-linux-arm64-gnu": "0.17.1",
76
- "@cratestack/cbor-node-linux-x64-musl": "0.17.1",
77
- "@cratestack/cbor-node-linux-arm64-musl": "0.17.1",
78
- "@cratestack/cbor-node-win32-x64-msvc": "0.17.1"
72
+ "@cratestack/cbor-node-darwin-x64": "0.18.0",
73
+ "@cratestack/cbor-node-darwin-arm64": "0.18.0",
74
+ "@cratestack/cbor-node-linux-x64-gnu": "0.18.0",
75
+ "@cratestack/cbor-node-linux-arm64-gnu": "0.18.0",
76
+ "@cratestack/cbor-node-linux-x64-musl": "0.18.0",
77
+ "@cratestack/cbor-node-linux-arm64-musl": "0.18.0",
78
+ "@cratestack/cbor-node-win32-x64-msvc": "0.18.0"
79
79
  }
80
80
  }