@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/prefix.js
ADDED
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Grant prefixes and a path segment's escaping.
|
|
3
|
+
*
|
|
4
|
+
* A grant is a {@link Prefixes} set: each {@link Prefix} covers a path and everything beneath
|
|
5
|
+
* it, the empty prefix covering every path. A grant never holds a wildcard: parsing one fails
|
|
6
|
+
* loudly with an {@link InvalidPrefix} of code `wildcard`. The Rust twin is `moq_net::path`.
|
|
7
|
+
*
|
|
8
|
+
* A separate entrypoint (`@moq/net/prefix`) so a token minting service reads grants without
|
|
9
|
+
* loading the wire stack.
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* The segments of `path`, split only at a `/` no `\` escapes and still escaped as written.
|
|
15
|
+
*
|
|
16
|
+
* The empty path has none. Anything else yields one more segment than it has separators,
|
|
17
|
+
* empty ones included, so a caller that requires non-empty segments checks them itself.
|
|
18
|
+
* With `limit`, stops after that many segments.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* parts("room/a\\/b/cam"); // ["room", "a\\/b", "cam"]
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export function parts(path, limit) {
|
|
26
|
+
if (path === "")
|
|
27
|
+
return [];
|
|
28
|
+
// Without a `\`, every `/` separates.
|
|
29
|
+
if (!path.includes("\\"))
|
|
30
|
+
return limit === undefined ? path.split("/") : path.split("/", limit);
|
|
31
|
+
const max = limit ?? Number.POSITIVE_INFINITY;
|
|
32
|
+
const out = [];
|
|
33
|
+
let start = 0;
|
|
34
|
+
for (let i = 0; i < path.length && out.length < max; i++) {
|
|
35
|
+
const c = path[i];
|
|
36
|
+
if (c === "\\") {
|
|
37
|
+
// The escaped character is never a separator.
|
|
38
|
+
i++;
|
|
39
|
+
}
|
|
40
|
+
else if (c === "/") {
|
|
41
|
+
out.push(path.slice(start, i));
|
|
42
|
+
start = i + 1;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (out.length < max)
|
|
46
|
+
out.push(path.slice(start));
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* A segment's content: each escaped `\` or `/` as the character itself.
|
|
51
|
+
*
|
|
52
|
+
* Expects a segment as {@link parts} yields it from a valid path, where every `\` escapes
|
|
53
|
+
* the character after it.
|
|
54
|
+
*/
|
|
55
|
+
// biome-ignore lint/suspicious/noShadowRestrictedNames: the name mirrors Rust; the deprecated global is unused.
|
|
56
|
+
export function unescape(segment) {
|
|
57
|
+
return segment.includes("\\") ? segment.replace(/\\(.)/gs, "$1") : segment;
|
|
58
|
+
}
|
|
59
|
+
/** The segment holding `content`: each `\` or `/` escaped by a `\`. The inverse of {@link unescape}. */
|
|
60
|
+
// biome-ignore lint/suspicious/noShadowRestrictedNames: the name mirrors Rust; the deprecated global is unused.
|
|
61
|
+
export function escape(content) {
|
|
62
|
+
return /[\\/]/.test(content) ? content.replace(/[\\/]/g, "\\$&") : content;
|
|
63
|
+
}
|
|
64
|
+
// Whether `segment` is one escaped segment: every `\` escapes a `\` or `/`, and no `/` is bare.
|
|
65
|
+
function isSegment(segment) {
|
|
66
|
+
return /^(?:[^\\/]|\\[\\/])*$/.test(segment);
|
|
67
|
+
}
|
|
68
|
+
// The most segments a prefix may have, matching the path limit on the wire.
|
|
69
|
+
const MAX_SEGMENTS = 32;
|
|
70
|
+
/** The non-empty segments of a path, normalized like a broadcast path. */
|
|
71
|
+
function splitPath(path) {
|
|
72
|
+
return parts(path).filter((part) => part !== "");
|
|
73
|
+
}
|
|
74
|
+
/** Thrown when a grant member is not a valid {@link Prefix}. */
|
|
75
|
+
export class InvalidPrefix extends Error {
|
|
76
|
+
/** Which rule was broken. */
|
|
77
|
+
code;
|
|
78
|
+
/** Create an error with the broken rule in `code` and a human-readable `message`. */
|
|
79
|
+
constructor(code, message, options) {
|
|
80
|
+
super(message, options);
|
|
81
|
+
this.name = "InvalidPrefix";
|
|
82
|
+
this.code = code;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
// Order two strings by code point, which agrees with UTF-8 byte order and so with the Rust crate.
|
|
86
|
+
function compareText(a, b) {
|
|
87
|
+
const n = Math.min(a.length, b.length);
|
|
88
|
+
for (let i = 0; i < n; i++) {
|
|
89
|
+
let x = a.charCodeAt(i);
|
|
90
|
+
let y = b.charCodeAt(i);
|
|
91
|
+
if (x === y)
|
|
92
|
+
continue;
|
|
93
|
+
// UTF-16 sorts surrogates below U+E000..U+FFFF; code point order puts them above.
|
|
94
|
+
if (x >= 0xd800 && y >= 0xd800) {
|
|
95
|
+
x = x < 0xe000 ? x + 0x2000 : x - 0x800;
|
|
96
|
+
y = y < 0xe000 ? y + 0x2000 : y - 0x800;
|
|
97
|
+
}
|
|
98
|
+
return x - y;
|
|
99
|
+
}
|
|
100
|
+
return a.length - b.length;
|
|
101
|
+
}
|
|
102
|
+
// Order two segment lists segment by segment, so a list sorts right before every list it starts.
|
|
103
|
+
function compareSegments(a, b) {
|
|
104
|
+
const n = Math.min(a.length, b.length);
|
|
105
|
+
for (let i = 0; i < n; i++) {
|
|
106
|
+
const order = compareText(a[i], b[i]);
|
|
107
|
+
if (order !== 0)
|
|
108
|
+
return order;
|
|
109
|
+
}
|
|
110
|
+
return a.length - b.length;
|
|
111
|
+
}
|
|
112
|
+
// Whether `inner` starts with every segment of `outer`.
|
|
113
|
+
function startsWith(outer, inner) {
|
|
114
|
+
return outer.length <= inner.length && outer.every((segment, i) => segment === inner[i]);
|
|
115
|
+
}
|
|
116
|
+
function wildcard(text) {
|
|
117
|
+
const hint = text === "**"
|
|
118
|
+
? 'write the empty prefix "" for everything'
|
|
119
|
+
: text.endsWith("/**") && !text.slice(0, -3).includes("*")
|
|
120
|
+
? `write ${JSON.stringify(text.slice(0, -3))} for its subtree`
|
|
121
|
+
: "wildcards are refused";
|
|
122
|
+
return new InvalidPrefix("wildcard", `${JSON.stringify(text)} is a wildcard, but a grant is a prefix covering its whole subtree: ${hint}`);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* One grant member: a path covering itself and every path beneath it. The empty prefix
|
|
126
|
+
* covers every path.
|
|
127
|
+
*
|
|
128
|
+
* A prefix is never a wildcard: `foo` covers `foo` and its subtree, so a grant writes `foo`
|
|
129
|
+
* where releases before 0.22 wrote `foo/**`, and the empty prefix where they wrote `**`.
|
|
130
|
+
* Build one with {@link Prefix.parse} or {@link Prefix.all}.
|
|
131
|
+
*
|
|
132
|
+
* @public
|
|
133
|
+
*/
|
|
134
|
+
export class Prefix {
|
|
135
|
+
/** The canonical text: segments joined by `/`, escapes as written. */
|
|
136
|
+
text;
|
|
137
|
+
/** The segments, still escaped as written. */
|
|
138
|
+
segments;
|
|
139
|
+
constructor(segments) {
|
|
140
|
+
this.segments = Object.freeze([...segments]);
|
|
141
|
+
this.text = segments.join("/");
|
|
142
|
+
Object.freeze(this);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Parse a grant member. Throws {@link InvalidPrefix}: `wildcard` for any `*`, and `path`
|
|
146
|
+
* for a leading, trailing, or doubled `/`, a `\` that escapes neither `\` nor `/`, or more
|
|
147
|
+
* than 32 segments.
|
|
148
|
+
*/
|
|
149
|
+
static parse(text) {
|
|
150
|
+
if (text.includes("*"))
|
|
151
|
+
throw wildcard(text);
|
|
152
|
+
const invalid = (reason) => new InvalidPrefix("path", `invalid prefix ${JSON.stringify(text)}: ${reason}`);
|
|
153
|
+
// One past the limit is enough to refuse, without splitting a peer's megabytes of `a/a/...` first.
|
|
154
|
+
const segments = parts(text, MAX_SEGMENTS + 1);
|
|
155
|
+
if (segments.length > MAX_SEGMENTS)
|
|
156
|
+
throw invalid(`more than ${MAX_SEGMENTS} segments`);
|
|
157
|
+
for (const segment of segments) {
|
|
158
|
+
if (segment === "")
|
|
159
|
+
throw invalid("empty path segment");
|
|
160
|
+
if (!isSegment(segment))
|
|
161
|
+
throw invalid(`invalid segment ${JSON.stringify(segment)}`);
|
|
162
|
+
}
|
|
163
|
+
return new Prefix(segments);
|
|
164
|
+
}
|
|
165
|
+
/** The empty prefix, which covers every path. */
|
|
166
|
+
static all() {
|
|
167
|
+
return new Prefix([]);
|
|
168
|
+
}
|
|
169
|
+
/** Order two prefixes segment by segment, so a prefix sorts right before everything beneath it. */
|
|
170
|
+
static compare(a, b) {
|
|
171
|
+
return compareSegments(a.segments, b.segments);
|
|
172
|
+
}
|
|
173
|
+
/** The canonical text. */
|
|
174
|
+
toString() {
|
|
175
|
+
return this.text;
|
|
176
|
+
}
|
|
177
|
+
/** Serializes as the canonical text, matching the Rust crate's serde form. */
|
|
178
|
+
toJSON() {
|
|
179
|
+
return this.text;
|
|
180
|
+
}
|
|
181
|
+
/** Whether the two are the same prefix. */
|
|
182
|
+
equals(other) {
|
|
183
|
+
return this.text === other.text;
|
|
184
|
+
}
|
|
185
|
+
/** Whether this is the empty prefix, covering every path. */
|
|
186
|
+
get isEmpty() {
|
|
187
|
+
return this.text === "";
|
|
188
|
+
}
|
|
189
|
+
/** Whether `path`, normalized like a broadcast path, is this prefix or beneath it. */
|
|
190
|
+
matches(path) {
|
|
191
|
+
return startsWith(this.segments, splitPath(path));
|
|
192
|
+
}
|
|
193
|
+
/** Whether `path`, normalized like a broadcast path, and this prefix share a path: one lies beneath the other. */
|
|
194
|
+
overlaps(path) {
|
|
195
|
+
const segments = splitPath(path);
|
|
196
|
+
return startsWith(this.segments, segments) || startsWith(segments, this.segments);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* This prefix placed beneath the path `root`, normalized like a broadcast path (slashes
|
|
200
|
+
* trimmed and collapsed). Throws {@link InvalidPrefix} when `root` holds a wildcard or a
|
|
201
|
+
* malformed escape, or the result has more than 32 segments.
|
|
202
|
+
*/
|
|
203
|
+
rooted(root) {
|
|
204
|
+
const segments = [...Prefix.parse(splitPath(root).join("/")).segments, ...this.segments];
|
|
205
|
+
if (segments.length > MAX_SEGMENTS) {
|
|
206
|
+
throw new InvalidPrefix("path", `more than ${MAX_SEGMENTS} segments`);
|
|
207
|
+
}
|
|
208
|
+
return new Prefix(segments);
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* This prefix as seen from the path `root`, normalized like a broadcast path: the rest
|
|
212
|
+
* beneath it, or the empty prefix when this one covers `root` already. Undefined when the
|
|
213
|
+
* two share no path.
|
|
214
|
+
*/
|
|
215
|
+
rebase(root) {
|
|
216
|
+
const base = splitPath(root);
|
|
217
|
+
if (startsWith(this.segments, base))
|
|
218
|
+
return Prefix.all();
|
|
219
|
+
if (startsWith(base, this.segments))
|
|
220
|
+
return new Prefix(this.segments.slice(base.length));
|
|
221
|
+
return undefined;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* A grant: a set of {@link Prefix}es, reduced so no member lies beneath another, and sorted
|
|
226
|
+
* segment by segment, so two sets covering the same paths are {@link Prefixes.equals | equal}.
|
|
227
|
+
* The empty set grants nothing.
|
|
228
|
+
*
|
|
229
|
+
* Every operation is near-linear in the members on every shape: a prefix's ancestors sort
|
|
230
|
+
* right before it, so finding the member covering a path is one binary search.
|
|
231
|
+
*
|
|
232
|
+
* @public
|
|
233
|
+
*/
|
|
234
|
+
export class Prefixes {
|
|
235
|
+
#members = [];
|
|
236
|
+
/** The reduced set of the given prefixes. Empty when none are given. */
|
|
237
|
+
constructor(prefixes) {
|
|
238
|
+
if (!prefixes)
|
|
239
|
+
return;
|
|
240
|
+
const sorted = [...prefixes].sort(Prefix.compare);
|
|
241
|
+
// Sorted, a prefix's subtree is the run right after it, so one sweep against the last
|
|
242
|
+
// member kept drops every covered one.
|
|
243
|
+
for (const prefix of sorted) {
|
|
244
|
+
const last = this.#members[this.#members.length - 1];
|
|
245
|
+
if (!last || !startsWith(last.segments, prefix.segments))
|
|
246
|
+
this.#members.push(prefix);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
/** The set holding the empty prefix, which covers every path. */
|
|
250
|
+
static all() {
|
|
251
|
+
return new Prefixes([Prefix.all()]);
|
|
252
|
+
}
|
|
253
|
+
/** Parse each text as a {@link Prefix} into one set. Throws {@link InvalidPrefix}. */
|
|
254
|
+
static parse(texts) {
|
|
255
|
+
return new Prefixes(Array.from(texts, (text) => Prefix.parse(text)));
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Add a prefix, dropping the members beneath it.
|
|
259
|
+
*
|
|
260
|
+
* Returns false when a member already covers it, leaving the set unchanged.
|
|
261
|
+
*/
|
|
262
|
+
insert(prefix) {
|
|
263
|
+
if (this.#covering(prefix.segments))
|
|
264
|
+
return false;
|
|
265
|
+
const at = this.#after(prefix.segments);
|
|
266
|
+
let end = at;
|
|
267
|
+
while (end < this.#members.length && startsWith(prefix.segments, this.#members[end].segments))
|
|
268
|
+
end++;
|
|
269
|
+
this.#members.splice(at, end - at, prefix);
|
|
270
|
+
return true;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Whether some member covers `path`, normalized like a broadcast path. A member covering a
|
|
274
|
+
* path covers its whole subtree, so this also says whether the set grants everything beneath it.
|
|
275
|
+
*/
|
|
276
|
+
matches(path) {
|
|
277
|
+
return this.#covering(splitPath(path));
|
|
278
|
+
}
|
|
279
|
+
/** Whether some member lies at, above, or beneath `path`, normalized like a broadcast path. */
|
|
280
|
+
overlaps(path) {
|
|
281
|
+
const segments = splitPath(path);
|
|
282
|
+
if (this.#covering(segments))
|
|
283
|
+
return true;
|
|
284
|
+
// Anything beneath the path sorts right after it.
|
|
285
|
+
const next = this.#members[this.#after(segments)];
|
|
286
|
+
return next !== undefined && startsWith(segments, next.segments);
|
|
287
|
+
}
|
|
288
|
+
/** Whether every member of `other` is covered here: `other` grants nothing this set does not. */
|
|
289
|
+
covers(other) {
|
|
290
|
+
return other.#members.every((prefix) => this.#covering(prefix.segments));
|
|
291
|
+
}
|
|
292
|
+
/** The paths in both sets: each member of one that the other covers. */
|
|
293
|
+
intersect(other) {
|
|
294
|
+
return new Prefixes([
|
|
295
|
+
...this.#members.filter((prefix) => other.#covering(prefix.segments)),
|
|
296
|
+
...other.#members.filter((prefix) => this.#covering(prefix.segments)),
|
|
297
|
+
]);
|
|
298
|
+
}
|
|
299
|
+
/** What this set covers beneath `root`, named relative to it. See {@link Prefix.rebase}. */
|
|
300
|
+
rebase(root) {
|
|
301
|
+
return new Prefixes(this.#members.flatMap((member) => member.rebase(root) ?? []));
|
|
302
|
+
}
|
|
303
|
+
/** Every member placed beneath `root`. See {@link Prefix.rooted}. */
|
|
304
|
+
rooted(root) {
|
|
305
|
+
return new Prefixes(this.#members.map((member) => member.rooted(root)));
|
|
306
|
+
}
|
|
307
|
+
/** The number of members. */
|
|
308
|
+
get size() {
|
|
309
|
+
return this.#members.length;
|
|
310
|
+
}
|
|
311
|
+
/** The members, in canonical order. */
|
|
312
|
+
[Symbol.iterator]() {
|
|
313
|
+
return this.#members[Symbol.iterator]();
|
|
314
|
+
}
|
|
315
|
+
/** The members as a fresh array, in canonical order. */
|
|
316
|
+
toArray() {
|
|
317
|
+
return [...this.#members];
|
|
318
|
+
}
|
|
319
|
+
/** Serializes as a list of texts, matching the Rust crate's serde form. */
|
|
320
|
+
toJSON() {
|
|
321
|
+
return this.#members.map((member) => member.text);
|
|
322
|
+
}
|
|
323
|
+
/** Whether the two sets cover the same paths. */
|
|
324
|
+
equals(other) {
|
|
325
|
+
return this.size === other.size && this.#members.every((member, i) => member.equals(other.#members[i]));
|
|
326
|
+
}
|
|
327
|
+
// Whether the last member at or before `segments` covers them. In a reduced, sorted set it is
|
|
328
|
+
// the only candidate: any covering member sorts before them, with only its own subtree, which
|
|
329
|
+
// holds no other member, in between.
|
|
330
|
+
#covering(segments) {
|
|
331
|
+
const at = this.#after(segments);
|
|
332
|
+
const member = this.#members[at] && compareSegments(this.#members[at].segments, segments) === 0 ? at : at - 1;
|
|
333
|
+
return member >= 0 && startsWith(this.#members[member].segments, segments);
|
|
334
|
+
}
|
|
335
|
+
// The index of the first member sorting at or after `segments`.
|
|
336
|
+
#after(segments) {
|
|
337
|
+
let lo = 0;
|
|
338
|
+
let hi = this.#members.length;
|
|
339
|
+
while (lo < hi) {
|
|
340
|
+
const mid = (lo + hi) >>> 1;
|
|
341
|
+
if (compareSegments(this.#members[mid].segments, segments) < 0)
|
|
342
|
+
lo = mid + 1;
|
|
343
|
+
else
|
|
344
|
+
hi = mid;
|
|
345
|
+
}
|
|
346
|
+
return lo;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
//# sourceMappingURL=prefix.js.map
|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C,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACzG,CAAC;IAED,8FAA8F;IAC9F,8FAA8F;IAC9F,qCAAqC;IACrC,SAAS,CAAC,QAA2B;QACpC,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACjC,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,eAAe,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;QAC9G,OAAO,MAAM,IAAI,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAC5E,CAAC;IAED,gEAAgE;IAChE,MAAM,CAAC,QAA2B;QACjC,IAAI,EAAE,GAAG,CAAC,CAAC;QACX,IAAI,EAAE,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;QAC9B,OAAO,EAAE,GAAG,EAAE,EAAE,CAAC;YAChB,MAAM,GAAG,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC;YAC5B,IAAI,eAAe,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,QAAQ,CAAC,GAAG,CAAC;gBAAE,EAAE,GAAG,GAAG,GAAG,CAAC,CAAC;;gBACxE,EAAE,GAAG,GAAG,CAAC;QACf,CAAC;QACD,OAAO,EAAE,CAAC;IACX,CAAC;CACD","sourcesContent":["/**\n * Grant prefixes and a path segment's escaping.\n *\n * A grant is a {@link Prefixes} set: each {@link Prefix} covers a path and everything beneath\n * it, the empty prefix covering every path. A grant never holds a wildcard: parsing one fails\n * loudly with an {@link InvalidPrefix} of code `wildcard`. The Rust twin is `moq_net::path`.\n *\n * A separate entrypoint (`@moq/net/prefix`) so a token minting service reads grants without\n * loading the wire stack.\n *\n * @module\n */\n\n/**\n * The segments of `path`, split only at a `/` no `\\` escapes and still escaped as written.\n *\n * The empty path has none. Anything else yields one more segment than it has separators,\n * empty ones included, so a caller that requires non-empty segments checks them itself.\n * With `limit`, stops after that many segments.\n *\n * @example\n * ```typescript\n * parts(\"room/a\\\\/b/cam\"); // [\"room\", \"a\\\\/b\", \"cam\"]\n * ```\n */\nexport function parts(path: string, limit?: number): string[] {\n\tif (path === \"\") return [];\n\t// Without a `\\`, every `/` separates.\n\tif (!path.includes(\"\\\\\")) return limit === undefined ? path.split(\"/\") : path.split(\"/\", limit);\n\tconst max = limit ?? Number.POSITIVE_INFINITY;\n\tconst out: string[] = [];\n\tlet start = 0;\n\tfor (let i = 0; i < path.length && out.length < max; i++) {\n\t\tconst c = path[i];\n\t\tif (c === \"\\\\\") {\n\t\t\t// The escaped character is never a separator.\n\t\t\ti++;\n\t\t} else if (c === \"/\") {\n\t\t\tout.push(path.slice(start, i));\n\t\t\tstart = i + 1;\n\t\t}\n\t}\n\tif (out.length < max) out.push(path.slice(start));\n\treturn out;\n}\n\n/**\n * A segment's content: each escaped `\\` or `/` as the character itself.\n *\n * Expects a segment as {@link parts} yields it from a valid path, where every `\\` escapes\n * the character after it.\n */\n// biome-ignore lint/suspicious/noShadowRestrictedNames: the name mirrors Rust; the deprecated global is unused.\nexport function unescape(segment: string): string {\n\treturn segment.includes(\"\\\\\") ? segment.replace(/\\\\(.)/gs, \"$1\") : segment;\n}\n\n/** The segment holding `content`: each `\\` or `/` escaped by a `\\`. The inverse of {@link unescape}. */\n// biome-ignore lint/suspicious/noShadowRestrictedNames: the name mirrors Rust; the deprecated global is unused.\nexport function escape(content: string): string {\n\treturn /[\\\\/]/.test(content) ? content.replace(/[\\\\/]/g, \"\\\\$&\") : content;\n}\n\n// Whether `segment` is one escaped segment: every `\\` escapes a `\\` or `/`, and no `/` is bare.\nfunction isSegment(segment: string): boolean {\n\treturn /^(?:[^\\\\/]|\\\\[\\\\/])*$/.test(segment);\n}\n\n// The most segments a prefix may have, matching the path limit on the wire.\nconst MAX_SEGMENTS = 32;\n\n/** The non-empty segments of a path, normalized like a broadcast path. */\nfunction splitPath(path: string): string[] {\n\treturn parts(path).filter((part) => part !== \"\");\n}\n\n/** Thrown when a grant member is not a valid {@link Prefix}. */\nexport class InvalidPrefix extends Error {\n\t/** Which rule was broken. */\n\treadonly code: InvalidPrefix.Code;\n\n\t/** Create an error with the broken rule in `code` and a human-readable `message`. */\n\tconstructor(code: InvalidPrefix.Code, message: string, options?: ErrorOptions) {\n\t\tsuper(message, options);\n\t\tthis.name = \"InvalidPrefix\";\n\t\tthis.code = code;\n\t}\n}\n\n/** Types for {@link InvalidPrefix}. */\nexport namespace InvalidPrefix {\n\t/** Why a string is not a valid {@link Prefix}. */\n\texport type Code =\n\t\t/** It holds a `*`: a grant is a prefix, never a wildcard. */\n\t\t| \"wildcard\"\n\t\t/** It is not a valid path: an empty segment, a bad escape, or too many segments. */\n\t\t| \"path\";\n}\n\n// Order two strings by code point, which agrees with UTF-8 byte order and so with the Rust crate.\nfunction compareText(a: string, b: string): number {\n\tconst n = Math.min(a.length, b.length);\n\tfor (let i = 0; i < n; i++) {\n\t\tlet x = a.charCodeAt(i);\n\t\tlet y = b.charCodeAt(i);\n\t\tif (x === y) continue;\n\t\t// UTF-16 sorts surrogates below U+E000..U+FFFF; code point order puts them above.\n\t\tif (x >= 0xd800 && y >= 0xd800) {\n\t\t\tx = x < 0xe000 ? x + 0x2000 : x - 0x800;\n\t\t\ty = y < 0xe000 ? y + 0x2000 : y - 0x800;\n\t\t}\n\t\treturn x - y;\n\t}\n\treturn a.length - b.length;\n}\n\n// Order two segment lists segment by segment, so a list sorts right before every list it starts.\nfunction compareSegments(a: readonly string[], b: readonly string[]): number {\n\tconst n = Math.min(a.length, b.length);\n\tfor (let i = 0; i < n; i++) {\n\t\tconst order = compareText(a[i], b[i]);\n\t\tif (order !== 0) return order;\n\t}\n\treturn a.length - b.length;\n}\n\n// Whether `inner` starts with every segment of `outer`.\nfunction startsWith(outer: readonly string[], inner: readonly string[]): boolean {\n\treturn outer.length <= inner.length && outer.every((segment, i) => segment === inner[i]);\n}\n\nfunction wildcard(text: string): InvalidPrefix {\n\tconst hint =\n\t\ttext === \"**\"\n\t\t\t? 'write the empty prefix \"\" for everything'\n\t\t\t: text.endsWith(\"/**\") && !text.slice(0, -3).includes(\"*\")\n\t\t\t\t? `write ${JSON.stringify(text.slice(0, -3))} for its subtree`\n\t\t\t\t: \"wildcards are refused\";\n\treturn new InvalidPrefix(\n\t\t\"wildcard\",\n\t\t`${JSON.stringify(text)} is a wildcard, but a grant is a prefix covering its whole subtree: ${hint}`,\n\t);\n}\n\n/**\n * One grant member: a path covering itself and every path beneath it. The empty prefix\n * covers every path.\n *\n * A prefix is never a wildcard: `foo` covers `foo` and its subtree, so a grant writes `foo`\n * where releases before 0.22 wrote `foo/**`, and the empty prefix where they wrote `**`.\n * Build one with {@link Prefix.parse} or {@link Prefix.all}.\n *\n * @public\n */\nexport class Prefix {\n\t/** The canonical text: segments joined by `/`, escapes as written. */\n\treadonly text: string;\n\t/** The segments, still escaped as written. */\n\treadonly segments: readonly string[];\n\n\tprivate constructor(segments: readonly string[]) {\n\t\tthis.segments = Object.freeze([...segments]);\n\t\tthis.text = segments.join(\"/\");\n\t\tObject.freeze(this);\n\t}\n\n\t/**\n\t * Parse a grant member. Throws {@link InvalidPrefix}: `wildcard` for any `*`, and `path`\n\t * for a leading, trailing, or doubled `/`, a `\\` that escapes neither `\\` nor `/`, or more\n\t * than 32 segments.\n\t */\n\tstatic parse(text: string): Prefix {\n\t\tif (text.includes(\"*\")) throw wildcard(text);\n\t\tconst invalid = (reason: string) =>\n\t\t\tnew InvalidPrefix(\"path\", `invalid prefix ${JSON.stringify(text)}: ${reason}`);\n\t\t// One past the limit is enough to refuse, without splitting a peer's megabytes of `a/a/...` first.\n\t\tconst segments = parts(text, MAX_SEGMENTS + 1);\n\t\tif (segments.length > MAX_SEGMENTS) throw invalid(`more than ${MAX_SEGMENTS} segments`);\n\t\tfor (const segment of segments) {\n\t\t\tif (segment === \"\") throw invalid(\"empty path segment\");\n\t\t\tif (!isSegment(segment)) throw invalid(`invalid segment ${JSON.stringify(segment)}`);\n\t\t}\n\t\treturn new Prefix(segments);\n\t}\n\n\t/** The empty prefix, which covers every path. */\n\tstatic all(): Prefix {\n\t\treturn new Prefix([]);\n\t}\n\n\t/** Order two prefixes segment by segment, so a prefix sorts right before everything beneath it. */\n\tstatic compare(a: Prefix, b: Prefix): number {\n\t\treturn compareSegments(a.segments, b.segments);\n\t}\n\n\t/** The canonical text. */\n\ttoString(): string {\n\t\treturn this.text;\n\t}\n\n\t/** Serializes as the canonical text, matching the Rust crate's serde form. */\n\ttoJSON(): string {\n\t\treturn this.text;\n\t}\n\n\t/** Whether the two are the same prefix. */\n\tequals(other: Prefix): boolean {\n\t\treturn this.text === other.text;\n\t}\n\n\t/** Whether this is the empty prefix, covering every path. */\n\tget isEmpty(): boolean {\n\t\treturn this.text === \"\";\n\t}\n\n\t/** Whether `path`, normalized like a broadcast path, is this prefix or beneath it. */\n\tmatches(path: string): boolean {\n\t\treturn startsWith(this.segments, splitPath(path));\n\t}\n\n\t/** Whether `path`, normalized like a broadcast path, and this prefix share a path: one lies beneath the other. */\n\toverlaps(path: string): boolean {\n\t\tconst segments = splitPath(path);\n\t\treturn startsWith(this.segments, segments) || startsWith(segments, this.segments);\n\t}\n\n\t/**\n\t * This prefix placed beneath the path `root`, normalized like a broadcast path (slashes\n\t * trimmed and collapsed). Throws {@link InvalidPrefix} when `root` holds a wildcard or a\n\t * malformed escape, or the result has more than 32 segments.\n\t */\n\trooted(root: string): Prefix {\n\t\tconst segments = [...Prefix.parse(splitPath(root).join(\"/\")).segments, ...this.segments];\n\t\tif (segments.length > MAX_SEGMENTS) {\n\t\t\tthrow new InvalidPrefix(\"path\", `more than ${MAX_SEGMENTS} segments`);\n\t\t}\n\t\treturn new Prefix(segments);\n\t}\n\n\t/**\n\t * This prefix as seen from the path `root`, normalized like a broadcast path: the rest\n\t * beneath it, or the empty prefix when this one covers `root` already. Undefined when the\n\t * two share no path.\n\t */\n\trebase(root: string): Prefix | undefined {\n\t\tconst base = splitPath(root);\n\t\tif (startsWith(this.segments, base)) return Prefix.all();\n\t\tif (startsWith(base, this.segments)) return new Prefix(this.segments.slice(base.length));\n\t\treturn undefined;\n\t}\n}\n\n/**\n * A grant: a set of {@link Prefix}es, reduced so no member lies beneath another, and sorted\n * segment by segment, so two sets covering the same paths are {@link Prefixes.equals | equal}.\n * The empty set grants nothing.\n *\n * Every operation is near-linear in the members on every shape: a prefix's ancestors sort\n * right before it, so finding the member covering a path is one binary search.\n *\n * @public\n */\nexport class Prefixes implements Iterable<Prefix> {\n\t#members: Prefix[] = [];\n\n\t/** The reduced set of the given prefixes. Empty when none are given. */\n\tconstructor(prefixes?: Iterable<Prefix>) {\n\t\tif (!prefixes) return;\n\t\tconst sorted = [...prefixes].sort(Prefix.compare);\n\t\t// Sorted, a prefix's subtree is the run right after it, so one sweep against the last\n\t\t// member kept drops every covered one.\n\t\tfor (const prefix of sorted) {\n\t\t\tconst last = this.#members[this.#members.length - 1];\n\t\t\tif (!last || !startsWith(last.segments, prefix.segments)) this.#members.push(prefix);\n\t\t}\n\t}\n\n\t/** The set holding the empty prefix, which covers every path. */\n\tstatic all(): Prefixes {\n\t\treturn new Prefixes([Prefix.all()]);\n\t}\n\n\t/** Parse each text as a {@link Prefix} into one set. Throws {@link InvalidPrefix}. */\n\tstatic parse(texts: Iterable<string>): Prefixes {\n\t\treturn new Prefixes(Array.from(texts, (text) => Prefix.parse(text)));\n\t}\n\n\t/**\n\t * Add a prefix, dropping the members beneath it.\n\t *\n\t * Returns false when a member already covers it, leaving the set unchanged.\n\t */\n\tinsert(prefix: Prefix): boolean {\n\t\tif (this.#covering(prefix.segments)) return false;\n\t\tconst at = this.#after(prefix.segments);\n\t\tlet end = at;\n\t\twhile (end < this.#members.length && startsWith(prefix.segments, this.#members[end].segments)) end++;\n\t\tthis.#members.splice(at, end - at, prefix);\n\t\treturn true;\n\t}\n\n\t/**\n\t * Whether some member covers `path`, normalized like a broadcast path. A member covering a\n\t * path covers its whole subtree, so this also says whether the set grants everything beneath it.\n\t */\n\tmatches(path: string): boolean {\n\t\treturn this.#covering(splitPath(path));\n\t}\n\n\t/** Whether some member lies at, above, or beneath `path`, normalized like a broadcast path. */\n\toverlaps(path: string): boolean {\n\t\tconst segments = splitPath(path);\n\t\tif (this.#covering(segments)) return true;\n\t\t// Anything beneath the path sorts right after it.\n\t\tconst next = this.#members[this.#after(segments)];\n\t\treturn next !== undefined && startsWith(segments, next.segments);\n\t}\n\n\t/** Whether every member of `other` is covered here: `other` grants nothing this set does not. */\n\tcovers(other: Prefixes): boolean {\n\t\treturn other.#members.every((prefix) => this.#covering(prefix.segments));\n\t}\n\n\t/** The paths in both sets: each member of one that the other covers. */\n\tintersect(other: Prefixes): Prefixes {\n\t\treturn new Prefixes([\n\t\t\t...this.#members.filter((prefix) => other.#covering(prefix.segments)),\n\t\t\t...other.#members.filter((prefix) => this.#covering(prefix.segments)),\n\t\t]);\n\t}\n\n\t/** What this set covers beneath `root`, named relative to it. See {@link Prefix.rebase}. */\n\trebase(root: string): Prefixes {\n\t\treturn new Prefixes(this.#members.flatMap((member) => member.rebase(root) ?? []));\n\t}\n\n\t/** Every member placed beneath `root`. See {@link Prefix.rooted}. */\n\trooted(root: string): Prefixes {\n\t\treturn new Prefixes(this.#members.map((member) => member.rooted(root)));\n\t}\n\n\t/** The number of members. */\n\tget size(): number {\n\t\treturn this.#members.length;\n\t}\n\n\t/** The members, in canonical order. */\n\t[Symbol.iterator](): Iterator<Prefix> {\n\t\treturn this.#members[Symbol.iterator]();\n\t}\n\n\t/** The members as a fresh array, in canonical order. */\n\ttoArray(): Prefix[] {\n\t\treturn [...this.#members];\n\t}\n\n\t/** Serializes as a list of texts, matching the Rust crate's serde form. */\n\ttoJSON(): string[] {\n\t\treturn this.#members.map((member) => member.text);\n\t}\n\n\t/** Whether the two sets cover the same paths. */\n\tequals(other: Prefixes): boolean {\n\t\treturn this.size === other.size && this.#members.every((member, i) => member.equals(other.#members[i]));\n\t}\n\n\t// Whether the last member at or before `segments` covers them. In a reduced, sorted set it is\n\t// the only candidate: any covering member sorts before them, with only its own subtree, which\n\t// holds no other member, in between.\n\t#covering(segments: readonly string[]): boolean {\n\t\tconst at = this.#after(segments);\n\t\tconst member = this.#members[at] && compareSegments(this.#members[at].segments, segments) === 0 ? at : at - 1;\n\t\treturn member >= 0 && startsWith(this.#members[member].segments, segments);\n\t}\n\n\t// The index of the first member sorting at or after `segments`.\n\t#after(segments: readonly string[]): number {\n\t\tlet lo = 0;\n\t\tlet hi = this.#members.length;\n\t\twhile (lo < hi) {\n\t\t\tconst mid = (lo + hi) >>> 1;\n\t\t\tif (compareSegments(this.#members[mid].segments, segments) < 0) lo = mid + 1;\n\t\t\telse hi = mid;\n\t\t}\n\t\treturn lo;\n\t}\n}\n"]}
|
package/priority.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"priority.d.ts","sourceRoot":"","sources":["../src/priority.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
package/priority.js
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Group stream prioritization shared by the moq-lite and moq-transport publishers, mirroring
|
|
3
|
+
* the Rust `lite::priority` queue.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { hooks } from "./internal.js";
|
|
8
|
+
// The transport compares send orders as a single number, so the ranks are packed into
|
|
9
|
+
// disjoint ranges: the subscriber's priority takes the high bits so it always dominates, the
|
|
10
|
+
// publisher's below it, and the position below that. Group data stays negative so protocol
|
|
11
|
+
// streams at the transport's default order of 0 always make progress. Two signed byte
|
|
12
|
+
// priorities and a 36-bit position fit the negative half of the safe integer range.
|
|
13
|
+
const GROUP_SPAN = 2 ** 36;
|
|
14
|
+
/**
|
|
15
|
+
* The transport send order for a group, where HIGHER values are transmitted first.
|
|
16
|
+
*
|
|
17
|
+
* A higher `priority` always wins. Below it, a group is ranked by its `position` in its own
|
|
18
|
+
* subscription rather than by its key, so two tracks at the same priority interleave:
|
|
19
|
+
* each one's next group ties with the other's, whatever their group numbering. Comparing
|
|
20
|
+
* keys instead would let a track that had been running longer, or that numbered its
|
|
21
|
+
* groups from a clock, starve one that started later.
|
|
22
|
+
*
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
export function sendOrder({ priority, publisher = 0, position = 0 }) {
|
|
26
|
+
const rank = (127 - clamp(priority, -128, 127)) * 256 + (127 - clamp(publisher, -128, 127));
|
|
27
|
+
return -(rank * GROUP_SPAN + clamp(position, 0, GROUP_SPAN - 1) + 1);
|
|
28
|
+
}
|
|
29
|
+
// Every rank is bounded: the priorities by their wire type, the position by the space left
|
|
30
|
+
// below them. Anything outside is a caller bug rather than a value worth preserving.
|
|
31
|
+
function clamp(value, min, max) {
|
|
32
|
+
return Math.min(Math.max(Math.trunc(value), min), max);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Ranks one subscription's group streams against each other, and re-ranks them whenever the
|
|
36
|
+
* set changes, the subscription is updated, or a stream's own {@link Ranking} may move.
|
|
37
|
+
*
|
|
38
|
+
* A group's rank is its policy's priority, then its position among the groups in flight at
|
|
39
|
+
* that priority, so which group goes first is decided here rather than by arithmetic on
|
|
40
|
+
* sequence numbers. The policy's {@link track.Order} picks the direction: newest first sheds a
|
|
41
|
+
* congested backlog rather than the live edge, oldest first drains it.
|
|
42
|
+
*
|
|
43
|
+
* One listener covers the whole subscription, plus one per signal the streams' rankings watch
|
|
44
|
+
* however many share it. A listener per group would instead pile up on the subscription, and a
|
|
45
|
+
* track that stalls with many groups open would trip the signals leak guard.
|
|
46
|
+
*
|
|
47
|
+
* @internal
|
|
48
|
+
*/
|
|
49
|
+
export class Priority {
|
|
50
|
+
#track;
|
|
51
|
+
#publisher;
|
|
52
|
+
#streams = new Map();
|
|
53
|
+
// Each signal the ranked streams' rankings watch, with how many do.
|
|
54
|
+
#watched = new Map();
|
|
55
|
+
#dispose;
|
|
56
|
+
#closed = false;
|
|
57
|
+
/**
|
|
58
|
+
* Follow `track`'s subscription until {@link close}, breaking ties at one subscriber
|
|
59
|
+
* priority by the track's `publisher` priority.
|
|
60
|
+
*/
|
|
61
|
+
constructor(track, publisher = 0) {
|
|
62
|
+
this.#track = track;
|
|
63
|
+
this.#publisher = publisher;
|
|
64
|
+
this.#dispose = hooks.preferences(track).revision.subscribe(() => this.#rerank());
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The send order for a stream starting at this group and object, before it opens, at
|
|
68
|
+
* `ranking`'s policy when it has one of its own.
|
|
69
|
+
*/
|
|
70
|
+
rank(key, object, ranking) {
|
|
71
|
+
const whole = this.#whole();
|
|
72
|
+
const start = { key, object, policy: ranking?.policy(whole) ?? whole };
|
|
73
|
+
let position = 0;
|
|
74
|
+
for (const other of this.#streams.values()) {
|
|
75
|
+
if (other.policy.priority === start.policy.priority && compareStarts(other, start) < 0)
|
|
76
|
+
position++;
|
|
77
|
+
}
|
|
78
|
+
return sendOrder({ priority: start.policy.priority, publisher: this.#publisher, position });
|
|
79
|
+
}
|
|
80
|
+
/** Hold a place for a stream starting at this group and object while it waits to open. */
|
|
81
|
+
reserve(key, object, ranking) {
|
|
82
|
+
const place = {
|
|
83
|
+
rank: () => this.rank(key, object, ranking),
|
|
84
|
+
release: () => this.remove(place),
|
|
85
|
+
};
|
|
86
|
+
this.#insert(place, key, object, ranking);
|
|
87
|
+
return place;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Rank a stream by its first object, at `ranking`'s policy when it has one of its own, now
|
|
91
|
+
* and after ranking changes, until {@link remove}.
|
|
92
|
+
*/
|
|
93
|
+
add(stream, key, object, ranking) {
|
|
94
|
+
// Also covers the stream itself: opening one can block on transport capacity, so an
|
|
95
|
+
// update that landed while it did predates this registration.
|
|
96
|
+
this.#insert(stream, key, object, ranking);
|
|
97
|
+
}
|
|
98
|
+
/** Stop ranking a finished group's stream, promoting whatever was queued behind it. */
|
|
99
|
+
remove(stream) {
|
|
100
|
+
const start = this.#streams.get(stream);
|
|
101
|
+
if (!start)
|
|
102
|
+
return;
|
|
103
|
+
this.#streams.delete(stream);
|
|
104
|
+
for (const getter of start.ranking?.changed ?? []) {
|
|
105
|
+
const watched = this.#watched.get(getter);
|
|
106
|
+
if (!watched)
|
|
107
|
+
continue;
|
|
108
|
+
watched.count--;
|
|
109
|
+
if (watched.count > 0)
|
|
110
|
+
continue;
|
|
111
|
+
watched.dispose();
|
|
112
|
+
this.#watched.delete(getter);
|
|
113
|
+
}
|
|
114
|
+
if (this.#closed && this.#streams.size === 0) {
|
|
115
|
+
this.#dispose();
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
this.#rerank();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Stop taking new groups, and release the subscription listener once the last one leaves.
|
|
123
|
+
*
|
|
124
|
+
* The track can finish while several groups are still draining, and those are the ones the
|
|
125
|
+
* subscriber is still waiting on. They keep being promoted as the groups ahead of them
|
|
126
|
+
* finish, rather than being stranded at whatever position they held when the track ended.
|
|
127
|
+
*/
|
|
128
|
+
close() {
|
|
129
|
+
this.#closed = true;
|
|
130
|
+
if (this.#streams.size === 0)
|
|
131
|
+
this.#dispose();
|
|
132
|
+
}
|
|
133
|
+
#insert(stream, key, object, ranking) {
|
|
134
|
+
this.#streams.set(stream, { key, object, ranking, policy: this.#whole() });
|
|
135
|
+
for (const getter of ranking?.changed ?? []) {
|
|
136
|
+
const watched = this.#watched.get(getter);
|
|
137
|
+
if (watched)
|
|
138
|
+
watched.count++;
|
|
139
|
+
else
|
|
140
|
+
this.#watched.set(getter, { count: 1, dispose: getter.subscribe(() => this.#rerank()) });
|
|
141
|
+
}
|
|
142
|
+
this.#rerank();
|
|
143
|
+
}
|
|
144
|
+
// The subscription's own policy, which a stream without a ranking of its own goes out at.
|
|
145
|
+
#whole() {
|
|
146
|
+
return hooks.preferences(this.#track).policy();
|
|
147
|
+
}
|
|
148
|
+
// Sorted once, so ranking every stream costs one sort rather than a scan per stream: a
|
|
149
|
+
// stream's position is how many at its priority sort strictly ahead of it.
|
|
150
|
+
#rerank() {
|
|
151
|
+
const whole = this.#whole();
|
|
152
|
+
for (const start of this.#streams.values())
|
|
153
|
+
start.policy = start.ranking?.policy(whole) ?? whole;
|
|
154
|
+
const queue = [...this.#streams].sort(([, a], [, b]) => compareStarts(a, b));
|
|
155
|
+
let first = 0;
|
|
156
|
+
let position = 0;
|
|
157
|
+
for (let i = 0; i < queue.length; i++) {
|
|
158
|
+
const [stream, start] = queue[i];
|
|
159
|
+
const prev = queue[i - 1]?.[1];
|
|
160
|
+
if (prev?.policy.priority !== start.policy.priority) {
|
|
161
|
+
first = i;
|
|
162
|
+
position = 0;
|
|
163
|
+
}
|
|
164
|
+
else if (compareStarts(prev, start) !== 0) {
|
|
165
|
+
position = i - first;
|
|
166
|
+
}
|
|
167
|
+
if ("setPriority" in stream)
|
|
168
|
+
stream.setPriority(sendOrder({ priority: start.policy.priority, publisher: this.#publisher, position }));
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
// Negative when `a` goes before `b`. A higher priority goes first. Within one, each start's
|
|
173
|
+
// own order picks the direction, newest first when descending and oldest first when
|
|
174
|
+
// ascending, so starts of two orders compare by key against negated key. Earlier objects win
|
|
175
|
+
// within one group so a fill precedes its live rest, and identical starts tie.
|
|
176
|
+
function compareStarts(a, b) {
|
|
177
|
+
if (a.policy.priority !== b.policy.priority)
|
|
178
|
+
return b.policy.priority - a.policy.priority;
|
|
179
|
+
const signed = (start) => (start.policy.order === "ascending" ? -start.key : start.key);
|
|
180
|
+
const [x, y] = [signed(a), signed(b)];
|
|
181
|
+
if (x !== y)
|
|
182
|
+
return x > y ? -1 : 1;
|
|
183
|
+
return a.object - b.object;
|
|
184
|
+
}
|
|
185
|
+
//# sourceMappingURL=priority.js.map
|
package/priority.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"priority.js","sourceRoot":"","sources":["../src/priority.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAKtC,sFAAsF;AACtF,6FAA6F;AAC7F,2FAA2F;AAC3F,sFAAsF;AACtF,oFAAoF;AACpF,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE,CAAC;AAwB3B;;;;;;;;;;GAUG;AACH,MAAM,UAAU,SAAS,CAAC,EAAE,QAAQ,EAAE,SAAS,GAAG,CAAC,EAAE,QAAQ,GAAG,CAAC,EAAQ;IACxE,MAAM,IAAI,GAAG,CAAC,GAAG,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;IAC5F,OAAO,CAAC,CAAC,IAAI,GAAG,UAAU,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC,EAAE,UAAU,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;AACtE,CAAC;AAED,2FAA2F;AAC3F,qFAAqF;AACrF,SAAS,KAAK,CAAC,KAAa,EAAE,GAAW,EAAE,GAAW;IACrD,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;AACxD,CAAC;AAwCD;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,QAAQ;IACpB,MAAM,CAAmB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AA6F;AAC7F,+EAA+E;AAC/E,SAAS,aAAa,CAAC,CAAQ,EAAE,CAAQ;IACxC,IAAI,CAAC,CAAC,MAAM,CAAC,QAAQ,KAAK,CAAC,CAAC,MAAM,CAAC,QAAQ;QAAE,OAAO,CAAC,CAAC,MAAM,CAAC,QAAQ,GAAG,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC;IAC1F,MAAM,MAAM,GAAG,CAAC,KAAY,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,KAAK,WAAW,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC/F,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IACtC,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACnC,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;AAC5B,CAAC","sourcesContent":["/**\n * Group stream prioritization shared by the moq-lite and moq-transport publishers, mirroring\n * the Rust `lite::priority` queue.\n *\n * @module\n */\n\nimport type { Dispose, Getter } from \"@moq/signals\";\nimport { hooks } from \"./internal.ts\";\nimport type { Policy } from \"./lite/subscribe.ts\";\nimport type { Writer } from \"./stream.ts\";\nimport type * as track from \"./track.ts\";\n\n// The transport compares send orders as a single number, so the ranks are packed into\n// disjoint ranges: the subscriber's priority takes the high bits so it always dominates, the\n// publisher's below it, and the position below that. Group data stays negative so protocol\n// streams at the transport's default order of 0 always make progress. Two signed byte\n// priorities and a 36-bit position fit the negative half of the safe integer range.\nconst GROUP_SPAN = 2 ** 36;\n\n/**\n * What to rank a group stream by.\n *\n * @internal\n */\nexport interface Rank {\n\t/** The subscriber's track priority (`-128..=127`), which outweighs everything below it. */\n\tpriority: number;\n\n\t/**\n\t * The publisher's track priority (`-128..=127`), breaking ties between subscriptions at one\n\t * subscriber priority. Defaults to 0, the unset priority.\n\t */\n\tpublisher?: number;\n\n\t/**\n\t * Where the group sits in the queue its own subscription wants sent, 0 being the one to\n\t * send next. Defaults to 0, which is right for a stream that is the only one of its kind.\n\t */\n\tposition?: number;\n}\n\n/**\n * The transport send order for a group, where HIGHER values are transmitted first.\n *\n * A higher `priority` always wins. Below it, a group is ranked by its `position` in its own\n * subscription rather than by its key, so two tracks at the same priority interleave:\n * each one's next group ties with the other's, whatever their group numbering. Comparing\n * keys instead would let a track that had been running longer, or that numbered its\n * groups from a clock, starve one that started later.\n *\n * @internal\n */\nexport function sendOrder({ priority, publisher = 0, position = 0 }: Rank): number {\n\tconst rank = (127 - clamp(priority, -128, 127)) * 256 + (127 - clamp(publisher, -128, 127));\n\treturn -(rank * GROUP_SPAN + clamp(position, 0, GROUP_SPAN - 1) + 1);\n}\n\n// Every rank is bounded: the priorities by their wire type, the position by the space left\n// below them. Anything outside is a caller bug rather than a value worth preserving.\nfunction clamp(value: number, min: number, max: number): number {\n\treturn Math.min(Math.max(Math.trunc(value), min), max);\n}\n\n/**\n * A group stream's own ranking, for one whose policy can differ from its subscription's:\n * lite-07 ranks each group by the ranges still wanting it.\n *\n * @internal\n */\nexport interface Ranking {\n\t/** The policy the stream goes out at now, `whole` being the subscription's. */\n\tpolicy(whole: Policy): Policy;\n\t/** What besides the subscription can change {@link policy}, watched while the stream is ranked. */\n\treadonly changed: readonly Getter<unknown>[];\n}\n\n// Where a group stream starts, its group and its first object in that group, with the ranking\n// it has of its own and the policy it was last ranked at.\ninterface Start {\n\tkey: bigint;\n\tobject: number;\n\tranking?: Ranking;\n\tpolicy: Policy;\n}\n\n// A stream ranked by its start: an open one, or a place held for one still waiting to open.\ntype Ranked = Pick<Writer, \"setPriority\"> | Place;\n\n/**\n * A group stream's place while it waits for stream credit: it ranks the subscription's other\n * streams as an open one would, so a newer group overtakes an older one still waiting.\n *\n * @internal\n */\nexport interface Place {\n\t/** The send order the stream would open at now. */\n\trank(): number;\n\t/** Give the place up, once the stream opened or will not. */\n\trelease(): void;\n}\n\n/**\n * Ranks one subscription's group streams against each other, and re-ranks them whenever the\n * set changes, the subscription is updated, or a stream's own {@link Ranking} may move.\n *\n * A group's rank is its policy's priority, then its position among the groups in flight at\n * that priority, so which group goes first is decided here rather than by arithmetic on\n * sequence numbers. The policy's {@link track.Order} picks the direction: newest first sheds a\n * congested backlog rather than the live edge, oldest first drains it.\n *\n * One listener covers the whole subscription, plus one per signal the streams' rankings watch\n * however many share it. A listener per group would instead pile up on the subscription, and a\n * track that stalls with many groups open would trip the signals leak guard.\n *\n * @internal\n */\nexport class Priority {\n\t#track: track.Subscriber;\n\t#publisher: number;\n\t#streams = new Map<Ranked, Start>();\n\t// Each signal the ranked streams' rankings watch, with how many do.\n\t#watched = new Map<Getter<unknown>, { count: number; dispose: Dispose }>();\n\t#dispose: Dispose;\n\t#closed = false;\n\n\t/**\n\t * Follow `track`'s subscription until {@link close}, breaking ties at one subscriber\n\t * priority by the track's `publisher` priority.\n\t */\n\tconstructor(track: track.Subscriber, publisher = 0) {\n\t\tthis.#track = track;\n\t\tthis.#publisher = publisher;\n\t\tthis.#dispose = hooks.preferences(track).revision.subscribe(() => this.#rerank());\n\t}\n\n\t/**\n\t * The send order for a stream starting at this group and object, before it opens, at\n\t * `ranking`'s policy when it has one of its own.\n\t */\n\trank(key: bigint, object: number, ranking?: Ranking): number {\n\t\tconst whole = this.#whole();\n\t\tconst start = { key, object, policy: ranking?.policy(whole) ?? whole };\n\t\tlet position = 0;\n\t\tfor (const other of this.#streams.values()) {\n\t\t\tif (other.policy.priority === start.policy.priority && compareStarts(other, start) < 0) position++;\n\t\t}\n\t\treturn sendOrder({ priority: start.policy.priority, publisher: this.#publisher, position });\n\t}\n\n\t/** Hold a place for a stream starting at this group and object while it waits to open. */\n\treserve(key: bigint, object: number, ranking?: Ranking): Place {\n\t\tconst place: Place = {\n\t\t\trank: () => this.rank(key, object, ranking),\n\t\t\trelease: () => this.remove(place),\n\t\t};\n\t\tthis.#insert(place, key, object, ranking);\n\t\treturn place;\n\t}\n\n\t/**\n\t * Rank a stream by its first object, at `ranking`'s policy when it has one of its own, now\n\t * and after ranking changes, until {@link remove}.\n\t */\n\tadd(stream: Writer, key: bigint, object: number, ranking?: Ranking) {\n\t\t// Also covers the stream itself: opening one can block on transport capacity, so an\n\t\t// update that landed while it did predates this registration.\n\t\tthis.#insert(stream, key, object, ranking);\n\t}\n\n\t/** Stop ranking a finished group's stream, promoting whatever was queued behind it. */\n\tremove(stream: Ranked) {\n\t\tconst start = this.#streams.get(stream);\n\t\tif (!start) return;\n\t\tthis.#streams.delete(stream);\n\t\tfor (const getter of start.ranking?.changed ?? []) {\n\t\t\tconst watched = this.#watched.get(getter);\n\t\t\tif (!watched) continue;\n\t\t\twatched.count--;\n\t\t\tif (watched.count > 0) continue;\n\t\t\twatched.dispose();\n\t\t\tthis.#watched.delete(getter);\n\t\t}\n\n\t\tif (this.#closed && this.#streams.size === 0) {\n\t\t\tthis.#dispose();\n\t\t} else {\n\t\t\tthis.#rerank();\n\t\t}\n\t}\n\n\t/**\n\t * Stop taking new groups, and release the subscription listener once the last one leaves.\n\t *\n\t * The track can finish while several groups are still draining, and those are the ones the\n\t * subscriber is still waiting on. They keep being promoted as the groups ahead of them\n\t * finish, rather than being stranded at whatever position they held when the track ended.\n\t */\n\tclose() {\n\t\tthis.#closed = true;\n\t\tif (this.#streams.size === 0) this.#dispose();\n\t}\n\n\t#insert(stream: Ranked, key: bigint, object: number, ranking?: Ranking) {\n\t\tthis.#streams.set(stream, { key, object, ranking, policy: this.#whole() });\n\t\tfor (const getter of ranking?.changed ?? []) {\n\t\t\tconst watched = this.#watched.get(getter);\n\t\t\tif (watched) watched.count++;\n\t\t\telse this.#watched.set(getter, { count: 1, dispose: getter.subscribe(() => this.#rerank()) });\n\t\t}\n\t\tthis.#rerank();\n\t}\n\n\t// The subscription's own policy, which a stream without a ranking of its own goes out at.\n\t#whole(): Policy {\n\t\treturn hooks.preferences(this.#track).policy();\n\t}\n\n\t// Sorted once, so ranking every stream costs one sort rather than a scan per stream: a\n\t// stream's position is how many at its priority sort strictly ahead of it.\n\t#rerank() {\n\t\tconst whole = this.#whole();\n\t\tfor (const start of this.#streams.values()) start.policy = start.ranking?.policy(whole) ?? whole;\n\t\tconst queue = [...this.#streams].sort(([, a], [, b]) => compareStarts(a, b));\n\t\tlet first = 0;\n\t\tlet position = 0;\n\t\tfor (let i = 0; i < queue.length; i++) {\n\t\t\tconst [stream, start] = queue[i];\n\t\t\tconst prev = queue[i - 1]?.[1];\n\t\t\tif (prev?.policy.priority !== start.policy.priority) {\n\t\t\t\tfirst = i;\n\t\t\t\tposition = 0;\n\t\t\t} else if (compareStarts(prev, start) !== 0) {\n\t\t\t\tposition = i - first;\n\t\t\t}\n\t\t\tif (\"setPriority\" in stream)\n\t\t\t\tstream.setPriority(\n\t\t\t\t\tsendOrder({ priority: start.policy.priority, publisher: this.#publisher, position }),\n\t\t\t\t);\n\t\t}\n\t}\n}\n\n// Negative when `a` goes before `b`. A higher priority goes first. Within one, each start's\n// own order picks the direction, newest first when descending and oldest first when\n// ascending, so starts of two orders compare by key against negated key. Earlier objects win\n// within one group so a fill precedes its live rest, and identical starts tie.\nfunction compareStarts(a: Start, b: Start): number {\n\tif (a.policy.priority !== b.policy.priority) return b.policy.priority - a.policy.priority;\n\tconst signed = (start: Start) => (start.policy.order === \"ascending\" ? -start.key : start.key);\n\tconst [x, y] = [signed(a), signed(b)];\n\tif (x !== y) return x > y ? -1 : 1;\n\treturn a.object - b.object;\n}\n"]}
|
package/queue.d.ts
ADDED
package/queue.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["../src/queue.ts"],"names":[],"mappings":""}
|