@cratestack/cbor-web 0.8.14 → 0.8.15

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
  */
@@ -182,6 +194,10 @@ function __wbg_get_imports() {
182
194
  wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
183
195
  }
184
196
  },
197
+ __wbg_from_50138b2ca136f50c: function(arg0) {
198
+ const ret = Array.from(arg0);
199
+ return ret;
200
+ },
185
201
  __wbg_get_197a3fe98f169e38: function(arg0, arg1) {
186
202
  const ret = arg0[arg1 >>> 0];
187
203
  return ret;
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cratestack/cbor-web",
3
- "version": "0.8.14",
3
+ "version": "0.8.15",
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,7 +43,7 @@
43
43
  "lint": "biome check ."
44
44
  },
45
45
  "dependencies": {
46
- "@cratestack/ts-types": "0.8.14"
46
+ "@cratestack/ts-types": "0.8.15"
47
47
  },
48
48
  "devDependencies": {
49
49
  "typescript": "^7.0.2",