@dxos/pipeline 0.0.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.
Files changed (35) hide show
  1. package/LICENSE +105 -0
  2. package/README.md +41 -0
  3. package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
  4. package/dist/lib/neutral/chunk-J5LGTIGS.mjs.map +7 -0
  5. package/dist/lib/neutral/index.mjs +67 -0
  6. package/dist/lib/neutral/index.mjs.map +7 -0
  7. package/dist/lib/neutral/meta.json +1 -0
  8. package/dist/lib/neutral/testing/index.mjs +18 -0
  9. package/dist/lib/neutral/testing/index.mjs.map +7 -0
  10. package/dist/types/src/Pipeline.d.ts +31 -0
  11. package/dist/types/src/Pipeline.d.ts.map +1 -0
  12. package/dist/types/src/Pipeline.test.d.ts +2 -0
  13. package/dist/types/src/Pipeline.test.d.ts.map +1 -0
  14. package/dist/types/src/Stage.d.ts +64 -0
  15. package/dist/types/src/Stage.d.ts.map +1 -0
  16. package/dist/types/src/Stage.test.d.ts +2 -0
  17. package/dist/types/src/Stage.test.d.ts.map +1 -0
  18. package/dist/types/src/index.d.ts +3 -0
  19. package/dist/types/src/index.d.ts.map +1 -0
  20. package/dist/types/src/testing/capture.d.ts +8 -0
  21. package/dist/types/src/testing/capture.d.ts.map +1 -0
  22. package/dist/types/src/testing/capture.test.d.ts +2 -0
  23. package/dist/types/src/testing/capture.test.d.ts.map +1 -0
  24. package/dist/types/src/testing/index.d.ts +2 -0
  25. package/dist/types/src/testing/index.d.ts.map +1 -0
  26. package/dist/types/tsconfig.tsbuildinfo +1 -0
  27. package/package.json +45 -0
  28. package/src/Pipeline.test.ts +118 -0
  29. package/src/Pipeline.ts +54 -0
  30. package/src/Stage.test.ts +66 -0
  31. package/src/Stage.ts +128 -0
  32. package/src/index.ts +6 -0
  33. package/src/testing/capture.test.ts +18 -0
  34. package/src/testing/capture.ts +22 -0
  35. package/src/testing/index.ts +5 -0
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@dxos/pipeline",
3
+ "version": "0.0.0",
4
+ "description": "Generic back-pressured streaming pipeline (source → stages → sink).",
5
+ "homepage": "https://dxos.org",
6
+ "bugs": "https://github.com/dxos/dxos/issues",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/dxos/dxos"
10
+ },
11
+ "license": "FSL-1.1-Apache-2.0",
12
+ "author": "info@dxos.org",
13
+ "sideEffects": false,
14
+ "type": "module",
15
+ "exports": {
16
+ ".": {
17
+ "default": "./dist/lib/neutral/index.mjs",
18
+ "source": "./src/index.ts",
19
+ "types": "./dist/types/src/index.d.ts"
20
+ },
21
+ "./testing": {
22
+ "default": "./dist/lib/neutral/testing/index.mjs",
23
+ "source": "./src/testing/index.ts",
24
+ "types": "./dist/types/src/testing/index.d.ts"
25
+ }
26
+ },
27
+ "types": "dist/types/src/index.d.ts",
28
+ "files": [
29
+ "dist",
30
+ "src"
31
+ ],
32
+ "scripts": {},
33
+ "dependencies": {},
34
+ "devDependencies": {
35
+ "@dxos/effect": "workspace:*",
36
+ "effect": "catalog:",
37
+ "vitest": "catalog:"
38
+ },
39
+ "peerDependencies": {
40
+ "effect": "catalog:"
41
+ },
42
+ "publishConfig": {
43
+ "access": "public"
44
+ }
45
+ }
@@ -0,0 +1,118 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ import * as Context from 'effect/Context';
6
+ import * as Effect from 'effect/Effect';
7
+ import * as Layer from 'effect/Layer';
8
+ import * as Stream from 'effect/Stream';
9
+ import { describe, test } from 'vitest';
10
+
11
+ import { EffectEx } from '@dxos/effect';
12
+
13
+ import * as Pipeline from './Pipeline';
14
+ import * as Stage from './Stage';
15
+ import { captureSink } from './testing';
16
+
17
+ describe('Pipeline.run', () => {
18
+ test('chains stages left-to-right and drains to the sink', async ({ expect }) => {
19
+ const { sink, items } = captureSink<number>();
20
+ await EffectEx.runPromise(
21
+ Stream.fromIterable([1, 2, 3]).pipe(
22
+ Stage.map('double', (n) => Effect.succeed(n * 2)),
23
+ Stage.map('inc', (n) => Effect.succeed(n + 1)),
24
+ Pipeline.run({ sink }),
25
+ ),
26
+ );
27
+ expect(items).toEqual([3, 5, 7]);
28
+ });
29
+
30
+ test('propagates the shared context via the Requirements channel', async ({ expect }) => {
31
+ class Factor extends Context.Tag('Factor')<Factor, { readonly factor: number }>() {}
32
+ const { sink, items } = captureSink<number>();
33
+ const program = Stream.fromIterable([1, 2]).pipe(
34
+ Stage.map('scale', (n) => Factor.pipe(Effect.map(({ factor }) => n * factor))),
35
+ Pipeline.run({ sink }),
36
+ );
37
+ await EffectEx.runPromise(Effect.provide(program, Layer.succeed(Factor, { factor: 5 })));
38
+ expect(items).toEqual([5, 10]);
39
+ });
40
+
41
+ test('skips undefined stage outputs before the sink', async ({ expect }) => {
42
+ const { sink, items } = captureSink<number>();
43
+ await EffectEx.runPromise(
44
+ Stream.fromIterable([1, 2, 3, 4]).pipe(
45
+ Stage.map('evens', (n) => Effect.succeed(n % 2 === 0 ? n : undefined)),
46
+ Pipeline.run({ sink }),
47
+ ),
48
+ );
49
+ expect(items).toEqual([2, 4]);
50
+ });
51
+
52
+ test('drops undefined between stages so a mid-chain stage can no-op', async ({ expect }) => {
53
+ const { sink, items } = captureSink<number>();
54
+ await EffectEx.runPromise(
55
+ Stream.fromIterable([1, 2, 3, 4]).pipe(
56
+ // First stage no-ops on odds; the undefined must NOT reach the second stage.
57
+ Stage.map('evens', (n) => Effect.succeed(n % 2 === 0 ? n : undefined)),
58
+ // Second stage would produce NaN if it ever received `undefined`.
59
+ Stage.map('inc', (n) => Effect.succeed(n + 1)),
60
+ Pipeline.run({ sink }),
61
+ ),
62
+ );
63
+ expect(items).toEqual([3, 5]);
64
+ });
65
+ });
66
+
67
+ describe('Pipeline.run overflow', () => {
68
+ test('suspend (default) delivers every item to a slow sink — no loss', async ({ expect }) => {
69
+ const items: number[] = [];
70
+ // A sink that yields between commits; back pressure must still deliver all items.
71
+ const sink = (out: number) => Effect.sync(() => items.push(out)).pipe(Effect.zipLeft(Effect.yieldNow()));
72
+ await EffectEx.runPromise(
73
+ Stream.fromIterable(Array.from({ length: 50 }, (_unused, index) => index)).pipe(
74
+ Stage.map('id', (n) => Effect.succeed(n)),
75
+ Pipeline.run({ sink, overflow: 'suspend', bufferSize: 4 }),
76
+ ),
77
+ );
78
+ expect(items).toEqual(Array.from({ length: 50 }, (_unused, index) => index));
79
+ });
80
+
81
+ test('sliding pipeline runs to completion and delivers the final item', async ({ expect }) => {
82
+ const { sink, items } = captureSink<number>();
83
+ await EffectEx.runPromise(
84
+ Stream.fromIterable([1, 2, 3, 4, 5]).pipe(
85
+ Stage.map('id', (n) => Effect.succeed(n)),
86
+ Pipeline.run({ sink, overflow: 'sliding', bufferSize: 2 }),
87
+ ),
88
+ );
89
+ expect(items.length).toBeGreaterThan(0);
90
+ expect(items[items.length - 1]).toBe(5);
91
+ });
92
+
93
+ test('per-stage overflow override runs to completion', async ({ expect }) => {
94
+ const { sink, items } = captureSink<number>();
95
+ await EffectEx.runPromise(
96
+ Stream.fromIterable([1, 2, 3]).pipe(
97
+ Stage.map('id', (n) => Effect.succeed(n), { overflow: 'sliding', bufferSize: 1 }),
98
+ Pipeline.run({ sink }),
99
+ ),
100
+ );
101
+ expect(items[items.length - 1]).toBe(3);
102
+ });
103
+
104
+ test('per-stage sliding overflow coalesces stale input while a slow run is in flight', async ({ expect }) => {
105
+ const runs: number[] = [];
106
+ // A slow map over a synchronous 4-item source: while the first run sleeps, items 2/3/4 arrive and
107
+ // the input-side sliding buffer (capacity 1) keeps only the latest, so intermediate items drop.
108
+ const slow = Stage.map(
109
+ 'slow',
110
+ (n: number) => Effect.sync(() => runs.push(n)).pipe(Effect.zipRight(Effect.sleep('40 millis')), Effect.as(n)),
111
+ { overflow: 'sliding', bufferSize: 1 },
112
+ );
113
+ const { sink } = captureSink<number>();
114
+ await EffectEx.runPromise(Stream.fromIterable([1, 2, 3, 4]).pipe(slow, Pipeline.run({ sink })));
115
+ expect(runs.length).toBeLessThan(4);
116
+ expect(runs.at(-1)).toBe(4);
117
+ });
118
+ });
@@ -0,0 +1,54 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ // @import-as-namespace
6
+
7
+ import * as Effect from 'effect/Effect';
8
+ import * as Function from 'effect/Function';
9
+ import * as Stream from 'effect/Stream';
10
+
11
+ import * as Stage from './Stage';
12
+
13
+ /**
14
+ * Terminal commit for a pipeline: applies a stage's output value. Keeps stages pure — they emit
15
+ * typed `Out` descriptions and the sink performs the side effect (in-memory capture in tests, a
16
+ * database write in production).
17
+ */
18
+ export type Sink<Out, E = never, R = never> = (out: Out) => Effect.Effect<void, E, R>;
19
+
20
+ export type RunOptions<Out, E = never, R = never> = {
21
+ /** Terminal commit for the final stage output. */
22
+ readonly sink: Sink<Out, E, R>;
23
+ /** Pipeline-level overflow policy. Defaults to `suspend` (back pressure, never drop). */
24
+ readonly overflow?: Stage.Overflow;
25
+ /** Pipeline-level bounded-buffer capacity. */
26
+ readonly bufferSize?: number;
27
+ };
28
+
29
+ /**
30
+ * Drain a composed stream to a sink: apply the pipeline-level overflow buffer and run to
31
+ * completion. Cancellation is structural — interrupting the returned effect interrupts the stream
32
+ * and all in-flight stage work; there are no daemon fibers to leak. Compose with `pipe`, chaining
33
+ * `Stage` transforms ahead of it: `pipe(source, Stage.map(...), Stage.window(...), Pipeline.run({
34
+ * sink }))`. Mirrors `Stream.runForEach`'s own shape: the sink's `E`/`R` (bound once, from `options`)
35
+ * are kept independent of — and unioned with — the piped-in stream's own `E`/`R`, so the incoming
36
+ * stream's generics aren't forced to unify with the sink's at the call site.
37
+ */
38
+ export const run: {
39
+ <Out, E2, R2>(
40
+ options: RunOptions<Out, E2, R2>,
41
+ ): <E, R>(source: Stream.Stream<Out, E, R>) => Effect.Effect<void, E2 | E, R2 | R>;
42
+ <Out, E, R, E2, R2>(
43
+ source: Stream.Stream<Out, E, R>,
44
+ options: RunOptions<Out, E2, R2>,
45
+ ): Effect.Effect<void, E2 | E, R2 | R>;
46
+ } = Function.dual(2, (source: Stream.Stream<any, any, any>, options: RunOptions<any, any, any>) =>
47
+ source.pipe(
48
+ Stream.buffer({
49
+ capacity: options.bufferSize ?? Stage.DEFAULT_BUFFER_SIZE,
50
+ strategy: options.overflow ?? 'suspend',
51
+ }),
52
+ Stream.runForEach(options.sink),
53
+ ),
54
+ );
@@ -0,0 +1,66 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ import * as Chunk from 'effect/Chunk';
6
+ import * as Context from 'effect/Context';
7
+ import * as Effect from 'effect/Effect';
8
+ import * as Stream from 'effect/Stream';
9
+ import { describe, test } from 'vitest';
10
+
11
+ import { EffectEx } from '@dxos/effect';
12
+
13
+ import * as Stage from './Stage';
14
+
15
+ describe('Stage.map', () => {
16
+ test('applies the function to each item in order (concurrency 1)', async ({ expect }) => {
17
+ // Standalone stage: annotate the callback parameter to pin `In` (nothing upstream to infer from).
18
+ const stage = Stage.map('double', (n: number) => Effect.succeed(n * 2));
19
+ const out = await collect(stage(Stream.fromIterable([1, 2, 3])));
20
+ expect(out).toEqual([2, 4, 6]);
21
+ });
22
+
23
+ test('injects the shared context via the Requirements channel', async ({ expect }) => {
24
+ class Factor extends Context.Tag('Factor')<Factor, { readonly factor: number }>() {}
25
+ // `R` (the Factor requirement) infers from the callback; only `In` needs the annotation.
26
+ const stage = Stage.map('scale', (n: number) => Factor.pipe(Effect.map(({ factor }) => n * factor)));
27
+ const out = await collect(
28
+ stage(Stream.fromIterable([1, 2, 3])).pipe(Stream.provideService(Factor, { factor: 10 })),
29
+ );
30
+ expect(out).toEqual([10, 20, 30]);
31
+ });
32
+ });
33
+
34
+ describe('Stage.filter', () => {
35
+ test('drops items that do not match the predicate', async ({ expect }) => {
36
+ const stage = Stage.filter('evens', (n: number) => n % 2 === 0);
37
+ const out = await collect(stage(Stream.fromIterable([1, 2, 3, 4])));
38
+ expect(out).toEqual([2, 4]);
39
+ });
40
+ });
41
+
42
+ describe('Stage.window', () => {
43
+ test('invokes with a growing then sliding window of the last `size` items', async ({ expect }) => {
44
+ const stage = Stage.window('win', 2, (window: readonly number[]) => Effect.succeed([...window]));
45
+ const out = await collect(stage(Stream.fromIterable([1, 2, 3, 4])));
46
+ expect(out).toEqual([[1], [1, 2], [2, 3], [3, 4]]);
47
+ });
48
+
49
+ test('injects the shared context via the Requirements channel', async ({ expect }) => {
50
+ class Base extends Context.Tag('Base')<Base, { readonly base: number }>() {}
51
+ const stage = Stage.window('sum', 2, (window: readonly number[]) =>
52
+ Base.pipe(Effect.map(({ base }) => window.reduce((total, item) => total + item, base))),
53
+ );
54
+ const out = await collect(stage(Stream.fromIterable([1, 2, 3])).pipe(Stream.provideService(Base, { base: 100 })));
55
+ expect(out).toEqual([101, 103, 105]);
56
+ });
57
+
58
+ test('rejects a non-positive window size', ({ expect }) => {
59
+ expect(() => Stage.window('bad', 0, (window: readonly number[]) => Effect.succeed(window.length))).toThrow(
60
+ RangeError,
61
+ );
62
+ });
63
+ });
64
+
65
+ const collect = <Out, E>(stream: Stream.Stream<Out, E>): Promise<readonly Out[]> =>
66
+ EffectEx.runPromise(stream.pipe(Stream.runCollect, Effect.map(Chunk.toReadonlyArray)));
package/src/Stage.ts ADDED
@@ -0,0 +1,128 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ // @import-as-namespace
6
+
7
+ import * as Effect from 'effect/Effect';
8
+ import * as Stream from 'effect/Stream';
9
+
10
+ /**
11
+ * Overflow policy applied when a consumer cannot keep pace, mapped onto `Stream.buffer` strategies.
12
+ * - `suspend`: back pressure — never drop (default; correct for email/document processing).
13
+ * - `sliding`: drop the oldest buffered item, keep the latest (correct for live transcription).
14
+ * - `dropping`: drop the newest item when the buffer is full.
15
+ */
16
+ export type Overflow = 'suspend' | 'sliding' | 'dropping';
17
+
18
+ /** Default bounded-buffer capacity for both pipeline-level and per-stage buffering. */
19
+ export const DEFAULT_BUFFER_SIZE = 16;
20
+
21
+ /**
22
+ * A pipeline stage: a pipeable `Stream → Stream` transform, the same shape `Stream.mapEffect` /
23
+ * `Stream.filter` already have — generic over the *input* stream's own error/requirements (`E0`/
24
+ * `R0`) and unioning in the stage's own `E`/`R`, so stages compose in a `pipe` chain the same way
25
+ * Effect's own Stream operators do. Authors build stages with {@link map} / {@link window} /
26
+ * {@link filter}; shared dependencies flow through `R`, provided once at the edge via
27
+ * `Effect.provide`.
28
+ */
29
+ export type Stage<In, Out, E = never, R = never> = <E0 = never, R0 = never>(
30
+ self: Stream.Stream<In, E0, R0>,
31
+ ) => Stream.Stream<Out, E0 | E, R0 | R>;
32
+
33
+ /** Options shared by buffering stage constructors. */
34
+ type BufferOptions = {
35
+ /**
36
+ * Per-stage overflow override; when set, a bounded buffer is inserted at the stage's async
37
+ * boundary. For {@link map} the buffer sits *before* `mapEffect`, so under load it sheds/coalesces
38
+ * in-flight input (`sliding` keeps the latest queued item — true latest-wins — `dropping` drops
39
+ * new arrivals while a run is in flight). For {@link window} it sits after windowing (a window
40
+ * must see every item), bounding output rate.
41
+ */
42
+ readonly overflow?: Overflow;
43
+ /** Buffer capacity for the per-stage override. */
44
+ readonly bufferSize?: number;
45
+ };
46
+
47
+ export type MapOptions = BufferOptions & {
48
+ /** In-flight parallelism. Defaults to 1 (ordered + back-pressured); higher values may reorder. */
49
+ readonly concurrency?: number;
50
+ };
51
+
52
+ export type WindowOptions = BufferOptions;
53
+
54
+ // A per-stage buffer is inserted only when an overflow override is requested; otherwise the stage
55
+ // stays a pure transform and relies on the pipeline-level buffer.
56
+ const withBuffer =
57
+ (options: BufferOptions) =>
58
+ <A, E, R>(stream: Stream.Stream<A, E, R>): Stream.Stream<A, E, R> =>
59
+ options.overflow
60
+ ? Stream.buffer(stream, { capacity: options.bufferSize ?? DEFAULT_BUFFER_SIZE, strategy: options.overflow })
61
+ : stream;
62
+
63
+ /**
64
+ * 1:1 async transform. `fn` may return `undefined` to no-op for an item; the value is dropped
65
+ * before it reaches the next stage, so the returned stage's `Out` excludes `undefined`.
66
+ * `concurrency` defaults to 1 (ordered). `id` labels the per-item span for tracing.
67
+ *
68
+ * `Out`/`E`/`R` always infer from `fn`'s result; `In` only infers when the stage is composed inline
69
+ * in a `pipe` (pinned by the upstream stream). Built as a standalone value, pin `In` by annotating
70
+ * the callback parameter (`(item: T) => …`) or the binding (`const s: Stage<…> = …`). The four type
71
+ * parameters are intentionally all-or-nothing: passing a partial list (e.g. `map<In, Out>(…)`) is a
72
+ * compile error rather than silently forcing `E`/`R` to `never` and rejecting a service-using `fn`.
73
+ */
74
+ export const map =
75
+ <In, Out, E, R>(
76
+ id: string,
77
+ fn: (item: In) => Effect.Effect<Out, E, R>,
78
+ options: MapOptions = {},
79
+ ): Stage<In, Exclude<Out, undefined>, E, R> =>
80
+ <E0, R0>(self: Stream.Stream<In, E0, R0>) =>
81
+ self.pipe(
82
+ withBuffer(options),
83
+ // The overflow buffer sits *before* `mapEffect`: while a run is in flight it absorbs new
84
+ // input, so `sliding` coalesces to the latest queued item (latest-wins) and `dropping` sheds
85
+ // new arrivals. A buffer after `mapEffect` would bound outputs, not in-flight input, leaving
86
+ // overflow inert.
87
+ Stream.mapEffect((item) => fn(item).pipe(Effect.withSpan(id)), { concurrency: options.concurrency ?? 1 }),
88
+ Stream.filter((item): item is Exclude<Out, undefined> => item !== undefined),
89
+ );
90
+
91
+ /**
92
+ * Sliding-window transform: invokes `fn` once per incoming item with a fixed-size rolling view of
93
+ * the last `size` items. The window is bounded by `size`, so memory does not grow with stream
94
+ * length; it composes with (and is distinct from) the overflow buffer, which bounds rate mismatch.
95
+ * `fn` may return `undefined` to no-op, narrowing `Out` the same way {@link map} does. Type
96
+ * parameters follow {@link map}: `Out`/`E`/`R` infer from `fn`, `In` is pinned inline by the
97
+ * upstream or (standalone) by annotating the callback parameter or the binding, and a partial type
98
+ * argument list is a compile error.
99
+ */
100
+ export const window = <In, Out, E, R>(
101
+ id: string,
102
+ size: number,
103
+ fn: (window: readonly In[]) => Effect.Effect<Out, E, R>,
104
+ options: WindowOptions = {},
105
+ ): Stage<In, Exclude<Out, undefined>, E, R> => {
106
+ // A window must retain at least one item; a non-positive size makes `.slice(-size)` degenerate
107
+ // (`slice(-0)` returns the whole array, growing unbounded).
108
+ if (!Number.isInteger(size) || size < 1) {
109
+ throw new RangeError(`Stage.window size must be a positive integer: ${size}`);
110
+ }
111
+
112
+ return <E0, R0>(self: Stream.Stream<In, E0, R0>) =>
113
+ self.pipe(
114
+ Stream.mapAccum([] as readonly In[], (buffer, item) => {
115
+ const next = [...buffer, item].slice(-size);
116
+ return [next, next];
117
+ }),
118
+ Stream.mapEffect((buffer) => fn(buffer).pipe(Effect.withSpan(id)), { concurrency: 1 }),
119
+ withBuffer(options),
120
+ Stream.filter((item): item is Exclude<Out, undefined> => item !== undefined),
121
+ );
122
+ };
123
+
124
+ /** Drop items that do not match `pred`. */
125
+ export const filter =
126
+ <In>(id: string, pred: (item: In) => boolean): Stage<In, In> =>
127
+ <E0, R0>(self: Stream.Stream<In, E0, R0>) =>
128
+ self.pipe(Stream.filter(pred));
package/src/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ export * as Pipeline from './Pipeline';
6
+ export * as Stage from './Stage';
@@ -0,0 +1,18 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ import * as Effect from 'effect/Effect';
6
+ import { describe, test } from 'vitest';
7
+
8
+ import { EffectEx } from '@dxos/effect';
9
+
10
+ import { captureSink } from './index';
11
+
12
+ describe('captureSink', () => {
13
+ test('records every committed value in order', async ({ expect }) => {
14
+ const { sink, items } = captureSink<number>();
15
+ await EffectEx.runPromise(Effect.all([sink(1), sink(2), sink(3)]));
16
+ expect(items).toEqual([1, 2, 3]);
17
+ });
18
+ });
@@ -0,0 +1,22 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ import * as Effect from 'effect/Effect';
6
+
7
+ import * as Pipeline from '../Pipeline';
8
+
9
+ /** In-memory sink capturing every emitted value for assertions. */
10
+ export type CaptureSink<Out> = {
11
+ readonly sink: Pipeline.Sink<Out>;
12
+ readonly items: Out[];
13
+ };
14
+
15
+ export const captureSink = <Out>(): CaptureSink<Out> => {
16
+ const items: Out[] = [];
17
+ const sink: Pipeline.Sink<Out> = (out) =>
18
+ Effect.sync(() => {
19
+ items.push(out);
20
+ });
21
+ return { sink, items };
22
+ };
@@ -0,0 +1,5 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ export * from './capture';