@streamsy/core 0.5.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,5 +1,5 @@
1
- import { _ as StreamsWriter, dt as StreamId, g as StreamsReader, m as StorageCapabilities, r as Storage, rt as ChangeSnapshot } from "../owner-records-BV5Un5R0.js";
2
- import { M as MemoryOptions, N as ProtocolOptions } from "../index-C26ncp7Y.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
4
  interface StorageContractOptions {
5
5
  readonly name: string;
@@ -1,8 +1,8 @@
1
- import { I as next, M as Storage, N as ZERO_OFFSET, Q as StreamId, q as ProducerId, z as StorageFault } from "../streamsy-DJMArv09.js";
2
- import { n as CommitBoundary, t as layer } from "../layer-DJ-c63nY.js";
3
- import { a as MutationRejected, t as layer$1 } from "../layer-DyezIxJT.js";
1
+ import { B as next, I as Storage, L as ZERO_OFFSET, U as StorageFault, Z as ProducerId, nt as StreamId } from "../streamsy-D9OCCdw0.js";
2
+ import { n as CommitBoundary, t as layer } from "../layer-DQZj5tXr.js";
3
+ import { a as MutationRejected, t as layer$1 } from "../layer-8Y1cg6UL.js";
4
4
  import { t as OwnerRecords } from "../owner-records-C0p8jeC1.js";
5
- import { Array, Cause, Context, Deferred, Effect, Exit, Fiber, Layer, Match, Option, Predicate, Queue, Record, Ref, Stream } from "effect";
5
+ import { Array, Cause, Context, Deferred, Effect, Exit, Fiber, Layer, Match, Option, Predicate, PubSub, Queue, Record, Ref, Scope, Stream } from "effect";
6
6
  import { describe, expect, it } from "vitest";
7
7
  import { TestClock } from "effect/testing";
8
8
  // src/testing/storage-contract.ts
@@ -161,6 +161,20 @@ const StorageContract = {
161
161
  expect(yield* records.read("checkpoint")).toEqual(Option.some("1"));
162
162
  expect(Option.isSome(yield* storage.record(id))).toBe(true);
163
163
  }));
164
+ recordsTest("R3 committed reports a transaction's ids after its commit and nothing after a rollback", ({ boundary }) => Effect.gen(function* () {
165
+ const storage = yield* Storage;
166
+ const other = StreamId.make("other");
167
+ const committed = yield* storage.committed;
168
+ const failed = yield* Effect.exit(boundary.withTransaction(Effect.andThen(mutate(create()), Effect.fail("rollback"))));
169
+ expect(Exit.isFailure(failed)).toBe(true);
170
+ expect(yield* PubSub.takeUpTo(committed, Infinity)).toEqual([]);
171
+ yield* boundary.withTransaction(Effect.gen(function* () {
172
+ yield* mutate(create());
173
+ yield* mutate(create(record(other)));
174
+ expect(yield* PubSub.takeUpTo(committed, Infinity)).toEqual([]);
175
+ }));
176
+ expect(yield* PubSub.takeUpTo(committed, Infinity)).toEqual([[id, other]]);
177
+ }));
164
178
  test("01 Append advances tail and folds close atomically", Effect.gen(function* () {
165
179
  yield* mutate(create());
166
180
  applied(yield* mutate(append({ patch: {
@@ -684,6 +698,55 @@ const StorageContract = {
684
698
  expect(yield* storage.record(id)).toEqual(Option.none());
685
699
  }
686
700
  }), options.expected.fork === "chain" && options.expected.atomicScope === "store", "requires chain fork and store atomic scope");
701
+ test("34a committed broadcasts without replay and releases each subscription independently", Effect.gen(function* () {
702
+ const storage = yield* Storage;
703
+ let released = 0;
704
+ const scope = yield* Scope.fork(yield* Scope.Scope);
705
+ const first = yield* storage.committed.pipe(Effect.tap(() => Effect.addFinalizer(() => Effect.sync(() => {
706
+ released += 1;
707
+ }))), Scope.provide(scope));
708
+ yield* mutate(create());
709
+ expect(yield* PubSub.take(first)).toEqual([id]);
710
+ const second = yield* storage.committed;
711
+ expect(yield* PubSub.takeUpTo(second, Infinity)).toEqual([]);
712
+ yield* mutate(append());
713
+ expect(yield* PubSub.take(first)).toEqual([id]);
714
+ expect(yield* PubSub.take(second)).toEqual([id]);
715
+ yield* Scope.close(scope, Exit.void);
716
+ expect(released).toBe(1);
717
+ yield* mutate(remove());
718
+ expect(yield* PubSub.take(second)).toEqual([id]);
719
+ }));
720
+ test("35 committed reports the ids of create, append, delete and expiry after commit", Effect.gen(function* () {
721
+ const storage = yield* Storage;
722
+ const expiring = StreamId.make("expiring");
723
+ const committed = yield* storage.committed;
724
+ yield* mutate(create());
725
+ expect(yield* PubSub.takeUpTo(committed, Infinity)).toEqual([[id]]);
726
+ yield* mutate(append());
727
+ rejected(yield* Effect.flip(mutate(create())), "exists");
728
+ yield* mutate(remove());
729
+ yield* mutate(create({
730
+ ...record(expiring),
731
+ lifecycle: {
732
+ closed: false,
733
+ softDeleted: false,
734
+ expiresAtMs: 100
735
+ }
736
+ }));
737
+ yield* mutate({
738
+ _tag: "Delete",
739
+ streamId: expiring,
740
+ reason: "expiry",
741
+ expectedExpiresAtMs: 100
742
+ });
743
+ expect(yield* PubSub.takeUpTo(committed, Infinity)).toEqual([
744
+ [id],
745
+ [id],
746
+ [expiring],
747
+ [expiring]
748
+ ]);
749
+ }));
687
750
  });
688
751
  },
689
752
  /** The configured memory suite must exercise each shipped capability value. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamsy/core",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Effect-first Durable Streams protocol, storage contract, memory layer and toolkit.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -1,35 +0,0 @@
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
- export { isForeignOwner as a, checkWriteOwner as i, attachOwner as n, ownerOf as o, attachStorage as r, storageOf as s, CurrentOwner as t };