@moqtap/codec 0.1.0 → 0.1.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.
Files changed (67) hide show
  1. package/dist/{chunk-YBSEOSSP.js → chunk-A27S7HW7.js} +5 -1
  2. package/dist/{chunk-5WFXFLL4.cjs → chunk-FUFTMAQD.cjs} +96 -63
  3. package/dist/{chunk-2NARXGVA.cjs → chunk-FWISIR26.cjs} +5 -1
  4. package/dist/{chunk-23YG7F46.js → chunk-IXHOBNXA.js} +117 -17
  5. package/dist/{chunk-3BSZ55L3.cjs → chunk-NLYTRGXA.cjs} +153 -19
  6. package/dist/{chunk-GDRGWFEK.cjs → chunk-NPWHHWXT.cjs} +249 -37
  7. package/dist/{chunk-IQPDRQVC.js → chunk-U2B3B42P.js} +62 -29
  8. package/dist/{chunk-WNTXF3DE.cjs → chunk-YBZD3DU5.cjs} +127 -27
  9. package/dist/{chunk-DC4L6ZIT.js → chunk-YTXLWKOR.js} +153 -19
  10. package/dist/{chunk-YPXLV5YK.js → chunk-Z66WDWHI.js} +249 -37
  11. package/dist/{codec-qPzfmLNu.d.ts → codec-B2mc2g3i.d.ts} +5 -5
  12. package/dist/{codec-CTvFtQQI.d.cts → codec-Bvr7rFtj.d.cts} +5 -5
  13. package/dist/draft14-session.cjs +2 -2
  14. package/dist/draft14-session.d.cts +4 -4
  15. package/dist/draft14-session.d.ts +4 -4
  16. package/dist/draft14-session.js +1 -1
  17. package/dist/draft14.cjs +4 -4
  18. package/dist/draft14.d.cts +15 -15
  19. package/dist/draft14.d.ts +15 -15
  20. package/dist/draft14.js +3 -3
  21. package/dist/draft7-session.cjs +2 -2
  22. package/dist/draft7-session.d.cts +3 -3
  23. package/dist/draft7-session.d.ts +3 -3
  24. package/dist/draft7-session.js +1 -1
  25. package/dist/draft7.cjs +5 -5
  26. package/dist/draft7.d.cts +10 -10
  27. package/dist/draft7.d.ts +10 -10
  28. package/dist/draft7.js +2 -2
  29. package/dist/index.cjs +6 -6
  30. package/dist/index.d.cts +6 -6
  31. package/dist/index.d.ts +6 -6
  32. package/dist/index.js +3 -3
  33. package/dist/{session-types-B9NIf7_F.d.ts → session-types-DFjMk4HH.d.ts} +20 -20
  34. package/dist/{session-types-CCo-oA-d.d.cts → session-types-DW1RSZX_.d.cts} +20 -20
  35. package/dist/session.cjs +4 -4
  36. package/dist/session.d.cts +3 -3
  37. package/dist/session.d.ts +3 -3
  38. package/dist/session.js +2 -2
  39. package/dist/{types-CIk5W10V.d.ts → types-BTFeKYCb.d.cts} +37 -37
  40. package/dist/{types-CIk5W10V.d.cts → types-BTFeKYCb.d.ts} +37 -37
  41. package/dist/{types-ClXELFGN.d.cts → types-DPYE49t0.d.cts} +36 -36
  42. package/dist/{types-ClXELFGN.d.ts → types-DPYE49t0.d.ts} +36 -36
  43. package/package.json +7 -7
  44. package/src/core/buffer-reader.ts +16 -9
  45. package/src/core/buffer-writer.ts +2 -2
  46. package/src/core/errors.ts +1 -1
  47. package/src/core/session-types.ts +28 -41
  48. package/src/core/types.ts +70 -70
  49. package/src/drafts/draft07/announce-fsm.ts +1 -1
  50. package/src/drafts/draft07/codec.ts +195 -86
  51. package/src/drafts/draft07/index.ts +43 -44
  52. package/src/drafts/draft07/messages.ts +1 -1
  53. package/src/drafts/draft07/parameters.ts +2 -2
  54. package/src/drafts/draft07/rules.ts +68 -37
  55. package/src/drafts/draft07/session-fsm.ts +330 -117
  56. package/src/drafts/draft07/session.ts +10 -10
  57. package/src/drafts/draft07/subscription-fsm.ts +1 -1
  58. package/src/drafts/draft07/varint.ts +4 -4
  59. package/src/drafts/draft14/codec.ts +339 -189
  60. package/src/drafts/draft14/index.ts +103 -108
  61. package/src/drafts/draft14/messages.ts +61 -61
  62. package/src/drafts/draft14/rules.ts +77 -34
  63. package/src/drafts/draft14/session-fsm.ts +458 -146
  64. package/src/drafts/draft14/session.ts +13 -13
  65. package/src/drafts/draft14/types.ts +68 -68
  66. package/src/index.ts +66 -31
  67. package/src/session.ts +20 -20
@@ -31,12 +31,8 @@ var CONTROL_MESSAGES = /* @__PURE__ */ new Set([
31
31
  "max_request_id",
32
32
  "requests_blocked"
33
33
  ]);
34
- var CLIENT_ONLY_MESSAGES = /* @__PURE__ */ new Set([
35
- "client_setup"
36
- ]);
37
- var SERVER_ONLY_MESSAGES = /* @__PURE__ */ new Set([
38
- "server_setup"
39
- ]);
34
+ var CLIENT_ONLY_MESSAGES = /* @__PURE__ */ new Set(["client_setup"]);
35
+ var SERVER_ONLY_MESSAGES = /* @__PURE__ */ new Set(["server_setup"]);
40
36
  var BIDIRECTIONAL_MESSAGES = /* @__PURE__ */ new Set([
41
37
  "subscribe",
42
38
  "subscribe_ok",
@@ -135,22 +131,42 @@ var Draft14SessionFSM = (_class = class {
135
131
  checkRole(message, direction) {
136
132
  const senderRole = direction === "outbound" ? this._role : this._role === "client" ? "server" : "client";
137
133
  if (CLIENT_ONLY_MESSAGES.has(message.type) && senderRole !== "client") {
138
- return violation("ROLE_VIOLATION", `${message.type} can only be sent by client`, this._phase, message.type);
134
+ return violation(
135
+ "ROLE_VIOLATION",
136
+ `${message.type} can only be sent by client`,
137
+ this._phase,
138
+ message.type
139
+ );
139
140
  }
140
141
  if (SERVER_ONLY_MESSAGES.has(message.type) && senderRole !== "server") {
141
- return violation("ROLE_VIOLATION", `${message.type} can only be sent by server`, this._phase, message.type);
142
+ return violation(
143
+ "ROLE_VIOLATION",
144
+ `${message.type} can only be sent by server`,
145
+ this._phase,
146
+ message.type
147
+ );
142
148
  }
143
149
  return null;
144
150
  }
145
151
  checkDuplicateRequestId(requestId, msgType) {
146
152
  if (this._requestIds.has(requestId)) {
147
- return violation("DUPLICATE_REQUEST_ID", `Request ID ${requestId} already in use`, this._phase, msgType);
153
+ return violation(
154
+ "DUPLICATE_REQUEST_ID",
155
+ `Request ID ${requestId} already in use`,
156
+ this._phase,
157
+ msgType
158
+ );
148
159
  }
149
160
  return null;
150
161
  }
151
162
  checkKnownRequestId(requestId, msgType) {
152
163
  if (!this._requestIds.has(requestId)) {
153
- return violation("UNKNOWN_REQUEST_ID", `No request with ID ${requestId}`, this._phase, msgType);
164
+ return violation(
165
+ "UNKNOWN_REQUEST_ID",
166
+ `No request with ID ${requestId}`,
167
+ this._phase,
168
+ msgType
169
+ );
154
170
  }
155
171
  return null;
156
172
  }
@@ -225,27 +241,67 @@ var Draft14SessionFSM = (_class = class {
225
241
  }
226
242
  handleClientSetup(_message, direction) {
227
243
  if (this._phase !== "idle") {
228
- return { ok: false, violation: violation("SETUP_VIOLATION", "CLIENT_SETUP already sent/received", this._phase, "client_setup") };
244
+ return {
245
+ ok: false,
246
+ violation: violation(
247
+ "SETUP_VIOLATION",
248
+ "CLIENT_SETUP already sent/received",
249
+ this._phase,
250
+ "client_setup"
251
+ )
252
+ };
229
253
  }
230
254
  if (direction === "outbound" && this._role !== "client") {
231
- return { ok: false, violation: violation("ROLE_VIOLATION", "Only client can send CLIENT_SETUP", this._phase, "client_setup") };
255
+ return {
256
+ ok: false,
257
+ violation: violation(
258
+ "ROLE_VIOLATION",
259
+ "Only client can send CLIENT_SETUP",
260
+ this._phase,
261
+ "client_setup"
262
+ )
263
+ };
232
264
  }
233
265
  this._phase = "setup";
234
266
  return { ok: true, phase: this._phase, sideEffects: [] };
235
267
  }
236
268
  handleServerSetup(_message, direction) {
237
269
  if (this._phase !== "setup") {
238
- return { ok: false, violation: violation("SETUP_VIOLATION", "SERVER_SETUP before CLIENT_SETUP", this._phase, "server_setup") };
270
+ return {
271
+ ok: false,
272
+ violation: violation(
273
+ "SETUP_VIOLATION",
274
+ "SERVER_SETUP before CLIENT_SETUP",
275
+ this._phase,
276
+ "server_setup"
277
+ )
278
+ };
239
279
  }
240
280
  if (direction === "outbound" && this._role !== "server") {
241
- return { ok: false, violation: violation("ROLE_VIOLATION", "Only server can send SERVER_SETUP", this._phase, "server_setup") };
281
+ return {
282
+ ok: false,
283
+ violation: violation(
284
+ "ROLE_VIOLATION",
285
+ "Only server can send SERVER_SETUP",
286
+ this._phase,
287
+ "server_setup"
288
+ )
289
+ };
242
290
  }
243
291
  this._phase = "ready";
244
292
  return { ok: true, phase: this._phase, sideEffects: [{ type: "session-ready" }] };
245
293
  }
246
294
  handleGoAway(message, _direction, sideEffects) {
247
295
  if (this._phase !== "ready" && this._phase !== "draining") {
248
- return { ok: false, violation: violation("UNEXPECTED_MESSAGE", `GOAWAY not valid in phase ${this._phase}`, this._phase, "goaway") };
296
+ return {
297
+ ok: false,
298
+ violation: violation(
299
+ "UNEXPECTED_MESSAGE",
300
+ `GOAWAY not valid in phase ${this._phase}`,
301
+ this._phase,
302
+ "goaway"
303
+ )
304
+ };
249
305
  }
250
306
  this._phase = "draining";
251
307
  const goaway = message;
@@ -287,10 +343,26 @@ var Draft14SessionFSM = (_class = class {
287
343
  if (idErr) return { ok: false, violation: idErr };
288
344
  const existing = this._subscriptions.get(ok.request_id);
289
345
  if (!existing) {
290
- return { ok: false, violation: violation("UNKNOWN_REQUEST_ID", `No subscription with request ID ${ok.request_id}`, this._phase, message.type) };
346
+ return {
347
+ ok: false,
348
+ violation: violation(
349
+ "UNKNOWN_REQUEST_ID",
350
+ `No subscription with request ID ${ok.request_id}`,
351
+ this._phase,
352
+ message.type
353
+ )
354
+ };
291
355
  }
292
356
  if (existing.phase !== "pending") {
293
- return { ok: false, violation: violation("STATE_VIOLATION", `Subscription ${ok.request_id} is ${existing.phase}, not pending`, this._phase, message.type) };
357
+ return {
358
+ ok: false,
359
+ violation: violation(
360
+ "STATE_VIOLATION",
361
+ `Subscription ${ok.request_id} is ${existing.phase}, not pending`,
362
+ this._phase,
363
+ message.type
364
+ )
365
+ };
294
366
  }
295
367
  this._subscriptions.set(ok.request_id, { ...existing, phase: "active" });
296
368
  sideEffects.push({ type: "subscription-activated", subscribeId: ok.request_id });
@@ -304,13 +376,33 @@ var Draft14SessionFSM = (_class = class {
304
376
  if (idErr) return { ok: false, violation: idErr };
305
377
  const existing = this._subscriptions.get(subErr.request_id);
306
378
  if (!existing) {
307
- return { ok: false, violation: violation("UNKNOWN_REQUEST_ID", `No subscription with request ID ${subErr.request_id}`, this._phase, message.type) };
379
+ return {
380
+ ok: false,
381
+ violation: violation(
382
+ "UNKNOWN_REQUEST_ID",
383
+ `No subscription with request ID ${subErr.request_id}`,
384
+ this._phase,
385
+ message.type
386
+ )
387
+ };
308
388
  }
309
389
  if (existing.phase !== "pending") {
310
- return { ok: false, violation: violation("STATE_VIOLATION", `Subscription ${subErr.request_id} is ${existing.phase}, not pending`, this._phase, message.type) };
390
+ return {
391
+ ok: false,
392
+ violation: violation(
393
+ "STATE_VIOLATION",
394
+ `Subscription ${subErr.request_id} is ${existing.phase}, not pending`,
395
+ this._phase,
396
+ message.type
397
+ )
398
+ };
311
399
  }
312
400
  this._subscriptions.set(subErr.request_id, { ...existing, phase: "error" });
313
- sideEffects.push({ type: "subscription-ended", subscribeId: subErr.request_id, reason: subErr.reason_phrase });
401
+ sideEffects.push({
402
+ type: "subscription-ended",
403
+ subscribeId: subErr.request_id,
404
+ reason: subErr.reason_phrase
405
+ });
314
406
  return { ok: true, phase: this._phase, sideEffects };
315
407
  }
316
408
  handleSubscribeUpdate(message, _direction, sideEffects) {
@@ -321,10 +413,26 @@ var Draft14SessionFSM = (_class = class {
321
413
  if (idErr) return { ok: false, violation: idErr };
322
414
  const existing = this._subscriptions.get(update.request_id);
323
415
  if (!existing) {
324
- return { ok: false, violation: violation("UNKNOWN_REQUEST_ID", `No subscription with request ID ${update.request_id}`, this._phase, message.type) };
416
+ return {
417
+ ok: false,
418
+ violation: violation(
419
+ "UNKNOWN_REQUEST_ID",
420
+ `No subscription with request ID ${update.request_id}`,
421
+ this._phase,
422
+ message.type
423
+ )
424
+ };
325
425
  }
326
426
  if (existing.phase !== "active") {
327
- return { ok: false, violation: violation("STATE_VIOLATION", `Subscription ${update.request_id} is ${existing.phase}, not active`, this._phase, message.type) };
427
+ return {
428
+ ok: false,
429
+ violation: violation(
430
+ "STATE_VIOLATION",
431
+ `Subscription ${update.request_id} is ${existing.phase}, not active`,
432
+ this._phase,
433
+ message.type
434
+ )
435
+ };
328
436
  }
329
437
  return { ok: true, phase: this._phase, sideEffects };
330
438
  }
@@ -336,10 +444,22 @@ var Draft14SessionFSM = (_class = class {
336
444
  if (idErr) return { ok: false, violation: idErr };
337
445
  const existing = this._subscriptions.get(unsub.request_id);
338
446
  if (!existing) {
339
- return { ok: false, violation: violation("UNKNOWN_REQUEST_ID", `No subscription with request ID ${unsub.request_id}`, this._phase, message.type) };
447
+ return {
448
+ ok: false,
449
+ violation: violation(
450
+ "UNKNOWN_REQUEST_ID",
451
+ `No subscription with request ID ${unsub.request_id}`,
452
+ this._phase,
453
+ message.type
454
+ )
455
+ };
340
456
  }
341
457
  this._subscriptions.set(unsub.request_id, { ...existing, phase: "done" });
342
- sideEffects.push({ type: "subscription-ended", subscribeId: unsub.request_id, reason: "unsubscribed" });
458
+ sideEffects.push({
459
+ type: "subscription-ended",
460
+ subscribeId: unsub.request_id,
461
+ reason: "unsubscribed"
462
+ });
343
463
  return { ok: true, phase: this._phase, sideEffects };
344
464
  }
345
465
  // ─── Publish lifecycle ────────────────────────────────────────────────────────
@@ -364,10 +484,26 @@ var Draft14SessionFSM = (_class = class {
364
484
  if (idErr) return { ok: false, violation: idErr };
365
485
  const existing = this._publishes.get(ok.request_id);
366
486
  if (!existing) {
367
- return { ok: false, violation: violation("UNKNOWN_REQUEST_ID", `No publish with request ID ${ok.request_id}`, this._phase, message.type) };
487
+ return {
488
+ ok: false,
489
+ violation: violation(
490
+ "UNKNOWN_REQUEST_ID",
491
+ `No publish with request ID ${ok.request_id}`,
492
+ this._phase,
493
+ message.type
494
+ )
495
+ };
368
496
  }
369
497
  if (existing.phase !== "pending") {
370
- return { ok: false, violation: violation("STATE_VIOLATION", `Publish ${ok.request_id} is ${existing.phase}, not pending`, this._phase, message.type) };
498
+ return {
499
+ ok: false,
500
+ violation: violation(
501
+ "STATE_VIOLATION",
502
+ `Publish ${ok.request_id} is ${existing.phase}, not pending`,
503
+ this._phase,
504
+ message.type
505
+ )
506
+ };
371
507
  }
372
508
  this._publishes.set(ok.request_id, { ...existing, phase: "active" });
373
509
  sideEffects.push({ type: "publish-activated", requestId: ok.request_id });
@@ -381,13 +517,33 @@ var Draft14SessionFSM = (_class = class {
381
517
  if (idErr) return { ok: false, violation: idErr };
382
518
  const existing = this._publishes.get(pubErr.request_id);
383
519
  if (!existing) {
384
- return { ok: false, violation: violation("UNKNOWN_REQUEST_ID", `No publish with request ID ${pubErr.request_id}`, this._phase, message.type) };
520
+ return {
521
+ ok: false,
522
+ violation: violation(
523
+ "UNKNOWN_REQUEST_ID",
524
+ `No publish with request ID ${pubErr.request_id}`,
525
+ this._phase,
526
+ message.type
527
+ )
528
+ };
385
529
  }
386
530
  if (existing.phase !== "pending") {
387
- return { ok: false, violation: violation("STATE_VIOLATION", `Publish ${pubErr.request_id} is ${existing.phase}, not pending`, this._phase, message.type) };
531
+ return {
532
+ ok: false,
533
+ violation: violation(
534
+ "STATE_VIOLATION",
535
+ `Publish ${pubErr.request_id} is ${existing.phase}, not pending`,
536
+ this._phase,
537
+ message.type
538
+ )
539
+ };
388
540
  }
389
541
  this._publishes.set(pubErr.request_id, { ...existing, phase: "error" });
390
- sideEffects.push({ type: "publish-ended", requestId: pubErr.request_id, reason: pubErr.reason_phrase });
542
+ sideEffects.push({
543
+ type: "publish-ended",
544
+ requestId: pubErr.request_id,
545
+ reason: pubErr.reason_phrase
546
+ });
391
547
  return { ok: true, phase: this._phase, sideEffects };
392
548
  }
393
549
  handlePublishDone(message, _direction, sideEffects) {
@@ -398,10 +554,22 @@ var Draft14SessionFSM = (_class = class {
398
554
  if (idErr) return { ok: false, violation: idErr };
399
555
  const existing = this._publishes.get(done.request_id);
400
556
  if (!existing) {
401
- return { ok: false, violation: violation("UNKNOWN_REQUEST_ID", `No publish with request ID ${done.request_id}`, this._phase, message.type) };
557
+ return {
558
+ ok: false,
559
+ violation: violation(
560
+ "UNKNOWN_REQUEST_ID",
561
+ `No publish with request ID ${done.request_id}`,
562
+ this._phase,
563
+ message.type
564
+ )
565
+ };
402
566
  }
403
567
  this._publishes.set(done.request_id, { ...existing, phase: "done" });
404
- sideEffects.push({ type: "publish-ended", requestId: done.request_id, reason: done.reason_phrase });
568
+ sideEffects.push({
569
+ type: "publish-ended",
570
+ requestId: done.request_id,
571
+ reason: done.reason_phrase
572
+ });
405
573
  return { ok: true, phase: this._phase, sideEffects };
406
574
  }
407
575
  // ─── Fetch lifecycle ──────────────────────────────────────────────────────────
@@ -426,10 +594,26 @@ var Draft14SessionFSM = (_class = class {
426
594
  if (idErr) return { ok: false, violation: idErr };
427
595
  const existing = this._fetches.get(ok.request_id);
428
596
  if (!existing) {
429
- return { ok: false, violation: violation("UNKNOWN_REQUEST_ID", `No fetch with request ID ${ok.request_id}`, this._phase, message.type) };
597
+ return {
598
+ ok: false,
599
+ violation: violation(
600
+ "UNKNOWN_REQUEST_ID",
601
+ `No fetch with request ID ${ok.request_id}`,
602
+ this._phase,
603
+ message.type
604
+ )
605
+ };
430
606
  }
431
607
  if (existing.phase !== "pending") {
432
- return { ok: false, violation: violation("STATE_VIOLATION", `Fetch ${ok.request_id} is ${existing.phase}, not pending`, this._phase, message.type) };
608
+ return {
609
+ ok: false,
610
+ violation: violation(
611
+ "STATE_VIOLATION",
612
+ `Fetch ${ok.request_id} is ${existing.phase}, not pending`,
613
+ this._phase,
614
+ message.type
615
+ )
616
+ };
433
617
  }
434
618
  this._fetches.set(ok.request_id, { ...existing, phase: "active" });
435
619
  sideEffects.push({ type: "fetch-activated", requestId: ok.request_id });
@@ -443,13 +627,33 @@ var Draft14SessionFSM = (_class = class {
443
627
  if (idErr) return { ok: false, violation: idErr };
444
628
  const existing = this._fetches.get(fetchErr.request_id);
445
629
  if (!existing) {
446
- return { ok: false, violation: violation("UNKNOWN_REQUEST_ID", `No fetch with request ID ${fetchErr.request_id}`, this._phase, message.type) };
630
+ return {
631
+ ok: false,
632
+ violation: violation(
633
+ "UNKNOWN_REQUEST_ID",
634
+ `No fetch with request ID ${fetchErr.request_id}`,
635
+ this._phase,
636
+ message.type
637
+ )
638
+ };
447
639
  }
448
640
  if (existing.phase !== "pending") {
449
- return { ok: false, violation: violation("STATE_VIOLATION", `Fetch ${fetchErr.request_id} is ${existing.phase}, not pending`, this._phase, message.type) };
641
+ return {
642
+ ok: false,
643
+ violation: violation(
644
+ "STATE_VIOLATION",
645
+ `Fetch ${fetchErr.request_id} is ${existing.phase}, not pending`,
646
+ this._phase,
647
+ message.type
648
+ )
649
+ };
450
650
  }
451
651
  this._fetches.set(fetchErr.request_id, { ...existing, phase: "error" });
452
- sideEffects.push({ type: "fetch-ended", requestId: fetchErr.request_id, reason: fetchErr.reason_phrase });
652
+ sideEffects.push({
653
+ type: "fetch-ended",
654
+ requestId: fetchErr.request_id,
655
+ reason: fetchErr.reason_phrase
656
+ });
453
657
  return { ok: true, phase: this._phase, sideEffects };
454
658
  }
455
659
  handleFetchCancel(message, _direction, sideEffects) {
@@ -460,7 +664,15 @@ var Draft14SessionFSM = (_class = class {
460
664
  if (idErr) return { ok: false, violation: idErr };
461
665
  const existing = this._fetches.get(cancel.request_id);
462
666
  if (!existing) {
463
- return { ok: false, violation: violation("UNKNOWN_REQUEST_ID", `No fetch with request ID ${cancel.request_id}`, this._phase, message.type) };
667
+ return {
668
+ ok: false,
669
+ violation: violation(
670
+ "UNKNOWN_REQUEST_ID",
671
+ `No fetch with request ID ${cancel.request_id}`,
672
+ this._phase,
673
+ message.type
674
+ )
675
+ };
464
676
  }
465
677
  this._fetches.set(cancel.request_id, { ...existing, phase: "cancelled" });
466
678
  sideEffects.push({ type: "fetch-ended", requestId: cancel.request_id, reason: "cancelled" });
@@ -2,7 +2,7 @@ import {
2
2
  BufferReader,
3
3
  BufferWriter,
4
4
  DecodeError
5
- } from "./chunk-YBSEOSSP.js";
5
+ } from "./chunk-A27S7HW7.js";
6
6
 
7
7
  // src/drafts/draft14/messages.ts
8
8
  var MSG_SUBSCRIBE_UPDATE = 0x02n;
@@ -13,12 +13,12 @@ var MSG_PUBLISH_NAMESPACE = 0x06n;
13
13
  var MSG_PUBLISH_NAMESPACE_OK = 0x07n;
14
14
  var MSG_PUBLISH_NAMESPACE_ERROR = 0x08n;
15
15
  var MSG_PUBLISH_NAMESPACE_DONE = 0x09n;
16
- var MSG_UNSUBSCRIBE = 0x0An;
17
- var MSG_PUBLISH_DONE = 0x0Bn;
18
- var MSG_PUBLISH_NAMESPACE_CANCEL = 0x0Cn;
19
- var MSG_TRACK_STATUS = 0x0Dn;
20
- var MSG_TRACK_STATUS_OK = 0x0En;
21
- var MSG_TRACK_STATUS_ERROR = 0x0Fn;
16
+ var MSG_UNSUBSCRIBE = 0x0an;
17
+ var MSG_PUBLISH_DONE = 0x0bn;
18
+ var MSG_PUBLISH_NAMESPACE_CANCEL = 0x0cn;
19
+ var MSG_TRACK_STATUS = 0x0dn;
20
+ var MSG_TRACK_STATUS_OK = 0x0en;
21
+ var MSG_TRACK_STATUS_ERROR = 0x0fn;
22
22
  var MSG_GOAWAY = 0x10n;
23
23
  var MSG_SUBSCRIBE_NAMESPACE = 0x11n;
24
24
  var MSG_SUBSCRIBE_NAMESPACE_OK = 0x12n;
@@ -29,10 +29,10 @@ var MSG_FETCH = 0x16n;
29
29
  var MSG_FETCH_CANCEL = 0x17n;
30
30
  var MSG_FETCH_OK = 0x18n;
31
31
  var MSG_FETCH_ERROR = 0x19n;
32
- var MSG_REQUESTS_BLOCKED = 0x1An;
33
- var MSG_PUBLISH = 0x1Dn;
34
- var MSG_PUBLISH_OK = 0x1En;
35
- var MSG_PUBLISH_ERROR = 0x1Fn;
32
+ var MSG_REQUESTS_BLOCKED = 0x1an;
33
+ var MSG_PUBLISH = 0x1dn;
34
+ var MSG_PUBLISH_OK = 0x1en;
35
+ var MSG_PUBLISH_ERROR = 0x1fn;
36
36
  var MSG_CLIENT_SETUP = 0x20n;
37
37
  var MSG_SERVER_SETUP = 0x21n;
38
38
  var PARAM_ROLE = 0x00n;
@@ -137,7 +137,7 @@ function decodeParams(reader) {
137
137
  tmpWriter.writeVarInt(value);
138
138
  const raw = tmpWriter.finish();
139
139
  unknown.push({
140
- id: "0x" + paramType.toString(16),
140
+ id: `0x${paramType.toString(16)}`,
141
141
  length: raw.byteLength,
142
142
  raw_hex: bytesToHex(raw)
143
143
  });
@@ -149,7 +149,7 @@ function decodeParams(reader) {
149
149
  result.path = new TextDecoder().decode(bytes);
150
150
  } else {
151
151
  unknown.push({
152
- id: "0x" + paramType.toString(16),
152
+ id: `0x${paramType.toString(16)}`,
153
153
  length,
154
154
  raw_hex: bytesToHex(bytes)
155
155
  });
@@ -337,7 +337,11 @@ function encodeRequestsBlockedPayload(msg, w) {
337
337
  function decodeClientSetupPayload(r) {
338
338
  const numVersions = Number(r.readVarInt());
339
339
  if (numVersions === 0) {
340
- throw new DecodeError("CONSTRAINT_VIOLATION", "CLIENT_SETUP must offer at least one version", r.offset);
340
+ throw new DecodeError(
341
+ "CONSTRAINT_VIOLATION",
342
+ "CLIENT_SETUP must offer at least one version",
343
+ r.offset
344
+ );
341
345
  }
342
346
  const supported_versions = [];
343
347
  for (let i = 0; i < numVersions; i++) {
@@ -527,7 +531,16 @@ function decodeFetchPayload(r) {
527
531
  const start_object = r.readVarInt();
528
532
  const end_group = r.readVarInt();
529
533
  const parameters = decodeParams(r);
530
- return { type: "fetch", request_id, track_namespace, track_name, start_group, start_object, end_group, parameters };
534
+ return {
535
+ type: "fetch",
536
+ request_id,
537
+ track_namespace,
538
+ track_name,
539
+ start_group,
540
+ start_object,
541
+ end_group,
542
+ parameters
543
+ };
531
544
  }
532
545
  function decodeFetchOkPayload(r) {
533
546
  const request_id = r.readVarInt();
@@ -721,7 +734,11 @@ function decodeMessage(bytes) {
721
734
  if (!decoder) {
722
735
  return {
723
736
  ok: false,
724
- error: new DecodeError("UNKNOWN_MESSAGE_TYPE", `Unknown message type ID: 0x${typeId.toString(16)}`, 0)
737
+ error: new DecodeError(
738
+ "UNKNOWN_MESSAGE_TYPE",
739
+ `Unknown message type ID: 0x${typeId.toString(16)}`,
740
+ 0
741
+ )
725
742
  };
726
743
  }
727
744
  const message = decoder(payloadReader);
@@ -772,7 +789,14 @@ function decodeSubgroupStream(bytes) {
772
789
  const r = new BufferReader(bytes);
773
790
  const streamType = r.readVarInt();
774
791
  if (streamType !== 0n) {
775
- return { ok: false, error: new DecodeError("CONSTRAINT_VIOLATION", `Expected subgroup stream type 0, got ${streamType}`, 0) };
792
+ return {
793
+ ok: false,
794
+ error: new DecodeError(
795
+ "CONSTRAINT_VIOLATION",
796
+ `Expected subgroup stream type 0, got ${streamType}`,
797
+ 0
798
+ )
799
+ };
776
800
  }
777
801
  const trackAlias = r.readVarInt();
778
802
  const groupId = r.readVarInt();
@@ -818,7 +842,14 @@ function decodeFetchStream(bytes) {
818
842
  const r = new BufferReader(bytes);
819
843
  const streamType = r.readVarInt();
820
844
  if (streamType !== 2n) {
821
- return { ok: false, error: new DecodeError("CONSTRAINT_VIOLATION", `Expected fetch stream type 2, got ${streamType}`, 0) };
845
+ return {
846
+ ok: false,
847
+ error: new DecodeError(
848
+ "CONSTRAINT_VIOLATION",
849
+ `Expected fetch stream type 2, got ${streamType}`,
850
+ 0
851
+ )
852
+ };
822
853
  }
823
854
  const subscribeRequestId = r.readVarInt();
824
855
  const objects = [];
@@ -897,7 +928,11 @@ function createSubgroupStreamDecoder() {
897
928
  const streamType = r.readVarInt();
898
929
  if (streamType !== 0n) {
899
930
  controller.error(
900
- new DecodeError("CONSTRAINT_VIOLATION", `Expected subgroup stream type 0, got ${streamType}`, 0)
931
+ new DecodeError(
932
+ "CONSTRAINT_VIOLATION",
933
+ `Expected subgroup stream type 0, got ${streamType}`,
934
+ 0
935
+ )
901
936
  );
902
937
  return;
903
938
  }
@@ -941,9 +976,7 @@ function createSubgroupStreamDecoder() {
941
976
  },
942
977
  flush(controller) {
943
978
  if (buffer.length > 0) {
944
- controller.error(
945
- new DecodeError("UNEXPECTED_END", "Stream ended with incomplete data", 0)
946
- );
979
+ controller.error(new DecodeError("UNEXPECTED_END", "Stream ended with incomplete data", 0));
947
980
  }
948
981
  }
949
982
  });
@@ -963,7 +996,11 @@ function createFetchStreamDecoder() {
963
996
  const streamType = r.readVarInt();
964
997
  if (streamType !== 2n) {
965
998
  controller.error(
966
- new DecodeError("CONSTRAINT_VIOLATION", `Expected fetch stream type 2, got ${streamType}`, 0)
999
+ new DecodeError(
1000
+ "CONSTRAINT_VIOLATION",
1001
+ `Expected fetch stream type 2, got ${streamType}`,
1002
+ 0
1003
+ )
967
1004
  );
968
1005
  return;
969
1006
  }
@@ -1001,9 +1038,7 @@ function createFetchStreamDecoder() {
1001
1038
  },
1002
1039
  flush(controller) {
1003
1040
  if (buffer.length > 0) {
1004
- controller.error(
1005
- new DecodeError("UNEXPECTED_END", "Stream ended with incomplete data", 0)
1006
- );
1041
+ controller.error(new DecodeError("UNEXPECTED_END", "Stream ended with incomplete data", 0));
1007
1042
  }
1008
1043
  }
1009
1044
  });
@@ -1106,9 +1141,7 @@ function createDataStreamDecoder() {
1106
1141
  },
1107
1142
  flush(controller) {
1108
1143
  if (buffer.length > 0) {
1109
- controller.error(
1110
- new DecodeError("UNEXPECTED_END", "Stream ended with incomplete data", 0)
1111
- );
1144
+ controller.error(new DecodeError("UNEXPECTED_END", "Stream ended with incomplete data", 0));
1112
1145
  }
1113
1146
  }
1114
1147
  });