@streamsy/projection 0.15.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -471
- package/dist/{checkpoint-store-BE0zelau.js → checkpoint-store-8FaC7V5x.js} +304 -106
- package/dist/checkpoint-store-C_Nipiyw.d.ts +317 -0
- package/dist/checkpoint.d.ts +1 -1
- package/dist/checkpoint.js +1 -1
- package/dist/index.d.ts +356 -212
- package/dist/index.js +1349 -721
- package/package.json +12 -12
- package/dist/checkpoint-store-Cy5myzCL.d.ts +0 -188
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { C as ItemOf, S as
|
|
1
|
+
import { A as RangeUnreproducible, B as Slices, C as InvalidWakeTime, D as ProjectionFault, E as OutputRejected, F as Entry, I as InputMap, L as InputServices, M as SupersededGeneration, N as TokenConflict, O as ProjectionFaultReason, P as UnsupportedComposition, R as ItemOf, S as InvalidSource, T as NotAttached, _ as HistoryUnavailable, a as Identity, b as InvalidBinding, c as ProjectionKey, d as RoutedStreamRecord, g as GenerationMismatch, h as Unit, j as RetiredGeneration, k as ProjectionFaultReasonTag, l as RetirementStatus, m as Range, n as CheckpointStore, o as ListedBinding, r as CheckpointStoreApi, s as Loaded, t as CheckpointRecord, u as RouteRecords, v as IdentityMismatch, w as NonRetryable, x as InvalidRecord, y as InputNotFound, z as Slice } from "./checkpoint-store-C_Nipiyw.js";
|
|
2
2
|
import { Cause, Context, Data, DateTime, Effect, Layer, Option, Pipeable, Schedule, Schema, Semaphore, Stream } from "effect";
|
|
3
|
-
import {
|
|
4
|
-
import { MarkFailure, ProjectionMarkSummary } from "@streamsy/core/internal";
|
|
3
|
+
import { Decided, Decision, DurableState, InvalidStreamParams, Offset, OffsetMismatch, OwnerId, StorageFault, StorageOwner, StreamAddress, StreamId, StreamsFault, Streamsy } from "@streamsy/core";
|
|
4
|
+
import { Bindable, MarkFailure, ProjectionMarkSummary } from "@streamsy/core/internal";
|
|
5
5
|
import { Reader, StreamRoute, Streams, Writer } from "@streamsy/core/protocol";
|
|
6
|
-
import {
|
|
6
|
+
import { SqlError } from "effect/sql";
|
|
7
7
|
interface RunOptions {
|
|
8
8
|
/** Maximum checkpoint transactions per call; absent means run to completion. */
|
|
9
9
|
readonly limit?: number;
|
|
@@ -15,7 +15,11 @@ interface WakeAt {
|
|
|
15
15
|
readonly _tag: "WakeAt";
|
|
16
16
|
readonly wakeAt: number;
|
|
17
17
|
}
|
|
18
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* Return this request from process; returning void clears the previous deadline. It never throws.
|
|
20
|
+
* A time that is not a non-negative safe integer in epoch milliseconds fails the unit with a
|
|
21
|
+
* `ProjectionFault` whose reason is `InvalidWakeTime`, before anything is committed.
|
|
22
|
+
*/
|
|
19
23
|
declare const wakeAt: (time: number | DateTime.DateTime) => WakeAt;
|
|
20
24
|
type Result$1 = void | WakeAt | Folded<unknown> | Emitted<OutputNames> | Accumulated<unknown, OutputNames>;
|
|
21
25
|
interface ResolvedOutput {
|
|
@@ -24,7 +28,7 @@ interface ResolvedOutput {
|
|
|
24
28
|
readonly shared: boolean;
|
|
25
29
|
} | undefined;
|
|
26
30
|
readonly service: {
|
|
27
|
-
readonly owner:
|
|
31
|
+
readonly owner: OwnerId;
|
|
28
32
|
readonly wire: Reader<StreamsFault> & Writer<StreamsFault>;
|
|
29
33
|
};
|
|
30
34
|
}
|
|
@@ -41,6 +45,12 @@ interface Commit<in Result, in Provides = never, out Requires = never> extends P
|
|
|
41
45
|
readonly load: (key: ProjectionKey) => Effect.Effect<Loaded, ProjectionFault, Requires>;
|
|
42
46
|
readonly apply: (pending: Pending<Result, Provides>) => Effect.Effect<void, ProjectionFault | HandlerFailed, Requires>;
|
|
43
47
|
readonly remove?: (key: ProjectionKey) => Effect.Effect<void, ProjectionFault, Requires>;
|
|
48
|
+
/**
|
|
49
|
+
* The generations and params with a live checkpoint for an id, from the store `load`
|
|
50
|
+
* reads. `Projection.attach` uses it for startup replay. Without it, or when it fails
|
|
51
|
+
* with `UnsupportedComposition`, startup replay needs explicit `bindings`.
|
|
52
|
+
*/
|
|
53
|
+
readonly list?: (id: string) => Effect.Effect<ReadonlyArray<ListedBinding>, ProjectionFault, Requires>;
|
|
44
54
|
/** Fence future checkpoint writes, then run cleanup even if the key was already retired. */
|
|
45
55
|
readonly retire?: (request: RetireRequest) => Effect.Effect<RetirementStatus, ProjectionFault, Requires>;
|
|
46
56
|
}
|
|
@@ -93,15 +103,6 @@ declare const Folded: Data.TaggedEnum.ConstructorFrom<Folded<unknown>, "_tag">,
|
|
|
93
103
|
* declare at-least-once. The guarantee must describe the actual write. */
|
|
94
104
|
declare const make: <Result, Provides = never, Requires = never>(options: Omit<Commit<Result, Provides, Requires>, typeof TypeId$1 | "pipe">) => Commit<Result, Provides, Requires>;
|
|
95
105
|
declare const checkpoint: Commit<Folded<unknown>, never, CheckpointStore>;
|
|
96
|
-
declare const Transaction_base: Context.ServiceClass<Transaction, "@streamsy/projection/Transaction", {
|
|
97
|
-
readonly owner: object;
|
|
98
|
-
readonly withTransaction: <A, E, R>(body: Effect.Effect<A, E, R>) => Effect.Effect<A, E | ProjectionFault, R>;
|
|
99
|
-
}>;
|
|
100
|
-
/** The storage owner's transaction, used by Commit.transaction. */
|
|
101
|
-
export declare class Transaction extends Transaction_base {
|
|
102
|
-
/** Join the commit boundary on a memory or SQL storage host. */
|
|
103
|
-
static readonly layer: Layer.Layer<Transaction, never, CommitBoundary>;
|
|
104
|
-
}
|
|
105
106
|
declare const TransactionCommitTypeId: unique symbol;
|
|
106
107
|
/** A commit that joins the storage owner's transaction and supplies no handler services. */
|
|
107
108
|
interface TransactionCommit<in Result, out Requires> extends Commit<Result, never, Requires> {
|
|
@@ -124,12 +125,12 @@ interface TransactionCommit<in Result, out Requires> extends Commit<Result, neve
|
|
|
124
125
|
* Durable Object clients share the driver's transaction, so a second client
|
|
125
126
|
* joins the first. Using a second object's storage on one fiber is unsupported.
|
|
126
127
|
*/
|
|
127
|
-
declare const transaction: TransactionCommit<Result$1,
|
|
128
|
+
declare const transaction: TransactionCommit<Result$1, StorageOwner>;
|
|
128
129
|
/**
|
|
129
130
|
* Clean up binding state in the owner's transaction on forget and retire.
|
|
130
131
|
* The boundary follows the same nesting rules as {@link transaction}.
|
|
131
132
|
*/
|
|
132
|
-
declare const transactionWithCleanup: <R>(cleanup: (key: ProjectionKey) => Effect.Effect<void, ProjectionFault, R>) => TransactionCommit<Result$1,
|
|
133
|
+
declare const transactionWithCleanup: <R>(cleanup: (key: ProjectionKey) => Effect.Effect<void, ProjectionFault, R>) => TransactionCommit<Result$1, StorageOwner | R>;
|
|
133
134
|
declare const producer: Commit<Accumulated<unknown, Readonly<Record<string, never>>> | Emitted<Readonly<Record<string, never>>>, never, CheckpointStore>;
|
|
134
135
|
declare const atLeastOnce: Commit<void | WakeAt, never, CheckpointStore>;
|
|
135
136
|
declare const withCompensation: {
|
|
@@ -139,6 +140,19 @@ declare const withCompensation: {
|
|
|
139
140
|
declare namespace commit_d_exports {
|
|
140
141
|
export { Accumulated, Commit, Emitted, Folded, HandlerFailed, OutputBatch, Pending, RetireRequest, TransactionCommit, TypeId$1 as TypeId, Variance, atLeastOnce, checkpoint, make, producer, transaction, transactionWithCleanup, withCompensation };
|
|
141
142
|
}
|
|
143
|
+
type StateSchema<A, I = unknown> = Schema.Codec<A, I>;
|
|
144
|
+
/** A value, or a function of the decoded params the projection was bound with. */
|
|
145
|
+
type Initial<A, P = Record<string, string>> = A | ((params: P) => A);
|
|
146
|
+
/** The `state:` field of a declaration. */
|
|
147
|
+
interface StateDefinition<A, I = unknown, P = Record<string, string>> {
|
|
148
|
+
readonly schema: StateSchema<A, I>;
|
|
149
|
+
readonly initial: Initial<A, P>;
|
|
150
|
+
}
|
|
151
|
+
/** The state of a bound projection. `initial` runs only when stored state is absent. */
|
|
152
|
+
interface BoundState<A> {
|
|
153
|
+
readonly schema: StateSchema<A>;
|
|
154
|
+
readonly initial: () => A;
|
|
155
|
+
}
|
|
142
156
|
declare const TypeId: unique symbol;
|
|
143
157
|
interface PerGeneration<D extends StreamDeclaration, N extends string, By extends string = never> {
|
|
144
158
|
readonly [TypeId]: {
|
|
@@ -174,51 +188,12 @@ interface GenerationOutputBindings {
|
|
|
174
188
|
readonly shared: boolean;
|
|
175
189
|
}>;
|
|
176
190
|
}
|
|
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>;
|
|
203
|
-
type StateSchema<A, I = unknown> = Schema.Codec<A, I>;
|
|
204
|
-
/** A value, or a function of the decoded params the projection was bound with. */
|
|
205
|
-
type Initial<A, P = Record<string, string>> = A | ((params: P) => A);
|
|
206
|
-
/** The `state:` field of a declaration. */
|
|
207
|
-
interface StateDefinition<A, I = unknown, P = Record<string, string>> {
|
|
208
|
-
readonly schema: StateSchema<A, I>;
|
|
209
|
-
readonly initial: Initial<A, P>;
|
|
210
|
-
}
|
|
211
|
-
/** The state of a bound projection. `initial` runs only when stored state is absent. */
|
|
212
|
-
interface BoundState<A> {
|
|
213
|
-
readonly schema: StateSchema<A>;
|
|
214
|
-
readonly initial: () => A;
|
|
215
|
-
}
|
|
216
191
|
/** Common bound declaration consumed by the kernel. */
|
|
217
192
|
interface Executable<I extends InputMap, E, R, Q, Result, P = never, S = unknown, OR = never> extends Identity, GenerationOutputBindings {
|
|
218
193
|
readonly inputs: I;
|
|
219
194
|
readonly state?: BoundState<S>;
|
|
220
195
|
readonly streams?: Readonly<Record<string, Streamsy.Address<unknown, OR>>>;
|
|
221
|
-
readonly accepted?: Streamsy.Address<Streamsy.
|
|
196
|
+
readonly accepted?: Streamsy.Address<Streamsy.FrontierEvent, OR>;
|
|
222
197
|
readonly commit: Commit<Result, P, Q>;
|
|
223
198
|
readonly prepare?: (batch: Slices<I>, unit: Unit) => Effect.Effect<unknown, E, Q>;
|
|
224
199
|
readonly process: (batch: Slices<I>, unit: Unit, encoded?: string, prepared?: unknown, attempt?: number) => Effect.Effect<Result, E, R | P>;
|
|
@@ -243,18 +218,72 @@ type Readable<Inputs extends InputMap, S, Q> = Identity & {
|
|
|
243
218
|
* value and every offset is the start of its input.
|
|
244
219
|
*/
|
|
245
220
|
declare const read: <Inputs extends InputMap, S = never, Q = never>(projection: Readable<Inputs, S, Q>) => Effect.Effect<Snapshot<StateValue<S>, Inputs>, ProjectionFault, Q>;
|
|
221
|
+
/** A Streamsy.frontierStream class. Use FrontierStream<{}> for a fixed-address trigger with no params. */
|
|
222
|
+
type FrontierStream<P = any> = StreamDeclaration & StreamRoute.StateRoute<P, Streamsy.FrontierStreamCollections> & {
|
|
223
|
+
readonly paramCodecs: StreamRoute.ParamCodecs;
|
|
224
|
+
};
|
|
225
|
+
interface FrontierDefinition<C extends StreamRoute.ParamCodecs, I extends Input, O> {
|
|
226
|
+
readonly id: string;
|
|
227
|
+
readonly generation?: number;
|
|
228
|
+
/** The param codecs. Omit them, or pass `{}`, for a projection without params. */
|
|
229
|
+
readonly params?: C;
|
|
230
|
+
/** The one source stream. Its params must be projection params. */
|
|
231
|
+
readonly input: I & OneWithin<C, I>;
|
|
232
|
+
/** The State declaration with frontier stream collections that gets the row. Its params must be projection params. */
|
|
233
|
+
readonly output: O & OneWithin<C, O>;
|
|
234
|
+
}
|
|
235
|
+
type FrontierDeclaration<C extends StreamRoute.ParamCodecs, I extends Input, O extends Input> = AccumulatingDeclaration<C, {
|
|
236
|
+
readonly source: I;
|
|
237
|
+
}, {
|
|
238
|
+
readonly wake: O;
|
|
239
|
+
}, null, never, never, never, CheckpointStore>;
|
|
240
|
+
/**
|
|
241
|
+
* A frontier projection: one source stream gives one keyed row in one frontier stream.
|
|
242
|
+
* Each unit appends one upsert `{ stream, offset, closed? }` with
|
|
243
|
+
* `Commit.producer`, so several source writes in one unit fold into one row,
|
|
244
|
+
* and a retry answers `Duplicate`. The producer creates a missing frontier stream
|
|
245
|
+
* on its own owner. A frontier stream on another owner must exist before the first
|
|
246
|
+
* append: its owner creates it at start. When the source is removed or
|
|
247
|
+
* expires, the binding appends a State delete for its row and forgets itself.
|
|
248
|
+
*
|
|
249
|
+
* The row is the one that `frontier: output` would publish for the source, except that a
|
|
250
|
+
* gone source deletes its row, so that triggers clear their outputs. Rows that a State
|
|
251
|
+
* source carries are not forwarded.
|
|
252
|
+
*
|
|
253
|
+
* ```ts
|
|
254
|
+
* const filesFrontier = Projection.frontier({
|
|
255
|
+
* id: "files-wake",
|
|
256
|
+
* params: { user: UserKey, folderId: FolderKey },
|
|
257
|
+
* input: Files,
|
|
258
|
+
* output: UserFrontier,
|
|
259
|
+
* });
|
|
260
|
+
* ```
|
|
261
|
+
*/
|
|
262
|
+
declare function frontier<C extends StreamRoute.ParamCodecs = {}, const I extends Input = Input, const O extends FrontierStream = FrontierStream>(definition: FrontierDefinition<C, I, O>): FrontierDeclaration<C, I, O>;
|
|
263
|
+
/**
|
|
264
|
+
* The binding of a declaration: `singleton` without params, `at(params)` otherwise. Method
|
|
265
|
+
* syntax: a declaration with typed params is assignable here.
|
|
266
|
+
*/
|
|
267
|
+
type AttachableBinding<B, Params = DecodedParams> = {
|
|
268
|
+
readonly singleton: B;
|
|
269
|
+
} | {
|
|
270
|
+
at(params: Params): B;
|
|
271
|
+
};
|
|
272
|
+
/** The part of a projection declaration that a runner reads to match and bind ids. */
|
|
273
|
+
interface Matchable {
|
|
274
|
+
readonly id: string;
|
|
275
|
+
readonly generation: number;
|
|
276
|
+
readonly params: StreamRoute.ParamCodecs;
|
|
277
|
+
readonly inputs: Inputs;
|
|
278
|
+
}
|
|
246
279
|
/** The part of a projection declaration that the attach runner reads. */
|
|
247
|
-
|
|
280
|
+
type Attachable<B, HE = never, HR = never, Params = DecodedParams> = Matchable & AttachableBinding<B, Params> & RetryOptions<HE, HR>;
|
|
281
|
+
interface RetryOptions<HE, HR> {
|
|
248
282
|
readonly retry?: {
|
|
249
283
|
readonly schedule?: Schedule.Schedule<unknown>;
|
|
250
284
|
readonly maxAttempts?: number;
|
|
251
285
|
onExhausted?(this: void, unit: Unit<unknown>, failure: RunnerFailure): Effect.Effect<void, HE, HR>;
|
|
252
286
|
} | undefined;
|
|
253
|
-
readonly id: string;
|
|
254
|
-
readonly generation: number;
|
|
255
|
-
readonly params: StreamRoute.ParamCodecs;
|
|
256
|
-
readonly inputs: Inputs;
|
|
257
|
-
at(params: Params): B;
|
|
258
287
|
}
|
|
259
288
|
/** The result of one `pass`: one committed unit (`progress`), or no input or wake to commit. */
|
|
260
289
|
interface PassResult<Inputs extends InputMap = InputMap> {
|
|
@@ -284,12 +313,13 @@ declare const pass: <Inputs extends InputMap, E, R, Q, Result, P, OR = never>(pr
|
|
|
284
313
|
declare const run: <Inputs extends InputMap, E, R, Q, Result, P, S = never, OR = never>(projection: Executable<Inputs, E, R, Q, Result, P, S, OR>, options?: RunOptions | undefined) => Effect.Effect<Progress<StateValue<S>, Inputs>, E | ProjectionFault, OR | Q | InputServices<Inputs> | Exclude<R, P>>;
|
|
285
314
|
/** Only identity and encoded params are needed; execution uses the runner's binding. */
|
|
286
315
|
type Binding = Pick<Identity, "id" | "params">;
|
|
287
|
-
type Declaration$2 =
|
|
316
|
+
type Declaration$2 = Matchable & AttachableBinding<Binding>;
|
|
288
317
|
/** Last failure of a binding, trigger stream or runner pass. */
|
|
289
318
|
interface RunnerFailure {
|
|
290
319
|
readonly at: number;
|
|
291
|
-
readonly
|
|
292
|
-
|
|
320
|
+
readonly isRetryable: boolean;
|
|
321
|
+
/** The `_tag` of the fault's reason, such as `TokenConflict`. */
|
|
322
|
+
readonly reason: Option.Option<ProjectionFaultReasonTag>;
|
|
293
323
|
readonly message: string;
|
|
294
324
|
}
|
|
295
325
|
/** Live binding observations with the binding's encoded params. */
|
|
@@ -377,7 +407,7 @@ interface RegistryApi {
|
|
|
377
407
|
* Use after a fold fix. The cursor survives restart in both durability modes.
|
|
378
408
|
* An unknown trigger stream dies with RangeError. First attach already reads from the start.
|
|
379
409
|
*/
|
|
380
|
-
readonly rescan: (target: string | Declaration$2, trigger:
|
|
410
|
+
readonly rescan: (target: string | Declaration$2, trigger: FrontierStream<{}> | string) => Effect.Effect<void, NotAttached | StorageFault>;
|
|
381
411
|
/**
|
|
382
412
|
* Wait for the attached identity's checkpoint, subscribing before the first read.
|
|
383
413
|
* Matching failed runs prompt a reread for committed progress. No timeout.
|
|
@@ -403,17 +433,39 @@ declare const Registry_base: Context.ServiceClass<Registry, "@streamsy/projectio
|
|
|
403
433
|
declare class Registry extends Registry_base {
|
|
404
434
|
/** Match a binding's projection id and encoded params, independent of key order. */
|
|
405
435
|
static readonly isFor: (binding: Binding) => (event: RunnerEvent) => boolean;
|
|
406
|
-
/**
|
|
407
|
-
|
|
436
|
+
/**
|
|
437
|
+
* The runners attached to the storage owner. The state lives on the owner, so this
|
|
438
|
+
* layer can sit anywhere beside the attach layers, and building it twice is harmless.
|
|
439
|
+
*/
|
|
440
|
+
static readonly layer: Layer.Layer<Registry, never, StorageOwner>;
|
|
408
441
|
}
|
|
409
|
-
/**
|
|
410
|
-
|
|
411
|
-
readonly
|
|
412
|
-
}
|
|
413
|
-
|
|
442
|
+
/** Open one generation-owned stream in the current process transaction. */
|
|
443
|
+
interface RoutedHandle<A, Params, R> {
|
|
444
|
+
readonly open: (params: Params) => Effect.Effect<A, ProjectionFault, R>;
|
|
445
|
+
}
|
|
446
|
+
declare const RoutedOutputs: unique symbol;
|
|
447
|
+
interface RoutedDefinition<R> {
|
|
448
|
+
readonly matches: (streamId: string) => boolean;
|
|
449
|
+
readonly restore: (streamId: string) => Streamsy.Address<unknown, R> | undefined;
|
|
450
|
+
}
|
|
451
|
+
interface RoutedOutputBindings<R> {
|
|
452
|
+
readonly [RoutedOutputs]?: ReadonlyMap<string, RoutedDefinition<R>>;
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* A stream declaration. A singleton stream gives its `singleton` address; a stream with params
|
|
456
|
+
* is bound with the projection params through `at(params)`.
|
|
457
|
+
*/
|
|
458
|
+
type StreamDeclaration = StreamRoute.StreamRoute<any, any> & Streamsy.Any & Bindable<any, Streamsy.Address<any, any>>;
|
|
459
|
+
/** A stream declaration, or a fixed address that binding does not change. */
|
|
414
460
|
type Input = StreamDeclaration | Streamsy.Address<any, any>;
|
|
415
461
|
type Inputs = Readonly<Record<string, Input>>;
|
|
416
|
-
|
|
462
|
+
/** The value a declaration binds to: its `singleton`, or the result of its `at(params)`. */
|
|
463
|
+
type BoundOf<D> = D extends {
|
|
464
|
+
readonly singleton: infer B;
|
|
465
|
+
} ? B : D extends {
|
|
466
|
+
readonly at: (...args: any) => infer B;
|
|
467
|
+
} ? B : never;
|
|
468
|
+
type AddressOf<X> = X extends PerGeneration<infer D, string, string> ? BoundOf<D> : X extends StreamDeclaration ? BoundOf<X> : X extends Streamsy.Address<any, any> ? X : never;
|
|
417
469
|
type Addresses<I extends RoutedMap> = { readonly [K in keyof I]: AddressOf<I[K]>; };
|
|
418
470
|
type HandlerOutput<X> = X extends PerGeneration<infer D, string, infer By> ? [By] extends [never] ? AddressOf<X> : string extends By ? AddressOf<X> | RoutedHandle<AddressOf<X>, DecodedParams, D["Identifier"]> : RoutedHandle<AddressOf<X>, Pick<DeclaredParams<D>, By & keyof DeclaredParams<D>>, D["Identifier"]> : AddressOf<X>;
|
|
419
471
|
type HandlerOutputs<O extends RoutedMap> = { readonly [K in keyof O]: HandlerOutput<O[K]>; };
|
|
@@ -425,23 +477,58 @@ type OneWithin<C extends StreamRoute.ParamCodecs, X> = InvalidInput<C, X> extend
|
|
|
425
477
|
type InvalidOutput<C extends StreamRoute.ParamCodecs, X> = X extends PerGeneration<infer D, infer N, infer By> ? Extract<N | By, keyof C> | Invalid<C, Omit<DeclaredParams<D>, N | By>> : InvalidInput<C, X>;
|
|
426
478
|
type OneOutputWithin<C extends StreamRoute.ParamCodecs, X> = InvalidOutput<C, X> extends never ? X : never;
|
|
427
479
|
type OutputsWithin<C extends StreamRoute.ParamCodecs, D extends RoutedMap> = { readonly [K in keyof D]: OneOutputWithin<C, D[K]>; };
|
|
428
|
-
/**
|
|
429
|
-
|
|
480
|
+
/**
|
|
481
|
+
* True when a param codec record names no parameter: the declaration is a singleton. The type
|
|
482
|
+
* reads the record's keys and the run time reads its entries, so a record typed wider than its
|
|
483
|
+
* value, such as `const codecs: StreamRoute.ParamCodecs = {}`, gives `false` here but a singleton
|
|
484
|
+
* at run time. `declare` gives such a singleton `at` and `resolve` too, so the typed members work.
|
|
485
|
+
*/
|
|
486
|
+
type IsSingletonParams<Codecs> = [keyof Codecs] extends [never] ? true : false;
|
|
487
|
+
/**
|
|
488
|
+
* The binding members of a declaration. A declaration without params has `singleton`, its bound
|
|
489
|
+
* value. A declaration with params has `at(params)` and `resolve(params)`.
|
|
490
|
+
*
|
|
491
|
+
* At run time a declaration whose codec record is empty also has non-enumerable `at` and
|
|
492
|
+
* `resolve`. They ignore their argument and give the `singleton` value, so a record typed wider
|
|
493
|
+
* than its value, such as `const codecs: StreamRoute.ParamCodecs = {}`, still binds through the
|
|
494
|
+
* `at` its type has. A record typed narrower than its value, such as `const codecs: {} = { id }`,
|
|
495
|
+
* has the `singleton` type but only `at` and `resolve` at run time.
|
|
496
|
+
*/
|
|
497
|
+
type DeclarationBindings<Codecs extends StreamRoute.ParamCodecs, Bound> = IsSingletonParams<Codecs> extends true ? {
|
|
498
|
+
/** The bound value of this declaration without params. One cached object. */
|
|
499
|
+
readonly singleton: Bound;
|
|
500
|
+
} : {
|
|
501
|
+
/**
|
|
502
|
+
* Bind the params. Throws a `RangeError` when a param does not encode or cannot form an
|
|
503
|
+
* input or output stream id; its `cause` is the `InvalidStreamParams`. Use `resolve` for
|
|
504
|
+
* request values.
|
|
505
|
+
*/
|
|
506
|
+
readonly at: (params: StreamRoute.Params<Codecs>) => Bound;
|
|
507
|
+
/** Bind the params, or fail with `InvalidStreamParams`. Never throws. */
|
|
508
|
+
readonly resolve: (params: StreamRoute.Params<Codecs>) => Effect.Effect<Bound, InvalidStreamParams>;
|
|
509
|
+
};
|
|
510
|
+
/** The members of a declaration other than its binding. */
|
|
511
|
+
interface DeclarationCore<Codecs extends StreamRoute.ParamCodecs, HE = never, HR = never> {
|
|
430
512
|
readonly retry?: BindingRetry<StreamRoute.Params<Codecs>, HE, HR> | undefined;
|
|
431
513
|
readonly id: string;
|
|
432
514
|
readonly generation: number;
|
|
433
515
|
readonly params: Codecs;
|
|
434
|
-
/** The declared inputs, before
|
|
516
|
+
/** The declared inputs, before binding. */
|
|
435
517
|
readonly inputs: Inputs;
|
|
436
|
-
/** Throws a RangeError when a param does not encode. */
|
|
437
|
-
readonly at: (params: StreamRoute.Params<Codecs>) => Bound;
|
|
438
518
|
/** Tries declaration inputs in order. Shared inputs return only their declared subset. */
|
|
439
519
|
readonly parse: (id: string) => Option.Option<Partial<StreamRoute.Params<Codecs>>>;
|
|
440
520
|
}
|
|
441
|
-
|
|
442
|
-
|
|
521
|
+
/**
|
|
522
|
+
* Inert: `singleton`, or `at(params)` for a declaration with params, gives the bound value that
|
|
523
|
+
* runners take.
|
|
524
|
+
*/
|
|
525
|
+
type Declaration<Codecs extends StreamRoute.ParamCodecs, Bound, HE = never, HR = never> = DeclarationCore<Codecs, HE, HR> & DeclarationBindings<Codecs, Bound>;
|
|
526
|
+
/** The services of a frontier stream. `frontier: true` and no frontier need none. */
|
|
527
|
+
type FrontierServices<W> = W extends FrontierOutput ? Services<{
|
|
528
|
+
frontier: W;
|
|
443
529
|
}> : never;
|
|
444
|
-
|
|
530
|
+
/** A frontier stream adds an output batch, so the Commit sees an output-writing result. */
|
|
531
|
+
type FrontierResult<Result, W> = W extends FrontierOutput ? Result extends Folded<infer A> ? Accumulated<A, {}> : Result extends WakeAt ? Emitted<{}> & Pick<WakeAt, "wakeAt"> : Emitted<{}> : Result;
|
|
445
532
|
/** Binding retry timing and budget, shared by both attach hosts. */
|
|
446
533
|
interface BindingRetry<Params, E = never, R = never> {
|
|
447
534
|
/**
|
|
@@ -460,77 +547,84 @@ interface BindingRetry<Params, E = never, R = never> {
|
|
|
460
547
|
readonly onExhausted?: (unit: Unit<Params>, failure: RunnerFailure) => Effect.Effect<void, E, R>;
|
|
461
548
|
}
|
|
462
549
|
interface Common<C extends StreamRoute.ParamCodecs, I extends Inputs, W = undefined, HE = never, HR = never> {
|
|
463
|
-
readonly retry?: BindingRetry<StreamRoute.Params<C
|
|
550
|
+
readonly retry?: BindingRetry<StreamRoute.Params<NoInfer<C>>, HE, HR>;
|
|
464
551
|
readonly id: string;
|
|
465
552
|
readonly generation?: number;
|
|
466
|
-
|
|
553
|
+
/** The param codecs. Omit them, or pass `{}`, for a declaration without params. */
|
|
554
|
+
readonly params?: C;
|
|
467
555
|
readonly inputs: I & Within<C, I>;
|
|
468
|
-
/**
|
|
469
|
-
|
|
556
|
+
/**
|
|
557
|
+
* Publish the input offsets each unit accepted as frontier rows. `true` appends them to each
|
|
558
|
+
* fixed State output with a frontier collection; a frontier stream gets them as part of the
|
|
559
|
+
* unit. `true` is only allowed on the emit kinds.
|
|
560
|
+
*/
|
|
561
|
+
readonly frontier?: W & OneOutputWithin<C, W>;
|
|
470
562
|
}
|
|
471
563
|
/** Decoded params, keyed by name. */
|
|
472
564
|
type DecodedParams = Readonly<Record<string, unknown>>;
|
|
473
565
|
interface Committing<Result, P, Q> {
|
|
474
566
|
readonly commit: Commit<Result, P, Q>;
|
|
475
567
|
}
|
|
476
|
-
|
|
568
|
+
/** The bound value of a running declaration. */
|
|
569
|
+
type RunningBound<I extends Inputs, E, R, Result, P, Q, S = never, OR = never> = Omit<Executable<Addresses<I>, E | ProjectionFault, R, Q, Result, P, S, OR>, "process" | "prepare" | "state"> & {
|
|
477
570
|
readonly state: [S] extends [never] ? undefined : BoundState<S>;
|
|
478
571
|
readonly process: (batch: Slices<Addresses<I>>, unit: Unit, encoded?: string) => Effect.Effect<Result, E | ProjectionFault, R>;
|
|
479
|
-
}
|
|
572
|
+
};
|
|
573
|
+
type RunningDeclaration<C extends StreamRoute.ParamCodecs, I extends Inputs, E, R, Result, P, Q, S = never, OR = never, HE = never, HR = never> = Declaration<C, RunningBound<I, E, R, Result, P, Q, S, OR>, HE, HR>;
|
|
480
574
|
type StatefulDeclaration<C extends StreamRoute.ParamCodecs, I extends Inputs, A, E, R, Result, P, Q, OR = never, HE = never, HR = never> = RunningDeclaration<C, I, E, R, Result, P, Q, A, OR, HE, HR>;
|
|
481
|
-
type OutputDeclaration<C extends StreamRoute.ParamCodecs, I extends Inputs, O extends RoutedMap, E, R, Result, P, Q, A = never, OR = never, HE = never, HR = never> =
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
575
|
+
type OutputDeclaration<C extends StreamRoute.ParamCodecs, I extends Inputs, O extends RoutedMap, E, R, Result, P, Q, A = never, OR = never, HE = never, HR = never> = Declaration<C, OutputBound<I, O, E, R, Result, P, Q, A, OR>, HE, HR>;
|
|
576
|
+
/** The bound value of a declaration with outputs: a running binding plus its output streams. */
|
|
577
|
+
type OutputBound<I extends Inputs, O extends RoutedMap, E, R, Result, P, Q, A = never, OR = never> = RunningBound<I, E, R, Result, P, Q, A, Services<O> | OR> & {
|
|
578
|
+
readonly streams: Readonly<Record<string, Streamsy.Address<unknown, Services<O> | OR>>>;
|
|
485
579
|
};
|
|
486
580
|
type AccumulatingDeclaration<C extends StreamRoute.ParamCodecs, I extends Inputs, O extends RoutedMap, A, E, R, P, Q, OR = never, HE = never, HR = never> = OutputDeclaration<C, I, O, E, R, Accumulated<A, O>, P, Q, A, OR, HE, HR>;
|
|
487
|
-
|
|
488
|
-
type
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
readonly
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
readonly
|
|
498
|
-
|
|
499
|
-
|
|
581
|
+
type RoutedMap = Readonly<Record<string, RoutedOutput>>;
|
|
582
|
+
type StaticOutputMap = Readonly<Record<string, Input | PerGeneration<StreamDeclaration, string>>>;
|
|
583
|
+
type Item<T> = AddressOf<T> extends {
|
|
584
|
+
readonly collections: infer C extends DurableState.Collections;
|
|
585
|
+
} ? DurableState.Entry<C> : AddressOf<T> extends {
|
|
586
|
+
readonly codec: Schema.Codec<infer A, any, any, any>;
|
|
587
|
+
} ? A : never;
|
|
588
|
+
type Services<O extends RoutedMap> = { [K in keyof O]: AddressOf<O[K]> extends Streamsy.Address<any, infer R> ? R : never; }[keyof O];
|
|
589
|
+
interface BoundOutputs<R> extends GenerationOutputBindings, RoutedOutputBindings<R> {
|
|
590
|
+
readonly streams?: Readonly<Record<string, Streamsy.Address<unknown, R>>>;
|
|
591
|
+
readonly accepted?: Streamsy.Address<Streamsy.FrontierEvent, R>;
|
|
592
|
+
}
|
|
593
|
+
/** Create the generation-bound outputs of one binding, using each output's owner. */
|
|
594
|
+
declare const createOutputs: <R>(bound: BoundOutputs<R>) => Effect.Effect<void, ProjectionFault, R>;
|
|
595
|
+
/** A frontier stream: a `Streamsy.frontierStream` class, or `Projection.perGeneration` of one. */
|
|
596
|
+
type FrontierOutput = FrontierStream | PerGeneration<FrontierStream, string>;
|
|
597
|
+
/** @internal Shared with View.circuit. */
|
|
598
|
+
export declare const isFrontierCollection: (collection: unknown) => boolean;
|
|
599
|
+
interface FrontierContext {
|
|
600
|
+
readonly commit: Pick<Commit<never>, "name">;
|
|
601
|
+
readonly params: StreamRoute.ParamCodecs;
|
|
602
|
+
readonly outputs?: RoutedMap | undefined;
|
|
603
|
+
readonly inputTemplates?: ReadonlyArray<string> | undefined;
|
|
500
604
|
}
|
|
501
|
-
type WakeDeclaration<C extends StreamRoute.ParamCodecs, I extends Input, O extends Input, W = undefined> = AccumulatingDeclaration<C, {
|
|
502
|
-
readonly source: I;
|
|
503
|
-
}, {
|
|
504
|
-
readonly wake: O;
|
|
505
|
-
}, null, never, never, never, CheckpointStore, AcceptedServices<W>>;
|
|
506
605
|
/**
|
|
507
|
-
*
|
|
508
|
-
*
|
|
509
|
-
* `Commit.producer`, so several source writes in one unit fold into one row,
|
|
510
|
-
* and a retry answers `Duplicate`. The producer creates a missing wake stream
|
|
511
|
-
* on its own owner. A wake stream on another owner must exist before the first
|
|
512
|
-
* append: its owner creates it at start. When the source is removed or
|
|
513
|
-
* expires, the binding appends a State delete for its row and forgets itself.
|
|
606
|
+
* Check the `frontier` option of a declaration. For `true`, answer the frontier collection
|
|
607
|
+
* of each output that gets the rows. A frontier stream answers `undefined`.
|
|
514
608
|
*
|
|
515
|
-
*
|
|
516
|
-
* const filesWake = Projection.wake({
|
|
517
|
-
* id: "files-wake",
|
|
518
|
-
* params: { user: UserKey, folderId: FolderKey },
|
|
519
|
-
* input: Files,
|
|
520
|
-
* output: UserWake,
|
|
521
|
-
* });
|
|
522
|
-
* ```
|
|
609
|
+
* @internal Shared with View.circuit.
|
|
523
610
|
*/
|
|
524
|
-
declare
|
|
525
|
-
|
|
611
|
+
export declare const validateFrontier: (frontier: true | FrontierOutput | undefined, context: FrontierContext) => ReadonlyMap<string, string> | undefined;
|
|
612
|
+
/**
|
|
613
|
+
* The frontier rows of one unit, for either destination: the rows its State inputs carry,
|
|
614
|
+
* then one row for each input that moved or closed. `closed` holds the inputs whose close an
|
|
615
|
+
* earlier unit recorded.
|
|
616
|
+
*
|
|
617
|
+
* @internal Shared with View.circuit.
|
|
618
|
+
*/
|
|
619
|
+
export declare const unitFrontiers: (inputs: InputMap, unit: Pick<Unit, "ranges">, batch: Slices<InputMap>, closed?: Readonly<Record<string, boolean>>) => ReadonlyArray<Streamsy.Frontier>;
|
|
526
620
|
type Step<X, E = never, R = never> = X | Effect.Effect<X, E, R>;
|
|
527
621
|
/** Each output keeps its item type here; missing keys emit nothing. */
|
|
528
622
|
type Emits<O extends RoutedMap> = { readonly [K in keyof O]?: ReadonlyArray<Item<O[K]>>; };
|
|
529
623
|
/** Fold one entry at a time. The default Commit saves state and offsets in one write. */
|
|
530
|
-
declare function fold<C extends StreamRoute.ParamCodecs, I extends Inputs, A, SI, E = never, R = never, P = never, Q = CheckpointStore, W extends
|
|
531
|
-
readonly state: StateDefinition<A, SI, StreamRoute.Params<C
|
|
532
|
-
readonly fold: (state: NoInfer<A>, entry: Entry<Addresses<I>>, unit: Unit<StreamRoute.Params<C
|
|
533
|
-
}): StatefulDeclaration<C, I, A, E, R, Folded<A>, P, Q,
|
|
624
|
+
declare function fold<C extends StreamRoute.ParamCodecs = {}, I extends Inputs = Inputs, A = never, SI = never, E = never, R = never, P = never, Q = CheckpointStore, W extends FrontierOutput | undefined = undefined, HE = never, HR = never>(definition: Common<C, I, W, HE, HR> & ([W] extends [undefined] ? Partial<Committing<FrontierResult<Folded<NoInfer<A>>, W>, P, Q>> : Committing<FrontierResult<Folded<NoInfer<A>>, W>, P, Q>) & {
|
|
625
|
+
readonly state: StateDefinition<A, SI, StreamRoute.Params<NoInfer<C>>>;
|
|
626
|
+
readonly fold: (state: NoInfer<A>, entry: Entry<Addresses<I>>, unit: Unit<StreamRoute.Params<NoInfer<C>>>) => Step<A, E, R>;
|
|
627
|
+
}): StatefulDeclaration<C, I, A, E, R, Folded<A>, P, Q, FrontierServices<W>, HE, HR>;
|
|
534
628
|
/** void unless the handler result can be a WakeAt. */
|
|
535
629
|
type TimerResult<A> = 0 extends 1 & A ? void : [Extract<A, WakeAt>] extends [never] ? void : void | WakeAt;
|
|
536
630
|
/** The third argument of `process`. */
|
|
@@ -544,50 +638,47 @@ interface OutputsContext<O extends RoutedMap> {
|
|
|
544
638
|
readonly outputs: HandlerOutputs<O>;
|
|
545
639
|
}
|
|
546
640
|
type TransactionBrand = Omit<TransactionCommit<never, never>, keyof Commit<never>>;
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
readonly commit: TransactionBrand;
|
|
552
|
-
};
|
|
553
|
-
};
|
|
641
|
+
/** A declaration whose bound value carries the transaction commit brand. */
|
|
642
|
+
type TransactionDeclaration<C extends StreamRoute.ParamCodecs, B, HE, HR> = Declaration<C, B & {
|
|
643
|
+
readonly commit: TransactionBrand;
|
|
644
|
+
}, HE, HR>;
|
|
554
645
|
/** Run side effects once per unit, including recorded wakes. Return wakeAt(time) to
|
|
555
646
|
* replace the timer, or void to clear it. Timers require atLeastOnce or transaction.
|
|
556
647
|
* prepare runs at least once, outside the transaction. */
|
|
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
|
|
648
|
+
declare function process$1<C extends StreamRoute.ParamCodecs = {}, I extends Inputs = Inputs, E = never, R = never, P = never, Q = never, Prepared = void, PE = never, PR = never, W extends FrontierOutput | undefined = undefined, HE = never, HR = never, A = void>(definition: Common<C, I, W, HE, HR> & Committing<FrontierResult<TimerResult<A>, W>, P, Q> & {
|
|
558
649
|
readonly outputs?: never;
|
|
559
|
-
readonly prepare?: (batch: Slices<Addresses<I>>, unit: Unit<StreamRoute.Params<C
|
|
560
|
-
readonly process: (batch: Slices<Addresses<I>>, unit: Unit<StreamRoute.Params<C
|
|
561
|
-
}): RunningDeclaration<C, I, E | PE, R, TimerResult<A>, P, Q | PR, never,
|
|
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
|
|
650
|
+
readonly prepare?: (batch: Slices<Addresses<I>>, unit: Unit<StreamRoute.Params<NoInfer<C>>>) => Effect.Effect<Prepared, PE, PR>;
|
|
651
|
+
readonly process: (batch: Slices<Addresses<I>>, unit: Unit<StreamRoute.Params<NoInfer<C>>>, context: ProcessContext<Prepared>) => Effect.Effect<A, E, R>;
|
|
652
|
+
}): RunningDeclaration<C, I, E | PE, R, TimerResult<A>, P, Q | PR, never, FrontierServices<W>, HE, HR>;
|
|
653
|
+
declare function process$1<C extends StreamRoute.ParamCodecs = {}, I extends Inputs = Inputs, const O extends RoutedMap = RoutedMap, E = never, R = never, Q = never, Prepared = void, PE = never, PR = never, W extends FrontierOutput | undefined = undefined, HE = never, HR = never, A = void>(definition: Common<C, I, W, HE, HR> & Committing<FrontierResult<TimerResult<A>, W>, never, Q> & {
|
|
563
654
|
readonly commit: TransactionBrand;
|
|
564
655
|
readonly outputs: O & OutputsWithin<C, O>;
|
|
565
|
-
readonly prepare?: (batch: Slices<Addresses<I>>, unit: Unit<StreamRoute.Params<C
|
|
566
|
-
readonly process: (batch: Slices<Addresses<I>>, unit: Unit<StreamRoute.Params<C
|
|
567
|
-
}):
|
|
656
|
+
readonly prepare?: (batch: Slices<Addresses<I>>, unit: Unit<StreamRoute.Params<NoInfer<C>>>, context: OutputsContext<O>) => Effect.Effect<Prepared, PE, PR>;
|
|
657
|
+
readonly process: (batch: Slices<Addresses<I>>, unit: Unit<StreamRoute.Params<NoInfer<C>>>, context: ProcessContext<Prepared> & OutputsContext<O>) => Effect.Effect<A, E, R>;
|
|
658
|
+
}): TransactionDeclaration<C, OutputBound<I, O, E | PE, R, TimerResult<A>, never, Q | PR, never, FrontierServices<W>>, HE, HR>;
|
|
568
659
|
/** Emit zero or more output items for each input entry, in entry order. */
|
|
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
|
|
660
|
+
declare function emit<C extends StreamRoute.ParamCodecs = {}, I extends Inputs = Inputs, const O extends StaticOutputMap = StaticOutputMap, X extends Emits<O> = Emits<O>, E = never, R = never, P = never, Q = never, W extends FrontierOutput | true | undefined = undefined, HE = never, HR = never>(definition: Common<C, I, W, HE, HR> & Committing<Emitted<NoInfer<O>>, P, Q> & {
|
|
570
661
|
readonly outputs: O & OutputsWithin<C, O>;
|
|
571
|
-
readonly emit: ((entry: Entry<Addresses<I>>, unit: Unit<StreamRoute.Params<C
|
|
662
|
+
readonly emit: ((entry: Entry<Addresses<I>>, unit: Unit<StreamRoute.Params<NoInfer<C>>>) => Step<X, E, R>) & (Exclude<keyof X, keyof O> extends never ? unknown : {
|
|
572
663
|
readonly undeclaredOutput: Exclude<keyof X, keyof O>;
|
|
573
664
|
});
|
|
574
|
-
}): OutputDeclaration<C, I, O, E, R, Emitted<O>, P, Q, never,
|
|
665
|
+
}): OutputDeclaration<C, I, O, E, R, Emitted<O>, P, Q, never, FrontierServices<W>, HE, HR>;
|
|
575
666
|
type Definition<C extends StreamRoute.ParamCodecs, I extends Inputs, O extends StaticOutputMap, A, SI, P, Q, W, HE, HR> = Common<C, I, W, HE, HR> & Committing<Accumulated<NoInfer<A>, NoInfer<O>>, P, Q> & {
|
|
576
667
|
readonly outputs: O & OutputsWithin<C, O>;
|
|
577
|
-
readonly state: StateDefinition<A, SI, StreamRoute.Params<C
|
|
668
|
+
readonly state: StateDefinition<A, SI, StreamRoute.Params<NoInfer<C>>>;
|
|
578
669
|
};
|
|
579
670
|
/** Thread the value and collect outputs, once per entry. */
|
|
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
|
|
581
|
-
readonly mapAccum: ((state: NoInfer<A>, entry: Entry<Addresses<I>>, unit: Unit<StreamRoute.Params<C
|
|
671
|
+
declare function mapAccum<C extends StreamRoute.ParamCodecs = {}, I extends Inputs = Inputs, const O extends StaticOutputMap = StaticOutputMap, A = never, SI = never, X extends Emits<O> = Emits<O>, E = never, R = never, P = never, Q = never, W extends FrontierOutput | true | undefined = undefined, HE = never, HR = never>(definition: Definition<C, I, O, A, SI, P, Q, W, HE, HR> & {
|
|
672
|
+
readonly mapAccum: ((state: NoInfer<A>, entry: Entry<Addresses<I>>, unit: Unit<StreamRoute.Params<NoInfer<C>>>) => Step<readonly [A, X], E, R>) & (Exclude<keyof X, keyof O> extends never ? unknown : {
|
|
582
673
|
readonly undeclaredOutput: Exclude<keyof X, keyof O>;
|
|
583
674
|
});
|
|
584
|
-
}): AccumulatingDeclaration<C, I, O, A, E, R, P, Q,
|
|
675
|
+
}): AccumulatingDeclaration<C, I, O, A, E, R, P, Q, FrontierServices<W>, HE, HR>;
|
|
585
676
|
/** Compute the next value and outputs once for the whole unit batch. */
|
|
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
|
|
587
|
-
readonly mapAccumBatch: ((state: NoInfer<A>, batch: Slices<Addresses<I>>, unit: Unit<StreamRoute.Params<C
|
|
677
|
+
declare function mapAccumBatch<C extends StreamRoute.ParamCodecs = {}, I extends Inputs = Inputs, const O extends StaticOutputMap = StaticOutputMap, A = never, SI = never, X extends Emits<O> = Emits<O>, E = never, R = never, P = never, Q = never, W extends FrontierOutput | true | undefined = undefined, HE = never, HR = never>(definition: Definition<C, I, O, A, SI, P, Q, W, HE, HR> & {
|
|
678
|
+
readonly mapAccumBatch: ((state: NoInfer<A>, batch: Slices<Addresses<I>>, unit: Unit<StreamRoute.Params<NoInfer<C>>>) => Step<readonly [A, X], E, R>) & (Exclude<keyof X, keyof O> extends never ? unknown : {
|
|
588
679
|
readonly undeclaredOutput: Exclude<keyof X, keyof O>;
|
|
589
680
|
});
|
|
590
|
-
}): AccumulatingDeclaration<C, I, O, A, E, R, P, Q,
|
|
681
|
+
}): AccumulatingDeclaration<C, I, O, A, E, R, P, Q, FrontierServices<W>, HE, HR>;
|
|
591
682
|
interface FollowOptions extends RunOptions {
|
|
592
683
|
/** Upper bound on one wake wait; default 30000. */
|
|
593
684
|
readonly repairIntervalMs?: number;
|
|
@@ -611,7 +702,9 @@ interface FollowOptions extends RunOptions {
|
|
|
611
702
|
* `Projection.follow` span covers the whole stream.
|
|
612
703
|
*/
|
|
613
704
|
declare const follow: <Inputs extends InputMap, E, R, Q, Result, P, S = never, OR = never>(projection: Executable<Inputs, E, R, Q, Result, P, S, OR>, options?: FollowOptions) => Stream.Stream<Progress<StateValue<S>, Inputs>, E | ProjectionFault, Exclude<R, P> | Q | OR | InputServices<Inputs>>;
|
|
614
|
-
|
|
705
|
+
/** The stream services of the trigger classes in `triggers`. */
|
|
706
|
+
type TriggerServices<T extends ReadonlyArray<FrontierStream<{}>>> = T[number]["Identifier"];
|
|
707
|
+
interface AttachOptions<Params = DecodedParams, E = never, R = never, T extends ReadonlyArray<FrontierStream<{}>> = ReadonlyArray<FrontierStream<{}>>> {
|
|
615
708
|
/**
|
|
616
709
|
* Decoded params to consider for startup replay. Defaults to the checkpoint
|
|
617
710
|
* inventory when it is available. An explicit list uses this declaration's
|
|
@@ -619,13 +712,13 @@ interface AttachOptions<Params = DecodedParams, E = never, R = never> {
|
|
|
619
712
|
*/
|
|
620
713
|
readonly bindings?: Effect.Effect<ReadonlyArray<Params>, E, R>;
|
|
621
714
|
/**
|
|
622
|
-
* Fixed-address
|
|
623
|
-
*
|
|
624
|
-
*
|
|
715
|
+
* Fixed-address frontier stream classes whose source ids request binding runs. Each class
|
|
716
|
+
* is a requirement of the attach layer. Its service on this storage owner is local; on
|
|
717
|
+
* another owner it is remote, so provide that class through Protocol.bind.
|
|
625
718
|
* Projection.attach follows remote triggers in scope; ProjectionWakeup.attach
|
|
626
719
|
* accepts only triggers on its own owner. Cursors persist in both modes.
|
|
627
720
|
*/
|
|
628
|
-
readonly triggers?:
|
|
721
|
+
readonly triggers?: T;
|
|
629
722
|
/** Units for each binding in one run. Default 100. */
|
|
630
723
|
readonly limit?: number;
|
|
631
724
|
/**
|
|
@@ -653,9 +746,10 @@ interface AttachOptions<Params = DecodedParams, E = never, R = never> {
|
|
|
653
746
|
}
|
|
654
747
|
/**
|
|
655
748
|
* Run a projection whenever a local commit writes one of its inputs. The layer
|
|
656
|
-
* subscribes to `
|
|
749
|
+
* subscribes to `StorageOwner.committed` when it is built, so build it with the
|
|
657
750
|
* storage layer and before the app writes. For each written id, the input's
|
|
658
|
-
* `parse` gives the params, and the runner runs `projection.at(params)
|
|
751
|
+
* `parse` gives the params, and the runner runs `projection.at(params)`, or
|
|
752
|
+
* `projection.singleton` for a projection without params.
|
|
659
753
|
* The background runner also queues startup replays from the checkpoint
|
|
660
754
|
* inventory or `options.bindings`.
|
|
661
755
|
*
|
|
@@ -668,7 +762,7 @@ interface AttachOptions<Params = DecodedParams, E = never, R = never> {
|
|
|
668
762
|
* window, and the layer runs due marks when it starts. Recorded process timers
|
|
669
763
|
* wake at their deadline; after host suspend, a capped wait rechecks within 30 s.
|
|
670
764
|
* Return a time after unit.due to avoid repeatedly running a passed deadline.
|
|
671
|
-
* Inputs on another owner can use local or remote
|
|
765
|
+
* Inputs on another owner can use local or remote frontier streams in `triggers`.
|
|
672
766
|
* A provided trigger service on another owner is read one page per pass outside
|
|
673
767
|
* the local transaction; durable marks and the page cursor then commit together.
|
|
674
768
|
* A scoped live-read follower signals new remote rows. Remote read failures use
|
|
@@ -677,12 +771,12 @@ interface AttachOptions<Params = DecodedParams, E = never, R = never> {
|
|
|
677
771
|
* an attached binding under `Projection.follow` too: use one writer per key.
|
|
678
772
|
*
|
|
679
773
|
* ```ts
|
|
680
|
-
* const app = Layer.mergeAll(Api, Projection.attach(
|
|
774
|
+
* const app = Layer.mergeAll(Api, Projection.attach(filesFrontier)).pipe(
|
|
681
775
|
* Layer.provideMerge(BunStorage.layer(streams, { path })),
|
|
682
776
|
* );
|
|
683
777
|
* ```
|
|
684
778
|
*/
|
|
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,
|
|
779
|
+
declare const attach$1: <I extends InputMap, E, R, Q, Result, P, OR = never, HE = never, HR = never, Params extends DecodedParams = DecodedParams, BE = never, BR = never, const T extends ReadonlyArray<FrontierStream<{}>> = readonly []>(projection: Attachable<Executable<I, E, R, Q, Result, P, unknown, OR>, HE, HR, Params>, options?: AttachOptions<NoInfer<Params>, BE, BR, T>) => Layer.Layer<never, never, StorageOwner | Exclude<R, P> | Q | OR | HR | InputServices<I> | BR | TriggerServices<T>>;
|
|
686
780
|
/** A bound value projection. Output items from its adapter are discarded. */
|
|
687
781
|
interface CurrentProjection<Inputs extends InputMap, S, E, R, Q> extends Identity {
|
|
688
782
|
readonly inputs: Inputs;
|
|
@@ -709,7 +803,7 @@ declare const current: <Inputs extends InputMap, S, E, R, Q>(projection: Current
|
|
|
709
803
|
* codecs. On MySQL, listing fails while the range contains a legacy hashed key
|
|
710
804
|
* that has yet to be rewritten.
|
|
711
805
|
*/
|
|
712
|
-
declare const bindings: <C extends Readonly<Record<string, Schema.Codec<unknown, string, never, never>>>>(declaration: Pick<Declaration<C, unknown
|
|
806
|
+
declare const bindings: <C extends Readonly<Record<string, Schema.Codec<unknown, string, never, never>>>>(declaration: Pick<Declaration<C, unknown>, "id" | "params">, options?: {
|
|
713
807
|
readonly generation?: number;
|
|
714
808
|
} | undefined) => Effect.Effect<readonly StreamRoute.Params<C>[], InvalidBinding | ProjectionFault, CheckpointStore>;
|
|
715
809
|
declare const Tail: Schema.Struct<{
|
|
@@ -760,12 +854,12 @@ interface DecideSpec<Inputs extends InputMap, K extends keyof Inputs, S, B, E, R
|
|
|
760
854
|
* Retry only this append's OffsetMismatch while the retry schedule allows.
|
|
761
855
|
*/
|
|
762
856
|
declare const decide: <Inputs extends InputMap, const K extends keyof Inputs & string, B, E, R, PE, PR, Q, S>(projection: CurrentProjection<Inputs, S, PE, PR, Q>, spec: DecideSpec<Inputs, K, S, B, E, R>) => Effect.Effect<Decided<B>, OffsetMismatch | Exclude<[Effect.Effect<Decision<B, ItemOf<Inputs[K]>>, E, R> | Effect.Effect<Snapshot<S, Inputs>, PE | ProjectionFault, PR | Q | InputServices<Inputs>> | Effect.Effect<{
|
|
763
|
-
readonly owner:
|
|
857
|
+
readonly owner: import("@streamsy/core").OwnerId;
|
|
764
858
|
readonly wire: import("@streamsy/core/protocol").Reader<import("@streamsy/core").StreamsFault> & import("@streamsy/core/protocol").Writer<import("@streamsy/core").StreamsFault>;
|
|
765
|
-
}, never, Inputs[K]["stream"]["Identifier"]> | Effect.Effect<import("@streamsy/core").AppendResult, import("@streamsy/core").AppendConflict | import("@streamsy/core").EncodeFault | LostRace | import("@streamsy/core").NotSupported | import("@streamsy/core").StorageFault | import("@streamsy/core").StreamBusy | import("@streamsy/core").StreamClosed | import("@streamsy/core").StreamGone | import("@streamsy/core").StreamNotFound | import("@streamsy/core").TransportFault, never>] extends [Effect.Effect<infer _A, infer E_1, infer _R>] ? E_1 : never, LostRace>, [Effect.Effect<Decision<B, ItemOf<Inputs[K]>>, E, R> | Effect.Effect<Snapshot<S, Inputs>, PE | ProjectionFault, PR | Q | InputServices<Inputs>> | Effect.Effect<{
|
|
766
|
-
readonly owner:
|
|
859
|
+
}, never, Inputs[K]["stream"]["Identifier"]> | Effect.Effect<import("@streamsy/core").AppendResult, import("@streamsy/core").AppendConflict | import("@streamsy/core").EncodeFault | LostRace | import("@streamsy/core").NotSupported | import("@streamsy/core").StorageFault | import("@streamsy/core").StreamBusy | import("@streamsy/core").StreamClosed | import("@streamsy/core").StreamGone | import("@streamsy/core").StreamNotFound | import("@streamsy/core").TransportFault, never> | Effect.Effect<string & import("effect/Brand").Brand<"Offset"> & import("effect/Brand").Brand<"StreamsyOffset">, ProjectionFault, never>] extends [Effect.Effect<infer _A, infer E_1, infer _R>] ? E_1 : never, LostRace>, [Effect.Effect<Decision<B, ItemOf<Inputs[K]>>, E, R> | Effect.Effect<Snapshot<S, Inputs>, PE | ProjectionFault, PR | Q | InputServices<Inputs>> | Effect.Effect<{
|
|
860
|
+
readonly owner: import("@streamsy/core").OwnerId;
|
|
767
861
|
readonly wire: import("@streamsy/core/protocol").Reader<import("@streamsy/core").StreamsFault> & import("@streamsy/core/protocol").Writer<import("@streamsy/core").StreamsFault>;
|
|
768
|
-
}, never, Inputs[K]["stream"]["Identifier"]> | Effect.Effect<import("@streamsy/core").AppendResult, import("@streamsy/core").AppendConflict | import("@streamsy/core").EncodeFault | LostRace | import("@streamsy/core").NotSupported | import("@streamsy/core").StorageFault | import("@streamsy/core").StreamBusy | import("@streamsy/core").StreamClosed | import("@streamsy/core").StreamGone | import("@streamsy/core").StreamNotFound | import("@streamsy/core").TransportFault, never>] extends [Effect.Effect<infer _A_1, infer _E, infer R_1>] ? R_1 : never>;
|
|
862
|
+
}, never, Inputs[K]["stream"]["Identifier"]> | Effect.Effect<import("@streamsy/core").AppendResult, import("@streamsy/core").AppendConflict | import("@streamsy/core").EncodeFault | LostRace | import("@streamsy/core").NotSupported | import("@streamsy/core").StorageFault | import("@streamsy/core").StreamBusy | import("@streamsy/core").StreamClosed | import("@streamsy/core").StreamGone | import("@streamsy/core").StreamNotFound | import("@streamsy/core").TransportFault, never> | Effect.Effect<string & import("effect/Brand").Brand<"Offset"> & import("effect/Brand").Brand<"StreamsyOffset">, ProjectionFault, never>] extends [Effect.Effect<infer _A_1, infer _E, infer R_1>] ? R_1 : never>;
|
|
769
863
|
/**
|
|
770
864
|
* Marks the `OffsetMismatch` of this call's own append. As in `Streams.decide`,
|
|
771
865
|
* only this error is retried: an `OffsetMismatch` that the caller's `decide`
|
|
@@ -779,8 +873,8 @@ declare class LostRace {
|
|
|
779
873
|
* Deletes a live checkpoint and marks its routed outputs as forgotten so retirement
|
|
780
874
|
* can still find them. Preserves retirement tombstones. Stop the follower first,
|
|
781
875
|
* or use a new generation.
|
|
782
|
-
* Pass the binding from `declaration.at(params)` for a
|
|
783
|
-
* key deletes the checkpoint and leaves the route records live.
|
|
876
|
+
* Pass the binding from `declaration.at(params)`, or `declaration.singleton`, for a
|
|
877
|
+
* routed projection. A bare key deletes the checkpoint and leaves the route records live.
|
|
784
878
|
* Delete stream outputs first, because forgetting restarts their producer sequences.
|
|
785
879
|
*/
|
|
786
880
|
declare const forget: <R>(projection: ProjectionKey & {
|
|
@@ -801,29 +895,45 @@ interface Retired {
|
|
|
801
895
|
interface Retirable<R, Q> extends ProjectionKey, BoundOutputs<R> {
|
|
802
896
|
readonly commit: Pick<Commit<never, never, Q>, "retire">;
|
|
803
897
|
}
|
|
804
|
-
|
|
805
|
-
|
|
898
|
+
interface RetireOptions {
|
|
899
|
+
/** The generation to retire. */
|
|
806
900
|
readonly generation: number;
|
|
901
|
+
/** Remove (the default) or close each exclusively owned generation output. */
|
|
807
902
|
readonly streams?: StreamMode;
|
|
808
|
-
}
|
|
903
|
+
}
|
|
904
|
+
/**
|
|
905
|
+
* The arguments of `retire` after the declaration: `options` alone for a declaration without
|
|
906
|
+
* params, and `params, options` otherwise.
|
|
907
|
+
*/
|
|
908
|
+
type RetireArgs<C extends StreamRoute.ParamCodecs> = IsSingletonParams<C> extends true ? [options: RetireOptions] : [params: StreamRoute.Params<C>, options: RetireOptions];
|
|
909
|
+
/**
|
|
910
|
+
* Retire one binding and clean up its exclusively owned generation outputs. A declaration
|
|
911
|
+
* without params takes no params argument: `retire(declaration, { generation })`.
|
|
912
|
+
*/
|
|
913
|
+
declare const retire: <C extends StreamRoute.ParamCodecs, R, Q, HE, HR>(declaration: Declaration<C, Retirable<R, Q>, HE, HR>, ...args: NoInfer<RetireArgs<C>>) => Effect.Effect<Retired, ProjectionFault, R | Q>;
|
|
809
914
|
declare namespace projection_d_exports {
|
|
810
|
-
export { InputLag, Lag, PerGeneration, Registry, RegistryApi, Retired, RetiredStream, RoutedHandle, RunnerEvent, RunnerFailure, RunnerStatus, Tails, WakeAt,
|
|
915
|
+
export { FrontierOutput, FrontierServices, FrontierStream, InputLag, Lag, PerGeneration, Registry, RegistryApi, RetireArgs, RetireOptions, Retired, RetiredStream, RoutedHandle, RunnerEvent, RunnerFailure, RunnerStatus, Tails, WakeAt, attach$1 as attach, bindings, caughtUp, createOutputs, current, decide, each, emit, fold, follow, forget, frontier, generationBinding, isPerGeneration, items, key$1 as key, lag, mapAccum, mapAccumBatch, pass, perGeneration, process$1 as process, read, retire, run, tails, wakeAt };
|
|
811
916
|
}
|
|
812
917
|
declare const key$1: (projection: Identity) => ProjectionKey;
|
|
813
918
|
/** Runs each tagged entry in order and discards its success value. */
|
|
814
919
|
declare const each: <Inputs extends InputMap, E, R, P = Record<string, string>>(handle: (entry: Entry<Inputs>, unit: Unit<P>) => Effect.Effect<unknown, E, R>) => ((batch: Slices<Inputs>, unit: Unit<P>) => Effect.Effect<void, E, R>);
|
|
815
920
|
declare namespace state_table_d_exports {
|
|
816
|
-
export { Bound, Declaration$1 as Declaration, ListOptions, clear, define, migrate, rebuild, reset };
|
|
921
|
+
export { Bound, Declaration$1 as Declaration, ListOptions, UnitRows, clear, define, migrate, rebuild, reset, unit };
|
|
817
922
|
}
|
|
818
|
-
/**
|
|
819
|
-
|
|
923
|
+
/**
|
|
924
|
+
* Create the row index on a SQL storage owner (SQLite, Postgres or MySQL) at host
|
|
925
|
+
* startup, outside storage migrations. A memory owner needs none, so it does nothing.
|
|
926
|
+
*/
|
|
927
|
+
declare const migrate: Effect.Effect<void, ProjectionFault | SqlError.SqlError, StorageOwner>;
|
|
820
928
|
/** Keyset pages are not snapshots. Follow changes from the first page's offset. */
|
|
821
929
|
interface ListOptions {
|
|
822
930
|
readonly after?: string | undefined;
|
|
823
931
|
readonly limit?: number | undefined;
|
|
824
932
|
}
|
|
933
|
+
/** Bound reads keep `SqlError` in their errors. Only SQL backends fail with it. */
|
|
934
|
+
type ReadError = SqlError.SqlError;
|
|
825
935
|
/** A State stream bound to its params: a bound projection, plus the row reads and `sync`. */
|
|
826
|
-
interface Bound<C extends
|
|
936
|
+
interface Bound<C extends DurableState.Collections, R> {
|
|
827
937
|
readonly id: string;
|
|
828
938
|
readonly generation: number;
|
|
829
939
|
readonly params: Record<string, string>;
|
|
@@ -831,21 +941,22 @@ interface Bound<C extends StreamAddress.Collections, R> {
|
|
|
831
941
|
readonly inputs: {
|
|
832
942
|
readonly state: Streamsy.Address<string, R>;
|
|
833
943
|
};
|
|
834
|
-
|
|
944
|
+
/** The frontier stream from `define`'s `frontier` option, if any. */
|
|
945
|
+
readonly accepted?: Streamsy.Address<Streamsy.FrontierEvent, R>;
|
|
835
946
|
readonly commit: typeof transaction;
|
|
836
947
|
readonly process: (batch: Slices<{
|
|
837
948
|
readonly state: Streamsy.Address<string, R>;
|
|
838
|
-
}>) => Effect.Effect<void, ProjectionFault,
|
|
949
|
+
}>) => Effect.Effect<void, ProjectionFault, StorageOwner | R>;
|
|
839
950
|
/** The row of `key`. `value` is undefined when the row is absent. */
|
|
840
951
|
readonly get: <K extends keyof C & string>(collection: K, key: string) => Effect.Effect<{
|
|
841
952
|
readonly offset: string;
|
|
842
953
|
readonly value: C[K]["schema"]["Type"] | undefined;
|
|
843
|
-
}, Schema.SchemaError |
|
|
954
|
+
}, Schema.SchemaError | ReadError, StorageOwner | C[K]["schema"]["DecodingServices"]>;
|
|
844
955
|
/** The rows of `keys` that exist, by key. */
|
|
845
956
|
readonly getMany: <K extends keyof C & string>(collection: K, keys: ReadonlyArray<string>) => Effect.Effect<{
|
|
846
957
|
readonly offset: string;
|
|
847
958
|
readonly rows: ReadonlyMap<string, C[K]["schema"]["Type"]>;
|
|
848
|
-
}, Schema.SchemaError |
|
|
959
|
+
}, Schema.SchemaError | ReadError, StorageOwner | C[K]["schema"]["DecodingServices"]>;
|
|
849
960
|
/** The rows in key order. `next` is the last key of a full page. */
|
|
850
961
|
readonly list: <K extends keyof C & string>(collection: K, options?: ListOptions) => Effect.Effect<{
|
|
851
962
|
readonly offset: string;
|
|
@@ -854,34 +965,67 @@ interface Bound<C extends StreamAddress.Collections, R> {
|
|
|
854
965
|
readonly value: C[K]["schema"]["Type"];
|
|
855
966
|
}>;
|
|
856
967
|
readonly next: string | undefined;
|
|
857
|
-
}, ProjectionFault | Schema.SchemaError |
|
|
968
|
+
}, ProjectionFault | Schema.SchemaError | ReadError, StorageOwner | C[K]["schema"]["DecodingServices"]>;
|
|
858
969
|
/** The stream offset that the rows reflect. */
|
|
859
|
-
readonly offset: () => Effect.Effect<string,
|
|
970
|
+
readonly offset: () => Effect.Effect<string, ReadError, StorageOwner>;
|
|
860
971
|
/** Apply the stream from the head of the table to its tail, in the caller's transaction. */
|
|
861
|
-
readonly sync: () => Effect.Effect<void, ProjectionFault,
|
|
972
|
+
readonly sync: () => Effect.Effect<void, ProjectionFault, StorageOwner | R>;
|
|
862
973
|
}
|
|
863
|
-
/**
|
|
864
|
-
|
|
974
|
+
/**
|
|
975
|
+
* The declaration of a State table. Runners and `attach` take it like any declaration. A table
|
|
976
|
+
* of a singleton State stream has `singleton`; one with params has `at(params)` and `resolve`.
|
|
977
|
+
*/
|
|
978
|
+
type Declaration$1<Codecs extends StreamRoute.ParamCodecs, C extends DurableState.Collections, R> = Omit<DeclarationCore<Codecs>, "inputs" | "parse"> & {
|
|
865
979
|
readonly inputs: {
|
|
866
980
|
readonly state: State<Codecs, C, R>;
|
|
867
981
|
};
|
|
868
982
|
readonly parse: (id: string) => Option.Option<StreamRoute.Params<Codecs>>;
|
|
869
|
-
}
|
|
870
|
-
/**
|
|
871
|
-
type
|
|
983
|
+
} & DeclarationBindings<Codecs, Bound<C, R>>;
|
|
984
|
+
/** The address of a `Streamsy.state` class with collections `C`, served by `R`. */
|
|
985
|
+
type StateBound<C extends DurableState.Collections, R> = StreamAddress.StateAddress<C> & Streamsy.Address<DurableState.CollectionsEvent<C>, R, DurableState.CollectionsDecodingServices<C>, DurableState.CollectionsEncodingServices<C>>;
|
|
986
|
+
/**
|
|
987
|
+
* A `Streamsy.state` class with param codecs `Codecs` and collections `C`, served by `R`: a
|
|
988
|
+
* singleton State stream with `singleton`, or one with params and `at(params)`.
|
|
989
|
+
*/
|
|
990
|
+
type State<Codecs extends StreamRoute.ParamCodecs, C extends DurableState.Collections, R> = StreamRoute.StateRoute<StreamRoute.Params<Codecs>, C> & Streamsy.Any & {
|
|
872
991
|
readonly paramCodecs: Codecs;
|
|
873
|
-
|
|
874
|
-
};
|
|
992
|
+
} & Bindable<StreamRoute.Params<Codecs>, StateBound<C, R>>;
|
|
875
993
|
/** A State stream's declaration, kept current by the ordinary projection runners. */
|
|
876
|
-
declare function define<Codecs extends StreamRoute.ParamCodecs, C extends
|
|
877
|
-
|
|
878
|
-
|
|
994
|
+
declare function define<Codecs extends StreamRoute.ParamCodecs, C extends DurableState.Collections, R, W extends FrontierStream | undefined = undefined>(state: State<Codecs, C, R>, options?: {
|
|
995
|
+
/**
|
|
996
|
+
* A frontier stream that gets one row for the State stream at each applied offset, and the
|
|
997
|
+
* frontier rows that the State stream carries.
|
|
998
|
+
*/
|
|
999
|
+
readonly frontier?: W & OneWithin<Codecs, W>;
|
|
1000
|
+
}): Declaration$1<Codecs, C, R | FrontierServices<W>>;
|
|
879
1001
|
/** Delete cached rows and their applied offset, even if the State stream has been removed. */
|
|
880
|
-
declare const clear: <C extends
|
|
1002
|
+
declare const clear: <C extends DurableState.Collections, R>(table: Bound<C, R>) => Effect.Effect<void, ProjectionFault, StorageOwner>;
|
|
881
1003
|
/** Discard the index and replay the State stream atomically, retaining the binding checkpoint. */
|
|
882
|
-
declare const rebuild: <C extends
|
|
1004
|
+
declare const rebuild: <C extends DurableState.Collections, R>(table: Bound<C, R>) => Effect.Effect<void, ProjectionFault, R | StorageOwner>;
|
|
883
1005
|
/** Append a reset to the State stream. The next table run applies it. */
|
|
884
|
-
declare const reset: <C extends
|
|
1006
|
+
declare const reset: <C extends DurableState.Collections, R>(table: Bound<C, R>) => Effect.Effect<import("@streamsy/core").AppendResult, Streams.AppendFailure<{}>, R>;
|
|
1007
|
+
/** The rows of one State stream as one unit sees them, and the changes the unit makes. */
|
|
1008
|
+
interface UnitRows<C extends DurableState.Collections> {
|
|
1009
|
+
/** Read the stored rows of these keys into the unit, 50 keys for each query. */
|
|
1010
|
+
readonly load: (collection: keyof C & string, keys: Iterable<string>) => Effect.Effect<void, ProjectionFault, StorageOwner>;
|
|
1011
|
+
/** The unit's own last write of the key, or else the stored row. A removed key gives undefined. */
|
|
1012
|
+
readonly get: <K extends keyof C & string>(collection: K, key: string) => Effect.Effect<C[K]["schema"]["Type"] | undefined, ProjectionFault, StorageOwner | C[K]["schema"]["DecodingServices"]>;
|
|
1013
|
+
/** Record an upsert. False when the row equals what `get` returns, and then nothing is recorded. */
|
|
1014
|
+
readonly upsert: <K extends keyof C & string>(collection: K, row: C[K]["schema"]["Type"], options?: {
|
|
1015
|
+
readonly headers?: DurableState.ChangeHeaders;
|
|
1016
|
+
}) => Effect.Effect<boolean, ProjectionFault, StorageOwner | C[K]["schema"]["EncodingServices"]>;
|
|
1017
|
+
/** Record a delete. False when the key has no row, and then nothing is recorded. */
|
|
1018
|
+
readonly remove: (collection: keyof C & string, key: string, options?: {
|
|
1019
|
+
readonly headers?: DurableState.ChangeHeaders;
|
|
1020
|
+
}) => Effect.Effect<boolean, ProjectionFault, StorageOwner>;
|
|
1021
|
+
/** The recorded changes in call order. Return them under the output's name. */
|
|
1022
|
+
readonly changes: () => ReadonlyArray<DurableState.Entry<C>>;
|
|
1023
|
+
}
|
|
1024
|
+
/**
|
|
1025
|
+
* Create a missing unwrapped output, call `sync`, and open the unit's rows. Call it once
|
|
1026
|
+
* for each unit, inside a `Commit.transaction` handler, and return `changes()`.
|
|
1027
|
+
*/
|
|
1028
|
+
declare const unit: <C extends DurableState.Collections, R>(table: Bound<C, R>) => Effect.Effect<UnitRows<C>, ProjectionFault, R | StorageOwner>;
|
|
885
1029
|
declare const FoldByKeyError_base: Schema.Class<FoldByKeyError, Schema.TaggedStruct<"FoldByKeyError", {
|
|
886
1030
|
readonly message: Schema.String;
|
|
887
1031
|
}>, import("effect/Cause").YieldableError & {
|
|
@@ -895,26 +1039,26 @@ declare namespace fold_by_key_d_exports {
|
|
|
895
1039
|
/** Return this from a fold to delete its row. The next record receives undefined. */
|
|
896
1040
|
declare const remove: unique symbol;
|
|
897
1041
|
type Remove = typeof remove;
|
|
898
|
-
type Output<C extends
|
|
1042
|
+
type Output<C extends DurableState.Collections, R> = StreamAddress.StateAddress<C> & Streamsy.Address<DurableState.CollectionsEvent<C>, R, DurableState.CollectionsDecodingServices<C>, DurableState.CollectionsEncodingServices<C>>;
|
|
899
1043
|
/**
|
|
900
1044
|
* A `Projection.process` handler for a declaration that lists the State stream
|
|
901
1045
|
* of the table in `outputs`, under the key `O`.
|
|
902
1046
|
*/
|
|
903
|
-
type Handler<C extends
|
|
1047
|
+
type Handler<C extends DurableState.Collections, O extends string, I extends InputMap, P, E, R, TR> = (batch: Slices<I>, unit: Unit<P>, context: {
|
|
904
1048
|
readonly outputs: Readonly<Record<O, Output<C, TR>>>;
|
|
905
|
-
}) => Effect.Effect<void, E | FoldByKeyError | ProjectionFault, R | TR |
|
|
906
|
-
interface Spec<C extends
|
|
1049
|
+
}) => Effect.Effect<void, E | FoldByKeyError | ProjectionFault, R | TR | StorageOwner | DurableState.CollectionsDecodingServices<C> | DurableState.CollectionsEncodingServices<C>>;
|
|
1050
|
+
interface Spec<C extends DurableState.Collections, K extends keyof C & string, O extends string, A, P, E, R> {
|
|
907
1051
|
readonly output: O;
|
|
908
1052
|
readonly collection: K;
|
|
909
1053
|
readonly key: (record: A, unit: Unit<P>) => string | undefined;
|
|
910
1054
|
readonly fold: (previous: C[K]["schema"]["Type"] | undefined, record: A, unit: Unit<P>) => Step<C[K]["schema"]["Type"] | Remove, E, R>;
|
|
911
1055
|
}
|
|
912
|
-
type Expanded<C extends
|
|
1056
|
+
type Expanded<C extends DurableState.Collections, K extends keyof C & string, O extends string, I extends InputMap, A, P, E, R> = Spec<C, K, O, A, P, E, R> & {
|
|
913
1057
|
readonly records: (item: ItemOf<I[keyof I]>, unit: Unit<P>) => ReadonlyArray<A>;
|
|
914
1058
|
};
|
|
915
1059
|
/** Build a transaction process handler for one collection, grouping records in first-seen order. */
|
|
916
|
-
declare function process<Codecs extends StreamRoute.ParamCodecs, C extends
|
|
917
|
-
declare function process<Codecs extends StreamRoute.ParamCodecs, C extends
|
|
1060
|
+
declare function process<Codecs extends StreamRoute.ParamCodecs, C extends DurableState.Collections, TR, K extends keyof C & string, O extends string, I extends InputMap, A, P, E = never, R = never>(table: Declaration$1<Codecs, C, TR>, spec: Expanded<C, K, O, I, A, P, E, R>): Handler<C, O, I, P, E, R, TR>;
|
|
1061
|
+
declare function process<Codecs extends StreamRoute.ParamCodecs, C extends DurableState.Collections, TR, K extends keyof C & string, O extends string, I extends InputMap, P, E = never, R = never>(table: Declaration$1<Codecs, C, TR>, spec: Spec<C, K, O, ItemOf<I[keyof I]>, P, E, R> & {
|
|
918
1062
|
readonly records?: never;
|
|
919
1063
|
}): Handler<C, O, I, P, E, R, TR>;
|
|
920
1064
|
/**
|
|
@@ -949,7 +1093,7 @@ interface WakeupHost {
|
|
|
949
1093
|
* A wake during backoff waits; a stopped timer fires late after retry or restart.
|
|
950
1094
|
* Return a time after unit.due to avoid repeatedly running a passed deadline.
|
|
951
1095
|
*/
|
|
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<{
|
|
1096
|
+
declare const attach: <I extends InputMap, E, R, Q, Result, P, OR = never, HE = never, HR = never, Params extends DecodedParams = DecodedParams, BE = never, BR = never, const T extends ReadonlyArray<FrontierStream<{}>> = readonly []>(projection: Attachable<Executable<I, E, R, Q, Result, P, unknown, OR>, HE, HR, Params>, options?: AttachOptions<NoInfer<Params>, BE, BR, T>) => Effect.Effect<{
|
|
953
1097
|
name: string;
|
|
954
1098
|
next: Effect.Effect<Option.Option<number>, import("@streamsy/core").StorageFault, BR | OR | Q | InputServices<I>>;
|
|
955
1099
|
retryable: typeof retryable;
|
|
@@ -960,8 +1104,8 @@ declare const attach: <I extends InputMap, E, R, Q, Result, P, OR = never, HE =
|
|
|
960
1104
|
changed: Effect.Effect<void, never, never>;
|
|
961
1105
|
retry: import("effect/Schedule").Schedule<unknown, unknown, never, never>;
|
|
962
1106
|
deferred: Effect.Effect<number, import("@streamsy/core").StorageFault, never>;
|
|
963
|
-
}, never, import("effect/Scope").Scope |
|
|
1107
|
+
}, never, import("effect/Scope").Scope | StorageOwner | TriggerServices<T>>;
|
|
964
1108
|
export declare const ProjectionWakeup: {
|
|
965
1109
|
attach: typeof attach;
|
|
966
1110
|
};
|
|
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,
|
|
1111
|
+
export { type Accumulated, type AttachOptions, type Attachable, CheckpointRecord, CheckpointStore, type CheckpointStoreApi, commit_d_exports as Commit, type CurrentProjection, type DecideSpec, type Declaration, type Emits, type Emitted, type Entry, fold_by_key_d_exports as FoldByKey, type Folded, type FollowOptions, type FrontierStream, GenerationMismatch, HistoryUnavailable, type Identity, IdentityMismatch, type Initial, type InputMap, InputNotFound, InvalidBinding, InvalidRecord, InvalidSource, InvalidWakeTime, type ItemOf, type Loaded, NonRetryable, NotAttached, type Offsets, type OutputBatch, OutputRejected, type OutputsContext, type PassResult, type ProcessContext, type Progress, projection_d_exports as Projection, ProjectionFault, ProjectionFaultReason, type ProjectionFaultReasonTag, type ProjectionKey, type Range, RangeUnreproducible, type RegistryApi, RetiredGeneration, type RouteRecords, type RoutedHandle, type RoutedStreamRecord, type RunOptions, type RunnerFailure, type RunnerStatus, type Slice, type Slices, type Snapshot, type StateDefinition, type StateSchema, state_table_d_exports as StateTable, type Step, SupersededGeneration, TokenConflict, type Unit, UnsupportedComposition, type WakeAt };
|