@streamsy/core 0.4.0 → 0.6.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,14 +1,14 @@
1
- import { t as __exportAll } from "../rolldown-runtime-D7D4PA-g.js";
2
- import { A as StreamsReader, C as ProducerGap, D as StreamGone, E as StreamClosed, O as StreamNotFound, Q as StreamId, S as OffsetMismatch, T as StreamBusy, V as TransportFault, _ as InvalidAppendRequest, b as InvalidReadRequest, f as AppendResult, g as ForkSourceNotFound, h as CreateConflict, j as StreamsWriter, m as AppendConflict, n as bind, p as CreateResult, w as StaleEpoch, x as NotSupported, y as InvalidForkRequest } from "../streamsy-OjRubIPC.js";
3
- import { Context, DateTime, Effect, Fiber, Layer, Option, Schema, Scope, Stream } from "effect";
1
+ import { t as __exportAll } from "../rolldown-runtime-D8jQpDG7.js";
2
+ import { A as StreamClosed, C as InvalidForkRequest, D as ProducerGap, E as OffsetMismatch, F as StreamsWriter, G as TransportFault, M as StreamNotFound, O as StaleEpoch, P as StreamsReader, T as NotSupported, _ as CreateResult, b as ForkSourceNotFound, g as AppendResult, j as StreamGone, k as StreamBusy, n as bind, nt as StreamId, v as AppendConflict, w as InvalidReadRequest, x as InvalidAppendRequest, y as CreateConflict } from "../streamsy-D9OCCdw0.js";
3
+ import { Array, Context, DateTime, Effect, Fiber, Layer, Option, Schema, Scope, Stream } from "effect";
4
4
  import { HttpClient, HttpClientRequest } from "effect/http";
5
- //#region src/remote/request.ts
5
+ // src/remote/request.ts
6
6
  function requests(options) {
7
7
  const base = new URL(options.baseUrl);
8
8
  if (!/^https?:$/.test(base.protocol) || base.search || base.hash || base.username || base.password) throw new TypeError("baseUrl must be an HTTP(S) URL without credentials, query or fragment");
9
9
  const prefix = base.pathname.replace(/\/$/, "") + "/";
10
10
  const url = (id) => {
11
- if (!id || id.split("/").some((part) => !part || part === "." || part === "..") || /[%?#\\]/.test(id)) throw new TypeError("Stream ID must be a canonical relative path");
11
+ if (!id || Array.some(id.split("/"), (part) => !part || part === "." || part === "..") || /[%?#\\]/.test(id)) throw new TypeError("Stream ID must be a canonical relative path");
12
12
  const target = new URL(base);
13
13
  target.pathname = prefix + id;
14
14
  if (target.pathname !== prefix + id) throw new TypeError("Stream ID must be URL-safe");
@@ -60,8 +60,7 @@ function requests(options) {
60
60
  }
61
61
  };
62
62
  }
63
- //#endregion
64
- //#region src/remote/wire.ts
63
+ // src/remote/wire.ts
65
64
  /**
66
65
  * Standard Durable Streams HTTP response primitives.
67
66
  *
@@ -114,7 +113,7 @@ const integer = (operation, name, value) => {
114
113
  return Effect.succeed(Number(value));
115
114
  };
116
115
  const body = (operation, response) => response.stream.pipe(Stream.runCollect, Effect.map((chunks) => {
117
- const bytes = new Uint8Array(chunks.reduce((size, chunk) => size + chunk.length, 0));
116
+ const bytes = new Uint8Array(Array.reduce(chunks, 0, (size, chunk) => size + chunk.length));
118
117
  let position = 0;
119
118
  for (const chunk of chunks) {
120
119
  bytes.set(chunk, position);
@@ -147,9 +146,8 @@ const readMessages = (operation, response, bytes) => {
147
146
  }));
148
147
  };
149
148
  const jsonArray = Schema.fromJsonString(Schema.Array(Schema.Unknown));
150
- const jsonMessages = (operation, decoded) => Schema.decodeEffect(jsonArray)(decoded).pipe(Effect.mapError((cause) => failure(operation, "decode", "Read body is not a JSON array", cause)), Effect.map((items) => items.map((item) => ({ data: new TextEncoder().encode(JSON.stringify(item)) }))));
151
- //#endregion
152
- //#region src/remote/response.ts
149
+ const jsonMessages = (operation, decoded) => Schema.decodeEffect(jsonArray)(decoded).pipe(Effect.mapError((cause) => failure(operation, "decode", "Read body is not a JSON array", cause)), Effect.map((items) => Array.map(items, (item) => ({ data: new TextEncoder().encode(JSON.stringify(item)) }))));
150
+ // src/remote/response.ts
153
151
  /** Decode standard HTTP successes and fail with the protocol details carried by the wire. */
154
152
  const emptyToUndefined = (value) => {
155
153
  const trimmed = value.trim();
@@ -342,8 +340,7 @@ const remove = (operation, response, context) => Effect.gen(function* () {
342
340
  if (response.status === 503) return yield* new StreamBusy({ id: context.id });
343
341
  return yield* unexpected(operation, response);
344
342
  });
345
- //#endregion
346
- //#region src/remote/streams.ts
343
+ // src/remote/streams.ts
347
344
  var streams_exports = /* @__PURE__ */ __exportAll({
348
345
  TransportFault: () => TransportFault,
349
346
  layer: () => layer,
@@ -424,5 +421,4 @@ function layer(group, options) {
424
421
  const protocol = layerProtocol(options);
425
422
  return bind(protocol, group);
426
423
  }
427
- //#endregion
428
424
  export { streams_exports as RemoteStreams };
@@ -1,4 +1,4 @@
1
- //#region \0rolldown/runtime.js
1
+ // \0rolldown/runtime.js
2
2
  var __defProp = Object.defineProperty;
3
3
  var __exportAll = (all, no_symbols) => {
4
4
  let target = {};
@@ -9,5 +9,4 @@ var __exportAll = (all, no_symbols) => {
9
9
  if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
10
10
  return target;
11
11
  };
12
- //#endregion
13
12
  export { __exportAll as t };
@@ -0,0 +1,93 @@
1
+ import { Context, Data, Effect, Predicate } from "effect";
2
+ // src/internal/owner.ts
3
+ /** Private bridge: a stream guard dies with this sentinel; the atomic runner translates it. */
4
+ const ForeignOwnerType = Symbol.for("@streamsy/core/internal/ForeignOwner");
5
+ var ForeignOwner = class extends Data.TaggedError("ForeignOwner") {
6
+ stream;
7
+ [ForeignOwnerType] = true;
8
+ constructor(stream, knownOwner) {
9
+ super({ message: knownOwner ? `Stream write to ${stream} does not share the checkpoint owner` : `Cannot establish a storage owner for ${stream}; the exposed Storage does not own the protocol wires` });
10
+ this.stream = stream;
11
+ }
12
+ };
13
+ const isForeignOwner = (value) => Predicate.hasProperty(value, ForeignOwnerType) && value[ForeignOwnerType] === true;
14
+ const OwnerMetadata = Symbol.for("@streamsy/core/internal/CommitOwner");
15
+ const attachOwner = (value, owner) => Object.defineProperty(value, OwnerMetadata, {
16
+ value: owner,
17
+ enumerable: false
18
+ });
19
+ const ownerOf = (value) => {
20
+ if (!(OwnerMetadata in value)) return value;
21
+ const owner = value[OwnerMetadata];
22
+ return Predicate.isObjectKeyword(owner) ? owner : value;
23
+ };
24
+ const CurrentOwner = Context.Reference("@streamsy/core/internal/CurrentOwner", { defaultValue: () => void 0 });
25
+ const checkWriteOwner = (owner, id, knownOwner) => Effect.flatMap(CurrentOwner, (expected) => expected === void 0 || expected === owner ? Effect.void : Effect.die(new ForeignOwner(id, knownOwner)));
26
+ const Metadata = Symbol.for("@streamsy/core/internal/StorageOwner");
27
+ const attachStorage = (wire, storage) => Object.defineProperty(wire, Metadata, {
28
+ value: storage,
29
+ enumerable: false
30
+ });
31
+ const storageOf = (wire) => {
32
+ if (!(Metadata in wire)) return void 0;
33
+ return wire[Metadata];
34
+ };
35
+ // src/toolkit/route-internal.ts
36
+ /** Ids are canonical relative paths, the same rule the remote Layer enforces. */
37
+ function isCanonicalIdSegment(value) {
38
+ if (value.length === 0 || value === "." || value === "..") return false;
39
+ return !/[%?#/\\]/.test(value);
40
+ }
41
+ function compileSegments(template) {
42
+ if (template.length === 0) throw new RangeError("a stream route template must name at least one segment");
43
+ if (template.startsWith("/")) throw new RangeError("a stream route template is relative and cannot start with a slash");
44
+ if (/[?#*]/.test(template)) throw new RangeError("a stream route template cannot contain a query, fragment, or wildcard");
45
+ const names = [];
46
+ const segments = [];
47
+ for (const part of template.split("/")) {
48
+ if (part.length === 0) throw new RangeError("a stream route template cannot contain an empty segment");
49
+ if (!part.startsWith(":")) {
50
+ if (!isCanonicalIdSegment(part)) throw new RangeError(`a stream route literal segment is not a canonical id segment: ${part}`);
51
+ segments.push({
52
+ kind: "literal",
53
+ value: part
54
+ });
55
+ continue;
56
+ }
57
+ const name = part.slice(1);
58
+ if (name.length === 0) throw new RangeError("a stream route parameter needs a name");
59
+ if (names.includes(name)) throw new RangeError(`duplicate stream route parameter: ${name}`);
60
+ names.push(name);
61
+ segments.push({
62
+ kind: "parameter",
63
+ name
64
+ });
65
+ }
66
+ return {
67
+ template,
68
+ segments: Object.freeze(segments),
69
+ names: Object.freeze(names)
70
+ };
71
+ }
72
+ /**
73
+ * True when two template routes can both match one id.
74
+ *
75
+ * Lengths must agree, and every position must be either an equal literal pair
76
+ * or a parameter on at least one side. A parameter is treated as matching any
77
+ * segment, so a codec-constrained parameter can report an overlap it would
78
+ * never actually match. A custom route carries no template and is never
79
+ * checked; HTTP dispatch uses declaration order and the first match wins.
80
+ */
81
+ function templatesOverlap(left, right) {
82
+ if (left.length === 0 || right.length === 0) return false;
83
+ const a = compileSegments(left).segments;
84
+ const b = compileSegments(right).segments;
85
+ if (a.length !== b.length) return false;
86
+ for (const [index, segment] of a.entries()) {
87
+ const other = b[index];
88
+ if (!other || segment.kind === "parameter" || other.kind === "parameter") continue;
89
+ if (segment.value !== other.value) return false;
90
+ }
91
+ return true;
92
+ }
93
+ export { attachOwner as a, isForeignOwner as c, CurrentOwner as i, ownerOf as l, isCanonicalIdSegment as n, attachStorage as o, templatesOverlap as r, checkWriteOwner as s, compileSegments as t, storageOf as u };
@@ -1,8 +1,7 @@
1
- import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
2
- import { i as checkWriteOwner, o as ownerOf, s as storageOf } from "./owner-BQzMpfC1.js";
3
- import { Context, Data, Duration, Effect, Layer, Option, Predicate, Result, Schedule, Schema, Stream } from "effect";
4
- import { isReadonlyArrayNonEmpty } from "effect/Array";
5
- //#region src/schema/index.ts
1
+ import { t as __exportAll } from "./rolldown-runtime-D8jQpDG7.js";
2
+ import { l as ownerOf, n as isCanonicalIdSegment, r as templatesOverlap, s as checkWriteOwner, t as compileSegments, u as storageOf } from "./route-internal-DNL0oGTN.js";
3
+ import { Array, Context, Data, Duration, Effect, Layer, Option, Predicate, Record, Result, Schedule, Schema, Stream } from "effect";
4
+ // src/schema/index.ts
6
5
  const StreamId = Schema.String.pipe(Schema.brand("StreamId"));
7
6
  const Offset = Schema.String.pipe(Schema.check(Schema.isPattern(/^\d{16}_\d{16}$/)), Schema.brand("Offset"));
8
7
  const ProducerId = Schema.String.pipe(Schema.brand("ProducerId"));
@@ -66,8 +65,7 @@ const RecordPatch = Schema.Struct({
66
65
  "lastSeq"
67
66
  ])))
68
67
  });
69
- //#endregion
70
- //#region src/fault.ts
68
+ // src/fault.ts
71
69
  var StorageFault = class extends Schema.TaggedError()("StorageFault", {
72
70
  operation: Schema.String,
73
71
  message: Schema.String,
@@ -106,8 +104,7 @@ const StreamsFault = Schema.Union([StorageFault, TransportFault]);
106
104
  const isStreamsFault = Schema.is(StreamsFault);
107
105
  /** A storage or transport failure that can succeed later. */
108
106
  const isRetryableFault = (error) => isStreamsFault(error) && error.retryable;
109
- //#endregion
110
- //#region src/offset/index.ts
107
+ // src/offset/index.ts
111
108
  const ZERO_OFFSET = Offset.make(`${"0".repeat(16)}_${"0".repeat(16)}`);
112
109
  const isValid = (offset) => /^\d{16}_\d{16}$/.test(offset);
113
110
  const compare = (a, b) => a === b ? 0 : a < b ? -1 : 1;
@@ -118,15 +115,12 @@ function next(previous) {
118
115
  if (value > 9999999999999999n) throw new RangeError("Offset exhausted");
119
116
  return Offset.make(`${String(value).padStart(16, "0")}_${"0".repeat(16)}`);
120
117
  }
121
- //#endregion
122
- //#region src/storage/storage.ts
118
+ // src/storage/storage.ts
123
119
  var Storage = class extends Context.Service()("@streamsy/core/Storage") {};
124
- //#endregion
125
- //#region src/protocol/tags.ts
120
+ // src/protocol/tags.ts
126
121
  var StreamsReader = class extends Context.Service()("@streamsy/core/StreamsReader") {};
127
122
  var StreamsWriter = class extends Context.Service()("@streamsy/core/StreamsWriter") {};
128
- //#endregion
129
- //#region src/protocol/errors.ts
123
+ // src/protocol/errors.ts
130
124
  /** Protocol rejections. Optional create reasons reflect the public HTTP wire's loss of detail. */
131
125
  var StreamNotFound = class extends Schema.TaggedError()("StreamNotFound", { id: StreamId }) {
132
126
  get message() {
@@ -243,78 +237,24 @@ const protocolErrorTags = {
243
237
  NotSupported: true
244
238
  };
245
239
  /** The HTTP edge answers every protocol rejection through one mapper, so it needs one guard. */
246
- const isProtocolError = (error) => Object.hasOwn(protocolErrorTags, error._tag);
247
- //#endregion
248
- //#region src/protocol/results.ts
240
+ const isProtocolError = (error) => Record.has(protocolErrorTags, error._tag);
241
+ // src/protocol/results.ts
249
242
  /** Constructors and matchers for the protocol results above. */
250
243
  const CreateResult = Data.taggedEnum();
251
244
  const AppendResult = Data.taggedEnum();
252
- //#endregion
253
- //#region src/toolkit/route-internal.ts
254
- /** Ids are canonical relative paths, the same rule the remote Layer enforces. */
255
- function isCanonicalIdSegment(value) {
256
- if (value.length === 0 || value === "." || value === "..") return false;
257
- return !/[%?#/\\]/.test(value);
258
- }
259
- function compileSegments(template) {
260
- if (template.length === 0) throw new RangeError("a stream route template must name at least one segment");
261
- if (template.startsWith("/")) throw new RangeError("a stream route template is relative and cannot start with a slash");
262
- if (/[?#*]/.test(template)) throw new RangeError("a stream route template cannot contain a query, fragment, or wildcard");
263
- const names = [];
264
- const segments = [];
265
- for (const part of template.split("/")) {
266
- if (part.length === 0) throw new RangeError("a stream route template cannot contain an empty segment");
267
- if (!part.startsWith(":")) {
268
- if (!isCanonicalIdSegment(part)) throw new RangeError(`a stream route literal segment is not a canonical id segment: ${part}`);
269
- segments.push({
270
- kind: "literal",
271
- value: part
272
- });
273
- continue;
274
- }
275
- const name = part.slice(1);
276
- if (name.length === 0) throw new RangeError("a stream route parameter needs a name");
277
- if (names.includes(name)) throw new RangeError(`duplicate stream route parameter: ${name}`);
278
- names.push(name);
279
- segments.push({
280
- kind: "parameter",
281
- name
282
- });
283
- }
284
- return {
285
- template,
286
- segments: Object.freeze(segments),
287
- names: Object.freeze(names)
288
- };
289
- }
290
- /**
291
- * True when two template routes can both match one id.
292
- *
293
- * Lengths must agree, and every position must be either an equal literal pair
294
- * or a parameter on at least one side. A parameter is treated as matching any
295
- * segment, so a codec-constrained parameter can report an overlap it would
296
- * never actually match. A custom route carries no template and is never
297
- * checked; HTTP dispatch uses declaration order and the first match wins.
298
- */
299
- function templatesOverlap(left, right) {
300
- if (left.length === 0 || right.length === 0) return false;
301
- const a = compileSegments(left).segments;
302
- const b = compileSegments(right).segments;
303
- if (a.length !== b.length) return false;
304
- for (const [index, segment] of a.entries()) {
305
- const other = b[index];
306
- if (!other || segment.kind === "parameter" || other.kind === "parameter") continue;
307
- if (segment.value !== other.value) return false;
308
- }
309
- return true;
310
- }
311
- //#endregion
312
- //#region src/toolkit/address.ts
245
+ // src/toolkit/address.ts
313
246
  var address_exports = /* @__PURE__ */ __exportAll({
314
247
  bytes: () => bytes$2,
248
+ isChange: () => isChange,
249
+ isControl: () => isControl,
250
+ isUpsert: () => isUpsert,
315
251
  json: () => json$2,
252
+ reset: () => reset,
253
+ snapshotEnd: () => snapshotEnd,
254
+ snapshotStart: () => snapshotStart,
316
255
  state: () => state$2,
317
- stateChange: () => stateChange
256
+ stateChange: () => stateChange,
257
+ stateControl: () => stateControl
318
258
  });
319
259
  /** The address constructors. Each class owns the `_tag` of one address kind. */
320
260
  const JsonAddress = Data.TaggedClass("Json");
@@ -361,17 +301,43 @@ function stateChange(options) {
361
301
  })
362
302
  })]);
363
303
  }
304
+ /** The codec for a State control message. It needs no services. */
305
+ const stateControl = Schema.Struct({ headers: Schema.Struct({
306
+ control: Schema.Literals([
307
+ "snapshot-start",
308
+ "snapshot-end",
309
+ "reset"
310
+ ]),
311
+ offset: Schema.optionalKey(Schema.String)
312
+ }) });
313
+ /** True for a control message. A change has `headers.operation` and no `headers.control`. */
314
+ const isControl = (event) => Predicate.hasProperty(event.headers, "control");
315
+ /** True for an upsert or delete change. */
316
+ const isChange = (event) => !isControl(event);
317
+ /** True for an upsert change, with its value available. */
318
+ const isUpsert = (event) => isChange(event) && event.headers.operation === "upsert";
319
+ const control = (name, options) => ({ headers: options.offset === void 0 ? { control: name } : {
320
+ control: name,
321
+ offset: options.offset
322
+ } });
323
+ /** A `reset` control. A reader should clear its materialized state and apply what follows. */
324
+ const reset = (options = {}) => control("reset", options);
325
+ /** A `snapshot-start` control. The changes up to `snapshot-end` form a complete snapshot. */
326
+ const snapshotStart = (options = {}) => control("snapshot-start", options);
327
+ /** A `snapshot-end` control. It closes the snapshot that `snapshot-start` opened. */
328
+ const snapshotEnd = (options = {}) => control("snapshot-end", options);
364
329
  /**
365
- * A stream of Durable State change events for several collections. Each record
330
+ * A stream of Durable State events for several collections. Each record
366
331
  * key is the `type` on the wire; each entry gives the value schema and the value
367
- * field that becomes the event `key`.
332
+ * field that becomes the event `key`. The codec also decodes and encodes the
333
+ * State control messages `snapshot-start`, `snapshot-end` and `reset`.
368
334
  */
369
335
  function state$2(id, options) {
370
- const codecs = Object.entries(options.collections).map(([type, collection]) => stateChange({
336
+ const codecs = Array.map(Record.toEntries(options.collections), ([type, collection]) => stateChange({
371
337
  schema: collection.schema,
372
338
  type
373
339
  }));
374
- const address = json$2(id, { schema: Schema.Union(codecs) });
340
+ const address = json$2(id, { schema: Schema.Union([...codecs, stateControl]) });
375
341
  return new JsonAddress({
376
342
  id: address.id,
377
343
  contentType: address.contentType,
@@ -387,8 +353,7 @@ function bytes$2(id, options = {}) {
387
353
  codec: Schema.Uint8Array
388
354
  });
389
355
  }
390
- //#endregion
391
- //#region src/toolkit/route.ts
356
+ // src/toolkit/route.ts
392
357
  var route_exports = /* @__PURE__ */ __exportAll({
393
358
  bytes: () => bytes$1,
394
359
  custom: () => custom$1,
@@ -402,7 +367,7 @@ function pathSchema(codecs) {
402
367
  }
403
368
  function decodeParams(codecs, raw) {
404
369
  const decoded = {};
405
- for (const name of Object.keys(codecs)) {
370
+ for (const name of Record.keys(codecs)) {
406
371
  const value = raw[name];
407
372
  const codec = codecs[name];
408
373
  if (value === void 0 || codec === void 0) return Option.none();
@@ -430,7 +395,7 @@ function matchTemplate(segments, codecs, id) {
430
395
  }
431
396
  function buildId(template, segments, codecs, params) {
432
397
  const record = params;
433
- const built = segments.map((segment) => {
398
+ const built = Array.map(segments, (segment) => {
434
399
  if (segment.kind === "literal") return segment.value;
435
400
  const codec = codecs[segment.name];
436
401
  const value = record[segment.name];
@@ -440,7 +405,7 @@ function buildId(template, segments, codecs, params) {
440
405
  if (!isCanonicalIdSegment(text)) throw new RangeError(`stream route ${template} parameter ${segment.name} is not a canonical id segment: ${text}`);
441
406
  return text;
442
407
  });
443
- return StreamId.make(built.join("/"));
408
+ return StreamId.make(Array.join(built, "/"));
444
409
  }
445
410
  /**
446
411
  * The codec record and the template must name the same parameters. The type
@@ -448,7 +413,7 @@ function buildId(template, segments, codecs, params) {
448
413
  */
449
414
  function checkTemplateParams(template, names, codecs) {
450
415
  for (const name of names) if (codecs[name] === void 0) throw new RangeError(`stream route ${template} has no codec for parameter: ${name}`);
451
- for (const name of Object.keys(codecs)) if (!names.includes(name)) throw new RangeError(`stream route codec is absent from the template: ${name}`);
416
+ for (const name of Record.keys(codecs)) if (!names.includes(name)) throw new RangeError(`stream route codec is absent from the template: ${name}`);
452
417
  }
453
418
  function json$1(template, options) {
454
419
  const { segments, names } = compileSegments(template);
@@ -496,8 +461,7 @@ function custom$1(options) {
496
461
  address: options.address
497
462
  });
498
463
  }
499
- //#endregion
500
- //#region src/toolkit/streams.ts
464
+ // src/toolkit/streams.ts
501
465
  var streams_exports = /* @__PURE__ */ __exportAll({
502
466
  append: () => append,
503
467
  collect: () => collect,
@@ -531,7 +495,7 @@ const append = Effect.fn("Streams.append")(function* (address, items, options) {
531
495
  cause
532
496
  }))));
533
497
  for (const item of encoded) if (Predicate.isUint8Array(item) && item.byteLength === 0) return yield* Effect.die(/* @__PURE__ */ new RangeError(`Cannot append an empty bytes item to ${address.id}`));
534
- const data = list.length === 0 && callOptions.close ? /* @__PURE__ */ new Uint8Array() : Predicate.isTagged(address, "Json") ? new TextEncoder().encode(`[${encoded.join(",")}]`) : concatBytes(encoded);
498
+ const data = list.length === 0 && callOptions.close ? /* @__PURE__ */ new Uint8Array() : Predicate.isTagged(address, "Json") ? new TextEncoder().encode(`[${Array.join(Array.map(encoded, String), ",")}]`) : concatBytes(encoded);
535
499
  const possible = (error) => possibleFor(callOptions, error);
536
500
  const appended = (yield* StreamsWriter).append(address.id, {
537
501
  ...callOptions,
@@ -541,8 +505,8 @@ const append = Effect.fn("Streams.append")(function* (address, items, options) {
541
505
  return yield* Effect.catchIf(appended, possible, Effect.fail, Effect.die);
542
506
  });
543
507
  function concatBytes(parts) {
544
- const arrays = parts.map((part) => Predicate.isString(part) ? new TextEncoder().encode(part) : part);
545
- const result = new Uint8Array(arrays.reduce((size, part) => size + part.byteLength, 0));
508
+ const arrays = Array.map(parts, (part) => Predicate.isString(part) ? new TextEncoder().encode(part) : part);
509
+ const result = new Uint8Array(Array.reduce(arrays, 0, (size, part) => size + part.byteLength));
546
510
  let offset = 0;
547
511
  for (const part of arrays) {
548
512
  result.set(part, offset);
@@ -617,7 +581,7 @@ const decide = Effect.fn("Streams.decide")(function* (address, spec) {
617
581
  folded = last === void 0 ? yield* fold(address, spec.initial, spec.fold) : yield* fold(address, () => last.state, spec.fold, { offset: last.offset });
618
582
  const { state, offset } = folded;
619
583
  const { value, items } = yield* spec.decide(state, { offset });
620
- if (!isReadonlyArrayNonEmpty(items)) return {
584
+ if (!Array.isReadonlyArrayNonEmpty(items)) return {
621
585
  value,
622
586
  offset,
623
587
  appended: false
@@ -704,8 +668,7 @@ const head = Effect.fn("Streams.head")(function* (address) {
704
668
  const remove = Effect.fn("Streams.remove")(function* (address) {
705
669
  return yield* (yield* StreamsWriter).remove(address.id);
706
670
  });
707
- //#endregion
708
- //#region src/toolkit/streamsy.ts
671
+ // src/toolkit/streamsy.ts
709
672
  const templateOf = (route) => {
710
673
  if (!("template" in route)) return void 0;
711
674
  const template = route.template;
@@ -714,7 +677,7 @@ const templateOf = (route) => {
714
677
  };
715
678
  /** Template streams must have disjoint id grammars. Custom routes use declaration order. */
716
679
  function checkNoOverlap(routes) {
717
- const templates = routes.flatMap((route) => {
680
+ const templates = Array.flatMap(routes, (route) => {
718
681
  const template = templateOf(route);
719
682
  return template === void 0 ? [] : [template];
720
683
  });
@@ -805,7 +768,7 @@ function checkStreams(keys) {
805
768
  templates.add(key.template);
806
769
  if (key.key === Wildcard.key && index !== keys.length - 1) throw new RangeError("Wildcard must be last");
807
770
  }
808
- checkNoOverlap(keys.map((key) => declaration(key).route));
771
+ checkNoOverlap(Array.map(keys, (key) => declaration(key).route));
809
772
  }
810
773
  function bind(source, streams) {
811
774
  const keys = streams.streams;
@@ -825,5 +788,4 @@ function group(...keys) {
825
788
  checkStreams(keys);
826
789
  return Object.freeze({ streams: Object.freeze(keys) });
827
790
  }
828
- //#endregion
829
- export { StreamLifecycle as $, StreamsReader as A, StreamsFault as B, ProducerGap as C, StreamGone as D, StreamClosed as E, isValid as F, MessageWindow as G, isRetryableFault as H, next as I, ProducerState as J, Offset as K, DecodeFault as L, Storage as M, ZERO_OFFSET as N, StreamNotFound as O, compare as P, StreamId as Q, EncodeFault as R, OffsetMismatch as S, StreamBusy as T, isStreamsFault as U, TransportFault as V, ChangeSnapshot as W, StoredMessage as X, RecordPatch as Y, StreamConfig as Z, InvalidAppendRequest as _, custom as a, InvalidReadRequest as b, state as c, address_exports as d, StreamRecord as et, AppendResult as f, ForkSourceNotFound as g, CreateConflict as h, checkStreams as i, StreamsWriter as j, isProtocolError as k, streams_exports as l, AppendConflict as m, bind as n, group as o, CreateResult as p, ProducerId as q, bytes as r, json as s, Wildcard as t, route_exports as u, InvalidEpochSeq as v, StaleEpoch as w, NotSupported as x, InvalidForkRequest as y, StorageFault as z };
791
+ export { RecordPatch as $, StreamClosed as A, next as B, InvalidForkRequest as C, ProducerGap as D, OffsetMismatch as E, StreamsWriter as F, TransportFault as G, EncodeFault as H, Storage as I, ChangeSnapshot as J, isRetryableFault as K, ZERO_OFFSET as L, StreamNotFound as M, isProtocolError as N, StaleEpoch as O, StreamsReader as P, ProducerState as Q, compare as R, InvalidEpochSeq as S, NotSupported as T, StorageFault as U, DecodeFault as V, StreamsFault as W, Offset as X, MessageWindow as Y, ProducerId as Z, CreateResult as _, custom as a, ForkSourceNotFound as b, state as c, address_exports as d, StoredMessage as et, isControl as f, AppendResult as g, stateControl as h, checkStreams as i, StreamRecord as it, StreamGone as j, StreamBusy as k, streams_exports as l, stateChange as m, bind as n, StreamId as nt, group as o, isUpsert as p, isStreamsFault as q, bytes as r, StreamLifecycle as rt, json as s, Wildcard as t, StreamConfig as tt, route_exports as u, AppendConflict as v, InvalidReadRequest as w, InvalidAppendRequest as x, CreateConflict as y, isValid as z };
@@ -1,7 +1,6 @@
1
- import { _ as StreamsWriter, dt as StreamId, g as StreamsReader, m as StorageCapabilities, r as Storage, rt as ChangeSnapshot } from "../owner-records-QDlssl__.js";
2
- import { M as MemoryOptions, N as ProtocolOptions } from "../index-CFv8vZvy.js";
1
+ import { _ as StreamsWriter, dt as StreamId, g as StreamsReader, m as StorageCapabilities, r as Storage, rt as ChangeSnapshot } from "../owner-records-H7VEuBpy.js";
2
+ import { M as MemoryOptions, N as ProtocolOptions } from "../index-p68har8W.js";
3
3
  import { Context, Effect, Layer } from "effect";
4
- //#region src/testing/storage-contract.d.ts
5
4
  interface StorageContractOptions {
6
5
  readonly name: string;
7
6
  readonly layer: Layer.Layer<Storage>;
@@ -14,15 +13,11 @@ export declare const StorageContract: {
14
13
  /** The configured memory suite must exercise each shipped capability value. */
15
14
  assertModes(configurations: ReadonlyArray<StorageCapabilities>): void;
16
15
  };
17
- //#endregion
18
- //#region src/testing/fault-injection.d.ts
19
16
  /** One selected attempt per decorator; "after" injects only if that mutation applies. */
20
17
  export declare function faultyStorage(source: Layer.Layer<Storage>, options: {
21
18
  readonly failOn: number;
22
19
  readonly when: "before" | "after";
23
20
  }): Layer.Layer<Storage>;
24
- //#endregion
25
- //#region src/testing/streams-test.d.ts
26
21
  declare const StreamsTest_base: Context.ServiceClass<StreamsTest, "@streamsy/core/StreamsTest", {
27
22
  readonly storage: typeof Storage.Service;
28
23
  readonly subscribers: Effect.Effect<number>;
@@ -34,11 +29,8 @@ declare const StreamsTest_base: Context.ServiceClass<StreamsTest, "@streamsy/cor
34
29
  export declare class StreamsTest extends StreamsTest_base {}
35
30
  /** Real protocol and memory, with deterministic observation at the scoped changes boundary. */
36
31
  export declare const layerTest: (options?: MemoryOptions & ProtocolOptions) => Layer.Layer<StreamsReader | StreamsTest | StreamsWriter, never, never>;
37
- //#endregion
38
- //#region src/testing/expect-failure-tag.d.ts
39
32
  /** An unexpected success stays a failure so the enclosing test cannot pass. */
40
33
  export declare const expectFailureTag: <A, E extends {
41
34
  readonly _tag: string;
42
35
  }, R>(effect: Effect.Effect<A, E, R>, tag: E["_tag"]) => Effect.Effect<E, A, R>;
43
- //#endregion
44
36
  export type { StorageContractOptions };