@moq/net 0.4.8 → 0.22.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.
- package/README.md +7 -1
- package/announce.d.ts +1 -1
- package/announce.d.ts.map +1 -1
- package/announce.js +1 -1
- package/announce.js.map +1 -1
- package/announced.d.ts +51 -47
- package/announced.d.ts.map +1 -1
- package/announced.js +183 -31
- package/announced.js.map +1 -1
- package/announced.test-util.d.ts +2 -0
- package/announced.test-util.d.ts.map +1 -0
- package/announced.test-util.js +27 -0
- package/announced.test-util.js.map +1 -0
- package/auth.d.ts +64 -0
- package/auth.d.ts.map +1 -0
- package/auth.js +20 -0
- package/auth.js.map +1 -0
- package/auth_gate.d.ts +2 -0
- package/auth_gate.d.ts.map +1 -0
- package/auth_gate.js +24 -0
- package/auth_gate.js.map +1 -0
- package/auth_session.d.ts +49 -0
- package/auth_session.d.ts.map +1 -0
- package/auth_session.js +1097 -0
- package/auth_session.js.map +1 -0
- package/bandwidth.d.ts +129 -25
- package/bandwidth.d.ts.map +1 -1
- package/bandwidth.js +410 -138
- package/bandwidth.js.map +1 -1
- package/bandwidth_api.d.ts +1 -1
- package/bandwidth_api.d.ts.map +1 -1
- package/bandwidth_api.js +1 -1
- package/bandwidth_api.js.map +1 -1
- package/broadcast.d.ts +62 -36
- package/broadcast.d.ts.map +1 -1
- package/broadcast.js +556 -172
- package/broadcast.js.map +1 -1
- package/cache.d.ts +103 -0
- package/cache.d.ts.map +1 -0
- package/cache.js +254 -0
- package/cache.js.map +1 -0
- package/claim.test-util.d.ts +5 -0
- package/claim.test-util.d.ts.map +1 -0
- package/claim.test-util.js +13 -0
- package/claim.test-util.js.map +1 -0
- package/connection/accept.d.ts +20 -12
- package/connection/accept.d.ts.map +1 -1
- package/connection/accept.js +97 -129
- package/connection/accept.js.map +1 -1
- package/connection/browser.d.ts.map +1 -1
- package/connection/browser.js +28 -19
- package/connection/browser.js.map +1 -1
- package/connection/connect.d.ts +119 -23
- package/connection/connect.d.ts.map +1 -1
- package/connection/connect.js +535 -216
- package/connection/connect.js.map +1 -1
- package/connection/dials.d.ts +45 -0
- package/connection/dials.d.ts.map +1 -0
- package/connection/dials.js +109 -0
- package/connection/dials.js.map +1 -0
- package/connection/endpoint.d.ts +60 -0
- package/connection/endpoint.d.ts.map +1 -0
- package/connection/endpoint.js +114 -0
- package/connection/endpoint.js.map +1 -0
- package/connection/forward.d.ts +7 -1
- package/connection/forward.d.ts.map +1 -1
- package/connection/forward.js +265 -80
- package/connection/forward.js.map +1 -1
- package/connection/goaway.d.ts +16 -9
- package/connection/goaway.d.ts.map +1 -1
- package/connection/goaway.js +22 -108
- package/connection/goaway.js.map +1 -1
- package/connection/handshake.d.ts +32 -6
- package/connection/handshake.d.ts.map +1 -1
- package/connection/handshake.js +97 -20
- package/connection/handshake.js.map +1 -1
- package/connection/index.d.ts +3 -6
- package/connection/index.d.ts.map +1 -1
- package/connection/index.js +1 -2
- package/connection/index.js.map +1 -1
- package/connection/liveness.d.ts +14 -0
- package/connection/liveness.d.ts.map +1 -0
- package/connection/liveness.js +30 -0
- package/connection/liveness.js.map +1 -0
- package/connection/pool.d.ts +137 -58
- package/connection/pool.d.ts.map +1 -1
- package/connection/pool.js +281 -117
- package/connection/pool.js.map +1 -1
- package/connection/reload.d.ts +60 -12
- package/connection/reload.d.ts.map +1 -1
- package/connection/reload.js +859 -233
- package/connection/reload.js.map +1 -1
- package/connection/session.d.ts +91 -0
- package/connection/session.d.ts.map +1 -0
- package/connection/session.js +2 -0
- package/connection/session.js.map +1 -0
- package/connection/stats.d.ts +20 -11
- package/connection/stats.d.ts.map +1 -1
- package/connection/stats.js +64 -8
- package/connection/stats.js.map +1 -1
- package/connection/ticker.d.ts +4 -0
- package/connection/ticker.d.ts.map +1 -0
- package/connection/ticker.js +66 -0
- package/connection/ticker.js.map +1 -0
- package/connection/tokens.d.ts +2 -0
- package/connection/tokens.d.ts.map +1 -0
- package/connection/tokens.js +404 -0
- package/connection/tokens.js.map +1 -0
- package/connection/transport.d.ts.map +1 -1
- package/connection/transport.js +4 -4
- package/connection/transport.js.map +1 -1
- package/connection/withdrawal.d.ts +2 -0
- package/connection/withdrawal.d.ts.map +1 -0
- package/connection/withdrawal.js +23 -0
- package/connection/withdrawal.js.map +1 -0
- package/consume.js +213 -46
- package/consume.js.map +1 -1
- package/cover.d.ts +59 -0
- package/cover.d.ts.map +1 -0
- package/cover.js +375 -0
- package/cover.js.map +1 -0
- package/datagram.d.ts +70 -11
- package/datagram.d.ts.map +1 -1
- package/datagram.js +317 -1
- package/datagram.js.map +1 -1
- package/datagram_stream.d.ts +18 -0
- package/datagram_stream.d.ts.map +1 -0
- package/datagram_stream.js +67 -0
- package/datagram_stream.js.map +1 -0
- package/defined.test-util.d.ts +2 -0
- package/defined.test-util.d.ts.map +1 -0
- package/defined.test-util.js +7 -0
- package/defined.test-util.js.map +1 -0
- package/delivered.d.ts +75 -0
- package/delivered.d.ts.map +1 -0
- package/delivered.js +228 -0
- package/delivered.js.map +1 -0
- package/demand.d.ts +173 -0
- package/demand.d.ts.map +1 -0
- package/demand.js +582 -0
- package/demand.js.map +1 -0
- package/drops.d.ts +93 -0
- package/drops.d.ts.map +1 -0
- package/drops.js +283 -0
- package/drops.js.map +1 -0
- package/error.d.ts +120 -21
- package/error.d.ts.map +1 -1
- package/error.js +230 -37
- package/error.js.map +1 -1
- package/errors.d.ts +2 -2
- package/errors.d.ts.map +1 -1
- package/errors.js +2 -2
- package/errors.js.map +1 -1
- package/fill.d.ts +174 -0
- package/fill.d.ts.map +1 -0
- package/fill.js +760 -0
- package/fill.js.map +1 -0
- package/flate/decoder.d.ts +2 -0
- package/flate/decoder.d.ts.map +1 -0
- package/flate/decoder.js +63 -0
- package/flate/decoder.js.map +1 -0
- package/flate/encoder.d.ts +2 -0
- package/flate/encoder.d.ts.map +1 -0
- package/flate/encoder.js +64 -0
- package/flate/encoder.js.map +1 -0
- package/flate/group.d.ts +34 -0
- package/flate/group.d.ts.map +1 -0
- package/flate/group.js +140 -0
- package/flate/group.js.map +1 -0
- package/frame.d.ts +80 -0
- package/frame.d.ts.map +1 -0
- package/frame.js +296 -0
- package/frame.js.map +1 -0
- package/frame.test-util.d.ts +5 -0
- package/frame.test-util.d.ts.map +1 -0
- package/frame.test-util.js +9 -0
- package/frame.test-util.js.map +1 -0
- package/group.d.ts +108 -45
- package/group.d.ts.map +1 -1
- package/group.js +1616 -307
- package/group.js.map +1 -1
- package/group_api.d.ts +7 -0
- package/group_api.d.ts.map +1 -0
- package/group_api.js +7 -0
- package/group_api.js.map +1 -0
- package/hop.d.ts +62 -76
- package/hop.d.ts.map +1 -1
- package/hop.js +92 -64
- package/hop.js.map +1 -1
- package/identity.d.ts +39 -0
- package/identity.d.ts.map +1 -0
- package/identity.js +47 -0
- package/identity.js.map +1 -0
- package/ietf/active_count.d.ts +2 -0
- package/ietf/active_count.d.ts.map +1 -0
- package/ietf/active_count.js +30 -0
- package/ietf/active_count.js.map +1 -0
- package/ietf/aliases.js +69 -35
- package/ietf/aliases.js.map +1 -1
- package/ietf/cluster.d.ts +3 -3
- package/ietf/cluster.js +14 -62
- package/ietf/cluster.js.map +1 -1
- package/ietf/connection.d.ts +1 -31
- package/ietf/connection.d.ts.map +1 -1
- package/ietf/connection.js +305 -143
- package/ietf/connection.js.map +1 -1
- package/ietf/datagram.d.ts +60 -0
- package/ietf/datagram.d.ts.map +1 -0
- package/ietf/datagram.js +152 -0
- package/ietf/datagram.js.map +1 -0
- package/ietf/error.d.ts +3 -3
- package/ietf/error.js +82 -100
- package/ietf/error.js.map +1 -1
- package/ietf/fetch.d.ts +91 -35
- package/ietf/fetch.d.ts.map +1 -1
- package/ietf/fetch.js +172 -93
- package/ietf/fetch.js.map +1 -1
- package/ietf/filter.d.ts +20 -30
- package/ietf/filter.d.ts.map +1 -1
- package/ietf/filter.js +140 -171
- package/ietf/filter.js.map +1 -1
- package/ietf/goaway.d.ts +11 -9
- package/ietf/goaway.d.ts.map +1 -1
- package/ietf/goaway.js +22 -35
- package/ietf/goaway.js.map +1 -1
- package/ietf/hidden.js +1 -1
- package/ietf/hidden.js.map +1 -1
- package/ietf/index.d.ts +2 -14
- package/ietf/index.d.ts.map +1 -1
- package/ietf/index.js +4 -14
- package/ietf/index.js.map +1 -1
- package/ietf/join.d.ts +7 -0
- package/ietf/join.d.ts.map +1 -0
- package/ietf/join.js +234 -0
- package/ietf/join.js.map +1 -0
- package/ietf/message.d.ts +18 -2
- package/ietf/message.d.ts.map +1 -1
- package/ietf/message.js +60 -40
- package/ietf/message.js.map +1 -1
- package/ietf/message.test-util.d.ts +6 -0
- package/ietf/message.test-util.d.ts.map +1 -0
- package/ietf/message.test-util.js +13 -0
- package/ietf/message.test-util.js.map +1 -0
- package/ietf/namespace.d.ts +17 -3
- package/ietf/namespace.d.ts.map +1 -1
- package/ietf/namespace.js +78 -26
- package/ietf/namespace.js.map +1 -1
- package/ietf/object.d.ts +194 -32
- package/ietf/object.d.ts.map +1 -1
- package/ietf/object.js +405 -178
- package/ietf/object.js.map +1 -1
- package/ietf/parameters.d.ts +22 -42
- package/ietf/parameters.d.ts.map +1 -1
- package/ietf/parameters.js +260 -472
- package/ietf/parameters.js.map +1 -1
- package/ietf/priority.d.ts +17 -2
- package/ietf/priority.d.ts.map +1 -1
- package/ietf/priority.js +19 -4
- package/ietf/priority.js.map +1 -1
- package/ietf/properties.d.ts +5 -4
- package/ietf/properties.d.ts.map +1 -1
- package/ietf/properties.js +78 -48
- package/ietf/properties.js.map +1 -1
- package/ietf/publish.d.ts +22 -30
- package/ietf/publish.d.ts.map +1 -1
- package/ietf/publish.js +45 -139
- package/ietf/publish.js.map +1 -1
- package/ietf/publish_namespace.d.ts +46 -69
- package/ietf/publish_namespace.d.ts.map +1 -1
- package/ietf/publish_namespace.js +66 -184
- package/ietf/publish_namespace.js.map +1 -1
- package/ietf/publisher.js +1800 -600
- package/ietf/publisher.js.map +1 -1
- package/ietf/range.d.ts +2 -0
- package/ietf/range.d.ts.map +1 -0
- package/ietf/range.js +222 -0
- package/ietf/range.js.map +1 -0
- package/ietf/request.d.ts +3 -27
- package/ietf/request.d.ts.map +1 -1
- package/ietf/request.js +41 -78
- package/ietf/request.js.map +1 -1
- package/ietf/request_stream.d.ts +1 -6
- package/ietf/request_stream.d.ts.map +1 -1
- package/ietf/request_stream.js +306 -16
- package/ietf/request_stream.js.map +1 -1
- package/ietf/session.d.ts +41 -0
- package/ietf/session.d.ts.map +1 -0
- package/ietf/session.js +65 -0
- package/ietf/session.js.map +1 -0
- package/ietf/setup.d.ts +4 -29
- package/ietf/setup.d.ts.map +1 -1
- package/ietf/setup.js +6 -117
- package/ietf/setup.js.map +1 -1
- package/ietf/setup_options.d.ts +31 -0
- package/ietf/setup_options.d.ts.map +1 -0
- package/ietf/setup_options.js +138 -0
- package/ietf/setup_options.js.map +1 -0
- package/ietf/solicit.js +4 -14
- package/ietf/solicit.js.map +1 -1
- package/ietf/subscribe.d.ts +48 -41
- package/ietf/subscribe.d.ts.map +1 -1
- package/ietf/subscribe.js +118 -239
- package/ietf/subscribe.js.map +1 -1
- package/ietf/subscribe_namespace.d.ts +13 -76
- package/ietf/subscribe_namespace.d.ts.map +1 -1
- package/ietf/subscribe_namespace.js +30 -201
- package/ietf/subscribe_namespace.js.map +1 -1
- package/ietf/subscriber.js +1839 -536
- package/ietf/subscriber.js.map +1 -1
- package/ietf/token.js +105 -27
- package/ietf/token.js.map +1 -1
- package/ietf/track.d.ts +25 -22
- package/ietf/track.d.ts.map +1 -1
- package/ietf/track.js +48 -61
- package/ietf/track.js.map +1 -1
- package/ietf/version.d.ts +13 -42
- package/ietf/version.d.ts.map +1 -1
- package/ietf/version.js +22 -48
- package/ietf/version.js.map +1 -1
- package/implementation.d.ts +2 -0
- package/implementation.d.ts.map +1 -0
- package/implementation.js +5 -0
- package/implementation.js.map +1 -0
- package/index.d.ts +25 -10
- package/index.d.ts.map +1 -1
- package/index.js +19 -6
- package/index.js.map +1 -1
- package/internal.d.ts +1512 -64
- package/internal.d.ts.map +1 -1
- package/internal.js +557 -79
- package/internal.js.map +1 -1
- package/ledger.d.ts +23 -0
- package/ledger.d.ts.map +1 -0
- package/ledger.js +247 -0
- package/ledger.js.map +1 -0
- package/listing.d.ts +132 -0
- package/listing.d.ts.map +1 -0
- package/listing.js +486 -0
- package/listing.js.map +1 -0
- package/lite/announce.d.ts +124 -63
- package/lite/announce.d.ts.map +1 -1
- package/lite/announce.js +384 -158
- package/lite/announce.js.map +1 -1
- package/lite/announce_stream.d.ts +2 -0
- package/lite/announce_stream.d.ts.map +1 -0
- package/lite/announce_stream.js +92 -0
- package/lite/announce_stream.js.map +1 -0
- package/lite/answer.d.ts +22 -0
- package/lite/answer.d.ts.map +1 -0
- package/lite/answer.js +301 -0
- package/lite/answer.js.map +1 -0
- package/lite/auth.d.ts +45 -0
- package/lite/auth.d.ts.map +1 -0
- package/lite/auth.js +204 -0
- package/lite/auth.js.map +1 -0
- package/lite/compat.d.ts +31 -0
- package/lite/compat.d.ts.map +1 -0
- package/lite/compat.js +86 -0
- package/lite/compat.js.map +1 -0
- package/lite/connection.d.ts +1 -45
- package/lite/connection.d.ts.map +1 -1
- package/lite/connection.js +360 -77
- package/lite/connection.js.map +1 -1
- package/lite/datagram-end.d.ts +26 -0
- package/lite/datagram-end.d.ts.map +1 -0
- package/lite/datagram-end.js +30 -0
- package/lite/datagram-end.js.map +1 -0
- package/lite/datagram.d.ts +73 -8
- package/lite/datagram.d.ts.map +1 -1
- package/lite/datagram.js +144 -9
- package/lite/datagram.js.map +1 -1
- package/lite/duration.d.ts +6 -0
- package/lite/duration.d.ts.map +1 -0
- package/lite/duration.js +14 -0
- package/lite/duration.js.map +1 -0
- package/lite/error.d.ts +9 -0
- package/lite/error.d.ts.map +1 -0
- package/lite/error.js +24 -0
- package/lite/error.js.map +1 -0
- package/lite/fills.d.ts +162 -0
- package/lite/fills.d.ts.map +1 -0
- package/lite/fills.js +486 -0
- package/lite/fills.js.map +1 -0
- package/lite/fit.d.ts +49 -0
- package/lite/fit.d.ts.map +1 -0
- package/lite/fit.js +305 -0
- package/lite/fit.js.map +1 -0
- package/lite/goaway.d.ts +1 -1
- package/lite/goaway.d.ts.map +1 -1
- package/lite/goaway.js +5 -13
- package/lite/goaway.js.map +1 -1
- package/lite/group.d.ts +64 -13
- package/lite/group.d.ts.map +1 -1
- package/lite/group.js +108 -30
- package/lite/group.js.map +1 -1
- package/lite/identity.d.ts +25 -0
- package/lite/identity.d.ts.map +1 -0
- package/lite/identity.js +79 -0
- package/lite/identity.js.map +1 -0
- package/lite/index.d.ts +2 -1
- package/lite/index.d.ts.map +1 -1
- package/lite/index.js +2 -1
- package/lite/index.js.map +1 -1
- package/lite/message.d.ts +9 -1
- package/lite/message.d.ts.map +1 -1
- package/lite/message.js +28 -44
- package/lite/message.js.map +1 -1
- package/lite/priority.d.ts +9 -2
- package/lite/priority.d.ts.map +1 -1
- package/lite/priority.js +11 -105
- package/lite/priority.js.map +1 -1
- package/lite/probe.d.ts.map +1 -1
- package/lite/probe.js +9 -0
- package/lite/probe.js.map +1 -1
- package/lite/publisher.d.ts +10 -1
- package/lite/publisher.d.ts.map +1 -1
- package/lite/publisher.js +2548 -437
- package/lite/publisher.js.map +1 -1
- package/lite/routed.d.ts +59 -0
- package/lite/routed.d.ts.map +1 -0
- package/lite/routed.js +564 -0
- package/lite/routed.js.map +1 -0
- package/lite/session.d.ts +1 -27
- package/lite/session.d.ts.map +1 -1
- package/lite/session.js +0 -99
- package/lite/session.js.map +1 -1
- package/lite/setup.d.ts +29 -2
- package/lite/setup.d.ts.map +1 -1
- package/lite/setup.js +95 -21
- package/lite/setup.js.map +1 -1
- package/lite/stream.d.ts +5 -11
- package/lite/stream.d.ts.map +1 -1
- package/lite/stream.js +5 -1
- package/lite/stream.js.map +1 -1
- package/lite/subscribe.d.ts +475 -75
- package/lite/subscribe.d.ts.map +1 -1
- package/lite/subscribe.js +1373 -142
- package/lite/subscribe.js.map +1 -1
- package/lite/subscriber.d.ts +7 -44
- package/lite/subscriber.d.ts.map +1 -1
- package/lite/subscriber.js +3290 -515
- package/lite/subscriber.js.map +1 -1
- package/lite/track.d.ts +24 -9
- package/lite/track.d.ts.map +1 -1
- package/lite/track.js +116 -37
- package/lite/track.js.map +1 -1
- package/lite/tracks.d.ts +55 -0
- package/lite/tracks.d.ts.map +1 -0
- package/lite/tracks.js +114 -0
- package/lite/tracks.js.map +1 -0
- package/lite/version.d.ts +132 -24
- package/lite/version.d.ts.map +1 -1
- package/lite/version.js +378 -33
- package/lite/version.js.map +1 -1
- package/meta.d.ts +77 -0
- package/meta.d.ts.map +1 -0
- package/meta.js +130 -0
- package/meta.js.map +1 -0
- package/meta_api.d.ts +7 -0
- package/meta_api.d.ts.map +1 -0
- package/meta_api.js +7 -0
- package/meta_api.js.map +1 -0
- package/mint.d.ts +28 -0
- package/mint.d.ts.map +1 -0
- package/mint.js +66 -0
- package/mint.js.map +1 -0
- package/open.d.ts +63 -0
- package/open.d.ts.map +1 -0
- package/open.js +250 -0
- package/open.js.map +1 -0
- package/origin.d.ts +392 -140
- package/origin.d.ts.map +1 -1
- package/origin.js +2533 -686
- package/origin.js.map +1 -1
- package/package.json +8 -13
- package/path.d.ts +51 -51
- package/path.d.ts.map +1 -1
- package/path.js +210 -57
- package/path.js.map +1 -1
- package/payload.d.ts +33 -0
- package/payload.d.ts.map +1 -0
- package/payload.js +65 -0
- package/payload.js.map +1 -0
- package/prefix.d.ts +152 -0
- package/prefix.d.ts.map +1 -0
- package/prefix.js +349 -0
- package/prefix.js.map +1 -0
- package/priority.d.ts +8 -0
- package/priority.d.ts.map +1 -0
- package/priority.js +185 -0
- package/priority.js.map +1 -0
- package/queue.d.ts +2 -0
- package/queue.d.ts.map +1 -0
- package/queue.js +46 -0
- package/queue.js.map +1 -0
- package/ranges.d.ts +36 -0
- package/ranges.d.ts.map +1 -0
- package/ranges.js +312 -0
- package/ranges.js.map +1 -0
- package/rescale.d.ts +24 -0
- package/rescale.d.ts.map +1 -0
- package/rescale.js +39 -0
- package/rescale.js.map +1 -0
- package/resume.d.ts +55 -0
- package/resume.d.ts.map +1 -0
- package/resume.js +4173 -0
- package/resume.js.map +1 -0
- package/resume.test-util.d.ts +2 -0
- package/resume.test-util.d.ts.map +1 -0
- package/resume.test-util.js +25 -0
- package/resume.test-util.js.map +1 -0
- package/skips.d.ts +48 -0
- package/skips.d.ts.map +1 -0
- package/skips.js +182 -0
- package/skips.js.map +1 -0
- package/stream.d.ts +75 -37
- package/stream.d.ts.map +1 -1
- package/stream.js +236 -92
- package/stream.js.map +1 -1
- package/subscription.test-util.d.ts +2 -0
- package/subscription.test-util.d.ts.map +1 -0
- package/subscription.test-util.js +49 -0
- package/subscription.test-util.js.map +1 -0
- package/tail.d.ts +23 -14
- package/tail.d.ts.map +1 -1
- package/tail.js +224 -97
- package/tail.js.map +1 -1
- package/time.d.ts +41 -102
- package/time.d.ts.map +1 -1
- package/time.js +129 -91
- package/time.js.map +1 -1
- package/timed.d.ts +21 -0
- package/timed.d.ts.map +1 -0
- package/timed.js +2 -0
- package/timed.js.map +1 -0
- package/track.d.ts +577 -245
- package/track.d.ts.map +1 -1
- package/track.js +7306 -771
- package/track.js.map +1 -1
- package/track_api.d.ts +7 -0
- package/track_api.d.ts.map +1 -0
- package/track_api.js +7 -0
- package/track_api.js.map +1 -0
- package/util/abort.d.ts +1 -0
- package/util/abort.d.ts.map +1 -1
- package/util/abort.js +23 -1
- package/util/abort.js.map +1 -1
- package/util/announce.d.ts +4 -0
- package/util/announce.d.ts.map +1 -0
- package/util/announce.js +11 -0
- package/util/announce.js.map +1 -0
- package/util/bigint.d.ts +3 -0
- package/util/bigint.d.ts.map +1 -0
- package/util/bigint.js +8 -0
- package/util/bigint.js.map +1 -0
- package/util/change.d.ts +12 -0
- package/util/change.d.ts.map +1 -0
- package/util/change.js +18 -0
- package/util/change.js.map +1 -0
- package/util/deadline.d.ts +2 -0
- package/util/deadline.d.ts.map +1 -0
- package/util/deadline.js +108 -0
- package/util/deadline.js.map +1 -0
- package/util/decode_error.d.ts +3 -0
- package/util/decode_error.d.ts.map +1 -0
- package/util/decode_error.js +11 -0
- package/util/decode_error.js.map +1 -0
- package/util/demand.d.ts +8 -0
- package/util/demand.d.ts.map +1 -0
- package/util/demand.js +24 -0
- package/util/demand.js.map +1 -0
- package/util/given_up.d.ts +2 -0
- package/util/given_up.d.ts.map +1 -0
- package/util/given_up.js +101 -0
- package/util/given_up.js.map +1 -0
- package/util/hex.d.ts +6 -0
- package/util/hex.d.ts.map +1 -1
- package/util/hex.js +19 -4
- package/util/hex.js.map +1 -1
- package/util/key.d.ts +15 -0
- package/util/key.d.ts.map +1 -0
- package/util/key.js +38 -0
- package/util/key.js.map +1 -0
- package/util/limits.d.ts +2 -0
- package/util/limits.d.ts.map +1 -0
- package/util/limits.js +76 -0
- package/util/limits.js.map +1 -0
- package/util/observed.d.ts +23 -0
- package/util/observed.d.ts.map +1 -0
- package/util/observed.js +122 -0
- package/util/observed.js.map +1 -0
- package/util/sorted.d.ts +2 -0
- package/util/sorted.d.ts.map +1 -0
- package/util/sorted.js +149 -0
- package/util/sorted.js.map +1 -0
- package/util/timeout.d.ts +2 -1
- package/util/timeout.d.ts.map +1 -1
- package/util/timeout.js +13 -9
- package/util/timeout.js.map +1 -1
- package/util/timer.d.ts +2 -0
- package/util/timer.d.ts.map +1 -0
- package/util/timer.js +19 -0
- package/util/timer.js.map +1 -0
- package/util/utf8.d.ts +2 -0
- package/util/utf8.d.ts.map +1 -1
- package/util/utf8.js +7 -1
- package/util/utf8.js.map +1 -1
- package/util/varint.d.ts.map +1 -1
- package/util/varint.js +8 -1
- package/util/varint.js.map +1 -1
- package/util/watch.d.ts +8 -0
- package/util/watch.d.ts.map +1 -0
- package/util/watch.js +38 -0
- package/util/watch.js.map +1 -0
- package/util/yield.d.ts +2 -0
- package/util/yield.d.ts.map +1 -0
- package/util/yield.js +31 -0
- package/util/yield.js.map +1 -0
- package/varint.d.ts +0 -29
- package/varint.d.ts.map +1 -1
- package/varint.js +7 -28
- package/varint.js.map +1 -1
- package/varint_api.d.ts +7 -0
- package/varint_api.d.ts.map +1 -0
- package/varint_api.js +7 -0
- package/varint_api.js.map +1 -0
- package/version.d.ts +2 -0
- package/version.d.ts.map +1 -0
- package/version.js +4 -0
- package/version.js.map +1 -0
- package/window.d.ts +570 -0
- package/window.d.ts.map +1 -0
- package/window.js +1677 -0
- package/window.js.map +1 -0
- package/wire.d.ts +145 -30
- package/wire.d.ts.map +1 -1
- package/wire.js +27 -0
- package/wire.js.map +1 -1
- package/connection/established.d.ts +0 -53
- package/connection/established.d.ts.map +0 -1
- package/connection/established.js +0 -2
- package/connection/established.js.map +0 -1
- package/ietf/adapter.d.ts +0 -75
- package/ietf/adapter.d.ts.map +0 -1
- package/ietf/adapter.js +0 -699
- package/ietf/adapter.js.map +0 -1
- package/lite/datagram_stream.d.ts +0 -8
- package/lite/datagram_stream.d.ts.map +0 -1
- package/lite/datagram_stream.js +0 -43
- package/lite/datagram_stream.js.map +0 -1
- package/lite/fetch.d.ts +0 -28
- package/lite/fetch.d.ts.map +0 -1
- package/lite/fetch.js +0 -78
- package/lite/fetch.js.map +0 -1
- package/util/log.d.ts +0 -5
- package/util/log.d.ts.map +0 -1
- package/util/log.js +0 -16
- package/util/log.js.map +0 -1
- package/zod.d.ts +0 -13
- package/zod.d.ts.map +0 -1
- package/zod.js +0 -18
- package/zod.js.map +0 -1
package/tail.js
CHANGED
|
@@ -1,21 +1,13 @@
|
|
|
1
|
+
import { now, sleep } from "@moq/clock";
|
|
1
2
|
import { Signal } from "@moq/signals";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* has ended the subscription.
|
|
6
|
-
*
|
|
7
|
-
* A group reset before its header arrived leaves no trace, and QUIC does not order streams,
|
|
8
|
-
* so a stream opened before the end can still be in flight after it. This bounds the wait on
|
|
9
|
-
* IETF, and on moq-lite when the subscription has no max age to bound it with.
|
|
10
|
-
*/
|
|
11
|
-
export const TAIL_GRACE_MS = Milli(1000);
|
|
12
|
-
// setTimeout truncates a longer delay to a signed 32-bit int and fires at once.
|
|
13
|
-
const MAX_TIMEOUT_MS = 2 ** 31 - 1;
|
|
3
|
+
import { insertRun, runGaps, runsFrom } from "./internal.js";
|
|
4
|
+
import { GRACE, Ledger, MAX_RUNS } from "./ledger.js";
|
|
5
|
+
import { max, min } from "./util/key.js";
|
|
14
6
|
/**
|
|
15
7
|
* The group streams a subscription has received, so its end can wait for the ones still owed.
|
|
16
8
|
*
|
|
17
9
|
* A publisher ends a subscription before every group stream it opened has necessarily
|
|
18
|
-
* arrived. This records which
|
|
10
|
+
* arrived. This records which keys are accounted for (a stream's header arrived, or
|
|
19
11
|
* the publisher dropped them) and how many streams are still being read, and {@link settle}
|
|
20
12
|
* waits on them.
|
|
21
13
|
*
|
|
@@ -25,140 +17,275 @@ const MAX_TIMEOUT_MS = 2 ** 31 - 1;
|
|
|
25
17
|
* @internal
|
|
26
18
|
*/
|
|
27
19
|
export class Tail {
|
|
28
|
-
//
|
|
29
|
-
|
|
30
|
-
//
|
|
31
|
-
// final: a later, longer grace or a lowered floor cannot reopen it.
|
|
32
|
-
#runs = [];
|
|
33
|
-
// Group streams whose header arrived, and those still being read.
|
|
20
|
+
// The keys accounted for, whose gaps fold once the grace stops waiting for them.
|
|
21
|
+
#ledger;
|
|
22
|
+
// Group streams whose header arrived, and those still being read and holding the end.
|
|
34
23
|
#streams = 0;
|
|
35
24
|
#active = 0;
|
|
25
|
+
// The counted streams holding the end open, which a settle gives up on once they go quiet.
|
|
26
|
+
#held = new Set();
|
|
27
|
+
// The lowest group a stream's header named, which proves the group exists.
|
|
28
|
+
#first;
|
|
36
29
|
#changed = new Signal(0);
|
|
37
30
|
#grace;
|
|
38
|
-
|
|
31
|
+
// Keys a drop named, so a stream whose header the drop overtook can be told from one
|
|
32
|
+
// whose gap the grace gave up on.
|
|
33
|
+
#dropped = [];
|
|
39
34
|
constructor(options = {}) {
|
|
40
|
-
this.#grace = options.grace ?? (() =>
|
|
41
|
-
this.#
|
|
35
|
+
this.#grace = options.grace ?? (() => GRACE);
|
|
36
|
+
this.#ledger = new Ledger({ proven: options.proven });
|
|
37
|
+
}
|
|
38
|
+
/** Release what the tail keeps beside its ledger, once its subscription ended. */
|
|
39
|
+
close() {
|
|
40
|
+
this.#dropped = [];
|
|
41
|
+
this.#held.clear();
|
|
42
42
|
}
|
|
43
43
|
/** Group streams whose header arrived, whether they finished or were reset. */
|
|
44
44
|
get streams() {
|
|
45
45
|
return this.#streams;
|
|
46
46
|
}
|
|
47
|
+
/** The lowest group whose stream's header arrived. */
|
|
48
|
+
get first() {
|
|
49
|
+
return this.#first;
|
|
50
|
+
}
|
|
47
51
|
/**
|
|
48
|
-
* Record a group stream whose header arrived
|
|
49
|
-
*
|
|
52
|
+
* Record a group stream whose header arrived, held until it is read to its end. `last` says
|
|
53
|
+
* when it last delivered data, so a settle can give up on a quiet one; without it the stream is
|
|
54
|
+
* waited for until it ends, which is what a reader that cannot tell its stream is lost wants.
|
|
50
55
|
*/
|
|
51
|
-
open(
|
|
56
|
+
open(key, last) {
|
|
52
57
|
this.#streams += 1;
|
|
58
|
+
if (this.#first === undefined || key < this.#first)
|
|
59
|
+
this.#first = key;
|
|
60
|
+
this.#active += 1;
|
|
61
|
+
this.#account(key, key + 1n);
|
|
62
|
+
let stall;
|
|
63
|
+
const stalled = new Promise((resolve) => {
|
|
64
|
+
stall = resolve;
|
|
65
|
+
});
|
|
66
|
+
const held = last && { last, since: now(), stalled: false, stall };
|
|
67
|
+
if (held)
|
|
68
|
+
this.#held.add(held);
|
|
69
|
+
// Parked holds nothing.
|
|
70
|
+
let state = "held";
|
|
71
|
+
return {
|
|
72
|
+
stalled,
|
|
73
|
+
done: () => {
|
|
74
|
+
if (state === "done")
|
|
75
|
+
return;
|
|
76
|
+
if (state === "held")
|
|
77
|
+
this.#active -= 1;
|
|
78
|
+
if (held)
|
|
79
|
+
this.#held.delete(held);
|
|
80
|
+
state = "done";
|
|
81
|
+
this.#bump();
|
|
82
|
+
},
|
|
83
|
+
park: () => {
|
|
84
|
+
if (state !== "held")
|
|
85
|
+
return;
|
|
86
|
+
state = "parked";
|
|
87
|
+
this.#active -= 1;
|
|
88
|
+
if (held)
|
|
89
|
+
this.#held.delete(held);
|
|
90
|
+
this.#bump();
|
|
91
|
+
},
|
|
92
|
+
resume: () => {
|
|
93
|
+
if (state !== "parked")
|
|
94
|
+
return;
|
|
95
|
+
state = "held";
|
|
96
|
+
this.#active += 1;
|
|
97
|
+
if (held && !held.stalled) {
|
|
98
|
+
held.since = now();
|
|
99
|
+
this.#held.add(held);
|
|
100
|
+
}
|
|
101
|
+
this.#bump();
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Hold the end open for something being read that is not one of the counted streams,
|
|
107
|
+
* such as a joining FETCH's head, or let go of a counted stream while it waits on one.
|
|
108
|
+
* Returns the call that lets go, which is idempotent.
|
|
109
|
+
*/
|
|
110
|
+
hold() {
|
|
53
111
|
this.#active += 1;
|
|
54
|
-
|
|
55
|
-
let closed = false;
|
|
112
|
+
let released = false;
|
|
56
113
|
return () => {
|
|
57
|
-
if (
|
|
114
|
+
if (released)
|
|
58
115
|
return;
|
|
59
|
-
|
|
116
|
+
released = true;
|
|
60
117
|
this.#active -= 1;
|
|
61
118
|
this.#bump();
|
|
62
119
|
};
|
|
63
120
|
}
|
|
64
|
-
/**
|
|
121
|
+
/**
|
|
122
|
+
* Stop holding the end open for a counted stream while it waits on something that holds
|
|
123
|
+
* it instead. Returns the call that holds it again, which must come before the stream's
|
|
124
|
+
* own close.
|
|
125
|
+
*/
|
|
126
|
+
suspend() {
|
|
127
|
+
this.#active -= 1;
|
|
128
|
+
this.#bump();
|
|
129
|
+
let resumed = false;
|
|
130
|
+
return () => {
|
|
131
|
+
if (resumed)
|
|
132
|
+
return;
|
|
133
|
+
resumed = true;
|
|
134
|
+
this.#active += 1;
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/** Re-check what {@link settle} waits on, after something outside the ledger changed. */
|
|
138
|
+
touch() {
|
|
139
|
+
this.#bump();
|
|
140
|
+
}
|
|
141
|
+
/** Record keys `[start, end)` as accounted for without a stream: dropped, or a datagram. */
|
|
65
142
|
account(start, end) {
|
|
66
143
|
this.#account(start, end);
|
|
67
144
|
}
|
|
145
|
+
/** Record `[start, end)` as given up by a drop, accounting for it. */
|
|
146
|
+
drop(start, end) {
|
|
147
|
+
insertRun(this.#dropped, start, end);
|
|
148
|
+
while (this.#dropped.length > MAX_RUNS)
|
|
149
|
+
this.#dropped.shift();
|
|
150
|
+
this.#account(start, end);
|
|
151
|
+
}
|
|
152
|
+
/** Whether a drop named `key`. */
|
|
153
|
+
dropped(key) {
|
|
154
|
+
const run = this.#dropped[runsFrom(this.#dropped, key)];
|
|
155
|
+
return run !== undefined && run.start <= key;
|
|
156
|
+
}
|
|
68
157
|
/** Restart the age of every gap reaching into `[start, end)`, which the demand newly asks for. */
|
|
69
158
|
demand(start, end) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
159
|
+
this.#ledger.demand(start, end, now());
|
|
160
|
+
}
|
|
161
|
+
/** The parts of `[start, end)` accounted for: a stream arrived, a drop named them, or the grace gave up. */
|
|
162
|
+
accounted(start, end) {
|
|
163
|
+
return runGaps(this.#ledger.gaps(start, end), start, end);
|
|
164
|
+
}
|
|
165
|
+
/** Whether a group stream is still being read. */
|
|
166
|
+
get reading() {
|
|
167
|
+
return this.#active > 0;
|
|
79
168
|
}
|
|
80
|
-
/**
|
|
169
|
+
/** Bumped on every change {@link settle} watches. */
|
|
170
|
+
get changed() {
|
|
171
|
+
return this.#changed;
|
|
172
|
+
}
|
|
173
|
+
/** Whether every key in `[start, end)` is accounted for. */
|
|
81
174
|
covers(start, end) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
175
|
+
return this.#ledger.covers(start, end);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Whether a proven tail lost the proof for `owed`: a run it does not cover reaches below what
|
|
179
|
+
* its ledger forgot, so it cannot tell a group still owed from one it forgot was accounted for.
|
|
180
|
+
* What it owes above that is still waited for, since the wire can yet account for it. Mirrors the
|
|
181
|
+
* Rust `Tail::lost`.
|
|
182
|
+
*/
|
|
183
|
+
lost(owed) {
|
|
184
|
+
const below = this.#ledger.forgotten;
|
|
185
|
+
return (below !== undefined && owed.some((run) => run.start < below && !this.covers(run.start, min(run.end, below))));
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Whether nothing still on the wire can change what `[start, end)` gets: every group at or above
|
|
189
|
+
* what the ledger forgot is accounted for. Below that, {@link lost} says whether proof was lost.
|
|
190
|
+
* Mirrors the Rust `Tail::answered`.
|
|
191
|
+
*/
|
|
192
|
+
answered(start, end) {
|
|
193
|
+
return this.covers(max(start, this.#ledger.forgotten ?? 0n), end);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* What of `[start, end)` this tail spent on its subscription: what it accounts for, and everything
|
|
197
|
+
* below what it forgot, which it may have been told of. A fill for any of it needs a fresh
|
|
198
|
+
* subscription, since this one never reopens a group it delivered or dropped. Mirrors the Rust
|
|
199
|
+
* `Tail::spent`.
|
|
200
|
+
*/
|
|
201
|
+
spent(start, end) {
|
|
202
|
+
const below = this.#ledger.forgotten ?? 0n;
|
|
203
|
+
const forgotten = min(end, below);
|
|
204
|
+
const spent = start < forgotten ? [{ start, end: forgotten }] : [];
|
|
205
|
+
return [...spent, ...this.accounted(max(start, below), end)];
|
|
86
206
|
}
|
|
87
207
|
/**
|
|
88
208
|
* Wait until every stream is read to its end and `complete()` holds, or the grace passes
|
|
89
209
|
* with nothing left being read, or `closed` settles.
|
|
90
210
|
*
|
|
91
|
-
* A stream still being read is
|
|
92
|
-
*
|
|
93
|
-
* arrived.
|
|
211
|
+
* A stream still being read is waited for, until its own FIN or reset, or until a drop naming
|
|
212
|
+
* its group lets go of it (see {@link Counted.done}). The grace gives up on streams that never
|
|
213
|
+
* arrived, and `limit` caps it. With no grace nothing is timed: every start waits for the wire
|
|
214
|
+
* to account for it.
|
|
94
215
|
*/
|
|
95
|
-
|
|
216
|
+
settle(complete, closed, limit) {
|
|
217
|
+
return this.#settle(complete, closed, limit, false);
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* {@link settle} (with the same `limit`) once the publisher ended the subscription, which also gives up on a stream that
|
|
221
|
+
* delivered nothing for {@link GRACE} since (see {@link Counted.stalled}): a browser can lose a
|
|
222
|
+
* stream's reset, leaving it open forever. Not with no grace, where the wire names every group.
|
|
223
|
+
*/
|
|
224
|
+
drain(complete, closed, limit) {
|
|
225
|
+
return this.#settle(complete, closed, limit, true);
|
|
226
|
+
}
|
|
227
|
+
async #settle(complete, closed, limit, drain) {
|
|
96
228
|
// A gap that aged past the grace since the last insert is no longer waited for either.
|
|
97
|
-
this.#
|
|
229
|
+
const grace = this.#grace();
|
|
230
|
+
const from = now();
|
|
231
|
+
this.#ledger.expire(from, grace);
|
|
232
|
+
const wait = grace === undefined ? undefined : limit === undefined ? grace : grace.min(limit);
|
|
98
233
|
let expired = false;
|
|
99
|
-
const timer =
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
234
|
+
const timer = new AbortController();
|
|
235
|
+
if (wait !== undefined) {
|
|
236
|
+
void sleep(wait, { signal: timer.signal }).then(() => {
|
|
237
|
+
expired = true;
|
|
238
|
+
this.#bump();
|
|
239
|
+
}, () => { });
|
|
240
|
+
}
|
|
241
|
+
// Wakes the loop when the quietest stream's time is up, one at a time.
|
|
242
|
+
let wake;
|
|
103
243
|
try {
|
|
104
244
|
while (closed.peek() === undefined) {
|
|
105
245
|
if (this.#active === 0 && (expired || complete()))
|
|
106
246
|
return;
|
|
247
|
+
if (drain && grace !== undefined) {
|
|
248
|
+
wake?.abort();
|
|
249
|
+
const next = this.#quiet(GRACE, from);
|
|
250
|
+
if (next !== undefined) {
|
|
251
|
+
wake = new AbortController();
|
|
252
|
+
void sleep(next, { signal: wake.signal }).then(() => this.#bump(), () => { });
|
|
253
|
+
}
|
|
254
|
+
}
|
|
107
255
|
await Signal.race(this.#changed, closed);
|
|
108
256
|
}
|
|
109
257
|
}
|
|
110
258
|
finally {
|
|
111
|
-
|
|
259
|
+
timer.abort();
|
|
260
|
+
wake?.abort();
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
// Give up on each held stream that delivered nothing for `window` since `from`, and return how
|
|
264
|
+
// long until the next one would have, or undefined with none held.
|
|
265
|
+
#quiet(window, from) {
|
|
266
|
+
const at = now();
|
|
267
|
+
let next;
|
|
268
|
+
for (const held of this.#held) {
|
|
269
|
+
const quiet = at.since(held.last().max(held.since).max(from));
|
|
270
|
+
if (quiet.ge(window)) {
|
|
271
|
+
this.#held.delete(held);
|
|
272
|
+
held.stalled = true;
|
|
273
|
+
held.stall();
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
const left = window.sub(quiet);
|
|
277
|
+
next = next === undefined ? left : next.min(left);
|
|
112
278
|
}
|
|
279
|
+
return next;
|
|
113
280
|
}
|
|
114
281
|
#account(start, end) {
|
|
115
282
|
if (start >= end)
|
|
116
283
|
return;
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
let placed = false;
|
|
121
|
-
for (const run of this.#runs) {
|
|
122
|
-
if (run.end < start) {
|
|
123
|
-
runs.push(run);
|
|
124
|
-
}
|
|
125
|
-
else if (end < run.start) {
|
|
126
|
-
// Splitting a gap leaves both halves as late as it was.
|
|
127
|
-
if (!placed)
|
|
128
|
-
runs.push(merged ?? { start, end, since: run.since });
|
|
129
|
-
placed = true;
|
|
130
|
-
runs.push(run);
|
|
131
|
-
}
|
|
132
|
-
else {
|
|
133
|
-
merged = {
|
|
134
|
-
start: Math.min(merged?.start ?? start, run.start),
|
|
135
|
-
end: Math.max(merged?.end ?? end, run.end),
|
|
136
|
-
since: merged?.since ?? run.since,
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
// A run past every other one opens a new gap.
|
|
141
|
-
if (!placed)
|
|
142
|
-
runs.push(merged ?? { start, end, since: now });
|
|
143
|
-
this.#runs = runs;
|
|
144
|
-
this.#expire(now);
|
|
284
|
+
const at = now();
|
|
285
|
+
this.#ledger.account(start, end, at);
|
|
286
|
+
this.#ledger.expire(at, this.#grace());
|
|
145
287
|
this.#bump();
|
|
146
288
|
}
|
|
147
|
-
// Fold every gap older than the grace into the runs around it.
|
|
148
|
-
#expire(now) {
|
|
149
|
-
const grace = this.#grace();
|
|
150
|
-
const runs = [];
|
|
151
|
-
for (const run of this.#runs) {
|
|
152
|
-
const below = runs.at(-1);
|
|
153
|
-
if (below && now - run.since >= grace) {
|
|
154
|
-
runs[runs.length - 1] = { ...below, end: run.end };
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
runs.push(run);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
this.#runs = runs;
|
|
161
|
-
}
|
|
162
289
|
#bump() {
|
|
163
290
|
this.#changed.update((revision) => revision + 1);
|
|
164
291
|
}
|
package/tail.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tail.js","sourceRoot":"","sources":["../src/tail.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,MAAM,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAElC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;AAEzC,gFAAgF;AAChF,MAAM,cAAc,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AAcnC;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,IAAI;IAChB,yFAAyF;IAC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K,IAAI,GAAG,CAAC,KAAK;iBACjC,CAAC;YACH,CAAC;QACF,CAAC;QACD,8CAA8C;QAC9C,IAAI,CAAC,MAAM;YAAE,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;QAC7D,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAClB,IAAI,CAAC,KAAK,EAAE,CAAC;IACd,CAAC;IAED,+DAA+D;IAC/D,OAAO,CAAC,GAAW;QAClB,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QAC5B,MAAM,IAAI,GAAU,EAAE,CAAC;QACvB,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YAC9B,MAAM,KAAK,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;YAC1B,IAAI,KAAK,IAAI,GAAG,GAAG,GAAG,CAAC,KAAK,IAAI,KAAK,EAAE,CAAC;gBACvC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,CAAC;YACpD,CAAC;iBAAM,CAAC;gBACP,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAChB,CAAC;QACF,CAAC;QACD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,KAAK;QACJ,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC;IAClD,CAAC;CACD","sourcesContent":["import { type GetPromise, Signal } from \"@moq/signals\";\nimport { Milli } from \"./time.ts\";\n\n/**\n * How long a subscriber waits for a group stream it cannot account for once the publisher\n * has ended the subscription.\n *\n * A group reset before its header arrived leaves no trace, and QUIC does not order streams,\n * so a stream opened before the end can still be in flight after it. This bounds the wait on\n * IETF, and on moq-lite when the subscription has no max age to bound it with.\n */\nexport const TAIL_GRACE_MS = Milli(1000);\n\n// setTimeout truncates a longer delay to a signed 32-bit int and fires at once.\nconst MAX_TIMEOUT_MS = 2 ** 31 - 1;\n\n// A run of accounted sequences `[start, end)`, and when the gap below it opened (in\n// `performance.now()` milliseconds), which is when its missing groups became late.\ntype Run = { start: number; end: number; since: number };\n\n/** How a {@link Tail} measures its grace. */\nexport interface TailOptions {\n\t/** How long to wait for a group that cannot be accounted for. Read each time it is needed. */\n\tgrace?: () => Milli;\n\t/** The clock, in `performance.now()` milliseconds. */\n\tnow?: () => number;\n}\n\n/**\n * The group streams a subscription has received, so its end can wait for the ones still owed.\n *\n * A publisher ends a subscription before every group stream it opened has necessarily\n * arrived. This records which sequences are accounted for (a stream's header arrived, or\n * the publisher dropped them) and how many streams are still being read, and {@link settle}\n * waits on them.\n *\n * A lost datagram is not owed: it leaves a hole that waits out the grace like a stream reset\n * before its header.\n *\n * @internal\n */\nexport class Tail {\n\t// Disjoint, sorted, non-adjacent runs of accounted sequences. A gap older than the grace\n\t// can no longer be waited for, so it folds into the runs around it, which bounds this by\n\t// the gaps opened within the grace rather than every gap in the subscription. A fold is\n\t// final: a later, longer grace or a lowered floor cannot reopen it.\n\t#runs: Run[] = [];\n\t// Group streams whose header arrived, and those still being read.\n\t#streams = 0;\n\t#active = 0;\n\t#changed = new Signal(0);\n\t#grace: () => Milli;\n\t#now: () => number;\n\n\tconstructor(options: TailOptions = {}) {\n\t\tthis.#grace = options.grace ?? (() => TAIL_GRACE_MS);\n\t\tthis.#now = options.now ?? (() => performance.now());\n\t}\n\n\t/** Group streams whose header arrived, whether they finished or were reset. */\n\tget streams(): number {\n\t\treturn this.#streams;\n\t}\n\n\t/**\n\t * Record a group stream whose header arrived. Returns the call that marks it read to\n\t * its end, which is idempotent.\n\t */\n\topen(sequence: number): () => void {\n\t\tthis.#streams += 1;\n\t\tthis.#active += 1;\n\t\tthis.#account(sequence, sequence + 1);\n\n\t\tlet closed = false;\n\t\treturn () => {\n\t\t\tif (closed) return;\n\t\t\tclosed = true;\n\t\t\tthis.#active -= 1;\n\t\t\tthis.#bump();\n\t\t};\n\t}\n\n\t/** Record sequences `[start, end)` as accounted for without a stream: dropped, or a datagram. */\n\taccount(start: number, end: number): void {\n\t\tthis.#account(start, end);\n\t}\n\n\t/** Restart the age of every gap reaching into `[start, end)`, which the demand newly asks for. */\n\tdemand(start: number, end: number): void {\n\t\tif (start >= end) return;\n\t\tconst now = this.#now();\n\t\tlet below = 0;\n\t\tthis.#runs = this.#runs.map((run) => {\n\t\t\tconst reached = below < end && start < run.start;\n\t\t\tbelow = run.end;\n\t\t\treturn reached ? { ...run, since: now } : run;\n\t\t});\n\t}\n\n\t/** Whether every sequence in `[start, end)` is accounted for. */\n\tcovers(start: number, end: number): boolean {\n\t\tif (start >= end) return true;\n\t\t// Runs are merged on insert, so one run covers the span or none does.\n\t\treturn this.#runs.some((run) => run.start <= start && end <= run.end);\n\t}\n\n\t/**\n\t * Wait until every stream is read to its end and `complete()` holds, or the grace passes\n\t * with nothing left being read, or `closed` settles.\n\t *\n\t * A stream still being read is always waited for: a group ends on its own stream's FIN\n\t * or reset, never because its track ended. The grace only gives up on streams that never\n\t * arrived.\n\t */\n\tasync settle(complete: () => boolean, closed: GetPromise<unknown>): Promise<void> {\n\t\t// A gap that aged past the grace since the last insert is no longer waited for either.\n\t\tthis.#expire(this.#now());\n\n\t\tlet expired = false;\n\t\tconst timer = setTimeout(\n\t\t\t() => {\n\t\t\t\texpired = true;\n\t\t\t\tthis.#bump();\n\t\t\t},\n\t\t\tMath.min(this.#grace(), MAX_TIMEOUT_MS),\n\t\t);\n\t\ttry {\n\t\t\twhile (closed.peek() === undefined) {\n\t\t\t\tif (this.#active === 0 && (expired || complete())) return;\n\t\t\t\tawait Signal.race(this.#changed, closed);\n\t\t\t}\n\t\t} finally {\n\t\t\tclearTimeout(timer);\n\t\t}\n\t}\n\n\t#account(start: number, end: number): void {\n\t\tif (start >= end) return;\n\n\t\tconst now = this.#now();\n\t\tconst runs: Run[] = [];\n\t\tlet merged: Run | undefined;\n\t\tlet placed = false;\n\t\tfor (const run of this.#runs) {\n\t\t\tif (run.end < start) {\n\t\t\t\truns.push(run);\n\t\t\t} else if (end < run.start) {\n\t\t\t\t// Splitting a gap leaves both halves as late as it was.\n\t\t\t\tif (!placed) runs.push(merged ?? { start, end, since: run.since });\n\t\t\t\tplaced = true;\n\t\t\t\truns.push(run);\n\t\t\t} else {\n\t\t\t\tmerged = {\n\t\t\t\t\tstart: Math.min(merged?.start ?? start, run.start),\n\t\t\t\t\tend: Math.max(merged?.end ?? end, run.end),\n\t\t\t\t\tsince: merged?.since ?? run.since,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t\t// A run past every other one opens a new gap.\n\t\tif (!placed) runs.push(merged ?? { start, end, since: now });\n\t\tthis.#runs = runs;\n\t\tthis.#expire(now);\n\t\tthis.#bump();\n\t}\n\n\t// Fold every gap older than the grace into the runs around it.\n\t#expire(now: number): void {\n\t\tconst grace = this.#grace();\n\t\tconst runs: Run[] = [];\n\t\tfor (const run of this.#runs) {\n\t\t\tconst below = runs.at(-1);\n\t\t\tif (below && now - run.since >= grace) {\n\t\t\t\truns[runs.length - 1] = { ...below, end: run.end };\n\t\t\t} else {\n\t\t\t\truns.push(run);\n\t\t\t}\n\t\t}\n\t\tthis.#runs = runs;\n\t}\n\n\t#bump(): void {\n\t\tthis.#changed.update((revision) => revision + 1);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"tail.js","sourceRoot":"","sources":["../src/tail.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,GAAG,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACrE,OAAO,EAAgC,MAAM,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,EAAE,SAAS,EAAY,OAAO,EAAE,QAAQ,E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,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACnD,CAAC;QACD,OAAO,IAAI,CAAC;IACb,CAAC;IAED,QAAQ,CAAC,KAAa,EAAE,GAAW;QAClC,IAAI,KAAK,IAAI,GAAG;YAAE,OAAO;QACzB,MAAM,EAAE,GAAG,GAAG,EAAE,CAAC;QACjB,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;QACrC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;QACvC,IAAI,CAAC,KAAK,EAAE,CAAC;IACd,CAAC;IAED,KAAK;QACJ,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC;IAClD,CAAC;CACD","sourcesContent":["import { type Duration, type Instant, now, sleep } from \"@moq/clock\";\nimport { type GetPromise, type Getter, Signal } from \"@moq/signals\";\nimport { insertRun, type Run, runGaps, runsFrom } from \"./internal.ts\";\nimport { GRACE, Ledger, MAX_RUNS } from \"./ledger.ts\";\nimport { max, min } from \"./util/key.ts\";\n\n/** How a {@link Tail} measures its grace. */\nexport interface TailOptions {\n\t/**\n\t * How long to wait for a group that cannot be accounted for, or `undefined` to wait until the\n\t * wire accounts for it (lite-07, which names every start). Read each time it is needed.\n\t */\n\tgrace?: () => Duration | undefined;\n\t/** Lite-07: the publisher names every start, so the ledger never folds a gap (see {@link Tail.lost}). */\n\tproven?: boolean;\n}\n\n/** A group stream a {@link Tail} counts, from its header until it is read to its end. */\nexport interface Counted {\n\t/** Stop holding the end open for it: read to its end, or a drop accounted for its group. Idempotent. */\n\tdone(): void;\n\t/** Stop holding the end open while it waits, unread, on a copy another stream delivers. Idempotent. */\n\tpark(): void;\n\t/** Hold the end open again once it reads the group itself. Idempotent. */\n\tresume(): void;\n\t/**\n\t * Settles once {@link Tail.drain} gave up on it: the subscription ended and it delivered nothing\n\t * for the grace, as a stream whose reset the browser lost does. It stays counted\n\t * until the reader ends it with {@link done}.\n\t */\n\treadonly stalled: Promise<void>;\n}\n\n// A stream the end is held open for.\ninterface Held {\n\t// When it last delivered data.\n\tlast: () => Instant;\n\t// When it began being held, since a resumed stream's wait on a copy is not its quiet time.\n\tsince: Instant;\n\t// Given up on, so it is not watched again.\n\tstalled: boolean;\n\tstall: () => void;\n}\n\n/**\n * The group streams a subscription has received, so its end can wait for the ones still owed.\n *\n * A publisher ends a subscription before every group stream it opened has necessarily\n * arrived. This records which keys are accounted for (a stream's header arrived, or\n * the publisher dropped them) and how many streams are still being read, and {@link settle}\n * waits on them.\n *\n * A lost datagram is not owed: it leaves a hole that waits out the grace like a stream reset\n * before its header.\n *\n * @internal\n */\nexport class Tail {\n\t// The keys accounted for, whose gaps fold once the grace stops waiting for them.\n\t#ledger: Ledger;\n\t// Group streams whose header arrived, and those still being read and holding the end.\n\t#streams = 0;\n\t#active = 0;\n\t// The counted streams holding the end open, which a settle gives up on once they go quiet.\n\t#held = new Set<Held>();\n\t// The lowest group a stream's header named, which proves the group exists.\n\t#first: bigint | undefined;\n\t#changed = new Signal(0);\n\t#grace: () => Duration | undefined;\n\t// Keys a drop named, so a stream whose header the drop overtook can be told from one\n\t// whose gap the grace gave up on.\n\t#dropped: Run[] = [];\n\n\tconstructor(options: TailOptions = {}) {\n\t\tthis.#grace = options.grace ?? (() => GRACE);\n\t\tthis.#ledger = new Ledger({ proven: options.proven });\n\t}\n\n\t/** Release what the tail keeps beside its ledger, once its subscription ended. */\n\tclose(): void {\n\t\tthis.#dropped = [];\n\t\tthis.#held.clear();\n\t}\n\n\t/** Group streams whose header arrived, whether they finished or were reset. */\n\tget streams(): number {\n\t\treturn this.#streams;\n\t}\n\n\t/** The lowest group whose stream's header arrived. */\n\tget first(): bigint | undefined {\n\t\treturn this.#first;\n\t}\n\n\t/**\n\t * Record a group stream whose header arrived, held until it is read to its end. `last` says\n\t * when it last delivered data, so a settle can give up on a quiet one; without it the stream is\n\t * waited for until it ends, which is what a reader that cannot tell its stream is lost wants.\n\t */\n\topen(key: bigint, last?: () => Instant): Counted {\n\t\tthis.#streams += 1;\n\t\tif (this.#first === undefined || key < this.#first) this.#first = key;\n\t\tthis.#active += 1;\n\t\tthis.#account(key, key + 1n);\n\n\t\tlet stall!: () => void;\n\t\tconst stalled = new Promise<void>((resolve) => {\n\t\t\tstall = resolve;\n\t\t});\n\t\tconst held: Held | undefined = last && { last, since: now(), stalled: false, stall };\n\t\tif (held) this.#held.add(held);\n\n\t\t// Parked holds nothing.\n\t\tlet state: \"held\" | \"parked\" | \"done\" = \"held\";\n\t\treturn {\n\t\t\tstalled,\n\t\t\tdone: () => {\n\t\t\t\tif (state === \"done\") return;\n\t\t\t\tif (state === \"held\") this.#active -= 1;\n\t\t\t\tif (held) this.#held.delete(held);\n\t\t\t\tstate = \"done\";\n\t\t\t\tthis.#bump();\n\t\t\t},\n\t\t\tpark: () => {\n\t\t\t\tif (state !== \"held\") return;\n\t\t\t\tstate = \"parked\";\n\t\t\t\tthis.#active -= 1;\n\t\t\t\tif (held) this.#held.delete(held);\n\t\t\t\tthis.#bump();\n\t\t\t},\n\t\t\tresume: () => {\n\t\t\t\tif (state !== \"parked\") return;\n\t\t\t\tstate = \"held\";\n\t\t\t\tthis.#active += 1;\n\t\t\t\tif (held && !held.stalled) {\n\t\t\t\t\theld.since = now();\n\t\t\t\t\tthis.#held.add(held);\n\t\t\t\t}\n\t\t\t\tthis.#bump();\n\t\t\t},\n\t\t};\n\t}\n\n\t/**\n\t * Hold the end open for something being read that is not one of the counted streams,\n\t * such as a joining FETCH's head, or let go of a counted stream while it waits on one.\n\t * Returns the call that lets go, which is idempotent.\n\t */\n\thold(): () => void {\n\t\tthis.#active += 1;\n\t\tlet released = false;\n\t\treturn () => {\n\t\t\tif (released) return;\n\t\t\treleased = true;\n\t\t\tthis.#active -= 1;\n\t\t\tthis.#bump();\n\t\t};\n\t}\n\n\t/**\n\t * Stop holding the end open for a counted stream while it waits on something that holds\n\t * it instead. Returns the call that holds it again, which must come before the stream's\n\t * own close.\n\t */\n\tsuspend(): () => void {\n\t\tthis.#active -= 1;\n\t\tthis.#bump();\n\t\tlet resumed = false;\n\t\treturn () => {\n\t\t\tif (resumed) return;\n\t\t\tresumed = true;\n\t\t\tthis.#active += 1;\n\t\t};\n\t}\n\n\t/** Re-check what {@link settle} waits on, after something outside the ledger changed. */\n\ttouch(): void {\n\t\tthis.#bump();\n\t}\n\n\t/** Record keys `[start, end)` as accounted for without a stream: dropped, or a datagram. */\n\taccount(start: bigint, end: bigint): void {\n\t\tthis.#account(start, end);\n\t}\n\n\t/** Record `[start, end)` as given up by a drop, accounting for it. */\n\tdrop(start: bigint, end: bigint): void {\n\t\tinsertRun(this.#dropped, start, end);\n\t\twhile (this.#dropped.length > MAX_RUNS) this.#dropped.shift();\n\t\tthis.#account(start, end);\n\t}\n\n\t/** Whether a drop named `key`. */\n\tdropped(key: bigint): boolean {\n\t\tconst run = this.#dropped[runsFrom(this.#dropped, key)];\n\t\treturn run !== undefined && run.start <= key;\n\t}\n\n\t/** Restart the age of every gap reaching into `[start, end)`, which the demand newly asks for. */\n\tdemand(start: bigint, end: bigint): void {\n\t\tthis.#ledger.demand(start, end, now());\n\t}\n\n\t/** The parts of `[start, end)` accounted for: a stream arrived, a drop named them, or the grace gave up. */\n\taccounted(start: bigint, end: bigint): Run[] {\n\t\treturn runGaps(this.#ledger.gaps(start, end), start, end);\n\t}\n\n\t/** Whether a group stream is still being read. */\n\tget reading(): boolean {\n\t\treturn this.#active > 0;\n\t}\n\n\t/** Bumped on every change {@link settle} watches. */\n\tget changed(): Getter<number> {\n\t\treturn this.#changed;\n\t}\n\n\t/** Whether every key in `[start, end)` is accounted for. */\n\tcovers(start: bigint, end: bigint): boolean {\n\t\treturn this.#ledger.covers(start, end);\n\t}\n\n\t/**\n\t * Whether a proven tail lost the proof for `owed`: a run it does not cover reaches below what\n\t * its ledger forgot, so it cannot tell a group still owed from one it forgot was accounted for.\n\t * What it owes above that is still waited for, since the wire can yet account for it. Mirrors the\n\t * Rust `Tail::lost`.\n\t */\n\tlost(owed: { start: bigint; end: bigint }[]): boolean {\n\t\tconst below = this.#ledger.forgotten;\n\t\treturn (\n\t\t\tbelow !== undefined && owed.some((run) => run.start < below && !this.covers(run.start, min(run.end, below)))\n\t\t);\n\t}\n\n\t/**\n\t * Whether nothing still on the wire can change what `[start, end)` gets: every group at or above\n\t * what the ledger forgot is accounted for. Below that, {@link lost} says whether proof was lost.\n\t * Mirrors the Rust `Tail::answered`.\n\t */\n\tanswered(start: bigint, end: bigint): boolean {\n\t\treturn this.covers(max(start, this.#ledger.forgotten ?? 0n), end);\n\t}\n\n\t/**\n\t * What of `[start, end)` this tail spent on its subscription: what it accounts for, and everything\n\t * below what it forgot, which it may have been told of. A fill for any of it needs a fresh\n\t * subscription, since this one never reopens a group it delivered or dropped. Mirrors the Rust\n\t * `Tail::spent`.\n\t */\n\tspent(start: bigint, end: bigint): Run[] {\n\t\tconst below = this.#ledger.forgotten ?? 0n;\n\t\tconst forgotten = min(end, below);\n\t\tconst spent: Run[] = start < forgotten ? [{ start, end: forgotten }] : [];\n\t\treturn [...spent, ...this.accounted(max(start, below), end)];\n\t}\n\n\t/**\n\t * Wait until every stream is read to its end and `complete()` holds, or the grace passes\n\t * with nothing left being read, or `closed` settles.\n\t *\n\t * A stream still being read is waited for, until its own FIN or reset, or until a drop naming\n\t * its group lets go of it (see {@link Counted.done}). The grace gives up on streams that never\n\t * arrived, and `limit` caps it. With no grace nothing is timed: every start waits for the wire\n\t * to account for it.\n\t */\n\tsettle(complete: () => boolean, closed: GetPromise<unknown>, limit?: Duration): Promise<void> {\n\t\treturn this.#settle(complete, closed, limit, false);\n\t}\n\n\t/**\n\t * {@link settle} (with the same `limit`) once the publisher ended the subscription, which also gives up on a stream that\n\t * delivered nothing for {@link GRACE} since (see {@link Counted.stalled}): a browser can lose a\n\t * stream's reset, leaving it open forever. Not with no grace, where the wire names every group.\n\t */\n\tdrain(complete: () => boolean, closed: GetPromise<unknown>, limit?: Duration): Promise<void> {\n\t\treturn this.#settle(complete, closed, limit, true);\n\t}\n\n\tasync #settle(\n\t\tcomplete: () => boolean,\n\t\tclosed: GetPromise<unknown>,\n\t\tlimit: Duration | undefined,\n\t\tdrain: boolean,\n\t): Promise<void> {\n\t\t// A gap that aged past the grace since the last insert is no longer waited for either.\n\t\tconst grace = this.#grace();\n\t\tconst from = now();\n\t\tthis.#ledger.expire(from, grace);\n\n\t\tconst wait = grace === undefined ? undefined : limit === undefined ? grace : grace.min(limit);\n\t\tlet expired = false;\n\t\tconst timer = new AbortController();\n\t\tif (wait !== undefined) {\n\t\t\tvoid sleep(wait, { signal: timer.signal }).then(\n\t\t\t\t() => {\n\t\t\t\t\texpired = true;\n\t\t\t\t\tthis.#bump();\n\t\t\t\t},\n\t\t\t\t() => {},\n\t\t\t);\n\t\t}\n\t\t// Wakes the loop when the quietest stream's time is up, one at a time.\n\t\tlet wake: AbortController | undefined;\n\t\ttry {\n\t\t\twhile (closed.peek() === undefined) {\n\t\t\t\tif (this.#active === 0 && (expired || complete())) return;\n\t\t\t\tif (drain && grace !== undefined) {\n\t\t\t\t\twake?.abort();\n\t\t\t\t\tconst next = this.#quiet(GRACE, from);\n\t\t\t\t\tif (next !== undefined) {\n\t\t\t\t\t\twake = new AbortController();\n\t\t\t\t\t\tvoid sleep(next, { signal: wake.signal }).then(\n\t\t\t\t\t\t\t() => this.#bump(),\n\t\t\t\t\t\t\t() => {},\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tawait Signal.race(this.#changed, closed);\n\t\t\t}\n\t\t} finally {\n\t\t\ttimer.abort();\n\t\t\twake?.abort();\n\t\t}\n\t}\n\n\t// Give up on each held stream that delivered nothing for `window` since `from`, and return how\n\t// long until the next one would have, or undefined with none held.\n\t#quiet(window: Duration, from: Instant): Duration | undefined {\n\t\tconst at = now();\n\t\tlet next: Duration | undefined;\n\t\tfor (const held of this.#held) {\n\t\t\tconst quiet = at.since(held.last().max(held.since).max(from));\n\t\t\tif (quiet.ge(window)) {\n\t\t\t\tthis.#held.delete(held);\n\t\t\t\theld.stalled = true;\n\t\t\t\theld.stall();\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst left = window.sub(quiet);\n\t\t\tnext = next === undefined ? left : next.min(left);\n\t\t}\n\t\treturn next;\n\t}\n\n\t#account(start: bigint, end: bigint): void {\n\t\tif (start >= end) return;\n\t\tconst at = now();\n\t\tthis.#ledger.account(start, end, at);\n\t\tthis.#ledger.expire(at, this.#grace());\n\t\tthis.#bump();\n\t}\n\n\t#bump(): void {\n\t\tthis.#changed.update((revision) => revision + 1);\n\t}\n}\n"]}
|
package/time.d.ts
CHANGED
|
@@ -1,72 +1,3 @@
|
|
|
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
|
-
*/
|
|
7
|
-
/** A duration in nanoseconds, branded so it can't be mixed with other units. */
|
|
8
|
-
export type Nano = number & {
|
|
9
|
-
readonly _brand: "nano";
|
|
10
|
-
};
|
|
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
|
-
};
|
|
28
|
-
/** A duration in microseconds, branded so it can't be mixed with other units. */
|
|
29
|
-
export type Micro = number & {
|
|
30
|
-
readonly _brand: "micro";
|
|
31
|
-
};
|
|
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;
|
|
48
|
-
};
|
|
49
|
-
/** A duration in milliseconds, branded so it can't be mixed with other units. */
|
|
50
|
-
export type Milli = number & {
|
|
51
|
-
readonly _brand: "milli";
|
|
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
1
|
/** Units per second for a {@link Timestamp}'s value, e.g. `1000` for milliseconds. */
|
|
71
2
|
export type Timescale = number & {
|
|
72
3
|
readonly _brand: "timescale";
|
|
@@ -89,57 +20,65 @@ export declare const Timescale: ((unitsPerSecond: number) => Timescale) & {
|
|
|
89
20
|
NANO: Timescale;
|
|
90
21
|
};
|
|
91
22
|
/**
|
|
92
|
-
* A presentation timestamp: a raw value in a given {@link Timescale}
|
|
23
|
+
* A presentation timestamp: a raw value in a given {@link Timescale}, or a scale-less track's
|
|
24
|
+
* group key.
|
|
93
25
|
*
|
|
94
|
-
* Mirrors the Rust `Timestamp`. Unlike
|
|
26
|
+
* Mirrors the Rust `Timestamp`. Unlike a `@moq/clock` `Duration` it carries its
|
|
95
27
|
* own scale, so a track can pick its units and conversions can't silently mix them up.
|
|
96
28
|
*
|
|
97
|
-
*
|
|
98
|
-
* (
|
|
99
|
-
* track timescale. Integer timestamps are exact through `2^53 - 1` units; this package
|
|
29
|
+
* A scaled value must be finite and in `[0, Number.MAX_SAFE_INTEGER]`. Fractions are allowed
|
|
30
|
+
* ({@link Timestamp.now}, scale conversion). Encoding rounds down to an integer at the
|
|
31
|
+
* track timescale, as the Rust `Timestamp::convert` does. Integer timestamps are exact through `2^53 - 1` units; this package
|
|
100
32
|
* does not use BigInt for timestamps. {@link Timestamp.as} also refuses a converted
|
|
101
33
|
* value that leaves that range, so a legal source timestamp cannot become an unencodable
|
|
102
34
|
* wire timestamp after a scale change.
|
|
35
|
+
*
|
|
36
|
+
* A scale-less track has no time: each frame's timestamp is {@link Timestamp.unscaled}, whose
|
|
37
|
+
* {@link value} is its group's key and whose {@link scale} is `undefined`, as Rust's
|
|
38
|
+
* `Timestamp::unscaled(key)`. A key past `Number.MAX_SAFE_INTEGER` is refused, so such a group's
|
|
39
|
+
* frames cannot be read here. Anything that needs a scale ({@link as}, {@link asMillis},
|
|
40
|
+
* {@link asMicros}) throws a `RangeError` on one, and {@link isBefore} orders it against no
|
|
41
|
+
* scaled timestamp.
|
|
103
42
|
*/
|
|
104
43
|
export declare class Timestamp {
|
|
105
|
-
/** The raw value
|
|
44
|
+
/** The raw value in `scale` units, or an unscaled timestamp's group key. */
|
|
106
45
|
readonly value: number;
|
|
107
|
-
/** Units per second the {@link value} is measured in. */
|
|
108
|
-
readonly scale: Timescale;
|
|
46
|
+
/** Units per second the {@link value} is measured in, or `undefined` when unscaled. */
|
|
47
|
+
readonly scale: Timescale | undefined;
|
|
109
48
|
/** Build a timestamp of `value` units at `scale`. */
|
|
110
49
|
constructor(value: number, scale: Timescale);
|
|
111
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* A scale-less track's timestamp: `key` is its group's key (or a datagram's key), with no
|
|
52
|
+
* time. Throws a `RangeError` past `Number.MAX_SAFE_INTEGER`, which a `number` cannot hold.
|
|
53
|
+
*/
|
|
54
|
+
static unscaled(key: bigint | number): Timestamp;
|
|
55
|
+
/** The installed clock's monotonic instant in milliseconds, not wall-clock time. */
|
|
112
56
|
static now(): Timestamp;
|
|
57
|
+
/** A timestamp of `secs` seconds. */
|
|
58
|
+
static fromSecs(secs: number): Timestamp;
|
|
113
59
|
/** A timestamp of `ms` milliseconds. */
|
|
114
60
|
static fromMillis(ms: number): Timestamp;
|
|
115
61
|
/** A timestamp of `us` microseconds. */
|
|
116
62
|
static fromMicros(us: number): Timestamp;
|
|
117
|
-
/**
|
|
63
|
+
/** A timestamp of `ns` nanoseconds. */
|
|
64
|
+
static fromNanos(ns: number): Timestamp;
|
|
65
|
+
/**
|
|
66
|
+
* This timestamp's value re-expressed at `scale`; throws a `RangeError` if it is unscaled or
|
|
67
|
+
* the result is not in the safe range.
|
|
68
|
+
*/
|
|
118
69
|
as(scale: Timescale): number;
|
|
119
|
-
/** The value in
|
|
70
|
+
/** The value in seconds; throws a `RangeError` if it is unscaled. */
|
|
71
|
+
asSecs(): number;
|
|
72
|
+
/** The value in milliseconds; throws a `RangeError` if it is unscaled. */
|
|
120
73
|
asMillis(): number;
|
|
121
|
-
/** The value in microseconds. */
|
|
74
|
+
/** The value in microseconds; throws a `RangeError` if it is unscaled. */
|
|
122
75
|
asMicros(): number;
|
|
76
|
+
/** The value in nanoseconds; throws a `RangeError` if it is unscaled or past the safe range. */
|
|
77
|
+
asNanos(): number;
|
|
78
|
+
/**
|
|
79
|
+
* Whether this presents before `other`, whatever their scales. Two unscaled timestamps order
|
|
80
|
+
* by key; a scaled and an unscaled one don't order, so neither is before the other.
|
|
81
|
+
*/
|
|
82
|
+
isBefore(other: Timestamp): boolean;
|
|
123
83
|
}
|
|
124
|
-
/** A duration in seconds, branded so it can't be mixed with other units. */
|
|
125
|
-
export type Second = number & {
|
|
126
|
-
readonly _brand: "second";
|
|
127
|
-
};
|
|
128
|
-
/** Constructors, conversions, and arithmetic for {@link Second} values. */
|
|
129
|
-
export declare const Second: ((value: number) => Second) & {
|
|
130
|
-
zero: Second;
|
|
131
|
-
fromNano: (ns: Nano) => Second;
|
|
132
|
-
fromMicro: (us: Micro) => Second;
|
|
133
|
-
fromMilli: (ms: Milli) => Second;
|
|
134
|
-
toNano: (s: Second) => Nano;
|
|
135
|
-
toMicro: (s: Second) => Micro;
|
|
136
|
-
toMilli: (s: Second) => Milli;
|
|
137
|
-
now: () => Second;
|
|
138
|
-
add: (a: Second, b: Second) => Second;
|
|
139
|
-
sub: (a: Second, b: Second) => Second;
|
|
140
|
-
mul: (a: Second, b: number) => Second;
|
|
141
|
-
div: (a: Second, b: number) => Second;
|
|
142
|
-
max: (a: Second, b: Second) => Second;
|
|
143
|
-
min: (a: Second, b: Second) => Second;
|
|
144
|
-
};
|
|
145
84
|
//# 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":"
|
|
1
|
+
{"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../src/time.ts"],"names":[],"mappings":"AAWA,sFAAsF;AACtF,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAA;CAAE,CAAC;AAElE;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,oBACJ,MAAM,KAAG,SAAS;IAOlC,2BAA2B;YACd,SAAS;IACtB,8BAA8B;WACd,SAAS;IACzB,kCAAkC;WACd,SAAS;IAC7B,sCAAsC;UACf,SAAS;CAEjC,CAAC;AAQF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,SAAS;IACrB,4EAA4E;IAC5E,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,uFAAuF;IACvF,QAAQ,CAAC,KAAK,EAAE,SAAS,GAAG,SAAS,CAAC;IAEtC,qDAAqD;IACrD,YAAY,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAI1C;IAED;;;OAGG;IACH,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAW/C;IAED,oFAAoF;IACpF,MAAM,CAAC,GAAG,IAAI,SAAS,CAEtB;IAED,qCAAqC;IACrC,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAEvC;IAED,wCAAwC;IACxC,MAAM,CAAC,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,SAAS,CAEvC;IAED,wCAAwC;IACxC,MAAM,CAAC,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,SAAS,CAEvC;IAED,uCAAuC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