@streamsy/core 0.4.0 → 0.5.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 +40 -3
- package/dist/{cursor-generator-CGz1TO_N.js → cursor-generator-DySXZ93b.js} +1 -2
- package/dist/http/index.d.ts +1 -1
- package/dist/http/index.js +2 -2
- package/dist/{http-EnNOUsIK.js → http-x2IjDHvw.js} +9 -11
- package/dist/{index-CFv8vZvy.d.ts → index-C26ncp7Y.d.ts} +63 -43
- package/dist/index.d.ts +2 -2
- package/dist/index.js +52 -51
- package/dist/internal/index.d.ts +1 -3
- package/dist/internal/index.js +2 -2
- package/dist/{layer-D8ybaCL2.js → layer-DJ-c63nY.js} +31 -31
- package/dist/{layer-KvknRFUT.js → layer-DyezIxJT.js} +22 -33
- package/dist/{owner-BQzMpfC1.js → owner-BWQ2KvC_.js} +1 -2
- package/dist/{owner-records-QDlssl__.d.ts → owner-records-BV5Un5R0.d.ts} +0 -22
- package/dist/{owner-records-CX6yU28i.js → owner-records-C0p8jeC1.js} +1 -2
- package/dist/{program-DJ8NpHIf.js → program-DXUjw5B2.js} +38 -55
- package/dist/protocol/index.d.ts +2 -4
- package/dist/protocol/index.js +4 -5
- package/dist/remote/index.d.ts +2 -4
- package/dist/remote/index.js +10 -14
- package/dist/{rolldown-runtime-D7D4PA-g.js → rolldown-runtime-D8jQpDG7.js} +1 -2
- package/dist/{streamsy-OjRubIPC.js → streamsy-DJMArv09.js} +61 -44
- package/dist/testing/index.d.ts +2 -10
- package/dist/testing/index.js +22 -27
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
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
5
|
HTTP app, and a client for remote hosts. Version 0.4.0 requires
|
|
6
|
-
`effect@4.0.
|
|
6
|
+
`effect@4.0.5`.
|
|
7
7
|
|
|
8
8
|
```sh
|
|
9
9
|
bun add @streamsy/core effect
|
|
@@ -17,12 +17,15 @@ class Events extends Streamsy.json<Events>()("Readme/Events", "events", {
|
|
|
17
17
|
params: {},
|
|
18
18
|
schema: Schema.String,
|
|
19
19
|
}) {}
|
|
20
|
+
|
|
20
21
|
const program = Effect.gen(function* () {
|
|
21
22
|
const events = yield* Events;
|
|
22
23
|
yield* events.create({});
|
|
23
24
|
yield* events.append({}, ["hello"]);
|
|
25
|
+
|
|
24
26
|
return yield* events.read({}).pipe(Stream.runCollect);
|
|
25
27
|
});
|
|
28
|
+
|
|
26
29
|
await Effect.runPromise(program.pipe(Effect.provide(MemoryStorage.layer(Streamsy.group(Events)))));
|
|
27
30
|
```
|
|
28
31
|
|
|
@@ -32,8 +35,10 @@ Compiled source: [packages/core/examples/readme.ts](https://github.com/gingerhen
|
|
|
32
35
|
|
|
33
36
|
- `StreamAddress` names a stream with its content type and schema, including
|
|
34
37
|
`StreamAddress.state(id, { collections })` for a Durable State stream. One address
|
|
35
|
-
declares several collections keyed by their wire `type`.
|
|
36
|
-
|
|
38
|
+
declares several collections keyed by their wire `type`. Its items are the
|
|
39
|
+
changes of those collections and the State control messages `snapshot-start`,
|
|
40
|
+
`snapshot-end` and `reset`. `Streamsy` declares a named stream service from an
|
|
41
|
+
id template.
|
|
37
42
|
- Stream services create, append, read, follow, and remove streams. Create and
|
|
38
43
|
append return `_tag` variants such as `Created` / `Exists` and
|
|
39
44
|
`Appended` / `Duplicate`. Protocol failures are tagged errors
|
|
@@ -122,6 +127,38 @@ an `offset`, each event gets that offset and a default `txid`. Projection output
|
|
|
122
127
|
have no source offset. The route's collection names and key fields define the
|
|
123
128
|
Durable State wire events.
|
|
124
129
|
|
|
130
|
+
## Control messages
|
|
131
|
+
|
|
132
|
+
A State stream can also hold the control messages of the Durable State
|
|
133
|
+
protocol. A control has `headers.control` and an optional `headers.offset`. It
|
|
134
|
+
has no `type` or `key`.
|
|
135
|
+
|
|
136
|
+
| Control | Make it with | A reader should |
|
|
137
|
+
| ---------------- | ------------------------------- | ------------------------------------------------------------- |
|
|
138
|
+
| `reset` | `StreamAddress.reset()` | Clear its rows, then apply the items after it |
|
|
139
|
+
| `snapshot-start` | `StreamAddress.snapshotStart()` | Treat the changes up to `snapshot-end` as a complete snapshot |
|
|
140
|
+
| `snapshot-end` | `StreamAddress.snapshotEnd()` | Close the snapshot |
|
|
141
|
+
|
|
142
|
+
Each constructor takes `{ offset }`. Items of a State address have the type
|
|
143
|
+
`StreamAddress.CollectionsEvent<Collections>`. Narrow an item with
|
|
144
|
+
`StreamAddress.isChange` or `StreamAddress.isControl` before you read `type`,
|
|
145
|
+
`key` or `headers.operation`:
|
|
146
|
+
|
|
147
|
+
```ts
|
|
148
|
+
for (const item of batch.items) {
|
|
149
|
+
if (StreamAddress.isControl(item)) {
|
|
150
|
+
if (item.headers.control === "reset") rows.clear();
|
|
151
|
+
} else if ("value" in item) rows.set(item.key, item.value);
|
|
152
|
+
else rows.delete(item.key);
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
`DurableState.changes` and projection outputs accept a control beside row
|
|
157
|
+
changes and write it unchanged. With an `offset`, a control that has no offset
|
|
158
|
+
gets that offset. `Serve.state` serves stored controls as they are. It still
|
|
159
|
+
refuses the `x-streamsy-state-reset: snapshot` request header, because the
|
|
160
|
+
server does not make snapshots.
|
|
161
|
+
|
|
125
162
|
## Documentation
|
|
126
163
|
|
|
127
164
|
- [Declare streams](https://streamsy.dev/docs/streams/declare)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DateTime } from "effect";
|
|
2
|
-
|
|
2
|
+
// src/policy/cursor-generator.ts
|
|
3
3
|
const CURSOR_EPOCH_MS = DateTime.toEpochMillis(DateTime.makeUnsafe("2024-10-09T00:00:00.000Z"));
|
|
4
4
|
const CURSOR_INTERVAL_MS = 2e4;
|
|
5
5
|
function generateCursor(clock, previous, random = Math.random) {
|
|
@@ -9,5 +9,4 @@ function generateCursor(clock, previous, random = Math.random) {
|
|
|
9
9
|
if (Number.isNaN(previousInterval) || previousInterval < currentInterval) return String(currentInterval);
|
|
10
10
|
return String(previousInterval + Math.max(1, Math.floor(random() * 180)));
|
|
11
11
|
}
|
|
12
|
-
//#endregion
|
|
13
12
|
export { generateCursor as t };
|
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-C26ncp7Y.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-DXUjw5B2.js";
|
|
2
|
+
import { n as routes } from "../http-x2IjDHvw.js";
|
|
3
3
|
export { ShutdownSignal, app, checkReadOptions, layerShutdownSignal, read, routes, securityHeaders, streamPath };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { t as __exportAll } from "./rolldown-runtime-
|
|
2
|
-
import { A as StreamsReader, i as checkStreams, j as StreamsWriter } from "./streamsy-
|
|
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-
|
|
4
|
-
import { Effect } from "effect";
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D8jQpDG7.js";
|
|
2
|
+
import { A as StreamsReader, i as checkStreams, j as StreamsWriter } from "./streamsy-DJMArv09.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-DXUjw5B2.js";
|
|
4
|
+
import { Array, Effect, Option } from "effect";
|
|
5
5
|
import { HttpRouter, HttpServerRequest, HttpServerResponse } from "effect/http";
|
|
6
|
-
|
|
6
|
+
// src/http/routes.ts
|
|
7
7
|
/** The `allow` header for each access level. */
|
|
8
8
|
const allowedMethods = {
|
|
9
9
|
read: "GET, HEAD, OPTIONS",
|
|
@@ -11,7 +11,7 @@ const allowedMethods = {
|
|
|
11
11
|
full: "GET, HEAD, PUT, POST, DELETE, OPTIONS"
|
|
12
12
|
};
|
|
13
13
|
function routes(group, options) {
|
|
14
|
-
const entries = group.streams
|
|
14
|
+
const entries = Array.map(group.streams, (stream) => ({
|
|
15
15
|
stream,
|
|
16
16
|
access: typeof options.access === "function" ? options.access(stream) : options.access
|
|
17
17
|
}));
|
|
@@ -23,12 +23,12 @@ function routes(group, options) {
|
|
|
23
23
|
...settings,
|
|
24
24
|
pathPrefix: prefix
|
|
25
25
|
});
|
|
26
|
-
checkStreams(
|
|
26
|
+
checkStreams(Array.map(entries, (entry) => entry.stream));
|
|
27
27
|
const handler = Effect.gen(function* () {
|
|
28
28
|
const request = yield* HttpServerRequest.HttpServerRequest;
|
|
29
29
|
const url = requestUrl(request);
|
|
30
30
|
const id = url === void 0 ? void 0 : path.strip(url.pathname);
|
|
31
|
-
const entry =
|
|
31
|
+
const entry = Option.getOrUndefined(Array.findFirst(entries, ({ stream }) => id !== void 0 && stream.match(id)));
|
|
32
32
|
if (entry === void 0) {
|
|
33
33
|
yield* discardRequestBody(request);
|
|
34
34
|
return HttpServerResponse.empty({
|
|
@@ -53,8 +53,7 @@ function routes(group, options) {
|
|
|
53
53
|
});
|
|
54
54
|
return HttpRouter.add("*", prefix === "/" ? "/*" : `/${prefix.slice(1)}/*`, handler);
|
|
55
55
|
}
|
|
56
|
-
|
|
57
|
-
//#region src/http/index.ts
|
|
56
|
+
// src/http/index.ts
|
|
58
57
|
var http_exports = /* @__PURE__ */ __exportAll({
|
|
59
58
|
ShutdownSignal: () => ShutdownSignal,
|
|
60
59
|
app: () => app,
|
|
@@ -65,5 +64,4 @@ var http_exports = /* @__PURE__ */ __exportAll({
|
|
|
65
64
|
securityHeaders: () => securityHeaders,
|
|
66
65
|
streamPath: () => streamPath
|
|
67
66
|
});
|
|
68
|
-
//#endregion
|
|
69
67
|
export { routes as n, http_exports as t };
|
|
@@ -1,10 +1,7 @@
|
|
|
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-
|
|
2
|
-
import { Context, Data, Duration, Effect, Layer, Option, Schedule, Schema, Stream } from "effect";
|
|
3
|
-
import { NonEmptyReadonlyArray } from "effect/Array";
|
|
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-BV5Un5R0.js";
|
|
2
|
+
import { Array, Context, Data, Duration, Effect, Function, Layer, Option, Schedule, Schema, Stream } from "effect";
|
|
4
3
|
import { HttpRouter, HttpServerRequest, HttpServerResponse } from "effect/http";
|
|
5
|
-
import {
|
|
6
|
-
import { SqlError } from "effect/sql/SqlError";
|
|
7
|
-
//#region src/http/program.d.ts
|
|
4
|
+
import { SqlError } from "effect/sql";
|
|
8
5
|
interface HttpOptions {
|
|
9
6
|
readonly pathPrefix?: string;
|
|
10
7
|
/** Lifetime of an SSE response. Default 60 seconds. */
|
|
@@ -21,8 +18,6 @@ interface HttpOptions {
|
|
|
21
18
|
* what let one composition serve several backends.
|
|
22
19
|
*/
|
|
23
20
|
declare function app(options?: HttpOptions): Effect.Effect<HttpServerResponse.HttpServerResponse, never, HttpServerRequest.HttpServerRequest | StreamsReader | StreamsWriter>;
|
|
24
|
-
//#endregion
|
|
25
|
-
//#region src/http/stream-path-service.d.ts
|
|
26
21
|
/** Prefix helpers shared by protocol and host routers. */
|
|
27
22
|
declare const streamPath: (pathPrefix?: string) => {
|
|
28
23
|
requiredPathPattern: () => string;
|
|
@@ -30,7 +25,7 @@ declare const streamPath: (pathPrefix?: string) => {
|
|
|
30
25
|
canonicalizeForkSource: (source: string) => string;
|
|
31
26
|
};
|
|
32
27
|
declare namespace address_d_exports {
|
|
33
|
-
export { Collection, Collections, CollectionsChange, CollectionsDecodingServices, CollectionsEncodedChange, CollectionsEncodingServices, StateAddress, StateChange, StateDelete, StateHeaders, StateKey, StateUpsert, StreamAddress, ValidCollections, bytes$2 as bytes, json$2 as json, state$2 as state, stateChange };
|
|
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 };
|
|
34
29
|
}
|
|
35
30
|
/** Omit `offset` and `txid` rather than setting them to `undefined`. */
|
|
36
31
|
interface StateHeaders {
|
|
@@ -63,6 +58,22 @@ type StateEncodedChange<A, Type extends string = string> = (Omit<StateUpsert<A,
|
|
|
63
58
|
readonly operation: "insert" | "update" | "upsert";
|
|
64
59
|
};
|
|
65
60
|
}) | StateDelete<A, Type>;
|
|
61
|
+
/** The control signals of the Durable State protocol (STATE-PROTOCOL.md section 4.2). */
|
|
62
|
+
type StateControlName = "snapshot-start" | "snapshot-end" | "reset";
|
|
63
|
+
/**
|
|
64
|
+
* A control message of a Durable State stream. It has no `type` or `key`.
|
|
65
|
+
* `snapshot-start` and `snapshot-end` mark a run of changes that is a complete
|
|
66
|
+
* snapshot. `reset` tells a reader to clear its materialized state. Omit
|
|
67
|
+
* `offset` rather than setting it to `undefined`.
|
|
68
|
+
*/
|
|
69
|
+
interface StateControl {
|
|
70
|
+
readonly headers: {
|
|
71
|
+
readonly control: StateControlName;
|
|
72
|
+
readonly offset?: string;
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/** One item of a Durable State stream: a change of one collection or a control. */
|
|
76
|
+
type StateEvent<A, Type extends string = string> = StateChange<A, Type> | StateControl;
|
|
66
77
|
/** The value fields that may serve as a Durable State key. */
|
|
67
78
|
type StateKey<A> = { [K in keyof A]-?: A[K] extends string | number ? K : never; }[keyof A];
|
|
68
79
|
/** One collection of a Durable State stream: its value schema and the value field used as the key. */
|
|
@@ -82,6 +93,9 @@ type ValidCollections<C extends Collections> = { readonly [K in keyof C]: C[K]["
|
|
|
82
93
|
/** The union of change events across every collection, discriminated by `type`. */
|
|
83
94
|
type CollectionsChange<C extends Collections> = { [K in keyof C & string]: StateChange<C[K]["schema"]["Type"], K>; }[keyof C & string];
|
|
84
95
|
type CollectionsEncodedChange<C extends Collections> = { [K in keyof C & string]: StateEncodedChange<C[K]["schema"]["Encoded"], K>; }[keyof C & string];
|
|
96
|
+
/** The items of a State address: the change events of its collections, plus controls. */
|
|
97
|
+
type CollectionsEvent<C extends Collections> = CollectionsChange<C> | StateControl;
|
|
98
|
+
type CollectionsEncodedEvent<C extends Collections> = CollectionsEncodedChange<C> | StateControl;
|
|
85
99
|
type CollectionsDecodingServices<C extends Collections> = C[keyof C]["schema"]["DecodingServices"];
|
|
86
100
|
type CollectionsEncodingServices<C extends Collections> = C[keyof C]["schema"]["EncodingServices"];
|
|
87
101
|
/** Inert identity and codec. Constructing an address acquires no service or resource. */
|
|
@@ -91,8 +105,8 @@ interface StreamAddress<A, RD = never, RE = never> {
|
|
|
91
105
|
readonly contentType: string;
|
|
92
106
|
readonly codec: Schema.Codec<A, string | Uint8Array, RD, RE>;
|
|
93
107
|
}
|
|
94
|
-
/** A JSON address whose items are the change events of its collections. */
|
|
95
|
-
interface StateAddress<C extends Collections, RD = CollectionsDecodingServices<C>, RE = CollectionsEncodingServices<C>> extends StreamAddress<
|
|
108
|
+
/** A JSON address whose items are the change events of its collections and State controls. */
|
|
109
|
+
interface StateAddress<C extends Collections, RD = CollectionsDecodingServices<C>, RE = CollectionsEncodingServices<C>> extends StreamAddress<CollectionsEvent<C>, RD, RE> {
|
|
96
110
|
readonly collections: C;
|
|
97
111
|
}
|
|
98
112
|
declare function json$2<A, I, RD, RE>(id: string, options: {
|
|
@@ -107,10 +121,29 @@ declare function stateChange<A, I, RD, RE, const Type extends string>(options: {
|
|
|
107
121
|
readonly schema: Schema.Codec<A, I, RD, RE>;
|
|
108
122
|
readonly type: Type;
|
|
109
123
|
}): Schema.Codec<StateChange<A, Type>, StateEncodedChange<I, Type>, RD, RE>;
|
|
124
|
+
/** The codec for a State control message. It needs no services. */
|
|
125
|
+
declare const stateControl: Schema.Codec<StateControl>;
|
|
126
|
+
/** True for a control message. A change has `headers.operation` and no `headers.control`. */
|
|
127
|
+
declare const isControl: <E extends StateEvent<unknown>>(event: E) => event is Extract<E, StateControl>;
|
|
128
|
+
/** True for an upsert or delete change. */
|
|
129
|
+
declare const isChange: <E extends StateEvent<unknown>>(event: E) => event is Exclude<E, StateControl>;
|
|
130
|
+
/** A `reset` control. A reader should clear its materialized state and apply what follows. */
|
|
131
|
+
declare const reset: (options?: {
|
|
132
|
+
readonly offset?: string;
|
|
133
|
+
}) => StateControl;
|
|
134
|
+
/** A `snapshot-start` control. The changes up to `snapshot-end` form a complete snapshot. */
|
|
135
|
+
declare const snapshotStart: (options?: {
|
|
136
|
+
readonly offset?: string;
|
|
137
|
+
}) => StateControl;
|
|
138
|
+
/** A `snapshot-end` control. It closes the snapshot that `snapshot-start` opened. */
|
|
139
|
+
declare const snapshotEnd: (options?: {
|
|
140
|
+
readonly offset?: string;
|
|
141
|
+
}) => StateControl;
|
|
110
142
|
/**
|
|
111
|
-
* A stream of Durable State
|
|
143
|
+
* A stream of Durable State events for several collections. Each record
|
|
112
144
|
* key is the `type` on the wire; each entry gives the value schema and the value
|
|
113
|
-
* field that becomes the event `key`.
|
|
145
|
+
* field that becomes the event `key`. The codec also decodes and encodes the
|
|
146
|
+
* State control messages `snapshot-start`, `snapshot-end` and `reset`.
|
|
114
147
|
*/
|
|
115
148
|
declare function state$2<const C extends Collections>(id: string, options: {
|
|
116
149
|
readonly collections: C & ValidCollections<C>;
|
|
@@ -147,7 +180,7 @@ type WithPathSchema<P> = {
|
|
|
147
180
|
readonly paramSchema: PathSchema<P>;
|
|
148
181
|
};
|
|
149
182
|
/** A route whose address refs retain their declared State collections. */
|
|
150
|
-
type StateRoute<P, C extends Collections, Template extends string = string> = Omit<StreamRoute<P,
|
|
183
|
+
type StateRoute<P, C extends Collections, Template extends string = string> = Omit<StreamRoute<P, CollectionsEvent<C>, CollectionsDecodingServices<C>, CollectionsEncodingServices<C>, Template>, "address"> & {
|
|
151
184
|
readonly collections: C;
|
|
152
185
|
readonly address: (params: P) => StateAddress<C>;
|
|
153
186
|
};
|
|
@@ -178,12 +211,8 @@ declare function custom$1<RouteParams, A, RD, RE>(options: {
|
|
|
178
211
|
readonly parse: (id: string) => Option.Option<RouteParams>;
|
|
179
212
|
readonly address: (params: RouteParams) => StreamAddress<A, RD, RE>;
|
|
180
213
|
}): StreamRoute<RouteParams, A, RD, RE>;
|
|
181
|
-
//#endregion
|
|
182
|
-
//#region src/offset/index.d.ts
|
|
183
214
|
declare const ZERO_OFFSET: string & import("effect/Brand").Brand<"Offset">;
|
|
184
215
|
declare const compare: (a: string, b: string) => number;
|
|
185
|
-
//#endregion
|
|
186
|
-
//#region src/storage/commit-boundary.d.ts
|
|
187
216
|
interface CommitBoundaryApi {
|
|
188
217
|
/**
|
|
189
218
|
* Run `body` in the storage owner's transaction. A nested call joins the outer
|
|
@@ -192,13 +221,11 @@ interface CommitBoundaryApi {
|
|
|
192
221
|
* together. Keep the body on the calling fiber, and do not wait in it for wakes that
|
|
193
222
|
* only its own commit publishes. Only SQL hosts fail with `SqlError`.
|
|
194
223
|
*/
|
|
195
|
-
readonly withTransaction: <A, E, R>(body: Effect.Effect<A, E, R>) => Effect.Effect<A, E | SqlError, R>;
|
|
224
|
+
readonly withTransaction: <A, E, R>(body: Effect.Effect<A, E, R>) => Effect.Effect<A, E | SqlError.SqlError, R>;
|
|
196
225
|
}
|
|
197
226
|
declare const CommitBoundary_base: Context.ServiceClass<CommitBoundary, "@streamsy/core/CommitBoundary", CommitBoundaryApi>;
|
|
198
227
|
/** The transaction of the storage owner. Every Streamsy storage host provides it. */
|
|
199
228
|
declare class CommitBoundary extends CommitBoundary_base {}
|
|
200
|
-
//#endregion
|
|
201
|
-
//#region src/protocol/expiry.d.ts
|
|
202
229
|
/** One host-triggered sweep; the host owns scheduling and cancellation. */
|
|
203
230
|
declare const expireDue: () => Effect.Effect<void, StorageFault, Storage>;
|
|
204
231
|
declare namespace layer_d_exports {
|
|
@@ -210,8 +237,6 @@ interface ProtocolOptions {
|
|
|
210
237
|
readonly longPollTimeoutMs?: number;
|
|
211
238
|
}
|
|
212
239
|
declare const layer$1: (options?: ProtocolOptions) => Layer.Layer<StreamsReader | StreamsWriter, never, Storage>;
|
|
213
|
-
//#endregion
|
|
214
|
-
//#region src/storage/memory/layer.d.ts
|
|
215
240
|
interface MemoryOptions {
|
|
216
241
|
readonly constrained?: boolean;
|
|
217
242
|
readonly pollIntervalMs?: number;
|
|
@@ -226,7 +251,7 @@ declare const layerProtocol: (options?: Options) => Layer.Layer<CommitBoundary |
|
|
|
226
251
|
/** Memory host. Streams and their feeds share the exposed storage boundary. */
|
|
227
252
|
declare function layer<const Keys extends ReadonlyArray<Any>>(group: Group<Keys>, options?: Options): Layer.Layer<Storage | CommitBoundary | OwnerRecords | Host<Group<Keys>>>;
|
|
228
253
|
declare namespace durable_state_d_exports {
|
|
229
|
-
export { Change, ChangeHeaders, Delete, Upsert, changes, remove$1 as remove, upsert };
|
|
254
|
+
export { Change, ChangeHeaders, Delete, Entry, Upsert, changes, remove$1 as remove, upsert };
|
|
230
255
|
}
|
|
231
256
|
interface ChangeHeaders {
|
|
232
257
|
readonly txid?: string;
|
|
@@ -250,6 +275,11 @@ type Upsert<A, Type extends string = string> = Data.TaggedEnum.Value<Operation<A
|
|
|
250
275
|
type Delete<A, Type extends string = string> = Data.TaggedEnum.Value<Operation<A, Type>, "Delete">;
|
|
251
276
|
/** A pending change for one of the collections in `C`. */
|
|
252
277
|
type Change<C extends Collections> = { [K in keyof C & string]: Upsert<C[K]["schema"]["Type"], K> | Delete<C[K]["schema"]["Type"], K>; }[keyof C & string];
|
|
278
|
+
/**
|
|
279
|
+
* One entry for `changes`: a pending change, or a State control such as
|
|
280
|
+
* `StreamAddress.reset()`.
|
|
281
|
+
*/
|
|
282
|
+
type Entry<C extends Collections> = Change<C> | StateControl;
|
|
253
283
|
/** Describe an upsert into a collection. The key is read from the value. */
|
|
254
284
|
declare const upsert: <const Type extends string, A>(type: Type, value: A, options?: {
|
|
255
285
|
readonly headers?: ChangeHeaders;
|
|
@@ -261,14 +291,15 @@ declare const remove$1: <const Type extends string, A = never>(type: Type, key:
|
|
|
261
291
|
}) => Delete<NoInfer<A>, Type>;
|
|
262
292
|
/**
|
|
263
293
|
* Stamp Durable State changes with their key and headers. With an `offset`, each
|
|
264
|
-
* change gets that offset and a default txid of `<offset>:<index>`.
|
|
294
|
+
* change gets that offset and a default txid of `<offset>:<index>`. A control
|
|
295
|
+
* entry passes through. It gets the `offset` only when it has none of its own.
|
|
265
296
|
*/
|
|
266
297
|
declare function changes<C extends Collections, RD, RE>(address: StateAddress<C, RD, RE>, options: {
|
|
267
298
|
readonly offset?: string;
|
|
268
|
-
}, entries: NonEmptyReadonlyArray<
|
|
299
|
+
}, entries: Array.NonEmptyReadonlyArray<Entry<C>>): Array.NonEmptyReadonlyArray<CollectionsEvent<C>>;
|
|
269
300
|
declare function changes<C extends Collections, RD, RE>(address: StateAddress<C, RD, RE>, options: {
|
|
270
301
|
readonly offset?: string;
|
|
271
|
-
}, entries: ReadonlyArray<
|
|
302
|
+
}, entries: ReadonlyArray<Entry<C>>): ReadonlyArray<CollectionsEvent<C>>;
|
|
272
303
|
declare namespace producer_d_exports {
|
|
273
304
|
export { Position, next };
|
|
274
305
|
}
|
|
@@ -301,7 +332,7 @@ declare const create: <A, RD, RE>(address: StreamAddress<A, RD, RE>, options?: O
|
|
|
301
332
|
*/
|
|
302
333
|
type AppendItems<A, O> = O extends {
|
|
303
334
|
readonly close: true;
|
|
304
|
-
} ? ReadonlyArray<A> : NonEmptyReadonlyArray<A>;
|
|
335
|
+
} ? ReadonlyArray<A> : Array.NonEmptyReadonlyArray<A>;
|
|
305
336
|
/**
|
|
306
337
|
* Append items to one stream. The error type lists only the rejections that the
|
|
307
338
|
* options make possible; a host that answers another one dies.
|
|
@@ -322,7 +353,7 @@ interface Collected<A> {
|
|
|
322
353
|
* Read the stream up to its tail and fold every item into one value. Pass
|
|
323
354
|
* `options.offset` to fold on from a tail that an earlier fold returned.
|
|
324
355
|
*/
|
|
325
|
-
declare const fold: <A, RD, RE, S>(address: StreamAddress<A, RD, RE>, initial: LazyArg<S>, f: (state: S, item: A) => S, options?: ReadOptions$1 | undefined) => Effect.Effect<Folded<S>, ReadFailure, RD | StreamsReader>;
|
|
356
|
+
declare const fold: <A, RD, RE, S>(address: StreamAddress<A, RD, RE>, initial: Function.LazyArg<S>, f: (state: S, item: A) => S, options?: ReadOptions$1 | undefined) => Effect.Effect<Folded<S>, ReadFailure, RD | StreamsReader>;
|
|
326
357
|
/** Read the stream up to its tail and return its items. */
|
|
327
358
|
declare const collect: <A, RD, RE>(address: StreamAddress<A, RD, RE>, options?: ReadOptions$1 | undefined) => Effect.Effect<Collected<A>, ReadFailure, RD | StreamsReader>;
|
|
328
359
|
/** What one `decide` step answers: a value, and the items to append for it. */
|
|
@@ -340,7 +371,7 @@ interface Decided<B> {
|
|
|
340
371
|
}
|
|
341
372
|
interface DecideSpec<A, S, B, E, R> {
|
|
342
373
|
/** The start value of the fold. Each call starts from a new value. */
|
|
343
|
-
readonly initial: LazyArg<S>;
|
|
374
|
+
readonly initial: Function.LazyArg<S>;
|
|
344
375
|
readonly fold: (state: S, item: A) => S;
|
|
345
376
|
/**
|
|
346
377
|
* Decide what to append from the folded state. `offset` is the tail the state is
|
|
@@ -379,8 +410,6 @@ declare const items: <A, E, R>(batches: Stream.Stream<Batch<A>, E, R>) => Stream
|
|
|
379
410
|
declare const session: <A, RD, RE>(address: StreamAddress<A, RD, RE>, options: ReadNextOptions) => Effect.Effect<ReadNextResult, StorageFault | TransportFault | ReadNextError, StreamsReader>;
|
|
380
411
|
declare const head: <A, RD, RE>(address: StreamAddress<A, RD, RE>) => Effect.Effect<HeadResult, HeadFailure, StreamsReader>;
|
|
381
412
|
declare const remove: <A, RD, RE>(address: StreamAddress<A, RD, RE>) => Effect.Effect<void, RemoveFailure, StreamsWriter>;
|
|
382
|
-
//#endregion
|
|
383
|
-
//#region src/toolkit/streamsy.d.ts
|
|
384
413
|
/** A stream service with named failures for each toolkit call. */
|
|
385
414
|
interface Api<P, A, RD = never, RE = never> {
|
|
386
415
|
readonly owner: object;
|
|
@@ -389,7 +418,7 @@ interface Api<P, A, RD = never, RE = never> {
|
|
|
389
418
|
readonly create: (params: P, options?: Omit<CreateOptions, "contentType">) => Effect.Effect<CreateResult, CreateFailure>;
|
|
390
419
|
readonly append: <const O extends AppendCallOptions = {}>(params: P, items: AppendItems<A, O>, options?: O) => Effect.Effect<AppendResult, AppendFailure<O>, RE>;
|
|
391
420
|
readonly read: (params: P, options?: ReadOptions$1) => Stream.Stream<Batch<A>, ReadFailure, RD>;
|
|
392
|
-
readonly fold: <S>(params: P, initial: LazyArg<S>, f: (state: S, item: A) => S, options?: ReadOptions$1) => Effect.Effect<Folded<S>, ReadFailure, RD>;
|
|
421
|
+
readonly fold: <S>(params: P, initial: Function.LazyArg<S>, f: (state: S, item: A) => S, options?: ReadOptions$1) => Effect.Effect<Folded<S>, ReadFailure, RD>;
|
|
393
422
|
readonly collect: (params: P, options?: ReadOptions$1) => Effect.Effect<Collected<A>, ReadFailure, RD>;
|
|
394
423
|
readonly decide: <S, B, E, R>(params: P, spec: DecideSpec<A, S, B, E, R>) => Effect.Effect<Decided<B>, ReadFailure | AppendFailure<{
|
|
395
424
|
expectedOffset: string;
|
|
@@ -412,7 +441,7 @@ type Class<Self, Name extends string, P, A, RD, RE, R extends StreamRoute<P, A,
|
|
|
412
441
|
};
|
|
413
442
|
type JsonClass<Self, Name extends string, T extends string, C extends ParamCodecs, A, I, RD, RE> = Class<Self, Name, Params<C>, A, RD, RE, ReturnType<typeof json$1<T, C, A, I, RD, RE>>>;
|
|
414
443
|
declare const json: <Self>() => <const Name extends string, const T extends string, C extends ParamCodecs, A, I, RD, RE>(name: Name, ...args: Parameters<typeof json$1<T, C, A, I, RD, RE>>) => JsonClass<Self, Name, T, C, A, I, RD, RE>;
|
|
415
|
-
type StateClass<Self, Name extends string, T extends string, C extends ParamCodecs, Collections$1 extends Collections> = Class<Self, Name, Params<C>,
|
|
444
|
+
type StateClass<Self, Name extends string, T extends string, C extends ParamCodecs, Collections$1 extends Collections> = Class<Self, Name, Params<C>, CollectionsEvent<Collections$1>, CollectionsDecodingServices<Collections$1>, CollectionsEncodingServices<Collections$1>, ReturnType<typeof state$1<T, C, Collections$1>>>;
|
|
416
445
|
declare const state: <Self>() => <const Name extends string, const T extends string, C extends ParamCodecs, const Collections$2 extends Collections>(name: Name, ...args: Parameters<typeof state$1<T, C, Collections$2>>) => StateClass<Self, Name, T, C, Collections$2>;
|
|
417
446
|
type BytesClass<Self, Name extends string, T extends string, C extends ParamCodecs> = Class<Self, Name, Params<C>, Uint8Array, never, never, ReturnType<typeof bytes$1<T, C>>>;
|
|
418
447
|
declare const bytes: <Self>() => <const Name extends string, const T extends string, C extends ParamCodecs>(name: Name, ...args: Parameters<typeof bytes$1<T, C>>) => BytesClass<Self, Name, T, C>;
|
|
@@ -446,8 +475,6 @@ type Services<G extends Group> = G["streams"][number]["Identifier"];
|
|
|
446
475
|
/** What every host Layer gives for a group: its stream services. */
|
|
447
476
|
type Host<G extends Group> = Services<G>;
|
|
448
477
|
declare function group<const Keys extends ReadonlyArray<Any>>(...keys: Keys): Group<Keys>;
|
|
449
|
-
//#endregion
|
|
450
|
-
//#region src/http/routes.d.ts
|
|
451
478
|
type RouteLayer<R> = Layer.Layer<never, never, HttpRouter.HttpRouter | HttpRouter.Request.From<"Requires", Exclude<R, HttpRouter.Provided>>>;
|
|
452
479
|
interface Access<S extends Any = Any> {
|
|
453
480
|
readonly stream: S;
|
|
@@ -460,8 +487,6 @@ interface RoutesOptions extends Omit<HttpOptions, "pathPrefix"> {
|
|
|
460
487
|
}
|
|
461
488
|
/** One prefix controls both route registration and protocol path stripping. */
|
|
462
489
|
declare function routes<const Keys extends ReadonlyArray<Any>>(group: Group<Keys>, options: RoutesOptions): RouteLayer<Identifiers<Keys>>;
|
|
463
|
-
//#endregion
|
|
464
|
-
//#region src/http/read-program.d.ts
|
|
465
490
|
interface ReadOptions {
|
|
466
491
|
readonly sseDeadlineMs?: number;
|
|
467
492
|
readonly cacheVisibility?: "private" | "public";
|
|
@@ -470,15 +495,11 @@ interface ReadOptions {
|
|
|
470
495
|
declare function checkReadOptions(options: ReadOptions): void;
|
|
471
496
|
/** Read an already resolved id using the protocol's HTTP framing and live modes. */
|
|
472
497
|
declare function read(id: StreamId, options?: ReadOptions): Effect.Effect<HttpServerResponse.HttpServerResponse, InvalidReadRequest | NotSupported | StorageFault | StreamGone | StreamNotFound | TransportFault, HttpServerRequest.HttpServerRequest | StreamsReader>;
|
|
473
|
-
//#endregion
|
|
474
|
-
//#region src/http/security-headers.d.ts
|
|
475
498
|
/** Shared protocol and host security headers. */
|
|
476
499
|
declare const securityHeaders: Readonly<{
|
|
477
500
|
"x-content-type-options": "nosniff";
|
|
478
501
|
"cross-origin-resource-policy": "cross-origin";
|
|
479
502
|
}>;
|
|
480
|
-
//#endregion
|
|
481
|
-
//#region src/http/shutdown-signal.d.ts
|
|
482
503
|
/**
|
|
483
504
|
* Tells live HTTP reads that the host is about to stop. A parked long poll then
|
|
484
505
|
* answers `204` with its offset and cursor, and an open SSE body ends after its
|
|
@@ -509,5 +530,4 @@ declare const layerShutdownSignal: Layer.Layer<ShutdownSignal, never, never>;
|
|
|
509
530
|
declare namespace index_d_exports {
|
|
510
531
|
export { Access, HttpOptions, ReadOptions, RoutesOptions, ShutdownSignal, ShutdownSignalService, app, checkReadOptions, layerShutdownSignal, read, routes, securityHeaders, streamPath };
|
|
511
532
|
}
|
|
512
|
-
//#endregion
|
|
513
533
|
export { durable_state_d_exports as A, address_d_exports as B, FollowFailure as C, streams_d_exports as D, RemoveFailure as E, CommitBoundary as F, HttpOptions as H, CommitBoundaryApi as I, ZERO_OFFSET as L, MemoryOptions as M, ProtocolOptions as N, streamsy_d_exports as O, layer_d_exports as P, compare as R, Folded as S, ReadFailure as T, app as U, streamPath as V, Collected as _, securityHeaders as a, Decided as b, read as c, routes as d, Any as f, Batch as g, AppendFailure as h, layerShutdownSignal as i, streams_d_exports$1 as j, producer_d_exports as k, Access as l, Identifiers as m, ShutdownSignal as n, ReadOptions as o, Group as p, ShutdownSignalService as r, checkReadOptions as s, index_d_exports as t, RoutesOptions as u, CreateFailure as v, HeadFailure as w, Decision as x, DecideSpec as y, route_d_exports as z };
|
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-BV5Un5R0.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-C26ncp7Y.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 };
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { t as __exportAll } from "./rolldown-runtime-
|
|
2
|
-
import { $ as StreamLifecycle, B as StreamsFault, C as ProducerGap, D as StreamGone, E as StreamClosed, G as MessageWindow, H as isRetryableFault, J as ProducerState, K as Offset, L as DecodeFault, M as Storage, N as ZERO_OFFSET, O as StreamNotFound, P as compare, Q as StreamId, R as EncodeFault, S as OffsetMismatch, T as StreamBusy, U as isStreamsFault, V as TransportFault, W as ChangeSnapshot, X as StoredMessage, Y as RecordPatch, Z as StreamConfig, _ as InvalidAppendRequest, a as custom, b as InvalidReadRequest, c as state, d as address_exports, et as StreamRecord, f as AppendResult, g as ForkSourceNotFound, h as CreateConflict, k as isProtocolError, m as AppendConflict, n as bind, o as group, p as CreateResult, q as ProducerId, r as bytes, s as json, t as Wildcard, v as InvalidEpochSeq, w as StaleEpoch, x as NotSupported, y as InvalidForkRequest, z as StorageFault } from "./streamsy-
|
|
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-
|
|
6
|
-
import { Data, Layer, Predicate, Schema } from "effect";
|
|
7
|
-
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D8jQpDG7.js";
|
|
2
|
+
import { $ as StreamLifecycle, B as StreamsFault, C as ProducerGap, D as StreamGone, E as StreamClosed, G as MessageWindow, H as isRetryableFault, J as ProducerState, K as Offset, L as DecodeFault, M as Storage, N as ZERO_OFFSET, O as StreamNotFound, P as compare, Q as StreamId, R as EncodeFault, S as OffsetMismatch, T as StreamBusy, U as isStreamsFault, V as TransportFault, W as ChangeSnapshot, X as StoredMessage, Y as RecordPatch, Z as StreamConfig, _ as InvalidAppendRequest, a as custom, b as InvalidReadRequest, c as state, d as address_exports, et as StreamRecord, f as AppendResult, g as ForkSourceNotFound, h as CreateConflict, k as isProtocolError, m as AppendConflict, n as bind, o as group, p as CreateResult, q as ProducerId, r as bytes, s as json, t as Wildcard, v as InvalidEpochSeq, w as StaleEpoch, x as NotSupported, y as InvalidForkRequest, z as StorageFault } from "./streamsy-DJMArv09.js";
|
|
3
|
+
import { n as CommitBoundary, t as layer$1 } from "./layer-DJ-c63nY.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-DyezIxJT.js";
|
|
5
|
+
import { t as http_exports } from "./http-x2IjDHvw.js";
|
|
6
|
+
import { Array, Data, Layer, Predicate, Record, Schema } from "effect";
|
|
7
|
+
// src/storage/capabilities.ts
|
|
8
8
|
const StorageCapabilities = Schema.Struct({
|
|
9
9
|
fork: Schema.Literals([
|
|
10
10
|
"none",
|
|
@@ -15,8 +15,7 @@ const StorageCapabilities = Schema.Struct({
|
|
|
15
15
|
wake: Schema.Literals(["poll", "push"]),
|
|
16
16
|
expiryIndex: Schema.Literals(["lazy", "indexed"])
|
|
17
17
|
});
|
|
18
|
-
|
|
19
|
-
//#region src/storage/memory/streams.ts
|
|
18
|
+
// src/storage/memory/streams.ts
|
|
20
19
|
var streams_exports = /* @__PURE__ */ __exportAll({
|
|
21
20
|
layer: () => layer,
|
|
22
21
|
layerProtocol: () => layerProtocol
|
|
@@ -28,14 +27,14 @@ function layer(group, options = {}) {
|
|
|
28
27
|
const protocol = layer$2(options).pipe(Layer.provideMerge(storage));
|
|
29
28
|
return bind(protocol, group).pipe(Layer.provideMerge(storage));
|
|
30
29
|
}
|
|
31
|
-
|
|
32
|
-
//#region src/toolkit/durable-state.ts
|
|
30
|
+
// src/toolkit/durable-state.ts
|
|
33
31
|
var durable_state_exports = /* @__PURE__ */ __exportAll({
|
|
34
32
|
changes: () => changes,
|
|
35
33
|
remove: () => remove,
|
|
36
34
|
upsert: () => upsert
|
|
37
35
|
});
|
|
38
36
|
const operations = Data.taggedEnum();
|
|
37
|
+
const isOperation = (entry) => Predicate.isTagged(entry, "Upsert") || Predicate.isTagged(entry, "Delete");
|
|
39
38
|
/** Describe an upsert into a collection. The key is read from the value. */
|
|
40
39
|
const upsert = (type, value, options = {}) => operations.Upsert({
|
|
41
40
|
type,
|
|
@@ -57,57 +56,60 @@ const checkKey = (type, source, raw) => {
|
|
|
57
56
|
const readKey = (type, field, value) => checkKey(type, `field "${String(field)}"`, String(value[field] ?? ""));
|
|
58
57
|
function changes(address, options, entries) {
|
|
59
58
|
const { offset } = options;
|
|
60
|
-
return
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
value: entry.value,
|
|
76
|
-
headers: {
|
|
77
|
-
operation: "upsert",
|
|
78
|
-
...headers
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
const key = checkKey(entry.type, "key", entry.key);
|
|
83
|
-
return entry.oldValue === void 0 ? {
|
|
84
|
-
type: entry.type,
|
|
85
|
-
key,
|
|
86
|
-
headers: {
|
|
87
|
-
operation: "delete",
|
|
88
|
-
...headers
|
|
89
|
-
}
|
|
90
|
-
} : {
|
|
59
|
+
return Array.map(entries, (entry, index) => isOperation(entry) ? stampChange(address.collections, entry, offset, index) : stampControl(entry, offset));
|
|
60
|
+
}
|
|
61
|
+
const stampChange = (collections, entry, offset, index) => {
|
|
62
|
+
const collection = Record.has(collections, entry.type) ? collections[entry.type] : void 0;
|
|
63
|
+
if (collection === void 0) throw new TypeError(`Unknown state collection "${entry.type}"`);
|
|
64
|
+
const override = entry.headers ?? {};
|
|
65
|
+
const txid = override.txid ?? (offset === void 0 ? void 0 : `${offset}:${index}`);
|
|
66
|
+
const headers = {};
|
|
67
|
+
if (offset !== void 0) headers.offset = offset;
|
|
68
|
+
if (txid !== void 0) headers.txid = txid;
|
|
69
|
+
if (override.timestamp !== void 0) headers.timestamp = override.timestamp;
|
|
70
|
+
if (override.from !== void 0) headers.from = override.from;
|
|
71
|
+
if (Predicate.isTagged(entry, "Upsert")) {
|
|
72
|
+
const key = readKey(entry.type, collection.key, entry.value);
|
|
73
|
+
return {
|
|
91
74
|
type: entry.type,
|
|
92
75
|
key,
|
|
93
|
-
|
|
76
|
+
value: entry.value,
|
|
94
77
|
headers: {
|
|
95
|
-
operation: "
|
|
78
|
+
operation: "upsert",
|
|
96
79
|
...headers
|
|
97
80
|
}
|
|
98
81
|
};
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
82
|
+
}
|
|
83
|
+
const key = checkKey(entry.type, "key", entry.key);
|
|
84
|
+
return entry.oldValue === void 0 ? {
|
|
85
|
+
type: entry.type,
|
|
86
|
+
key,
|
|
87
|
+
headers: {
|
|
88
|
+
operation: "delete",
|
|
89
|
+
...headers
|
|
90
|
+
}
|
|
91
|
+
} : {
|
|
92
|
+
type: entry.type,
|
|
93
|
+
key,
|
|
94
|
+
old_value: entry.oldValue,
|
|
95
|
+
headers: {
|
|
96
|
+
operation: "delete",
|
|
97
|
+
...headers
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
const stampControl = (entry, offset) => offset === void 0 || entry.headers.offset !== void 0 ? entry : { headers: {
|
|
102
|
+
control: entry.headers.control,
|
|
103
|
+
offset
|
|
104
|
+
} };
|
|
105
|
+
// src/toolkit/producer.ts
|
|
103
106
|
var producer_exports = /* @__PURE__ */ __exportAll({ next: () => next });
|
|
104
107
|
/** Advance only after the caller has acknowledged appended or duplicate. Persist this tuple at the owning edge. */
|
|
105
108
|
const next = (position) => ({
|
|
106
109
|
...position,
|
|
107
110
|
producerSeq: position.producerSeq + 1
|
|
108
111
|
});
|
|
109
|
-
|
|
110
|
-
//#region src/streamsy.ts
|
|
112
|
+
// src/streamsy.ts
|
|
111
113
|
var streamsy_exports = /* @__PURE__ */ __exportAll({
|
|
112
114
|
Wildcard: () => Wildcard,
|
|
113
115
|
bytes: () => bytes,
|
|
@@ -116,5 +118,4 @@ var streamsy_exports = /* @__PURE__ */ __exportAll({
|
|
|
116
118
|
json: () => json,
|
|
117
119
|
state: () => state
|
|
118
120
|
});
|
|
119
|
-
//#endregion
|
|
120
121
|
export { AppendConflict, AppendResult, ChangeSnapshot, CommitBoundary, CreateConflict, CreateResult, DecodeFault, durable_state_exports as DurableState, EncodeFault, ForkSourceNotFound, http_exports as Http, InvalidAppendRequest, InvalidEpochSeq, InvalidForkRequest, InvalidReadRequest, streams_exports as MemoryStorage, MessageWindow, Mutation, MutationApplied, MutationRejected, Mutations, NotSupported, Offset, OffsetMismatch, Operation, OperationResult, OperationResults, Operations, producer_exports as Producer, ProducerGap, ProducerId, ProducerPrecondition, ProducerState, RecordPatch, StaleEpoch, Storage, StorageCapabilities, StorageFault, StoredMessage, address_exports as StreamAddress, StreamBusy, StreamClosed, StreamConfig, StreamGone, StreamId, StreamLifecycle, StreamNotFound, StreamRecord, StreamsFault, streamsy_exports as Streamsy, TransportFault, ZERO_OFFSET, compare, isProtocolError, isRetryableFault, isStreamsFault };
|
package/dist/internal/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { n as OwnerRecordsApi, t as OwnerRecords } from "../owner-records-
|
|
1
|
+
import { n as OwnerRecordsApi, t as OwnerRecords } from "../owner-records-BV5Un5R0.js";
|
|
2
2
|
import { Context, Effect } from "effect";
|
|
3
|
-
//#region src/internal/owner.d.ts
|
|
4
3
|
/** Private bridge: a stream guard dies with this sentinel; the atomic runner translates it. */
|
|
5
4
|
declare const ForeignOwnerType: unique symbol;
|
|
6
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 & {
|
|
@@ -18,5 +17,4 @@ type Owner = object;
|
|
|
18
17
|
export declare const attachOwner: <A extends object>(value: A, owner: Owner) => A;
|
|
19
18
|
export declare const ownerOf: (value: object) => Owner;
|
|
20
19
|
export declare const CurrentOwner: Context.Reference<object | undefined>;
|
|
21
|
-
//#endregion
|
|
22
20
|
export { OwnerRecords, type OwnerRecordsApi };
|