@streamsy/core 0.15.0 → 0.17.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 +4 -284
- package/dist/{create-validation-DzLxKiux.js → create-validation-NKP81BC0.js} +1 -1
- package/dist/http/index.d.ts +1 -1
- package/dist/http/index.js +2 -2
- package/dist/{http-YoA8cUTN.js → http-aCMEaxro.js} +2 -2
- package/dist/index-DIx4D2t0.d.ts +836 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +134 -224
- package/dist/internal/index.d.ts +284 -25
- package/dist/internal/index.js +12 -3
- package/dist/{layer-DjKTdIY5.js → layer-DTOhxWkw.js} +21 -19
- package/dist/{layer-J6sV3UXD.js → layer-Dv_LBCgD.js} +15 -8
- package/dist/{program-BlfAJNlD.js → program-gGLU50A1.js} +16 -11
- package/dist/protocol/index.d.ts +1 -2
- package/dist/protocol/index.js +3 -3
- package/dist/read-message-DP1UpEFl.js +660 -0
- package/dist/remote/index.d.ts +5 -3
- package/dist/remote/index.js +158 -28
- package/dist/{projection-marks-BEZv8qDJ.d.ts → storage-xTb82JxJ.d.ts} +376 -397
- package/dist/{streamsy-HKC10a_V.js → streamsy-DiAjZWlT.js} +336 -174
- package/dist/testing/index.d.ts +7 -7
- package/dist/testing/index.js +28 -21
- package/package.json +4 -4
- package/dist/boundary-f1biibJ1.js +0 -371
- package/dist/index-BtVxu6VJ.d.ts +0 -774
- package/dist/route-internal-DNL0oGTN.js +0 -93
package/dist/internal/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Cause, Context, Effect, Option, Schema } from "effect";
|
|
1
|
+
import { A as ReadResult, C as StorageOwnerApi, G as StreamId, O as ReadMessage, Q as StorageFault, S as StorageOwner, Y as DecodeFault, Z as InvalidStreamParams, f as StreamAddress, t as StorageShape, x as OwnerId } from "../storage-xTb82JxJ.js";
|
|
2
|
+
import { Cause, Context, Data, Effect, Option, Schema, Scope } from "effect";
|
|
3
|
+
import { SqlClient, SqlError } from "effect/sql";
|
|
3
4
|
/** Private bridge: a stream guard dies with this sentinel; the atomic runner translates it. */
|
|
4
5
|
declare const ForeignOwnerType: unique symbol;
|
|
5
6
|
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 & {
|
|
@@ -13,10 +14,223 @@ declare class ForeignOwner extends ForeignOwner_base<{
|
|
|
13
14
|
constructor(stream: string, knownOwner: boolean);
|
|
14
15
|
}
|
|
15
16
|
export declare const isForeignOwner: (value: unknown) => value is ForeignOwner;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
export declare const CurrentOwner: Context.Reference<OwnerId | undefined>;
|
|
18
|
+
/**
|
|
19
|
+
* Work that joins an owned transaction just before it commits. It receives the
|
|
20
|
+
* stream ids that the transaction created, appended to or deleted.
|
|
21
|
+
*/
|
|
22
|
+
type CommitHook = (ids: ReadonlySet<StreamId>) => Effect.Effect<void, SqlError.SqlError>;
|
|
23
|
+
/**
|
|
24
|
+
* Commit hooks on the storage owner, for the durable projection marks.
|
|
25
|
+
*
|
|
26
|
+
* A hook runs inside each later owned transaction that wrote at least one stream
|
|
27
|
+
* id, after the body and before COMMIT. Statements in the hook join the
|
|
28
|
+
* transaction, and a hook failure rolls the transaction back. A SQL host treats
|
|
29
|
+
* a hook failure like a body failure, so a retryable `SqlError` replays the
|
|
30
|
+
* whole transaction, hook included. The memory host turns a hook failure into a
|
|
31
|
+
* defect. A hook must not write streams: its ids would not reach other hooks.
|
|
32
|
+
*/
|
|
33
|
+
interface CommitHooksApi {
|
|
34
|
+
/** Register `hook` until the scope closes. */
|
|
35
|
+
readonly beforeCommit: (hook: CommitHook) => Effect.Effect<void, never, Scope.Scope>;
|
|
36
|
+
}
|
|
37
|
+
/** Shared registry for storage boundaries: register in a scope, run in order. */
|
|
38
|
+
export declare const commitHookRegistry: () => {
|
|
39
|
+
beforeCommit: (hook: CommitHook) => Effect.Effect<void, never, Scope.Scope>;
|
|
40
|
+
run: (ids: ReadonlySet<StreamId>) => Effect.Effect<void, SqlError.SqlError>;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Encoded records on the storage owner, for the projection checkpoint store.
|
|
44
|
+
* Calls inside `StorageOwner.withTransaction` join that transaction.
|
|
45
|
+
*/
|
|
46
|
+
interface OwnerRecordsApi {
|
|
47
|
+
readonly read: (key: string) => Effect.Effect<Option.Option<string>, StorageFault>;
|
|
48
|
+
/**
|
|
49
|
+
* A snapshot of the owner's encoded entries whose keys start with this exact prefix.
|
|
50
|
+
* A store that cannot list fails with operation `OWNER_RECORDS_LIST_UNSUPPORTED`.
|
|
51
|
+
*/
|
|
52
|
+
readonly list: (prefix: string) => Effect.Effect<ReadonlyArray<readonly [key: string, encoded: string]>, StorageFault>;
|
|
53
|
+
readonly write: (key: string, encoded: string) => Effect.Effect<void, StorageFault>;
|
|
54
|
+
readonly remove: (key: string) => Effect.Effect<void, StorageFault>;
|
|
55
|
+
}
|
|
56
|
+
/** The `StorageFault.operation` of an owner store that cannot list its records. */
|
|
57
|
+
export declare const OWNER_RECORDS_LIST_UNSUPPORTED = "records.list.unsupported";
|
|
58
|
+
/** Last failed run, retained through marks, retries and resumes. Messages hold at most 1,000 characters. */
|
|
59
|
+
interface MarkFailure {
|
|
60
|
+
readonly at: number;
|
|
61
|
+
readonly reason: Option.Option<string>;
|
|
62
|
+
readonly message: string;
|
|
63
|
+
}
|
|
64
|
+
/** One pending mark: a binding with input work, a retry, or a recorded wake. */
|
|
65
|
+
interface PendingMark {
|
|
66
|
+
/** The binding's canonical params, as `canonicalParams` encodes them. */
|
|
67
|
+
readonly params: string;
|
|
68
|
+
/** Raised by every mark. A clear only deletes the row when its `seq` still matches. */
|
|
69
|
+
readonly seq: number;
|
|
70
|
+
/** Failed runs since the last success. A mark keeps it. */
|
|
71
|
+
readonly attempts: number;
|
|
72
|
+
/** Epoch ms. 0 means due now; ignored while stopped. */
|
|
73
|
+
readonly dueAt: number;
|
|
74
|
+
/** Recorded wake; when set, equals dueAt and the row has no failure or attempts. */
|
|
75
|
+
readonly wakeAt: Option.Option<number>;
|
|
76
|
+
/** Waits until retry or resume. A mark preserves the stop. */
|
|
77
|
+
readonly stopped: boolean;
|
|
78
|
+
readonly failure: Option.Option<MarkFailure>;
|
|
79
|
+
}
|
|
80
|
+
/** Disjoint counts of one projection's marks at the supplied time. */
|
|
81
|
+
interface ProjectionMarkSummary {
|
|
82
|
+
readonly fresh: number;
|
|
83
|
+
readonly sleeping: number;
|
|
84
|
+
readonly retryDue: number;
|
|
85
|
+
readonly backingOff: number;
|
|
86
|
+
readonly stopped: number;
|
|
87
|
+
/** Earliest due time across non-stopped marks, including fresh and sleeping marks. */
|
|
88
|
+
readonly nextDueAt: Option.Option<number>;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Pending marks for attached projections, on a storage owner or in private memory.
|
|
92
|
+
*
|
|
93
|
+
* A mark is keyed by projection id and canonical params. A deploy that raises the
|
|
94
|
+
* generation picks up the existing marks.
|
|
95
|
+
*/
|
|
96
|
+
interface ProjectionMarksApi {
|
|
97
|
+
/** Maximum projection id length in Unicode code points, when bounded by storage. */
|
|
98
|
+
readonly maxProjectionIdLength?: number;
|
|
99
|
+
/**
|
|
100
|
+
* Insert a mark for each binding, or raise its `seq`. A raise keeps
|
|
101
|
+
* `attempts`, `stopped` and `failure`, so a write never resets backoff or a stop.
|
|
102
|
+
* A sleeping row becomes due now and loses its wake index.
|
|
103
|
+
* Call it inside a commit hook. It joins the transaction and fails like the
|
|
104
|
+
* transaction's own statements.
|
|
105
|
+
*/
|
|
106
|
+
readonly mark: (projection: string, params: ReadonlyArray<string>) => Effect.Effect<void, SqlError.SqlError>;
|
|
107
|
+
/** The earliest `dueAt` of the projection's non-stopped marks. */
|
|
108
|
+
readonly nextDue: (projection: string) => Effect.Effect<Option.Option<number>, StorageFault>;
|
|
109
|
+
/** Five disjoint counts: fresh, sleeping, retry due, backing off and stopped. */
|
|
110
|
+
readonly summary: (projection: string, now: number) => Effect.Effect<ProjectionMarkSummary, StorageFault>;
|
|
111
|
+
/** Up to `limit` non-stopped marks with `dueAt <= now`, earliest first. */
|
|
112
|
+
readonly due: (projection: string, now: number, limit: number) => Effect.Effect<ReadonlyArray<PendingMark>, StorageFault>;
|
|
113
|
+
/** The marks of these bindings that exist, keyed by params. */
|
|
114
|
+
readonly read: (projection: string, params: ReadonlyArray<string>) => Effect.Effect<ReadonlyMap<string, PendingMark>, StorageFault>;
|
|
115
|
+
/** Delete on a matching `seq`; otherwise keep the row and reset its failure, attempts, dueAt, wakeAt and stop. */
|
|
116
|
+
readonly clear: (projection: string, params: string, seq: number) => Effect.Effect<void, StorageFault>;
|
|
117
|
+
/** Keep a matching row asleep at wakeAt and reset failure state. A seq mismatch
|
|
118
|
+
* becomes fresh and due now. An absent row is inserted asleep with seq 1. */
|
|
119
|
+
readonly sleep: (projection: string, params: string, seq: number, wakeAt: number) => Effect.Effect<void, StorageFault>;
|
|
120
|
+
/** Delete the mark whatever its `seq`. */
|
|
121
|
+
readonly remove: (projection: string, params: string) => Effect.Effect<void, StorageFault>;
|
|
122
|
+
/** Insert or update a failure, preserving seq. Some(dueAt) backs off; None stops. */
|
|
123
|
+
readonly fail: (projection: string, params: string, options: {
|
|
124
|
+
readonly attempts: number;
|
|
125
|
+
readonly failure: MarkFailure;
|
|
126
|
+
readonly dueAt: Option.Option<number>;
|
|
127
|
+
}) => Effect.Effect<void, StorageFault>;
|
|
128
|
+
/** Set failed or stopped marks due now and clear their stop, preserving attempts, seq and failure.
|
|
129
|
+
* Optionally select one binding. Returns the number changed; already due, non-stopped marks are unchanged.
|
|
130
|
+
*/
|
|
131
|
+
readonly retry: (projection: string, params?: string) => Effect.Effect<number, StorageFault>;
|
|
132
|
+
/** Make stopped marks due now, preserving attempts, seq and failure. Returns the number changed. */
|
|
133
|
+
readonly resume: (projection: string) => Effect.Effect<number, StorageFault>;
|
|
134
|
+
/** Up to limit marks with attempts > 0, stopped first, then by dueAt and params. */
|
|
135
|
+
readonly failed: (projection: string, limit: number) => Effect.Effect<ReadonlyArray<PendingMark>, StorageFault>;
|
|
136
|
+
}
|
|
137
|
+
interface TransactionParticipant {
|
|
138
|
+
/** Runs synchronously after the draft becomes committed, before wakes. Must not throw. */
|
|
139
|
+
readonly onCommit: () => void;
|
|
140
|
+
/**
|
|
141
|
+
* Runs synchronously when the outer transaction rolls back. Must not throw.
|
|
142
|
+
* A throw adds a defect to the transaction's cause. Effect's typed recovery
|
|
143
|
+
* gives defects precedence even when the exit still contains a typed failure.
|
|
144
|
+
*/
|
|
145
|
+
readonly onRollback: () => void;
|
|
146
|
+
}
|
|
147
|
+
declare const MemoryEnlistFault_base: Schema.Class<MemoryEnlistFault, Schema.TaggedStruct<"MemoryEnlistFault", {
|
|
148
|
+
readonly message: Schema.String;
|
|
149
|
+
}>, Cause.YieldableError & {
|
|
150
|
+
readonly brand: unique symbol;
|
|
151
|
+
}>;
|
|
152
|
+
export declare class MemoryEnlistFault extends MemoryEnlistFault_base {}
|
|
153
|
+
/**
|
|
154
|
+
* The backend kind of a storage owner. `Sql`: Streamsy packages put their tables on
|
|
155
|
+
* this client, in its transaction. `Memory`: Streamsy packages join the owner's
|
|
156
|
+
* transaction open on this fiber with `enlist`, which fails outside it.
|
|
157
|
+
*/
|
|
158
|
+
export type OwnerBackend = Data.TaggedEnum<{
|
|
159
|
+
Sql: {
|
|
160
|
+
readonly client: SqlClient.SqlClient;
|
|
161
|
+
};
|
|
162
|
+
Memory: {
|
|
163
|
+
readonly enlist: (participant: TransactionParticipant) => Effect.Effect<void, MemoryEnlistFault>;
|
|
164
|
+
};
|
|
165
|
+
}>;
|
|
166
|
+
export declare const OwnerBackend: Data.TaggedEnum.Constructor<{
|
|
167
|
+
readonly _tag: "Memory";
|
|
168
|
+
readonly enlist: (participant: TransactionParticipant) => Effect.Effect<void, MemoryEnlistFault>;
|
|
169
|
+
} | {
|
|
170
|
+
readonly _tag: "Sql";
|
|
171
|
+
readonly client: SqlClient.SqlClient;
|
|
172
|
+
}>;
|
|
173
|
+
/** A SQL owner's backend. */
|
|
174
|
+
type SqlBackend = Data.TaggedEnum.Value<OwnerBackend, "Sql">;
|
|
175
|
+
/** A memory owner's backend. */
|
|
176
|
+
type MemoryBackend = Data.TaggedEnum.Value<OwnerBackend, "Memory">;
|
|
177
|
+
/**
|
|
178
|
+
* Join the memory owner's transaction open on this fiber. A SQL owner has no memory
|
|
179
|
+
* transaction, so there it fails as an enlist outside the owner fiber does.
|
|
180
|
+
*/
|
|
181
|
+
export declare const memoryEnlist: (backend: OwnerBackend) => MemoryBackend["enlist"];
|
|
182
|
+
/**
|
|
183
|
+
* A key for one value on each owner. Keep the key in a module constant: each owner runs
|
|
184
|
+
* `make` with its own parts once, on first use.
|
|
185
|
+
*/
|
|
186
|
+
export declare class OwnerSlot<A> {
|
|
187
|
+
readonly make: (parts: OwnerParts) => A;
|
|
188
|
+
constructor(make: (parts: OwnerParts) => A);
|
|
189
|
+
}
|
|
190
|
+
/** The adapter parts of a storage owner, for Streamsy packages. */
|
|
191
|
+
interface OwnerParts {
|
|
192
|
+
readonly storage: StorageShape;
|
|
193
|
+
readonly records: OwnerRecordsApi;
|
|
194
|
+
readonly hooks: CommitHooksApi;
|
|
195
|
+
readonly marks: ProjectionMarksApi;
|
|
196
|
+
readonly backend: OwnerBackend;
|
|
197
|
+
/**
|
|
198
|
+
* The value of `key` on this owner. The first call runs the key's `make`; later calls
|
|
199
|
+
* with the same key return that value, whichever layer asks.
|
|
200
|
+
*/
|
|
201
|
+
readonly slot: <A>(key: OwnerSlot<A>) => A;
|
|
202
|
+
}
|
|
203
|
+
/** What an adapter supplies to build a storage owner. */
|
|
204
|
+
interface OwnerOptions {
|
|
205
|
+
/** A short label for the owner id, such as `memory` or `sql`. */
|
|
206
|
+
readonly label: string;
|
|
207
|
+
readonly storage: StorageShape;
|
|
208
|
+
readonly records: OwnerRecordsApi;
|
|
209
|
+
readonly hooks: CommitHooksApi;
|
|
210
|
+
readonly marks: ProjectionMarksApi;
|
|
211
|
+
readonly backend: OwnerBackend;
|
|
212
|
+
/** The owner's transaction. A SQL host maps each `SqlError` to a `StorageFault`. */
|
|
213
|
+
readonly withTransaction: StorageOwnerApi["withTransaction"];
|
|
214
|
+
}
|
|
215
|
+
/** A fresh owner identity. Each call returns a value no other call returns. */
|
|
216
|
+
export declare const newOwnerId: (label: string) => OwnerId;
|
|
217
|
+
/** Build a storage owner from its adapter parts. Each call is a new owner. */
|
|
218
|
+
export declare const buildStorageOwner: (options: OwnerOptions) => typeof StorageOwner.Service;
|
|
219
|
+
/** The parts a decorator can replace. */
|
|
220
|
+
interface OwnerPatch {
|
|
221
|
+
readonly storage?: StorageShape;
|
|
222
|
+
readonly records?: OwnerRecordsApi;
|
|
223
|
+
readonly hooks?: CommitHooksApi;
|
|
224
|
+
readonly marks?: ProjectionMarksApi;
|
|
225
|
+
readonly withTransaction?: StorageOwnerApi["withTransaction"];
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* The same owner with some parts replaced, for decorators in tests. The id, the backend
|
|
229
|
+
* and the slots stay the owner's own.
|
|
230
|
+
*/
|
|
231
|
+
export declare const decorateOwner: (owner: typeof StorageOwner.Service, patch: OwnerPatch) => typeof StorageOwner.Service;
|
|
232
|
+
/** The adapter parts of `owner`. Dies when `buildStorageOwner` did not build it. */
|
|
233
|
+
export declare const ownerParts: (owner: typeof StorageOwner.Service) => OwnerParts;
|
|
20
234
|
/**
|
|
21
235
|
* The MySQL producer key holds a stream id and at most this many producer id
|
|
22
236
|
* code points, so every storage dialect enforces it. Projections that build
|
|
@@ -53,26 +267,71 @@ interface TemplateGrammar<Template extends string = string> {
|
|
|
53
267
|
readonly names: ReadonlyArray<string>;
|
|
54
268
|
}
|
|
55
269
|
export declare function compileSegments<const Template extends string>(template: Template): TemplateGrammar<Template>;
|
|
270
|
+
/**
|
|
271
|
+
* True when a route is a singleton: a template route whose template names no parameter.
|
|
272
|
+
* A custom route has an empty template and is never a singleton.
|
|
273
|
+
*/
|
|
274
|
+
export declare function isSingletonRoute(route: {
|
|
275
|
+
readonly template: string;
|
|
276
|
+
}): boolean;
|
|
56
277
|
/** A new private marks store. Each operation runs synchronously when its Effect executes. */
|
|
57
278
|
export declare const memoryProjectionMarks: () => ProjectionMarksApi;
|
|
58
|
-
interface TransactionParticipant {
|
|
59
|
-
/** Runs synchronously after the draft becomes committed, before wakes. Must not throw. */
|
|
60
|
-
readonly onCommit: () => void;
|
|
61
|
-
/**
|
|
62
|
-
* Runs synchronously when the outer transaction rolls back. Must not throw.
|
|
63
|
-
* A throw adds a defect to the transaction's cause. Effect's typed recovery
|
|
64
|
-
* gives defects precedence even when the exit still contains a typed failure.
|
|
65
|
-
*/
|
|
66
|
-
readonly onRollback: () => void;
|
|
67
|
-
}
|
|
68
|
-
declare const MemoryEnlistFault_base: Schema.Class<MemoryEnlistFault, Schema.TaggedStruct<"MemoryEnlistFault", {
|
|
69
|
-
readonly message: Schema.String;
|
|
70
|
-
}>, Cause.YieldableError & {
|
|
71
|
-
readonly brand: unique symbol;
|
|
72
|
-
}>;
|
|
73
|
-
declare class MemoryEnlistFault extends MemoryEnlistFault_base {}
|
|
74
|
-
/** Join the memory owner transaction open on this fiber. */
|
|
75
|
-
export declare function enlist(owner: object, participant: TransactionParticipant): Effect.Effect<void, MemoryEnlistFault>;
|
|
76
279
|
export declare const attachOffsets: <A extends object>(result: A, offsets: ReadonlyArray<string>) => A;
|
|
77
280
|
export declare const offsetsOf: (result: Pick<ReadResult, "messages">) => ReadonlyArray<string> | undefined;
|
|
78
|
-
|
|
281
|
+
/** A decoded message, or None for a change outside a non-strict State address's collections. */
|
|
282
|
+
export declare const decodeMessage: <A, RD, RE>(address: StreamAddress<A, RD, RE>, message: ReadMessage, index: number) => Effect.Effect<Option.Option<A>, DecodeFault, RD>;
|
|
283
|
+
/** Decode the State envelope while keeping row values in their wire form. */
|
|
284
|
+
export declare const decodeStateWire: (input: string, options?: import("effect/SchemaAST").ParseOptions) => Effect.Effect<{
|
|
285
|
+
readonly headers: {
|
|
286
|
+
readonly control: "reset" | "snapshot-end" | "snapshot-start";
|
|
287
|
+
readonly offset?: string | undefined;
|
|
288
|
+
};
|
|
289
|
+
} | {
|
|
290
|
+
readonly type: string;
|
|
291
|
+
readonly key: string;
|
|
292
|
+
readonly value: unknown;
|
|
293
|
+
readonly headers: {
|
|
294
|
+
readonly offset?: string | undefined;
|
|
295
|
+
readonly txid?: string | undefined;
|
|
296
|
+
readonly timestamp?: string | undefined;
|
|
297
|
+
readonly from?: string | undefined;
|
|
298
|
+
readonly operation: "upsert";
|
|
299
|
+
};
|
|
300
|
+
} | {
|
|
301
|
+
readonly type: string;
|
|
302
|
+
readonly key: string;
|
|
303
|
+
readonly old_value?: unknown;
|
|
304
|
+
readonly headers: {
|
|
305
|
+
readonly offset?: string | undefined;
|
|
306
|
+
readonly txid?: string | undefined;
|
|
307
|
+
readonly timestamp?: string | undefined;
|
|
308
|
+
readonly from?: string | undefined;
|
|
309
|
+
readonly operation: "delete";
|
|
310
|
+
};
|
|
311
|
+
}, Schema.SchemaError, never>;
|
|
312
|
+
/**
|
|
313
|
+
* Throw a params failure from a synchronous binding such as `at(params)`. The throw is a
|
|
314
|
+
* `RangeError` whose `cause` is the typed failure, so `resolveParams` can recover it.
|
|
315
|
+
*/
|
|
316
|
+
export declare const throwInvalidStreamParams: (error: InvalidStreamParams) => never;
|
|
317
|
+
/**
|
|
318
|
+
* Run a throwing params binding inside an Effect. A params failure becomes
|
|
319
|
+
* `InvalidStreamParams` in `E`; any other throw is a defect.
|
|
320
|
+
*/
|
|
321
|
+
export declare const resolveParams: <A>(bind: () => A) => Effect.Effect<A, InvalidStreamParams>;
|
|
322
|
+
/**
|
|
323
|
+
* A declaration that binds to a value. A singleton declaration has `singleton`, its bound
|
|
324
|
+
* value. A declaration with params has `at(params)`.
|
|
325
|
+
*/
|
|
326
|
+
type Bindable<P, B> = {
|
|
327
|
+
readonly singleton: B;
|
|
328
|
+
} | {
|
|
329
|
+
readonly at: (params: P) => B;
|
|
330
|
+
};
|
|
331
|
+
/**
|
|
332
|
+
* Bind any declaration for `params`: its `singleton` for a singleton, `at(params)` otherwise.
|
|
333
|
+
* A singleton ignores `params`, as its route reads none. `at` may throw a `RangeError` whose
|
|
334
|
+
* `cause` is an `InvalidStreamParams`; wrap the call in `resolveParams` for request values.
|
|
335
|
+
*/
|
|
336
|
+
export declare const bindDeclaration: <P, B>(declaration: Bindable<P, B>, params: P) => B;
|
|
337
|
+
export type { Bindable, CommitHook, CommitHooksApi, MarkFailure, MemoryBackend, OwnerOptions, OwnerParts, OwnerPatch, OwnerRecordsApi, PendingMark, ProjectionMarkSummary, ProjectionMarksApi, SqlBackend, TransactionParticipant };
|
package/dist/internal/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import { a as attachOwner, c as isForeignOwner, i as CurrentOwner, l as ownerOf, t as compileSegments } from "../route-internal-DNL0oGTN.js";
|
|
1
|
+
import { C as memoryProjectionMarks, O as commitHookRegistry, _ as decorateOwner, a as compileSegments, b as ownerParts, d as CurrentOwner, g as buildStorageOwner, h as OwnerSlot, l as resolveParams, m as OwnerBackend, n as decodeStateWire, p as isForeignOwner, s as isSingletonRoute, t as decodeMessage, u as throwInvalidStreamParams, v as memoryEnlist, x as MemoryEnlistFault, y as newOwnerId } from "../read-message-DP1UpEFl.js";
|
|
3
2
|
import { n as offsetsOf, t as attachOffsets } from "../read-offsets-CQ4VkAs8.js";
|
|
4
3
|
import { Array, Effect } from "effect";
|
|
4
|
+
// src/internal/owner-records.ts
|
|
5
|
+
/** The `StorageFault.operation` of an owner store that cannot list its records. */
|
|
6
|
+
const OWNER_RECORDS_LIST_UNSUPPORTED = "records.list.unsupported";
|
|
5
7
|
// src/internal/limits.ts
|
|
6
8
|
/**
|
|
7
9
|
* The MySQL producer key holds a stream id and at most this many producer id
|
|
@@ -26,4 +28,11 @@ const fitKey = (key, limit, readable = key) => {
|
|
|
26
28
|
const prefix = Array.join(Array.take(codePoints(readable), limit - DIGEST_LENGTH), "");
|
|
27
29
|
return Effect.map(sha256Hex(key), (digest) => `${prefix}#${digest}`);
|
|
28
30
|
};
|
|
29
|
-
|
|
31
|
+
// src/internal/bind-declaration.ts
|
|
32
|
+
/**
|
|
33
|
+
* Bind any declaration for `params`: its `singleton` for a singleton, `at(params)` otherwise.
|
|
34
|
+
* A singleton ignores `params`, as its route reads none. `at` may throw a `RangeError` whose
|
|
35
|
+
* `cause` is an `InvalidStreamParams`; wrap the call in `resolveParams` for request values.
|
|
36
|
+
*/
|
|
37
|
+
const bindDeclaration = (declaration, params) => "singleton" in declaration ? declaration.singleton : declaration.at(params);
|
|
38
|
+
export { CurrentOwner, MAX_PRODUCER_ID_LENGTH, MemoryEnlistFault, OWNER_RECORDS_LIST_UNSUPPORTED, OwnerBackend, OwnerSlot, attachOffsets, bindDeclaration, buildStorageOwner, commitHookRegistry, compileSegments, decodeMessage, decodeStateWire, decorateOwner, fitKey, isForeignOwner, isSingletonRoute, memoryEnlist, memoryProjectionMarks, newOwnerId, offsetsOf, ownerParts, resolveParams, throwInvalidStreamParams };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D8jQpDG7.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { n as validateCreateOptions, r as frameMessages, t as frameCreateMessages } from "./create-validation-
|
|
2
|
+
import { A as ProducerGap, B as compare, C as InvalidAppendRequest, D as InvalidReadRequest, E as InvalidForkRequest, F as StreamNotFound, J as ProducerState, L as StreamsReader, M as StreamBusy, N as StreamClosed, O as NotSupported, P as StreamGone, Q as StreamId, R as StreamsWriter, S as ForkSourceNotFound, T as InvalidEpochSeq, U as next, V as isStreamsyOffset, X as StoredMessage, Y as RecordPatch, b as AppendConflict, et as StreamRecord, j as StaleEpoch, k as OffsetMismatch, n as bind, q as ProducerId, tt as StreamsyOffset, v as AppendResult, x as CreateConflict, y as CreateResult, z as ZERO_OFFSET } from "./streamsy-DiAjZWlT.js";
|
|
3
|
+
import { b as ownerParts, k as StorageOwner } from "./read-message-DP1UpEFl.js";
|
|
4
|
+
import { n as validateCreateOptions, r as frameMessages, t as frameCreateMessages } from "./create-validation-NKP81BC0.js";
|
|
5
5
|
import { t as attachOffsets } from "./read-offsets-CQ4VkAs8.js";
|
|
6
6
|
import { t as generateCursor } from "./cursor-generator-DySXZ93b.js";
|
|
7
7
|
import { Array, Clock, Context, Data, Effect, Layer, Match, Option, Predicate, Random, Result, Schema, Stream } from "effect";
|
|
@@ -17,14 +17,14 @@ const Operation = Schema.Union([
|
|
|
17
17
|
initialMessages: Schema.Array(StoredMessage),
|
|
18
18
|
forkSource: Schema.optionalKey(Schema.Struct({
|
|
19
19
|
id: StreamId,
|
|
20
|
-
liveAtOffset:
|
|
20
|
+
liveAtOffset: StreamsyOffset
|
|
21
21
|
}))
|
|
22
22
|
}),
|
|
23
23
|
Schema.TaggedStruct("Append", {
|
|
24
24
|
streamId: StreamId,
|
|
25
25
|
messages: Schema.Array(StoredMessage),
|
|
26
26
|
patch: RecordPatch,
|
|
27
|
-
expectedOffset: Schema.optionalKey(
|
|
27
|
+
expectedOffset: Schema.optionalKey(StreamsyOffset),
|
|
28
28
|
expectedClosed: Schema.optionalKey(Schema.Boolean),
|
|
29
29
|
producer: Schema.optionalKey(ProducerPrecondition)
|
|
30
30
|
}),
|
|
@@ -134,7 +134,7 @@ var ForkPlanBuilder = class {
|
|
|
134
134
|
message: `Source stream is soft-deleted: ${sourcePath}`
|
|
135
135
|
}) });
|
|
136
136
|
const forkOffset = options.forkOffset ?? source.currentOffset;
|
|
137
|
-
if (!
|
|
137
|
+
if (!isStreamsyOffset(forkOffset)) return ForkBuildResult.Rejected({ error: new InvalidForkRequest({
|
|
138
138
|
id: targetId,
|
|
139
139
|
message: "Invalid Stream-Fork-Offset format"
|
|
140
140
|
}) });
|
|
@@ -158,7 +158,7 @@ var ForkPlanBuilder = class {
|
|
|
158
158
|
const expiry = resolveForkExpiry(options, source);
|
|
159
159
|
const fork = {
|
|
160
160
|
forkedFrom: sourcePath,
|
|
161
|
-
forkOffset:
|
|
161
|
+
forkOffset: StreamsyOffset.make(forkOffset)
|
|
162
162
|
};
|
|
163
163
|
if (subOffset !== void 0 && subOffset > 0) fork.forkSubOffset = subOffset;
|
|
164
164
|
const baseRecord = this.deps.newRecord(targetId, contentType, {
|
|
@@ -177,13 +177,13 @@ var ForkPlanBuilder = class {
|
|
|
177
177
|
initialMessages,
|
|
178
178
|
forkSource: {
|
|
179
179
|
id: sourcePath,
|
|
180
|
-
liveAtOffset:
|
|
180
|
+
liveAtOffset: StreamsyOffset.make(forkOffset)
|
|
181
181
|
}
|
|
182
182
|
});
|
|
183
183
|
return ForkBuildResult.Fork({
|
|
184
184
|
plan,
|
|
185
185
|
toResult: (record) => CreateResult.Created({
|
|
186
|
-
|
|
186
|
+
offset: record.currentOffset,
|
|
187
187
|
contentType,
|
|
188
188
|
closed: record.lifecycle.closed
|
|
189
189
|
})
|
|
@@ -256,7 +256,7 @@ const touch = Effect.fn("Protocol.touch")(function* (storage, record) {
|
|
|
256
256
|
});
|
|
257
257
|
/** One host-triggered sweep; the host owns scheduling and cancellation. */
|
|
258
258
|
const expireDue = Effect.fn("Protocol.expireDue")(function* () {
|
|
259
|
-
const storage = yield*
|
|
259
|
+
const { storage } = ownerParts(yield* StorageOwner);
|
|
260
260
|
const now = yield* Clock.currentTimeMillis;
|
|
261
261
|
while (true) {
|
|
262
262
|
const deadline = yield* storage.nextExpiry;
|
|
@@ -303,7 +303,7 @@ const existingResult = Effect.fn("Protocol.existingResult")(function* (record, o
|
|
|
303
303
|
message: "Stream exists with different configuration"
|
|
304
304
|
});
|
|
305
305
|
return CreateResult.Exists({
|
|
306
|
-
|
|
306
|
+
offset: record.currentOffset,
|
|
307
307
|
contentType: record.config.contentType,
|
|
308
308
|
closed: record.lifecycle.closed
|
|
309
309
|
});
|
|
@@ -322,7 +322,7 @@ const create = Effect.fn("Protocol.create")(function* (storage, id, options = {}
|
|
|
322
322
|
const sourceId = StreamId.make(options.forkedFrom);
|
|
323
323
|
const source = yield* expireIfNeeded(storage, sourceId);
|
|
324
324
|
const after = options.forkOffset;
|
|
325
|
-
const tail = options.forkSubOffset && after &&
|
|
325
|
+
const tail = options.forkSubOffset && after && isStreamsyOffset(after) ? [...yield* storage.messages(sourceId, { after })] : void 0;
|
|
326
326
|
const built = new ForkPlanBuilder({
|
|
327
327
|
clock: { now: () => now },
|
|
328
328
|
newRecord: (target, type, opts, fork) => newRecord(target, type, opts, now, fork)
|
|
@@ -359,7 +359,7 @@ const create = Effect.fn("Protocol.create")(function* (storage, id, options = {}
|
|
|
359
359
|
return yield* storage.mutate({ operations: [plan] }).pipe(Effect.uninterruptible, Effect.map((result) => {
|
|
360
360
|
const record = result.results[0].record;
|
|
361
361
|
return CreateResult.Created({
|
|
362
|
-
|
|
362
|
+
offset: record.currentOffset,
|
|
363
363
|
contentType: record.config.contentType,
|
|
364
364
|
closed: record.lifecycle.closed
|
|
365
365
|
});
|
|
@@ -447,10 +447,12 @@ const append = Effect.fn("Protocol.append")(function* (storage, id, options) {
|
|
|
447
447
|
});
|
|
448
448
|
if (!closeOnly && !contentTypeMatches(record.config.contentType, options.contentType)) return yield* new AppendConflict({
|
|
449
449
|
id,
|
|
450
|
+
reason: "content-type",
|
|
450
451
|
message: "Content-Type mismatch"
|
|
451
452
|
});
|
|
452
453
|
if (!closeOnly && options.seq && record.lifecycle.lastSeq && options.seq <= record.lifecycle.lastSeq) return yield* new AppendConflict({
|
|
453
454
|
id,
|
|
455
|
+
reason: "sequence",
|
|
454
456
|
message: "Sequence conflict"
|
|
455
457
|
});
|
|
456
458
|
if (options.expectedOffset !== void 0 && options.expectedOffset !== record.currentOffset) return yield* new OffsetMismatch({
|
|
@@ -512,20 +514,20 @@ const head = Effect.fn("Protocol.head")(function* (storage, id) {
|
|
|
512
514
|
if (record.lifecycle.softDeleted) return yield* new StreamGone({ id });
|
|
513
515
|
return {
|
|
514
516
|
contentType: record.config.contentType,
|
|
515
|
-
|
|
517
|
+
offset: record.currentOffset,
|
|
516
518
|
ttlSeconds: record.config.ttlSeconds,
|
|
517
519
|
expiresAt: record.config.expiresAt,
|
|
518
520
|
closed: record.lifecycle.closed
|
|
519
521
|
};
|
|
520
522
|
});
|
|
521
|
-
const validateOffset = (id, offset) => offset === void 0 || offset === "-1" || offset === "now" ||
|
|
523
|
+
const validateOffset = (id, offset) => offset === void 0 || offset === "-1" || offset === "now" || isStreamsyOffset(offset) ? Effect.void : Effect.fail(new InvalidReadRequest({
|
|
522
524
|
id,
|
|
523
525
|
message: "Invalid offset format"
|
|
524
526
|
}));
|
|
525
527
|
const readRecord = Effect.fn("Protocol.readRecord")(function* (storage, record, options, limit) {
|
|
526
528
|
const from = options.offset === "now" ? record.currentOffset : options.offset;
|
|
527
529
|
const normalized = !from || from === "-1" ? void 0 : from;
|
|
528
|
-
const after = normalized === void 0 ? void 0 :
|
|
530
|
+
const after = normalized === void 0 ? void 0 : StreamsyOffset.make(normalized);
|
|
529
531
|
yield* touch(storage, record);
|
|
530
532
|
const messages = yield* storage.messages(record.id, {
|
|
531
533
|
after,
|
|
@@ -563,7 +565,7 @@ const readNext = Effect.fn("Protocol.readNext")(function* (storage, id, options,
|
|
|
563
565
|
if (Option.isNone(found)) return yield* new StreamNotFound({ id });
|
|
564
566
|
const record = found.value;
|
|
565
567
|
if (record.lifecycle.softDeleted) return yield* new StreamGone({ id });
|
|
566
|
-
const from = options.offset === "now" ? record.currentOffset :
|
|
568
|
+
const from = options.offset === "now" ? record.currentOffset : isStreamsyOffset(options.offset) ? options.offset : ZERO_OFFSET;
|
|
567
569
|
const initial = yield* readRecord(storage, record, { offset: from });
|
|
568
570
|
const cursor = Effect.gen(function* () {
|
|
569
571
|
const now = yield* Clock.currentTimeMillis;
|
|
@@ -594,7 +596,7 @@ var layer_exports = /* @__PURE__ */ __exportAll({
|
|
|
594
596
|
layer: () => layer
|
|
595
597
|
});
|
|
596
598
|
const layer = (options = {}) => Layer.effectContext(Effect.gen(function* () {
|
|
597
|
-
const storage = yield*
|
|
599
|
+
const { storage } = ownerParts(yield* StorageOwner);
|
|
598
600
|
const timeout = options.longPollTimeoutMs ?? 3e4;
|
|
599
601
|
if (!Number.isFinite(timeout) || timeout <= 0) return yield* Effect.die(/* @__PURE__ */ new RangeError("longPollTimeoutMs must be positive"));
|
|
600
602
|
const readLimit = options.readLimit ?? 1e3;
|
|
@@ -623,6 +625,6 @@ const layer = (options = {}) => Layer.effectContext(Effect.gen(function* () {
|
|
|
623
625
|
}));
|
|
624
626
|
})
|
|
625
627
|
});
|
|
626
|
-
return Context.make(StreamsReader,
|
|
628
|
+
return Context.make(StreamsReader, reader).pipe(Context.add(StreamsWriter, writer));
|
|
627
629
|
}));
|
|
628
630
|
export { MutationRejected as a, OperationResult as c, ProducerPrecondition as d, MutationApplied as i, OperationResults as l, layer_exports as n, Mutations as o, Mutation as r, Operation as s, layer as t, Operations as u };
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { a as MutationRejected, l as OperationResults, o as Mutations, u as Operations } from "./layer-
|
|
4
|
-
import {
|
|
5
|
-
import { Array, Context, Effect, Layer, Option, Order, Predicate, PubSub, Queue, Schedule, Stream } from "effect";
|
|
1
|
+
import { z as ZERO_OFFSET } from "./streamsy-DiAjZWlT.js";
|
|
2
|
+
import { D as patchRecord, E as indexDeadlines, S as makeBoundary, T as copyRecord, g as buildStorageOwner, k as StorageOwner, m as OwnerBackend, w as copyMessage } from "./read-message-DP1UpEFl.js";
|
|
3
|
+
import { a as MutationRejected, l as OperationResults, o as Mutations, u as Operations } from "./layer-DTOhxWkw.js";
|
|
4
|
+
import { Array, Effect, Layer, Option, Order, Predicate, PubSub, Queue, Schedule, Stream } from "effect";
|
|
6
5
|
// src/storage/memory/lineage.ts
|
|
7
6
|
/** Synchronous port of cascade-reclaim and chained message composition.
|
|
8
7
|
* Called only inside the memory mutation lock or synchronous read snapshot.
|
|
@@ -127,7 +126,7 @@ function reject(state, operation, index) {
|
|
|
127
126
|
if (actual?.epoch !== expected?.epoch || actual?.lastSeq !== expected?.lastSeq) return rejected("producer");
|
|
128
127
|
}
|
|
129
128
|
}
|
|
130
|
-
const layer = (options = {}) => Layer.
|
|
129
|
+
const layer = (options = {}) => Layer.effect(StorageOwner, Effect.gen(function* () {
|
|
131
130
|
const chain = !options.constrained;
|
|
132
131
|
const interval = options.pollIntervalMs ?? 25;
|
|
133
132
|
if (!Number.isFinite(interval) || interval <= 0) return yield* Effect.die(/* @__PURE__ */ new RangeError("pollIntervalMs must be positive"));
|
|
@@ -190,7 +189,7 @@ const layer = (options = {}) => Layer.effectContext(Effect.gen(function* () {
|
|
|
190
189
|
changed
|
|
191
190
|
};
|
|
192
191
|
};
|
|
193
|
-
const storage =
|
|
192
|
+
const storage = {
|
|
194
193
|
capabilities: {
|
|
195
194
|
fork: chain ? "chain" : "copy",
|
|
196
195
|
atomicScope: chain ? "store" : "stream",
|
|
@@ -217,7 +216,15 @@ const layer = (options = {}) => Layer.effectContext(Effect.gen(function* () {
|
|
|
217
216
|
changes: (id) => changes(committed, bus, id, chain, interval),
|
|
218
217
|
committed: PubSub.subscribe(feed),
|
|
219
218
|
nextExpiry: owner.access((state) => Option.fromUndefinedOr(state.deadlines[0]).pipe(Option.map((deadline) => ({ ...deadline }))))
|
|
219
|
+
};
|
|
220
|
+
return buildStorageOwner({
|
|
221
|
+
label: "memory",
|
|
222
|
+
storage,
|
|
223
|
+
records: owner.records,
|
|
224
|
+
hooks: owner.hooks,
|
|
225
|
+
marks: owner.marks,
|
|
226
|
+
backend: OwnerBackend.Memory({ enlist: owner.enlist }),
|
|
227
|
+
withTransaction: owner.withTransaction
|
|
220
228
|
});
|
|
221
|
-
return Context.make(Storage, attachOwner(storage, ownerOf(owner.boundary))).pipe(Context.add(CommitBoundary, owner.boundary), Context.add(OwnerRecords, owner.records), Context.add(CommitHooks, owner.hooks), Context.add(ProjectionMarks, owner.marks));
|
|
222
229
|
}));
|
|
223
230
|
export { layer as t };
|