@streamsy/projection 0.11.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +162 -29
- package/dist/{checkpoint-store-D1saxIIM.d.ts → checkpoint-store-B1199nDD.d.ts} +58 -3
- package/dist/{checkpoint-store-Bm8z-f-l.js → checkpoint-store-ViVETLzZ.js} +201 -35
- package/dist/checkpoint.d.ts +2 -2
- package/dist/checkpoint.js +1 -1
- package/dist/index.d.ts +560 -153
- package/dist/index.js +1627 -257
- package/package.json +4 -5
package/README.md
CHANGED
|
@@ -5,18 +5,25 @@ step. Its `commit:` value defines how results and offsets become durable.
|
|
|
5
5
|
|
|
6
6
|
## Constructors
|
|
7
7
|
|
|
8
|
-
| Constructor | Handler | Result
|
|
9
|
-
| -------------------------- | ------------------------ |
|
|
10
|
-
| `Projection.fold` | `(state, entry, unit)` | Next value
|
|
11
|
-
| `Projection.process` | `(batch, unit, context)` | Effect of void
|
|
12
|
-
| `Projection.emit` | `(entry, unit)` | Output items
|
|
13
|
-
| `Projection.mapAccum` | `(state, entry, unit)` | `[state, emits]`
|
|
14
|
-
| `Projection.mapAccumBatch` | `(state, batch, unit)` | `[state, emits]`
|
|
8
|
+
| Constructor | Handler | Result | Commit |
|
|
9
|
+
| -------------------------- | ------------------------ | -------------------------- | ------------------------------- |
|
|
10
|
+
| `Projection.fold` | `(state, entry, unit)` | Next value | Defaults to `Commit.checkpoint` |
|
|
11
|
+
| `Projection.process` | `(batch, unit, context)` | Effect of void or `WakeAt` | Required |
|
|
12
|
+
| `Projection.emit` | `(entry, unit)` | Output items | Required |
|
|
13
|
+
| `Projection.mapAccum` | `(state, entry, unit)` | `[state, emits]` | Required |
|
|
14
|
+
| `Projection.mapAccumBatch` | `(state, batch, unit)` | `[state, emits]` | Required |
|
|
15
15
|
|
|
16
16
|
Except for `process`, steps return a value or an Effect. A missing output key
|
|
17
17
|
emits nothing. `Projection.each` adapts an entry handler for `process`.
|
|
18
18
|
Batch handlers must give the same final rows for any unit size. In per-entry
|
|
19
|
-
steps, use `unit` for parameters and
|
|
19
|
+
steps, use `unit` for parameters and unit ranges.
|
|
20
|
+
|
|
21
|
+
A local input's `Slice.offsets` holds one storage offset per item, in item order;
|
|
22
|
+
its last offset equals `nextOffset` when non-empty. `Entry.offset` carries the
|
|
23
|
+
same offset, and a read from `entry.offset` resumes after that entry. Non-empty
|
|
24
|
+
HTTP inputs have `offsets` undefined and entries omit `offset`, because HTTP
|
|
25
|
+
supplies page boundaries only. Every empty slice has `offsets: []`, including
|
|
26
|
+
skipped inputs and timer-only units. Pinned retries retain the entry offsets.
|
|
20
27
|
|
|
21
28
|
```ts
|
|
22
29
|
import { Effect, Layer, Schema } from "effect";
|
|
@@ -75,9 +82,24 @@ across producer outputs. Chain projections for sinks with different guarantees.
|
|
|
75
82
|
outside the transaction. It runs at least once and passes its result to
|
|
76
83
|
`process`. A retry can read new input and change `unit.key`.
|
|
77
84
|
|
|
85
|
+
`Commit.transactionWithCleanup((key, sql) => cleanup)` passes the binding's
|
|
86
|
+
checkpoint key and transaction SQL client to the cleanup Effect.
|
|
87
|
+
`Projection.forget` runs cleanup after deleting any live checkpoint.
|
|
88
|
+
`Projection.retire` runs it after the tombstone write and owned output cleanup.
|
|
89
|
+
The callback also runs on a repeated retirement. A cleanup failure rolls back
|
|
90
|
+
changes in the same transaction, including SQL run with the supplied client.
|
|
91
|
+
|
|
78
92
|
`Commit.withCompensation(f)` calls `f(result, cause, unit)` after successful
|
|
79
93
|
processing if the commit fails. It is also available as a `.pipe` combinator.
|
|
80
|
-
For
|
|
94
|
+
For external delivery, use `Commit.atLeastOnce` with `unit.key` as the idempotency key,
|
|
95
|
+
the declaration's [binding retry policy](https://streamsy.dev/docs/reference/projection/runners#binding-retry)
|
|
96
|
+
for a retry budget and `onExhausted`, and [`Projection.wakeAt`](https://streamsy.dev/docs/projections/process#timers)
|
|
97
|
+
for a deferred retry or a snooze. See the [effects guide](https://streamsy.dev/docs/projections/effects) for the complete pattern.
|
|
98
|
+
|
|
99
|
+
To stop a binding on a permanent typed handler error, add
|
|
100
|
+
`readonly [NonRetryable] = true` using `NonRetryable` from `@streamsy/projection`.
|
|
101
|
+
Attached runners report the failure without stepping the retry schedule or
|
|
102
|
+
calling `onExhausted`.
|
|
81
103
|
|
|
82
104
|
`Commit.make` defines `load`, `apply`, and optional `remove`. Custom Commits
|
|
83
105
|
extend ranges on retry. Never save after a failed handler; compare-and-set on
|
|
@@ -145,8 +167,9 @@ const filesWake = Projection.wake({
|
|
|
145
167
|
```
|
|
146
168
|
|
|
147
169
|
Here `Files.at` takes `user` and `folderId`, and `UserWake.at` takes
|
|
148
|
-
`user`. Each Files id supplies both params for attachment. The wake stream can live
|
|
149
|
-
|
|
170
|
+
`user`. Each Files id supplies both params for attachment. The wake stream can live
|
|
171
|
+
on another owner, where its owner must create it before the first append. The producer
|
|
172
|
+
creates a missing output on its checkpoint owner only. A retry answers `Duplicate`, so delivery is effectively
|
|
150
173
|
once for each binding. Rows of one source arrive in source order. A reader that
|
|
151
174
|
comes before the first append gets 404 unless the owner calls the normal State
|
|
152
175
|
service's `create` to make an empty stream available. `Streamsy.wake` is a State
|
|
@@ -221,16 +244,42 @@ its binding on its first commit, and the app names no bindings.
|
|
|
221
244
|
```ts
|
|
222
245
|
const host = Layer.mergeAll(Api, Projection.attach(filesWake)).pipe(
|
|
223
246
|
Layer.provideMerge(CheckpointStore.layer),
|
|
224
|
-
Layer.provideMerge(BunStorage.layer(streams, { path })),
|
|
247
|
+
Layer.provideMerge(BunStorage.layer(streams, { client: { filename: path } })),
|
|
225
248
|
);
|
|
226
249
|
```
|
|
227
250
|
|
|
228
251
|
Each input must give every projection param, so that one id picks one binding.
|
|
229
252
|
`attach` throws a `RangeError` when an input does not. Inputs on another owner
|
|
230
|
-
never commit here
|
|
253
|
+
never commit here; use a wake stream in `triggers` to request their bindings. Do not also run an attached binding
|
|
231
254
|
under `Projection.follow`.
|
|
232
255
|
|
|
233
|
-
|
|
256
|
+
Pass fixed-address wake classes with `triggers: [Wake]`. A provided stream service
|
|
257
|
+
on another owner makes a trigger remote; a matching owner or absent service
|
|
258
|
+
uses local storage. Provide the remote class
|
|
259
|
+
at runtime with `Protocol.bind(RemoteStreams.layerProtocol(...), Streamsy.group(Wake))`
|
|
260
|
+
or another owner's protocol layer. `Projection.attach` starts a scoped live-read
|
|
261
|
+
follower for each remote trigger, so a remote upsert wakes it without a local
|
|
262
|
+
commit. `ProjectionWakeup.attach` rejects remote triggers at attach with a
|
|
263
|
+
`RangeError` naming the stream; it accepts only its own storage owner's triggers.
|
|
264
|
+
|
|
265
|
+
A pass reads local triggers, drains bindings, then reads one page per remote
|
|
266
|
+
trigger outside the local transaction. Durable marks and the page's `nextOffset`
|
|
267
|
+
commit together locally. Cursors persist in both durability modes; private marks
|
|
268
|
+
can be lost after ingestion on restart. Missing or deleted remote streams leave
|
|
269
|
+
the cursor unchanged without a fault. Invalid requests, data or page cursors stop
|
|
270
|
+
only that trigger with `invalid-source`; `registry.rescan` and projection-level
|
|
271
|
+
`registry.retry` clear the stop. Remote transport or storage read failures fail
|
|
272
|
+
the pass retryably after all remote triggers are attempted. Local commits during
|
|
273
|
+
pass backoff wait until it ends, up to the default 30 s cap. The follower uses its
|
|
274
|
+
own `passRetry` steps and never signals a failure. `next` makes no network request.
|
|
275
|
+
See [Trigger streams](https://streamsy.dev/docs/projections/run#trigger-streams).
|
|
276
|
+
|
|
277
|
+
By default `Projection.attach` keeps pending binding marks, timers and backoff in private memory.
|
|
278
|
+
In both modes a retryable failed binding waits alone, by default from 1 s doubling to 1 hour, while
|
|
279
|
+
its neighbours run. A non-retryable projection or storage fault stops only the binding that failed.
|
|
280
|
+
Handler errors and defects retry. A local commit or trigger row does not shorten backoff or end a stop;
|
|
281
|
+
`registry.retry` or `registry.schedule` makes it due now. `registry.failed` lists
|
|
282
|
+
failed bindings with their stored cause. A runner start makes stopped marks due once.
|
|
234
283
|
If the process stops after a commit and before the run, the binding is late
|
|
235
284
|
until its source gets its next write. The next run catches up from the
|
|
236
285
|
checkpoint while the source history remains available. Removal before that run
|
|
@@ -239,19 +288,17 @@ file does not show.
|
|
|
239
288
|
|
|
240
289
|
Pass `durable: true` to close that gap. Each commit then also writes a pending
|
|
241
290
|
mark for each binding it touches, in the same transaction, to
|
|
242
|
-
`streamsy_projection_pending`. A binding that catches up
|
|
243
|
-
|
|
244
|
-
the
|
|
245
|
-
|
|
246
|
-
neighbours keep running. Durable mode needs a local memory or SQL storage
|
|
247
|
-
layer.
|
|
291
|
+
`streamsy_projection_pending`. A binding that catches up keeps a sleeping mark
|
|
292
|
+
when its checkpoint records a wake; otherwise it deletes its mark, unless a write
|
|
293
|
+
during the run marked it again. When the layer starts, it runs
|
|
294
|
+
the bindings with due marks, up to `batch` (default 25) per pass. Durable mode needs a local memory or SQL storage layer.
|
|
248
295
|
|
|
249
296
|
On Cloudflare, acquire a wakeup in the object's layer scope. Local commits
|
|
250
297
|
fill the same runner's pending set; `next` answers "now" while it has work,
|
|
251
298
|
and each alarm drains one pass (100 units per binding by default).
|
|
252
299
|
`ProjectionWakeup.attach` is durable by default, because Cloudflare evicts idle
|
|
253
300
|
objects. After an eviction or a deploy, the object's acquire reads the marks
|
|
254
|
-
and arms the alarm. Pass `durable: false` for
|
|
301
|
+
and arms the alarm, including sleeping timer deadlines. Pass `durable: false` for private memory marks and timers that reset on eviction until the binding's next input.
|
|
255
302
|
|
|
256
303
|
```ts
|
|
257
304
|
StreamsyObject.make({
|
|
@@ -261,15 +308,101 @@ StreamsyObject.make({
|
|
|
261
308
|
});
|
|
262
309
|
```
|
|
263
310
|
|
|
264
|
-
Both forms accept `
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
311
|
+
Both attach forms accept `concurrency` (default `1`), the most bindings run at once.
|
|
312
|
+
It must be a positive safe integer. Each binding still runs in at most one fiber;
|
|
313
|
+
units within that binding run in order.
|
|
314
|
+
|
|
315
|
+
| Host | `Commit.transaction` | `Commit.atLeastOnce` |
|
|
316
|
+
| --------------------------- | ---------------------------------------------------------------------------------------- | ------------------------------------ |
|
|
317
|
+
| SQLite (Bun, Node and Deno) | Transaction bodies serialize; reads and `prepare` can overlap another unit's transaction | Handler bodies run in parallel |
|
|
318
|
+
| Durable Objects | As SQLite | Handler bodies overlap across awaits |
|
|
319
|
+
| Postgres and MySQL | Handler bodies run in parallel up to the pool size, subject to shared output row locks | Handler bodies run in parallel |
|
|
320
|
+
|
|
321
|
+
Keep `concurrency` below the pool size: each `Commit.transaction` unit holds one
|
|
322
|
+
pooled connection for its whole handler. Both server drivers default to 10 connections;
|
|
323
|
+
leave a connection for reads, appends and runner storage operations. Inside the handler, run all SQL on the
|
|
324
|
+
provided `SqlClient` in the handler's fiber. `sql.reserve` or a fiber without the
|
|
325
|
+
handler's transaction context waits forever on SQLite, and on a pool once every
|
|
326
|
+
connection holds a transaction. Appending to a shared output last keeps its row
|
|
327
|
+
lock short: units serialize from that append until commit. Units that lock streams
|
|
328
|
+
in opposite orders across separate appends can deadlock on Postgres or MySQL; the
|
|
329
|
+
database aborts one transaction and its binding backs off before retrying.
|
|
330
|
+
|
|
331
|
+
All five constructors accept `retry: { schedule?, maxAttempts?, onExhausted? }`.
|
|
332
|
+
The default binding retry doubles from 1 s to 1 hour without a limit. A finite schedule
|
|
333
|
+
or `maxAttempts` stops the binding when exhausted; `registry.failed` includes
|
|
334
|
+
`exhausted: true`. `registry.retry` permits one more run. New input during backoff
|
|
335
|
+
keeps the attempt count and deadline; success clears them. The runner replays a fresh
|
|
336
|
+
schedule for the failure count, so use step-count schedules, without input or elapsed-time
|
|
337
|
+
dependence. Stored deadlines survive durable restarts without recomputation.
|
|
338
|
+
`onExhausted(unit, failure)` runs at least once before stopping; dedupe with `unit.key`.
|
|
339
|
+
It receives decoded params. If no unit formed before the exhausting failure, the hook
|
|
340
|
+
is skipped and logged. A failing hook is logged and the binding stops anyway.
|
|
341
|
+
Non-retryable faults stop without the hook. Hooks run outside the handler transaction.
|
|
342
|
+
A `process` context includes `attempt`, starting at 1 and increasing on failed attached
|
|
343
|
+
runs. Direct `run` and `follow` always use 1. See [binding retry](https://streamsy.dev/docs/reference/projection/runners#binding-retry).
|
|
344
|
+
|
|
345
|
+
Both forms accept `passRetry: Schedule.Schedule<unknown>`. Timing only: the runner calls
|
|
346
|
+
the schedule once per retryable failed pass with no input. Bun waits for its delays; the
|
|
347
|
+
alarm host uses them to re-arm. A dying schedule is logged and treated as exhausted. The default is capped, jittered exponential backoff.
|
|
348
|
+
An attach call that still passes the removed `retry` option throws a `RangeError` naming `passRetry`.
|
|
349
|
+
A finite schedule stops pass retries when exhausted. Binding failures use the declaration's `retry` policy; the pass policy paces failures in marks, cursor or trigger operations.
|
|
268
350
|
|
|
269
351
|
SQL hosts keep checkpoints in `streamsy_owner_records`. Older projection tables
|
|
270
352
|
are not migrated or read; projections rebuild from zero.
|
|
271
353
|
Layer authors use `EncodedStore` and `fromStore` from `@streamsy/projection/checkpoint`.
|
|
272
354
|
|
|
355
|
+
`Projection.Registry.layer` exposes attached runners through `status`, `changes`,
|
|
356
|
+
`events`, `failed` and `awaitOffset`. `registry.schedule(binding)` also accepts an
|
|
357
|
+
array of bindings of one projection and wakes the runner once. Mixed projection
|
|
358
|
+
ids die with `RangeError`; empty arrays do nothing and duplicates coalesce. Every
|
|
359
|
+
binding is validated before any marks are written. Invalid params fail with
|
|
360
|
+
`InvalidBinding`. Marks are written in chunks of 100; a later storage failure can
|
|
361
|
+
leave earlier chunks marked, so repeat the request safely. The call returns before
|
|
362
|
+
processing finishes. `registry.retry(target)` makes failed work due now.
|
|
363
|
+
|
|
364
|
+
After a fold fix, `registry.rescan(projectionOrId, WakeClassOrStreamId)` resets one
|
|
365
|
+
trigger cursor to `ZERO_OFFSET`, clears its stop and wakes the runner. It does not
|
|
366
|
+
reset binding checkpoints; use the appropriate version or generation for the fix.
|
|
367
|
+
A row that still fails to decode stops that stream again. The cursor is stored in
|
|
368
|
+
both durability modes and survives restart; ingested marks survive only in durable
|
|
369
|
+
mode. An unknown projection fails with `NotAttached`; an unknown trigger dies with
|
|
370
|
+
`RangeError`. A first attach already reads a trigger stream from its start, so a new
|
|
371
|
+
family needs no rescan. See [runner requests](https://streamsy.dev/docs/projections/run#observe-attached-runners).
|
|
372
|
+
|
|
373
|
+
## Timers
|
|
374
|
+
|
|
375
|
+
A `Projection.process` handler can return `Projection.wakeAt(time)`, with epoch
|
|
376
|
+
milliseconds or an Effect `DateTime`, under `Commit.atLeastOnce` or
|
|
377
|
+
`Commit.transaction` (including compensation wrappers). Returning void clears the
|
|
378
|
+
previous timer; new input before the deadline can replace or cancel it. Other
|
|
379
|
+
return values are discarded. A custom `Commit<void>` does not fit a timer handler.
|
|
380
|
+
|
|
381
|
+
When the recorded time is due, the handler receives `unit.due: Some(time)`. Without
|
|
382
|
+
new input, the slices and `unit.ranges` are empty. With new input, one unit carries
|
|
383
|
+
both the items and the due time. The key includes the recorded due time, so pinned
|
|
384
|
+
retries keep it and distinct deadlines have different keys. Decide what is due
|
|
385
|
+
from `unit.due`; read `Clock` only to choose a late policy.
|
|
386
|
+
|
|
387
|
+
`run`, `pass` and `follow` handle due timers when they next run. They do not wait
|
|
388
|
+
for the deadline; `follow` can discover it on an input change or repair cycle.
|
|
389
|
+
A `run` cycle makes at most one due unit without input, even if its handler returns
|
|
390
|
+
a time already passed. Return a time after `unit.due` for the next wake.
|
|
391
|
+
|
|
392
|
+
`Projection.attach` wakes a sleeping binding at its recorded deadline. Its process
|
|
393
|
+
wait re-reads the wall clock at least every 30 seconds while a deadline exists,
|
|
394
|
+
so after host suspend a passed wake is discovered within 30 seconds of resume.
|
|
395
|
+
`ProjectionWakeup.attach` exposes that deadline to the Durable Object alarm host,
|
|
396
|
+
which arms its alarm for the wake time. Wakes can be late; handlers use `unit.due`
|
|
397
|
+
to apply their late policy. A wake during backoff waits for backoff to end. A
|
|
398
|
+
stopped binding keeps its checkpoint timer and fires late after retry or restart.
|
|
399
|
+
With `durable: false`, pending work and timers live in private memory: restart or
|
|
400
|
+
eviction loses a timer's wake until the binding's next input. Use durable marks
|
|
401
|
+
on persistent storage for restart recovery.
|
|
402
|
+
|
|
403
|
+
Return a time after `unit.due` for the next wake. Repeatedly returning a passed
|
|
404
|
+
time leaves the mark due immediately and can run the handler at pass speed.
|
|
405
|
+
|
|
273
406
|
## Run and recover
|
|
274
407
|
|
|
275
408
|
`declaration.at(params)` binds a projection. `pass` runs one unit; `run` continues
|
|
@@ -278,10 +411,10 @@ that runs to caught up, then waits for changes, with a default repair interval o
|
|
|
278
411
|
30 seconds. Remote inputs work with `follow` and `run`.
|
|
279
412
|
|
|
280
413
|
`run` and each `follow` element give a `Progress`: the `state` and `offsets` that
|
|
281
|
-
the last pass left, plus `status`, `units`, and `
|
|
414
|
+
the last pass left, plus `status`, `units`, `items`, and `wakeAt: Option<number>`. The stream
|
|
282
415
|
emits after the first cycle, after each cycle that commits a unit or reaches
|
|
283
|
-
`limit`, and after the last cycle when every input is closed; then it ends. A
|
|
284
|
-
that finds no input emits nothing. Invalid options fail the stream at its first pull.
|
|
416
|
+
`limit`, and after the last cycle when every input is closed; then it ends. A cycle
|
|
417
|
+
that finds no input or due timer emits nothing. Invalid options fail the stream at its first pull.
|
|
285
418
|
|
|
286
419
|
```ts
|
|
287
420
|
// Forks the follower into the caller's scope; closing the scope stops it.
|
|
@@ -303,7 +436,7 @@ already run. Any number of `current` and `decide` calls can run beside the
|
|
|
303
436
|
follower, including inside a caller transaction. Table and stateless output
|
|
304
437
|
projections are follow-only; wait on their output to see a command.
|
|
305
438
|
|
|
306
|
-
`follow` retries
|
|
439
|
+
`follow` retries `token-conflict`, `output-busy`, and retryable `storage-failure`: `options.retry` overrides the
|
|
307
440
|
`ProjectionRetry` context reference, whose default is jittered exponential
|
|
308
441
|
backoff from 200 ms, capped at 30 s. `run` does not retry. Handler errors retain
|
|
309
442
|
their types; `ProjectionFault` carries `phase`, `reason`, and `cause`.
|
|
@@ -8,6 +8,12 @@ interface Slice<A> {
|
|
|
8
8
|
/** Cursor the read started after. Equal to `nextOffset` when the slice is empty. */
|
|
9
9
|
readonly from: string;
|
|
10
10
|
readonly items: ReadonlyArray<A>;
|
|
11
|
+
/**
|
|
12
|
+
* One storage offset per item, also the read cursor just after that item.
|
|
13
|
+
* For a non-empty local slice, offsets.at(-1) === nextOffset. Undefined for
|
|
14
|
+
* non-empty HTTP reads; empty slices always have offsets: [].
|
|
15
|
+
*/
|
|
16
|
+
readonly offsets?: ReadonlyArray<string>;
|
|
11
17
|
readonly nextOffset: string;
|
|
12
18
|
readonly upToDate: boolean;
|
|
13
19
|
readonly closed: boolean;
|
|
@@ -20,11 +26,26 @@ type Entry<Inputs extends InputMap> = { readonly [K in keyof Inputs]: {
|
|
|
20
26
|
readonly input: K;
|
|
21
27
|
readonly item: ItemOf<Inputs[K]>;
|
|
22
28
|
readonly index: number;
|
|
29
|
+
/** Storage offset of this item; reading from it resumes after the item. Absent over HTTP. */
|
|
30
|
+
readonly offset?: string;
|
|
23
31
|
}; }[keyof Inputs];
|
|
24
32
|
type InputServices<Inputs extends InputMap> = Inputs[keyof Inputs]["stream"]["Identifier"];
|
|
33
|
+
/** A typed handler failure bearing this marker stops its binding without retry. */
|
|
34
|
+
declare const NonRetryable: unique symbol;
|
|
35
|
+
declare const NotAttached_base: Schema.Class<NotAttached, Schema.TaggedStruct<"NotAttached", {
|
|
36
|
+
readonly projection: Schema.String;
|
|
37
|
+
}>, import("effect/Cause").YieldableError>;
|
|
38
|
+
/** No live runner for this declaration exists in the selected registry. */
|
|
39
|
+
declare class NotAttached extends NotAttached_base {}
|
|
40
|
+
declare const InvalidBinding_base: Schema.Class<InvalidBinding, Schema.TaggedStruct<"InvalidBinding", {
|
|
41
|
+
readonly projection: Schema.String;
|
|
42
|
+
readonly params: Schema.$Record<Schema.String, Schema.String>;
|
|
43
|
+
}>, import("effect/Cause").YieldableError>;
|
|
44
|
+
/** Encoded params do not round-trip through the attached declaration's codecs. */
|
|
45
|
+
declare class InvalidBinding extends InvalidBinding_base {}
|
|
25
46
|
declare const ProjectionFault_base: Schema.Class<ProjectionFault, Schema.TaggedStruct<"ProjectionFault", {
|
|
26
47
|
readonly phase: Schema.Literals<readonly ["load", "read", "pin", "process", "checkpoint"]>;
|
|
27
|
-
readonly reason: Schema.Literals<readonly ["history-unavailable", "identity-mismatch", "invalid-record", "invalid-source", "invalid-options", "invalid-output", "token-conflict", "range-unreproducible", "stale-epoch", "storage-failure", "unsupported-composition"]>;
|
|
48
|
+
readonly reason: Schema.Literals<readonly ["history-unavailable", "identity-mismatch", "invalid-record", "invalid-source", "invalid-options", "invalid-output", "token-conflict", "output-busy", "range-unreproducible", "stale-epoch", "retired-generation", "storage-failure", "unsupported-composition"]>;
|
|
28
49
|
readonly input: Schema.optionalKey<Schema.String>;
|
|
29
50
|
readonly message: Schema.String;
|
|
30
51
|
readonly cause: Schema.optionalKey<Schema.Defect>;
|
|
@@ -49,6 +70,8 @@ interface Unit<P = Record<string, string>> {
|
|
|
49
70
|
readonly params: P;
|
|
50
71
|
/** The inputs that contributed items or a terminal outcome; retries reproduce these. */
|
|
51
72
|
readonly ranges: Record<string, Range>;
|
|
73
|
+
/** Recorded wake time, rather than the clock time when this unit runs. */
|
|
74
|
+
readonly due: Option.Option<number>;
|
|
52
75
|
readonly key: string;
|
|
53
76
|
}
|
|
54
77
|
declare const CheckpointRecord: Schema.Struct<{
|
|
@@ -66,8 +89,11 @@ declare const CheckpointRecord: Schema.Struct<{
|
|
|
66
89
|
readonly count: Schema.Finite;
|
|
67
90
|
readonly upToDate: Schema.optionalKey<Schema.Boolean>;
|
|
68
91
|
}>>;
|
|
92
|
+
readonly due: Schema.optionalKey<Schema.Finite>;
|
|
69
93
|
readonly seqs: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Finite>>;
|
|
70
94
|
}>>;
|
|
95
|
+
/** Next process wake, in epoch milliseconds. Absent means no timer. */
|
|
96
|
+
readonly wakeAt: Schema.optionalKey<Schema.Finite>;
|
|
71
97
|
/** Inputs whose terminal close has already been processed. */
|
|
72
98
|
readonly closed: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Boolean>>;
|
|
73
99
|
/** The final gone unit committed; only forgetting remains. */
|
|
@@ -81,6 +107,7 @@ declare const CheckpointRecord: Schema.Struct<{
|
|
|
81
107
|
}>;
|
|
82
108
|
}>;
|
|
83
109
|
interface CheckpointRecord extends Schema.Schema.Type<typeof CheckpointRecord> {}
|
|
110
|
+
type RetirementStatus = "retired" | "already-retired";
|
|
84
111
|
interface ProjectionKey {
|
|
85
112
|
readonly id: string;
|
|
86
113
|
readonly version: number;
|
|
@@ -92,13 +119,39 @@ interface Loaded {
|
|
|
92
119
|
readonly record: Option.Option<CheckpointRecord>;
|
|
93
120
|
readonly token: string;
|
|
94
121
|
}
|
|
122
|
+
/** A binding found by `CheckpointStoreApi.list`. */
|
|
123
|
+
interface ListedBinding {
|
|
124
|
+
readonly generation: number;
|
|
125
|
+
readonly params: Record<string, string>;
|
|
126
|
+
}
|
|
127
|
+
interface RoutedStreamRecord {
|
|
128
|
+
readonly output: string;
|
|
129
|
+
readonly streamId: string;
|
|
130
|
+
}
|
|
131
|
+
/** Access the route inventory in the checkpoint owner's transaction. */
|
|
132
|
+
interface RouteRecords {
|
|
133
|
+
readonly has: (key: ProjectionKey, output: string, streamId: string) => Effect.Effect<boolean, ProjectionFault>;
|
|
134
|
+
readonly add: (key: ProjectionKey, output: string, streamId: string) => Effect.Effect<void, ProjectionFault>;
|
|
135
|
+
readonly list: (key: ProjectionKey) => Effect.Effect<ReadonlyArray<RoutedStreamRecord>, ProjectionFault>;
|
|
136
|
+
readonly clear: (key: ProjectionKey) => Effect.Effect<void, ProjectionFault>;
|
|
137
|
+
}
|
|
95
138
|
interface CheckpointStoreApi {
|
|
96
139
|
readonly load: (key: ProjectionKey) => Effect.Effect<Loaded, ProjectionFault>;
|
|
140
|
+
/**
|
|
141
|
+
* Lists each generation and encoded params with a live checkpoint for an id, across
|
|
142
|
+
* checkpoint versions. Each pair appears once, in unspecified order.
|
|
143
|
+
*/
|
|
144
|
+
readonly list?: (id: string) => Effect.Effect<ReadonlyArray<ListedBinding>, ProjectionFault>;
|
|
145
|
+
/** Generation-owned streams opened lazily by routed outputs. */
|
|
146
|
+
readonly routes?: RouteRecords;
|
|
97
147
|
/** Compare-and-set inside the owner transaction; returns the new token. */
|
|
98
148
|
readonly compareAndSet: (key: ProjectionKey, ifToken: string, record: CheckpointRecord) => Effect.Effect<string, ProjectionFault>;
|
|
99
|
-
/** Deletes
|
|
149
|
+
/** Deletes a live record. Absent keys and tombstones are ignored. */
|
|
100
150
|
readonly remove: (key: ProjectionKey) => Effect.Effect<void, ProjectionFault>;
|
|
151
|
+
/** Replaces the live or absent record with a tombstone. */
|
|
152
|
+
readonly retire?: (key: ProjectionKey) => Effect.Effect<RetirementStatus, ProjectionFault>;
|
|
101
153
|
}
|
|
154
|
+
type EncodedEntries = ReadonlyArray<readonly [key: string, encoded: string]>;
|
|
102
155
|
declare const CheckpointStore_base: Context.ServiceClass<CheckpointStore, "@streamsy/projection/CheckpointStore", CheckpointStoreApi>;
|
|
103
156
|
/** Stores each projection's offsets and encoded state in one compare-and-set record. */
|
|
104
157
|
declare class CheckpointStore extends CheckpointStore_base {
|
|
@@ -112,6 +165,8 @@ declare class CheckpointStore extends CheckpointStore_base {
|
|
|
112
165
|
}
|
|
113
166
|
/** The encoded seam a checkpoint Layer builds on; both shipped Layers use it. */
|
|
114
167
|
interface EncodedStore {
|
|
168
|
+
/** A snapshot of the stored entries whose keys start with the exact prefix. */
|
|
169
|
+
readonly list?: (prefix: string) => Effect.Effect<EncodedEntries, ProjectionFault>;
|
|
115
170
|
readonly read: (key: string) => Effect.Effect<Option.Option<string>, ProjectionFault>;
|
|
116
171
|
readonly write: (key: string, value: string) => Effect.Effect<void, ProjectionFault>;
|
|
117
172
|
readonly remove: (key: string) => Effect.Effect<void, ProjectionFault>;
|
|
@@ -126,4 +181,4 @@ interface Identity {
|
|
|
126
181
|
readonly params: Record<string, string>;
|
|
127
182
|
readonly inputs: InputMap;
|
|
128
183
|
}
|
|
129
|
-
export {
|
|
184
|
+
export { ItemOf as C, InputServices as S, Slices as T, NonRetryable as _, Identity as a, Entry as b, ProjectionKey as c, RoutedStreamRecord as d, fromStore as f, InvalidBinding as g, Unit as h, EncodedStore as i, RetirementStatus as l, Range as m, CheckpointStore as n, ListedBinding as o, recordKey as p, CheckpointStoreApi as r, Loaded as s, CheckpointRecord as t, RouteRecords as u, NotAttached as v, Slice as w, InputMap as x, ProjectionFault as y };
|