@streamsy/projection 0.16.0 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { C as ItemOf, S as InputServices, T as Slices, _ as NonRetryable, a as Identity, b as Entry, c as ProjectionKey, d as RoutedStreamRecord, g as InvalidBinding, h as Unit, l as RetirementStatus, m as Range, n as CheckpointStore, r as CheckpointStoreApi, s as Loaded, t as CheckpointRecord, u as RouteRecords, v as NotAttached, w as Slice, x as InputMap, y as ProjectionFault } from "./checkpoint-store-BQviDBDA.js";
1
+ import { A as RangeUnreproducible, B as Slices, C as InvalidWakeTime, D as ProjectionFault, E as OutputRejected, F as Entry, I as InputMap, L as InputServices, M as SupersededGeneration, N as TokenConflict, O as ProjectionFaultReason, P as UnsupportedComposition, R as ItemOf, S as InvalidSource, T as NotAttached, _ as HistoryUnavailable, a as Identity, b as InvalidBinding, c as ProjectionKey, d as RoutedStreamRecord, g as GenerationMismatch, h as Unit, j as RetiredGeneration, k as ProjectionFaultReasonTag, l as RetirementStatus, m as Range, n as CheckpointStore, o as ListedBinding, r as CheckpointStoreApi, s as Loaded, t as CheckpointRecord, u as RouteRecords, v as IdentityMismatch, w as NonRetryable, x as InvalidRecord, y as InputNotFound, z as Slice } from "./checkpoint-store-C_Nipiyw.js";
2
2
  import { Cause, Context, Data, DateTime, Effect, Layer, Option, Pipeable, Schedule, Schema, Semaphore, Stream } from "effect";
3
- import { CommitBoundary, Decided, Decision, DurableState, Offset, OffsetMismatch, Storage, StorageFault, StreamAddress, StreamId, StreamsFault, Streamsy } from "@streamsy/core";
4
- import { MarkFailure, ProjectionMarkSummary } from "@streamsy/core/internal";
3
+ import { Decided, Decision, DurableState, InvalidStreamParams, Offset, OffsetMismatch, OwnerId, StorageFault, StorageOwner, StreamAddress, StreamId, StreamsFault, Streamsy } from "@streamsy/core";
4
+ import { Bindable, MarkFailure, ProjectionMarkSummary } from "@streamsy/core/internal";
5
5
  import { Reader, StreamRoute, Streams, Writer } from "@streamsy/core/protocol";
6
- import { SqlClient, SqlError } from "effect/sql";
6
+ import { SqlError } from "effect/sql";
7
7
  interface RunOptions {
8
8
  /** Maximum checkpoint transactions per call; absent means run to completion. */
9
9
  readonly limit?: number;
@@ -15,7 +15,11 @@ interface WakeAt {
15
15
  readonly _tag: "WakeAt";
16
16
  readonly wakeAt: number;
17
17
  }
18
- /** Return this request from process; returning void clears the previous deadline. */
18
+ /**
19
+ * Return this request from process; returning void clears the previous deadline. It never throws.
20
+ * A time that is not a non-negative safe integer in epoch milliseconds fails the unit with a
21
+ * `ProjectionFault` whose reason is `InvalidWakeTime`, before anything is committed.
22
+ */
19
23
  declare const wakeAt: (time: number | DateTime.DateTime) => WakeAt;
20
24
  type Result$1 = void | WakeAt | Folded<unknown> | Emitted<OutputNames> | Accumulated<unknown, OutputNames>;
21
25
  interface ResolvedOutput {
@@ -24,7 +28,7 @@ interface ResolvedOutput {
24
28
  readonly shared: boolean;
25
29
  } | undefined;
26
30
  readonly service: {
27
- readonly owner: object;
31
+ readonly owner: OwnerId;
28
32
  readonly wire: Reader<StreamsFault> & Writer<StreamsFault>;
29
33
  };
30
34
  }
@@ -41,6 +45,12 @@ interface Commit<in Result, in Provides = never, out Requires = never> extends P
41
45
  readonly load: (key: ProjectionKey) => Effect.Effect<Loaded, ProjectionFault, Requires>;
42
46
  readonly apply: (pending: Pending<Result, Provides>) => Effect.Effect<void, ProjectionFault | HandlerFailed, Requires>;
43
47
  readonly remove?: (key: ProjectionKey) => Effect.Effect<void, ProjectionFault, Requires>;
48
+ /**
49
+ * The generations and params with a live checkpoint for an id, from the store `load`
50
+ * reads. `Projection.attach` uses it for startup replay. Without it, or when it fails
51
+ * with `UnsupportedComposition`, startup replay needs explicit `bindings`.
52
+ */
53
+ readonly list?: (id: string) => Effect.Effect<ReadonlyArray<ListedBinding>, ProjectionFault, Requires>;
44
54
  /** Fence future checkpoint writes, then run cleanup even if the key was already retired. */
45
55
  readonly retire?: (request: RetireRequest) => Effect.Effect<RetirementStatus, ProjectionFault, Requires>;
46
56
  }
@@ -93,15 +103,6 @@ declare const Folded: Data.TaggedEnum.ConstructorFrom<Folded<unknown>, "_tag">,
93
103
  * declare at-least-once. The guarantee must describe the actual write. */
94
104
  declare const make: <Result, Provides = never, Requires = never>(options: Omit<Commit<Result, Provides, Requires>, typeof TypeId$1 | "pipe">) => Commit<Result, Provides, Requires>;
95
105
  declare const checkpoint: Commit<Folded<unknown>, never, CheckpointStore>;
96
- declare const Transaction_base: Context.ServiceClass<Transaction, "@streamsy/projection/Transaction", {
97
- readonly owner: object;
98
- readonly withTransaction: <A, E, R>(body: Effect.Effect<A, E, R>) => Effect.Effect<A, E | ProjectionFault, R>;
99
- }>;
100
- /** The storage owner's transaction, used by Commit.transaction. */
101
- export declare class Transaction extends Transaction_base {
102
- /** Join the commit boundary on a memory or SQL storage host. */
103
- static readonly layer: Layer.Layer<Transaction, never, CommitBoundary>;
104
- }
105
106
  declare const TransactionCommitTypeId: unique symbol;
106
107
  /** A commit that joins the storage owner's transaction and supplies no handler services. */
107
108
  interface TransactionCommit<in Result, out Requires> extends Commit<Result, never, Requires> {
@@ -124,12 +125,12 @@ interface TransactionCommit<in Result, out Requires> extends Commit<Result, neve
124
125
  * Durable Object clients share the driver's transaction, so a second client
125
126
  * joins the first. Using a second object's storage on one fiber is unsupported.
126
127
  */
127
- declare const transaction: TransactionCommit<Result$1, CheckpointStore | Transaction>;
128
+ declare const transaction: TransactionCommit<Result$1, StorageOwner>;
128
129
  /**
129
130
  * Clean up binding state in the owner's transaction on forget and retire.
130
131
  * The boundary follows the same nesting rules as {@link transaction}.
131
132
  */
132
- declare const transactionWithCleanup: <R>(cleanup: (key: ProjectionKey) => Effect.Effect<void, ProjectionFault, R>) => TransactionCommit<Result$1, CheckpointStore | Transaction | R>;
133
+ declare const transactionWithCleanup: <R>(cleanup: (key: ProjectionKey) => Effect.Effect<void, ProjectionFault, R>) => TransactionCommit<Result$1, StorageOwner | R>;
133
134
  declare const producer: Commit<Accumulated<unknown, Readonly<Record<string, never>>> | Emitted<Readonly<Record<string, never>>>, never, CheckpointStore>;
134
135
  declare const atLeastOnce: Commit<void | WakeAt, never, CheckpointStore>;
135
136
  declare const withCompensation: {
@@ -224,7 +225,8 @@ type FrontierStream<P = any> = StreamDeclaration & StreamRoute.StateRoute<P, Str
224
225
  interface FrontierDefinition<C extends StreamRoute.ParamCodecs, I extends Input, O> {
225
226
  readonly id: string;
226
227
  readonly generation?: number;
227
- readonly params: C;
228
+ /** The param codecs. Omit them, or pass `{}`, for a projection without params. */
229
+ readonly params?: C;
228
230
  /** The one source stream. Its params must be projection params. */
229
231
  readonly input: I & OneWithin<C, I>;
230
232
  /** The State declaration with frontier stream collections that gets the row. Its params must be projection params. */
@@ -257,19 +259,31 @@ type FrontierDeclaration<C extends StreamRoute.ParamCodecs, I extends Input, O e
257
259
  * });
258
260
  * ```
259
261
  */
260
- declare function frontier<C extends StreamRoute.ParamCodecs, const I extends Input, const O extends FrontierStream>(definition: FrontierDefinition<C, I, O>): FrontierDeclaration<C, I, O>;
262
+ declare function frontier<C extends StreamRoute.ParamCodecs = {}, const I extends Input = Input, const O extends FrontierStream = FrontierStream>(definition: FrontierDefinition<C, I, O>): FrontierDeclaration<C, I, O>;
263
+ /**
264
+ * The binding of a declaration: `singleton` without params, `at(params)` otherwise. Method
265
+ * syntax: a declaration with typed params is assignable here.
266
+ */
267
+ type AttachableBinding<B, Params = DecodedParams> = {
268
+ readonly singleton: B;
269
+ } | {
270
+ at(params: Params): B;
271
+ };
272
+ /** The part of a projection declaration that a runner reads to match and bind ids. */
273
+ interface Matchable {
274
+ readonly id: string;
275
+ readonly generation: number;
276
+ readonly params: StreamRoute.ParamCodecs;
277
+ readonly inputs: Inputs;
278
+ }
261
279
  /** The part of a projection declaration that the attach runner reads. */
262
- interface Attachable<B, HE = never, HR = never, Params = DecodedParams> {
280
+ type Attachable<B, HE = never, HR = never, Params = DecodedParams> = Matchable & AttachableBinding<B, Params> & RetryOptions<HE, HR>;
281
+ interface RetryOptions<HE, HR> {
263
282
  readonly retry?: {
264
283
  readonly schedule?: Schedule.Schedule<unknown>;
265
284
  readonly maxAttempts?: number;
266
285
  onExhausted?(this: void, unit: Unit<unknown>, failure: RunnerFailure): Effect.Effect<void, HE, HR>;
267
286
  } | undefined;
268
- readonly id: string;
269
- readonly generation: number;
270
- readonly params: StreamRoute.ParamCodecs;
271
- readonly inputs: Inputs;
272
- at(params: Params): B;
273
287
  }
274
288
  /** The result of one `pass`: one committed unit (`progress`), or no input or wake to commit. */
275
289
  interface PassResult<Inputs extends InputMap = InputMap> {
@@ -299,12 +313,13 @@ declare const pass: <Inputs extends InputMap, E, R, Q, Result, P, OR = never>(pr
299
313
  declare const run: <Inputs extends InputMap, E, R, Q, Result, P, S = never, OR = never>(projection: Executable<Inputs, E, R, Q, Result, P, S, OR>, options?: RunOptions | undefined) => Effect.Effect<Progress<StateValue<S>, Inputs>, E | ProjectionFault, OR | Q | InputServices<Inputs> | Exclude<R, P>>;
300
314
  /** Only identity and encoded params are needed; execution uses the runner's binding. */
301
315
  type Binding = Pick<Identity, "id" | "params">;
302
- type Declaration$2 = Omit<Attachable<Binding>, "retry">;
316
+ type Declaration$2 = Matchable & AttachableBinding<Binding>;
303
317
  /** Last failure of a binding, trigger stream or runner pass. */
304
318
  interface RunnerFailure {
305
319
  readonly at: number;
306
- readonly retryable: boolean;
307
- readonly reason: Option.Option<ProjectionFault["reason"]>;
320
+ readonly isRetryable: boolean;
321
+ /** The `_tag` of the fault's reason, such as `TokenConflict`. */
322
+ readonly reason: Option.Option<ProjectionFaultReasonTag>;
308
323
  readonly message: string;
309
324
  }
310
325
  /** Live binding observations with the binding's encoded params. */
@@ -418,8 +433,11 @@ declare const Registry_base: Context.ServiceClass<Registry, "@streamsy/projectio
418
433
  declare class Registry extends Registry_base {
419
434
  /** Match a binding's projection id and encoded params, independent of key order. */
420
435
  static readonly isFor: (binding: Binding) => (event: RunnerEvent) => boolean;
421
- /** Provide below the attach layers so they see this same registry. */
422
- static readonly layer: Layer.Layer<Registry>;
436
+ /**
437
+ * The runners attached to the storage owner. The state lives on the owner, so this
438
+ * layer can sit anywhere beside the attach layers, and building it twice is harmless.
439
+ */
440
+ static readonly layer: Layer.Layer<Registry, never, StorageOwner>;
423
441
  }
424
442
  /** Open one generation-owned stream in the current process transaction. */
425
443
  interface RoutedHandle<A, Params, R> {
@@ -433,14 +451,21 @@ interface RoutedDefinition<R> {
433
451
  interface RoutedOutputBindings<R> {
434
452
  readonly [RoutedOutputs]?: ReadonlyMap<string, RoutedDefinition<R>>;
435
453
  }
436
- /** A stream declaration. `.at(params)` resolves it with the projection params. */
437
- type StreamDeclaration = StreamRoute.StreamRoute<any, any> & Streamsy.Any & {
438
- readonly at: (params: any) => Streamsy.Address<any, any>;
439
- };
440
- /** A stream declaration, or a fixed address that `.at` does not rebind. */
454
+ /**
455
+ * A stream declaration. A singleton stream gives its `singleton` address; a stream with params
456
+ * is bound with the projection params through `at(params)`.
457
+ */
458
+ type StreamDeclaration = StreamRoute.StreamRoute<any, any> & Streamsy.Any & Bindable<any, Streamsy.Address<any, any>>;
459
+ /** A stream declaration, or a fixed address that binding does not change. */
441
460
  type Input = StreamDeclaration | Streamsy.Address<any, any>;
442
461
  type Inputs = Readonly<Record<string, Input>>;
443
- type AddressOf<X> = X extends PerGeneration<infer D, string, string> ? ReturnType<D["at"]> : X extends StreamDeclaration ? ReturnType<X["at"]> : X extends Streamsy.Address<any, any> ? X : never;
462
+ /** The value a declaration binds to: its `singleton`, or the result of its `at(params)`. */
463
+ type BoundOf<D> = D extends {
464
+ readonly singleton: infer B;
465
+ } ? B : D extends {
466
+ readonly at: (...args: any) => infer B;
467
+ } ? B : never;
468
+ type AddressOf<X> = X extends PerGeneration<infer D, string, string> ? BoundOf<D> : X extends StreamDeclaration ? BoundOf<X> : X extends Streamsy.Address<any, any> ? X : never;
444
469
  type Addresses<I extends RoutedMap> = { readonly [K in keyof I]: AddressOf<I[K]>; };
445
470
  type HandlerOutput<X> = X extends PerGeneration<infer D, string, infer By> ? [By] extends [never] ? AddressOf<X> : string extends By ? AddressOf<X> | RoutedHandle<AddressOf<X>, DecodedParams, D["Identifier"]> : RoutedHandle<AddressOf<X>, Pick<DeclaredParams<D>, By & keyof DeclaredParams<D>>, D["Identifier"]> : AddressOf<X>;
446
471
  type HandlerOutputs<O extends RoutedMap> = { readonly [K in keyof O]: HandlerOutput<O[K]>; };
@@ -452,19 +477,52 @@ type OneWithin<C extends StreamRoute.ParamCodecs, X> = InvalidInput<C, X> extend
452
477
  type InvalidOutput<C extends StreamRoute.ParamCodecs, X> = X extends PerGeneration<infer D, infer N, infer By> ? Extract<N | By, keyof C> | Invalid<C, Omit<DeclaredParams<D>, N | By>> : InvalidInput<C, X>;
453
478
  type OneOutputWithin<C extends StreamRoute.ParamCodecs, X> = InvalidOutput<C, X> extends never ? X : never;
454
479
  type OutputsWithin<C extends StreamRoute.ParamCodecs, D extends RoutedMap> = { readonly [K in keyof D]: OneOutputWithin<C, D[K]>; };
455
- /** Inert: `at` binds the params and returns the value runners take. */
456
- interface Declaration<Codecs extends StreamRoute.ParamCodecs, Bound, HE = never, HR = never> {
480
+ /**
481
+ * True when a param codec record names no parameter: the declaration is a singleton. The type
482
+ * reads the record's keys and the run time reads its entries, so a record typed wider than its
483
+ * value, such as `const codecs: StreamRoute.ParamCodecs = {}`, gives `false` here but a singleton
484
+ * at run time. `declare` gives such a singleton `at` and `resolve` too, so the typed members work.
485
+ */
486
+ type IsSingletonParams<Codecs> = [keyof Codecs] extends [never] ? true : false;
487
+ /**
488
+ * The binding members of a declaration. A declaration without params has `singleton`, its bound
489
+ * value. A declaration with params has `at(params)` and `resolve(params)`.
490
+ *
491
+ * At run time a declaration whose codec record is empty also has non-enumerable `at` and
492
+ * `resolve`. They ignore their argument and give the `singleton` value, so a record typed wider
493
+ * than its value, such as `const codecs: StreamRoute.ParamCodecs = {}`, still binds through the
494
+ * `at` its type has. A record typed narrower than its value, such as `const codecs: {} = { id }`,
495
+ * has the `singleton` type but only `at` and `resolve` at run time.
496
+ */
497
+ type DeclarationBindings<Codecs extends StreamRoute.ParamCodecs, Bound> = IsSingletonParams<Codecs> extends true ? {
498
+ /** The bound value of this declaration without params. One cached object. */
499
+ readonly singleton: Bound;
500
+ } : {
501
+ /**
502
+ * Bind the params. Throws a `RangeError` when a param does not encode or cannot form an
503
+ * input or output stream id; its `cause` is the `InvalidStreamParams`. Use `resolve` for
504
+ * request values.
505
+ */
506
+ readonly at: (params: StreamRoute.Params<Codecs>) => Bound;
507
+ /** Bind the params, or fail with `InvalidStreamParams`. Never throws. */
508
+ readonly resolve: (params: StreamRoute.Params<Codecs>) => Effect.Effect<Bound, InvalidStreamParams>;
509
+ };
510
+ /** The members of a declaration other than its binding. */
511
+ interface DeclarationCore<Codecs extends StreamRoute.ParamCodecs, HE = never, HR = never> {
457
512
  readonly retry?: BindingRetry<StreamRoute.Params<Codecs>, HE, HR> | undefined;
458
513
  readonly id: string;
459
514
  readonly generation: number;
460
515
  readonly params: Codecs;
461
- /** The declared inputs, before `at` binds them. */
516
+ /** The declared inputs, before binding. */
462
517
  readonly inputs: Inputs;
463
- /** Throws a RangeError when a param does not encode. */
464
- readonly at: (params: StreamRoute.Params<Codecs>) => Bound;
465
518
  /** Tries declaration inputs in order. Shared inputs return only their declared subset. */
466
519
  readonly parse: (id: string) => Option.Option<Partial<StreamRoute.Params<Codecs>>>;
467
520
  }
521
+ /**
522
+ * Inert: `singleton`, or `at(params)` for a declaration with params, gives the bound value that
523
+ * runners take.
524
+ */
525
+ type Declaration<Codecs extends StreamRoute.ParamCodecs, Bound, HE = never, HR = never> = DeclarationCore<Codecs, HE, HR> & DeclarationBindings<Codecs, Bound>;
468
526
  /** The services of a frontier stream. `frontier: true` and no frontier need none. */
469
527
  type FrontierServices<W> = W extends FrontierOutput ? Services<{
470
528
  frontier: W;
@@ -489,10 +547,11 @@ interface BindingRetry<Params, E = never, R = never> {
489
547
  readonly onExhausted?: (unit: Unit<Params>, failure: RunnerFailure) => Effect.Effect<void, E, R>;
490
548
  }
491
549
  interface Common<C extends StreamRoute.ParamCodecs, I extends Inputs, W = undefined, HE = never, HR = never> {
492
- readonly retry?: BindingRetry<StreamRoute.Params<C>, HE, HR>;
550
+ readonly retry?: BindingRetry<StreamRoute.Params<NoInfer<C>>, HE, HR>;
493
551
  readonly id: string;
494
552
  readonly generation?: number;
495
- readonly params: C;
553
+ /** The param codecs. Omit them, or pass `{}`, for a declaration without params. */
554
+ readonly params?: C;
496
555
  readonly inputs: I & Within<C, I>;
497
556
  /**
498
557
  * Publish the input offsets each unit accepted as frontier rows. `true` appends them to each
@@ -506,21 +565,23 @@ type DecodedParams = Readonly<Record<string, unknown>>;
506
565
  interface Committing<Result, P, Q> {
507
566
  readonly commit: Commit<Result, P, Q>;
508
567
  }
509
- type RunningDeclaration<C extends StreamRoute.ParamCodecs, I extends Inputs, E, R, Result, P, Q, S = never, OR = never, HE = never, HR = never> = Declaration<C, Omit<Executable<Addresses<I>, E | ProjectionFault, R, Q, Result, P, S, OR>, "process" | "prepare" | "state"> & {
568
+ /** The bound value of a running declaration. */
569
+ type RunningBound<I extends Inputs, E, R, Result, P, Q, S = never, OR = never> = Omit<Executable<Addresses<I>, E | ProjectionFault, R, Q, Result, P, S, OR>, "process" | "prepare" | "state"> & {
510
570
  readonly state: [S] extends [never] ? undefined : BoundState<S>;
511
571
  readonly process: (batch: Slices<Addresses<I>>, unit: Unit, encoded?: string) => Effect.Effect<Result, E | ProjectionFault, R>;
512
- }, HE, HR>;
572
+ };
573
+ type RunningDeclaration<C extends StreamRoute.ParamCodecs, I extends Inputs, E, R, Result, P, Q, S = never, OR = never, HE = never, HR = never> = Declaration<C, RunningBound<I, E, R, Result, P, Q, S, OR>, HE, HR>;
513
574
  type StatefulDeclaration<C extends StreamRoute.ParamCodecs, I extends Inputs, A, E, R, Result, P, Q, OR = never, HE = never, HR = never> = RunningDeclaration<C, I, E, R, Result, P, Q, A, OR, HE, HR>;
514
- type OutputDeclaration<C extends StreamRoute.ParamCodecs, I extends Inputs, O extends RoutedMap, E, R, Result, P, Q, A = never, OR = never, HE = never, HR = never> = Omit<RunningDeclaration<C, I, E, R, Result, P, Q, A, Services<O> | OR, HE, HR>, "at"> & {
515
- readonly at: (params: StreamRoute.Params<C>) => ReturnType<RunningDeclaration<C, I, E, R, Result, P, Q, A, Services<O> | OR, HE, HR>["at"]> & {
516
- readonly streams: Readonly<Record<string, Streamsy.Address<unknown, Services<O> | OR>>>;
517
- };
575
+ type OutputDeclaration<C extends StreamRoute.ParamCodecs, I extends Inputs, O extends RoutedMap, E, R, Result, P, Q, A = never, OR = never, HE = never, HR = never> = Declaration<C, OutputBound<I, O, E, R, Result, P, Q, A, OR>, HE, HR>;
576
+ /** The bound value of a declaration with outputs: a running binding plus its output streams. */
577
+ type OutputBound<I extends Inputs, O extends RoutedMap, E, R, Result, P, Q, A = never, OR = never> = RunningBound<I, E, R, Result, P, Q, A, Services<O> | OR> & {
578
+ readonly streams: Readonly<Record<string, Streamsy.Address<unknown, Services<O> | OR>>>;
518
579
  };
519
580
  type AccumulatingDeclaration<C extends StreamRoute.ParamCodecs, I extends Inputs, O extends RoutedMap, A, E, R, P, Q, OR = never, HE = never, HR = never> = OutputDeclaration<C, I, O, E, R, Accumulated<A, O>, P, Q, A, OR, HE, HR>;
520
581
  type RoutedMap = Readonly<Record<string, RoutedOutput>>;
521
582
  type StaticOutputMap = Readonly<Record<string, Input | PerGeneration<StreamDeclaration, string>>>;
522
583
  type Item<T> = AddressOf<T> extends {
523
- readonly collections: infer C extends StreamAddress.Collections;
584
+ readonly collections: infer C extends DurableState.Collections;
524
585
  } ? DurableState.Entry<C> : AddressOf<T> extends {
525
586
  readonly codec: Schema.Codec<infer A, any, any, any>;
526
587
  } ? A : never;
@@ -560,9 +621,9 @@ type Step<X, E = never, R = never> = X | Effect.Effect<X, E, R>;
560
621
  /** Each output keeps its item type here; missing keys emit nothing. */
561
622
  type Emits<O extends RoutedMap> = { readonly [K in keyof O]?: ReadonlyArray<Item<O[K]>>; };
562
623
  /** Fold one entry at a time. The default Commit saves state and offsets in one write. */
563
- declare function fold<C extends StreamRoute.ParamCodecs, I extends Inputs, A, SI, E = never, R = never, P = never, Q = CheckpointStore, W extends FrontierOutput | undefined = undefined, HE = never, HR = never>(definition: Common<C, I, W, HE, HR> & ([W] extends [undefined] ? Partial<Committing<FrontierResult<Folded<NoInfer<A>>, W>, P, Q>> : Committing<FrontierResult<Folded<NoInfer<A>>, W>, P, Q>) & {
564
- readonly state: StateDefinition<A, SI, StreamRoute.Params<C>>;
565
- readonly fold: (state: NoInfer<A>, entry: Entry<Addresses<I>>, unit: Unit<StreamRoute.Params<C>>) => Step<A, E, R>;
624
+ declare function fold<C extends StreamRoute.ParamCodecs = {}, I extends Inputs = Inputs, A = never, SI = never, E = never, R = never, P = never, Q = CheckpointStore, W extends FrontierOutput | undefined = undefined, HE = never, HR = never>(definition: Common<C, I, W, HE, HR> & ([W] extends [undefined] ? Partial<Committing<FrontierResult<Folded<NoInfer<A>>, W>, P, Q>> : Committing<FrontierResult<Folded<NoInfer<A>>, W>, P, Q>) & {
625
+ readonly state: StateDefinition<A, SI, StreamRoute.Params<NoInfer<C>>>;
626
+ readonly fold: (state: NoInfer<A>, entry: Entry<Addresses<I>>, unit: Unit<StreamRoute.Params<NoInfer<C>>>) => Step<A, E, R>;
566
627
  }): StatefulDeclaration<C, I, A, E, R, Folded<A>, P, Q, FrontierServices<W>, HE, HR>;
567
628
  /** void unless the handler result can be a WakeAt. */
568
629
  type TimerResult<A> = 0 extends 1 & A ? void : [Extract<A, WakeAt>] extends [never] ? void : void | WakeAt;
@@ -577,47 +638,44 @@ interface OutputsContext<O extends RoutedMap> {
577
638
  readonly outputs: HandlerOutputs<O>;
578
639
  }
579
640
  type TransactionBrand = Omit<TransactionCommit<never, never>, keyof Commit<never>>;
580
- type WithTransactionCommit<D extends {
581
- readonly at: (...args: never[]) => object;
582
- }> = Omit<D, "at"> & {
583
- readonly at: (...args: Parameters<D["at"]>) => ReturnType<D["at"]> & {
584
- readonly commit: TransactionBrand;
585
- };
586
- };
641
+ /** A declaration whose bound value carries the transaction commit brand. */
642
+ type TransactionDeclaration<C extends StreamRoute.ParamCodecs, B, HE, HR> = Declaration<C, B & {
643
+ readonly commit: TransactionBrand;
644
+ }, HE, HR>;
587
645
  /** Run side effects once per unit, including recorded wakes. Return wakeAt(time) to
588
646
  * replace the timer, or void to clear it. Timers require atLeastOnce or transaction.
589
647
  * prepare runs at least once, outside the transaction. */
590
- declare function process$1<C extends StreamRoute.ParamCodecs, I extends Inputs, E = never, R = never, P = never, Q = never, Prepared = void, PE = never, PR = never, W extends FrontierOutput | undefined = undefined, HE = never, HR = never, A = void>(definition: Common<C, I, W, HE, HR> & Committing<FrontierResult<TimerResult<A>, W>, P, Q> & {
648
+ declare function process$1<C extends StreamRoute.ParamCodecs = {}, I extends Inputs = Inputs, E = never, R = never, P = never, Q = never, Prepared = void, PE = never, PR = never, W extends FrontierOutput | undefined = undefined, HE = never, HR = never, A = void>(definition: Common<C, I, W, HE, HR> & Committing<FrontierResult<TimerResult<A>, W>, P, Q> & {
591
649
  readonly outputs?: never;
592
- readonly prepare?: (batch: Slices<Addresses<I>>, unit: Unit<StreamRoute.Params<C>>) => Effect.Effect<Prepared, PE, PR>;
593
- readonly process: (batch: Slices<Addresses<I>>, unit: Unit<StreamRoute.Params<C>>, context: ProcessContext<Prepared>) => Effect.Effect<A, E, R>;
650
+ readonly prepare?: (batch: Slices<Addresses<I>>, unit: Unit<StreamRoute.Params<NoInfer<C>>>) => Effect.Effect<Prepared, PE, PR>;
651
+ readonly process: (batch: Slices<Addresses<I>>, unit: Unit<StreamRoute.Params<NoInfer<C>>>, context: ProcessContext<Prepared>) => Effect.Effect<A, E, R>;
594
652
  }): RunningDeclaration<C, I, E | PE, R, TimerResult<A>, P, Q | PR, never, FrontierServices<W>, HE, HR>;
595
- declare function process$1<C extends StreamRoute.ParamCodecs, I extends Inputs, const O extends RoutedMap, E = never, R = never, Q = never, Prepared = void, PE = never, PR = never, W extends FrontierOutput | undefined = undefined, HE = never, HR = never, A = void>(definition: Common<C, I, W, HE, HR> & Committing<FrontierResult<TimerResult<A>, W>, never, Q> & {
653
+ declare function process$1<C extends StreamRoute.ParamCodecs = {}, I extends Inputs = Inputs, const O extends RoutedMap = RoutedMap, E = never, R = never, Q = never, Prepared = void, PE = never, PR = never, W extends FrontierOutput | undefined = undefined, HE = never, HR = never, A = void>(definition: Common<C, I, W, HE, HR> & Committing<FrontierResult<TimerResult<A>, W>, never, Q> & {
596
654
  readonly commit: TransactionBrand;
597
655
  readonly outputs: O & OutputsWithin<C, O>;
598
- readonly prepare?: (batch: Slices<Addresses<I>>, unit: Unit<StreamRoute.Params<C>>, context: OutputsContext<O>) => Effect.Effect<Prepared, PE, PR>;
599
- readonly process: (batch: Slices<Addresses<I>>, unit: Unit<StreamRoute.Params<C>>, context: ProcessContext<Prepared> & OutputsContext<O>) => Effect.Effect<A, E, R>;
600
- }): WithTransactionCommit<OutputDeclaration<C, I, O, E | PE, R, TimerResult<A>, never, Q | PR, never, FrontierServices<W>, HE, HR>>;
656
+ readonly prepare?: (batch: Slices<Addresses<I>>, unit: Unit<StreamRoute.Params<NoInfer<C>>>, context: OutputsContext<O>) => Effect.Effect<Prepared, PE, PR>;
657
+ readonly process: (batch: Slices<Addresses<I>>, unit: Unit<StreamRoute.Params<NoInfer<C>>>, context: ProcessContext<Prepared> & OutputsContext<O>) => Effect.Effect<A, E, R>;
658
+ }): TransactionDeclaration<C, OutputBound<I, O, E | PE, R, TimerResult<A>, never, Q | PR, never, FrontierServices<W>>, HE, HR>;
601
659
  /** Emit zero or more output items for each input entry, in entry order. */
602
- declare function emit<C extends StreamRoute.ParamCodecs, I extends Inputs, const O extends StaticOutputMap, X extends Emits<O>, E = never, R = never, P = never, Q = never, W extends FrontierOutput | true | undefined = undefined, HE = never, HR = never>(definition: Common<C, I, W, HE, HR> & Committing<Emitted<NoInfer<O>>, P, Q> & {
660
+ declare function emit<C extends StreamRoute.ParamCodecs = {}, I extends Inputs = Inputs, const O extends StaticOutputMap = StaticOutputMap, X extends Emits<O> = Emits<O>, E = never, R = never, P = never, Q = never, W extends FrontierOutput | true | undefined = undefined, HE = never, HR = never>(definition: Common<C, I, W, HE, HR> & Committing<Emitted<NoInfer<O>>, P, Q> & {
603
661
  readonly outputs: O & OutputsWithin<C, O>;
604
- readonly emit: ((entry: Entry<Addresses<I>>, unit: Unit<StreamRoute.Params<C>>) => Step<X, E, R>) & (Exclude<keyof X, keyof O> extends never ? unknown : {
662
+ readonly emit: ((entry: Entry<Addresses<I>>, unit: Unit<StreamRoute.Params<NoInfer<C>>>) => Step<X, E, R>) & (Exclude<keyof X, keyof O> extends never ? unknown : {
605
663
  readonly undeclaredOutput: Exclude<keyof X, keyof O>;
606
664
  });
607
665
  }): OutputDeclaration<C, I, O, E, R, Emitted<O>, P, Q, never, FrontierServices<W>, HE, HR>;
608
666
  type Definition<C extends StreamRoute.ParamCodecs, I extends Inputs, O extends StaticOutputMap, A, SI, P, Q, W, HE, HR> = Common<C, I, W, HE, HR> & Committing<Accumulated<NoInfer<A>, NoInfer<O>>, P, Q> & {
609
667
  readonly outputs: O & OutputsWithin<C, O>;
610
- readonly state: StateDefinition<A, SI, StreamRoute.Params<C>>;
668
+ readonly state: StateDefinition<A, SI, StreamRoute.Params<NoInfer<C>>>;
611
669
  };
612
670
  /** Thread the value and collect outputs, once per entry. */
613
- declare function mapAccum<C extends StreamRoute.ParamCodecs, I extends Inputs, const O extends StaticOutputMap, A, SI, X extends Emits<O>, E = never, R = never, P = never, Q = never, W extends FrontierOutput | true | undefined = undefined, HE = never, HR = never>(definition: Definition<C, I, O, A, SI, P, Q, W, HE, HR> & {
614
- readonly mapAccum: ((state: NoInfer<A>, entry: Entry<Addresses<I>>, unit: Unit<StreamRoute.Params<C>>) => Step<readonly [A, X], E, R>) & (Exclude<keyof X, keyof O> extends never ? unknown : {
671
+ declare function mapAccum<C extends StreamRoute.ParamCodecs = {}, I extends Inputs = Inputs, const O extends StaticOutputMap = StaticOutputMap, A = never, SI = never, X extends Emits<O> = Emits<O>, E = never, R = never, P = never, Q = never, W extends FrontierOutput | true | undefined = undefined, HE = never, HR = never>(definition: Definition<C, I, O, A, SI, P, Q, W, HE, HR> & {
672
+ readonly mapAccum: ((state: NoInfer<A>, entry: Entry<Addresses<I>>, unit: Unit<StreamRoute.Params<NoInfer<C>>>) => Step<readonly [A, X], E, R>) & (Exclude<keyof X, keyof O> extends never ? unknown : {
615
673
  readonly undeclaredOutput: Exclude<keyof X, keyof O>;
616
674
  });
617
675
  }): AccumulatingDeclaration<C, I, O, A, E, R, P, Q, FrontierServices<W>, HE, HR>;
618
676
  /** Compute the next value and outputs once for the whole unit batch. */
619
- declare function mapAccumBatch<C extends StreamRoute.ParamCodecs, I extends Inputs, const O extends StaticOutputMap, A, SI, X extends Emits<O>, E = never, R = never, P = never, Q = never, W extends FrontierOutput | true | undefined = undefined, HE = never, HR = never>(definition: Definition<C, I, O, A, SI, P, Q, W, HE, HR> & {
620
- readonly mapAccumBatch: ((state: NoInfer<A>, batch: Slices<Addresses<I>>, unit: Unit<StreamRoute.Params<C>>) => Step<readonly [A, X], E, R>) & (Exclude<keyof X, keyof O> extends never ? unknown : {
677
+ declare function mapAccumBatch<C extends StreamRoute.ParamCodecs = {}, I extends Inputs = Inputs, const O extends StaticOutputMap = StaticOutputMap, A = never, SI = never, X extends Emits<O> = Emits<O>, E = never, R = never, P = never, Q = never, W extends FrontierOutput | true | undefined = undefined, HE = never, HR = never>(definition: Definition<C, I, O, A, SI, P, Q, W, HE, HR> & {
678
+ readonly mapAccumBatch: ((state: NoInfer<A>, batch: Slices<Addresses<I>>, unit: Unit<StreamRoute.Params<NoInfer<C>>>) => Step<readonly [A, X], E, R>) & (Exclude<keyof X, keyof O> extends never ? unknown : {
621
679
  readonly undeclaredOutput: Exclude<keyof X, keyof O>;
622
680
  });
623
681
  }): AccumulatingDeclaration<C, I, O, A, E, R, P, Q, FrontierServices<W>, HE, HR>;
@@ -644,7 +702,9 @@ interface FollowOptions extends RunOptions {
644
702
  * `Projection.follow` span covers the whole stream.
645
703
  */
646
704
  declare const follow: <Inputs extends InputMap, E, R, Q, Result, P, S = never, OR = never>(projection: Executable<Inputs, E, R, Q, Result, P, S, OR>, options?: FollowOptions) => Stream.Stream<Progress<StateValue<S>, Inputs>, E | ProjectionFault, Exclude<R, P> | Q | OR | InputServices<Inputs>>;
647
- interface AttachOptions<Params = DecodedParams, E = never, R = never> {
705
+ /** The stream services of the trigger classes in `triggers`. */
706
+ type TriggerServices<T extends ReadonlyArray<FrontierStream<{}>>> = T[number]["Identifier"];
707
+ interface AttachOptions<Params = DecodedParams, E = never, R = never, T extends ReadonlyArray<FrontierStream<{}>> = ReadonlyArray<FrontierStream<{}>>> {
648
708
  /**
649
709
  * Decoded params to consider for startup replay. Defaults to the checkpoint
650
710
  * inventory when it is available. An explicit list uses this declaration's
@@ -652,13 +712,13 @@ interface AttachOptions<Params = DecodedParams, E = never, R = never> {
652
712
  */
653
713
  readonly bindings?: Effect.Effect<ReadonlyArray<Params>, E, R>;
654
714
  /**
655
- * Fixed-address frontier stream classes whose source ids request binding runs. A provided
656
- * stream service on another storage owner is remote; an absent service or a
657
- * matching owner is local. Provide the remote class through Protocol.bind.
715
+ * Fixed-address frontier stream classes whose source ids request binding runs. Each class
716
+ * is a requirement of the attach layer. Its service on this storage owner is local; on
717
+ * another owner it is remote, so provide that class through Protocol.bind.
658
718
  * Projection.attach follows remote triggers in scope; ProjectionWakeup.attach
659
719
  * accepts only triggers on its own owner. Cursors persist in both modes.
660
720
  */
661
- readonly triggers?: ReadonlyArray<FrontierStream<{}>>;
721
+ readonly triggers?: T;
662
722
  /** Units for each binding in one run. Default 100. */
663
723
  readonly limit?: number;
664
724
  /**
@@ -686,9 +746,10 @@ interface AttachOptions<Params = DecodedParams, E = never, R = never> {
686
746
  }
687
747
  /**
688
748
  * Run a projection whenever a local commit writes one of its inputs. The layer
689
- * subscribes to `Storage.committed` when it is built, so build it with the
749
+ * subscribes to `StorageOwner.committed` when it is built, so build it with the
690
750
  * storage layer and before the app writes. For each written id, the input's
691
- * `parse` gives the params, and the runner runs `projection.at(params)`.
751
+ * `parse` gives the params, and the runner runs `projection.at(params)`, or
752
+ * `projection.singleton` for a projection without params.
692
753
  * The background runner also queues startup replays from the checkpoint
693
754
  * inventory or `options.bindings`.
694
755
  *
@@ -715,7 +776,7 @@ interface AttachOptions<Params = DecodedParams, E = never, R = never> {
715
776
  * );
716
777
  * ```
717
778
  */
718
- declare const attach$1: <I extends InputMap, E, R, Q, Result, P, OR = never, HE = never, HR = never, Params extends DecodedParams = DecodedParams, BE = never, BR = never>(projection: Attachable<Executable<I, E, R, Q, Result, P, unknown, OR>, HE, HR, Params>, options?: AttachOptions<NoInfer<Params>, BE, BR>) => Layer.Layer<never, never, Storage | Exclude<R, P> | Q | OR | HR | InputServices<I> | BR>;
779
+ declare const attach$1: <I extends InputMap, E, R, Q, Result, P, OR = never, HE = never, HR = never, Params extends DecodedParams = DecodedParams, BE = never, BR = never, const T extends ReadonlyArray<FrontierStream<{}>> = readonly []>(projection: Attachable<Executable<I, E, R, Q, Result, P, unknown, OR>, HE, HR, Params>, options?: AttachOptions<NoInfer<Params>, BE, BR, T>) => Layer.Layer<never, never, StorageOwner | Exclude<R, P> | Q | OR | HR | InputServices<I> | BR | TriggerServices<T>>;
719
780
  /** A bound value projection. Output items from its adapter are discarded. */
720
781
  interface CurrentProjection<Inputs extends InputMap, S, E, R, Q> extends Identity {
721
782
  readonly inputs: Inputs;
@@ -742,7 +803,7 @@ declare const current: <Inputs extends InputMap, S, E, R, Q>(projection: Current
742
803
  * codecs. On MySQL, listing fails while the range contains a legacy hashed key
743
804
  * that has yet to be rewritten.
744
805
  */
745
- declare const bindings: <C extends Readonly<Record<string, Schema.Codec<unknown, string, never, never>>>>(declaration: Pick<Declaration<C, unknown, never, never>, "id" | "params">, options?: {
806
+ declare const bindings: <C extends Readonly<Record<string, Schema.Codec<unknown, string, never, never>>>>(declaration: Pick<Declaration<C, unknown>, "id" | "params">, options?: {
746
807
  readonly generation?: number;
747
808
  } | undefined) => Effect.Effect<readonly StreamRoute.Params<C>[], InvalidBinding | ProjectionFault, CheckpointStore>;
748
809
  declare const Tail: Schema.Struct<{
@@ -793,12 +854,12 @@ interface DecideSpec<Inputs extends InputMap, K extends keyof Inputs, S, B, E, R
793
854
  * Retry only this append's OffsetMismatch while the retry schedule allows.
794
855
  */
795
856
  declare const decide: <Inputs extends InputMap, const K extends keyof Inputs & string, B, E, R, PE, PR, Q, S>(projection: CurrentProjection<Inputs, S, PE, PR, Q>, spec: DecideSpec<Inputs, K, S, B, E, R>) => Effect.Effect<Decided<B>, OffsetMismatch | Exclude<[Effect.Effect<Decision<B, ItemOf<Inputs[K]>>, E, R> | Effect.Effect<Snapshot<S, Inputs>, PE | ProjectionFault, PR | Q | InputServices<Inputs>> | Effect.Effect<{
796
- readonly owner: object;
857
+ readonly owner: import("@streamsy/core").OwnerId;
797
858
  readonly wire: import("@streamsy/core/protocol").Reader<import("@streamsy/core").StreamsFault> & import("@streamsy/core/protocol").Writer<import("@streamsy/core").StreamsFault>;
798
- }, never, Inputs[K]["stream"]["Identifier"]> | Effect.Effect<import("@streamsy/core").AppendResult, import("@streamsy/core").AppendConflict | import("@streamsy/core").EncodeFault | LostRace | import("@streamsy/core").NotSupported | import("@streamsy/core").StorageFault | import("@streamsy/core").StreamBusy | import("@streamsy/core").StreamClosed | import("@streamsy/core").StreamGone | import("@streamsy/core").StreamNotFound | import("@streamsy/core").TransportFault, never>] extends [Effect.Effect<infer _A, infer E_1, infer _R>] ? E_1 : never, LostRace>, [Effect.Effect<Decision<B, ItemOf<Inputs[K]>>, E, R> | Effect.Effect<Snapshot<S, Inputs>, PE | ProjectionFault, PR | Q | InputServices<Inputs>> | Effect.Effect<{
799
- readonly owner: object;
859
+ }, never, Inputs[K]["stream"]["Identifier"]> | Effect.Effect<import("@streamsy/core").AppendResult, import("@streamsy/core").AppendConflict | import("@streamsy/core").EncodeFault | LostRace | import("@streamsy/core").NotSupported | import("@streamsy/core").StorageFault | import("@streamsy/core").StreamBusy | import("@streamsy/core").StreamClosed | import("@streamsy/core").StreamGone | import("@streamsy/core").StreamNotFound | import("@streamsy/core").TransportFault, never> | Effect.Effect<string & import("effect/Brand").Brand<"Offset"> & import("effect/Brand").Brand<"StreamsyOffset">, ProjectionFault, never>] extends [Effect.Effect<infer _A, infer E_1, infer _R>] ? E_1 : never, LostRace>, [Effect.Effect<Decision<B, ItemOf<Inputs[K]>>, E, R> | Effect.Effect<Snapshot<S, Inputs>, PE | ProjectionFault, PR | Q | InputServices<Inputs>> | Effect.Effect<{
860
+ readonly owner: import("@streamsy/core").OwnerId;
800
861
  readonly wire: import("@streamsy/core/protocol").Reader<import("@streamsy/core").StreamsFault> & import("@streamsy/core/protocol").Writer<import("@streamsy/core").StreamsFault>;
801
- }, never, Inputs[K]["stream"]["Identifier"]> | Effect.Effect<import("@streamsy/core").AppendResult, import("@streamsy/core").AppendConflict | import("@streamsy/core").EncodeFault | LostRace | import("@streamsy/core").NotSupported | import("@streamsy/core").StorageFault | import("@streamsy/core").StreamBusy | import("@streamsy/core").StreamClosed | import("@streamsy/core").StreamGone | import("@streamsy/core").StreamNotFound | import("@streamsy/core").TransportFault, never>] extends [Effect.Effect<infer _A_1, infer _E, infer R_1>] ? R_1 : never>;
862
+ }, never, Inputs[K]["stream"]["Identifier"]> | Effect.Effect<import("@streamsy/core").AppendResult, import("@streamsy/core").AppendConflict | import("@streamsy/core").EncodeFault | LostRace | import("@streamsy/core").NotSupported | import("@streamsy/core").StorageFault | import("@streamsy/core").StreamBusy | import("@streamsy/core").StreamClosed | import("@streamsy/core").StreamGone | import("@streamsy/core").StreamNotFound | import("@streamsy/core").TransportFault, never> | Effect.Effect<string & import("effect/Brand").Brand<"Offset"> & import("effect/Brand").Brand<"StreamsyOffset">, ProjectionFault, never>] extends [Effect.Effect<infer _A_1, infer _E, infer R_1>] ? R_1 : never>;
802
863
  /**
803
864
  * Marks the `OffsetMismatch` of this call's own append. As in `Streams.decide`,
804
865
  * only this error is retried: an `OffsetMismatch` that the caller's `decide`
@@ -812,8 +873,8 @@ declare class LostRace {
812
873
  * Deletes a live checkpoint and marks its routed outputs as forgotten so retirement
813
874
  * can still find them. Preserves retirement tombstones. Stop the follower first,
814
875
  * or use a new generation.
815
- * Pass the binding from `declaration.at(params)` for a routed projection. A bare
816
- * key deletes the checkpoint and leaves the route records live.
876
+ * Pass the binding from `declaration.at(params)`, or `declaration.singleton`, for a
877
+ * routed projection. A bare key deletes the checkpoint and leaves the route records live.
817
878
  * Delete stream outputs first, because forgetting restarts their producer sequences.
818
879
  */
819
880
  declare const forget: <R>(projection: ProjectionKey & {
@@ -834,41 +895,36 @@ interface Retired {
834
895
  interface Retirable<R, Q> extends ProjectionKey, BoundOutputs<R> {
835
896
  readonly commit: Pick<Commit<never, never, Q>, "retire">;
836
897
  }
837
- /** Retire one binding and clean up its exclusively owned generation outputs. */
838
- declare const retire: <C extends StreamRoute.ParamCodecs, R, Q, HE, HR>(declaration: Declaration<C, Retirable<R, Q>, HE, HR>, params: StreamRoute.Params<C>, options: {
898
+ interface RetireOptions {
899
+ /** The generation to retire. */
839
900
  readonly generation: number;
901
+ /** Remove (the default) or close each exclusively owned generation output. */
840
902
  readonly streams?: StreamMode;
841
- }) => Effect.Effect<Retired, ProjectionFault, R | Q>;
903
+ }
904
+ /**
905
+ * The arguments of `retire` after the declaration: `options` alone for a declaration without
906
+ * params, and `params, options` otherwise.
907
+ */
908
+ type RetireArgs<C extends StreamRoute.ParamCodecs> = IsSingletonParams<C> extends true ? [options: RetireOptions] : [params: StreamRoute.Params<C>, options: RetireOptions];
909
+ /**
910
+ * Retire one binding and clean up its exclusively owned generation outputs. A declaration
911
+ * without params takes no params argument: `retire(declaration, { generation })`.
912
+ */
913
+ declare const retire: <C extends StreamRoute.ParamCodecs, R, Q, HE, HR>(declaration: Declaration<C, Retirable<R, Q>, HE, HR>, ...args: NoInfer<RetireArgs<C>>) => Effect.Effect<Retired, ProjectionFault, R | Q>;
842
914
  declare namespace projection_d_exports {
843
- export { FrontierOutput, FrontierServices, FrontierStream, InputLag, Lag, PerGeneration, Registry, RegistryApi, Retired, RetiredStream, RoutedHandle, RunnerEvent, RunnerFailure, RunnerStatus, Tails, WakeAt, attach$1 as attach, bindings, caughtUp, createOutputs, current, decide, each, emit, fold, follow, forget, frontier, generationBinding, isPerGeneration, items, key$1 as key, lag, mapAccum, mapAccumBatch, pass, perGeneration, process$1 as process, read, retire, run, tails, wakeAt };
915
+ export { FrontierOutput, FrontierServices, FrontierStream, InputLag, Lag, PerGeneration, Registry, RegistryApi, RetireArgs, RetireOptions, Retired, RetiredStream, RoutedHandle, RunnerEvent, RunnerFailure, RunnerStatus, Tails, WakeAt, attach$1 as attach, bindings, caughtUp, createOutputs, current, decide, each, emit, fold, follow, forget, frontier, generationBinding, isPerGeneration, items, key$1 as key, lag, mapAccum, mapAccumBatch, pass, perGeneration, process$1 as process, read, retire, run, tails, wakeAt };
844
916
  }
845
917
  declare const key$1: (projection: Identity) => ProjectionKey;
846
918
  /** Runs each tagged entry in order and discards its success value. */
847
919
  declare const each: <Inputs extends InputMap, E, R, P = Record<string, string>>(handle: (entry: Entry<Inputs>, unit: Unit<P>) => Effect.Effect<unknown, E, R>) => ((batch: Slices<Inputs>, unit: Unit<P>) => Effect.Effect<void, E, R>);
848
- declare const BackendTypeId: unique symbol;
849
- interface Opaque {
850
- readonly [BackendTypeId]: true;
851
- }
852
- declare const StateTableBackend_base: Context.ServiceClass<StateTableBackend, "@streamsy/projection/StateTableBackend", Opaque>;
853
- /** Host-selected row storage for StateTable and FoldByKey. */
854
- export declare class StateTableBackend extends StateTableBackend_base {
855
- /** Keep rows in the host database. Run StateTable.migrate with the same client. */
856
- static readonly layerSql: Layer.Layer<StateTableBackend, never, SqlClient.SqlClient>;
857
- /**
858
- * Keep rows in the heap and join the memory owner's transaction. Every layer over one
859
- * owner shares its rows. A read outside a unit, or on a fiber that the unit forked,
860
- * sees committed rows only.
861
- */
862
- static readonly layerMemory: Layer.Layer<StateTableBackend, never, CommitBoundary>;
863
- }
864
920
  declare namespace state_table_d_exports {
865
921
  export { Bound, Declaration$1 as Declaration, ListOptions, UnitRows, clear, define, migrate, rebuild, reset, unit };
866
922
  }
867
923
  /**
868
- * Create the row index on SQLite, Postgres or MySQL at host startup, outside storage
869
- * migrations. A host with `StateTableBackend.layerSql` runs it with the same client.
924
+ * Create the row index on a SQL storage owner (SQLite, Postgres or MySQL) at host
925
+ * startup, outside storage migrations. A memory owner needs none, so it does nothing.
870
926
  */
871
- declare const migrate: (sql: SqlClient.SqlClient) => Effect.Effect<void, ProjectionFault | SqlError.SqlError, never>;
927
+ declare const migrate: Effect.Effect<void, ProjectionFault | SqlError.SqlError, StorageOwner>;
872
928
  /** Keyset pages are not snapshots. Follow changes from the first page's offset. */
873
929
  interface ListOptions {
874
930
  readonly after?: string | undefined;
@@ -877,7 +933,7 @@ interface ListOptions {
877
933
  /** Bound reads keep `SqlError` in their errors. Only SQL backends fail with it. */
878
934
  type ReadError = SqlError.SqlError;
879
935
  /** A State stream bound to its params: a bound projection, plus the row reads and `sync`. */
880
- interface Bound<C extends StreamAddress.Collections, R> {
936
+ interface Bound<C extends DurableState.Collections, R> {
881
937
  readonly id: string;
882
938
  readonly generation: number;
883
939
  readonly params: Record<string, string>;
@@ -890,17 +946,17 @@ interface Bound<C extends StreamAddress.Collections, R> {
890
946
  readonly commit: typeof transaction;
891
947
  readonly process: (batch: Slices<{
892
948
  readonly state: Streamsy.Address<string, R>;
893
- }>) => Effect.Effect<void, ProjectionFault, StateTableBackend | R>;
949
+ }>) => Effect.Effect<void, ProjectionFault, StorageOwner | R>;
894
950
  /** The row of `key`. `value` is undefined when the row is absent. */
895
951
  readonly get: <K extends keyof C & string>(collection: K, key: string) => Effect.Effect<{
896
952
  readonly offset: string;
897
953
  readonly value: C[K]["schema"]["Type"] | undefined;
898
- }, Schema.SchemaError | ReadError, StateTableBackend | C[K]["schema"]["DecodingServices"]>;
954
+ }, Schema.SchemaError | ReadError, StorageOwner | C[K]["schema"]["DecodingServices"]>;
899
955
  /** The rows of `keys` that exist, by key. */
900
956
  readonly getMany: <K extends keyof C & string>(collection: K, keys: ReadonlyArray<string>) => Effect.Effect<{
901
957
  readonly offset: string;
902
958
  readonly rows: ReadonlyMap<string, C[K]["schema"]["Type"]>;
903
- }, Schema.SchemaError | ReadError, StateTableBackend | C[K]["schema"]["DecodingServices"]>;
959
+ }, Schema.SchemaError | ReadError, StorageOwner | C[K]["schema"]["DecodingServices"]>;
904
960
  /** The rows in key order. `next` is the last key of a full page. */
905
961
  readonly list: <K extends keyof C & string>(collection: K, options?: ListOptions) => Effect.Effect<{
906
962
  readonly offset: string;
@@ -909,26 +965,33 @@ interface Bound<C extends StreamAddress.Collections, R> {
909
965
  readonly value: C[K]["schema"]["Type"];
910
966
  }>;
911
967
  readonly next: string | undefined;
912
- }, ProjectionFault | Schema.SchemaError | ReadError, StateTableBackend | C[K]["schema"]["DecodingServices"]>;
968
+ }, ProjectionFault | Schema.SchemaError | ReadError, StorageOwner | C[K]["schema"]["DecodingServices"]>;
913
969
  /** The stream offset that the rows reflect. */
914
- readonly offset: () => Effect.Effect<string, ReadError, StateTableBackend>;
970
+ readonly offset: () => Effect.Effect<string, ReadError, StorageOwner>;
915
971
  /** Apply the stream from the head of the table to its tail, in the caller's transaction. */
916
- readonly sync: () => Effect.Effect<void, ProjectionFault, StateTableBackend | R>;
972
+ readonly sync: () => Effect.Effect<void, ProjectionFault, StorageOwner | R>;
917
973
  }
918
- /** The declaration of a State table. Runners and `attach` take it like any declaration. */
919
- interface Declaration$1<Codecs extends StreamRoute.ParamCodecs, C extends StreamAddress.Collections, R> extends Omit<Declaration<Codecs, Bound<C, R>>, "inputs" | "parse"> {
974
+ /**
975
+ * The declaration of a State table. Runners and `attach` take it like any declaration. A table
976
+ * of a singleton State stream has `singleton`; one with params has `at(params)` and `resolve`.
977
+ */
978
+ type Declaration$1<Codecs extends StreamRoute.ParamCodecs, C extends DurableState.Collections, R> = Omit<DeclarationCore<Codecs>, "inputs" | "parse"> & {
920
979
  readonly inputs: {
921
980
  readonly state: State<Codecs, C, R>;
922
981
  };
923
982
  readonly parse: (id: string) => Option.Option<StreamRoute.Params<Codecs>>;
924
- }
925
- /** A `Streamsy.state` class with param codecs `Codecs` and collections `C`, served by `R`. */
926
- type State<Codecs extends StreamRoute.ParamCodecs, C extends StreamAddress.Collections, R> = StreamRoute.StateRoute<StreamRoute.Params<Codecs>, C> & Streamsy.Any & {
983
+ } & DeclarationBindings<Codecs, Bound<C, R>>;
984
+ /** The address of a `Streamsy.state` class with collections `C`, served by `R`. */
985
+ type StateBound<C extends DurableState.Collections, R> = StreamAddress.StateAddress<C> & Streamsy.Address<DurableState.CollectionsEvent<C>, R, DurableState.CollectionsDecodingServices<C>, DurableState.CollectionsEncodingServices<C>>;
986
+ /**
987
+ * A `Streamsy.state` class with param codecs `Codecs` and collections `C`, served by `R`: a
988
+ * singleton State stream with `singleton`, or one with params and `at(params)`.
989
+ */
990
+ type State<Codecs extends StreamRoute.ParamCodecs, C extends DurableState.Collections, R> = StreamRoute.StateRoute<StreamRoute.Params<Codecs>, C> & Streamsy.Any & {
927
991
  readonly paramCodecs: Codecs;
928
- readonly at: (params: StreamRoute.Params<Codecs>) => StreamAddress.StateAddress<C> & Streamsy.Address<StreamAddress.CollectionsEvent<C>, R, StreamAddress.CollectionsDecodingServices<C>, StreamAddress.CollectionsEncodingServices<C>>;
929
- };
992
+ } & Bindable<StreamRoute.Params<Codecs>, StateBound<C, R>>;
930
993
  /** A State stream's declaration, kept current by the ordinary projection runners. */
931
- declare function define<Codecs extends StreamRoute.ParamCodecs, C extends StreamAddress.Collections, R, W extends FrontierStream | undefined = undefined>(state: State<Codecs, C, R>, options?: {
994
+ declare function define<Codecs extends StreamRoute.ParamCodecs, C extends DurableState.Collections, R, W extends FrontierStream | undefined = undefined>(state: State<Codecs, C, R>, options?: {
932
995
  /**
933
996
  * A frontier stream that gets one row for the State stream at each applied offset, and the
934
997
  * frontier rows that the State stream carries.
@@ -936,25 +999,25 @@ declare function define<Codecs extends StreamRoute.ParamCodecs, C extends Stream
936
999
  readonly frontier?: W & OneWithin<Codecs, W>;
937
1000
  }): Declaration$1<Codecs, C, R | FrontierServices<W>>;
938
1001
  /** Delete cached rows and their applied offset, even if the State stream has been removed. */
939
- declare const clear: <C extends StreamAddress.Collections, R>(table: Bound<C, R>) => Effect.Effect<void, ProjectionFault, StateTableBackend | Transaction>;
1002
+ declare const clear: <C extends DurableState.Collections, R>(table: Bound<C, R>) => Effect.Effect<void, ProjectionFault, StorageOwner>;
940
1003
  /** Discard the index and replay the State stream atomically, retaining the binding checkpoint. */
941
- declare const rebuild: <C extends StreamAddress.Collections, R>(table: Bound<C, R>) => Effect.Effect<void, ProjectionFault, R | StateTableBackend | Transaction>;
1004
+ declare const rebuild: <C extends DurableState.Collections, R>(table: Bound<C, R>) => Effect.Effect<void, ProjectionFault, R | StorageOwner>;
942
1005
  /** Append a reset to the State stream. The next table run applies it. */
943
- declare const reset: <C extends StreamAddress.Collections, R>(table: Bound<C, R>) => Effect.Effect<import("@streamsy/core").AppendResult, Streams.AppendFailure<{}>, R>;
1006
+ declare const reset: <C extends DurableState.Collections, R>(table: Bound<C, R>) => Effect.Effect<import("@streamsy/core").AppendResult, Streams.AppendFailure<{}>, R>;
944
1007
  /** The rows of one State stream as one unit sees them, and the changes the unit makes. */
945
- interface UnitRows<C extends StreamAddress.Collections> {
1008
+ interface UnitRows<C extends DurableState.Collections> {
946
1009
  /** Read the stored rows of these keys into the unit, 50 keys for each query. */
947
- readonly load: (collection: keyof C & string, keys: Iterable<string>) => Effect.Effect<void, ProjectionFault, StateTableBackend>;
1010
+ readonly load: (collection: keyof C & string, keys: Iterable<string>) => Effect.Effect<void, ProjectionFault, StorageOwner>;
948
1011
  /** The unit's own last write of the key, or else the stored row. A removed key gives undefined. */
949
- readonly get: <K extends keyof C & string>(collection: K, key: string) => Effect.Effect<C[K]["schema"]["Type"] | undefined, ProjectionFault, StateTableBackend | C[K]["schema"]["DecodingServices"]>;
1012
+ readonly get: <K extends keyof C & string>(collection: K, key: string) => Effect.Effect<C[K]["schema"]["Type"] | undefined, ProjectionFault, StorageOwner | C[K]["schema"]["DecodingServices"]>;
950
1013
  /** Record an upsert. False when the row equals what `get` returns, and then nothing is recorded. */
951
1014
  readonly upsert: <K extends keyof C & string>(collection: K, row: C[K]["schema"]["Type"], options?: {
952
1015
  readonly headers?: DurableState.ChangeHeaders;
953
- }) => Effect.Effect<boolean, ProjectionFault, StateTableBackend | C[K]["schema"]["EncodingServices"]>;
1016
+ }) => Effect.Effect<boolean, ProjectionFault, StorageOwner | C[K]["schema"]["EncodingServices"]>;
954
1017
  /** Record a delete. False when the key has no row, and then nothing is recorded. */
955
1018
  readonly remove: (collection: keyof C & string, key: string, options?: {
956
1019
  readonly headers?: DurableState.ChangeHeaders;
957
- }) => Effect.Effect<boolean, ProjectionFault, StateTableBackend>;
1020
+ }) => Effect.Effect<boolean, ProjectionFault, StorageOwner>;
958
1021
  /** The recorded changes in call order. Return them under the output's name. */
959
1022
  readonly changes: () => ReadonlyArray<DurableState.Entry<C>>;
960
1023
  }
@@ -962,7 +1025,7 @@ interface UnitRows<C extends StreamAddress.Collections> {
962
1025
  * Create a missing unwrapped output, call `sync`, and open the unit's rows. Call it once
963
1026
  * for each unit, inside a `Commit.transaction` handler, and return `changes()`.
964
1027
  */
965
- declare const unit: <C extends StreamAddress.Collections, R>(table: Bound<C, R>) => Effect.Effect<UnitRows<C>, ProjectionFault, R | StateTableBackend>;
1028
+ declare const unit: <C extends DurableState.Collections, R>(table: Bound<C, R>) => Effect.Effect<UnitRows<C>, ProjectionFault, R | StorageOwner>;
966
1029
  declare const FoldByKeyError_base: Schema.Class<FoldByKeyError, Schema.TaggedStruct<"FoldByKeyError", {
967
1030
  readonly message: Schema.String;
968
1031
  }>, import("effect/Cause").YieldableError & {
@@ -976,26 +1039,26 @@ declare namespace fold_by_key_d_exports {
976
1039
  /** Return this from a fold to delete its row. The next record receives undefined. */
977
1040
  declare const remove: unique symbol;
978
1041
  type Remove = typeof remove;
979
- type Output<C extends StreamAddress.Collections, R> = StreamAddress.StateAddress<C> & Streamsy.Address<StreamAddress.CollectionsEvent<C>, R, StreamAddress.CollectionsDecodingServices<C>, StreamAddress.CollectionsEncodingServices<C>>;
1042
+ type Output<C extends DurableState.Collections, R> = StreamAddress.StateAddress<C> & Streamsy.Address<DurableState.CollectionsEvent<C>, R, DurableState.CollectionsDecodingServices<C>, DurableState.CollectionsEncodingServices<C>>;
980
1043
  /**
981
1044
  * A `Projection.process` handler for a declaration that lists the State stream
982
1045
  * of the table in `outputs`, under the key `O`.
983
1046
  */
984
- type Handler<C extends StreamAddress.Collections, O extends string, I extends InputMap, P, E, R, TR> = (batch: Slices<I>, unit: Unit<P>, context: {
1047
+ type Handler<C extends DurableState.Collections, O extends string, I extends InputMap, P, E, R, TR> = (batch: Slices<I>, unit: Unit<P>, context: {
985
1048
  readonly outputs: Readonly<Record<O, Output<C, TR>>>;
986
- }) => Effect.Effect<void, E | FoldByKeyError | ProjectionFault, R | TR | StateTableBackend | StreamAddress.CollectionsDecodingServices<C> | StreamAddress.CollectionsEncodingServices<C>>;
987
- interface Spec<C extends StreamAddress.Collections, K extends keyof C & string, O extends string, A, P, E, R> {
1049
+ }) => Effect.Effect<void, E | FoldByKeyError | ProjectionFault, R | TR | StorageOwner | DurableState.CollectionsDecodingServices<C> | DurableState.CollectionsEncodingServices<C>>;
1050
+ interface Spec<C extends DurableState.Collections, K extends keyof C & string, O extends string, A, P, E, R> {
988
1051
  readonly output: O;
989
1052
  readonly collection: K;
990
1053
  readonly key: (record: A, unit: Unit<P>) => string | undefined;
991
1054
  readonly fold: (previous: C[K]["schema"]["Type"] | undefined, record: A, unit: Unit<P>) => Step<C[K]["schema"]["Type"] | Remove, E, R>;
992
1055
  }
993
- type Expanded<C extends StreamAddress.Collections, K extends keyof C & string, O extends string, I extends InputMap, A, P, E, R> = Spec<C, K, O, A, P, E, R> & {
1056
+ type Expanded<C extends DurableState.Collections, K extends keyof C & string, O extends string, I extends InputMap, A, P, E, R> = Spec<C, K, O, A, P, E, R> & {
994
1057
  readonly records: (item: ItemOf<I[keyof I]>, unit: Unit<P>) => ReadonlyArray<A>;
995
1058
  };
996
1059
  /** Build a transaction process handler for one collection, grouping records in first-seen order. */
997
- declare function process<Codecs extends StreamRoute.ParamCodecs, C extends StreamAddress.Collections, TR, K extends keyof C & string, O extends string, I extends InputMap, A, P, E = never, R = never>(table: Declaration$1<Codecs, C, TR>, spec: Expanded<C, K, O, I, A, P, E, R>): Handler<C, O, I, P, E, R, TR>;
998
- declare function process<Codecs extends StreamRoute.ParamCodecs, C extends StreamAddress.Collections, TR, K extends keyof C & string, O extends string, I extends InputMap, P, E = never, R = never>(table: Declaration$1<Codecs, C, TR>, spec: Spec<C, K, O, ItemOf<I[keyof I]>, P, E, R> & {
1060
+ declare function process<Codecs extends StreamRoute.ParamCodecs, C extends DurableState.Collections, TR, K extends keyof C & string, O extends string, I extends InputMap, A, P, E = never, R = never>(table: Declaration$1<Codecs, C, TR>, spec: Expanded<C, K, O, I, A, P, E, R>): Handler<C, O, I, P, E, R, TR>;
1061
+ declare function process<Codecs extends StreamRoute.ParamCodecs, C extends DurableState.Collections, TR, K extends keyof C & string, O extends string, I extends InputMap, P, E = never, R = never>(table: Declaration$1<Codecs, C, TR>, spec: Spec<C, K, O, ItemOf<I[keyof I]>, P, E, R> & {
999
1062
  readonly records?: never;
1000
1063
  }): Handler<C, O, I, P, E, R, TR>;
1001
1064
  /**
@@ -1030,7 +1093,7 @@ interface WakeupHost {
1030
1093
  * A wake during backoff waits; a stopped timer fires late after retry or restart.
1031
1094
  * Return a time after unit.due to avoid repeatedly running a passed deadline.
1032
1095
  */
1033
- declare const attach: <I extends InputMap, E, R, Q, Result, P, OR = never, HE = never, HR = never, Params extends DecodedParams = DecodedParams, BE = never, BR = never>(projection: Attachable<Executable<I, E, R, Q, Result, P, unknown, OR>, HE, HR, Params>, options?: AttachOptions<NoInfer<Params>, BE, BR>) => Effect.Effect<{
1096
+ declare const attach: <I extends InputMap, E, R, Q, Result, P, OR = never, HE = never, HR = never, Params extends DecodedParams = DecodedParams, BE = never, BR = never, const T extends ReadonlyArray<FrontierStream<{}>> = readonly []>(projection: Attachable<Executable<I, E, R, Q, Result, P, unknown, OR>, HE, HR, Params>, options?: AttachOptions<NoInfer<Params>, BE, BR, T>) => Effect.Effect<{
1034
1097
  name: string;
1035
1098
  next: Effect.Effect<Option.Option<number>, import("@streamsy/core").StorageFault, BR | OR | Q | InputServices<I>>;
1036
1099
  retryable: typeof retryable;
@@ -1041,8 +1104,8 @@ declare const attach: <I extends InputMap, E, R, Q, Result, P, OR = never, HE =
1041
1104
  changed: Effect.Effect<void, never, never>;
1042
1105
  retry: import("effect/Schedule").Schedule<unknown, unknown, never, never>;
1043
1106
  deferred: Effect.Effect<number, import("@streamsy/core").StorageFault, never>;
1044
- }, never, import("effect/Scope").Scope | import("@streamsy/core").Storage>;
1107
+ }, never, import("effect/Scope").Scope | StorageOwner | TriggerServices<T>>;
1045
1108
  export declare const ProjectionWakeup: {
1046
1109
  attach: typeof attach;
1047
1110
  };
1048
- export { type Accumulated, type AttachOptions, type Attachable, CheckpointRecord, CheckpointStore, type CheckpointStoreApi, commit_d_exports as Commit, type CurrentProjection, type DecideSpec, type Declaration, type Emits, type Emitted, type Entry, fold_by_key_d_exports as FoldByKey, type Folded, type FollowOptions, type FrontierStream, type Identity, type Initial, type InputMap, InvalidBinding, type ItemOf, type Loaded, NonRetryable, NotAttached, type Offsets, type OutputBatch, type OutputsContext, type PassResult, type ProcessContext, type Progress, projection_d_exports as Projection, ProjectionFault, type ProjectionKey, type Range, type RegistryApi, type RouteRecords, type RoutedHandle, type RoutedStreamRecord, type RunOptions, type RunnerFailure, type RunnerStatus, type Slice, type Slices, type Snapshot, type StateDefinition, type StateSchema, state_table_d_exports as StateTable, type Step, type Unit, type WakeAt };
1111
+ export { type Accumulated, type AttachOptions, type Attachable, CheckpointRecord, CheckpointStore, type CheckpointStoreApi, commit_d_exports as Commit, type CurrentProjection, type DecideSpec, type Declaration, type Emits, type Emitted, type Entry, fold_by_key_d_exports as FoldByKey, type Folded, type FollowOptions, type FrontierStream, GenerationMismatch, HistoryUnavailable, type Identity, IdentityMismatch, type Initial, type InputMap, InputNotFound, InvalidBinding, InvalidRecord, InvalidSource, InvalidWakeTime, type ItemOf, type Loaded, NonRetryable, NotAttached, type Offsets, type OutputBatch, OutputRejected, type OutputsContext, type PassResult, type ProcessContext, type Progress, projection_d_exports as Projection, ProjectionFault, ProjectionFaultReason, type ProjectionFaultReasonTag, type ProjectionKey, type Range, RangeUnreproducible, type RegistryApi, RetiredGeneration, type RouteRecords, type RoutedHandle, type RoutedStreamRecord, type RunOptions, type RunnerFailure, type RunnerStatus, type Slice, type Slices, type Snapshot, type StateDefinition, type StateSchema, state_table_d_exports as StateTable, type Step, SupersededGeneration, TokenConflict, type Unit, UnsupportedComposition, type WakeAt };