@streamsy/projection 0.4.0 → 0.6.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 +129 -7
- package/dist/{checkpoint-store-DacqeoMQ.js → checkpoint-store-Bm8z-f-l.js} +43 -24
- package/dist/{checkpoint-store-yQb6UDAb.d.ts → checkpoint-store-D1saxIIM.d.ts} +12 -9
- package/dist/checkpoint.d.ts +1 -1
- package/dist/checkpoint.js +1 -1
- package/dist/index.d.ts +136 -74
- package/dist/index.js +464 -173
- package/dist/{rolldown-runtime-D7D4PA-g.js → rolldown-runtime-D8jQpDG7.js} +1 -2
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,25 +1,21 @@
|
|
|
1
|
-
import { _ as Slice, a as Identity, d as Unit, f as ProjectionFault, g as ItemOf, h as InputServices, m as InputMap, n as CheckpointStore, o as Loaded, p as Entry, r as CheckpointStoreApi, s as ProjectionKey, t as CheckpointRecord, u as Range, v as Slices } from "./checkpoint-store-
|
|
2
|
-
import { Cause, Context, Data, Effect,
|
|
3
|
-
import { CommitBoundary, Decided, Decision, DurableState, OffsetMismatch, StreamAddress, Streamsy } from "@streamsy/core";
|
|
1
|
+
import { _ as Slice, a as Identity, d as Unit, f as ProjectionFault, g as ItemOf, h as InputServices, m as InputMap, n as CheckpointStore, o as Loaded, p as Entry, r as CheckpointStoreApi, s as ProjectionKey, t as CheckpointRecord, u as Range, v as Slices } from "./checkpoint-store-D1saxIIM.js";
|
|
2
|
+
import { Cause, Context, Data, Effect, Layer, Option, Pipeable, Schedule, Schema, Stream } from "effect";
|
|
3
|
+
import { CommitBoundary, Decided, Decision, DurableState, OffsetMismatch, Storage, StreamAddress, StreamId, Streamsy } from "@streamsy/core";
|
|
4
4
|
import { StreamRoute } from "@streamsy/core/protocol";
|
|
5
|
-
import { Pipeable } from "effect/Pipeable";
|
|
6
5
|
import { SqlClient } from "effect/sql";
|
|
7
|
-
//#region src/read.d.ts
|
|
8
6
|
interface RunOptions {
|
|
9
7
|
/** Maximum checkpoint transactions per call; absent means run to completion. */
|
|
10
8
|
readonly limit?: number;
|
|
11
9
|
}
|
|
12
10
|
/** Tagged items in declaration order, then stream order within each input. */
|
|
13
11
|
declare const items: <Inputs extends InputMap>(batch: Slices<Inputs>) => ReadonlyArray<Entry<Inputs>>;
|
|
14
|
-
//#endregion
|
|
15
|
-
//#region src/commit/model.d.ts
|
|
16
12
|
declare const TypeId = "~@streamsy/projection/Commit";
|
|
17
13
|
interface Variance<in Result, in Provides, out Requires> {
|
|
18
14
|
readonly result: (_: Result) => void;
|
|
19
15
|
readonly provides: (_: Provides) => void;
|
|
20
16
|
readonly requires: () => Requires;
|
|
21
17
|
}
|
|
22
|
-
interface Commit<in Result, in Provides = never, out Requires = never> extends Pipeable {
|
|
18
|
+
interface Commit<in Result, in Provides = never, out Requires = never> extends Pipeable.Pipeable {
|
|
23
19
|
readonly [TypeId]: Variance<Result, Provides, Requires>;
|
|
24
20
|
readonly name: string;
|
|
25
21
|
readonly guarantee: "exactly-once" | "effectively-once" | "at-least-once";
|
|
@@ -68,11 +64,7 @@ declare const Folded: Data.TaggedEnum.ConstructorFrom<Folded<unknown>, "_tag">,
|
|
|
68
64
|
* load must return the stored state. If run and the write are not atomic,
|
|
69
65
|
* declare at-least-once. The guarantee must describe the actual write. */
|
|
70
66
|
declare const make: <Result, Provides = never, Requires = never>(options: Omit<Commit<Result, Provides, Requires>, typeof TypeId | "pipe">) => Commit<Result, Provides, Requires>;
|
|
71
|
-
//#endregion
|
|
72
|
-
//#region src/commit/checkpoint.d.ts
|
|
73
67
|
declare const checkpoint: Commit<Folded<unknown>, never, CheckpointStore>;
|
|
74
|
-
//#endregion
|
|
75
|
-
//#region src/transaction.d.ts
|
|
76
68
|
declare const Transaction_base: Context.ServiceClass<Transaction, "@streamsy/projection/Transaction", {
|
|
77
69
|
readonly owner: object;
|
|
78
70
|
readonly sql: SqlClient.SqlClient;
|
|
@@ -86,20 +78,10 @@ export declare class Transaction extends Transaction_base {
|
|
|
86
78
|
*/
|
|
87
79
|
static readonly layer: Layer.Layer<Transaction, never, CommitBoundary | SqlClient.SqlClient>;
|
|
88
80
|
}
|
|
89
|
-
//#endregion
|
|
90
|
-
//#region src/commit/internal.d.ts
|
|
91
81
|
type Result$1 = void | Folded<unknown> | Emitted<OutputNames> | Accumulated<unknown, OutputNames>;
|
|
92
|
-
//#endregion
|
|
93
|
-
//#region src/commit/transaction.d.ts
|
|
94
82
|
declare const transaction: Commit<Result$1, SqlClient.SqlClient, CheckpointStore | Transaction>;
|
|
95
|
-
//#endregion
|
|
96
|
-
//#region src/commit/producer.d.ts
|
|
97
83
|
declare const producer: Commit<Accumulated<unknown, Readonly<Record<string, never>>> | Emitted<Readonly<Record<string, never>>>, never, CheckpointStore>;
|
|
98
|
-
//#endregion
|
|
99
|
-
//#region src/commit/at-least-once.d.ts
|
|
100
84
|
declare const atLeastOnce: Commit<void, never, CheckpointStore>;
|
|
101
|
-
//#endregion
|
|
102
|
-
//#region src/commit/compensation.d.ts
|
|
103
85
|
declare const withCompensation: {
|
|
104
86
|
<Result, R>(f: (result: Result, cause: Cause.Cause<ProjectionFault | HandlerFailed>, unit: Unit) => Effect.Effect<void, never, R>): <P, Q>(self: Commit<Result, P, Q>) => Commit<Result, P, Q | R>;
|
|
105
87
|
<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>;
|
|
@@ -107,17 +89,13 @@ declare const withCompensation: {
|
|
|
107
89
|
declare namespace commit_d_exports {
|
|
108
90
|
export { Accumulated, Commit, Emitted, Folded, HandlerFailed, OutputBatch, Pending, TypeId, Variance, atLeastOnce, checkpoint, make, producer, transaction, withCompensation };
|
|
109
91
|
}
|
|
110
|
-
//#endregion
|
|
111
|
-
//#region src/outputs.d.ts
|
|
112
92
|
type RoutedMap = Inputs;
|
|
113
93
|
type Item<T> = AddressOf<T> extends {
|
|
114
94
|
readonly collections: infer C extends StreamAddress.Collections;
|
|
115
|
-
} ? DurableState.
|
|
95
|
+
} ? DurableState.Entry<C> : AddressOf<T> extends {
|
|
116
96
|
readonly codec: Schema.Codec<infer A, any, any, any>;
|
|
117
97
|
} ? A : never;
|
|
118
98
|
type Services<O extends RoutedMap> = { [K in keyof O]: AddressOf<O[K]> extends Streamsy.Address<any, infer R> ? R : never; }[keyof O];
|
|
119
|
-
//#endregion
|
|
120
|
-
//#region src/state.d.ts
|
|
121
99
|
type StateSchema<A, I = unknown> = Schema.Codec<A, I>;
|
|
122
100
|
/** A value, or a function of the decoded params the projection was bound with. */
|
|
123
101
|
type Initial<A, P = Record<string, string>> = A | ((params: P) => A);
|
|
@@ -131,8 +109,6 @@ interface BoundState<A> {
|
|
|
131
109
|
readonly schema: StateSchema<A>;
|
|
132
110
|
readonly initial: () => A;
|
|
133
111
|
}
|
|
134
|
-
//#endregion
|
|
135
|
-
//#region src/executable.d.ts
|
|
136
112
|
/** Common bound declaration consumed by the kernel. */
|
|
137
113
|
interface Executable<I extends InputMap, E, R, Q, Result, P = never, S = unknown, OR = never> extends Identity {
|
|
138
114
|
readonly inputs: I;
|
|
@@ -142,8 +118,6 @@ interface Executable<I extends InputMap, E, R, Q, Result, P = never, S = unknown
|
|
|
142
118
|
readonly prepare?: (batch: Slices<I>, unit: Unit) => Effect.Effect<unknown, E, Q>;
|
|
143
119
|
readonly process: (batch: Slices<I>, unit: Unit, encoded?: string, prepared?: unknown) => Effect.Effect<Result, E, R | P>;
|
|
144
120
|
}
|
|
145
|
-
//#endregion
|
|
146
|
-
//#region src/declaration.d.ts
|
|
147
121
|
/** A stream declaration. `.at(params)` resolves it with the projection params. */
|
|
148
122
|
type StreamDeclaration = StreamRoute.StreamRoute<any, any> & Streamsy.Any & {
|
|
149
123
|
readonly at: (params: any) => Streamsy.Address<any, any>;
|
|
@@ -158,6 +132,7 @@ type Invalid<C extends StreamRoute.ParamCodecs, P> = { readonly [Name in keyof P
|
|
|
158
132
|
type InvalidInput<C extends StreamRoute.ParamCodecs, X> = X extends StreamDeclaration ? Invalid<C, DeclaredParams<X>> : never;
|
|
159
133
|
/** Every declaration's params must be projection params with the same type. */
|
|
160
134
|
type Within<C extends StreamRoute.ParamCodecs, I extends Inputs> = { readonly [K in keyof I]: InvalidInput<C, I[K]> extends never ? I[K] : never; };
|
|
135
|
+
type OneWithin<C extends StreamRoute.ParamCodecs, X> = InvalidInput<C, X> extends never ? X : never;
|
|
161
136
|
type OutputsWithin<C extends StreamRoute.ParamCodecs, D extends RoutedMap> = Within<C, D>;
|
|
162
137
|
/** Inert: `at` binds the params and returns the value runners take. */
|
|
163
138
|
interface Declaration<Codecs extends StreamRoute.ParamCodecs, Bound> {
|
|
@@ -165,6 +140,8 @@ interface Declaration<Codecs extends StreamRoute.ParamCodecs, Bound> {
|
|
|
165
140
|
readonly version: number;
|
|
166
141
|
readonly generation: number;
|
|
167
142
|
readonly params: Codecs;
|
|
143
|
+
/** The declared inputs, before `at` binds them. */
|
|
144
|
+
readonly inputs: Inputs;
|
|
168
145
|
/** Throws a RangeError when a param does not encode. */
|
|
169
146
|
readonly at: (params: StreamRoute.Params<Codecs>) => Bound;
|
|
170
147
|
/** Tries declaration inputs in order. Shared inputs return only their declared subset. */
|
|
@@ -191,28 +168,20 @@ type OutputDeclaration<C extends StreamRoute.ParamCodecs, I extends Inputs, O ex
|
|
|
191
168
|
};
|
|
192
169
|
};
|
|
193
170
|
type AccumulatingDeclaration<C extends StreamRoute.ParamCodecs, I extends Inputs, O extends RoutedMap, A, E, R, P, Q> = OutputDeclaration<C, I, O, E, R, Accumulated<A, O>, P, Q, A>;
|
|
194
|
-
//#endregion
|
|
195
|
-
//#region src/step.d.ts
|
|
196
171
|
type Step<X, E = never, R = never> = X | Effect.Effect<X, E, R>;
|
|
197
172
|
/** Each output keeps its item type here; missing keys emit nothing. */
|
|
198
173
|
type Emits<O extends RoutedMap> = { readonly [K in keyof O]?: ReadonlyArray<Item<O[K]>>; };
|
|
199
|
-
//#endregion
|
|
200
|
-
//#region src/fold.d.ts
|
|
201
174
|
/** Fold one entry at a time. The default Commit saves state and offsets in one write. */
|
|
202
175
|
declare function fold<C extends StreamRoute.ParamCodecs, I extends Inputs, A, SI, E = never, R = never, P = never, Q = CheckpointStore>(definition: Common<C, I> & {
|
|
203
176
|
readonly state: StateDefinition<A, SI, StreamRoute.Params<C>>;
|
|
204
177
|
readonly commit?: Committing<Folded<NoInfer<A>>, P, Q>["commit"];
|
|
205
178
|
readonly fold: (state: NoInfer<A>, entry: Entry<Addresses<I>>, unit: Unit<StreamRoute.Params<C>>) => Step<A, E, R>;
|
|
206
179
|
}): StatefulDeclaration<C, I, A, E, R, Folded<A>, P, Q>;
|
|
207
|
-
//#endregion
|
|
208
|
-
//#region src/process.d.ts
|
|
209
180
|
/** Run side effects once per unit. prepare runs at least once, outside the transaction. */
|
|
210
181
|
declare function process<C extends StreamRoute.ParamCodecs, I extends Inputs, E = never, R = never, P = never, Q = never, Prepared = void, PE = never, PR = never>(definition: Common<C, I> & Committing<void, P, Q> & {
|
|
211
182
|
readonly prepare?: (batch: Slices<Addresses<I>>, unit: Unit<StreamRoute.Params<C>>) => Effect.Effect<Prepared, PE, PR>;
|
|
212
183
|
readonly process: (batch: Slices<Addresses<I>>, unit: Unit<StreamRoute.Params<C>>, prepared: Prepared) => Effect.Effect<void, E, R>;
|
|
213
184
|
}): RunningDeclaration<C, I, E | PE, R, void, P, Q | PR>;
|
|
214
|
-
//#endregion
|
|
215
|
-
//#region src/emit.d.ts
|
|
216
185
|
/** Emit zero or more output items for each input entry, in entry order. */
|
|
217
186
|
declare function emit<C extends StreamRoute.ParamCodecs, I extends Inputs, const O extends RoutedMap, X extends Emits<O>, E = never, R = never, P = never, Q = never>(definition: Common<C, I> & Committing<Emitted<NoInfer<O>>, P, Q> & {
|
|
218
187
|
readonly outputs: O & OutputsWithin<C, O>;
|
|
@@ -220,8 +189,6 @@ declare function emit<C extends StreamRoute.ParamCodecs, I extends Inputs, const
|
|
|
220
189
|
readonly undeclaredOutput: Exclude<keyof X, keyof O>;
|
|
221
190
|
});
|
|
222
191
|
}): OutputDeclaration<C, I, O, E, R, Emitted<O>, P, Q>;
|
|
223
|
-
//#endregion
|
|
224
|
-
//#region src/map-accum.d.ts
|
|
225
192
|
type Definition<C extends StreamRoute.ParamCodecs, I extends Inputs, O extends RoutedMap, A, SI, P, Q> = Common<C, I> & Committing<Accumulated<NoInfer<A>, NoInfer<O>>, P, Q> & {
|
|
226
193
|
readonly outputs: O & OutputsWithin<C, O>;
|
|
227
194
|
readonly state: StateDefinition<A, SI, StreamRoute.Params<C>>;
|
|
@@ -238,8 +205,6 @@ declare function mapAccumBatch<C extends StreamRoute.ParamCodecs, I extends Inpu
|
|
|
238
205
|
readonly undeclaredOutput: Exclude<keyof X, keyof O>;
|
|
239
206
|
});
|
|
240
207
|
}): AccumulatingDeclaration<C, I, O, A, E, R, P, Q>;
|
|
241
|
-
//#endregion
|
|
242
|
-
//#region src/snapshot.d.ts
|
|
243
208
|
/** The accepted offset of each input, keyed by input name. The next pass reads after these. */
|
|
244
209
|
type Offsets<Inputs extends InputMap> = { readonly [K in keyof Inputs]: string; };
|
|
245
210
|
/** The state and the offsets it is at. `state` is `undefined` when the declaration has no `state:`. */
|
|
@@ -248,30 +213,41 @@ interface Snapshot<S, Inputs extends InputMap> {
|
|
|
248
213
|
readonly offsets: Offsets<Inputs>;
|
|
249
214
|
}
|
|
250
215
|
type StateValue<S> = [S] extends [never] ? undefined : S;
|
|
216
|
+
/** Internal: what `read` needs from a bound projection. */
|
|
217
|
+
type Readable<Inputs extends InputMap, S, Q> = Identity & {
|
|
218
|
+
readonly inputs: Inputs;
|
|
219
|
+
readonly state?: BoundState<S>;
|
|
220
|
+
readonly commit: Pick<Commit<never, never, Q>, "load">;
|
|
221
|
+
};
|
|
251
222
|
/**
|
|
252
223
|
* Reads the state and offsets from one checkpoint record, so the state
|
|
253
224
|
* always matches the offsets. Before the first unit, the state is the declared initial
|
|
254
225
|
* value and every offset is the start of its input.
|
|
255
226
|
*/
|
|
256
|
-
declare const read: <Inputs extends InputMap, S = never, Q = never>(projection:
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
readonly
|
|
260
|
-
}) => Effect.Effect<Snapshot<StateValue<S>, Inputs>, ProjectionFault, Q>;
|
|
261
|
-
//#endregion
|
|
262
|
-
//#region src/run.d.ts
|
|
263
|
-
interface Progress<Inputs extends InputMap = InputMap> {
|
|
264
|
-
readonly status: "progress" | "caught-up" | "source-closed" | "limit-reached";
|
|
227
|
+
declare const read: <Inputs extends InputMap, S = never, Q = never>(projection: Readable<Inputs, S, Q>) => Effect.Effect<Snapshot<StateValue<S>, Inputs>, ProjectionFault, Q>;
|
|
228
|
+
/** The result of one `pass`: one committed unit (`progress`), or no input to commit. */
|
|
229
|
+
interface PassResult<Inputs extends InputMap = InputMap> {
|
|
230
|
+
readonly status: "progress" | "caught-up" | "source-closed";
|
|
265
231
|
readonly units: number;
|
|
266
232
|
readonly items: number;
|
|
267
233
|
readonly offsets: Offsets<Inputs>;
|
|
268
234
|
}
|
|
235
|
+
/** One runner cycle: the committed state and offsets, plus the work that the cycle did. */
|
|
236
|
+
interface Progress<S, Inputs extends InputMap = InputMap> extends Snapshot<S, Inputs> {
|
|
237
|
+
readonly status: "caught-up" | "limit-reached" | "source-closed";
|
|
238
|
+
/** Units that this cycle committed. */
|
|
239
|
+
readonly units: number;
|
|
240
|
+
/** Input items in those units. */
|
|
241
|
+
readonly items: number;
|
|
242
|
+
}
|
|
269
243
|
/** Restore and adapt one input unit; the Commit owns every write. */
|
|
270
|
-
declare const pass: <Inputs extends InputMap, E, R, Q, Result, P, OR = never>(projection: Executable<Inputs, E, R, Q, Result, P, unknown, OR>) => Effect.Effect<
|
|
271
|
-
/**
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
244
|
+
declare const pass: <Inputs extends InputMap, E, R, Q, Result, P, OR = never>(projection: Executable<Inputs, E, R, Q, Result, P, unknown, OR>) => Effect.Effect<PassResult<Inputs>, E | ProjectionFault, Exclude<R, P> | Q | OR | InputServices<Inputs>>;
|
|
245
|
+
/**
|
|
246
|
+
* Repeats pass until caught up, closed, or limited, then decodes the state of the last
|
|
247
|
+
* pass once. After a gone input, the result holds the state that the final unit
|
|
248
|
+
* committed, although the kernel then deletes the record. Use one writer per key.
|
|
249
|
+
*/
|
|
250
|
+
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>>;
|
|
275
251
|
interface FollowOptions extends RunOptions {
|
|
276
252
|
/** Upper bound on one wake wait; default 30000. */
|
|
277
253
|
readonly repairIntervalMs?: number;
|
|
@@ -279,14 +255,55 @@ interface FollowOptions extends RunOptions {
|
|
|
279
255
|
readonly retry?: Schedule.Schedule<unknown>;
|
|
280
256
|
}
|
|
281
257
|
/**
|
|
282
|
-
*
|
|
283
|
-
*
|
|
284
|
-
*
|
|
285
|
-
*
|
|
258
|
+
* Follows a projection as a pull stream. Each element is one committed cycle: the
|
|
259
|
+
* state and offsets that the last pass left, plus the units and items of the cycle.
|
|
260
|
+
*
|
|
261
|
+
* To run the stream is to be the writer, so run one `follow` stream per key. The next
|
|
262
|
+
* cycle runs only when the consumer pulls, so a slow consumer gets one element that
|
|
263
|
+
* covers all the input that arrived meanwhile. The stream emits after the first cycle,
|
|
264
|
+
* after each cycle that commits a unit or reaches `limit`, and after the last cycle
|
|
265
|
+
* when every input is closed or an input is gone; then it ends. After a gone input, the
|
|
266
|
+
* last element holds the state that the final unit committed, and the kernel then
|
|
267
|
+
* deletes the record. A wake that finds no input emits nothing.
|
|
268
|
+
* Options are checked at the first pull. On HTTP backends a parked hint is cancelled
|
|
269
|
+
* and replaced once per `repairIntervalMs` until an input changes. One
|
|
270
|
+
* `Projection.follow` span covers the whole stream.
|
|
286
271
|
*/
|
|
287
|
-
declare const follow: <Inputs extends InputMap, E, R, Q, Result, P, OR = never>(projection: Executable<Inputs, E, R, Q, Result, P,
|
|
288
|
-
|
|
289
|
-
|
|
272
|
+
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>>;
|
|
273
|
+
/** The part of a projection declaration that the attach runner reads. */
|
|
274
|
+
interface Attachable<B> {
|
|
275
|
+
readonly id: string;
|
|
276
|
+
readonly params: StreamRoute.ParamCodecs;
|
|
277
|
+
readonly inputs: Inputs;
|
|
278
|
+
at(params: Readonly<Record<string, unknown>>): B;
|
|
279
|
+
}
|
|
280
|
+
interface AttachOptions {
|
|
281
|
+
/** Units for each binding in one run. Default 100. */
|
|
282
|
+
readonly limit?: number;
|
|
283
|
+
/** Retry a failed drain pass. Defaults to capped, jittered exponential backoff. */
|
|
284
|
+
readonly retry?: Schedule.Schedule<unknown>;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Run a projection whenever a local commit writes one of its inputs. The layer
|
|
288
|
+
* subscribes to `Storage.committed` when it is built, so build it with the
|
|
289
|
+
* storage layer and before the app writes. For each written id, the input's
|
|
290
|
+
* `parse` gives the params, and the runner runs `projection.at(params)`.
|
|
291
|
+
*
|
|
292
|
+
* Use it on long-lived hosts (Bun, Node). On a Cloudflare object, use
|
|
293
|
+
* `ProjectionWakeup.attach(projection)`.
|
|
294
|
+
*
|
|
295
|
+
* The set of bindings with work lives in memory. A crash after a commit and
|
|
296
|
+
* before the run leaves that binding late until its source gets its next write.
|
|
297
|
+
* Inputs on another owner never commit here, so they never trigger. Do not run
|
|
298
|
+
* an attached binding under `Projection.follow` too: use one writer per key.
|
|
299
|
+
*
|
|
300
|
+
* ```ts
|
|
301
|
+
* const app = Layer.mergeAll(Api, Projection.attach(filesWake)).pipe(
|
|
302
|
+
* Layer.provideMerge(BunStorage.layer(streams, { path })),
|
|
303
|
+
* );
|
|
304
|
+
* ```
|
|
305
|
+
*/
|
|
306
|
+
declare const attach$1: <I extends InputMap, E, R, Q, Result, P, OR = never>(projection: Attachable<Executable<I, E, R, Q, Result, P, unknown, OR>>, options?: AttachOptions) => Layer.Layer<never, never, Storage | Exclude<R, P> | Q | OR | InputServices<I>>;
|
|
290
307
|
/** A bound value projection. Output items from its adapter are discarded. */
|
|
291
308
|
interface CurrentProjection<Inputs extends InputMap, S, E, R, Q> extends Identity {
|
|
292
309
|
readonly inputs: Inputs;
|
|
@@ -303,8 +320,6 @@ interface CurrentProjection<Inputs extends InputMap, S, E, R, Q> extends Identit
|
|
|
303
320
|
* Fold steps must be replayable. Pending ranges are read from committed offsets.
|
|
304
321
|
*/
|
|
305
322
|
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>>;
|
|
306
|
-
//#endregion
|
|
307
|
-
//#region src/decide.d.ts
|
|
308
323
|
interface DecideSpec<Inputs extends InputMap, K extends keyof Inputs, S, B, E, R> {
|
|
309
324
|
/** The input to append to. Its offset in the snapshot is the CAS token. */
|
|
310
325
|
readonly input: K;
|
|
@@ -335,8 +350,6 @@ declare class LostRace {
|
|
|
335
350
|
readonly mismatch: OffsetMismatch;
|
|
336
351
|
constructor(mismatch: OffsetMismatch);
|
|
337
352
|
}
|
|
338
|
-
//#endregion
|
|
339
|
-
//#region src/forget.d.ts
|
|
340
353
|
/**
|
|
341
354
|
* Deletes the record. Stop the follower first, or use a new generation.
|
|
342
355
|
* Delete stream outputs first, because forgetting restarts their producer sequences.
|
|
@@ -344,15 +357,64 @@ declare class LostRace {
|
|
|
344
357
|
declare const forget: <R>(projection: ProjectionKey & {
|
|
345
358
|
readonly commit: Pick<Commit<never, never, R>, "remove">;
|
|
346
359
|
}) => Effect.Effect<void, ProjectionFault, R>;
|
|
360
|
+
/** A State declaration with the wake collections. */
|
|
361
|
+
type WakeOutput = StreamDeclaration & StreamRoute.StateRoute<any, Streamsy.WakeCollections>;
|
|
362
|
+
interface WakeDefinition<C extends StreamRoute.ParamCodecs, I extends Input, O> {
|
|
363
|
+
readonly id: string;
|
|
364
|
+
readonly version?: number;
|
|
365
|
+
readonly generation?: number;
|
|
366
|
+
readonly params: C;
|
|
367
|
+
/** The one source stream. Its params must be projection params. */
|
|
368
|
+
readonly input: I & OneWithin<C, I>;
|
|
369
|
+
/** The State declaration with wake collections that gets the row. Its params must be projection params. */
|
|
370
|
+
readonly output: O & OneWithin<C, O>;
|
|
371
|
+
}
|
|
372
|
+
type WakeDeclaration<C extends StreamRoute.ParamCodecs, I extends Input, O extends Input> = AccumulatingDeclaration<C, {
|
|
373
|
+
readonly source: I;
|
|
374
|
+
}, {
|
|
375
|
+
readonly wake: O;
|
|
376
|
+
}, null, never, never, never, CheckpointStore>;
|
|
377
|
+
/**
|
|
378
|
+
* A wake projection: one source stream gives one keyed row in one wake stream.
|
|
379
|
+
* Each unit appends one upsert `{ stream, offset, closed? }` with
|
|
380
|
+
* `Commit.producer`, so several source writes in one unit fold into one row,
|
|
381
|
+
* and a retry answers `Duplicate`. The producer creates a missing wake stream
|
|
382
|
+
* on its own owner. A wake stream on another owner must exist before the first
|
|
383
|
+
* append: its owner creates it at start. When the source is removed or
|
|
384
|
+
* expires, the binding appends a State delete for its row and forgets itself.
|
|
385
|
+
*
|
|
386
|
+
* ```ts
|
|
387
|
+
* const filesWake = Projection.wake({
|
|
388
|
+
* id: "files-wake",
|
|
389
|
+
* params: { user: UserKey, folderId: FolderKey },
|
|
390
|
+
* input: Files,
|
|
391
|
+
* output: UserWake,
|
|
392
|
+
* });
|
|
393
|
+
* ```
|
|
394
|
+
*/
|
|
395
|
+
declare function wake<C extends StreamRoute.ParamCodecs, const I extends Input, const O extends WakeOutput>(definition: WakeDefinition<C, I, O>): WakeDeclaration<C, I, O>;
|
|
347
396
|
declare namespace projection_d_exports {
|
|
348
|
-
export { current, decide, each, emit, fold, follow, forget, items, key, mapAccum, mapAccumBatch, pass, process, read, run };
|
|
397
|
+
export { attach$1 as attach, current, decide, each, emit, fold, follow, forget, items, key, mapAccum, mapAccumBatch, pass, process, read, run, wake };
|
|
349
398
|
}
|
|
350
399
|
declare const key: (projection: Identity) => ProjectionKey;
|
|
351
400
|
/** Runs each tagged entry in order and discards its success value. */
|
|
352
401
|
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>);
|
|
353
|
-
|
|
354
|
-
//#region src/retry.d.ts
|
|
355
|
-
/** Default storage-failure retry for follow; an explicit options.retry takes precedence. */
|
|
402
|
+
/** Default retry for following and attached runners; an explicit options.retry takes precedence. */
|
|
356
403
|
export declare const ProjectionRetry: Context.Reference<Schedule.Schedule<unknown, unknown, never, never>>;
|
|
357
|
-
|
|
358
|
-
|
|
404
|
+
/**
|
|
405
|
+
* Local commits choose bindings; each alarm drains the same runner used by
|
|
406
|
+
* Projection.attach. Acquire it in the object layer's scope, before any
|
|
407
|
+
* request writes.
|
|
408
|
+
*/
|
|
409
|
+
declare const attach: <I extends InputMap, E, R, Q, Result, P, OR = never>(projection: Attachable<Executable<I, E, R, Q, Result, P, unknown, OR>>, options?: AttachOptions) => Effect.Effect<{
|
|
410
|
+
name: string;
|
|
411
|
+
next: Effect.Effect<import("effect/Option").Option<number>, never, never>;
|
|
412
|
+
run: Effect.Effect<{
|
|
413
|
+
more: boolean;
|
|
414
|
+
}, E | ProjectionFault, OR | Q | InputServices<I> | Exclude<R, P>>;
|
|
415
|
+
retry: import("effect/Schedule").Schedule<unknown, unknown, never, never>;
|
|
416
|
+
}, never, import("effect/Scope").Scope | import("@streamsy/core").Storage>;
|
|
417
|
+
export declare const ProjectionWakeup: {
|
|
418
|
+
attach: typeof attach;
|
|
419
|
+
};
|
|
420
|
+
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, type Folded, type FollowOptions, type Identity, type Initial, type InputMap, type ItemOf, type Loaded, type Offsets, type OutputBatch, type PassResult, type Progress, projection_d_exports as Projection, ProjectionFault, type ProjectionKey, type Range, type RunOptions, type Slice, type Slices, type Snapshot, type StateDefinition, type StateSchema, type Step, type Unit };
|