@streamsy/core 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 +3 -3
- package/dist/http/index.d.ts +2 -2
- package/dist/http/index.js +3 -3
- package/dist/{http-wFQusDU7.js → http-YoA8cUTN.js} +12 -2
- package/dist/{index-B_o4-vX4.d.ts → index-vnyfaf-e.d.ts} +92 -7
- package/dist/index.d.ts +2 -2
- package/dist/index.js +24 -4
- package/dist/internal/index.d.ts +7 -3
- package/dist/internal/index.js +3 -2
- package/dist/{layer-CwD1bD5X.js → layer-D4RAoIfM.js} +10 -64
- package/dist/{layer-DZOWeK0B.js → layer-DjKTdIY5.js} +3 -2
- package/dist/marks-YTDGyaMN.js +197 -0
- package/dist/{program-B6L8HGca.js → program-BlfAJNlD.js} +78 -2
- package/dist/{projection-marks-Ca0Q-L9H.d.ts → projection-marks-c7-wvpSn.d.ts} +56 -12
- package/dist/protocol/index.d.ts +2 -2
- package/dist/protocol/index.js +2 -2
- package/dist/read-offsets-CQ4VkAs8.js +11 -0
- package/dist/remote/index.d.ts +2 -2
- package/dist/testing/index.d.ts +2 -2
- package/dist/testing/index.js +356 -12
- package/package.json +1 -1
- package/dist/projection-marks-RqurLPLA.js +0 -24
package/README.md
CHANGED
|
@@ -206,9 +206,9 @@ It has the normal State service, including `create`, `append`, `remove`,
|
|
|
206
206
|
`read`, `follow`, `fold` and `collect`. Use `DurableState.materialize` to fold
|
|
207
207
|
its events into the latest rows.
|
|
208
208
|
|
|
209
|
-
`Projection.wake`
|
|
210
|
-
|
|
211
|
-
|
|
209
|
+
`Projection.wake` creates a missing output on its checkpoint owner. On another
|
|
210
|
+
owner, the wake stream must already exist. Its owner calls the normal State
|
|
211
|
+
service's `create` before the first append. A repeated create answers
|
|
212
212
|
`Exists`:
|
|
213
213
|
|
|
214
214
|
```ts
|
package/dist/http/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { type Access, type HttpOptions, type ReadOptions, type RoutesOptions, ShutdownSignal, type ShutdownSignalService, app, checkReadOptions, layerShutdownSignal, read, routes, securityHeaders, streamPath };
|
|
1
|
+
import { C as Access, S as read, T as routes, _ as ShutdownSignalService, a as LIVE_SOCKET_PROTOCOL, b as ReadOptions, c as LiveControlFrame, d as controlFrame, f as isLiveUpgrade, g as ShutdownSignal, h as upgradeRequired, i as LIVE_PONG, l as LiveOpenFrame, m as openFrame, n as HttpLiveMode, nt as HttpOptions, o as LiveBatch, p as nextCursor, r as LIVE_PING, rt as app, s as LiveCloseCode, tt as streamPath, u as closeCodeForStatus, v as layerShutdownSignal, w as RoutesOptions, x as checkReadOptions, y as securityHeaders } from "../index-vnyfaf-e.js";
|
|
2
|
+
export { type Access, type HttpLiveMode, type HttpOptions, LIVE_PING, LIVE_PONG, LIVE_SOCKET_PROTOCOL, type LiveBatch, LiveCloseCode, type LiveControlFrame, type LiveOpenFrame, type ReadOptions, type RoutesOptions, ShutdownSignal, type ShutdownSignalService, app, checkReadOptions, closeCodeForStatus, controlFrame, isLiveUpgrade, layerShutdownSignal, nextCursor, openFrame, read, routes, securityHeaders, streamPath, upgradeRequired };
|
package/dist/http/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import { n as routes } from "../http-
|
|
3
|
-
export { ShutdownSignal, app, checkReadOptions, layerShutdownSignal, read, routes, securityHeaders, streamPath };
|
|
1
|
+
import { a as LIVE_PING, c as LiveCloseCode, d as isLiveUpgrade, f as nextCursor, g as layerShutdownSignal, h as ShutdownSignal, l as closeCodeForStatus, m as upgradeRequired, n as checkReadOptions, o as LIVE_PONG, p as openFrame, r as read, s as LIVE_SOCKET_PROTOCOL, t as app, u as controlFrame, v as streamPath, y as securityHeaders } from "../program-BlfAJNlD.js";
|
|
2
|
+
import { n as routes } from "../http-YoA8cUTN.js";
|
|
3
|
+
export { LIVE_PING, LIVE_PONG, LIVE_SOCKET_PROTOCOL, LiveCloseCode, ShutdownSignal, app, checkReadOptions, closeCodeForStatus, controlFrame, isLiveUpgrade, layerShutdownSignal, nextCursor, openFrame, read, routes, securityHeaders, streamPath, upgradeRequired };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D8jQpDG7.js";
|
|
2
2
|
import { F as StreamsReader, I as StreamsWriter, i as checkStreams } from "./streamsy-HKC10a_V.js";
|
|
3
|
-
import { a as
|
|
3
|
+
import { _ as discardRequestBody, a as LIVE_PING, c as LiveCloseCode, d as isLiveUpgrade, f as nextCursor, g as layerShutdownSignal, h as ShutdownSignal, i as requestUrl, l as closeCodeForStatus, m as upgradeRequired, n as checkReadOptions, o as LIVE_PONG, p as openFrame, r as read, s as LIVE_SOCKET_PROTOCOL, t as app, u as controlFrame, v as streamPath, y as securityHeaders } from "./program-BlfAJNlD.js";
|
|
4
4
|
import { Array, Effect, Option } from "effect";
|
|
5
5
|
import { HttpRouter, HttpServerRequest, HttpServerResponse } from "effect/http";
|
|
6
6
|
// src/http/routes.ts
|
|
@@ -55,13 +55,23 @@ function routes(group, options) {
|
|
|
55
55
|
}
|
|
56
56
|
// src/http/index.ts
|
|
57
57
|
var http_exports = /* @__PURE__ */ __exportAll({
|
|
58
|
+
LIVE_PING: () => LIVE_PING,
|
|
59
|
+
LIVE_PONG: () => LIVE_PONG,
|
|
60
|
+
LIVE_SOCKET_PROTOCOL: () => LIVE_SOCKET_PROTOCOL,
|
|
61
|
+
LiveCloseCode: () => LiveCloseCode,
|
|
58
62
|
ShutdownSignal: () => ShutdownSignal,
|
|
59
63
|
app: () => app,
|
|
60
64
|
checkReadOptions: () => checkReadOptions,
|
|
65
|
+
closeCodeForStatus: () => closeCodeForStatus,
|
|
66
|
+
controlFrame: () => controlFrame,
|
|
67
|
+
isLiveUpgrade: () => isLiveUpgrade,
|
|
61
68
|
layerShutdownSignal: () => layerShutdownSignal,
|
|
69
|
+
nextCursor: () => nextCursor,
|
|
70
|
+
openFrame: () => openFrame,
|
|
62
71
|
read: () => read,
|
|
63
72
|
routes: () => routes,
|
|
64
73
|
securityHeaders: () => securityHeaders,
|
|
65
|
-
streamPath: () => streamPath
|
|
74
|
+
streamPath: () => streamPath,
|
|
75
|
+
upgradeRequired: () => upgradeRequired
|
|
66
76
|
});
|
|
67
77
|
export { routes as n, http_exports as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as
|
|
1
|
+
import { A as CreateResult, D as StreamsWriter, Dt as StorageFault, E as StreamsReader, Et as EncodeFault, I as AppendConflict, J as InvalidReadRequest, N as ReadNextResult, O as Writer, Ot as StreamsFault, R as AppendErrorFor, St as StreamId, T as Reader, Tt as DecodeFault, U as HeadError, V as CreateError, X as OffsetMismatch, Y as NotSupported, at as StreamGone, ct as AppendCallOptions, d as OwnerRecords, dt as ReadNextOptions, et as ReadNextError, ft as ReadOptions$1, i as ProjectionMarks, it as StreamClosed, j as HeadResult, k as AppendResult, kt as TransportFault, ot as StreamNotFound, p as Storage, pt as CreateOptions, rt as StreamBusy, s as CommitHooks, tt as RemoveError, ut as ProducerOptions } from "./projection-marks-c7-wvpSn.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";
|
|
@@ -342,7 +342,11 @@ declare const next: (position: Position) => Position;
|
|
|
342
342
|
declare const WakeRow: Schema.Struct<{
|
|
343
343
|
/** Canonical id of the source stream. It is also the State key. */
|
|
344
344
|
readonly stream: Schema.brand<Schema.String, "StreamId">;
|
|
345
|
-
/**
|
|
345
|
+
/**
|
|
346
|
+
* A position in the source that the row's writer vouches for. The stream
|
|
347
|
+
* holding the row says what is vouched: written in a source wake stream,
|
|
348
|
+
* or accepted in a projection's accepted stream.
|
|
349
|
+
*/
|
|
346
350
|
readonly offset: Schema.brand<Schema.String, "Offset">;
|
|
347
351
|
/** Present when the source stream is closed. */
|
|
348
352
|
readonly closed: Schema.optionalKey<Schema.Literal<true>>;
|
|
@@ -354,7 +358,11 @@ declare const wakeCollections: {
|
|
|
354
358
|
readonly schema: Schema.Struct<{
|
|
355
359
|
/** Canonical id of the source stream. It is also the State key. */
|
|
356
360
|
readonly stream: Schema.brand<Schema.String, "StreamId">;
|
|
357
|
-
/**
|
|
361
|
+
/**
|
|
362
|
+
* A position in the source that the row's writer vouches for. The stream
|
|
363
|
+
* holding the row says what is vouched: written in a source wake stream,
|
|
364
|
+
* or accepted in a projection's accepted stream.
|
|
365
|
+
*/
|
|
358
366
|
readonly offset: Schema.brand<Schema.String, "Offset">;
|
|
359
367
|
/** Present when the source stream is closed. */
|
|
360
368
|
readonly closed: Schema.optionalKey<Schema.Literal<true>>;
|
|
@@ -389,7 +397,11 @@ declare const wake: <Self>() => <const Name extends string, const Template exten
|
|
|
389
397
|
readonly schema: Schema.Struct<{
|
|
390
398
|
/** Canonical id of the source stream. It is also the State key. */
|
|
391
399
|
readonly stream: Schema.brand<Schema.String, "StreamId">;
|
|
392
|
-
/**
|
|
400
|
+
/**
|
|
401
|
+
* A position in the source that the row's writer vouches for. The stream
|
|
402
|
+
* holding the row says what is vouched: written in a source wake stream,
|
|
403
|
+
* or accepted in a projection's accepted stream.
|
|
404
|
+
*/
|
|
393
405
|
readonly offset: Schema.brand<Schema.String, "Offset">;
|
|
394
406
|
/** Present when the source stream is closed. */
|
|
395
407
|
readonly closed: Schema.optionalKey<Schema.Literal<true>>;
|
|
@@ -445,6 +457,8 @@ interface FollowWakeOptions extends Omit<FollowOptions, "offset"> {
|
|
|
445
457
|
/** Saved source cursors. Read again for each batch, so the consumer may update the map. */
|
|
446
458
|
readonly cursors: ReadonlyMap<StreamId, string>;
|
|
447
459
|
}
|
|
460
|
+
/** Follow options for a wait, including a saved wake cursor. */
|
|
461
|
+
type AwaitWakeOptions = Omit<FollowWakeOptions, "cursors">;
|
|
448
462
|
interface WakeActionsOptions {
|
|
449
463
|
/** Saved source cursors. A missing entry starts from `-1`. */
|
|
450
464
|
readonly cursors: ReadonlyMap<StreamId, string>;
|
|
@@ -475,8 +489,18 @@ declare function wakeActions(events: ReadonlyArray<WakeEvent>, options: WakeActi
|
|
|
475
489
|
* skips the streams that were already read.
|
|
476
490
|
*/
|
|
477
491
|
declare function followWake<Self, P>(declaration: Context.Key<Self, Api<P, WakeEvent>>, params: P, options: FollowWakeOptions): Stream.Stream<WakeBatch, FollowFailure, Self>;
|
|
492
|
+
/**
|
|
493
|
+
* Wait until a wake row for `stream` reaches `offset`. Works with local and
|
|
494
|
+
* remote services. Callers choose their own timeout. Removed source ids must
|
|
495
|
+
* not be reused; a new generation needs a new wake stream or a State reset.
|
|
496
|
+
* Without `options.from`, each call reads the wake history from the start.
|
|
497
|
+
*/
|
|
498
|
+
declare const awaitWake: <Self, P>(declaration: Context.Key<Self, Api<P, WakeEvent>>, params: P, target: {
|
|
499
|
+
readonly stream: StreamId;
|
|
500
|
+
readonly offset: string;
|
|
501
|
+
}, options?: AwaitWakeOptions) => Effect.Effect<void, FollowFailure, Self>;
|
|
478
502
|
declare namespace streamsy_d_exports {
|
|
479
|
-
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 };
|
|
503
|
+
export { Address, Any, Api, AwaitWakeOptions, BytesClass, Class, CustomClass, FollowWakeOptions, Group, Host, JsonClass, Services, StateClass, WakeActions, WakeActionsOptions, WakeBatch, WakeCollections, WakeEvent, WakeItem, WakeMessage, WakeRow, Wildcard, awaitWake, bytes, custom, followWake, group, json, state, wake, wakeActions, wakeCollections };
|
|
480
504
|
}
|
|
481
505
|
declare namespace streams_d_exports {
|
|
482
506
|
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 };
|
|
@@ -697,7 +721,68 @@ declare const ShutdownSignal_base: Context.ServiceClass<ShutdownSignal, "@stream
|
|
|
697
721
|
declare class ShutdownSignal extends ShutdownSignal_base {}
|
|
698
722
|
/** A fresh signal. Provide it to the routes and call `drain` before they close. */
|
|
699
723
|
declare const layerShutdownSignal: Layer.Layer<ShutdownSignal, never, never>;
|
|
724
|
+
interface SseControlData {
|
|
725
|
+
streamNextOffset: string;
|
|
726
|
+
streamCursor?: string;
|
|
727
|
+
streamClosed?: true;
|
|
728
|
+
upToDate?: true;
|
|
729
|
+
}
|
|
730
|
+
/**
|
|
731
|
+
* Frames of `live=websocket`, a Streamsy extension to Durable Streams HTTP.
|
|
732
|
+
*
|
|
733
|
+
* The server sends one `open` text frame, then a binary `data` frame and a
|
|
734
|
+
* `control` text frame for each batch. A `data` frame holds the exact body of
|
|
735
|
+
* a catch-up `GET` for the batch. A `control` frame has the fields of an SSE
|
|
736
|
+
* control event, and a client moves its offset only on `control`.
|
|
737
|
+
*/
|
|
738
|
+
declare const LIVE_SOCKET_PROTOCOL = "streamsy-live.v1";
|
|
739
|
+
/** The only client message. The runtime answers it without running the server. */
|
|
740
|
+
declare const LIVE_PING = "ping";
|
|
741
|
+
declare const LIVE_PONG = "pong";
|
|
742
|
+
/** The close codes of `streamsy-live.v1`. */
|
|
743
|
+
declare const LiveCloseCode: {
|
|
744
|
+
/** The stream closed. A `control` frame with `streamClosed` came first. */
|
|
745
|
+
readonly StreamClosed: 1000;
|
|
746
|
+
readonly InternalError: 1011;
|
|
747
|
+
/** The server restarted or cannot read the socket's state. Reconnect at once. */
|
|
748
|
+
readonly Restart: 1012;
|
|
749
|
+
/** The socket fell behind the byte cap. Read over HTTP, then reconnect. */
|
|
750
|
+
readonly CatchUpRequired: 4100;
|
|
751
|
+
readonly BadMessage: 4400;
|
|
752
|
+
readonly NotFound: 4404;
|
|
753
|
+
readonly Gone: 4410;
|
|
754
|
+
};
|
|
755
|
+
type LiveCloseCode = (typeof LiveCloseCode)[keyof typeof LiveCloseCode];
|
|
756
|
+
interface LiveOpenFrame {
|
|
757
|
+
readonly type: "open";
|
|
758
|
+
readonly protocol: typeof LIVE_SOCKET_PROTOCOL;
|
|
759
|
+
readonly contentType: string;
|
|
760
|
+
readonly streamNextOffset: string;
|
|
761
|
+
}
|
|
762
|
+
interface LiveControlFrame extends SseControlData {
|
|
763
|
+
readonly type: "control";
|
|
764
|
+
}
|
|
765
|
+
interface LiveBatch {
|
|
766
|
+
readonly nextOffset: string;
|
|
767
|
+
readonly cursor: string;
|
|
768
|
+
readonly upToDate: boolean;
|
|
769
|
+
readonly closed: boolean;
|
|
770
|
+
}
|
|
771
|
+
/** The browser socket API hides response headers, so `open` carries the content type. */
|
|
772
|
+
declare function openFrame(contentType: string, streamNextOffset: string): string;
|
|
773
|
+
/** The SSE control rules: no cursor on a closed stream, `upToDate` only while open. */
|
|
774
|
+
declare function controlFrame(batch: LiveBatch): string;
|
|
775
|
+
/** The cursor a long-poll response would carry after `previous`. */
|
|
776
|
+
declare const nextCursor: (previous: string | undefined) => Effect.Effect<string, never, never>;
|
|
777
|
+
/** The close code for a read that failed with an HTTP status. */
|
|
778
|
+
declare function closeCodeForStatus(status: number): LiveCloseCode;
|
|
779
|
+
/** A `GET` that asks for `live=websocket` with an `Upgrade: websocket` header. */
|
|
780
|
+
declare function isLiveUpgrade(request: Request): boolean;
|
|
781
|
+
/** The answer to `live=websocket` from a host or request that cannot upgrade. Clients fall back to long-poll. */
|
|
782
|
+
declare function upgradeRequired(): Response;
|
|
783
|
+
/** `websocket` is a Streamsy extension. Only a host that accepts the upgrade serves it. */
|
|
784
|
+
type HttpLiveMode = "long-poll" | "sse" | "websocket";
|
|
700
785
|
declare namespace index_d_exports {
|
|
701
|
-
export { Access, HttpOptions, ReadOptions, RoutesOptions, ShutdownSignal, ShutdownSignalService, app, checkReadOptions, layerShutdownSignal, read, routes, securityHeaders, streamPath };
|
|
786
|
+
export { Access, HttpLiveMode, HttpOptions, LIVE_PING, LIVE_PONG, LIVE_SOCKET_PROTOCOL, LiveBatch, LiveCloseCode, LiveControlFrame, LiveOpenFrame, ReadOptions, RoutesOptions, ShutdownSignal, ShutdownSignalService, app, checkReadOptions, closeCodeForStatus, controlFrame, isLiveUpgrade, layerShutdownSignal, nextCursor, openFrame, read, routes, securityHeaders, streamPath, upgradeRequired };
|
|
702
787
|
}
|
|
703
|
-
export {
|
|
788
|
+
export { route_d_exports as $, Batch as A, RemoveFailure as B, Access as C, Group as D, Any as E, Decision as F, streams_d_exports$1 as G, streamsy_d_exports as H, Folded as I, layer_d_exports as J, MemoryOptions as K, FollowFailure as L, CreateFailure as M, DecideSpec as N, Identifiers as O, Decided as P, compare as Q, HeadFailure as R, read as S, routes as T, producer_d_exports as U, streams_d_exports as V, durable_state_d_exports as W, CommitBoundaryApi as X, CommitBoundary as Y, ZERO_OFFSET as Z, ShutdownSignalService as _, LIVE_SOCKET_PROTOCOL as a, ReadOptions as b, LiveControlFrame as c, controlFrame as d, address_d_exports as et, isLiveUpgrade as f, ShutdownSignal as g, upgradeRequired as h, LIVE_PONG as i, Collected as j, AppendFailure as k, LiveOpenFrame as l, openFrame as m, HttpLiveMode as n, HttpOptions as nt, LiveBatch as o, nextCursor as p, ProtocolOptions as q, LIVE_PING as r, app as rt, LiveCloseCode as s, index_d_exports as t, streamPath as tt, closeCodeForStatus as u, layerShutdownSignal as v, RoutesOptions as w, checkReadOptions as x, securityHeaders as y, ReadFailure as z };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
import { A as
|
|
1
|
+
import { $ as ReadError, A as CreateResult, At as isRetryableFault, B as CreateConflictReason, C as ProducerPrecondition, Ct as StreamLifecycle, Dt as StorageFault, Et as EncodeFault, F as AppendBaseError, G as InvalidCreateRequest, H as ForkSourceNotFound, I as AppendConflict, J as InvalidReadRequest, K as InvalidEpochSeq, L as AppendError, M as ReadMessage, N as ReadNextResult, Ot as StreamsFault, P as ReadResult, Q as ProtocolError, R as AppendErrorFor, S as Operations, St as StreamId, Tt as DecodeFault, U as HeadError, V as CreateError, W as InvalidAppendRequest, X as OffsetMismatch, Y as NotSupported, Z as ProducerGap, _ as MutationRejected, _t as ProducerId, at as StreamGone, b as OperationResult, bt as StoredMessage, ct as AppendCallOptions, dt as ReadNextOptions, et as ReadNextError, ft as ReadOptions, g as MutationApplied, gt as Offset, h as Mutation, ht as MessageWindow, it as StreamClosed, j as HeadResult, jt as isStreamsFault, k as AppendResult, kt as TransportFault, lt as AppendOptions, m as StorageShape, mt as ChangeSnapshot, nt as StaleEpoch, ot as StreamNotFound, p as Storage, pt as CreateOptions, q as InvalidForkRequest, rt as StreamBusy, st as isProtocolError, tt as RemoveError, ut as ProducerOptions, v as Mutations, vt as ProducerState, w as StorageCapabilities, wt as StreamRecord, x as OperationResults, xt as StreamConfig, y as Operation, yt as RecordPatch, z as CreateConflict } from "./projection-marks-c7-wvpSn.js";
|
|
2
|
+
import { A as Batch, B as RemoveFailure, F as Decision, G as streams_d_exports, H as streamsy_d_exports, I as Folded, L as FollowFailure, M as CreateFailure, N as DecideSpec, P as Decided, Q as compare, R as HeadFailure, U as producer_d_exports, W as durable_state_d_exports, X as CommitBoundaryApi, Y as CommitBoundary, Z as ZERO_OFFSET, et as address_d_exports, j as Collected, k as AppendFailure, t as index_d_exports, z as ReadFailure } from "./index-vnyfaf-e.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, InvalidCreateRequest, 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 };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D8jQpDG7.js";
|
|
2
2
|
import { $ as ProducerState, A as StreamBusy, C as InvalidEpochSeq, D as OffsetMismatch, E as NotSupported, G as StreamsFault, H as DecodeFault, J as isStreamsFault, K as TransportFault, L as Storage, M as StreamGone, N as StreamNotFound, O as ProducerGap, P as isProtocolError, Q as ProducerId, R as ZERO_OFFSET, S as InvalidCreateRequest, T as InvalidReadRequest, U as EncodeFault, W as StorageFault, X as MessageWindow, Y as ChangeSnapshot, Z as Offset, _ as CreateResult, a as custom, at as StreamRecord, b as ForkSourceNotFound, c as state, d as address_exports, et as RecordPatch, f as isControl, g as AppendResult, h as stateControl, it as StreamLifecycle, j as StreamClosed, k as StaleEpoch, m as stateChange, n as bind, nt as StreamConfig, o as group, p as isUpsert, q as isRetryableFault, r as bytes, rt as StreamId, s as json, t as Wildcard, tt as StoredMessage, v as AppendConflict, w as InvalidForkRequest, x as InvalidAppendRequest, y as CreateConflict, z as compare } from "./streamsy-HKC10a_V.js";
|
|
3
|
-
import { n as CommitBoundary, t as layer$1 } from "./layer-
|
|
4
|
-
import { a as MutationRejected, c as OperationResult, d as ProducerPrecondition, i as MutationApplied, l as OperationResults, o as Mutations, r as Mutation, s as Operation, t as layer$2, u as Operations } from "./layer-
|
|
5
|
-
import { t as http_exports } from "./http-
|
|
3
|
+
import { n as CommitBoundary, t as layer$1 } from "./layer-D4RAoIfM.js";
|
|
4
|
+
import { a as MutationRejected, c as OperationResult, d as ProducerPrecondition, i as MutationApplied, l as OperationResults, o as Mutations, r as Mutation, s as Operation, t as layer$2, u as Operations } from "./layer-DjKTdIY5.js";
|
|
5
|
+
import { t as http_exports } from "./http-YoA8cUTN.js";
|
|
6
6
|
import { Array, Data, Effect, Layer, Option, Predicate, Record, Schema, Stream } from "effect";
|
|
7
7
|
// src/storage/capabilities.ts
|
|
8
8
|
const StorageCapabilities = Schema.Struct({
|
|
@@ -194,7 +194,11 @@ const next = (position) => ({
|
|
|
194
194
|
const WakeRow = Schema.Struct({
|
|
195
195
|
/** Canonical id of the source stream. It is also the State key. */
|
|
196
196
|
stream: StreamId,
|
|
197
|
-
/**
|
|
197
|
+
/**
|
|
198
|
+
* A position in the source that the row's writer vouches for. The stream
|
|
199
|
+
* holding the row says what is vouched: written in a source wake stream,
|
|
200
|
+
* or accepted in a projection's accepted stream.
|
|
201
|
+
*/
|
|
198
202
|
offset: Offset,
|
|
199
203
|
/** Present when the source stream is closed. */
|
|
200
204
|
closed: Schema.optionalKey(Schema.Literal(true))
|
|
@@ -328,12 +332,28 @@ function followWake(declaration, params, options) {
|
|
|
328
332
|
return [next.snapshot, [out]];
|
|
329
333
|
}))));
|
|
330
334
|
}
|
|
335
|
+
/**
|
|
336
|
+
* Wait until a wake row for `stream` reaches `offset`. Works with local and
|
|
337
|
+
* remote services. Callers choose their own timeout. Removed source ids must
|
|
338
|
+
* not be reused; a new generation needs a new wake stream or a State reset.
|
|
339
|
+
* Without `options.from`, each call reads the wake history from the start.
|
|
340
|
+
*/
|
|
341
|
+
const awaitWake = (declaration, params, target, options = {}) => followWake(declaration, params, {
|
|
342
|
+
...options,
|
|
343
|
+
cursors: /* @__PURE__ */ new Map()
|
|
344
|
+
}).pipe(Stream.mapAccum(() => Option.none(), (observed, batch) => {
|
|
345
|
+
let current = observed;
|
|
346
|
+
for (const item of batch.items) if (WakeItem.$is("Reset")(item) || WakeItem.$is("Removed")(item) && item.stream === target.stream || WakeItem.$is("Snapshot")(item) && !item.streams.has(target.stream)) current = Option.none();
|
|
347
|
+
else if (WakeItem.$is("Dirty")(item) && item.stream === target.stream) current = Option.some(item.offset);
|
|
348
|
+
return [current, [batch.upToDate && Option.isSome(current) && compare(current.value, target.offset) >= 0]];
|
|
349
|
+
}), Stream.filter((reached) => reached), Stream.runHead, Effect.flatMap((found) => Option.isSome(found) ? Effect.void : Effect.never));
|
|
331
350
|
// src/streamsy.ts
|
|
332
351
|
var streamsy_exports = /* @__PURE__ */ __exportAll({
|
|
333
352
|
WakeItem: () => WakeItem,
|
|
334
353
|
WakeMessage: () => WakeMessage,
|
|
335
354
|
WakeRow: () => WakeRow,
|
|
336
355
|
Wildcard: () => Wildcard,
|
|
356
|
+
awaitWake: () => awaitWake,
|
|
337
357
|
bytes: () => bytes,
|
|
338
358
|
custom: () => custom,
|
|
339
359
|
followWake: () => followWake,
|
package/dist/internal/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import { Context, Effect } from "effect";
|
|
1
|
+
import { P as ReadResult, a as ProjectionMarksApi, c as CommitHooksApi, d as OwnerRecords, f as OwnerRecordsApi, i as ProjectionMarks, l as commitHookRegistry, n as PendingMark, o as CommitHook, r as ProjectionMarkSummary, s as CommitHooks, t as MarkFailure, u as OWNER_RECORDS_LIST_UNSUPPORTED } from "../projection-marks-c7-wvpSn.js";
|
|
2
|
+
import { Context, Effect, Option } from "effect";
|
|
3
3
|
/** Private bridge: a stream guard dies with this sentinel; the atomic runner translates it. */
|
|
4
4
|
declare const ForeignOwnerType: unique symbol;
|
|
5
5
|
declare const ForeignOwner_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
@@ -53,4 +53,8 @@ interface TemplateGrammar<Template extends string = string> {
|
|
|
53
53
|
readonly names: ReadonlyArray<string>;
|
|
54
54
|
}
|
|
55
55
|
export declare function compileSegments<const Template extends string>(template: Template): TemplateGrammar<Template>;
|
|
56
|
-
|
|
56
|
+
/** A new private marks store. Each operation runs synchronously when its Effect executes. */
|
|
57
|
+
export declare const memoryProjectionMarks: () => ProjectionMarksApi;
|
|
58
|
+
export declare const attachOffsets: <A extends object>(result: A, offsets: ReadonlyArray<string>) => A;
|
|
59
|
+
export declare const offsetsOf: (result: Pick<ReadResult, "messages">) => ReadonlyArray<string> | undefined;
|
|
60
|
+
export { type CommitHook, CommitHooks, type CommitHooksApi, type MarkFailure, OWNER_RECORDS_LIST_UNSUPPORTED, OwnerRecords, type OwnerRecordsApi, type PendingMark, type ProjectionMarkSummary, ProjectionMarks, type ProjectionMarksApi, commitHookRegistry };
|
package/dist/internal/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { a as attachOwner, c as isForeignOwner, i as CurrentOwner, l as ownerOf, t as compileSegments } from "../route-internal-DNL0oGTN.js";
|
|
2
|
-
import {
|
|
2
|
+
import { n as offsetsOf, t as attachOffsets } from "../read-offsets-CQ4VkAs8.js";
|
|
3
|
+
import { _ as commitHookRegistry, g as CommitHooks, h as ProjectionMarks, s as memoryProjectionMarks, v as OWNER_RECORDS_LIST_UNSUPPORTED, y as OwnerRecords } from "../marks-YTDGyaMN.js";
|
|
3
4
|
import { Array, Effect } from "effect";
|
|
4
5
|
// src/internal/limits.ts
|
|
5
6
|
/**
|
|
@@ -25,4 +26,4 @@ const fitKey = (key, limit, readable = key) => {
|
|
|
25
26
|
const prefix = Array.join(Array.take(codePoints(readable), limit - DIGEST_LENGTH), "");
|
|
26
27
|
return Effect.map(sha256Hex(key), (digest) => `${prefix}#${digest}`);
|
|
27
28
|
};
|
|
28
|
-
export { CommitHooks, CurrentOwner, MAX_PRODUCER_ID_LENGTH, OwnerRecords, ProjectionMarks, attachOwner, commitHookRegistry, compileSegments, fitKey, isForeignOwner, ownerOf };
|
|
29
|
+
export { CommitHooks, CurrentOwner, MAX_PRODUCER_ID_LENGTH, OWNER_RECORDS_LIST_UNSUPPORTED, OwnerRecords, ProjectionMarks, attachOffsets, attachOwner, commitHookRegistry, compileSegments, fitKey, isForeignOwner, memoryProjectionMarks, offsetsOf, ownerOf };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { L as Storage, R as ZERO_OFFSET } from "./streamsy-HKC10a_V.js";
|
|
2
|
-
import { a as MutationRejected, l as OperationResults, o as Mutations, u as Operations } from "./layer-
|
|
2
|
+
import { a as MutationRejected, l as OperationResults, o as Mutations, u as Operations } from "./layer-DjKTdIY5.js";
|
|
3
3
|
import { a as attachOwner, l as ownerOf } from "./route-internal-DNL0oGTN.js";
|
|
4
|
-
import { i as
|
|
4
|
+
import { _ as commitHookRegistry, a as failed, c as nextDue, d as resume, f as retry, g as CommitHooks, h as ProjectionMarks, i as fail, l as read, m as summary, n as copyMarks, o as mark, p as sleep, r as due, t as clear, u as remove, y as OwnerRecords } from "./marks-YTDGyaMN.js";
|
|
5
5
|
import { Array, Context, Effect, Layer, Option, Order, Predicate, PubSub, Queue, Schedule, Semaphore, Stream } from "effect";
|
|
6
6
|
// src/storage/commit-boundary.ts
|
|
7
7
|
/** The transaction of the storage owner. Every Streamsy storage host provides it. */
|
|
@@ -142,65 +142,6 @@ const createNotifier = Effect.gen(function* () {
|
|
|
142
142
|
})
|
|
143
143
|
};
|
|
144
144
|
});
|
|
145
|
-
// src/storage/memory/marks.ts
|
|
146
|
-
/** A private transaction draft of the marks. */
|
|
147
|
-
const copyMarks = (marks) => new Map(Array.map([...marks], ([projection, rows]) => [projection, new Map(rows)]));
|
|
148
|
-
const rowsOf = (marks, projection) => {
|
|
149
|
-
const found = marks.get(projection);
|
|
150
|
-
if (found !== void 0) return found;
|
|
151
|
-
const rows = /* @__PURE__ */ new Map();
|
|
152
|
-
marks.set(projection, rows);
|
|
153
|
-
return rows;
|
|
154
|
-
};
|
|
155
|
-
const byDue = Order.mapInput(Order.Tuple([Order.Number, Order.String]), (mark) => [mark.dueAt, mark.params]);
|
|
156
|
-
const mark = (marks, projection, params) => {
|
|
157
|
-
const rows = rowsOf(marks, projection);
|
|
158
|
-
for (const value of params) {
|
|
159
|
-
const found = rows.get(value);
|
|
160
|
-
rows.set(value, found === void 0 ? {
|
|
161
|
-
params: value,
|
|
162
|
-
seq: 1,
|
|
163
|
-
attempts: 0,
|
|
164
|
-
dueAt: 0
|
|
165
|
-
} : {
|
|
166
|
-
...found,
|
|
167
|
-
seq: found.seq + 1
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
const nextDue = (marks, projection) => {
|
|
172
|
-
let earliest;
|
|
173
|
-
for (const row of marks.get(projection)?.values() ?? []) earliest = earliest === void 0 ? row.dueAt : Math.min(earliest, row.dueAt);
|
|
174
|
-
return Option.fromUndefinedOr(earliest);
|
|
175
|
-
};
|
|
176
|
-
const due = (marks, projection, now, limit) => Array.sort(Array.filter([...marks.get(projection)?.values() ?? []], (row) => row.dueAt <= now), byDue).slice(0, limit);
|
|
177
|
-
const read = (marks, projection, params) => {
|
|
178
|
-
const rows = marks.get(projection);
|
|
179
|
-
const found = /* @__PURE__ */ new Map();
|
|
180
|
-
for (const value of params) {
|
|
181
|
-
const row = rows?.get(value);
|
|
182
|
-
if (row !== void 0) found.set(value, row);
|
|
183
|
-
}
|
|
184
|
-
return found;
|
|
185
|
-
};
|
|
186
|
-
const clear = (marks, projection, params, seq) => {
|
|
187
|
-
const rows = marks.get(projection);
|
|
188
|
-
if (rows?.get(params)?.seq === seq) rows.delete(params);
|
|
189
|
-
};
|
|
190
|
-
const remove = (marks, projection, params) => {
|
|
191
|
-
marks.get(projection)?.delete(params);
|
|
192
|
-
};
|
|
193
|
-
const defer = (marks, projection, params, attempts, dueAt) => {
|
|
194
|
-
const rows = rowsOf(marks, projection);
|
|
195
|
-
const found = rows.get(params);
|
|
196
|
-
rows.set(params, {
|
|
197
|
-
params,
|
|
198
|
-
seq: found?.seq ?? 1,
|
|
199
|
-
attempts,
|
|
200
|
-
dueAt
|
|
201
|
-
});
|
|
202
|
-
};
|
|
203
|
-
const deferred = (marks, projection) => Array.filter([...marks.get(projection)?.values() ?? []], (row) => row.attempts > 0).length;
|
|
204
145
|
// src/storage/memory/boundary.ts
|
|
205
146
|
var ActiveDraft = class extends Context.Service()("@streamsy/core/internal/MemoryActiveDraft") {};
|
|
206
147
|
const makeBoundary = (committed, publish) => Effect.gen(function* () {
|
|
@@ -245,6 +186,7 @@ const makeBoundary = (committed, publish) => Effect.gen(function* () {
|
|
|
245
186
|
const boundary = CommitBoundary.of({ withTransaction });
|
|
246
187
|
const records = OwnerRecords.of({
|
|
247
188
|
read: (key) => Effect.map(current, (draft) => Option.fromUndefinedOr((Option.isSome(draft) ? draft.value.records : committedRecords).get(key))),
|
|
189
|
+
list: (prefix) => Effect.map(current, (draft) => Array.filter(Array.fromIterable(Option.isSome(draft) ? draft.value.records : committedRecords), ([key]) => key.startsWith(prefix))),
|
|
248
190
|
remove: (key) => withTransaction(Effect.map(current, (draft) => {
|
|
249
191
|
if (Option.isNone(draft)) throw new Error("Memory record delete requires an owner");
|
|
250
192
|
draft.value.records.delete(key);
|
|
@@ -257,17 +199,21 @@ const makeBoundary = (committed, publish) => Effect.gen(function* () {
|
|
|
257
199
|
const readMarks = (f) => Effect.map(current, (draft) => f(Option.isSome(draft) ? draft.value.marks : committedMarks));
|
|
258
200
|
const writeMarks = (f) => withTransaction(Effect.map(current, (draft) => {
|
|
259
201
|
if (Option.isNone(draft)) throw new Error("Memory mark write requires an owner");
|
|
260
|
-
f(draft.value.marks);
|
|
202
|
+
return f(draft.value.marks);
|
|
261
203
|
}));
|
|
262
204
|
const marks = ProjectionMarks.of({
|
|
263
205
|
mark: (projection, params) => writeMarks((table) => mark(table, projection, params)),
|
|
264
206
|
nextDue: (projection) => readMarks((table) => nextDue(table, projection)),
|
|
207
|
+
summary: (projection, now) => readMarks((table) => summary(table, projection, now)),
|
|
265
208
|
due: (projection, now, limit) => readMarks((table) => due(table, projection, now, limit)),
|
|
266
209
|
read: (projection, params) => readMarks((table) => read(table, projection, params)),
|
|
267
210
|
clear: (projection, params, seq) => writeMarks((table) => clear(table, projection, params, seq)),
|
|
211
|
+
sleep: (projection, params, seq, wakeAt) => writeMarks((table) => sleep(table, projection, params, seq, wakeAt)),
|
|
268
212
|
remove: (projection, params) => writeMarks((table) => remove(table, projection, params)),
|
|
269
|
-
|
|
270
|
-
|
|
213
|
+
fail: (projection, params, options) => writeMarks((table) => fail(table, projection, params, options)),
|
|
214
|
+
resume: (projection) => writeMarks((table) => resume(table, projection)),
|
|
215
|
+
failed: (projection, limit) => readMarks((table) => failed(table, projection, limit)),
|
|
216
|
+
retry: (projection, params) => writeMarks((table) => retry(table, projection, params))
|
|
271
217
|
});
|
|
272
218
|
return {
|
|
273
219
|
boundary: attachOwner(boundary, owner),
|
|
@@ -2,6 +2,7 @@ import { t as __exportAll } from "./rolldown-runtime-D8jQpDG7.js";
|
|
|
2
2
|
import { $ as ProducerState, A as StreamBusy, B as isValid, C as InvalidEpochSeq, D as OffsetMismatch, E as NotSupported, F as StreamsReader, I as StreamsWriter, L as Storage, M as StreamGone, N as StreamNotFound, O as ProducerGap, Q as ProducerId, R as ZERO_OFFSET, T as InvalidReadRequest, V as next, Z as Offset, _ as CreateResult, at as StreamRecord, b as ForkSourceNotFound, et as RecordPatch, g as AppendResult, j as StreamClosed, k as StaleEpoch, n as bind, rt as StreamId, tt as StoredMessage, v as AppendConflict, w as InvalidForkRequest, x as InvalidAppendRequest, y as CreateConflict, z as compare } from "./streamsy-HKC10a_V.js";
|
|
3
3
|
import { o as attachStorage } from "./route-internal-DNL0oGTN.js";
|
|
4
4
|
import { n as validateCreateOptions, r as frameMessages, t as frameCreateMessages } from "./create-validation-DzLxKiux.js";
|
|
5
|
+
import { t as attachOffsets } from "./read-offsets-CQ4VkAs8.js";
|
|
5
6
|
import { t as generateCursor } from "./cursor-generator-DySXZ93b.js";
|
|
6
7
|
import { Array, Clock, Context, Data, Effect, Layer, Match, Option, Predicate, Random, Result, Schema, Stream } from "effect";
|
|
7
8
|
// src/storage/mutation.ts
|
|
@@ -532,13 +533,13 @@ const readRecord = Effect.fn("Protocol.readRecord")(function* (storage, record,
|
|
|
532
533
|
});
|
|
533
534
|
const nextOffset = messages.at(-1)?.offset ?? record.currentOffset;
|
|
534
535
|
const upToDate = nextOffset === record.currentOffset;
|
|
535
|
-
return {
|
|
536
|
+
return attachOffsets({
|
|
536
537
|
contentType: record.config.contentType,
|
|
537
538
|
messages: Array.map(messages, (message) => ({ data: message.data })),
|
|
538
539
|
nextOffset,
|
|
539
540
|
upToDate,
|
|
540
541
|
closed: record.lifecycle.closed && upToDate
|
|
541
|
-
};
|
|
542
|
+
}, Array.map(messages, (message) => message.offset));
|
|
542
543
|
});
|
|
543
544
|
const read = Effect.fn("Protocol.read")(function* (storage, id, options = {}, readLimit = 1e3) {
|
|
544
545
|
yield* validateOffset(id, options.offset);
|