@streamsy/core 0.7.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  An Effect implementation of the [Durable Streams](https://durablestreams.com)
4
4
  protocol. Typed stream declarations, stream services, an in-process memory Layer, an
5
5
  HTTP app, and a client for remote hosts. Requires
6
- `effect@4.0.5`.
6
+ `effect@4.1.2`.
7
7
 
8
8
  ```sh
9
9
  bun add @streamsy/core effect
@@ -283,10 +283,10 @@ read notification source. Custom storage adapters must provide `committed`.
283
283
  ## Documentation
284
284
 
285
285
  - [Declare streams](https://streamsy.dev/docs/streams/declare)
286
- - [Layers and storage](https://streamsy.dev/docs/hosting)
287
- - [Protocol routes](https://streamsy.dev/docs/http/routes)
288
- - [Remote client](https://streamsy.dev/docs/http/remote)
289
- - [Write a storage adapter](https://streamsy.dev/docs/hosting/storage-adapter)
286
+ - [Choose storage](https://streamsy.dev/docs/storage)
287
+ - [Expose the stream protocol](https://streamsy.dev/docs/servers/protocol)
288
+ - [Connect to a remote server](https://streamsy.dev/docs/servers/remote)
289
+ - [Write a storage adapter](https://streamsy.dev/docs/storage/adapter)
290
290
 
291
291
  Source: https://github.com/gingerhendrix/streamsy
292
292
 
@@ -0,0 +1,53 @@
1
+ import { S as InvalidCreateRequest } from "./streamsy-BWX6z980.js";
2
+ import { Array, DateTime, Effect, Option, Result } from "effect";
3
+ // src/policy/message-framer.ts
4
+ /**
5
+ * Body framing for the durable streams protocol.
6
+ *
7
+ * Responsibilities:
8
+ *
9
+ * - Non-JSON content types pass the original bytes through as a single
10
+ * message.
11
+ * - JSON content types are decoded and re-encoded:
12
+ * - JSON object input becomes one canonical `JSON.stringify(parsed)` message.
13
+ * - JSON array input produces one message per item.
14
+ * - Empty JSON array produces zero messages.
15
+ * - The JSON branch is selected by `contentType.toLowerCase().startsWith("application/json")`,
16
+ * without parameter stripping.
17
+ * - Invalid JSON propagates the underlying `JSON.parse` error.
18
+ *
19
+ * Used by `AppendService`, `CreateStreamService`, and `ForkPlanBuilder` before
20
+ * incoming request bodies are persisted as stored messages.
21
+ */
22
+ function frameMessages(data, contentType) {
23
+ if (!contentType.toLowerCase().startsWith("application/json")) return [data];
24
+ const parsed = JSON.parse(new TextDecoder().decode(data));
25
+ if (Array.isArray(parsed)) return parsed.length === 0 ? [] : Array.map(parsed, (item) => new TextEncoder().encode(JSON.stringify(item)));
26
+ return [new TextEncoder().encode(JSON.stringify(parsed))];
27
+ }
28
+ // src/policy/create-validation.ts
29
+ /** Validate expiry before either transport accesses a stream. */
30
+ const validateCreateOptions = Effect.fn("Create.validateOptions")(function* (id, options = {}) {
31
+ if (options.ttlSeconds !== void 0 && options.expiresAt !== void 0) return yield* new InvalidCreateRequest({
32
+ id,
33
+ message: "Cannot specify both Stream-TTL and Stream-Expires-At"
34
+ });
35
+ if (options.expiresAt !== void 0 && Option.isNone(DateTime.make(options.expiresAt))) return yield* new InvalidCreateRequest({
36
+ id,
37
+ message: "Invalid Stream-Expires-At format"
38
+ });
39
+ });
40
+ /** Create bodies use typed JSON failures without changing append framing. */
41
+ function frameCreateMessages(id, data, contentType) {
42
+ return Result.try({
43
+ try: () => data === void 0 ? [] : frameMessages(data, contentType),
44
+ catch: (error) => {
45
+ if (error instanceof SyntaxError) return new InvalidCreateRequest({
46
+ id,
47
+ message: "Invalid JSON"
48
+ });
49
+ throw error;
50
+ }
51
+ });
52
+ }
53
+ export { validateCreateOptions as n, frameMessages as r, frameCreateMessages as t };
@@ -1,2 +1,2 @@
1
- import { H as HttpOptions, U as app, V as streamPath, a as securityHeaders, c as read, d as routes, i as layerShutdownSignal, l as Access, n as ShutdownSignal, o as ReadOptions, r as ShutdownSignalService, s as checkReadOptions, u as RoutesOptions } from "../index-IhF2sua7.js";
1
+ import { H as HttpOptions, U as app, V as streamPath, a as securityHeaders, c as read, d as routes, i as layerShutdownSignal, l as Access, n as ShutdownSignal, o as ReadOptions, r as ShutdownSignalService, s as checkReadOptions, u as RoutesOptions } from "../index-CtXiBkjV.js";
2
2
  export { type Access, type HttpOptions, type ReadOptions, type RoutesOptions, ShutdownSignal, type ShutdownSignalService, app, checkReadOptions, layerShutdownSignal, read, routes, securityHeaders, streamPath };
@@ -1,3 +1,3 @@
1
- import { a as ShutdownSignal, c as streamPath, l as securityHeaders, n as checkReadOptions, o as layerShutdownSignal, r as read, t as app } from "../program-CYtMjdvD.js";
2
- import { n as routes } from "../http-B10ao6xE.js";
1
+ import { a as ShutdownSignal, c as streamPath, l as securityHeaders, n as checkReadOptions, o as layerShutdownSignal, r as read, t as app } from "../program-DPq8FYrT.js";
2
+ import { n as routes } from "../http-CwDadGy6.js";
3
3
  export { ShutdownSignal, app, checkReadOptions, layerShutdownSignal, read, routes, securityHeaders, streamPath };
@@ -1,6 +1,6 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-D8jQpDG7.js";
2
- import { F as StreamsWriter, P as StreamsReader, i as checkStreams } from "./streamsy-D9OCCdw0.js";
3
- import { a as ShutdownSignal, c as streamPath, i as requestUrl, l as securityHeaders, n as checkReadOptions, o as layerShutdownSignal, r as read, s as discardRequestBody, t as app } from "./program-CYtMjdvD.js";
2
+ import { F as StreamsReader, I as StreamsWriter, i as checkStreams } from "./streamsy-BWX6z980.js";
3
+ import { a as ShutdownSignal, c as streamPath, i as requestUrl, l as securityHeaders, n as checkReadOptions, o as layerShutdownSignal, r as read, s as discardRequestBody, t as app } from "./program-DPq8FYrT.js";
4
4
  import { Array, Effect, Option } from "effect";
5
5
  import { HttpRouter, HttpServerRequest, HttpServerResponse } from "effect/http";
6
6
  // src/http/routes.ts
@@ -1,4 +1,4 @@
1
- import { $ as StreamBusy, A as ReadNextResult, B as HeadError, C as StreamsReader, Ct as StorageFault, D as CreateResult, E as AppendResult, F as AppendErrorFor, G as NotSupported, K as OffsetMismatch, N as AppendConflict, O as HeadResult, R as CreateError, S as Reader, St as EncodeFault, T as Writer, Tt as TransportFault, W as InvalidReadRequest, X as ReadNextError, Z as RemoveError, a as CommitHooks, c as OwnerRecords, ct as ReadOptions$1, et as StreamClosed, it as AppendCallOptions, lt as CreateOptions, n as ProjectionMarks, nt as StreamNotFound, ot as ProducerOptions, st as ReadNextOptions, tt as StreamGone, u as Storage, vt as StreamId, w as StreamsWriter, wt as StreamsFault, xt as DecodeFault } from "./projection-marks-28vAwOzM.js";
1
+ import { A as ReadNextResult, B as HeadError, C as StreamsReader, Ct as EncodeFault, D as CreateResult, E as AppendResult, Et as TransportFault, F as AppendErrorFor, G as InvalidReadRequest, K as NotSupported, N as AppendConflict, O as HeadResult, Q as RemoveError, R as CreateError, S as Reader, St as DecodeFault, T as Writer, Tt as StreamsFault, Z as ReadNextError, a as CommitHooks, at as AppendCallOptions, c as OwnerRecords, ct as ReadNextOptions, et as StreamBusy, lt as ReadOptions$1, n as ProjectionMarks, nt as StreamGone, q as OffsetMismatch, rt as StreamNotFound, st as ProducerOptions, tt as StreamClosed, u as Storage, ut as CreateOptions, w as StreamsWriter, wt as StorageFault, yt as StreamId } from "./projection-marks-Ca0Q-L9H.js";
2
2
  import { Array, Context, Data, Duration, Effect, Function, Layer, Option, Schedule, Schema, Stream } from "effect";
3
3
  import { HttpRouter, HttpServerRequest, HttpServerResponse } from "effect/http";
4
4
  import { SqlError } from "effect/sql";
@@ -414,113 +414,21 @@ type WakeItem = Data.TaggedEnum<{
414
414
  };
415
415
  }>;
416
416
  /** Constructors and matchers for `WakeItem`. */
417
- declare const WakeItem: {
418
- readonly $is: <Tag extends "Dirty" | "Removed" | "Reset" | "Snapshot">(tag: Tag) => (u: unknown) => u is Extract<{
419
- readonly _tag: "Dirty";
420
- readonly stream: StreamId;
421
- readonly from: string;
422
- readonly offset: string;
423
- readonly closed: boolean;
424
- }, {
425
- readonly _tag: Tag;
426
- }> | Extract<{
427
- readonly _tag: "Removed";
428
- readonly stream: StreamId;
429
- }, {
430
- readonly _tag: Tag;
431
- }> | Extract<{
432
- readonly _tag: "Reset";
433
- }, {
434
- readonly _tag: Tag;
435
- }> | Extract<{
436
- readonly _tag: "Snapshot";
437
- readonly streams: ReadonlySet<StreamId>;
438
- }, {
439
- readonly _tag: Tag;
440
- }>;
441
- readonly $match: {
442
- <Cases extends { readonly [Tag in "Dirty" | "Removed" | "Reset" | "Snapshot"]: (args: Extract<{
443
- readonly _tag: "Dirty";
444
- readonly stream: StreamId;
445
- readonly from: string;
446
- readonly offset: string;
447
- readonly closed: boolean;
448
- } | {
449
- readonly _tag: "Removed";
450
- readonly stream: StreamId;
451
- } | {
452
- readonly _tag: "Reset";
453
- } | {
454
- readonly _tag: "Snapshot";
455
- readonly streams: ReadonlySet<StreamId>;
456
- }, {
457
- readonly _tag: Tag;
458
- }>) => any; }>(cases: Cases): (value: {
459
- readonly _tag: "Dirty";
460
- readonly stream: StreamId;
461
- readonly from: string;
462
- readonly offset: string;
463
- readonly closed: boolean;
464
- } | {
465
- readonly _tag: "Removed";
466
- readonly stream: StreamId;
467
- } | {
468
- readonly _tag: "Reset";
469
- } | {
470
- readonly _tag: "Snapshot";
471
- readonly streams: ReadonlySet<StreamId>;
472
- }) => import("effect/Unify").Unify<ReturnType<Cases["Dirty" | "Removed" | "Reset" | "Snapshot"]>>;
473
- <Cases extends { readonly [Tag in "Dirty" | "Removed" | "Reset" | "Snapshot"]: (args: Extract<{
474
- readonly _tag: "Dirty";
475
- readonly stream: StreamId;
476
- readonly from: string;
477
- readonly offset: string;
478
- readonly closed: boolean;
479
- } | {
480
- readonly _tag: "Removed";
481
- readonly stream: StreamId;
482
- } | {
483
- readonly _tag: "Reset";
484
- } | {
485
- readonly _tag: "Snapshot";
486
- readonly streams: ReadonlySet<StreamId>;
487
- }, {
488
- readonly _tag: Tag;
489
- }>) => any; }>(value: {
490
- readonly _tag: "Dirty";
491
- readonly stream: StreamId;
492
- readonly from: string;
493
- readonly offset: string;
494
- readonly closed: boolean;
495
- } | {
496
- readonly _tag: "Removed";
497
- readonly stream: StreamId;
498
- } | {
499
- readonly _tag: "Reset";
500
- } | {
501
- readonly _tag: "Snapshot";
502
- readonly streams: ReadonlySet<StreamId>;
503
- }, cases: Cases): import("effect/Unify").Unify<ReturnType<Cases["Dirty" | "Removed" | "Reset" | "Snapshot"]>>;
504
- };
505
- readonly Dirty: Data.TaggedEnum.ConstructorFrom<{
506
- readonly _tag: "Dirty";
507
- readonly stream: StreamId;
508
- readonly from: string;
509
- readonly offset: string;
510
- readonly closed: boolean;
511
- }, "_tag">;
512
- readonly Removed: Data.TaggedEnum.ConstructorFrom<{
513
- readonly _tag: "Removed";
514
- readonly stream: StreamId;
515
- }, "_tag">;
516
- readonly Reset: Data.TaggedEnum.ConstructorFrom<{
517
- readonly _tag: "Reset";
518
- }, "_tag">;
519
- readonly Snapshot: Data.TaggedEnum.ConstructorFrom<{
520
- readonly _tag: "Snapshot";
521
- readonly streams: ReadonlySet<StreamId>;
522
- }, "_tag">;
523
- };
417
+ declare const WakeItem: Data.TaggedEnum.Constructor<{
418
+ readonly _tag: "Dirty";
419
+ readonly stream: StreamId;
420
+ readonly from: string;
421
+ readonly offset: string;
422
+ readonly closed: boolean;
423
+ } | {
424
+ readonly _tag: "Removed";
425
+ readonly stream: StreamId;
426
+ } | {
427
+ readonly _tag: "Reset";
428
+ } | {
429
+ readonly _tag: "Snapshot";
430
+ readonly streams: ReadonlySet<StreamId>;
431
+ }>;
524
432
  /** One batch of wake actions. Save `offset` as the wake cursor after every item is handled. */
525
433
  interface WakeBatch {
526
434
  readonly items: ReadonlyArray<WakeItem>;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { $ as StreamBusy, A as ReadNextResult, B as HeadError, Ct as StorageFault, D as CreateResult, Dt as isStreamsFault, E as AppendResult, Et as isRetryableFault, F as AppendErrorFor, G as NotSupported, H as InvalidEpochSeq, I as CreateConflict, J as ProtocolError, K as OffsetMismatch, L as CreateConflictReason, M as AppendBaseError, N as AppendConflict, O as HeadResult, P as AppendError, Q as StaleEpoch, R as CreateError, St as EncodeFault, Tt as TransportFault, U as InvalidForkRequest, V as InvalidAppendRequest, W as InvalidReadRequest, X as ReadNextError, Y as ReadError, Z as RemoveError, _ as OperationResult, _t as StreamConfig, at as AppendOptions, b as ProducerPrecondition, bt as StreamRecord, ct as ReadOptions, d as StorageShape, dt as MessageWindow, et as StreamClosed, f as Mutation, ft as Offset, g as Operation, gt as StoredMessage, h as Mutations, ht as RecordPatch, it as AppendCallOptions, j as ReadResult, k as ReadMessage, lt as CreateOptions, m as MutationRejected, mt as ProducerState, nt as StreamNotFound, ot as ProducerOptions, p as MutationApplied, pt as ProducerId, q as ProducerGap, rt as isProtocolError, st as ReadNextOptions, tt as StreamGone, u as Storage, ut as ChangeSnapshot, v as OperationResults, vt as StreamId, wt as StreamsFault, x as StorageCapabilities, xt as DecodeFault, y as Operations, yt as StreamLifecycle, z as ForkSourceNotFound } from "./projection-marks-28vAwOzM.js";
2
- import { A as durable_state_d_exports, B as address_d_exports, C as FollowFailure, E as RemoveFailure, F as CommitBoundary, I as CommitBoundaryApi, L as ZERO_OFFSET, O as streamsy_d_exports, R as compare, S as Folded, T as ReadFailure, _ as Collected, b as Decided, g as Batch, h as AppendFailure, j as streams_d_exports, k as producer_d_exports, t as index_d_exports, v as CreateFailure, w as HeadFailure, x as Decision, y as DecideSpec } from "./index-IhF2sua7.js";
3
- export { AppendBaseError, type AppendCallOptions, AppendConflict, AppendError, AppendErrorFor, type AppendFailure, type AppendOptions, AppendResult, type Batch, ChangeSnapshot, type Collected, CommitBoundary, type CommitBoundaryApi, CreateConflict, CreateConflictReason, CreateError, type CreateFailure, type CreateOptions, CreateResult, type DecideSpec, type Decided, type Decision, DecodeFault, durable_state_d_exports as DurableState, EncodeFault, type Folded, type FollowFailure, ForkSourceNotFound, HeadError, type HeadFailure, type HeadResult, index_d_exports as Http, InvalidAppendRequest, InvalidEpochSeq, InvalidForkRequest, InvalidReadRequest, streams_d_exports as MemoryStorage, MessageWindow, Mutation, MutationApplied, MutationRejected, Mutations, NotSupported, Offset, OffsetMismatch, Operation, OperationResult, OperationResults, Operations, producer_d_exports as Producer, ProducerGap, ProducerId, type ProducerOptions, ProducerPrecondition, ProducerState, ProtocolError, ReadError, type ReadFailure, type ReadMessage, ReadNextError, type ReadNextOptions, type ReadNextResult, type ReadOptions, type ReadResult, RecordPatch, RemoveError, type RemoveFailure, StaleEpoch, Storage, StorageCapabilities, StorageFault, type StorageShape, StoredMessage, address_d_exports as StreamAddress, StreamBusy, StreamClosed, StreamConfig, StreamGone, StreamId, StreamLifecycle, StreamNotFound, StreamRecord, StreamsFault, streamsy_d_exports as Streamsy, TransportFault, ZERO_OFFSET, compare, isProtocolError, isRetryableFault, isStreamsFault };
1
+ import { $ as StaleEpoch, A as ReadNextResult, B as HeadError, Ct as EncodeFault, D as CreateResult, Dt as isRetryableFault, E as AppendResult, Et as TransportFault, F as AppendErrorFor, G as InvalidReadRequest, H as InvalidCreateRequest, I as CreateConflict, J as ProducerGap, K as NotSupported, L as CreateConflictReason, M as AppendBaseError, N as AppendConflict, O as HeadResult, Ot as isStreamsFault, P as AppendError, Q as RemoveError, R as CreateError, St as DecodeFault, Tt as StreamsFault, U as InvalidEpochSeq, V as InvalidAppendRequest, W as InvalidForkRequest, X as ReadError, Y as ProtocolError, Z as ReadNextError, _ as OperationResult, _t as StoredMessage, at as AppendCallOptions, b as ProducerPrecondition, bt as StreamLifecycle, ct as ReadNextOptions, d as StorageShape, dt as ChangeSnapshot, et as StreamBusy, f as Mutation, ft as MessageWindow, g as Operation, gt as RecordPatch, h as Mutations, ht as ProducerState, it as isProtocolError, j as ReadResult, k as ReadMessage, lt as ReadOptions, m as MutationRejected, mt as ProducerId, nt as StreamGone, ot as AppendOptions, p as MutationApplied, pt as Offset, q as OffsetMismatch, rt as StreamNotFound, st as ProducerOptions, tt as StreamClosed, u as Storage, ut as CreateOptions, v as OperationResults, vt as StreamConfig, wt as StorageFault, x as StorageCapabilities, xt as StreamRecord, y as Operations, yt as StreamId, z as ForkSourceNotFound } from "./projection-marks-Ca0Q-L9H.js";
2
+ import { A as durable_state_d_exports, B as address_d_exports, C as FollowFailure, E as RemoveFailure, F as CommitBoundary, I as CommitBoundaryApi, L as ZERO_OFFSET, O as streamsy_d_exports, R as compare, S as Folded, T as ReadFailure, _ as Collected, b as Decided, g as Batch, h as AppendFailure, j as streams_d_exports, k as producer_d_exports, t as index_d_exports, v as CreateFailure, w as HeadFailure, x as Decision, y as DecideSpec } from "./index-CtXiBkjV.js";
3
+ export { AppendBaseError, type AppendCallOptions, AppendConflict, AppendError, AppendErrorFor, type AppendFailure, type AppendOptions, AppendResult, type Batch, ChangeSnapshot, type Collected, CommitBoundary, type CommitBoundaryApi, CreateConflict, CreateConflictReason, CreateError, type CreateFailure, type CreateOptions, CreateResult, type DecideSpec, type Decided, type Decision, DecodeFault, durable_state_d_exports as DurableState, EncodeFault, type Folded, type FollowFailure, ForkSourceNotFound, HeadError, type HeadFailure, type HeadResult, index_d_exports as Http, InvalidAppendRequest, InvalidCreateRequest, InvalidEpochSeq, InvalidForkRequest, InvalidReadRequest, streams_d_exports as MemoryStorage, MessageWindow, Mutation, MutationApplied, MutationRejected, Mutations, NotSupported, Offset, OffsetMismatch, Operation, OperationResult, OperationResults, Operations, producer_d_exports as Producer, ProducerGap, ProducerId, type ProducerOptions, ProducerPrecondition, ProducerState, ProtocolError, ReadError, type ReadFailure, type ReadMessage, ReadNextError, type ReadNextOptions, type ReadNextResult, type ReadOptions, type ReadResult, RecordPatch, RemoveError, type RemoveFailure, StaleEpoch, Storage, StorageCapabilities, StorageFault, type StorageShape, StoredMessage, address_d_exports as StreamAddress, StreamBusy, StreamClosed, StreamConfig, StreamGone, StreamId, StreamLifecycle, StreamNotFound, StreamRecord, StreamsFault, streamsy_d_exports as Streamsy, TransportFault, ZERO_OFFSET, compare, isProtocolError, isRetryableFault, isStreamsFault };
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-D8jQpDG7.js";
2
- import { $ as RecordPatch, A as StreamClosed, C as InvalidForkRequest, D as ProducerGap, E as OffsetMismatch, G as TransportFault, H as EncodeFault, I as Storage, J as ChangeSnapshot, K as isRetryableFault, L as ZERO_OFFSET, M as StreamNotFound, N as isProtocolError, O as StaleEpoch, Q as ProducerState, R as compare, S as InvalidEpochSeq, T as NotSupported, U as StorageFault, V as DecodeFault, W as StreamsFault, X as Offset, Y as MessageWindow, Z as ProducerId, _ as CreateResult, a as custom, b as ForkSourceNotFound, c as state, d as address_exports, et as StoredMessage, f as isControl, g as AppendResult, h as stateControl, it as StreamRecord, j as StreamGone, k as StreamBusy, m as stateChange, n as bind, nt as StreamId, o as group, p as isUpsert, q as isStreamsFault, r as bytes, rt as StreamLifecycle, s as json, t as Wildcard, tt as StreamConfig, v as AppendConflict, w as InvalidReadRequest, x as InvalidAppendRequest, y as CreateConflict } from "./streamsy-D9OCCdw0.js";
3
- import { n as CommitBoundary, t as layer$1 } from "./layer-C-QriVBc.js";
4
- import { a as MutationRejected, c as OperationResult, d as ProducerPrecondition, i as MutationApplied, l as OperationResults, o as Mutations, r as Mutation, s as Operation, t as layer$2, u as Operations } from "./layer-8Y1cg6UL.js";
5
- import { t as http_exports } from "./http-B10ao6xE.js";
2
+ import { $ as ProducerState, A as StreamBusy, C as InvalidEpochSeq, D as OffsetMismatch, E as NotSupported, G as StreamsFault, H as DecodeFault, J as isStreamsFault, K as TransportFault, L as Storage, M as StreamGone, N as StreamNotFound, O as ProducerGap, P as isProtocolError, Q as ProducerId, R as ZERO_OFFSET, S as InvalidCreateRequest, T as InvalidReadRequest, U as EncodeFault, W as StorageFault, X as MessageWindow, Y as ChangeSnapshot, Z as Offset, _ as CreateResult, a as custom, at as StreamRecord, b as ForkSourceNotFound, c as state, d as address_exports, et as RecordPatch, f as isControl, g as AppendResult, h as stateControl, it as StreamLifecycle, j as StreamClosed, k as StaleEpoch, m as stateChange, n as bind, nt as StreamConfig, o as group, p as isUpsert, q as isRetryableFault, r as bytes, rt as StreamId, s as json, t as Wildcard, tt as StoredMessage, v as AppendConflict, w as InvalidForkRequest, x as InvalidAppendRequest, y as CreateConflict, z as compare } from "./streamsy-BWX6z980.js";
3
+ import { n as CommitBoundary, t as layer$1 } from "./layer-VOzdazlb.js";
4
+ import { a as MutationRejected, c as OperationResult, d as ProducerPrecondition, i as MutationApplied, l as OperationResults, o as Mutations, r as Mutation, s as Operation, t as layer$2, u as Operations } from "./layer-B1JEYOZb.js";
5
+ import { t as http_exports } from "./http-CwDadGy6.js";
6
6
  import { Array, Data, Effect, Layer, Option, Predicate, Record, Schema, Stream } from "effect";
7
7
  // src/storage/capabilities.ts
8
8
  const StorageCapabilities = Schema.Struct({
@@ -344,4 +344,4 @@ var streamsy_exports = /* @__PURE__ */ __exportAll({
344
344
  wakeActions: () => wakeActions,
345
345
  wakeCollections: () => wakeCollections
346
346
  });
347
- export { AppendConflict, AppendResult, ChangeSnapshot, CommitBoundary, CreateConflict, CreateResult, DecodeFault, durable_state_exports as DurableState, EncodeFault, ForkSourceNotFound, http_exports as Http, InvalidAppendRequest, InvalidEpochSeq, InvalidForkRequest, InvalidReadRequest, streams_exports as MemoryStorage, MessageWindow, Mutation, MutationApplied, MutationRejected, Mutations, NotSupported, Offset, OffsetMismatch, Operation, OperationResult, OperationResults, Operations, producer_exports as Producer, ProducerGap, ProducerId, ProducerPrecondition, ProducerState, RecordPatch, StaleEpoch, Storage, StorageCapabilities, StorageFault, StoredMessage, address_exports as StreamAddress, StreamBusy, StreamClosed, StreamConfig, StreamGone, StreamId, StreamLifecycle, StreamNotFound, StreamRecord, StreamsFault, streamsy_exports as Streamsy, TransportFault, ZERO_OFFSET, compare, isProtocolError, isRetryableFault, isStreamsFault };
347
+ export { AppendConflict, AppendResult, ChangeSnapshot, CommitBoundary, CreateConflict, CreateResult, DecodeFault, durable_state_exports as DurableState, EncodeFault, ForkSourceNotFound, http_exports as Http, InvalidAppendRequest, InvalidCreateRequest, InvalidEpochSeq, InvalidForkRequest, InvalidReadRequest, streams_exports as MemoryStorage, MessageWindow, Mutation, MutationApplied, MutationRejected, Mutations, NotSupported, Offset, OffsetMismatch, Operation, OperationResult, OperationResults, Operations, producer_exports as Producer, ProducerGap, ProducerId, ProducerPrecondition, ProducerState, RecordPatch, StaleEpoch, Storage, StorageCapabilities, StorageFault, StoredMessage, address_exports as StreamAddress, StreamBusy, StreamClosed, StreamConfig, StreamGone, StreamId, StreamLifecycle, StreamNotFound, StreamRecord, StreamsFault, streamsy_exports as Streamsy, TransportFault, ZERO_OFFSET, compare, isProtocolError, isRetryableFault, isStreamsFault };
@@ -1,4 +1,4 @@
1
- import { a as CommitHooks, c as OwnerRecords, i as CommitHook, l as OwnerRecordsApi, n as ProjectionMarks, o as CommitHooksApi, r as ProjectionMarksApi, s as commitHookRegistry, t as PendingMark } from "../projection-marks-28vAwOzM.js";
1
+ import { a as CommitHooks, c as OwnerRecords, i as CommitHook, l as OwnerRecordsApi, n as ProjectionMarks, o as CommitHooksApi, r as ProjectionMarksApi, s as commitHookRegistry, t as PendingMark } from "../projection-marks-Ca0Q-L9H.js";
2
2
  import { Context, Effect } from "effect";
3
3
  /** Private bridge: a stream guard dies with this sentinel; the atomic runner translates it. */
4
4
  declare const ForeignOwnerType: unique symbol;
@@ -1,8 +1,9 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-D8jQpDG7.js";
2
- import { $ as RecordPatch, A as StreamClosed, B as next, C as InvalidForkRequest, D as ProducerGap, E as OffsetMismatch, F as StreamsWriter, I as Storage, L as ZERO_OFFSET, M as StreamNotFound, O as StaleEpoch, P as StreamsReader, Q as ProducerState, R as compare, S as InvalidEpochSeq, T as NotSupported, X as Offset, Z as ProducerId, _ as CreateResult, b as ForkSourceNotFound, et as StoredMessage, g as AppendResult, it as StreamRecord, j as StreamGone, k as StreamBusy, n as bind, nt as StreamId, v as AppendConflict, w as InvalidReadRequest, x as InvalidAppendRequest, y as CreateConflict, z as isValid } from "./streamsy-D9OCCdw0.js";
2
+ import { $ as ProducerState, A as StreamBusy, B as isValid, C as InvalidEpochSeq, D as OffsetMismatch, E as NotSupported, F as StreamsReader, I as StreamsWriter, L as Storage, M as StreamGone, N as StreamNotFound, O as ProducerGap, Q as ProducerId, R as ZERO_OFFSET, T as InvalidReadRequest, V as next, Z as Offset, _ as CreateResult, at as StreamRecord, b as ForkSourceNotFound, et as RecordPatch, g as AppendResult, j as StreamClosed, k as StaleEpoch, n as bind, rt as StreamId, tt as StoredMessage, v as AppendConflict, w as InvalidForkRequest, x as InvalidAppendRequest, y as CreateConflict, z as compare } from "./streamsy-BWX6z980.js";
3
3
  import { o as attachStorage } from "./route-internal-DNL0oGTN.js";
4
+ import { n as validateCreateOptions, r as frameMessages, t as frameCreateMessages } from "./create-validation-Dwx1OQAN.js";
4
5
  import { t as generateCursor } from "./cursor-generator-DySXZ93b.js";
5
- import { Array, Clock, Context, Data, Effect, Layer, Match, Option, Predicate, Random, Schema, Stream } from "effect";
6
+ import { Array, Clock, Context, Data, Effect, Layer, Match, Option, Predicate, Random, Result, Schema, Stream } from "effect";
6
7
  // src/storage/mutation.ts
7
8
  const ProducerPrecondition = Schema.Struct({
8
9
  producerId: ProducerId,
@@ -105,31 +106,6 @@ function isExpired(record, now) {
105
106
  const at = record.lifecycle.expiresAtMs;
106
107
  return at !== void 0 && at <= now;
107
108
  }
108
- // src/policy/message-framer.ts
109
- /**
110
- * Body framing for the durable streams protocol.
111
- *
112
- * Responsibilities:
113
- *
114
- * - Non-JSON content types pass the original bytes through as a single
115
- * message.
116
- * - JSON content types are decoded and re-encoded:
117
- * - JSON object input becomes one canonical `JSON.stringify(parsed)` message.
118
- * - JSON array input produces one message per item.
119
- * - Empty JSON array produces zero messages.
120
- * - The JSON branch is selected by `contentType.toLowerCase().startsWith("application/json")`,
121
- * without parameter stripping.
122
- * - Invalid JSON propagates the underlying `JSON.parse` error.
123
- *
124
- * Used by `AppendService`, `CreateStreamService`, and `ForkPlanBuilder` before
125
- * incoming request bodies are persisted as stored messages.
126
- */
127
- function frameMessages(data, contentType) {
128
- if (!contentType.toLowerCase().startsWith("application/json")) return [data];
129
- const parsed = JSON.parse(new TextDecoder().decode(data));
130
- if (Array.isArray(parsed)) return parsed.length === 0 ? [] : Array.map(parsed, (item) => new TextEncoder().encode(JSON.stringify(item)));
131
- return [new TextEncoder().encode(JSON.stringify(parsed))];
132
- }
133
109
  // src/policy/fork-plan-builder.ts
134
110
  /** Fork-side validation and plan building. */
135
111
  const ForkBuildResult = Data.taggedEnum();
@@ -188,7 +164,12 @@ var ForkPlanBuilder = class {
188
164
  ...options,
189
165
  ...expiry
190
166
  }, fork);
191
- const initialMessages = this.initialMessages(prefix.messages, options.initialData, contentType, baseRecord.currentOffset);
167
+ const framed = frameCreateMessages(targetId, options.initialData, contentType);
168
+ if (Result.isFailure(framed)) return ForkBuildResult.Rejected({ error: new InvalidForkRequest({
169
+ id: targetId,
170
+ message: framed.failure.message
171
+ }) });
172
+ const initialMessages = this.initialMessages([...prefix.messages, ...framed.success], baseRecord.currentOffset);
192
173
  const child = this.withInitialTail(baseRecord, initialMessages);
193
174
  const plan = Operations.Create({
194
175
  record: child,
@@ -226,8 +207,7 @@ var ForkPlanBuilder = class {
226
207
  if (subOffset > first.data.byteLength) return ForkPrefix.Invalid({ errorMessage: "Stream-Fork-Sub-Offset exceeds source message length" });
227
208
  return ForkPrefix.Prefix({ messages: [first.data.subarray(0, subOffset)] });
228
209
  }
229
- initialMessages(prefix, initialData, contentType, previousOffset) {
230
- const framed = [...prefix, ...initialData ? frameMessages(initialData, contentType) : []];
210
+ initialMessages(framed, previousOffset) {
231
211
  let offset = previousOffset;
232
212
  const now = this.deps.clock.now();
233
213
  return Array.map(framed, (data) => {
@@ -328,6 +308,7 @@ const existingResult = Effect.fn("Protocol.existingResult")(function* (record, o
328
308
  });
329
309
  });
330
310
  const create = Effect.fn("Protocol.create")(function* (storage, id, options = {}) {
311
+ yield* validateCreateOptions(id, options);
331
312
  if (options.forkedFrom !== void 0 && storage.capabilities.fork === "none") return yield* new NotSupported({
332
313
  id,
333
314
  feature: "fork"
@@ -358,7 +339,8 @@ const create = Effect.fn("Protocol.create")(function* (storage, id, options = {}
358
339
  const type = options.contentType ?? "application/octet-stream";
359
340
  const record = newRecord(id, type, options, now);
360
341
  let offset = record.currentOffset;
361
- const initialMessages = Array.map(options.initialData ? frameMessages(options.initialData, type) : [], (data) => ({
342
+ const framed = yield* Effect.fromResult(frameCreateMessages(id, options.initialData, type));
343
+ const initialMessages = Array.map(framed, (data) => ({
362
344
  data,
363
345
  offset: offset = next(offset),
364
346
  timestamp: now
@@ -1,5 +1,5 @@
1
- import { I as Storage, L as ZERO_OFFSET } from "./streamsy-D9OCCdw0.js";
2
- import { a as MutationRejected, l as OperationResults, o as Mutations, u as Operations } from "./layer-8Y1cg6UL.js";
1
+ import { L as Storage, R as ZERO_OFFSET } from "./streamsy-BWX6z980.js";
2
+ import { a as MutationRejected, l as OperationResults, o as Mutations, u as Operations } from "./layer-B1JEYOZb.js";
3
3
  import { a as attachOwner, l as ownerOf } from "./route-internal-DNL0oGTN.js";
4
4
  import { i as OwnerRecords, n as CommitHooks, r as commitHookRegistry, t as ProjectionMarks } from "./projection-marks-RqurLPLA.js";
5
5
  import { Array, Context, Effect, Layer, Option, Order, Predicate, PubSub, Queue, Schedule, Semaphore, Stream } from "effect";
@@ -1,5 +1,5 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-D8jQpDG7.js";
2
- import { F as StreamsWriter, N as isProtocolError, P as StreamsReader, _ as CreateResult, g as AppendResult, nt as StreamId, z as isValid } from "./streamsy-D9OCCdw0.js";
2
+ import { B as isValid, F as StreamsReader, I as StreamsWriter, P as isProtocolError, _ as CreateResult, g as AppendResult, rt as StreamId } from "./streamsy-BWX6z980.js";
3
3
  import { t as generateCursor } from "./cursor-generator-DySXZ93b.js";
4
4
  import { Array, Clock, Context, DateTime, Deferred, Effect, Layer, Match, Option, Random, Record, Ref, Schedule, Stream } from "effect";
5
5
  import { HttpServerRequest, HttpServerResponse } from "effect/http";
@@ -683,6 +683,7 @@ function protocolErrorResponse(error, context) {
683
683
  AppendConflict: conflict,
684
684
  InvalidReadRequest: badRequest,
685
685
  InvalidForkRequest: badRequest,
686
+ InvalidCreateRequest: badRequest,
686
687
  InvalidAppendRequest: badRequest,
687
688
  StreamClosed: ({ offset }) => responses$1.empty(409, {
688
689
  "stream-closed": "true",