@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.
- package/README.md +122 -1
- package/dist/http/index.d.ts +1 -1
- package/dist/http/index.js +2 -2
- package/dist/{http-x2IjDHvw.js → http-B10ao6xE.js} +2 -2
- package/dist/{index-C26ncp7Y.d.ts → index-p68har8W.d.ts} +262 -4
- package/dist/index.d.ts +2 -2
- package/dist/index.js +232 -6
- package/dist/internal/index.d.ts +24 -1
- package/dist/internal/index.js +2 -2
- package/dist/{layer-DyezIxJT.js → layer-8Y1cg6UL.js} +2 -2
- package/dist/{layer-DJ-c63nY.js → layer-DQZj5tXr.js} +12 -8
- package/dist/{owner-records-BV5Un5R0.d.ts → owner-records-H7VEuBpy.d.ts} +10 -1
- package/dist/{program-DXUjw5B2.js → program-CYtMjdvD.js} +1 -1
- package/dist/protocol/index.d.ts +2 -2
- package/dist/protocol/index.js +3 -3
- package/dist/remote/index.d.ts +2 -2
- package/dist/remote/index.js +1 -1
- package/dist/route-internal-DNL0oGTN.js +93 -0
- package/dist/{streamsy-DJMArv09.js → streamsy-D9OCCdw0.js} +5 -60
- package/dist/testing/index.d.ts +2 -2
- package/dist/testing/index.js +67 -4
- package/package.json +1 -1
- package/dist/owner-BWQ2KvC_.js +0 -35
package/dist/testing/index.d.ts
CHANGED
|
@@ -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-
|
|
2
|
-
import { M as MemoryOptions, N as ProtocolOptions } from "../index-
|
|
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;
|
package/dist/testing/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as CommitBoundary, t as layer } from "../layer-
|
|
3
|
-
import { a as MutationRejected, t as layer$1 } from "../layer-
|
|
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
package/dist/owner-BWQ2KvC_.js
DELETED
|
@@ -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 };
|