@norskvideo/moq-net 0.1.2 → 0.1.4

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 (310) hide show
  1. package/README.md +1 -0
  2. package/announced.d.ts +111 -21
  3. package/announced.d.ts.map +1 -1
  4. package/announced.js +213 -40
  5. package/announced.js.map +1 -1
  6. package/broadcast.d.ts +80 -25
  7. package/broadcast.d.ts.map +1 -1
  8. package/broadcast.js +270 -49
  9. package/broadcast.js.map +1 -1
  10. package/connection/accept.d.ts +6 -0
  11. package/connection/accept.d.ts.map +1 -1
  12. package/connection/accept.js +42 -13
  13. package/connection/accept.js.map +1 -1
  14. package/connection/browser.d.ts +5 -0
  15. package/connection/browser.d.ts.map +1 -0
  16. package/connection/browser.js +31 -0
  17. package/connection/browser.js.map +1 -0
  18. package/connection/connect.d.ts +43 -1
  19. package/connection/connect.d.ts.map +1 -1
  20. package/connection/connect.js +118 -123
  21. package/connection/connect.js.map +1 -1
  22. package/connection/established.d.ts +43 -16
  23. package/connection/established.d.ts.map +1 -1
  24. package/connection/established.js.map +1 -1
  25. package/connection/handshake.d.ts +12 -1
  26. package/connection/handshake.d.ts.map +1 -1
  27. package/connection/handshake.js +30 -14
  28. package/connection/handshake.js.map +1 -1
  29. package/connection/index.d.ts +8 -0
  30. package/connection/index.d.ts.map +1 -1
  31. package/connection/index.js +6 -0
  32. package/connection/index.js.map +1 -1
  33. package/connection/reload.d.ts +66 -9
  34. package/connection/reload.d.ts.map +1 -1
  35. package/connection/reload.js +192 -66
  36. package/connection/reload.js.map +1 -1
  37. package/connection/stats.d.ts +92 -0
  38. package/connection/stats.d.ts.map +1 -0
  39. package/connection/stats.js +35 -0
  40. package/connection/stats.js.map +1 -0
  41. package/connection/transport.d.ts +10 -0
  42. package/connection/transport.d.ts.map +1 -0
  43. package/connection/transport.js +12 -0
  44. package/connection/transport.js.map +1 -0
  45. package/consume.d.ts +44 -0
  46. package/consume.d.ts.map +1 -0
  47. package/consume.js +60 -0
  48. package/consume.js.map +1 -0
  49. package/datagram.d.ts +23 -0
  50. package/datagram.d.ts.map +1 -0
  51. package/datagram.js +3 -0
  52. package/datagram.js.map +1 -0
  53. package/error.d.ts +76 -0
  54. package/error.d.ts.map +1 -0
  55. package/error.js +107 -0
  56. package/error.js.map +1 -0
  57. package/group.d.ts +143 -38
  58. package/group.d.ts.map +1 -1
  59. package/group.js +270 -68
  60. package/group.js.map +1 -1
  61. package/ietf/adapter.d.ts +2 -2
  62. package/ietf/adapter.d.ts.map +1 -1
  63. package/ietf/adapter.js +20 -10
  64. package/ietf/adapter.js.map +1 -1
  65. package/ietf/aliases.d.ts +73 -5
  66. package/ietf/aliases.d.ts.map +1 -1
  67. package/ietf/aliases.js +121 -14
  68. package/ietf/aliases.js.map +1 -1
  69. package/ietf/cluster.d.ts +141 -0
  70. package/ietf/cluster.d.ts.map +1 -0
  71. package/ietf/cluster.js +204 -0
  72. package/ietf/cluster.js.map +1 -0
  73. package/ietf/connection.d.ts +39 -6
  74. package/ietf/connection.d.ts.map +1 -1
  75. package/ietf/connection.js +73 -12
  76. package/ietf/connection.js.map +1 -1
  77. package/ietf/fetch.d.ts +17 -0
  78. package/ietf/fetch.d.ts.map +1 -1
  79. package/ietf/fetch.js +21 -0
  80. package/ietf/fetch.js.map +1 -1
  81. package/ietf/filter.d.ts +87 -0
  82. package/ietf/filter.d.ts.map +1 -0
  83. package/ietf/filter.js +292 -0
  84. package/ietf/filter.js.map +1 -0
  85. package/ietf/index.d.ts +2 -0
  86. package/ietf/index.d.ts.map +1 -1
  87. package/ietf/index.js +3 -0
  88. package/ietf/index.js.map +1 -1
  89. package/ietf/namespace.d.ts +6 -0
  90. package/ietf/namespace.d.ts.map +1 -1
  91. package/ietf/namespace.js +27 -2
  92. package/ietf/namespace.js.map +1 -1
  93. package/ietf/object.d.ts +54 -6
  94. package/ietf/object.d.ts.map +1 -1
  95. package/ietf/object.js +178 -25
  96. package/ietf/object.js.map +1 -1
  97. package/ietf/parameters.d.ts +35 -10
  98. package/ietf/parameters.d.ts.map +1 -1
  99. package/ietf/parameters.js +236 -45
  100. package/ietf/parameters.js.map +1 -1
  101. package/ietf/priority.d.ts +5 -0
  102. package/ietf/priority.d.ts.map +1 -0
  103. package/ietf/priority.js +10 -0
  104. package/ietf/priority.js.map +1 -0
  105. package/ietf/properties.d.ts +13 -2
  106. package/ietf/properties.d.ts.map +1 -1
  107. package/ietf/properties.js +65 -8
  108. package/ietf/properties.js.map +1 -1
  109. package/ietf/publish.d.ts.map +1 -1
  110. package/ietf/publish.js +13 -3
  111. package/ietf/publish.js.map +1 -1
  112. package/ietf/publish_namespace.d.ts +16 -2
  113. package/ietf/publish_namespace.d.ts.map +1 -1
  114. package/ietf/publish_namespace.js +25 -6
  115. package/ietf/publish_namespace.js.map +1 -1
  116. package/ietf/publisher.d.ts +40 -7
  117. package/ietf/publisher.d.ts.map +1 -1
  118. package/ietf/publisher.js +751 -134
  119. package/ietf/publisher.js.map +1 -1
  120. package/ietf/request.js +1 -1
  121. package/ietf/request.js.map +1 -1
  122. package/ietf/solicit.d.ts +41 -0
  123. package/ietf/solicit.d.ts.map +1 -0
  124. package/ietf/solicit.js +47 -0
  125. package/ietf/solicit.js.map +1 -0
  126. package/ietf/subscribe.d.ts +41 -2
  127. package/ietf/subscribe.d.ts.map +1 -1
  128. package/ietf/subscribe.js +103 -22
  129. package/ietf/subscribe.js.map +1 -1
  130. package/ietf/subscribe_namespace.d.ts +21 -7
  131. package/ietf/subscribe_namespace.d.ts.map +1 -1
  132. package/ietf/subscribe_namespace.js +31 -14
  133. package/ietf/subscribe_namespace.js.map +1 -1
  134. package/ietf/subscriber.d.ts +20 -7
  135. package/ietf/subscriber.d.ts.map +1 -1
  136. package/ietf/subscriber.js +512 -142
  137. package/ietf/subscriber.js.map +1 -1
  138. package/ietf/version.d.ts +7 -1
  139. package/ietf/version.d.ts.map +1 -1
  140. package/ietf/version.js +7 -0
  141. package/ietf/version.js.map +1 -1
  142. package/index.d.ts +10 -5
  143. package/index.d.ts.map +1 -1
  144. package/index.js +10 -5
  145. package/index.js.map +1 -1
  146. package/internal.d.ts +29 -0
  147. package/internal.d.ts.map +1 -0
  148. package/internal.js +8 -0
  149. package/internal.js.map +1 -0
  150. package/lite/announce.d.ts +62 -15
  151. package/lite/announce.d.ts.map +1 -1
  152. package/lite/announce.js +230 -94
  153. package/lite/announce.js.map +1 -1
  154. package/lite/connection.d.ts +69 -20
  155. package/lite/connection.d.ts.map +1 -1
  156. package/lite/connection.js +128 -81
  157. package/lite/connection.js.map +1 -1
  158. package/lite/datagram.d.ts +23 -0
  159. package/lite/datagram.d.ts.map +1 -0
  160. package/lite/datagram.js +57 -0
  161. package/lite/datagram.js.map +1 -0
  162. package/lite/datagram_stream.d.ts +8 -0
  163. package/lite/datagram_stream.d.ts.map +1 -0
  164. package/lite/datagram_stream.js +44 -0
  165. package/lite/datagram_stream.js.map +1 -0
  166. package/lite/fetch.d.ts.map +1 -1
  167. package/lite/fetch.js +2 -2
  168. package/lite/fetch.js.map +1 -1
  169. package/lite/index.d.ts +3 -0
  170. package/lite/index.d.ts.map +1 -1
  171. package/lite/index.js +3 -0
  172. package/lite/index.js.map +1 -1
  173. package/lite/priority.d.ts +67 -0
  174. package/lite/priority.d.ts.map +1 -0
  175. package/lite/priority.js +114 -0
  176. package/lite/priority.js.map +1 -0
  177. package/lite/probe.d.ts +18 -2
  178. package/lite/probe.d.ts.map +1 -1
  179. package/lite/probe.js +24 -22
  180. package/lite/probe.js.map +1 -1
  181. package/lite/publisher.d.ts +14 -7
  182. package/lite/publisher.d.ts.map +1 -1
  183. package/lite/publisher.js +406 -84
  184. package/lite/publisher.js.map +1 -1
  185. package/lite/setup.d.ts +83 -6
  186. package/lite/setup.d.ts.map +1 -1
  187. package/lite/setup.js +203 -31
  188. package/lite/setup.js.map +1 -1
  189. package/lite/stream.d.ts +12 -3
  190. package/lite/stream.d.ts.map +1 -1
  191. package/lite/stream.js +7 -4
  192. package/lite/stream.js.map +1 -1
  193. package/lite/subscribe.d.ts +37 -23
  194. package/lite/subscribe.d.ts.map +1 -1
  195. package/lite/subscribe.js +70 -55
  196. package/lite/subscribe.js.map +1 -1
  197. package/lite/subscriber.d.ts +29 -23
  198. package/lite/subscriber.d.ts.map +1 -1
  199. package/lite/subscriber.js +689 -112
  200. package/lite/subscriber.js.map +1 -1
  201. package/lite/track.d.ts +25 -13
  202. package/lite/track.d.ts.map +1 -1
  203. package/lite/track.js +60 -35
  204. package/lite/track.js.map +1 -1
  205. package/lite/version.d.ts +39 -4
  206. package/lite/version.d.ts.map +1 -1
  207. package/lite/version.js +139 -17
  208. package/lite/version.js.map +1 -1
  209. package/mock.d.ts +53 -3
  210. package/mock.d.ts.map +1 -1
  211. package/mock.js +110 -21
  212. package/mock.js.map +1 -1
  213. package/{lite/origin.d.ts → origin.d.ts} +25 -1
  214. package/origin.d.ts.map +1 -0
  215. package/{lite/origin.js → origin.js} +25 -1
  216. package/origin.js.map +1 -0
  217. package/package.json +6 -4
  218. package/path.d.ts +67 -0
  219. package/path.d.ts.map +1 -1
  220. package/path.js +128 -0
  221. package/path.js.map +1 -1
  222. package/stream.d.ts +94 -4
  223. package/stream.d.ts.map +1 -1
  224. package/stream.js +128 -17
  225. package/stream.js.map +1 -1
  226. package/time.d.ts +109 -86
  227. package/time.d.ts.map +1 -1
  228. package/time.js +80 -30
  229. package/time.js.map +1 -1
  230. package/track.d.ts +298 -47
  231. package/track.d.ts.map +1 -1
  232. package/track.js +721 -109
  233. package/track.js.map +1 -1
  234. package/util/timeout.d.ts +5 -0
  235. package/util/timeout.d.ts.map +1 -0
  236. package/util/timeout.js +18 -0
  237. package/util/timeout.js.map +1 -0
  238. package/util/utf8.d.ts +3 -0
  239. package/util/utf8.d.ts.map +1 -0
  240. package/util/utf8.js +7 -0
  241. package/util/utf8.js.map +1 -0
  242. package/varint.d.ts +14 -3
  243. package/varint.d.ts.map +1 -1
  244. package/varint.js +23 -12
  245. package/varint.js.map +1 -1
  246. package/zod.d.ts +5 -5
  247. package/zod.d.ts.map +1 -1
  248. package/zod.js.map +1 -1
  249. package/bandwidth.d.ts +0 -11
  250. package/bandwidth.d.ts.map +0 -1
  251. package/bandwidth.js +0 -7
  252. package/bandwidth.js.map +0 -1
  253. package/connection/cert.test.d.ts +0 -2
  254. package/connection/cert.test.d.ts.map +0 -1
  255. package/connection/cert.test.js +0 -26
  256. package/connection/cert.test.js.map +0 -1
  257. package/connection/reload.test.d.ts +0 -2
  258. package/connection/reload.test.d.ts.map +0 -1
  259. package/connection/reload.test.js +0 -39
  260. package/connection/reload.test.js.map +0 -1
  261. package/group.test.d.ts +0 -2
  262. package/group.test.d.ts.map +0 -1
  263. package/group.test.js +0 -66
  264. package/group.test.js.map +0 -1
  265. package/ietf/aliases.test.d.ts +0 -2
  266. package/ietf/aliases.test.d.ts.map +0 -1
  267. package/ietf/aliases.test.js +0 -30
  268. package/ietf/aliases.test.js.map +0 -1
  269. package/ietf/ietf.test.d.ts +0 -2
  270. package/ietf/ietf.test.d.ts.map +0 -1
  271. package/ietf/ietf.test.js +0 -873
  272. package/ietf/ietf.test.js.map +0 -1
  273. package/integration.test.d.ts +0 -2
  274. package/integration.test.d.ts.map +0 -1
  275. package/integration.test.js +0 -90
  276. package/integration.test.js.map +0 -1
  277. package/lite/origin.d.ts.map +0 -1
  278. package/lite/origin.js.map +0 -1
  279. package/lite/subscriber.test.d.ts +0 -2
  280. package/lite/subscriber.test.d.ts.map +0 -1
  281. package/lite/subscriber.test.js +0 -30
  282. package/lite/subscriber.test.js.map +0 -1
  283. package/lite/track.test.d.ts +0 -2
  284. package/lite/track.test.d.ts.map +0 -1
  285. package/lite/track.test.js +0 -53
  286. package/lite/track.test.js.map +0 -1
  287. package/path.test.d.ts +0 -2
  288. package/path.test.d.ts.map +0 -1
  289. package/path.test.js +0 -169
  290. package/path.test.js.map +0 -1
  291. package/stream.test.d.ts +0 -2
  292. package/stream.test.d.ts.map +0 -1
  293. package/stream.test.js +0 -210
  294. package/stream.test.js.map +0 -1
  295. package/track.test.d.ts +0 -2
  296. package/track.test.d.ts.map +0 -1
  297. package/track.test.js +0 -56
  298. package/track.test.js.map +0 -1
  299. package/util/error.d.ts +0 -3
  300. package/util/error.d.ts.map +0 -1
  301. package/util/error.js +0 -9
  302. package/util/error.js.map +0 -1
  303. package/util/index.d.ts +0 -2
  304. package/util/index.d.ts.map +0 -1
  305. package/util/index.js +0 -3
  306. package/util/index.js.map +0 -1
  307. package/varint.test.d.ts +0 -2
  308. package/varint.test.d.ts.map +0 -1
  309. package/varint.test.js +0 -106
  310. package/varint.test.js.map +0 -1
package/stream.js CHANGED
@@ -1,8 +1,40 @@
1
1
  /* @ts-self-types="./stream.d.ts" */
2
+ import { fromTransport } from "./error.js";
2
3
  import { Version } from "./ietf/version.js";
4
+ import { TimeoutError, withTimeout } from "./util/timeout.js";
5
+ import { decodeUtf8 } from "./util/utf8.js";
3
6
  import * as Varint from "./varint.js";
4
7
  const MAX_U31 = 2 ** 31 - 1;
5
8
  const MAX_READ_SIZE = 1024 * 1024 * 64; // don't allocate more than 64MB for a message
9
+ /**
10
+ * Options handed to the transport for one outgoing stream.
11
+ *
12
+ * `waitUntilAvailable` waits for the peer's concurrent stream limit to free a slot instead
13
+ * of rejecting with a `QuotaExceededError`, which is what we want for the streams a session
14
+ * opens occasionally. `@types/web` doesn't declare it yet, hence the intersection.
15
+ */
16
+ export function sendOptions(options) {
17
+ return { sendOrder: options?.sendOrder, waitUntilAvailable: options?.waitUntilAvailable ?? true };
18
+ }
19
+ // How long any open may wait for the peer to free a stream slot. Every open needs this,
20
+ // whether or not it asked to wait: an implementation may park an over-limit open rather
21
+ // than rejecting it, and a peer can advertise a stream limit of zero and never raise it.
22
+ // Matches the subscribe budget.
23
+ const OPEN_TIMEOUT_MS = 10_000;
24
+ /**
25
+ * Bound an open that would otherwise park until the peer grants stream credit, restoring
26
+ * the pre-waitUntilAvailable failure after a grace period. A stream arriving after the
27
+ * deadline is discarded, since nobody is waiting for it any more.
28
+ */
29
+ async function openWithin(opening, timeout, discard) {
30
+ try {
31
+ return await withTimeout(opening, timeout, `stream open timed out after ${timeout}ms waiting for a slot`);
32
+ }
33
+ catch (err) {
34
+ opening.then(discard).catch(() => void 0);
35
+ throw err;
36
+ }
37
+ }
6
38
  function isLeadingOnes(version) {
7
39
  return (version !== undefined &&
8
40
  version !== Version.DRAFT_14 &&
@@ -13,8 +45,12 @@ export class Stream {
13
45
  reader;
14
46
  writer;
15
47
  constructor(props) {
16
- this.writer = props.writer ?? new Writer(props.writable, props.version);
17
- this.reader = props.reader ?? new Reader(props.readable, undefined, props.version);
48
+ const writer = props.writer ?? (props.writable && new Writer(props.writable, props.version));
49
+ const reader = props.reader ?? (props.readable && new Reader(props.readable, undefined, props.version));
50
+ if (!writer || !reader)
51
+ throw new Error("stream needs both halves");
52
+ this.writer = writer;
53
+ this.reader = reader;
18
54
  }
19
55
  static async accept(quic, version) {
20
56
  for (;;) {
@@ -27,9 +63,18 @@ export class Stream {
27
63
  return new Stream({ readable, writable, version });
28
64
  }
29
65
  }
30
- static async open(quic, version, priority) {
31
- const { readable, writable } = await quic.createBidirectionalStream({ sendOrder: priority });
32
- return new Stream({ readable, writable, version });
66
+ /**
67
+ * Open an outgoing bidirectional stream.
68
+ * @param quic - The session to open it on
69
+ * @param options - The version its varints encode with, and the send order ranking it
70
+ * against the session's other streams
71
+ */
72
+ static async open(quic, options) {
73
+ const { readable, writable } = await openWithin(quic.createBidirectionalStream(sendOptions(options)), options?.timeout ?? OPEN_TIMEOUT_MS, (stream) => {
74
+ void stream.writable.abort().catch(() => void 0);
75
+ void stream.readable.cancel().catch(() => void 0);
76
+ });
77
+ return new Stream({ readable, writable, version: options?.version });
33
78
  }
34
79
  close() {
35
80
  this.writer.close();
@@ -46,6 +91,7 @@ export class Reader {
46
91
  #buffer;
47
92
  #stream; // if undefined, the buffer is consumed then EOF
48
93
  #reader;
94
+ #closed;
49
95
  version;
50
96
  constructor(stream, buffer, version) {
51
97
  this.#buffer = buffer ?? new Uint8Array();
@@ -58,7 +104,11 @@ export class Reader {
58
104
  if (!this.#reader) {
59
105
  return false;
60
106
  }
61
- const result = await this.#reader.read();
107
+ // Every read of this stream funnels through here, so decoding the peer's reset code
108
+ // once is enough to keep the raw transport error out of every caller (and every app).
109
+ const result = await this.#reader.read().catch((err) => {
110
+ throw fromTransport(err);
111
+ });
62
112
  if (result.done) {
63
113
  return false;
64
114
  }
@@ -109,7 +159,7 @@ export class Reader {
109
159
  async string() {
110
160
  const length = await this.u53();
111
161
  const buffer = await this.read(length);
112
- return new TextDecoder().decode(buffer);
162
+ return decodeUtf8(buffer);
113
163
  }
114
164
  async bool() {
115
165
  const v = await this.u8();
@@ -131,13 +181,10 @@ export class Reader {
131
181
  return result;
132
182
  }
133
183
  // Returns a Number using 53-bits, the max Javascript can use for integer math.
134
- // Values > 2^53-1 are coerced to a Number (precision is lost) and logged. We
135
- // downgrade overflow from throw to warn so a stray u64 field on the wire (e.g.
136
- // a peer's session-level Origin id) doesn't tear down the whole stream/session.
137
184
  async u53() {
138
185
  const v = await this.u62();
139
186
  if (v > Varint.MAX_U53) {
140
- console.warn(`value larger than 53-bits; use u62 instead (precision lost): ${v.toString()}`);
187
+ throw new Error(`value larger than 53-bits: ${v.toString()}`);
141
188
  }
142
189
  return Number(v);
143
190
  }
@@ -210,14 +257,20 @@ export class Reader {
210
257
  stop(reason) {
211
258
  this.#reader?.cancel(reason).catch(() => void 0);
212
259
  }
260
+ // Decoded like #fill: a caller racing this against a read must not get a different error
261
+ // shape depending on which one won. Derived once, so racing it per frame doesn't allocate.
213
262
  get closed() {
214
- return this.#reader?.closed ?? Promise.resolve();
263
+ this.#closed ??= (this.#reader?.closed ?? Promise.resolve()).catch((err) => {
264
+ throw fromTransport(err);
265
+ });
266
+ return this.#closed;
215
267
  }
216
268
  }
217
269
  // Writer wraps a stream and writes chunks of data
218
270
  export class Writer {
219
271
  #writer;
220
272
  #stream;
273
+ #closed;
221
274
  // Scratch buffer for writing varints.
222
275
  // Fixed at 9 bytes (leading-ones max).
223
276
  #scratch;
@@ -228,6 +281,19 @@ export class Writer {
228
281
  this.#writer = this.#stream.getWriter();
229
282
  this.version = version;
230
283
  }
284
+ /**
285
+ * Rank this stream against the session's others, where HIGHER values are sent first.
286
+ *
287
+ * A send order only schedules the local end, so a stream the peer opened has to be ranked
288
+ * here rather than at the peer's {@link open}.
289
+ *
290
+ * The spec makes `sendOrder` a settable attribute on every {@link SendStream}. Where the
291
+ * interface isn't implemented (Chrome as of writing, a mock, a polyfill) this just sets an
292
+ * ignored property, the same way an ignored `sendOrder` option does at {@link open}.
293
+ */
294
+ setPriority(sendOrder) {
295
+ this.#stream.sendOrder = sendOrder;
296
+ }
231
297
  async bool(v) {
232
298
  await this.write(setUint8(this.#scratch, v ? 1 : 0));
233
299
  }
@@ -269,7 +335,11 @@ export class Writer {
269
335
  }
270
336
  }
271
337
  async write(v) {
272
- await this.#writer.write(v);
338
+ // Mirrors Reader.#fill: every write funnels through here, so a STOP_SENDING from the
339
+ // peer surfaces as a typed code rather than the transport's own error shape.
340
+ await this.#writer.write(v).catch((err) => {
341
+ throw fromTransport(err);
342
+ });
273
343
  }
274
344
  async string(str) {
275
345
  const data = new TextEncoder().encode(str);
@@ -279,15 +349,56 @@ export class Writer {
279
349
  close() {
280
350
  this.#writer.close().catch(() => void 0);
281
351
  }
352
+ // Mirrors Reader.closed: a STOP_SENDING reaches a caller racing this with the same
353
+ // typed code it would get from a write.
282
354
  get closed() {
283
- return this.#writer.closed;
355
+ this.#closed ??= this.#writer.closed.catch((err) => {
356
+ throw fromTransport(err);
357
+ });
358
+ return this.#closed;
284
359
  }
285
360
  reset(reason) {
286
361
  this.#writer.abort(reason).catch(() => void 0);
287
362
  }
288
- static async open(quic, version) {
289
- const writable = (await quic.createUnidirectionalStream());
290
- return new Writer(writable, version);
363
+ /**
364
+ * Open an outgoing unidirectional stream.
365
+ * @param quic - The session to open it on
366
+ * @param options - The version its varints encode with, and the send order ranking it
367
+ * against the session's other streams
368
+ */
369
+ static async open(quic, options) {
370
+ const writable = await openWithin(quic.createUnidirectionalStream(sendOptions(options)), options?.timeout ?? OPEN_TIMEOUT_MS, (stream) => void stream.abort().catch(() => void 0));
371
+ return new Writer(writable, options?.version);
372
+ }
373
+ /**
374
+ * Like {@link Writer.open}, but gives up when `cancel` settles or `timeout` elapses,
375
+ * returning undefined so the caller can drop whatever it meant to send. A stream that
376
+ * opens after that is reset rather than leaked. A real transport failure still throws.
377
+ *
378
+ * Worth using even with `waitUntilAvailable: false`, since an implementation may park
379
+ * an over-limit open instead of rejecting it.
380
+ */
381
+ static async tryOpen(quic, options) {
382
+ // A rejected `cancel` (STOP_SENDING) means the peer is gone too, so both settle
383
+ // paths mean "give up" and neither is left unhandled. Built before the open, and
384
+ // raced ahead of it, so an already-cancelled caller wins even against a slot that
385
+ // is free right now.
386
+ const cancelled = options.cancel.then(() => undefined, () => undefined);
387
+ const open = Writer.open(quic, options);
388
+ try {
389
+ const stream = await Promise.race([cancelled, open]);
390
+ if (stream)
391
+ return stream;
392
+ }
393
+ catch (err) {
394
+ // open already discarded the late stream on its way out.
395
+ if (!(err instanceof TimeoutError))
396
+ throw err;
397
+ return undefined;
398
+ }
399
+ const abandoned = new Error("abandoned waiting for a stream slot");
400
+ open.then((w) => w.reset(abandoned)).catch(() => void 0);
401
+ return undefined;
291
402
  }
292
403
  }
293
404
  function setUint8(dst, v) {
package/stream.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"stream.js","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAEtC,MAAM,OAAO,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AAC5B,MAAM,aAAa,GAAG,IAAI,GAAG,IAAI,GAAG,EAAE,CAAC,CAAC,8CAA8C;AA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,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;AACtE,CAAC;AAED,SAAS,QAAQ,CAAC,GAAgB,EAAE,CAAS;IAC5C,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACrC,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACpB,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;AACtE,CAAC;AAED,8CAA8C;AAC9C,MAAM,OAAO,OAAO;IACnB,OAAO,CAA0D;IACjE,QAAQ,CAAe;IAEvB,YAAY,IAAkB,EAAE,OAAqB;QACpD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,6BAA6B,CAAC,SAAS,EAE1D,CAAC;QACF,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,IAAI;QACT,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QACvC,IAAI,IAAI,CAAC,IAAI;YAAE,OAAO;QACtB,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IACzD,CAAC;IAED,KAAK;QACJ,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC;CACD","sourcesContent":["import type { IetfVersion } from \"./ietf/version.ts\";\nimport { Version } from \"./ietf/version.ts\";\nimport * as Varint from \"./varint.ts\";\n\nconst MAX_U31 = 2 ** 31 - 1;\nconst MAX_READ_SIZE = 1024 * 1024 * 64; // don't allocate more than 64MB for a message\n\nfunction isLeadingOnes(version?: IetfVersion): boolean {\n\treturn (\n\t\tversion !== undefined &&\n\t\tversion !== Version.DRAFT_14 &&\n\t\tversion !== Version.DRAFT_15 &&\n\t\tversion !== Version.DRAFT_16\n\t);\n}\n\nexport class Stream {\n\treader: Reader;\n\twriter: Writer;\n\n\tconstructor(props: {\n\t\twritable: WritableStream<Uint8Array>;\n\t\treadable: ReadableStream<Uint8Array>;\n\t\twriter?: Writer;\n\t\treader?: Reader;\n\t\tversion?: IetfVersion;\n\t}) {\n\t\tthis.writer = props.writer ?? new Writer(props.writable, props.version);\n\t\tthis.reader = props.reader ?? new Reader(props.readable, undefined, props.version);\n\t}\n\n\tstatic async accept(quic: WebTransport, version?: IetfVersion): Promise<Stream | undefined> {\n\t\tfor (;;) {\n\t\t\tconst reader =\n\t\t\t\tquic.incomingBidirectionalStreams.getReader() as ReadableStreamDefaultReader<WebTransportBidirectionalStream>;\n\t\t\tconst next = await reader.read();\n\t\t\treader.releaseLock();\n\n\t\t\tif (next.done) return;\n\t\t\tconst { readable, writable } = next.value;\n\t\t\treturn new Stream({ readable, writable, version });\n\t\t}\n\t}\n\n\tstatic async open(quic: WebTransport, version?: IetfVersion, priority?: number): Promise<Stream> {\n\t\tconst { readable, writable } = await quic.createBidirectionalStream({ sendOrder: priority });\n\t\treturn new Stream({ readable, writable, version });\n\t}\n\n\tclose() {\n\t\tthis.writer.close();\n\t\tthis.reader.stop(new Error(\"cancel\"));\n\t}\n\n\tabort(reason: Error) {\n\t\tthis.writer.reset(reason);\n\t\tthis.reader.stop(reason);\n\t}\n}\n\n// Reader wraps a stream and provides convience methods for reading pieces from a stream\n// Unfortunately we can't use a BYOB reader because it's not supported with WebTransport+WebWorkers yet.\nexport class Reader {\n\t#buffer: Uint8Array;\n\t#stream?: ReadableStream<Uint8Array>; // if undefined, the buffer is consumed then EOF\n\t#reader?: ReadableStreamDefaultReader<Uint8Array>;\n\tversion?: IetfVersion;\n\n\t// Either stream or buffer MUST be provided.\n\tconstructor(stream: ReadableStream<Uint8Array>, buffer?: Uint8Array, version?: IetfVersion);\n\tconstructor(stream: undefined, buffer: Uint8Array, version?: IetfVersion);\n\tconstructor(stream?: ReadableStream<Uint8Array>, buffer?: Uint8Array, version?: IetfVersion) {\n\t\tthis.#buffer = buffer ?? new Uint8Array();\n\t\tthis.#stream = stream;\n\t\tthis.#reader = this.#stream?.getReader();\n\t\tthis.version = version;\n\t}\n\n\t// Adds more data to the buffer, returning true if more data was added.\n\tasync #fill(): Promise<boolean> {\n\t\tif (!this.#reader) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst result = await this.#reader.read();\n\t\tif (result.done) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif (result.value.byteLength === 0) {\n\t\t\tthrow new Error(\"unexpected empty chunk\");\n\t\t}\n\n\t\tconst buffer = new Uint8Array(result.value);\n\n\t\tif (this.#buffer.byteLength === 0) {\n\t\t\tthis.#buffer = buffer;\n\t\t} else {\n\t\t\tconst temp = new Uint8Array(this.#buffer.byteLength + buffer.byteLength);\n\t\t\ttemp.set(this.#buffer);\n\t\t\ttemp.set(buffer, this.#buffer.byteLength);\n\t\t\tthis.#buffer = temp;\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t// Add more data to the buffer until it's at least size bytes.\n\tasync #fillTo(size: number) {\n\t\tif (size > MAX_READ_SIZE) {\n\t\t\tthrow new Error(`read size ${size} exceeds max size ${MAX_READ_SIZE}`);\n\t\t}\n\n\t\twhile (this.#buffer.byteLength < size) {\n\t\t\tif (!(await this.#fill())) {\n\t\t\t\tthrow new Error(\"unexpected end of stream\");\n\t\t\t}\n\t\t}\n\t}\n\n\t// Consumes the first size bytes of the buffer.\n\t#slice(size: number): Uint8Array {\n\t\tconst result = new Uint8Array(this.#buffer.buffer, this.#buffer.byteOffset, size);\n\t\tthis.#buffer = new Uint8Array(\n\t\t\tthis.#buffer.buffer,\n\t\t\tthis.#buffer.byteOffset + size,\n\t\t\tthis.#buffer.byteLength - size,\n\t\t);\n\n\t\treturn result;\n\t}\n\n\tasync read(size: number): Promise<Uint8Array> {\n\t\tif (size === 0) return new Uint8Array();\n\n\t\tawait this.#fillTo(size);\n\t\treturn this.#slice(size);\n\t}\n\n\tasync readAll(): Promise<Uint8Array> {\n\t\twhile (await this.#fill()) {\n\t\t\t// keep going\n\t\t}\n\t\treturn this.#slice(this.#buffer.byteLength);\n\t}\n\n\tasync string(): Promise<string> {\n\t\tconst length = await this.u53();\n\t\tconst buffer = await this.read(length);\n\t\treturn new TextDecoder().decode(buffer);\n\t}\n\n\tasync bool(): Promise<boolean> {\n\t\tconst v = await this.u8();\n\t\tif (v === 0) return false;\n\t\tif (v === 1) return true;\n\t\tthrow new Error(\"invalid bool value\");\n\t}\n\n\tasync u8(): Promise<number> {\n\t\tawait this.#fillTo(1);\n\t\treturn this.#slice(1)[0];\n\t}\n\n\tasync u16(): Promise<number> {\n\t\tawait this.#fillTo(2);\n\t\tconst view = new DataView(this.#buffer.buffer, this.#buffer.byteOffset, 2);\n\t\tconst result = view.getUint16(0);\n\t\tthis.#slice(2);\n\t\treturn result;\n\t}\n\n\t// Returns a Number using 53-bits, the max Javascript can use for integer math.\n\t// Values > 2^53-1 are coerced to a Number (precision is lost) and logged. We\n\t// downgrade overflow from throw to warn so a stray u64 field on the wire (e.g.\n\t// a peer's session-level Origin id) doesn't tear down the whole stream/session.\n\tasync u53(): Promise<number> {\n\t\tconst v = await this.u62();\n\t\tif (v > Varint.MAX_U53) {\n\t\t\tconsole.warn(`value larger than 53-bits; use u62 instead (precision lost): ${v.toString()}`);\n\t\t}\n\n\t\treturn Number(v);\n\t}\n\n\t// NOTE: Returns a bigint instead of a number since it may be larger than 53-bits\n\tasync u62(): Promise<bigint> {\n\t\tif (isLeadingOnes(this.version)) {\n\t\t\treturn this.#readLeadingOnes();\n\t\t}\n\t\treturn this.#readQuicVarint();\n\t}\n\n\tasync #readQuicVarint(): Promise<bigint> {\n\t\tawait this.#fillTo(1);\n\t\tconst size = (this.#buffer[0] & 0xc0) >> 6;\n\n\t\tif (size === 0) {\n\t\t\tconst first = this.#slice(1)[0];\n\t\t\treturn BigInt(first) & 0x3fn;\n\t\t}\n\t\tif (size === 1) {\n\t\t\tawait this.#fillTo(2);\n\t\t\tconst slice = this.#slice(2);\n\t\t\tconst view = new DataView(slice.buffer, slice.byteOffset, slice.byteLength);\n\n\t\t\treturn BigInt(view.getUint16(0)) & 0x3fffn;\n\t\t}\n\t\tif (size === 2) {\n\t\t\tawait this.#fillTo(4);\n\t\t\tconst slice = this.#slice(4);\n\t\t\tconst view = new DataView(slice.buffer, slice.byteOffset, slice.byteLength);\n\n\t\t\treturn BigInt(view.getUint32(0)) & 0x3fffffffn;\n\t\t}\n\t\tawait this.#fillTo(8);\n\t\tconst slice = this.#slice(8);\n\t\tconst view = new DataView(slice.buffer, slice.byteOffset, slice.byteLength);\n\n\t\treturn view.getBigUint64(0) & 0x3fffffffffffffffn;\n\t}\n\n\tasync #readLeadingOnes(): Promise<bigint> {\n\t\tawait this.#fillTo(1);\n\t\tconst b = this.#buffer[0];\n\n\t\t// Count leading 1-bits\n\t\tlet ones = 0;\n\t\tfor (let bit = 7; bit >= 0; bit--) {\n\t\t\tif (b & (1 << bit)) ones++;\n\t\t\telse break;\n\t\t}\n\n\t\t// 1111110x is a 7-byte form. Draft-17 rejects it; draft-18+ allows it per #1595.\n\t\tif (ones === 6 && this.version === Version.DRAFT_17) {\n\t\t\tthrow new Error(\"invalid leading-ones varint: 1111110x prefix is reserved on draft-17\");\n\t\t}\n\n\t\tlet totalSize: number;\n\t\tif (ones <= 5) totalSize = ones + 1;\n\t\telse if (ones === 6) totalSize = 7;\n\t\telse if (ones === 7) totalSize = 8;\n\t\telse totalSize = 9; // ones === 8\n\n\t\tawait this.#fillTo(totalSize);\n\t\tconst slice = this.#slice(totalSize);\n\n\t\tconst [value] = Varint.decodeLeadingOnes(slice);\n\t\treturn value;\n\t}\n\n\t// Returns false if there is more data to read, blocking if it hasn't been received yet.\n\tasync done(): Promise<boolean> {\n\t\tif (this.#buffer.byteLength > 0) return false;\n\t\treturn !(await this.#fill());\n\t}\n\n\tstop(reason: unknown) {\n\t\tthis.#reader?.cancel(reason).catch(() => void 0);\n\t}\n\n\tget closed(): Promise<void> {\n\t\treturn this.#reader?.closed ?? Promise.resolve();\n\t}\n}\n\n// Writer wraps a stream and writes chunks of data\nexport class Writer {\n\t#writer: WritableStreamDefaultWriter<Uint8Array>;\n\t#stream: WritableStream<Uint8Array>;\n\n\t// Scratch buffer for writing varints.\n\t// Fixed at 9 bytes (leading-ones max).\n\t#scratch: ArrayBuffer;\n\n\tversion?: IetfVersion;\n\n\tconstructor(stream: WritableStream<Uint8Array>, version?: IetfVersion) {\n\t\tthis.#stream = stream;\n\t\tthis.#scratch = new ArrayBuffer(9);\n\t\tthis.#writer = this.#stream.getWriter();\n\t\tthis.version = version;\n\t}\n\n\tasync bool(v: boolean) {\n\t\tawait this.write(setUint8(this.#scratch, v ? 1 : 0));\n\t}\n\n\tasync u8(v: number) {\n\t\tawait this.write(setUint8(this.#scratch, v));\n\t}\n\n\tasync u16(v: number) {\n\t\tawait this.write(setUint16(this.#scratch, v));\n\t}\n\n\tasync i32(v: number) {\n\t\tif (Math.abs(v) > MAX_U31) {\n\t\t\tthrow new Error(`overflow, value larger than 32-bits: ${v.toString()}`);\n\t\t}\n\n\t\t// We don't use a VarInt, so it always takes 4 bytes.\n\t\t// This could be improved but nothing is standardized yet.\n\t\tawait this.write(setInt32(this.#scratch, v));\n\t}\n\n\tasync u53(v: number) {\n\t\tif (v > Varint.MAX_U53) {\n\t\t\t// Number values above 2^53-1 have already lost precision before reaching\n\t\t\t// the wire, but downgrade overflow to warn so an upstream miscount\n\t\t\t// doesn't tear down the whole stream. The encoded varint will reflect\n\t\t\t// the truncated Number value.\n\t\t\tconsole.warn(`value larger than 53-bits; use u62 instead (precision lost): ${v.toString()}`);\n\t\t}\n\t\tif (isLeadingOnes(this.version)) {\n\t\t\tawait this.write(Varint.encodeLeadingOnesTo(this.#scratch, v));\n\t\t} else {\n\t\t\tawait this.write(Varint.encodeTo(this.#scratch, v));\n\t\t}\n\t}\n\n\tasync u62(v: bigint) {\n\t\tif (isLeadingOnes(this.version)) {\n\t\t\tawait this.write(Varint.encodeLeadingOnesTo(this.#scratch, v));\n\t\t} else {\n\t\t\tawait this.write(Varint.encodeTo(this.#scratch, v));\n\t\t}\n\t}\n\n\tasync write(v: Uint8Array) {\n\t\tawait this.#writer.write(v);\n\t}\n\n\tasync string(str: string) {\n\t\tconst data = new TextEncoder().encode(str);\n\t\tawait this.u53(data.byteLength);\n\t\tawait this.write(data);\n\t}\n\n\tclose() {\n\t\tthis.#writer.close().catch(() => void 0);\n\t}\n\n\tget closed(): Promise<void> {\n\t\treturn this.#writer.closed;\n\t}\n\n\treset(reason: unknown) {\n\t\tthis.#writer.abort(reason).catch(() => void 0);\n\t}\n\n\tstatic async open(quic: WebTransport, version?: IetfVersion): Promise<Writer> {\n\t\tconst writable = (await quic.createUnidirectionalStream()) as WritableStream<Uint8Array>;\n\t\treturn new Writer(writable, version);\n\t}\n}\n\nfunction setUint8(dst: ArrayBuffer, v: number): Uint8Array {\n\tconst buffer = new Uint8Array(dst, 0, 1);\n\tbuffer[0] = v;\n\treturn buffer;\n}\n\nfunction setUint16(dst: ArrayBuffer, v: number): Uint8Array {\n\tconst view = new DataView(dst, 0, 2);\n\tview.setUint16(0, v);\n\treturn new Uint8Array(view.buffer, view.byteOffset, view.byteLength);\n}\n\nfunction setInt32(dst: ArrayBuffer, v: number): Uint8Array {\n\tconst view = new DataView(dst, 0, 4);\n\tview.setInt32(0, v);\n\treturn new Uint8Array(view.buffer, view.byteOffset, view.byteLength);\n}\n\n// Returns the next stream from the connection\nexport class Readers {\n\t#reader: ReadableStreamDefaultReader<ReadableStream<Uint8Array>>;\n\t#version?: IetfVersion;\n\n\tconstructor(quic: WebTransport, version?: IetfVersion) {\n\t\tthis.#reader = quic.incomingUnidirectionalStreams.getReader() as ReadableStreamDefaultReader<\n\t\t\tReadableStream<Uint8Array>\n\t\t>;\n\t\tthis.#version = version;\n\t}\n\n\tasync next(): Promise<Reader | undefined> {\n\t\tconst next = await this.#reader.read();\n\t\tif (next.done) return;\n\t\treturn new Reader(next.value, undefined, this.#version);\n\t}\n\n\tclose() {\n\t\tthis.#reader.cancel();\n\t}\n}\n"]}
1
+ {"version":3,"file":"stream.js","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAEtC,MAAM,OAAO,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AAC5B,MAAM,aAAa,GAAG,IAAI,GAAG,IAAI,GAAG,EAAE,CAAC,CAAC,8CAA8C;AAEtF;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,OAAqB;IAChD,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,OAAO,EAAE,kBAAkB,IAAI,IAAI,EAAE,CAAC;AACnG,CAAC;AAED,wFAAwF;AACxF,wFAAwF;AACxF,yFAAyF;AACzF,gCAAgC;AAChC,MAAM,eAAe,GAAG,MAAM,CAAC;AAE/B;;;;GAIG;AACH,KAAK,UAAU,UAAU,CAAI,OAAmB,EAAE,OAAe,EAAE,OAA4B;IAC9F,IAAI,CAAC;QACJ,OAAO,MAAM,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,+BAA+B,OAAO,uBAAuB,CAAC,CAAC;IAC3G,CAAC;IAAC,OAAO,GAAY,EAAE,CAAC;QACvB,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;QAC1C,MAAM,GAAG,CAAC;IACX,CAAC;AACF,CAAC;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E,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;AACtE,CAAC;AAED,SAAS,QAAQ,CAAC,GAAgB,EAAE,CAAS;IAC5C,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACrC,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACpB,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;AACtE,CAAC;AAED,8CAA8C;AAC9C,MAAM,OAAO,OAAO;IACnB,OAAO,CAA0D;IACjE,QAAQ,CAAe;IAEvB,YAAY,IAAkB,EAAE,OAAqB;QACpD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,6BAA6B,CAAC,SAAS,EAE1D,CAAC;QACF,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,IAAI;QACT,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QACvC,IAAI,IAAI,CAAC,IAAI;YAAE,OAAO;QACtB,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IACzD,CAAC;IAED,KAAK;QACJ,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC;CACD","sourcesContent":["import { fromTransport } from \"./error.ts\";\nimport type { IetfVersion } from \"./ietf/version.ts\";\nimport { Version } from \"./ietf/version.ts\";\nimport { TimeoutError, withTimeout } from \"./util/timeout.ts\";\nimport { decodeUtf8 } from \"./util/utf8.ts\";\nimport * as Varint from \"./varint.ts\";\n\nconst MAX_U31 = 2 ** 31 - 1;\nconst MAX_READ_SIZE = 1024 * 1024 * 64; // don't allocate more than 64MB for a message\n\n/**\n * Options handed to the transport for one outgoing stream.\n *\n * `waitUntilAvailable` waits for the peer's concurrent stream limit to free a slot instead\n * of rejecting with a `QuotaExceededError`, which is what we want for the streams a session\n * opens occasionally. `@types/web` doesn't declare it yet, hence the intersection.\n */\nexport function sendOptions(options?: OpenOptions): WebTransportSendStreamOptions & { waitUntilAvailable?: boolean } {\n\treturn { sendOrder: options?.sendOrder, waitUntilAvailable: options?.waitUntilAvailable ?? true };\n}\n\n// How long any open may wait for the peer to free a stream slot. Every open needs this,\n// whether or not it asked to wait: an implementation may park an over-limit open rather\n// than rejecting it, and a peer can advertise a stream limit of zero and never raise it.\n// Matches the subscribe budget.\nconst OPEN_TIMEOUT_MS = 10_000;\n\n/**\n * Bound an open that would otherwise park until the peer grants stream credit, restoring\n * the pre-waitUntilAvailable failure after a grace period. A stream arriving after the\n * deadline is discarded, since nobody is waiting for it any more.\n */\nasync function openWithin<T>(opening: Promise<T>, timeout: number, discard: (stream: T) => void): Promise<T> {\n\ttry {\n\t\treturn await withTimeout(opening, timeout, `stream open timed out after ${timeout}ms waiting for a slot`);\n\t} catch (err: unknown) {\n\t\topening.then(discard).catch(() => void 0);\n\t\tthrow err;\n\t}\n}\n\nfunction isLeadingOnes(version?: IetfVersion): boolean {\n\treturn (\n\t\tversion !== undefined &&\n\t\tversion !== Version.DRAFT_14 &&\n\t\tversion !== Version.DRAFT_15 &&\n\t\tversion !== Version.DRAFT_16\n\t);\n}\n\n/**\n * The `WebTransportSendStream` that every outgoing stream is, narrowed to the one attribute\n * this package uses. The DOM types available here still describe them as plain\n * `WritableStream`s, so the interface has to be named structurally.\n *\n * `sendOrder` is optional because it is absent until set, and stays absent on an\n * implementation that doesn't carry the interface at all.\n *\n * @see https://www.w3.org/TR/webtransport/#webtransportsendstream\n */\nexport type SendStream = WritableStream<Uint8Array> & { sendOrder?: number };\n\n/** Options for opening an outgoing stream. */\nexport interface OpenOptions {\n\t/** The negotiated IETF version, which selects the varint encoding. */\n\tversion?: IetfVersion;\n\n\t/**\n\t * The transport send order, where HIGHER values are transmitted first.\n\t * Left to the transport's default when unset.\n\t */\n\tsendOrder?: number;\n\n\t/**\n\t * Reject if the peer hasn't freed a stream slot within this many milliseconds. Defaults\n\t * to 10s. There is no way to wait indefinitely: a peer can advertise a stream limit of\n\t * zero and never raise it, so every open needs a way out.\n\t */\n\ttimeout?: number;\n\n\t/**\n\t * Ask the transport to wait for a stream slot rather than failing when the peer's\n\t * concurrent stream limit is exhausted. Defaults to true.\n\t *\n\t * Set it false on a path that opens streams faster than the peer can retire them. The\n\t * transport queues the opens it can't satisfy and serves them in order, with no way to\n\t * cancel one, so waiting there spends returning credit on whatever was requested first\n\t * rather than on what matters now.\n\t */\n\twaitUntilAvailable?: boolean;\n}\n\n/** Options for {@link Writer.tryOpen}. */\nexport interface TryOpenOptions extends OpenOptions {\n\t/** Give up once this settles, however it settles. */\n\tcancel: Promise<unknown>;\n}\n\nexport class Stream {\n\treader: Reader;\n\twriter: Writer;\n\n\t/** Wrap the two halves of a transport stream. */\n\tconstructor(props: {\n\t\twritable: WritableStream<Uint8Array>;\n\t\treadable: ReadableStream<Uint8Array>;\n\t\tversion?: IetfVersion;\n\t});\n\t/** Pair halves that were opened separately, as the SETUP exchange does. */\n\tconstructor(props: { writer: Writer; reader: Reader });\n\tconstructor(props: {\n\t\twritable?: WritableStream<Uint8Array>;\n\t\treadable?: ReadableStream<Uint8Array>;\n\t\twriter?: Writer;\n\t\treader?: Reader;\n\t\tversion?: IetfVersion;\n\t}) {\n\t\tconst writer = props.writer ?? (props.writable && new Writer(props.writable, props.version));\n\t\tconst reader = props.reader ?? (props.readable && new Reader(props.readable, undefined, props.version));\n\t\tif (!writer || !reader) throw new Error(\"stream needs both halves\");\n\n\t\tthis.writer = writer;\n\t\tthis.reader = reader;\n\t}\n\n\tstatic async accept(quic: WebTransport, version?: IetfVersion): Promise<Stream | undefined> {\n\t\tfor (;;) {\n\t\t\tconst reader =\n\t\t\t\tquic.incomingBidirectionalStreams.getReader() as ReadableStreamDefaultReader<WebTransportBidirectionalStream>;\n\t\t\tconst next = await reader.read();\n\t\t\treader.releaseLock();\n\n\t\t\tif (next.done) return;\n\t\t\tconst { readable, writable } = next.value;\n\t\t\treturn new Stream({ readable, writable, version });\n\t\t}\n\t}\n\n\t/**\n\t * Open an outgoing bidirectional stream.\n\t * @param quic - The session to open it on\n\t * @param options - The version its varints encode with, and the send order ranking it\n\t * against the session's other streams\n\t */\n\tstatic async open(quic: WebTransport, options?: OpenOptions): Promise<Stream> {\n\t\tconst { readable, writable } = await openWithin(\n\t\t\tquic.createBidirectionalStream(sendOptions(options)),\n\t\t\toptions?.timeout ?? OPEN_TIMEOUT_MS,\n\t\t\t(stream) => {\n\t\t\t\tvoid stream.writable.abort().catch(() => void 0);\n\t\t\t\tvoid stream.readable.cancel().catch(() => void 0);\n\t\t\t},\n\t\t);\n\t\treturn new Stream({ readable, writable, version: options?.version });\n\t}\n\n\tclose() {\n\t\tthis.writer.close();\n\t\tthis.reader.stop(new Error(\"cancel\"));\n\t}\n\n\tabort(reason: Error) {\n\t\tthis.writer.reset(reason);\n\t\tthis.reader.stop(reason);\n\t}\n}\n\n// Reader wraps a stream and provides convience methods for reading pieces from a stream\n// Unfortunately we can't use a BYOB reader because it's not supported with WebTransport+WebWorkers yet.\nexport class Reader {\n\t#buffer: Uint8Array;\n\t#stream?: ReadableStream<Uint8Array>; // if undefined, the buffer is consumed then EOF\n\t#reader?: ReadableStreamDefaultReader<Uint8Array>;\n\t#closed?: Promise<void>;\n\tversion?: IetfVersion;\n\n\t// Either stream or buffer MUST be provided.\n\tconstructor(stream: ReadableStream<Uint8Array>, buffer?: Uint8Array, version?: IetfVersion);\n\tconstructor(stream: undefined, buffer: Uint8Array, version?: IetfVersion);\n\tconstructor(stream?: ReadableStream<Uint8Array>, buffer?: Uint8Array, version?: IetfVersion) {\n\t\tthis.#buffer = buffer ?? new Uint8Array();\n\t\tthis.#stream = stream;\n\t\tthis.#reader = this.#stream?.getReader();\n\t\tthis.version = version;\n\t}\n\n\t// Adds more data to the buffer, returning true if more data was added.\n\tasync #fill(): Promise<boolean> {\n\t\tif (!this.#reader) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Every read of this stream funnels through here, so decoding the peer's reset code\n\t\t// once is enough to keep the raw transport error out of every caller (and every app).\n\t\tconst result = await this.#reader.read().catch((err: unknown) => {\n\t\t\tthrow fromTransport(err);\n\t\t});\n\n\t\tif (result.done) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif (result.value.byteLength === 0) {\n\t\t\tthrow new Error(\"unexpected empty chunk\");\n\t\t}\n\n\t\tconst buffer = new Uint8Array(result.value);\n\n\t\tif (this.#buffer.byteLength === 0) {\n\t\t\tthis.#buffer = buffer;\n\t\t} else {\n\t\t\tconst temp = new Uint8Array(this.#buffer.byteLength + buffer.byteLength);\n\t\t\ttemp.set(this.#buffer);\n\t\t\ttemp.set(buffer, this.#buffer.byteLength);\n\t\t\tthis.#buffer = temp;\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t// Add more data to the buffer until it's at least size bytes.\n\tasync #fillTo(size: number) {\n\t\tif (size > MAX_READ_SIZE) {\n\t\t\tthrow new Error(`read size ${size} exceeds max size ${MAX_READ_SIZE}`);\n\t\t}\n\n\t\twhile (this.#buffer.byteLength < size) {\n\t\t\tif (!(await this.#fill())) {\n\t\t\t\tthrow new Error(\"unexpected end of stream\");\n\t\t\t}\n\t\t}\n\t}\n\n\t// Consumes the first size bytes of the buffer.\n\t#slice(size: number): Uint8Array {\n\t\tconst result = new Uint8Array(this.#buffer.buffer, this.#buffer.byteOffset, size);\n\t\tthis.#buffer = new Uint8Array(\n\t\t\tthis.#buffer.buffer,\n\t\t\tthis.#buffer.byteOffset + size,\n\t\t\tthis.#buffer.byteLength - size,\n\t\t);\n\n\t\treturn result;\n\t}\n\n\tasync read(size: number): Promise<Uint8Array> {\n\t\tif (size === 0) return new Uint8Array();\n\n\t\tawait this.#fillTo(size);\n\t\treturn this.#slice(size);\n\t}\n\n\tasync readAll(): Promise<Uint8Array> {\n\t\twhile (await this.#fill()) {\n\t\t\t// keep going\n\t\t}\n\t\treturn this.#slice(this.#buffer.byteLength);\n\t}\n\n\tasync string(): Promise<string> {\n\t\tconst length = await this.u53();\n\t\tconst buffer = await this.read(length);\n\t\treturn decodeUtf8(buffer);\n\t}\n\n\tasync bool(): Promise<boolean> {\n\t\tconst v = await this.u8();\n\t\tif (v === 0) return false;\n\t\tif (v === 1) return true;\n\t\tthrow new Error(\"invalid bool value\");\n\t}\n\n\tasync u8(): Promise<number> {\n\t\tawait this.#fillTo(1);\n\t\treturn this.#slice(1)[0];\n\t}\n\n\tasync u16(): Promise<number> {\n\t\tawait this.#fillTo(2);\n\t\tconst view = new DataView(this.#buffer.buffer, this.#buffer.byteOffset, 2);\n\t\tconst result = view.getUint16(0);\n\t\tthis.#slice(2);\n\t\treturn result;\n\t}\n\n\t// Returns a Number using 53-bits, the max Javascript can use for integer math.\n\tasync u53(): Promise<number> {\n\t\tconst v = await this.u62();\n\t\tif (v > Varint.MAX_U53) {\n\t\t\tthrow new Error(`value larger than 53-bits: ${v.toString()}`);\n\t\t}\n\n\t\treturn Number(v);\n\t}\n\n\t// NOTE: Returns a bigint instead of a number since it may be larger than 53-bits\n\tasync u62(): Promise<bigint> {\n\t\tif (isLeadingOnes(this.version)) {\n\t\t\treturn this.#readLeadingOnes();\n\t\t}\n\t\treturn this.#readQuicVarint();\n\t}\n\n\tasync #readQuicVarint(): Promise<bigint> {\n\t\tawait this.#fillTo(1);\n\t\tconst size = (this.#buffer[0] & 0xc0) >> 6;\n\n\t\tif (size === 0) {\n\t\t\tconst first = this.#slice(1)[0];\n\t\t\treturn BigInt(first) & 0x3fn;\n\t\t}\n\t\tif (size === 1) {\n\t\t\tawait this.#fillTo(2);\n\t\t\tconst slice = this.#slice(2);\n\t\t\tconst view = new DataView(slice.buffer, slice.byteOffset, slice.byteLength);\n\n\t\t\treturn BigInt(view.getUint16(0)) & 0x3fffn;\n\t\t}\n\t\tif (size === 2) {\n\t\t\tawait this.#fillTo(4);\n\t\t\tconst slice = this.#slice(4);\n\t\t\tconst view = new DataView(slice.buffer, slice.byteOffset, slice.byteLength);\n\n\t\t\treturn BigInt(view.getUint32(0)) & 0x3fffffffn;\n\t\t}\n\t\tawait this.#fillTo(8);\n\t\tconst slice = this.#slice(8);\n\t\tconst view = new DataView(slice.buffer, slice.byteOffset, slice.byteLength);\n\n\t\treturn view.getBigUint64(0) & 0x3fffffffffffffffn;\n\t}\n\n\tasync #readLeadingOnes(): Promise<bigint> {\n\t\tawait this.#fillTo(1);\n\t\tconst b = this.#buffer[0];\n\n\t\t// Count leading 1-bits\n\t\tlet ones = 0;\n\t\tfor (let bit = 7; bit >= 0; bit--) {\n\t\t\tif (b & (1 << bit)) ones++;\n\t\t\telse break;\n\t\t}\n\n\t\t// 1111110x is a 7-byte form. Draft-17 rejects it; draft-18+ allows it per #1595.\n\t\tif (ones === 6 && this.version === Version.DRAFT_17) {\n\t\t\tthrow new Error(\"invalid leading-ones varint: 1111110x prefix is reserved on draft-17\");\n\t\t}\n\n\t\tlet totalSize: number;\n\t\tif (ones <= 5) totalSize = ones + 1;\n\t\telse if (ones === 6) totalSize = 7;\n\t\telse if (ones === 7) totalSize = 8;\n\t\telse totalSize = 9; // ones === 8\n\n\t\tawait this.#fillTo(totalSize);\n\t\tconst slice = this.#slice(totalSize);\n\n\t\tconst [value] = Varint.decodeLeadingOnes(slice);\n\t\treturn value;\n\t}\n\n\t// Returns false if there is more data to read, blocking if it hasn't been received yet.\n\tasync done(): Promise<boolean> {\n\t\tif (this.#buffer.byteLength > 0) return false;\n\t\treturn !(await this.#fill());\n\t}\n\n\tstop(reason: unknown) {\n\t\tthis.#reader?.cancel(reason).catch(() => void 0);\n\t}\n\n\t// Decoded like #fill: a caller racing this against a read must not get a different error\n\t// shape depending on which one won. Derived once, so racing it per frame doesn't allocate.\n\tget closed(): Promise<void> {\n\t\tthis.#closed ??= (this.#reader?.closed ?? Promise.resolve()).catch((err: unknown) => {\n\t\t\tthrow fromTransport(err);\n\t\t});\n\t\treturn this.#closed;\n\t}\n}\n\n// Writer wraps a stream and writes chunks of data\nexport class Writer {\n\t#writer: WritableStreamDefaultWriter<Uint8Array>;\n\t#stream: WritableStream<Uint8Array>;\n\t#closed?: Promise<void>;\n\n\t// Scratch buffer for writing varints.\n\t// Fixed at 9 bytes (leading-ones max).\n\t#scratch: ArrayBuffer;\n\n\tversion?: IetfVersion;\n\n\tconstructor(stream: WritableStream<Uint8Array>, version?: IetfVersion) {\n\t\tthis.#stream = stream;\n\t\tthis.#scratch = new ArrayBuffer(9);\n\t\tthis.#writer = this.#stream.getWriter();\n\t\tthis.version = version;\n\t}\n\n\t/**\n\t * Rank this stream against the session's others, where HIGHER values are sent first.\n\t *\n\t * A send order only schedules the local end, so a stream the peer opened has to be ranked\n\t * here rather than at the peer's {@link open}.\n\t *\n\t * The spec makes `sendOrder` a settable attribute on every {@link SendStream}. Where the\n\t * interface isn't implemented (Chrome as of writing, a mock, a polyfill) this just sets an\n\t * ignored property, the same way an ignored `sendOrder` option does at {@link open}.\n\t */\n\tsetPriority(sendOrder: number) {\n\t\t(this.#stream as SendStream).sendOrder = sendOrder;\n\t}\n\n\tasync bool(v: boolean) {\n\t\tawait this.write(setUint8(this.#scratch, v ? 1 : 0));\n\t}\n\n\tasync u8(v: number) {\n\t\tawait this.write(setUint8(this.#scratch, v));\n\t}\n\n\tasync u16(v: number) {\n\t\tawait this.write(setUint16(this.#scratch, v));\n\t}\n\n\tasync i32(v: number) {\n\t\tif (Math.abs(v) > MAX_U31) {\n\t\t\tthrow new Error(`overflow, value larger than 32-bits: ${v.toString()}`);\n\t\t}\n\n\t\t// We don't use a VarInt, so it always takes 4 bytes.\n\t\t// This could be improved but nothing is standardized yet.\n\t\tawait this.write(setInt32(this.#scratch, v));\n\t}\n\n\tasync u53(v: number) {\n\t\tif (v > Varint.MAX_U53) {\n\t\t\t// Number values above 2^53-1 have already lost precision before reaching\n\t\t\t// the wire, but downgrade overflow to warn so an upstream miscount\n\t\t\t// doesn't tear down the whole stream. The encoded varint will reflect\n\t\t\t// the truncated Number value.\n\t\t\tconsole.warn(`value larger than 53-bits; use u62 instead (precision lost): ${v.toString()}`);\n\t\t}\n\t\tif (isLeadingOnes(this.version)) {\n\t\t\tawait this.write(Varint.encodeLeadingOnesTo(this.#scratch, v));\n\t\t} else {\n\t\t\tawait this.write(Varint.encodeTo(this.#scratch, v));\n\t\t}\n\t}\n\n\tasync u62(v: bigint) {\n\t\tif (isLeadingOnes(this.version)) {\n\t\t\tawait this.write(Varint.encodeLeadingOnesTo(this.#scratch, v));\n\t\t} else {\n\t\t\tawait this.write(Varint.encodeTo(this.#scratch, v));\n\t\t}\n\t}\n\n\tasync write(v: Uint8Array) {\n\t\t// Mirrors Reader.#fill: every write funnels through here, so a STOP_SENDING from the\n\t\t// peer surfaces as a typed code rather than the transport's own error shape.\n\t\tawait this.#writer.write(v).catch((err: unknown) => {\n\t\t\tthrow fromTransport(err);\n\t\t});\n\t}\n\n\tasync string(str: string) {\n\t\tconst data = new TextEncoder().encode(str);\n\t\tawait this.u53(data.byteLength);\n\t\tawait this.write(data);\n\t}\n\n\tclose() {\n\t\tthis.#writer.close().catch(() => void 0);\n\t}\n\n\t// Mirrors Reader.closed: a STOP_SENDING reaches a caller racing this with the same\n\t// typed code it would get from a write.\n\tget closed(): Promise<void> {\n\t\tthis.#closed ??= this.#writer.closed.catch((err: unknown) => {\n\t\t\tthrow fromTransport(err);\n\t\t});\n\t\treturn this.#closed;\n\t}\n\n\treset(reason: unknown) {\n\t\tthis.#writer.abort(reason).catch(() => void 0);\n\t}\n\n\t/**\n\t * Open an outgoing unidirectional stream.\n\t * @param quic - The session to open it on\n\t * @param options - The version its varints encode with, and the send order ranking it\n\t * against the session's other streams\n\t */\n\tstatic async open(quic: WebTransport, options?: OpenOptions): Promise<Writer> {\n\t\tconst writable = await openWithin(\n\t\t\tquic.createUnidirectionalStream(sendOptions(options)) as Promise<WritableStream<Uint8Array>>,\n\t\t\toptions?.timeout ?? OPEN_TIMEOUT_MS,\n\t\t\t(stream) => void stream.abort().catch(() => void 0),\n\t\t);\n\n\t\treturn new Writer(writable, options?.version);\n\t}\n\n\t/**\n\t * Like {@link Writer.open}, but gives up when `cancel` settles or `timeout` elapses,\n\t * returning undefined so the caller can drop whatever it meant to send. A stream that\n\t * opens after that is reset rather than leaked. A real transport failure still throws.\n\t *\n\t * Worth using even with `waitUntilAvailable: false`, since an implementation may park\n\t * an over-limit open instead of rejecting it.\n\t */\n\tstatic async tryOpen(quic: WebTransport, options: TryOpenOptions): Promise<Writer | undefined> {\n\t\t// A rejected `cancel` (STOP_SENDING) means the peer is gone too, so both settle\n\t\t// paths mean \"give up\" and neither is left unhandled. Built before the open, and\n\t\t// raced ahead of it, so an already-cancelled caller wins even against a slot that\n\t\t// is free right now.\n\t\tconst cancelled = options.cancel.then(\n\t\t\t() => undefined,\n\t\t\t() => undefined,\n\t\t);\n\t\tconst open = Writer.open(quic, options);\n\n\t\ttry {\n\t\t\tconst stream = await Promise.race([cancelled, open]);\n\t\t\tif (stream) return stream;\n\t\t} catch (err: unknown) {\n\t\t\t// open already discarded the late stream on its way out.\n\t\t\tif (!(err instanceof TimeoutError)) throw err;\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst abandoned = new Error(\"abandoned waiting for a stream slot\");\n\t\topen.then((w) => w.reset(abandoned)).catch(() => void 0);\n\t\treturn undefined;\n\t}\n}\n\nfunction setUint8(dst: ArrayBuffer, v: number): Uint8Array {\n\tconst buffer = new Uint8Array(dst, 0, 1);\n\tbuffer[0] = v;\n\treturn buffer;\n}\n\nfunction setUint16(dst: ArrayBuffer, v: number): Uint8Array {\n\tconst view = new DataView(dst, 0, 2);\n\tview.setUint16(0, v);\n\treturn new Uint8Array(view.buffer, view.byteOffset, view.byteLength);\n}\n\nfunction setInt32(dst: ArrayBuffer, v: number): Uint8Array {\n\tconst view = new DataView(dst, 0, 4);\n\tview.setInt32(0, v);\n\treturn new Uint8Array(view.buffer, view.byteOffset, view.byteLength);\n}\n\n// Returns the next stream from the connection\nexport class Readers {\n\t#reader: ReadableStreamDefaultReader<ReadableStream<Uint8Array>>;\n\t#version?: IetfVersion;\n\n\tconstructor(quic: WebTransport, version?: IetfVersion) {\n\t\tthis.#reader = quic.incomingUnidirectionalStreams.getReader() as ReadableStreamDefaultReader<\n\t\t\tReadableStream<Uint8Array>\n\t\t>;\n\t\tthis.#version = version;\n\t}\n\n\tasync next(): Promise<Reader | undefined> {\n\t\tconst next = await this.#reader.read();\n\t\tif (next.done) return;\n\t\treturn new Reader(next.value, undefined, this.#version);\n\t}\n\n\tclose() {\n\t\tthis.#reader.cancel();\n\t}\n}\n"]}
package/time.d.ts CHANGED
@@ -1,109 +1,132 @@
1
+ /**
2
+ * Branded time types (nanoseconds, microseconds, milliseconds, seconds) with conversions,
3
+ * plus {@link Timescale} and {@link Timestamp} for presentation timing.
4
+ *
5
+ * @module
6
+ */
1
7
  /** A duration in nanoseconds, branded so it can't be mixed with other units. */
2
8
  export type Nano = number & {
3
9
  readonly _brand: "nano";
4
10
  };
5
- /**
6
- * Constructors, conversions, and arithmetic for {@link Nano} values.
7
- *
8
- * Calling `Nano(x)` brands a raw number as nanoseconds. The unit is the caller's
9
- * assertion: no conversion happens, so reach for `fromMicro`/`fromMilli`/`fromSecond`
10
- * when the source has a unit.
11
- */
12
- export declare const Nano: {
13
- readonly zero: Nano;
14
- readonly fromMicro: (us: Micro) => Nano;
15
- readonly fromMilli: (ms: Milli) => Nano;
16
- readonly fromSecond: (s: Second) => Nano;
17
- readonly toMicro: (ns: Nano) => Micro;
18
- readonly toMilli: (ns: Nano) => Milli;
19
- readonly toSecond: (ns: Nano) => Second;
20
- readonly now: () => Nano;
21
- readonly add: (a: Nano, b: Nano) => Nano;
22
- readonly sub: (a: Nano, b: Nano) => Nano;
23
- readonly mul: (a: Nano, b: number) => Nano;
24
- readonly div: (a: Nano, b: number) => Nano;
25
- readonly max: (a: Nano, b: Nano) => Nano;
26
- readonly min: (a: Nano, b: Nano) => Nano;
11
+ /** Constructors, conversions, and arithmetic for {@link Nano} values. */
12
+ export declare const Nano: ((value: number) => Nano) & {
13
+ zero: Nano;
14
+ fromMicro: (us: Micro) => Nano;
15
+ fromMilli: (ms: Milli) => Nano;
16
+ fromSecond: (s: Second) => Nano;
17
+ toMicro: (ns: Nano) => Micro;
18
+ toMilli: (ns: Nano) => Milli;
19
+ toSecond: (ns: Nano) => Second;
20
+ now: () => Nano;
21
+ add: (a: Nano, b: Nano) => Nano;
22
+ sub: (a: Nano, b: Nano) => Nano;
23
+ mul: (a: Nano, b: number) => Nano;
24
+ div: (a: Nano, b: number) => Nano;
25
+ max: (a: Nano, b: Nano) => Nano;
26
+ min: (a: Nano, b: Nano) => Nano;
27
27
  };
28
28
  /** A duration in microseconds, branded so it can't be mixed with other units. */
29
29
  export type Micro = number & {
30
30
  readonly _brand: "micro";
31
31
  };
32
- /**
33
- * Constructors, conversions, and arithmetic for {@link Micro} values.
34
- *
35
- * Calling `Micro(x)` brands a raw number as microseconds. This asserts the unit
36
- * rather than converting, so use `fromNano`/`fromMilli`/`fromSecond` to convert
37
- * from another unit.
38
- */
39
- export declare const Micro: {
40
- readonly zero: Micro;
41
- readonly fromNano: (ns: Nano) => Micro;
42
- readonly fromMilli: (ms: Milli) => Micro;
43
- readonly fromSecond: (s: Second) => Micro;
44
- readonly toNano: (us: Micro) => Nano;
45
- readonly toMilli: (us: Micro) => Milli;
46
- readonly toSecond: (us: Micro) => Second;
47
- readonly now: () => Micro;
48
- readonly add: (a: Micro, b: Micro) => Micro;
49
- readonly sub: (a: Micro, b: Micro) => Micro;
50
- readonly mul: (a: Micro, b: number) => Micro;
51
- readonly div: (a: Micro, b: number) => Micro;
52
- readonly max: (a: Micro, b: Micro) => Micro;
53
- readonly min: (a: Micro, b: Micro) => Micro;
32
+ /** Constructors, conversions, and arithmetic for {@link Micro} values. */
33
+ export declare const Micro: ((value: number) => Micro) & {
34
+ zero: Micro;
35
+ fromNano: (ns: Nano) => Micro;
36
+ fromMilli: (ms: Milli) => Micro;
37
+ fromSecond: (s: Second) => Micro;
38
+ toNano: (us: Micro) => Nano;
39
+ toMilli: (us: Micro) => Milli;
40
+ toSecond: (us: Micro) => Second;
41
+ now: () => Micro;
42
+ add: (a: Micro, b: Micro) => Micro;
43
+ sub: (a: Micro, b: Micro) => Micro;
44
+ mul: (a: Micro, b: number) => Micro;
45
+ div: (a: Micro, b: number) => Micro;
46
+ max: (a: Micro, b: Micro) => Micro;
47
+ min: (a: Micro, b: Micro) => Micro;
54
48
  };
55
49
  /** A duration in milliseconds, branded so it can't be mixed with other units. */
56
50
  export type Milli = number & {
57
51
  readonly _brand: "milli";
58
52
  };
53
+ /** Constructors, conversions, and arithmetic for {@link Milli} values. */
54
+ export declare const Milli: ((value: number) => Milli) & {
55
+ zero: Milli;
56
+ fromNano: (ns: Nano) => Milli;
57
+ fromMicro: (us: Micro) => Milli;
58
+ fromSecond: (s: Second) => Milli;
59
+ toNano: (ms: Milli) => Nano;
60
+ toMicro: (ms: Milli) => Micro;
61
+ toSecond: (ms: Milli) => Second;
62
+ now: () => Milli;
63
+ add: (a: Milli, b: Milli) => Milli;
64
+ sub: (a: Milli, b: Milli) => Milli;
65
+ mul: (a: Milli, b: number) => Milli;
66
+ div: (a: Milli, b: number) => Milli;
67
+ max: (a: Milli, b: Milli) => Milli;
68
+ min: (a: Milli, b: Milli) => Milli;
69
+ };
70
+ /** Units per second for a {@link Timestamp}'s value, e.g. `1000` for milliseconds. */
71
+ export type Timescale = number & {
72
+ readonly _brand: "timescale";
73
+ };
74
+ /** Named timescales and a checked constructor (rejects non-positive / non-integer values). */
75
+ export declare const Timescale: ((unitsPerSecond: number) => Timescale) & {
76
+ /** One unit per second. */
77
+ SECOND: Timescale;
78
+ /** 1,000 units per second. */
79
+ MILLI: Timescale;
80
+ /** 1,000,000 units per second. */
81
+ MICRO: Timescale;
82
+ /** 1,000,000,000 units per second. */
83
+ NANO: Timescale;
84
+ };
59
85
  /**
60
- * Constructors, conversions, and arithmetic for {@link Milli} values.
86
+ * A presentation timestamp: a raw value in a given {@link Timescale}.
61
87
  *
62
- * Calling `Milli(x)` brands a raw number as milliseconds. This asserts the unit
63
- * rather than converting, so use `fromNano`/`fromMicro`/`fromSecond` to convert
64
- * from another unit.
88
+ * Mirrors the Rust `Timestamp`. Unlike the bare `Milli`/`Micro` aliases it carries its
89
+ * own scale, so a track can pick its units and conversions can't silently mix them up.
65
90
  */
66
- export declare const Milli: {
67
- readonly zero: Milli;
68
- readonly fromNano: (ns: Nano) => Milli;
69
- readonly fromMicro: (us: Micro) => Milli;
70
- readonly fromSecond: (s: Second) => Milli;
71
- readonly toNano: (ms: Milli) => Nano;
72
- readonly toMicro: (ms: Milli) => Micro;
73
- readonly toSecond: (ms: Milli) => Second;
74
- readonly now: () => Milli;
75
- readonly add: (a: Milli, b: Milli) => Milli;
76
- readonly sub: (a: Milli, b: Milli) => Milli;
77
- readonly mul: (a: Milli, b: number) => Milli;
78
- readonly div: (a: Milli, b: number) => Milli;
79
- readonly max: (a: Milli, b: Milli) => Milli;
80
- readonly min: (a: Milli, b: Milli) => Milli;
81
- };
91
+ export declare class Timestamp {
92
+ /** The raw value, in `scale` units. */
93
+ readonly value: number;
94
+ /** Units per second the {@link value} is measured in. */
95
+ readonly scale: Timescale;
96
+ /** Build a timestamp of `value` units at `scale`. */
97
+ constructor(value: number, scale: Timescale);
98
+ /** Monotonic now (`performance.now()`, milliseconds since page load), not wall-clock time. */
99
+ static now(): Timestamp;
100
+ /** A timestamp of `ms` milliseconds. */
101
+ static fromMillis(ms: number): Timestamp;
102
+ /** A timestamp of `us` microseconds. */
103
+ static fromMicros(us: number): Timestamp;
104
+ /** This timestamp's value re-expressed at `scale` (a raw number, not a new Timestamp). */
105
+ as(scale: Timescale): number;
106
+ /** The value in milliseconds. */
107
+ asMillis(): number;
108
+ /** The value in microseconds. */
109
+ asMicros(): number;
110
+ }
82
111
  /** A duration in seconds, branded so it can't be mixed with other units. */
83
112
  export type Second = number & {
84
113
  readonly _brand: "second";
85
114
  };
86
- /**
87
- * Constructors, conversions, and arithmetic for {@link Second} values.
88
- *
89
- * Calling `Second(x)` brands a raw number as seconds. This asserts the unit
90
- * rather than converting, so use `fromNano`/`fromMicro`/`fromMilli` to convert
91
- * from another unit.
92
- */
93
- export declare const Second: {
94
- readonly zero: Second;
95
- readonly fromNano: (ns: Nano) => Second;
96
- readonly fromMicro: (us: Micro) => Second;
97
- readonly fromMilli: (ms: Milli) => Second;
98
- readonly toNano: (s: Second) => Nano;
99
- readonly toMicro: (s: Second) => Micro;
100
- readonly toMilli: (s: Second) => Milli;
101
- readonly now: () => Second;
102
- readonly add: (a: Second, b: Second) => Second;
103
- readonly sub: (a: Second, b: Second) => Second;
104
- readonly mul: (a: Second, b: number) => Second;
105
- readonly div: (a: Second, b: number) => Second;
106
- readonly max: (a: Second, b: Second) => Second;
107
- readonly min: (a: Second, b: Second) => Second;
115
+ /** Constructors, conversions, and arithmetic for {@link Second} values. */
116
+ export declare const Second: ((value: number) => Second) & {
117
+ zero: Second;
118
+ fromNano: (ns: Nano) => Second;
119
+ fromMicro: (us: Micro) => Second;
120
+ fromMilli: (ms: Milli) => Second;
121
+ toNano: (s: Second) => Nano;
122
+ toMicro: (s: Second) => Micro;
123
+ toMilli: (s: Second) => Milli;
124
+ now: () => Second;
125
+ add: (a: Second, b: Second) => Second;
126
+ sub: (a: Second, b: Second) => Second;
127
+ mul: (a: Second, b: number) => Second;
128
+ div: (a: Second, b: number) => Second;
129
+ max: (a: Second, b: Second) => Second;
130
+ min: (a: Second, b: Second) => Second;
108
131
  };
109
132
  //# sourceMappingURL=time.d.ts.map
package/time.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../src/time.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,MAAM,MAAM,IAAI,GAAG,MAAM,GAAG;I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