@statewalker/webrun-msgpack 0.1.1 → 0.3.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.
@@ -0,0 +1,70 @@
1
+ /*!
2
+ * MessagePack serializer and deserializer.
3
+ *
4
+ * A TypeScript port of msgpack.js by Yves Goergen:
5
+ * https://github.com/ygoe/msgpack.js
6
+ * ported from commit 05733cfb43a2974cf669f0eb8693f43b548bdcd4 (2024-04-16) on `master`,
7
+ * which carries three fixes that the last npm release, `@ygoe/msgpack@1.0.3`, does not.
8
+ * Every change made to the upstream logic is listed in this package's README, section
9
+ * "Provenance and credits".
10
+ *
11
+ * Original work: Copyright © 2019, Yves Goergen, https://unclassified.software/source/msgpack-js
12
+ * TypeScript port and modifications: Copyright (c) 2026 statewalker
13
+ *
14
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
15
+ * associated documentation files (the “Software”), to deal in the Software without restriction,
16
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute,
17
+ * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
18
+ * furnished to do so, subject to the following conditions:
19
+ *
20
+ * The above copyright notice and this permission notice shall be included in all copies or
21
+ * substantial portions of the Software.
22
+ *
23
+ * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
24
+ * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
26
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
+ */
29
+ /** Options for {@link serialize}. */
30
+ export interface SerializeOptions {
31
+ /**
32
+ * Treat `data` as an array of values and concatenate their encodings, one MessagePack document
33
+ * after another, instead of encoding the array itself. Default: `false`.
34
+ */
35
+ multiple?: boolean;
36
+ /**
37
+ * What to write in place of a value whose type cannot be serialized (a function, a symbol, a
38
+ * bigint): either the replacement value itself, or a function that returns one given the
39
+ * original. When absent, such a value throws.
40
+ */
41
+ invalidTypeReplacement?: unknown;
42
+ }
43
+ /** Options for {@link deserialize}. */
44
+ export interface DeserializeOptions {
45
+ /**
46
+ * Read every concatenated MessagePack document in the input and return them as an array.
47
+ * Default: `false` — read one document and ignore any bytes after it.
48
+ */
49
+ multiple?: boolean;
50
+ }
51
+ /** The byte shapes {@link deserialize} accepts. */
52
+ export type MsgpackInput = Uint8Array | ArrayBuffer | ArrayLike<number>;
53
+ /** An extension value whose type this implementation does not interpret (anything but a timestamp). */
54
+ export interface MsgpackExtension {
55
+ type: number;
56
+ data: Uint8Array;
57
+ }
58
+ /**
59
+ * Serializes a value to a MessagePack byte array.
60
+ *
61
+ * The result is a view over a larger internal buffer; send the view, not its `.buffer`.
62
+ */
63
+ export declare function serialize(data: unknown, options?: SerializeOptions): Uint8Array<ArrayBuffer>;
64
+ /**
65
+ * Deserializes a MessagePack byte array to a value.
66
+ *
67
+ * `bin` values are returned as `Uint8Array` views into the input, not copies.
68
+ */
69
+ export declare function deserialize(input: MsgpackInput, options?: DeserializeOptions): unknown;
70
+ //# sourceMappingURL=msgpack-core.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"msgpack-core.d.ts","sourceRoot":"","sources":["../src/msgpack-core.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,qCAAqC;AACrC,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;OAIG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAClC;AAED,uCAAuC;AACvC,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,mDAAmD;AACnD,MAAM,MAAM,YAAY,GAAG,UAAU,GAAG,WAAW,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;AAExE,uGAAuG;AACvG,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,UAAU,CAAC;CAClB;AAID;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,UAAU,CAAC,WAAW,CAAC,CAmQ5F;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAoNtF"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Encode each value as a length-prefixed msgpack frame.
3
+ * Frame format: [4-byte big-endian length][msgpack bytes]
4
+ *
5
+ * The input may be synchronous (an array, a generator) or asynchronous.
6
+ */
7
+ export declare function encodeMsgpack<T>(input: Iterable<T> | AsyncIterable<T>): AsyncGenerator<Uint8Array>;
8
+ /**
9
+ * Decode length-prefixed msgpack frames, reassembling across chunk boundaries.
10
+ *
11
+ * The input may be synchronous (an array of chunks) or asynchronous.
12
+ */
13
+ export declare function decodeMsgpack<T>(input: Iterable<Uint8Array> | AsyncIterable<Uint8Array>): AsyncGenerator<T>;
14
+ /**
15
+ * Encode each Float32Array as a msgpack frame.
16
+ * The Float32Array is converted to a Uint8Array view (zero-copy) before encoding as msgpack bin.
17
+ *
18
+ * The input may be synchronous (an array, a generator) or asynchronous.
19
+ */
20
+ export declare function encodeFloat32Arrays(input: Iterable<Float32Array> | AsyncIterable<Float32Array>): AsyncGenerator<Uint8Array>;
21
+ /**
22
+ * Decode msgpack frames back to Float32Array.
23
+ * Each frame contains a msgpack bin value (Uint8Array), reinterpreted as Float32Array.
24
+ *
25
+ * The input may be synchronous (an array of chunks) or asynchronous.
26
+ */
27
+ export declare function decodeFloat32Arrays(input: Iterable<Uint8Array> | AsyncIterable<Uint8Array>): AsyncGenerator<Float32Array>;
28
+ //# sourceMappingURL=msgpack.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"msgpack.d.ts","sourceRoot":"","sources":["../src/msgpack.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAuB,aAAa,CAAC,CAAC,EACpC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,GACpC,cAAc,CAAC,UAAU,CAAC,CAS5B;AAED;;;;GAIG;AACH,wBAAuB,aAAa,CAAC,CAAC,EACpC,KAAK,EAAE,QAAQ,CAAC,UAAU,CAAC,GAAG,aAAa,CAAC,UAAU,CAAC,GACtD,cAAc,CAAC,CAAC,CAAC,CAgBnB;AAED;;;;;GAKG;AACH,wBAAuB,mBAAmB,CACxC,KAAK,EAAE,QAAQ,CAAC,YAAY,CAAC,GAAG,aAAa,CAAC,YAAY,CAAC,GAC1D,cAAc,CAAC,UAAU,CAAC,CAU5B;AAED;;;;;GAKG;AACH,wBAAuB,mBAAmB,CACxC,KAAK,EAAE,QAAQ,CAAC,UAAU,CAAC,GAAG,aAAa,CAAC,UAAU,CAAC,GACtD,cAAc,CAAC,YAAY,CAAC,CAK9B"}
@@ -0,0 +1,22 @@
1
+ import type { PortCodec } from "@statewalker/webrun-rpc";
2
+ /**
3
+ * For ports whose messages are bytes — a WebSocket, a WebRTC data channel, a
4
+ * LiveKit data packet.
5
+ *
6
+ * One envelope becomes one msgpack frame and one `postMessage`. There is no
7
+ * length prefix, because every transport this codec targets preserves message
8
+ * boundaries; adding one would be redundant framing on a transport that
9
+ * already frames. (`encodeMsgpack`/`decodeMsgpack` in this package *do* carry
10
+ * a length prefix — they are a stream codec for a transport with no
11
+ * boundaries, and are a different thing.)
12
+ *
13
+ * The transfer list is deliberately ignored: after encoding, the payload is
14
+ * inside the bytes, so there is nothing left to hand over.
15
+ *
16
+ * **Not interchangeable with `structuredCodec` in one respect:** msgpack drops
17
+ * object keys whose value is `undefined`, where structured clone preserves
18
+ * them. Nothing layer 2 sends depends on that distinction today, and it must
19
+ * not come to — see spec D16.
20
+ */
21
+ export declare const msgpackCodec: PortCodec;
22
+ //# sourceMappingURL=port-codec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"port-codec.d.ts","sourceRoot":"","sources":["../src/port-codec.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAgB,MAAM,yBAAyB,CAAC;AA2BvE;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,YAAY,EAAE,SAmB1B,CAAC"}
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@statewalker/webrun-msgpack",
3
- "version": "0.1.1",
3
+ "version": "0.3.0",
4
4
  "private": false,
5
5
  "type": "module",
6
- "description": "Length-prefixed MessagePack frame codec for async iterables. Streams-safe encode/decode for values and Float32Arrays.",
6
+ "description": "MessagePack for the wire, with no runtime dependencies: serialize/deserialize (a TypeScript port of msgpack.js), a length-prefixed stream codec for iterables (values and Float32Arrays), and msgpackCodec, a PortCodec that carries webrun-rpc port envelopes over a byte transport.",
7
7
  "homepage": "https://github.com/statewalker/webrun-wire",
8
8
  "author": {
9
9
  "name": "Mikhail Kotelnikov",
@@ -16,33 +16,41 @@
16
16
  "directory": "packages/webrun-msgpack"
17
17
  },
18
18
  "exports": {
19
- ".": "./src/index.ts"
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "import": "./dist/index.js"
22
+ }
20
23
  },
21
24
  "files": [
22
25
  "dist",
23
26
  "src"
24
27
  ],
25
28
  "dependencies": {
26
- "@ygoe/msgpack": "^1.0.3"
29
+ "@statewalker/webrun-rpc": "0.4.0"
27
30
  },
28
31
  "devDependencies": {
32
+ "@biomejs/biome": "^2.5.8",
29
33
  "rimraf": "^6.1.3",
30
- "tsdown": "^0.22.14",
34
+ "rolldown": "^1.2.4",
31
35
  "typescript": "^7.0.2",
32
- "vitest": "^4.1.10"
36
+ "vitest": "^4.1.10",
37
+ "@statewalker/webrun-streams": "0.2.0",
38
+ "@statewalker/webrun-streams-conformance": "0.2.0"
33
39
  },
34
40
  "sideEffects": false,
35
41
  "publishConfig": {
36
42
  "access": "public"
37
43
  },
44
+ "types": "./dist/index.d.ts",
38
45
  "scripts": {
39
- "build": "tsdown",
46
+ "build": "rimraf dist && rolldown -c && tsc --emitDeclarationOnly --declaration",
40
47
  "dev": "tsdown --watch",
41
48
  "test": "vitest run",
42
49
  "test:watch": "vitest",
43
50
  "typecheck": "tsc --noEmit",
51
+ "typecheck:tests": "tsc -p tsconfig.tests.json",
44
52
  "clean": "rimraf dist",
45
- "lint": "biome check --write .",
53
+ "lint": "biome check src tests",
46
54
  "format": "biome format --write ."
47
55
  }
48
56
  }
package/src/index.ts CHANGED
@@ -4,3 +4,12 @@ export {
4
4
  encodeFloat32Arrays,
5
5
  encodeMsgpack,
6
6
  } from "./msgpack.js";
7
+ export {
8
+ type DeserializeOptions,
9
+ deserialize,
10
+ type MsgpackExtension,
11
+ type MsgpackInput,
12
+ type SerializeOptions,
13
+ serialize,
14
+ } from "./msgpack-core.js";
15
+ export { msgpackCodec } from "./port-codec.js";