@moqtap/codec 0.1.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.
Files changed (71) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +95 -0
  3. package/dist/chunk-23YG7F46.js +764 -0
  4. package/dist/chunk-2NARXGVA.cjs +194 -0
  5. package/dist/chunk-3BSZ55L3.cjs +307 -0
  6. package/dist/chunk-5WFXFLL4.cjs +1185 -0
  7. package/dist/chunk-DC4L6ZIT.js +307 -0
  8. package/dist/chunk-GDRGWFEK.cjs +498 -0
  9. package/dist/chunk-IQPDRQVC.js +1185 -0
  10. package/dist/chunk-QYG6KGOV.cjs +101 -0
  11. package/dist/chunk-UOBWHJA5.js +101 -0
  12. package/dist/chunk-WNTXF3DE.cjs +764 -0
  13. package/dist/chunk-YBSEOSSP.js +194 -0
  14. package/dist/chunk-YPXLV5YK.js +498 -0
  15. package/dist/codec-CTvFtQQI.d.cts +86 -0
  16. package/dist/codec-qPzfmLNu.d.ts +86 -0
  17. package/dist/draft14-session.cjs +6 -0
  18. package/dist/draft14-session.d.cts +8 -0
  19. package/dist/draft14-session.d.ts +8 -0
  20. package/dist/draft14-session.js +6 -0
  21. package/dist/draft14.cjs +121 -0
  22. package/dist/draft14.d.cts +96 -0
  23. package/dist/draft14.d.ts +96 -0
  24. package/dist/draft14.js +121 -0
  25. package/dist/draft7-session.cjs +7 -0
  26. package/dist/draft7-session.d.cts +7 -0
  27. package/dist/draft7-session.d.ts +7 -0
  28. package/dist/draft7-session.js +7 -0
  29. package/dist/draft7.cjs +60 -0
  30. package/dist/draft7.d.cts +72 -0
  31. package/dist/draft7.d.ts +72 -0
  32. package/dist/draft7.js +60 -0
  33. package/dist/index.cjs +40 -0
  34. package/dist/index.d.cts +40 -0
  35. package/dist/index.d.ts +40 -0
  36. package/dist/index.js +40 -0
  37. package/dist/session-types-B9NIf7_F.d.ts +101 -0
  38. package/dist/session-types-CCo-oA-d.d.cts +101 -0
  39. package/dist/session.cjs +27 -0
  40. package/dist/session.d.cts +24 -0
  41. package/dist/session.d.ts +24 -0
  42. package/dist/session.js +27 -0
  43. package/dist/types-CIk5W10V.d.cts +249 -0
  44. package/dist/types-CIk5W10V.d.ts +249 -0
  45. package/dist/types-ClXELFGN.d.cts +241 -0
  46. package/dist/types-ClXELFGN.d.ts +241 -0
  47. package/package.json +84 -0
  48. package/src/core/buffer-reader.ts +107 -0
  49. package/src/core/buffer-writer.ts +91 -0
  50. package/src/core/errors.ts +1 -0
  51. package/src/core/session-types.ts +103 -0
  52. package/src/core/types.ts +363 -0
  53. package/src/drafts/draft07/announce-fsm.ts +2 -0
  54. package/src/drafts/draft07/codec.ts +874 -0
  55. package/src/drafts/draft07/index.ts +70 -0
  56. package/src/drafts/draft07/messages.ts +44 -0
  57. package/src/drafts/draft07/parameters.ts +12 -0
  58. package/src/drafts/draft07/rules.ts +75 -0
  59. package/src/drafts/draft07/session-fsm.ts +353 -0
  60. package/src/drafts/draft07/session.ts +21 -0
  61. package/src/drafts/draft07/subscription-fsm.ts +3 -0
  62. package/src/drafts/draft07/varint.ts +23 -0
  63. package/src/drafts/draft14/codec.ts +1330 -0
  64. package/src/drafts/draft14/index.ts +132 -0
  65. package/src/drafts/draft14/messages.ts +76 -0
  66. package/src/drafts/draft14/rules.ts +70 -0
  67. package/src/drafts/draft14/session-fsm.ts +480 -0
  68. package/src/drafts/draft14/session.ts +26 -0
  69. package/src/drafts/draft14/types.ts +365 -0
  70. package/src/index.ts +85 -0
  71. package/src/session.ts +58 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 moqtap
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,95 @@
1
+ # @moqtap/codec
2
+
3
+ MoQT (Media over QUIC Transport) wire-format codec and session state machine for JavaScript/TypeScript.
4
+
5
+ - Multi-draft support (draft-07, draft-14)
6
+ - Stateless encode/decode of all MoQT control messages and data streams
7
+ - Protocol session state machine with FSM-based validation
8
+ - Zero runtime dependencies
9
+ - Works in Node.js, Bun, and browsers
10
+ - Full TypeScript types with discriminated unions
11
+
12
+ ## Install
13
+
14
+ ```bash
15
+ npm install @moqtap/codec
16
+ ```
17
+
18
+ ## Quick Start
19
+
20
+ MoQT is pre-RFC, so a draft version must always be specified. Use draft-scoped imports for the best experience:
21
+
22
+ ```typescript
23
+ import { createDraft07Codec } from '@moqtap/codec/draft7';
24
+
25
+ const codec = createDraft07Codec();
26
+
27
+ // Decode a message from bytes
28
+ const result = codec.decodeMessage(bytes);
29
+ if (result.ok) {
30
+ console.log(result.value.type); // e.g. 'subscribe'
31
+ }
32
+
33
+ // Encode a message to bytes
34
+ const encoded = codec.encodeMessage({
35
+ type: 'client_setup',
36
+ supportedVersions: [0xff000007n],
37
+ parameters: new Map(),
38
+ });
39
+ ```
40
+
41
+ Or use the factory if your application supports multiple drafts:
42
+
43
+ ```typescript
44
+ import { createCodec } from '@moqtap/codec';
45
+
46
+ const codec = createCodec({ draft: '07' }); // or '14'
47
+ ```
48
+
49
+ ## Subpath Exports
50
+
51
+ | Import path | Description |
52
+ |---|---|
53
+ | `@moqtap/codec` | Factory + shared types (`createCodec({ draft })`) |
54
+ | `@moqtap/codec/draft7` | Draft-07 codec |
55
+ | `@moqtap/codec/draft14` | Draft-14 codec |
56
+ | `@moqtap/codec/session` | Session state machine factory |
57
+ | `@moqtap/codec/draft7/session` | Draft-07 session |
58
+ | `@moqtap/codec/draft14/session` | Draft-14 session |
59
+
60
+ > **Note:** A default (versionless) codec will be available once the MoQT specification reaches RFC status. Until then, always specify a draft version.
61
+
62
+ ## Draft-Specific Imports
63
+
64
+ For applications targeting a single draft version:
65
+
66
+ ```typescript
67
+ // Draft-07
68
+ import { createDraft07Codec } from '@moqtap/codec/draft7';
69
+ import { createDraft07SessionState } from '@moqtap/codec/draft7/session';
70
+
71
+ // Draft-14
72
+ import { createDraft14Codec } from '@moqtap/codec/draft14';
73
+ import { createDraft14SessionState } from '@moqtap/codec/draft14/session';
74
+ ```
75
+
76
+ ## Session State Machine
77
+
78
+ Validate protocol message sequences without transport coupling:
79
+
80
+ ```typescript
81
+ import { createDraft07SessionState } from '@moqtap/codec/draft7/session';
82
+ import { createDraft07Codec } from '@moqtap/codec/draft7';
83
+
84
+ const codec = createDraft07Codec();
85
+ const session = createDraft07SessionState({ codec, role: 'client' });
86
+
87
+ const result = session.receive(incomingMessage);
88
+ if (!result.ok) {
89
+ console.error('Protocol violation:', result.violation);
90
+ }
91
+ ```
92
+
93
+ ## License
94
+
95
+ MIT