@moq/net 0.4.0 → 0.4.2

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 (204) hide show
  1. package/announced.d.ts +14 -0
  2. package/announced.d.ts.map +1 -1
  3. package/announced.js.map +1 -1
  4. package/broadcast.d.ts +27 -10
  5. package/broadcast.d.ts.map +1 -1
  6. package/broadcast.js +47 -21
  7. package/broadcast.js.map +1 -1
  8. package/connection/accept.js +14 -4
  9. package/connection/accept.js.map +1 -1
  10. package/connection/connect.d.ts.map +1 -1
  11. package/connection/connect.js +14 -4
  12. package/connection/connect.js.map +1 -1
  13. package/connection/established.d.ts +2 -1
  14. package/connection/established.d.ts.map +1 -1
  15. package/connection/established.js.map +1 -1
  16. package/connection/forward.js +61 -47
  17. package/connection/forward.js.map +1 -1
  18. package/connection/goaway.d.ts +34 -0
  19. package/connection/goaway.d.ts.map +1 -0
  20. package/connection/goaway.js +176 -0
  21. package/connection/goaway.js.map +1 -0
  22. package/connection/handshake.d.ts +5 -2
  23. package/connection/handshake.d.ts.map +1 -1
  24. package/connection/handshake.js +45 -10
  25. package/connection/handshake.js.map +1 -1
  26. package/connection/pool.d.ts +24 -11
  27. package/connection/pool.d.ts.map +1 -1
  28. package/connection/pool.js +50 -18
  29. package/connection/pool.js.map +1 -1
  30. package/connection/reload.d.ts.map +1 -1
  31. package/connection/reload.js +189 -35
  32. package/connection/reload.js.map +1 -1
  33. package/error.d.ts +11 -0
  34. package/error.d.ts.map +1 -1
  35. package/error.js +35 -0
  36. package/error.js.map +1 -1
  37. package/errors.d.ts +1 -1
  38. package/errors.d.ts.map +1 -1
  39. package/errors.js +1 -1
  40. package/errors.js.map +1 -1
  41. package/group.d.ts.map +1 -1
  42. package/group.js +5 -4
  43. package/group.js.map +1 -1
  44. package/hop.d.ts +8 -0
  45. package/hop.d.ts.map +1 -1
  46. package/hop.js +16 -0
  47. package/hop.js.map +1 -1
  48. package/ietf/adapter.d.ts +9 -1
  49. package/ietf/adapter.d.ts.map +1 -1
  50. package/ietf/adapter.js +46 -17
  51. package/ietf/adapter.js.map +1 -1
  52. package/ietf/cluster.d.ts +3 -3
  53. package/ietf/cluster.js +3 -3
  54. package/ietf/cluster.js.map +1 -1
  55. package/ietf/connection.d.ts +1 -1
  56. package/ietf/connection.d.ts.map +1 -1
  57. package/ietf/connection.js +118 -41
  58. package/ietf/connection.js.map +1 -1
  59. package/ietf/error.js +27 -2
  60. package/ietf/error.js.map +1 -1
  61. package/ietf/fetch.d.ts +7 -20
  62. package/ietf/fetch.d.ts.map +1 -1
  63. package/ietf/fetch.js +52 -22
  64. package/ietf/fetch.js.map +1 -1
  65. package/ietf/filter.d.ts +2 -0
  66. package/ietf/filter.d.ts.map +1 -1
  67. package/ietf/filter.js +4 -0
  68. package/ietf/filter.js.map +1 -1
  69. package/ietf/goaway.d.ts +9 -1
  70. package/ietf/goaway.d.ts.map +1 -1
  71. package/ietf/goaway.js +20 -0
  72. package/ietf/goaway.js.map +1 -1
  73. package/ietf/hidden.d.ts +2 -0
  74. package/ietf/hidden.d.ts.map +1 -0
  75. package/ietf/hidden.js +30 -0
  76. package/ietf/hidden.js.map +1 -0
  77. package/ietf/index.d.ts +2 -1
  78. package/ietf/index.d.ts.map +1 -1
  79. package/ietf/index.js +2 -1
  80. package/ietf/index.js.map +1 -1
  81. package/ietf/object.d.ts +15 -8
  82. package/ietf/object.d.ts.map +1 -1
  83. package/ietf/object.js +54 -36
  84. package/ietf/object.js.map +1 -1
  85. package/ietf/parameters.d.ts +12 -0
  86. package/ietf/parameters.d.ts.map +1 -1
  87. package/ietf/parameters.js +82 -12
  88. package/ietf/parameters.js.map +1 -1
  89. package/ietf/properties.d.ts +1 -0
  90. package/ietf/properties.d.ts.map +1 -1
  91. package/ietf/properties.js +14 -0
  92. package/ietf/properties.js.map +1 -1
  93. package/ietf/publish.d.ts +19 -2
  94. package/ietf/publish.d.ts.map +1 -1
  95. package/ietf/publish.js +40 -6
  96. package/ietf/publish.js.map +1 -1
  97. package/ietf/publish_namespace.d.ts +2 -2
  98. package/ietf/publish_namespace.js +2 -2
  99. package/ietf/publish_namespace.js.map +1 -1
  100. package/ietf/publisher.js +383 -214
  101. package/ietf/publisher.js.map +1 -1
  102. package/ietf/subscribe.d.ts +7 -1
  103. package/ietf/subscribe.d.ts.map +1 -1
  104. package/ietf/subscribe.js +25 -18
  105. package/ietf/subscribe.js.map +1 -1
  106. package/ietf/subscribe_namespace.d.ts +8 -2
  107. package/ietf/subscribe_namespace.d.ts.map +1 -1
  108. package/ietf/subscribe_namespace.js +20 -11
  109. package/ietf/subscribe_namespace.js.map +1 -1
  110. package/ietf/subscriber.js +226 -88
  111. package/ietf/subscriber.js.map +1 -1
  112. package/ietf/token.d.ts +2 -0
  113. package/ietf/token.d.ts.map +1 -0
  114. package/ietf/token.js +99 -0
  115. package/ietf/token.js.map +1 -0
  116. package/ietf/track.d.ts +4 -0
  117. package/ietf/track.d.ts.map +1 -1
  118. package/ietf/track.js +6 -20
  119. package/ietf/track.js.map +1 -1
  120. package/index.d.ts +1 -1
  121. package/index.d.ts.map +1 -1
  122. package/index.js.map +1 -1
  123. package/internal.d.ts +19 -3
  124. package/internal.d.ts.map +1 -1
  125. package/internal.js +43 -0
  126. package/internal.js.map +1 -1
  127. package/lite/announce.d.ts +46 -2
  128. package/lite/announce.d.ts.map +1 -1
  129. package/lite/announce.js +133 -15
  130. package/lite/announce.js.map +1 -1
  131. package/lite/connection.d.ts +1 -1
  132. package/lite/connection.d.ts.map +1 -1
  133. package/lite/connection.js +30 -9
  134. package/lite/connection.js.map +1 -1
  135. package/lite/datagram.d.ts +3 -2
  136. package/lite/datagram.d.ts.map +1 -1
  137. package/lite/datagram.js +7 -8
  138. package/lite/datagram.js.map +1 -1
  139. package/lite/group.d.ts +12 -8
  140. package/lite/group.d.ts.map +1 -1
  141. package/lite/group.js +37 -16
  142. package/lite/group.js.map +1 -1
  143. package/lite/message.d.ts +2 -2
  144. package/lite/message.d.ts.map +1 -1
  145. package/lite/message.js +14 -5
  146. package/lite/message.js.map +1 -1
  147. package/lite/publisher.js +174 -133
  148. package/lite/publisher.js.map +1 -1
  149. package/lite/setup.d.ts +1 -1
  150. package/lite/setup.d.ts.map +1 -1
  151. package/lite/setup.js +22 -19
  152. package/lite/setup.js.map +1 -1
  153. package/lite/subscribe.d.ts +10 -4
  154. package/lite/subscribe.d.ts.map +1 -1
  155. package/lite/subscribe.js +20 -10
  156. package/lite/subscribe.js.map +1 -1
  157. package/lite/subscriber.d.ts +10 -2
  158. package/lite/subscriber.d.ts.map +1 -1
  159. package/lite/subscriber.js +333 -188
  160. package/lite/subscriber.js.map +1 -1
  161. package/lite/version.d.ts +11 -0
  162. package/lite/version.d.ts.map +1 -1
  163. package/lite/version.js +56 -0
  164. package/lite/version.js.map +1 -1
  165. package/origin.d.ts +46 -19
  166. package/origin.d.ts.map +1 -1
  167. package/origin.js +529 -189
  168. package/origin.js.map +1 -1
  169. package/package.json +8 -4
  170. package/stream.d.ts +79 -14
  171. package/stream.d.ts.map +1 -1
  172. package/stream.js +375 -133
  173. package/stream.js.map +1 -1
  174. package/tail.d.ts +18 -0
  175. package/tail.d.ts.map +1 -0
  176. package/tail.js +167 -0
  177. package/tail.js.map +1 -0
  178. package/track.d.ts +46 -7
  179. package/track.d.ts.map +1 -1
  180. package/track.js +263 -101
  181. package/track.js.map +1 -1
  182. package/util/abort.d.ts +2 -0
  183. package/util/abort.d.ts.map +1 -0
  184. package/util/abort.js +20 -0
  185. package/util/abort.js.map +1 -0
  186. package/util/u64.d.ts +39 -0
  187. package/util/u64.d.ts.map +1 -0
  188. package/util/u64.js +83 -0
  189. package/util/u64.js.map +1 -0
  190. package/util/varint.d.ts +29 -0
  191. package/util/varint.d.ts.map +1 -0
  192. package/util/varint.js +198 -0
  193. package/util/varint.js.map +1 -0
  194. package/varint.d.ts +10 -6
  195. package/varint.d.ts.map +1 -1
  196. package/varint.js +40 -237
  197. package/varint.js.map +1 -1
  198. package/wire.d.ts +19 -3
  199. package/wire.d.ts.map +1 -1
  200. package/wire.js.map +1 -1
  201. package/ietf/control.d.ts +0 -135
  202. package/ietf/control.d.ts.map +0 -1
  203. package/ietf/control.js +0 -242
  204. package/ietf/control.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"reload.js","sourceRoot":"","sources":["../../src/connection/reload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAgC,IAAI,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAClF,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE/D,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,OAAO,EAAqB,OAAO,EAA+C,MAAM,cAAc,CAAC;AAuDvG;;;;;;;;GAQG;AACH,MAAM,aAAa,GAA0B;IAC5C,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;IACzB,UAAU,EAAE,CAAC;IACb,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;IACrB,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC;CAC1B,CAAC;AAEF,2EAA2E;AAC3E,MAAM,cAAc,GAAG,GAAG,CAAC;AAK3B;;;;;GAKG;AACH,MAAM,OAAO,MAAM;IAClB,iEAAiE;IACjE,GAAG,CAA0B;IAE7B,sCAAsC;IACtC,OAAO,CAAkB;IAEzB,iCAAiC;IACjC,MAAM,GAAG,IAAI,MAAM,CAAe,cAAc,CAAC,CAAC;IAElD;;;;;;OAMG;IACM,KAAK,CAA4B;IAE1C,0EAA0E;IAC1E,WAAW,GAAG,IAAI,MAAM,C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pF,CAAC;wBAAS,CAAC;oBACV,iFAAiF;oBACjF,4DAA4D;oBAC5D,IAAI,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,SAAS,EAAE,CAAC;wBAC1C,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC;4BACrC,QAAQ,CAAC,MAAM,CAAC,EAAE,GAAG,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CAAC;wBAClD,CAAC;oBACF,CAAC;gBACF,CAAC;YACF,CAAC,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;QAC1C,KAAK,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;QAE9C,OAAO,QAAQ,CAAC;IACjB,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,KAAK;QACV,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC;IACzC,CAAC;IAED,qGAAqG;IACrG,KAAK,CAAC,KAAa;QAClB,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QACtB,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,SAAS;YAAE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC;IACxE,CAAC;CACD","sourcesContent":["import { Effect, type GetPromise, type Getter, Once, Signal } from \"@moq/signals\";\nimport * as Announce from \"../announced.ts\";\nimport { Allocator } from \"../bandwidth.ts\";\nimport { error, SessionCode, SessionError } from \"../error.ts\";\nimport type { Consumer as OriginConsumer, Producer as OriginProducer } from \"../origin.ts\";\nimport * as Path from \"../path.ts\";\nimport * as Time from \"../time.ts\";\nimport { wireOf } from \"../wire.ts\";\nimport { type ConnectProps, connect, type WebSocketProps, type WebTransportProps } from \"./connect.ts\";\nimport type { Established } from \"./established.ts\";\nimport type { Probe, Stats } from \"./stats.ts\";\n\n/**\n * Exponential backoff settings for the reconnect loop.\n *\n * The delays carry jitter, so a fleet of tabs knocked offline together doesn't reconnect in\n * lockstep. Every failure is retried; {@link ReloadDelay.timeout} is what stops the current\n * URL. A new URL or a disable/re-enable starts another sequence.\n */\nexport type ReloadDelay = {\n\t/** The delay before reconnecting (default: 1000ms). */\n\tinitial?: Time.Milli;\n\n\t/** The multiplier for the delay (default: 2). */\n\tmultiplier?: number;\n\n\t/** The maximum delay (default: 5000ms). */\n\tmax?: Time.Milli;\n\n\t/**\n\t * Maximum total time to spend retrying the current URL before giving up\n\t * (default: 10000ms). Resets after each successful connection, a URL change, or a\n\t * disable/re-enable. Set to 0 for unlimited retries.\n\t */\n\ttimeout?: Time.Milli;\n};\n\n/**\n * Connection and retry options for {@link Reload}.\n *\n * {@link ConnectProps.transport} is excluded: a supplied session is good for exactly one\n * connection, so the reconnect loop has nothing to reuse once that session drops. Call\n * {@link connect} directly when you have a session to hand over.\n *\n * @internal\n */\nexport type ReloadProps = Omit<ConnectProps, \"url\" | \"signal\" | \"transport\"> & {\n\t/** A reload owns the abort signal for each connection attempt. */\n\tsignal?: never;\n\n\t/** A one-shot transport cannot be reused by the reconnect loop. */\n\ttransport?: never;\n\n\t/** Whether to reload the connection when it disconnects (default: true). */\n\tenabled?: boolean | Signal<boolean>;\n\n\t/** The URL of the relay server. */\n\turl?: URL | Signal<URL | undefined>;\n\n\t/** Backoff settings for the reconnect loop; every field falls back to its default. */\n\tdelay?: ReloadDelay;\n};\n\n/**\n * The backoff applied to whichever {@link ReloadDelay} fields a caller leaves out.\n *\n * The timeout is short on purpose: a failure that clears within it was transient, and one that\n * doesn't should surface on {@link Reload.error} rather than leave the page silently\n * reconnecting for minutes. A loop nobody watches wants `timeout: 0` instead, since there is\n * no one to react. Giving up does not dispose the loop: a new URL or a disable/re-enable\n * starts another sequence.\n */\nconst DEFAULT_DELAY: Required<ReloadDelay> = {\n\tinitial: Time.Milli(1000),\n\tmultiplier: 2,\n\tmax: Time.Milli(5000),\n\ttimeout: Time.Milli(10000),\n};\n\n/** How often the send-rate estimate is sampled from the live transport. */\nconst BANDWIDTH_POLL = 100;\n\n/** Current state of a reconnecting connection. */\nexport type ReloadStatus = \"connecting\" | \"connected\" | \"disconnected\";\n\n/**\n * The reconnect loop behind a Connection handle: connects, waits for the session to end, then\n * redials with exponential backoff.\n *\n * @internal\n */\nexport class Reload {\n\t/** Relay URL to connect to; updating it triggers a reconnect. */\n\turl: Signal<URL | undefined>;\n\n\t/** Whether reconnecting is active. */\n\tenabled: Signal<boolean>;\n\n\t/** Current connection status. */\n\tstatus = new Signal<ReloadStatus>(\"disconnected\");\n\n\t/**\n\t * The failure that stopped retrying the current URL, or undefined while the loop is live.\n\t *\n\t * Set on an auth rejection or when the retry window expires. Cleared when a new URL or a\n\t * disable/re-enable starts another sequence, not on a page hide/show. Transient drops\n\t * that are still being retried leave this empty.\n\t */\n\treadonly error: Getter<Error | undefined>;\n\n\t/** The currently established session, or undefined while disconnected. */\n\testablished = new Signal<Established | undefined>(undefined);\n\n\t/**\n\t * The current connection's PROBE estimates, spanning reconnects.\n\t *\n\t * Undefined while disconnected: the estimates belong to a single connection.\n\t * See {@link Established.probe}.\n\t */\n\treadonly probe: Getter<Probe | undefined>;\n\n\t/**\n\t * Divides this connection's send-rate estimate among the tracks sharing it.\n\t *\n\t * The same instance across reconnects, so reservations survive a drop. The\n\t * estimate is `undefined` while disconnected, which tells a sender to hold\n\t * its rate rather than encode at zero.\n\t */\n\treadonly bandwidth: Allocator;\n\n\t/** WebTransport options applied to each connection attempt (not reactive). */\n\twebtransport?: WebTransportProps;\n\n\t/** WebSocket fallback options applied to each connection attempt (not reactive). */\n\twebsocket: WebSocketProps | undefined;\n\n\t/**\n\t * Whether the relay supports broadcast discovery, applied to each connection attempt (not\n\t * reactive). Undefined defers to the default for the URL. See {@link Established.discovery}.\n\t */\n\tdiscovery?: boolean;\n\n\t/**\n\t * The origin whose broadcasts are served, spanning reconnects (not reactive).\n\t *\n\t * Each session announces the origin's table when it attaches, so a broadcast published\n\t * while offline surfaces on the next connection and a reconnect re-announces everything\n\t * still published. See the `publish` connect option.\n\t */\n\tpublish?: OriginConsumer;\n\n\t/**\n\t * The origin fed with the peer's announced broadcasts, spanning reconnects (not\n\t * reactive).\n\t *\n\t * The entries a session fed retract when it dies, and the next session re-populates the\n\t * table, so a consumer watching the origin sees offline/online transitions across a\n\t * reconnect. See the `consume` connect option.\n\t */\n\tconsume?: OriginProducer;\n\n\t/** Backoff settings for the reconnect loop; an unset field uses its default. */\n\tdelay: ReloadDelay;\n\n\t/** The reactive effect scope driving the connect loop; closed by {@link Reload.close}. */\n\t#signals = new Effect();\n\n\t// Sampled from the live session; undefined while disconnected or the transport has none.\n\t#estimate = new Signal<number | undefined>(undefined);\n\n\t/**\n\t * Settles once this loop is disposed via {@link Reload.close}: `null` on a clean close,\n\t * or the abort {@link Error}. Peek it synchronously (`undefined` while open), observe it\n\t * reactively, or `await` it. Attempt failures live on {@link Reload.error} instead.\n\t */\n\tget closed(): GetPromise<Error | null> {\n\t\treturn this.#closed;\n\t}\n\n\t#closed = new Once<Error | null>();\n\t#error = new Signal<Error | undefined>(undefined);\n\n\t// The current wait between attempts, doubling per failure, and when the retry window expires.\n\t// Both are undefined between sequences, so a later edit to `delay` applies to the next one.\n\t#delay: DOMHighResTimeStamp | undefined;\n\t#deadline: DOMHighResTimeStamp | undefined;\n\n\t// The URL the current retry sequence is for. Cleared when disabled, URL-less, or given\n\t// up, so the next attempt starts a fresh backoff window.\n\t#sequenceHref: string | undefined;\n\n\t// The href that exhausted its retry sequence. Survives a page hide/show so resume does\n\t// not redial credentials the peer already refused. Cleared when the URL changes or the\n\t// loop is disabled.\n\t#givenUpHref: string | undefined;\n\n\t// Increased by 1 each time to trigger a reload.\n\t#tick = new Signal(0);\n\n\t// True after the browser freezes or hides the page until it visibly resumes.\n\t#suspended = new Signal(false);\n\n\t// Use the serialized URL as the reactive connection key. URL objects use identity\n\t// equality, but replacing one with an equivalent instance should not reconnect.\n\t#url: Getter<string | undefined>;\n\tconstructor(props?: ReloadProps) {\n\t\tthis.url = Signal.from(props?.url);\n\t\tthis.enabled = Signal.from(props?.enabled ?? true);\n\t\tthis.delay = props?.delay ?? {};\n\t\tthis.webtransport = props?.webtransport;\n\t\tthis.websocket = props?.websocket;\n\t\tthis.discovery = props?.discovery;\n\t\tthis.publish = props?.publish;\n\t\tthis.consume = props?.consume;\n\n\t\t// Requests on the consume origin stay pending across a reconnect, and before the\n\t\t// first session establishes, rather than reading as unroutable the moment no session\n\t\t// is attached. Released only when this loop is disposed: giving up the current URL\n\t\t// is recoverable (a new URL or a disable/re-enable starts another sequence), so a\n\t\t// request must keep waiting rather than go unroutable in the gap.\n\t\tif (this.consume) {\n\t\t\tthis.#signals.cleanup(wireOf(this.consume).expect());\n\t\t}\n\n\t\tthis.error = this.#error;\n\n\t\tconst win = globalThis.window;\n\t\tconst doc = globalThis.document;\n\t\tif (typeof win !== \"undefined\" && typeof doc !== \"undefined\") {\n\t\t\tthis.#signals.event(win, \"pagehide\", () => this.#suspended.set(true));\n\t\t\tthis.#signals.event(win, \"pageshow\", () => this.#suspended.set(false));\n\t\t\tthis.#signals.event(win, \"unload\", () => this.#suspended.set(true));\n\t\t\tthis.#signals.event(doc, \"visibilitychange\", () => {\n\t\t\t\tif (!doc.hidden) this.#suspended.set(false);\n\t\t\t});\n\t\t}\n\n\t\tthis.probe = this.#signals.computed((effect) => {\n\t\t\tconst connection = effect.get(this.established);\n\t\t\treturn connection && effect.get(connection.probe);\n\t\t});\n\n\t\tthis.bandwidth = new Allocator(this.#estimate);\n\t\tthis.#signals.cleanup(() => this.bandwidth.close());\n\n\t\t// The transport has no event for the send-rate estimate, so sample on our\n\t\t// own schedule and skip a tick while the previous snapshot is outstanding.\n\t\tthis.#signals.run((effect) => {\n\t\t\teffect.set(this.#estimate, undefined);\n\t\t\tconst connection = effect.get(this.established);\n\t\t\tif (!connection) return;\n\n\t\t\tlet pending = false;\n\t\t\tconst sample = async () => {\n\t\t\t\tif (pending) return;\n\t\t\t\tpending = true;\n\t\t\t\ttry {\n\t\t\t\t\tconst stats = await Promise.race([effect.cancel, connection.stats()]);\n\t\t\t\t\tif (stats) this.#estimate.set(stats.estimatedSendRate);\n\t\t\t\t} finally {\n\t\t\t\t\tpending = false;\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tvoid sample();\n\t\t\teffect.interval(() => void sample(), BANDWIDTH_POLL);\n\t\t});\n\n\t\tthis.#url = this.#signals.computed((effect) => effect.get(this.url)?.href);\n\t\t// Create a reactive root so cleanup is easier.\n\t\tthis.#signals.run(this.#connect.bind(this));\n\t}\n\n\t#connect(effect: Effect): void {\n\t\t// Will retry when the tick changes.\n\t\teffect.get(this.#tick);\n\n\t\tconst enabled = effect.get(this.enabled);\n\t\tif (!enabled) {\n\t\t\tthis.#givenUpHref = undefined;\n\t\t\tthis.#resetSequence();\n\t\t\treturn;\n\t\t}\n\n\t\t// Hide/freeze pauses an in-flight sequence without recovering from give-up.\n\t\tconst suspended = effect.get(this.#suspended);\n\t\tif (suspended) {\n\t\t\tthis.#resetSequence();\n\t\t\treturn;\n\t\t}\n\n\t\tconst href = effect.get(this.#url);\n\t\tif (!href) {\n\t\t\tthis.#givenUpHref = undefined;\n\t\t\tthis.#resetSequence();\n\t\t\treturn;\n\t\t}\n\t\tconst url = new URL(href);\n\n\t\tif (this.#givenUpHref === href) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.#sequenceHref !== href) {\n\t\t\tthis.#resetSequence();\n\t\t\tthis.#sequenceHref = href;\n\t\t\tthis.#error.set(undefined);\n\t\t\tthis.#givenUpHref = undefined;\n\t\t}\n\n\t\teffect.set(this.status, \"connecting\", \"disconnected\");\n\n\t\t// This run's teardown, handed to connect() so a rerun cancels the attempt in flight.\n\t\tconst signal = effect.abort;\n\n\t\teffect.spawn(async () => {\n\t\t\t// Set once the session is live, so #retry can tell a healthy session that\n\t\t\t// later dropped from a connect failure or a peer that flaps immediately.\n\t\t\tlet connected: DOMHighResTimeStamp | undefined;\n\n\t\t\ttry {\n\t\t\t\tconst connection = await connect({\n\t\t\t\t\turl,\n\t\t\t\t\twebsocket: this.websocket,\n\t\t\t\t\twebtransport: this.webtransport,\n\t\t\t\t\tdiscovery: this.discovery,\n\t\t\t\t\tpublish: this.publish,\n\t\t\t\t\tconsume: this.consume,\n\t\t\t\t\tsignal,\n\t\t\t\t});\n\n\t\t\t\t// Hand the connection to the effect, which closes it now if this run is already over.\n\t\t\t\teffect.cleanup(() => connection.close());\n\t\t\t\tif (signal.aborted) return;\n\n\t\t\t\teffect.set(this.established, connection);\n\t\t\t\teffect.set(this.status, \"connected\", \"disconnected\");\n\n\t\t\t\tconnected = performance.now();\n\n\t\t\t\t// A cancelled effect resolves undefined, so the sentinel tells the session\n\t\t\t\t// closing (null for clean, an Error otherwise) apart from this run being\n\t\t\t\t// torn down.\n\t\t\t\tconst closed = await Promise.race([effect.cancel, connection.closed]);\n\t\t\t\tif (closed === undefined) return;\n\n\t\t\t\tconsole.warn(\"connection closed, reconnecting\");\n\t\t\t\tthis.#retry(effect, connected, closed ?? undefined);\n\t\t\t} catch (err) {\n\t\t\t\t// Treat teardown as cancellation, not a connection failure.\n\t\t\t\tif (signal.aborted) return;\n\n\t\t\t\tconsole.warn(\"connection error:\", err);\n\t\t\t\tthis.#retry(effect, connected, err);\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Schedule the next connect attempt after the current backoff, or stop once the retry window\n\t * has expired. `connected` is when the dead session was established, if it ever was, and\n\t * `cause` the error that killed it, if it died with one.\n\t */\n\t#retry(effect: Effect, connected: DOMHighResTimeStamp | undefined, cause?: unknown): void {\n\t\t// Resolved per sequence rather than at construction, so an edit to `delay` (including\n\t\t// one that drops a field back to its default) applies to the next retry. Field by\n\t\t// field rather than by spread: a caller building `{ initial: maybeInitial }` from an\n\t\t// optional value passes an explicit undefined, which a spread would take as the\n\t\t// answer, turning the backoff into NaN or the window into forever.\n\t\tconst delay = this.delay ?? {};\n\t\tconst initial = delay.initial ?? DEFAULT_DELAY.initial;\n\t\tconst multiplier = delay.multiplier ?? DEFAULT_DELAY.multiplier;\n\t\tconst max = delay.max ?? DEFAULT_DELAY.max;\n\t\tconst timeout = delay.timeout ?? DEFAULT_DELAY.timeout;\n\n\t\t// Any session is dead now: report disconnected during the backoff rather than\n\t\t// when the retry reruns the effect.\n\t\tthis.established.set(undefined);\n\t\tthis.status.set(\"disconnected\");\n\n\t\t// A session that outlived the initial delay was healthy, so clear the backoff and\n\t\t// start a fresh retry window: a one-off drop should reconnect promptly. Anything\n\t\t// shorter is a peer that accepts and immediately severs, which has to keep\n\t\t// escalating or we hammer it forever at the initial delay.\n\t\tif (connected !== undefined && performance.now() - connected >= initial) {\n\t\t\tthis.#delay = undefined;\n\t\t\tthis.#deadline = undefined;\n\t\t}\n\n\t\t// An auth rejection stops this URL however long the session lived. UNAUTHORIZED is a\n\t\t// specified code rather than one we guessed at, so this is the peer saying these\n\t\t// credentials will never work; retrying them just burns the window. Matches\n\t\t// moq-tokio's reconnect loop, which stops on the same close. A new URL or a\n\t\t// disable/re-enable starts another sequence; the handle itself is not disposed.\n\t\t//\n\t\t// Only a session close says that. The stream registry gives 2 to DELIVERY_TIMEOUT,\n\t\t// so a stream reset during the SETUP exchange would otherwise suppress reconnect\n\t\t// for good.\n\t\tif (cause instanceof SessionError && cause.code === SessionCode.Unauthorized) {\n\t\t\tconsole.warn(\"session rejected as unauthorized, not retrying\");\n\t\t\tthis.#giveUp(cause);\n\t\t\treturn;\n\t\t}\n\n\t\tconst now = performance.now();\n\t\tthis.#delay ??= initial;\n\t\tthis.#deadline ??= timeout > 0 ? now + timeout : Number.POSITIVE_INFINITY;\n\n\t\tif (now >= this.#deadline) {\n\t\t\tconsole.warn(\"reconnect timed out\");\n\t\t\t// A graceful close has no error, so report the timeout itself.\n\t\t\tthis.#giveUp(cause === undefined ? new Error(\"reconnect timed out\") : error(cause));\n\t\t\treturn;\n\t\t}\n\n\t\t// Equal jitter, so a fleet of tabs knocked offline together doesn't reconnect on the same\n\t\t// tick, and never past the deadline the retry window promised.\n\t\tconst wait = Math.min(this.#delay * (0.5 + Math.random() / 2), this.#deadline - now);\n\t\tthis.#delay = Math.min(this.#delay * multiplier, max);\n\n\t\tconst tick = this.#tick.peek() + 1;\n\t\teffect.timer(() => this.#tick.update((prev) => Math.max(prev, tick)), wait);\n\t}\n\n\t#giveUp(cause: Error): void {\n\t\tthis.#error.set(cause);\n\t\tthis.#givenUpHref = this.#sequenceHref;\n\t\tthis.#resetSequence();\n\t}\n\n\t#resetSequence(): void {\n\t\tthis.#delay = undefined;\n\t\tthis.#deadline = undefined;\n\t\tthis.#sequenceHref = undefined;\n\t}\n\n\t/**\n\t * Subscribe to broadcast announcements matching `scope`, spanning reconnects.\n\t *\n\t * The same {@link Announce.Consumer} stream as {@link Established.announced}, but everything active\n\t * is retracted (a `retracted` update) whenever the connection drops and re-announced on\n\t * reconnect, so a consumer draining `next()` never clings to a dead route across a reconnect.\n\t *\n\t * Stays empty while the relay lacks {@link Established.discovery}.\n\t */\n\tannounced(scope: Path.Pattern = Path.Pattern.all()): Announce.Consumer {\n\t\t// With a consume origin the table already spans reconnects (the forwarder retracts\n\t\t// a dead session's entries), so its stream is the same thing with less machinery.\n\t\tif (this.consume) return this.consume.announced(scope);\n\n\t\tconst producer = new Announce.Producer();\n\t\tconst consumer = producer.consume();\n\n\t\tconst pump = new Effect();\n\t\tpump.run((effect) => {\n\t\t\tconst conn = effect.get(this.established);\n\t\t\tif (!conn) return;\n\n\t\t\t// Without discovery the upstream announce stream never yields, so leave the\n\t\t\t// consumer empty rather than opening a subscription that can't be answered.\n\t\t\tif (!conn.discovery) return;\n\n\t\t\tconst upstream = conn.announced(scope);\n\t\t\teffect.cleanup(() => upstream.close());\n\n\t\t\t// Track what this connection announced so we can retract it if the connection\n\t\t\t// drops; the last event rides along for the retraction.\n\t\t\tconst active = new Map<Path.Valid, Announce.Update>();\n\n\t\t\teffect.spawn(async () => {\n\t\t\t\ttry {\n\t\t\t\t\tfor (;;) {\n\t\t\t\t\t\tconst entry = await Promise.race([effect.cancel, upstream.next()]);\n\t\t\t\t\t\tif (!entry) break;\n\t\t\t\t\t\tif (Announce.isActive(entry.kind)) active.set(entry.prefix, entry);\n\t\t\t\t\t\telse active.delete(entry.prefix);\n\t\t\t\t\t\tproducer.append(entry);\n\t\t\t\t\t}\n\t\t\t\t} catch {\n\t\t\t\t\t// A dropped connection resets the announce stream; the retractions below cover it.\n\t\t\t\t} finally {\n\t\t\t\t\t// Retract everything from the connection that just went away, so a per-broadcast\n\t\t\t\t\t// watcher tears down instead of clinging to the dead route.\n\t\t\t\t\tif (consumer.closed.peek() === undefined) {\n\t\t\t\t\t\tfor (const entry of active.values()) {\n\t\t\t\t\t\t\tproducer.append({ ...entry, kind: \"retracted\" });\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\n\t\tthis.#signals.cleanup(() => pump.close());\n\t\tvoid consumer.closed.then(() => pump.close());\n\n\t\treturn consumer;\n\t}\n\n\t/**\n\t * Snapshot the live connection's transport counters, or undefined while disconnected.\n\t * See {@link Established.stats}.\n\t */\n\tasync stats(): Promise<Stats | undefined> {\n\t\treturn this.established.peek()?.stats();\n\t}\n\n\t/** Stop reconnecting, close the current connection, and settle {@link Reload.closed}. Idempotent. */\n\tclose(abort?: Error) {\n\t\tthis.#signals.close();\n\t\tif (this.#closed.peek() === undefined) this.#closed.set(abort ?? null);\n\t}\n}\n"]}
1
+ {"version":3,"file":"reload.js","sourceRoot":"","sources":["../../src/connection/reload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAgC,IAAI,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAClF,OAAO,KAAK,Q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C,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC;IACzC,CAAC;IAED,qGAAqG;IACrG,KAAK,CAAC,KAAa;QAClB,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QACtB,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,CAAC;QACzB,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,SAAS;YAAE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC;IACxE,CAAC;CACD;AAED;;;GAGG;AACH,MAAM,QAAQ;IACb,WAAW,CAAc;IACzB,MAAM,CAAgC;IACtC,SAAS,CAAa;IACtB,QAAQ,GAAG,KAAK,CAAC;IAEjB,YAAY,UAAuB,EAAE,QAAoB,EAAE,QAAoB;QAC9E,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAC9B,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC1B,IAAI,CAAC,MAAM,GAAG,UAAU,CAAC,GAAG,EAAE;YAC7B,OAAO,CAAC,IAAI,CAAC,4CAA4C,CAAC,CAAC;YAC3D,IAAI,CAAC,MAAM,EAAE,CAAC;QACf,CAAC,EAAE,QAAQ,CAAC,CAAC;QACb,KAAK,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IAClD,CAAC;IAED,6EAA6E;IAC7E,MAAM;QACL,IAAI,IAAI,CAAC,QAAQ;YAAE,OAAO;QAC1B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC1B,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;QACzB,IAAI,CAAC,SAAS,EAAE,CAAC;IAClB,CAAC;CACD","sourcesContent":["import { Effect, type GetPromise, type Getter, Once, Signal } from \"@moq/signals\";\nimport * as Announce from \"../announced.ts\";\nimport { Allocator } from \"../bandwidth.ts\";\nimport { error, SessionCode, SessionError } from \"../error.ts\";\nimport type { Consumer as OriginConsumer, Producer as OriginProducer } from \"../origin.ts\";\nimport * as Path from \"../path.ts\";\nimport * as Time from \"../time.ts\";\nimport { wireOf } from \"../wire.ts\";\nimport { type ConnectProps, connect, type WebSocketProps, type WebTransportProps } from \"./connect.ts\";\nimport type { Established } from \"./established.ts\";\nimport { DEFAULT_HANDOVER, type Drain, dialed, type GoawayProps, handover, pinnedTransport, target } from \"./goaway.ts\";\nimport type { Probe, Stats } from \"./stats.ts\";\n\n/**\n * Exponential backoff settings for the reconnect loop.\n *\n * The delays carry jitter, so a fleet of tabs knocked offline together doesn't reconnect in\n * lockstep. Every failure is retried; {@link ReloadDelay.timeout} is what stops the current\n * URL. A new URL or a disable/re-enable starts another sequence.\n */\nexport type ReloadDelay = {\n\t/** The delay before reconnecting (default: 1000ms). */\n\tinitial?: Time.Milli;\n\n\t/** The multiplier for the delay (default: 2). */\n\tmultiplier?: number;\n\n\t/** The maximum delay (default: 5000ms). */\n\tmax?: Time.Milli;\n\n\t/**\n\t * Maximum total time to spend retrying the current URL before giving up\n\t * (default: 10000ms). Resets after each successful connection, a URL change, or a\n\t * disable/re-enable. Set to 0 for unlimited retries.\n\t */\n\ttimeout?: Time.Milli;\n};\n\n/**\n * Connection and retry options for {@link Reload}.\n *\n * {@link ConnectProps.transport} is excluded: a supplied session is good for exactly one\n * connection, so the reconnect loop has nothing to reuse once that session drops. Call\n * {@link connect} directly when you have a session to hand over.\n *\n * @internal\n */\nexport type ReloadProps = Omit<ConnectProps, \"url\" | \"signal\" | \"transport\"> & {\n\t/** A reload owns the abort signal for each connection attempt. */\n\tsignal?: never;\n\n\t/** A one-shot transport cannot be reused by the reconnect loop. */\n\ttransport?: never;\n\n\t/** Whether to reload the connection when it disconnects (default: true). */\n\tenabled?: boolean | Signal<boolean>;\n\n\t/** The URL of the relay server. */\n\turl?: URL | Signal<URL | undefined>;\n\n\t/** Backoff settings for the reconnect loop; every field falls back to its default. */\n\tdelay?: ReloadDelay;\n\n\t/** How to react to the peer's GOAWAY; every field falls back to its default. */\n\tgoaway?: GoawayProps;\n};\n\n/**\n * The backoff applied to whichever {@link ReloadDelay} fields a caller leaves out.\n *\n * The timeout is short on purpose: a failure that clears within it was transient, and one that\n * doesn't should surface on {@link Reload.error} rather than leave the page silently\n * reconnecting for minutes. A loop nobody watches wants `timeout: 0` instead, since there is\n * no one to react. Giving up does not dispose the loop: a new URL or a disable/re-enable\n * starts another sequence.\n */\nconst DEFAULT_DELAY: Required<ReloadDelay> = {\n\tinitial: Time.Milli(1000),\n\tmultiplier: 2,\n\tmax: Time.Milli(5000),\n\ttimeout: Time.Milli(10000),\n};\n\n/** How often the send-rate estimate is sampled from the live transport. */\nconst BANDWIDTH_POLL = 100;\n\n/** Current state of a reconnecting connection. */\nexport type ReloadStatus = \"connecting\" | \"connected\" | \"disconnected\";\n\n/**\n * The reconnect loop behind a Connection handle: connects, waits for the session to end, then\n * redials with exponential backoff.\n *\n * @internal\n */\nexport class Reload {\n\t/** Relay URL to connect to; updating it triggers a reconnect. */\n\turl: Signal<URL | undefined>;\n\n\t/** Whether reconnecting is active. */\n\tenabled: Signal<boolean>;\n\n\t/** Current connection status. */\n\tstatus = new Signal<ReloadStatus>(\"disconnected\");\n\n\t/**\n\t * The failure that stopped retrying the current URL, or undefined while the loop is live.\n\t *\n\t * Set on an auth rejection or when the retry window expires. Cleared when a new URL or a\n\t * disable/re-enable starts another sequence, not on a page hide/show. Transient drops\n\t * that are still being retried leave this empty.\n\t */\n\treadonly error: Getter<Error | undefined>;\n\n\t/** The currently established session, or undefined while disconnected. */\n\testablished = new Signal<Established | undefined>(undefined);\n\n\t/**\n\t * The current connection's PROBE estimates, spanning reconnects.\n\t *\n\t * Undefined while disconnected: the estimates belong to a single connection.\n\t * See {@link Established.probe}.\n\t */\n\treadonly probe: Getter<Probe | undefined>;\n\n\t/**\n\t * Divides this connection's send-rate estimate among the tracks sharing it.\n\t *\n\t * The same instance across reconnects, so reservations survive a drop. The\n\t * estimate is `undefined` while disconnected, which tells a sender to hold\n\t * its rate rather than encode at zero.\n\t */\n\treadonly bandwidth: Allocator;\n\n\t/** WebTransport options applied to each connection attempt (not reactive). */\n\twebtransport?: WebTransportProps;\n\n\t/** WebSocket fallback options applied to each connection attempt (not reactive). */\n\twebsocket: WebSocketProps | undefined;\n\n\t/**\n\t * Whether the relay supports broadcast discovery, applied to each connection attempt (not\n\t * reactive). Undefined defers to the default for the URL. See {@link Established.discovery}.\n\t */\n\tdiscovery?: boolean;\n\n\t/**\n\t * The origin whose broadcasts are served, spanning reconnects (not reactive).\n\t *\n\t * Each session announces the origin's table when it attaches, so a broadcast published\n\t * while offline surfaces on the next connection and a reconnect re-announces everything\n\t * still published. See the `publish` connect option.\n\t */\n\tpublish?: OriginConsumer;\n\n\t/**\n\t * The origin fed with the peer's announced broadcasts, spanning reconnects (not\n\t * reactive).\n\t *\n\t * The entries a session fed retract when it dies, and the next session re-populates the\n\t * table, so a consumer watching the origin sees offline/online transitions across a\n\t * reconnect. See the `consume` connect option.\n\t */\n\tconsume?: OriginProducer;\n\n\t/** Backoff settings for the reconnect loop; an unset field uses its default. */\n\tdelay: ReloadDelay;\n\n\t/** How to react to the peer's GOAWAY (not reactive). */\n\tgoaway: GoawayProps;\n\n\t/**\n\t * The URL an accepted GOAWAY redirect assigned, or undefined while the loop dials\n\t * {@link Reload.url}. Sticky across reconnects: a redirect is an assignment, not a\n\t * detour. Cleared when a new URL or a disable/re-enable starts another sequence.\n\t */\n\treadonly redirect: Getter<URL | undefined>;\n\n\t/** The reactive effect scope driving the connect loop; closed by {@link Reload.close}. */\n\t#signals = new Effect();\n\n\t// Sampled from the live session; undefined while disconnected or the transport has none.\n\t#estimate = new Signal<number | undefined>(undefined);\n\n\t/**\n\t * Settles once this loop is disposed via {@link Reload.close}: `null` on a clean close,\n\t * or the abort {@link Error}. Peek it synchronously (`undefined` while open), observe it\n\t * reactively, or `await` it. Attempt failures live on {@link Reload.error} instead.\n\t */\n\tget closed(): GetPromise<Error | null> {\n\t\treturn this.#closed;\n\t}\n\n\t#closed = new Once<Error | null>();\n\t#error = new Signal<Error | undefined>(undefined);\n\t#redirect = new Signal<URL | undefined>(undefined);\n\t// The configured href the redirect was assigned for.\n\t#redirectHref: string | undefined;\n\n\t// A session the peer sent GOAWAY on, serving its groups in flight while the replacement\n\t// dials. Retired when it closes, at its handover cap, or when the sequence ends.\n\t#draining: Draining | undefined;\n\n\t// Whether a connect attempt is in flight, so a retiring predecessor reports the right status.\n\t#dialing = false;\n\n\t// The current wait between attempts, doubling per failure, and when the retry window expires.\n\t// Both are undefined between sequences, so a later edit to `delay` applies to the next one.\n\t#delay: DOMHighResTimeStamp | undefined;\n\t#deadline: DOMHighResTimeStamp | undefined;\n\n\t// The URL the current retry sequence is for. Cleared when disabled, URL-less, or given\n\t// up, so the next attempt starts a fresh backoff window.\n\t#sequenceHref: string | undefined;\n\n\t// The href that exhausted its retry sequence. Survives a page hide/show so resume does\n\t// not redial credentials the peer already refused. Cleared when the URL changes or the\n\t// loop is disabled.\n\t#givenUpHref: string | undefined;\n\n\t// Increased by 1 each time to trigger a reload.\n\t#tick = new Signal(0);\n\n\t// True after the browser freezes or hides the page until it visibly resumes.\n\t#suspended = new Signal(false);\n\n\t// Use the serialized URL as the reactive connection key. URL objects use identity\n\t// equality, but replacing one with an equivalent instance should not reconnect.\n\t#url: Getter<string | undefined>;\n\tconstructor(props?: ReloadProps) {\n\t\tthis.url = Signal.from(props?.url);\n\t\tthis.enabled = Signal.from(props?.enabled ?? true);\n\t\tthis.delay = props?.delay ?? {};\n\t\tthis.goaway = props?.goaway ?? {};\n\t\tthis.redirect = this.#redirect;\n\t\tthis.webtransport = props?.webtransport;\n\t\tthis.websocket = props?.websocket;\n\t\tthis.discovery = props?.discovery;\n\t\tthis.publish = props?.publish;\n\t\tthis.consume = props?.consume;\n\n\t\t// Requests on the consume origin stay pending across a reconnect, and before the\n\t\t// first session establishes, rather than reading as unroutable the moment no session\n\t\t// is attached. Released only when this loop is disposed: giving up the current URL\n\t\t// is recoverable (a new URL or a disable/re-enable starts another sequence), so a\n\t\t// request must keep waiting rather than go unroutable in the gap.\n\t\tif (this.consume) {\n\t\t\tthis.#signals.cleanup(wireOf(this.consume).expect());\n\t\t}\n\n\t\tthis.error = this.#error;\n\n\t\tconst win = globalThis.window;\n\t\tconst doc = globalThis.document;\n\t\tif (typeof win !== \"undefined\" && typeof doc !== \"undefined\") {\n\t\t\tthis.#signals.event(win, \"pagehide\", () => this.#suspended.set(true));\n\t\t\tthis.#signals.event(win, \"pageshow\", () => this.#suspended.set(false));\n\t\t\tthis.#signals.event(win, \"unload\", () => this.#suspended.set(true));\n\t\t\tthis.#signals.event(doc, \"visibilitychange\", () => {\n\t\t\t\tif (!doc.hidden) this.#suspended.set(false);\n\t\t\t});\n\t\t}\n\n\t\tthis.probe = this.#signals.computed((effect) => {\n\t\t\tconst connection = effect.get(this.established);\n\t\t\treturn connection && effect.get(connection.probe);\n\t\t});\n\n\t\tthis.bandwidth = new Allocator(this.#estimate);\n\t\tthis.#signals.cleanup(() => this.bandwidth.close());\n\n\t\t// The transport has no event for the send-rate estimate, so sample on our\n\t\t// own schedule and skip a tick while the previous snapshot is outstanding.\n\t\tthis.#signals.run((effect) => {\n\t\t\teffect.set(this.#estimate, undefined);\n\t\t\tconst connection = effect.get(this.established);\n\t\t\tif (!connection) return;\n\n\t\t\tlet pending = false;\n\t\t\tconst sample = async () => {\n\t\t\t\tif (pending) return;\n\t\t\t\tpending = true;\n\t\t\t\ttry {\n\t\t\t\t\tconst stats = await effect.race(connection.stats());\n\t\t\t\t\tif (stats) this.#estimate.set(stats.estimatedSendRate);\n\t\t\t\t} finally {\n\t\t\t\t\tpending = false;\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tvoid sample();\n\t\t\teffect.interval(() => void sample(), BANDWIDTH_POLL);\n\t\t});\n\n\t\tthis.#url = this.#signals.computed((effect) => effect.get(this.url)?.href);\n\t\t// Create a reactive root so cleanup is easier.\n\t\tthis.#signals.run(this.#connect.bind(this));\n\t}\n\n\t#connect(effect: Effect): void {\n\t\t// Will retry when the tick changes.\n\t\teffect.get(this.#tick);\n\n\t\tconst enabled = effect.get(this.enabled);\n\t\tif (!enabled) {\n\t\t\tthis.#givenUpHref = undefined;\n\t\t\tthis.#resetSequence();\n\t\t\tthis.#redirect.set(undefined);\n\t\t\treturn;\n\t\t}\n\n\t\t// Hide/freeze pauses an in-flight sequence without recovering from give-up.\n\t\tconst suspended = effect.get(this.#suspended);\n\t\tif (suspended) {\n\t\t\tthis.#resetSequence();\n\t\t\treturn;\n\t\t}\n\n\t\tconst href = effect.get(this.#url);\n\t\tif (!href) {\n\t\t\tthis.#givenUpHref = undefined;\n\t\t\tthis.#resetSequence();\n\t\t\tthis.#redirect.set(undefined);\n\t\t\treturn;\n\t\t}\n\t\tconst url = new URL(href);\n\n\t\tif (this.#givenUpHref === href) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.#sequenceHref !== href) {\n\t\t\tthis.#resetSequence();\n\t\t\t// A redirect was assigned for another URL; this one starts from itself. A page\n\t\t\t// hide/show resumes the same URL, so it keeps the assignment.\n\t\t\tif (this.#redirectHref !== href) this.#redirect.set(undefined);\n\t\t\tthis.#sequenceHref = href;\n\t\t\tthis.#error.set(undefined);\n\t\t\tthis.#givenUpHref = undefined;\n\t\t}\n\n\t\t// A drained predecessor still serves while its replacement dials.\n\t\tif (!this.#draining) this.status.set(\"connecting\");\n\n\t\t// This run's teardown, handed to connect() so a rerun cancels the attempt in flight.\n\t\tconst signal = effect.abort;\n\n\t\t// The session this run serves, closed with the run. A drained one leaves this slot\n\t\t// for #draining, which outlives the run.\n\t\tlet current: Established | undefined;\n\t\teffect.cleanup(() => {\n\t\t\tif (current) {\n\t\t\t\tcurrent.close();\n\t\t\t\tif (this.established.peek() === current) this.established.set(undefined);\n\t\t\t\tcurrent = undefined;\n\t\t\t}\n\t\t\tif (this.established.peek() === undefined) this.status.set(\"disconnected\");\n\t\t});\n\n\t\teffect.spawn(async () => {\n\t\t\t// Set once the session is live, so #retry can tell a healthy session that\n\t\t\t// later dropped from a connect failure or a peer that flaps immediately.\n\t\t\tlet connected: DOMHighResTimeStamp | undefined;\n\n\t\t\ttry {\n\t\t\t\t// Loops only to migrate: a GOAWAY off a healthy session dials its replacement\n\t\t\t\t// straight away, with no backoff.\n\t\t\t\tfor (;;) {\n\t\t\t\t\tconst dialing = this.#redirect.peek() ?? url;\n\n\t\t\t\t\tthis.#dialing = true;\n\t\t\t\t\tlet connection: Established;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconnection = await connect({\n\t\t\t\t\t\t\turl: dialing,\n\t\t\t\t\t\t\t// A redirect names the relay; a fallback URL pinned for the old one does not follow.\n\t\t\t\t\t\t\twebsocket: this.#redirect.peek() ? { ...this.websocket, url: undefined } : this.websocket,\n\t\t\t\t\t\t\twebtransport: this.webtransport,\n\t\t\t\t\t\t\tdiscovery: this.discovery,\n\t\t\t\t\t\t\tpublish: this.publish,\n\t\t\t\t\t\t\tconsume: this.consume,\n\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t\t});\n\t\t\t\t\t} finally {\n\t\t\t\t\t\tthis.#dialing = false;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Hand the connection to the effect, which closes it now if this run is already over.\n\t\t\t\t\tif (signal.aborted) {\n\t\t\t\t\t\tconnection.close();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tcurrent = connection;\n\n\t\t\t\t\t// The replacement serves now; a predecessor keeps draining its groups in flight.\n\t\t\t\t\tthis.established.set(connection);\n\t\t\t\t\tthis.status.set(\"connected\");\n\t\t\t\t\tconnected = performance.now();\n\n\t\t\t\t\t// A cancelled effect resolves undefined, so the sentinel tells the session\n\t\t\t\t\t// closing (null for clean, an Error otherwise) apart from this run being\n\t\t\t\t\t// torn down. Anything else is the peer's GOAWAY.\n\t\t\t\t\tconst ended = await effect.race(connection.closed, wireOf(connection).goaway);\n\t\t\t\t\tif (ended === undefined) return;\n\t\t\t\t\tif (ended === null || ended instanceof Error) {\n\t\t\t\t\t\tconsole.warn(\"connection closed, reconnecting\");\n\t\t\t\t\t\tif (this.established.peek() === connection) this.established.set(undefined);\n\t\t\t\t\t\tthis.#retry(effect, connected, ended ?? undefined);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tcurrent = undefined;\n\t\t\t\t\t// A pinned WebSocket URL can win the race against the primary. Judge the\n\t\t\t\t\t// redirect against that endpoint, not the primary we never reached.\n\t\t\t\t\tconst socket = this.#redirect.peek() ? undefined : this.websocket?.url;\n\t\t\t\t\tif (!this.#migrate(connection, dialed(dialing, connection.transport, socket), ended)) return;\n\n\t\t\t\t\t// A session that outlived the initial delay was healthy, so its handover is not a\n\t\t\t\t\t// failure. One redirected almost at once still migrates, but through the backoff,\n\t\t\t\t\t// so two peers bouncing us between them escalate and eventually give up.\n\t\t\t\t\tif (performance.now() - connected < this.#initial()) {\n\t\t\t\t\t\tthis.#retry(effect, connected, new Error(\"peer redirected immediately\"));\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tthis.#delay = undefined;\n\t\t\t\t\tthis.#deadline = undefined;\n\t\t\t\t}\n\t\t\t} catch (err) {\n\t\t\t\t// Treat teardown as cancellation, not a connection failure.\n\t\t\t\tif (signal.aborted) return;\n\n\t\t\t\tconsole.warn(\"connection error:\", err);\n\t\t\t\tthis.#retry(effect, connected, err);\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Act on the peer's GOAWAY for `connection`, which was dialed at `dialing`: resolve where\n\t * to go next and leave the old session serving until it drains. Returns false when the\n\t * redirect is refused, which ends the sequence rather than redialing.\n\t */\n\t#migrate(connection: Established, dialing: URL, drain: Drain): boolean {\n\t\tconst hashes = this.webtransport?.serverCertificateHashes?.length ?? 0;\n\t\tconst configured = hashes > 0 || this.webtransport?.serverCertificate !== undefined;\n\t\t// The pin is a WebTransport option. A WebSocket that won the race never used it.\n\t\tconst pinned = pinnedTransport(connection.transport, configured);\n\n\t\tlet next: URL | undefined;\n\t\ttry {\n\t\t\tnext = target(this.goaway.redirect ?? \"same-host\", drain.uri, dialing, pinned);\n\t\t} catch (err) {\n\t\t\t// The peer is leaving and named somewhere we won't go: redialing the old address\n\t\t\t// would ignore it, so stop here.\n\t\t\tconsole.warn(\"GOAWAY redirect refused:\", err);\n\t\t\tconnection.close();\n\t\t\tthis.established.set(undefined);\n\t\t\tthis.status.set(\"disconnected\");\n\t\t\tthis.#giveUp(error(err));\n\t\t\treturn false;\n\t\t}\n\n\t\t// Only an accepted redirect replaces the URL; an empty one keeps it.\n\t\tif (next) {\n\t\t\tthis.#redirect.set(next);\n\t\t\tthis.#redirectHref = this.#sequenceHref;\n\t\t}\n\n\t\tconsole.info(\"GOAWAY received; migrating\");\n\t\t// A newer GOAWAY retires an older predecessor rather than holding two open.\n\t\tthis.#draining?.retire();\n\t\tconst cap = handover(this.goaway.handover ?? DEFAULT_HANDOVER, drain.timeout);\n\t\tconst draining = new Draining(connection, cap, () => {\n\t\t\tif (this.#draining === draining) this.#draining = undefined;\n\t\t\t// If nothing replaced it yet, nothing is serving.\n\t\t\tif (this.established.peek() !== connection) return;\n\t\t\tthis.established.set(undefined);\n\t\t\tthis.status.set(this.#dialing ? \"connecting\" : \"disconnected\");\n\t\t});\n\t\tthis.#draining = draining;\n\t\treturn true;\n\t}\n\n\t#initial(): Time.Milli {\n\t\treturn this.delay?.initial ?? DEFAULT_DELAY.initial;\n\t}\n\n\t/**\n\t * Schedule the next connect attempt after the current backoff, or stop once the retry window\n\t * has expired. `connected` is when the dead session was established, if it ever was, and\n\t * `cause` the error that killed it, if it died with one.\n\t */\n\t#retry(effect: Effect, connected: DOMHighResTimeStamp | undefined, cause?: unknown): void {\n\t\t// Resolved per sequence rather than at construction, so an edit to `delay` (including\n\t\t// one that drops a field back to its default) applies to the next retry. Field by\n\t\t// field rather than by spread: a caller building `{ initial: maybeInitial }` from an\n\t\t// optional value passes an explicit undefined, which a spread would take as the\n\t\t// answer, turning the backoff into NaN or the window into forever.\n\t\tconst delay = this.delay ?? {};\n\t\tconst initial = this.#initial();\n\t\tconst multiplier = delay.multiplier ?? DEFAULT_DELAY.multiplier;\n\t\tconst max = delay.max ?? DEFAULT_DELAY.max;\n\t\tconst timeout = delay.timeout ?? DEFAULT_DELAY.timeout;\n\n\t\t// Report disconnected during the backoff rather than when the retry reruns the\n\t\t// effect, unless a drained predecessor still serves until it retires.\n\t\tif (this.established.peek() === undefined) this.status.set(\"disconnected\");\n\n\t\t// A session that outlived the initial delay was healthy, so clear the backoff and\n\t\t// start a fresh retry window: a one-off drop should reconnect promptly. Anything\n\t\t// shorter is a peer that accepts and immediately severs, which has to keep\n\t\t// escalating or we hammer it forever at the initial delay.\n\t\tif (connected !== undefined && performance.now() - connected >= initial) {\n\t\t\tthis.#delay = undefined;\n\t\t\tthis.#deadline = undefined;\n\t\t}\n\n\t\t// An auth rejection stops this URL however long the session lived. UNAUTHORIZED is a\n\t\t// specified code rather than one we guessed at, so this is the peer saying these\n\t\t// credentials will never work; retrying them just burns the window. Matches\n\t\t// moq-tokio's reconnect loop, which stops on the same close. A new URL or a\n\t\t// disable/re-enable starts another sequence; the handle itself is not disposed.\n\t\t//\n\t\t// Only a session close says that. The stream registry gives 2 to DELIVERY_TIMEOUT,\n\t\t// so a stream reset during the SETUP exchange would otherwise suppress reconnect\n\t\t// for good.\n\t\tif (cause instanceof SessionError && cause.code === SessionCode.Unauthorized) {\n\t\t\tconsole.warn(\"session rejected as unauthorized, not retrying\");\n\t\t\tthis.#giveUp(cause);\n\t\t\treturn;\n\t\t}\n\n\t\tconst now = performance.now();\n\t\tthis.#delay ??= initial;\n\t\tthis.#deadline ??= timeout > 0 ? now + timeout : Number.POSITIVE_INFINITY;\n\n\t\tif (now >= this.#deadline) {\n\t\t\tconsole.warn(\"reconnect timed out\");\n\t\t\t// A graceful close has no error, so report the timeout itself.\n\t\t\tthis.#giveUp(cause === undefined ? new Error(\"reconnect timed out\") : error(cause));\n\t\t\treturn;\n\t\t}\n\n\t\t// Equal jitter, so a fleet of tabs knocked offline together doesn't reconnect on the same\n\t\t// tick, and never past the deadline the retry window promised.\n\t\tconst wait = Math.min(this.#delay * (0.5 + Math.random() / 2), this.#deadline - now);\n\t\tthis.#delay = Math.min(this.#delay * multiplier, max);\n\n\t\tconst tick = this.#tick.peek() + 1;\n\t\teffect.timer(() => this.#tick.update((prev) => Math.max(prev, tick)), wait);\n\t}\n\n\t#giveUp(cause: Error): void {\n\t\tthis.#error.set(cause);\n\t\tthis.#givenUpHref = this.#sequenceHref;\n\t\tthis.#resetSequence();\n\t}\n\n\t#resetSequence(): void {\n\t\tthis.#delay = undefined;\n\t\tthis.#deadline = undefined;\n\t\tthis.#sequenceHref = undefined;\n\t\tthis.#draining?.retire();\n\t}\n\n\t/**\n\t * Subscribe to broadcast announcements matching `scope`, spanning reconnects.\n\t *\n\t * The same {@link Announce.Consumer} stream as {@link Established.announced}, but everything active\n\t * is retracted (a `retracted` update) whenever the connection drops and re-announced on\n\t * reconnect, so a consumer draining `next()` never clings to a dead route across a reconnect.\n\t *\n\t * Stays empty while the relay lacks {@link Established.discovery}.\n\t */\n\tannounced(scope: Path.Pattern = Path.Pattern.all(), options?: Announce.Options): Announce.Consumer {\n\t\t// With a consume origin the table already spans reconnects (the forwarder retracts\n\t\t// a dead session's entries), so its stream is the same thing with less machinery.\n\t\tif (this.consume) return this.consume.announced(scope, options);\n\n\t\tconst producer = new Announce.Producer();\n\t\tconst consumer = producer.consume();\n\n\t\tconst pump = new Effect();\n\t\tpump.run((effect) => {\n\t\t\tconst conn = effect.get(this.established);\n\t\t\tif (!conn) return;\n\n\t\t\t// Without discovery the upstream announce stream never yields, so leave the\n\t\t\t// consumer empty rather than opening a subscription that can't be answered.\n\t\t\tif (!conn.discovery) return;\n\n\t\t\tconst upstream = conn.announced(scope, options);\n\t\t\teffect.cleanup(() => upstream.close());\n\n\t\t\t// Track what this connection announced so we can retract it if the connection\n\t\t\t// drops; the last event rides along for the retraction.\n\t\t\tconst active = new Map<Path.Valid, Announce.Update>();\n\n\t\t\teffect.spawn(async () => {\n\t\t\t\ttry {\n\t\t\t\t\tfor (;;) {\n\t\t\t\t\t\tconst entry = await effect.race(upstream.next());\n\t\t\t\t\t\tif (!entry) break;\n\t\t\t\t\t\tif (Announce.isActive(entry.kind)) active.set(entry.prefix, entry);\n\t\t\t\t\t\telse active.delete(entry.prefix);\n\t\t\t\t\t\tproducer.append(entry);\n\t\t\t\t\t}\n\t\t\t\t} catch {\n\t\t\t\t\t// A dropped connection resets the announce stream; the retractions below cover it.\n\t\t\t\t} finally {\n\t\t\t\t\t// Retract everything from the connection that just went away, so a per-broadcast\n\t\t\t\t\t// watcher tears down instead of clinging to the dead route.\n\t\t\t\t\tif (consumer.closed.peek() === undefined) {\n\t\t\t\t\t\tfor (const entry of active.values()) {\n\t\t\t\t\t\t\tproducer.append({ ...entry, kind: \"retracted\" });\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\n\t\tthis.#signals.cleanup(() => pump.close());\n\t\tvoid consumer.closed.then(() => pump.close());\n\n\t\treturn consumer;\n\t}\n\n\t/**\n\t * Snapshot the live connection's transport counters, or undefined while disconnected.\n\t * See {@link Established.stats}.\n\t */\n\tasync stats(): Promise<Stats | undefined> {\n\t\treturn this.established.peek()?.stats();\n\t}\n\n\t/** Stop reconnecting, close the current connection, and settle {@link Reload.closed}. Idempotent. */\n\tclose(abort?: Error) {\n\t\tthis.#signals.close();\n\t\tthis.#draining?.retire();\n\t\tif (this.#closed.peek() === undefined) this.#closed.set(abort ?? null);\n\t}\n}\n\n/**\n * A session the peer sent GOAWAY on, left serving so its groups in flight finish. It retires\n * when it closes on its own or overstays its handover window, and `onRetire` runs once either way.\n */\nclass Draining {\n\t#connection: Established;\n\t#timer: ReturnType<typeof setTimeout>;\n\t#onRetire: () => void;\n\t#retired = false;\n\n\tconstructor(connection: Established, handover: Time.Milli, onRetire: () => void) {\n\t\tthis.#connection = connection;\n\t\tthis.#onRetire = onRetire;\n\t\tthis.#timer = setTimeout(() => {\n\t\t\tconsole.warn(\"old session did not drain in time; closing\");\n\t\t\tthis.retire();\n\t\t}, handover);\n\t\tvoid connection.closed.then(() => this.retire());\n\t}\n\n\t/** Close the old session now, whatever remains of its window. Idempotent. */\n\tretire(): void {\n\t\tif (this.#retired) return;\n\t\tthis.#retired = true;\n\t\tclearTimeout(this.#timer);\n\t\tthis.#connection.close();\n\t\tthis.#onRetire();\n\t}\n}\n"]}
package/error.d.ts CHANGED
@@ -197,6 +197,17 @@ export declare class NotFound extends Stream {
197
197
  cause?: unknown;
198
198
  });
199
199
  }
200
+ /**
201
+ * A peer's GOAWAY named a redirect the connection refuses, or one it could not parse.
202
+ *
203
+ * Terminal: the peer is leaving, so the connection stops rather than redialing the old
204
+ * address. Mirrors the Rust `Error::RefusedRedirect`.
205
+ *
206
+ * @public
207
+ */
208
+ export declare class RefusedRedirect extends Error {
209
+ constructor(reason: string);
210
+ }
200
211
  /**
201
212
  * A peer broke the protocol in a way the spec says must end the session.
202
213
  *
package/error.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,uDAAuD;AACvD,OAAO,CAAC,MAAM,YAAY,EAAE,OAAO,MAAM,CAAC;AAE1C,oDAAoD;AACpD,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,CAAC,YAAY,CAAC,EAAE,IAAI,CAAA;CAAE,CAAC;AAErE;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,WAAW,UACF,MAAM,KAAG,WAAW;IACxC,kDAAkD;qBACnC,WAAW;IAC1B,8DAA8D;uBAC7C,WAAW;IAC5B,6FAA6F;2BACxE,WAAW;IACh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E,EAGtD;CACD;AAED;;;;;;;GAOG;AACH,qBAAa,eAAgB,SAAQ,KAAK;IACzC,YAAY,MAAM,EAAE,MAAM,EAGzB;CACD;AAED;;;;;;;;GAQG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;IAC3C,YAAY,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,EAGzD;CACD;AAED,4EAA4E;AAC5E,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,IAAI,WAAW,EAAE,YAAY,IAAI,MAAM,EAAE,CAAC;AAClF,2EAA2E;AAC3E,MAAM,MAAM,kBAAkB,GAAG,aAAa,CAAC;AAiM/C;;;;;;;GAOG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAa3C"}
package/error.js CHANGED
@@ -204,6 +204,20 @@ export class NotFound extends Stream {
204
204
  this.name = "NotFound";
205
205
  }
206
206
  }
207
+ /**
208
+ * A peer's GOAWAY named a redirect the connection refuses, or one it could not parse.
209
+ *
210
+ * Terminal: the peer is leaving, so the connection stops rather than redialing the old
211
+ * address. Mirrors the Rust `Error::RefusedRedirect`.
212
+ *
213
+ * @public
214
+ */
215
+ export class RefusedRedirect extends Error {
216
+ constructor(reason) {
217
+ super(`GOAWAY redirect refused: ${reason}`);
218
+ this.name = "RefusedRedirect";
219
+ }
220
+ }
207
221
  /**
208
222
  * A peer broke the protocol in a way the spec says must end the session.
209
223
  *
@@ -369,6 +383,27 @@ export function fromClose(info) {
369
383
  return null;
370
384
  return new Session(code, { reason: info.reason });
371
385
  }
386
+ /**
387
+ * The session's close as the error it ends everything with, carrying the peer's code. A clean
388
+ * close code is still an error here: whatever the close cut off did not end.
389
+ *
390
+ * @internal
391
+ */
392
+ export function closeError(quic) {
393
+ return quic.closed.then((info) => fromClose(info) ?? new Session(SessionCode.Cancel, { reason: info.reason }), (err) => error(err));
394
+ }
395
+ /**
396
+ * Report a failure the session's close caused as the session's own error, which carries the
397
+ * peer's close code; any other failure passes through.
398
+ *
399
+ * @internal
400
+ */
401
+ export async function sessionCause(quic, err) {
402
+ const source = typeof err === "object" && err !== null ? err.source : undefined;
403
+ if (quic && source === "session")
404
+ return closeError(quic);
405
+ return error(err);
406
+ }
372
407
  /**
373
408
  * Coerce an unknown thrown value into an `Error`.
374
409
  *
package/error.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEnD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAQjD;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CACvC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAY,EAAe,EAAE,CAAC,eAAe,CAAC,IAAI,CAAgB,EAAE;IAClF,kDAAkD;IAClD,MAAM,EAAE,GAAkB;IAC1B,8DAA8D;IAC9D,QAAQ,EAAE,GAAkB;IAC5B,6FAA6F;IAC7F,YAAY,EAAE,GAAkB;IAChC,2DAA2D;IAC3D,iBAAiB,EAAE,GAAkB;IACrC,oEAAoE;IACpE,kBAAkB,EAAE,GAAkB;IACtC,+DAA+D;IAC/D,aAAa,EAAE,IAAmB;IAClC,uCAAuC;IACvC,OAAO,EAAE,IAAmB;IAC5B,sCAAsC;IACtC,OAAO,EAAE,IAAmB;CACnB,CAAC,CACX,CAAC;AAQF;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CACtC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAY,EAAc,EAAE,CAAC,eAAe,CAAC,IAAI,CAAe,EAAE;IAChF,8DAA8D;IAC9D,QAAQ,EAAE,GAAiB;IAC3B,+EAA+E;IAC/E,MAAM,EAAE,GAAiB;IACzB,gDA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AO,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,IAAI,IAAI,eAAe,CAAC;AAC/C,CAAC","sourcesContent":["/**\n * Errors, including the code a peer reports when it resets a stream or closes the session.\n *\n * @module\n */\n\nimport { sharedStreamCode } from \"./ietf/error.ts\";\nimport type { IetfVersion } from \"./ietf/version.ts\";\nimport { TimeoutError } from \"./util/timeout.ts\";\n\n/** The nominal brand for session termination codes. */\ndeclare const SESSION_CODE: unique symbol;\n\n/** A code from the session termination registry. */\nexport type SessionCode = number & { readonly [SESSION_CODE]: true };\n\n/**\n * Codes a peer sends when terminating the session, mirroring the Rust `Session`.\n *\n * Specified by moq-lite, which reuses moq-transport's codes unchanged. Call `SessionCode(code)`\n * to construct an application code in the 64+ range. {@link StreamCode} is the other registry,\n * and the two are disjoint, so the same integer means different things in each.\n *\n * Codes 32-47 are reserved: nothing is sent there, and the draft gives a received one no\n * meaning, so treat anything not listed below as an unspecified error rather than guessing.\n *\n * @public\n */\nexport const SessionCode = Object.freeze(\n\tObject.assign((code: number): SessionCode => applicationCode(code) as SessionCode, {\n\t\t/** Ending the session normally, with no error. */\n\t\tCancel: 0x0 as SessionCode,\n\t\t/** Something went wrong that isn't worth a dedicated code. */\n\t\tInternal: 0x1 as SessionCode,\n\t\t/** The credentials don't grant the requested path or operation. Retrying will fail again. */\n\t\tUnauthorized: 0x2 as SessionCode,\n\t\t/** A protocol rule was broken; the session is unusable. */\n\t\tProtocolViolation: 0x3 as SessionCode,\n\t\t/** A key-value pair was malformed or repeated more than allowed. */\n\t\tKeyValueFormatting: 0x6 as SessionCode,\n\t\t/** The peer did not close within the GOAWAY drain deadline. */\n\t\tGoawayTimeout: 0x10 as SessionCode,\n\t\t/** A control message took too long. */\n\t\tTimeout: 0x11 as SessionCode,\n\t\t/** No version could be negotiated. */\n\t\tVersion: 0x15 as SessionCode,\n\t} as const),\n);\n\n/** The nominal brand for stream reset codes. */\ndeclare const STREAM_CODE: unique symbol;\n\n/** A code from the stream reset registry. */\nexport type StreamCode = number & { readonly [STREAM_CODE]: true };\n\n/**\n * Codes a peer sends when resetting a stream, mirroring the Rust `Stream`.\n *\n * The counterpart to {@link SessionCode}, and a disjoint space: a stream reset of 0 is\n * {@link StreamCode.Internal}, not a cancellation ({@link StreamCode.Cancel} is 1). Call\n * `StreamCode(code)` to construct an application code in the 64+ range.\n *\n * Conditions the shared codes don't cover are assigned in moq-lite's own 48-63 range, so a\n * received one is the named code. 32 through 47 is reserved: nothing is sent there and a\n * received one is an unspecified error.\n *\n * @public\n */\nexport const StreamCode = Object.freeze(\n\tObject.assign((code: number): StreamCode => applicationCode(code) as StreamCode, {\n\t\t/** Something went wrong that isn't worth a dedicated code. */\n\t\tInternal: 0x0 as StreamCode,\n\t\t/** The sender is done with this stream, not failing. A routine unsubscribe. */\n\t\tCancel: 0x1 as StreamCode,\n\t\t/** The content missed its delivery deadline. */\n\t\tDeliveryTimeout: 0x2 as StreamCode,\n\t\t/** The session ended, taking this stream with it. */\n\t\tSessionClosed: 0x3 as StreamCode,\n\t\t/** The session is going away (a GOAWAY was received). */\n\t\tGoingAway: 0x4 as StreamCode,\n\t\t/** The reader fell too far behind and content was dropped to catch up. */\n\t\tTooFarBehind: 0x5 as StreamCode,\n\t\t/** The track's content could not be parsed. */\n\t\tMalformedTrack: 0x12 as StreamCode,\n\t\t/** The peer took too long to answer a control request. */\n\t\tControlTimeout: 0x31 as StreamCode,\n\t\t/** The requested broadcast or track does not exist at the peer. */\n\t\tNotFound: 0x33 as StreamCode,\n\t\t/** The group was superseded by a newer one and dropped. */\n\t\tOld: 0x34 as StreamCode,\n\t\t/** The group was dropped under memory pressure, so it can be re-fetched. */\n\t\tEvicted: 0x35 as StreamCode,\n\t\t/** A frame declared a payload larger than the receiver accepts. */\n\t\tFrameTooLarge: 0x38 as StreamCode,\n\t\t/** The publisher could serve this request but has no capacity for it now. */\n\t\tNoCapacity: 0x30 as StreamCode,\n\t\t/** A group grew past its cache budget and was aborted. */\n\t\tGroupTooLarge: 0x32 as StreamCode,\n\t} as const),\n);\n\nfunction applicationCode(code: number): number {\n\tif (!Number.isInteger(code) || code < 64 || code > 0xffffffff) {\n\t\tthrow new RangeError(`invalid application error code: ${code}`);\n\t}\n\treturn code;\n}\n\n/**\n * An error the peer reported by closing the session, carrying its {@link SessionCode}.\n *\n * This surfaces on every transport, so catch this type rather than feature-detecting\n * `WebTransportError`, which a non-browser runtime never defines and the WebSocket fallback\n * never throws.\n *\n * ```ts\n * connection.error.subscribe((err) => {\n * if (err instanceof Session && err.code === SessionCode.Unauthorized) {\n * console.warn(\"server rejected the session\");\n * }\n * });\n * ```\n *\n * @public\n */\nexport class Session extends Error {\n\t/** The session code the peer sent, verbatim. */\n\treadonly code: SessionCode;\n\n\tconstructor(code: SessionCode, options?: { cause?: unknown; reason?: string }) {\n\t\tsuper(options?.reason ? `remote error: ${code} (${options.reason})` : `remote error: ${code}`, options);\n\t\tthis.name = \"Session\";\n\t\tthis.code = code;\n\t}\n}\n\n/** Options for a {@link Stream}. */\nexport interface StreamOptions {\n\t/** The failure this one wraps. */\n\tcause?: unknown;\n\t/** The peer's human-readable reason, appended to the default message. */\n\treason?: string;\n\t/** Replaces the default `remote error: <code>` text, for a condition raised locally. */\n\tmessage?: string;\n}\n\n/**\n * An error carrying a {@link StreamCode}: the code a peer sent when it reset a stream, or the\n * one this side sends when it resets one.\n *\n * This surfaces on every transport, so catch this type rather than feature-detecting\n * `WebTransportError`, which a non-browser runtime never defines and the WebSocket fallback\n * never throws. Local conditions with a code of their own subclass it ({@link TooFarBehind},\n * {@link FrameTooLarge}, {@link GroupTooLarge}, {@link NotFound}), so the same `code` check catches a condition\n * whether it was raised here or reported by the peer.\n *\n * ```ts\n * try {\n * frame = await group.readFrame();\n * } catch (err) {\n * if (err instanceof Stream && err.code === StreamCode.Cancel) return;\n * throw err;\n * }\n * ```\n *\n * @public\n */\nexport class Stream extends Error {\n\t/** The stream code; moq-lite resets forward it verbatim. */\n\treadonly code: StreamCode;\n\n\tconstructor(code: StreamCode, options?: StreamOptions) {\n\t\tsuper(\n\t\t\toptions?.message ??\n\t\t\t\t(options?.reason ? `remote error: ${code} (${options.reason})` : `remote error: ${code}`),\n\t\t\toptions,\n\t\t);\n\t\tthis.name = \"Stream\";\n\t\tthis.code = code;\n\t}\n}\n\n/**\n * The reader asked for a frame the group never held, so the stream has a gap.\n *\n * Raised locally by a frame read, and decoded from a moq-lite peer's `TOO_FAR_BEHIND` reset, since a gap\n * reads the same either way.\n *\n * @public\n */\nexport class TooFarBehind extends Stream {\n\tconstructor(options?: { cause?: unknown }) {\n\t\tsuper(StreamCode.TooFarBehind, {\n\t\t\t...options,\n\t\t\tmessage: \"lagged: frames were evicted before being read\",\n\t\t});\n\t\tthis.name = \"TooFarBehind\";\n\t}\n}\n\n/**\n * A frame is larger than a group can cache, so appending it would exceed the budget by itself.\n *\n * Raised locally by a frame write, and decoded from a moq-lite peer's `FRAME_TOO_LARGE` reset.\n * Mirrors the Rust `Error::FrameTooLarge`, which rejects the same frame before touching any state.\n *\n * @public\n */\nexport class FrameTooLarge extends Stream {\n\tconstructor(options?: { cause?: unknown }) {\n\t\tsuper(StreamCode.FrameTooLarge, {\n\t\t\t...options,\n\t\t\tmessage: \"frame too large: larger than a group can cache\",\n\t\t});\n\t\tthis.name = \"FrameTooLarge\";\n\t}\n}\n\n/**\n * A write grew the group past its cache budget, so the group is aborted.\n *\n * Raised locally by a frame write, and decoded from a moq-lite peer's `GROUP_TOO_LARGE`\n * reset. Mirrors the Rust `Error::GroupTooLarge`.\n *\n * @public\n */\nexport class GroupTooLarge extends Stream {\n\tconstructor(options?: { cause?: unknown }) {\n\t\tsuper(StreamCode.GroupTooLarge, {\n\t\t\t...options,\n\t\t\tmessage: \"group too large: exceeded the cache budget\",\n\t\t});\n\t\tthis.name = \"GroupTooLarge\";\n\t}\n}\n\n/**\n * The requested broadcast or track is not served here.\n *\n * @public\n */\nexport class NotFound extends Stream {\n\tconstructor(what: string, options?: { cause?: unknown }) {\n\t\tsuper(StreamCode.NotFound, { ...options, message: `not found: ${what}` });\n\t\tthis.name = \"NotFound\";\n\t}\n}\n\n/**\n * A peer broke the protocol in a way the spec says must end the session.\n *\n * Thrown where the violation is detected, rather than handled there: a decoder has no session\n * to close. The dispatch that owns the session watches for it and closes, so a nonconforming\n * peer cannot repeat the violation on the next stream.\n *\n * @public\n */\nexport class ProtocolViolation extends Error {\n\tconstructor(message: string, options?: { cause?: unknown }) {\n\t\tsuper(message, options);\n\t\tthis.name = \"ProtocolViolation\";\n\t}\n}\n\n/** Package-internal compatibility names used by the wire implementation. */\nexport { Session as SessionError, Stream as StreamError, TooFarBehind as Lagged };\n/** Package-internal compatibility name used by the wire implementation. */\nexport type StreamErrorOptions = StreamOptions;\n\n/** The WebTransport-shaped fields a stream reset code arrives in. */\ntype StreamErrorLike = { source?: unknown; streamErrorCode?: unknown };\n\nfunction streamCode(err: unknown): StreamCode | undefined {\n\tif (typeof err !== \"object\" || err === null) return undefined;\n\n\tconst { source, streamErrorCode } = err as StreamErrorLike;\n\tif (source !== \"stream\" || typeof streamErrorCode !== \"number\") return undefined;\n\n\treturn streamErrorCode as StreamCode;\n}\n\n/** Transport context for encoding and decoding errors. @internal */\ninterface TransportErrorOptions {\n\t/** The negotiated IETF draft, or absent for moq-lite. */\n\tversion?: IetfVersion;\n}\n\n/**\n * Which {@link StreamCode} to send when resetting a stream because of `err`.\n *\n * The counterpart to {@link fromTransport}, and the pair has to agree: a code we send for a\n * condition is the code we read that condition back from, or two peers disagree about what it\n * means. Mirrors the Rust `From<&Error> for Stream`.\n *\n * Lossy on purpose. An error describes what went wrong here, while the registry is what the peer\n * can act on, so anything without a code of its own degrades to {@link StreamCode.Internal}\n * rather than inventing one. A {@link Session} lands there too: the two registries are\n * disjoint, so forwarding its code onto a stream would mistranslate it.\n *\n * On an IETF stream the code has to be one the negotiated draft assigns the same meaning to,\n * so a condition it does not register degrades to INTERNAL_ERROR as well. See\n * {@link sharedStreamCode}.\n *\n * @internal\n */\nexport function toStreamCode(err: unknown, options?: TransportErrorOptions): StreamCode {\n\tconst code = localStreamCode(err);\n\tif (options?.version === undefined) return code;\n\treturn sharedStreamCode(code, options.version) ? code : StreamCode.Internal;\n}\n\n/** The moq-lite code for a local failure, before any draft has a say. */\nfunction localStreamCode(err: unknown): StreamCode {\n\tif (err instanceof Stream) return err.code;\n\tif (err instanceof TimeoutError) return StreamCode.DeliveryTimeout;\n\t// Session-scoped: the peer learns which rule it broke from the session close, not from here.\n\tif (err instanceof ProtocolViolation) return StreamCode.SessionClosed;\n\treturn StreamCode.Internal;\n}\n\n/**\n * The {@link StreamCode.ControlTimeout} error for a control request the peer never answered.\n *\n * A control request that outlives its deadline is not late content, so it does not go out as\n * {@link StreamCode.DeliveryTimeout} the way a bare {@link TimeoutError} would. Callers that\n * bound a request's response build this instead.\n *\n * @internal\n */\nexport function controlTimeout(cause: unknown): Stream {\n\tconst message = cause instanceof Error && cause.message ? cause.message : \"control request timed out\";\n\treturn new Stream(StreamCode.ControlTimeout, { cause, message });\n}\n\n/**\n * Decode a transport failure into a {@link Stream} when it carries a stream reset code,\n * otherwise pass it through.\n *\n * Native WebTransport rejects with a `WebTransportError`; the WebSocket fallback mints an error\n * with the same `source`/`streamErrorCode` fields. Reading the fields rather than the class\n * covers both, and works in a runtime with no `WebTransportError` at all.\n *\n * On moq-lite, a code with a local class decodes back into it, so a peer's condition is caught by\n * the same `instanceof` as one raised here.\n *\n * On an IETF stream a code keeps its value unless moq-lite claims that number for something\n * the draft does not: `0x4` is GOING_AWAY here but UNKNOWN_OBJECT_STATUS on draft-16 and 17,\n * and reading one back as the other would retire a session that is not going anywhere. Those\n * read as {@link StreamCode.Internal} with the wire value kept in the message, since\n * {@link StreamCode} is one numeric space and cannot hold a foreign code without lying about\n * it. A code moq-lite names nothing for survives intact: nothing can misread it.\n *\n * @internal Called at the transport boundary so the raw error never reaches an application.\n */\nexport function fromTransport(err: unknown, options?: TransportErrorOptions): Error {\n\tconst code = streamCode(err);\n\tif (code === undefined) return error(err);\n\tif (options?.version !== undefined && !sharedStreamCode(code, options.version) && claimedLocally(code)) {\n\t\treturn new Stream(StreamCode.Internal, { cause: err, message: `remote error: ${code}` });\n\t}\n\tif (code === StreamCode.TooFarBehind) return new TooFarBehind({ cause: err });\n\tif (code === StreamCode.FrameTooLarge) return new FrameTooLarge({ cause: err });\n\tif (code === StreamCode.GroupTooLarge) return new GroupTooLarge({ cause: err });\n\treturn new Stream(code, { cause: err });\n}\n\n/** The codes moq-lite names, which a foreign one must not borrow. */\nconst NAMED_CODES: ReadonlySet<number> = new Set(Object.values(StreamCode));\n\n/**\n * Whether moq-lite could give `code` a meaning of its own: one of its named codes, or\n * anywhere in the 64+ range, where `StreamCode(code)` mints an application code and an\n * application compares against its own. moq-transport registers nothing above 0x12 and has\n * no application range at all, so a foreign code landing there is never what it looks like.\n */\nfunction claimedLocally(code: number): boolean {\n\treturn code >= 64 || NAMED_CODES.has(code);\n}\n\nconst legacyWebTransportErrors = new WeakSet<object>();\n\n/**\n * Build the `reason` to hand `abort()` / `cancel()` so the transport puts `code` on the wire.\n *\n * Both the WebTransport spec and the WebSocket fallback take the reset code from a\n * `WebTransportError`'s `streamErrorCode` and send 0 for anything else, a plain `Error`\n * included. Since 0 is {@link StreamCode.Internal}, cancelling with a bare `Error` tells the\n * peer we failed rather than that we are done.\n *\n * The native constructor exists exactly where native WebTransport does, which is where the\n * fallback isn't used, so mint a matching shape elsewhere rather than feature-detect a global\n * that will not be there.\n *\n * @internal\n */\nexport function toTransport(code: StreamCode, message: string): Error {\n\tconst Native = (globalThis as { WebTransportError?: typeof WebTransportError }).WebTransportError;\n\tif (Native) {\n\t\tconst Legacy = Native as unknown as new (init: { message: string; streamErrorCode: number }) => Error;\n\t\tif (legacyWebTransportErrors.has(Native)) return new Legacy({ message, streamErrorCode: code });\n\n\t\ttry {\n\t\t\treturn new Native(message, { source: \"stream\", streamErrorCode: code });\n\t\t} catch (err) {\n\t\t\t// Chromium still implements the previous single-dictionary constructor.\n\t\t\tif (!(err instanceof TypeError)) throw err;\n\t\t\tlegacyWebTransportErrors.add(Native);\n\t\t\treturn new Legacy({ message, streamErrorCode: code });\n\t\t}\n\t}\n\n\treturn Object.assign(new Error(message), { source: \"stream\" as const, streamErrorCode: code });\n}\n\n/**\n * Decode a session close into its terminal error: `null` for a clean close\n * ({@link SessionCode.Cancel}), otherwise a {@link Session} carrying the peer's code.\n *\n * @internal Applied to the transport's `closed` info so the code survives to the application.\n */\nexport function fromClose(info: WebTransportCloseInfo): Session | null {\n\tconst code = (info.closeCode ?? SessionCode.Cancel) as SessionCode;\n\tif (code === SessionCode.Cancel) return null;\n\treturn new Session(code, { reason: info.reason });\n}\n\n/**\n * Coerce an unknown thrown value into an `Error`.\n *\n * @internal\n */\nexport function error(err: unknown): Error {\n\treturn err instanceof Error ? err : new Error(String(err));\n}\n\n/**\n * Format an error into a non-empty, human-readable string for logging.\n *\n * Safari always leaves `WebTransportError.message` blank, so a bare `err.message` degrades to\n * an empty string and the reason is lost. This falls back to the error type name and appends\n * the WebTransport `source` and application `streamErrorCode`, so the log line always says\n * something.\n */\nexport function reason(err: unknown): string {\n\tconst e = error(err);\n\n\t// WebTransportError carries the failure origin and the peer's application error code,\n\t// often the only identifying detail since WebKit leaves `message` empty.\n\tif (typeof WebTransportError !== \"undefined\" && e instanceof WebTransportError) {\n\t\tconst parts = [`source=${e.source}`];\n\t\tif (e.streamErrorCode !== null) parts.push(`code=${e.streamErrorCode}`);\n\t\tconst detail = parts.join(\" \");\n\t\treturn e.message ? `${e.message} (${detail})` : `WebTransportError: ${detail}`;\n\t}\n\n\treturn e.message || e.name || \"unknown error\";\n}\n"]}
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEnD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAQjD;;;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AAiB,EAAE,CAAC;QAChF,MAAM,KAAK,GAAG,CAAC,UAAU,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;QACrC,IAAI,CAAC,CAAC,eAAe,KAAK,IAAI;YAAE,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,eAAe,EAAE,CAAC,CAAC;QACxE,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC/B,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,OAAO,KAAK,MAAM,GAAG,CAAC,CAAC,CAAC,sBAAsB,MAAM,EAAE,CAAC;IAChF,CAAC;IAED,OAAO,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,IAAI,IAAI,eAAe,CAAC;AAC/C,CAAC","sourcesContent":["/**\n * Errors, including the code a peer reports when it resets a stream or closes the session.\n *\n * @module\n */\n\nimport { sharedStreamCode } from \"./ietf/error.ts\";\nimport type { IetfVersion } from \"./ietf/version.ts\";\nimport { TimeoutError } from \"./util/timeout.ts\";\n\n/** The nominal brand for session termination codes. */\ndeclare const SESSION_CODE: unique symbol;\n\n/** A code from the session termination registry. */\nexport type SessionCode = number & { readonly [SESSION_CODE]: true };\n\n/**\n * Codes a peer sends when terminating the session, mirroring the Rust `Session`.\n *\n * Specified by moq-lite, which reuses moq-transport's codes unchanged. Call `SessionCode(code)`\n * to construct an application code in the 64+ range. {@link StreamCode} is the other registry,\n * and the two are disjoint, so the same integer means different things in each.\n *\n * Codes 32-47 are reserved: nothing is sent there, and the draft gives a received one no\n * meaning, so treat anything not listed below as an unspecified error rather than guessing.\n *\n * @public\n */\nexport const SessionCode = Object.freeze(\n\tObject.assign((code: number): SessionCode => applicationCode(code) as SessionCode, {\n\t\t/** Ending the session normally, with no error. */\n\t\tCancel: 0x0 as SessionCode,\n\t\t/** Something went wrong that isn't worth a dedicated code. */\n\t\tInternal: 0x1 as SessionCode,\n\t\t/** The credentials don't grant the requested path or operation. Retrying will fail again. */\n\t\tUnauthorized: 0x2 as SessionCode,\n\t\t/** A protocol rule was broken; the session is unusable. */\n\t\tProtocolViolation: 0x3 as SessionCode,\n\t\t/** A key-value pair was malformed or repeated more than allowed. */\n\t\tKeyValueFormatting: 0x6 as SessionCode,\n\t\t/** The peer did not close within the GOAWAY drain deadline. */\n\t\tGoawayTimeout: 0x10 as SessionCode,\n\t\t/** A control message took too long. */\n\t\tTimeout: 0x11 as SessionCode,\n\t\t/** No version could be negotiated. */\n\t\tVersion: 0x15 as SessionCode,\n\t} as const),\n);\n\n/** The nominal brand for stream reset codes. */\ndeclare const STREAM_CODE: unique symbol;\n\n/** A code from the stream reset registry. */\nexport type StreamCode = number & { readonly [STREAM_CODE]: true };\n\n/**\n * Codes a peer sends when resetting a stream, mirroring the Rust `Stream`.\n *\n * The counterpart to {@link SessionCode}, and a disjoint space: a stream reset of 0 is\n * {@link StreamCode.Internal}, not a cancellation ({@link StreamCode.Cancel} is 1). Call\n * `StreamCode(code)` to construct an application code in the 64+ range.\n *\n * Conditions the shared codes don't cover are assigned in moq-lite's own 48-63 range, so a\n * received one is the named code. 32 through 47 is reserved: nothing is sent there and a\n * received one is an unspecified error.\n *\n * @public\n */\nexport const StreamCode = Object.freeze(\n\tObject.assign((code: number): StreamCode => applicationCode(code) as StreamCode, {\n\t\t/** Something went wrong that isn't worth a dedicated code. */\n\t\tInternal: 0x0 as StreamCode,\n\t\t/** The sender is done with this stream, not failing. A routine unsubscribe. */\n\t\tCancel: 0x1 as StreamCode,\n\t\t/** The content missed its delivery deadline. */\n\t\tDeliveryTimeout: 0x2 as StreamCode,\n\t\t/** The session ended, taking this stream with it. */\n\t\tSessionClosed: 0x3 as StreamCode,\n\t\t/** The session is going away (a GOAWAY was received). */\n\t\tGoingAway: 0x4 as StreamCode,\n\t\t/** The reader fell too far behind and content was dropped to catch up. */\n\t\tTooFarBehind: 0x5 as StreamCode,\n\t\t/** The track's content could not be parsed. */\n\t\tMalformedTrack: 0x12 as StreamCode,\n\t\t/** The peer took too long to answer a control request. */\n\t\tControlTimeout: 0x31 as StreamCode,\n\t\t/** The requested broadcast or track does not exist at the peer. */\n\t\tNotFound: 0x33 as StreamCode,\n\t\t/** The group was superseded by a newer one and dropped. */\n\t\tOld: 0x34 as StreamCode,\n\t\t/** The group was dropped under memory pressure, so it can be re-fetched. */\n\t\tEvicted: 0x35 as StreamCode,\n\t\t/** A frame declared a payload larger than the receiver accepts. */\n\t\tFrameTooLarge: 0x38 as StreamCode,\n\t\t/** The publisher could serve this request but has no capacity for it now. */\n\t\tNoCapacity: 0x30 as StreamCode,\n\t\t/** A group grew past its cache budget and was aborted. */\n\t\tGroupTooLarge: 0x32 as StreamCode,\n\t} as const),\n);\n\nfunction applicationCode(code: number): number {\n\tif (!Number.isInteger(code) || code < 64 || code > 0xffffffff) {\n\t\tthrow new RangeError(`invalid application error code: ${code}`);\n\t}\n\treturn code;\n}\n\n/**\n * An error the peer reported by closing the session, carrying its {@link SessionCode}.\n *\n * This surfaces on every transport, so catch this type rather than feature-detecting\n * `WebTransportError`, which a non-browser runtime never defines and the WebSocket fallback\n * never throws.\n *\n * ```ts\n * connection.error.subscribe((err) => {\n * if (err instanceof Session && err.code === SessionCode.Unauthorized) {\n * console.warn(\"server rejected the session\");\n * }\n * });\n * ```\n *\n * @public\n */\nexport class Session extends Error {\n\t/** The session code the peer sent, verbatim. */\n\treadonly code: SessionCode;\n\n\tconstructor(code: SessionCode, options?: { cause?: unknown; reason?: string }) {\n\t\tsuper(options?.reason ? `remote error: ${code} (${options.reason})` : `remote error: ${code}`, options);\n\t\tthis.name = \"Session\";\n\t\tthis.code = code;\n\t}\n}\n\n/** Options for a {@link Stream}. */\nexport interface StreamOptions {\n\t/** The failure this one wraps. */\n\tcause?: unknown;\n\t/** The peer's human-readable reason, appended to the default message. */\n\treason?: string;\n\t/** Replaces the default `remote error: <code>` text, for a condition raised locally. */\n\tmessage?: string;\n}\n\n/**\n * An error carrying a {@link StreamCode}: the code a peer sent when it reset a stream, or the\n * one this side sends when it resets one.\n *\n * This surfaces on every transport, so catch this type rather than feature-detecting\n * `WebTransportError`, which a non-browser runtime never defines and the WebSocket fallback\n * never throws. Local conditions with a code of their own subclass it ({@link TooFarBehind},\n * {@link FrameTooLarge}, {@link GroupTooLarge}, {@link NotFound}), so the same `code` check catches a condition\n * whether it was raised here or reported by the peer.\n *\n * ```ts\n * try {\n * frame = await group.readFrame();\n * } catch (err) {\n * if (err instanceof Stream && err.code === StreamCode.Cancel) return;\n * throw err;\n * }\n * ```\n *\n * @public\n */\nexport class Stream extends Error {\n\t/** The stream code; moq-lite resets forward it verbatim. */\n\treadonly code: StreamCode;\n\n\tconstructor(code: StreamCode, options?: StreamOptions) {\n\t\tsuper(\n\t\t\toptions?.message ??\n\t\t\t\t(options?.reason ? `remote error: ${code} (${options.reason})` : `remote error: ${code}`),\n\t\t\toptions,\n\t\t);\n\t\tthis.name = \"Stream\";\n\t\tthis.code = code;\n\t}\n}\n\n/**\n * The reader asked for a frame the group never held, so the stream has a gap.\n *\n * Raised locally by a frame read, and decoded from a moq-lite peer's `TOO_FAR_BEHIND` reset, since a gap\n * reads the same either way.\n *\n * @public\n */\nexport class TooFarBehind extends Stream {\n\tconstructor(options?: { cause?: unknown }) {\n\t\tsuper(StreamCode.TooFarBehind, {\n\t\t\t...options,\n\t\t\tmessage: \"lagged: frames were evicted before being read\",\n\t\t});\n\t\tthis.name = \"TooFarBehind\";\n\t}\n}\n\n/**\n * A frame is larger than a group can cache, so appending it would exceed the budget by itself.\n *\n * Raised locally by a frame write, and decoded from a moq-lite peer's `FRAME_TOO_LARGE` reset.\n * Mirrors the Rust `Error::FrameTooLarge`, which rejects the same frame before touching any state.\n *\n * @public\n */\nexport class FrameTooLarge extends Stream {\n\tconstructor(options?: { cause?: unknown }) {\n\t\tsuper(StreamCode.FrameTooLarge, {\n\t\t\t...options,\n\t\t\tmessage: \"frame too large: larger than a group can cache\",\n\t\t});\n\t\tthis.name = \"FrameTooLarge\";\n\t}\n}\n\n/**\n * A write grew the group past its cache budget, so the group is aborted.\n *\n * Raised locally by a frame write, and decoded from a moq-lite peer's `GROUP_TOO_LARGE`\n * reset. Mirrors the Rust `Error::GroupTooLarge`.\n *\n * @public\n */\nexport class GroupTooLarge extends Stream {\n\tconstructor(options?: { cause?: unknown }) {\n\t\tsuper(StreamCode.GroupTooLarge, {\n\t\t\t...options,\n\t\t\tmessage: \"group too large: exceeded the cache budget\",\n\t\t});\n\t\tthis.name = \"GroupTooLarge\";\n\t}\n}\n\n/**\n * The requested broadcast or track is not served here.\n *\n * @public\n */\nexport class NotFound extends Stream {\n\tconstructor(what: string, options?: { cause?: unknown }) {\n\t\tsuper(StreamCode.NotFound, { ...options, message: `not found: ${what}` });\n\t\tthis.name = \"NotFound\";\n\t}\n}\n\n/**\n * A peer's GOAWAY named a redirect the connection refuses, or one it could not parse.\n *\n * Terminal: the peer is leaving, so the connection stops rather than redialing the old\n * address. Mirrors the Rust `Error::RefusedRedirect`.\n *\n * @public\n */\nexport class RefusedRedirect extends Error {\n\tconstructor(reason: string) {\n\t\tsuper(`GOAWAY redirect refused: ${reason}`);\n\t\tthis.name = \"RefusedRedirect\";\n\t}\n}\n\n/**\n * A peer broke the protocol in a way the spec says must end the session.\n *\n * Thrown where the violation is detected, rather than handled there: a decoder has no session\n * to close. The dispatch that owns the session watches for it and closes, so a nonconforming\n * peer cannot repeat the violation on the next stream.\n *\n * @public\n */\nexport class ProtocolViolation extends Error {\n\tconstructor(message: string, options?: { cause?: unknown }) {\n\t\tsuper(message, options);\n\t\tthis.name = \"ProtocolViolation\";\n\t}\n}\n\n/** Package-internal compatibility names used by the wire implementation. */\nexport { Session as SessionError, Stream as StreamError, TooFarBehind as Lagged };\n/** Package-internal compatibility name used by the wire implementation. */\nexport type StreamErrorOptions = StreamOptions;\n\n/** The WebTransport-shaped fields a stream reset code arrives in. */\ntype StreamErrorLike = { source?: unknown; streamErrorCode?: unknown };\n\nfunction streamCode(err: unknown): StreamCode | undefined {\n\tif (typeof err !== \"object\" || err === null) return undefined;\n\n\tconst { source, streamErrorCode } = err as StreamErrorLike;\n\tif (source !== \"stream\" || typeof streamErrorCode !== \"number\") return undefined;\n\n\treturn streamErrorCode as StreamCode;\n}\n\n/** Transport context for encoding and decoding errors. @internal */\ninterface TransportErrorOptions {\n\t/** The negotiated IETF draft, or absent for moq-lite. */\n\tversion?: IetfVersion;\n}\n\n/**\n * Which {@link StreamCode} to send when resetting a stream because of `err`.\n *\n * The counterpart to {@link fromTransport}, and the pair has to agree: a code we send for a\n * condition is the code we read that condition back from, or two peers disagree about what it\n * means. Mirrors the Rust `From<&Error> for Stream`.\n *\n * Lossy on purpose. An error describes what went wrong here, while the registry is what the peer\n * can act on, so anything without a code of its own degrades to {@link StreamCode.Internal}\n * rather than inventing one. A {@link Session} lands there too: the two registries are\n * disjoint, so forwarding its code onto a stream would mistranslate it.\n *\n * On an IETF stream the code has to be one the negotiated draft assigns the same meaning to,\n * so a condition it does not register degrades to INTERNAL_ERROR as well. See\n * {@link sharedStreamCode}.\n *\n * @internal\n */\nexport function toStreamCode(err: unknown, options?: TransportErrorOptions): StreamCode {\n\tconst code = localStreamCode(err);\n\tif (options?.version === undefined) return code;\n\treturn sharedStreamCode(code, options.version) ? code : StreamCode.Internal;\n}\n\n/** The moq-lite code for a local failure, before any draft has a say. */\nfunction localStreamCode(err: unknown): StreamCode {\n\tif (err instanceof Stream) return err.code;\n\tif (err instanceof TimeoutError) return StreamCode.DeliveryTimeout;\n\t// Session-scoped: the peer learns which rule it broke from the session close, not from here.\n\tif (err instanceof ProtocolViolation) return StreamCode.SessionClosed;\n\treturn StreamCode.Internal;\n}\n\n/**\n * The {@link StreamCode.ControlTimeout} error for a control request the peer never answered.\n *\n * A control request that outlives its deadline is not late content, so it does not go out as\n * {@link StreamCode.DeliveryTimeout} the way a bare {@link TimeoutError} would. Callers that\n * bound a request's response build this instead.\n *\n * @internal\n */\nexport function controlTimeout(cause: unknown): Stream {\n\tconst message = cause instanceof Error && cause.message ? cause.message : \"control request timed out\";\n\treturn new Stream(StreamCode.ControlTimeout, { cause, message });\n}\n\n/**\n * Decode a transport failure into a {@link Stream} when it carries a stream reset code,\n * otherwise pass it through.\n *\n * Native WebTransport rejects with a `WebTransportError`; the WebSocket fallback mints an error\n * with the same `source`/`streamErrorCode` fields. Reading the fields rather than the class\n * covers both, and works in a runtime with no `WebTransportError` at all.\n *\n * On moq-lite, a code with a local class decodes back into it, so a peer's condition is caught by\n * the same `instanceof` as one raised here.\n *\n * On an IETF stream a code keeps its value unless moq-lite claims that number for something\n * the draft does not: `0x4` is GOING_AWAY here but UNKNOWN_OBJECT_STATUS on draft-16 and 17,\n * and reading one back as the other would retire a session that is not going anywhere. Those\n * read as {@link StreamCode.Internal} with the wire value kept in the message, since\n * {@link StreamCode} is one numeric space and cannot hold a foreign code without lying about\n * it. A code moq-lite names nothing for survives intact: nothing can misread it.\n *\n * @internal Called at the transport boundary so the raw error never reaches an application.\n */\nexport function fromTransport(err: unknown, options?: TransportErrorOptions): Error {\n\tconst code = streamCode(err);\n\tif (code === undefined) return error(err);\n\tif (options?.version !== undefined && !sharedStreamCode(code, options.version) && claimedLocally(code)) {\n\t\treturn new Stream(StreamCode.Internal, { cause: err, message: `remote error: ${code}` });\n\t}\n\tif (code === StreamCode.TooFarBehind) return new TooFarBehind({ cause: err });\n\tif (code === StreamCode.FrameTooLarge) return new FrameTooLarge({ cause: err });\n\tif (code === StreamCode.GroupTooLarge) return new GroupTooLarge({ cause: err });\n\treturn new Stream(code, { cause: err });\n}\n\n/** The codes moq-lite names, which a foreign one must not borrow. */\nconst NAMED_CODES: ReadonlySet<number> = new Set(Object.values(StreamCode));\n\n/**\n * Whether moq-lite could give `code` a meaning of its own: one of its named codes, or\n * anywhere in the 64+ range, where `StreamCode(code)` mints an application code and an\n * application compares against its own. moq-transport registers nothing above 0x12 and has\n * no application range at all, so a foreign code landing there is never what it looks like.\n */\nfunction claimedLocally(code: number): boolean {\n\treturn code >= 64 || NAMED_CODES.has(code);\n}\n\nconst legacyWebTransportErrors = new WeakSet<object>();\n\n/**\n * Build the `reason` to hand `abort()` / `cancel()` so the transport puts `code` on the wire.\n *\n * Both the WebTransport spec and the WebSocket fallback take the reset code from a\n * `WebTransportError`'s `streamErrorCode` and send 0 for anything else, a plain `Error`\n * included. Since 0 is {@link StreamCode.Internal}, cancelling with a bare `Error` tells the\n * peer we failed rather than that we are done.\n *\n * The native constructor exists exactly where native WebTransport does, which is where the\n * fallback isn't used, so mint a matching shape elsewhere rather than feature-detect a global\n * that will not be there.\n *\n * @internal\n */\nexport function toTransport(code: StreamCode, message: string): Error {\n\tconst Native = (globalThis as { WebTransportError?: typeof WebTransportError }).WebTransportError;\n\tif (Native) {\n\t\tconst Legacy = Native as unknown as new (init: { message: string; streamErrorCode: number }) => Error;\n\t\tif (legacyWebTransportErrors.has(Native)) return new Legacy({ message, streamErrorCode: code });\n\n\t\ttry {\n\t\t\treturn new Native(message, { source: \"stream\", streamErrorCode: code });\n\t\t} catch (err) {\n\t\t\t// Chromium still implements the previous single-dictionary constructor.\n\t\t\tif (!(err instanceof TypeError)) throw err;\n\t\t\tlegacyWebTransportErrors.add(Native);\n\t\t\treturn new Legacy({ message, streamErrorCode: code });\n\t\t}\n\t}\n\n\treturn Object.assign(new Error(message), { source: \"stream\" as const, streamErrorCode: code });\n}\n\n/**\n * Decode a session close into its terminal error: `null` for a clean close\n * ({@link SessionCode.Cancel}), otherwise a {@link Session} carrying the peer's code.\n *\n * @internal Applied to the transport's `closed` info so the code survives to the application.\n */\nexport function fromClose(info: WebTransportCloseInfo): Session | null {\n\tconst code = (info.closeCode ?? SessionCode.Cancel) as SessionCode;\n\tif (code === SessionCode.Cancel) return null;\n\treturn new Session(code, { reason: info.reason });\n}\n\n/**\n * The session's close as the error it ends everything with, carrying the peer's code. A clean\n * close code is still an error here: whatever the close cut off did not end.\n *\n * @internal\n */\nexport function closeError(quic: WebTransport): Promise<Error> {\n\treturn quic.closed.then(\n\t\t(info) => fromClose(info) ?? new Session(SessionCode.Cancel, { reason: info.reason }),\n\t\t(err: unknown) => error(err),\n\t);\n}\n\n/**\n * Report a failure the session's close caused as the session's own error, which carries the\n * peer's close code; any other failure passes through.\n *\n * @internal\n */\nexport async function sessionCause(quic: WebTransport | undefined, err: unknown): Promise<Error> {\n\tconst source = typeof err === \"object\" && err !== null ? (err as { source?: unknown }).source : undefined;\n\tif (quic && source === \"session\") return closeError(quic);\n\treturn error(err);\n}\n\n/**\n * Coerce an unknown thrown value into an `Error`.\n *\n * @internal\n */\nexport function error(err: unknown): Error {\n\treturn err instanceof Error ? err : new Error(String(err));\n}\n\n/**\n * Format an error into a non-empty, human-readable string for logging.\n *\n * Safari always leaves `WebTransportError.message` blank, so a bare `err.message` degrades to\n * an empty string and the reason is lost. This falls back to the error type name and appends\n * the WebTransport `source` and application `streamErrorCode`, so the log line always says\n * something.\n */\nexport function reason(err: unknown): string {\n\tconst e = error(err);\n\n\t// WebTransportError carries the failure origin and the peer's application error code,\n\t// often the only identifying detail since WebKit leaves `message` empty.\n\tif (typeof WebTransportError !== \"undefined\" && e instanceof WebTransportError) {\n\t\tconst parts = [`source=${e.source}`];\n\t\tif (e.streamErrorCode !== null) parts.push(`code=${e.streamErrorCode}`);\n\t\tconst detail = parts.join(\" \");\n\t\treturn e.message ? `${e.message} (${detail})` : `WebTransportError: ${detail}`;\n\t}\n\n\treturn e.message || e.name || \"unknown error\";\n}\n"]}
package/errors.d.ts CHANGED
@@ -3,5 +3,5 @@
3
3
  *
4
4
  * @module
5
5
  */
6
- export { FrameTooLarge, GroupTooLarge, NotFound, ProtocolViolation, Session, Stream, type StreamOptions, TooFarBehind, } from "./error";
6
+ export { FrameTooLarge, GroupTooLarge, NotFound, ProtocolViolation, RefusedRedirect, Session, Stream, type StreamOptions, TooFarBehind, } from "./error";
7
7
  //# sourceMappingURL=errors.d.ts.map
package/errors.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACN,aAAa,EACb,aAAa,EACb,QAAQ,EACR,iBAAiB,EACjB,OAAO,EACP,MAAM,EACN,KAAK,aAAa,EAClB,YAAY,GACZ,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACN,aAAa,EACb,aAAa,EACb,QAAQ,EACR,iBAAiB,EACjB,eAAe,EACf,OAAO,EACP,MAAM,EACN,KAAK,aAAa,EAClB,YAAY,GACZ,MAAM,YAAY,CAAC"}
package/errors.js CHANGED
@@ -4,5 +4,5 @@
4
4
  *
5
5
  * @module
6
6
  */
7
- export { FrameTooLarge, GroupTooLarge, NotFound, ProtocolViolation, Session, Stream, TooFarBehind, } from "./error.js";
7
+ export { FrameTooLarge, GroupTooLarge, NotFound, ProtocolViolation, RefusedRedirect, Session, Stream, TooFarBehind, } from "./error.js";
8
8
  //# sourceMappingURL=errors.js.map
package/errors.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACN,aAAa,EACb,aAAa,EACb,QAAQ,EACR,iBAAiB,EACjB,OAAO,EACP,MAAM,EAEN,YAAY,GACZ,MAAM,YAAY,CAAC","sourcesContent":["/**\n * Session and stream error types.\n *\n * @module\n */\nexport {\n\tFrameTooLarge,\n\tGroupTooLarge,\n\tNotFound,\n\tProtocolViolation,\n\tSession,\n\tStream,\n\ttype StreamOptions,\n\tTooFarBehind,\n} from \"./error.ts\";\n"]}
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACN,aAAa,EACb,aAAa,EACb,QAAQ,EACR,iBAAiB,EACjB,eAAe,EACf,OAAO,EACP,MAAM,EAEN,YAAY,GACZ,MAAM,YAAY,CAAC","sourcesContent":["/**\n * Session and stream error types.\n *\n * @module\n */\nexport {\n\tFrameTooLarge,\n\tGroupTooLarge,\n\tNotFound,\n\tProtocolViolation,\n\tRefusedRedirect,\n\tSession,\n\tStream,\n\ttype StreamOptions,\n\tTooFarBehind,\n} from \"./error.ts\";\n"]}
package/group.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"group.d.ts","sourceRoot":"","sources":["../src/group.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAgB,KAAK,UAAU,EAA6B,MAAM,cAAc,CAAC;AAGxF,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,4GAA4G;AAC5G,eAAO,MAAM,qBAAqB,QAAmB,CAAC;AAEtD,uHAAuH;AACvH,eAAO,MAAM,gBAAgB,OAAO,CAAC;AAErC;;;;;GAKG;AACH,MAAM,WAAW,KAAK;IACrB,yBAAyB;IACzB,OAAO,EAAE,UAAU,CAAC;IACpB;;;OAGG;IACH,SAAS,EAAE,SAAS,CAAC;CACrB;AAED,+CAA+C;AAC/C,MAAM,WAAW,WAAW;IAC3B;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;AAED,gCAAgC;AAChC,MAAM,WAAW,IAAI;IACpB,sDAAsD;IACtD,QAAQ,EAAE,MAAM,CAAC;CACjB;AAqCD;;;;GAIG;AACH,qBAAa,QAAQ;;IACpB,sDAAsD;IACtD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAc1B,YAAY,QAAQ,EAAE,MAAM,EAG3B;IAWD;;;OAGG;IACH,IAAI,MAAM,IAAI,UAAU,CAAC,KAAK,GAAG,IAAI,CAAC,CAErC;IAED,oCAAoC;IACpC,OAAO,IAAI,QAAQ,CAElB;IAmED,mCAAmC;IACnC,UAAU,CAAC,KAAK,EAAE,KAAK,QAkCtB;IAED,0FAA0F;IAC1F,WAA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IAC/E,KAAK,CAAC,KAAK,CAAC,EAAE,KAAK,QAGlB;CACD"}
package/group.js CHANGED
@@ -340,14 +340,15 @@ export class Consumer {
340
340
  this.#verdict.set(this.#terminal ?? null);
341
341
  return true;
342
342
  }
343
+ // Takes a thunk rather than a started promise, so a group already past its budget
344
+ // never begins the write: an abandoned write would reject later with no handler.
343
345
  #guard(operation) {
344
- if (this.#expire(true))
345
- return Promise.reject(this.#terminal);
346
+ this.#expire(true);
346
347
  if (this.#terminal)
347
348
  return Promise.reject(this.#terminal);
348
349
  const expiry = this.#expiry;
349
350
  if (!expiry)
350
- return operation;
351
+ return operation();
351
352
  return new Promise((resolve, reject) => {
352
353
  let settled = false;
353
354
  const disposes = [];
@@ -368,7 +369,7 @@ export class Consumer {
368
369
  };
369
370
  for (const changed of expiry.changed)
370
371
  disposes.push(changed.subscribe(check));
371
- operation.then((value) => finish(() => resolve(value)), (error) => finish(() => reject(error)));
372
+ operation().then((value) => finish(() => resolve(value)), (error) => finish(() => reject(error)));
372
373
  check();
373
374
  });
374
375
  }