@streamsy/core 0.4.0 → 0.5.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 +40 -3
- package/dist/{cursor-generator-CGz1TO_N.js → cursor-generator-DySXZ93b.js} +1 -2
- package/dist/http/index.d.ts +1 -1
- package/dist/http/index.js +2 -2
- package/dist/{http-EnNOUsIK.js → http-x2IjDHvw.js} +9 -11
- package/dist/{index-CFv8vZvy.d.ts → index-C26ncp7Y.d.ts} +63 -43
- package/dist/index.d.ts +2 -2
- package/dist/index.js +52 -51
- package/dist/internal/index.d.ts +1 -3
- package/dist/internal/index.js +2 -2
- package/dist/{layer-D8ybaCL2.js → layer-DJ-c63nY.js} +31 -31
- package/dist/{layer-KvknRFUT.js → layer-DyezIxJT.js} +22 -33
- package/dist/{owner-BQzMpfC1.js → owner-BWQ2KvC_.js} +1 -2
- package/dist/{owner-records-QDlssl__.d.ts → owner-records-BV5Un5R0.d.ts} +0 -22
- package/dist/{owner-records-CX6yU28i.js → owner-records-C0p8jeC1.js} +1 -2
- package/dist/{program-DJ8NpHIf.js → program-DXUjw5B2.js} +38 -55
- package/dist/protocol/index.d.ts +2 -4
- package/dist/protocol/index.js +4 -5
- package/dist/remote/index.d.ts +2 -4
- package/dist/remote/index.js +10 -14
- package/dist/{rolldown-runtime-D7D4PA-g.js → rolldown-runtime-D8jQpDG7.js} +1 -2
- package/dist/{streamsy-OjRubIPC.js → streamsy-DJMArv09.js} +61 -44
- package/dist/testing/index.d.ts +2 -10
- package/dist/testing/index.js +22 -27
- package/package.json +1 -1
package/dist/testing/index.d.ts
CHANGED
|
@@ -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-
|
|
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-BV5Un5R0.js";
|
|
2
|
+
import { M as MemoryOptions, N as ProtocolOptions } from "../index-C26ncp7Y.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 };
|
package/dist/testing/index.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { I as next, M as Storage, N as ZERO_OFFSET, Q as StreamId, q as ProducerId, z as StorageFault } from "../streamsy-
|
|
2
|
-
import { n as CommitBoundary, t as layer } from "../layer-
|
|
3
|
-
import { a as MutationRejected, t as layer$1 } from "../layer-
|
|
4
|
-
import { t as OwnerRecords } from "../owner-records-
|
|
5
|
-
import { Cause, Context, Deferred, Effect, Exit, Fiber, Layer, Match, Option, Predicate, Queue, Ref, Stream } from "effect";
|
|
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";
|
|
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";
|
|
6
6
|
import { describe, expect, it } from "vitest";
|
|
7
7
|
import { TestClock } from "effect/testing";
|
|
8
|
-
|
|
9
|
-
/** Executable Bun edge: a fresh scoped Layer and virtual clock for every case. */
|
|
8
|
+
// src/testing/storage-contract.ts
|
|
10
9
|
const id = StreamId.make("s");
|
|
11
10
|
const child = StreamId.make("child");
|
|
12
11
|
const producerId = ProducerId.make("p");
|
|
@@ -246,12 +245,12 @@ const StorageContract = {
|
|
|
246
245
|
yield* mutate(create());
|
|
247
246
|
const three = next(two), four = next(three);
|
|
248
247
|
yield* mutate(append({
|
|
249
|
-
messages: [
|
|
248
|
+
messages: Array.map([
|
|
250
249
|
four,
|
|
251
250
|
one,
|
|
252
251
|
three,
|
|
253
252
|
two
|
|
254
|
-
]
|
|
253
|
+
], (offset) => ({
|
|
255
254
|
offset,
|
|
256
255
|
data: encode(offset),
|
|
257
256
|
timestamp: 0
|
|
@@ -259,21 +258,21 @@ const StorageContract = {
|
|
|
259
258
|
patch: { currentOffset: four }
|
|
260
259
|
}));
|
|
261
260
|
const storage = yield* Storage;
|
|
262
|
-
expect((yield* storage.messages(id, {})
|
|
261
|
+
expect(Array.map(yield* storage.messages(id, {}), (m) => m.offset)).toEqual([
|
|
263
262
|
one,
|
|
264
263
|
two,
|
|
265
264
|
three,
|
|
266
265
|
four
|
|
267
266
|
]);
|
|
268
|
-
expect((yield* storage.messages(id, {
|
|
267
|
+
expect(Array.map(yield* storage.messages(id, {
|
|
269
268
|
after: one,
|
|
270
269
|
until: three
|
|
271
|
-
})
|
|
272
|
-
expect((yield* storage.messages(id, {
|
|
270
|
+
}), (m) => m.offset)).toEqual([two, three]);
|
|
271
|
+
expect(Array.map(yield* storage.messages(id, {
|
|
273
272
|
after: one,
|
|
274
273
|
until: four,
|
|
275
274
|
limit: 1
|
|
276
|
-
})
|
|
275
|
+
}), (m) => m.offset)).toEqual([two]);
|
|
277
276
|
expect(yield* storage.messages(id, { limit: 0 })).toEqual([]);
|
|
278
277
|
}));
|
|
279
278
|
test("08 first changes element differs from stale observed offset", Effect.gen(function* () {
|
|
@@ -457,7 +456,7 @@ const StorageContract = {
|
|
|
457
456
|
yield* fork();
|
|
458
457
|
applied(yield* mutate(remove()), options.expected.fork === "chain" ? "SoftDeleted" : "Purged");
|
|
459
458
|
const storage = yield* Storage;
|
|
460
|
-
expect((yield* storage.messages(child, {})
|
|
459
|
+
expect(Array.map(yield* storage.messages(child, {}), (m) => new TextDecoder().decode(m.data))).toEqual(["a"]);
|
|
461
460
|
if (options.expected.fork === "chain") rejected(yield* Effect.flip(mutate(remove())), "gone");
|
|
462
461
|
yield* mutate(remove(child));
|
|
463
462
|
expect(yield* storage.record(id)).toEqual(Option.none());
|
|
@@ -631,7 +630,7 @@ const StorageContract = {
|
|
|
631
630
|
}));
|
|
632
631
|
applied(yield* fork(child, grandchild), "Created");
|
|
633
632
|
applied(yield* fork(id, sibling, one), "Created");
|
|
634
|
-
const texts = (streamId) => storage.messages(streamId, {}).pipe(Effect.map((messages) =>
|
|
633
|
+
const texts = (streamId) => storage.messages(streamId, {}).pipe(Effect.map((messages) => Array.map(messages, (m) => new TextDecoder().decode(m.data))));
|
|
635
634
|
expect(yield* texts(grandchild)).toEqual(["a", "child"]);
|
|
636
635
|
expect(yield* texts(sibling)).toEqual(["a"]);
|
|
637
636
|
const deletion = options.expected.fork === "chain" ? "SoftDeleted" : "Purged";
|
|
@@ -678,9 +677,9 @@ const StorageContract = {
|
|
|
678
677
|
};
|
|
679
678
|
const outcome = yield* storage.mutate({ operations: deleteFirst ? [remove(), creation] : [creation, remove()] });
|
|
680
679
|
expect(outcome).toMatchObject({ _tag: "Applied" });
|
|
681
|
-
if (Predicate.isTagged(outcome, "Applied")) expect(outcome.results
|
|
680
|
+
if (Predicate.isTagged(outcome, "Applied")) expect(Array.map(outcome.results, ({ _tag: tag }) => tag)).toEqual(deleteFirst ? ["SoftDeleted", "Created"] : ["Created", "SoftDeleted"]);
|
|
682
681
|
expect((yield* current).lifecycle.softDeleted).toBe(true);
|
|
683
|
-
expect((yield* storage.messages(child, {})
|
|
682
|
+
expect(Array.map(yield* storage.messages(child, {}), (m) => m.offset)).toEqual([one]);
|
|
684
683
|
yield* mutate(remove(child));
|
|
685
684
|
expect(yield* storage.record(id)).toEqual(Option.none());
|
|
686
685
|
}
|
|
@@ -690,17 +689,16 @@ const StorageContract = {
|
|
|
690
689
|
/** The configured memory suite must exercise each shipped capability value. */
|
|
691
690
|
assertModes(configurations) {
|
|
692
691
|
it("configured contract runs cover both shipped capability modes", () => {
|
|
693
|
-
for (const [key, expected] of
|
|
692
|
+
for (const [key, expected] of Record.toEntries({
|
|
694
693
|
fork: ["chain", "copy"],
|
|
695
694
|
atomicScope: ["store", "stream"],
|
|
696
695
|
wake: ["push", "poll"],
|
|
697
696
|
expiryIndex: ["indexed", "lazy"]
|
|
698
|
-
})) expect(new Set(
|
|
697
|
+
})) expect(new Set(Array.map(configurations, (c) => Option.getOrUndefined(Array.findFirst(Record.toEntries(c), ([k]) => k === key))?.[1]))).toEqual(new Set(expected));
|
|
699
698
|
});
|
|
700
699
|
}
|
|
701
700
|
};
|
|
702
|
-
|
|
703
|
-
//#region src/testing/fault-injection.ts
|
|
701
|
+
// src/testing/fault-injection.ts
|
|
704
702
|
/** One selected attempt per decorator; "after" injects only if that mutation applies. */
|
|
705
703
|
function faultyStorage(source, options) {
|
|
706
704
|
return Layer.effect(Storage, Effect.gen(function* () {
|
|
@@ -724,8 +722,7 @@ function faultyStorage(source, options) {
|
|
|
724
722
|
});
|
|
725
723
|
})).pipe(Layer.provide(source));
|
|
726
724
|
}
|
|
727
|
-
|
|
728
|
-
//#region src/testing/streams-test.ts
|
|
725
|
+
// src/testing/streams-test.ts
|
|
729
726
|
var StreamsTest = class extends Context.Service()("@streamsy/core/StreamsTest") {};
|
|
730
727
|
/** Real protocol and memory, with deterministic observation at the scoped changes boundary. */
|
|
731
728
|
const layerTest = (options = {}) => Layer.effectContext(Effect.gen(function* () {
|
|
@@ -749,9 +746,7 @@ const layerTest = (options = {}) => Layer.effectContext(Effect.gen(function* ()
|
|
|
749
746
|
snapshot: Queue.take(snapshots)
|
|
750
747
|
}));
|
|
751
748
|
})).pipe(Layer.provide(layer(options)));
|
|
752
|
-
|
|
753
|
-
//#region src/testing/expect-failure-tag.ts
|
|
749
|
+
// src/testing/expect-failure-tag.ts
|
|
754
750
|
/** An unexpected success stays a failure so the enclosing test cannot pass. */
|
|
755
751
|
const expectFailureTag = (effect, tag) => effect.pipe(Effect.flip, Effect.tap((error) => Effect.sync(() => expect(error._tag).toBe(tag))));
|
|
756
|
-
//#endregion
|
|
757
752
|
export { StorageContract, StreamsTest, expectFailureTag, faultyStorage, layerTest };
|