@streamsy/core 0.2.1 → 0.4.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.
@@ -0,0 +1,513 @@
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-QDlssl__.js";
2
+ import { Context, Data, Duration, Effect, Layer, Option, Schedule, Schema, Stream } from "effect";
3
+ import { NonEmptyReadonlyArray } from "effect/Array";
4
+ import { HttpRouter, HttpServerRequest, HttpServerResponse } from "effect/http";
5
+ import { LazyArg } from "effect/Function";
6
+ import { SqlError } from "effect/sql/SqlError";
7
+ //#region src/http/program.d.ts
8
+ interface HttpOptions {
9
+ readonly pathPrefix?: string;
10
+ /** Lifetime of an SSE response. Default 60 seconds. */
11
+ readonly sseDeadlineMs?: number;
12
+ readonly maxMessageSize?: number;
13
+ readonly cacheVisibility?: "private" | "public";
14
+ }
15
+ /**
16
+ * The public HTTP program. It is the whole application an Effect host serves.
17
+ *
18
+ * Its success type is `HttpServerResponse` alone, its error channel is closed,
19
+ * and it requires exactly `HttpServerRequest | StreamsReader | StreamsWriter`.
20
+ * Those three facts are what let a host type it as an Alchemy `HttpEffect` and
21
+ * what let one composition serve several backends.
22
+ */
23
+ 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
+ /** Prefix helpers shared by protocol and host routers. */
27
+ declare const streamPath: (pathPrefix?: string) => {
28
+ requiredPathPattern: () => string;
29
+ strip: (pathname: string) => string;
30
+ canonicalizeForkSource: (source: string) => string;
31
+ };
32
+ 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 };
34
+ }
35
+ /** Omit `offset` and `txid` rather than setting them to `undefined`. */
36
+ interface StateHeaders {
37
+ readonly operation: "upsert" | "delete";
38
+ readonly offset?: string;
39
+ readonly txid?: string;
40
+ readonly timestamp?: string;
41
+ readonly from?: string;
42
+ }
43
+ interface StateUpsert<A, Type extends string = string> {
44
+ readonly type: Type;
45
+ readonly key: string;
46
+ readonly value: A;
47
+ readonly headers: StateHeaders & {
48
+ readonly operation: "upsert";
49
+ };
50
+ }
51
+ interface StateDelete<A, Type extends string = string> {
52
+ readonly type: Type;
53
+ readonly key: string;
54
+ readonly old_value?: A;
55
+ readonly headers: StateHeaders & {
56
+ readonly operation: "delete";
57
+ };
58
+ }
59
+ /** A change event consumed by `@durable-streams/state`, narrowed by its `type`. */
60
+ type StateChange<A, Type extends string = string> = StateUpsert<A, Type> | StateDelete<A, Type>;
61
+ type StateEncodedChange<A, Type extends string = string> = (Omit<StateUpsert<A, Type>, "headers"> & {
62
+ readonly headers: Omit<StateHeaders, "operation"> & {
63
+ readonly operation: "insert" | "update" | "upsert";
64
+ };
65
+ }) | StateDelete<A, Type>;
66
+ /** The value fields that may serve as a Durable State key. */
67
+ type StateKey<A> = { [K in keyof A]-?: A[K] extends string | number ? K : never; }[keyof A];
68
+ /** One collection of a Durable State stream: its value schema and the value field used as the key. */
69
+ interface Collection<A, I, RD, RE, Key extends StateKey<A> = StateKey<A>> {
70
+ readonly schema: Schema.Codec<A, I, RD, RE>;
71
+ readonly key: Key;
72
+ }
73
+ /** Collections keyed by the `type` that names them on the wire. */
74
+ type Collections = Record<string, Collection<any, any, any, any, any>>;
75
+ /**
76
+ * Each `key` must name a string or number field of its own collection's value.
77
+ * A mismatch reports on the `key` property of the offending collection.
78
+ */
79
+ type ValidCollections<C extends Collections> = { readonly [K in keyof C]: C[K]["key"] extends StateKey<C[K]["schema"]["Type"]> ? C[K] : {
80
+ readonly key: StateKey<C[K]["schema"]["Type"]>;
81
+ }; };
82
+ /** The union of change events across every collection, discriminated by `type`. */
83
+ type CollectionsChange<C extends Collections> = { [K in keyof C & string]: StateChange<C[K]["schema"]["Type"], K>; }[keyof C & string];
84
+ type CollectionsEncodedChange<C extends Collections> = { [K in keyof C & string]: StateEncodedChange<C[K]["schema"]["Encoded"], K>; }[keyof C & string];
85
+ type CollectionsDecodingServices<C extends Collections> = C[keyof C]["schema"]["DecodingServices"];
86
+ type CollectionsEncodingServices<C extends Collections> = C[keyof C]["schema"]["EncodingServices"];
87
+ /** Inert identity and codec. Constructing an address acquires no service or resource. */
88
+ interface StreamAddress<A, RD = never, RE = never> {
89
+ readonly _tag: "Json" | "Bytes";
90
+ readonly id: StreamId;
91
+ readonly contentType: string;
92
+ readonly codec: Schema.Codec<A, string | Uint8Array, RD, RE>;
93
+ }
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<CollectionsChange<C>, RD, RE> {
96
+ readonly collections: C;
97
+ }
98
+ declare function json$2<A, I, RD, RE>(id: string, options: {
99
+ readonly schema: Schema.Codec<A, I, RD, RE>;
100
+ }): StreamAddress<A, RD, RE>;
101
+ /**
102
+ * A codec for the upsert and delete change events of one collection.
103
+ * `state` composes one of these per collection. Omit optional headers instead
104
+ * of setting them to `undefined`.
105
+ */
106
+ declare function stateChange<A, I, RD, RE, const Type extends string>(options: {
107
+ readonly schema: Schema.Codec<A, I, RD, RE>;
108
+ readonly type: Type;
109
+ }): Schema.Codec<StateChange<A, Type>, StateEncodedChange<I, Type>, RD, RE>;
110
+ /**
111
+ * A stream of Durable State change events for several collections. Each record
112
+ * key is the `type` on the wire; each entry gives the value schema and the value
113
+ * field that becomes the event `key`.
114
+ */
115
+ declare function state$2<const C extends Collections>(id: string, options: {
116
+ readonly collections: C & ValidCollections<C>;
117
+ }): StateAddress<C>;
118
+ /** Items from one bytes append are joined into one stored message. */
119
+ declare function bytes$2(id: string, options?: {
120
+ readonly contentType?: string;
121
+ }): StreamAddress<Uint8Array>;
122
+ declare namespace route_d_exports {
123
+ export { ExactTemplateParams, Matcher, ParamCodecs, Params, PathSchema, StateRoute, StreamRoute, bytes$1 as bytes, custom$1 as custom, json$1 as json, state$1 as state };
124
+ }
125
+ /**
126
+ * Inert id stream. Constructing a route acquires no service and no resource.
127
+ *
128
+ * A route owns one id grammar and the address constructor for its addresses. A stream
129
+ * binds the route to a storage graph, and `Placement.byRoute` picks the Durable
130
+ * Object that owns it.
131
+ */
132
+ interface StreamRoute<RouteParams, A, RD = never, RE = never, Template extends string = string> {
133
+ readonly _tag: "StreamRoute";
134
+ /** Relative template, for example `journal/:user`. Empty for a custom route. */
135
+ readonly template: Template;
136
+ readonly paramSchema?: PathSchema<RouteParams>;
137
+ /** The router-facing contract. True when this route owns the id. */
138
+ readonly match: (id: string) => boolean;
139
+ /** The primitive. `None` when the id does not match or a parameter fails to decode. */
140
+ readonly parse: (id: string) => Option.Option<RouteParams>;
141
+ /** Build the address. `parse(address(params).id)` must be `Some(params)`. */
142
+ readonly address: (params: RouteParams) => StreamAddress<A, RD, RE>;
143
+ }
144
+ /** The stream codecs exposed to HTTP path decoding. */
145
+ type PathSchema<P> = Schema.Codec<P, Readonly<Record<string, string | undefined>>>;
146
+ type WithPathSchema<P> = {
147
+ readonly paramSchema: PathSchema<P>;
148
+ };
149
+ /** A route whose address refs retain their declared State collections. */
150
+ type StateRoute<P, C extends Collections, Template extends string = string> = Omit<StreamRoute<P, CollectionsChange<C>, CollectionsDecodingServices<C>, CollectionsEncodingServices<C>, Template>, "address"> & {
151
+ readonly collections: C;
152
+ readonly address: (params: P) => StateAddress<C>;
153
+ };
154
+ /** The route predicate used by stream validation and HTTP dispatch. */
155
+ interface Matcher {
156
+ readonly match: (id: string) => boolean;
157
+ }
158
+ /** One codec per template parameter. Decoding runs from a string with no services. */
159
+ type ParamCodecs = Readonly<Record<string, Schema.Codec<unknown, string>>>;
160
+ type Params<Codecs extends ParamCodecs> = { readonly [Name in keyof Codecs]: Codecs[Name]["Type"]; };
161
+ type TemplateNames<Template extends string> = Template extends `${string}:${infer Name}/${infer Rest}` ? Name | TemplateNames<Rest> : Template extends `${string}:${infer Name}` ? Name : never;
162
+ /** Every `:name` must have a codec, and every codec must appear in the template. */
163
+ type ExactTemplateParams<Template extends string, Codecs extends ParamCodecs> = string extends Template ? unknown : Exclude<TemplateNames<Template>, keyof Codecs> extends never ? Exclude<keyof Codecs, TemplateNames<Template>> extends never ? unknown : never : never;
164
+ declare function json$1<const Template extends string, Codecs extends ParamCodecs, A, I, RD, RE>(template: Template, options: {
165
+ readonly params: Codecs & ExactTemplateParams<Template, Codecs>;
166
+ readonly schema: Schema.Codec<A, I, RD, RE>;
167
+ }): StreamRoute<Params<Codecs>, A, RD, RE, Template> & WithPathSchema<Params<Codecs>>;
168
+ declare function state$1<const Template extends string, Codecs extends ParamCodecs, const C extends Collections>(template: Template, options: {
169
+ readonly params: Codecs & ExactTemplateParams<Template, Codecs>;
170
+ readonly collections: C & ValidCollections<C>;
171
+ }): StateRoute<Params<Codecs>, C, Template> & WithPathSchema<Params<Codecs>>;
172
+ declare function bytes$1<const Template extends string, Codecs extends ParamCodecs>(template: Template, options: {
173
+ readonly params: Codecs & ExactTemplateParams<Template, Codecs>;
174
+ readonly contentType?: string;
175
+ }): StreamRoute<Params<Codecs>, Uint8Array, never, never, Template> & WithPathSchema<Params<Codecs>>;
176
+ /** Escape hatch for a grammar a template cannot express, such as a regex stream. */
177
+ declare function custom$1<RouteParams, A, RD, RE>(options: {
178
+ readonly parse: (id: string) => Option.Option<RouteParams>;
179
+ readonly address: (params: RouteParams) => StreamAddress<A, RD, RE>;
180
+ }): StreamRoute<RouteParams, A, RD, RE>;
181
+ //#endregion
182
+ //#region src/offset/index.d.ts
183
+ declare const ZERO_OFFSET: string & import("effect/Brand").Brand<"Offset">;
184
+ declare const compare: (a: string, b: string) => number;
185
+ //#endregion
186
+ //#region src/storage/commit-boundary.d.ts
187
+ interface CommitBoundaryApi {
188
+ /**
189
+ * Run `body` in the storage owner's transaction. A nested call joins the outer
190
+ * transaction (no savepoints), so a failure must escape the outer body to roll back.
191
+ * Stream writes, owner records and, on SQL hosts, application SQL in `body` commit
192
+ * together. Keep the body on the calling fiber, and do not wait in it for wakes that
193
+ * only its own commit publishes. Only SQL hosts fail with `SqlError`.
194
+ */
195
+ readonly withTransaction: <A, E, R>(body: Effect.Effect<A, E, R>) => Effect.Effect<A, E | SqlError, R>;
196
+ }
197
+ declare const CommitBoundary_base: Context.ServiceClass<CommitBoundary, "@streamsy/core/CommitBoundary", CommitBoundaryApi>;
198
+ /** The transaction of the storage owner. Every Streamsy storage host provides it. */
199
+ declare class CommitBoundary extends CommitBoundary_base {}
200
+ //#endregion
201
+ //#region src/protocol/expiry.d.ts
202
+ /** One host-triggered sweep; the host owns scheduling and cancellation. */
203
+ declare const expireDue: () => Effect.Effect<void, StorageFault, Storage>;
204
+ declare namespace layer_d_exports {
205
+ export { ProtocolOptions, bind, expireDue, layer$1 as layer };
206
+ }
207
+ interface ProtocolOptions {
208
+ /** Maximum messages per catch-up page; live reads return the whole tail. Default 1000. */
209
+ readonly readLimit?: number;
210
+ readonly longPollTimeoutMs?: number;
211
+ }
212
+ declare const layer$1: (options?: ProtocolOptions) => Layer.Layer<StreamsReader | StreamsWriter, never, Storage>;
213
+ //#endregion
214
+ //#region src/storage/memory/layer.d.ts
215
+ interface MemoryOptions {
216
+ readonly constrained?: boolean;
217
+ readonly pollIntervalMs?: number;
218
+ }
219
+ declare namespace streams_d_exports$1 {
220
+ export { Options, layer, layerProtocol };
221
+ }
222
+ /** Options for `layer` and `layerProtocol`. */
223
+ interface Options extends MemoryOptions, ProtocolOptions {}
224
+ /** Generic reader and writer over memory storage, for protocol tools. */
225
+ declare const layerProtocol: (options?: Options) => Layer.Layer<CommitBoundary | OwnerRecords | Storage | StreamsReader | StreamsWriter, never, never>;
226
+ /** Memory host. Streams and their feeds share the exposed storage boundary. */
227
+ declare function layer<const Keys extends ReadonlyArray<Any>>(group: Group<Keys>, options?: Options): Layer.Layer<Storage | CommitBoundary | OwnerRecords | Host<Group<Keys>>>;
228
+ declare namespace durable_state_d_exports {
229
+ export { Change, ChangeHeaders, Delete, Upsert, changes, remove$1 as remove, upsert };
230
+ }
231
+ interface ChangeHeaders {
232
+ readonly txid?: string;
233
+ readonly timestamp?: string;
234
+ readonly from?: string;
235
+ }
236
+ type Operation<A, Type extends string> = Data.TaggedEnum<{
237
+ Upsert: {
238
+ readonly type: Type;
239
+ readonly value: A;
240
+ readonly headers?: ChangeHeaders;
241
+ };
242
+ Delete: {
243
+ readonly type: Type;
244
+ readonly key: string | number;
245
+ readonly oldValue?: A;
246
+ readonly headers?: ChangeHeaders;
247
+ };
248
+ }>;
249
+ type Upsert<A, Type extends string = string> = Data.TaggedEnum.Value<Operation<A, Type>, "Upsert">;
250
+ type Delete<A, Type extends string = string> = Data.TaggedEnum.Value<Operation<A, Type>, "Delete">;
251
+ /** A pending change for one of the collections in `C`. */
252
+ 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];
253
+ /** Describe an upsert into a collection. The key is read from the value. */
254
+ declare const upsert: <const Type extends string, A>(type: Type, value: A, options?: {
255
+ readonly headers?: ChangeHeaders;
256
+ }) => Upsert<A, Type>;
257
+ /** Describe a delete from a collection by key. An `oldValue` is written as `old_value`. */
258
+ declare const remove$1: <const Type extends string, A = never>(type: Type, key: string | number, options?: {
259
+ readonly oldValue?: A;
260
+ readonly headers?: ChangeHeaders;
261
+ }) => Delete<NoInfer<A>, Type>;
262
+ /**
263
+ * 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>`.
265
+ */
266
+ declare function changes<C extends Collections, RD, RE>(address: StateAddress<C, RD, RE>, options: {
267
+ readonly offset?: string;
268
+ }, entries: NonEmptyReadonlyArray<Change<C>>): NonEmptyReadonlyArray<CollectionsChange<C>>;
269
+ declare function changes<C extends Collections, RD, RE>(address: StateAddress<C, RD, RE>, options: {
270
+ readonly offset?: string;
271
+ }, entries: ReadonlyArray<Change<C>>): ReadonlyArray<CollectionsChange<C>>;
272
+ declare namespace producer_d_exports {
273
+ export { Position, next };
274
+ }
275
+ type Position = ProducerOptions;
276
+ /** Advance only after the caller has acknowledged appended or duplicate. Persist this tuple at the owning edge. */
277
+ declare const next: (position: Position) => Position;
278
+ declare namespace streamsy_d_exports {
279
+ export { Address, Any, Api, BytesClass, Class, CustomClass, Group, Host, JsonClass, Services, StateClass, Wildcard, bytes, custom, group, json, state };
280
+ }
281
+ declare namespace streams_d_exports {
282
+ 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 };
283
+ }
284
+ /** Full toolkit failures, including protocol rejections and infrastructure faults. */
285
+ type ReadFailure = StreamNotFound | StreamGone | InvalidReadRequest | StreamsFault | DecodeFault;
286
+ type FollowFailure = ReadFailure | NotSupported;
287
+ type AppendFailure<O = AppendCallOptions> = AppendErrorFor<O> | StreamsFault | EncodeFault;
288
+ type CreateFailure = CreateError | StreamsFault;
289
+ type HeadFailure = HeadError | StreamsFault;
290
+ type RemoveFailure = RemoveError | StreamsFault;
291
+ interface Batch<A> {
292
+ readonly items: ReadonlyArray<A>;
293
+ readonly nextOffset: string;
294
+ readonly upToDate: boolean;
295
+ readonly closed: boolean;
296
+ }
297
+ declare const create: <A, RD, RE>(address: StreamAddress<A, RD, RE>, options?: Omit<CreateOptions, "contentType"> | undefined) => Effect.Effect<CreateResult, CreateFailure, StreamsWriter>;
298
+ /**
299
+ * The items one append takes. An append carries at least one item, unless it
300
+ * closes the stream. Caller-bug rejections from a host are defects.
301
+ */
302
+ type AppendItems<A, O> = O extends {
303
+ readonly close: true;
304
+ } ? ReadonlyArray<A> : NonEmptyReadonlyArray<A>;
305
+ /**
306
+ * Append items to one stream. The error type lists only the rejections that the
307
+ * options make possible; a host that answers another one dies.
308
+ */
309
+ declare const append: <A, RD, RE, const O extends AppendCallOptions = {}>(address: StreamAddress<A, RD, RE>, items: AppendItems<A, O>, options?: O | undefined) => Effect.Effect<AppendResult, AppendFailure<O>, RE | StreamsWriter>;
310
+ declare function read$1<A, RD, RE>(address: StreamAddress<A, RD, RE>, options?: ReadOptions$1): Stream.Stream<Batch<A>, ReadFailure, StreamsReader | RD>;
311
+ /** A folded value and the tail it was read up to. `offset` is this stream's CAS token. */
312
+ interface Folded<S> {
313
+ readonly state: S;
314
+ readonly offset: string;
315
+ }
316
+ /** Every item read and the tail they were read up to. */
317
+ interface Collected<A> {
318
+ readonly items: ReadonlyArray<A>;
319
+ readonly offset: string;
320
+ }
321
+ /**
322
+ * Read the stream up to its tail and fold every item into one value. Pass
323
+ * `options.offset` to fold on from a tail that an earlier fold returned.
324
+ */
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>;
326
+ /** Read the stream up to its tail and return its items. */
327
+ declare const collect: <A, RD, RE>(address: StreamAddress<A, RD, RE>, options?: ReadOptions$1 | undefined) => Effect.Effect<Collected<A>, ReadFailure, RD | StreamsReader>;
328
+ /** What one `decide` step answers: a value, and the items to append for it. */
329
+ interface Decision<B, A> {
330
+ readonly value: B;
331
+ /** Items to append. Empty means "no write": the call returns without a tail check. */
332
+ readonly items: ReadonlyArray<A>;
333
+ }
334
+ /** The result of a read, decide, append loop. */
335
+ interface Decided<B> {
336
+ readonly value: B;
337
+ /** The new tail after a write, or the tail that was read when there was no write. */
338
+ readonly offset: string;
339
+ readonly appended: boolean;
340
+ }
341
+ interface DecideSpec<A, S, B, E, R> {
342
+ /** The start value of the fold. Each call starts from a new value. */
343
+ readonly initial: LazyArg<S>;
344
+ readonly fold: (state: S, item: A) => S;
345
+ /**
346
+ * Decide what to append from the folded state. `offset` is the tail the state is
347
+ * at; the append checks it. This step must not write and must not change
348
+ * `state`: a retry folds on from the same state after a lost race.
349
+ */
350
+ readonly decide: (state: S, at: {
351
+ readonly offset: string;
352
+ }) => Effect.Effect<Decision<B, NoInfer<A>>, E, R>;
353
+ /** Retries after `OffsetMismatch`. Default: `Schedule.recurs(3)`. Nothing else is retried. */
354
+ readonly retry?: Schedule.Schedule<unknown, OffsetMismatch>;
355
+ }
356
+ /**
357
+ * Read, decide, append. Fold the stream to its tail, decide from the state, and
358
+ * append with `expectedOffset` set to the tail that was read. After an
359
+ * `OffsetMismatch`, fold on from that tail and decide again while `retry` allows;
360
+ * then fail with the last `OffsetMismatch`. Transport faults are not retried: a
361
+ * lost reply may hide an append that landed.
362
+ */
363
+ declare const decide: <A, RD, RE, S, B, E, R>(address: StreamAddress<A, RD, RE>, spec: DecideSpec<A, S, B, E, R>) => Effect.Effect<Decided<B>, E | AppendConflict | DecodeFault | EncodeFault | InvalidReadRequest | NotSupported | OffsetMismatch | StorageFault | StreamBusy | StreamClosed | StreamGone | StreamNotFound | TransportFault, R | RD | RE | StreamsReader | StreamsWriter>;
364
+ interface FollowOptions extends ReadOptions$1 {
365
+ /**
366
+ * Schedule for retrying a failed read after a retryable `TransportFault` or `StorageFault`.
367
+ * Default: exponential from 200 ms, jittered, capped at 30 s, forever. Other
368
+ * failures end the stream at once.
369
+ */
370
+ readonly retry?: Schedule.Schedule<unknown>;
371
+ }
372
+ /**
373
+ * Catch up, then wait one readNext at a time, filtering empty open batches.
374
+ * A read that fails with a retryable transport or storage fault is retried from the same
375
+ * offset, so a restart or network drop yields each item once.
376
+ */
377
+ declare function follow<A, RD, RE>(address: StreamAddress<A, RD, RE>, options?: FollowOptions): Stream.Stream<Batch<A>, FollowFailure, StreamsReader | RD>;
378
+ declare const items: <A, E, R>(batches: Stream.Stream<Batch<A>, E, R>) => Stream.Stream<A, E, R>;
379
+ declare const session: <A, RD, RE>(address: StreamAddress<A, RD, RE>, options: ReadNextOptions) => Effect.Effect<ReadNextResult, StorageFault | TransportFault | ReadNextError, StreamsReader>;
380
+ declare const head: <A, RD, RE>(address: StreamAddress<A, RD, RE>) => Effect.Effect<HeadResult, HeadFailure, StreamsReader>;
381
+ 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
+ /** A stream service with named failures for each toolkit call. */
385
+ interface Api<P, A, RD = never, RE = never> {
386
+ readonly owner: object;
387
+ readonly route: StreamRoute<P, A, RD, RE>;
388
+ readonly wire: Reader<StreamsFault> & Writer<StreamsFault>;
389
+ readonly create: (params: P, options?: Omit<CreateOptions, "contentType">) => Effect.Effect<CreateResult, CreateFailure>;
390
+ readonly append: <const O extends AppendCallOptions = {}>(params: P, items: AppendItems<A, O>, options?: O) => Effect.Effect<AppendResult, AppendFailure<O>, RE>;
391
+ 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>;
393
+ readonly collect: (params: P, options?: ReadOptions$1) => Effect.Effect<Collected<A>, ReadFailure, RD>;
394
+ readonly decide: <S, B, E, R>(params: P, spec: DecideSpec<A, S, B, E, R>) => Effect.Effect<Decided<B>, ReadFailure | AppendFailure<{
395
+ expectedOffset: string;
396
+ }> | E, RD | RE | R>;
397
+ readonly follow: (params: P, options?: FollowOptions) => Stream.Stream<Batch<A>, FollowFailure, RD>;
398
+ readonly session: (params: P, options: ReadNextOptions) => Effect.Effect<ReadNextResult, Exclude<FollowFailure, DecodeFault>>;
399
+ readonly head: (params: P) => Effect.Effect<HeadResult, HeadFailure>;
400
+ readonly remove: (params: P) => Effect.Effect<void, RemoveFailure>;
401
+ readonly fork: (params: P, source: P, options?: Omit<CreateOptions, "contentType" | "forkedFrom">) => Effect.Effect<CreateResult, CreateFailure>;
402
+ }
403
+ /** An address names one stream. It holds no data. It is not an Effect `Ref`. */
404
+ type Address<A, R, RD = never, RE = never> = StreamAddress<A, RD, RE> & {
405
+ readonly stream: Context.Key<R, {
406
+ readonly owner: object;
407
+ readonly wire: Reader<StreamsFault> & Writer<StreamsFault>;
408
+ }>;
409
+ };
410
+ type Class<Self, Name extends string, P, A, RD, RE, R extends StreamRoute<P, A, RD, RE>> = Context.ServiceClass<Self, `@streamsy/core/Stream/${Name}`, Api<P, A, RD, RE>> & R & {
411
+ readonly at: (params: P) => ReturnType<R["address"]> & Address<A, Self, RD, RE>;
412
+ };
413
+ 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
+ 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>, CollectionsChange<Collections$1>, CollectionsDecodingServices<Collections$1>, CollectionsEncodingServices<Collections$1>, ReturnType<typeof state$1<T, C, Collections$1>>>;
416
+ 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
+ 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
+ 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>;
419
+ type CustomClass<Self, Name extends string, P, A, RD, RE> = Class<Self, Name, P, A, RD, RE, ReturnType<typeof custom$1<P, A, RD, RE>>>;
420
+ declare const custom: <Self>() => <const Name extends string, P, A, RD, RE>(name: Name, options: Parameters<typeof custom$1<P, A, RD, RE>>[0]) => CustomClass<Self, Name, P, A, RD, RE>;
421
+ declare const Wildcard_base: Class<Wildcard, "Wildcard", {
422
+ id: string;
423
+ }, Uint8Array<ArrayBufferLike>, never, never, StreamRoute<{
424
+ id: string;
425
+ }, Uint8Array<ArrayBufferLike>, never, never, string>>;
426
+ declare class Wildcard extends Wildcard_base {}
427
+ /** Class instances carry Effect's service marker; individual Self types remain on each key. */
428
+ interface StreamIdentifier {
429
+ readonly [Context.ServiceTypeId]: typeof Context.ServiceTypeId;
430
+ }
431
+ /** The provider and HTTP boundary need only the wire and the route grammar. */
432
+ interface Any extends Context.Key<StreamIdentifier, {
433
+ readonly owner: object;
434
+ readonly wire: Reader<StreamsFault> & Writer<StreamsFault>;
435
+ }> {
436
+ readonly template: string;
437
+ readonly match: (id: string) => boolean;
438
+ }
439
+ type Identifiers<Keys extends ReadonlyArray<Any>> = Keys[number]["Identifier"];
440
+ /** Bind streams to their owning protocol graph. */
441
+ declare function bind<A, E, R, const Keys extends ReadonlyArray<Any>>(graph: Layer.Layer<A | StreamsReader | StreamsWriter, E, R>, streams: Group<Keys>): Layer.Layer<Identifiers<Keys>, E, R>;
442
+ interface Group<Keys extends ReadonlyArray<Any> = ReadonlyArray<Any>> {
443
+ readonly streams: Keys;
444
+ }
445
+ type Services<G extends Group> = G["streams"][number]["Identifier"];
446
+ /** What every host Layer gives for a group: its stream services. */
447
+ type Host<G extends Group> = Services<G>;
448
+ declare function group<const Keys extends ReadonlyArray<Any>>(...keys: Keys): Group<Keys>;
449
+ //#endregion
450
+ //#region src/http/routes.d.ts
451
+ type RouteLayer<R> = Layer.Layer<never, never, HttpRouter.HttpRouter | HttpRouter.Request.From<"Requires", Exclude<R, HttpRouter.Provided>>>;
452
+ interface Access<S extends Any = Any> {
453
+ readonly stream: S;
454
+ /** append permits POST; full also permits PUT and DELETE. */
455
+ readonly access: "read" | "append" | "full";
456
+ }
457
+ interface RoutesOptions extends Omit<HttpOptions, "pathPrefix"> {
458
+ readonly prefix?: `/${string}`;
459
+ readonly access: Access["access"] | ((stream: Any) => Access["access"]);
460
+ }
461
+ /** One prefix controls both route registration and protocol path stripping. */
462
+ 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
+ interface ReadOptions {
466
+ readonly sseDeadlineMs?: number;
467
+ readonly cacheVisibility?: "private" | "public";
468
+ }
469
+ /** @internal Shared construction-time validation for HTTP read routes. */
470
+ declare function checkReadOptions(options: ReadOptions): void;
471
+ /** Read an already resolved id using the protocol's HTTP framing and live modes. */
472
+ 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
+ /** Shared protocol and host security headers. */
476
+ declare const securityHeaders: Readonly<{
477
+ "x-content-type-options": "nosniff";
478
+ "cross-origin-resource-policy": "cross-origin";
479
+ }>;
480
+ //#endregion
481
+ //#region src/http/shutdown-signal.d.ts
482
+ /**
483
+ * Tells live HTTP reads that the host is about to stop. A parked long poll then
484
+ * answers `204` with its offset and cursor, and an open SSE body ends after its
485
+ * last whole batch. Clients take their normal reconnect path.
486
+ *
487
+ * The service is optional. Live reads look it up with `Effect.serviceOption`, so
488
+ * a host without it (for example the Durable Object host) keeps its behaviour.
489
+ */
490
+ interface ShutdownSignalService {
491
+ /** Completes when the host starts to drain; never fails. */
492
+ readonly draining: Effect.Effect<void>;
493
+ /** Counts a live read while `effect` runs. */
494
+ readonly track: <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
495
+ /** Counts a live read while `stream` runs. */
496
+ readonly trackStream: <A, E, R>(stream: Stream.Stream<A, E, R>) => Stream.Stream<A, E, R>;
497
+ /**
498
+ * Starts the drain, then waits until no live read is running or `timeout`
499
+ * passes. Safe to call more than once.
500
+ */
501
+ readonly drain: (timeout: Duration.Input) => Effect.Effect<void>;
502
+ /** The number of live reads now running. */
503
+ readonly active: Effect.Effect<number>;
504
+ }
505
+ declare const ShutdownSignal_base: Context.ServiceClass<ShutdownSignal, "@streamsy/core/ShutdownSignal", ShutdownSignalService>;
506
+ declare class ShutdownSignal extends ShutdownSignal_base {}
507
+ /** A fresh signal. Provide it to the routes and call `drain` before they close. */
508
+ declare const layerShutdownSignal: Layer.Layer<ShutdownSignal, never, never>;
509
+ declare namespace index_d_exports {
510
+ export { Access, HttpOptions, ReadOptions, RoutesOptions, ShutdownSignal, ShutdownSignalService, app, checkReadOptions, layerShutdownSignal, read, routes, securityHeaders, streamPath };
511
+ }
512
+ //#endregion
513
+ 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 };