@streamsy/core 0.5.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 +122 -1
- package/dist/http/index.d.ts +1 -1
- package/dist/http/index.js +2 -2
- package/dist/{http-x2IjDHvw.js → http-B10ao6xE.js} +2 -2
- package/dist/{index-C26ncp7Y.d.ts → index-p68har8W.d.ts} +262 -4
- package/dist/index.d.ts +2 -2
- package/dist/index.js +232 -6
- package/dist/internal/index.d.ts +24 -1
- package/dist/internal/index.js +2 -2
- package/dist/{layer-DyezIxJT.js → layer-8Y1cg6UL.js} +2 -2
- package/dist/{layer-DJ-c63nY.js → layer-DQZj5tXr.js} +12 -8
- package/dist/{owner-records-BV5Un5R0.d.ts → owner-records-H7VEuBpy.d.ts} +10 -1
- package/dist/{program-DXUjw5B2.js → program-CYtMjdvD.js} +1 -1
- package/dist/protocol/index.d.ts +2 -2
- package/dist/protocol/index.js +3 -3
- package/dist/remote/index.d.ts +2 -2
- package/dist/remote/index.js +1 -1
- package/dist/route-internal-DNL0oGTN.js +93 -0
- package/dist/{streamsy-DJMArv09.js → streamsy-D9OCCdw0.js} +5 -60
- package/dist/testing/index.d.ts +2 -2
- package/dist/testing/index.js +67 -4
- package/package.json +1 -1
- package/dist/owner-BWQ2KvC_.js +0 -35
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
An Effect implementation of the [Durable Streams](https://durablestreams.com)
|
|
4
4
|
protocol. Typed stream declarations, stream services, an in-process memory Layer, an
|
|
5
|
-
HTTP app, and a client for remote hosts.
|
|
5
|
+
HTTP app, and a client for remote hosts. Requires
|
|
6
6
|
`effect@4.0.5`.
|
|
7
7
|
|
|
8
8
|
```sh
|
|
@@ -159,6 +159,127 @@ gets that offset. `Serve.state` serves stored controls as they are. It still
|
|
|
159
159
|
refuses the `x-streamsy-state-reset: snapshot` request header, because the
|
|
160
160
|
server does not make snapshots.
|
|
161
161
|
|
|
162
|
+
## Materialize State
|
|
163
|
+
|
|
164
|
+
`DurableState.materialize(state, events)` folds State items into one map of rows
|
|
165
|
+
for each collection. Start from `DurableState.materialized(address)`. It applies
|
|
166
|
+
the State rules: an upsert sets a row, a delete removes it, `reset` clears every
|
|
167
|
+
collection, and `snapshot-end` removes each row that the snapshot did not name. A
|
|
168
|
+
snapshot can span several calls. The input state does not change.
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
let state = DurableState.materialized(Board.at({ id }));
|
|
172
|
+
|
|
173
|
+
for (const batch of batches) state = DurableState.materialize(state, batch.items);
|
|
174
|
+
|
|
175
|
+
state.rows.card; // ReadonlyMap<string, Card>
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Wake streams
|
|
179
|
+
|
|
180
|
+
A wake stream indexes the writes of a family of streams. It is a State stream
|
|
181
|
+
with one row for each source stream: `{ stream, offset, closed? }`, keyed by the
|
|
182
|
+
source id. The row holds the source tail after its last write. A client follows
|
|
183
|
+
one wake stream and reads only the source streams that moved past its saved
|
|
184
|
+
cursors.
|
|
185
|
+
|
|
186
|
+
```ts
|
|
187
|
+
class Files extends Streamsy.state<Files>()("App/Files", "folders/:folderId/files", {
|
|
188
|
+
params: { folderId: FolderKey },
|
|
189
|
+
collections: { file: { schema: FileValue, key: "path" } },
|
|
190
|
+
}) {}
|
|
191
|
+
|
|
192
|
+
class UserWake extends Streamsy.wake<UserWake>()("App/UserWake", "users/:user/wake", {
|
|
193
|
+
params: { user: UserKey },
|
|
194
|
+
}) {}
|
|
195
|
+
|
|
196
|
+
const streams = Streamsy.group(Files, UserWake);
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
A wake declaration names no sources. A projection writes its rows:
|
|
200
|
+
`Projection.wake` from `@streamsy/projection` links one source stream to one
|
|
201
|
+
wake stream, with params of its own. The source and the wake stream can live on
|
|
202
|
+
different storage owners. See the projection README.
|
|
203
|
+
|
|
204
|
+
`Streamsy.wake` is a preset for `Streamsy.state` with `wakeCollections`.
|
|
205
|
+
It has the normal State service, including `create`, `append`, `remove`,
|
|
206
|
+
`read`, `follow`, `fold` and `collect`. Use `DurableState.materialize` to fold
|
|
207
|
+
its events into the latest rows.
|
|
208
|
+
|
|
209
|
+
`Projection.wake` opts its output into creation on the first append, including
|
|
210
|
+
on another owner. The owner can call the normal State service's `create` to
|
|
211
|
+
make an empty stream available before that append. A repeated create answers
|
|
212
|
+
`Exists`:
|
|
213
|
+
|
|
214
|
+
```ts
|
|
215
|
+
const start = Effect.gen(function* () {
|
|
216
|
+
const wake = yield* UserWake;
|
|
217
|
+
yield* wake.create({ user });
|
|
218
|
+
});
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
HTTP access is mount policy. Choose read access for projection outputs on a
|
|
222
|
+
public mount and full access on an internal mount where producers create and
|
|
223
|
+
append them:
|
|
224
|
+
|
|
225
|
+
```ts
|
|
226
|
+
Http.routes(streams, {
|
|
227
|
+
prefix: "/streams",
|
|
228
|
+
access: (stream) => (stream === UserWake ? "read" : "full"),
|
|
229
|
+
});
|
|
230
|
+
Http.routes(Streamsy.group(UserWake), { prefix: "/__wake", access: "full" });
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
`Streamsy.followWake` turns wake batches into actions:
|
|
234
|
+
|
|
235
|
+
```ts
|
|
236
|
+
const actions = Streamsy.followWake(
|
|
237
|
+
UserWake,
|
|
238
|
+
{ user },
|
|
239
|
+
{
|
|
240
|
+
from: saved.wake,
|
|
241
|
+
cursors: saved.cursors,
|
|
242
|
+
},
|
|
243
|
+
);
|
|
244
|
+
// Each batch: { items: WakeItem[], offset }. An item is Dirty, Removed, Reset or Snapshot.
|
|
245
|
+
// Save each source cursor first, then save `offset` as the wake cursor.
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
A client with its own HTTP reader does not need a `RemoteStreams` stack.
|
|
249
|
+
It decodes each page with `Streamsy.WakeMessage` and calls the pure
|
|
250
|
+
`Streamsy.wakeActions`, which `followWake` also uses:
|
|
251
|
+
|
|
252
|
+
```ts
|
|
253
|
+
const decodePage = Schema.decodeUnknownEffect(Schema.Array(Streamsy.WakeMessage));
|
|
254
|
+
|
|
255
|
+
const handle = (page: unknown, snapshot?: ReadonlySet<StreamId>) =>
|
|
256
|
+
Effect.map(decodePage(page), (events) =>
|
|
257
|
+
Streamsy.wakeActions(events, { cursors: saved.cursors, snapshot }),
|
|
258
|
+
);
|
|
259
|
+
// { items, snapshot }: items as above. Pass snapshot to the call for the next page.
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
A wake row lags its source by one projection pass, on the same owner and on
|
|
263
|
+
another one. The client reads each source to its tail, so the lag costs
|
|
264
|
+
latency only.
|
|
265
|
+
|
|
266
|
+
A wake row relies on append-only streams. The `offset` of a source only goes up,
|
|
267
|
+
so a client compares it with its saved cursor. Never reuse a source id: do not
|
|
268
|
+
create a stream again under the id of a removed or expired stream. The new
|
|
269
|
+
stream starts at a lower offset, and a client with a saved cursor skips its
|
|
270
|
+
items. The projection also treats a gone source as removed for good.
|
|
271
|
+
|
|
272
|
+
## Local commit events
|
|
273
|
+
|
|
274
|
+
`Storage.committed` is a scoped
|
|
275
|
+
`Effect<PubSub.Subscription<ReadonlyArray<StreamId>>>`. The subscription exists
|
|
276
|
+
when the effect returns, so a later commit always lands in it. Memory and SQL
|
|
277
|
+
storage publish the ids touched by each successful local commit after it
|
|
278
|
+
commits. Rolled-back writes publish nothing. Each subscriber gets its own
|
|
279
|
+
subscription, which its scope releases. Events are best effort and have no replay; commits from
|
|
280
|
+
another process do not appear. `Storage.changes(id)` remains the per-stream
|
|
281
|
+
read notification source. Custom storage adapters must provide `committed`.
|
|
282
|
+
|
|
162
283
|
## Documentation
|
|
163
284
|
|
|
164
285
|
- [Declare streams](https://streamsy.dev/docs/streams/declare)
|
package/dist/http/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { H as HttpOptions, U as app, V as streamPath, a as securityHeaders, c as read, d as routes, i as layerShutdownSignal, l as Access, n as ShutdownSignal, o as ReadOptions, r as ShutdownSignalService, s as checkReadOptions, u as RoutesOptions } from "../index-
|
|
1
|
+
import { H as HttpOptions, U as app, V as streamPath, a as securityHeaders, c as read, d as routes, i as layerShutdownSignal, l as Access, n as ShutdownSignal, o as ReadOptions, r as ShutdownSignalService, s as checkReadOptions, u as RoutesOptions } from "../index-p68har8W.js";
|
|
2
2
|
export { type Access, type HttpOptions, type ReadOptions, type RoutesOptions, ShutdownSignal, type ShutdownSignalService, app, checkReadOptions, layerShutdownSignal, read, routes, securityHeaders, streamPath };
|
package/dist/http/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as ShutdownSignal, c as streamPath, l as securityHeaders, n as checkReadOptions, o as layerShutdownSignal, r as read, t as app } from "../program-
|
|
2
|
-
import { n as routes } from "../http-
|
|
1
|
+
import { a as ShutdownSignal, c as streamPath, l as securityHeaders, n as checkReadOptions, o as layerShutdownSignal, r as read, t as app } from "../program-CYtMjdvD.js";
|
|
2
|
+
import { n as routes } from "../http-B10ao6xE.js";
|
|
3
3
|
export { ShutdownSignal, app, checkReadOptions, layerShutdownSignal, read, routes, securityHeaders, streamPath };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D8jQpDG7.js";
|
|
2
|
-
import {
|
|
3
|
-
import { a as ShutdownSignal, c as streamPath, i as requestUrl, l as securityHeaders, n as checkReadOptions, o as layerShutdownSignal, r as read, s as discardRequestBody, t as app } from "./program-
|
|
2
|
+
import { F as StreamsWriter, P as StreamsReader, i as checkStreams } from "./streamsy-D9OCCdw0.js";
|
|
3
|
+
import { a as ShutdownSignal, c as streamPath, i as requestUrl, l as securityHeaders, n as checkReadOptions, o as layerShutdownSignal, r as read, s as discardRequestBody, t as app } from "./program-CYtMjdvD.js";
|
|
4
4
|
import { Array, Effect, Option } from "effect";
|
|
5
5
|
import { HttpRouter, HttpServerRequest, HttpServerResponse } from "effect/http";
|
|
6
6
|
// src/http/routes.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as ProducerOptions, C as ReadNextResult, E as AppendConflict, J as StreamGone, K as StreamBusy, L as InvalidReadRequest, N as HeadError, O as AppendErrorFor, R as NotSupported, U as ReadNextError, W as RemoveError, Y as StreamNotFound, Z as AppendCallOptions, _ as StreamsWriter, _t as StreamsFault, b as CreateResult, dt as StreamId, et as ReadNextOptions, g as StreamsReader, gt as StorageFault, h as Reader, ht as EncodeFault, j as CreateError, mt as DecodeFault, nt as CreateOptions, q as StreamClosed, r as Storage, t as OwnerRecords, tt as ReadOptions$1, v as Writer, vt as TransportFault, x as HeadResult, y as AppendResult, z as OffsetMismatch } from "./owner-records-
|
|
1
|
+
import { $ as ProducerOptions, C as ReadNextResult, E as AppendConflict, J as StreamGone, K as StreamBusy, L as InvalidReadRequest, N as HeadError, O as AppendErrorFor, R as NotSupported, U as ReadNextError, W as RemoveError, Y as StreamNotFound, Z as AppendCallOptions, _ as StreamsWriter, _t as StreamsFault, b as CreateResult, dt as StreamId, et as ReadNextOptions, g as StreamsReader, gt as StorageFault, h as Reader, ht as EncodeFault, j as CreateError, mt as DecodeFault, nt as CreateOptions, q as StreamClosed, r as Storage, t as OwnerRecords, tt as ReadOptions$1, v as Writer, vt as TransportFault, x as HeadResult, y as AppendResult, z as OffsetMismatch } from "./owner-records-H7VEuBpy.js";
|
|
2
2
|
import { Array, Context, Data, Duration, Effect, Function, Layer, Option, Schedule, Schema, Stream } from "effect";
|
|
3
3
|
import { HttpRouter, HttpServerRequest, HttpServerResponse } from "effect/http";
|
|
4
4
|
import { SqlError } from "effect/sql";
|
|
@@ -25,7 +25,7 @@ declare const streamPath: (pathPrefix?: string) => {
|
|
|
25
25
|
canonicalizeForkSource: (source: string) => string;
|
|
26
26
|
};
|
|
27
27
|
declare namespace address_d_exports {
|
|
28
|
-
export { Collection, Collections, CollectionsChange, CollectionsDecodingServices, CollectionsEncodedChange, CollectionsEncodedEvent, CollectionsEncodingServices, CollectionsEvent, StateAddress, StateChange, StateControl, StateControlName, StateDelete, StateEvent, StateHeaders, StateKey, StateUpsert, StreamAddress, ValidCollections, bytes$2 as bytes, isChange, isControl, json$2 as json, reset, snapshotEnd, snapshotStart, state$2 as state, stateChange, stateControl };
|
|
28
|
+
export { Collection, Collections, CollectionsChange, CollectionsDecodingServices, CollectionsEncodedChange, CollectionsEncodedEvent, CollectionsEncodingServices, CollectionsEvent, StateAddress, StateChange, StateControl, StateControlName, StateDelete, StateEvent, StateHeaders, StateKey, StateUpsert, StreamAddress, ValidCollections, bytes$2 as bytes, isChange, isControl, isUpsert, json$2 as json, reset, snapshotEnd, snapshotStart, state$2 as state, stateChange, stateControl };
|
|
29
29
|
}
|
|
30
30
|
/** Omit `offset` and `txid` rather than setting them to `undefined`. */
|
|
31
31
|
interface StateHeaders {
|
|
@@ -127,6 +127,8 @@ declare const stateControl: Schema.Codec<StateControl>;
|
|
|
127
127
|
declare const isControl: <E extends StateEvent<unknown>>(event: E) => event is Extract<E, StateControl>;
|
|
128
128
|
/** True for an upsert or delete change. */
|
|
129
129
|
declare const isChange: <E extends StateEvent<unknown>>(event: E) => event is Exclude<E, StateControl>;
|
|
130
|
+
/** True for an upsert change, with its value available. */
|
|
131
|
+
declare const isUpsert: <E extends StateEvent<unknown>>(event: E) => event is Extract<E, StateUpsert<unknown>>;
|
|
130
132
|
/** A `reset` control. A reader should clear its materialized state and apply what follows. */
|
|
131
133
|
declare const reset: (options?: {
|
|
132
134
|
readonly offset?: string;
|
|
@@ -251,7 +253,7 @@ declare const layerProtocol: (options?: Options) => Layer.Layer<CommitBoundary |
|
|
|
251
253
|
/** Memory host. Streams and their feeds share the exposed storage boundary. */
|
|
252
254
|
declare function layer<const Keys extends ReadonlyArray<Any>>(group: Group<Keys>, options?: Options): Layer.Layer<Storage | CommitBoundary | OwnerRecords | Host<Group<Keys>>>;
|
|
253
255
|
declare namespace durable_state_d_exports {
|
|
254
|
-
export { Change, ChangeHeaders, Delete, Entry, Upsert, changes, remove$1 as remove, upsert };
|
|
256
|
+
export { Change, ChangeHeaders, Delete, Entry, Materialized, Rows, Upsert, changes, materialize, materialized, remove$1 as remove, upsert };
|
|
255
257
|
}
|
|
256
258
|
interface ChangeHeaders {
|
|
257
259
|
readonly txid?: string;
|
|
@@ -300,14 +302,269 @@ declare function changes<C extends Collections, RD, RE>(address: StateAddress<C,
|
|
|
300
302
|
declare function changes<C extends Collections, RD, RE>(address: StateAddress<C, RD, RE>, options: {
|
|
301
303
|
readonly offset?: string;
|
|
302
304
|
}, entries: ReadonlyArray<Entry<C>>): ReadonlyArray<CollectionsEvent<C>>;
|
|
305
|
+
/** The rows of one collection, by State key. */
|
|
306
|
+
type Rows<C extends Collections> = { readonly [K in keyof C & string]: ReadonlyMap<string, C[K]["schema"]["Type"]>; };
|
|
307
|
+
/**
|
|
308
|
+
* The materialized state of a Durable State stream: the latest row for each key
|
|
309
|
+
* of each collection. `snapshot` holds the keys seen since an open
|
|
310
|
+
* `snapshot-start`, and is `undefined` outside a snapshot.
|
|
311
|
+
*/
|
|
312
|
+
interface Materialized<C extends Collections> {
|
|
313
|
+
readonly rows: Rows<C>;
|
|
314
|
+
readonly snapshot: ReadonlySet<string> | undefined;
|
|
315
|
+
}
|
|
316
|
+
/** Empty materialized state for the collections of `address`. */
|
|
317
|
+
declare function materialized<C extends Collections>(address: {
|
|
318
|
+
readonly collections: C;
|
|
319
|
+
}): Materialized<C>;
|
|
320
|
+
/**
|
|
321
|
+
* Fold State events into materialized state, with the State protocol rules:
|
|
322
|
+
*
|
|
323
|
+
* - `upsert` sets the row of its key, and `delete` removes it.
|
|
324
|
+
* - `reset` clears every collection.
|
|
325
|
+
* - `snapshot-end` removes each row that no change since `snapshot-start` named.
|
|
326
|
+
* A snapshot may span several calls.
|
|
327
|
+
*
|
|
328
|
+
* The input state is not changed. Only the collections that `events` touch are copied.
|
|
329
|
+
*/
|
|
330
|
+
declare function materialize<C extends Collections>(state: Materialized<C>, events: Iterable<CollectionsEvent<C>>): Materialized<C>;
|
|
303
331
|
declare namespace producer_d_exports {
|
|
304
332
|
export { Position, next };
|
|
305
333
|
}
|
|
306
334
|
type Position = ProducerOptions;
|
|
307
335
|
/** Advance only after the caller has acknowledged appended or duplicate. Persist this tuple at the owning edge. */
|
|
308
336
|
declare const next: (position: Position) => Position;
|
|
337
|
+
/** One row of a wake stream: the latest known state of one source stream. */
|
|
338
|
+
declare const WakeRow: Schema.Struct<{
|
|
339
|
+
/** Canonical id of the source stream. It is also the State key. */
|
|
340
|
+
readonly stream: Schema.brand<Schema.String, "StreamId">;
|
|
341
|
+
/** Source tail after the write. The same value as a reader's saved cursor. */
|
|
342
|
+
readonly offset: Schema.brand<Schema.String, "Offset">;
|
|
343
|
+
/** Present when the source stream is closed. */
|
|
344
|
+
readonly closed: Schema.optionalKey<Schema.Literal<true>>;
|
|
345
|
+
}>;
|
|
346
|
+
type WakeRow = typeof WakeRow.Type;
|
|
347
|
+
/** The one collection of every wake stream. Its State `type` is `stream`. */
|
|
348
|
+
declare const wakeCollections: {
|
|
349
|
+
readonly stream: {
|
|
350
|
+
readonly schema: Schema.Struct<{
|
|
351
|
+
/** Canonical id of the source stream. It is also the State key. */
|
|
352
|
+
readonly stream: Schema.brand<Schema.String, "StreamId">;
|
|
353
|
+
/** Source tail after the write. The same value as a reader's saved cursor. */
|
|
354
|
+
readonly offset: Schema.brand<Schema.String, "Offset">;
|
|
355
|
+
/** Present when the source stream is closed. */
|
|
356
|
+
readonly closed: Schema.optionalKey<Schema.Literal<true>>;
|
|
357
|
+
}>;
|
|
358
|
+
readonly key: "stream";
|
|
359
|
+
};
|
|
360
|
+
};
|
|
361
|
+
type WakeCollections = typeof wakeCollections;
|
|
362
|
+
/** One item of a wake stream. */
|
|
363
|
+
type WakeEvent = CollectionsEvent<WakeCollections>;
|
|
364
|
+
/**
|
|
365
|
+
* The codec of one wake stream message: a `stream` change or a State control.
|
|
366
|
+
* A client that decodes raw JSON pages uses it in place of a typed service.
|
|
367
|
+
*/
|
|
368
|
+
declare const WakeMessage: Schema.Codec<WakeEvent, CollectionsEncodedEvent<WakeCollections>>;
|
|
369
|
+
/**
|
|
370
|
+
* Declare a wake stream: a State stream of `WakeRow`s at a template.
|
|
371
|
+
*
|
|
372
|
+
* ```ts
|
|
373
|
+
* class UserWake extends Streamsy.wake<UserWake>()("App/UserWake", "users/:user/wake", {
|
|
374
|
+
* params: { user: UserKey },
|
|
375
|
+
* }) {}
|
|
376
|
+
* ```
|
|
377
|
+
*
|
|
378
|
+
* The declaration names no sources. A `Projection.wake` binding links one
|
|
379
|
+
* source stream to one wake stream, with params of its own.
|
|
380
|
+
*/
|
|
381
|
+
declare const wake: <Self>() => <const Name extends string, const Template extends string, C extends ParamCodecs>(name: Name, template: Template, options: {
|
|
382
|
+
readonly params: C & ExactTemplateParams<Template, C>;
|
|
383
|
+
}) => StateClass<Self, Name, Template, C, {
|
|
384
|
+
readonly stream: {
|
|
385
|
+
readonly schema: Schema.Struct<{
|
|
386
|
+
/** Canonical id of the source stream. It is also the State key. */
|
|
387
|
+
readonly stream: Schema.brand<Schema.String, "StreamId">;
|
|
388
|
+
/** Source tail after the write. The same value as a reader's saved cursor. */
|
|
389
|
+
readonly offset: Schema.brand<Schema.String, "Offset">;
|
|
390
|
+
/** Present when the source stream is closed. */
|
|
391
|
+
readonly closed: Schema.optionalKey<Schema.Literal<true>>;
|
|
392
|
+
}>;
|
|
393
|
+
readonly key: "stream";
|
|
394
|
+
};
|
|
395
|
+
}>;
|
|
396
|
+
/** One action for a consumer of a wake stream. */
|
|
397
|
+
type WakeItem = Data.TaggedEnum<{
|
|
398
|
+
/** Read `stream` from `from` up to at least `offset`, then save its cursor. */
|
|
399
|
+
Dirty: {
|
|
400
|
+
readonly stream: StreamId;
|
|
401
|
+
readonly from: string;
|
|
402
|
+
readonly offset: string;
|
|
403
|
+
readonly closed: boolean;
|
|
404
|
+
};
|
|
405
|
+
/** The stream was removed. Drop its cursor and its local data. */
|
|
406
|
+
Removed: {
|
|
407
|
+
readonly stream: StreamId;
|
|
408
|
+
};
|
|
409
|
+
/** Drop every cursor. The items after this one start each stream from `-1`. */
|
|
410
|
+
Reset: {};
|
|
411
|
+
/** A complete snapshot ended. Drop each stream that `streams` does not hold. */
|
|
412
|
+
Snapshot: {
|
|
413
|
+
readonly streams: ReadonlySet<StreamId>;
|
|
414
|
+
};
|
|
415
|
+
}>;
|
|
416
|
+
/** Constructors and matchers for `WakeItem`. */
|
|
417
|
+
declare const WakeItem: {
|
|
418
|
+
readonly $is: <Tag extends "Dirty" | "Removed" | "Reset" | "Snapshot">(tag: Tag) => (u: unknown) => u is Extract<{
|
|
419
|
+
readonly _tag: "Dirty";
|
|
420
|
+
readonly stream: StreamId;
|
|
421
|
+
readonly from: string;
|
|
422
|
+
readonly offset: string;
|
|
423
|
+
readonly closed: boolean;
|
|
424
|
+
}, {
|
|
425
|
+
readonly _tag: Tag;
|
|
426
|
+
}> | Extract<{
|
|
427
|
+
readonly _tag: "Removed";
|
|
428
|
+
readonly stream: StreamId;
|
|
429
|
+
}, {
|
|
430
|
+
readonly _tag: Tag;
|
|
431
|
+
}> | Extract<{
|
|
432
|
+
readonly _tag: "Reset";
|
|
433
|
+
}, {
|
|
434
|
+
readonly _tag: Tag;
|
|
435
|
+
}> | Extract<{
|
|
436
|
+
readonly _tag: "Snapshot";
|
|
437
|
+
readonly streams: ReadonlySet<StreamId>;
|
|
438
|
+
}, {
|
|
439
|
+
readonly _tag: Tag;
|
|
440
|
+
}>;
|
|
441
|
+
readonly $match: {
|
|
442
|
+
<Cases extends { readonly [Tag in "Dirty" | "Removed" | "Reset" | "Snapshot"]: (args: Extract<{
|
|
443
|
+
readonly _tag: "Dirty";
|
|
444
|
+
readonly stream: StreamId;
|
|
445
|
+
readonly from: string;
|
|
446
|
+
readonly offset: string;
|
|
447
|
+
readonly closed: boolean;
|
|
448
|
+
} | {
|
|
449
|
+
readonly _tag: "Removed";
|
|
450
|
+
readonly stream: StreamId;
|
|
451
|
+
} | {
|
|
452
|
+
readonly _tag: "Reset";
|
|
453
|
+
} | {
|
|
454
|
+
readonly _tag: "Snapshot";
|
|
455
|
+
readonly streams: ReadonlySet<StreamId>;
|
|
456
|
+
}, {
|
|
457
|
+
readonly _tag: Tag;
|
|
458
|
+
}>) => any; }>(cases: Cases): (value: {
|
|
459
|
+
readonly _tag: "Dirty";
|
|
460
|
+
readonly stream: StreamId;
|
|
461
|
+
readonly from: string;
|
|
462
|
+
readonly offset: string;
|
|
463
|
+
readonly closed: boolean;
|
|
464
|
+
} | {
|
|
465
|
+
readonly _tag: "Removed";
|
|
466
|
+
readonly stream: StreamId;
|
|
467
|
+
} | {
|
|
468
|
+
readonly _tag: "Reset";
|
|
469
|
+
} | {
|
|
470
|
+
readonly _tag: "Snapshot";
|
|
471
|
+
readonly streams: ReadonlySet<StreamId>;
|
|
472
|
+
}) => import("effect/Unify").Unify<ReturnType<Cases["Dirty" | "Removed" | "Reset" | "Snapshot"]>>;
|
|
473
|
+
<Cases extends { readonly [Tag in "Dirty" | "Removed" | "Reset" | "Snapshot"]: (args: Extract<{
|
|
474
|
+
readonly _tag: "Dirty";
|
|
475
|
+
readonly stream: StreamId;
|
|
476
|
+
readonly from: string;
|
|
477
|
+
readonly offset: string;
|
|
478
|
+
readonly closed: boolean;
|
|
479
|
+
} | {
|
|
480
|
+
readonly _tag: "Removed";
|
|
481
|
+
readonly stream: StreamId;
|
|
482
|
+
} | {
|
|
483
|
+
readonly _tag: "Reset";
|
|
484
|
+
} | {
|
|
485
|
+
readonly _tag: "Snapshot";
|
|
486
|
+
readonly streams: ReadonlySet<StreamId>;
|
|
487
|
+
}, {
|
|
488
|
+
readonly _tag: Tag;
|
|
489
|
+
}>) => any; }>(value: {
|
|
490
|
+
readonly _tag: "Dirty";
|
|
491
|
+
readonly stream: StreamId;
|
|
492
|
+
readonly from: string;
|
|
493
|
+
readonly offset: string;
|
|
494
|
+
readonly closed: boolean;
|
|
495
|
+
} | {
|
|
496
|
+
readonly _tag: "Removed";
|
|
497
|
+
readonly stream: StreamId;
|
|
498
|
+
} | {
|
|
499
|
+
readonly _tag: "Reset";
|
|
500
|
+
} | {
|
|
501
|
+
readonly _tag: "Snapshot";
|
|
502
|
+
readonly streams: ReadonlySet<StreamId>;
|
|
503
|
+
}, cases: Cases): import("effect/Unify").Unify<ReturnType<Cases["Dirty" | "Removed" | "Reset" | "Snapshot"]>>;
|
|
504
|
+
};
|
|
505
|
+
readonly Dirty: Data.TaggedEnum.ConstructorFrom<{
|
|
506
|
+
readonly _tag: "Dirty";
|
|
507
|
+
readonly stream: StreamId;
|
|
508
|
+
readonly from: string;
|
|
509
|
+
readonly offset: string;
|
|
510
|
+
readonly closed: boolean;
|
|
511
|
+
}, "_tag">;
|
|
512
|
+
readonly Removed: Data.TaggedEnum.ConstructorFrom<{
|
|
513
|
+
readonly _tag: "Removed";
|
|
514
|
+
readonly stream: StreamId;
|
|
515
|
+
}, "_tag">;
|
|
516
|
+
readonly Reset: Data.TaggedEnum.ConstructorFrom<{
|
|
517
|
+
readonly _tag: "Reset";
|
|
518
|
+
}, "_tag">;
|
|
519
|
+
readonly Snapshot: Data.TaggedEnum.ConstructorFrom<{
|
|
520
|
+
readonly _tag: "Snapshot";
|
|
521
|
+
readonly streams: ReadonlySet<StreamId>;
|
|
522
|
+
}, "_tag">;
|
|
523
|
+
};
|
|
524
|
+
/** One batch of wake actions. Save `offset` as the wake cursor after every item is handled. */
|
|
525
|
+
interface WakeBatch {
|
|
526
|
+
readonly items: ReadonlyArray<WakeItem>;
|
|
527
|
+
readonly offset: string;
|
|
528
|
+
readonly upToDate: boolean;
|
|
529
|
+
}
|
|
530
|
+
interface FollowWakeOptions extends Omit<FollowOptions, "offset"> {
|
|
531
|
+
/** The saved wake cursor. Default: `-1`, a cold start. */
|
|
532
|
+
readonly from?: string;
|
|
533
|
+
/** Saved source cursors. Read again for each batch, so the consumer may update the map. */
|
|
534
|
+
readonly cursors: ReadonlyMap<StreamId, string>;
|
|
535
|
+
}
|
|
536
|
+
interface WakeActionsOptions {
|
|
537
|
+
/** Saved source cursors. A missing entry starts from `-1`. */
|
|
538
|
+
readonly cursors: ReadonlyMap<StreamId, string>;
|
|
539
|
+
/** The streams of a snapshot that an earlier batch left open. */
|
|
540
|
+
readonly snapshot?: ReadonlySet<StreamId> | undefined;
|
|
541
|
+
}
|
|
542
|
+
/** The actions of one wake batch, and the snapshot state for the next batch. */
|
|
543
|
+
interface WakeActions {
|
|
544
|
+
readonly items: ReadonlyArray<WakeItem>;
|
|
545
|
+
/** The streams of a snapshot that is still open. Pass it to the next call. */
|
|
546
|
+
readonly snapshot: ReadonlySet<StreamId> | undefined;
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
* The actions for one batch of wake messages. The function is pure: it reads
|
|
550
|
+
* no stream and changes none of its inputs. Rows for one stream collapse to one
|
|
551
|
+
* item; a delete then an upsert of one stream gives `Removed`, then `Dirty` from
|
|
552
|
+
* `-1`. Pass the returned `snapshot` to the call for the next batch.
|
|
553
|
+
*
|
|
554
|
+
* `followWake` uses it over a typed service. A client with its own HTTP reader
|
|
555
|
+
* decodes each page with `WakeMessage` and calls it directly.
|
|
556
|
+
*/
|
|
557
|
+
declare function wakeActions(events: ReadonlyArray<WakeEvent>, options: WakeActionsOptions): WakeActions;
|
|
558
|
+
/**
|
|
559
|
+
* Follow one wake stream and give the actions for each batch: which source
|
|
560
|
+
* streams to read, from which cursor, and which to drop. The helper reads no
|
|
561
|
+
* source stream. Save each source cursor first and the wake cursor (`offset`)
|
|
562
|
+
* last; a stop between the two reads the same rows again, and the offset check
|
|
563
|
+
* skips the streams that were already read.
|
|
564
|
+
*/
|
|
565
|
+
declare function followWake<Self, P>(declaration: Context.Key<Self, Api<P, WakeEvent>>, params: P, options: FollowWakeOptions): Stream.Stream<WakeBatch, FollowFailure, Self>;
|
|
309
566
|
declare namespace streamsy_d_exports {
|
|
310
|
-
export { Address, Any, Api, BytesClass, Class, CustomClass, Group, Host, JsonClass, Services, StateClass, Wildcard, bytes, custom, group, json, state };
|
|
567
|
+
export { Address, Any, Api, BytesClass, Class, CustomClass, FollowWakeOptions, Group, Host, JsonClass, Services, StateClass, WakeActions, WakeActionsOptions, WakeBatch, WakeCollections, WakeEvent, WakeItem, WakeMessage, WakeRow, Wildcard, bytes, custom, followWake, group, json, state, wake, wakeActions, wakeCollections };
|
|
311
568
|
}
|
|
312
569
|
declare namespace streams_d_exports {
|
|
313
570
|
export { AppendFailure, AppendItems, Batch, Collected, CreateFailure, DecideSpec, Decided, Decision, Folded, FollowFailure, FollowOptions, HeadFailure, ReadFailure, RemoveFailure, append, collect, create, decide, fold, follow, head, items, read$1 as read, remove, session };
|
|
@@ -483,6 +740,7 @@ interface Access<S extends Any = Any> {
|
|
|
483
740
|
}
|
|
484
741
|
interface RoutesOptions extends Omit<HttpOptions, "pathPrefix"> {
|
|
485
742
|
readonly prefix?: `/${string}`;
|
|
743
|
+
/** The access of each stream on this mount. */
|
|
486
744
|
readonly access: Access["access"] | ((stream: Any) => Access["access"]);
|
|
487
745
|
}
|
|
488
746
|
/** One prefix controls both route registration and protocol path stripping. */
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { $ as ProducerOptions, A as CreateConflictReason, B as ProducerGap, C as ReadNextResult, D as AppendError, E as AppendConflict, F as InvalidEpochSeq, G as StaleEpoch, H as ReadError, I as InvalidForkRequest, J as StreamGone, K as StreamBusy, L as InvalidReadRequest, M as ForkSourceNotFound, N as HeadError, O as AppendErrorFor, P as InvalidAppendRequest, Q as AppendOptions, R as NotSupported, S as ReadMessage, T as AppendBaseError, U as ReadNextError, V as ProtocolError, W as RemoveError, X as isProtocolError, Y as StreamNotFound, Z as AppendCallOptions, _t as StreamsFault, a as Mutation, at as Offset, b as CreateResult, bt as isStreamsFault, c as Mutations, ct as RecordPatch, d as OperationResults, dt as StreamId, et as ReadNextOptions, f as Operations, ft as StreamLifecycle, gt as StorageFault, ht as EncodeFault, i as StorageShape, it as MessageWindow, j as CreateError, k as CreateConflict, l as Operation, lt as StoredMessage, m as StorageCapabilities, mt as DecodeFault, nt as CreateOptions, o as MutationApplied, ot as ProducerId, p as ProducerPrecondition, pt as StreamRecord, q as StreamClosed, r as Storage, rt as ChangeSnapshot, s as MutationRejected, st as ProducerState, tt as ReadOptions, u as OperationResult, ut as StreamConfig, vt as TransportFault, w as ReadResult, x as HeadResult, y as AppendResult, yt as isRetryableFault, z as OffsetMismatch } from "./owner-records-
|
|
2
|
-
import { A as durable_state_d_exports, B as address_d_exports, C as FollowFailure, E as RemoveFailure, F as CommitBoundary, I as CommitBoundaryApi, L as ZERO_OFFSET, O as streamsy_d_exports, R as compare, S as Folded, T as ReadFailure, _ as Collected, b as Decided, g as Batch, h as AppendFailure, j as streams_d_exports, k as producer_d_exports, t as index_d_exports, v as CreateFailure, w as HeadFailure, x as Decision, y as DecideSpec } from "./index-
|
|
1
|
+
import { $ as ProducerOptions, A as CreateConflictReason, B as ProducerGap, C as ReadNextResult, D as AppendError, E as AppendConflict, F as InvalidEpochSeq, G as StaleEpoch, H as ReadError, I as InvalidForkRequest, J as StreamGone, K as StreamBusy, L as InvalidReadRequest, M as ForkSourceNotFound, N as HeadError, O as AppendErrorFor, P as InvalidAppendRequest, Q as AppendOptions, R as NotSupported, S as ReadMessage, T as AppendBaseError, U as ReadNextError, V as ProtocolError, W as RemoveError, X as isProtocolError, Y as StreamNotFound, Z as AppendCallOptions, _t as StreamsFault, a as Mutation, at as Offset, b as CreateResult, bt as isStreamsFault, c as Mutations, ct as RecordPatch, d as OperationResults, dt as StreamId, et as ReadNextOptions, f as Operations, ft as StreamLifecycle, gt as StorageFault, ht as EncodeFault, i as StorageShape, it as MessageWindow, j as CreateError, k as CreateConflict, l as Operation, lt as StoredMessage, m as StorageCapabilities, mt as DecodeFault, nt as CreateOptions, o as MutationApplied, ot as ProducerId, p as ProducerPrecondition, pt as StreamRecord, q as StreamClosed, r as Storage, rt as ChangeSnapshot, s as MutationRejected, st as ProducerState, tt as ReadOptions, u as OperationResult, ut as StreamConfig, vt as TransportFault, w as ReadResult, x as HeadResult, y as AppendResult, yt as isRetryableFault, z as OffsetMismatch } from "./owner-records-H7VEuBpy.js";
|
|
2
|
+
import { A as durable_state_d_exports, B as address_d_exports, C as FollowFailure, E as RemoveFailure, F as CommitBoundary, I as CommitBoundaryApi, L as ZERO_OFFSET, O as streamsy_d_exports, R as compare, S as Folded, T as ReadFailure, _ as Collected, b as Decided, g as Batch, h as AppendFailure, j as streams_d_exports, k as producer_d_exports, t as index_d_exports, v as CreateFailure, w as HeadFailure, x as Decision, y as DecideSpec } from "./index-p68har8W.js";
|
|
3
3
|
export { AppendBaseError, type AppendCallOptions, AppendConflict, AppendError, AppendErrorFor, type AppendFailure, type AppendOptions, AppendResult, type Batch, ChangeSnapshot, type Collected, CommitBoundary, type CommitBoundaryApi, CreateConflict, CreateConflictReason, CreateError, type CreateFailure, type CreateOptions, CreateResult, type DecideSpec, type Decided, type Decision, DecodeFault, durable_state_d_exports as DurableState, EncodeFault, type Folded, type FollowFailure, ForkSourceNotFound, HeadError, type HeadFailure, type HeadResult, index_d_exports as Http, InvalidAppendRequest, InvalidEpochSeq, InvalidForkRequest, InvalidReadRequest, streams_d_exports as MemoryStorage, MessageWindow, Mutation, MutationApplied, MutationRejected, Mutations, NotSupported, Offset, OffsetMismatch, Operation, OperationResult, OperationResults, Operations, producer_d_exports as Producer, ProducerGap, ProducerId, type ProducerOptions, ProducerPrecondition, ProducerState, ProtocolError, ReadError, type ReadFailure, type ReadMessage, ReadNextError, type ReadNextOptions, type ReadNextResult, type ReadOptions, type ReadResult, RecordPatch, RemoveError, type RemoveFailure, StaleEpoch, Storage, StorageCapabilities, StorageFault, type StorageShape, StoredMessage, address_d_exports as StreamAddress, StreamBusy, StreamClosed, StreamConfig, StreamGone, StreamId, StreamLifecycle, StreamNotFound, StreamRecord, StreamsFault, streamsy_d_exports as Streamsy, TransportFault, ZERO_OFFSET, compare, isProtocolError, isRetryableFault, isStreamsFault };
|