@streamsy/projection 0.12.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 +12 -0
- package/dist/{checkpoint-store-DCfrS4Fd.d.ts → checkpoint-store-B1199nDD.d.ts} +34 -3
- package/dist/{checkpoint-store--bWf1qeP.js → checkpoint-store-ViVETLzZ.js} +169 -31
- package/dist/checkpoint.d.ts +2 -2
- package/dist/checkpoint.js +1 -1
- package/dist/index.d.ts +233 -46
- package/dist/index.js +718 -142
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Cause, Context, Data, DateTime, Effect, Layer, Option, Pipeable, Schedule, Schema, Stream } from "effect";
|
|
3
|
-
import { CommitBoundary, Decided, Decision, DurableState, OffsetMismatch, Storage, StorageFault, StreamAddress, StreamId, Streamsy } from "@streamsy/core";
|
|
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
4
|
import { MarkFailure, ProjectionMarkSummary } from "@streamsy/core/internal";
|
|
5
|
-
import { StreamRoute, Streams } from "@streamsy/core/protocol";
|
|
5
|
+
import { Reader, StreamRoute, Streams, Writer } from "@streamsy/core/protocol";
|
|
6
6
|
import { SqlClient, SqlError } from "effect/sql";
|
|
7
7
|
interface RunOptions {
|
|
8
8
|
/** Maximum checkpoint transactions per call; absent means run to completion. */
|
|
@@ -10,13 +10,6 @@ interface RunOptions {
|
|
|
10
10
|
}
|
|
11
11
|
/** Tagged items in declaration order, then stream order within each input. */
|
|
12
12
|
declare const items: <Inputs extends InputMap>(batch: Slices<Inputs>) => ReadonlyArray<Entry<Inputs>>;
|
|
13
|
-
type RoutedMap = Inputs;
|
|
14
|
-
type Item<T> = AddressOf<T> extends {
|
|
15
|
-
readonly collections: infer C extends StreamAddress.Collections;
|
|
16
|
-
} ? DurableState.Entry<C> : AddressOf<T> extends {
|
|
17
|
-
readonly codec: Schema.Codec<infer A, any, any, any>;
|
|
18
|
-
} ? A : never;
|
|
19
|
-
type Services<O extends RoutedMap> = { [K in keyof O]: AddressOf<O[K]> extends Streamsy.Address<any, infer R> ? R : never; }[keyof O];
|
|
20
13
|
/** A process handler's request to run again at an epoch-millisecond deadline. */
|
|
21
14
|
interface WakeAt {
|
|
22
15
|
readonly _tag: "WakeAt";
|
|
@@ -24,19 +17,36 @@ interface WakeAt {
|
|
|
24
17
|
}
|
|
25
18
|
/** Return this request from process; returning void clears the previous deadline. */
|
|
26
19
|
declare const wakeAt: (time: number | DateTime.DateTime) => WakeAt;
|
|
27
|
-
|
|
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";
|
|
28
32
|
interface Variance<in Result, in Provides, out Requires> {
|
|
29
33
|
readonly result: (_: Result) => void;
|
|
30
34
|
readonly provides: (_: Provides) => void;
|
|
31
35
|
readonly requires: () => Requires;
|
|
32
36
|
}
|
|
33
37
|
interface Commit<in Result, in Provides = never, out Requires = never> extends Pipeable.Pipeable {
|
|
34
|
-
readonly [TypeId]: Variance<Result, Provides, Requires>;
|
|
38
|
+
readonly [TypeId$1]: Variance<Result, Provides, Requires>;
|
|
35
39
|
readonly name: string;
|
|
36
40
|
readonly guarantee: "exactly-once" | "effectively-once" | "at-least-once";
|
|
37
41
|
readonly load: (key: ProjectionKey) => Effect.Effect<Loaded, ProjectionFault, Requires>;
|
|
38
42
|
readonly apply: (pending: Pending<Result, Provides>) => Effect.Effect<void, ProjectionFault | HandlerFailed, Requires>;
|
|
39
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>;
|
|
40
50
|
}
|
|
41
51
|
interface Pending<Result, Provides = never> {
|
|
42
52
|
readonly key: ProjectionKey;
|
|
@@ -44,6 +54,8 @@ interface Pending<Result, Provides = never> {
|
|
|
44
54
|
readonly loaded: Loaded;
|
|
45
55
|
readonly next: CheckpointRecord;
|
|
46
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>;
|
|
47
59
|
}
|
|
48
60
|
declare const HandlerFailed_base: Schema.Class<HandlerFailed, Schema.TaggedStruct<"HandlerFailed", {
|
|
49
61
|
readonly error: Schema.Unknown;
|
|
@@ -79,7 +91,7 @@ declare const Folded: Data.TaggedEnum.ConstructorFrom<Folded<unknown>, "_tag">,
|
|
|
79
91
|
* Custom Commits do not support timer handlers in this release.
|
|
80
92
|
* load must return the stored state. If run and the write are not atomic,
|
|
81
93
|
* declare at-least-once. The guarantee must describe the actual write. */
|
|
82
|
-
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>;
|
|
83
95
|
declare const checkpoint: Commit<Folded<unknown>, never, CheckpointStore>;
|
|
84
96
|
declare const Transaction_base: Context.ServiceClass<Transaction, "@streamsy/projection/Transaction", {
|
|
85
97
|
readonly owner: object;
|
|
@@ -94,8 +106,39 @@ export declare class Transaction extends Transaction_base {
|
|
|
94
106
|
*/
|
|
95
107
|
static readonly layer: Layer.Layer<Transaction, never, CommitBoundary | SqlClient.SqlClient>;
|
|
96
108
|
}
|
|
97
|
-
type Result$1 = void | WakeAt | Folded<unknown> | Emitted<OutputNames> | Accumulated<unknown, OutputNames>;
|
|
98
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
|
+
};
|
|
99
142
|
declare const producer: Commit<Accumulated<unknown, Readonly<Record<string, never>>> | Emitted<Readonly<Record<string, never>>>, never, CheckpointStore>;
|
|
100
143
|
declare const atLeastOnce: Commit<void | WakeAt, never, CheckpointStore>;
|
|
101
144
|
declare const withCompensation: {
|
|
@@ -103,8 +146,69 @@ declare const withCompensation: {
|
|
|
103
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>;
|
|
104
147
|
};
|
|
105
148
|
declare namespace commit_d_exports {
|
|
106
|
-
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
|
+
};
|
|
159
|
+
}
|
|
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>>;
|
|
107
197
|
}
|
|
198
|
+
type RoutedMap = Readonly<Record<string, RoutedOutput>>;
|
|
199
|
+
type StaticOutputMap = Readonly<Record<string, Input | PerGeneration<StreamDeclaration, string>>>;
|
|
200
|
+
type Item<T> = AddressOf<T> extends {
|
|
201
|
+
readonly collections: infer C extends StreamAddress.Collections;
|
|
202
|
+
} ? DurableState.Entry<C> : AddressOf<T> extends {
|
|
203
|
+
readonly codec: Schema.Codec<infer A, any, any, any>;
|
|
204
|
+
} ? A : never;
|
|
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>;
|
|
108
212
|
type StateSchema<A, I = unknown> = Schema.Codec<A, I>;
|
|
109
213
|
/** A value, or a function of the decoded params the projection was bound with. */
|
|
110
214
|
type Initial<A, P = Record<string, string>> = A | ((params: P) => A);
|
|
@@ -119,7 +223,7 @@ interface BoundState<A> {
|
|
|
119
223
|
readonly initial: () => A;
|
|
120
224
|
}
|
|
121
225
|
/** Common bound declaration consumed by the kernel. */
|
|
122
|
-
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 {
|
|
123
227
|
readonly inputs: I;
|
|
124
228
|
readonly state?: BoundState<S>;
|
|
125
229
|
readonly streams?: Readonly<Record<string, Streamsy.Address<unknown, OR>>>;
|
|
@@ -149,7 +253,7 @@ type Readable<Inputs extends InputMap, S, Q> = Identity & {
|
|
|
149
253
|
*/
|
|
150
254
|
declare const read: <Inputs extends InputMap, S = never, Q = never>(projection: Readable<Inputs, S, Q>) => Effect.Effect<Snapshot<StateValue<S>, Inputs>, ProjectionFault, Q>;
|
|
151
255
|
/** The part of a projection declaration that the attach runner reads. */
|
|
152
|
-
interface Attachable<B, HE = never, HR = never> {
|
|
256
|
+
interface Attachable<B, HE = never, HR = never, Params = DecodedParams> {
|
|
153
257
|
readonly retry?: {
|
|
154
258
|
readonly schedule?: Schedule.Schedule<unknown>;
|
|
155
259
|
readonly maxAttempts?: number;
|
|
@@ -160,7 +264,7 @@ interface Attachable<B, HE = never, HR = never> {
|
|
|
160
264
|
readonly generation: number;
|
|
161
265
|
readonly params: StreamRoute.ParamCodecs;
|
|
162
266
|
readonly inputs: Inputs;
|
|
163
|
-
at(params:
|
|
267
|
+
at(params: Params): B;
|
|
164
268
|
}
|
|
165
269
|
/** The result of one `pass`: one committed unit (`progress`), or no input or wake to commit. */
|
|
166
270
|
interface PassResult<Inputs extends InputMap = InputMap> {
|
|
@@ -319,15 +423,18 @@ type StreamDeclaration = StreamRoute.StreamRoute<any, any> & Streamsy.Any & {
|
|
|
319
423
|
/** A stream declaration, or a fixed address that `.at` does not rebind. */
|
|
320
424
|
type Input = StreamDeclaration | Streamsy.Address<any, any>;
|
|
321
425
|
type Inputs = Readonly<Record<string, Input>>;
|
|
322
|
-
type AddressOf<X> = X extends StreamDeclaration ? ReturnType<X["at"]> : X extends Streamsy.Address<any, any> ? X : never;
|
|
323
|
-
type Addresses<I extends
|
|
324
|
-
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]>; };
|
|
325
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];
|
|
326
431
|
type InvalidInput<C extends StreamRoute.ParamCodecs, X> = X extends StreamDeclaration ? Invalid<C, DeclaredParams<X>> : never;
|
|
327
432
|
/** Every declaration's params must be projection params with the same type. */
|
|
328
433
|
type Within<C extends StreamRoute.ParamCodecs, I extends Inputs> = { readonly [K in keyof I]: InvalidInput<C, I[K]> extends never ? I[K] : never; };
|
|
329
434
|
type OneWithin<C extends StreamRoute.ParamCodecs, X> = InvalidInput<C, X> extends never ? X : never;
|
|
330
|
-
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]>; };
|
|
331
438
|
/** Inert: `at` binds the params and returns the value runners take. */
|
|
332
439
|
interface Declaration<Codecs extends StreamRoute.ParamCodecs, Bound, HE = never, HR = never> {
|
|
333
440
|
readonly retry?: BindingRetry<StreamRoute.Params<Codecs>, HE, HR> | undefined;
|
|
@@ -342,10 +449,10 @@ interface Declaration<Codecs extends StreamRoute.ParamCodecs, Bound, HE = never,
|
|
|
342
449
|
/** Tries declaration inputs in order. Shared inputs return only their declared subset. */
|
|
343
450
|
readonly parse: (id: string) => Option.Option<Partial<StreamRoute.Params<Codecs>>>;
|
|
344
451
|
}
|
|
345
|
-
type AcceptedServices<W> = W extends
|
|
452
|
+
type AcceptedServices<W> = W extends AcceptedOutput ? Services<{
|
|
346
453
|
accepted: W;
|
|
347
454
|
}> : never;
|
|
348
|
-
type AcceptedResult<Result, W> = W extends
|
|
455
|
+
type AcceptedResult<Result, W> = W extends AcceptedOutput ? Result extends Folded<infer A> ? Accumulated<A, {}> : Result extends WakeAt ? Emitted<{}> & Pick<WakeAt, "wakeAt"> : Emitted<{}> : Result;
|
|
349
456
|
/** Binding retry timing and budget, shared by both attach hosts. */
|
|
350
457
|
interface BindingRetry<Params, E = never, R = never> {
|
|
351
458
|
/**
|
|
@@ -371,8 +478,10 @@ interface Common<C extends StreamRoute.ParamCodecs, I extends Inputs, W = undefi
|
|
|
371
478
|
readonly params: C;
|
|
372
479
|
readonly inputs: I & Within<C, I>;
|
|
373
480
|
/** Publish accepted input offsets in this wake stream as part of each unit. */
|
|
374
|
-
readonly accepted?: W &
|
|
481
|
+
readonly accepted?: W & OneOutputWithin<C, W>;
|
|
375
482
|
}
|
|
483
|
+
/** Decoded params, keyed by name. */
|
|
484
|
+
type DecodedParams = Readonly<Record<string, unknown>>;
|
|
376
485
|
interface Committing<Result, P, Q> {
|
|
377
486
|
readonly commit: Commit<Result, P, Q>;
|
|
378
487
|
}
|
|
@@ -392,7 +501,7 @@ type WakeOutput<P = any> = StreamDeclaration & StreamRoute.StateRoute<P, Streams
|
|
|
392
501
|
readonly paramCodecs: StreamRoute.ParamCodecs;
|
|
393
502
|
};
|
|
394
503
|
interface WakeDefinition<C extends StreamRoute.ParamCodecs, I extends Input, O, W = undefined> {
|
|
395
|
-
readonly accepted?: W &
|
|
504
|
+
readonly accepted?: W & OneOutputWithin<C, W>;
|
|
396
505
|
readonly id: string;
|
|
397
506
|
readonly version?: number;
|
|
398
507
|
readonly generation?: number;
|
|
@@ -425,12 +534,13 @@ type WakeDeclaration<C extends StreamRoute.ParamCodecs, I extends Input, O exten
|
|
|
425
534
|
* });
|
|
426
535
|
* ```
|
|
427
536
|
*/
|
|
428
|
-
declare function wake<C extends StreamRoute.ParamCodecs, const I extends Input, const O extends WakeOutput, W extends
|
|
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>;
|
|
429
539
|
type Step<X, E = never, R = never> = X | Effect.Effect<X, E, R>;
|
|
430
540
|
/** Each output keeps its item type here; missing keys emit nothing. */
|
|
431
541
|
type Emits<O extends RoutedMap> = { readonly [K in keyof O]?: ReadonlyArray<Item<O[K]>>; };
|
|
432
542
|
/** Fold one entry at a time. The default Commit saves state and offsets in one write. */
|
|
433
|
-
declare function fold<C extends StreamRoute.ParamCodecs, I extends Inputs, A, SI, E = never, R = never, P = never, Q = CheckpointStore, W extends
|
|
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>) & {
|
|
434
544
|
readonly state: StateDefinition<A, SI, StreamRoute.Params<C>>;
|
|
435
545
|
readonly fold: (state: NoInfer<A>, entry: Entry<Addresses<I>>, unit: Unit<StreamRoute.Params<C>>) => Step<A, E, R>;
|
|
436
546
|
}): StatefulDeclaration<C, I, A, E, R, Folded<A>, P, Q, AcceptedServices<W>, HE, HR>;
|
|
@@ -442,42 +552,42 @@ interface ProcessContext<Prepared = void> {
|
|
|
442
552
|
/** Binding run attempt, starting at 1. Always 1 under run and follow. */
|
|
443
553
|
readonly attempt: number;
|
|
444
554
|
}
|
|
445
|
-
/** The
|
|
555
|
+
/** The address or routed handle of each declared output. Open handles only inside `process`. */
|
|
446
556
|
interface OutputsContext<O extends RoutedMap> {
|
|
447
|
-
readonly outputs:
|
|
557
|
+
readonly outputs: HandlerOutputs<O>;
|
|
448
558
|
}
|
|
449
559
|
/** Run side effects once per unit, including recorded wakes. Return wakeAt(time) to
|
|
450
560
|
* replace the timer, or void to clear it. Timers require atLeastOnce or transaction.
|
|
451
561
|
* prepare runs at least once, outside the transaction. */
|
|
452
|
-
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
|
|
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> & {
|
|
453
563
|
readonly outputs?: never;
|
|
454
564
|
readonly prepare?: (batch: Slices<Addresses<I>>, unit: Unit<StreamRoute.Params<C>>) => Effect.Effect<Prepared, PE, PR>;
|
|
455
565
|
readonly process: (batch: Slices<Addresses<I>>, unit: Unit<StreamRoute.Params<C>>, context: ProcessContext<Prepared>) => Effect.Effect<A, E, R>;
|
|
456
566
|
}): RunningDeclaration<C, I, E | PE, R, TimerResult<A>, P, Q | PR, never, AcceptedServices<W>, HE, HR>;
|
|
457
|
-
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
|
|
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> & {
|
|
458
568
|
readonly outputs: O & OutputsWithin<C, O>;
|
|
459
569
|
readonly prepare?: (batch: Slices<Addresses<I>>, unit: Unit<StreamRoute.Params<C>>, context: OutputsContext<O>) => Effect.Effect<Prepared, PE, PR>;
|
|
460
570
|
readonly process: (batch: Slices<Addresses<I>>, unit: Unit<StreamRoute.Params<C>>, context: ProcessContext<Prepared> & OutputsContext<O>) => Effect.Effect<A, E, R>;
|
|
461
571
|
}): OutputDeclaration<C, I, O, E | PE, R, TimerResult<A>, SqlClient.SqlClient, Q | PR, never, AcceptedServices<W>, HE, HR>;
|
|
462
572
|
/** Emit zero or more output items for each input entry, in entry order. */
|
|
463
|
-
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> & {
|
|
464
574
|
readonly outputs: O & OutputsWithin<C, O>;
|
|
465
575
|
readonly emit: ((entry: Entry<Addresses<I>>, unit: Unit<StreamRoute.Params<C>>) => Step<X, E, R>) & (Exclude<keyof X, keyof O> extends never ? unknown : {
|
|
466
576
|
readonly undeclaredOutput: Exclude<keyof X, keyof O>;
|
|
467
577
|
});
|
|
468
578
|
}): OutputDeclaration<C, I, O, E, R, Emitted<O>, P, Q, never, AcceptedServices<W>, HE, HR>;
|
|
469
|
-
type Definition<C extends StreamRoute.ParamCodecs, I extends Inputs, O extends
|
|
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> & {
|
|
470
580
|
readonly outputs: O & OutputsWithin<C, O>;
|
|
471
581
|
readonly state: StateDefinition<A, SI, StreamRoute.Params<C>>;
|
|
472
582
|
};
|
|
473
583
|
/** Thread the value and collect outputs, once per entry. */
|
|
474
|
-
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> & {
|
|
475
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 : {
|
|
476
586
|
readonly undeclaredOutput: Exclude<keyof X, keyof O>;
|
|
477
587
|
});
|
|
478
588
|
}): AccumulatingDeclaration<C, I, O, A, E, R, P, Q, AcceptedServices<W>, HE, HR>;
|
|
479
589
|
/** Compute the next value and outputs once for the whole unit batch. */
|
|
480
|
-
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> & {
|
|
481
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 : {
|
|
482
592
|
readonly undeclaredOutput: Exclude<keyof X, keyof O>;
|
|
483
593
|
});
|
|
@@ -505,7 +615,13 @@ interface FollowOptions extends RunOptions {
|
|
|
505
615
|
* `Projection.follow` span covers the whole stream.
|
|
506
616
|
*/
|
|
507
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>>;
|
|
508
|
-
interface AttachOptions {
|
|
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>;
|
|
509
625
|
/**
|
|
510
626
|
* Fixed-address wake classes whose source ids request binding runs. A provided
|
|
511
627
|
* stream service on another storage owner is remote; an absent service or a
|
|
@@ -544,6 +660,8 @@ interface AttachOptions {
|
|
|
544
660
|
* subscribes to `Storage.committed` when it is built, so build it with the
|
|
545
661
|
* storage layer and before the app writes. For each written id, the input's
|
|
546
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`.
|
|
547
665
|
*
|
|
548
666
|
* Use it on long-lived hosts (Bun, Node). On a Cloudflare object, use
|
|
549
667
|
* `ProjectionWakeup.attach(projection)`.
|
|
@@ -568,7 +686,7 @@ interface AttachOptions {
|
|
|
568
686
|
* );
|
|
569
687
|
* ```
|
|
570
688
|
*/
|
|
571
|
-
declare const attach$1: <I extends InputMap, E, R, Q, Result, P, OR = never, HE = never, HR = never>(projection: Attachable<Executable<I, E, R, Q, Result, P, unknown, OR>, HE, HR>, options?: AttachOptions) => Layer.Layer<never, never, Storage | Exclude<R, P> | Q | OR | HR | InputServices<I
|
|
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>;
|
|
572
690
|
/** A bound value projection. Output items from its adapter are discarded. */
|
|
573
691
|
interface CurrentProjection<Inputs extends InputMap, S, E, R, Q> extends Identity {
|
|
574
692
|
readonly inputs: Inputs;
|
|
@@ -585,6 +703,51 @@ interface CurrentProjection<Inputs extends InputMap, S, E, R, Q> extends Identit
|
|
|
585
703
|
* Fold steps must be replayable. Pending ranges are read from committed offsets.
|
|
586
704
|
*/
|
|
587
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>>;
|
|
588
751
|
interface DecideSpec<Inputs extends InputMap, K extends keyof Inputs, S, B, E, R> {
|
|
589
752
|
/** The input to append to. Its offset in the snapshot is the CAS token. */
|
|
590
753
|
readonly input: K;
|
|
@@ -616,20 +779,40 @@ declare class LostRace {
|
|
|
616
779
|
constructor(mismatch: OffsetMismatch);
|
|
617
780
|
}
|
|
618
781
|
/**
|
|
619
|
-
* Deletes
|
|
782
|
+
* Deletes a live record and preserves retirement tombstones. Stop the follower first,
|
|
783
|
+
* or use a new generation.
|
|
620
784
|
* Delete stream outputs first, because forgetting restarts their producer sequences.
|
|
621
785
|
*/
|
|
622
786
|
declare const forget: <R>(projection: ProjectionKey & {
|
|
623
787
|
readonly commit: Pick<Commit<never, never, R>, "remove">;
|
|
624
788
|
}) => Effect.Effect<void, ProjectionFault, R>;
|
|
789
|
+
type StreamMode = "remove" | "close";
|
|
790
|
+
interface RetiredOutput {
|
|
791
|
+
readonly id: string;
|
|
792
|
+
readonly result: "removed" | "closed" | "absent" | "shared";
|
|
793
|
+
}
|
|
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>;
|
|
625
808
|
declare namespace projection_d_exports {
|
|
626
|
-
export { Registry, RegistryApi, RunnerEvent, RunnerFailure, RunnerStatus, WakeAt, WakeOutput, attach$1 as attach, current, decide, each, emit, fold, follow, forget, items, key, mapAccum, mapAccumBatch, pass, process$1 as process, read, run, wake, wakeAt };
|
|
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 };
|
|
627
810
|
}
|
|
628
811
|
declare const key: (projection: Identity) => ProjectionKey;
|
|
629
812
|
/** Runs each tagged entry in order and discards its success value. */
|
|
630
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>);
|
|
631
814
|
declare namespace state_table_d_exports {
|
|
632
|
-
export { Bound, Declaration$1 as Declaration, ListOptions, define, migrate, rebuild, reset };
|
|
815
|
+
export { Bound, Declaration$1 as Declaration, ListOptions, clear, define, migrate, rebuild, reset };
|
|
633
816
|
}
|
|
634
817
|
/** Create the SQLite row index at host startup, outside storage migrations. */
|
|
635
818
|
declare const migrate: (sql: SqlClient.SqlClient) => Effect.Effect<void, ProjectionFault | SqlError.SqlError, never>;
|
|
@@ -693,6 +876,8 @@ type State<Codecs extends StreamRoute.ParamCodecs, C extends StreamAddress.Colle
|
|
|
693
876
|
declare function define<Codecs extends StreamRoute.ParamCodecs, C extends StreamAddress.Collections, R, W extends WakeOutput | undefined = undefined>(state: State<Codecs, C, R>, options?: {
|
|
694
877
|
readonly accepted?: W & OneWithin<Codecs, W>;
|
|
695
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>;
|
|
696
881
|
/** Discard the index and replay the State stream atomically, retaining the binding checkpoint. */
|
|
697
882
|
declare const rebuild: <C extends StreamAddress.Collections, R>(table: Bound<C, R>) => Effect.Effect<void, ProjectionFault, R | Transaction>;
|
|
698
883
|
/** Append a reset to the State stream. The next table run applies it. */
|
|
@@ -753,6 +938,8 @@ interface WakeupHost {
|
|
|
753
938
|
* request writes. Triggers must belong to this storage owner. A provided trigger
|
|
754
939
|
* service on another owner dies at attach with a RangeError naming its stream;
|
|
755
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.
|
|
756
943
|
*
|
|
757
944
|
* Durable by default: each commit writes a pending mark for its bindings in
|
|
758
945
|
* the same transaction, so an eviction or a deploy between the commit and the
|
|
@@ -762,13 +949,13 @@ interface WakeupHost {
|
|
|
762
949
|
* A wake during backoff waits; a stopped timer fires late after retry or restart.
|
|
763
950
|
* Return a time after unit.due to avoid repeatedly running a passed deadline.
|
|
764
951
|
*/
|
|
765
|
-
declare const attach: <I extends InputMap, E, R, Q, Result, P, OR = never, HE = never, HR = never>(projection: Attachable<Executable<I, E, R, Q, Result, P, unknown, OR>, HE, HR>, options?: AttachOptions) => Effect.Effect<{
|
|
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<{
|
|
766
953
|
name: string;
|
|
767
|
-
next: Effect.Effect<Option.Option<number>, import("@streamsy/core").StorageFault,
|
|
954
|
+
next: Effect.Effect<Option.Option<number>, import("@streamsy/core").StorageFault, BR | OR | Q | InputServices<I>>;
|
|
768
955
|
retryable: typeof retryable;
|
|
769
956
|
run: Effect.Effect<{
|
|
770
957
|
more: boolean;
|
|
771
|
-
}, import("@streamsy/core").StorageFault, HR | OR | Q | InputServices<I> | Exclude<R, P>>;
|
|
958
|
+
}, import("@streamsy/core").StorageFault, BR | HR | OR | Q | InputServices<I> | Exclude<R, P>>;
|
|
772
959
|
bind: (bound: WakeupHost) => Effect.Effect<void, never, never>;
|
|
773
960
|
changed: Effect.Effect<void, never, never>;
|
|
774
961
|
retry: import("effect/Schedule").Schedule<unknown, unknown, never, never>;
|
|
@@ -777,4 +964,4 @@ declare const attach: <I extends InputMap, E, R, Q, Result, P, OR = never, HE =
|
|
|
777
964
|
export declare const ProjectionWakeup: {
|
|
778
965
|
attach: typeof attach;
|
|
779
966
|
};
|
|
780
|
-
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, 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 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 };
|
|
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 };
|