@cratestack/cbor-web 0.8.14 → 0.9.1

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.
@@ -20,23 +20,31 @@ export function contentType() {
20
20
  }
21
21
 
22
22
  /**
23
- * Decodes CBOR bytes into a plain JS value. Malformed input surfaces as
24
- * a rejected/thrown `Error`, never a trap — see the module doc comment.
23
+ * Decodes CBOR bytes into a plain JS value. A CBOR byte string comes
24
+ * back as a `Uint8Array` — the inverse of [`encode`]'s handling, closing
25
+ * cratestack#783's symmetric decode half. Two things are load-bearing
26
+ * for that: `JsSerializable` (which pins `Value::Bytes` to
27
+ * `serialize_bytes` rather than the base64 string `Value` emits for
28
+ * human-readable formats, and `serde_wasm_bindgen::Serializer` reports
29
+ * itself as one), and leaving `serialize_bytes_as_arrays` at its default
30
+ * so `serialize_bytes` produces a `Uint8Array` and not a plain `Array`.
31
+ * Malformed input surfaces as a rejected/thrown `Error`, never a trap —
32
+ * see the module doc comment.
25
33
  *
26
34
  * Two `serde_wasm_bindgen` default `Serializer` behaviors would otherwise
27
35
  * corrupt the result, so this builds an explicit `Serializer` instead of
28
36
  * using the `to_value` convenience function:
29
37
  * - `serialize_maps_as_objects(true)` — the default turns Rust maps
30
- * (including `serde_json::Value::Object`) into JS `Map` instances,
31
- * not plain `{}` objects. A `Map` round-trips fine through explicit
38
+ * (including `Value::Map`) into JS `Map` instances, not plain `{}`
39
+ * objects. A `Map` round-trips fine through explicit
32
40
  * `.get()`/`.entries()` calls, but silently renders as `"{}"` under
33
41
  * `JSON.stringify`, which isn't what a `decode(bytes): unknown`
34
42
  * caller expects.
35
43
  * - `serialize_missing_as_null(true)` — the default serializes both
36
- * `serialize_none()` and `serialize_unit()` (what `serde_json::Value
37
- * ::Null`'s own `Serialize` impl calls) as JS `undefined`, not
38
- * `null`. An object property set to `undefined` is silently dropped
39
- * by `JSON.stringify`, which is what made this look like data loss
44
+ * `serialize_none()` (what `Value::Null` calls) and
45
+ * `serialize_unit()` as JS `undefined`, not `null`. An object
46
+ * property set to `undefined` is silently dropped by
47
+ * `JSON.stringify`, which is what made this look like data loss
40
48
  * during development rather than a `null`-vs-`undefined` mismatch.
41
49
  * @param {Uint8Array} bytes
42
50
  * @returns {any}
@@ -54,11 +62,15 @@ export function decode(bytes) {
54
62
  /**
55
63
  * Encodes an arbitrary JS value as CBOR bytes.
56
64
  *
57
- * `value` is deserialized into an owned `serde_json::Value` first (JS has
58
- * no notion of the concrete Rust types `CborCodec::encode<T>` is generic
59
- * over), then re-serialized through `EncodableValue` — see
60
- * `json_bridge.rs` for why that indirection exists rather than encoding
61
- * the `serde_json::Value` tree directly.
65
+ * `value` is deserialized into an owned `cratestack_core::Value` first
66
+ * (JS has no notion of the concrete Rust types `CborCodec::encode<T>` is
67
+ * generic over), then encoded. `Value` rather than `serde_json::Value`
68
+ * is what makes binary data work at all: a JS `Uint8Array`/`ArrayBuffer`
69
+ * lands in `Value::Bytes` (`serde-wasm-bindgen`'s `deserialize_any`
70
+ * routes both to `visit_byte_buf`) and goes out as a CBOR byte string,
71
+ * instead of degrading into a map of index→value that no `Vec<u8>` on
72
+ * the Rust side can decode — cratestack#783. See `value_bridge.rs` for
73
+ * the full rationale and the host-runnable byte assertions.
62
74
  * @param {any} value
63
75
  * @returns {Uint8Array}
64
76
  */
@@ -84,7 +96,7 @@ export function start() {
84
96
  function __wbg_get_imports() {
85
97
  const import0 = {
86
98
  __proto__: null,
87
- __wbg_Error_fdd633d4bb5dd76a: function(arg0, arg1) {
99
+ __wbg_Error_408e67f47ca7b58b: function(arg0, arg1) {
88
100
  const ret = Error(getStringFromWasm0(arg0, arg1));
89
101
  return ret;
90
102
  },
@@ -95,60 +107,60 @@ function __wbg_get_imports() {
95
107
  getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
96
108
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
97
109
  },
98
- __wbg___wbindgen_bigint_get_as_i64_d9e915702856f831: function(arg0, arg1) {
110
+ __wbg___wbindgen_bigint_get_as_i64_c4ecf48528083721: function(arg0, arg1) {
99
111
  const v = arg1;
100
112
  const ret = typeof(v) === 'bigint' ? v : undefined;
101
113
  getDataViewMemory0().setBigInt64(arg0 + 8 * 1, isLikeNone(ret) ? BigInt(0) : ret, true);
102
114
  getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
103
115
  },
104
- __wbg___wbindgen_boolean_get_edaed31a367ce1bd: function(arg0) {
116
+ __wbg___wbindgen_boolean_get_c9c83ebd41b34df3: function(arg0) {
105
117
  const v = arg0;
106
118
  const ret = typeof(v) === 'boolean' ? v : undefined;
107
119
  return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
108
120
  },
109
- __wbg___wbindgen_debug_string_8a447059637473e2: function(arg0, arg1) {
121
+ __wbg___wbindgen_debug_string_a57024b9c6e4a48b: function(arg0, arg1) {
110
122
  const ret = debugString(arg1);
111
123
  const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
112
124
  const len1 = WASM_VECTOR_LEN;
113
125
  getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
114
126
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
115
127
  },
116
- __wbg___wbindgen_in_4990f46af709e33c: function(arg0, arg1) {
128
+ __wbg___wbindgen_in_ac983077f137f2e6: function(arg0, arg1) {
117
129
  const ret = arg0 in arg1;
118
130
  return ret;
119
131
  },
120
- __wbg___wbindgen_is_bigint_90b5ccfe67c78460: function(arg0) {
132
+ __wbg___wbindgen_is_bigint_8ffbbef442139384: function(arg0) {
121
133
  const ret = typeof(arg0) === 'bigint';
122
134
  return ret;
123
135
  },
124
- __wbg___wbindgen_is_function_acc5528be2b923f2: function(arg0) {
136
+ __wbg___wbindgen_is_function_5e4570eb24ffa122: function(arg0) {
125
137
  const ret = typeof(arg0) === 'function';
126
138
  return ret;
127
139
  },
128
- __wbg___wbindgen_is_object_0beba4a1980d3eea: function(arg0) {
140
+ __wbg___wbindgen_is_object_a2790eb24c211ea0: function(arg0) {
129
141
  const val = arg0;
130
142
  const ret = typeof(val) === 'object' && val !== null;
131
143
  return ret;
132
144
  },
133
- __wbg___wbindgen_is_string_1fca8072260dd261: function(arg0) {
145
+ __wbg___wbindgen_is_string_e6f02f0ea5f20a32: function(arg0) {
134
146
  const ret = typeof(arg0) === 'string';
135
147
  return ret;
136
148
  },
137
- __wbg___wbindgen_jsval_eq_4e8c38722cb8ff51: function(arg0, arg1) {
149
+ __wbg___wbindgen_jsval_eq_0a18949a61670320: function(arg0, arg1) {
138
150
  const ret = arg0 === arg1;
139
151
  return ret;
140
152
  },
141
- __wbg___wbindgen_jsval_loose_eq_4b9aba9e5b3c4582: function(arg0, arg1) {
153
+ __wbg___wbindgen_jsval_loose_eq_acf2776254a8d832: function(arg0, arg1) {
142
154
  const ret = arg0 == arg1;
143
155
  return ret;
144
156
  },
145
- __wbg___wbindgen_number_get_1cc01dd708740256: function(arg0, arg1) {
157
+ __wbg___wbindgen_number_get_136b9679cab35cfb: function(arg0, arg1) {
146
158
  const obj = arg1;
147
159
  const ret = typeof(obj) === 'number' ? obj : undefined;
148
160
  getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
149
161
  getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
150
162
  },
151
- __wbg___wbindgen_string_get_71bb4348194e31f0: function(arg0, arg1) {
163
+ __wbg___wbindgen_string_get_d154f1e671052120: function(arg0, arg1) {
152
164
  const obj = arg1;
153
165
  const ret = typeof(obj) === 'string' ? obj : undefined;
154
166
  var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
@@ -156,22 +168,22 @@ function __wbg_get_imports() {
156
168
  getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
157
169
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
158
170
  },
159
- __wbg___wbindgen_throw_ea4887a5f8f9a9db: function(arg0, arg1) {
171
+ __wbg___wbindgen_throw_bb96b2010945f0bc: function(arg0, arg1) {
160
172
  throw new Error(getStringFromWasm0(arg0, arg1));
161
173
  },
162
- __wbg_call_8e98ed2f3c86c4b5: function() { return handleError(function (arg0, arg1) {
174
+ __wbg_call_1c5886ab9c57d1c7: function() { return handleError(function (arg0, arg1) {
163
175
  const ret = arg0.call(arg1);
164
176
  return ret;
165
177
  }, arguments); },
166
- __wbg_done_b62d4a7d2286852a: function(arg0) {
178
+ __wbg_done_669171204c3dcae2: function(arg0) {
167
179
  const ret = arg0.done;
168
180
  return ret;
169
181
  },
170
- __wbg_entries_c261c3fa1f281256: function(arg0) {
182
+ __wbg_entries_7774d489e1da5f4f: function(arg0) {
171
183
  const ret = Object.entries(arg0);
172
184
  return ret;
173
185
  },
174
- __wbg_error_a6fa202b58aa1cd3: function(arg0, arg1) {
186
+ __wbg_error_757e9472f8410341: function(arg0, arg1) {
175
187
  let deferred0_0;
176
188
  let deferred0_1;
177
189
  try {
@@ -182,19 +194,23 @@ function __wbg_get_imports() {
182
194
  wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
183
195
  }
184
196
  },
185
- __wbg_get_197a3fe98f169e38: function(arg0, arg1) {
197
+ __wbg_from_74f3d90e0ff11240: function(arg0) {
198
+ const ret = Array.from(arg0);
199
+ return ret;
200
+ },
201
+ __wbg_get_c0c8f8d7da0c03dd: function(arg0, arg1) {
186
202
  const ret = arg0[arg1 >>> 0];
187
203
  return ret;
188
204
  },
189
- __wbg_get_9a29be2cb383ed9a: function() { return handleError(function (arg0, arg1) {
205
+ __wbg_get_d173c0308df22d37: function() { return handleError(function (arg0, arg1) {
190
206
  const ret = Reflect.get(arg0, arg1);
191
207
  return ret;
192
208
  }, arguments); },
193
- __wbg_get_unchecked_54a4374c38e08460: function(arg0, arg1) {
209
+ __wbg_get_unchecked_e20b893aeafc3fca: function(arg0, arg1) {
194
210
  const ret = arg0[arg1 >>> 0];
195
211
  return ret;
196
212
  },
197
- __wbg_instanceof_ArrayBuffer_2a7bb09fee70c2da: function(arg0) {
213
+ __wbg_instanceof_ArrayBuffer_993d02d2d254cad1: function(arg0) {
198
214
  let result;
199
215
  try {
200
216
  result = arg0 instanceof ArrayBuffer;
@@ -204,7 +220,7 @@ function __wbg_get_imports() {
204
220
  const ret = result;
205
221
  return ret;
206
222
  },
207
- __wbg_instanceof_Map_afa18d5840c04c15: function(arg0) {
223
+ __wbg_instanceof_Map_9a4d6ead180ae3a9: function(arg0) {
208
224
  let result;
209
225
  try {
210
226
  result = arg0 instanceof Map;
@@ -214,7 +230,7 @@ function __wbg_get_imports() {
214
230
  const ret = result;
215
231
  return ret;
216
232
  },
217
- __wbg_instanceof_Uint8Array_f080092dc70f5d58: function(arg0) {
233
+ __wbg_instanceof_Uint8Array_f935dbb0aa7cdeed: function(arg0) {
218
234
  let result;
219
235
  try {
220
236
  result = arg0 instanceof Uint8Array;
@@ -224,65 +240,65 @@ function __wbg_get_imports() {
224
240
  const ret = result;
225
241
  return ret;
226
242
  },
227
- __wbg_isArray_145a34fd0a38d37b: function(arg0) {
243
+ __wbg_isArray_6339f732981044bf: function(arg0) {
228
244
  const ret = Array.isArray(arg0);
229
245
  return ret;
230
246
  },
231
- __wbg_isSafeInteger_a3389a198582f5f6: function(arg0) {
247
+ __wbg_isSafeInteger_f3d6cd19ccfe4512: function(arg0) {
232
248
  const ret = Number.isSafeInteger(arg0);
233
249
  return ret;
234
250
  },
235
- __wbg_iterator_cc47ba25a2be735a: function() {
251
+ __wbg_iterator_5cebbb86e33c6dd6: function() {
236
252
  const ret = Symbol.iterator;
237
253
  return ret;
238
254
  },
239
- __wbg_length_589238bdcf171f0e: function(arg0) {
255
+ __wbg_length_36bd29c6848c2144: function(arg0) {
240
256
  const ret = arg0.length;
241
257
  return ret;
242
258
  },
243
- __wbg_length_c6054974c0a6cdb9: function(arg0) {
259
+ __wbg_length_ecfa2c63d3d0d82c: function(arg0) {
244
260
  const ret = arg0.length;
245
261
  return ret;
246
262
  },
263
+ __wbg_new_116be93542d39019: function() {
264
+ const ret = new Array();
265
+ return ret;
266
+ },
247
267
  __wbg_new_227d7c05414eb861: function() {
248
268
  const ret = new Error();
249
269
  return ret;
250
270
  },
251
- __wbg_new_2e117a478906f062: function() {
252
- const ret = new Object();
271
+ __wbg_new_77cc4f4f472aeb81: function(arg0) {
272
+ const ret = new Uint8Array(arg0);
253
273
  return ret;
254
274
  },
255
- __wbg_new_3444eb7412549f0b: function() {
275
+ __wbg_new_cdf041679ded4c5f: function() {
256
276
  const ret = new Map();
257
277
  return ret;
258
278
  },
259
- __wbg_new_36e147a8ced3c6e0: function() {
260
- const ret = new Array();
261
- return ret;
262
- },
263
- __wbg_new_81880fb5002cb255: function(arg0) {
264
- const ret = new Uint8Array(arg0);
279
+ __wbg_new_ebe3e0f6837f0879: function() {
280
+ const ret = new Object();
265
281
  return ret;
266
282
  },
267
- __wbg_next_0c4066e251d2eff9: function() { return handleError(function (arg0) {
283
+ __wbg_next_42cf16ee0dafc9e2: function() { return handleError(function (arg0) {
268
284
  const ret = arg0.next();
269
285
  return ret;
270
286
  }, arguments); },
271
- __wbg_next_402fa10b59ab20c3: function(arg0) {
287
+ __wbg_next_8f26b64fa5e9f64b: function(arg0) {
272
288
  const ret = arg0.next;
273
289
  return ret;
274
290
  },
275
- __wbg_prototypesetcall_d721637c7ca66eb8: function(arg0, arg1, arg2) {
291
+ __wbg_prototypesetcall_de8e0d9553586985: function(arg0, arg1, arg2) {
276
292
  Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
277
293
  },
278
- __wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
279
- arg0[arg1] = arg2;
280
- },
281
- __wbg_set_9a1d61e17de7054c: function(arg0, arg1, arg2) {
294
+ __wbg_set_014226dfeca53178: function(arg0, arg1, arg2) {
282
295
  const ret = arg0.set(arg1, arg2);
283
296
  return ret;
284
297
  },
285
- __wbg_set_dc601f4a69da0bc2: function(arg0, arg1, arg2) {
298
+ __wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
299
+ arg0[arg1] = arg2;
300
+ },
301
+ __wbg_set_a80955eb93b145c6: function(arg0, arg1, arg2) {
286
302
  arg0[arg1 >>> 0] = arg2;
287
303
  },
288
304
  __wbg_stack_3b0d974bbf31e44f: function(arg0, arg1) {
@@ -292,7 +308,7 @@ function __wbg_get_imports() {
292
308
  getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
293
309
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
294
310
  },
295
- __wbg_value_49f783bb59765962: function(arg0) {
311
+ __wbg_value_1e2369fab29b420e: function(arg0) {
296
312
  const ret = arg0.value;
297
313
  return ret;
298
314
  },
@@ -307,11 +323,16 @@ function __wbg_get_imports() {
307
323
  return ret;
308
324
  },
309
325
  __wbindgen_cast_0000000000000003: function(arg0, arg1) {
326
+ // Cast intrinsic for `Ref(Slice(U8)) -> NamedExternref("Uint8Array")`.
327
+ const ret = getArrayU8FromWasm0(arg0, arg1);
328
+ return ret;
329
+ },
330
+ __wbindgen_cast_0000000000000004: function(arg0, arg1) {
310
331
  // Cast intrinsic for `Ref(String) -> Externref`.
311
332
  const ret = getStringFromWasm0(arg0, arg1);
312
333
  return ret;
313
334
  },
314
- __wbindgen_cast_0000000000000004: function(arg0) {
335
+ __wbindgen_cast_0000000000000005: function(arg0) {
315
336
  // Cast intrinsic for `U64 -> Externref`.
316
337
  const ret = BigInt.asUintN(64, arg0);
317
338
  return ret;
@@ -533,11 +554,15 @@ function __wbg_finalize_init(instance, module) {
533
554
 
534
555
  async function __wbg_load(module, imports) {
535
556
  if (typeof Response === 'function' && module instanceof Response) {
557
+ if (!module.ok) {
558
+ throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
559
+ }
560
+
536
561
  if (typeof WebAssembly.instantiateStreaming === 'function') {
537
562
  try {
538
563
  return await WebAssembly.instantiateStreaming(module, imports);
539
564
  } catch (e) {
540
- const validResponse = module.ok && expectedResponseType(module.type);
565
+ const validResponse = expectedResponseType(module.type);
541
566
 
542
567
  if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
543
568
  console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cratestack/cbor-web",
3
- "version": "0.8.14",
3
+ "version": "0.9.1",
4
4
  "description": "wasm-bindgen CBOR codec for browser CrateStack RPC clients. Async one-time WASM init, synchronous encode/decode after — backed by the same Rust CborCodec the server and Rust client already use.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -43,13 +43,13 @@
43
43
  "lint": "biome check ."
44
44
  },
45
45
  "dependencies": {
46
- "@cratestack/ts-types": "0.8.14"
46
+ "@cratestack/ts-types": "0.9.1"
47
47
  },
48
48
  "devDependencies": {
49
49
  "typescript": "^7.0.2",
50
- "vitest": "^4.1.10"
50
+ "vitest": "^4.1.11"
51
51
  },
52
52
  "engines": {
53
- "node": ">=18"
53
+ "node": ">=24"
54
54
  }
55
55
  }