@streamsy/projection 0.0.0-tegami-trusted-publish-setup → 0.4.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/LICENSE +21 -0
- package/README.md +171 -6
- package/dist/checkpoint-store-DacqeoMQ.js +249 -0
- package/dist/checkpoint-store-yQb6UDAb.d.ts +126 -0
- package/dist/checkpoint.d.ts +2 -0
- package/dist/checkpoint.js +1 -0
- package/dist/index.d.ts +358 -0
- package/dist/index.js +1003 -0
- package/dist/rolldown-runtime-D7D4PA-g.js +13 -0
- package/package.json +62 -2
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,358 @@
|
|
|
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-yQb6UDAb.js";
|
|
2
|
+
import { Cause, Context, Data, Effect, Fiber, Layer, Option, Schedule, Schema, Scope } from "effect";
|
|
3
|
+
import { CommitBoundary, Decided, Decision, DurableState, OffsetMismatch, StreamAddress, Streamsy } from "@streamsy/core";
|
|
4
|
+
import { StreamRoute } from "@streamsy/core/protocol";
|
|
5
|
+
import { Pipeable } from "effect/Pipeable";
|
|
6
|
+
import { SqlClient } from "effect/sql";
|
|
7
|
+
//#region src/read.d.ts
|
|
8
|
+
interface RunOptions {
|
|
9
|
+
/** Maximum checkpoint transactions per call; absent means run to completion. */
|
|
10
|
+
readonly limit?: number;
|
|
11
|
+
}
|
|
12
|
+
/** Tagged items in declaration order, then stream order within each input. */
|
|
13
|
+
declare const items: <Inputs extends InputMap>(batch: Slices<Inputs>) => ReadonlyArray<Entry<Inputs>>;
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/commit/model.d.ts
|
|
16
|
+
declare const TypeId = "~@streamsy/projection/Commit";
|
|
17
|
+
interface Variance<in Result, in Provides, out Requires> {
|
|
18
|
+
readonly result: (_: Result) => void;
|
|
19
|
+
readonly provides: (_: Provides) => void;
|
|
20
|
+
readonly requires: () => Requires;
|
|
21
|
+
}
|
|
22
|
+
interface Commit<in Result, in Provides = never, out Requires = never> extends Pipeable {
|
|
23
|
+
readonly [TypeId]: Variance<Result, Provides, Requires>;
|
|
24
|
+
readonly name: string;
|
|
25
|
+
readonly guarantee: "exactly-once" | "effectively-once" | "at-least-once";
|
|
26
|
+
readonly load: (key: ProjectionKey) => Effect.Effect<Loaded, ProjectionFault, Requires>;
|
|
27
|
+
readonly apply: (pending: Pending<Result, Provides>) => Effect.Effect<void, ProjectionFault | HandlerFailed, Requires>;
|
|
28
|
+
readonly remove?: (key: ProjectionKey) => Effect.Effect<void, ProjectionFault, Requires>;
|
|
29
|
+
}
|
|
30
|
+
interface Pending<Result, Provides = never> {
|
|
31
|
+
readonly key: ProjectionKey;
|
|
32
|
+
readonly unit: Unit;
|
|
33
|
+
readonly loaded: Loaded;
|
|
34
|
+
readonly next: CheckpointRecord;
|
|
35
|
+
readonly run: Effect.Effect<Result, HandlerFailed, Provides>;
|
|
36
|
+
}
|
|
37
|
+
declare const HandlerFailed_base: Schema.Class<HandlerFailed, Schema.TaggedStruct<"HandlerFailed", {
|
|
38
|
+
readonly error: Schema.Unknown;
|
|
39
|
+
}>, import("effect/Cause").YieldableError>;
|
|
40
|
+
/** Opaque to Commit authors; the kernel restores the original typed handler error. */
|
|
41
|
+
export declare class HandlerFailed extends HandlerFailed_base {}
|
|
42
|
+
interface Folded<S> {
|
|
43
|
+
readonly _tag: "Folded";
|
|
44
|
+
readonly value: S;
|
|
45
|
+
readonly encoded: string;
|
|
46
|
+
}
|
|
47
|
+
interface Emitted<O> {
|
|
48
|
+
readonly _tag: "Emitted";
|
|
49
|
+
readonly outputs: OutputBatch<O>;
|
|
50
|
+
}
|
|
51
|
+
interface Accumulated<S, O> {
|
|
52
|
+
readonly _tag: "Accumulated";
|
|
53
|
+
readonly value: S;
|
|
54
|
+
readonly encoded: string;
|
|
55
|
+
readonly outputs: OutputBatch<O>;
|
|
56
|
+
}
|
|
57
|
+
/** Output names survive type erasure; each value is represented by its resolved batch entry. */
|
|
58
|
+
type OutputNames = Readonly<Record<string, never>>;
|
|
59
|
+
/** Resolved addresses and encoded row changes, in declaration and entry order. */
|
|
60
|
+
type OutputBatch<O> = { readonly [K in keyof O]: {
|
|
61
|
+
readonly address: StreamAddress.StreamAddress<unknown>;
|
|
62
|
+
readonly items: ReadonlyArray<unknown>;
|
|
63
|
+
}; };
|
|
64
|
+
declare const Folded: Data.TaggedEnum.ConstructorFrom<Folded<unknown>, "_tag">, Emitted: Data.TaggedEnum.ConstructorFrom<Emitted<Readonly<Record<string, never>>>, "_tag">, Accumulated: Data.TaggedEnum.ConstructorFrom<Accumulated<unknown, Readonly<Record<string, never>>>, "_tag">;
|
|
65
|
+
/** Custom Commits extend the input range on retry. Never store next when run fails;
|
|
66
|
+
* condition the write on loaded.token (checkpoint / token-conflict when it moved),
|
|
67
|
+
* and return token "0" for an absent record.
|
|
68
|
+
* load must return the stored state. If run and the write are not atomic,
|
|
69
|
+
* declare at-least-once. The guarantee must describe the actual write. */
|
|
70
|
+
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
|
+
declare const checkpoint: Commit<Folded<unknown>, never, CheckpointStore>;
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region src/transaction.d.ts
|
|
76
|
+
declare const Transaction_base: Context.ServiceClass<Transaction, "@streamsy/projection/Transaction", {
|
|
77
|
+
readonly owner: object;
|
|
78
|
+
readonly sql: SqlClient.SqlClient;
|
|
79
|
+
readonly withTransaction: <A, E, R>(body: Effect.Effect<A, E, R>) => Effect.Effect<A, E | ProjectionFault, R>;
|
|
80
|
+
}>;
|
|
81
|
+
/** The SQL transaction and stream owner used by Commit.transaction. */
|
|
82
|
+
export declare class Transaction extends Transaction_base {
|
|
83
|
+
/**
|
|
84
|
+
* The storage owner's SQL transaction, for Commit.transaction. Works over every SQL
|
|
85
|
+
* storage host. A memory host has no SqlClient, so this Layer does not fit it.
|
|
86
|
+
*/
|
|
87
|
+
static readonly layer: Layer.Layer<Transaction, never, CommitBoundary | SqlClient.SqlClient>;
|
|
88
|
+
}
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/commit/internal.d.ts
|
|
91
|
+
type Result$1 = void | Folded<unknown> | Emitted<OutputNames> | Accumulated<unknown, OutputNames>;
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region src/commit/transaction.d.ts
|
|
94
|
+
declare const transaction: Commit<Result$1, SqlClient.SqlClient, CheckpointStore | Transaction>;
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region src/commit/producer.d.ts
|
|
97
|
+
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
|
+
declare const atLeastOnce: Commit<void, never, CheckpointStore>;
|
|
101
|
+
//#endregion
|
|
102
|
+
//#region src/commit/compensation.d.ts
|
|
103
|
+
declare const withCompensation: {
|
|
104
|
+
<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
|
+
<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>;
|
|
106
|
+
};
|
|
107
|
+
declare namespace commit_d_exports {
|
|
108
|
+
export { Accumulated, Commit, Emitted, Folded, HandlerFailed, OutputBatch, Pending, TypeId, Variance, atLeastOnce, checkpoint, make, producer, transaction, withCompensation };
|
|
109
|
+
}
|
|
110
|
+
//#endregion
|
|
111
|
+
//#region src/outputs.d.ts
|
|
112
|
+
type RoutedMap = Inputs;
|
|
113
|
+
type Item<T> = AddressOf<T> extends {
|
|
114
|
+
readonly collections: infer C extends StreamAddress.Collections;
|
|
115
|
+
} ? DurableState.Change<C> : AddressOf<T> extends {
|
|
116
|
+
readonly codec: Schema.Codec<infer A, any, any, any>;
|
|
117
|
+
} ? A : never;
|
|
118
|
+
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
|
+
type StateSchema<A, I = unknown> = Schema.Codec<A, I>;
|
|
122
|
+
/** A value, or a function of the decoded params the projection was bound with. */
|
|
123
|
+
type Initial<A, P = Record<string, string>> = A | ((params: P) => A);
|
|
124
|
+
/** The `state:` field of a declaration. */
|
|
125
|
+
interface StateDefinition<A, I = unknown, P = Record<string, string>> {
|
|
126
|
+
readonly schema: StateSchema<A, I>;
|
|
127
|
+
readonly initial: Initial<A, P>;
|
|
128
|
+
}
|
|
129
|
+
/** The state of a bound projection. `initial` runs only when stored state is absent. */
|
|
130
|
+
interface BoundState<A> {
|
|
131
|
+
readonly schema: StateSchema<A>;
|
|
132
|
+
readonly initial: () => A;
|
|
133
|
+
}
|
|
134
|
+
//#endregion
|
|
135
|
+
//#region src/executable.d.ts
|
|
136
|
+
/** Common bound declaration consumed by the kernel. */
|
|
137
|
+
interface Executable<I extends InputMap, E, R, Q, Result, P = never, S = unknown, OR = never> extends Identity {
|
|
138
|
+
readonly inputs: I;
|
|
139
|
+
readonly state?: BoundState<S>;
|
|
140
|
+
readonly streams?: Readonly<Record<string, Streamsy.Address<unknown, OR>>>;
|
|
141
|
+
readonly commit: Commit<Result, P, Q>;
|
|
142
|
+
readonly prepare?: (batch: Slices<I>, unit: Unit) => Effect.Effect<unknown, E, Q>;
|
|
143
|
+
readonly process: (batch: Slices<I>, unit: Unit, encoded?: string, prepared?: unknown) => Effect.Effect<Result, E, R | P>;
|
|
144
|
+
}
|
|
145
|
+
//#endregion
|
|
146
|
+
//#region src/declaration.d.ts
|
|
147
|
+
/** A stream declaration. `.at(params)` resolves it with the projection params. */
|
|
148
|
+
type StreamDeclaration = StreamRoute.StreamRoute<any, any> & Streamsy.Any & {
|
|
149
|
+
readonly at: (params: any) => Streamsy.Address<any, any>;
|
|
150
|
+
};
|
|
151
|
+
/** A stream declaration, or a fixed address that `.at` does not rebind. */
|
|
152
|
+
type Input = StreamDeclaration | Streamsy.Address<any, any>;
|
|
153
|
+
type Inputs = Readonly<Record<string, Input>>;
|
|
154
|
+
type AddressOf<X> = X extends StreamDeclaration ? ReturnType<X["at"]> : X extends Streamsy.Address<any, any> ? X : never;
|
|
155
|
+
type Addresses<I extends Inputs> = { readonly [K in keyof I]: AddressOf<I[K]>; };
|
|
156
|
+
type DeclaredParams<X> = X extends StreamRoute.StreamRoute<infer P, any, any, any> ? P : {};
|
|
157
|
+
type Invalid<C extends StreamRoute.ParamCodecs, P> = { readonly [Name in keyof P]: Name extends keyof StreamRoute.Params<C> ? P[Name] extends StreamRoute.Params<C>[Name] ? StreamRoute.Params<C>[Name] extends P[Name] ? never : Name : Name : Name; }[keyof P];
|
|
158
|
+
type InvalidInput<C extends StreamRoute.ParamCodecs, X> = X extends StreamDeclaration ? Invalid<C, DeclaredParams<X>> : never;
|
|
159
|
+
/** Every declaration's params must be projection params with the same type. */
|
|
160
|
+
type Within<C extends StreamRoute.ParamCodecs, I extends Inputs> = { readonly [K in keyof I]: InvalidInput<C, I[K]> extends never ? I[K] : never; };
|
|
161
|
+
type OutputsWithin<C extends StreamRoute.ParamCodecs, D extends RoutedMap> = Within<C, D>;
|
|
162
|
+
/** Inert: `at` binds the params and returns the value runners take. */
|
|
163
|
+
interface Declaration<Codecs extends StreamRoute.ParamCodecs, Bound> {
|
|
164
|
+
readonly id: string;
|
|
165
|
+
readonly version: number;
|
|
166
|
+
readonly generation: number;
|
|
167
|
+
readonly params: Codecs;
|
|
168
|
+
/** Throws a RangeError when a param does not encode. */
|
|
169
|
+
readonly at: (params: StreamRoute.Params<Codecs>) => Bound;
|
|
170
|
+
/** Tries declaration inputs in order. Shared inputs return only their declared subset. */
|
|
171
|
+
readonly parse: (id: string) => Option.Option<Partial<StreamRoute.Params<Codecs>>>;
|
|
172
|
+
}
|
|
173
|
+
interface Common<C extends StreamRoute.ParamCodecs, I extends Inputs> {
|
|
174
|
+
readonly id: string;
|
|
175
|
+
readonly version?: number;
|
|
176
|
+
readonly generation?: number;
|
|
177
|
+
readonly params: C;
|
|
178
|
+
readonly inputs: I & Within<C, I>;
|
|
179
|
+
}
|
|
180
|
+
interface Committing<Result, P, Q> {
|
|
181
|
+
readonly commit: Commit<Result, P, Q>;
|
|
182
|
+
}
|
|
183
|
+
type RunningDeclaration<C extends StreamRoute.ParamCodecs, I extends Inputs, E, R, Result, P, Q, S = never, OR = never> = Declaration<C, Omit<Executable<Addresses<I>, E | ProjectionFault, R, Q, Result, P, S, OR>, "process" | "prepare" | "state"> & {
|
|
184
|
+
readonly state: [S] extends [never] ? undefined : BoundState<S>;
|
|
185
|
+
readonly process: (batch: Slices<Addresses<I>>, unit: Unit, encoded?: string) => Effect.Effect<Result, E | ProjectionFault, R>;
|
|
186
|
+
}>;
|
|
187
|
+
type StatefulDeclaration<C extends StreamRoute.ParamCodecs, I extends Inputs, A, E, R, Result, P, Q> = RunningDeclaration<C, I, E, R, Result, P, Q, A>;
|
|
188
|
+
type OutputDeclaration<C extends StreamRoute.ParamCodecs, I extends Inputs, O extends RoutedMap, E, R, Result, P, Q, A = never> = Omit<RunningDeclaration<C, I, E, R, Result, P, Q, A, Services<O>>, "at"> & {
|
|
189
|
+
readonly at: (params: StreamRoute.Params<C>) => ReturnType<RunningDeclaration<C, I, E, R, Result, P, Q, A, Services<O>>["at"]> & {
|
|
190
|
+
readonly streams: Readonly<Record<string, Streamsy.Address<unknown, Services<O>>>>;
|
|
191
|
+
};
|
|
192
|
+
};
|
|
193
|
+
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
|
+
type Step<X, E = never, R = never> = X | Effect.Effect<X, E, R>;
|
|
197
|
+
/** Each output keeps its item type here; missing keys emit nothing. */
|
|
198
|
+
type Emits<O extends RoutedMap> = { readonly [K in keyof O]?: ReadonlyArray<Item<O[K]>>; };
|
|
199
|
+
//#endregion
|
|
200
|
+
//#region src/fold.d.ts
|
|
201
|
+
/** Fold one entry at a time. The default Commit saves state and offsets in one write. */
|
|
202
|
+
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
|
+
readonly state: StateDefinition<A, SI, StreamRoute.Params<C>>;
|
|
204
|
+
readonly commit?: Committing<Folded<NoInfer<A>>, P, Q>["commit"];
|
|
205
|
+
readonly fold: (state: NoInfer<A>, entry: Entry<Addresses<I>>, unit: Unit<StreamRoute.Params<C>>) => Step<A, E, R>;
|
|
206
|
+
}): StatefulDeclaration<C, I, A, E, R, Folded<A>, P, Q>;
|
|
207
|
+
//#endregion
|
|
208
|
+
//#region src/process.d.ts
|
|
209
|
+
/** Run side effects once per unit. prepare runs at least once, outside the transaction. */
|
|
210
|
+
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
|
+
readonly prepare?: (batch: Slices<Addresses<I>>, unit: Unit<StreamRoute.Params<C>>) => Effect.Effect<Prepared, PE, PR>;
|
|
212
|
+
readonly process: (batch: Slices<Addresses<I>>, unit: Unit<StreamRoute.Params<C>>, prepared: Prepared) => Effect.Effect<void, E, R>;
|
|
213
|
+
}): RunningDeclaration<C, I, E | PE, R, void, P, Q | PR>;
|
|
214
|
+
//#endregion
|
|
215
|
+
//#region src/emit.d.ts
|
|
216
|
+
/** Emit zero or more output items for each input entry, in entry order. */
|
|
217
|
+
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
|
+
readonly outputs: O & OutputsWithin<C, O>;
|
|
219
|
+
readonly emit: ((entry: Entry<Addresses<I>>, unit: Unit<StreamRoute.Params<C>>) => Step<X, E, R>) & (Exclude<keyof X, keyof O> extends never ? unknown : {
|
|
220
|
+
readonly undeclaredOutput: Exclude<keyof X, keyof O>;
|
|
221
|
+
});
|
|
222
|
+
}): OutputDeclaration<C, I, O, E, R, Emitted<O>, P, Q>;
|
|
223
|
+
//#endregion
|
|
224
|
+
//#region src/map-accum.d.ts
|
|
225
|
+
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
|
+
readonly outputs: O & OutputsWithin<C, O>;
|
|
227
|
+
readonly state: StateDefinition<A, SI, StreamRoute.Params<C>>;
|
|
228
|
+
};
|
|
229
|
+
/** Thread the value and collect outputs, once per entry. */
|
|
230
|
+
declare function mapAccum<C extends StreamRoute.ParamCodecs, I extends Inputs, const O extends RoutedMap, A, SI, X extends Emits<O>, E = never, R = never, P = never, Q = never>(definition: Definition<C, I, O, A, SI, P, Q> & {
|
|
231
|
+
readonly mapAccum: ((state: NoInfer<A>, entry: Entry<Addresses<I>>, unit: Unit<StreamRoute.Params<C>>) => Step<readonly [A, X], E, R>) & (Exclude<keyof X, keyof O> extends never ? unknown : {
|
|
232
|
+
readonly undeclaredOutput: Exclude<keyof X, keyof O>;
|
|
233
|
+
});
|
|
234
|
+
}): AccumulatingDeclaration<C, I, O, A, E, R, P, Q>;
|
|
235
|
+
/** Compute the next value and outputs once for the whole unit batch. */
|
|
236
|
+
declare function mapAccumBatch<C extends StreamRoute.ParamCodecs, I extends Inputs, const O extends RoutedMap, A, SI, X extends Emits<O>, E = never, R = never, P = never, Q = never>(definition: Definition<C, I, O, A, SI, P, Q> & {
|
|
237
|
+
readonly mapAccumBatch: ((state: NoInfer<A>, batch: Slices<Addresses<I>>, unit: Unit<StreamRoute.Params<C>>) => Step<readonly [A, X], E, R>) & (Exclude<keyof X, keyof O> extends never ? unknown : {
|
|
238
|
+
readonly undeclaredOutput: Exclude<keyof X, keyof O>;
|
|
239
|
+
});
|
|
240
|
+
}): AccumulatingDeclaration<C, I, O, A, E, R, P, Q>;
|
|
241
|
+
//#endregion
|
|
242
|
+
//#region src/snapshot.d.ts
|
|
243
|
+
/** The accepted offset of each input, keyed by input name. The next pass reads after these. */
|
|
244
|
+
type Offsets<Inputs extends InputMap> = { readonly [K in keyof Inputs]: string; };
|
|
245
|
+
/** The state and the offsets it is at. `state` is `undefined` when the declaration has no `state:`. */
|
|
246
|
+
interface Snapshot<S, Inputs extends InputMap> {
|
|
247
|
+
readonly state: S;
|
|
248
|
+
readonly offsets: Offsets<Inputs>;
|
|
249
|
+
}
|
|
250
|
+
type StateValue<S> = [S] extends [never] ? undefined : S;
|
|
251
|
+
/**
|
|
252
|
+
* Reads the state and offsets from one checkpoint record, so the state
|
|
253
|
+
* always matches the offsets. Before the first unit, the state is the declared initial
|
|
254
|
+
* value and every offset is the start of its input.
|
|
255
|
+
*/
|
|
256
|
+
declare const read: <Inputs extends InputMap, S = never, Q = never>(projection: Identity & {
|
|
257
|
+
readonly inputs: Inputs;
|
|
258
|
+
readonly state?: BoundState<S>;
|
|
259
|
+
readonly commit: Pick<Commit<never, never, Q>, "load">;
|
|
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";
|
|
265
|
+
readonly units: number;
|
|
266
|
+
readonly items: number;
|
|
267
|
+
readonly offsets: Offsets<Inputs>;
|
|
268
|
+
}
|
|
269
|
+
/** 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<Progress<Inputs>, E | ProjectionFault, OR | Q | InputServices<Inputs> | Exclude<R, P>>;
|
|
271
|
+
/** Repeats pass until caught up, closed, or limited. Use one writer per key. */
|
|
272
|
+
declare const run: <Inputs extends InputMap, E, R, Q, Result, P, OR = never>(projection: Executable<Inputs, E, R, Q, Result, P, unknown, OR>, options?: RunOptions | undefined) => Effect.Effect<Progress<Inputs>, E | ProjectionFault, OR | Q | InputServices<Inputs> | Exclude<R, P>>;
|
|
273
|
+
//#endregion
|
|
274
|
+
//#region src/follow.d.ts
|
|
275
|
+
interface FollowOptions extends RunOptions {
|
|
276
|
+
/** Upper bound on one wake wait; default 30000. */
|
|
277
|
+
readonly repairIntervalMs?: number;
|
|
278
|
+
/** Override the forever, capped exponential retry for retryable storage failures. */
|
|
279
|
+
readonly retry?: Schedule.Schedule<unknown>;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Runs to caught-up, then waits for the first input to hint at a change and runs
|
|
283
|
+
* again. The caller's scope owns the fiber and every parked wait; joining exposes
|
|
284
|
+
* the terminal close or a typed failure. On HTTP backends a parked hint is cancelled
|
|
285
|
+
* and replaced once per `repairIntervalMs` until an input changes.
|
|
286
|
+
*/
|
|
287
|
+
declare const follow: <Inputs extends InputMap, E, R, Q, Result, P, OR = never>(projection: Executable<Inputs, E, R, Q, Result, P, unknown, OR>, options?: FollowOptions | undefined) => Effect.Effect<Fiber.Fiber<Progress<Inputs>, E | ProjectionFault>, ProjectionFault, OR | Q | Scope.Scope | InputServices<Inputs> | Exclude<R, P>>;
|
|
288
|
+
//#endregion
|
|
289
|
+
//#region src/current.d.ts
|
|
290
|
+
/** A bound value projection. Output items from its adapter are discarded. */
|
|
291
|
+
interface CurrentProjection<Inputs extends InputMap, S, E, R, Q> extends Identity {
|
|
292
|
+
readonly inputs: Inputs;
|
|
293
|
+
readonly state: BoundState<S>;
|
|
294
|
+
readonly commit: Pick<Commit<never, never, Q>, "load">;
|
|
295
|
+
readonly process: (batch: Slices<Inputs>, unit: Unit, encoded?: string) => Effect.Effect<{
|
|
296
|
+
readonly value: S;
|
|
297
|
+
readonly encoded: string;
|
|
298
|
+
}, E, R>;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Folds the checkpoint and input tail in memory, without locks or writes.
|
|
302
|
+
* Includes entries appended before the call. A growing input can delay completion.
|
|
303
|
+
* Fold steps must be replayable. Pending ranges are read from committed offsets.
|
|
304
|
+
*/
|
|
305
|
+
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
|
+
interface DecideSpec<Inputs extends InputMap, K extends keyof Inputs, S, B, E, R> {
|
|
309
|
+
/** The input to append to. Its offset in the snapshot is the CAS token. */
|
|
310
|
+
readonly input: K;
|
|
311
|
+
/**
|
|
312
|
+
* Decide what to append from the current value snapshot. This step must not write.
|
|
313
|
+
*/
|
|
314
|
+
readonly decide: (snapshot: Snapshot<S, Inputs>) => Effect.Effect<Decision<B, ItemOf<Inputs[K]>>, E, R>;
|
|
315
|
+
/** Retries after `OffsetMismatch`. Default: `Schedule.recurs(3)`. Nothing else is retried. */
|
|
316
|
+
readonly retry?: Schedule.Schedule<unknown, OffsetMismatch>;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Fold in memory, decide, and append with the snapshot input offset.
|
|
320
|
+
* Retry only this append's OffsetMismatch while the retry schedule allows.
|
|
321
|
+
*/
|
|
322
|
+
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<{
|
|
323
|
+
readonly owner: object;
|
|
324
|
+
readonly wire: import("@streamsy/core/protocol").Reader<import("@streamsy/core").StreamsFault> & import("@streamsy/core/protocol").Writer<import("@streamsy/core").StreamsFault>;
|
|
325
|
+
}, 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<{
|
|
326
|
+
readonly owner: object;
|
|
327
|
+
readonly wire: import("@streamsy/core/protocol").Reader<import("@streamsy/core").StreamsFault> & import("@streamsy/core/protocol").Writer<import("@streamsy/core").StreamsFault>;
|
|
328
|
+
}, 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>;
|
|
329
|
+
/**
|
|
330
|
+
* Marks the `OffsetMismatch` of this call's own append. As in `Streams.decide`,
|
|
331
|
+
* only this error is retried: an `OffsetMismatch` that the caller's `decide`
|
|
332
|
+
* raises is its own failure and passes through.
|
|
333
|
+
*/
|
|
334
|
+
declare class LostRace {
|
|
335
|
+
readonly mismatch: OffsetMismatch;
|
|
336
|
+
constructor(mismatch: OffsetMismatch);
|
|
337
|
+
}
|
|
338
|
+
//#endregion
|
|
339
|
+
//#region src/forget.d.ts
|
|
340
|
+
/**
|
|
341
|
+
* Deletes the record. Stop the follower first, or use a new generation.
|
|
342
|
+
* Delete stream outputs first, because forgetting restarts their producer sequences.
|
|
343
|
+
*/
|
|
344
|
+
declare const forget: <R>(projection: ProjectionKey & {
|
|
345
|
+
readonly commit: Pick<Commit<never, never, R>, "remove">;
|
|
346
|
+
}) => Effect.Effect<void, ProjectionFault, R>;
|
|
347
|
+
declare namespace projection_d_exports {
|
|
348
|
+
export { current, decide, each, emit, fold, follow, forget, items, key, mapAccum, mapAccumBatch, pass, process, read, run };
|
|
349
|
+
}
|
|
350
|
+
declare const key: (projection: Identity) => ProjectionKey;
|
|
351
|
+
/** Runs each tagged entry in order and discards its success value. */
|
|
352
|
+
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
|
+
//#endregion
|
|
354
|
+
//#region src/retry.d.ts
|
|
355
|
+
/** Default storage-failure retry for follow; an explicit options.retry takes precedence. */
|
|
356
|
+
export declare const ProjectionRetry: Context.Reference<Schedule.Schedule<unknown, unknown, never, never>>;
|
|
357
|
+
//#endregion
|
|
358
|
+
export { type Accumulated, 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 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 };
|