@streamsy/projection 0.12.0 → 0.14.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 +66 -31
- package/dist/checkpoint-store-BE0zelau.js +459 -0
- package/dist/{checkpoint-store-DCfrS4Fd.d.ts → checkpoint-store-Cy5myzCL.d.ts} +42 -7
- package/dist/checkpoint.d.ts +2 -2
- package/dist/checkpoint.js +1 -1
- package/dist/index.d.ts +253 -66
- package/dist/index.js +817 -188
- package/package.json +4 -4
- package/dist/checkpoint-store--bWf1qeP.js +0 -296
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-Cy5myzCL.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<R = never> {
|
|
48
|
+
readonly key: ProjectionKey;
|
|
49
|
+
readonly cleanup: Effect.Effect<void, ProjectionFault, R>;
|
|
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,23 +91,45 @@ 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;
|
|
86
|
-
readonly sql: SqlClient.SqlClient;
|
|
87
98
|
readonly withTransaction: <A, E, R>(body: Effect.Effect<A, E, R>) => Effect.Effect<A, E | ProjectionFault, R>;
|
|
88
99
|
}>;
|
|
89
|
-
/** The
|
|
100
|
+
/** The storage owner's transaction, used by Commit.transaction. */
|
|
90
101
|
export declare class Transaction extends Transaction_base {
|
|
91
|
-
/**
|
|
92
|
-
|
|
93
|
-
* storage host. A memory host has no SqlClient, so this Layer does not fit it.
|
|
94
|
-
*/
|
|
95
|
-
static readonly layer: Layer.Layer<Transaction, never, CommitBoundary | SqlClient.SqlClient>;
|
|
102
|
+
/** Join the commit boundary on a memory or SQL storage host. */
|
|
103
|
+
static readonly layer: Layer.Layer<Transaction, never, CommitBoundary>;
|
|
96
104
|
}
|
|
97
|
-
|
|
98
|
-
|
|
105
|
+
declare const TransactionCommitTypeId: unique symbol;
|
|
106
|
+
/** A commit that joins the storage owner's transaction and supplies no handler services. */
|
|
107
|
+
interface TransactionCommit<in Result, out Requires> extends Commit<Result, never, Requires> {
|
|
108
|
+
readonly [TransactionCommitTypeId]: true;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Commit the unit and checkpoint together on a memory or SQL storage host.
|
|
112
|
+
* A SqlClient used by the handler must be the storage owner's client for its
|
|
113
|
+
* statements to join the transaction.
|
|
114
|
+
*
|
|
115
|
+
* On the same client the unit joins the outer transaction without a savepoint.
|
|
116
|
+
* With two boundaries over one client, only the outer boundary's hooks and
|
|
117
|
+
* `committed` subscribers see the commit.
|
|
118
|
+
*
|
|
119
|
+
* On another SQL client the unit opens its own transaction. It commits first and
|
|
120
|
+
* survives an outer rollback. Use one client per database for nested work. With
|
|
121
|
+
* two clients on one database, SQLite can wait until it reports a busy lock.
|
|
122
|
+
* Postgres or MySQL can wait for a row lock that the outer transaction holds.
|
|
123
|
+
*
|
|
124
|
+
* Durable Object clients share the driver's transaction, so a second client
|
|
125
|
+
* joins the first. Using a second object's storage on one fiber is unsupported.
|
|
126
|
+
*/
|
|
127
|
+
declare const transaction: TransactionCommit<Result$1, CheckpointStore | Transaction>;
|
|
128
|
+
/**
|
|
129
|
+
* Clean up binding state in the owner's transaction on forget and retire.
|
|
130
|
+
* The boundary follows the same nesting rules as {@link transaction}.
|
|
131
|
+
*/
|
|
132
|
+
declare const transactionWithCleanup: <R>(cleanup: (key: ProjectionKey) => Effect.Effect<void, ProjectionFault, R>) => TransactionCommit<Result$1, CheckpointStore | Transaction | R>;
|
|
99
133
|
declare const producer: Commit<Accumulated<unknown, Readonly<Record<string, never>>> | Emitted<Readonly<Record<string, never>>>, never, CheckpointStore>;
|
|
100
134
|
declare const atLeastOnce: Commit<void | WakeAt, never, CheckpointStore>;
|
|
101
135
|
declare const withCompensation: {
|
|
@@ -103,8 +137,69 @@ declare const withCompensation: {
|
|
|
103
137
|
<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
138
|
};
|
|
105
139
|
declare namespace commit_d_exports {
|
|
106
|
-
export { Accumulated, Commit, Emitted, Folded, HandlerFailed, OutputBatch, Pending, TypeId, Variance, atLeastOnce, checkpoint, make, producer, transaction, withCompensation };
|
|
140
|
+
export { Accumulated, Commit, Emitted, Folded, HandlerFailed, OutputBatch, Pending, RetireRequest, TransactionCommit, TypeId$1 as TypeId, Variance, atLeastOnce, checkpoint, make, producer, transaction, transactionWithCleanup, withCompensation };
|
|
141
|
+
}
|
|
142
|
+
declare const TypeId: unique symbol;
|
|
143
|
+
interface PerGeneration<D extends StreamDeclaration, N extends string, By extends string = never> {
|
|
144
|
+
readonly [TypeId]: {
|
|
145
|
+
readonly route: D;
|
|
146
|
+
readonly param: N;
|
|
147
|
+
readonly shared: boolean;
|
|
148
|
+
readonly routeBy?: readonly By[];
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
type RoutedOutput = Input | PerGeneration<StreamDeclaration, string, string>;
|
|
152
|
+
type DeclaredParams<D> = D extends StreamRoute.StreamRoute<infer P, infer _A, infer _RD, infer _RE> ? P : {};
|
|
153
|
+
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;
|
|
154
|
+
/** Bind one numeric output route parameter to the projection's generation. */
|
|
155
|
+
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: {
|
|
156
|
+
readonly routeBy: readonly [By, ...By[]];
|
|
157
|
+
readonly shared?: false;
|
|
158
|
+
}): PerGeneration<D, N, By>;
|
|
159
|
+
declare function perGeneration<D extends StreamDeclaration, const N extends NumberParams<D>>(route: D, param: N, options?: {
|
|
160
|
+
readonly shared?: boolean;
|
|
161
|
+
readonly routeBy?: never;
|
|
162
|
+
}): PerGeneration<D, N>;
|
|
163
|
+
declare const isPerGeneration: (value: RoutedOutput) => value is PerGeneration<StreamDeclaration, string, string>;
|
|
164
|
+
declare const generationBinding: <D extends StreamDeclaration, N extends string, By extends string = never>(binding: PerGeneration<D, N, By>) => {
|
|
165
|
+
readonly route: D;
|
|
166
|
+
readonly param: N;
|
|
167
|
+
readonly shared: boolean;
|
|
168
|
+
readonly routeBy?: readonly By[] | undefined;
|
|
169
|
+
};
|
|
170
|
+
/** Private metadata on the bound value. */
|
|
171
|
+
declare const GenerationOutputs: unique symbol;
|
|
172
|
+
interface GenerationOutputBindings {
|
|
173
|
+
readonly [GenerationOutputs]?: ReadonlyMap<string, {
|
|
174
|
+
readonly shared: boolean;
|
|
175
|
+
}>;
|
|
107
176
|
}
|
|
177
|
+
/** Open one generation-owned stream in the current process transaction. */
|
|
178
|
+
interface RoutedHandle<A, Params, R> {
|
|
179
|
+
readonly open: (params: Params) => Effect.Effect<A, ProjectionFault, R>;
|
|
180
|
+
}
|
|
181
|
+
declare const RoutedOutputs: unique symbol;
|
|
182
|
+
interface RoutedDefinition<R> {
|
|
183
|
+
readonly matches: (streamId: string) => boolean;
|
|
184
|
+
readonly restore: (streamId: string) => Streamsy.Address<unknown, R> | undefined;
|
|
185
|
+
}
|
|
186
|
+
interface RoutedOutputBindings<R> {
|
|
187
|
+
readonly [RoutedOutputs]?: ReadonlyMap<string, RoutedDefinition<R>>;
|
|
188
|
+
}
|
|
189
|
+
type RoutedMap = Readonly<Record<string, RoutedOutput>>;
|
|
190
|
+
type StaticOutputMap = Readonly<Record<string, Input | PerGeneration<StreamDeclaration, string>>>;
|
|
191
|
+
type Item<T> = AddressOf<T> extends {
|
|
192
|
+
readonly collections: infer C extends StreamAddress.Collections;
|
|
193
|
+
} ? DurableState.Entry<C> : AddressOf<T> extends {
|
|
194
|
+
readonly codec: Schema.Codec<infer A, any, any, any>;
|
|
195
|
+
} ? A : never;
|
|
196
|
+
type Services<O extends RoutedMap> = { [K in keyof O]: AddressOf<O[K]> extends Streamsy.Address<any, infer R> ? R : never; }[keyof O];
|
|
197
|
+
interface BoundOutputs<R> extends GenerationOutputBindings, RoutedOutputBindings<R> {
|
|
198
|
+
readonly streams?: Readonly<Record<string, Streamsy.Address<unknown, R>>>;
|
|
199
|
+
readonly accepted?: Streamsy.Address<Streamsy.WakeEvent, R>;
|
|
200
|
+
}
|
|
201
|
+
/** Create the generation-bound outputs of one binding, using each output's owner. */
|
|
202
|
+
declare const createOutputs: <R>(bound: BoundOutputs<R>) => Effect.Effect<void, ProjectionFault, R>;
|
|
108
203
|
type StateSchema<A, I = unknown> = Schema.Codec<A, I>;
|
|
109
204
|
/** A value, or a function of the decoded params the projection was bound with. */
|
|
110
205
|
type Initial<A, P = Record<string, string>> = A | ((params: P) => A);
|
|
@@ -119,7 +214,7 @@ interface BoundState<A> {
|
|
|
119
214
|
readonly initial: () => A;
|
|
120
215
|
}
|
|
121
216
|
/** 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 {
|
|
217
|
+
interface Executable<I extends InputMap, E, R, Q, Result, P = never, S = unknown, OR = never> extends Identity, GenerationOutputBindings {
|
|
123
218
|
readonly inputs: I;
|
|
124
219
|
readonly state?: BoundState<S>;
|
|
125
220
|
readonly streams?: Readonly<Record<string, Streamsy.Address<unknown, OR>>>;
|
|
@@ -149,18 +244,17 @@ type Readable<Inputs extends InputMap, S, Q> = Identity & {
|
|
|
149
244
|
*/
|
|
150
245
|
declare const read: <Inputs extends InputMap, S = never, Q = never>(projection: Readable<Inputs, S, Q>) => Effect.Effect<Snapshot<StateValue<S>, Inputs>, ProjectionFault, Q>;
|
|
151
246
|
/** The part of a projection declaration that the attach runner reads. */
|
|
152
|
-
interface Attachable<B, HE = never, HR = never> {
|
|
247
|
+
interface Attachable<B, HE = never, HR = never, Params = DecodedParams> {
|
|
153
248
|
readonly retry?: {
|
|
154
249
|
readonly schedule?: Schedule.Schedule<unknown>;
|
|
155
250
|
readonly maxAttempts?: number;
|
|
156
251
|
onExhausted?(this: void, unit: Unit<unknown>, failure: RunnerFailure): Effect.Effect<void, HE, HR>;
|
|
157
252
|
} | undefined;
|
|
158
253
|
readonly id: string;
|
|
159
|
-
readonly version: number;
|
|
160
254
|
readonly generation: number;
|
|
161
255
|
readonly params: StreamRoute.ParamCodecs;
|
|
162
256
|
readonly inputs: Inputs;
|
|
163
|
-
at(params:
|
|
257
|
+
at(params: Params): B;
|
|
164
258
|
}
|
|
165
259
|
/** The result of one `pass`: one committed unit (`progress`), or no input or wake to commit. */
|
|
166
260
|
interface PassResult<Inputs extends InputMap = InputMap> {
|
|
@@ -319,20 +413,22 @@ type StreamDeclaration = StreamRoute.StreamRoute<any, any> & Streamsy.Any & {
|
|
|
319
413
|
/** A stream declaration, or a fixed address that `.at` does not rebind. */
|
|
320
414
|
type Input = StreamDeclaration | Streamsy.Address<any, any>;
|
|
321
415
|
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
|
|
416
|
+
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;
|
|
417
|
+
type Addresses<I extends RoutedMap> = { readonly [K in keyof I]: AddressOf<I[K]>; };
|
|
418
|
+
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>;
|
|
419
|
+
type HandlerOutputs<O extends RoutedMap> = { readonly [K in keyof O]: HandlerOutput<O[K]>; };
|
|
325
420
|
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
421
|
type InvalidInput<C extends StreamRoute.ParamCodecs, X> = X extends StreamDeclaration ? Invalid<C, DeclaredParams<X>> : never;
|
|
327
422
|
/** Every declaration's params must be projection params with the same type. */
|
|
328
423
|
type Within<C extends StreamRoute.ParamCodecs, I extends Inputs> = { readonly [K in keyof I]: InvalidInput<C, I[K]> extends never ? I[K] : never; };
|
|
329
424
|
type OneWithin<C extends StreamRoute.ParamCodecs, X> = InvalidInput<C, X> extends never ? X : never;
|
|
330
|
-
type
|
|
425
|
+
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>;
|
|
426
|
+
type OneOutputWithin<C extends StreamRoute.ParamCodecs, X> = InvalidOutput<C, X> extends never ? X : never;
|
|
427
|
+
type OutputsWithin<C extends StreamRoute.ParamCodecs, D extends RoutedMap> = { readonly [K in keyof D]: OneOutputWithin<C, D[K]>; };
|
|
331
428
|
/** Inert: `at` binds the params and returns the value runners take. */
|
|
332
429
|
interface Declaration<Codecs extends StreamRoute.ParamCodecs, Bound, HE = never, HR = never> {
|
|
333
430
|
readonly retry?: BindingRetry<StreamRoute.Params<Codecs>, HE, HR> | undefined;
|
|
334
431
|
readonly id: string;
|
|
335
|
-
readonly version: number;
|
|
336
432
|
readonly generation: number;
|
|
337
433
|
readonly params: Codecs;
|
|
338
434
|
/** The declared inputs, before `at` binds them. */
|
|
@@ -342,10 +438,10 @@ interface Declaration<Codecs extends StreamRoute.ParamCodecs, Bound, HE = never,
|
|
|
342
438
|
/** Tries declaration inputs in order. Shared inputs return only their declared subset. */
|
|
343
439
|
readonly parse: (id: string) => Option.Option<Partial<StreamRoute.Params<Codecs>>>;
|
|
344
440
|
}
|
|
345
|
-
type AcceptedServices<W> = W extends
|
|
441
|
+
type AcceptedServices<W> = W extends AcceptedOutput ? Services<{
|
|
346
442
|
accepted: W;
|
|
347
443
|
}> : never;
|
|
348
|
-
type AcceptedResult<Result, W> = W extends
|
|
444
|
+
type AcceptedResult<Result, W> = W extends AcceptedOutput ? Result extends Folded<infer A> ? Accumulated<A, {}> : Result extends WakeAt ? Emitted<{}> & Pick<WakeAt, "wakeAt"> : Emitted<{}> : Result;
|
|
349
445
|
/** Binding retry timing and budget, shared by both attach hosts. */
|
|
350
446
|
interface BindingRetry<Params, E = never, R = never> {
|
|
351
447
|
/**
|
|
@@ -366,13 +462,14 @@ interface BindingRetry<Params, E = never, R = never> {
|
|
|
366
462
|
interface Common<C extends StreamRoute.ParamCodecs, I extends Inputs, W = undefined, HE = never, HR = never> {
|
|
367
463
|
readonly retry?: BindingRetry<StreamRoute.Params<C>, HE, HR>;
|
|
368
464
|
readonly id: string;
|
|
369
|
-
readonly version?: number;
|
|
370
465
|
readonly generation?: number;
|
|
371
466
|
readonly params: C;
|
|
372
467
|
readonly inputs: I & Within<C, I>;
|
|
373
468
|
/** Publish accepted input offsets in this wake stream as part of each unit. */
|
|
374
|
-
readonly accepted?: W &
|
|
469
|
+
readonly accepted?: W & OneOutputWithin<C, W>;
|
|
375
470
|
}
|
|
471
|
+
/** Decoded params, keyed by name. */
|
|
472
|
+
type DecodedParams = Readonly<Record<string, unknown>>;
|
|
376
473
|
interface Committing<Result, P, Q> {
|
|
377
474
|
readonly commit: Commit<Result, P, Q>;
|
|
378
475
|
}
|
|
@@ -392,9 +489,8 @@ type WakeOutput<P = any> = StreamDeclaration & StreamRoute.StateRoute<P, Streams
|
|
|
392
489
|
readonly paramCodecs: StreamRoute.ParamCodecs;
|
|
393
490
|
};
|
|
394
491
|
interface WakeDefinition<C extends StreamRoute.ParamCodecs, I extends Input, O, W = undefined> {
|
|
395
|
-
readonly accepted?: W &
|
|
492
|
+
readonly accepted?: W & OneOutputWithin<C, W>;
|
|
396
493
|
readonly id: string;
|
|
397
|
-
readonly version?: number;
|
|
398
494
|
readonly generation?: number;
|
|
399
495
|
readonly params: C;
|
|
400
496
|
/** The one source stream. Its params must be projection params. */
|
|
@@ -425,12 +521,13 @@ type WakeDeclaration<C extends StreamRoute.ParamCodecs, I extends Input, O exten
|
|
|
425
521
|
* });
|
|
426
522
|
* ```
|
|
427
523
|
*/
|
|
428
|
-
declare function wake<C extends StreamRoute.ParamCodecs, const I extends Input, const O extends WakeOutput, W extends
|
|
524
|
+
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>;
|
|
525
|
+
type AcceptedOutput = WakeOutput | PerGeneration<WakeOutput, string>;
|
|
429
526
|
type Step<X, E = never, R = never> = X | Effect.Effect<X, E, R>;
|
|
430
527
|
/** Each output keeps its item type here; missing keys emit nothing. */
|
|
431
528
|
type Emits<O extends RoutedMap> = { readonly [K in keyof O]?: ReadonlyArray<Item<O[K]>>; };
|
|
432
529
|
/** 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
|
|
530
|
+
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
531
|
readonly state: StateDefinition<A, SI, StreamRoute.Params<C>>;
|
|
435
532
|
readonly fold: (state: NoInfer<A>, entry: Entry<Addresses<I>>, unit: Unit<StreamRoute.Params<C>>) => Step<A, E, R>;
|
|
436
533
|
}): StatefulDeclaration<C, I, A, E, R, Folded<A>, P, Q, AcceptedServices<W>, HE, HR>;
|
|
@@ -442,42 +539,51 @@ interface ProcessContext<Prepared = void> {
|
|
|
442
539
|
/** Binding run attempt, starting at 1. Always 1 under run and follow. */
|
|
443
540
|
readonly attempt: number;
|
|
444
541
|
}
|
|
445
|
-
/** The
|
|
542
|
+
/** The address or routed handle of each declared output. Open handles only inside `process`. */
|
|
446
543
|
interface OutputsContext<O extends RoutedMap> {
|
|
447
|
-
readonly outputs:
|
|
448
|
-
}
|
|
544
|
+
readonly outputs: HandlerOutputs<O>;
|
|
545
|
+
}
|
|
546
|
+
type TransactionBrand = Omit<TransactionCommit<never, never>, keyof Commit<never>>;
|
|
547
|
+
type WithTransactionCommit<D extends {
|
|
548
|
+
readonly at: (...args: never[]) => object;
|
|
549
|
+
}> = Omit<D, "at"> & {
|
|
550
|
+
readonly at: (...args: Parameters<D["at"]>) => ReturnType<D["at"]> & {
|
|
551
|
+
readonly commit: TransactionBrand;
|
|
552
|
+
};
|
|
553
|
+
};
|
|
449
554
|
/** Run side effects once per unit, including recorded wakes. Return wakeAt(time) to
|
|
450
555
|
* replace the timer, or void to clear it. Timers require atLeastOnce or transaction.
|
|
451
556
|
* 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
|
|
557
|
+
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
558
|
readonly outputs?: never;
|
|
454
559
|
readonly prepare?: (batch: Slices<Addresses<I>>, unit: Unit<StreamRoute.Params<C>>) => Effect.Effect<Prepared, PE, PR>;
|
|
455
560
|
readonly process: (batch: Slices<Addresses<I>>, unit: Unit<StreamRoute.Params<C>>, context: ProcessContext<Prepared>) => Effect.Effect<A, E, R>;
|
|
456
561
|
}): 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
|
|
562
|
+
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>, never, Q> & {
|
|
563
|
+
readonly commit: TransactionBrand;
|
|
458
564
|
readonly outputs: O & OutputsWithin<C, O>;
|
|
459
565
|
readonly prepare?: (batch: Slices<Addresses<I>>, unit: Unit<StreamRoute.Params<C>>, context: OutputsContext<O>) => Effect.Effect<Prepared, PE, PR>;
|
|
460
566
|
readonly process: (batch: Slices<Addresses<I>>, unit: Unit<StreamRoute.Params<C>>, context: ProcessContext<Prepared> & OutputsContext<O>) => Effect.Effect<A, E, R>;
|
|
461
|
-
}): OutputDeclaration<C, I, O, E | PE, R, TimerResult<A>,
|
|
567
|
+
}): WithTransactionCommit<OutputDeclaration<C, I, O, E | PE, R, TimerResult<A>, never, Q | PR, never, AcceptedServices<W>, HE, HR>>;
|
|
462
568
|
/** 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
|
|
569
|
+
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
570
|
readonly outputs: O & OutputsWithin<C, O>;
|
|
465
571
|
readonly emit: ((entry: Entry<Addresses<I>>, unit: Unit<StreamRoute.Params<C>>) => Step<X, E, R>) & (Exclude<keyof X, keyof O> extends never ? unknown : {
|
|
466
572
|
readonly undeclaredOutput: Exclude<keyof X, keyof O>;
|
|
467
573
|
});
|
|
468
574
|
}): 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
|
|
575
|
+
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
576
|
readonly outputs: O & OutputsWithin<C, O>;
|
|
471
577
|
readonly state: StateDefinition<A, SI, StreamRoute.Params<C>>;
|
|
472
578
|
};
|
|
473
579
|
/** Thread the value and collect outputs, once per entry. */
|
|
474
|
-
declare function mapAccum<C extends StreamRoute.ParamCodecs, I extends Inputs, const O extends
|
|
580
|
+
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
581
|
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
582
|
readonly undeclaredOutput: Exclude<keyof X, keyof O>;
|
|
477
583
|
});
|
|
478
584
|
}): AccumulatingDeclaration<C, I, O, A, E, R, P, Q, AcceptedServices<W>, HE, HR>;
|
|
479
585
|
/** 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
|
|
586
|
+
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
587
|
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
588
|
readonly undeclaredOutput: Exclude<keyof X, keyof O>;
|
|
483
589
|
});
|
|
@@ -505,7 +611,13 @@ interface FollowOptions extends RunOptions {
|
|
|
505
611
|
* `Projection.follow` span covers the whole stream.
|
|
506
612
|
*/
|
|
507
613
|
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 {
|
|
614
|
+
interface AttachOptions<Params = DecodedParams, E = never, R = never> {
|
|
615
|
+
/**
|
|
616
|
+
* Decoded params to consider for startup replay. Defaults to the checkpoint
|
|
617
|
+
* inventory when it is available. An explicit list uses this declaration's
|
|
618
|
+
* id and generation to check for existing checkpoints.
|
|
619
|
+
*/
|
|
620
|
+
readonly bindings?: Effect.Effect<ReadonlyArray<Params>, E, R>;
|
|
509
621
|
/**
|
|
510
622
|
* Fixed-address wake classes whose source ids request binding runs. A provided
|
|
511
623
|
* stream service on another storage owner is remote; an absent service or a
|
|
@@ -544,6 +656,8 @@ interface AttachOptions {
|
|
|
544
656
|
* subscribes to `Storage.committed` when it is built, so build it with the
|
|
545
657
|
* storage layer and before the app writes. For each written id, the input's
|
|
546
658
|
* `parse` gives the params, and the runner runs `projection.at(params)`.
|
|
659
|
+
* The background runner also queues startup replays from the checkpoint
|
|
660
|
+
* inventory or `options.bindings`.
|
|
547
661
|
*
|
|
548
662
|
* Use it on long-lived hosts (Bun, Node). On a Cloudflare object, use
|
|
549
663
|
* `ProjectionWakeup.attach(projection)`.
|
|
@@ -568,7 +682,7 @@ interface AttachOptions {
|
|
|
568
682
|
* );
|
|
569
683
|
* ```
|
|
570
684
|
*/
|
|
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
|
|
685
|
+
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
686
|
/** A bound value projection. Output items from its adapter are discarded. */
|
|
573
687
|
interface CurrentProjection<Inputs extends InputMap, S, E, R, Q> extends Identity {
|
|
574
688
|
readonly inputs: Inputs;
|
|
@@ -585,6 +699,52 @@ interface CurrentProjection<Inputs extends InputMap, S, E, R, Q> extends Identit
|
|
|
585
699
|
* Fold steps must be replayable. Pending ranges are read from committed offsets.
|
|
586
700
|
*/
|
|
587
701
|
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>>;
|
|
702
|
+
/**
|
|
703
|
+
* Lists the decoded params of bindings with live checkpoints in the selected store.
|
|
704
|
+
* By default it includes every generation of the declaration's id. The inventory
|
|
705
|
+
* reads every stored version slot, even with a generation filter.
|
|
706
|
+
* Each binding appears once, in unspecified order.
|
|
707
|
+
*
|
|
708
|
+
* Fails with `InvalidBinding` if live params cannot round-trip through the current
|
|
709
|
+
* codecs. On MySQL, listing fails while the range contains a legacy hashed key
|
|
710
|
+
* that has yet to be rewritten.
|
|
711
|
+
*/
|
|
712
|
+
declare const bindings: <C extends Readonly<Record<string, Schema.Codec<unknown, string, never, never>>>>(declaration: Pick<Declaration<C, unknown, never, never>, "id" | "params">, options?: {
|
|
713
|
+
readonly generation?: number;
|
|
714
|
+
} | undefined) => Effect.Effect<readonly StreamRoute.Params<C>[], InvalidBinding | ProjectionFault, CheckpointStore>;
|
|
715
|
+
declare const Tail: Schema.Struct<{
|
|
716
|
+
readonly stream: Schema.brand<Schema.String, "StreamId">;
|
|
717
|
+
readonly offset: Schema.brand<Schema.String, "Offset">;
|
|
718
|
+
readonly closed: Schema.Boolean;
|
|
719
|
+
}>;
|
|
720
|
+
/** A serializable vector of fixed source tails, keyed by input name. */
|
|
721
|
+
declare const Tails: Schema.$Record<Schema.String, Schema.Struct<{
|
|
722
|
+
readonly stream: Schema.brand<Schema.String, "StreamId">;
|
|
723
|
+
readonly offset: Schema.brand<Schema.String, "Offset">;
|
|
724
|
+
readonly closed: Schema.Boolean;
|
|
725
|
+
}>>;
|
|
726
|
+
type Tails<Inputs extends InputMap = InputMap> = { readonly [Name in keyof Inputs]: typeof Tail.Type; };
|
|
727
|
+
interface InputLag {
|
|
728
|
+
readonly committed: Offset;
|
|
729
|
+
readonly target: Offset;
|
|
730
|
+
/** True while the input needs an offset, a close, or settlement of a pinned range. */
|
|
731
|
+
readonly behind: boolean;
|
|
732
|
+
}
|
|
733
|
+
interface Lag<Inputs extends InputMap = InputMap> {
|
|
734
|
+
/** True when all source targets are committed and there is no pending unit. */
|
|
735
|
+
readonly caughtUp: boolean;
|
|
736
|
+
readonly inputs: { readonly [Name in keyof Inputs]: InputLag; };
|
|
737
|
+
}
|
|
738
|
+
type Sources<Inputs extends InputMap> = Pick<Identity, "id"> & {
|
|
739
|
+
readonly inputs: Inputs;
|
|
740
|
+
};
|
|
741
|
+
type Checkpointed<Inputs extends InputMap, Q> = Omit<Readable<Inputs, never, Q>, "state">;
|
|
742
|
+
/** Capture each resolved input head once. The vector can be reused while producers keep writing. */
|
|
743
|
+
declare const tails: <Inputs extends InputMap>(projection: Sources<Inputs>) => Effect.Effect<Tails<Inputs>, ProjectionFault, InputServices<Inputs>>;
|
|
744
|
+
/** Compare fixed source tails with one committed checkpoint, including processed closes. Checks source readiness only. */
|
|
745
|
+
declare const lag: <Inputs extends InputMap, Q>(projection: Checkpointed<Inputs, Q>, targets?: Tails<InputMap> | undefined) => Effect.Effect<Lag<Inputs>, ProjectionFault, Q | InputServices<Inputs>>;
|
|
746
|
+
/** Wait for one fixed vector of source tails. The caller controls the timeout. */
|
|
747
|
+
declare const caughtUp: <Inputs extends InputMap, Q>(projection: Checkpointed<Inputs, Q>, targets?: Tails<InputMap> | undefined) => Effect.Effect<void, ProjectionFault, Q | InputServices<Inputs>>;
|
|
588
748
|
interface DecideSpec<Inputs extends InputMap, K extends keyof Inputs, S, B, E, R> {
|
|
589
749
|
/** The input to append to. Its offset in the snapshot is the CAS token. */
|
|
590
750
|
readonly input: K;
|
|
@@ -616,20 +776,44 @@ declare class LostRace {
|
|
|
616
776
|
constructor(mismatch: OffsetMismatch);
|
|
617
777
|
}
|
|
618
778
|
/**
|
|
619
|
-
* Deletes
|
|
779
|
+
* Deletes a live checkpoint and marks its routed outputs as forgotten so retirement
|
|
780
|
+
* can still find them. Preserves retirement tombstones. Stop the follower first,
|
|
781
|
+
* or use a new generation.
|
|
782
|
+
* Pass the binding from `declaration.at(params)` for a routed projection. A bare
|
|
783
|
+
* key deletes the checkpoint and leaves the route records live.
|
|
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 RetiredStream {
|
|
791
|
+
/** The declared output name, or "@streamsy/accepted". */
|
|
792
|
+
readonly output: string;
|
|
793
|
+
readonly id: string;
|
|
794
|
+
readonly result: "removed" | "closed" | "absent" | "shared";
|
|
795
|
+
}
|
|
796
|
+
interface Retired {
|
|
797
|
+
readonly record: RetirementStatus;
|
|
798
|
+
/** Every wrapped output stream, sorted by output name and then stream id. */
|
|
799
|
+
readonly streams: ReadonlyArray<RetiredStream>;
|
|
800
|
+
}
|
|
801
|
+
interface Retirable<R, Q> extends ProjectionKey, BoundOutputs<R> {
|
|
802
|
+
readonly commit: Pick<Commit<never, never, Q>, "retire">;
|
|
803
|
+
}
|
|
804
|
+
/** Retire one binding and clean up its exclusively owned generation outputs. */
|
|
805
|
+
declare const retire: <C extends StreamRoute.ParamCodecs, R, Q, HE, HR>(declaration: Declaration<C, Retirable<R, Q>, HE, HR>, params: StreamRoute.Params<C>, options: {
|
|
806
|
+
readonly generation: number;
|
|
807
|
+
readonly streams?: StreamMode;
|
|
808
|
+
}) => Effect.Effect<Retired, ProjectionFault, R | Q>;
|
|
625
809
|
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 };
|
|
810
|
+
export { InputLag, Lag, PerGeneration, Registry, RegistryApi, Retired, RetiredStream, 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$1 as key, lag, mapAccum, mapAccumBatch, pass, perGeneration, process$1 as process, read, retire, run, tails, wake, wakeAt };
|
|
627
811
|
}
|
|
628
|
-
declare const key: (projection: Identity) => ProjectionKey;
|
|
812
|
+
declare const key$1: (projection: Identity) => ProjectionKey;
|
|
629
813
|
/** Runs each tagged entry in order and discards its success value. */
|
|
630
814
|
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
815
|
declare namespace state_table_d_exports {
|
|
632
|
-
export { Bound, Declaration$1 as Declaration, ListOptions, define, migrate, rebuild, reset };
|
|
816
|
+
export { Bound, Declaration$1 as Declaration, ListOptions, clear, define, migrate, rebuild, reset };
|
|
633
817
|
}
|
|
634
818
|
/** Create the SQLite row index at host startup, outside storage migrations. */
|
|
635
819
|
declare const migrate: (sql: SqlClient.SqlClient) => Effect.Effect<void, ProjectionFault | SqlError.SqlError, never>;
|
|
@@ -641,7 +825,6 @@ interface ListOptions {
|
|
|
641
825
|
/** A State stream bound to its params: a bound projection, plus the row reads and `sync`. */
|
|
642
826
|
interface Bound<C extends StreamAddress.Collections, R> {
|
|
643
827
|
readonly id: string;
|
|
644
|
-
readonly version: number;
|
|
645
828
|
readonly generation: number;
|
|
646
829
|
readonly params: Record<string, string>;
|
|
647
830
|
/** The State stream, read as stored JSON text. */
|
|
@@ -652,7 +835,7 @@ interface Bound<C extends StreamAddress.Collections, R> {
|
|
|
652
835
|
readonly commit: typeof transaction;
|
|
653
836
|
readonly process: (batch: Slices<{
|
|
654
837
|
readonly state: Streamsy.Address<string, R>;
|
|
655
|
-
}>) => Effect.Effect<void, ProjectionFault,
|
|
838
|
+
}>) => Effect.Effect<void, ProjectionFault, SqlClient.SqlClient | R>;
|
|
656
839
|
/** The row of `key`. `value` is undefined when the row is absent. */
|
|
657
840
|
readonly get: <K extends keyof C & string>(collection: K, key: string) => Effect.Effect<{
|
|
658
841
|
readonly offset: string;
|
|
@@ -675,7 +858,7 @@ interface Bound<C extends StreamAddress.Collections, R> {
|
|
|
675
858
|
/** The stream offset that the rows reflect. */
|
|
676
859
|
readonly offset: () => Effect.Effect<string, SqlError.SqlError, SqlClient.SqlClient>;
|
|
677
860
|
/** Apply the stream from the head of the table to its tail, in the caller's transaction. */
|
|
678
|
-
readonly sync: () => Effect.Effect<void, ProjectionFault,
|
|
861
|
+
readonly sync: () => Effect.Effect<void, ProjectionFault, SqlClient.SqlClient | R>;
|
|
679
862
|
}
|
|
680
863
|
/** The declaration of a State table. Runners and `attach` take it like any declaration. */
|
|
681
864
|
interface Declaration$1<Codecs extends StreamRoute.ParamCodecs, C extends StreamAddress.Collections, R> extends Omit<Declaration<Codecs, Bound<C, R>>, "inputs" | "parse"> {
|
|
@@ -693,8 +876,10 @@ 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, SqlClient.SqlClient | Transaction>;
|
|
696
881
|
/** Discard the index and replay the State stream atomically, retaining the binding checkpoint. */
|
|
697
|
-
declare const rebuild: <C extends StreamAddress.Collections, R>(table: Bound<C, R>) => Effect.Effect<void, ProjectionFault, R | Transaction>;
|
|
882
|
+
declare const rebuild: <C extends StreamAddress.Collections, R>(table: Bound<C, R>) => Effect.Effect<void, ProjectionFault, R | SqlClient.SqlClient | Transaction>;
|
|
698
883
|
/** Append a reset to the State stream. The next table run applies it. */
|
|
699
884
|
declare const reset: <C extends StreamAddress.Collections, R>(table: Bound<C, R>) => Effect.Effect<import("@streamsy/core").AppendResult, Streams.AppendFailure<{}>, R>;
|
|
700
885
|
declare const FoldByKeyError_base: Schema.Class<FoldByKeyError, Schema.TaggedStruct<"FoldByKeyError", {
|
|
@@ -717,7 +902,7 @@ type Output<C extends StreamAddress.Collections, R> = StreamAddress.StateAddress
|
|
|
717
902
|
*/
|
|
718
903
|
type Handler<C extends StreamAddress.Collections, O extends string, I extends InputMap, P, E, R, TR> = (batch: Slices<I>, unit: Unit<P>, context: {
|
|
719
904
|
readonly outputs: Readonly<Record<O, Output<C, TR>>>;
|
|
720
|
-
}) => Effect.Effect<void, E | FoldByKeyError | ProjectionFault, R | TR | SqlClient.SqlClient |
|
|
905
|
+
}) => Effect.Effect<void, E | FoldByKeyError | ProjectionFault, R | TR | SqlClient.SqlClient | StreamAddress.CollectionsDecodingServices<C> | StreamAddress.CollectionsEncodingServices<C>>;
|
|
721
906
|
interface Spec<C extends StreamAddress.Collections, K extends keyof C & string, O extends string, A, P, E, R> {
|
|
722
907
|
readonly output: O;
|
|
723
908
|
readonly collection: K;
|
|
@@ -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 };
|