@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.
@@ -1,9 +1,8 @@
1
- import { Context, Data, Effect, Option, PubSub, Schema, Scope, Stream } from "effect";
2
- import { SqlError } from "effect/sql";
1
+ import { Array, Brand, Context, Data, Effect, Option, PubSub, Schema, Scope, Stream } from "effect";
3
2
  declare const StorageFault_base: Schema.Class<StorageFault, Schema.TaggedStruct<"StorageFault", {
4
3
  readonly operation: Schema.String;
5
4
  readonly message: Schema.String;
6
- readonly retryable: Schema.Boolean;
5
+ readonly isRetryable: Schema.Boolean;
7
6
  readonly cause: Schema.optionalKey<Schema.Defect>;
8
7
  }>, import("effect/Cause").YieldableError>;
9
8
  declare class StorageFault extends StorageFault_base {}
@@ -17,6 +16,16 @@ declare const DecodeFault_base: Schema.Class<DecodeFault, Schema.TaggedStruct<"D
17
16
  readonly cause: Schema.optionalKey<Schema.Defect>;
18
17
  }>, import("effect/Cause").YieldableError>;
19
18
  declare class DecodeFault extends DecodeFault_base {}
19
+ declare const InvalidStreamParams_base: Schema.Class<InvalidStreamParams, Schema.TaggedStruct<"InvalidStreamParams", {
20
+ readonly stream: Schema.String;
21
+ readonly parameter: Schema.String;
22
+ readonly message: Schema.String;
23
+ }>, import("effect/Cause").YieldableError>;
24
+ /**
25
+ * A stream param value cannot form a stream id, for example a value that contains `/` or is
26
+ * empty. `stream` is the route template and `parameter` names the param.
27
+ */
28
+ declare class InvalidStreamParams extends InvalidStreamParams_base {}
20
29
  declare const TransportFault_base: Schema.Class<TransportFault, Schema.TaggedStruct<"TransportFault", {
21
30
  readonly operation: Schema.String;
22
31
  readonly reason: Schema.Literals<readonly ["request", "response", "decode", "configuration"]>;
@@ -28,16 +37,25 @@ declare const TransportFault_base: Schema.Class<TransportFault, Schema.TaggedStr
28
37
  /** Failures of the remote boundary; protocol rejections have their own typed errors. */
29
38
  declare class TransportFault extends TransportFault_base {
30
39
  /** Failed requests, 429s and 5xx responses can succeed later. */
31
- get retryable(): boolean;
40
+ get isRetryable(): boolean;
32
41
  }
33
42
  declare const StreamsFault: Schema.Union<readonly [typeof StorageFault, typeof TransportFault]>;
34
43
  type StreamsFault = typeof StreamsFault.Type;
35
44
  /** A storage or transport failure, as opposed to a protocol rejection. */
36
45
  declare const isStreamsFault: <I>(input: I) => input is I & (StorageFault | TransportFault);
37
- /** A storage or transport failure that can succeed later. */
38
- declare const isRetryableFault: (error: unknown) => error is StreamsFault;
46
+ /**
47
+ * True for an error that can succeed later: any error with a boolean `isRetryable` that is
48
+ * `true`, such as a `StorageFault`, a `TransportFault` or a `ProjectionFault`.
49
+ */
50
+ declare const isRetryableFault: (error: unknown) => boolean;
39
51
  declare const StreamId: Schema.brand<Schema.String, "StreamId">;
52
+ /**
53
+ * A position in a stream, as any Durable Streams server issues it. Offsets are opaque: compare
54
+ * them, but do not parse them. The read sentinels `-1` and `now` are not offsets.
55
+ */
40
56
  declare const Offset: Schema.brand<Schema.String, "Offset">;
57
+ /** The offset format that Streamsy storage issues. Every `StreamsyOffset` is an `Offset`. */
58
+ declare const StreamsyOffset: Schema.brand<Schema.brand<Schema.String, "Offset">, "StreamsyOffset">;
41
59
  declare const ProducerId: Schema.brand<Schema.String, "ProducerId">;
42
60
  declare const StreamConfig: Schema.Struct<{
43
61
  readonly contentType: Schema.String;
@@ -50,7 +68,7 @@ declare const StreamLifecycle: Schema.Struct<{
50
68
  readonly closed: Schema.Boolean;
51
69
  readonly closedAt: Schema.optionalKey<Schema.Finite>;
52
70
  readonly forkedFrom: Schema.optionalKey<Schema.brand<Schema.String, "StreamId">>;
53
- readonly forkOffset: Schema.optionalKey<Schema.brand<Schema.String, "Offset">>;
71
+ readonly forkOffset: Schema.optionalKey<Schema.brand<Schema.brand<Schema.String, "Offset">, "StreamsyOffset">>;
54
72
  readonly forkSubOffset: Schema.optionalKey<Schema.Finite>;
55
73
  readonly softDeleted: Schema.Boolean;
56
74
  readonly expiresAtMs: Schema.optionalKey<Schema.Finite>;
@@ -68,15 +86,15 @@ declare const StreamRecord: Schema.Struct<{
68
86
  readonly closed: Schema.Boolean;
69
87
  readonly closedAt: Schema.optionalKey<Schema.Finite>;
70
88
  readonly forkedFrom: Schema.optionalKey<Schema.brand<Schema.String, "StreamId">>;
71
- readonly forkOffset: Schema.optionalKey<Schema.brand<Schema.String, "Offset">>;
89
+ readonly forkOffset: Schema.optionalKey<Schema.brand<Schema.brand<Schema.String, "Offset">, "StreamsyOffset">>;
72
90
  readonly forkSubOffset: Schema.optionalKey<Schema.Finite>;
73
91
  readonly softDeleted: Schema.Boolean;
74
92
  readonly expiresAtMs: Schema.optionalKey<Schema.Finite>;
75
93
  }>;
76
- readonly currentOffset: Schema.brand<Schema.String, "Offset">;
94
+ readonly currentOffset: Schema.brand<Schema.brand<Schema.String, "Offset">, "StreamsyOffset">;
77
95
  }>;
78
96
  declare const StoredMessage: Schema.Struct<{
79
- readonly offset: Schema.brand<Schema.String, "Offset">;
97
+ readonly offset: Schema.brand<Schema.brand<Schema.String, "Offset">, "StreamsyOffset">;
80
98
  readonly timestamp: Schema.Finite;
81
99
  readonly data: Schema.Uint8Array;
82
100
  }>;
@@ -85,18 +103,19 @@ declare const ProducerState: Schema.Struct<{
85
103
  readonly lastSeq: Schema.Finite;
86
104
  }>;
87
105
  declare const MessageWindow: Schema.Struct<{
88
- readonly after: Schema.optionalKey<Schema.brand<Schema.String, "Offset">>;
89
- readonly until: Schema.optionalKey<Schema.brand<Schema.String, "Offset">>;
106
+ readonly after: Schema.optionalKey<Schema.brand<Schema.brand<Schema.String, "Offset">, "StreamsyOffset">>;
107
+ readonly until: Schema.optionalKey<Schema.brand<Schema.brand<Schema.String, "Offset">, "StreamsyOffset">>;
90
108
  readonly limit: Schema.optionalKey<Schema.Finite>;
91
109
  }>;
92
110
  declare const ChangeSnapshot: Schema.Struct<{
93
111
  readonly present: Schema.Boolean;
94
- readonly currentOffset: Schema.brand<Schema.String, "Offset">;
112
+ readonly currentOffset: Schema.brand<Schema.brand<Schema.String, "Offset">, "StreamsyOffset">;
95
113
  readonly closed: Schema.Boolean;
96
114
  readonly softDeleted: Schema.Boolean;
97
115
  }>;
98
116
  type StreamId = typeof StreamId.Type;
99
117
  type Offset = typeof Offset.Type;
118
+ type StreamsyOffset = typeof StreamsyOffset.Type;
100
119
  type ProducerId = typeof ProducerId.Type;
101
120
  interface StreamConfig extends Schema.Schema.Type<typeof StreamConfig> {}
102
121
  interface StreamLifecycle extends Schema.Schema.Type<typeof StreamLifecycle> {}
@@ -106,7 +125,7 @@ interface ProducerState extends Schema.Schema.Type<typeof ProducerState> {}
106
125
  interface MessageWindow extends Schema.Schema.Type<typeof MessageWindow> {}
107
126
  interface ChangeSnapshot extends Schema.Schema.Type<typeof ChangeSnapshot> {}
108
127
  declare const RecordPatch: Schema.Struct<{
109
- readonly currentOffset: Schema.optionalKey<Schema.brand<Schema.String, "Offset">>;
128
+ readonly currentOffset: Schema.optionalKey<Schema.brand<Schema.brand<Schema.String, "Offset">, "StreamsyOffset">>;
110
129
  readonly config: Schema.optionalKey<Schema.Struct<{
111
130
  readonly ttlSeconds: Schema.optionalKey<Schema.Finite>;
112
131
  readonly expiresAt: Schema.optionalKey<Schema.String>;
@@ -115,7 +134,7 @@ declare const RecordPatch: Schema.Struct<{
115
134
  readonly lastSeq: Schema.optionalKey<Schema.String>;
116
135
  readonly closedAt: Schema.optionalKey<Schema.Finite>;
117
136
  readonly forkedFrom: Schema.optionalKey<Schema.brand<Schema.String, "StreamId">>;
118
- readonly forkOffset: Schema.optionalKey<Schema.brand<Schema.String, "Offset">>;
137
+ readonly forkOffset: Schema.optionalKey<Schema.brand<Schema.brand<Schema.String, "Offset">, "StreamsyOffset">>;
119
138
  readonly forkSubOffset: Schema.optionalKey<Schema.Finite>;
120
139
  readonly expiresAtMs: Schema.optionalKey<Schema.Finite>;
121
140
  readonly closed: Schema.optionalKey<Schema.Boolean>;
@@ -124,17 +143,11 @@ declare const RecordPatch: Schema.Struct<{
124
143
  readonly clear: Schema.optionalKey<Schema.$Array<Schema.Literals<readonly ["ttlSeconds", "expiresAt", "expiresAtMs", "lastSeq"]>>>;
125
144
  }>;
126
145
  interface RecordPatch extends Schema.Schema.Type<typeof RecordPatch> {}
127
- /** Private pure-policy input, promoted to protocol options in Batch 3. */
128
- interface CreateOptions {
129
- readonly contentType?: string;
130
- readonly ttlSeconds?: number;
131
- readonly expiresAt?: string;
132
- readonly closed?: boolean;
133
- readonly forkedFrom?: string;
134
- readonly forkOffset?: string;
135
- readonly forkSubOffset?: number;
136
- readonly initialData?: Uint8Array;
137
- }
146
+ /**
147
+ * Where a read starts: `-1` for the start of the stream, `now` for its current tail, or an
148
+ * `Offset` that an earlier read or write returned.
149
+ */
150
+ type StartOffset = "-1" | "now" | Offset;
138
151
  interface ProducerOptions {
139
152
  readonly producerId: string;
140
153
  readonly producerEpoch: number;
@@ -154,12 +167,12 @@ interface AppendOptions {
154
167
  * means "append only if the stream is still empty". Streamsy extension to
155
168
  * the Durable Streams protocol.
156
169
  */
157
- readonly expectedOffset?: string;
170
+ readonly expectedOffset?: Offset;
158
171
  }
159
172
  /** Append options for a typed address. The address supplies the body and its content type. */
160
173
  type AppendCallOptions = Omit<AppendOptions, "data" | "contentType">;
161
174
  interface ReadOptions {
162
- offset?: string;
175
+ readonly offset?: StartOffset;
163
176
  }
164
177
  /**
165
178
  * Options for one transport-neutral read/wait operation. `readNext` returns
@@ -168,159 +181,35 @@ interface ReadOptions {
168
181
  * it; they are intentionally not part of this protocol contract.
169
182
  */
170
183
  interface ReadNextOptions {
171
- offset: string;
172
- cursor?: string;
173
- }
174
- declare const StreamNotFound_base: Schema.Class<StreamNotFound, Schema.TaggedStruct<"StreamNotFound", {
175
- readonly id: Schema.brand<Schema.String, "StreamId">;
176
- }>, import("effect/Cause").YieldableError>;
177
- /** Protocol rejections. Optional create reasons reflect the public HTTP wire's loss of detail. */
178
- declare class StreamNotFound extends StreamNotFound_base {
179
- get message(): string;
180
- }
181
- declare const StreamGone_base: Schema.Class<StreamGone, Schema.TaggedStruct<"StreamGone", {
182
- readonly id: Schema.brand<Schema.String, "StreamId">;
183
- }>, import("effect/Cause").YieldableError>;
184
- declare class StreamGone extends StreamGone_base {
185
- get message(): string;
186
- }
187
- declare const StreamClosed_base: Schema.Class<StreamClosed, Schema.TaggedStruct<"StreamClosed", {
188
- readonly id: Schema.brand<Schema.String, "StreamId">;
189
- readonly offset: Schema.String;
190
- }>, import("effect/Cause").YieldableError>;
191
- declare class StreamClosed extends StreamClosed_base {
192
- get message(): string;
193
- }
194
- declare const OffsetMismatch_base: Schema.Class<OffsetMismatch, Schema.TaggedStruct<"OffsetMismatch", {
195
- readonly id: Schema.brand<Schema.String, "StreamId">;
196
- readonly expected: Schema.String;
197
- readonly actual: Schema.String;
198
- }>, import("effect/Cause").YieldableError>;
199
- declare class OffsetMismatch extends OffsetMismatch_base {
200
- get message(): string;
201
- }
202
- declare const AppendConflict_base: Schema.Class<AppendConflict, Schema.TaggedStruct<"AppendConflict", {
203
- readonly id: Schema.brand<Schema.String, "StreamId">;
204
- readonly message: Schema.String;
205
- }>, import("effect/Cause").YieldableError>;
206
- declare class AppendConflict extends AppendConflict_base {}
207
- declare const StreamBusy_base: Schema.Class<StreamBusy, Schema.TaggedStruct<"StreamBusy", {
208
- readonly id: Schema.brand<Schema.String, "StreamId">;
209
- }>, import("effect/Cause").YieldableError>;
210
- declare class StreamBusy extends StreamBusy_base {
211
- get message(): string;
212
- }
213
- declare const StaleEpoch_base: Schema.Class<StaleEpoch, Schema.TaggedStruct<"StaleEpoch", {
214
- readonly id: Schema.brand<Schema.String, "StreamId">;
215
- readonly currentEpoch: Schema.Finite;
216
- }>, import("effect/Cause").YieldableError>;
217
- declare class StaleEpoch extends StaleEpoch_base {
218
- get message(): string;
219
- }
220
- declare const ProducerGap_base: Schema.Class<ProducerGap, Schema.TaggedStruct<"ProducerGap", {
221
- readonly id: Schema.brand<Schema.String, "StreamId">;
222
- readonly expectedSeq: Schema.Finite;
223
- readonly receivedSeq: Schema.Finite;
224
- }>, import("effect/Cause").YieldableError>;
225
- declare class ProducerGap extends ProducerGap_base {
226
- get message(): string;
227
- }
228
- declare const InvalidEpochSeq_base: Schema.Class<InvalidEpochSeq, Schema.TaggedStruct<"InvalidEpochSeq", {
229
- readonly id: Schema.brand<Schema.String, "StreamId">;
230
- }>, import("effect/Cause").YieldableError>;
231
- declare class InvalidEpochSeq extends InvalidEpochSeq_base {
232
- get message(): string;
233
- }
234
- declare const InvalidAppendRequest_base: Schema.Class<InvalidAppendRequest, Schema.TaggedStruct<"InvalidAppendRequest", {
235
- readonly id: Schema.brand<Schema.String, "StreamId">;
236
- readonly message: Schema.String;
237
- }>, import("effect/Cause").YieldableError>;
238
- declare class InvalidAppendRequest extends InvalidAppendRequest_base {}
239
- declare const InvalidCreateRequest_base: Schema.Class<InvalidCreateRequest, Schema.TaggedStruct<"InvalidCreateRequest", {
240
- readonly id: Schema.brand<Schema.String, "StreamId">;
241
- readonly message: Schema.String;
242
- }>, import("effect/Cause").YieldableError>;
243
- declare class InvalidCreateRequest extends InvalidCreateRequest_base {}
244
- declare const CreateConflict_base: Schema.Class<CreateConflict, Schema.TaggedStruct<"CreateConflict", {
245
- readonly id: Schema.brand<Schema.String, "StreamId">;
246
- readonly reason: Schema.optionalKey<Schema.Literals<readonly ["config-mismatch", "soft-deleted", "fork-content-type", "fork-source-soft-deleted"]>>;
247
- readonly message: Schema.String;
248
- }>, import("effect/Cause").YieldableError>;
249
- declare class CreateConflict extends CreateConflict_base {}
250
- declare const ForkSourceNotFound_base: Schema.Class<ForkSourceNotFound, Schema.TaggedStruct<"ForkSourceNotFound", {
251
- readonly id: Schema.brand<Schema.String, "StreamId">;
252
- readonly source: Schema.brand<Schema.String, "StreamId">;
253
- }>, import("effect/Cause").YieldableError>;
254
- declare class ForkSourceNotFound extends ForkSourceNotFound_base {
255
- get message(): string;
184
+ readonly offset: StartOffset;
185
+ readonly cursor?: string;
256
186
  }
257
- declare const InvalidForkRequest_base: Schema.Class<InvalidForkRequest, Schema.TaggedStruct<"InvalidForkRequest", {
258
- readonly id: Schema.brand<Schema.String, "StreamId">;
259
- readonly message: Schema.String;
260
- }>, import("effect/Cause").YieldableError>;
261
- declare class InvalidForkRequest extends InvalidForkRequest_base {}
262
- declare const NotSupported_base: Schema.Class<NotSupported, Schema.TaggedStruct<"NotSupported", {
263
- readonly id: Schema.brand<Schema.String, "StreamId">;
264
- readonly feature: Schema.String;
265
- }>, import("effect/Cause").YieldableError>;
266
- declare class NotSupported extends NotSupported_base {
267
- get message(): string;
268
- }
269
- type CreateConflictReason = NonNullable<CreateConflict["reason"]>;
270
- type HeadError = StreamNotFound | StreamGone;
271
- declare const InvalidReadRequest_base: Schema.Class<InvalidReadRequest, Schema.TaggedStruct<"InvalidReadRequest", {
272
- readonly id: Schema.brand<Schema.String, "StreamId">;
273
- readonly message: Schema.String;
274
- }>, import("effect/Cause").YieldableError>;
275
- declare class InvalidReadRequest extends InvalidReadRequest_base {}
276
- type ReadError = StreamNotFound | StreamGone | InvalidReadRequest;
277
- type ReadNextError = ReadError | NotSupported;
278
- type CreateError = CreateConflict | InvalidCreateRequest | ForkSourceNotFound | InvalidForkRequest | NotSupported;
279
- /**
280
- * Append rejections that any call can get, whatever its options. The memory and
281
- * storage hosts never answer `NotSupported`; the remote client does when the server
282
- * or its own capabilities refuse a feature.
283
- */
284
- type AppendBaseError = StreamNotFound | StreamGone | StreamClosed | StreamBusy | AppendConflict | NotSupported;
285
- type AppendError = AppendBaseError | InvalidAppendRequest | OffsetMismatch | StaleEpoch | ProducerGap | InvalidEpochSeq;
286
- /**
287
- * The append rejections that call options `O` make possible. `OffsetMismatch`
288
- * needs `expectedOffset`, and the producer rejections need `producer`. An option
289
- * that may be set counts as set.
290
- */
291
- type AppendErrorFor<O> = AppendBaseError | (true extends MaySet<O, "expectedOffset"> ? OffsetMismatch : never) | (true extends MaySet<O, "producer"> ? StaleEpoch | ProducerGap : never);
292
- /** Whether options `O` may hold a value for `K`. A union holds it if any member may. */
293
- type MaySet<O, K extends PropertyKey> = O extends unknown ? K extends keyof O ? [Exclude<O[K], undefined>] extends [never] ? false : true : false : never;
294
- type RemoveError = StreamNotFound | StreamGone | StreamBusy;
295
- type ProtocolError = HeadError | ReadNextError | CreateError | AppendError | RemoveError;
296
- /** The HTTP edge answers every protocol rejection through one mapper, so it needs one guard. */
297
- declare const isProtocolError: (error: {
298
- readonly _tag: string;
299
- }) => error is ProtocolError;
300
187
  /** Payload-only messages exposed by the public protocol; storage owns offsets and timestamps. */
301
188
  interface ReadMessage {
302
189
  readonly data: Uint8Array;
303
190
  }
304
191
  type CreateResult = {
305
192
  readonly _tag: "Created";
306
- readonly nextOffset: string;
193
+ /** The tail of the stream; an after-exclusive read cursor. */
194
+ readonly offset: Offset;
307
195
  readonly contentType: string;
308
196
  readonly closed: boolean;
309
197
  } | {
310
198
  readonly _tag: "Exists";
311
- readonly nextOffset: string;
199
+ /** The tail of the stream; an after-exclusive read cursor. */
200
+ readonly offset: Offset;
312
201
  readonly contentType: string;
313
202
  readonly closed: boolean;
314
203
  };
315
204
  type AppendResult = {
316
205
  readonly _tag: "Appended";
317
- /** Tail after this write; an after-exclusive read cursor. */ readonly offset: string;
206
+ /** Tail after this write; an after-exclusive read cursor. */ readonly offset: Offset;
318
207
  readonly producerEpoch?: number;
319
208
  readonly producerSeq?: number;
320
209
  readonly closed: boolean;
321
210
  } | {
322
211
  readonly _tag: "Duplicate";
323
- /** Current tail at acknowledgement, at or after the original write. */ readonly offset: string;
212
+ /** Current tail at acknowledgement, at or after the original write. */ readonly offset: Offset;
324
213
  readonly producerEpoch: number;
325
214
  readonly producerSeq: number;
326
215
  readonly closed: boolean;
@@ -331,7 +220,7 @@ declare const AppendResult: Data.TaggedEnum.Constructor<AppendResult>;
331
220
  interface ReadResult {
332
221
  readonly contentType: string;
333
222
  readonly messages: ReadonlyArray<ReadMessage>;
334
- readonly nextOffset: string;
223
+ readonly nextOffset: Offset;
335
224
  readonly upToDate: boolean;
336
225
  readonly closed: boolean;
337
226
  }
@@ -341,26 +230,12 @@ interface ReadNextResult extends ReadResult {
341
230
  }
342
231
  interface HeadResult {
343
232
  readonly contentType: string;
344
- readonly nextOffset: string;
233
+ /** The tail of the stream; an after-exclusive read cursor. */
234
+ readonly offset: Offset;
345
235
  readonly ttlSeconds?: number;
346
236
  readonly expiresAt?: string;
347
237
  readonly closed: boolean;
348
238
  }
349
- interface Reader<E = StorageFault> {
350
- readonly head: (id: StreamId) => Effect.Effect<HeadResult, HeadError | E>;
351
- readonly read: (id: StreamId, options?: ReadOptions) => Effect.Effect<ReadResult, ReadError | E>;
352
- readonly readNext: (id: StreamId, options: ReadNextOptions) => Effect.Effect<ReadNextResult, ReadNextError | E>;
353
- }
354
- interface Writer<E = StorageFault> {
355
- readonly create: (id: StreamId, options?: CreateOptions) => Effect.Effect<CreateResult, CreateError | E>;
356
- readonly fork: (id: StreamId, source: StreamId, options?: Omit<CreateOptions, "forkedFrom">) => Effect.Effect<CreateResult, CreateError | E>;
357
- readonly append: (id: StreamId, options: AppendOptions) => Effect.Effect<AppendResult, AppendError | E>;
358
- readonly remove: (id: StreamId) => Effect.Effect<void, RemoveError | E>;
359
- }
360
- declare const StreamsReader_base: Context.ServiceClass<StreamsReader, "@streamsy/core/StreamsReader", Reader<StorageFault | TransportFault>>;
361
- declare class StreamsReader extends StreamsReader_base {}
362
- declare const StreamsWriter_base: Context.ServiceClass<StreamsWriter, "@streamsy/core/StreamsWriter", Writer<StorageFault | TransportFault>>;
363
- declare class StreamsWriter extends StreamsWriter_base {}
364
239
  declare const StorageCapabilities: Schema.Struct<{
365
240
  readonly fork: Schema.Literals<readonly ["none", "copy", "chain"]>;
366
241
  readonly atomicScope: Schema.Literals<readonly ["stream", "store"]>;
@@ -368,6 +243,263 @@ declare const StorageCapabilities: Schema.Struct<{
368
243
  readonly expiryIndex: Schema.Literals<readonly ["lazy", "indexed"]>;
369
244
  }>;
370
245
  interface StorageCapabilities extends Schema.Schema.Type<typeof StorageCapabilities> {}
246
+ /**
247
+ * The identity of one storage owner. A stream service bound to the owner carries the
248
+ * same value in its `owner` field, so `stream.owner === owner.id` tests ownership.
249
+ */
250
+ type OwnerId = Brand.Branded<string, "@streamsy/core/OwnerId">;
251
+ interface StorageOwnerApi {
252
+ /** Identity. A stream service bound to this owner carries the same value in `owner`. */
253
+ readonly id: OwnerId;
254
+ readonly capabilities: StorageCapabilities;
255
+ /**
256
+ * Run `body` in the owner's transaction. Nested calls on the same owner join
257
+ * without savepoints, so a failure must escape the outer body to roll back.
258
+ * Same-owner stream writes and records commit with application SQL on that client.
259
+ * With two owners over one SQL client, only the outer owner's hooks and
260
+ * `committed` subscribers see the commit.
261
+ *
262
+ * A nested call on another SQL client opens its own transaction, as does a lone
263
+ * stream write on that client. Its commit comes first and survives an outer
264
+ * rollback. Use one client per database for nested work. With two clients on
265
+ * one database, SQLite can wait until it reports a busy lock. Postgres or MySQL
266
+ * can wait for a row lock that the outer transaction holds.
267
+ *
268
+ * Durable Object clients share the driver's transaction, so a second client
269
+ * joins the first. Using a second object's storage on one fiber is unsupported.
270
+ * `MemoryStorage` dies when work enters another `MemoryStorage` owner.
271
+ *
272
+ * Keep the body on the calling fiber, and do not wait in it for wakes that only
273
+ * its own commit publishes. A SQL host fails with `StorageFault` when the
274
+ * transaction or a SQL statement in it fails, with `isRetryable` from the SQL error.
275
+ */
276
+ readonly withTransaction: <A, E, R>(body: Effect.Effect<A, E, R>) => Effect.Effect<A, E | StorageFault, R>;
277
+ /**
278
+ * Subscribe to the stream ids of later local commits. The subscription exists when
279
+ * this effect returns. Each item holds the ids that one commit created, appended to
280
+ * or deleted. In process and best effort. The scope releases the subscription.
281
+ */
282
+ readonly committed: Effect.Effect<PubSub.Subscription<ReadonlyArray<StreamId>>, never, Scope.Scope>;
283
+ }
284
+ declare const StorageOwner_base: Context.ServiceClass<StorageOwner, "@streamsy/core/StorageOwner", StorageOwnerApi>;
285
+ /** The storage owner of a local host: its identity, its transaction and its commits. */
286
+ declare class StorageOwner extends StorageOwner_base {}
287
+ declare namespace durable_state_d_exports {
288
+ export { Change, ChangeEvent, ChangeHeaders, Collection, Collections, CollectionsChange, CollectionsDecodingServices, CollectionsEncodedChange, CollectionsEncodedEvent, CollectionsEncodingServices, CollectionsEvent, Control, ControlName, Delete, DeleteEvent, Entry, Event, EventHeaders, Key, Materialized, Rows, Upsert, UpsertEvent, ValidCollections, changeCodec, changes, controlCodec, isChange, isControl, isUpsert, materialize, materialized, remove, reset, snapshotEnd, snapshotStart, upsert };
289
+ }
290
+ /** Omit `offset` and `txid` rather than setting them to `undefined`. */
291
+ interface EventHeaders {
292
+ readonly operation: "upsert" | "delete";
293
+ readonly offset?: string;
294
+ readonly txid?: string;
295
+ readonly timestamp?: string;
296
+ readonly from?: string;
297
+ }
298
+ interface UpsertEvent<A, Type extends string = string> {
299
+ readonly type: Type;
300
+ readonly key: string;
301
+ readonly value: A;
302
+ readonly headers: EventHeaders & {
303
+ readonly operation: "upsert";
304
+ };
305
+ }
306
+ interface DeleteEvent<A, Type extends string = string> {
307
+ readonly type: Type;
308
+ readonly key: string;
309
+ readonly old_value?: A;
310
+ readonly headers: EventHeaders & {
311
+ readonly operation: "delete";
312
+ };
313
+ }
314
+ /** A change event consumed by `@durable-streams/state`, narrowed by its `type`. */
315
+ type ChangeEvent<A, Type extends string = string> = UpsertEvent<A, Type> | DeleteEvent<A, Type>;
316
+ type EncodedChangeEvent<A, Type extends string = string> = (Omit<UpsertEvent<A, Type>, "headers"> & {
317
+ readonly headers: Omit<EventHeaders, "operation"> & {
318
+ readonly operation: "insert" | "update" | "upsert";
319
+ };
320
+ }) | DeleteEvent<A, Type>;
321
+ /** The control signals of the Durable State protocol (STATE-PROTOCOL.md section 4.2). */
322
+ type ControlName = "snapshot-start" | "snapshot-end" | "reset";
323
+ /**
324
+ * A control message of a Durable State stream. It has no `type` or `key`.
325
+ * `snapshot-start` and `snapshot-end` mark a run of changes that is a complete
326
+ * snapshot. `reset` tells a reader to clear its materialized state. Omit
327
+ * `offset` rather than setting it to `undefined`.
328
+ */
329
+ interface Control {
330
+ readonly headers: {
331
+ readonly control: ControlName;
332
+ readonly offset?: string;
333
+ };
334
+ }
335
+ /** One item of a Durable State stream: a change of one collection or a control. */
336
+ type Event<A, Type extends string = string> = ChangeEvent<A, Type> | Control;
337
+ /** The value fields that may serve as a Durable State key. */
338
+ type Key<A> = { [K in keyof A]-?: A[K] extends string | number ? K : never; }[keyof A];
339
+ /** One collection of a Durable State stream: its value schema and the value field used as the key. */
340
+ interface Collection<A, I, RD, RE, KeyField extends Key<A> = Key<A>> {
341
+ readonly schema: Schema.Codec<A, I, RD, RE>;
342
+ readonly key: KeyField;
343
+ }
344
+ /** Collections keyed by the `type` that names them on the wire. */
345
+ type Collections = Record<string, Collection<any, any, any, any, any>>;
346
+ /**
347
+ * Each `key` must name a string or number field of its own collection's value.
348
+ * A mismatch reports on the `key` property of the offending collection.
349
+ */
350
+ type ValidCollections<C extends Collections> = { readonly [K in keyof C]: C[K]["key"] extends Key<C[K]["schema"]["Type"]> ? C[K] : {
351
+ readonly key: Key<C[K]["schema"]["Type"]>;
352
+ }; };
353
+ /** The union of change events across every collection, discriminated by `type`. */
354
+ type CollectionsChange<C extends Collections> = { [K in keyof C & string]: ChangeEvent<C[K]["schema"]["Type"], K>; }[keyof C & string];
355
+ type CollectionsEncodedChange<C extends Collections> = { [K in keyof C & string]: EncodedChangeEvent<C[K]["schema"]["Encoded"], K>; }[keyof C & string];
356
+ /** The items of a State address: the change events of its collections, plus controls. */
357
+ type CollectionsEvent<C extends Collections> = CollectionsChange<C> | Control;
358
+ type CollectionsEncodedEvent<C extends Collections> = CollectionsEncodedChange<C> | Control;
359
+ type CollectionsDecodingServices<C extends Collections> = C[keyof C]["schema"]["DecodingServices"];
360
+ type CollectionsEncodingServices<C extends Collections> = C[keyof C]["schema"]["EncodingServices"];
361
+ /**
362
+ * A codec for the upsert and delete change events of one collection.
363
+ * `StreamAddress.state` composes one of these per collection. Omit optional
364
+ * headers instead of setting them to `undefined`.
365
+ */
366
+ declare function changeCodec<A, I, RD, RE, const Type extends string>(options: {
367
+ readonly schema: Schema.Codec<A, I, RD, RE>;
368
+ readonly type: Type;
369
+ }): Schema.Codec<ChangeEvent<A, Type>, EncodedChangeEvent<I, Type>, RD, RE>;
370
+ /** The codec for a State control message. It needs no services. */
371
+ declare const controlCodec: Schema.Codec<Control>;
372
+ /** True for a control message. A change has `headers.operation` and no `headers.control`. */
373
+ declare const isControl: <E extends Event<unknown>>(event: E) => event is Extract<E, Control>;
374
+ /** True for an upsert or delete change. */
375
+ declare const isChange: <E extends Event<unknown>>(event: E) => event is Exclude<E, Control>;
376
+ /** True for an upsert change, with its value available. */
377
+ declare const isUpsert: <E extends Event<unknown>>(event: E) => event is Extract<E, UpsertEvent<unknown>>;
378
+ /** A `reset` control. A reader should clear its materialized state and apply what follows. */
379
+ declare const reset: (options?: {
380
+ readonly offset?: StartOffset;
381
+ }) => Control;
382
+ /** A `snapshot-start` control. The changes up to `snapshot-end` form a complete snapshot. */
383
+ declare const snapshotStart: (options?: {
384
+ readonly offset?: StartOffset;
385
+ }) => Control;
386
+ /** A `snapshot-end` control. It closes the snapshot that `snapshot-start` opened. */
387
+ declare const snapshotEnd: (options?: {
388
+ readonly offset?: StartOffset;
389
+ }) => Control;
390
+ interface ChangeHeaders {
391
+ readonly txid?: string;
392
+ readonly timestamp?: string;
393
+ readonly from?: string;
394
+ }
395
+ type Operation$1<A, Type extends string> = Data.TaggedEnum<{
396
+ Upsert: {
397
+ readonly type: Type;
398
+ readonly value: A;
399
+ readonly headers?: ChangeHeaders;
400
+ };
401
+ Delete: {
402
+ readonly type: Type;
403
+ readonly key: string | number;
404
+ readonly oldValue?: A;
405
+ readonly headers?: ChangeHeaders;
406
+ };
407
+ }>;
408
+ type Upsert<A, Type extends string = string> = Data.TaggedEnum.Value<Operation$1<A, Type>, "Upsert">;
409
+ type Delete<A, Type extends string = string> = Data.TaggedEnum.Value<Operation$1<A, Type>, "Delete">;
410
+ /** A pending change for one of the collections in `C`. */
411
+ 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];
412
+ /**
413
+ * One entry for `changes`: a pending change, or a State control such as
414
+ * `DurableState.reset()`.
415
+ */
416
+ type Entry<C extends Collections> = Change<C> | Control;
417
+ /** Describe an upsert into a collection. The key is read from the value. */
418
+ declare const upsert: <const Type extends string, A>(type: Type, value: A, options?: {
419
+ readonly headers?: ChangeHeaders;
420
+ }) => Upsert<A, Type>;
421
+ /** Describe a delete from a collection by key. An `oldValue` is written as `old_value`. */
422
+ declare const remove: <const Type extends string, A = never>(type: Type, key: string | number, options?: {
423
+ readonly oldValue?: A;
424
+ readonly headers?: ChangeHeaders;
425
+ }) => Delete<NoInfer<A>, Type>;
426
+ /**
427
+ * Stamp Durable State changes with their key and headers. `source` gives the
428
+ * collections: a `Streamsy.state` class, a bound State address, or a
429
+ * `StreamAddress.state` address. With an `offset`, each change gets that offset
430
+ * and a default txid of `<offset>:<index>`. A control entry passes through. It
431
+ * gets the `offset` only when it has none of its own.
432
+ */
433
+ declare function changes<C extends Collections>(source: {
434
+ readonly collections: C;
435
+ }, entries: Array.NonEmptyReadonlyArray<Entry<C>>, options?: {
436
+ readonly offset?: StartOffset;
437
+ }): Array.NonEmptyReadonlyArray<CollectionsEvent<C>>;
438
+ declare function changes<C extends Collections>(source: {
439
+ readonly collections: C;
440
+ }, entries: ReadonlyArray<Entry<C>>, options?: {
441
+ readonly offset?: StartOffset;
442
+ }): ReadonlyArray<CollectionsEvent<C>>;
443
+ /** The rows of one collection, by State key. */
444
+ type Rows<C extends Collections> = { readonly [K in keyof C & string]: ReadonlyMap<string, C[K]["schema"]["Type"]>; };
445
+ /**
446
+ * The materialized state of a Durable State stream: the latest row for each key
447
+ * of each collection. `snapshot` holds the keys seen since an open
448
+ * `snapshot-start`, and is `undefined` outside a snapshot.
449
+ */
450
+ interface Materialized<C extends Collections> {
451
+ readonly rows: Rows<C>;
452
+ readonly snapshot: ReadonlySet<string> | undefined;
453
+ }
454
+ /** Empty materialized state for the collections of `address`. */
455
+ declare function materialized<C extends Collections>(address: {
456
+ readonly collections: C;
457
+ }): Materialized<C>;
458
+ /**
459
+ * Fold State events into materialized state, with the State protocol rules:
460
+ *
461
+ * - `upsert` sets the row of its key, and `delete` removes it.
462
+ * - `reset` clears every collection.
463
+ * - `snapshot-end` removes each row that no change since `snapshot-start` named.
464
+ * A snapshot may span several calls.
465
+ *
466
+ * The input state is not changed. Only the collections that `events` touch are copied.
467
+ */
468
+ declare function materialize<C extends Collections>(state: Materialized<C>, events: Iterable<CollectionsEvent<C>>): Materialized<C>;
469
+ declare namespace address_d_exports {
470
+ export { StateAddress, StreamAddress, bytes, json, state };
471
+ }
472
+ /** Inert identity and codec. Constructing an address acquires no service or resource. */
473
+ interface StreamAddress<A, RD = never, RE = never> {
474
+ readonly _tag: "Json" | "Bytes";
475
+ readonly id: StreamId;
476
+ readonly contentType: string;
477
+ readonly codec: Schema.Codec<A, string | Uint8Array, RD, RE>;
478
+ }
479
+ /** A JSON address whose items are the change events of its collections and State controls. */
480
+ interface StateAddress<C extends Collections, RD = CollectionsDecodingServices<C>, RE = CollectionsEncodingServices<C>> extends StreamAddress<CollectionsEvent<C>, RD, RE> {
481
+ readonly collections: C;
482
+ /** Fail typed reads on changes to undeclared collections. */
483
+ readonly strict?: boolean;
484
+ }
485
+ declare function json<A, I, RD, RE>(id: string, options: {
486
+ readonly schema: Schema.Codec<A, I, RD, RE>;
487
+ }): StreamAddress<A, RD, RE>;
488
+ /**
489
+ * A stream of Durable State events for several collections. Each record
490
+ * key is the `type` on the wire; each entry gives the value schema and the value
491
+ * field that becomes the event `key`. The codec also decodes and encodes the
492
+ * State control messages `snapshot-start`, `snapshot-end` and `reset`.
493
+ * Typed reads skip changes to undeclared collections unless `strict` is true.
494
+ */
495
+ declare function state<const C extends Collections>(id: string, options: {
496
+ readonly collections: C & ValidCollections<C>;
497
+ readonly strict?: boolean;
498
+ }): StateAddress<C>;
499
+ /** Items from one bytes append are joined into one stored message. */
500
+ declare function bytes(id: string, options?: {
501
+ readonly contentType?: string;
502
+ }): StreamAddress<Uint8Array>;
371
503
  declare const ProducerPrecondition: Schema.Struct<{
372
504
  readonly producerId: Schema.brand<Schema.String, "ProducerId">;
373
505
  readonly expected: Schema.Option<Schema.Struct<{
@@ -393,31 +525,31 @@ declare const Operation: Schema.Union<readonly [Schema.TaggedStruct<"Create", {
393
525
  readonly closed: Schema.Boolean;
394
526
  readonly closedAt: Schema.optionalKey<Schema.Finite>;
395
527
  readonly forkedFrom: Schema.optionalKey<Schema.brand<Schema.String, "StreamId">>;
396
- readonly forkOffset: Schema.optionalKey<Schema.brand<Schema.String, "Offset">>;
528
+ readonly forkOffset: Schema.optionalKey<Schema.brand<Schema.brand<Schema.String, "Offset">, "StreamsyOffset">>;
397
529
  readonly forkSubOffset: Schema.optionalKey<Schema.Finite>;
398
530
  readonly softDeleted: Schema.Boolean;
399
531
  readonly expiresAtMs: Schema.optionalKey<Schema.Finite>;
400
532
  }>;
401
- readonly currentOffset: Schema.brand<Schema.String, "Offset">;
533
+ readonly currentOffset: Schema.brand<Schema.brand<Schema.String, "Offset">, "StreamsyOffset">;
402
534
  }>;
403
535
  readonly initialMessages: Schema.$Array<Schema.Struct<{
404
- readonly offset: Schema.brand<Schema.String, "Offset">;
536
+ readonly offset: Schema.brand<Schema.brand<Schema.String, "Offset">, "StreamsyOffset">;
405
537
  readonly timestamp: Schema.Finite;
406
538
  readonly data: Schema.Uint8Array;
407
539
  }>>;
408
540
  readonly forkSource: Schema.optionalKey<Schema.Struct<{
409
541
  readonly id: Schema.brand<Schema.String, "StreamId">;
410
- readonly liveAtOffset: Schema.brand<Schema.String, "Offset">;
542
+ readonly liveAtOffset: Schema.brand<Schema.brand<Schema.String, "Offset">, "StreamsyOffset">;
411
543
  }>>;
412
544
  }>, Schema.TaggedStruct<"Append", {
413
545
  readonly streamId: Schema.brand<Schema.String, "StreamId">;
414
546
  readonly messages: Schema.$Array<Schema.Struct<{
415
- readonly offset: Schema.brand<Schema.String, "Offset">;
547
+ readonly offset: Schema.brand<Schema.brand<Schema.String, "Offset">, "StreamsyOffset">;
416
548
  readonly timestamp: Schema.Finite;
417
549
  readonly data: Schema.Uint8Array;
418
550
  }>>;
419
551
  readonly patch: Schema.Struct<{
420
- readonly currentOffset: Schema.optionalKey<Schema.brand<Schema.String, "Offset">>;
552
+ readonly currentOffset: Schema.optionalKey<Schema.brand<Schema.brand<Schema.String, "Offset">, "StreamsyOffset">>;
421
553
  readonly config: Schema.optionalKey<Schema.Struct<{
422
554
  readonly ttlSeconds: Schema.optionalKey<Schema.Finite>;
423
555
  readonly expiresAt: Schema.optionalKey<Schema.String>;
@@ -426,7 +558,7 @@ declare const Operation: Schema.Union<readonly [Schema.TaggedStruct<"Create", {
426
558
  readonly lastSeq: Schema.optionalKey<Schema.String>;
427
559
  readonly closedAt: Schema.optionalKey<Schema.Finite>;
428
560
  readonly forkedFrom: Schema.optionalKey<Schema.brand<Schema.String, "StreamId">>;
429
- readonly forkOffset: Schema.optionalKey<Schema.brand<Schema.String, "Offset">>;
561
+ readonly forkOffset: Schema.optionalKey<Schema.brand<Schema.brand<Schema.String, "Offset">, "StreamsyOffset">>;
430
562
  readonly forkSubOffset: Schema.optionalKey<Schema.Finite>;
431
563
  readonly expiresAtMs: Schema.optionalKey<Schema.Finite>;
432
564
  readonly closed: Schema.optionalKey<Schema.Boolean>;
@@ -434,7 +566,7 @@ declare const Operation: Schema.Union<readonly [Schema.TaggedStruct<"Create", {
434
566
  }>>;
435
567
  readonly clear: Schema.optionalKey<Schema.$Array<Schema.Literals<readonly ["ttlSeconds", "expiresAt", "expiresAtMs", "lastSeq"]>>>;
436
568
  }>;
437
- readonly expectedOffset: Schema.optionalKey<Schema.brand<Schema.String, "Offset">>;
569
+ readonly expectedOffset: Schema.optionalKey<Schema.brand<Schema.brand<Schema.String, "Offset">, "StreamsyOffset">>;
438
570
  readonly expectedClosed: Schema.optionalKey<Schema.Boolean>;
439
571
  readonly producer: Schema.optionalKey<Schema.Struct<{
440
572
  readonly producerId: Schema.brand<Schema.String, "ProducerId">;
@@ -467,31 +599,31 @@ declare const Mutation: Schema.Struct<{
467
599
  readonly closed: Schema.Boolean;
468
600
  readonly closedAt: Schema.optionalKey<Schema.Finite>;
469
601
  readonly forkedFrom: Schema.optionalKey<Schema.brand<Schema.String, "StreamId">>;
470
- readonly forkOffset: Schema.optionalKey<Schema.brand<Schema.String, "Offset">>;
602
+ readonly forkOffset: Schema.optionalKey<Schema.brand<Schema.brand<Schema.String, "Offset">, "StreamsyOffset">>;
471
603
  readonly forkSubOffset: Schema.optionalKey<Schema.Finite>;
472
604
  readonly softDeleted: Schema.Boolean;
473
605
  readonly expiresAtMs: Schema.optionalKey<Schema.Finite>;
474
606
  }>;
475
- readonly currentOffset: Schema.brand<Schema.String, "Offset">;
607
+ readonly currentOffset: Schema.brand<Schema.brand<Schema.String, "Offset">, "StreamsyOffset">;
476
608
  }>;
477
609
  readonly initialMessages: Schema.$Array<Schema.Struct<{
478
- readonly offset: Schema.brand<Schema.String, "Offset">;
610
+ readonly offset: Schema.brand<Schema.brand<Schema.String, "Offset">, "StreamsyOffset">;
479
611
  readonly timestamp: Schema.Finite;
480
612
  readonly data: Schema.Uint8Array;
481
613
  }>>;
482
614
  readonly forkSource: Schema.optionalKey<Schema.Struct<{
483
615
  readonly id: Schema.brand<Schema.String, "StreamId">;
484
- readonly liveAtOffset: Schema.brand<Schema.String, "Offset">;
616
+ readonly liveAtOffset: Schema.brand<Schema.brand<Schema.String, "Offset">, "StreamsyOffset">;
485
617
  }>>;
486
618
  }>, Schema.TaggedStruct<"Append", {
487
619
  readonly streamId: Schema.brand<Schema.String, "StreamId">;
488
620
  readonly messages: Schema.$Array<Schema.Struct<{
489
- readonly offset: Schema.brand<Schema.String, "Offset">;
621
+ readonly offset: Schema.brand<Schema.brand<Schema.String, "Offset">, "StreamsyOffset">;
490
622
  readonly timestamp: Schema.Finite;
491
623
  readonly data: Schema.Uint8Array;
492
624
  }>>;
493
625
  readonly patch: Schema.Struct<{
494
- readonly currentOffset: Schema.optionalKey<Schema.brand<Schema.String, "Offset">>;
626
+ readonly currentOffset: Schema.optionalKey<Schema.brand<Schema.brand<Schema.String, "Offset">, "StreamsyOffset">>;
495
627
  readonly config: Schema.optionalKey<Schema.Struct<{
496
628
  readonly ttlSeconds: Schema.optionalKey<Schema.Finite>;
497
629
  readonly expiresAt: Schema.optionalKey<Schema.String>;
@@ -500,7 +632,7 @@ declare const Mutation: Schema.Struct<{
500
632
  readonly lastSeq: Schema.optionalKey<Schema.String>;
501
633
  readonly closedAt: Schema.optionalKey<Schema.Finite>;
502
634
  readonly forkedFrom: Schema.optionalKey<Schema.brand<Schema.String, "StreamId">>;
503
- readonly forkOffset: Schema.optionalKey<Schema.brand<Schema.String, "Offset">>;
635
+ readonly forkOffset: Schema.optionalKey<Schema.brand<Schema.brand<Schema.String, "Offset">, "StreamsyOffset">>;
504
636
  readonly forkSubOffset: Schema.optionalKey<Schema.Finite>;
505
637
  readonly expiresAtMs: Schema.optionalKey<Schema.Finite>;
506
638
  readonly closed: Schema.optionalKey<Schema.Boolean>;
@@ -508,7 +640,7 @@ declare const Mutation: Schema.Struct<{
508
640
  }>>;
509
641
  readonly clear: Schema.optionalKey<Schema.$Array<Schema.Literals<readonly ["ttlSeconds", "expiresAt", "expiresAtMs", "lastSeq"]>>>;
510
642
  }>;
511
- readonly expectedOffset: Schema.optionalKey<Schema.brand<Schema.String, "Offset">>;
643
+ readonly expectedOffset: Schema.optionalKey<Schema.brand<Schema.brand<Schema.String, "Offset">, "StreamsyOffset">>;
512
644
  readonly expectedClosed: Schema.optionalKey<Schema.Boolean>;
513
645
  readonly producer: Schema.optionalKey<Schema.Struct<{
514
646
  readonly producerId: Schema.brand<Schema.String, "ProducerId">;
@@ -541,12 +673,12 @@ declare const OperationResult: Schema.Union<readonly [Schema.TaggedStruct<"Creat
541
673
  readonly closed: Schema.Boolean;
542
674
  readonly closedAt: Schema.optionalKey<Schema.Finite>;
543
675
  readonly forkedFrom: Schema.optionalKey<Schema.brand<Schema.String, "StreamId">>;
544
- readonly forkOffset: Schema.optionalKey<Schema.brand<Schema.String, "Offset">>;
676
+ readonly forkOffset: Schema.optionalKey<Schema.brand<Schema.brand<Schema.String, "Offset">, "StreamsyOffset">>;
545
677
  readonly forkSubOffset: Schema.optionalKey<Schema.Finite>;
546
678
  readonly softDeleted: Schema.Boolean;
547
679
  readonly expiresAtMs: Schema.optionalKey<Schema.Finite>;
548
680
  }>;
549
- readonly currentOffset: Schema.brand<Schema.String, "Offset">;
681
+ readonly currentOffset: Schema.brand<Schema.brand<Schema.String, "Offset">, "StreamsyOffset">;
550
682
  }>;
551
683
  }>, Schema.TaggedStruct<"Appended", {
552
684
  readonly record: Schema.Struct<{
@@ -562,12 +694,12 @@ declare const OperationResult: Schema.Union<readonly [Schema.TaggedStruct<"Creat
562
694
  readonly closed: Schema.Boolean;
563
695
  readonly closedAt: Schema.optionalKey<Schema.Finite>;
564
696
  readonly forkedFrom: Schema.optionalKey<Schema.brand<Schema.String, "StreamId">>;
565
- readonly forkOffset: Schema.optionalKey<Schema.brand<Schema.String, "Offset">>;
697
+ readonly forkOffset: Schema.optionalKey<Schema.brand<Schema.brand<Schema.String, "Offset">, "StreamsyOffset">>;
566
698
  readonly forkSubOffset: Schema.optionalKey<Schema.Finite>;
567
699
  readonly softDeleted: Schema.Boolean;
568
700
  readonly expiresAtMs: Schema.optionalKey<Schema.Finite>;
569
701
  }>;
570
- readonly currentOffset: Schema.brand<Schema.String, "Offset">;
702
+ readonly currentOffset: Schema.brand<Schema.brand<Schema.String, "Offset">, "StreamsyOffset">;
571
703
  }>;
572
704
  }>, Schema.TaggedStruct<"Purged", {
573
705
  readonly record: Schema.Struct<{
@@ -583,12 +715,12 @@ declare const OperationResult: Schema.Union<readonly [Schema.TaggedStruct<"Creat
583
715
  readonly closed: Schema.Boolean;
584
716
  readonly closedAt: Schema.optionalKey<Schema.Finite>;
585
717
  readonly forkedFrom: Schema.optionalKey<Schema.brand<Schema.String, "StreamId">>;
586
- readonly forkOffset: Schema.optionalKey<Schema.brand<Schema.String, "Offset">>;
718
+ readonly forkOffset: Schema.optionalKey<Schema.brand<Schema.brand<Schema.String, "Offset">, "StreamsyOffset">>;
587
719
  readonly forkSubOffset: Schema.optionalKey<Schema.Finite>;
588
720
  readonly softDeleted: Schema.Boolean;
589
721
  readonly expiresAtMs: Schema.optionalKey<Schema.Finite>;
590
722
  }>;
591
- readonly currentOffset: Schema.brand<Schema.String, "Offset">;
723
+ readonly currentOffset: Schema.brand<Schema.brand<Schema.String, "Offset">, "StreamsyOffset">;
592
724
  }>;
593
725
  }>, Schema.TaggedStruct<"SoftDeleted", {
594
726
  readonly record: Schema.Struct<{
@@ -604,12 +736,12 @@ declare const OperationResult: Schema.Union<readonly [Schema.TaggedStruct<"Creat
604
736
  readonly closed: Schema.Boolean;
605
737
  readonly closedAt: Schema.optionalKey<Schema.Finite>;
606
738
  readonly forkedFrom: Schema.optionalKey<Schema.brand<Schema.String, "StreamId">>;
607
- readonly forkOffset: Schema.optionalKey<Schema.brand<Schema.String, "Offset">>;
739
+ readonly forkOffset: Schema.optionalKey<Schema.brand<Schema.brand<Schema.String, "Offset">, "StreamsyOffset">>;
608
740
  readonly forkSubOffset: Schema.optionalKey<Schema.Finite>;
609
741
  readonly softDeleted: Schema.Boolean;
610
742
  readonly expiresAtMs: Schema.optionalKey<Schema.Finite>;
611
743
  }>;
612
- readonly currentOffset: Schema.brand<Schema.String, "Offset">;
744
+ readonly currentOffset: Schema.brand<Schema.brand<Schema.String, "Offset">, "StreamsyOffset">;
613
745
  }>;
614
746
  }>]>;
615
747
  /** The success channel of a storage mutation contains only applied operation results. */
@@ -628,12 +760,12 @@ declare const MutationApplied: Schema.TaggedStruct<"Applied", {
628
760
  readonly closed: Schema.Boolean;
629
761
  readonly closedAt: Schema.optionalKey<Schema.Finite>;
630
762
  readonly forkedFrom: Schema.optionalKey<Schema.brand<Schema.String, "StreamId">>;
631
- readonly forkOffset: Schema.optionalKey<Schema.brand<Schema.String, "Offset">>;
763
+ readonly forkOffset: Schema.optionalKey<Schema.brand<Schema.brand<Schema.String, "Offset">, "StreamsyOffset">>;
632
764
  readonly forkSubOffset: Schema.optionalKey<Schema.Finite>;
633
765
  readonly softDeleted: Schema.Boolean;
634
766
  readonly expiresAtMs: Schema.optionalKey<Schema.Finite>;
635
767
  }>;
636
- readonly currentOffset: Schema.brand<Schema.String, "Offset">;
768
+ readonly currentOffset: Schema.brand<Schema.brand<Schema.String, "Offset">, "StreamsyOffset">;
637
769
  }>;
638
770
  }>, Schema.TaggedStruct<"Appended", {
639
771
  readonly record: Schema.Struct<{
@@ -649,12 +781,12 @@ declare const MutationApplied: Schema.TaggedStruct<"Applied", {
649
781
  readonly closed: Schema.Boolean;
650
782
  readonly closedAt: Schema.optionalKey<Schema.Finite>;
651
783
  readonly forkedFrom: Schema.optionalKey<Schema.brand<Schema.String, "StreamId">>;
652
- readonly forkOffset: Schema.optionalKey<Schema.brand<Schema.String, "Offset">>;
784
+ readonly forkOffset: Schema.optionalKey<Schema.brand<Schema.brand<Schema.String, "Offset">, "StreamsyOffset">>;
653
785
  readonly forkSubOffset: Schema.optionalKey<Schema.Finite>;
654
786
  readonly softDeleted: Schema.Boolean;
655
787
  readonly expiresAtMs: Schema.optionalKey<Schema.Finite>;
656
788
  }>;
657
- readonly currentOffset: Schema.brand<Schema.String, "Offset">;
789
+ readonly currentOffset: Schema.brand<Schema.brand<Schema.String, "Offset">, "StreamsyOffset">;
658
790
  }>;
659
791
  }>, Schema.TaggedStruct<"Purged", {
660
792
  readonly record: Schema.Struct<{
@@ -670,12 +802,12 @@ declare const MutationApplied: Schema.TaggedStruct<"Applied", {
670
802
  readonly closed: Schema.Boolean;
671
803
  readonly closedAt: Schema.optionalKey<Schema.Finite>;
672
804
  readonly forkedFrom: Schema.optionalKey<Schema.brand<Schema.String, "StreamId">>;
673
- readonly forkOffset: Schema.optionalKey<Schema.brand<Schema.String, "Offset">>;
805
+ readonly forkOffset: Schema.optionalKey<Schema.brand<Schema.brand<Schema.String, "Offset">, "StreamsyOffset">>;
674
806
  readonly forkSubOffset: Schema.optionalKey<Schema.Finite>;
675
807
  readonly softDeleted: Schema.Boolean;
676
808
  readonly expiresAtMs: Schema.optionalKey<Schema.Finite>;
677
809
  }>;
678
- readonly currentOffset: Schema.brand<Schema.String, "Offset">;
810
+ readonly currentOffset: Schema.brand<Schema.brand<Schema.String, "Offset">, "StreamsyOffset">;
679
811
  }>;
680
812
  }>, Schema.TaggedStruct<"SoftDeleted", {
681
813
  readonly record: Schema.Struct<{
@@ -691,12 +823,12 @@ declare const MutationApplied: Schema.TaggedStruct<"Applied", {
691
823
  readonly closed: Schema.Boolean;
692
824
  readonly closedAt: Schema.optionalKey<Schema.Finite>;
693
825
  readonly forkedFrom: Schema.optionalKey<Schema.brand<Schema.String, "StreamId">>;
694
- readonly forkOffset: Schema.optionalKey<Schema.brand<Schema.String, "Offset">>;
826
+ readonly forkOffset: Schema.optionalKey<Schema.brand<Schema.brand<Schema.String, "Offset">, "StreamsyOffset">>;
695
827
  readonly forkSubOffset: Schema.optionalKey<Schema.Finite>;
696
828
  readonly softDeleted: Schema.Boolean;
697
829
  readonly expiresAtMs: Schema.optionalKey<Schema.Finite>;
698
830
  }>;
699
- readonly currentOffset: Schema.brand<Schema.String, "Offset">;
831
+ readonly currentOffset: Schema.brand<Schema.brand<Schema.String, "Offset">, "StreamsyOffset">;
700
832
  }>;
701
833
  }>]>>;
702
834
  }>;
@@ -716,12 +848,12 @@ declare const MutationRejected_base: Schema.Class<MutationRejected, Schema.Tagge
716
848
  readonly closed: Schema.Boolean;
717
849
  readonly closedAt: Schema.optionalKey<Schema.Finite>;
718
850
  readonly forkedFrom: Schema.optionalKey<Schema.brand<Schema.String, "StreamId">>;
719
- readonly forkOffset: Schema.optionalKey<Schema.brand<Schema.String, "Offset">>;
851
+ readonly forkOffset: Schema.optionalKey<Schema.brand<Schema.brand<Schema.String, "Offset">, "StreamsyOffset">>;
720
852
  readonly forkSubOffset: Schema.optionalKey<Schema.Finite>;
721
853
  readonly softDeleted: Schema.Boolean;
722
854
  readonly expiresAtMs: Schema.optionalKey<Schema.Finite>;
723
855
  }>;
724
- readonly currentOffset: Schema.brand<Schema.String, "Offset">;
856
+ readonly currentOffset: Schema.brand<Schema.brand<Schema.String, "Offset">, "StreamsyOffset">;
725
857
  }>>;
726
858
  }>, import("effect/Cause").YieldableError>;
727
859
  declare class MutationRejected extends MutationRejected_base {}
@@ -749,32 +881,32 @@ declare const Operations: Data.TaggedEnum.Constructor<{
749
881
  readonly closed: boolean;
750
882
  readonly closedAt?: number | undefined;
751
883
  readonly forkedFrom?: (string & import("effect/Brand").Brand<"StreamId">) | undefined;
752
- readonly forkOffset?: (string & import("effect/Brand").Brand<"Offset">) | undefined;
884
+ readonly forkOffset?: (string & import("effect/Brand").Brand<"Offset"> & import("effect/Brand").Brand<"StreamsyOffset">) | undefined;
753
885
  readonly forkSubOffset?: number | undefined;
754
886
  readonly softDeleted: boolean;
755
887
  readonly expiresAtMs?: number | undefined;
756
888
  };
757
- readonly currentOffset: string & import("effect/Brand").Brand<"Offset">;
889
+ readonly currentOffset: string & import("effect/Brand").Brand<"Offset"> & import("effect/Brand").Brand<"StreamsyOffset">;
758
890
  };
759
891
  readonly initialMessages: readonly {
760
- readonly offset: string & import("effect/Brand").Brand<"Offset">;
892
+ readonly offset: string & import("effect/Brand").Brand<"Offset"> & import("effect/Brand").Brand<"StreamsyOffset">;
761
893
  readonly timestamp: number;
762
894
  readonly data: Uint8Array<ArrayBufferLike>;
763
895
  }[];
764
896
  readonly forkSource?: {
765
897
  readonly id: string & import("effect/Brand").Brand<"StreamId">;
766
- readonly liveAtOffset: string & import("effect/Brand").Brand<"Offset">;
898
+ readonly liveAtOffset: string & import("effect/Brand").Brand<"Offset"> & import("effect/Brand").Brand<"StreamsyOffset">;
767
899
  } | undefined;
768
900
  } | {
769
901
  readonly _tag: "Append";
770
902
  readonly streamId: string & import("effect/Brand").Brand<"StreamId">;
771
903
  readonly messages: readonly {
772
- readonly offset: string & import("effect/Brand").Brand<"Offset">;
904
+ readonly offset: string & import("effect/Brand").Brand<"Offset"> & import("effect/Brand").Brand<"StreamsyOffset">;
773
905
  readonly timestamp: number;
774
906
  readonly data: Uint8Array<ArrayBufferLike>;
775
907
  }[];
776
908
  readonly patch: {
777
- readonly currentOffset?: (string & import("effect/Brand").Brand<"Offset">) | undefined;
909
+ readonly currentOffset?: (string & import("effect/Brand").Brand<"Offset"> & import("effect/Brand").Brand<"StreamsyOffset">) | undefined;
778
910
  readonly config?: {
779
911
  readonly ttlSeconds?: number | undefined;
780
912
  readonly expiresAt?: string | undefined;
@@ -783,7 +915,7 @@ declare const Operations: Data.TaggedEnum.Constructor<{
783
915
  readonly lastSeq?: string | undefined;
784
916
  readonly closedAt?: number | undefined;
785
917
  readonly forkedFrom?: (string & import("effect/Brand").Brand<"StreamId">) | undefined;
786
- readonly forkOffset?: (string & import("effect/Brand").Brand<"Offset">) | undefined;
918
+ readonly forkOffset?: (string & import("effect/Brand").Brand<"Offset"> & import("effect/Brand").Brand<"StreamsyOffset">) | undefined;
787
919
  readonly forkSubOffset?: number | undefined;
788
920
  readonly expiresAtMs?: number | undefined;
789
921
  readonly closed?: boolean | undefined;
@@ -791,7 +923,7 @@ declare const Operations: Data.TaggedEnum.Constructor<{
791
923
  } | undefined;
792
924
  readonly clear?: readonly ("expiresAt" | "expiresAtMs" | "lastSeq" | "ttlSeconds")[] | undefined;
793
925
  };
794
- readonly expectedOffset?: (string & import("effect/Brand").Brand<"Offset">) | undefined;
926
+ readonly expectedOffset?: (string & import("effect/Brand").Brand<"Offset"> & import("effect/Brand").Brand<"StreamsyOffset">) | undefined;
795
927
  readonly expectedClosed?: boolean | undefined;
796
928
  readonly producer?: {
797
929
  readonly producerId: string & import("effect/Brand").Brand<"ProducerId">;
@@ -825,12 +957,12 @@ declare const OperationResults: Data.TaggedEnum.Constructor<{
825
957
  readonly closed: boolean;
826
958
  readonly closedAt?: number | undefined;
827
959
  readonly forkedFrom?: (string & import("effect/Brand").Brand<"StreamId">) | undefined;
828
- readonly forkOffset?: (string & import("effect/Brand").Brand<"Offset">) | undefined;
960
+ readonly forkOffset?: (string & import("effect/Brand").Brand<"Offset"> & import("effect/Brand").Brand<"StreamsyOffset">) | undefined;
829
961
  readonly forkSubOffset?: number | undefined;
830
962
  readonly softDeleted: boolean;
831
963
  readonly expiresAtMs?: number | undefined;
832
964
  };
833
- readonly currentOffset: string & import("effect/Brand").Brand<"Offset">;
965
+ readonly currentOffset: string & import("effect/Brand").Brand<"Offset"> & import("effect/Brand").Brand<"StreamsyOffset">;
834
966
  };
835
967
  } | {
836
968
  readonly _tag: "Appended";
@@ -847,12 +979,12 @@ declare const OperationResults: Data.TaggedEnum.Constructor<{
847
979
  readonly closed: boolean;
848
980
  readonly closedAt?: number | undefined;
849
981
  readonly forkedFrom?: (string & import("effect/Brand").Brand<"StreamId">) | undefined;
850
- readonly forkOffset?: (string & import("effect/Brand").Brand<"Offset">) | undefined;
982
+ readonly forkOffset?: (string & import("effect/Brand").Brand<"Offset"> & import("effect/Brand").Brand<"StreamsyOffset">) | undefined;
851
983
  readonly forkSubOffset?: number | undefined;
852
984
  readonly softDeleted: boolean;
853
985
  readonly expiresAtMs?: number | undefined;
854
986
  };
855
- readonly currentOffset: string & import("effect/Brand").Brand<"Offset">;
987
+ readonly currentOffset: string & import("effect/Brand").Brand<"Offset"> & import("effect/Brand").Brand<"StreamsyOffset">;
856
988
  };
857
989
  } | {
858
990
  readonly _tag: "Purged";
@@ -869,12 +1001,12 @@ declare const OperationResults: Data.TaggedEnum.Constructor<{
869
1001
  readonly closed: boolean;
870
1002
  readonly closedAt?: number | undefined;
871
1003
  readonly forkedFrom?: (string & import("effect/Brand").Brand<"StreamId">) | undefined;
872
- readonly forkOffset?: (string & import("effect/Brand").Brand<"Offset">) | undefined;
1004
+ readonly forkOffset?: (string & import("effect/Brand").Brand<"Offset"> & import("effect/Brand").Brand<"StreamsyOffset">) | undefined;
873
1005
  readonly forkSubOffset?: number | undefined;
874
1006
  readonly softDeleted: boolean;
875
1007
  readonly expiresAtMs?: number | undefined;
876
1008
  };
877
- readonly currentOffset: string & import("effect/Brand").Brand<"Offset">;
1009
+ readonly currentOffset: string & import("effect/Brand").Brand<"Offset"> & import("effect/Brand").Brand<"StreamsyOffset">;
878
1010
  };
879
1011
  } | {
880
1012
  readonly _tag: "SoftDeleted";
@@ -891,12 +1023,12 @@ declare const OperationResults: Data.TaggedEnum.Constructor<{
891
1023
  readonly closed: boolean;
892
1024
  readonly closedAt?: number | undefined;
893
1025
  readonly forkedFrom?: (string & import("effect/Brand").Brand<"StreamId">) | undefined;
894
- readonly forkOffset?: (string & import("effect/Brand").Brand<"Offset">) | undefined;
1026
+ readonly forkOffset?: (string & import("effect/Brand").Brand<"Offset"> & import("effect/Brand").Brand<"StreamsyOffset">) | undefined;
895
1027
  readonly forkSubOffset?: number | undefined;
896
1028
  readonly softDeleted: boolean;
897
1029
  readonly expiresAtMs?: number | undefined;
898
1030
  };
899
- readonly currentOffset: string & import("effect/Brand").Brand<"Offset">;
1031
+ readonly currentOffset: string & import("effect/Brand").Brand<"Offset"> & import("effect/Brand").Brand<"StreamsyOffset">;
900
1032
  };
901
1033
  }>;
902
1034
  declare const Mutations: Data.TaggedEnum.Constructor<{
@@ -916,12 +1048,12 @@ declare const Mutations: Data.TaggedEnum.Constructor<{
916
1048
  readonly closed: boolean;
917
1049
  readonly closedAt?: number | undefined;
918
1050
  readonly forkedFrom?: (string & import("effect/Brand").Brand<"StreamId">) | undefined;
919
- readonly forkOffset?: (string & import("effect/Brand").Brand<"Offset">) | undefined;
1051
+ readonly forkOffset?: (string & import("effect/Brand").Brand<"Offset"> & import("effect/Brand").Brand<"StreamsyOffset">) | undefined;
920
1052
  readonly forkSubOffset?: number | undefined;
921
1053
  readonly softDeleted: boolean;
922
1054
  readonly expiresAtMs?: number | undefined;
923
1055
  };
924
- readonly currentOffset: string & import("effect/Brand").Brand<"Offset">;
1056
+ readonly currentOffset: string & import("effect/Brand").Brand<"Offset"> & import("effect/Brand").Brand<"StreamsyOffset">;
925
1057
  };
926
1058
  } | {
927
1059
  readonly _tag: "Appended";
@@ -938,12 +1070,12 @@ declare const Mutations: Data.TaggedEnum.Constructor<{
938
1070
  readonly closed: boolean;
939
1071
  readonly closedAt?: number | undefined;
940
1072
  readonly forkedFrom?: (string & import("effect/Brand").Brand<"StreamId">) | undefined;
941
- readonly forkOffset?: (string & import("effect/Brand").Brand<"Offset">) | undefined;
1073
+ readonly forkOffset?: (string & import("effect/Brand").Brand<"Offset"> & import("effect/Brand").Brand<"StreamsyOffset">) | undefined;
942
1074
  readonly forkSubOffset?: number | undefined;
943
1075
  readonly softDeleted: boolean;
944
1076
  readonly expiresAtMs?: number | undefined;
945
1077
  };
946
- readonly currentOffset: string & import("effect/Brand").Brand<"Offset">;
1078
+ readonly currentOffset: string & import("effect/Brand").Brand<"Offset"> & import("effect/Brand").Brand<"StreamsyOffset">;
947
1079
  };
948
1080
  } | {
949
1081
  readonly _tag: "Purged";
@@ -960,12 +1092,12 @@ declare const Mutations: Data.TaggedEnum.Constructor<{
960
1092
  readonly closed: boolean;
961
1093
  readonly closedAt?: number | undefined;
962
1094
  readonly forkedFrom?: (string & import("effect/Brand").Brand<"StreamId">) | undefined;
963
- readonly forkOffset?: (string & import("effect/Brand").Brand<"Offset">) | undefined;
1095
+ readonly forkOffset?: (string & import("effect/Brand").Brand<"Offset"> & import("effect/Brand").Brand<"StreamsyOffset">) | undefined;
964
1096
  readonly forkSubOffset?: number | undefined;
965
1097
  readonly softDeleted: boolean;
966
1098
  readonly expiresAtMs?: number | undefined;
967
1099
  };
968
- readonly currentOffset: string & import("effect/Brand").Brand<"Offset">;
1100
+ readonly currentOffset: string & import("effect/Brand").Brand<"Offset"> & import("effect/Brand").Brand<"StreamsyOffset">;
969
1101
  };
970
1102
  } | {
971
1103
  readonly _tag: "SoftDeleted";
@@ -982,12 +1114,12 @@ declare const Mutations: Data.TaggedEnum.Constructor<{
982
1114
  readonly closed: boolean;
983
1115
  readonly closedAt?: number | undefined;
984
1116
  readonly forkedFrom?: (string & import("effect/Brand").Brand<"StreamId">) | undefined;
985
- readonly forkOffset?: (string & import("effect/Brand").Brand<"Offset">) | undefined;
1117
+ readonly forkOffset?: (string & import("effect/Brand").Brand<"Offset"> & import("effect/Brand").Brand<"StreamsyOffset">) | undefined;
986
1118
  readonly forkSubOffset?: number | undefined;
987
1119
  readonly softDeleted: boolean;
988
1120
  readonly expiresAtMs?: number | undefined;
989
1121
  };
990
- readonly currentOffset: string & import("effect/Brand").Brand<"Offset">;
1122
+ readonly currentOffset: string & import("effect/Brand").Brand<"Offset"> & import("effect/Brand").Brand<"StreamsyOffset">;
991
1123
  };
992
1124
  }, ...({
993
1125
  readonly _tag: "Created";
@@ -1004,12 +1136,12 @@ declare const Mutations: Data.TaggedEnum.Constructor<{
1004
1136
  readonly closed: boolean;
1005
1137
  readonly closedAt?: number | undefined;
1006
1138
  readonly forkedFrom?: (string & import("effect/Brand").Brand<"StreamId">) | undefined;
1007
- readonly forkOffset?: (string & import("effect/Brand").Brand<"Offset">) | undefined;
1139
+ readonly forkOffset?: (string & import("effect/Brand").Brand<"Offset"> & import("effect/Brand").Brand<"StreamsyOffset">) | undefined;
1008
1140
  readonly forkSubOffset?: number | undefined;
1009
1141
  readonly softDeleted: boolean;
1010
1142
  readonly expiresAtMs?: number | undefined;
1011
1143
  };
1012
- readonly currentOffset: string & import("effect/Brand").Brand<"Offset">;
1144
+ readonly currentOffset: string & import("effect/Brand").Brand<"Offset"> & import("effect/Brand").Brand<"StreamsyOffset">;
1013
1145
  };
1014
1146
  } | {
1015
1147
  readonly _tag: "Appended";
@@ -1026,12 +1158,12 @@ declare const Mutations: Data.TaggedEnum.Constructor<{
1026
1158
  readonly closed: boolean;
1027
1159
  readonly closedAt?: number | undefined;
1028
1160
  readonly forkedFrom?: (string & import("effect/Brand").Brand<"StreamId">) | undefined;
1029
- readonly forkOffset?: (string & import("effect/Brand").Brand<"Offset">) | undefined;
1161
+ readonly forkOffset?: (string & import("effect/Brand").Brand<"Offset"> & import("effect/Brand").Brand<"StreamsyOffset">) | undefined;
1030
1162
  readonly forkSubOffset?: number | undefined;
1031
1163
  readonly softDeleted: boolean;
1032
1164
  readonly expiresAtMs?: number | undefined;
1033
1165
  };
1034
- readonly currentOffset: string & import("effect/Brand").Brand<"Offset">;
1166
+ readonly currentOffset: string & import("effect/Brand").Brand<"Offset"> & import("effect/Brand").Brand<"StreamsyOffset">;
1035
1167
  };
1036
1168
  } | {
1037
1169
  readonly _tag: "Purged";
@@ -1048,12 +1180,12 @@ declare const Mutations: Data.TaggedEnum.Constructor<{
1048
1180
  readonly closed: boolean;
1049
1181
  readonly closedAt?: number | undefined;
1050
1182
  readonly forkedFrom?: (string & import("effect/Brand").Brand<"StreamId">) | undefined;
1051
- readonly forkOffset?: (string & import("effect/Brand").Brand<"Offset">) | undefined;
1183
+ readonly forkOffset?: (string & import("effect/Brand").Brand<"Offset"> & import("effect/Brand").Brand<"StreamsyOffset">) | undefined;
1052
1184
  readonly forkSubOffset?: number | undefined;
1053
1185
  readonly softDeleted: boolean;
1054
1186
  readonly expiresAtMs?: number | undefined;
1055
1187
  };
1056
- readonly currentOffset: string & import("effect/Brand").Brand<"Offset">;
1188
+ readonly currentOffset: string & import("effect/Brand").Brand<"Offset"> & import("effect/Brand").Brand<"StreamsyOffset">;
1057
1189
  };
1058
1190
  } | {
1059
1191
  readonly _tag: "SoftDeleted";
@@ -1070,12 +1202,12 @@ declare const Mutations: Data.TaggedEnum.Constructor<{
1070
1202
  readonly closed: boolean;
1071
1203
  readonly closedAt?: number | undefined;
1072
1204
  readonly forkedFrom?: (string & import("effect/Brand").Brand<"StreamId">) | undefined;
1073
- readonly forkOffset?: (string & import("effect/Brand").Brand<"Offset">) | undefined;
1205
+ readonly forkOffset?: (string & import("effect/Brand").Brand<"Offset"> & import("effect/Brand").Brand<"StreamsyOffset">) | undefined;
1074
1206
  readonly forkSubOffset?: number | undefined;
1075
1207
  readonly softDeleted: boolean;
1076
1208
  readonly expiresAtMs?: number | undefined;
1077
1209
  };
1078
- readonly currentOffset: string & import("effect/Brand").Brand<"Offset">;
1210
+ readonly currentOffset: string & import("effect/Brand").Brand<"Offset"> & import("effect/Brand").Brand<"StreamsyOffset">;
1079
1211
  };
1080
1212
  })[]];
1081
1213
  }>;
@@ -1100,157 +1232,4 @@ interface StorageShape {
1100
1232
  readonly streamId: StreamId;
1101
1233
  }>, StorageFault>;
1102
1234
  }
1103
- declare const Storage_base: Context.ServiceClass<Storage, "@streamsy/core/Storage", StorageShape>;
1104
- declare class Storage extends Storage_base {}
1105
- interface CommitBoundaryApi {
1106
- /**
1107
- * Run `body` in the storage owner's transaction. Nested calls on the same owner
1108
- * join without savepoints, so a failure must escape the outer body to roll back.
1109
- * Same-owner stream writes and records commit with application SQL on that client.
1110
- * With two boundaries over one SQL client, only the outer boundary's hooks and
1111
- * `committed` subscribers see the commit.
1112
- *
1113
- * A nested call on another SQL client opens its own transaction, as does a lone
1114
- * `Storage.mutate` on that client. Its commit comes first and survives an outer
1115
- * rollback. Use one client per database for nested work. With two clients on
1116
- * one database, SQLite can wait until it reports a busy lock. Postgres or MySQL
1117
- * can wait for a row lock that the outer transaction holds.
1118
- *
1119
- * Durable Object clients share the driver's transaction, so a second client
1120
- * joins the first. Using a second object's storage on one fiber is unsupported.
1121
- * `MemoryStorage` dies when work enters another `MemoryStorage` owner.
1122
- *
1123
- * Keep the body on the calling fiber, and do not wait in it for wakes that only
1124
- * its own commit publishes. Only SQL hosts fail with `SqlError`.
1125
- */
1126
- readonly withTransaction: <A, E, R>(body: Effect.Effect<A, E, R>) => Effect.Effect<A, E | SqlError.SqlError, R>;
1127
- }
1128
- declare const CommitBoundary_base: Context.ServiceClass<CommitBoundary, "@streamsy/core/CommitBoundary", CommitBoundaryApi>;
1129
- /** The transaction of the storage owner. Every Streamsy storage host provides it. */
1130
- declare class CommitBoundary extends CommitBoundary_base {}
1131
- /**
1132
- * Encoded records on the storage owner, for the projection checkpoint store.
1133
- * Calls inside `CommitBoundary.withTransaction` join that transaction.
1134
- */
1135
- interface OwnerRecordsApi {
1136
- readonly read: (key: string) => Effect.Effect<Option.Option<string>, StorageFault>;
1137
- /**
1138
- * A snapshot of the owner's encoded entries whose keys start with this exact prefix.
1139
- * A store that cannot list fails with operation `OWNER_RECORDS_LIST_UNSUPPORTED`.
1140
- */
1141
- readonly list: (prefix: string) => Effect.Effect<ReadonlyArray<readonly [key: string, encoded: string]>, StorageFault>;
1142
- readonly write: (key: string, encoded: string) => Effect.Effect<void, StorageFault>;
1143
- readonly remove: (key: string) => Effect.Effect<void, StorageFault>;
1144
- }
1145
- /** The `StorageFault.operation` of an owner store that cannot list its records. */
1146
- declare const OWNER_RECORDS_LIST_UNSUPPORTED = "records.list.unsupported";
1147
- declare const OwnerRecords_base: Context.ServiceClass<OwnerRecords, "@streamsy/core/internal/OwnerRecords", OwnerRecordsApi>;
1148
- declare class OwnerRecords extends OwnerRecords_base {}
1149
- /**
1150
- * Work that joins an owned transaction just before it commits. It receives the
1151
- * stream ids that the transaction created, appended to or deleted.
1152
- */
1153
- type CommitHook = (ids: ReadonlySet<StreamId>) => Effect.Effect<void, SqlError.SqlError>;
1154
- /**
1155
- * Commit hooks on the storage owner, for the durable projection marks.
1156
- *
1157
- * A hook runs inside each later owned transaction that wrote at least one stream
1158
- * id, after the body and before COMMIT. Statements in the hook join the
1159
- * transaction, and a hook failure rolls the transaction back. A SQL host treats
1160
- * a hook failure like a body failure, so a retryable `SqlError` replays the
1161
- * whole transaction, hook included. The memory host turns a hook failure into a
1162
- * defect. A hook must not write streams: its ids would not reach other hooks.
1163
- */
1164
- interface CommitHooksApi {
1165
- /** Register `hook` until the scope closes. */
1166
- readonly beforeCommit: (hook: CommitHook) => Effect.Effect<void, never, Scope.Scope>;
1167
- }
1168
- declare const CommitHooks_base: Context.ServiceClass<CommitHooks, "@streamsy/core/internal/CommitHooks", CommitHooksApi>;
1169
- declare class CommitHooks extends CommitHooks_base {}
1170
- /** Shared registry for storage boundaries: register in a scope, run in order. */
1171
- declare const commitHookRegistry: () => {
1172
- beforeCommit: (hook: CommitHook) => Effect.Effect<void, never, Scope.Scope>;
1173
- run: (ids: ReadonlySet<StreamId>) => Effect.Effect<void, SqlError.SqlError>;
1174
- };
1175
- /** Last failed run, retained through marks, retries and resumes. Messages hold at most 1,000 characters. */
1176
- interface MarkFailure {
1177
- readonly at: number;
1178
- readonly reason: Option.Option<string>;
1179
- readonly message: string;
1180
- }
1181
- /** One pending mark: a binding with input work, a retry, or a recorded wake. */
1182
- interface PendingMark {
1183
- /** The binding's canonical params, as `canonicalParams` encodes them. */
1184
- readonly params: string;
1185
- /** Raised by every mark. A clear only deletes the row when its `seq` still matches. */
1186
- readonly seq: number;
1187
- /** Failed runs since the last success. A mark keeps it. */
1188
- readonly attempts: number;
1189
- /** Epoch ms. 0 means due now; ignored while stopped. */
1190
- readonly dueAt: number;
1191
- /** Recorded wake; when set, equals dueAt and the row has no failure or attempts. */
1192
- readonly wakeAt: Option.Option<number>;
1193
- /** Waits until retry or resume. A mark preserves the stop. */
1194
- readonly stopped: boolean;
1195
- readonly failure: Option.Option<MarkFailure>;
1196
- }
1197
- /** Disjoint counts of one projection's marks at the supplied time. */
1198
- interface ProjectionMarkSummary {
1199
- readonly fresh: number;
1200
- readonly sleeping: number;
1201
- readonly retryDue: number;
1202
- readonly backingOff: number;
1203
- readonly stopped: number;
1204
- /** Earliest due time across non-stopped marks, including fresh and sleeping marks. */
1205
- readonly nextDueAt: Option.Option<number>;
1206
- }
1207
- /**
1208
- * Pending marks for attached projections, on a storage owner or in private memory.
1209
- *
1210
- * A mark is keyed by projection id and canonical params. A deploy that raises the
1211
- * generation picks up the existing marks.
1212
- */
1213
- interface ProjectionMarksApi {
1214
- /** Maximum projection id length in Unicode code points, when bounded by storage. */
1215
- readonly maxProjectionIdLength?: number;
1216
- /**
1217
- * Insert a mark for each binding, or raise its `seq`. A raise keeps
1218
- * `attempts`, `stopped` and `failure`, so a write never resets backoff or a stop.
1219
- * A sleeping row becomes due now and loses its wake index.
1220
- * Call it inside a commit hook. It joins the transaction and fails like the
1221
- * transaction's own statements.
1222
- */
1223
- readonly mark: (projection: string, params: ReadonlyArray<string>) => Effect.Effect<void, SqlError.SqlError>;
1224
- /** The earliest `dueAt` of the projection's non-stopped marks. */
1225
- readonly nextDue: (projection: string) => Effect.Effect<Option.Option<number>, StorageFault>;
1226
- /** Five disjoint counts: fresh, sleeping, retry due, backing off and stopped. */
1227
- readonly summary: (projection: string, now: number) => Effect.Effect<ProjectionMarkSummary, StorageFault>;
1228
- /** Up to `limit` non-stopped marks with `dueAt <= now`, earliest first. */
1229
- readonly due: (projection: string, now: number, limit: number) => Effect.Effect<ReadonlyArray<PendingMark>, StorageFault>;
1230
- /** The marks of these bindings that exist, keyed by params. */
1231
- readonly read: (projection: string, params: ReadonlyArray<string>) => Effect.Effect<ReadonlyMap<string, PendingMark>, StorageFault>;
1232
- /** Delete on a matching `seq`; otherwise keep the row and reset its failure, attempts, dueAt, wakeAt and stop. */
1233
- readonly clear: (projection: string, params: string, seq: number) => Effect.Effect<void, StorageFault>;
1234
- /** Keep a matching row asleep at wakeAt and reset failure state. A seq mismatch
1235
- * becomes fresh and due now. An absent row is inserted asleep with seq 1. */
1236
- readonly sleep: (projection: string, params: string, seq: number, wakeAt: number) => Effect.Effect<void, StorageFault>;
1237
- /** Delete the mark whatever its `seq`. */
1238
- readonly remove: (projection: string, params: string) => Effect.Effect<void, StorageFault>;
1239
- /** Insert or update a failure, preserving seq. Some(dueAt) backs off; None stops. */
1240
- readonly fail: (projection: string, params: string, options: {
1241
- readonly attempts: number;
1242
- readonly failure: MarkFailure;
1243
- readonly dueAt: Option.Option<number>;
1244
- }) => Effect.Effect<void, StorageFault>;
1245
- /** Set failed or stopped marks due now and clear their stop, preserving attempts, seq and failure.
1246
- * Optionally select one binding. Returns the number changed; already due, non-stopped marks are unchanged.
1247
- */
1248
- readonly retry: (projection: string, params?: string) => Effect.Effect<number, StorageFault>;
1249
- /** Make stopped marks due now, preserving attempts, seq and failure. Returns the number changed. */
1250
- readonly resume: (projection: string) => Effect.Effect<number, StorageFault>;
1251
- /** Up to limit marks with attempts > 0, stopped first, then by dueAt and params. */
1252
- readonly failed: (projection: string, limit: number) => Effect.Effect<ReadonlyArray<PendingMark>, StorageFault>;
1253
- }
1254
- declare const ProjectionMarks_base: Context.ServiceClass<ProjectionMarks, "@streamsy/core/internal/ProjectionMarks", ProjectionMarksApi>;
1255
- declare class ProjectionMarks extends ProjectionMarks_base {}
1256
- export { ProducerGap as $, Writer as A, StreamsFault as At, AppendErrorFor as B, OperationResults as C, StreamConfig as Ct, Reader as D, DecodeFault as Dt, StorageCapabilities as E, StreamRecord as Et, ReadNextResult as F, HeadError as G, CreateConflictReason as H, ReadResult as I, InvalidEpochSeq as J, InvalidAppendRequest as K, AppendBaseError as L, CreateResult as M, isRetryableFault as Mt, HeadResult as N, isStreamsFault as Nt, StreamsReader as O, EncodeFault as Ot, ReadMessage as P, OffsetMismatch as Q, AppendConflict as R, OperationResult as S, StoredMessage as St, ProducerPrecondition as T, StreamLifecycle as Tt, CreateError as U, CreateConflict as V, ForkSourceNotFound as W, InvalidReadRequest as X, InvalidForkRequest as Y, NotSupported as Z, Mutation as _, MessageWindow as _t, ProjectionMarksApi as a, StreamBusy as at, Mutations as b, ProducerState as bt, CommitHooksApi as c, StreamNotFound as ct, OwnerRecords as d, AppendOptions as dt, ProtocolError as et, OwnerRecordsApi as f, ProducerOptions as ft, StorageShape as g, ChangeSnapshot as gt, Storage as h, CreateOptions as ht, ProjectionMarks as i, StaleEpoch as it, AppendResult as j, TransportFault as jt, StreamsWriter as k, StorageFault as kt, commitHookRegistry as l, isProtocolError as lt, CommitBoundaryApi as m, ReadOptions as mt, PendingMark as n, ReadNextError as nt, CommitHook as o, StreamClosed as ot, CommitBoundary as p, ReadNextOptions as pt, InvalidCreateRequest as q, ProjectionMarkSummary as r, RemoveError as rt, CommitHooks as s, StreamGone as st, MarkFailure as t, ReadError as tt, OWNER_RECORDS_LIST_UNSUPPORTED as u, AppendCallOptions as ut, MutationApplied as v, Offset as vt, Operations as w, StreamId as wt, Operation as x, RecordPatch as xt, MutationRejected as y, ProducerId as yt, AppendError as z };
1235
+ export { StreamsFault as $, ReadResult as A, ProducerId as B, StorageOwnerApi as C, HeadResult as D, CreateResult as E, ReadOptions as F, StreamId as G, RecordPatch as H, StartOffset as I, StreamsyOffset as J, StreamLifecycle as K, ChangeSnapshot as L, AppendOptions as M, ProducerOptions as N, ReadMessage as O, ReadNextOptions as P, StorageFault as Q, MessageWindow as R, StorageOwner as S, AppendResult as T, StoredMessage as U, ProducerState as V, StreamConfig as W, EncodeFault as X, DecodeFault as Y, InvalidStreamParams as Z, CollectionsEncodingServices as _, Mutations as a, durable_state_d_exports as b, OperationResults as c, StateAddress as d, TransportFault as et, StreamAddress as f, CollectionsEncodedEvent as g, CollectionsDecodingServices as h, MutationRejected as i, AppendCallOptions as j, ReadNextResult as k, Operations as l, Collections as m, Mutation as n, isStreamsFault as nt, Operation as o, address_d_exports as p, StreamRecord as q, MutationApplied as r, OperationResult as s, StorageShape as t, isRetryableFault as tt, ProducerPrecondition as u, CollectionsEvent as v, StorageCapabilities as w, OwnerId as x, ValidCollections as y, Offset as z };