reactor-effect-client 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (219) hide show
  1. package/README.md +66 -6
  2. package/dist/FetchHttp.js +1 -1
  3. package/dist/FetchHttp.js.map +1 -1
  4. package/dist/PeerFactory.d.ts +13 -2
  5. package/dist/PeerFactory.d.ts.map +1 -1
  6. package/dist/PeerFactory.js.map +1 -1
  7. package/dist/PeerTypes.d.ts +2 -2
  8. package/dist/PeerTypes.d.ts.map +1 -1
  9. package/dist/Sequence.d.ts +18 -14
  10. package/dist/Sequence.d.ts.map +1 -1
  11. package/dist/Sequence.js +117 -122
  12. package/dist/Sequence.js.map +1 -1
  13. package/dist/SessionTypes.d.ts +172 -15
  14. package/dist/SessionTypes.d.ts.map +1 -1
  15. package/dist/SessionTypes.js +18 -1
  16. package/dist/SessionTypes.js.map +1 -1
  17. package/dist/bytes.js +3 -3
  18. package/dist/bytes.js.map +1 -1
  19. package/dist/contract.d.ts +120 -29
  20. package/dist/contract.d.ts.map +1 -1
  21. package/dist/contract.js +105 -73
  22. package/dist/contract.js.map +1 -1
  23. package/dist/coordinator/_internal/client.d.ts +111 -17
  24. package/dist/coordinator/_internal/client.d.ts.map +1 -1
  25. package/dist/coordinator/_internal/client.js +187 -74
  26. package/dist/coordinator/_internal/client.js.map +1 -1
  27. package/dist/coordinator/_internal/recording.d.ts +33 -0
  28. package/dist/coordinator/_internal/recording.d.ts.map +1 -0
  29. package/dist/coordinator/_internal/recording.js +123 -0
  30. package/dist/coordinator/_internal/recording.js.map +1 -0
  31. package/dist/coordinator/_internal/response.d.ts.map +1 -1
  32. package/dist/coordinator/_internal/response.js +5 -7
  33. package/dist/coordinator/_internal/response.js.map +1 -1
  34. package/dist/coordinator/_internal/schemas.d.ts +40 -6
  35. package/dist/coordinator/_internal/schemas.d.ts.map +1 -1
  36. package/dist/coordinator/_internal/schemas.js +94 -64
  37. package/dist/coordinator/_internal/schemas.js.map +1 -1
  38. package/dist/coordinator/index.d.ts +14 -2
  39. package/dist/coordinator/index.d.ts.map +1 -1
  40. package/dist/coordinator/index.js +14 -18
  41. package/dist/coordinator/index.js.map +1 -1
  42. package/dist/correlation.d.ts +15 -0
  43. package/dist/correlation.d.ts.map +1 -1
  44. package/dist/correlation.js +26 -8
  45. package/dist/correlation.js.map +1 -1
  46. package/dist/duration.d.ts +25 -0
  47. package/dist/duration.d.ts.map +1 -0
  48. package/dist/duration.js +47 -0
  49. package/dist/duration.js.map +1 -0
  50. package/dist/errors.d.ts +1264 -49
  51. package/dist/errors.d.ts.map +1 -1
  52. package/dist/errors.js +698 -46
  53. package/dist/errors.js.map +1 -1
  54. package/dist/h3/_internal/client.d.ts +2 -2
  55. package/dist/h3/_internal/client.d.ts.map +1 -1
  56. package/dist/h3/_internal/client.js +280 -146
  57. package/dist/h3/_internal/client.js.map +1 -1
  58. package/dist/h3/_internal/contracts.d.ts.map +1 -1
  59. package/dist/h3/_internal/contracts.js +2 -2
  60. package/dist/h3/_internal/contracts.js.map +1 -1
  61. package/dist/h3/_internal/deployment.d.ts.map +1 -1
  62. package/dist/h3/_internal/deployment.js +5 -4
  63. package/dist/h3/_internal/deployment.js.map +1 -1
  64. package/dist/h3/_internal/evidence.js +1 -1
  65. package/dist/h3/_internal/evidence.js.map +1 -1
  66. package/dist/h3/_internal/operations.d.ts +58 -0
  67. package/dist/h3/_internal/operations.d.ts.map +1 -0
  68. package/dist/h3/_internal/operations.js +268 -0
  69. package/dist/h3/_internal/operations.js.map +1 -0
  70. package/dist/h3/_internal/references.d.ts.map +1 -1
  71. package/dist/h3/_internal/references.js +3 -8
  72. package/dist/h3/_internal/references.js.map +1 -1
  73. package/dist/h3/_internal/request.js +1 -1
  74. package/dist/h3/_internal/request.js.map +1 -1
  75. package/dist/h3/_internal/retained.d.ts +22 -0
  76. package/dist/h3/_internal/retained.d.ts.map +1 -0
  77. package/dist/h3/_internal/retained.js +89 -0
  78. package/dist/h3/_internal/retained.js.map +1 -0
  79. package/dist/h3/_internal/state.d.ts +15 -1
  80. package/dist/h3/_internal/state.d.ts.map +1 -1
  81. package/dist/h3/_internal/state.js +69 -29
  82. package/dist/h3/_internal/state.js.map +1 -1
  83. package/dist/h3/index.d.ts +1 -1
  84. package/dist/h3/index.d.ts.map +1 -1
  85. package/dist/h3/messages.d.ts +118 -109
  86. package/dist/h3/messages.d.ts.map +1 -1
  87. package/dist/h3/messages.js +73 -51
  88. package/dist/h3/messages.js.map +1 -1
  89. package/dist/h3/types.d.ts +109 -13
  90. package/dist/h3/types.d.ts.map +1 -1
  91. package/dist/host.d.ts +6 -6
  92. package/dist/host.d.ts.map +1 -1
  93. package/dist/host.js +4 -5
  94. package/dist/host.js.map +1 -1
  95. package/dist/index.d.ts +11 -5
  96. package/dist/index.d.ts.map +1 -1
  97. package/dist/index.js +5 -1
  98. package/dist/index.js.map +1 -1
  99. package/dist/json.d.ts +13 -6
  100. package/dist/json.d.ts.map +1 -1
  101. package/dist/json.js +34 -14
  102. package/dist/json.js.map +1 -1
  103. package/dist/media-stream.d.ts.map +1 -1
  104. package/dist/media-stream.js +9 -11
  105. package/dist/media-stream.js.map +1 -1
  106. package/dist/observation.d.ts +9 -0
  107. package/dist/observation.d.ts.map +1 -1
  108. package/dist/observation.js +20 -18
  109. package/dist/observation.js.map +1 -1
  110. package/dist/orchestration/h3-source.d.ts +32 -4
  111. package/dist/orchestration/h3-source.d.ts.map +1 -1
  112. package/dist/orchestration/h3-source.js +47 -14
  113. package/dist/orchestration/h3-source.js.map +1 -1
  114. package/dist/orchestration/index.d.ts +9 -6
  115. package/dist/orchestration/index.d.ts.map +1 -1
  116. package/dist/orchestration/index.js +5 -3
  117. package/dist/orchestration/index.js.map +1 -1
  118. package/dist/orchestration/media-buffer.d.ts +12 -4
  119. package/dist/orchestration/media-buffer.d.ts.map +1 -1
  120. package/dist/orchestration/media-buffer.js +31 -11
  121. package/dist/orchestration/media-buffer.js.map +1 -1
  122. package/dist/orchestration/open-h3.d.ts +65 -0
  123. package/dist/orchestration/open-h3.d.ts.map +1 -0
  124. package/dist/orchestration/open-h3.js +65 -0
  125. package/dist/orchestration/open-h3.js.map +1 -0
  126. package/dist/orchestration/references.d.ts +5 -1
  127. package/dist/orchestration/references.d.ts.map +1 -1
  128. package/dist/orchestration/references.js +37 -34
  129. package/dist/orchestration/references.js.map +1 -1
  130. package/dist/orchestration/renewal-state.js +1 -1
  131. package/dist/orchestration/renewal-state.js.map +1 -1
  132. package/dist/orchestration/renewal.d.ts +64 -64
  133. package/dist/orchestration/renewal.d.ts.map +1 -1
  134. package/dist/orchestration/renewal.js +149 -88
  135. package/dist/orchestration/renewal.js.map +1 -1
  136. package/dist/orchestration/request.d.ts +11 -12
  137. package/dist/orchestration/request.d.ts.map +1 -1
  138. package/dist/orchestration/request.js +63 -66
  139. package/dist/orchestration/request.js.map +1 -1
  140. package/dist/orchestration/routing.d.ts.map +1 -1
  141. package/dist/orchestration/routing.js +17 -14
  142. package/dist/orchestration/routing.js.map +1 -1
  143. package/dist/orchestration/source-slot.d.ts +15 -5
  144. package/dist/orchestration/source-slot.d.ts.map +1 -1
  145. package/dist/orchestration/source-slot.js +40 -21
  146. package/dist/orchestration/source-slot.js.map +1 -1
  147. package/dist/orchestration/types.d.ts +594 -39
  148. package/dist/orchestration/types.d.ts.map +1 -1
  149. package/dist/orchestration/types.js +20 -0
  150. package/dist/orchestration/types.js.map +1 -1
  151. package/dist/protobuf.js +2 -2
  152. package/dist/protobuf.js.map +1 -1
  153. package/dist/session/_internal/acquire.d.ts +4 -6
  154. package/dist/session/_internal/acquire.d.ts.map +1 -1
  155. package/dist/session/_internal/acquire.js +40 -50
  156. package/dist/session/_internal/acquire.js.map +1 -1
  157. package/dist/session/_internal/cleanup.d.ts +2 -1
  158. package/dist/session/_internal/cleanup.d.ts.map +1 -1
  159. package/dist/session/_internal/cleanup.js +23 -15
  160. package/dist/session/_internal/cleanup.js.map +1 -1
  161. package/dist/session/_internal/lifecycle.d.ts +5 -0
  162. package/dist/session/_internal/lifecycle.d.ts.map +1 -1
  163. package/dist/session/_internal/lifecycle.js +16 -6
  164. package/dist/session/_internal/lifecycle.js.map +1 -1
  165. package/dist/session/_internal/remote.d.ts.map +1 -1
  166. package/dist/session/_internal/remote.js +16 -7
  167. package/dist/session/_internal/remote.js.map +1 -1
  168. package/dist/session/_internal/uploads.d.ts +4 -1
  169. package/dist/session/_internal/uploads.d.ts.map +1 -1
  170. package/dist/session/_internal/uploads.js +25 -27
  171. package/dist/session/_internal/uploads.js.map +1 -1
  172. package/dist/session/commands.d.ts +1 -21
  173. package/dist/session/commands.d.ts.map +1 -1
  174. package/dist/session/commands.js +1 -12
  175. package/dist/session/commands.js.map +1 -1
  176. package/dist/session/files.d.ts +10 -2
  177. package/dist/session/files.d.ts.map +1 -1
  178. package/dist/session/files.js +11 -16
  179. package/dist/session/files.js.map +1 -1
  180. package/dist/session/index.d.ts +6 -6
  181. package/dist/session/index.d.ts.map +1 -1
  182. package/dist/session/index.js.map +1 -1
  183. package/dist/session/media.d.ts +53 -6
  184. package/dist/session/media.d.ts.map +1 -1
  185. package/dist/session/recorder.d.ts +24 -0
  186. package/dist/session/recorder.d.ts.map +1 -0
  187. package/dist/session/recorder.js +19 -0
  188. package/dist/session/recorder.js.map +1 -0
  189. package/dist/session.d.ts +5 -4
  190. package/dist/session.d.ts.map +1 -1
  191. package/dist/session.js +213 -110
  192. package/dist/session.js.map +1 -1
  193. package/dist/simulation/_internal/source.d.ts.map +1 -1
  194. package/dist/simulation/_internal/source.js +57 -48
  195. package/dist/simulation/_internal/source.js.map +1 -1
  196. package/dist/simulation/index.d.ts +4 -5
  197. package/dist/simulation/index.d.ts.map +1 -1
  198. package/dist/simulation/index.js +3 -4
  199. package/dist/simulation/index.js.map +1 -1
  200. package/dist/simulation/types.d.ts +16 -2
  201. package/dist/simulation/types.d.ts.map +1 -1
  202. package/dist/stats.d.ts +19 -0
  203. package/dist/stats.d.ts.map +1 -1
  204. package/dist/stats.js +79 -8
  205. package/dist/stats.js.map +1 -1
  206. package/package.json +5 -4
  207. package/notices/owned-webrtc/Effect-MIT.txt +0 -21
  208. package/notices/owned-webrtc/IETF.txt +0 -43
  209. package/notices/owned-webrtc/LICENSE +0 -21
  210. package/notices/owned-webrtc/UPSTREAM.md +0 -20
  211. package/notices/owned-webrtc/VP8-ADAPTATION.md +0 -32
  212. package/notices/owned-webrtc/VP8-AUTHORS.txt +0 -42
  213. package/notices/owned-webrtc/VP8-LICENSE.txt +0 -25
  214. package/notices/owned-webrtc/VP8-PATENTS.txt +0 -21
  215. package/notices/owned-webrtc/Werift-MIT.txt +0 -21
  216. package/notices/owned-webrtc/libvpx-v1.12.0-LICENSE.txt +0 -28
  217. package/notices/owned-webrtc/libvpx-v1.12.0-PATENTS.txt +0 -22
  218. package/notices/owned-webrtc/rfc3711.txt +0 -3139
  219. package/notices/owned-webrtc/str0m-MIT.txt +0 -7
package/README.md CHANGED
@@ -67,13 +67,67 @@ const clientLayer = Reactor.layer().pipe(
67
67
  const main = Effect.scoped(useSession).pipe(Effect.provide(clientLayer));
68
68
  ```
69
69
 
70
- `Native.make(configuration, nativeOptions)` and `Browser.make(configuration)` also construct the canonical factory with their host peer already selected. Constructing a factory makes no allocation. HTTP and crypto services remain explicit. The root session constructor has no filesystem or path requirement.
70
+ Building a host layer is its preflight: `Native.layer()` loads and verifies the native library, and `Browser.layer` detects WebRTC, so an unsupported host fails while the layer is built, before any `Client` exists to allocate a remote session. Constructing a factory makes no allocation. HTTP and crypto services remain explicit. The root session constructor has no filesystem or path requirement. A custom host provides `PeerFactory` itself: `make` returns a fresh `Peer` for each connection generation, and an optional `check` fails when the host cannot create one right now; the factory runs it before every remote allocation.
71
71
 
72
- Browser and native media values stay bound to their negotiated generation. A reconnect creates a new generation; existing readers end or fail with their source. Applications obtain the new media generation explicitly, or opt into orchestration's recovering media streams.
72
+ Browser and native media values stay bound to their negotiated generation. A reconnect creates a new generation; existing readers end or fail with their source. Applications obtain the new media generation explicitly, or opt into orchestration's recovering media streams. Each `VideoFrame` declares its pixel `format` (`"BGRA"` from the native host); nothing converts between formats implicitly. A recorder reads a track directly and sees loss before admission as a rise in `pressure`'s `droppedVideo`/`droppedAudio`, and a reader that falls behind its bound fails with `Overflow` and counts in `readerOverflows`. Every frame carries its admission `sequence` on its track, so `recorder(stream)` yields each frame plus a `Lost { after, count }` wherever the host dropped frames, at their position. A preview keeps only the newest frame with `Stream.buffer({ capacity: 1, strategy: "sliding" })`.
73
+
74
+ ## Errors
75
+
76
+ Every failure the client raises is one of four classes, each with its own `_tag`, so `Effect.catchTag` and a Schema union tell them apart:
77
+
78
+ - `ReactorError`: a session, coordinator or host failure;
79
+ - `CommandFailure`: a failed command, with the dispatch evidence its owner established;
80
+ - `AcquisitionFailure`: a failed acquisition, with the `cleanup` report of its partial lease, kept by reference;
81
+ - `PolicyFailure`, from `/orchestration`: a local refusal, which was never dispatched.
82
+
83
+ `isReactorFailure` recognizes any of them, and each class has an `is` guard. Re-raise a known failure through a guard rather than `instanceof ReactorError`, which none of the other three satisfies.
84
+
85
+ Each carries a tagged `reason`: route on `reason._tag`, with `Effect.catchReason`, `catchReasons` or `unwrapReason`. A `ReactorError`, `CommandFailure` or `AcquisitionFailure` reason is `Failure`, whose tag is a code such as `Timeout`, `Disconnected` or `InvalidInput`, or one of the reasons with fields of their own: `Http` (`status`, `retryAfter`, `body`), `Remote` and `RecorderDisabled` (`remoteCode`, `body`), `Native` (`status`, a Redacted `backendMessage`), `IceFailed` (`pairs`, `candidateTypes`) and `TransportFailed` (`pairs`). `ErrorCode` is the union of those tags. A `PolicyFailure` reason is a `Refusal` such as `QueueFull`, `SessionRecovering` or `Busy`, `Missing` with the request field whose clip has no known owner, or `Sequence` with the sequence's code.
86
+
87
+ `context.outcome` says whether the remote may have applied the request: `not-submitted`, `unknown` or `replied`. A `PolicyFailure`'s outcome is always `not-submitted`, so an `EngineError = CommandFailure | PolicyFailure` is read without narrowing. `isRetryable` is true for local backpressure, a connection lost before dispatch, an HTTP refusal that names a delay, and the `QueueFull` and `SessionRecovering` refusals, and never when the outcome is `unknown`; `retryAfter` is the delay an `Http` reason named.
88
+
89
+ ```ts
90
+ const admission = (failure: EngineError) =>
91
+ failure.context.outcome === "unknown" ? "reconcile" : failure.isRetryable ? "defer" : "reject";
92
+
93
+ const enqueued = engine.enqueue(request).pipe(
94
+ Effect.catchReasons("PolicyFailure", {
95
+ QueueFull: () => Effect.succeed("wait for a free generation slot"),
96
+ SessionRecovering: () => Effect.succeed("wait for the session to recover"),
97
+ }),
98
+ );
99
+ ```
100
+
101
+ `message` is written by the library and never contains provider or payload text, so spans and logs that record it stay payload-free. Provider and backend text is kept only for explicit inspection: `Http.body`, `Remote.body`, the Redacted `Native.backendMessage` and `context.detail`. Diagnostic JSON leaves all of them out, and none of them is part of the cause chain that exporters render.
102
+
103
+ ## Tracing
104
+
105
+ The client traces through Effect's `Tracer`, so any tracer the application provides, such as `OtlpTracer`, receives its spans. An operation a caller can cancel has a client span at the call: `reactor.session.create` and `reactor.session.attach`, `reactor.session.connect` and `reactor.session.reconnect` (with an event per phase, from `reactor.connect.described` to `reactor.connect.ready`), `reactor.session.upload` and `reactor.session.close`, and in orchestration `reactor.orchestration.renewal.open`, `recover`, `replace` and `switch`. A request the session owns past its caller's wait, a command or control request (`reactor.session.command`, `reactor.session.control`) or an H3 enqueue (`reactor.h3.enqueue`, with `reactor.h3.reconcile`), has its span on its own execution, so the span ends with the request's outcome even after the caller stopped waiting. Termination returns a verdict rather than failing, so `reactor.coordinator.terminate` and `reactor.session.close` carry it as `reactor.termination.attempted`, `confirmed` and `evidence`: a span that ended without error does not mean a paid session stopped. Spans name identity and outcome only: never a credential, command input, a reply, an upload's name or bytes, or provider text. The renewal tick, frames, streams and heartbeats are not traced.
106
+
107
+ ## Time options
108
+
109
+ Every time option is an Effect `Duration.Input` named by its role:
110
+
111
+ - on the session, `connectTimeout`, `readyTimeout`, `heartbeatInterval`, `replyTimeout` and `uploadTimeout`;
112
+ - on the coordinator, `requestTimeout` and the poll's `initialDelay` and `maxDelay`, and on a token, `maxSessionDuration` and `expiresAfter`, which must be whole seconds;
113
+ - on H3, `replyTimeout`, `uploadTimeout`, `setupTimeout`, `reconcileWindow` and `resultHookTimeout`;
114
+ - in orchestration, `lead`, `reconnectTimeout` and the `lifetime` that `open` returns.
115
+
116
+ A bare number is milliseconds, as everywhere in Effect, so write the unit: `lead: "30 seconds"`, because `lead: 30` is 30 milliseconds. `"Infinity"` disables the heartbeat and marks a source that never expires. A value that is NaN, negative, zero where zero means nothing, or longer than the option's maximum fails with `InvalidInput`, not submitted. Measurements, instants and media lengths stay numbers in the unit their name carries: `requestRecordingClip(seconds)`, `ClipRequest.durationSeconds`, a renewal's `ageSeconds`.
117
+
118
+ `replyTimeout` is the session's own deadline for a reply. The session's default and a command's override share the key: `session.command(name, data, { uploads, replyTimeout })`. It is not a caller's wait. After dispatch it fails with `Timeout`, outcome `unknown`, and the command's `requestId`, and the request's slot stays held until a late reply or the connection generation retires. To stop waiting without abandoning the command, fork it and bound only the join:
119
+
120
+ ```ts
121
+ const fiber = yield * Effect.forkScoped(session.command("set_seed", { seed: 1 }));
122
+ const reply = yield * Fiber.join(fiber).pipe(Effect.timeout("2 seconds"));
123
+ // Later, Fiber.await(fiber) still reads the command's own outcome.
124
+ ```
125
+
126
+ When the command must be replayed rather than awaited, prepare it as an `Orchestration.Submission`.
73
127
 
74
128
  ## Coordinator helpers
75
129
 
76
- `Coordinator` is a namespace on the root export. `Coordinator.make(configuration)` provides pricing, bounded token minting, session inspection, and termination reports through Effect HTTP services. Constructing this client makes no network request and requires no peer implementation.
130
+ `Coordinator` is a namespace on the root export. `Coordinator.make(configuration)` provides pricing, bounded token minting, session inspection, termination reports, and `downloadClip` for a prepared recording (`clip_ready`), which polls its HLS playlist and concatenates its segments within a caller wall deadline, through Effect HTTP services. Constructing this client makes no network request and requires no peer implementation. The root exports the Schemas the client decodes a session descriptor with, `SessionDescriptor`, `Capabilities`, `Track` and `Mapping`, and derives their types from them.
77
131
 
78
132
  ## H3 provider
79
133
 
@@ -96,15 +150,17 @@ const enqueueClip = (session: Session) =>
96
150
 
97
151
  Use a session created with `H3.modelName`. The adapter targets the documented `0.5.5` prompt-and-images subset of `reactor/h3-reference-to-video-turbo-realtime`. Prompt-only requests are supported. Image references accept owned bytes or explicit upload references; H3 itself requires no filesystem or path services. Reference-audio input is unsupported, and FastH3 `startingFrame`/`endingFrame` fields are absent from this contract.
98
152
 
153
+ `provider.operation(submission)` keeps a committed clip's facts for as long as its scope holds them: `accepted`, `reached("generated" | "started")` and `ended` each resolve once, every fact naming the transport generation of its evidence, and a clip that fails or is popped first fails the phases it never reached with `ClipEnded`. Evidence arriving after the reconcile window, or in a later transport generation of the same session, still attributes an unknown enqueue. A commit reserves the operation's slot before it sends, so a table full of unresolved operations refuses new commits with `Overflow` instead of discarding evidence; releasing the scope frees the slot.
154
+
99
155
  The adapter exposes autoplay, flush, playback, reset, and other model controls as explicit operations. Creating it does not change those policies or initiate reconnect. Request `metadata` is a provider string; orchestration keeps its richer application annotation separately.
100
156
 
101
157
  ## Orchestration and simulation
102
158
 
103
- `reactor-effect-client/orchestration` owns opt-in scheduling, sequence routing, renewal, and recovering media. `fromH3` adapts a provider into a physical source, and `make({ open, ...options })` returns a handle with `engine`, `media`, `mediaState`, sequence operations, and joined cleanup reports. The `open` effect supplies each source and its lifetime budget. Application scheduling, pricing, persona, and show policy stay outside the session and H3 layers.
159
+ `reactor-effect-client/orchestration` owns opt-in scheduling, sequence routing, renewal, and recovering media. `fromH3Session(session, options)` builds a physical source from one connected session, deriving its H3 provider view (exposed as `source.provider`) and its decoded media from that session, so a source cannot pair one session's commands with another's media; it needs a host with decoded media (the native host), and `make({ open, ...options })` returns a handle with `engine`, `media`, `mediaState`, sequence operations, and joined cleanup reports. The `open` effect supplies each source and its lifetime budget. `openH3({ mint, onAllocated })` is that effect for paid H3 sessions: it mints the token, allocates the session, runs `onAllocated({ session, grant })` before connecting so the owner can be recorded durably, then connects and derives the source, with the granted length as its lifetime. `Orchestration.layer(options)` provides the handle's `Engine`, `Media` and `Handle` services from one orchestration; each build opens its own paid chain, so bind the layer to a `const`. `engine.observe(options)` is the engine's gap-free observation, as `session.observe` and `provider.observe` are for theirs: it subscribes before reading, returning the current `EngineState` with a stream of every later event (apply events idempotently by `clipId`; after an `Overflow`, observe again). `handle.observe(options)` extends it to the whole handle: the engine and media state, then engine events, renewals and media-state transitions in the one order they happened. `onRenewal` runs on its own reader and never holds the handle's command permit, and the orchestration logs through Effect's logger at debug level. Application scheduling, pricing, persona, and show policy stay outside the session and H3 layers.
104
160
 
105
161
  `ClipRequest.sameSessionAs` targets the physical session that owns a known clip, including one already ready or playing, while leaving queue position unchanged. `before` requests insertion ahead of a clip still in the generation queue. Source affinity, insertion anchors, continuation, and sequence ownership must agree; missing, conflicting, retired, or recovering ownership fails locally with a `not-submitted` outcome. This keeps a dependent request on its required session during renewal without inventing an insertion point.
106
162
 
107
- `Orchestration.Submission` models an inert prepared operation. Preparation may be interrupted before commit; once execution commits, callers joining or abandoning the result do not replay the dispatch. `CommandFailure.context` distinguishes `not-submitted`, `unknown`, and `replied` outcomes independently of the transport error category.
163
+ `Orchestration.Submission` models an inert prepared operation. Preparation may be interrupted before commit; once execution commits, callers joining or abandoning the result do not replay the dispatch. `CommandFailure.context` distinguishes `not-submitted`, `unknown`, and `replied` outcomes independently of the transport error category, and an engine command fails with `EngineError`, a `CommandFailure` or a local `PolicyFailure`.
108
164
 
109
165
  `Orchestration.Sequences` owns bounded sequence affinity and explicit member outcomes. Partial admission is represented member-by-member as accepted, rejected, or indeterminate, and a sequence remains bound to one owner until it is sealed/retired and explicitly released.
110
166
 
@@ -118,9 +174,13 @@ The adapter exposes autoplay, flush, playback, reset, and other model controls a
118
174
 
119
175
  Effect `4.0.0-rc.115` itself references the global `TextDecoderOptions` type in its channel declarations. A strict Node project that deliberately omits DOM types may need to declare that standard interface. The workspace's installed-package check first proves this is the sole upstream diagnostic, then applies a test-only declaration; it does not enable `skipLibCheck` or hide SDK declaration errors.
120
176
 
177
+ ## Example
178
+
179
+ [`examples/`](https://github.com/mannyc2/reactor-effect-client/tree/main/packages/client/examples) is an application service written against the orchestration `Engine`, run and tested offline against the simulation on Effect's test clock: gap-free observation, retrying only what `isRetryable` allows, and never resending an enqueue whose outcome is `unknown`. The repository's [other examples](https://github.com/mannyc2/reactor-effect-client/tree/main/examples) include a server that broadcasts one renewing orchestration to many browsers.
180
+
121
181
  ## Development
122
182
 
123
- This package is built and tested from the workspace root; see the repository [CONTRIBUTING](https://github.com/mannyc2/reactor-effect-client/blob/main/CONTRIBUTING.md). Inside `packages/client`, `bun test` runs the portable suites and `bun run typecheck` checks the source closure both with browser types and with Node types.
183
+ This package is built and tested from the workspace root; see the repository [CONTRIBUTING](https://github.com/mannyc2/reactor-effect-client/blob/main/CONTRIBUTING.md). Inside `packages/client`, `bun run test` runs the portable suite under Vitest and `bun run typecheck` checks the source closure both with browser types and with Node types.
124
184
 
125
185
  ## License
126
186
 
package/dist/FetchHttp.js CHANGED
@@ -36,7 +36,7 @@ export const layer = Layer.effect(HttpClient.HttpClient, Effect.gen(function* ()
36
36
  ? Stream.empty
37
37
  : fromOwnedReadableStream({
38
38
  evaluate: () => source.body,
39
- onError: (cause) => new ReactorError("Http", "HTTP response body failed", { detail: cause }),
39
+ onError: (cause) => ReactorError.fromCode("Http", "HTTP response body failed", { detail: cause }),
40
40
  }).pipe(Stream.mapError((cause) => new HttpClientError.HttpClientError({
41
41
  reason: new HttpClientError.DecodeError({ request, response, cause }),
42
42
  })));
@@ -1 +1 @@
1
- {"version":3,"file":"FetchHttp.js","sourceRoot":"","sources":["../src/FetchHttp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAA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,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;iBACtE,CAAC,CACL,CACF,CAAC;YACR,yEAAyE;YACzE,sDAAsD;YACtD,OAAO,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE;gBAC7B,MAAM,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,EAAE;aAC9B,CAA0C,CAAC;QAC9C,CAAC,CAAC,CACH,CAAC;QAEJ,QAAQ,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YAC1B,KAAK,KAAK;gBACR,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAA2B,CAAC,CAAC;YACxD,KAAK,YAAY;gBACf,OAAO,IAAI,CAAC,IAAI,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;YACjD,KAAK,UAAU;gBACb,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACrC,KAAK,QAAQ;gBACX,OAAO,MAAM,CAAC,sBAAsB,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;YACvF;gBACE,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CACH,CAAC"}
@@ -2,11 +2,22 @@ import * as Context from "effect/Context";
2
2
  import type * as Effect from "effect/Effect";
3
3
  import type { Peer } from "./PeerTypes.js";
4
4
  import type { ReactorError } from "./errors.js";
5
+ /**
6
+ * A host's transport capability. A host resolves and validates what it needs
7
+ * while its layer is built, so building the layer is the host preflight and
8
+ * `make` never depends on another call having run first.
9
+ */
5
10
  export interface PeerFactoryShape {
6
- /** Validate host support before allocating a remote session. */
7
- readonly check: Effect.Effect<void, ReactorError>;
8
11
  /** A fresh transport for each connection generation. No Reactor orchestration. */
9
12
  readonly make: () => Peer;
13
+ /**
14
+ * Fails when the host cannot create a peer right now, for example while a
15
+ * native runtime still holds an owner that did not join. The session factory
16
+ * runs it before every remote allocation, so a paid session is never
17
+ * allocated for a peer that cannot be made. It must not change what `make`
18
+ * does; a host with nothing to check omits it.
19
+ */
20
+ readonly check?: Effect.Effect<void, ReactorError> | undefined;
10
21
  }
11
22
  declare const PeerFactory_base: Context.ServiceClass<PeerFactory, "reactor-effect-client/PeerFactory", PeerFactoryShape>;
12
23
  export declare class PeerFactory extends PeerFactory_base {
@@ -1 +1 @@
1
- {"version":3,"file":"PeerFactory.d.ts","sourceRoot":"","sources":["../src/PeerFactory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,MAAM,WAAW,gBAAgB;IAC/B,gEAAgE;IAChE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;IAClD,kFAAkF;IAClF,QAAQ,CAAC,IAAI,EAAE,MAAM,IAAI,CAAC;CAC3B;;AAED,qBAAa,WAAY,SAAQ,gBAEhC;CAAG;AAEJ,YAAY,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC"}
1
+ {"version":3,"file":"PeerFactory.d.ts","sourceRoot":"","sources":["../src/PeerFactory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,kFAAkF;IAClF,QAAQ,CAAC,IAAI,EAAE,MAAM,IAAI,CAAC;IAC1B;;;;;;OAMG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,YAAY,CAAC,GAAG,SAAS,CAAC;CAChE;;AAED,qBAAa,WAAY,SAAQ,gBAEhC;CAAG;AAEJ,YAAY,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"PeerFactory.js","sourceRoot":"","sources":["../src/PeerFactory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAY1C,MAAM,OAAO,WAAY,SAAQ,OAAO,CAAC,OAAO,EAAiC,CAC/E,mCAAmC,CACpC;CAAG"}
1
+ {"version":3,"file":"PeerFactory.js","sourceRoot":"","sources":["../src/PeerFactory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAuB1C,MAAM,OAAO,WAAY,SAAQ,OAAO,CAAC,OAAO,EAAiC,CAC/E,mCAAmC,CACpC;CAAG"}
@@ -46,7 +46,7 @@ export interface Prepared {
46
46
  /** Transport only. Coordinator allocation and Reactor protocol state remain session-owned. */
47
47
  export interface Peer {
48
48
  readonly rawMedia?: RawMedia;
49
- readonly shutdown?: () => Effect.Effect<void, ReactorError>;
49
+ readonly shutdown?: Effect.Effect<void, ReactorError>;
50
50
  readonly nativeTracks?: boolean;
51
51
  readonly mediaSupported?: boolean;
52
52
  prepare(servers: readonly IceServer[], tracks: readonly Track[], emit: (event: PeerEvent) => void): Effect.Effect<Prepared, ReactorError, Scope.Scope>;
@@ -59,6 +59,6 @@ export interface Peer {
59
59
  direction(name: string, active: boolean): Effect.Effect<void, ReactorError>;
60
60
  replace(name: string, track: MediaTrack | null): Effect.Effect<void, ReactorError>;
61
61
  maxBitrate(name: string, bitsPerSecond: number): Effect.Effect<void, ReactorError>;
62
- stats(): Effect.Effect<readonly unknown[], ReactorError>;
62
+ readonly stats: Effect.Effect<readonly unknown[], ReactorError>;
63
63
  }
64
64
  //# sourceMappingURL=PeerTypes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PeerTypes.d.ts","sourceRoot":"","sources":["../src/PeerTypes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAC7E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAEnD,MAAM,MAAM,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC;AACzC,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,YAAY,GAAG,WAAW,GAAG,cAAc,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAElG,iFAAiF;AACjF,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC;IACtC,KAAK,IAAI,UAAU,CAAC;IACpB,IAAI,IAAI,IAAI,CAAC;CACd;AAED,MAAM,MAAM,SAAS,GACjB;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAA;CAAE,GACrD;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAC/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AAI,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;IAC5E,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;IACnF,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;IACnF,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS,OAAO,EAAE,EAAE,YAAY,CAAC,CAAC;CACjE"}
@@ -1,4 +1,4 @@
1
- import { Effect } from "effect";
1
+ import { Effect, Schema } from "effect";
2
2
  export type SequenceStatus = "open" | "sealed" | "indeterminate" | "retired";
3
3
  export type MemberOutcome = {
4
4
  readonly _tag: "Accepted";
@@ -26,20 +26,22 @@ export interface SequenceSnapshot<Owner> {
26
26
  readonly sealRequested: boolean;
27
27
  readonly members: ReadonlyArray<MemberOutcome>;
28
28
  }
29
- declare const InvalidSequenceOptions_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
30
- readonly _tag: "InvalidSequenceOptions";
31
- } & Readonly<A>;
32
- export declare class InvalidSequenceOptions extends InvalidSequenceOptions_base<{
33
- readonly reason: string;
34
- }> {
29
+ declare const InvalidSequenceOptions_base: Schema.Class<InvalidSequenceOptions, Schema.TaggedStruct<"InvalidSequenceOptions", {
30
+ readonly message: Schema.String;
31
+ }>, import("effect/Cause").YieldableError>;
32
+ /** An affinity bound that is not a positive safe integer. */
33
+ export declare class InvalidSequenceOptions extends InvalidSequenceOptions_base {
35
34
  }
36
- declare const SequenceError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
37
- readonly _tag: "SequenceError";
38
- } & Readonly<A>;
39
- export declare class SequenceError extends SequenceError_base<{
40
- readonly sequenceId: string;
41
- readonly reason: "capacity" | "member-capacity" | "owner-mismatch" | "sealed" | "sealing" | "indeterminate" | "retired" | "missing" | "member-missing" | "member-duplicate" | "not-releasable";
42
- }> {
35
+ /** Why a sequence refused an operation. */
36
+ export declare const SequenceCode: Schema.Literals<readonly ["capacity", "member-capacity", "owner-mismatch", "sealed", "sealing", "indeterminate", "retired", "missing", "member-missing", "member-duplicate", "not-releasable"]>;
37
+ export type SequenceCode = typeof SequenceCode.Type;
38
+ declare const SequenceError_base: Schema.Class<SequenceError, Schema.TaggedStruct<"SequenceError", {
39
+ readonly sequenceId: Schema.String;
40
+ readonly code: Schema.Literals<readonly ["capacity", "member-capacity", "owner-mismatch", "sealed", "sealing", "indeterminate", "retired", "missing", "member-missing", "member-duplicate", "not-releasable"]>;
41
+ }>, import("effect/Cause").YieldableError>;
42
+ /** A sequence operation the affinity state refused; `code` says why. */
43
+ export declare class SequenceError extends SequenceError_base {
44
+ get message(): string;
43
45
  }
44
46
  export interface Affinity<Owner> {
45
47
  readonly get: (id: string) => Effect.Effect<SequenceSnapshot<Owner> | undefined>;
@@ -75,6 +77,8 @@ export interface Options<Owner> {
75
77
  /**
76
78
  * Bounded sequence-affinity state. Unresolved work is never evicted to admit
77
79
  * another sequence or member; callers explicitly account and release history.
80
+ * Every operation is one pure transition of the whole state, applied with
81
+ * `Ref.modify`, so none observes another half done.
78
82
  */
79
83
  export declare const makeAffinity: <Owner>(options?: Options<Owner>) => Effect.Effect<Affinity<Owner>, InvalidSequenceOptions>;
80
84
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"Sequence.d.ts","sourceRoot":"","sources":["../src/Sequence.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,MAAM,EAAkB,MAAM,QAAQ,CAA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, Semaphore } from "effect";
2
- export class InvalidSequenceOptions extends Data.TaggedError("InvalidSequenceOptions") {
1
+ import { Effect, Ref, Schema } from "effect";
2
+ /** An affinity bound that is not a positive safe integer. */
3
+ export class InvalidSequenceOptions extends Schema.TaggedError("reactor-effect-client/InvalidSequenceOptions")("InvalidSequenceOptions", { message: Schema.String }) {
3
4
  }
4
- export class SequenceError extends Data.TaggedError("SequenceError") {
5
+ /** Why a sequence refused an operation. */
6
+ export const SequenceCode = Schema.Literals([
7
+ "capacity",
8
+ "member-capacity",
9
+ "owner-mismatch",
10
+ "sealed",
11
+ "sealing",
12
+ "indeterminate",
13
+ "retired",
14
+ "missing",
15
+ "member-missing",
16
+ "member-duplicate",
17
+ "not-releasable",
18
+ ]);
19
+ /** A sequence operation the affinity state refused; `code` says why. */
20
+ export class SequenceError extends Schema.TaggedError("reactor-effect-client/SequenceError")("SequenceError", { sequenceId: Schema.String, code: SequenceCode }) {
21
+ get message() {
22
+ return `Sequence ${this.sequenceId}: ${this.code}`;
23
+ }
5
24
  }
25
+ const count = (members, tag) => members.reduce((total, member) => (member._tag === tag ? total + 1 : total), 0);
6
26
  const immutableMembers = (members) => Object.freeze(members.map((member) => Object.freeze({ ...member })));
7
27
  const snapshot = (entry) => Object.freeze({
8
28
  id: entry.id,
9
29
  owner: entry.owner,
10
30
  status: entry.status,
11
- acceptedCount: entry.acceptedCount,
12
- rejectedCount: entry.rejectedCount,
13
- indeterminateCount: entry.indeterminateCount,
31
+ acceptedCount: count(entry.members, "Accepted"),
32
+ rejectedCount: count(entry.members, "Rejected"),
33
+ indeterminateCount: count(entry.members, "Indeterminate"),
14
34
  pendingCount: entry.pending.size,
15
35
  sealRequested: entry.sealRequested,
16
36
  members: immutableMembers(entry.members),
17
37
  });
18
38
  const positiveInteger = (value, name) => Number.isSafeInteger(value) && value > 0
19
39
  ? Effect.succeed(value)
20
- : Effect.fail(new InvalidSequenceOptions({ reason: `${name} must be a positive safe integer` }));
40
+ : Effect.fail(new InvalidSequenceOptions({ message: `${name} must be a positive safe integer` }));
41
+ const refuse = (sequenceId, code) => new SequenceError({ sequenceId, code });
42
+ const unavailable = (id, entry) => entry.status === "sealed"
43
+ ? refuse(id, "sealed")
44
+ : entry.status === "indeterminate"
45
+ ? refuse(id, "indeterminate")
46
+ : entry.status === "retired"
47
+ ? refuse(id, "retired")
48
+ : entry.sealRequested
49
+ ? refuse(id, "sealing")
50
+ : undefined;
51
+ const put = (all, entry) => new Map(all).set(entry.id, entry);
21
52
  /**
22
53
  * Bounded sequence-affinity state. Unresolved work is never evicted to admit
23
54
  * another sequence or member; callers explicitly account and release history.
55
+ * Every operation is one pure transition of the whole state, applied with
56
+ * `Ref.modify`, so none observes another half done.
24
57
  */
25
58
  export const makeAffinity = (options = {}) => Effect.gen(function* () {
26
59
  const maxEntries = yield* positiveInteger(options.maxEntries ?? 256, "maxEntries");
27
60
  const maxMembers = yield* positiveInteger(options.maxMembers ?? 256, "maxMembers");
28
61
  const sameOwner = options.sameOwner ?? Object.is;
29
62
  const entries = yield* Ref.make(new Map());
30
- const lock = yield* Semaphore.make(1);
63
+ const apply = (transition) => Ref.modify(entries, (all) => {
64
+ const step = transition(all);
65
+ return step instanceof SequenceError
66
+ ? [Effect.fail(step), all]
67
+ : [Effect.succeed(step[0]), step[1]];
68
+ }).pipe(Effect.flatten);
69
+ /** A transition of one existing sequence. */
70
+ const onEntry = (id, transition) => (all) => {
71
+ const entry = all.get(id);
72
+ return entry === undefined ? refuse(id, "missing") : transition(entry, all);
73
+ };
31
74
  const get = (id) => Ref.get(entries).pipe(Effect.map((all) => {
32
75
  const entry = all.get(id);
33
76
  return entry === undefined ? undefined : snapshot(entry);
34
77
  }));
35
- const unavailable = (id, entry) => entry.status === "sealed"
36
- ? new SequenceError({ sequenceId: id, reason: "sealed" })
37
- : entry.status === "indeterminate"
38
- ? new SequenceError({ sequenceId: id, reason: "indeterminate" })
39
- : entry.status === "retired"
40
- ? new SequenceError({ sequenceId: id, reason: "retired" })
41
- : entry.sealRequested
42
- ? new SequenceError({ sequenceId: id, reason: "sealing" })
43
- : undefined;
44
- const set = (all, entry) => Ref.set(entries, new Map(all).set(entry.id, entry));
45
- const bind = (id, owner) => lock.withPermit(Effect.gen(function* () {
46
- const all = yield* Ref.get(entries);
78
+ const bind = (id, owner) => apply((all) => {
47
79
  const existing = all.get(id);
48
80
  if (existing !== undefined) {
49
81
  if (!sameOwner(existing.owner, owner))
50
- return yield* new SequenceError({ sequenceId: id, reason: "owner-mismatch" });
51
- const failure = unavailable(id, existing);
52
- if (failure !== undefined)
53
- return yield* failure;
54
- return existing.owner;
82
+ return refuse(id, "owner-mismatch");
83
+ return unavailable(id, existing) ?? [existing.owner, all];
55
84
  }
56
85
  if (all.size >= maxEntries)
57
- return yield* new SequenceError({ sequenceId: id, reason: "capacity" });
58
- const entry = {
59
- id,
86
+ return refuse(id, "capacity");
87
+ return [
60
88
  owner,
61
- status: "open",
62
- acceptedCount: 0,
63
- rejectedCount: 0,
64
- indeterminateCount: 0,
65
- pending: new Set(),
66
- sealRequested: false,
67
- members: [],
68
- };
69
- yield* set(all, entry);
70
- return owner;
71
- }));
72
- const begin = (id, memberId) => lock.withPermit(Effect.gen(function* () {
73
- const all = yield* Ref.get(entries);
74
- const entry = all.get(id);
75
- if (entry === undefined)
76
- return yield* new SequenceError({ sequenceId: id, reason: "missing" });
89
+ put(all, {
90
+ id,
91
+ owner,
92
+ status: "open",
93
+ pending: new Set(),
94
+ sealRequested: false,
95
+ members: [],
96
+ }),
97
+ ];
98
+ });
99
+ const begin = (id, memberId) => apply(onEntry(id, (entry, all) => {
77
100
  const failure = unavailable(id, entry);
78
101
  if (failure !== undefined)
79
- return yield* failure;
102
+ return failure;
80
103
  if (entry.pending.has(memberId) ||
81
- entry.members.some((member) => member.memberId === memberId)) {
82
- return yield* new SequenceError({ sequenceId: id, reason: "member-duplicate" });
83
- }
84
- if (entry.pending.size + entry.members.length >= maxMembers) {
85
- return yield* new SequenceError({ sequenceId: id, reason: "member-capacity" });
86
- }
87
- yield* set(all, { ...entry, pending: new Set(entry.pending).add(memberId) });
104
+ entry.members.some((member) => member.memberId === memberId))
105
+ return refuse(id, "member-duplicate");
106
+ if (entry.pending.size + entry.members.length >= maxMembers)
107
+ return refuse(id, "member-capacity");
108
+ return [undefined, put(all, { ...entry, pending: new Set(entry.pending).add(memberId) })];
88
109
  }));
89
- const settle = (id, memberId, outcome, update, terminal, requestSeal = false) => lock.withPermit(Effect.gen(function* () {
90
- const all = yield* Ref.get(entries);
91
- const entry = all.get(id);
92
- if (entry === undefined)
93
- return yield* new SequenceError({ sequenceId: id, reason: "missing" });
94
- if (!entry.pending.has(memberId)) {
95
- if (entry.members.some((member) => member.memberId === memberId)) {
96
- return yield* new SequenceError({ sequenceId: id, reason: "member-duplicate" });
97
- }
98
- return yield* new SequenceError({ sequenceId: id, reason: "member-missing" });
99
- }
110
+ const settle = (id, memberId, outcome, terminal, requestSeal = false) => apply(onEntry(id, (entry, all) => {
111
+ if (!entry.pending.has(memberId))
112
+ return entry.members.some((member) => member.memberId === memberId)
113
+ ? refuse(id, "member-duplicate")
114
+ : refuse(id, "member-missing");
100
115
  const pending = new Set(entry.pending);
101
116
  pending.delete(memberId);
102
- const counts = update(entry);
103
117
  const sealRequested = entry.sealRequested || requestSeal;
104
118
  const status = entry.status === "indeterminate" || entry.status === "retired"
105
119
  ? entry.status
@@ -108,48 +122,43 @@ export const makeAffinity = (options = {}) => Effect.gen(function* () {
108
122
  : sealRequested && pending.size === 0
109
123
  ? "sealed"
110
124
  : entry.status;
111
- yield* set(all, {
112
- ...entry,
113
- ...counts,
114
- status,
115
- sealRequested,
116
- pending,
117
- members: [...entry.members, outcome(entry)],
118
- });
125
+ return [
126
+ undefined,
127
+ put(all, {
128
+ ...entry,
129
+ status,
130
+ sealRequested,
131
+ pending,
132
+ members: [...entry.members, outcome(entry)],
133
+ }),
134
+ ];
119
135
  }));
120
- const accepted = (id, memberId, clipId, final = false) => settle(id, memberId, (entry) => ({ _tag: "Accepted", memberId, clipId, index: entry.acceptedCount, final }), (entry) => ({
121
- acceptedCount: entry.acceptedCount + 1,
122
- rejectedCount: entry.rejectedCount,
123
- indeterminateCount: entry.indeterminateCount,
124
- }), "known", final);
125
- const rejected = (id, memberId, reason, final = false) => settle(id, memberId, () => ({ _tag: "Rejected", memberId, reason }), (entry) => ({
126
- acceptedCount: entry.acceptedCount,
127
- rejectedCount: entry.rejectedCount + 1,
128
- indeterminateCount: entry.indeterminateCount,
136
+ const accepted = (id, memberId, clipId, final = false) => settle(id, memberId, (entry) => ({
137
+ _tag: "Accepted",
138
+ memberId,
139
+ clipId,
140
+ index: count(entry.members, "Accepted"),
141
+ final,
129
142
  }), "known", final);
130
- const uncertain = (id, memberId, reason) => settle(id, memberId, () => ({ _tag: "Indeterminate", memberId, reason }), (entry) => ({
131
- acceptedCount: entry.acceptedCount,
132
- rejectedCount: entry.rejectedCount,
133
- indeterminateCount: entry.indeterminateCount + 1,
134
- }), "unknown");
135
- const seal = (id) => lock.withPermit(Effect.gen(function* () {
136
- const all = yield* Ref.get(entries);
137
- const entry = all.get(id);
138
- if (entry === undefined)
139
- return yield* new SequenceError({ sequenceId: id, reason: "missing" });
143
+ const rejected = (id, memberId, reason, final = false) => settle(id, memberId, () => ({ _tag: "Rejected", memberId, reason }), "known", final);
144
+ const uncertain = (id, memberId, reason) => settle(id, memberId, () => ({ _tag: "Indeterminate", memberId, reason }), "unknown");
145
+ const seal = (id) => apply(onEntry(id, (entry, all) => {
140
146
  if (entry.status === "indeterminate")
141
- return yield* new SequenceError({ sequenceId: id, reason: "indeterminate" });
147
+ return refuse(id, "indeterminate");
142
148
  if (entry.status === "retired")
143
- return yield* new SequenceError({ sequenceId: id, reason: "retired" });
149
+ return refuse(id, "retired");
144
150
  if (entry.status === "sealed")
145
- return;
146
- yield* set(all, {
147
- ...entry,
148
- sealRequested: true,
149
- status: entry.pending.size === 0 ? "sealed" : "open",
150
- });
151
+ return [undefined, all];
152
+ return [
153
+ undefined,
154
+ put(all, {
155
+ ...entry,
156
+ sealRequested: true,
157
+ status: entry.pending.size === 0 ? "sealed" : "open",
158
+ }),
159
+ ];
151
160
  }));
152
- const retire = (owner) => lock.withPermit(Ref.update(entries, (all) => {
161
+ const retire = (owner) => Ref.update(entries, (all) => {
153
162
  const next = new Map(all);
154
163
  for (const [id, entry] of all) {
155
164
  if (!sameOwner(entry.owner, owner))
@@ -167,35 +176,21 @@ export const makeAffinity = (options = {}) => Effect.gen(function* () {
167
176
  next.set(id, {
168
177
  ...entry,
169
178
  status: "indeterminate",
170
- indeterminateCount: entry.indeterminateCount + entry.pending.size,
171
179
  pending: new Set(),
172
180
  members: [...entry.members, ...pendingOutcomes],
173
181
  });
174
182
  }
175
183
  return next;
176
- }));
177
- const acknowledgeIndeterminate = (id) => lock.withPermit(Effect.gen(function* () {
178
- const all = yield* Ref.get(entries);
179
- const entry = all.get(id);
180
- if (entry === undefined)
181
- return yield* new SequenceError({ sequenceId: id, reason: "missing" });
182
- if (entry.status !== "indeterminate" || entry.pending.size !== 0) {
183
- return yield* new SequenceError({ sequenceId: id, reason: "not-releasable" });
184
- }
185
- yield* set(all, { ...entry, status: "retired" });
186
- }));
187
- const release = (id) => lock.withPermit(Effect.gen(function* () {
188
- const all = yield* Ref.get(entries);
189
- const entry = all.get(id);
190
- if (entry === undefined)
191
- return yield* new SequenceError({ sequenceId: id, reason: "missing" });
192
- if (entry.pending.size !== 0 ||
193
- (entry.status !== "sealed" && entry.status !== "retired")) {
194
- return yield* new SequenceError({ sequenceId: id, reason: "not-releasable" });
195
- }
184
+ });
185
+ const acknowledgeIndeterminate = (id) => apply(onEntry(id, (entry, all) => entry.status !== "indeterminate" || entry.pending.size !== 0
186
+ ? refuse(id, "not-releasable")
187
+ : [undefined, put(all, { ...entry, status: "retired" })]));
188
+ const release = (id) => apply(onEntry(id, (entry, all) => {
189
+ if (entry.pending.size !== 0 || (entry.status !== "sealed" && entry.status !== "retired"))
190
+ return refuse(id, "not-releasable");
196
191
  const next = new Map(all);
197
192
  next.delete(id);
198
- yield* Ref.set(entries, next);
193
+ return [undefined, next];
199
194
  }));
200
195
  return {
201
196
  get,