@livestore/utils 0.4.0 → 0.5.0-dev.1
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/dist/.tsbuildinfo +1 -1
- package/dist/Deferred.d.ts.map +1 -1
- package/dist/NoopTracer.d.ts +7 -8
- package/dist/NoopTracer.d.ts.map +1 -1
- package/dist/NoopTracer.js +3 -18
- package/dist/NoopTracer.js.map +1 -1
- package/dist/NoopTracer.test.d.ts +2 -0
- package/dist/NoopTracer.test.d.ts.map +1 -0
- package/dist/NoopTracer.test.js +29 -0
- package/dist/NoopTracer.test.js.map +1 -0
- package/dist/base64.d.ts.map +1 -1
- package/dist/binary.d.ts.map +1 -1
- package/dist/browser/Opfs/Opfs.d.ts +179 -29
- package/dist/browser/Opfs/Opfs.d.ts.map +1 -1
- package/dist/browser/Opfs/Opfs.js +134 -309
- package/dist/browser/Opfs/Opfs.js.map +1 -1
- package/dist/browser/Opfs/debug-utils.d.ts.map +1 -1
- package/dist/browser/Opfs/debug-utils.js +6 -5
- package/dist/browser/Opfs/debug-utils.js.map +1 -1
- package/dist/browser/Opfs/mod.js +3 -3
- package/dist/browser/Opfs/utils.d.ts +8 -8
- package/dist/browser/Opfs/utils.d.ts.map +1 -1
- package/dist/browser/Opfs/utils.js +35 -26
- package/dist/browser/Opfs/utils.js.map +1 -1
- package/dist/browser/QuotaExceededError.d.ts +10 -9
- package/dist/browser/QuotaExceededError.d.ts.map +1 -1
- package/dist/browser/WebChannelBrowser.d.ts.map +1 -1
- package/dist/browser/WebChannelBrowser.js +25 -14
- package/dist/browser/WebChannelBrowser.js.map +1 -1
- package/dist/browser/WebError.d.ts +55 -87
- package/dist/browser/WebError.d.ts.map +1 -1
- package/dist/browser/WebError.js +92 -85
- package/dist/browser/WebError.js.map +1 -1
- package/dist/browser/WebError.test.js +7 -7
- package/dist/browser/WebError.test.js.map +1 -1
- package/dist/browser/WebLock.d.ts +1 -1
- package/dist/browser/WebLock.d.ts.map +1 -1
- package/dist/browser/WebLock.js +13 -13
- package/dist/browser/WebLock.js.map +1 -1
- package/dist/browser/mod.js +6 -6
- package/dist/cuid/cuid.browser.d.ts.map +1 -1
- package/dist/cuid/cuid.node.d.ts.map +1 -1
- package/dist/effect/Debug.d.ts +4 -7
- package/dist/effect/Debug.d.ts.map +1 -1
- package/dist/effect/Debug.js +34 -40
- package/dist/effect/Debug.js.map +1 -1
- package/dist/effect/Effect.d.ts +31 -22
- package/dist/effect/Effect.d.ts.map +1 -1
- package/dist/effect/Effect.js +54 -50
- package/dist/effect/Effect.js.map +1 -1
- package/dist/effect/Effect.test.d.ts +2 -0
- package/dist/effect/Effect.test.d.ts.map +1 -0
- package/dist/effect/Effect.test.js +72 -0
- package/dist/effect/Effect.test.js.map +1 -0
- package/dist/effect/Error.d.ts +4 -6
- package/dist/effect/Error.d.ts.map +1 -1
- package/dist/effect/Logger.d.ts +0 -6
- package/dist/effect/Logger.d.ts.map +1 -1
- package/dist/effect/Logger.js +0 -32
- package/dist/effect/Logger.js.map +1 -1
- package/dist/effect/OtelTracer.d.ts +1 -1
- package/dist/effect/OtelTracer.d.ts.map +1 -1
- package/dist/effect/OtelTracer.js +2 -3
- package/dist/effect/OtelTracer.js.map +1 -1
- package/dist/effect/RpcClient.d.ts +9 -9
- package/dist/effect/RpcClient.d.ts.map +1 -1
- package/dist/effect/RpcClient.js +113 -84
- package/dist/effect/RpcClient.js.map +1 -1
- package/dist/effect/Schedule.d.ts +1 -1
- package/dist/effect/Schedule.d.ts.map +1 -1
- package/dist/effect/Schedule.js +2 -2
- package/dist/effect/Schedule.js.map +1 -1
- package/dist/effect/Schema/debug-diff.d.ts +1 -1
- package/dist/effect/Schema/debug-diff.d.ts.map +1 -1
- package/dist/effect/Schema/debug-diff.js +5 -7
- package/dist/effect/Schema/debug-diff.js.map +1 -1
- package/dist/effect/Schema/debug-diff.test.js +8 -5
- package/dist/effect/Schema/debug-diff.test.js.map +1 -1
- package/dist/effect/Schema/index.d.ts +28 -20
- package/dist/effect/Schema/index.d.ts.map +1 -1
- package/dist/effect/Schema/index.js +56 -29
- package/dist/effect/Schema/index.js.map +1 -1
- package/dist/effect/Stream.d.ts +13 -5
- package/dist/effect/Stream.d.ts.map +1 -1
- package/dist/effect/Stream.js +19 -12
- package/dist/effect/Stream.js.map +1 -1
- package/dist/effect/Stream.test.js +10 -10
- package/dist/effect/Stream.test.js.map +1 -1
- package/dist/effect/Subscribable.d.ts +9 -3
- package/dist/effect/Subscribable.d.ts.map +1 -1
- package/dist/effect/Subscribable.js +20 -35
- package/dist/effect/Subscribable.js.map +1 -1
- package/dist/effect/SubscriptionRef.d.ts +5 -6
- package/dist/effect/SubscriptionRef.d.ts.map +1 -1
- package/dist/effect/SubscriptionRef.js +2 -3
- package/dist/effect/SubscriptionRef.js.map +1 -1
- package/dist/effect/TaskTracing.d.ts +1 -1
- package/dist/effect/TaskTracing.d.ts.map +1 -1
- package/dist/effect/TaskTracing.js +12 -16
- package/dist/effect/TaskTracing.js.map +1 -1
- package/dist/effect/WebChannel/WebChannel.d.ts +7 -7
- package/dist/effect/WebChannel/WebChannel.d.ts.map +1 -1
- package/dist/effect/WebChannel/WebChannel.js +69 -48
- package/dist/effect/WebChannel/WebChannel.js.map +1 -1
- package/dist/effect/WebChannel/WebChannel.test.js +16 -16
- package/dist/effect/WebChannel/WebChannel.test.js.map +1 -1
- package/dist/effect/WebChannel/broadcastChannelWithAck.d.ts.map +1 -1
- package/dist/effect/WebChannel/broadcastChannelWithAck.js +18 -11
- package/dist/effect/WebChannel/broadcastChannelWithAck.js.map +1 -1
- package/dist/effect/WebChannel/common.d.ts +16 -17
- package/dist/effect/WebChannel/common.d.ts.map +1 -1
- package/dist/effect/WebChannel/common.js +6 -6
- package/dist/effect/WebChannel/common.js.map +1 -1
- package/dist/effect/WebChannel/mod.js +3 -3
- package/dist/effect/WebSocket.d.ts +4 -6
- package/dist/effect/WebSocket.d.ts.map +1 -1
- package/dist/effect/WebSocket.js +4 -4
- package/dist/effect/WebSocket.js.map +1 -1
- package/dist/effect/WebSocket.test.js +3 -3
- package/dist/effect/WebSocket.test.js.map +1 -1
- package/dist/effect/mod.browser-build.test.d.ts +2 -0
- package/dist/effect/mod.browser-build.test.d.ts.map +1 -0
- package/dist/effect/mod.browser-build.test.js +18 -0
- package/dist/effect/mod.browser-build.test.js.map +1 -0
- package/dist/effect/mod.d.ts +13 -15
- package/dist/effect/mod.d.ts.map +1 -1
- package/dist/effect/mod.js +28 -33
- package/dist/effect/mod.js.map +1 -1
- package/dist/effect/spanEvent.d.ts.map +1 -1
- package/dist/effect/spanEvent.js +2 -2
- package/dist/effect/spanEvent.js.map +1 -1
- package/dist/effect/spanEvent.test.js +11 -14
- package/dist/effect/spanEvent.test.js.map +1 -1
- package/dist/env.d.ts.map +1 -1
- package/dist/env.js +1 -1
- package/dist/env.js.map +1 -1
- package/dist/fast-deep-equal.d.ts.map +1 -1
- package/dist/fast-deep-equal.js +1 -2
- package/dist/fast-deep-equal.js.map +1 -1
- package/dist/misc.d.ts.map +1 -1
- package/dist/misc.js +3 -3
- package/dist/misc.js.map +1 -1
- package/dist/mod.d.ts +1 -36
- package/dist/mod.d.ts.map +1 -1
- package/dist/mod.js +19 -27
- package/dist/mod.js.map +1 -1
- package/dist/node/mod.d.ts +11 -36
- package/dist/node/mod.d.ts.map +1 -1
- package/dist/node/mod.js +17 -42
- package/dist/node/mod.js.map +1 -1
- package/dist/object/index.d.ts +0 -9
- package/dist/object/index.d.ts.map +1 -1
- package/dist/object/index.js +1 -10
- package/dist/object/index.js.map +1 -1
- package/dist/object/stringify-object.d.ts.map +1 -1
- package/dist/object/stringify-object.test.js +1 -1
- package/dist/promise.d.ts.map +1 -1
- package/dist/qr.d.ts.map +1 -1
- package/dist/set.d.ts.map +1 -1
- package/dist/string.d.ts +0 -2
- package/dist/string.d.ts.map +1 -1
- package/dist/string.js +0 -2
- package/dist/string.js.map +1 -1
- package/package.json +38 -56
- package/src/NoopTracer.test.ts +36 -0
- package/src/NoopTracer.ts +18 -41
- package/src/browser/Opfs/Opfs.ts +304 -277
- package/src/browser/Opfs/debug-utils.ts +7 -6
- package/src/browser/Opfs/utils.ts +36 -26
- package/src/browser/QuotaExceededError.ts +13 -10
- package/src/browser/WebChannelBrowser.ts +25 -11
- package/src/browser/WebError.test.ts +6 -6
- package/src/browser/WebError.ts +107 -133
- package/src/browser/WebLock.ts +13 -14
- package/src/effect/Debug.ts +69 -78
- package/src/effect/Effect.test.ts +117 -0
- package/src/effect/Effect.ts +86 -73
- package/src/effect/Logger.ts +0 -48
- package/src/effect/OtelTracer.ts +2 -3
- package/src/effect/RpcClient.ts +126 -93
- package/src/effect/Schedule.ts +4 -5
- package/src/effect/Schema/debug-diff.test.ts +6 -6
- package/src/effect/Schema/debug-diff.ts +6 -8
- package/src/effect/Schema/index.ts +122 -61
- package/src/effect/Stream.test.ts +9 -9
- package/src/effect/Stream.ts +23 -16
- package/src/effect/Subscribable.ts +31 -42
- package/src/effect/SubscriptionRef.ts +8 -12
- package/src/effect/TaskTracing.ts +13 -16
- package/src/effect/WebChannel/WebChannel.test.ts +23 -23
- package/src/effect/WebChannel/WebChannel.ts +87 -56
- package/src/effect/WebChannel/broadcastChannelWithAck.ts +21 -11
- package/src/effect/WebChannel/common.ts +14 -15
- package/src/effect/WebSocket.test.ts +2 -2
- package/src/effect/WebSocket.ts +9 -6
- package/src/effect/mod.browser-build.test.ts +19 -0
- package/src/effect/mod.ts +37 -69
- package/src/effect/spanEvent.test.ts +10 -13
- package/src/effect/spanEvent.ts +5 -3
- package/src/fast-deep-equal.ts +4 -5
- package/src/misc.ts +3 -3
- package/src/mod.ts +5 -41
- package/src/node/mod.ts +20 -46
- package/src/object/index.ts +0 -24
- package/src/string.ts +0 -3
- package/dist/effect/BucketQueue.d.ts +0 -20
- package/dist/effect/BucketQueue.d.ts.map +0 -1
- package/dist/effect/BucketQueue.js +0 -34
- package/dist/effect/BucketQueue.js.map +0 -1
- package/dist/effect/Scheduler.d.ts +0 -4
- package/dist/effect/Scheduler.d.ts.map +0 -1
- package/dist/effect/Scheduler.js +0 -9
- package/dist/effect/Scheduler.js.map +0 -1
- package/dist/effect/ServiceContext.d.ts +0 -37
- package/dist/effect/ServiceContext.d.ts.map +0 -1
- package/dist/effect/ServiceContext.js +0 -55
- package/dist/effect/ServiceContext.js.map +0 -1
- package/dist/guards.d.ts +0 -20
- package/dist/guards.d.ts.map +0 -1
- package/dist/guards.js +0 -20
- package/dist/guards.js.map +0 -1
- package/dist/node/ChildProcessRunner/ChildProcessRunner.d.ts +0 -4
- package/dist/node/ChildProcessRunner/ChildProcessRunner.d.ts.map +0 -1
- package/dist/node/ChildProcessRunner/ChildProcessRunner.js +0 -128
- package/dist/node/ChildProcessRunner/ChildProcessRunner.js.map +0 -1
- package/dist/node/ChildProcessRunner/ChildProcessRunnerTest/ChildProcessRunner.test.d.ts +0 -10
- package/dist/node/ChildProcessRunner/ChildProcessRunnerTest/ChildProcessRunner.test.d.ts.map +0 -1
- package/dist/node/ChildProcessRunner/ChildProcessRunnerTest/ChildProcessRunner.test.js +0 -217
- package/dist/node/ChildProcessRunner/ChildProcessRunnerTest/ChildProcessRunner.test.js.map +0 -1
- package/dist/node/ChildProcessRunner/ChildProcessRunnerTest/schema.d.ts +0 -84
- package/dist/node/ChildProcessRunner/ChildProcessRunnerTest/schema.d.ts.map +0 -1
- package/dist/node/ChildProcessRunner/ChildProcessRunnerTest/schema.js +0 -68
- package/dist/node/ChildProcessRunner/ChildProcessRunnerTest/schema.js.map +0 -1
- package/dist/node/ChildProcessRunner/ChildProcessRunnerTest/serializedWorker.d.ts +0 -2
- package/dist/node/ChildProcessRunner/ChildProcessRunnerTest/serializedWorker.d.ts.map +0 -1
- package/dist/node/ChildProcessRunner/ChildProcessRunnerTest/serializedWorker.js +0 -52
- package/dist/node/ChildProcessRunner/ChildProcessRunnerTest/serializedWorker.js.map +0 -1
- package/dist/node/ChildProcessRunner/ChildProcessWorker.d.ts +0 -23
- package/dist/node/ChildProcessRunner/ChildProcessWorker.d.ts.map +0 -1
- package/dist/node/ChildProcessRunner/ChildProcessWorker.js +0 -138
- package/dist/node/ChildProcessRunner/ChildProcessWorker.js.map +0 -1
- package/dist/object/omit.d.ts +0 -3
- package/dist/object/omit.d.ts.map +0 -1
- package/dist/object/omit.js +0 -14
- package/dist/object/omit.js.map +0 -1
- package/dist/object/pick.d.ts +0 -14
- package/dist/object/pick.d.ts.map +0 -1
- package/dist/object/pick.js +0 -17
- package/dist/object/pick.js.map +0 -1
- package/dist/time.d.ts +0 -12
- package/dist/time.d.ts.map +0 -1
- package/dist/time.js +0 -22
- package/dist/time.js.map +0 -1
- package/src/effect/BucketQueue.ts +0 -49
- package/src/effect/Scheduler.ts +0 -13
- package/src/effect/ServiceContext.ts +0 -108
- package/src/guards.ts +0 -23
- package/src/node/ChildProcessRunner/ChildProcessRunner.ts +0 -148
- package/src/node/ChildProcessRunner/ChildProcessRunnerTest/ChildProcessRunner.test.ts +0 -311
- package/src/node/ChildProcessRunner/ChildProcessRunnerTest/schema.ts +0 -78
- package/src/node/ChildProcessRunner/ChildProcessRunnerTest/serializedWorker.ts +0 -65
- package/src/node/ChildProcessRunner/ChildProcessWorker.ts +0 -169
- package/src/object/omit.ts +0 -17
- package/src/object/pick.ts +0 -27
- package/src/time.ts +0 -25
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Effect, Option, Stream } from 'effect'
|
|
1
|
+
import { Effect, Option, Result, Stream } from 'effect'
|
|
2
2
|
import { describe, expect, it } from 'vitest'
|
|
3
3
|
|
|
4
4
|
import { concatWithLastElement, runCollectReadonlyArray } from './Stream.ts'
|
|
@@ -61,10 +61,10 @@ describe('concatWithLastElement', () => {
|
|
|
61
61
|
const stream1 = Stream.fail('first-error')
|
|
62
62
|
const result = concatWithLastElement(stream1, () => Stream.make('should-not-reach'))
|
|
63
63
|
|
|
64
|
-
const outcome = await Effect.runPromise(Effect.
|
|
65
|
-
expect(outcome._tag).toBe('
|
|
66
|
-
if (outcome
|
|
67
|
-
expect(outcome.
|
|
64
|
+
const outcome = await Effect.runPromise(Effect.result(runCollectReadonlyArray(result)))
|
|
65
|
+
expect(outcome._tag).toBe('Failure')
|
|
66
|
+
if (Result.isFailure(outcome) === true) {
|
|
67
|
+
expect(outcome.failure).toBe('first-error')
|
|
68
68
|
}
|
|
69
69
|
})
|
|
70
70
|
|
|
@@ -72,10 +72,10 @@ describe('concatWithLastElement', () => {
|
|
|
72
72
|
const stream1 = Stream.make(1, 2)
|
|
73
73
|
const result = concatWithLastElement(stream1, () => Stream.fail('second-error'))
|
|
74
74
|
|
|
75
|
-
const outcome = await Effect.runPromise(Effect.
|
|
76
|
-
expect(outcome._tag).toBe('
|
|
77
|
-
if (outcome
|
|
78
|
-
expect(outcome.
|
|
75
|
+
const outcome = await Effect.runPromise(Effect.result(runCollectReadonlyArray(result)))
|
|
76
|
+
expect(outcome._tag).toBe('Failure')
|
|
77
|
+
if (Result.isFailure(outcome) === true) {
|
|
78
|
+
expect(outcome.failure).toBe('second-error')
|
|
79
79
|
}
|
|
80
80
|
})
|
|
81
81
|
|
package/src/effect/Stream.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
/** biome-ignore-all lint/suspicious/useIterableCallbackReturn: Biome bug */
|
|
2
1
|
export * from 'effect/Stream'
|
|
3
2
|
|
|
4
|
-
import { type Cause,
|
|
5
|
-
import { dual } from 'effect/Function'
|
|
3
|
+
import { type Cause, Array, Effect, Function, Option, pipe, Ref, Stream } from 'effect'
|
|
6
4
|
|
|
7
5
|
export const tapLog = <R, E, A>(stream: Stream.Stream<A, E, R>): Stream.Stream<A, E, R> =>
|
|
8
|
-
|
|
6
|
+
tapArray<never, never, A, void>(Effect.forEach((_) => Effect.succeed(console.log(_))))(stream)
|
|
9
7
|
|
|
10
8
|
export const tapSync =
|
|
11
9
|
<A>(tapFn: (a: A) => unknown) =>
|
|
@@ -15,15 +13,24 @@ export const tapSync =
|
|
|
15
13
|
export const tapLogWithLabel =
|
|
16
14
|
(label: string) =>
|
|
17
15
|
<R, E, A>(stream: Stream.Stream<A, E, R>): Stream.Stream<A, E, R> =>
|
|
18
|
-
|
|
16
|
+
tapArray<never, never, A, void>(Effect.forEach((_) => Effect.succeed(console.log(label, _))))(stream)
|
|
19
17
|
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Runs an effect once for each array batch emitted by the stream, preserving
|
|
20
|
+
* the original stream elements.
|
|
21
|
+
*
|
|
22
|
+
* Use this for batch-oriented side effects such as `Queue.offerAll`. For
|
|
23
|
+
* element-wise side effects, prefer `Stream.tap`.
|
|
24
|
+
*
|
|
25
|
+
* @see {@link Stream.tap} for running an effect once per element.
|
|
26
|
+
*/
|
|
27
|
+
export const tapArray =
|
|
28
|
+
<R1, E1, A, Z>(f: (a: ReadonlyArray<A>) => Effect.Effect<Z, E1, R1>) =>
|
|
22
29
|
<R, E>(self: Stream.Stream<A, E, R>): Stream.Stream<A, E1 | E, R1 | R> =>
|
|
23
|
-
Stream.
|
|
30
|
+
Stream.mapArrayEffect(self, (array) =>
|
|
24
31
|
pipe(
|
|
25
|
-
f(
|
|
26
|
-
Effect.map(() =>
|
|
32
|
+
f(array),
|
|
33
|
+
Effect.map(() => array),
|
|
27
34
|
),
|
|
28
35
|
)
|
|
29
36
|
|
|
@@ -68,18 +75,18 @@ export const skipRepeated_ = <R, E, A>(
|
|
|
68
75
|
* It's different than `Stream.runHead` which runs the stream to completion.
|
|
69
76
|
* */
|
|
70
77
|
export const runFirst = <A, E, R>(stream: Stream.Stream<A, E, R>): Effect.Effect<Option.Option<A>, E, R> =>
|
|
71
|
-
stream.pipe(Stream.take(1), Stream.runCollect, Effect.map(
|
|
78
|
+
stream.pipe(Stream.take(1), Stream.runCollect, Effect.map(Array.head))
|
|
72
79
|
|
|
73
80
|
/**
|
|
74
|
-
* Returns the first element of the stream or throws a `
|
|
81
|
+
* Returns the first element of the stream or throws a `NoSuchElementError` if the stream is empty.
|
|
75
82
|
* It's different than `Stream.runHead` which runs the stream to completion.
|
|
76
83
|
* */
|
|
77
84
|
export const runFirstUnsafe = <A, E, R>(
|
|
78
85
|
stream: Stream.Stream<A, E, R>,
|
|
79
|
-
): Effect.Effect<A, Cause.
|
|
86
|
+
): Effect.Effect<A, Cause.NoSuchElementError | E, R> => runFirst(stream).pipe(Effect.flatMap(Effect.fromOption))
|
|
80
87
|
|
|
81
88
|
export const runCollectReadonlyArray = <A, E, R>(stream: Stream.Stream<A, E, R>): Effect.Effect<readonly A[], E, R> =>
|
|
82
|
-
stream.pipe(Stream.runCollect
|
|
89
|
+
stream.pipe(Stream.runCollect)
|
|
83
90
|
|
|
84
91
|
/**
|
|
85
92
|
* Concatenates two streams where the second stream has access to the last element
|
|
@@ -120,7 +127,7 @@ export const concatWithLastElement: {
|
|
|
120
127
|
stream: Stream.Stream<A1, E1, R1>,
|
|
121
128
|
getStream2: (lastElement: Option.Option<A1>) => Stream.Stream<A2, E2, R2>,
|
|
122
129
|
): Stream.Stream<A1 | A2, E1 | E2, R1 | R2>
|
|
123
|
-
} = dual(
|
|
130
|
+
} = Function.dual(
|
|
124
131
|
2,
|
|
125
132
|
<A1, E1, R1, A2, E2, R2>(
|
|
126
133
|
stream1: Stream.Stream<A1, E1, R1>,
|
|
@@ -163,7 +170,7 @@ export const concatWithLastElement: {
|
|
|
163
170
|
export const emitIfEmpty: {
|
|
164
171
|
<A>(fallbackValue: A): <E, R>(stream: Stream.Stream<A, E, R>) => Stream.Stream<A, E, R>
|
|
165
172
|
<A, E, R>(stream: Stream.Stream<A, E, R>, fallbackValue: A): Stream.Stream<A, E, R>
|
|
166
|
-
} = dual(
|
|
173
|
+
} = Function.dual(
|
|
167
174
|
2,
|
|
168
175
|
<A, E, R>(stream: Stream.Stream<A, E, R>, fallbackValue: A): Stream.Stream<A, E, R> =>
|
|
169
176
|
concatWithLastElement(stream, (lastElement) =>
|
|
@@ -4,10 +4,15 @@
|
|
|
4
4
|
* @since 2.0.0
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
import { Effect, Effectable, Function, Predicate, Stream, SubscriptionRef } from 'effect'
|
|
8
|
+
|
|
9
|
+
const ReadableTypeId: unique symbol = Symbol.for('effect/Readable')
|
|
10
|
+
type ReadableTypeId = typeof ReadableTypeId
|
|
11
|
+
|
|
12
|
+
interface Readable<A, E = never, R = never> {
|
|
13
|
+
readonly [ReadableTypeId]: ReadableTypeId
|
|
14
|
+
readonly get: Effect.Effect<A, E, R>
|
|
15
|
+
}
|
|
11
16
|
|
|
12
17
|
/**
|
|
13
18
|
* @since 2.0.0
|
|
@@ -25,7 +30,7 @@ export type TypeId = typeof TypeId
|
|
|
25
30
|
* @since 2.0.0
|
|
26
31
|
* @category models
|
|
27
32
|
*/
|
|
28
|
-
export interface Subscribable<A, E = never, R = never> extends Readable
|
|
33
|
+
export interface Subscribable<A, E = never, R = never> extends Readable<A, E, R>, Effect.Effect<A, E, R> {
|
|
29
34
|
readonly [TypeId]: TypeId
|
|
30
35
|
readonly changes: Stream.Stream<A, E, R>
|
|
31
36
|
}
|
|
@@ -34,52 +39,36 @@ export interface Subscribable<A, E = never, R = never> extends Readable.Readable
|
|
|
34
39
|
* @since 2.0.0
|
|
35
40
|
* @category refinements
|
|
36
41
|
*/
|
|
37
|
-
export const isSubscribable = (u: unknown): u is Subscribable<unknown, unknown, unknown> =>
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
//
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
readonly changes: Stream.Stream<A>
|
|
54
|
-
constructor(get: Effect.Effect<A>, changes: Stream.Stream<A>) {
|
|
55
|
-
super()
|
|
56
|
-
this.get = get
|
|
57
|
-
this.changes = changes
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
commit() {
|
|
61
|
-
return this.get
|
|
62
|
-
}
|
|
63
|
-
}
|
|
42
|
+
export const isSubscribable = (u: unknown): u is Subscribable<unknown, unknown, unknown> =>
|
|
43
|
+
Predicate.hasProperty(u, TypeId)
|
|
44
|
+
|
|
45
|
+
const Proto: Omit<Subscribable<unknown, unknown, unknown>, 'get' | 'changes'> = Object.assign(
|
|
46
|
+
Effectable.Prototype<Subscribable<unknown, unknown, unknown>>({
|
|
47
|
+
label: 'Subscribable',
|
|
48
|
+
evaluate() {
|
|
49
|
+
// @effect-diagnostics-next-line anyUnknownInErrorContext:off -- vendored fork; this shared prototype is generic over all A, E, R, so `unknown` in the error/requirements channels is structural, not a real error type
|
|
50
|
+
return this.get
|
|
51
|
+
},
|
|
52
|
+
}),
|
|
53
|
+
{
|
|
54
|
+
[ReadableTypeId]: ReadableTypeId,
|
|
55
|
+
[TypeId]: TypeId,
|
|
56
|
+
} as const,
|
|
57
|
+
)
|
|
64
58
|
|
|
65
59
|
/**
|
|
66
60
|
* @since 2.0.0
|
|
67
61
|
* @category constructors
|
|
68
62
|
*/
|
|
69
|
-
// export const make = <A, E, R>(options: {
|
|
70
|
-
// readonly get: Effect.Effect<A, E, R>
|
|
71
|
-
// readonly changes: Stream.Stream<A, E, R>
|
|
72
|
-
// }): Subscribable<A, E, R> => Object.assign(Object.create(Proto), options)
|
|
73
|
-
|
|
74
63
|
export const make = <A, E, R>(options: {
|
|
75
64
|
readonly get: Effect.Effect<A, E, R>
|
|
76
65
|
readonly changes: Stream.Stream<A, E, R>
|
|
77
|
-
}): Subscribable<A, E, R> =>
|
|
66
|
+
}): Subscribable<A, E, R> => Object.assign(Object.create(Proto), options)
|
|
78
67
|
|
|
79
68
|
export const fromSubscriptionRef = <A>(ref: SubscriptionRef.SubscriptionRef<A>): Subscribable<A> =>
|
|
80
69
|
make({
|
|
81
|
-
get:
|
|
82
|
-
changes:
|
|
70
|
+
get: SubscriptionRef.get(ref),
|
|
71
|
+
changes: SubscriptionRef.changes(ref),
|
|
83
72
|
})
|
|
84
73
|
|
|
85
74
|
/**
|
|
@@ -97,7 +86,7 @@ export const map: {
|
|
|
97
86
|
* @category combinators
|
|
98
87
|
*/
|
|
99
88
|
<A, E, R, B>(self: Subscribable<A, E, R>, f: (a: NoInfer<A>) => B): Subscribable<B, E, R>
|
|
100
|
-
} = dual(
|
|
89
|
+
} = Function.dual(
|
|
101
90
|
2,
|
|
102
91
|
<A, E, R, B>(self: Subscribable<A, E, R>, f: (a: NoInfer<A>) => B): Subscribable<B, E, R> =>
|
|
103
92
|
make({
|
|
@@ -126,7 +115,7 @@ export const mapEffect: {
|
|
|
126
115
|
self: Subscribable<A, E, R>,
|
|
127
116
|
f: (a: NoInfer<A>) => Effect.Effect<B, E2, R2>,
|
|
128
117
|
): Subscribable<B, E | E2, R | R2>
|
|
129
|
-
} = dual(
|
|
118
|
+
} = Function.dual(
|
|
130
119
|
2,
|
|
131
120
|
<A, E, R, B, E2, R2>(
|
|
132
121
|
self: Subscribable<A, E, R>,
|
|
@@ -1,23 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { dual } from 'effect/Function'
|
|
3
|
-
import type { Predicate, Refinement } from 'effect/Predicate'
|
|
1
|
+
import { Effect, Function, pipe, Stream, SubscriptionRef, type Predicate } from 'effect'
|
|
4
2
|
|
|
5
3
|
export * from 'effect/SubscriptionRef'
|
|
6
4
|
|
|
7
5
|
export const waitUntil: {
|
|
8
|
-
<A, B extends A>(
|
|
9
|
-
refinement: Refinement<NoInfer<A>, B>,
|
|
10
|
-
): (sref: SubscriptionRef.SubscriptionRef<A>) => Effect.Effect<B>
|
|
11
6
|
<A, B extends A>(
|
|
12
|
-
|
|
13
|
-
): (sref: SubscriptionRef.SubscriptionRef<A>) => Effect.Effect<
|
|
7
|
+
refinement: Predicate.Refinement<NoInfer<A>, B>,
|
|
8
|
+
): (sref: SubscriptionRef.SubscriptionRef<A>) => Effect.Effect<B>
|
|
9
|
+
<A, B extends A>(predicate: Predicate.Predicate<B>): (sref: SubscriptionRef.SubscriptionRef<A>) => Effect.Effect<A>
|
|
14
10
|
<A, B extends A>(
|
|
15
11
|
sref: SubscriptionRef.SubscriptionRef<A>,
|
|
16
|
-
refinement: Refinement<NoInfer<A>, B>,
|
|
12
|
+
refinement: Predicate.Refinement<NoInfer<A>, B>,
|
|
17
13
|
): Effect.Effect<B>
|
|
18
|
-
<A, B extends A>(sref: SubscriptionRef.SubscriptionRef<A>, predicate: Predicate<B>): Effect.Effect<A>
|
|
19
|
-
} = dual(2, <A>(sref: SubscriptionRef.SubscriptionRef<A>, predicate: (a: A) => boolean) =>
|
|
20
|
-
pipe(
|
|
14
|
+
<A, B extends A>(sref: SubscriptionRef.SubscriptionRef<A>, predicate: Predicate.Predicate<B>): Effect.Effect<A>
|
|
15
|
+
} = Function.dual(2, <A>(sref: SubscriptionRef.SubscriptionRef<A>, predicate: (a: A) => boolean) =>
|
|
16
|
+
pipe(SubscriptionRef.changes(sref), Stream.filter(predicate), Stream.runHead, Effect.flatMap(Effect.fromOption)),
|
|
21
17
|
)
|
|
22
18
|
|
|
23
19
|
export const fromStream = <A>(stream: Stream.Stream<A>, initialValue: A) =>
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import { Predicate } from 'effect'
|
|
2
|
-
import * as Context from 'effect/Context'
|
|
3
|
-
import * as Effect from 'effect/Effect'
|
|
4
|
-
import { pipe } from 'effect/Function'
|
|
5
|
-
import * as Layer from 'effect/Layer'
|
|
6
|
-
import * as Tracer from 'effect/Tracer'
|
|
1
|
+
import { Context, Effect, Layer, Predicate, Tracer } from 'effect'
|
|
7
2
|
|
|
8
3
|
export const withAsyncTaggingTracing =
|
|
9
4
|
(makeTrace: (name: string) => { run: (fn: any) => any }) =>
|
|
@@ -14,30 +9,32 @@ export const withAsyncTaggingTracing =
|
|
|
14
9
|
|
|
15
10
|
const makeTracer = Effect.gen(function* () {
|
|
16
11
|
const oldTracer = yield* Effect.tracer
|
|
12
|
+
const evaluate = <X>(primitive: Tracer.EffectPrimitive<X>, fiber: any) =>
|
|
13
|
+
oldTracer.context?.(primitive, fiber) ?? primitive['~effect/Effect/evaluate'](fiber)
|
|
17
14
|
return Tracer.make({
|
|
18
|
-
span: (
|
|
19
|
-
const span = oldTracer.span(
|
|
20
|
-
const trace = makeTrace(name)
|
|
15
|
+
span: (options) => {
|
|
16
|
+
const span = oldTracer.span(options)
|
|
17
|
+
const trace = makeTrace(options.name)
|
|
21
18
|
;(span as any).runInTask = (f: any) => trace.run(f)
|
|
22
19
|
return span
|
|
23
20
|
},
|
|
24
|
-
context: (
|
|
25
|
-
const maybeParentSpan = Context.getOption(Tracer.ParentSpan)
|
|
21
|
+
context: (primitive, fiber) => {
|
|
22
|
+
const maybeParentSpan = Context.getOption(fiber.context, Tracer.ParentSpan)
|
|
26
23
|
|
|
27
|
-
if (maybeParentSpan._tag === 'None') return
|
|
24
|
+
if (maybeParentSpan._tag === 'None') return evaluate(primitive, fiber)
|
|
28
25
|
const parentSpan = maybeParentSpan.value
|
|
29
|
-
if (parentSpan._tag === 'ExternalSpan') return
|
|
26
|
+
if (parentSpan._tag === 'ExternalSpan') return evaluate(primitive, fiber)
|
|
30
27
|
const span = parentSpan
|
|
31
28
|
if ('runInTask' in span && typeof span.runInTask === 'function') {
|
|
32
|
-
return span.runInTask(() =>
|
|
29
|
+
return span.runInTask(() => evaluate(primitive, fiber))
|
|
33
30
|
}
|
|
34
31
|
|
|
35
|
-
return
|
|
32
|
+
return evaluate(primitive, fiber)
|
|
36
33
|
},
|
|
37
34
|
})
|
|
38
35
|
})
|
|
39
36
|
|
|
40
|
-
const withTracerLayer =
|
|
37
|
+
const withTracerLayer = Layer.effect(Tracer.Tracer, makeTracer)
|
|
41
38
|
|
|
42
39
|
return Effect.provide(eff, withTracerLayer)
|
|
43
40
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import * as Vitest from '@effect/vitest'
|
|
2
|
-
import { Effect, Schema, Stream } from 'effect'
|
|
2
|
+
import { Effect, Fiber, Schema, Stream } from 'effect'
|
|
3
3
|
import { JSDOM } from 'jsdom'
|
|
4
4
|
|
|
5
5
|
import * as WebChannel from '../../browser/WebChannelBrowser.ts'
|
|
6
6
|
|
|
7
7
|
Vitest.describe('WebChannel', () => {
|
|
8
8
|
Vitest.describe('windowChannel', () => {
|
|
9
|
-
Vitest.
|
|
9
|
+
Vitest.live('should work with 2 windows', () =>
|
|
10
10
|
Effect.gen(function* () {
|
|
11
11
|
const windowA = new JSDOM().window as unknown as globalThis.Window
|
|
12
12
|
const windowB = new JSDOM().window as unknown as globalThis.Window
|
|
@@ -16,19 +16,19 @@ Vitest.describe('WebChannel', () => {
|
|
|
16
16
|
listenWindow: windowA,
|
|
17
17
|
sendWindow: windowB,
|
|
18
18
|
ids: { own: 'a', other: 'b' },
|
|
19
|
-
schema: Schema.
|
|
19
|
+
schema: Schema.Finite,
|
|
20
20
|
})
|
|
21
21
|
|
|
22
22
|
const msgFromBFiber = yield* channelToB.listen.pipe(
|
|
23
|
-
Stream.flatten(),
|
|
24
23
|
Stream.runHead,
|
|
25
|
-
Effect.
|
|
26
|
-
Effect.
|
|
24
|
+
Effect.flatMap(Effect.fromOption),
|
|
25
|
+
Effect.flatMap(Effect.fromResult),
|
|
26
|
+
Effect.forkChild,
|
|
27
27
|
)
|
|
28
28
|
|
|
29
29
|
yield* channelToB.send(1)
|
|
30
30
|
|
|
31
|
-
Vitest.expect(yield* msgFromBFiber).toEqual(2)
|
|
31
|
+
Vitest.expect(yield* Fiber.join(msgFromBFiber)).toEqual(2)
|
|
32
32
|
})
|
|
33
33
|
|
|
34
34
|
const codeSideB = Effect.gen(function* () {
|
|
@@ -36,26 +36,26 @@ Vitest.describe('WebChannel', () => {
|
|
|
36
36
|
listenWindow: windowB,
|
|
37
37
|
sendWindow: windowA,
|
|
38
38
|
ids: { own: 'b', other: 'a' },
|
|
39
|
-
schema: Schema.
|
|
39
|
+
schema: Schema.Finite,
|
|
40
40
|
})
|
|
41
41
|
|
|
42
42
|
const msgFromAFiber = yield* channelToA.listen.pipe(
|
|
43
|
-
Stream.flatten(),
|
|
44
43
|
Stream.runHead,
|
|
45
|
-
Effect.
|
|
46
|
-
Effect.
|
|
44
|
+
Effect.flatMap(Effect.fromOption),
|
|
45
|
+
Effect.flatMap(Effect.fromResult),
|
|
46
|
+
Effect.forkChild,
|
|
47
47
|
)
|
|
48
48
|
|
|
49
49
|
yield* channelToA.send(2)
|
|
50
50
|
|
|
51
|
-
Vitest.expect(yield* msgFromAFiber).toEqual(1)
|
|
51
|
+
Vitest.expect(yield* Fiber.join(msgFromAFiber)).toEqual(1)
|
|
52
52
|
})
|
|
53
53
|
|
|
54
54
|
yield* Effect.all([codeSideA, codeSideB], { concurrency: 'unbounded' })
|
|
55
55
|
}),
|
|
56
56
|
)
|
|
57
57
|
|
|
58
|
-
Vitest.
|
|
58
|
+
Vitest.live('should work with the same window', () =>
|
|
59
59
|
Effect.gen(function* () {
|
|
60
60
|
const window = new JSDOM().window as unknown as globalThis.Window
|
|
61
61
|
|
|
@@ -64,19 +64,19 @@ Vitest.describe('WebChannel', () => {
|
|
|
64
64
|
listenWindow: window,
|
|
65
65
|
sendWindow: window,
|
|
66
66
|
ids: { own: 'a', other: 'b' },
|
|
67
|
-
schema: Schema.
|
|
67
|
+
schema: Schema.Finite,
|
|
68
68
|
})
|
|
69
69
|
|
|
70
70
|
const msgFromBFiber = yield* channelToB.listen.pipe(
|
|
71
|
-
Stream.flatten(),
|
|
72
71
|
Stream.runHead,
|
|
73
|
-
Effect.
|
|
74
|
-
Effect.
|
|
72
|
+
Effect.flatMap(Effect.fromOption),
|
|
73
|
+
Effect.flatMap(Effect.fromResult),
|
|
74
|
+
Effect.forkChild,
|
|
75
75
|
)
|
|
76
76
|
|
|
77
77
|
yield* channelToB.send(1)
|
|
78
78
|
|
|
79
|
-
Vitest.expect(yield* msgFromBFiber).toEqual(2)
|
|
79
|
+
Vitest.expect(yield* Fiber.join(msgFromBFiber)).toEqual(2)
|
|
80
80
|
})
|
|
81
81
|
|
|
82
82
|
const codeSideB = Effect.gen(function* () {
|
|
@@ -84,19 +84,19 @@ Vitest.describe('WebChannel', () => {
|
|
|
84
84
|
listenWindow: window,
|
|
85
85
|
sendWindow: window,
|
|
86
86
|
ids: { own: 'b', other: 'a' },
|
|
87
|
-
schema: Schema.
|
|
87
|
+
schema: Schema.Finite,
|
|
88
88
|
})
|
|
89
89
|
|
|
90
90
|
const msgFromAFiber = yield* channelToA.listen.pipe(
|
|
91
|
-
Stream.flatten(),
|
|
92
91
|
Stream.runHead,
|
|
93
|
-
Effect.
|
|
94
|
-
Effect.
|
|
92
|
+
Effect.flatMap(Effect.fromOption),
|
|
93
|
+
Effect.flatMap(Effect.fromResult),
|
|
94
|
+
Effect.forkChild,
|
|
95
95
|
)
|
|
96
96
|
|
|
97
97
|
yield* channelToA.send(2)
|
|
98
98
|
|
|
99
|
-
Vitest.expect(yield* msgFromAFiber).toEqual(1)
|
|
99
|
+
Vitest.expect(yield* Fiber.join(msgFromAFiber)).toEqual(1)
|
|
100
100
|
})
|
|
101
101
|
|
|
102
102
|
yield* Effect.all([codeSideA, codeSideB], { concurrency: 'unbounded' })
|