@streamsy/projection 0.11.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +162 -29
- package/dist/{checkpoint-store-D1saxIIM.d.ts → checkpoint-store-B1199nDD.d.ts} +58 -3
- package/dist/{checkpoint-store-Bm8z-f-l.js → checkpoint-store-ViVETLzZ.js} +201 -35
- package/dist/checkpoint.d.ts +2 -2
- package/dist/checkpoint.js +1 -1
- package/dist/index.d.ts +560 -153
- package/dist/index.js +1627 -257
- package/package.json +4 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { _ as
|
|
2
|
-
import { Cause, Context, Data, Effect, Layer, Option, Pipeable, Schedule, Schema, Stream } from "effect";
|
|
3
|
-
import { CommitBoundary, Decided, Decision, DurableState, OffsetMismatch, Storage, StreamAddress, StreamId, Streamsy } from "@streamsy/core";
|
|
4
|
-
import {
|
|
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-B1199nDD.js";
|
|
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";
|
|
5
|
+
import { Reader, StreamRoute, Streams, Writer } from "@streamsy/core/protocol";
|
|
5
6
|
import { SqlClient, SqlError } from "effect/sql";
|
|
6
7
|
interface RunOptions {
|
|
7
8
|
/** Maximum checkpoint transactions per call; absent means run to completion. */
|
|
@@ -9,19 +10,43 @@ interface RunOptions {
|
|
|
9
10
|
}
|
|
10
11
|
/** Tagged items in declaration order, then stream order within each input. */
|
|
11
12
|
declare const items: <Inputs extends InputMap>(batch: Slices<Inputs>) => ReadonlyArray<Entry<Inputs>>;
|
|
12
|
-
|
|
13
|
+
/** A process handler's request to run again at an epoch-millisecond deadline. */
|
|
14
|
+
interface WakeAt {
|
|
15
|
+
readonly _tag: "WakeAt";
|
|
16
|
+
readonly wakeAt: number;
|
|
17
|
+
}
|
|
18
|
+
/** Return this request from process; returning void clears the previous deadline. */
|
|
19
|
+
declare const wakeAt: (time: number | DateTime.DateTime) => WakeAt;
|
|
20
|
+
type Result$1 = void | WakeAt | Folded<unknown> | Emitted<OutputNames> | Accumulated<unknown, OutputNames>;
|
|
21
|
+
interface ResolvedOutput {
|
|
22
|
+
readonly address: StreamAddress.StreamAddress<unknown>;
|
|
23
|
+
readonly generation?: {
|
|
24
|
+
readonly shared: boolean;
|
|
25
|
+
} | undefined;
|
|
26
|
+
readonly service: {
|
|
27
|
+
readonly owner: object;
|
|
28
|
+
readonly wire: Reader<StreamsFault> & Writer<StreamsFault>;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
declare const TypeId$1 = "~@streamsy/projection/Commit";
|
|
13
32
|
interface Variance<in Result, in Provides, out Requires> {
|
|
14
33
|
readonly result: (_: Result) => void;
|
|
15
34
|
readonly provides: (_: Provides) => void;
|
|
16
35
|
readonly requires: () => Requires;
|
|
17
36
|
}
|
|
18
37
|
interface Commit<in Result, in Provides = never, out Requires = never> extends Pipeable.Pipeable {
|
|
19
|
-
readonly [TypeId]: Variance<Result, Provides, Requires>;
|
|
38
|
+
readonly [TypeId$1]: Variance<Result, Provides, Requires>;
|
|
20
39
|
readonly name: string;
|
|
21
40
|
readonly guarantee: "exactly-once" | "effectively-once" | "at-least-once";
|
|
22
41
|
readonly load: (key: ProjectionKey) => Effect.Effect<Loaded, ProjectionFault, Requires>;
|
|
23
42
|
readonly apply: (pending: Pending<Result, Provides>) => Effect.Effect<void, ProjectionFault | HandlerFailed, Requires>;
|
|
24
43
|
readonly remove?: (key: ProjectionKey) => Effect.Effect<void, ProjectionFault, Requires>;
|
|
44
|
+
/** Fence future checkpoint writes, then run cleanup even if the key was already retired. */
|
|
45
|
+
readonly retire?: (request: RetireRequest) => Effect.Effect<RetirementStatus, ProjectionFault, Requires>;
|
|
46
|
+
}
|
|
47
|
+
interface RetireRequest {
|
|
48
|
+
readonly key: ProjectionKey;
|
|
49
|
+
readonly cleanup: Effect.Effect<void, ProjectionFault>;
|
|
25
50
|
}
|
|
26
51
|
interface Pending<Result, Provides = never> {
|
|
27
52
|
readonly key: ProjectionKey;
|
|
@@ -29,6 +54,8 @@ interface Pending<Result, Provides = never> {
|
|
|
29
54
|
readonly loaded: Loaded;
|
|
30
55
|
readonly next: CheckpointRecord;
|
|
31
56
|
readonly run: Effect.Effect<Result, HandlerFailed, Provides>;
|
|
57
|
+
/** Resolved generation-bound outputs, including the accepted stream when wrapped. */
|
|
58
|
+
readonly generationOutputs?: ReadonlyMap<string, ResolvedOutput>;
|
|
32
59
|
}
|
|
33
60
|
declare const HandlerFailed_base: Schema.Class<HandlerFailed, Schema.TaggedStruct<"HandlerFailed", {
|
|
34
61
|
readonly error: Schema.Unknown;
|
|
@@ -61,9 +88,10 @@ declare const Folded: Data.TaggedEnum.ConstructorFrom<Folded<unknown>, "_tag">,
|
|
|
61
88
|
/** Custom Commits extend the input range on retry. Never store next when run fails;
|
|
62
89
|
* condition the write on loaded.token (checkpoint / token-conflict when it moved),
|
|
63
90
|
* and return token "0" for an absent record.
|
|
91
|
+
* Custom Commits do not support timer handlers in this release.
|
|
64
92
|
* load must return the stored state. If run and the write are not atomic,
|
|
65
93
|
* declare at-least-once. The guarantee must describe the actual write. */
|
|
66
|
-
declare const make: <Result, Provides = never, Requires = never>(options: Omit<Commit<Result, Provides, Requires>, typeof TypeId | "pipe">) => Commit<Result, Provides, Requires>;
|
|
94
|
+
declare const make: <Result, Provides = never, Requires = never>(options: Omit<Commit<Result, Provides, Requires>, typeof TypeId$1 | "pipe">) => Commit<Result, Provides, Requires>;
|
|
67
95
|
declare const checkpoint: Commit<Folded<unknown>, never, CheckpointStore>;
|
|
68
96
|
declare const Transaction_base: Context.ServiceClass<Transaction, "@streamsy/projection/Transaction", {
|
|
69
97
|
readonly owner: object;
|
|
@@ -78,24 +106,109 @@ export declare class Transaction extends Transaction_base {
|
|
|
78
106
|
*/
|
|
79
107
|
static readonly layer: Layer.Layer<Transaction, never, CommitBoundary | SqlClient.SqlClient>;
|
|
80
108
|
}
|
|
81
|
-
type Result$1 = void | Folded<unknown> | Emitted<OutputNames> | Accumulated<unknown, OutputNames>;
|
|
82
109
|
declare const transaction: Commit<Result$1, SqlClient.SqlClient, CheckpointStore | Transaction>;
|
|
110
|
+
/** Clean up binding state in the owner transaction on both forget and retire. */
|
|
111
|
+
declare const transactionWithCleanup: (cleanup: (key: ProjectionKey, sql: SqlClient.SqlClient) => Effect.Effect<void, ProjectionFault>) => {
|
|
112
|
+
pipe<A>(this: A): A;
|
|
113
|
+
pipe<A, B = never>(this: A, ab: (_: A) => B): B;
|
|
114
|
+
pipe<A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C;
|
|
115
|
+
pipe<A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D;
|
|
116
|
+
pipe<A, B = never, C = never, D = never, E = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E): E;
|
|
117
|
+
pipe<A, B = never, C = never, D = never, E = never, F = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F): F;
|
|
118
|
+
pipe<A, B = never, C = never, D = never, E = never, F = never, G = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G): G;
|
|
119
|
+
pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G, gh: (_: G) => H): H;
|
|
120
|
+
pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G, gh: (_: G) => H, hi: (_: H) => I): I;
|
|
121
|
+
pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G, gh: (_: G) => H, hi: (_: H) => I, ij: (_: I) => J): J;
|
|
122
|
+
pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never, K = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G, gh: (_: G) => H, hi: (_: H) => I, ij: (_: I) => J, jk: (_: J) => K): K;
|
|
123
|
+
pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never, K = never, L = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G, gh: (_: G) => H, hi: (_: H) => I, ij: (_: I) => J, jk: (_: J) => K, kl: (_: K) => L): L;
|
|
124
|
+
pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never, K = never, L = never, M = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G, gh: (_: G) => H, hi: (_: H) => I, ij: (_: I) => J, jk: (_: J) => K, kl: (_: K) => L, lm: (_: L) => M): M;
|
|
125
|
+
pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never, K = never, L = never, M = never, N = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G, gh: (_: G) => H, hi: (_: H) => I, ij: (_: I) => J, jk: (_: J) => K, kl: (_: K) => L, lm: (_: L) => M, mn: (_: M) => N): N;
|
|
126
|
+
pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never, K = never, L = never, M = never, N = never, O = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G, gh: (_: G) => H, hi: (_: H) => I, ij: (_: I) => J, jk: (_: J) => K, kl: (_: K) => L, lm: (_: L) => M, mn: (_: M) => N, no: (_: N) => O): O;
|
|
127
|
+
pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never, K = never, L = never, M = never, N = never, O = never, P = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G, gh: (_: G) => H, hi: (_: H) => I, ij: (_: I) => J, jk: (_: J) => K, kl: (_: K) => L, lm: (_: L) => M, mn: (_: M) => N, no: (_: N) => O, op: (_: O) => P): P;
|
|
128
|
+
pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never, K = never, L = never, M = never, N = never, O = never, P = never, Q = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G, gh: (_: G) => H, hi: (_: H) => I, ij: (_: I) => J, jk: (_: J) => K, kl: (_: K) => L, lm: (_: L) => M, mn: (_: M) => N, no: (_: N) => O, op: (_: O) => P, pq: (_: P) => Q): Q;
|
|
129
|
+
pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never, K = never, L = never, M = never, N = never, O = never, P = never, Q = never, R = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G, gh: (_: G) => H, hi: (_: H) => I, ij: (_: I) => J, jk: (_: J) => K, kl: (_: K) => L, lm: (_: L) => M, mn: (_: M) => N, no: (_: N) => O, op: (_: O) => P, pq: (_: P) => Q, qr: (_: Q) => R): R;
|
|
130
|
+
pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never, K = never, L = never, M = never, N = never, O = never, P = never, Q = never, R = never, S = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G, gh: (_: G) => H, hi: (_: H) => I, ij: (_: I) => J, jk: (_: J) => K, kl: (_: K) => L, lm: (_: L) => M, mn: (_: M) => N, no: (_: N) => O, op: (_: O) => P, pq: (_: P) => Q, qr: (_: Q) => R, rs: (_: R) => S): S;
|
|
131
|
+
pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never, K = never, L = never, M = never, N = never, O = never, P = never, Q = never, R = never, S = never, T = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G, gh: (_: G) => H, hi: (_: H) => I, ij: (_: I) => J, jk: (_: J) => K, kl: (_: K) => L, lm: (_: L) => M, mn: (_: M) => N, no: (_: N) => O, op: (_: O) => P, pq: (_: P) => Q, qr: (_: Q) => R, rs: (_: R) => S, st: (_: S) => T): T;
|
|
132
|
+
pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never, K = never, L = never, M = never, N = never, O = never, P = never, Q = never, R = never, S = never, T = never, U = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G, gh: (_: G) => H, hi: (_: H) => I, ij: (_: I) => J, jk: (_: J) => K, kl: (_: K) => L, lm: (_: L) => M, mn: (_: M) => N, no: (_: N) => O, op: (_: O) => P, pq: (_: P) => Q, qr: (_: Q) => R, rs: (_: R) => S, st: (_: S) => T, tu: (_: T) => U): U;
|
|
133
|
+
pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never, K = never, L = never, M = never, N = never, O = never, P = never, Q = never, R = never, S = never, T = never, U = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E, ef: (_: E) => F, fg: (_: F) => G, gh: (_: G) => H, hi: (_: H) => I, ij: (_: I) => J, jk: (_: J) => K, kl: (_: K) => L, lm: (_: L) => M, mn: (_: M) => N, no: (_: N) => O, op: (_: O) => P, pq: (_: P) => Q, qr: (_: Q) => R, rs: (_: R) => S, st: (_: S) => T, tu: (_: T) => U): U;
|
|
134
|
+
"~@streamsy/projection/Commit": Variance<Result$1, SqlClient.SqlClient, CheckpointStore | Transaction>;
|
|
135
|
+
name: string;
|
|
136
|
+
guarantee: "exactly-once" | "effectively-once" | "at-least-once";
|
|
137
|
+
load: (key: ProjectionKey) => Effect.Effect<Loaded, ProjectionFault, CheckpointStore | Transaction>;
|
|
138
|
+
apply: (pending: Pending<Result$1, SqlClient.SqlClient>) => Effect.Effect<void, HandlerFailed | ProjectionFault, CheckpointStore | Transaction>;
|
|
139
|
+
remove: (key: ProjectionKey) => Effect.Effect<void, ProjectionFault, CheckpointStore | Transaction>;
|
|
140
|
+
retire: (request: RetireRequest) => Effect.Effect<RetirementStatus, ProjectionFault, CheckpointStore | Transaction>;
|
|
141
|
+
};
|
|
83
142
|
declare const producer: Commit<Accumulated<unknown, Readonly<Record<string, never>>> | Emitted<Readonly<Record<string, never>>>, never, CheckpointStore>;
|
|
84
|
-
declare const atLeastOnce: Commit<void, never, CheckpointStore>;
|
|
143
|
+
declare const atLeastOnce: Commit<void | WakeAt, never, CheckpointStore>;
|
|
85
144
|
declare const withCompensation: {
|
|
86
145
|
<Result, R>(f: (result: Result, cause: Cause.Cause<ProjectionFault | HandlerFailed>, unit: Unit) => Effect.Effect<void, never, R>): <P, Q>(self: Commit<Result, P, Q>) => Commit<Result, P, Q | R>;
|
|
87
146
|
<Result, P, Q, R>(self: Commit<Result, P, Q>, f: (result: Result, cause: Cause.Cause<ProjectionFault | HandlerFailed>, unit: Unit) => Effect.Effect<void, never, R>): Commit<Result, P, Q | R>;
|
|
88
147
|
};
|
|
89
148
|
declare namespace commit_d_exports {
|
|
90
|
-
export { Accumulated, Commit, Emitted, Folded, HandlerFailed, OutputBatch, Pending, TypeId, Variance, atLeastOnce, checkpoint, make, producer, transaction, withCompensation };
|
|
149
|
+
export { Accumulated, Commit, Emitted, Folded, HandlerFailed, OutputBatch, Pending, RetireRequest, TypeId$1 as TypeId, Variance, atLeastOnce, checkpoint, make, producer, transaction, transactionWithCleanup, withCompensation };
|
|
150
|
+
}
|
|
151
|
+
declare const TypeId: unique symbol;
|
|
152
|
+
interface PerGeneration<D extends StreamDeclaration, N extends string, By extends string = never> {
|
|
153
|
+
readonly [TypeId]: {
|
|
154
|
+
readonly route: D;
|
|
155
|
+
readonly param: N;
|
|
156
|
+
readonly shared: boolean;
|
|
157
|
+
readonly routeBy?: readonly By[];
|
|
158
|
+
};
|
|
91
159
|
}
|
|
92
|
-
type
|
|
160
|
+
type RoutedOutput = Input | PerGeneration<StreamDeclaration, string, string>;
|
|
161
|
+
type DeclaredParams<D> = D extends StreamRoute.StreamRoute<infer P, infer _A, infer _RD, infer _RE> ? P : {};
|
|
162
|
+
type NumberParams<D, P = DeclaredParams<D>> = { readonly [N in keyof P]-?: unknown extends P[N] ? never : [P[N], number] extends [number, P[N]] ? N : never; }[keyof P] & string;
|
|
163
|
+
/** Bind one numeric output route parameter to the projection's generation. */
|
|
164
|
+
declare function perGeneration<D extends StreamDeclaration, const N extends NumberParams<D>, const By extends Exclude<keyof DeclaredParams<D> & string, N>>(route: D, param: N, options: {
|
|
165
|
+
readonly routeBy: readonly [By, ...By[]];
|
|
166
|
+
readonly shared?: false;
|
|
167
|
+
}): PerGeneration<D, N, By>;
|
|
168
|
+
declare function perGeneration<D extends StreamDeclaration, const N extends NumberParams<D>>(route: D, param: N, options?: {
|
|
169
|
+
readonly shared?: boolean;
|
|
170
|
+
readonly routeBy?: never;
|
|
171
|
+
}): PerGeneration<D, N>;
|
|
172
|
+
declare const isPerGeneration: (value: RoutedOutput) => value is PerGeneration<StreamDeclaration, string, string>;
|
|
173
|
+
declare const generationBinding: <D extends StreamDeclaration, N extends string, By extends string = never>(binding: PerGeneration<D, N, By>) => {
|
|
174
|
+
readonly route: D;
|
|
175
|
+
readonly param: N;
|
|
176
|
+
readonly shared: boolean;
|
|
177
|
+
readonly routeBy?: readonly By[] | undefined;
|
|
178
|
+
};
|
|
179
|
+
/** Private metadata on the bound value. */
|
|
180
|
+
declare const GenerationOutputs: unique symbol;
|
|
181
|
+
interface GenerationOutputBindings {
|
|
182
|
+
readonly [GenerationOutputs]?: ReadonlyMap<string, {
|
|
183
|
+
readonly shared: boolean;
|
|
184
|
+
}>;
|
|
185
|
+
}
|
|
186
|
+
/** Open one generation-owned stream in the current process transaction. */
|
|
187
|
+
interface RoutedHandle<A, Params, R> {
|
|
188
|
+
readonly open: (params: Params) => Effect.Effect<A, ProjectionFault, R>;
|
|
189
|
+
}
|
|
190
|
+
declare const RoutedOutputs: unique symbol;
|
|
191
|
+
interface RoutedDefinition<R> {
|
|
192
|
+
readonly matches: (streamId: string) => boolean;
|
|
193
|
+
readonly restore: (streamId: string) => Streamsy.Address<unknown, R> | undefined;
|
|
194
|
+
}
|
|
195
|
+
interface RoutedOutputBindings<R> {
|
|
196
|
+
readonly [RoutedOutputs]?: ReadonlyMap<string, RoutedDefinition<R>>;
|
|
197
|
+
}
|
|
198
|
+
type RoutedMap = Readonly<Record<string, RoutedOutput>>;
|
|
199
|
+
type StaticOutputMap = Readonly<Record<string, Input | PerGeneration<StreamDeclaration, string>>>;
|
|
93
200
|
type Item<T> = AddressOf<T> extends {
|
|
94
201
|
readonly collections: infer C extends StreamAddress.Collections;
|
|
95
202
|
} ? DurableState.Entry<C> : AddressOf<T> extends {
|
|
96
203
|
readonly codec: Schema.Codec<infer A, any, any, any>;
|
|
97
204
|
} ? A : never;
|
|
98
205
|
type Services<O extends RoutedMap> = { [K in keyof O]: AddressOf<O[K]> extends Streamsy.Address<any, infer R> ? R : never; }[keyof O];
|
|
206
|
+
interface BoundOutputs<R> extends GenerationOutputBindings, RoutedOutputBindings<R> {
|
|
207
|
+
readonly streams?: Readonly<Record<string, Streamsy.Address<unknown, R>>>;
|
|
208
|
+
readonly accepted?: Streamsy.Address<Streamsy.WakeEvent, R>;
|
|
209
|
+
}
|
|
210
|
+
/** Create the generation-bound outputs of one binding, using each output's owner. */
|
|
211
|
+
declare const createOutputs: <R>(bound: BoundOutputs<R>) => Effect.Effect<void, ProjectionFault, R>;
|
|
99
212
|
type StateSchema<A, I = unknown> = Schema.Codec<A, I>;
|
|
100
213
|
/** A value, or a function of the decoded params the projection was bound with. */
|
|
101
214
|
type Initial<A, P = Record<string, string>> = A | ((params: P) => A);
|
|
@@ -110,13 +223,198 @@ interface BoundState<A> {
|
|
|
110
223
|
readonly initial: () => A;
|
|
111
224
|
}
|
|
112
225
|
/** Common bound declaration consumed by the kernel. */
|
|
113
|
-
interface Executable<I extends InputMap, E, R, Q, Result, P = never, S = unknown, OR = never> extends Identity {
|
|
226
|
+
interface Executable<I extends InputMap, E, R, Q, Result, P = never, S = unknown, OR = never> extends Identity, GenerationOutputBindings {
|
|
114
227
|
readonly inputs: I;
|
|
115
228
|
readonly state?: BoundState<S>;
|
|
116
229
|
readonly streams?: Readonly<Record<string, Streamsy.Address<unknown, OR>>>;
|
|
230
|
+
readonly accepted?: Streamsy.Address<Streamsy.WakeEvent, OR>;
|
|
117
231
|
readonly commit: Commit<Result, P, Q>;
|
|
118
232
|
readonly prepare?: (batch: Slices<I>, unit: Unit) => Effect.Effect<unknown, E, Q>;
|
|
119
|
-
readonly process: (batch: Slices<I>, unit: Unit, encoded?: string, prepared?: unknown) => Effect.Effect<Result, E, R | P>;
|
|
233
|
+
readonly process: (batch: Slices<I>, unit: Unit, encoded?: string, prepared?: unknown, attempt?: number) => Effect.Effect<Result, E, R | P>;
|
|
234
|
+
}
|
|
235
|
+
/** The accepted offset of each input, keyed by input name. The next pass reads after these. */
|
|
236
|
+
type Offsets<Inputs extends InputMap> = { readonly [K in keyof Inputs]: string; };
|
|
237
|
+
/** The state and the offsets it is at. `state` is `undefined` when the declaration has no `state:`. */
|
|
238
|
+
interface Snapshot<S, Inputs extends InputMap> {
|
|
239
|
+
readonly state: S;
|
|
240
|
+
readonly offsets: Offsets<Inputs>;
|
|
241
|
+
}
|
|
242
|
+
type StateValue<S> = [S] extends [never] ? undefined : S;
|
|
243
|
+
/** Internal: what `read` needs from a bound projection. */
|
|
244
|
+
type Readable<Inputs extends InputMap, S, Q> = Identity & {
|
|
245
|
+
readonly inputs: Inputs;
|
|
246
|
+
readonly state?: BoundState<S>;
|
|
247
|
+
readonly commit: Pick<Commit<never, never, Q>, "load">;
|
|
248
|
+
};
|
|
249
|
+
/**
|
|
250
|
+
* Reads the state and offsets from one checkpoint record, so the state
|
|
251
|
+
* always matches the offsets. Before the first unit, the state is the declared initial
|
|
252
|
+
* value and every offset is the start of its input.
|
|
253
|
+
*/
|
|
254
|
+
declare const read: <Inputs extends InputMap, S = never, Q = never>(projection: Readable<Inputs, S, Q>) => Effect.Effect<Snapshot<StateValue<S>, Inputs>, ProjectionFault, Q>;
|
|
255
|
+
/** The part of a projection declaration that the attach runner reads. */
|
|
256
|
+
interface Attachable<B, HE = never, HR = never, Params = DecodedParams> {
|
|
257
|
+
readonly retry?: {
|
|
258
|
+
readonly schedule?: Schedule.Schedule<unknown>;
|
|
259
|
+
readonly maxAttempts?: number;
|
|
260
|
+
onExhausted?(this: void, unit: Unit<unknown>, failure: RunnerFailure): Effect.Effect<void, HE, HR>;
|
|
261
|
+
} | undefined;
|
|
262
|
+
readonly id: string;
|
|
263
|
+
readonly version: number;
|
|
264
|
+
readonly generation: number;
|
|
265
|
+
readonly params: StreamRoute.ParamCodecs;
|
|
266
|
+
readonly inputs: Inputs;
|
|
267
|
+
at(params: Params): B;
|
|
268
|
+
}
|
|
269
|
+
/** The result of one `pass`: one committed unit (`progress`), or no input or wake to commit. */
|
|
270
|
+
interface PassResult<Inputs extends InputMap = InputMap> {
|
|
271
|
+
readonly status: "progress" | "caught-up" | "source-closed";
|
|
272
|
+
readonly units: number;
|
|
273
|
+
readonly items: number;
|
|
274
|
+
readonly offsets: Offsets<Inputs>;
|
|
275
|
+
}
|
|
276
|
+
/** One runner cycle: the committed state and offsets, plus the work that the cycle did. */
|
|
277
|
+
interface Progress<S, Inputs extends InputMap = InputMap> extends Snapshot<S, Inputs> {
|
|
278
|
+
readonly status: "caught-up" | "limit-reached" | "source-closed";
|
|
279
|
+
/** Next recorded process wake, in epoch milliseconds. */
|
|
280
|
+
readonly wakeAt: Option.Option<number>;
|
|
281
|
+
/** Units that this cycle committed. */
|
|
282
|
+
readonly units: number;
|
|
283
|
+
/** Input items in those units. */
|
|
284
|
+
readonly items: number;
|
|
285
|
+
}
|
|
286
|
+
/** Restore and adapt one input unit; the Commit owns every write. */
|
|
287
|
+
declare const pass: <Inputs extends InputMap, E, R, Q, Result, P, OR = never>(projection: Executable<Inputs, E, R, Q, Result, P, unknown, OR>) => Effect.Effect<PassResult<Inputs>, E | ProjectionFault, Exclude<R, P> | Q | OR | InputServices<Inputs>>;
|
|
288
|
+
/**
|
|
289
|
+
* Repeats pass until caught up, closed, or limited, then decodes the state of the last
|
|
290
|
+
* pass once. Recorded wakes run when due; this call does not wait for a future wake.
|
|
291
|
+
* At most one due unit without input runs per cycle. After a gone input, the result holds the state that the final unit
|
|
292
|
+
* committed, although the kernel then deletes the record. Use one writer per key.
|
|
293
|
+
*/
|
|
294
|
+
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>>;
|
|
295
|
+
/** Only identity and encoded params are needed; execution uses the runner's binding. */
|
|
296
|
+
type Binding = Pick<Identity, "id" | "params">;
|
|
297
|
+
type Declaration$2 = Omit<Attachable<Binding>, "retry">;
|
|
298
|
+
/** Last failure of a binding, trigger stream or runner pass. */
|
|
299
|
+
interface RunnerFailure {
|
|
300
|
+
readonly at: number;
|
|
301
|
+
readonly retryable: boolean;
|
|
302
|
+
readonly reason: Option.Option<ProjectionFault["reason"]>;
|
|
303
|
+
readonly message: string;
|
|
304
|
+
}
|
|
305
|
+
/** Live binding observations with the binding's encoded params. */
|
|
306
|
+
export type RunnerEvent = Data.TaggedEnum<{
|
|
307
|
+
Ran: {
|
|
308
|
+
readonly projection: string;
|
|
309
|
+
readonly params: Readonly<Record<string, string>>;
|
|
310
|
+
readonly status: Progress<unknown>["status"];
|
|
311
|
+
readonly units: number;
|
|
312
|
+
readonly offsets: Readonly<Record<string, string>>;
|
|
313
|
+
/** Next recorded process wake after this run. */
|
|
314
|
+
readonly wakeAt: Option.Option<number>;
|
|
315
|
+
};
|
|
316
|
+
Failed: {
|
|
317
|
+
readonly projection: string;
|
|
318
|
+
readonly params: Readonly<Record<string, string>>;
|
|
319
|
+
readonly attempts: number;
|
|
320
|
+
/** Binding backoff deadline; None while stopped. */
|
|
321
|
+
readonly dueAt: Option.Option<number>;
|
|
322
|
+
readonly failure: RunnerFailure;
|
|
323
|
+
readonly stopped: boolean;
|
|
324
|
+
};
|
|
325
|
+
Dropped: {
|
|
326
|
+
readonly projection: string;
|
|
327
|
+
readonly params: Readonly<Record<string, string>>;
|
|
328
|
+
};
|
|
329
|
+
}>;
|
|
330
|
+
export declare const RunnerEvent: Data.TaggedEnum.Constructor<{
|
|
331
|
+
readonly _tag: "Dropped";
|
|
332
|
+
readonly projection: string;
|
|
333
|
+
readonly params: Readonly<Record<string, string>>;
|
|
334
|
+
} | {
|
|
335
|
+
readonly _tag: "Failed";
|
|
336
|
+
readonly projection: string;
|
|
337
|
+
readonly params: Readonly<Record<string, string>>;
|
|
338
|
+
readonly attempts: number;
|
|
339
|
+
readonly dueAt: Option.Option<number>;
|
|
340
|
+
readonly failure: RunnerFailure;
|
|
341
|
+
readonly stopped: boolean;
|
|
342
|
+
} | {
|
|
343
|
+
readonly _tag: "Ran";
|
|
344
|
+
readonly projection: string;
|
|
345
|
+
readonly params: Readonly<Record<string, string>>;
|
|
346
|
+
readonly status: Progress<unknown>["status"];
|
|
347
|
+
readonly units: number;
|
|
348
|
+
readonly offsets: Readonly<Record<string, string>>;
|
|
349
|
+
readonly wakeAt: Option.Option<number>;
|
|
350
|
+
}>;
|
|
351
|
+
/** One live, attached runner. Process fields reset when the host restarts. */
|
|
352
|
+
interface RunnerStatus {
|
|
353
|
+
readonly projection: string;
|
|
354
|
+
readonly state: "running" | "retrying" | "failed";
|
|
355
|
+
/** Consecutive failed passes, rather than failed bindings. */
|
|
356
|
+
readonly failures: number;
|
|
357
|
+
/** Set while waiting for an automatic or explicitly requested pass retry. */
|
|
358
|
+
readonly retryAt: Option.Option<number>;
|
|
359
|
+
readonly active: number;
|
|
360
|
+
readonly queued: number;
|
|
361
|
+
readonly lastPassAt: Option.Option<number>;
|
|
362
|
+
/** Binding marks in either durability mode. The five counts are disjoint. */
|
|
363
|
+
readonly marks: ProjectionMarkSummary;
|
|
364
|
+
/** Last pass failure, cleared by a successful drain. */
|
|
365
|
+
readonly failure: Option.Option<RunnerFailure>;
|
|
366
|
+
readonly stopped: number;
|
|
367
|
+
readonly triggers: ReadonlyArray<{
|
|
368
|
+
readonly stream: string;
|
|
369
|
+
readonly failure: Option.Option<RunnerFailure>;
|
|
370
|
+
}>;
|
|
371
|
+
}
|
|
372
|
+
interface RegistryApi {
|
|
373
|
+
readonly status: Effect.Effect<ReadonlyArray<RunnerStatus>, StorageFault>;
|
|
374
|
+
/** Full snapshots after subscription and changes; failed reads are logged and skipped. */
|
|
375
|
+
readonly changes: Stream.Stream<ReadonlyArray<RunnerStatus>>;
|
|
376
|
+
/** Future events only. Unbounded buffering keeps slow consumers off the runner's path. */
|
|
377
|
+
readonly events: Stream.Stream<RunnerEvent>;
|
|
378
|
+
/**
|
|
379
|
+
* Queue bindings of one projection now, overriding backoff and stops, with one wake.
|
|
380
|
+
* All params are validated before writing; invalid params fail with InvalidBinding.
|
|
381
|
+
* Duplicates coalesce. Empty arrays do nothing;
|
|
382
|
+
* mixed projection ids die with RangeError. A later storage fault can leave earlier
|
|
383
|
+
* chunks marked; repeating the request is safe. Returns before processing finishes.
|
|
384
|
+
*/
|
|
385
|
+
readonly schedule: (binding: Binding | ReadonlyArray<Binding>) => Effect.Effect<void, InvalidBinding | NotAttached | StorageFault>;
|
|
386
|
+
/** Reset one trigger cursor in storage to the start, clear its stop, and wake the runner.
|
|
387
|
+
* Use after a fold fix. The cursor survives restart in both durability modes.
|
|
388
|
+
* An unknown trigger stream dies with RangeError. First attach already reads from the start.
|
|
389
|
+
*/
|
|
390
|
+
readonly rescan: (target: string | Declaration$2, trigger: WakeOutput<{}> | string) => Effect.Effect<void, NotAttached | StorageFault>;
|
|
391
|
+
/**
|
|
392
|
+
* Wait for the attached identity's checkpoint, subscribing before the first read.
|
|
393
|
+
* Matching failed runs prompt a reread for committed progress. No timeout.
|
|
394
|
+
*/
|
|
395
|
+
readonly awaitOffset: <Inputs extends InputMap, S = never, Q = never>(binding: Readable<Inputs, S, Q>, input: keyof Inputs & string, offset: string) => Effect.Effect<void, NotAttached | ProjectionFault, Q>;
|
|
396
|
+
/** Stored failed bindings, stopped first, then by deadline. Default limit 100, maximum 1,000. */
|
|
397
|
+
readonly failed: (target: string | Declaration$2 | Binding, options?: {
|
|
398
|
+
readonly limit?: number;
|
|
399
|
+
}) => Effect.Effect<ReadonlyArray<{
|
|
400
|
+
readonly params: Readonly<Record<string, string>>;
|
|
401
|
+
readonly attempts: number;
|
|
402
|
+
readonly dueAt: Option.Option<number>;
|
|
403
|
+
readonly stopped: boolean;
|
|
404
|
+
/** Stopped and the binding retry budget or schedule has ended. */
|
|
405
|
+
readonly exhausted: boolean;
|
|
406
|
+
readonly failure: Option.Option<MarkFailure>;
|
|
407
|
+
}>, NotAttached | StorageFault>;
|
|
408
|
+
/** Make failed and stopped work due now; a projection target also resumes its triggers. Returns the number of failed bindings selected. */
|
|
409
|
+
readonly retry: (target: string | Declaration$2 | Binding) => Effect.Effect<number, NotAttached | StorageFault>;
|
|
410
|
+
}
|
|
411
|
+
declare const Registry_base: Context.ServiceClass<Registry, "@streamsy/projection/Registry", RegistryApi>;
|
|
412
|
+
/** Optional in-process view of Projection.attach runners. */
|
|
413
|
+
declare class Registry extends Registry_base {
|
|
414
|
+
/** Match a binding's projection id and encoded params, independent of key order. */
|
|
415
|
+
static readonly isFor: (binding: Binding) => (event: RunnerEvent) => boolean;
|
|
416
|
+
/** Provide below the attach layers so they see this same registry. */
|
|
417
|
+
static readonly layer: Layer.Layer<Registry>;
|
|
120
418
|
}
|
|
121
419
|
/** A stream declaration. `.at(params)` resolves it with the projection params. */
|
|
122
420
|
type StreamDeclaration = StreamRoute.StreamRoute<any, any> & Streamsy.Any & {
|
|
@@ -125,17 +423,21 @@ type StreamDeclaration = StreamRoute.StreamRoute<any, any> & Streamsy.Any & {
|
|
|
125
423
|
/** A stream declaration, or a fixed address that `.at` does not rebind. */
|
|
126
424
|
type Input = StreamDeclaration | Streamsy.Address<any, any>;
|
|
127
425
|
type Inputs = Readonly<Record<string, Input>>;
|
|
128
|
-
type AddressOf<X> = X extends StreamDeclaration ? ReturnType<X["at"]> : X extends Streamsy.Address<any, any> ? X : never;
|
|
129
|
-
type Addresses<I extends
|
|
130
|
-
type
|
|
426
|
+
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;
|
|
427
|
+
type Addresses<I extends RoutedMap> = { readonly [K in keyof I]: AddressOf<I[K]>; };
|
|
428
|
+
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>;
|
|
429
|
+
type HandlerOutputs<O extends RoutedMap> = { readonly [K in keyof O]: HandlerOutput<O[K]>; };
|
|
131
430
|
type Invalid<C extends StreamRoute.ParamCodecs, P> = { readonly [Name in keyof P]: Name extends keyof StreamRoute.Params<C> ? P[Name] extends StreamRoute.Params<C>[Name] ? StreamRoute.Params<C>[Name] extends P[Name] ? never : Name : Name : Name; }[keyof P];
|
|
132
431
|
type InvalidInput<C extends StreamRoute.ParamCodecs, X> = X extends StreamDeclaration ? Invalid<C, DeclaredParams<X>> : never;
|
|
133
432
|
/** Every declaration's params must be projection params with the same type. */
|
|
134
433
|
type Within<C extends StreamRoute.ParamCodecs, I extends Inputs> = { readonly [K in keyof I]: InvalidInput<C, I[K]> extends never ? I[K] : never; };
|
|
135
434
|
type OneWithin<C extends StreamRoute.ParamCodecs, X> = InvalidInput<C, X> extends never ? X : never;
|
|
136
|
-
type
|
|
435
|
+
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>;
|
|
436
|
+
type OneOutputWithin<C extends StreamRoute.ParamCodecs, X> = InvalidOutput<C, X> extends never ? X : never;
|
|
437
|
+
type OutputsWithin<C extends StreamRoute.ParamCodecs, D extends RoutedMap> = { readonly [K in keyof D]: OneOutputWithin<C, D[K]>; };
|
|
137
438
|
/** Inert: `at` binds the params and returns the value runners take. */
|
|
138
|
-
interface Declaration<Codecs extends StreamRoute.ParamCodecs, Bound> {
|
|
439
|
+
interface Declaration<Codecs extends StreamRoute.ParamCodecs, Bound, HE = never, HR = never> {
|
|
440
|
+
readonly retry?: BindingRetry<StreamRoute.Params<Codecs>, HE, HR> | undefined;
|
|
139
441
|
readonly id: string;
|
|
140
442
|
readonly version: number;
|
|
141
443
|
readonly generation: number;
|
|
@@ -147,125 +449,153 @@ interface Declaration<Codecs extends StreamRoute.ParamCodecs, Bound> {
|
|
|
147
449
|
/** Tries declaration inputs in order. Shared inputs return only their declared subset. */
|
|
148
450
|
readonly parse: (id: string) => Option.Option<Partial<StreamRoute.Params<Codecs>>>;
|
|
149
451
|
}
|
|
150
|
-
|
|
452
|
+
type AcceptedServices<W> = W extends AcceptedOutput ? Services<{
|
|
453
|
+
accepted: W;
|
|
454
|
+
}> : never;
|
|
455
|
+
type AcceptedResult<Result, W> = W extends AcceptedOutput ? Result extends Folded<infer A> ? Accumulated<A, {}> : Result extends WakeAt ? Emitted<{}> & Pick<WakeAt, "wakeAt"> : Emitted<{}> : Result;
|
|
456
|
+
/** Binding retry timing and budget, shared by both attach hosts. */
|
|
457
|
+
interface BindingRetry<Params, E = never, R = never> {
|
|
458
|
+
/**
|
|
459
|
+
* Timing only: defaults to 1 s doubling to 1 hour. A fresh schedule replays the
|
|
460
|
+
* failure count; input- or elapsed-time-dependent schedules are unsupported.
|
|
461
|
+
* A schedule that ends exhausts the binding.
|
|
462
|
+
*/
|
|
463
|
+
readonly schedule?: Schedule.Schedule<unknown>;
|
|
464
|
+
/** Failed runs before stopping. Default: unlimited. */
|
|
465
|
+
readonly maxAttempts?: number;
|
|
466
|
+
/**
|
|
467
|
+
* Runs at least once before exhaustion stops the binding; dedupe with unit.key.
|
|
468
|
+
* Skipped and logged when no unit formed. Hook failures are logged and the binding
|
|
469
|
+
* stops anyway. Non-retryable faults stop without calling the hook.
|
|
470
|
+
*/
|
|
471
|
+
readonly onExhausted?: (unit: Unit<Params>, failure: RunnerFailure) => Effect.Effect<void, E, R>;
|
|
472
|
+
}
|
|
473
|
+
interface Common<C extends StreamRoute.ParamCodecs, I extends Inputs, W = undefined, HE = never, HR = never> {
|
|
474
|
+
readonly retry?: BindingRetry<StreamRoute.Params<C>, HE, HR>;
|
|
151
475
|
readonly id: string;
|
|
152
476
|
readonly version?: number;
|
|
153
477
|
readonly generation?: number;
|
|
154
478
|
readonly params: C;
|
|
155
479
|
readonly inputs: I & Within<C, I>;
|
|
480
|
+
/** Publish accepted input offsets in this wake stream as part of each unit. */
|
|
481
|
+
readonly accepted?: W & OneOutputWithin<C, W>;
|
|
156
482
|
}
|
|
483
|
+
/** Decoded params, keyed by name. */
|
|
484
|
+
type DecodedParams = Readonly<Record<string, unknown>>;
|
|
157
485
|
interface Committing<Result, P, Q> {
|
|
158
486
|
readonly commit: Commit<Result, P, Q>;
|
|
159
487
|
}
|
|
160
|
-
type RunningDeclaration<C extends StreamRoute.ParamCodecs, I extends Inputs, E, R, Result, P, Q, S = never, OR = never> = Declaration<C, Omit<Executable<Addresses<I>, E | ProjectionFault, R, Q, Result, P, S, OR>, "process" | "prepare" | "state"> & {
|
|
488
|
+
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"> & {
|
|
161
489
|
readonly state: [S] extends [never] ? undefined : BoundState<S>;
|
|
162
490
|
readonly process: (batch: Slices<Addresses<I>>, unit: Unit, encoded?: string) => Effect.Effect<Result, E | ProjectionFault, R>;
|
|
163
|
-
}>;
|
|
164
|
-
type StatefulDeclaration<C extends StreamRoute.ParamCodecs, I extends Inputs, A, E, R, Result, P, Q> = RunningDeclaration<C, I, E, R, Result, P, Q, A>;
|
|
165
|
-
type OutputDeclaration<C extends StreamRoute.ParamCodecs, I extends Inputs, O extends RoutedMap, E, R, Result, P, Q, A = never> = Omit<RunningDeclaration<C, I, E, R, Result, P, Q, A, Services<O
|
|
166
|
-
readonly at: (params: StreamRoute.Params<C>) => ReturnType<RunningDeclaration<C, I, E, R, Result, P, Q, A, Services<O
|
|
167
|
-
readonly streams: Readonly<Record<string, Streamsy.Address<unknown, Services<O
|
|
491
|
+
}, HE, HR>;
|
|
492
|
+
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>;
|
|
493
|
+
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"> & {
|
|
494
|
+
readonly at: (params: StreamRoute.Params<C>) => ReturnType<RunningDeclaration<C, I, E, R, Result, P, Q, A, Services<O> | OR, HE, HR>["at"]> & {
|
|
495
|
+
readonly streams: Readonly<Record<string, Streamsy.Address<unknown, Services<O> | OR>>>;
|
|
168
496
|
};
|
|
169
497
|
};
|
|
170
|
-
type AccumulatingDeclaration<C extends StreamRoute.ParamCodecs, I extends Inputs, O extends RoutedMap, A, E, R, P, Q> = OutputDeclaration<C, I, O, E, R, Accumulated<A, O>, P, Q, A>;
|
|
498
|
+
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>;
|
|
499
|
+
/** A Streamsy.wake class. Use WakeOutput<{}> for a fixed-address trigger with no params. */
|
|
500
|
+
type WakeOutput<P = any> = StreamDeclaration & StreamRoute.StateRoute<P, Streamsy.WakeCollections> & {
|
|
501
|
+
readonly paramCodecs: StreamRoute.ParamCodecs;
|
|
502
|
+
};
|
|
503
|
+
interface WakeDefinition<C extends StreamRoute.ParamCodecs, I extends Input, O, W = undefined> {
|
|
504
|
+
readonly accepted?: W & OneOutputWithin<C, W>;
|
|
505
|
+
readonly id: string;
|
|
506
|
+
readonly version?: number;
|
|
507
|
+
readonly generation?: number;
|
|
508
|
+
readonly params: C;
|
|
509
|
+
/** The one source stream. Its params must be projection params. */
|
|
510
|
+
readonly input: I & OneWithin<C, I>;
|
|
511
|
+
/** The State declaration with wake collections that gets the row. Its params must be projection params. */
|
|
512
|
+
readonly output: O & OneWithin<C, O>;
|
|
513
|
+
}
|
|
514
|
+
type WakeDeclaration<C extends StreamRoute.ParamCodecs, I extends Input, O extends Input, W = undefined> = AccumulatingDeclaration<C, {
|
|
515
|
+
readonly source: I;
|
|
516
|
+
}, {
|
|
517
|
+
readonly wake: O;
|
|
518
|
+
}, null, never, never, never, CheckpointStore, AcceptedServices<W>>;
|
|
519
|
+
/**
|
|
520
|
+
* A wake projection: one source stream gives one keyed row in one wake stream.
|
|
521
|
+
* Each unit appends one upsert `{ stream, offset, closed? }` with
|
|
522
|
+
* `Commit.producer`, so several source writes in one unit fold into one row,
|
|
523
|
+
* and a retry answers `Duplicate`. The producer creates a missing wake stream
|
|
524
|
+
* on its own owner. A wake stream on another owner must exist before the first
|
|
525
|
+
* append: its owner creates it at start. When the source is removed or
|
|
526
|
+
* expires, the binding appends a State delete for its row and forgets itself.
|
|
527
|
+
*
|
|
528
|
+
* ```ts
|
|
529
|
+
* const filesWake = Projection.wake({
|
|
530
|
+
* id: "files-wake",
|
|
531
|
+
* params: { user: UserKey, folderId: FolderKey },
|
|
532
|
+
* input: Files,
|
|
533
|
+
* output: UserWake,
|
|
534
|
+
* });
|
|
535
|
+
* ```
|
|
536
|
+
*/
|
|
537
|
+
declare function wake<C extends StreamRoute.ParamCodecs, const I extends Input, const O extends WakeOutput, W extends AcceptedOutput | undefined = undefined>(definition: WakeDefinition<C, I, O, W>): WakeDeclaration<C, I, O, W>;
|
|
538
|
+
type AcceptedOutput = WakeOutput | PerGeneration<WakeOutput, string>;
|
|
171
539
|
type Step<X, E = never, R = never> = X | Effect.Effect<X, E, R>;
|
|
172
540
|
/** Each output keeps its item type here; missing keys emit nothing. */
|
|
173
541
|
type Emits<O extends RoutedMap> = { readonly [K in keyof O]?: ReadonlyArray<Item<O[K]>>; };
|
|
174
542
|
/** Fold one entry at a time. The default Commit saves state and offsets in one write. */
|
|
175
|
-
declare function fold<C extends StreamRoute.ParamCodecs, I extends Inputs, A, SI, E = never, R = never, P = never, Q = CheckpointStore>(definition: Common<C, I> & {
|
|
543
|
+
declare function fold<C extends StreamRoute.ParamCodecs, I extends Inputs, A, SI, E = never, R = never, P = never, Q = CheckpointStore, W extends AcceptedOutput | undefined = undefined, HE = never, HR = never>(definition: Common<C, I, W, HE, HR> & ([W] extends [undefined] ? Partial<Committing<AcceptedResult<Folded<NoInfer<A>>, W>, P, Q>> : Committing<AcceptedResult<Folded<NoInfer<A>>, W>, P, Q>) & {
|
|
176
544
|
readonly state: StateDefinition<A, SI, StreamRoute.Params<C>>;
|
|
177
|
-
readonly commit?: Committing<Folded<NoInfer<A>>, P, Q>["commit"];
|
|
178
545
|
readonly fold: (state: NoInfer<A>, entry: Entry<Addresses<I>>, unit: Unit<StreamRoute.Params<C>>) => Step<A, E, R>;
|
|
179
|
-
}): StatefulDeclaration<C, I, A, E, R, Folded<A>, P, Q>;
|
|
546
|
+
}): StatefulDeclaration<C, I, A, E, R, Folded<A>, P, Q, AcceptedServices<W>, HE, HR>;
|
|
547
|
+
/** void unless the handler result can be a WakeAt. */
|
|
548
|
+
type TimerResult<A> = 0 extends 1 & A ? void : [Extract<A, WakeAt>] extends [never] ? void : void | WakeAt;
|
|
180
549
|
/** The third argument of `process`. */
|
|
181
550
|
interface ProcessContext<Prepared = void> {
|
|
182
551
|
readonly prepared: Prepared;
|
|
552
|
+
/** Binding run attempt, starting at 1. Always 1 under run and follow. */
|
|
553
|
+
readonly attempt: number;
|
|
183
554
|
}
|
|
184
|
-
/** The
|
|
555
|
+
/** The address or routed handle of each declared output. Open handles only inside `process`. */
|
|
185
556
|
interface OutputsContext<O extends RoutedMap> {
|
|
186
|
-
readonly outputs:
|
|
557
|
+
readonly outputs: HandlerOutputs<O>;
|
|
187
558
|
}
|
|
188
|
-
/** Run side effects once per unit
|
|
189
|
-
|
|
559
|
+
/** Run side effects once per unit, including recorded wakes. Return wakeAt(time) to
|
|
560
|
+
* replace the timer, or void to clear it. Timers require atLeastOnce or transaction.
|
|
561
|
+
* prepare runs at least once, outside the transaction. */
|
|
562
|
+
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 AcceptedOutput | undefined = undefined, HE = never, HR = never, A = void>(definition: Common<C, I, W, HE, HR> & Committing<AcceptedResult<TimerResult<A>, W>, P, Q> & {
|
|
190
563
|
readonly outputs?: never;
|
|
191
564
|
readonly prepare?: (batch: Slices<Addresses<I>>, unit: Unit<StreamRoute.Params<C>>) => Effect.Effect<Prepared, PE, PR>;
|
|
192
|
-
readonly process: (batch: Slices<Addresses<I>>, unit: Unit<StreamRoute.Params<C>>, context: ProcessContext<Prepared>) => Effect.Effect<
|
|
193
|
-
}): RunningDeclaration<C, I, E | PE, R,
|
|
194
|
-
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>(definition: Common<C, I> & Committing<
|
|
565
|
+
readonly process: (batch: Slices<Addresses<I>>, unit: Unit<StreamRoute.Params<C>>, context: ProcessContext<Prepared>) => Effect.Effect<A, E, R>;
|
|
566
|
+
}): RunningDeclaration<C, I, E | PE, R, TimerResult<A>, P, Q | PR, never, AcceptedServices<W>, HE, HR>;
|
|
567
|
+
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 AcceptedOutput | undefined = undefined, HE = never, HR = never, A = void>(definition: Common<C, I, W, HE, HR> & Committing<AcceptedResult<TimerResult<A>, W>, SqlClient.SqlClient, Q> & {
|
|
195
568
|
readonly outputs: O & OutputsWithin<C, O>;
|
|
196
569
|
readonly prepare?: (batch: Slices<Addresses<I>>, unit: Unit<StreamRoute.Params<C>>, context: OutputsContext<O>) => Effect.Effect<Prepared, PE, PR>;
|
|
197
|
-
readonly process: (batch: Slices<Addresses<I>>, unit: Unit<StreamRoute.Params<C>>, context: ProcessContext<Prepared> & OutputsContext<O>) => Effect.Effect<
|
|
198
|
-
}): OutputDeclaration<C, I, O, E | PE, R,
|
|
570
|
+
readonly process: (batch: Slices<Addresses<I>>, unit: Unit<StreamRoute.Params<C>>, context: ProcessContext<Prepared> & OutputsContext<O>) => Effect.Effect<A, E, R>;
|
|
571
|
+
}): OutputDeclaration<C, I, O, E | PE, R, TimerResult<A>, SqlClient.SqlClient, Q | PR, never, AcceptedServices<W>, HE, HR>;
|
|
199
572
|
/** Emit zero or more output items for each input entry, in entry order. */
|
|
200
|
-
declare function emit<C extends StreamRoute.ParamCodecs, I extends Inputs, const O extends
|
|
573
|
+
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 AcceptedOutput | undefined = undefined, HE = never, HR = never>(definition: Common<C, I, W, HE, HR> & Committing<Emitted<NoInfer<O>>, P, Q> & {
|
|
201
574
|
readonly outputs: O & OutputsWithin<C, O>;
|
|
202
575
|
readonly emit: ((entry: Entry<Addresses<I>>, unit: Unit<StreamRoute.Params<C>>) => Step<X, E, R>) & (Exclude<keyof X, keyof O> extends never ? unknown : {
|
|
203
576
|
readonly undeclaredOutput: Exclude<keyof X, keyof O>;
|
|
204
577
|
});
|
|
205
|
-
}): OutputDeclaration<C, I, O, E, R, Emitted<O>, P, Q>;
|
|
206
|
-
type Definition<C extends StreamRoute.ParamCodecs, I extends Inputs, O extends
|
|
578
|
+
}): OutputDeclaration<C, I, O, E, R, Emitted<O>, P, Q, never, AcceptedServices<W>, HE, HR>;
|
|
579
|
+
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> & {
|
|
207
580
|
readonly outputs: O & OutputsWithin<C, O>;
|
|
208
581
|
readonly state: StateDefinition<A, SI, StreamRoute.Params<C>>;
|
|
209
582
|
};
|
|
210
583
|
/** Thread the value and collect outputs, once per entry. */
|
|
211
|
-
declare function mapAccum<C extends StreamRoute.ParamCodecs, I extends Inputs, const O extends
|
|
584
|
+
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 AcceptedOutput | undefined = undefined, HE = never, HR = never>(definition: Definition<C, I, O, A, SI, P, Q, W, HE, HR> & {
|
|
212
585
|
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 : {
|
|
213
586
|
readonly undeclaredOutput: Exclude<keyof X, keyof O>;
|
|
214
587
|
});
|
|
215
|
-
}): AccumulatingDeclaration<C, I, O, A, E, R, P, Q>;
|
|
588
|
+
}): AccumulatingDeclaration<C, I, O, A, E, R, P, Q, AcceptedServices<W>, HE, HR>;
|
|
216
589
|
/** Compute the next value and outputs once for the whole unit batch. */
|
|
217
|
-
declare function mapAccumBatch<C extends StreamRoute.ParamCodecs, I extends Inputs, const O extends
|
|
590
|
+
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 AcceptedOutput | undefined = undefined, HE = never, HR = never>(definition: Definition<C, I, O, A, SI, P, Q, W, HE, HR> & {
|
|
218
591
|
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 : {
|
|
219
592
|
readonly undeclaredOutput: Exclude<keyof X, keyof O>;
|
|
220
593
|
});
|
|
221
|
-
}): AccumulatingDeclaration<C, I, O, A, E, R, P, Q>;
|
|
222
|
-
/** The accepted offset of each input, keyed by input name. The next pass reads after these. */
|
|
223
|
-
type Offsets<Inputs extends InputMap> = { readonly [K in keyof Inputs]: string; };
|
|
224
|
-
/** The state and the offsets it is at. `state` is `undefined` when the declaration has no `state:`. */
|
|
225
|
-
interface Snapshot<S, Inputs extends InputMap> {
|
|
226
|
-
readonly state: S;
|
|
227
|
-
readonly offsets: Offsets<Inputs>;
|
|
228
|
-
}
|
|
229
|
-
type StateValue<S> = [S] extends [never] ? undefined : S;
|
|
230
|
-
/** Internal: what `read` needs from a bound projection. */
|
|
231
|
-
type Readable<Inputs extends InputMap, S, Q> = Identity & {
|
|
232
|
-
readonly inputs: Inputs;
|
|
233
|
-
readonly state?: BoundState<S>;
|
|
234
|
-
readonly commit: Pick<Commit<never, never, Q>, "load">;
|
|
235
|
-
};
|
|
236
|
-
/**
|
|
237
|
-
* Reads the state and offsets from one checkpoint record, so the state
|
|
238
|
-
* always matches the offsets. Before the first unit, the state is the declared initial
|
|
239
|
-
* value and every offset is the start of its input.
|
|
240
|
-
*/
|
|
241
|
-
declare const read: <Inputs extends InputMap, S = never, Q = never>(projection: Readable<Inputs, S, Q>) => Effect.Effect<Snapshot<StateValue<S>, Inputs>, ProjectionFault, Q>;
|
|
242
|
-
/** The result of one `pass`: one committed unit (`progress`), or no input to commit. */
|
|
243
|
-
interface PassResult<Inputs extends InputMap = InputMap> {
|
|
244
|
-
readonly status: "progress" | "caught-up" | "source-closed";
|
|
245
|
-
readonly units: number;
|
|
246
|
-
readonly items: number;
|
|
247
|
-
readonly offsets: Offsets<Inputs>;
|
|
248
|
-
}
|
|
249
|
-
/** One runner cycle: the committed state and offsets, plus the work that the cycle did. */
|
|
250
|
-
interface Progress<S, Inputs extends InputMap = InputMap> extends Snapshot<S, Inputs> {
|
|
251
|
-
readonly status: "caught-up" | "limit-reached" | "source-closed";
|
|
252
|
-
/** Units that this cycle committed. */
|
|
253
|
-
readonly units: number;
|
|
254
|
-
/** Input items in those units. */
|
|
255
|
-
readonly items: number;
|
|
256
|
-
}
|
|
257
|
-
/** Restore and adapt one input unit; the Commit owns every write. */
|
|
258
|
-
declare const pass: <Inputs extends InputMap, E, R, Q, Result, P, OR = never>(projection: Executable<Inputs, E, R, Q, Result, P, unknown, OR>) => Effect.Effect<PassResult<Inputs>, E | ProjectionFault, Exclude<R, P> | Q | OR | InputServices<Inputs>>;
|
|
259
|
-
/**
|
|
260
|
-
* Repeats pass until caught up, closed, or limited, then decodes the state of the last
|
|
261
|
-
* pass once. After a gone input, the result holds the state that the final unit
|
|
262
|
-
* committed, although the kernel then deletes the record. Use one writer per key.
|
|
263
|
-
*/
|
|
264
|
-
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>>;
|
|
594
|
+
}): AccumulatingDeclaration<C, I, O, A, E, R, P, Q, AcceptedServices<W>, HE, HR>;
|
|
265
595
|
interface FollowOptions extends RunOptions {
|
|
266
596
|
/** Upper bound on one wake wait; default 30000. */
|
|
267
597
|
readonly repairIntervalMs?: number;
|
|
268
|
-
/** Override the forever, capped exponential retry for retryable
|
|
598
|
+
/** Override the forever, capped exponential retry for retryable projection faults. */
|
|
269
599
|
readonly retry?: Schedule.Schedule<unknown>;
|
|
270
600
|
}
|
|
271
601
|
/**
|
|
@@ -278,45 +608,60 @@ interface FollowOptions extends RunOptions {
|
|
|
278
608
|
* after each cycle that commits a unit or reaches `limit`, and after the last cycle
|
|
279
609
|
* when every input is closed or an input is gone; then it ends. After a gone input, the
|
|
280
610
|
* last element holds the state that the final unit committed, and the kernel then
|
|
281
|
-
* deletes the record. A
|
|
611
|
+
* deletes the record. A cycle that finds no input or due timer emits nothing.
|
|
612
|
+
* Recorded timers run on the next cycle; follow does not wait for their deadlines.
|
|
282
613
|
* Options are checked at the first pull. On HTTP backends a parked hint is cancelled
|
|
283
614
|
* and replaced once per `repairIntervalMs` until an input changes. One
|
|
284
615
|
* `Projection.follow` span covers the whole stream.
|
|
285
616
|
*/
|
|
286
617
|
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>>;
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
618
|
+
interface AttachOptions<Params = DecodedParams, E = never, R = never> {
|
|
619
|
+
/**
|
|
620
|
+
* Decoded params to consider for startup replay. Defaults to the checkpoint
|
|
621
|
+
* inventory when it is available. An explicit list uses this declaration's
|
|
622
|
+
* id, version and generation to check for existing checkpoints.
|
|
623
|
+
*/
|
|
624
|
+
readonly bindings?: Effect.Effect<ReadonlyArray<Params>, E, R>;
|
|
625
|
+
/**
|
|
626
|
+
* Fixed-address wake classes whose source ids request binding runs. A provided
|
|
627
|
+
* stream service on another storage owner is remote; an absent service or a
|
|
628
|
+
* matching owner is local. Provide the remote class through Protocol.bind.
|
|
629
|
+
* Projection.attach follows remote triggers in scope; ProjectionWakeup.attach
|
|
630
|
+
* accepts only triggers on its own owner. Cursors persist in both modes.
|
|
631
|
+
*/
|
|
632
|
+
readonly triggers?: ReadonlyArray<WakeOutput<{}>>;
|
|
295
633
|
/** Units for each binding in one run. Default 100. */
|
|
296
634
|
readonly limit?: number;
|
|
297
635
|
/**
|
|
298
|
-
*
|
|
636
|
+
* Timing only. The runner calls the schedule once per retryable failed pass with no input.
|
|
637
|
+
* Paces retryable failures reading marks, cursors or triggers. Retryable binding
|
|
638
|
+
* failures use the declaration's binding retry policy. Non-retryable faults stop their unit.
|
|
299
639
|
* Defaults to capped, jittered exponential backoff.
|
|
300
640
|
*/
|
|
301
|
-
readonly
|
|
641
|
+
readonly passRetry?: Schedule.Schedule<unknown>;
|
|
302
642
|
/**
|
|
303
643
|
* Keep a pending mark for each binding in the storage owner, written in the
|
|
304
644
|
* transaction of the commit that needs the run. After a restart or an
|
|
305
|
-
* eviction, the runner finds the marks and runs those bindings.
|
|
306
|
-
*
|
|
645
|
+
* eviction, the runner finds the marks and runs those bindings. Otherwise
|
|
646
|
+
* pending work, timers, binding backoff and stops live only for this runner.
|
|
647
|
+
* A non-durable timer loses its wake on restart until its next input.
|
|
307
648
|
* Needs a local memory or SQL storage layer.
|
|
308
649
|
*
|
|
309
650
|
* Default: false for `Projection.attach`, true for `ProjectionWakeup.attach`.
|
|
310
651
|
*/
|
|
311
652
|
readonly durable?: boolean;
|
|
312
|
-
/**
|
|
653
|
+
/** The due marks that one drain pass reads. Default 25. */
|
|
313
654
|
readonly batch?: number;
|
|
655
|
+
/** Bindings run at once. Default 1. Must be a positive safe integer. */
|
|
656
|
+
readonly concurrency?: number;
|
|
314
657
|
}
|
|
315
658
|
/**
|
|
316
659
|
* Run a projection whenever a local commit writes one of its inputs. The layer
|
|
317
660
|
* subscribes to `Storage.committed` when it is built, so build it with the
|
|
318
661
|
* storage layer and before the app writes. For each written id, the input's
|
|
319
662
|
* `parse` gives the params, and the runner runs `projection.at(params)`.
|
|
663
|
+
* The background runner also queues startup replays from the checkpoint
|
|
664
|
+
* inventory or `options.bindings`.
|
|
320
665
|
*
|
|
321
666
|
* Use it on long-lived hosts (Bun, Node). On a Cloudflare object, use
|
|
322
667
|
* `ProjectionWakeup.attach(projection)`.
|
|
@@ -324,8 +669,15 @@ interface AttachOptions {
|
|
|
324
669
|
* By default the set of bindings with work lives in memory. A crash after a
|
|
325
670
|
* commit and before the run leaves that binding late until its source gets its
|
|
326
671
|
* next write. With `durable: true`, a pending mark in storage covers that
|
|
327
|
-
* window, and the layer runs due marks when it starts.
|
|
328
|
-
*
|
|
672
|
+
* window, and the layer runs due marks when it starts. Recorded process timers
|
|
673
|
+
* wake at their deadline; after host suspend, a capped wait rechecks within 30 s.
|
|
674
|
+
* Return a time after unit.due to avoid repeatedly running a passed deadline.
|
|
675
|
+
* Inputs on another owner can use local or remote wake streams in `triggers`.
|
|
676
|
+
* A provided trigger service on another owner is read one page per pass outside
|
|
677
|
+
* the local transaction; durable marks and the page cursor then commit together.
|
|
678
|
+
* A scoped live-read follower signals new remote rows. Remote read failures use
|
|
679
|
+
* passRetry after local bindings drain; local commits during that backoff wait
|
|
680
|
+
* for it to end (up to 30 s with the default policy). Do not run
|
|
329
681
|
* an attached binding under `Projection.follow` too: use one writer per key.
|
|
330
682
|
*
|
|
331
683
|
* ```ts
|
|
@@ -334,7 +686,7 @@ interface AttachOptions {
|
|
|
334
686
|
* );
|
|
335
687
|
* ```
|
|
336
688
|
*/
|
|
337
|
-
declare const attach$1: <I extends InputMap, E, R, Q, Result, P, OR = never>(projection: Attachable<Executable<I, E, R, Q, Result, P, unknown, OR
|
|
689
|
+
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>;
|
|
338
690
|
/** A bound value projection. Output items from its adapter are discarded. */
|
|
339
691
|
interface CurrentProjection<Inputs extends InputMap, S, E, R, Q> extends Identity {
|
|
340
692
|
readonly inputs: Inputs;
|
|
@@ -351,6 +703,51 @@ interface CurrentProjection<Inputs extends InputMap, S, E, R, Q> extends Identit
|
|
|
351
703
|
* Fold steps must be replayable. Pending ranges are read from committed offsets.
|
|
352
704
|
*/
|
|
353
705
|
declare const current: <Inputs extends InputMap, S, E, R, Q>(projection: CurrentProjection<Inputs, S, E, R, Q>) => Effect.Effect<Snapshot<S, Inputs>, E | ProjectionFault, Q | R | InputServices<Inputs>>;
|
|
706
|
+
/**
|
|
707
|
+
* Lists the decoded params of bindings with live checkpoints in the selected store.
|
|
708
|
+
* By default it includes every generation of the declaration's id, across checkpoint
|
|
709
|
+
* versions. A generation filter still includes every version at that generation.
|
|
710
|
+
* Each binding appears once, in unspecified order.
|
|
711
|
+
*
|
|
712
|
+
* Fails with `InvalidBinding` if live params cannot round-trip through the current
|
|
713
|
+
* codecs. MySQL owner stores fail because historical hashed keys cannot be decoded.
|
|
714
|
+
*/
|
|
715
|
+
declare const bindings: <C extends Readonly<Record<string, Schema.Codec<unknown, string, never, never>>>>(declaration: Pick<Declaration<C, unknown, never, never>, "id" | "params">, options?: {
|
|
716
|
+
readonly generation?: number;
|
|
717
|
+
} | undefined) => Effect.Effect<readonly StreamRoute.Params<C>[], InvalidBinding | ProjectionFault, CheckpointStore>;
|
|
718
|
+
declare const Tail: Schema.Struct<{
|
|
719
|
+
readonly stream: Schema.brand<Schema.String, "StreamId">;
|
|
720
|
+
readonly offset: Schema.brand<Schema.String, "Offset">;
|
|
721
|
+
readonly closed: Schema.Boolean;
|
|
722
|
+
}>;
|
|
723
|
+
/** A serializable vector of fixed source tails, keyed by input name. */
|
|
724
|
+
declare const Tails: Schema.$Record<Schema.String, Schema.Struct<{
|
|
725
|
+
readonly stream: Schema.brand<Schema.String, "StreamId">;
|
|
726
|
+
readonly offset: Schema.brand<Schema.String, "Offset">;
|
|
727
|
+
readonly closed: Schema.Boolean;
|
|
728
|
+
}>>;
|
|
729
|
+
type Tails<Inputs extends InputMap = InputMap> = { readonly [Name in keyof Inputs]: typeof Tail.Type; };
|
|
730
|
+
interface InputLag {
|
|
731
|
+
readonly committed: Offset;
|
|
732
|
+
readonly target: Offset;
|
|
733
|
+
/** True while the input needs an offset, a close, or settlement of a pinned range. */
|
|
734
|
+
readonly behind: boolean;
|
|
735
|
+
}
|
|
736
|
+
interface Lag<Inputs extends InputMap = InputMap> {
|
|
737
|
+
/** True when all source targets are committed and there is no pending unit. */
|
|
738
|
+
readonly caughtUp: boolean;
|
|
739
|
+
readonly inputs: { readonly [Name in keyof Inputs]: InputLag; };
|
|
740
|
+
}
|
|
741
|
+
type Sources<Inputs extends InputMap> = Pick<Identity, "id"> & {
|
|
742
|
+
readonly inputs: Inputs;
|
|
743
|
+
};
|
|
744
|
+
type Checkpointed<Inputs extends InputMap, Q> = Omit<Readable<Inputs, never, Q>, "state">;
|
|
745
|
+
/** Capture each resolved input head once. The vector can be reused while producers keep writing. */
|
|
746
|
+
declare const tails: <Inputs extends InputMap>(projection: Sources<Inputs>) => Effect.Effect<Tails<Inputs>, ProjectionFault, InputServices<Inputs>>;
|
|
747
|
+
/** Compare fixed source tails with one committed checkpoint, including processed closes. Checks source readiness only. */
|
|
748
|
+
declare const lag: <Inputs extends InputMap, Q>(projection: Checkpointed<Inputs, Q>, targets?: Tails<InputMap> | undefined) => Effect.Effect<Lag<Inputs>, ProjectionFault, Q | InputServices<Inputs>>;
|
|
749
|
+
/** Wait for one fixed vector of source tails. The caller controls the timeout. */
|
|
750
|
+
declare const caughtUp: <Inputs extends InputMap, Q>(projection: Checkpointed<Inputs, Q>, targets?: Tails<InputMap> | undefined) => Effect.Effect<void, ProjectionFault, Q | InputServices<Inputs>>;
|
|
354
751
|
interface DecideSpec<Inputs extends InputMap, K extends keyof Inputs, S, B, E, R> {
|
|
355
752
|
/** The input to append to. Its offset in the snapshot is the CAS token. */
|
|
356
753
|
readonly input: K;
|
|
@@ -382,56 +779,40 @@ declare class LostRace {
|
|
|
382
779
|
constructor(mismatch: OffsetMismatch);
|
|
383
780
|
}
|
|
384
781
|
/**
|
|
385
|
-
* Deletes
|
|
782
|
+
* Deletes a live record and preserves retirement tombstones. Stop the follower first,
|
|
783
|
+
* or use a new generation.
|
|
386
784
|
* Delete stream outputs first, because forgetting restarts their producer sequences.
|
|
387
785
|
*/
|
|
388
786
|
declare const forget: <R>(projection: ProjectionKey & {
|
|
389
787
|
readonly commit: Pick<Commit<never, never, R>, "remove">;
|
|
390
788
|
}) => Effect.Effect<void, ProjectionFault, R>;
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
interface WakeDefinition<C extends StreamRoute.ParamCodecs, I extends Input, O> {
|
|
789
|
+
type StreamMode = "remove" | "close";
|
|
790
|
+
interface RetiredOutput {
|
|
394
791
|
readonly id: string;
|
|
395
|
-
readonly
|
|
396
|
-
readonly generation?: number;
|
|
397
|
-
readonly params: C;
|
|
398
|
-
/** The one source stream. Its params must be projection params. */
|
|
399
|
-
readonly input: I & OneWithin<C, I>;
|
|
400
|
-
/** The State declaration with wake collections that gets the row. Its params must be projection params. */
|
|
401
|
-
readonly output: O & OneWithin<C, O>;
|
|
792
|
+
readonly result: "removed" | "closed" | "absent" | "shared";
|
|
402
793
|
}
|
|
403
|
-
|
|
404
|
-
readonly
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
* ```ts
|
|
418
|
-
* const filesWake = Projection.wake({
|
|
419
|
-
* id: "files-wake",
|
|
420
|
-
* params: { user: UserKey, folderId: FolderKey },
|
|
421
|
-
* input: Files,
|
|
422
|
-
* output: UserWake,
|
|
423
|
-
* });
|
|
424
|
-
* ```
|
|
425
|
-
*/
|
|
426
|
-
declare function wake<C extends StreamRoute.ParamCodecs, const I extends Input, const O extends WakeOutput>(definition: WakeDefinition<C, I, O>): WakeDeclaration<C, I, O>;
|
|
794
|
+
interface Retired {
|
|
795
|
+
readonly record: RetirementStatus;
|
|
796
|
+
readonly outputs: Readonly<Record<string, RetiredOutput>>;
|
|
797
|
+
/** Exclusively owned streams opened by each routed output. */
|
|
798
|
+
readonly routed?: Readonly<Record<string, ReadonlyArray<RetiredOutput>>>;
|
|
799
|
+
}
|
|
800
|
+
interface Retirable<R, Q> extends ProjectionKey, BoundOutputs<R> {
|
|
801
|
+
readonly commit: Pick<Commit<never, never, Q>, "retire">;
|
|
802
|
+
}
|
|
803
|
+
/** Retire one binding and clean up its exclusively owned generation outputs. */
|
|
804
|
+
declare const retire: <C extends StreamRoute.ParamCodecs, R, Q, HE, HR>(declaration: Declaration<C, Retirable<R, Q>, HE, HR>, params: StreamRoute.Params<C>, options: {
|
|
805
|
+
readonly generation: number;
|
|
806
|
+
readonly streams?: StreamMode;
|
|
807
|
+
}) => Effect.Effect<Retired, ProjectionFault, R | Q>;
|
|
427
808
|
declare namespace projection_d_exports {
|
|
428
|
-
export { attach$1 as attach, current, decide, each, emit, fold, follow, forget, items, key, mapAccum, mapAccumBatch, pass, process$1 as process, read, run, wake };
|
|
809
|
+
export { InputLag, Lag, PerGeneration, Registry, RegistryApi, Retired, RetiredOutput, RoutedHandle, RunnerEvent, RunnerFailure, RunnerStatus, Tails, WakeAt, WakeOutput, attach$1 as attach, bindings, caughtUp, createOutputs, current, decide, each, emit, fold, follow, forget, generationBinding, isPerGeneration, items, key, lag, mapAccum, mapAccumBatch, pass, perGeneration, process$1 as process, read, retire, run, tails, wake, wakeAt };
|
|
429
810
|
}
|
|
430
811
|
declare const key: (projection: Identity) => ProjectionKey;
|
|
431
812
|
/** Runs each tagged entry in order and discards its success value. */
|
|
432
813
|
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>);
|
|
433
814
|
declare namespace state_table_d_exports {
|
|
434
|
-
export { Bound, Declaration$1 as Declaration, ListOptions, define, migrate, rebuild, reset };
|
|
815
|
+
export { Bound, Declaration$1 as Declaration, ListOptions, clear, define, migrate, rebuild, reset };
|
|
435
816
|
}
|
|
436
817
|
/** Create the SQLite row index at host startup, outside storage migrations. */
|
|
437
818
|
declare const migrate: (sql: SqlClient.SqlClient) => Effect.Effect<void, ProjectionFault | SqlError.SqlError, never>;
|
|
@@ -450,6 +831,7 @@ interface Bound<C extends StreamAddress.Collections, R> {
|
|
|
450
831
|
readonly inputs: {
|
|
451
832
|
readonly state: Streamsy.Address<string, R>;
|
|
452
833
|
};
|
|
834
|
+
readonly accepted?: Streamsy.Address<Streamsy.WakeEvent, R>;
|
|
453
835
|
readonly commit: typeof transaction;
|
|
454
836
|
readonly process: (batch: Slices<{
|
|
455
837
|
readonly state: Streamsy.Address<string, R>;
|
|
@@ -491,7 +873,11 @@ type State<Codecs extends StreamRoute.ParamCodecs, C extends StreamAddress.Colle
|
|
|
491
873
|
readonly at: (params: StreamRoute.Params<Codecs>) => StreamAddress.StateAddress<C> & Streamsy.Address<StreamAddress.CollectionsEvent<C>, R, StreamAddress.CollectionsDecodingServices<C>, StreamAddress.CollectionsEncodingServices<C>>;
|
|
492
874
|
};
|
|
493
875
|
/** A State stream's declaration, kept current by the ordinary projection runners. */
|
|
494
|
-
declare function define<Codecs extends StreamRoute.ParamCodecs, C extends StreamAddress.Collections, R>(state: State<Codecs, C, R
|
|
876
|
+
declare function define<Codecs extends StreamRoute.ParamCodecs, C extends StreamAddress.Collections, R, W extends WakeOutput | undefined = undefined>(state: State<Codecs, C, R>, options?: {
|
|
877
|
+
readonly accepted?: W & OneWithin<Codecs, W>;
|
|
878
|
+
}): Declaration$1<Codecs, C, R | AcceptedServices<W>>;
|
|
879
|
+
/** Delete cached rows and their applied offset, even if the State stream has been removed. */
|
|
880
|
+
declare const clear: <C extends StreamAddress.Collections, R>(table: Bound<C, R>) => Effect.Effect<void, ProjectionFault, Transaction>;
|
|
495
881
|
/** Discard the index and replay the State stream atomically, retaining the binding checkpoint. */
|
|
496
882
|
declare const rebuild: <C extends StreamAddress.Collections, R>(table: Bound<C, R>) => Effect.Effect<void, ProjectionFault, R | Transaction>;
|
|
497
883
|
/** Append a reset to the State stream. The next table run applies it. */
|
|
@@ -531,30 +917,51 @@ declare function process<Codecs extends StreamRoute.ParamCodecs, C extends Strea
|
|
|
531
917
|
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> & {
|
|
532
918
|
readonly records?: never;
|
|
533
919
|
}): Handler<C, O, I, P, E, R, TR>;
|
|
534
|
-
/**
|
|
920
|
+
/**
|
|
921
|
+
* Default retry for following and attached runners; options.passRetry on attach and options.retry on follow take precedence.
|
|
922
|
+
* For attached runners: timing only. The runner calls the schedule once per retryable failed pass with no input.
|
|
923
|
+
*/
|
|
535
924
|
export declare const ProjectionRetry: Context.Reference<Schedule.Schedule<unknown, unknown, never, never>>;
|
|
925
|
+
/** Unknown handler errors and defects retry; only a known non-retryable fault stops work. */
|
|
926
|
+
declare const retryable: (cause: Cause.Cause<unknown>) => boolean;
|
|
927
|
+
interface WakeupHost {
|
|
928
|
+
readonly reconcile: Effect.Effect<void>;
|
|
929
|
+
readonly retry: Effect.Effect<void>;
|
|
930
|
+
readonly state: Effect.Effect<{
|
|
931
|
+
readonly failures: number;
|
|
932
|
+
readonly retryAt: Option.Option<number>;
|
|
933
|
+
}>;
|
|
934
|
+
}
|
|
536
935
|
/**
|
|
537
936
|
* Local commits choose bindings; each alarm drains the same runner used by
|
|
538
937
|
* Projection.attach. Acquire it in the object layer's scope, before any
|
|
539
|
-
* request writes.
|
|
938
|
+
* request writes. Triggers must belong to this storage owner. A provided trigger
|
|
939
|
+
* service on another owner dies at attach with a RangeError naming its stream;
|
|
940
|
+
* remote trigger followers require the process host, Projection.attach.
|
|
941
|
+
* On acquire, startup replays from the checkpoint inventory or `options.bindings`
|
|
942
|
+
* are queued for the alarm on this object.
|
|
540
943
|
*
|
|
541
944
|
* Durable by default: each commit writes a pending mark for its bindings in
|
|
542
945
|
* the same transaction, so an eviction or a deploy between the commit and the
|
|
543
946
|
* alarm loses no work. The host's acquire reconcile reads the marks and arms
|
|
544
|
-
* the alarm.
|
|
947
|
+
* the alarm, including recorded process timer deadlines. A start makes stopped marks due once; a still-broken binding
|
|
948
|
+
* stops again. Stopped marks alone arm no alarm. Pass `durable: false` for private memory marks and timers that reset on eviction until the binding's next input.
|
|
949
|
+
* A wake during backoff waits; a stopped timer fires late after retry or restart.
|
|
950
|
+
* Return a time after unit.due to avoid repeatedly running a passed deadline.
|
|
545
951
|
*/
|
|
546
|
-
declare const attach: <I extends InputMap, E, R, Q, Result, P, OR = never>(projection: Attachable<Executable<I, E, R, Q, Result, P, unknown, OR
|
|
952
|
+
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<{
|
|
547
953
|
name: string;
|
|
548
|
-
next: Effect.Effect<
|
|
954
|
+
next: Effect.Effect<Option.Option<number>, import("@streamsy/core").StorageFault, BR | OR | Q | InputServices<I>>;
|
|
955
|
+
retryable: typeof retryable;
|
|
549
956
|
run: Effect.Effect<{
|
|
550
957
|
more: boolean;
|
|
551
|
-
} |
|
|
552
|
-
|
|
553
|
-
|
|
958
|
+
}, import("@streamsy/core").StorageFault, BR | HR | OR | Q | InputServices<I> | Exclude<R, P>>;
|
|
959
|
+
bind: (bound: WakeupHost) => Effect.Effect<void, never, never>;
|
|
960
|
+
changed: Effect.Effect<void, never, never>;
|
|
554
961
|
retry: import("effect/Schedule").Schedule<unknown, unknown, never, never>;
|
|
555
962
|
deferred: Effect.Effect<number, import("@streamsy/core").StorageFault, never>;
|
|
556
963
|
}, never, import("effect/Scope").Scope | import("@streamsy/core").Storage>;
|
|
557
964
|
export declare const ProjectionWakeup: {
|
|
558
965
|
attach: typeof attach;
|
|
559
966
|
};
|
|
560
|
-
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 Identity, type Initial, type InputMap, type ItemOf, type Loaded, type Offsets, type OutputBatch, type OutputsContext, type PassResult, type ProcessContext, type Progress, projection_d_exports as Projection, ProjectionFault, type ProjectionKey, type Range, type RunOptions, type Slice, type Slices, type Snapshot, type StateDefinition, type StateSchema, state_table_d_exports as StateTable, type Step, type Unit };
|
|
967
|
+
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 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, type WakeOutput };
|