@streamsy/core 0.4.0 → 0.6.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.
@@ -1,10 +1,7 @@
1
- import { $ as ProducerOptions, C as ReadNextResult, E as AppendConflict, J as StreamGone, K as StreamBusy, L as InvalidReadRequest, N as HeadError, O as AppendErrorFor, R as NotSupported, U as ReadNextError, W as RemoveError, Y as StreamNotFound, Z as AppendCallOptions, _ as StreamsWriter, _t as StreamsFault, b as CreateResult, dt as StreamId, et as ReadNextOptions, g as StreamsReader, gt as StorageFault, h as Reader, ht as EncodeFault, j as CreateError, mt as DecodeFault, nt as CreateOptions, q as StreamClosed, r as Storage, t as OwnerRecords, tt as ReadOptions$1, v as Writer, vt as TransportFault, x as HeadResult, y as AppendResult, z as OffsetMismatch } from "./owner-records-QDlssl__.js";
2
- import { Context, Data, Duration, Effect, Layer, Option, Schedule, Schema, Stream } from "effect";
3
- import { NonEmptyReadonlyArray } from "effect/Array";
1
+ import { $ as ProducerOptions, C as ReadNextResult, E as AppendConflict, J as StreamGone, K as StreamBusy, L as InvalidReadRequest, N as HeadError, O as AppendErrorFor, R as NotSupported, U as ReadNextError, W as RemoveError, Y as StreamNotFound, Z as AppendCallOptions, _ as StreamsWriter, _t as StreamsFault, b as CreateResult, dt as StreamId, et as ReadNextOptions, g as StreamsReader, gt as StorageFault, h as Reader, ht as EncodeFault, j as CreateError, mt as DecodeFault, nt as CreateOptions, q as StreamClosed, r as Storage, t as OwnerRecords, tt as ReadOptions$1, v as Writer, vt as TransportFault, x as HeadResult, y as AppendResult, z as OffsetMismatch } from "./owner-records-H7VEuBpy.js";
2
+ import { Array, Context, Data, Duration, Effect, Function, Layer, Option, Schedule, Schema, Stream } from "effect";
4
3
  import { HttpRouter, HttpServerRequest, HttpServerResponse } from "effect/http";
5
- import { LazyArg } from "effect/Function";
6
- import { SqlError } from "effect/sql/SqlError";
7
- //#region src/http/program.d.ts
4
+ import { SqlError } from "effect/sql";
8
5
  interface HttpOptions {
9
6
  readonly pathPrefix?: string;
10
7
  /** Lifetime of an SSE response. Default 60 seconds. */
@@ -21,8 +18,6 @@ interface HttpOptions {
21
18
  * what let one composition serve several backends.
22
19
  */
23
20
  declare function app(options?: HttpOptions): Effect.Effect<HttpServerResponse.HttpServerResponse, never, HttpServerRequest.HttpServerRequest | StreamsReader | StreamsWriter>;
24
- //#endregion
25
- //#region src/http/stream-path-service.d.ts
26
21
  /** Prefix helpers shared by protocol and host routers. */
27
22
  declare const streamPath: (pathPrefix?: string) => {
28
23
  requiredPathPattern: () => string;
@@ -30,7 +25,7 @@ declare const streamPath: (pathPrefix?: string) => {
30
25
  canonicalizeForkSource: (source: string) => string;
31
26
  };
32
27
  declare namespace address_d_exports {
33
- export { Collection, Collections, CollectionsChange, CollectionsDecodingServices, CollectionsEncodedChange, CollectionsEncodingServices, StateAddress, StateChange, StateDelete, StateHeaders, StateKey, StateUpsert, StreamAddress, ValidCollections, bytes$2 as bytes, json$2 as json, state$2 as state, stateChange };
28
+ export { Collection, Collections, CollectionsChange, CollectionsDecodingServices, CollectionsEncodedChange, CollectionsEncodedEvent, CollectionsEncodingServices, CollectionsEvent, StateAddress, StateChange, StateControl, StateControlName, StateDelete, StateEvent, StateHeaders, StateKey, StateUpsert, StreamAddress, ValidCollections, bytes$2 as bytes, isChange, isControl, isUpsert, json$2 as json, reset, snapshotEnd, snapshotStart, state$2 as state, stateChange, stateControl };
34
29
  }
35
30
  /** Omit `offset` and `txid` rather than setting them to `undefined`. */
36
31
  interface StateHeaders {
@@ -63,6 +58,22 @@ type StateEncodedChange<A, Type extends string = string> = (Omit<StateUpsert<A,
63
58
  readonly operation: "insert" | "update" | "upsert";
64
59
  };
65
60
  }) | StateDelete<A, Type>;
61
+ /** The control signals of the Durable State protocol (STATE-PROTOCOL.md section 4.2). */
62
+ type StateControlName = "snapshot-start" | "snapshot-end" | "reset";
63
+ /**
64
+ * A control message of a Durable State stream. It has no `type` or `key`.
65
+ * `snapshot-start` and `snapshot-end` mark a run of changes that is a complete
66
+ * snapshot. `reset` tells a reader to clear its materialized state. Omit
67
+ * `offset` rather than setting it to `undefined`.
68
+ */
69
+ interface StateControl {
70
+ readonly headers: {
71
+ readonly control: StateControlName;
72
+ readonly offset?: string;
73
+ };
74
+ }
75
+ /** One item of a Durable State stream: a change of one collection or a control. */
76
+ type StateEvent<A, Type extends string = string> = StateChange<A, Type> | StateControl;
66
77
  /** The value fields that may serve as a Durable State key. */
67
78
  type StateKey<A> = { [K in keyof A]-?: A[K] extends string | number ? K : never; }[keyof A];
68
79
  /** One collection of a Durable State stream: its value schema and the value field used as the key. */
@@ -82,6 +93,9 @@ type ValidCollections<C extends Collections> = { readonly [K in keyof C]: C[K]["
82
93
  /** The union of change events across every collection, discriminated by `type`. */
83
94
  type CollectionsChange<C extends Collections> = { [K in keyof C & string]: StateChange<C[K]["schema"]["Type"], K>; }[keyof C & string];
84
95
  type CollectionsEncodedChange<C extends Collections> = { [K in keyof C & string]: StateEncodedChange<C[K]["schema"]["Encoded"], K>; }[keyof C & string];
96
+ /** The items of a State address: the change events of its collections, plus controls. */
97
+ type CollectionsEvent<C extends Collections> = CollectionsChange<C> | StateControl;
98
+ type CollectionsEncodedEvent<C extends Collections> = CollectionsEncodedChange<C> | StateControl;
85
99
  type CollectionsDecodingServices<C extends Collections> = C[keyof C]["schema"]["DecodingServices"];
86
100
  type CollectionsEncodingServices<C extends Collections> = C[keyof C]["schema"]["EncodingServices"];
87
101
  /** Inert identity and codec. Constructing an address acquires no service or resource. */
@@ -91,8 +105,8 @@ interface StreamAddress<A, RD = never, RE = never> {
91
105
  readonly contentType: string;
92
106
  readonly codec: Schema.Codec<A, string | Uint8Array, RD, RE>;
93
107
  }
94
- /** A JSON address whose items are the change events of its collections. */
95
- interface StateAddress<C extends Collections, RD = CollectionsDecodingServices<C>, RE = CollectionsEncodingServices<C>> extends StreamAddress<CollectionsChange<C>, RD, RE> {
108
+ /** A JSON address whose items are the change events of its collections and State controls. */
109
+ interface StateAddress<C extends Collections, RD = CollectionsDecodingServices<C>, RE = CollectionsEncodingServices<C>> extends StreamAddress<CollectionsEvent<C>, RD, RE> {
96
110
  readonly collections: C;
97
111
  }
98
112
  declare function json$2<A, I, RD, RE>(id: string, options: {
@@ -107,10 +121,31 @@ declare function stateChange<A, I, RD, RE, const Type extends string>(options: {
107
121
  readonly schema: Schema.Codec<A, I, RD, RE>;
108
122
  readonly type: Type;
109
123
  }): Schema.Codec<StateChange<A, Type>, StateEncodedChange<I, Type>, RD, RE>;
124
+ /** The codec for a State control message. It needs no services. */
125
+ declare const stateControl: Schema.Codec<StateControl>;
126
+ /** True for a control message. A change has `headers.operation` and no `headers.control`. */
127
+ declare const isControl: <E extends StateEvent<unknown>>(event: E) => event is Extract<E, StateControl>;
128
+ /** True for an upsert or delete change. */
129
+ declare const isChange: <E extends StateEvent<unknown>>(event: E) => event is Exclude<E, StateControl>;
130
+ /** True for an upsert change, with its value available. */
131
+ declare const isUpsert: <E extends StateEvent<unknown>>(event: E) => event is Extract<E, StateUpsert<unknown>>;
132
+ /** A `reset` control. A reader should clear its materialized state and apply what follows. */
133
+ declare const reset: (options?: {
134
+ readonly offset?: string;
135
+ }) => StateControl;
136
+ /** A `snapshot-start` control. The changes up to `snapshot-end` form a complete snapshot. */
137
+ declare const snapshotStart: (options?: {
138
+ readonly offset?: string;
139
+ }) => StateControl;
140
+ /** A `snapshot-end` control. It closes the snapshot that `snapshot-start` opened. */
141
+ declare const snapshotEnd: (options?: {
142
+ readonly offset?: string;
143
+ }) => StateControl;
110
144
  /**
111
- * A stream of Durable State change events for several collections. Each record
145
+ * A stream of Durable State events for several collections. Each record
112
146
  * key is the `type` on the wire; each entry gives the value schema and the value
113
- * field that becomes the event `key`.
147
+ * field that becomes the event `key`. The codec also decodes and encodes the
148
+ * State control messages `snapshot-start`, `snapshot-end` and `reset`.
114
149
  */
115
150
  declare function state$2<const C extends Collections>(id: string, options: {
116
151
  readonly collections: C & ValidCollections<C>;
@@ -147,7 +182,7 @@ type WithPathSchema<P> = {
147
182
  readonly paramSchema: PathSchema<P>;
148
183
  };
149
184
  /** A route whose address refs retain their declared State collections. */
150
- type StateRoute<P, C extends Collections, Template extends string = string> = Omit<StreamRoute<P, CollectionsChange<C>, CollectionsDecodingServices<C>, CollectionsEncodingServices<C>, Template>, "address"> & {
185
+ type StateRoute<P, C extends Collections, Template extends string = string> = Omit<StreamRoute<P, CollectionsEvent<C>, CollectionsDecodingServices<C>, CollectionsEncodingServices<C>, Template>, "address"> & {
151
186
  readonly collections: C;
152
187
  readonly address: (params: P) => StateAddress<C>;
153
188
  };
@@ -178,12 +213,8 @@ declare function custom$1<RouteParams, A, RD, RE>(options: {
178
213
  readonly parse: (id: string) => Option.Option<RouteParams>;
179
214
  readonly address: (params: RouteParams) => StreamAddress<A, RD, RE>;
180
215
  }): StreamRoute<RouteParams, A, RD, RE>;
181
- //#endregion
182
- //#region src/offset/index.d.ts
183
216
  declare const ZERO_OFFSET: string & import("effect/Brand").Brand<"Offset">;
184
217
  declare const compare: (a: string, b: string) => number;
185
- //#endregion
186
- //#region src/storage/commit-boundary.d.ts
187
218
  interface CommitBoundaryApi {
188
219
  /**
189
220
  * Run `body` in the storage owner's transaction. A nested call joins the outer
@@ -192,13 +223,11 @@ interface CommitBoundaryApi {
192
223
  * together. Keep the body on the calling fiber, and do not wait in it for wakes that
193
224
  * only its own commit publishes. Only SQL hosts fail with `SqlError`.
194
225
  */
195
- readonly withTransaction: <A, E, R>(body: Effect.Effect<A, E, R>) => Effect.Effect<A, E | SqlError, R>;
226
+ readonly withTransaction: <A, E, R>(body: Effect.Effect<A, E, R>) => Effect.Effect<A, E | SqlError.SqlError, R>;
196
227
  }
197
228
  declare const CommitBoundary_base: Context.ServiceClass<CommitBoundary, "@streamsy/core/CommitBoundary", CommitBoundaryApi>;
198
229
  /** The transaction of the storage owner. Every Streamsy storage host provides it. */
199
230
  declare class CommitBoundary extends CommitBoundary_base {}
200
- //#endregion
201
- //#region src/protocol/expiry.d.ts
202
231
  /** One host-triggered sweep; the host owns scheduling and cancellation. */
203
232
  declare const expireDue: () => Effect.Effect<void, StorageFault, Storage>;
204
233
  declare namespace layer_d_exports {
@@ -210,8 +239,6 @@ interface ProtocolOptions {
210
239
  readonly longPollTimeoutMs?: number;
211
240
  }
212
241
  declare const layer$1: (options?: ProtocolOptions) => Layer.Layer<StreamsReader | StreamsWriter, never, Storage>;
213
- //#endregion
214
- //#region src/storage/memory/layer.d.ts
215
242
  interface MemoryOptions {
216
243
  readonly constrained?: boolean;
217
244
  readonly pollIntervalMs?: number;
@@ -226,7 +253,7 @@ declare const layerProtocol: (options?: Options) => Layer.Layer<CommitBoundary |
226
253
  /** Memory host. Streams and their feeds share the exposed storage boundary. */
227
254
  declare function layer<const Keys extends ReadonlyArray<Any>>(group: Group<Keys>, options?: Options): Layer.Layer<Storage | CommitBoundary | OwnerRecords | Host<Group<Keys>>>;
228
255
  declare namespace durable_state_d_exports {
229
- export { Change, ChangeHeaders, Delete, Upsert, changes, remove$1 as remove, upsert };
256
+ export { Change, ChangeHeaders, Delete, Entry, Materialized, Rows, Upsert, changes, materialize, materialized, remove$1 as remove, upsert };
230
257
  }
231
258
  interface ChangeHeaders {
232
259
  readonly txid?: string;
@@ -250,6 +277,11 @@ type Upsert<A, Type extends string = string> = Data.TaggedEnum.Value<Operation<A
250
277
  type Delete<A, Type extends string = string> = Data.TaggedEnum.Value<Operation<A, Type>, "Delete">;
251
278
  /** A pending change for one of the collections in `C`. */
252
279
  type Change<C extends Collections> = { [K in keyof C & string]: Upsert<C[K]["schema"]["Type"], K> | Delete<C[K]["schema"]["Type"], K>; }[keyof C & string];
280
+ /**
281
+ * One entry for `changes`: a pending change, or a State control such as
282
+ * `StreamAddress.reset()`.
283
+ */
284
+ type Entry<C extends Collections> = Change<C> | StateControl;
253
285
  /** Describe an upsert into a collection. The key is read from the value. */
254
286
  declare const upsert: <const Type extends string, A>(type: Type, value: A, options?: {
255
287
  readonly headers?: ChangeHeaders;
@@ -261,22 +293,278 @@ declare const remove$1: <const Type extends string, A = never>(type: Type, key:
261
293
  }) => Delete<NoInfer<A>, Type>;
262
294
  /**
263
295
  * Stamp Durable State changes with their key and headers. With an `offset`, each
264
- * change gets that offset and a default txid of `<offset>:<index>`.
296
+ * change gets that offset and a default txid of `<offset>:<index>`. A control
297
+ * entry passes through. It gets the `offset` only when it has none of its own.
265
298
  */
266
299
  declare function changes<C extends Collections, RD, RE>(address: StateAddress<C, RD, RE>, options: {
267
300
  readonly offset?: string;
268
- }, entries: NonEmptyReadonlyArray<Change<C>>): NonEmptyReadonlyArray<CollectionsChange<C>>;
301
+ }, entries: Array.NonEmptyReadonlyArray<Entry<C>>): Array.NonEmptyReadonlyArray<CollectionsEvent<C>>;
269
302
  declare function changes<C extends Collections, RD, RE>(address: StateAddress<C, RD, RE>, options: {
270
303
  readonly offset?: string;
271
- }, entries: ReadonlyArray<Change<C>>): ReadonlyArray<CollectionsChange<C>>;
304
+ }, entries: ReadonlyArray<Entry<C>>): ReadonlyArray<CollectionsEvent<C>>;
305
+ /** The rows of one collection, by State key. */
306
+ type Rows<C extends Collections> = { readonly [K in keyof C & string]: ReadonlyMap<string, C[K]["schema"]["Type"]>; };
307
+ /**
308
+ * The materialized state of a Durable State stream: the latest row for each key
309
+ * of each collection. `snapshot` holds the keys seen since an open
310
+ * `snapshot-start`, and is `undefined` outside a snapshot.
311
+ */
312
+ interface Materialized<C extends Collections> {
313
+ readonly rows: Rows<C>;
314
+ readonly snapshot: ReadonlySet<string> | undefined;
315
+ }
316
+ /** Empty materialized state for the collections of `address`. */
317
+ declare function materialized<C extends Collections>(address: {
318
+ readonly collections: C;
319
+ }): Materialized<C>;
320
+ /**
321
+ * Fold State events into materialized state, with the State protocol rules:
322
+ *
323
+ * - `upsert` sets the row of its key, and `delete` removes it.
324
+ * - `reset` clears every collection.
325
+ * - `snapshot-end` removes each row that no change since `snapshot-start` named.
326
+ * A snapshot may span several calls.
327
+ *
328
+ * The input state is not changed. Only the collections that `events` touch are copied.
329
+ */
330
+ declare function materialize<C extends Collections>(state: Materialized<C>, events: Iterable<CollectionsEvent<C>>): Materialized<C>;
272
331
  declare namespace producer_d_exports {
273
332
  export { Position, next };
274
333
  }
275
334
  type Position = ProducerOptions;
276
335
  /** Advance only after the caller has acknowledged appended or duplicate. Persist this tuple at the owning edge. */
277
336
  declare const next: (position: Position) => Position;
337
+ /** One row of a wake stream: the latest known state of one source stream. */
338
+ declare const WakeRow: Schema.Struct<{
339
+ /** Canonical id of the source stream. It is also the State key. */
340
+ readonly stream: Schema.brand<Schema.String, "StreamId">;
341
+ /** Source tail after the write. The same value as a reader's saved cursor. */
342
+ readonly offset: Schema.brand<Schema.String, "Offset">;
343
+ /** Present when the source stream is closed. */
344
+ readonly closed: Schema.optionalKey<Schema.Literal<true>>;
345
+ }>;
346
+ type WakeRow = typeof WakeRow.Type;
347
+ /** The one collection of every wake stream. Its State `type` is `stream`. */
348
+ declare const wakeCollections: {
349
+ readonly stream: {
350
+ readonly schema: Schema.Struct<{
351
+ /** Canonical id of the source stream. It is also the State key. */
352
+ readonly stream: Schema.brand<Schema.String, "StreamId">;
353
+ /** Source tail after the write. The same value as a reader's saved cursor. */
354
+ readonly offset: Schema.brand<Schema.String, "Offset">;
355
+ /** Present when the source stream is closed. */
356
+ readonly closed: Schema.optionalKey<Schema.Literal<true>>;
357
+ }>;
358
+ readonly key: "stream";
359
+ };
360
+ };
361
+ type WakeCollections = typeof wakeCollections;
362
+ /** One item of a wake stream. */
363
+ type WakeEvent = CollectionsEvent<WakeCollections>;
364
+ /**
365
+ * The codec of one wake stream message: a `stream` change or a State control.
366
+ * A client that decodes raw JSON pages uses it in place of a typed service.
367
+ */
368
+ declare const WakeMessage: Schema.Codec<WakeEvent, CollectionsEncodedEvent<WakeCollections>>;
369
+ /**
370
+ * Declare a wake stream: a State stream of `WakeRow`s at a template.
371
+ *
372
+ * ```ts
373
+ * class UserWake extends Streamsy.wake<UserWake>()("App/UserWake", "users/:user/wake", {
374
+ * params: { user: UserKey },
375
+ * }) {}
376
+ * ```
377
+ *
378
+ * The declaration names no sources. A `Projection.wake` binding links one
379
+ * source stream to one wake stream, with params of its own.
380
+ */
381
+ declare const wake: <Self>() => <const Name extends string, const Template extends string, C extends ParamCodecs>(name: Name, template: Template, options: {
382
+ readonly params: C & ExactTemplateParams<Template, C>;
383
+ }) => StateClass<Self, Name, Template, C, {
384
+ readonly stream: {
385
+ readonly schema: Schema.Struct<{
386
+ /** Canonical id of the source stream. It is also the State key. */
387
+ readonly stream: Schema.brand<Schema.String, "StreamId">;
388
+ /** Source tail after the write. The same value as a reader's saved cursor. */
389
+ readonly offset: Schema.brand<Schema.String, "Offset">;
390
+ /** Present when the source stream is closed. */
391
+ readonly closed: Schema.optionalKey<Schema.Literal<true>>;
392
+ }>;
393
+ readonly key: "stream";
394
+ };
395
+ }>;
396
+ /** One action for a consumer of a wake stream. */
397
+ type WakeItem = Data.TaggedEnum<{
398
+ /** Read `stream` from `from` up to at least `offset`, then save its cursor. */
399
+ Dirty: {
400
+ readonly stream: StreamId;
401
+ readonly from: string;
402
+ readonly offset: string;
403
+ readonly closed: boolean;
404
+ };
405
+ /** The stream was removed. Drop its cursor and its local data. */
406
+ Removed: {
407
+ readonly stream: StreamId;
408
+ };
409
+ /** Drop every cursor. The items after this one start each stream from `-1`. */
410
+ Reset: {};
411
+ /** A complete snapshot ended. Drop each stream that `streams` does not hold. */
412
+ Snapshot: {
413
+ readonly streams: ReadonlySet<StreamId>;
414
+ };
415
+ }>;
416
+ /** Constructors and matchers for `WakeItem`. */
417
+ declare const WakeItem: {
418
+ readonly $is: <Tag extends "Dirty" | "Removed" | "Reset" | "Snapshot">(tag: Tag) => (u: unknown) => u is Extract<{
419
+ readonly _tag: "Dirty";
420
+ readonly stream: StreamId;
421
+ readonly from: string;
422
+ readonly offset: string;
423
+ readonly closed: boolean;
424
+ }, {
425
+ readonly _tag: Tag;
426
+ }> | Extract<{
427
+ readonly _tag: "Removed";
428
+ readonly stream: StreamId;
429
+ }, {
430
+ readonly _tag: Tag;
431
+ }> | Extract<{
432
+ readonly _tag: "Reset";
433
+ }, {
434
+ readonly _tag: Tag;
435
+ }> | Extract<{
436
+ readonly _tag: "Snapshot";
437
+ readonly streams: ReadonlySet<StreamId>;
438
+ }, {
439
+ readonly _tag: Tag;
440
+ }>;
441
+ readonly $match: {
442
+ <Cases extends { readonly [Tag in "Dirty" | "Removed" | "Reset" | "Snapshot"]: (args: Extract<{
443
+ readonly _tag: "Dirty";
444
+ readonly stream: StreamId;
445
+ readonly from: string;
446
+ readonly offset: string;
447
+ readonly closed: boolean;
448
+ } | {
449
+ readonly _tag: "Removed";
450
+ readonly stream: StreamId;
451
+ } | {
452
+ readonly _tag: "Reset";
453
+ } | {
454
+ readonly _tag: "Snapshot";
455
+ readonly streams: ReadonlySet<StreamId>;
456
+ }, {
457
+ readonly _tag: Tag;
458
+ }>) => any; }>(cases: Cases): (value: {
459
+ readonly _tag: "Dirty";
460
+ readonly stream: StreamId;
461
+ readonly from: string;
462
+ readonly offset: string;
463
+ readonly closed: boolean;
464
+ } | {
465
+ readonly _tag: "Removed";
466
+ readonly stream: StreamId;
467
+ } | {
468
+ readonly _tag: "Reset";
469
+ } | {
470
+ readonly _tag: "Snapshot";
471
+ readonly streams: ReadonlySet<StreamId>;
472
+ }) => import("effect/Unify").Unify<ReturnType<Cases["Dirty" | "Removed" | "Reset" | "Snapshot"]>>;
473
+ <Cases extends { readonly [Tag in "Dirty" | "Removed" | "Reset" | "Snapshot"]: (args: Extract<{
474
+ readonly _tag: "Dirty";
475
+ readonly stream: StreamId;
476
+ readonly from: string;
477
+ readonly offset: string;
478
+ readonly closed: boolean;
479
+ } | {
480
+ readonly _tag: "Removed";
481
+ readonly stream: StreamId;
482
+ } | {
483
+ readonly _tag: "Reset";
484
+ } | {
485
+ readonly _tag: "Snapshot";
486
+ readonly streams: ReadonlySet<StreamId>;
487
+ }, {
488
+ readonly _tag: Tag;
489
+ }>) => any; }>(value: {
490
+ readonly _tag: "Dirty";
491
+ readonly stream: StreamId;
492
+ readonly from: string;
493
+ readonly offset: string;
494
+ readonly closed: boolean;
495
+ } | {
496
+ readonly _tag: "Removed";
497
+ readonly stream: StreamId;
498
+ } | {
499
+ readonly _tag: "Reset";
500
+ } | {
501
+ readonly _tag: "Snapshot";
502
+ readonly streams: ReadonlySet<StreamId>;
503
+ }, cases: Cases): import("effect/Unify").Unify<ReturnType<Cases["Dirty" | "Removed" | "Reset" | "Snapshot"]>>;
504
+ };
505
+ readonly Dirty: Data.TaggedEnum.ConstructorFrom<{
506
+ readonly _tag: "Dirty";
507
+ readonly stream: StreamId;
508
+ readonly from: string;
509
+ readonly offset: string;
510
+ readonly closed: boolean;
511
+ }, "_tag">;
512
+ readonly Removed: Data.TaggedEnum.ConstructorFrom<{
513
+ readonly _tag: "Removed";
514
+ readonly stream: StreamId;
515
+ }, "_tag">;
516
+ readonly Reset: Data.TaggedEnum.ConstructorFrom<{
517
+ readonly _tag: "Reset";
518
+ }, "_tag">;
519
+ readonly Snapshot: Data.TaggedEnum.ConstructorFrom<{
520
+ readonly _tag: "Snapshot";
521
+ readonly streams: ReadonlySet<StreamId>;
522
+ }, "_tag">;
523
+ };
524
+ /** One batch of wake actions. Save `offset` as the wake cursor after every item is handled. */
525
+ interface WakeBatch {
526
+ readonly items: ReadonlyArray<WakeItem>;
527
+ readonly offset: string;
528
+ readonly upToDate: boolean;
529
+ }
530
+ interface FollowWakeOptions extends Omit<FollowOptions, "offset"> {
531
+ /** The saved wake cursor. Default: `-1`, a cold start. */
532
+ readonly from?: string;
533
+ /** Saved source cursors. Read again for each batch, so the consumer may update the map. */
534
+ readonly cursors: ReadonlyMap<StreamId, string>;
535
+ }
536
+ interface WakeActionsOptions {
537
+ /** Saved source cursors. A missing entry starts from `-1`. */
538
+ readonly cursors: ReadonlyMap<StreamId, string>;
539
+ /** The streams of a snapshot that an earlier batch left open. */
540
+ readonly snapshot?: ReadonlySet<StreamId> | undefined;
541
+ }
542
+ /** The actions of one wake batch, and the snapshot state for the next batch. */
543
+ interface WakeActions {
544
+ readonly items: ReadonlyArray<WakeItem>;
545
+ /** The streams of a snapshot that is still open. Pass it to the next call. */
546
+ readonly snapshot: ReadonlySet<StreamId> | undefined;
547
+ }
548
+ /**
549
+ * The actions for one batch of wake messages. The function is pure: it reads
550
+ * no stream and changes none of its inputs. Rows for one stream collapse to one
551
+ * item; a delete then an upsert of one stream gives `Removed`, then `Dirty` from
552
+ * `-1`. Pass the returned `snapshot` to the call for the next batch.
553
+ *
554
+ * `followWake` uses it over a typed service. A client with its own HTTP reader
555
+ * decodes each page with `WakeMessage` and calls it directly.
556
+ */
557
+ declare function wakeActions(events: ReadonlyArray<WakeEvent>, options: WakeActionsOptions): WakeActions;
558
+ /**
559
+ * Follow one wake stream and give the actions for each batch: which source
560
+ * streams to read, from which cursor, and which to drop. The helper reads no
561
+ * source stream. Save each source cursor first and the wake cursor (`offset`)
562
+ * last; a stop between the two reads the same rows again, and the offset check
563
+ * skips the streams that were already read.
564
+ */
565
+ declare function followWake<Self, P>(declaration: Context.Key<Self, Api<P, WakeEvent>>, params: P, options: FollowWakeOptions): Stream.Stream<WakeBatch, FollowFailure, Self>;
278
566
  declare namespace streamsy_d_exports {
279
- export { Address, Any, Api, BytesClass, Class, CustomClass, Group, Host, JsonClass, Services, StateClass, Wildcard, bytes, custom, group, json, state };
567
+ export { Address, Any, Api, BytesClass, Class, CustomClass, FollowWakeOptions, Group, Host, JsonClass, Services, StateClass, WakeActions, WakeActionsOptions, WakeBatch, WakeCollections, WakeEvent, WakeItem, WakeMessage, WakeRow, Wildcard, bytes, custom, followWake, group, json, state, wake, wakeActions, wakeCollections };
280
568
  }
281
569
  declare namespace streams_d_exports {
282
570
  export { AppendFailure, AppendItems, Batch, Collected, CreateFailure, DecideSpec, Decided, Decision, Folded, FollowFailure, FollowOptions, HeadFailure, ReadFailure, RemoveFailure, append, collect, create, decide, fold, follow, head, items, read$1 as read, remove, session };
@@ -301,7 +589,7 @@ declare const create: <A, RD, RE>(address: StreamAddress<A, RD, RE>, options?: O
301
589
  */
302
590
  type AppendItems<A, O> = O extends {
303
591
  readonly close: true;
304
- } ? ReadonlyArray<A> : NonEmptyReadonlyArray<A>;
592
+ } ? ReadonlyArray<A> : Array.NonEmptyReadonlyArray<A>;
305
593
  /**
306
594
  * Append items to one stream. The error type lists only the rejections that the
307
595
  * options make possible; a host that answers another one dies.
@@ -322,7 +610,7 @@ interface Collected<A> {
322
610
  * Read the stream up to its tail and fold every item into one value. Pass
323
611
  * `options.offset` to fold on from a tail that an earlier fold returned.
324
612
  */
325
- declare const fold: <A, RD, RE, S>(address: StreamAddress<A, RD, RE>, initial: LazyArg<S>, f: (state: S, item: A) => S, options?: ReadOptions$1 | undefined) => Effect.Effect<Folded<S>, ReadFailure, RD | StreamsReader>;
613
+ declare const fold: <A, RD, RE, S>(address: StreamAddress<A, RD, RE>, initial: Function.LazyArg<S>, f: (state: S, item: A) => S, options?: ReadOptions$1 | undefined) => Effect.Effect<Folded<S>, ReadFailure, RD | StreamsReader>;
326
614
  /** Read the stream up to its tail and return its items. */
327
615
  declare const collect: <A, RD, RE>(address: StreamAddress<A, RD, RE>, options?: ReadOptions$1 | undefined) => Effect.Effect<Collected<A>, ReadFailure, RD | StreamsReader>;
328
616
  /** What one `decide` step answers: a value, and the items to append for it. */
@@ -340,7 +628,7 @@ interface Decided<B> {
340
628
  }
341
629
  interface DecideSpec<A, S, B, E, R> {
342
630
  /** The start value of the fold. Each call starts from a new value. */
343
- readonly initial: LazyArg<S>;
631
+ readonly initial: Function.LazyArg<S>;
344
632
  readonly fold: (state: S, item: A) => S;
345
633
  /**
346
634
  * Decide what to append from the folded state. `offset` is the tail the state is
@@ -379,8 +667,6 @@ declare const items: <A, E, R>(batches: Stream.Stream<Batch<A>, E, R>) => Stream
379
667
  declare const session: <A, RD, RE>(address: StreamAddress<A, RD, RE>, options: ReadNextOptions) => Effect.Effect<ReadNextResult, StorageFault | TransportFault | ReadNextError, StreamsReader>;
380
668
  declare const head: <A, RD, RE>(address: StreamAddress<A, RD, RE>) => Effect.Effect<HeadResult, HeadFailure, StreamsReader>;
381
669
  declare const remove: <A, RD, RE>(address: StreamAddress<A, RD, RE>) => Effect.Effect<void, RemoveFailure, StreamsWriter>;
382
- //#endregion
383
- //#region src/toolkit/streamsy.d.ts
384
670
  /** A stream service with named failures for each toolkit call. */
385
671
  interface Api<P, A, RD = never, RE = never> {
386
672
  readonly owner: object;
@@ -389,7 +675,7 @@ interface Api<P, A, RD = never, RE = never> {
389
675
  readonly create: (params: P, options?: Omit<CreateOptions, "contentType">) => Effect.Effect<CreateResult, CreateFailure>;
390
676
  readonly append: <const O extends AppendCallOptions = {}>(params: P, items: AppendItems<A, O>, options?: O) => Effect.Effect<AppendResult, AppendFailure<O>, RE>;
391
677
  readonly read: (params: P, options?: ReadOptions$1) => Stream.Stream<Batch<A>, ReadFailure, RD>;
392
- readonly fold: <S>(params: P, initial: LazyArg<S>, f: (state: S, item: A) => S, options?: ReadOptions$1) => Effect.Effect<Folded<S>, ReadFailure, RD>;
678
+ readonly fold: <S>(params: P, initial: Function.LazyArg<S>, f: (state: S, item: A) => S, options?: ReadOptions$1) => Effect.Effect<Folded<S>, ReadFailure, RD>;
393
679
  readonly collect: (params: P, options?: ReadOptions$1) => Effect.Effect<Collected<A>, ReadFailure, RD>;
394
680
  readonly decide: <S, B, E, R>(params: P, spec: DecideSpec<A, S, B, E, R>) => Effect.Effect<Decided<B>, ReadFailure | AppendFailure<{
395
681
  expectedOffset: string;
@@ -412,7 +698,7 @@ type Class<Self, Name extends string, P, A, RD, RE, R extends StreamRoute<P, A,
412
698
  };
413
699
  type JsonClass<Self, Name extends string, T extends string, C extends ParamCodecs, A, I, RD, RE> = Class<Self, Name, Params<C>, A, RD, RE, ReturnType<typeof json$1<T, C, A, I, RD, RE>>>;
414
700
  declare const json: <Self>() => <const Name extends string, const T extends string, C extends ParamCodecs, A, I, RD, RE>(name: Name, ...args: Parameters<typeof json$1<T, C, A, I, RD, RE>>) => JsonClass<Self, Name, T, C, A, I, RD, RE>;
415
- type StateClass<Self, Name extends string, T extends string, C extends ParamCodecs, Collections$1 extends Collections> = Class<Self, Name, Params<C>, CollectionsChange<Collections$1>, CollectionsDecodingServices<Collections$1>, CollectionsEncodingServices<Collections$1>, ReturnType<typeof state$1<T, C, Collections$1>>>;
701
+ type StateClass<Self, Name extends string, T extends string, C extends ParamCodecs, Collections$1 extends Collections> = Class<Self, Name, Params<C>, CollectionsEvent<Collections$1>, CollectionsDecodingServices<Collections$1>, CollectionsEncodingServices<Collections$1>, ReturnType<typeof state$1<T, C, Collections$1>>>;
416
702
  declare const state: <Self>() => <const Name extends string, const T extends string, C extends ParamCodecs, const Collections$2 extends Collections>(name: Name, ...args: Parameters<typeof state$1<T, C, Collections$2>>) => StateClass<Self, Name, T, C, Collections$2>;
417
703
  type BytesClass<Self, Name extends string, T extends string, C extends ParamCodecs> = Class<Self, Name, Params<C>, Uint8Array, never, never, ReturnType<typeof bytes$1<T, C>>>;
418
704
  declare const bytes: <Self>() => <const Name extends string, const T extends string, C extends ParamCodecs>(name: Name, ...args: Parameters<typeof bytes$1<T, C>>) => BytesClass<Self, Name, T, C>;
@@ -446,8 +732,6 @@ type Services<G extends Group> = G["streams"][number]["Identifier"];
446
732
  /** What every host Layer gives for a group: its stream services. */
447
733
  type Host<G extends Group> = Services<G>;
448
734
  declare function group<const Keys extends ReadonlyArray<Any>>(...keys: Keys): Group<Keys>;
449
- //#endregion
450
- //#region src/http/routes.d.ts
451
735
  type RouteLayer<R> = Layer.Layer<never, never, HttpRouter.HttpRouter | HttpRouter.Request.From<"Requires", Exclude<R, HttpRouter.Provided>>>;
452
736
  interface Access<S extends Any = Any> {
453
737
  readonly stream: S;
@@ -456,12 +740,11 @@ interface Access<S extends Any = Any> {
456
740
  }
457
741
  interface RoutesOptions extends Omit<HttpOptions, "pathPrefix"> {
458
742
  readonly prefix?: `/${string}`;
743
+ /** The access of each stream on this mount. */
459
744
  readonly access: Access["access"] | ((stream: Any) => Access["access"]);
460
745
  }
461
746
  /** One prefix controls both route registration and protocol path stripping. */
462
747
  declare function routes<const Keys extends ReadonlyArray<Any>>(group: Group<Keys>, options: RoutesOptions): RouteLayer<Identifiers<Keys>>;
463
- //#endregion
464
- //#region src/http/read-program.d.ts
465
748
  interface ReadOptions {
466
749
  readonly sseDeadlineMs?: number;
467
750
  readonly cacheVisibility?: "private" | "public";
@@ -470,15 +753,11 @@ interface ReadOptions {
470
753
  declare function checkReadOptions(options: ReadOptions): void;
471
754
  /** Read an already resolved id using the protocol's HTTP framing and live modes. */
472
755
  declare function read(id: StreamId, options?: ReadOptions): Effect.Effect<HttpServerResponse.HttpServerResponse, InvalidReadRequest | NotSupported | StorageFault | StreamGone | StreamNotFound | TransportFault, HttpServerRequest.HttpServerRequest | StreamsReader>;
473
- //#endregion
474
- //#region src/http/security-headers.d.ts
475
756
  /** Shared protocol and host security headers. */
476
757
  declare const securityHeaders: Readonly<{
477
758
  "x-content-type-options": "nosniff";
478
759
  "cross-origin-resource-policy": "cross-origin";
479
760
  }>;
480
- //#endregion
481
- //#region src/http/shutdown-signal.d.ts
482
761
  /**
483
762
  * Tells live HTTP reads that the host is about to stop. A parked long poll then
484
763
  * answers `204` with its offset and cursor, and an open SSE body ends after its
@@ -509,5 +788,4 @@ declare const layerShutdownSignal: Layer.Layer<ShutdownSignal, never, never>;
509
788
  declare namespace index_d_exports {
510
789
  export { Access, HttpOptions, ReadOptions, RoutesOptions, ShutdownSignal, ShutdownSignalService, app, checkReadOptions, layerShutdownSignal, read, routes, securityHeaders, streamPath };
511
790
  }
512
- //#endregion
513
791
  export { durable_state_d_exports as A, address_d_exports as B, FollowFailure as C, streams_d_exports as D, RemoveFailure as E, CommitBoundary as F, HttpOptions as H, CommitBoundaryApi as I, ZERO_OFFSET as L, MemoryOptions as M, ProtocolOptions as N, streamsy_d_exports as O, layer_d_exports as P, compare as R, Folded as S, ReadFailure as T, app as U, streamPath as V, Collected as _, securityHeaders as a, Decided as b, read as c, routes as d, Any as f, Batch as g, AppendFailure as h, layerShutdownSignal as i, streams_d_exports$1 as j, producer_d_exports as k, Access as l, Identifiers as m, ShutdownSignal as n, ReadOptions as o, Group as p, ShutdownSignalService as r, checkReadOptions as s, index_d_exports as t, RoutesOptions as u, CreateFailure as v, HeadFailure as w, Decision as x, DecideSpec as y, route_d_exports as z };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { $ as ProducerOptions, A as CreateConflictReason, B as ProducerGap, C as ReadNextResult, D as AppendError, E as AppendConflict, F as InvalidEpochSeq, G as StaleEpoch, H as ReadError, I as InvalidForkRequest, J as StreamGone, K as StreamBusy, L as InvalidReadRequest, M as ForkSourceNotFound, N as HeadError, O as AppendErrorFor, P as InvalidAppendRequest, Q as AppendOptions, R as NotSupported, S as ReadMessage, T as AppendBaseError, U as ReadNextError, V as ProtocolError, W as RemoveError, X as isProtocolError, Y as StreamNotFound, Z as AppendCallOptions, _t as StreamsFault, a as Mutation, at as Offset, b as CreateResult, bt as isStreamsFault, c as Mutations, ct as RecordPatch, d as OperationResults, dt as StreamId, et as ReadNextOptions, f as Operations, ft as StreamLifecycle, gt as StorageFault, ht as EncodeFault, i as StorageShape, it as MessageWindow, j as CreateError, k as CreateConflict, l as Operation, lt as StoredMessage, m as StorageCapabilities, mt as DecodeFault, nt as CreateOptions, o as MutationApplied, ot as ProducerId, p as ProducerPrecondition, pt as StreamRecord, q as StreamClosed, r as Storage, rt as ChangeSnapshot, s as MutationRejected, st as ProducerState, tt as ReadOptions, u as OperationResult, ut as StreamConfig, vt as TransportFault, w as ReadResult, x as HeadResult, y as AppendResult, yt as isRetryableFault, z as OffsetMismatch } from "./owner-records-QDlssl__.js";
2
- import { A as durable_state_d_exports, B as address_d_exports, C as FollowFailure, E as RemoveFailure, F as CommitBoundary, I as CommitBoundaryApi, L as ZERO_OFFSET, O as streamsy_d_exports, R as compare, S as Folded, T as ReadFailure, _ as Collected, b as Decided, g as Batch, h as AppendFailure, j as streams_d_exports, k as producer_d_exports, t as index_d_exports, v as CreateFailure, w as HeadFailure, x as Decision, y as DecideSpec } from "./index-CFv8vZvy.js";
1
+ import { $ as ProducerOptions, A as CreateConflictReason, B as ProducerGap, C as ReadNextResult, D as AppendError, E as AppendConflict, F as InvalidEpochSeq, G as StaleEpoch, H as ReadError, I as InvalidForkRequest, J as StreamGone, K as StreamBusy, L as InvalidReadRequest, M as ForkSourceNotFound, N as HeadError, O as AppendErrorFor, P as InvalidAppendRequest, Q as AppendOptions, R as NotSupported, S as ReadMessage, T as AppendBaseError, U as ReadNextError, V as ProtocolError, W as RemoveError, X as isProtocolError, Y as StreamNotFound, Z as AppendCallOptions, _t as StreamsFault, a as Mutation, at as Offset, b as CreateResult, bt as isStreamsFault, c as Mutations, ct as RecordPatch, d as OperationResults, dt as StreamId, et as ReadNextOptions, f as Operations, ft as StreamLifecycle, gt as StorageFault, ht as EncodeFault, i as StorageShape, it as MessageWindow, j as CreateError, k as CreateConflict, l as Operation, lt as StoredMessage, m as StorageCapabilities, mt as DecodeFault, nt as CreateOptions, o as MutationApplied, ot as ProducerId, p as ProducerPrecondition, pt as StreamRecord, q as StreamClosed, r as Storage, rt as ChangeSnapshot, s as MutationRejected, st as ProducerState, tt as ReadOptions, u as OperationResult, ut as StreamConfig, vt as TransportFault, w as ReadResult, x as HeadResult, y as AppendResult, yt as isRetryableFault, z as OffsetMismatch } from "./owner-records-H7VEuBpy.js";
2
+ import { A as durable_state_d_exports, B as address_d_exports, C as FollowFailure, E as RemoveFailure, F as CommitBoundary, I as CommitBoundaryApi, L as ZERO_OFFSET, O as streamsy_d_exports, R as compare, S as Folded, T as ReadFailure, _ as Collected, b as Decided, g as Batch, h as AppendFailure, j as streams_d_exports, k as producer_d_exports, t as index_d_exports, v as CreateFailure, w as HeadFailure, x as Decision, y as DecideSpec } from "./index-p68har8W.js";
3
3
  export { AppendBaseError, type AppendCallOptions, AppendConflict, AppendError, AppendErrorFor, type AppendFailure, type AppendOptions, AppendResult, type Batch, ChangeSnapshot, type Collected, CommitBoundary, type CommitBoundaryApi, CreateConflict, CreateConflictReason, CreateError, type CreateFailure, type CreateOptions, CreateResult, type DecideSpec, type Decided, type Decision, DecodeFault, durable_state_d_exports as DurableState, EncodeFault, type Folded, type FollowFailure, ForkSourceNotFound, HeadError, type HeadFailure, type HeadResult, index_d_exports as Http, InvalidAppendRequest, InvalidEpochSeq, InvalidForkRequest, InvalidReadRequest, streams_d_exports as MemoryStorage, MessageWindow, Mutation, MutationApplied, MutationRejected, Mutations, NotSupported, Offset, OffsetMismatch, Operation, OperationResult, OperationResults, Operations, producer_d_exports as Producer, ProducerGap, ProducerId, type ProducerOptions, ProducerPrecondition, ProducerState, ProtocolError, ReadError, type ReadFailure, type ReadMessage, ReadNextError, type ReadNextOptions, type ReadNextResult, type ReadOptions, type ReadResult, RecordPatch, RemoveError, type RemoveFailure, StaleEpoch, Storage, StorageCapabilities, StorageFault, type StorageShape, StoredMessage, address_d_exports as StreamAddress, StreamBusy, StreamClosed, StreamConfig, StreamGone, StreamId, StreamLifecycle, StreamNotFound, StreamRecord, StreamsFault, streamsy_d_exports as Streamsy, TransportFault, ZERO_OFFSET, compare, isProtocolError, isRetryableFault, isStreamsFault };