@moqtap/codec 0.6.0 → 0.8.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 (82) hide show
  1. package/README.md +28 -2
  2. package/dist/{chunk-CXFAQKL3.js → chunk-23KRITJ6.js} +1 -1
  3. package/dist/{chunk-JL3NEW3O.cjs → chunk-4XLYCT5Q.cjs} +90 -1
  4. package/dist/{chunk-DLSGOZ6P.js → chunk-5XZKO2U5.js} +34 -34
  5. package/dist/{chunk-62LYLROG.js → chunk-APTV6F72.js} +35 -35
  6. package/dist/{chunk-JB5VDJ2V.cjs → chunk-B56AG5HU.cjs} +37 -37
  7. package/dist/{chunk-JTRU76JN.cjs → chunk-BQHLUT37.cjs} +109 -111
  8. package/dist/{chunk-4HBKHNU2.cjs → chunk-CZNW3R5E.cjs} +37 -37
  9. package/dist/{chunk-OGZTQA24.cjs → chunk-EQAYMCXO.cjs} +64 -64
  10. package/dist/{chunk-HYI6LFMD.js → chunk-HEO2JG6C.js} +1 -1
  11. package/dist/{chunk-UP4XPH4J.js → chunk-I55J3KXD.js} +31 -31
  12. package/dist/{chunk-HZHSO7EW.cjs → chunk-IDV2JYJ6.cjs} +39 -39
  13. package/dist/{chunk-BAG6YWCP.cjs → chunk-IEJULBKB.cjs} +63 -63
  14. package/dist/{chunk-Y6KCSM3V.js → chunk-IJAF6PAY.js} +1 -1
  15. package/dist/{chunk-WMJVSBBE.cjs → chunk-J3ASFPCX.cjs} +57 -57
  16. package/dist/{chunk-Q5D6OW6Q.js → chunk-JJEN2VG5.js} +51 -53
  17. package/dist/{chunk-COWGGUL4.js → chunk-JKMYAUGY.js} +1 -1
  18. package/dist/{chunk-SIYYMFCC.cjs → chunk-KCH4BQXK.cjs} +37 -37
  19. package/dist/{chunk-VOU7PNHI.js → chunk-KLPWJU6W.js} +89 -0
  20. package/dist/{chunk-NZ7GYEMT.js → chunk-KNLPX3YA.js} +1 -1
  21. package/dist/{chunk-A33U4WVS.cjs → chunk-KTVN4P6J.cjs} +67 -67
  22. package/dist/{chunk-7KBAWOBA.js → chunk-KYVTM5VI.js} +1 -1
  23. package/dist/{chunk-RZ3UML47.js → chunk-MD2OA7SE.js} +1 -1
  24. package/dist/{chunk-MSG2FXJ2.cjs → chunk-MH7537FB.cjs} +68 -68
  25. package/dist/{chunk-SHMA4PBY.js → chunk-N2V7Z37J.js} +1 -1
  26. package/dist/{chunk-HO44OANK.cjs → chunk-QGIHC6BA.cjs} +36 -36
  27. package/dist/{chunk-PKEOQSSZ.cjs → chunk-RIIA4ALQ.cjs} +37 -37
  28. package/dist/{chunk-XZE5R57R.cjs → chunk-VZHL2U2N.cjs} +37 -37
  29. package/dist/{chunk-RW4UG7CN.js → chunk-XHAP2YST.js} +1 -1
  30. package/dist/{codec-B1snaM9L.d.cts → codec-BnamSx7L.d.cts} +1 -1
  31. package/dist/{codec-D49OofBr.d.ts → codec-CFhUGTu2.d.ts} +1 -1
  32. package/dist/draft07.cjs +4 -4
  33. package/dist/draft07.js +2 -2
  34. package/dist/draft08.cjs +3 -3
  35. package/dist/draft08.js +2 -2
  36. package/dist/draft09.cjs +3 -3
  37. package/dist/draft09.js +2 -2
  38. package/dist/draft10.cjs +3 -3
  39. package/dist/draft10.js +2 -2
  40. package/dist/draft11.cjs +3 -3
  41. package/dist/draft11.js +2 -2
  42. package/dist/draft12.cjs +3 -3
  43. package/dist/draft12.js +2 -2
  44. package/dist/draft13.cjs +3 -3
  45. package/dist/draft13.js +2 -2
  46. package/dist/draft14-session.d.cts +1 -1
  47. package/dist/draft14-session.d.ts +1 -1
  48. package/dist/draft14.cjs +3 -3
  49. package/dist/draft14.d.cts +3 -3
  50. package/dist/draft14.d.ts +3 -3
  51. package/dist/draft14.js +2 -2
  52. package/dist/draft15.cjs +3 -3
  53. package/dist/draft15.js +2 -2
  54. package/dist/draft16.cjs +3 -3
  55. package/dist/draft16.js +2 -2
  56. package/dist/draft17.cjs +3 -3
  57. package/dist/draft17.js +2 -2
  58. package/dist/draft18.cjs +3 -3
  59. package/dist/draft18.js +2 -2
  60. package/dist/draft19.cjs +3 -3
  61. package/dist/draft19.js +2 -2
  62. package/dist/index.cjs +81 -29
  63. package/dist/index.d.cts +73 -3
  64. package/dist/index.d.ts +73 -3
  65. package/dist/index.js +67 -15
  66. package/dist/session.d.cts +1 -1
  67. package/dist/session.d.ts +1 -1
  68. package/dist/{types-DjmrHp_s.d.cts → types-CVeKIk7A.d.cts} +29 -21
  69. package/dist/{types-DjmrHp_s.d.ts → types-CVeKIk7A.d.ts} +29 -21
  70. package/package.json +2 -2
  71. package/src/core/accessors.ts +120 -0
  72. package/src/core/buffer-reader.ts +74 -2
  73. package/src/core/buffer-writer.ts +56 -4
  74. package/src/drafts/draft14/codec.ts +50 -52
  75. package/src/drafts/draft14/types.ts +31 -23
  76. package/src/drafts/draft17/codec.ts +2 -2
  77. package/src/drafts/draft17/data-streams.ts +2 -2
  78. package/src/drafts/draft18/codec.ts +2 -2
  79. package/src/drafts/draft18/data-streams.ts +2 -2
  80. package/src/drafts/draft19/codec.ts +2 -2
  81. package/src/drafts/draft19/data-streams.ts +2 -2
  82. package/src/index.ts +8 -0
package/dist/index.cjs CHANGED
@@ -1,45 +1,93 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
2
2
 
3
- var _chunkA33U4WVScjs = require('./chunk-A33U4WVS.cjs');
3
+ var _chunkKTVN4P6Jcjs = require('./chunk-KTVN4P6J.cjs');
4
4
 
5
5
 
6
- var _chunkMSG2FXJ2cjs = require('./chunk-MSG2FXJ2.cjs');
6
+ var _chunkMH7537FBcjs = require('./chunk-MH7537FB.cjs');
7
7
 
8
8
 
9
- var _chunkJTRU76JNcjs = require('./chunk-JTRU76JN.cjs');
9
+ var _chunkBQHLUT37cjs = require('./chunk-BQHLUT37.cjs');
10
10
 
11
11
 
12
- var _chunkWMJVSBBEcjs = require('./chunk-WMJVSBBE.cjs');
12
+ var _chunkJ3ASFPCXcjs = require('./chunk-J3ASFPCX.cjs');
13
13
 
14
14
 
15
- var _chunkBAG6YWCPcjs = require('./chunk-BAG6YWCP.cjs');
15
+ var _chunkIEJULBKBcjs = require('./chunk-IEJULBKB.cjs');
16
16
 
17
17
 
18
- var _chunkOGZTQA24cjs = require('./chunk-OGZTQA24.cjs');
18
+ var _chunkEQAYMCXOcjs = require('./chunk-EQAYMCXO.cjs');
19
19
 
20
20
 
21
- var _chunkPKEOQSSZcjs = require('./chunk-PKEOQSSZ.cjs');
21
+ var _chunkRIIA4ALQcjs = require('./chunk-RIIA4ALQ.cjs');
22
22
 
23
23
 
24
- var _chunkHO44OANKcjs = require('./chunk-HO44OANK.cjs');
24
+ var _chunkQGIHC6BAcjs = require('./chunk-QGIHC6BA.cjs');
25
25
 
26
26
 
27
- var _chunkJB5VDJ2Vcjs = require('./chunk-JB5VDJ2V.cjs');
27
+ var _chunkB56AG5HUcjs = require('./chunk-B56AG5HU.cjs');
28
28
 
29
29
 
30
- var _chunkSIYYMFCCcjs = require('./chunk-SIYYMFCC.cjs');
30
+ var _chunkKCH4BQXKcjs = require('./chunk-KCH4BQXK.cjs');
31
31
 
32
32
 
33
- var _chunkHZHSO7EWcjs = require('./chunk-HZHSO7EW.cjs');
33
+ var _chunkIDV2JYJ6cjs = require('./chunk-IDV2JYJ6.cjs');
34
34
 
35
35
 
36
- var _chunkXZE5R57Rcjs = require('./chunk-XZE5R57R.cjs');
36
+ var _chunkVZHL2U2Ncjs = require('./chunk-VZHL2U2N.cjs');
37
37
 
38
38
 
39
- var _chunk4HBKHNU2cjs = require('./chunk-4HBKHNU2.cjs');
39
+ var _chunkCZNW3R5Ecjs = require('./chunk-CZNW3R5E.cjs');
40
40
 
41
41
 
42
- var _chunkJL3NEW3Ocjs = require('./chunk-JL3NEW3O.cjs');
42
+ var _chunk4XLYCT5Qcjs = require('./chunk-4XLYCT5Q.cjs');
43
+
44
+ // src/core/accessors.ts
45
+ function pick(msg, names) {
46
+ for (const name of names) {
47
+ const value = msg[name];
48
+ if (value != null) return value;
49
+ }
50
+ return void 0;
51
+ }
52
+ function bigintOf(value) {
53
+ if (value == null) return void 0;
54
+ if (typeof value === "bigint") return value;
55
+ if (typeof value === "number" || typeof value === "string") {
56
+ try {
57
+ return BigInt(value);
58
+ } catch (e) {
59
+ return void 0;
60
+ }
61
+ }
62
+ return void 0;
63
+ }
64
+ function requestIdOf(msg) {
65
+ return bigintOf(pick(msg, ["request_id", "requestId", "subscribe_id", "subscribeId"]));
66
+ }
67
+ function trackAliasOf(msg) {
68
+ return bigintOf(pick(msg, ["track_alias", "trackAlias"]));
69
+ }
70
+ function trackOf(msg) {
71
+ const source = _nullishCoalesce(pick(msg, ["standalone"]), () => ( msg));
72
+ const name = pick(source, ["track_name", "trackName"]);
73
+ if (typeof name !== "string") return void 0;
74
+ const namespace = pick(source, ["track_namespace", "trackNamespace"]);
75
+ return {
76
+ namespace: Array.isArray(namespace) ? namespace.map(String) : [],
77
+ name
78
+ };
79
+ }
80
+ function joiningRequestIdOf(msg) {
81
+ const source = _nullishCoalesce(pick(msg, ["joining"]), () => ( msg));
82
+ return bigintOf(
83
+ pick(source, [
84
+ "joining_request_id",
85
+ "joiningRequestId",
86
+ "joining_subscribe_id",
87
+ "joiningSubscribeId"
88
+ ])
89
+ );
90
+ }
43
91
 
44
92
  // src/index.ts
45
93
  var DRAFT_VERSIONS = {
@@ -67,31 +115,31 @@ Supported draft values: ${Object.keys(DRAFT_VERSIONS).join(", ")}`
67
115
  }
68
116
  switch (options.draft) {
69
117
  case "07":
70
- return _chunkHZHSO7EWcjs.createDraft07Codec.call(void 0, );
118
+ return _chunkIDV2JYJ6cjs.createDraft07Codec.call(void 0, );
71
119
  case "08":
72
- return _chunkXZE5R57Rcjs.createDraft08Codec.call(void 0, );
120
+ return _chunkVZHL2U2Ncjs.createDraft08Codec.call(void 0, );
73
121
  case "09":
74
- return _chunk4HBKHNU2cjs.createDraft09Codec.call(void 0, );
122
+ return _chunkCZNW3R5Ecjs.createDraft09Codec.call(void 0, );
75
123
  case "10":
76
- return _chunkPKEOQSSZcjs.createDraft10Codec.call(void 0, );
124
+ return _chunkRIIA4ALQcjs.createDraft10Codec.call(void 0, );
77
125
  case "11":
78
- return _chunkHO44OANKcjs.createDraft11Codec.call(void 0, );
126
+ return _chunkQGIHC6BAcjs.createDraft11Codec.call(void 0, );
79
127
  case "12":
80
- return _chunkJB5VDJ2Vcjs.createDraft12Codec.call(void 0, );
128
+ return _chunkB56AG5HUcjs.createDraft12Codec.call(void 0, );
81
129
  case "13":
82
- return _chunkSIYYMFCCcjs.createDraft13Codec.call(void 0, );
130
+ return _chunkKCH4BQXKcjs.createDraft13Codec.call(void 0, );
83
131
  case "14":
84
- return _chunkJTRU76JNcjs.createDraft14Codec.call(void 0, );
132
+ return _chunkBQHLUT37cjs.createDraft14Codec.call(void 0, );
85
133
  case "15":
86
- return _chunkWMJVSBBEcjs.createDraft15Codec.call(void 0, );
134
+ return _chunkJ3ASFPCXcjs.createDraft15Codec.call(void 0, );
87
135
  case "16":
88
- return _chunkBAG6YWCPcjs.createDraft16Codec.call(void 0, );
136
+ return _chunkIEJULBKBcjs.createDraft16Codec.call(void 0, );
89
137
  case "17":
90
- return _chunkOGZTQA24cjs.createDraft17Codec.call(void 0, );
138
+ return _chunkEQAYMCXOcjs.createDraft17Codec.call(void 0, );
91
139
  case "18":
92
- return _chunkA33U4WVScjs.createDraft18Codec.call(void 0, );
140
+ return _chunkKTVN4P6Jcjs.createDraft18Codec.call(void 0, );
93
141
  case "19":
94
- return _chunkMSG2FXJ2cjs.createDraft19Codec.call(void 0, );
142
+ return _chunkMH7537FBcjs.createDraft19Codec.call(void 0, );
95
143
  default:
96
144
  throw new Error(`Unsupported draft: ${draft}`);
97
145
  }
@@ -100,4 +148,8 @@ Supported draft values: ${Object.keys(DRAFT_VERSIONS).join(", ")}`
100
148
 
101
149
 
102
150
 
103
- exports.DRAFT_VERSIONS = DRAFT_VERSIONS; exports.DecodeError = _chunkJL3NEW3Ocjs.DecodeError; exports.createCodec = createCodec;
151
+
152
+
153
+
154
+
155
+ exports.DRAFT_VERSIONS = DRAFT_VERSIONS; exports.DecodeError = _chunk4XLYCT5Qcjs.DecodeError; exports.createCodec = createCodec; exports.joiningRequestIdOf = joiningRequestIdOf; exports.requestIdOf = requestIdOf; exports.trackAliasOf = trackAliasOf; exports.trackOf = trackOf;
package/dist/index.d.cts CHANGED
@@ -7,7 +7,7 @@ import { D as Draft10Codec } from './codec-BOyrk_C9.cjs';
7
7
  import { D as Draft11Codec } from './codec-cou9XBMF.cjs';
8
8
  import { D as Draft12Codec } from './codec-BOtv3R5j.cjs';
9
9
  import { D as Draft13Codec } from './codec-hvkJfCF5.cjs';
10
- import { D as Draft14Codec } from './codec-B1snaM9L.cjs';
10
+ import { D as Draft14Codec } from './codec-BnamSx7L.cjs';
11
11
  import { D as Draft15Codec } from './codec-BqqoYdh_.cjs';
12
12
  import { D as Draft16Codec } from './codec-CyApDKwf.cjs';
13
13
  import { D as Draft17Codec } from './codec-NMsTK0GX.cjs';
@@ -20,13 +20,83 @@ import './types-0IWbU9Z_.cjs';
20
20
  import './types-Ck45Ex5S.cjs';
21
21
  import './types-Bio-91Rt.cjs';
22
22
  import './types-CXlSn0I9.cjs';
23
- import './types-DjmrHp_s.cjs';
23
+ import './types-CVeKIk7A.cjs';
24
24
  import './types-CPaYBsMG.cjs';
25
25
  import './types-Cm9fjeYC.cjs';
26
26
  import './types-D9eiB_9A.cjs';
27
27
  import './types-Cqp10JtB.cjs';
28
28
  import './types-zHgCS6o5.cjs';
29
29
 
30
+ /**
31
+ * Draft-agnostic readers for decoded control messages.
32
+ *
33
+ * The codec keeps one message model per draft, because the drafts genuinely
34
+ * disagree: a track alias travels in SUBSCRIBE through draft-11 and in
35
+ * SUBSCRIBE_OK from draft-12; a request was a `subscribe_id` through draft-10
36
+ * and a `request_id` after it; a joining FETCH points at a
37
+ * `joining_subscribe_id` through draft-13 and a `joining_request_id` after it.
38
+ * Faithfulness to each draft is the point of the codec.
39
+ *
40
+ * What consumers usually want is the answer, not the archaeology — and every
41
+ * one of them that has asked has written the same field-spelling ladder by
42
+ * hand. These accessors are that ladder, written once.
43
+ *
44
+ * Each returns `undefined` when the message does not carry the field, which
45
+ * includes the cases where the draft has not assigned it yet: `trackAliasOf`
46
+ * on a draft-14 SUBSCRIBE is `undefined` because the publisher has not chosen
47
+ * the alias until SUBSCRIBE_OK.
48
+ *
49
+ * Both snake_case (what this codec emits) and camelCase spellings are read, so
50
+ * these also work on messages recovered from qlog-style traces written by
51
+ * other tools.
52
+ */
53
+ /** Any decoded control message, from any draft. */
54
+ type AnyMessage = Readonly<Record<string, unknown>>;
55
+ /** A track's full identity: the namespace tuple plus the name within it. */
56
+ interface TrackIdentity {
57
+ readonly namespace: string[];
58
+ readonly name: string;
59
+ }
60
+ /**
61
+ * The request this message belongs to.
62
+ *
63
+ * Named `subscribe_id` through draft-10 and `request_id` from draft-11, when
64
+ * the id space widened to cover every request type rather than subscriptions
65
+ * alone.
66
+ *
67
+ * Returns `undefined` for draft-17+ responses, which carry no id at all: each
68
+ * request there has its own bidirectional stream, and that stream — not a
69
+ * field — is what ties a response to its request.
70
+ */
71
+ declare function requestIdOf(msg: AnyMessage): bigint | undefined;
72
+ /**
73
+ * The track alias this message assigns or refers to, if any.
74
+ *
75
+ * Which message carries it moved: SUBSCRIBE through draft-11, then SUBSCRIBE_OK
76
+ * from draft-12, when assigning the alias became the publisher's job. PUBLISH
77
+ * carries it alongside the track name in every draft that has PUBLISH.
78
+ */
79
+ declare function trackAliasOf(msg: AnyMessage): bigint | undefined;
80
+ /**
81
+ * The track this message names, or `undefined` if it names none.
82
+ *
83
+ * Covers SUBSCRIBE, PUBLISH, TRACK_STATUS and a standalone FETCH — whose track
84
+ * sits under `standalone` in most drafts and flat in draft-07, which predates
85
+ * joining fetch. A joining FETCH names no track of its own; use
86
+ * {@link joiningRequestIdOf} to find the request whose track it continues.
87
+ *
88
+ * PUBLISH_NAMESPACE and its relatives are namespace-only and yield
89
+ * `undefined`: a namespace is not a track.
90
+ */
91
+ declare function trackOf(msg: AnyMessage): TrackIdentity | undefined;
92
+ /**
93
+ * For a joining FETCH, the request whose track it continues.
94
+ *
95
+ * Spelled `joining_subscribe_id` through draft-13 and `joining_request_id`
96
+ * after it, nested under `joining` in every draft that has one.
97
+ */
98
+ declare function joiningRequestIdOf(msg: AnyMessage): bigint | undefined;
99
+
30
100
  /**
31
101
  * @moqtap/codec — MoQT wire-format codec
32
102
  *
@@ -91,4 +161,4 @@ declare function createCodec(options: CodecOptions & {
91
161
  */
92
162
  declare function createCodec(options: CodecOptions): Draft07Codec | Draft08Codec | Draft09Codec | Draft10Codec | Draft11Codec | Draft12Codec | Draft13Codec | Draft14Codec | Draft15Codec | Draft16Codec | Draft17Codec | Draft18Codec | Draft19Codec;
93
163
 
94
- export { CodecOptions, DRAFT_VERSIONS, createCodec };
164
+ export { type AnyMessage, CodecOptions, DRAFT_VERSIONS, type TrackIdentity, createCodec, joiningRequestIdOf, requestIdOf, trackAliasOf, trackOf };
package/dist/index.d.ts CHANGED
@@ -7,7 +7,7 @@ import { D as Draft10Codec } from './codec-BLYAy2OP.js';
7
7
  import { D as Draft11Codec } from './codec-DL0njGkL.js';
8
8
  import { D as Draft12Codec } from './codec-D47r_-Rl.js';
9
9
  import { D as Draft13Codec } from './codec-CWj5iTxA.js';
10
- import { D as Draft14Codec } from './codec-D49OofBr.js';
10
+ import { D as Draft14Codec } from './codec-CFhUGTu2.js';
11
11
  import { D as Draft15Codec } from './codec-BNS3gS77.js';
12
12
  import { D as Draft16Codec } from './codec-D2JbI2tp.js';
13
13
  import { D as Draft17Codec } from './codec-DJmV04i0.js';
@@ -20,13 +20,83 @@ import './types-0IWbU9Z_.js';
20
20
  import './types-Ck45Ex5S.js';
21
21
  import './types-Bio-91Rt.js';
22
22
  import './types-CXlSn0I9.js';
23
- import './types-DjmrHp_s.js';
23
+ import './types-CVeKIk7A.js';
24
24
  import './types-CPaYBsMG.js';
25
25
  import './types-Cm9fjeYC.js';
26
26
  import './types-D9eiB_9A.js';
27
27
  import './types-Cqp10JtB.js';
28
28
  import './types-zHgCS6o5.js';
29
29
 
30
+ /**
31
+ * Draft-agnostic readers for decoded control messages.
32
+ *
33
+ * The codec keeps one message model per draft, because the drafts genuinely
34
+ * disagree: a track alias travels in SUBSCRIBE through draft-11 and in
35
+ * SUBSCRIBE_OK from draft-12; a request was a `subscribe_id` through draft-10
36
+ * and a `request_id` after it; a joining FETCH points at a
37
+ * `joining_subscribe_id` through draft-13 and a `joining_request_id` after it.
38
+ * Faithfulness to each draft is the point of the codec.
39
+ *
40
+ * What consumers usually want is the answer, not the archaeology — and every
41
+ * one of them that has asked has written the same field-spelling ladder by
42
+ * hand. These accessors are that ladder, written once.
43
+ *
44
+ * Each returns `undefined` when the message does not carry the field, which
45
+ * includes the cases where the draft has not assigned it yet: `trackAliasOf`
46
+ * on a draft-14 SUBSCRIBE is `undefined` because the publisher has not chosen
47
+ * the alias until SUBSCRIBE_OK.
48
+ *
49
+ * Both snake_case (what this codec emits) and camelCase spellings are read, so
50
+ * these also work on messages recovered from qlog-style traces written by
51
+ * other tools.
52
+ */
53
+ /** Any decoded control message, from any draft. */
54
+ type AnyMessage = Readonly<Record<string, unknown>>;
55
+ /** A track's full identity: the namespace tuple plus the name within it. */
56
+ interface TrackIdentity {
57
+ readonly namespace: string[];
58
+ readonly name: string;
59
+ }
60
+ /**
61
+ * The request this message belongs to.
62
+ *
63
+ * Named `subscribe_id` through draft-10 and `request_id` from draft-11, when
64
+ * the id space widened to cover every request type rather than subscriptions
65
+ * alone.
66
+ *
67
+ * Returns `undefined` for draft-17+ responses, which carry no id at all: each
68
+ * request there has its own bidirectional stream, and that stream — not a
69
+ * field — is what ties a response to its request.
70
+ */
71
+ declare function requestIdOf(msg: AnyMessage): bigint | undefined;
72
+ /**
73
+ * The track alias this message assigns or refers to, if any.
74
+ *
75
+ * Which message carries it moved: SUBSCRIBE through draft-11, then SUBSCRIBE_OK
76
+ * from draft-12, when assigning the alias became the publisher's job. PUBLISH
77
+ * carries it alongside the track name in every draft that has PUBLISH.
78
+ */
79
+ declare function trackAliasOf(msg: AnyMessage): bigint | undefined;
80
+ /**
81
+ * The track this message names, or `undefined` if it names none.
82
+ *
83
+ * Covers SUBSCRIBE, PUBLISH, TRACK_STATUS and a standalone FETCH — whose track
84
+ * sits under `standalone` in most drafts and flat in draft-07, which predates
85
+ * joining fetch. A joining FETCH names no track of its own; use
86
+ * {@link joiningRequestIdOf} to find the request whose track it continues.
87
+ *
88
+ * PUBLISH_NAMESPACE and its relatives are namespace-only and yield
89
+ * `undefined`: a namespace is not a track.
90
+ */
91
+ declare function trackOf(msg: AnyMessage): TrackIdentity | undefined;
92
+ /**
93
+ * For a joining FETCH, the request whose track it continues.
94
+ *
95
+ * Spelled `joining_subscribe_id` through draft-13 and `joining_request_id`
96
+ * after it, nested under `joining` in every draft that has one.
97
+ */
98
+ declare function joiningRequestIdOf(msg: AnyMessage): bigint | undefined;
99
+
30
100
  /**
31
101
  * @moqtap/codec — MoQT wire-format codec
32
102
  *
@@ -91,4 +161,4 @@ declare function createCodec(options: CodecOptions & {
91
161
  */
92
162
  declare function createCodec(options: CodecOptions): Draft07Codec | Draft08Codec | Draft09Codec | Draft10Codec | Draft11Codec | Draft12Codec | Draft13Codec | Draft14Codec | Draft15Codec | Draft16Codec | Draft17Codec | Draft18Codec | Draft19Codec;
93
163
 
94
- export { CodecOptions, DRAFT_VERSIONS, createCodec };
164
+ export { type AnyMessage, CodecOptions, DRAFT_VERSIONS, type TrackIdentity, createCodec, joiningRequestIdOf, requestIdOf, trackAliasOf, trackOf };
package/dist/index.js CHANGED
@@ -1,45 +1,93 @@
1
1
  import {
2
2
  createDraft18Codec
3
- } from "./chunk-DLSGOZ6P.js";
3
+ } from "./chunk-5XZKO2U5.js";
4
4
  import {
5
5
  createDraft19Codec
6
- } from "./chunk-62LYLROG.js";
6
+ } from "./chunk-APTV6F72.js";
7
7
  import {
8
8
  createDraft14Codec
9
- } from "./chunk-Q5D6OW6Q.js";
9
+ } from "./chunk-JJEN2VG5.js";
10
10
  import {
11
11
  createDraft15Codec
12
- } from "./chunk-RZ3UML47.js";
12
+ } from "./chunk-MD2OA7SE.js";
13
13
  import {
14
14
  createDraft16Codec
15
- } from "./chunk-HYI6LFMD.js";
15
+ } from "./chunk-HEO2JG6C.js";
16
16
  import {
17
17
  createDraft17Codec
18
- } from "./chunk-UP4XPH4J.js";
18
+ } from "./chunk-I55J3KXD.js";
19
19
  import {
20
20
  createDraft10Codec
21
- } from "./chunk-SHMA4PBY.js";
21
+ } from "./chunk-N2V7Z37J.js";
22
22
  import {
23
23
  createDraft11Codec
24
- } from "./chunk-COWGGUL4.js";
24
+ } from "./chunk-JKMYAUGY.js";
25
25
  import {
26
26
  createDraft12Codec
27
- } from "./chunk-NZ7GYEMT.js";
27
+ } from "./chunk-KNLPX3YA.js";
28
28
  import {
29
29
  createDraft13Codec
30
- } from "./chunk-CXFAQKL3.js";
30
+ } from "./chunk-23KRITJ6.js";
31
31
  import {
32
32
  createDraft07Codec
33
- } from "./chunk-7KBAWOBA.js";
33
+ } from "./chunk-KYVTM5VI.js";
34
34
  import {
35
35
  createDraft08Codec
36
- } from "./chunk-RW4UG7CN.js";
36
+ } from "./chunk-XHAP2YST.js";
37
37
  import {
38
38
  createDraft09Codec
39
- } from "./chunk-Y6KCSM3V.js";
39
+ } from "./chunk-IJAF6PAY.js";
40
40
  import {
41
41
  DecodeError
42
- } from "./chunk-VOU7PNHI.js";
42
+ } from "./chunk-KLPWJU6W.js";
43
+
44
+ // src/core/accessors.ts
45
+ function pick(msg, names) {
46
+ for (const name of names) {
47
+ const value = msg[name];
48
+ if (value != null) return value;
49
+ }
50
+ return void 0;
51
+ }
52
+ function bigintOf(value) {
53
+ if (value == null) return void 0;
54
+ if (typeof value === "bigint") return value;
55
+ if (typeof value === "number" || typeof value === "string") {
56
+ try {
57
+ return BigInt(value);
58
+ } catch {
59
+ return void 0;
60
+ }
61
+ }
62
+ return void 0;
63
+ }
64
+ function requestIdOf(msg) {
65
+ return bigintOf(pick(msg, ["request_id", "requestId", "subscribe_id", "subscribeId"]));
66
+ }
67
+ function trackAliasOf(msg) {
68
+ return bigintOf(pick(msg, ["track_alias", "trackAlias"]));
69
+ }
70
+ function trackOf(msg) {
71
+ const source = pick(msg, ["standalone"]) ?? msg;
72
+ const name = pick(source, ["track_name", "trackName"]);
73
+ if (typeof name !== "string") return void 0;
74
+ const namespace = pick(source, ["track_namespace", "trackNamespace"]);
75
+ return {
76
+ namespace: Array.isArray(namespace) ? namespace.map(String) : [],
77
+ name
78
+ };
79
+ }
80
+ function joiningRequestIdOf(msg) {
81
+ const source = pick(msg, ["joining"]) ?? msg;
82
+ return bigintOf(
83
+ pick(source, [
84
+ "joining_request_id",
85
+ "joiningRequestId",
86
+ "joining_subscribe_id",
87
+ "joiningSubscribeId"
88
+ ])
89
+ );
90
+ }
43
91
 
44
92
  // src/index.ts
45
93
  var DRAFT_VERSIONS = {
@@ -99,5 +147,9 @@ Supported draft values: ${Object.keys(DRAFT_VERSIONS).join(", ")}`
99
147
  export {
100
148
  DRAFT_VERSIONS,
101
149
  DecodeError,
102
- createCodec
150
+ createCodec,
151
+ joiningRequestIdOf,
152
+ requestIdOf,
153
+ trackAliasOf,
154
+ trackOf
103
155
  };
@@ -8,7 +8,7 @@ import { D as Draft10Message, a as Draft10MessageType } from './types-0IWbU9Z_.c
8
8
  import { D as Draft11Message, a as Draft11MessageType } from './types-Ck45Ex5S.cjs';
9
9
  import { D as Draft12Message, a as Draft12MessageType } from './types-Bio-91Rt.cjs';
10
10
  import { D as Draft13Message, a as Draft13MessageType } from './types-CXlSn0I9.cjs';
11
- import { D as Draft14Message, a as Draft14MessageType } from './types-DjmrHp_s.cjs';
11
+ import { D as Draft14Message, a as Draft14MessageType } from './types-CVeKIk7A.cjs';
12
12
  import { D as Draft15Message, a as Draft15MessageType } from './types-CPaYBsMG.cjs';
13
13
  import { D as Draft16Message, a as Draft16MessageType } from './types-Cm9fjeYC.cjs';
14
14
  import { D as Draft17Message, a as Draft17MessageType } from './types-D9eiB_9A.cjs';
package/dist/session.d.ts CHANGED
@@ -8,7 +8,7 @@ import { D as Draft10Message, a as Draft10MessageType } from './types-0IWbU9Z_.j
8
8
  import { D as Draft11Message, a as Draft11MessageType } from './types-Ck45Ex5S.js';
9
9
  import { D as Draft12Message, a as Draft12MessageType } from './types-Bio-91Rt.js';
10
10
  import { D as Draft13Message, a as Draft13MessageType } from './types-CXlSn0I9.js';
11
- import { D as Draft14Message, a as Draft14MessageType } from './types-DjmrHp_s.js';
11
+ import { D as Draft14Message, a as Draft14MessageType } from './types-CVeKIk7A.js';
12
12
  import { D as Draft15Message, a as Draft15MessageType } from './types-CPaYBsMG.js';
13
13
  import { D as Draft16Message, a as Draft16MessageType } from './types-Cm9fjeYC.js';
14
14
  import { D as Draft17Message, a as Draft17MessageType } from './types-D9eiB_9A.js';
@@ -63,8 +63,8 @@ interface Draft14Subscribe extends Draft14BaseMessage {
63
63
  readonly request_id: bigint;
64
64
  readonly track_namespace: string[];
65
65
  readonly track_name: string;
66
- readonly subscriber_priority: bigint;
67
- readonly group_order: bigint;
66
+ readonly subscriber_priority: number;
67
+ readonly group_order: number;
68
68
  readonly forward: bigint;
69
69
  readonly filter_type: bigint;
70
70
  readonly start_group?: bigint;
@@ -77,7 +77,7 @@ interface Draft14SubscribeOk extends Draft14BaseMessage {
77
77
  readonly request_id: bigint;
78
78
  readonly track_alias: bigint;
79
79
  readonly expires: bigint;
80
- readonly group_order: bigint;
80
+ readonly group_order: number;
81
81
  readonly content_exists: bigint;
82
82
  readonly largest_location?: Location;
83
83
  readonly parameters: Draft14Params;
@@ -89,7 +89,7 @@ interface Draft14SubscribeUpdate extends Draft14BaseMessage {
89
89
  readonly start_group: bigint;
90
90
  readonly start_object: bigint;
91
91
  readonly end_group: bigint;
92
- readonly subscriber_priority: bigint;
92
+ readonly subscriber_priority: number;
93
93
  readonly forward: bigint;
94
94
  readonly parameters: Draft14Params;
95
95
  }
@@ -109,7 +109,7 @@ interface Draft14Publish extends Draft14BaseMessage {
109
109
  readonly track_namespace: string[];
110
110
  readonly track_name: string;
111
111
  readonly track_alias: bigint;
112
- readonly group_order: bigint;
112
+ readonly group_order: number;
113
113
  readonly content_exists: bigint;
114
114
  readonly largest_location?: Location;
115
115
  readonly forward: bigint;
@@ -119,8 +119,8 @@ interface Draft14PublishOk extends Draft14BaseMessage {
119
119
  readonly type: 'publish_ok';
120
120
  readonly request_id: bigint;
121
121
  readonly forward: bigint;
122
- readonly subscriber_priority: bigint;
123
- readonly group_order: bigint;
122
+ readonly subscriber_priority: number;
123
+ readonly group_order: number;
124
124
  readonly filter_type: bigint;
125
125
  readonly start_group?: bigint;
126
126
  readonly start_object?: bigint;
@@ -188,26 +188,34 @@ interface Draft14UnsubscribeNamespace extends Draft14BaseMessage {
188
188
  readonly type: 'unsubscribe_namespace';
189
189
  readonly track_namespace_prefix: string[];
190
190
  }
191
+ interface StandaloneFetch {
192
+ readonly track_namespace: string[];
193
+ readonly track_name: string;
194
+ readonly start_group: bigint;
195
+ readonly start_object: bigint;
196
+ readonly end_group: bigint;
197
+ readonly end_object: bigint;
198
+ }
199
+ interface JoiningFetch {
200
+ readonly joining_request_id: bigint;
201
+ readonly joining_start: bigint;
202
+ }
191
203
  interface Draft14Fetch extends Draft14BaseMessage {
192
204
  readonly type: 'fetch';
193
205
  readonly request_id: bigint;
194
- readonly subscriber_priority: bigint;
195
- readonly group_order: bigint;
206
+ readonly subscriber_priority: number;
207
+ readonly group_order: number;
196
208
  readonly fetch_type: bigint;
197
- readonly track_namespace?: string[];
198
- readonly track_name?: string;
199
- readonly start_group?: bigint;
200
- readonly start_object?: bigint;
201
- readonly end_group?: bigint;
202
- readonly end_object?: bigint;
203
- readonly joining_request_id?: bigint;
204
- readonly joining_start?: bigint;
209
+ /** Present when fetch_type = 1 */
210
+ readonly standalone?: StandaloneFetch;
211
+ /** Present when fetch_type = 2 or 3 */
212
+ readonly joining?: JoiningFetch;
205
213
  readonly parameters: Draft14Params;
206
214
  }
207
215
  interface Draft14FetchOk extends Draft14BaseMessage {
208
216
  readonly type: 'fetch_ok';
209
217
  readonly request_id: bigint;
210
- readonly group_order: bigint;
218
+ readonly group_order: number;
211
219
  readonly end_of_track: bigint;
212
220
  readonly end_location: Location;
213
221
  readonly parameters: Draft14Params;
@@ -227,8 +235,8 @@ interface Draft14TrackStatus extends Draft14BaseMessage {
227
235
  readonly request_id: bigint;
228
236
  readonly track_namespace: string[];
229
237
  readonly track_name: string;
230
- readonly subscriber_priority: bigint;
231
- readonly group_order: bigint;
238
+ readonly subscriber_priority: number;
239
+ readonly group_order: number;
232
240
  readonly forward: bigint;
233
241
  readonly filter_type: bigint;
234
242
  readonly start_group?: bigint;
@@ -240,7 +248,7 @@ interface Draft14TrackStatusOk extends Draft14BaseMessage {
240
248
  readonly request_id: bigint;
241
249
  readonly track_alias: bigint;
242
250
  readonly expires: bigint;
243
- readonly group_order: bigint;
251
+ readonly group_order: number;
244
252
  readonly content_exists: bigint;
245
253
  readonly largest_location?: Location;
246
254
  readonly parameters: Draft14Params;