@moq/net 0.3.5 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (210) hide show
  1. package/announce.d.ts +7 -0
  2. package/announce.d.ts.map +1 -0
  3. package/announce.js +8 -0
  4. package/announce.js.map +1 -0
  5. package/announced.d.ts +35 -91
  6. package/announced.d.ts.map +1 -1
  7. package/announced.js +21 -156
  8. package/announced.js.map +1 -1
  9. package/bandwidth.d.ts +163 -0
  10. package/bandwidth.d.ts.map +1 -0
  11. package/bandwidth.js +304 -0
  12. package/bandwidth.js.map +1 -0
  13. package/bandwidth_api.d.ts +7 -0
  14. package/bandwidth_api.d.ts.map +1 -0
  15. package/bandwidth_api.js +8 -0
  16. package/bandwidth_api.js.map +1 -0
  17. package/broadcast.d.ts +20 -28
  18. package/broadcast.d.ts.map +1 -1
  19. package/broadcast.js +55 -38
  20. package/broadcast.js.map +1 -1
  21. package/connection/accept.d.ts +16 -1
  22. package/connection/accept.d.ts.map +1 -1
  23. package/connection/accept.js +39 -24
  24. package/connection/accept.js.map +1 -1
  25. package/connection/browser.d.ts.map +1 -1
  26. package/connection/browser.js +9 -7
  27. package/connection/browser.js.map +1 -1
  28. package/connection/connect.d.ts +30 -6
  29. package/connection/connect.d.ts.map +1 -1
  30. package/connection/connect.js +85 -45
  31. package/connection/connect.js.map +1 -1
  32. package/connection/established.d.ts +16 -21
  33. package/connection/established.d.ts.map +1 -1
  34. package/connection/established.js.map +1 -1
  35. package/connection/forward.d.ts +2 -0
  36. package/connection/forward.d.ts.map +1 -0
  37. package/connection/forward.js +159 -0
  38. package/connection/forward.js.map +1 -0
  39. package/connection/handshake.d.ts.map +1 -1
  40. package/connection/handshake.js +2 -2
  41. package/connection/handshake.js.map +1 -1
  42. package/connection/index.d.ts +5 -5
  43. package/connection/index.d.ts.map +1 -1
  44. package/connection/index.js +4 -5
  45. package/connection/index.js.map +1 -1
  46. package/connection/pool.d.ts +188 -0
  47. package/connection/pool.d.ts.map +1 -0
  48. package/connection/pool.js +351 -0
  49. package/connection/pool.js.map +1 -0
  50. package/connection/reload.d.ts +14 -93
  51. package/connection/reload.d.ts.map +1 -1
  52. package/connection/reload.js +216 -80
  53. package/connection/reload.js.map +1 -1
  54. package/connection/stats.d.ts +3 -26
  55. package/connection/stats.d.ts.map +1 -1
  56. package/connection/stats.js.map +1 -1
  57. package/connection/transport.d.ts +0 -7
  58. package/connection/transport.d.ts.map +1 -1
  59. package/consume.d.ts +1 -43
  60. package/consume.d.ts.map +1 -1
  61. package/consume.js +1 -1
  62. package/consume.js.map +1 -1
  63. package/error.d.ts +180 -29
  64. package/error.d.ts.map +1 -1
  65. package/error.js +310 -16
  66. package/error.js.map +1 -1
  67. package/errors.d.ts +7 -0
  68. package/errors.d.ts.map +1 -0
  69. package/errors.js +8 -0
  70. package/errors.js.map +1 -0
  71. package/group.d.ts +9 -43
  72. package/group.d.ts.map +1 -1
  73. package/group.js +283 -69
  74. package/group.js.map +1 -1
  75. package/hop.d.ts +107 -0
  76. package/hop.d.ts.map +1 -0
  77. package/hop.js +103 -0
  78. package/hop.js.map +1 -0
  79. package/ietf/aliases.d.ts +1 -78
  80. package/ietf/aliases.d.ts.map +1 -1
  81. package/ietf/cluster.d.ts +6 -120
  82. package/ietf/cluster.d.ts.map +1 -1
  83. package/ietf/cluster.js +81 -41
  84. package/ietf/cluster.js.map +1 -1
  85. package/ietf/connection.d.ts +6 -72
  86. package/ietf/connection.d.ts.map +1 -1
  87. package/ietf/connection.js +11 -47
  88. package/ietf/connection.js.map +1 -1
  89. package/ietf/error.d.ts +11 -0
  90. package/ietf/error.d.ts.map +1 -0
  91. package/ietf/error.js +168 -0
  92. package/ietf/error.js.map +1 -0
  93. package/ietf/filter.d.ts.map +1 -1
  94. package/ietf/filter.js +6 -1
  95. package/ietf/filter.js.map +1 -1
  96. package/ietf/goaway.d.ts.map +1 -1
  97. package/ietf/goaway.js +22 -5
  98. package/ietf/goaway.js.map +1 -1
  99. package/ietf/parameters.d.ts +2 -2
  100. package/ietf/parameters.d.ts.map +1 -1
  101. package/ietf/parameters.js +15 -17
  102. package/ietf/parameters.js.map +1 -1
  103. package/ietf/publish_namespace.d.ts +25 -0
  104. package/ietf/publish_namespace.d.ts.map +1 -1
  105. package/ietf/publish_namespace.js +63 -0
  106. package/ietf/publish_namespace.js.map +1 -1
  107. package/ietf/publisher.d.ts +1 -82
  108. package/ietf/publisher.d.ts.map +1 -1
  109. package/ietf/publisher.js +203 -136
  110. package/ietf/publisher.js.map +1 -1
  111. package/ietf/solicit.d.ts +1 -40
  112. package/ietf/solicit.d.ts.map +1 -1
  113. package/ietf/subscribe.d.ts +1 -5
  114. package/ietf/subscribe.d.ts.map +1 -1
  115. package/ietf/subscribe.js +8 -9
  116. package/ietf/subscribe.js.map +1 -1
  117. package/ietf/subscriber.d.ts +1 -65
  118. package/ietf/subscriber.d.ts.map +1 -1
  119. package/ietf/subscriber.js +154 -73
  120. package/ietf/subscriber.js.map +1 -1
  121. package/ietf/version.d.ts +12 -1
  122. package/ietf/version.d.ts.map +1 -1
  123. package/ietf/version.js +13 -0
  124. package/ietf/version.js.map +1 -1
  125. package/index.d.ts +11 -6
  126. package/index.d.ts.map +1 -1
  127. package/index.js +10 -5
  128. package/index.js.map +1 -1
  129. package/internal.d.ts +97 -1
  130. package/internal.d.ts.map +1 -1
  131. package/internal.js +65 -0
  132. package/internal.js.map +1 -1
  133. package/lite/announce.d.ts +15 -9
  134. package/lite/announce.d.ts.map +1 -1
  135. package/lite/announce.js +47 -20
  136. package/lite/announce.js.map +1 -1
  137. package/lite/connection.d.ts +9 -59
  138. package/lite/connection.d.ts.map +1 -1
  139. package/lite/connection.js +20 -32
  140. package/lite/connection.js.map +1 -1
  141. package/lite/fetch.d.ts +15 -1
  142. package/lite/fetch.d.ts.map +1 -1
  143. package/lite/fetch.js +39 -7
  144. package/lite/fetch.js.map +1 -1
  145. package/lite/goaway.d.ts.map +1 -1
  146. package/lite/goaway.js +7 -1
  147. package/lite/goaway.js.map +1 -1
  148. package/lite/group.d.ts +18 -4
  149. package/lite/group.d.ts.map +1 -1
  150. package/lite/group.js +31 -10
  151. package/lite/group.js.map +1 -1
  152. package/lite/priority.d.ts +1 -61
  153. package/lite/priority.d.ts.map +1 -1
  154. package/lite/priority.js +4 -5
  155. package/lite/priority.js.map +1 -1
  156. package/lite/publisher.d.ts +1 -69
  157. package/lite/publisher.d.ts.map +1 -1
  158. package/lite/publisher.js +507 -200
  159. package/lite/publisher.js.map +1 -1
  160. package/lite/setup.d.ts +7 -7
  161. package/lite/setup.d.ts.map +1 -1
  162. package/lite/setup.js +13 -13
  163. package/lite/setup.js.map +1 -1
  164. package/lite/subscribe.d.ts +61 -13
  165. package/lite/subscribe.d.ts.map +1 -1
  166. package/lite/subscribe.js +186 -44
  167. package/lite/subscribe.js.map +1 -1
  168. package/lite/subscriber.d.ts +8 -57
  169. package/lite/subscriber.d.ts.map +1 -1
  170. package/lite/subscriber.js +179 -117
  171. package/lite/subscriber.js.map +1 -1
  172. package/lite/track.d.ts +4 -10
  173. package/lite/track.d.ts.map +1 -1
  174. package/lite/track.js +34 -29
  175. package/lite/track.js.map +1 -1
  176. package/lite/version.d.ts +31 -6
  177. package/lite/version.d.ts.map +1 -1
  178. package/lite/version.js +71 -11
  179. package/lite/version.js.map +1 -1
  180. package/origin.d.ts +229 -29
  181. package/origin.d.ts.map +1 -1
  182. package/origin.js +1087 -37
  183. package/origin.js.map +1 -1
  184. package/package.json +3 -2
  185. package/path.d.ts +25 -7
  186. package/path.d.ts.map +1 -1
  187. package/path.js +5 -3
  188. package/path.js.map +1 -1
  189. package/stream.d.ts.map +1 -1
  190. package/stream.js +23 -14
  191. package/stream.js.map +1 -1
  192. package/time.d.ts +15 -2
  193. package/time.d.ts.map +1 -1
  194. package/time.js +28 -9
  195. package/time.js.map +1 -1
  196. package/track.d.ts +166 -83
  197. package/track.d.ts.map +1 -1
  198. package/track.js +617 -187
  199. package/track.js.map +1 -1
  200. package/wire.d.ts +67 -0
  201. package/wire.d.ts.map +1 -0
  202. package/wire.js +32 -0
  203. package/wire.js.map +1 -0
  204. package/zod.d.ts +1 -1
  205. package/zod.d.ts.map +1 -1
  206. package/zod.js.map +1 -1
  207. package/mock.d.ts +0 -66
  208. package/mock.d.ts.map +0 -1
  209. package/mock.js +0 -243
  210. package/mock.js.map +0 -1
package/announce.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Broadcast announcement streams.
3
+ *
4
+ * @module
5
+ */
6
+ export { Consumer, isActive, type Kind, type Update } from "./announced";
7
+ //# sourceMappingURL=announce.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"announce.d.ts","sourceRoot":"","sources":["../src/announce.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,IAAI,EAAE,KAAK,MAAM,EAAE,MAAM,gBAAgB,CAAC"}
package/announce.js ADDED
@@ -0,0 +1,8 @@
1
+ /* @ts-self-types="./announce.d.ts" */
2
+ /**
3
+ * Broadcast announcement streams.
4
+ *
5
+ * @module
6
+ */
7
+ export { Consumer, isActive } from "./announced.js";
8
+ //# sourceMappingURL=announce.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"announce.js","sourceRoot":"","sources":["../src/announce.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAA0B,MAAM,gBAAgB,CAAC","sourcesContent":["/**\n * Broadcast announcement streams.\n *\n * @module\n */\nexport { Consumer, isActive, type Kind, type Update } from \"./announced.ts\";\n"]}
package/announced.d.ts CHANGED
@@ -1,23 +1,42 @@
1
1
  /**
2
- * Broadcast announcement streams: which broadcast paths are available under a prefix.
2
+ * Broadcast announcement streams: which broadcast paths are available under a scope.
3
3
  *
4
4
  * @module
5
5
  */
6
- import { type GetPromise, type Getter, type GetterInit } from "@moq/signals";
7
- import type * as broadcast from "./broadcast.js";
8
- import type { Established } from "./connection/established.js";
9
- import * as Path from "./path.js";
6
+ import { type GetPromise } from "@moq/signals";
7
+ import type { Route } from "./hop.js";
8
+ import type * as Path from "./path.js";
10
9
  /**
11
- * The availability of a broadcast.
10
+ * What an {@link Update} reports about its prefix.
12
11
  *
13
12
  * @public
14
13
  */
15
- export interface Event {
16
- /** Broadcast path relative to the prefix passed to `announced()`. */
17
- path: Path.Valid;
18
- /** True when the broadcast is available, false when it was removed. */
19
- active: boolean;
14
+ export type Kind = "announced" | "updated" | "retracted";
15
+ /**
16
+ * A route announcement, update, or retraction.
17
+ *
18
+ * An announcement is always a prefix, never a broadcast: a route claims that
19
+ * {@link prefix} and every path beneath it can be served. By convention a publisher
20
+ * announces each broadcast's exact path, so enumerating routes enumerates broadcasts;
21
+ * resolve one with the origin's `request(path)`. Narrow with a {@link Path.Pattern}
22
+ * locally to follow a subset.
23
+ *
24
+ * @public
25
+ */
26
+ export interface Update {
27
+ /**
28
+ * The prefix the route covers, relative to the origin (for a session, its URL path).
29
+ */
30
+ prefix: Path.Valid;
31
+ /** What the filter's wildcards stood for, when this prefix pins all of them. */
32
+ captures: Path.Pattern[] | undefined;
33
+ /** Whether the prefix was announced, re-priced, or retracted. */
34
+ kind: Kind;
35
+ /** Hops and cost of the route; on a retraction, its last advertised values. */
36
+ route: Route;
20
37
  }
38
+ /** Whether a route covers the path after an update of this {@link Kind}. */
39
+ export declare function isActive(kind: Kind): boolean;
21
40
  /**
22
41
  * The write side of an announcement stream.
23
42
  *
@@ -25,9 +44,6 @@ export interface Event {
25
44
  */
26
45
  export declare class Producer {
27
46
  #private;
28
- /** Path prefix this stream is scoped to. */
29
- prefix: Path.Valid;
30
- constructor(prefix?: Path.Valid);
31
47
  /**
32
48
  * Settles once the stream closes: `null` on a clean close, or the abort {@link Error}.
33
49
  * Peek it synchronously (`undefined` while open), observe it reactively, or `await` it.
@@ -36,7 +52,7 @@ export declare class Producer {
36
52
  /** A read handle for this announcement stream. */
37
53
  consume(): Consumer;
38
54
  /** Writes an announcement to the queue. */
39
- append(event: Event): void;
55
+ append(update: Update): void;
40
56
  /** Closes the writer. Idempotent. */
41
57
  close(abort?: Error): void;
42
58
  }
@@ -44,92 +60,20 @@ export declare class Producer {
44
60
  * The read side of an announcement stream.
45
61
  *
46
62
  * Created internally: obtain one from {@link Producer.consume} or the connection's
47
- * `announced(prefix)`.
63
+ * `announced(scope)`.
48
64
  *
49
65
  * @public
50
66
  */
51
67
  export declare class Consumer {
52
68
  #private;
53
- /** Path prefix this stream is scoped to. */
54
- prefix: Path.Valid;
55
69
  private constructor();
56
70
  /** Settles once the stream closes; see {@link Producer.closed}. */
57
71
  get closed(): GetPromise<Error | null>;
72
+ /** The announcements as they arrive, until the stream closes. */
73
+ [Symbol.asyncIterator](): AsyncGenerator<Update, void, undefined>;
58
74
  /** Returns the next announcement. */
59
- next(): Promise<Event | undefined>;
75
+ next(): Promise<Update | undefined>;
60
76
  /** Closes the reader. Idempotent. */
61
77
  close(abort?: Error): void;
62
78
  }
63
- /**
64
- * What to watch, for {@link Broadcast}.
65
- *
66
- * @public
67
- */
68
- export interface BroadcastProps {
69
- /**
70
- * The connection to watch on. Accepts a live {@link Established} session, or a reactive one
71
- * (a `Connection.Reload`'s `established`), which is how the handle survives reconnects.
72
- */
73
- connection: GetterInit<Established | undefined>;
74
- /** The broadcast path to watch. */
75
- path: Path.Valid;
76
- }
77
- /**
78
- * A reactive handle to a single broadcast: {@link Broadcast.active} holds a live
79
- * {@link broadcast.Consumer} while the path is announced and `undefined` while nobody
80
- * publishes it.
81
- *
82
- * Use this instead of {@link Established.consume} whenever the broadcast may not exist yet.
83
- * Subscribing to a path nobody publishes gets the stream reset, so a consumer that races the
84
- * publisher stays silent forever unless it retries; this waits for the announcement instead.
85
- *
86
- * A same-name republish re-consumes, so the handle attaches to the new instance rather than
87
- * clinging to the dead one. A relay failover that keeps the same publisher does *not*: the
88
- * subscription resumes across the new route, so `active` holds the same consumer throughout and
89
- * never goes offline. Only a change of publisher produces an offline/online transition.
90
- *
91
- * Built from a reconnecting `Connection.Reload`, the handle also spans reconnects: the broadcast
92
- * drops to `undefined` while disconnected and resolves again once the new connection announces it.
93
- *
94
- * Falls back to consuming blind (and warns once) on a relay without
95
- * {@link Established.discovery}, where there is no announcement to wait for. `active` then
96
- * means *assumed present* rather than known live: nothing reports whether the path exists, so
97
- * a subscribe to a missing broadcast is how a caller finds out. The handle stays usable either
98
- * way, and because it is scoped to the path rather than to one publisher, a subscribe made
99
- * after a publisher finally appears succeeds.
100
- *
101
- * If discovery fails on a live session (the announcement stream is reset, or the relay
102
- * refuses it) the handle goes offline and stays there: nothing reopens the stream on that
103
- * connection. Build it from a `Connection.Reload` if you need it to recover, since a new
104
- * connection starts a new stream.
105
- *
106
- * Close it to release the announcement stream and the current broadcast.
107
- *
108
- * @public
109
- */
110
- export declare class Broadcast {
111
- #private;
112
- /** The broadcast path this handle watches. */
113
- readonly path: Path.Valid;
114
- /**
115
- * The live broadcast, or `undefined` while it is offline.
116
- *
117
- * Borrowed, not yours to close: this handle owns the consumer and swaps it when the path is
118
- * republished. `active` keeps pointing at whatever you closed, so once you drop the last
119
- * reference the shared broadcast is gone and reads fail until the next announcement replaces
120
- * it. Take a {@link broadcast.Consumer.clone} for a lifetime of your own, or close this whole
121
- * handle to release everything.
122
- */
123
- readonly active: Getter<broadcast.Consumer | undefined>;
124
- /**
125
- * Watch a path on a connection.
126
- *
127
- * Prefer `announcedBroadcast(path)` on the connection itself. Reach for this when the
128
- * session you want to follow isn't either connection type, e.g. your own
129
- * `Getter<Established | undefined>`.
130
- */
131
- constructor({ connection, path }: BroadcastProps);
132
- /** Closes the handle and the broadcast it currently holds. Idempotent. */
133
- close(): void;
134
- }
135
79
  //# sourceMappingURL=announced.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"announced.d.ts","sourceRoot":"","sources":["../src/announced.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAU,KAAK,UAAU,E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C3C,MAAM,CAAC,MAAM,EAAE,MAAM,QAKpB;IAED,qCAAqC;IACrC,KAAK,CAAC,KAAK,CAAC,EAAE,KAAK,QAElB;CACD;AAMD;;;;;;;GAOG;AACH,qBAAa,QAAQ;;IAGpB,OAAO,eAEN;IAED,mEAAmE;IACnE,IAAI,MAAM,IAAI,UAAU,CAAC,KAAK,GAAG,IAAI,CAAC,CAErC;IAMD,iEAAiE;IAC1D,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,cAAc,CAAC,MAAM,EAAE,IAAI,EAAE,SAAS,CAAC,CAMvE;IAED,qCAAqC;IAC/B,IAAI,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAWxC;IAED,qCAAqC;IACrC,KAAK,CAAC,KAAK,CAAC,EAAE,KAAK,QAElB;CACD"}
package/announced.js CHANGED
@@ -1,11 +1,14 @@
1
1
  /* @ts-self-types="./announced.d.ts" */
2
2
  /**
3
- * Broadcast announcement streams: which broadcast paths are available under a prefix.
3
+ * Broadcast announcement streams: which broadcast paths are available under a scope.
4
4
  *
5
5
  * @module
6
6
  */
7
- import { Effect, getter, Once, Signal } from "@moq/signals";
8
- import * as Path from "./path.js";
7
+ import { Once, Signal } from "@moq/signals";
8
+ /** Whether a route covers the path after an update of this {@link Kind}. */
9
+ export function isActive(kind) {
10
+ return kind !== "retracted";
11
+ }
9
12
  /** Reactive backing state shared by announcement producers and consumers. */
10
13
  class AnnounceState {
11
14
  queue = new Signal([]);
@@ -26,12 +29,7 @@ function closeState(state, abort) {
26
29
  * @public
27
30
  */
28
31
  export class Producer {
29
- /** Path prefix this stream is scoped to. */
30
- prefix;
31
32
  #state = new AnnounceState();
32
- constructor(prefix = Path.empty()) {
33
- this.prefix = prefix;
34
- }
35
33
  /**
36
34
  * Settles once the stream closes: `null` on a clean close, or the abort {@link Error}.
37
35
  * Peek it synchronously (`undefined` while open), observe it reactively, or `await` it.
@@ -41,14 +39,14 @@ export class Producer {
41
39
  }
42
40
  /** A read handle for this announcement stream. */
43
41
  consume() {
44
- return makeConsumer(this.prefix, this.#state);
42
+ return makeConsumer(this.#state);
45
43
  }
46
44
  /** Writes an announcement to the queue. */
47
- append(event) {
45
+ append(update) {
48
46
  if (this.#state.closed.peek() !== undefined)
49
47
  throw new Error("announcements are closed");
50
48
  this.#state.queue.mutate((queue) => {
51
- queue.push(event);
49
+ queue.push(update);
52
50
  });
53
51
  }
54
52
  /** Closes the writer. Idempotent. */
@@ -63,16 +61,13 @@ let makeConsumer;
63
61
  * The read side of an announcement stream.
64
62
  *
65
63
  * Created internally: obtain one from {@link Producer.consume} or the connection's
66
- * `announced(prefix)`.
64
+ * `announced(scope)`.
67
65
  *
68
66
  * @public
69
67
  */
70
68
  export class Consumer {
71
- /** Path prefix this stream is scoped to. */
72
- prefix;
73
69
  #state;
74
- constructor(prefix, state) {
75
- this.prefix = prefix;
70
+ constructor(state) {
76
71
  this.#state = state;
77
72
  }
78
73
  /** Settles once the stream closes; see {@link Producer.closed}. */
@@ -80,7 +75,16 @@ export class Consumer {
80
75
  return this.#state.closed;
81
76
  }
82
77
  static {
83
- makeConsumer = (prefix, state) => new Consumer(prefix, state);
78
+ makeConsumer = (state) => new Consumer(state);
79
+ }
80
+ /** The announcements as they arrive, until the stream closes. */
81
+ async *[Symbol.asyncIterator]() {
82
+ for (;;) {
83
+ const update = await this.next();
84
+ if (!update)
85
+ return;
86
+ yield update;
87
+ }
84
88
  }
85
89
  /** Returns the next announcement. */
86
90
  async next() {
@@ -101,143 +105,4 @@ export class Consumer {
101
105
  closeState(this.#state, abort);
102
106
  }
103
107
  }
104
- // Connections already warned about missing broadcast discovery, so the fallback logs at most
105
- // once per connection instead of once per watched path.
106
- const warnedNoDiscovery = new WeakSet();
107
- /**
108
- * A reactive handle to a single broadcast: {@link Broadcast.active} holds a live
109
- * {@link broadcast.Consumer} while the path is announced and `undefined` while nobody
110
- * publishes it.
111
- *
112
- * Use this instead of {@link Established.consume} whenever the broadcast may not exist yet.
113
- * Subscribing to a path nobody publishes gets the stream reset, so a consumer that races the
114
- * publisher stays silent forever unless it retries; this waits for the announcement instead.
115
- *
116
- * A same-name republish re-consumes, so the handle attaches to the new instance rather than
117
- * clinging to the dead one. A relay failover that keeps the same publisher does *not*: the
118
- * subscription resumes across the new route, so `active` holds the same consumer throughout and
119
- * never goes offline. Only a change of publisher produces an offline/online transition.
120
- *
121
- * Built from a reconnecting `Connection.Reload`, the handle also spans reconnects: the broadcast
122
- * drops to `undefined` while disconnected and resolves again once the new connection announces it.
123
- *
124
- * Falls back to consuming blind (and warns once) on a relay without
125
- * {@link Established.discovery}, where there is no announcement to wait for. `active` then
126
- * means *assumed present* rather than known live: nothing reports whether the path exists, so
127
- * a subscribe to a missing broadcast is how a caller finds out. The handle stays usable either
128
- * way, and because it is scoped to the path rather than to one publisher, a subscribe made
129
- * after a publisher finally appears succeeds.
130
- *
131
- * If discovery fails on a live session (the announcement stream is reset, or the relay
132
- * refuses it) the handle goes offline and stays there: nothing reopens the stream on that
133
- * connection. Build it from a `Connection.Reload` if you need it to recover, since a new
134
- * connection starts a new stream.
135
- *
136
- * Close it to release the announcement stream and the current broadcast.
137
- *
138
- * @public
139
- */
140
- export class Broadcast {
141
- /** The broadcast path this handle watches. */
142
- path;
143
- /**
144
- * The live broadcast, or `undefined` while it is offline.
145
- *
146
- * Borrowed, not yours to close: this handle owns the consumer and swaps it when the path is
147
- * republished. `active` keeps pointing at whatever you closed, so once you drop the last
148
- * reference the shared broadcast is gone and reads fail until the next announcement replaces
149
- * it. Take a {@link broadcast.Consumer.clone} for a lifetime of your own, or close this whole
150
- * handle to release everything.
151
- */
152
- active;
153
- #active = new Signal(undefined);
154
- #signals = new Effect();
155
- /**
156
- * Watch a path on a connection.
157
- *
158
- * Prefer `announcedBroadcast(path)` on the connection itself. Reach for this when the
159
- * session you want to follow isn't either connection type, e.g. your own
160
- * `Getter<Established | undefined>`.
161
- */
162
- constructor({ connection, path }) {
163
- this.path = path;
164
- this.active = this.#active;
165
- const source = getter(connection);
166
- this.#signals.run((effect) => {
167
- const conn = effect.get(source);
168
- if (!conn)
169
- return;
170
- // Without discovery no announcement ever arrives, so waiting would hang forever.
171
- if (!conn.discovery) {
172
- if (!warnedNoDiscovery.has(conn)) {
173
- warnedNoDiscovery.add(conn);
174
- console.warn("relay does not support broadcast discovery; consuming without waiting.");
175
- }
176
- const blind = conn.consume(path);
177
- effect.cleanup(() => blind.close());
178
- effect.set(this.#active, blind, undefined);
179
- // The announcement-gated path below goes offline when the stream ends with the
180
- // session; without discovery there is no stream, so watch the session itself.
181
- // A consumed broadcast is a path-scoped handle, not a subscription, so its own
182
- // `closed` says nothing about whether the path exists or the session is alive.
183
- // Raced against the run's teardown so a closed handle isn't retained until the
184
- // session ends; the cleanup above has already cleared `active` in that case.
185
- effect.spawn(async () => {
186
- await Promise.race([effect.cancel, conn.closed]);
187
- if (this.#active.peek() === blind)
188
- this.#active.set(undefined);
189
- });
190
- return;
191
- }
192
- const announced = conn.announced(path);
193
- effect.cleanup(() => announced.close());
194
- let current;
195
- const offline = () => {
196
- const mine = current;
197
- current?.close();
198
- current = undefined;
199
- // Only clear what this run put there. A spawn task that resumes after its run was
200
- // torn down would otherwise wipe the consumer a newer run already installed.
201
- if (this.#active.peek() === mine)
202
- this.#active.set(undefined);
203
- };
204
- effect.cleanup(offline);
205
- effect.spawn(async () => {
206
- try {
207
- for (;;) {
208
- const event = await Promise.race([effect.cancel, announced.next()]);
209
- if (!event)
210
- break;
211
- // Scoped to `path`, so the exact broadcast arrives with an empty suffix; ignore children.
212
- if (event.path !== Path.empty())
213
- continue;
214
- if (event.active) {
215
- // A live subscription survives a redundant (re-)announce; only replace a dead one.
216
- if (current && current.closed.peek() === undefined)
217
- continue;
218
- current?.close();
219
- current = conn.consume(path);
220
- this.#active.set(current);
221
- }
222
- else {
223
- offline();
224
- }
225
- }
226
- }
227
- catch (err) {
228
- // Discovery failed: the session died under the stream, or the relay refused
229
- // to answer. Nothing reopens it on this connection, so say so out loud.
230
- console.warn("broadcast discovery failed", err);
231
- }
232
- // The stream ended, or this run was torn down (its cleanup already ran). Either
233
- // way there is nothing left announcing the path, so don't hold a dead broadcast.
234
- offline();
235
- });
236
- });
237
- }
238
- /** Closes the handle and the broadcast it currently holds. Idempotent. */
239
- close() {
240
- this.#signals.close();
241
- }
242
- }
243
108
  //# sourceMappingURL=announced.js.map
package/announced.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"announced.js","sourceRoot":"","sources":["../src/announced.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,MAAM,EAAiD,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAG3G,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAclC,6EAA6E;AAC7E,MAAM,aAAa;IAClB,KAAK,GAAG,IAAI,MAAM,CAAU,EAAE,CAAC,CAAC;IAChC,MAAM,GAAG,IAAI,IAAI,EAAgB,CAAC;CAClC;AAED,yFAAyF;AACzF,SAAS,UAAU,CAAC,KAAoB,EAAE,KAAa;IACtD,IAAI,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,SAAS;QAAE,OAAO;IAC9C,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC;IAChC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;QAC5B,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,OAAO,QAAQ;IACpB,4CAA4C;IAC5C,MAAM,CAAa;IAEnB,MAAM,GAAG,IAAI,aAAa,EAAE,CAAC;IAE7B,YAAY,MAAM,GAAG,IAAI,CAAC,KAAK,EAAE;QAChC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACtB,CAAC;IAED;;;OAGG;IACH,IAAI,MAAM;QACT,OAAO,IAAI,CAAC,MAAM,C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QAAQ,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;CACD","sourcesContent":["/**\n * Broadcast announcement streams: which broadcast paths are available under a prefix.\n *\n * @module\n */\nimport { Effect, type GetPromise, type Getter, type GetterInit, getter, Once, Signal } from \"@moq/signals\";\nimport type * as broadcast from \"./broadcast.js\";\nimport type { Established } from \"./connection/established.js\";\nimport * as Path from \"./path.js\";\n\n/**\n * The availability of a broadcast.\n *\n * @public\n */\nexport interface Event {\n\t/** Broadcast path relative to the prefix passed to `announced()`. */\n\tpath: Path.Valid;\n\t/** True when the broadcast is available, false when it was removed. */\n\tactive: boolean;\n}\n\n/** Reactive backing state shared by announcement producers and consumers. */\nclass AnnounceState {\n\tqueue = new Signal<Event[]>([]);\n\tclosed = new Once<Error | null>();\n}\n\n// Once.set throws on a second settle, and both ends of a stream can close independently.\nfunction closeState(state: AnnounceState, abort?: Error) {\n\tif (state.closed.peek() !== undefined) return;\n\tstate.closed.set(abort ?? null);\n\tstate.queue.mutate((queue) => {\n\t\tqueue.length = 0;\n\t});\n}\n\n/**\n * The write side of an announcement stream.\n *\n * @public\n */\nexport class Producer {\n\t/** Path prefix this stream is scoped to. */\n\tprefix: Path.Valid;\n\n\t#state = new AnnounceState();\n\n\tconstructor(prefix = Path.empty()) {\n\t\tthis.prefix = prefix;\n\t}\n\n\t/**\n\t * Settles once the stream closes: `null` on a clean close, or the abort {@link Error}.\n\t * Peek it synchronously (`undefined` while open), observe it reactively, or `await` it.\n\t */\n\tget closed(): GetPromise<Error | null> {\n\t\treturn this.#state.closed;\n\t}\n\n\t/** A read handle for this announcement stream. */\n\tconsume(): Consumer {\n\t\treturn makeConsumer(this.prefix, this.#state);\n\t}\n\n\t/** Writes an announcement to the queue. */\n\tappend(event: Event) {\n\t\tif (this.#state.closed.peek() !== undefined) throw new Error(\"announcements are closed\");\n\t\tthis.#state.queue.mutate((queue) => {\n\t\t\tqueue.push(event);\n\t\t});\n\t}\n\n\t/** Closes the writer. Idempotent. */\n\tclose(abort?: Error) {\n\t\tcloseState(this.#state, abort);\n\t}\n}\n\n// Constructs a Consumer from within this module without exposing a public constructor\n// that would leak the unexported AnnounceState. Assigned in the class's static block.\nlet makeConsumer: (prefix: Path.Valid, state: AnnounceState) => Consumer;\n\n/**\n * The read side of an announcement stream.\n *\n * Created internally: obtain one from {@link Producer.consume} or the connection's\n * `announced(prefix)`.\n *\n * @public\n */\nexport class Consumer {\n\t/** Path prefix this stream is scoped to. */\n\tprefix: Path.Valid;\n\n\t#state: AnnounceState;\n\n\tprivate constructor(prefix: Path.Valid, state: AnnounceState) {\n\t\tthis.prefix = prefix;\n\t\tthis.#state = state;\n\t}\n\n\t/** Settles once the stream closes; see {@link Producer.closed}. */\n\tget closed(): GetPromise<Error | null> {\n\t\treturn this.#state.closed;\n\t}\n\n\tstatic {\n\t\tmakeConsumer = (prefix, state) => new Consumer(prefix, state);\n\t}\n\n\t/** Returns the next announcement. */\n\tasync next(): Promise<Event | undefined> {\n\t\tfor (;;) {\n\t\t\tconst announce = this.#state.queue.peek().shift();\n\t\t\tif (announce) return announce;\n\n\t\t\tconst closed = this.#state.closed.peek();\n\t\t\tif (closed instanceof Error) throw closed;\n\t\t\tif (closed !== undefined) return undefined;\n\n\t\t\tawait Signal.race(this.#state.queue, this.#state.closed);\n\t\t}\n\t}\n\n\t/** Closes the reader. Idempotent. */\n\tclose(abort?: Error) {\n\t\tcloseState(this.#state, abort);\n\t}\n}\n\n// Connections already warned about missing broadcast discovery, so the fallback logs at most\n// once per connection instead of once per watched path.\nconst warnedNoDiscovery = new WeakSet<Established>();\n\n/**\n * What to watch, for {@link Broadcast}.\n *\n * @public\n */\nexport interface BroadcastProps {\n\t/**\n\t * The connection to watch on. Accepts a live {@link Established} session, or a reactive one\n\t * (a `Connection.Reload`'s `established`), which is how the handle survives reconnects.\n\t */\n\tconnection: GetterInit<Established | undefined>;\n\n\t/** The broadcast path to watch. */\n\tpath: Path.Valid;\n}\n\n/**\n * A reactive handle to a single broadcast: {@link Broadcast.active} holds a live\n * {@link broadcast.Consumer} while the path is announced and `undefined` while nobody\n * publishes it.\n *\n * Use this instead of {@link Established.consume} whenever the broadcast may not exist yet.\n * Subscribing to a path nobody publishes gets the stream reset, so a consumer that races the\n * publisher stays silent forever unless it retries; this waits for the announcement instead.\n *\n * A same-name republish re-consumes, so the handle attaches to the new instance rather than\n * clinging to the dead one. A relay failover that keeps the same publisher does *not*: the\n * subscription resumes across the new route, so `active` holds the same consumer throughout and\n * never goes offline. Only a change of publisher produces an offline/online transition.\n *\n * Built from a reconnecting `Connection.Reload`, the handle also spans reconnects: the broadcast\n * drops to `undefined` while disconnected and resolves again once the new connection announces it.\n *\n * Falls back to consuming blind (and warns once) on a relay without\n * {@link Established.discovery}, where there is no announcement to wait for. `active` then\n * means *assumed present* rather than known live: nothing reports whether the path exists, so\n * a subscribe to a missing broadcast is how a caller finds out. The handle stays usable either\n * way, and because it is scoped to the path rather than to one publisher, a subscribe made\n * after a publisher finally appears succeeds.\n *\n * If discovery fails on a live session (the announcement stream is reset, or the relay\n * refuses it) the handle goes offline and stays there: nothing reopens the stream on that\n * connection. Build it from a `Connection.Reload` if you need it to recover, since a new\n * connection starts a new stream.\n *\n * Close it to release the announcement stream and the current broadcast.\n *\n * @public\n */\nexport class Broadcast {\n\t/** The broadcast path this handle watches. */\n\treadonly path: Path.Valid;\n\n\t/**\n\t * The live broadcast, or `undefined` while it is offline.\n\t *\n\t * Borrowed, not yours to close: this handle owns the consumer and swaps it when the path is\n\t * republished. `active` keeps pointing at whatever you closed, so once you drop the last\n\t * reference the shared broadcast is gone and reads fail until the next announcement replaces\n\t * it. Take a {@link broadcast.Consumer.clone} for a lifetime of your own, or close this whole\n\t * handle to release everything.\n\t */\n\treadonly active: Getter<broadcast.Consumer | undefined>;\n\n\t#active = new Signal<broadcast.Consumer | undefined>(undefined);\n\t#signals = new Effect();\n\n\t/**\n\t * Watch a path on a connection.\n\t *\n\t * Prefer `announcedBroadcast(path)` on the connection itself. Reach for this when the\n\t * session you want to follow isn't either connection type, e.g. your own\n\t * `Getter<Established | undefined>`.\n\t */\n\tconstructor({ connection, path }: BroadcastProps) {\n\t\tthis.path = path;\n\t\tthis.active = this.#active;\n\n\t\tconst source = getter(connection);\n\t\tthis.#signals.run((effect) => {\n\t\t\tconst conn = effect.get(source);\n\t\t\tif (!conn) return;\n\n\t\t\t// Without discovery no announcement ever arrives, so waiting would hang forever.\n\t\t\tif (!conn.discovery) {\n\t\t\t\tif (!warnedNoDiscovery.has(conn)) {\n\t\t\t\t\twarnedNoDiscovery.add(conn);\n\t\t\t\t\tconsole.warn(\"relay does not support broadcast discovery; consuming without waiting.\");\n\t\t\t\t}\n\n\t\t\t\tconst blind = conn.consume(path);\n\t\t\t\teffect.cleanup(() => blind.close());\n\t\t\t\teffect.set(this.#active, blind, undefined);\n\n\t\t\t\t// The announcement-gated path below goes offline when the stream ends with the\n\t\t\t\t// session; without discovery there is no stream, so watch the session itself.\n\t\t\t\t// A consumed broadcast is a path-scoped handle, not a subscription, so its own\n\t\t\t\t// `closed` says nothing about whether the path exists or the session is alive.\n\t\t\t\t// Raced against the run's teardown so a closed handle isn't retained until the\n\t\t\t\t// session ends; the cleanup above has already cleared `active` in that case.\n\t\t\t\teffect.spawn(async () => {\n\t\t\t\t\tawait Promise.race([effect.cancel, conn.closed]);\n\t\t\t\t\tif (this.#active.peek() === blind) this.#active.set(undefined);\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst announced = conn.announced(path);\n\t\t\teffect.cleanup(() => announced.close());\n\n\t\t\tlet current: broadcast.Consumer | undefined;\n\t\t\tconst offline = () => {\n\t\t\t\tconst mine = current;\n\t\t\t\tcurrent?.close();\n\t\t\t\tcurrent = undefined;\n\t\t\t\t// Only clear what this run put there. A spawn task that resumes after its run was\n\t\t\t\t// torn down would otherwise wipe the consumer a newer run already installed.\n\t\t\t\tif (this.#active.peek() === mine) this.#active.set(undefined);\n\t\t\t};\n\t\t\teffect.cleanup(offline);\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 event = await Promise.race([effect.cancel, announced.next()]);\n\t\t\t\t\t\tif (!event) break;\n\n\t\t\t\t\t\t// Scoped to `path`, so the exact broadcast arrives with an empty suffix; ignore children.\n\t\t\t\t\t\tif (event.path !== Path.empty()) continue;\n\n\t\t\t\t\t\tif (event.active) {\n\t\t\t\t\t\t\t// A live subscription survives a redundant (re-)announce; only replace a dead one.\n\t\t\t\t\t\t\tif (current && current.closed.peek() === undefined) continue;\n\t\t\t\t\t\t\tcurrent?.close();\n\t\t\t\t\t\t\tcurrent = conn.consume(path);\n\t\t\t\t\t\t\tthis.#active.set(current);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\toffline();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} catch (err) {\n\t\t\t\t\t// Discovery failed: the session died under the stream, or the relay refused\n\t\t\t\t\t// to answer. Nothing reopens it on this connection, so say so out loud.\n\t\t\t\t\tconsole.warn(\"broadcast discovery failed\", err);\n\t\t\t\t}\n\n\t\t\t\t// The stream ended, or this run was torn down (its cleanup already ran). Either\n\t\t\t\t// way there is nothing left announcing the path, so don't hold a dead broadcast.\n\t\t\t\toffline();\n\t\t\t});\n\t\t});\n\t}\n\n\t/** Closes the handle and the broadcast it currently holds. Idempotent. */\n\tclose() {\n\t\tthis.#signals.close();\n\t}\n}\n"]}
1
+ {"version":3,"file":"announced.js","sourceRoot":"","sources":["../src/announced.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAmB,IAAI,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAmC7D,4EAA4E;AAC5E,MAAM,UAAU,QAAQ,CAAC,IAAU;IAClC,OAAO,IAAI,KAAK,WAAW,CAAC;AAC7B,CAAC;AAED,6EAA6E;AAC7E,MAAM,aAAa;IAClB,KAAK,GAAG,IAAI,MAAM,CAAW,EAAE,CAAC,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B,KAAoB;QACvC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACrB,CAAC;IAED,mEAAmE;IACnE,IAAI,MAAM;QACT,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;IAC3B,CAAC;IAED;QACC,YAAY,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC/C,CAAC;IAED,iEAAiE;IACjE,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC;QAC5B,SAAS,CAAC;YACT,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;YACjC,IAAI,CAAC,MAAM;gBAAE,OAAO;YACpB,MAAM,MAAM,CAAC;QACd,CAAC;IACF,CAAC;IAED,qCAAqC;IACrC,KAAK,CAAC,IAAI;QACT,SAAS,CAAC;YACT,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC;YAClD,IAAI,QAAQ;gBAAE,OAAO,QAAQ,CAAC;YAE9B,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;YACzC,IAAI,MAAM,YAAY,KAAK;gBAAE,MAAM,MAAM,CAAC;YAC1C,IAAI,MAAM,KAAK,SAAS;gBAAE,OAAO,SAAS,CAAC;YAE3C,MAAM,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC1D,CAAC;IACF,CAAC;IAED,qCAAqC;IACrC,KAAK,CAAC,KAAa;QAClB,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAChC,CAAC;CACD","sourcesContent":["/**\n * Broadcast announcement streams: which broadcast paths are available under a scope.\n *\n * @module\n */\nimport { type GetPromise, Once, Signal } from \"@moq/signals\";\nimport type { Route } from \"./hop.js\";\nimport type * as Path from \"./path.js\";\n\n/**\n * What an {@link Update} reports about its prefix.\n *\n * @public\n */\nexport type Kind = \"announced\" | \"updated\" | \"retracted\";\n\n/**\n * A route announcement, update, or retraction.\n *\n * An announcement is always a prefix, never a broadcast: a route claims that\n * {@link prefix} and every path beneath it can be served. By convention a publisher\n * announces each broadcast's exact path, so enumerating routes enumerates broadcasts;\n * resolve one with the origin's `request(path)`. Narrow with a {@link Path.Pattern}\n * locally to follow a subset.\n *\n * @public\n */\nexport interface Update {\n\t/**\n\t * The prefix the route covers, relative to the origin (for a session, its URL path).\n\t */\n\tprefix: Path.Valid;\n\t/** What the filter's wildcards stood for, when this prefix pins all of them. */\n\tcaptures: Path.Pattern[] | undefined;\n\t/** Whether the prefix was announced, re-priced, or retracted. */\n\tkind: Kind;\n\t/** Hops and cost of the route; on a retraction, its last advertised values. */\n\troute: Route;\n}\n\n/** Whether a route covers the path after an update of this {@link Kind}. */\nexport function isActive(kind: Kind): boolean {\n\treturn kind !== \"retracted\";\n}\n\n/** Reactive backing state shared by announcement producers and consumers. */\nclass AnnounceState {\n\tqueue = new Signal<Update[]>([]);\n\tclosed = new Once<Error | null>();\n}\n\n// Once.set throws on a second settle, and both ends of a stream can close independently.\nfunction closeState(state: AnnounceState, abort?: Error) {\n\tif (state.closed.peek() !== undefined) return;\n\tstate.closed.set(abort ?? null);\n\tstate.queue.mutate((queue) => {\n\t\tqueue.length = 0;\n\t});\n}\n\n/**\n * The write side of an announcement stream.\n *\n * @public\n */\nexport class Producer {\n\t#state = new AnnounceState();\n\n\t/**\n\t * Settles once the stream closes: `null` on a clean close, or the abort {@link Error}.\n\t * Peek it synchronously (`undefined` while open), observe it reactively, or `await` it.\n\t */\n\tget closed(): GetPromise<Error | null> {\n\t\treturn this.#state.closed;\n\t}\n\n\t/** A read handle for this announcement stream. */\n\tconsume(): Consumer {\n\t\treturn makeConsumer(this.#state);\n\t}\n\n\t/** Writes an announcement to the queue. */\n\tappend(update: Update) {\n\t\tif (this.#state.closed.peek() !== undefined) throw new Error(\"announcements are closed\");\n\t\tthis.#state.queue.mutate((queue) => {\n\t\t\tqueue.push(update);\n\t\t});\n\t}\n\n\t/** Closes the writer. Idempotent. */\n\tclose(abort?: Error) {\n\t\tcloseState(this.#state, abort);\n\t}\n}\n\n// Constructs a Consumer from within this module without exposing a public constructor\n// that would leak the unexported AnnounceState. Assigned in the class's static block.\nlet makeConsumer: (state: AnnounceState) => Consumer;\n\n/**\n * The read side of an announcement stream.\n *\n * Created internally: obtain one from {@link Producer.consume} or the connection's\n * `announced(scope)`.\n *\n * @public\n */\nexport class Consumer {\n\t#state: AnnounceState;\n\n\tprivate constructor(state: AnnounceState) {\n\t\tthis.#state = state;\n\t}\n\n\t/** Settles once the stream closes; see {@link Producer.closed}. */\n\tget closed(): GetPromise<Error | null> {\n\t\treturn this.#state.closed;\n\t}\n\n\tstatic {\n\t\tmakeConsumer = (state) => new Consumer(state);\n\t}\n\n\t/** The announcements as they arrive, until the stream closes. */\n\tasync *[Symbol.asyncIterator](): AsyncGenerator<Update, void, undefined> {\n\t\tfor (;;) {\n\t\t\tconst update = await this.next();\n\t\t\tif (!update) return;\n\t\t\tyield update;\n\t\t}\n\t}\n\n\t/** Returns the next announcement. */\n\tasync next(): Promise<Update | undefined> {\n\t\tfor (;;) {\n\t\t\tconst announce = this.#state.queue.peek().shift();\n\t\t\tif (announce) return announce;\n\n\t\t\tconst closed = this.#state.closed.peek();\n\t\t\tif (closed instanceof Error) throw closed;\n\t\t\tif (closed !== undefined) return undefined;\n\n\t\t\tawait Signal.race(this.#state.queue, this.#state.closed);\n\t\t}\n\t}\n\n\t/** Closes the reader. Idempotent. */\n\tclose(abort?: Error) {\n\t\tcloseState(this.#state, abort);\n\t}\n}\n"]}
package/bandwidth.d.ts ADDED
@@ -0,0 +1,163 @@
1
+ /**
2
+ * Rate estimation split among the tracks sharing one connection.
3
+ *
4
+ * One estimate covers a whole connection, so senders sharing it divide it with
5
+ * an {@link Allocator} rather than each targeting the whole thing. How a sender
6
+ * then follows its share is policy and lives with the sender.
7
+ *
8
+ * @module
9
+ */
10
+ import { type GetPromise, type Getter } from "@moq/signals";
11
+ /**
12
+ * One demanded track's claim, snapshotted for {@link allocate}.
13
+ *
14
+ * `id` is the allocator's, not the track's sequence: two reservations of the
15
+ * same track are still two claims.
16
+ */
17
+ export interface Want {
18
+ /** Allocator-assigned identity of this claim. */
19
+ id: number;
20
+ /** Publisher priority; higher is served first. */
21
+ priority: number;
22
+ /** Ceiling in bits per second, not a measurement of current output. */
23
+ max: number;
24
+ }
25
+ /**
26
+ * Divide `estimate` among `wants`, returning the slice for `id`.
27
+ *
28
+ * Strict priority: a tier is filled to its reservations before the next one
29
+ * sees a bit. Within a tier the split is max-min fair, so a share asking for
30
+ * less than an even split takes all of it and leaves the rest to the others.
31
+ *
32
+ * Surplus above the total reserved is left unclaimed rather than spread around.
33
+ * A reservation is what a sender can use, so handing it more is not a reason to
34
+ * send more than it was configured for.
35
+ *
36
+ * `undefined` when `id` isn't among the wants, which is how an idle or closed
37
+ * track reports "hold your rate" instead of a grant of zero.
38
+ *
39
+ * Rates are bits per second.
40
+ */
41
+ export declare function allocate(estimate: number, wants: readonly Want[], id: number): number | undefined;
42
+ /** What {@link Allocator.reserve} reads off a track. */
43
+ export interface Demand {
44
+ /** Whether any subscriber is currently attached. */
45
+ readonly used: Getter<boolean>;
46
+ /** Settles once the track closes. */
47
+ readonly closed: GetPromise<Error | null>;
48
+ /** Publisher priority; higher is served first. */
49
+ readonly priority: number;
50
+ }
51
+ /**
52
+ * A non-owning handle on an allocator: reserve a slice, without its lifecycle.
53
+ *
54
+ * What a shared connection lends out. {@link Allocator} implements it, so code
55
+ * that is handed an allocator rather than owning one should accept this type:
56
+ * closing the registry stays the owner's alone, and a borrower cannot express it.
57
+ *
58
+ * @public
59
+ */
60
+ export interface Handle {
61
+ /** Reserve up to `max` for `track`; see {@link Allocator.reserve}. */
62
+ reserve(track: Demand, max: number): Reservation;
63
+ }
64
+ /**
65
+ * Divides one connection's bandwidth estimate among the tracks sharing it.
66
+ *
67
+ * Every sender on a connection reads the same estimate, so N senders each
68
+ * targeting all of it oversubscribe the uplink N times over. Register a track
69
+ * here and it gets a {@link Reservation} reporting only its own slice, so the
70
+ * slices sum to the estimate instead of each matching it.
71
+ *
72
+ * Advisory, not enforced. A track that ignores its slice, or can't follow it at
73
+ * all (PCM audio has a fixed bitrate), still sends what it sends; the transport
74
+ * sheds the excess by dropping groups.
75
+ *
76
+ * Hand the same instance to every sender on the connection.
77
+ */
78
+ export declare class Allocator implements Handle {
79
+ #private;
80
+ /**
81
+ * Divide `estimate`, normally a connection's sampled send rate.
82
+ *
83
+ * Omit it (or call {@link unlimited}) for nothing to divide: every reservation
84
+ * reports `undefined`, which already means "no opinion, hold your rate".
85
+ */
86
+ constructor(estimate?: Getter<number | undefined>);
87
+ /**
88
+ * An allocator with nothing to divide, so every reservation reports `undefined`.
89
+ *
90
+ * `undefined` already means "no opinion, hold your rate" to a sender, so this is
91
+ * what a transport with no congestion estimate, a local file, or a test harness
92
+ * wants.
93
+ */
94
+ static unlimited(): Allocator;
95
+ /**
96
+ * Reserve up to `max` for `track`, returning the reservation.
97
+ *
98
+ * `max` is a ceiling, not a measurement: reserve the most the track can ever
99
+ * send, not what it happens to be sending. A VBR encoder sitting on a black
100
+ * screen at 1 Mbps can jump to 6 Mbps between one frame and the next, and a
101
+ * reservation that had followed it down would have already handed that room
102
+ * to somebody else.
103
+ *
104
+ * Priority comes from the track (higher served first). A tier is filled to
105
+ * its reservations before the next one sees a bit; within a tier the split is
106
+ * max-min fair.
107
+ *
108
+ * The reservation lasts until {@link Reservation.close}: hold it for as long
109
+ * as the sender is publishing, change the ceiling with
110
+ * {@link Reservation.update}, and close it to hand the room back.
111
+ *
112
+ * {@link Reservation.peek} / {@link Reservation.grant} report `undefined`
113
+ * while nothing is subscribed to the track or the connection has no estimate.
114
+ * That tells a sender to hold its current rate rather than encode at zero.
115
+ */
116
+ reserve(track: Demand, max: number): Reservation;
117
+ /**
118
+ * Stop dividing. Existing reservations report `undefined` and further
119
+ * {@link reserve} calls still return a handle that never claims.
120
+ */
121
+ close(): void;
122
+ }
123
+ /**
124
+ * One track's standing claim on an {@link Allocator}, held for as long as the
125
+ * sender that took it is publishing.
126
+ *
127
+ * Close it to release the claim; a forgotten reservation keeps claiming until
128
+ * {@link close} (or {@link Symbol.dispose}) runs, and its siblings never get
129
+ * the room.
130
+ */
131
+ export declare class Reservation implements Disposable {
132
+ #private;
133
+ private constructor();
134
+ /**
135
+ * This reservation's slice right now.
136
+ *
137
+ * Stateless, unlike {@link grant}, which is a signal of what was last
138
+ * published and so can lag a synchronous {@link update} by a microtask if
139
+ * something else writes the registry first. Call this after {@link update}.
140
+ */
141
+ peek(): number | undefined;
142
+ /**
143
+ * This reservation's current slice of the estimate.
144
+ *
145
+ * `undefined` while nothing is subscribed, the connection has no estimate, or
146
+ * this reservation has been closed: hold the current rate rather than encode
147
+ * at zero.
148
+ */
149
+ get grant(): Getter<number | undefined>;
150
+ /**
151
+ * Change the ceiling, keeping the same claim.
152
+ *
153
+ * For a sender whose ceiling genuinely moved: an encoder reopening at a
154
+ * resolution it negotiated with the device, not an encoder observing its own
155
+ * output.
156
+ */
157
+ update(max: number): void;
158
+ /** Release the claim so siblings take the room. Idempotent. */
159
+ close(): void;
160
+ /** Calls {@link close}, so `using` releases the claim. */
161
+ [Symbol.dispose](): void;
162
+ }
163
+ //# sourceMappingURL=bandwidth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bandwidth.d.ts","sourceRoot":"","sources":["../src/bandwidth.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAU,KAAK,UAAU,EAAE,KAAK,MAAM,EAAU,MAAM,cAAc,CAAC;AAE5E;;;;;GAKG;AACH,MAAM,WAAW,IAAI;IACpB,iDAAiD;IACjD,EAAE,EAAE,MAAM,CAAC;IACX,kDAAkD;IAClD,QAA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