@livestore/utils 0.4.0 → 0.5.0-dev.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/dist/.tsbuildinfo +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 +17 -0
- package/dist/NoopTracer.test.js.map +1 -0
- 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 +132 -307
- 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 +5 -4
- package/dist/browser/Opfs/debug-utils.js.map +1 -1
- 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 +21 -10
- package/dist/browser/WebChannelBrowser.js.map +1 -1
- package/dist/browser/WebError.d.ts +54 -86
- package/dist/browser/WebError.d.ts.map +1 -1
- package/dist/browser/WebError.js +91 -84
- package/dist/browser/WebError.js.map +1 -1
- package/dist/browser/WebError.test.js +6 -6
- package/dist/browser/WebError.test.js.map +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/effect/Debug.d.ts +4 -7
- package/dist/effect/Debug.d.ts.map +1 -1
- package/dist/effect/Debug.js +32 -36
- 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 +51 -47
- 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 +7 -7
- package/dist/effect/RpcClient.d.ts.map +1 -1
- package/dist/effect/RpcClient.js +72 -52
- 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 +7 -4
- 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 +55 -28
- 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 +9 -9
- 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 +64 -43
- package/dist/effect/WebChannel/WebChannel.js.map +1 -1
- package/dist/effect/WebChannel/WebChannel.test.js +15 -15
- 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 +16 -9
- 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/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 +2 -2
- 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 +13 -18
- 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 +10 -13
- package/dist/effect/spanEvent.test.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.js +2 -2
- package/dist/misc.js.map +1 -1
- package/dist/mod.d.ts +0 -35
- package/dist/mod.d.ts.map +1 -1
- package/dist/mod.js +0 -8
- package/dist/mod.js.map +1 -1
- package/dist/node/mod.d.ts +17 -11
- package/dist/node/mod.d.ts.map +1 -1
- package/dist/node/mod.js +23 -16
- 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 +0 -9
- package/dist/object/index.js.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 +18 -36
- package/src/NoopTracer.test.ts +20 -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 +66 -59
- package/src/effect/Effect.test.ts +117 -0
- package/src/effect/Effect.ts +84 -71
- package/src/effect/Logger.ts +0 -48
- package/src/effect/OtelTracer.ts +2 -3
- package/src/effect/RpcClient.ts +80 -61
- 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 -55
- 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 +35 -69
- package/src/effect/spanEvent.test.ts +10 -13
- package/src/effect/spanEvent.ts +5 -3
- package/src/fast-deep-equal.ts +1 -2
- package/src/misc.ts +2 -2
- package/src/mod.ts +0 -36
- package/src/node/mod.ts +26 -20
- 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
|
@@ -8,7 +8,7 @@ describe('debug-diff', () => {
|
|
|
8
8
|
test('simple object', () => {
|
|
9
9
|
const schema = Schema.Struct({
|
|
10
10
|
a: Schema.String,
|
|
11
|
-
b: Schema.
|
|
11
|
+
b: Schema.Finite,
|
|
12
12
|
})
|
|
13
13
|
|
|
14
14
|
const a = { a: 'hello', b: 1 }
|
|
@@ -35,7 +35,7 @@ describe('debug-diff', () => {
|
|
|
35
35
|
const schema = Schema.Struct({
|
|
36
36
|
a: Schema.String,
|
|
37
37
|
b: Schema.Struct({
|
|
38
|
-
c: Schema.
|
|
38
|
+
c: Schema.Finite,
|
|
39
39
|
}),
|
|
40
40
|
})
|
|
41
41
|
const a = { a: 'hello', b: { c: 1 } }
|
|
@@ -58,7 +58,7 @@ describe('debug-diff', () => {
|
|
|
58
58
|
})
|
|
59
59
|
|
|
60
60
|
test('union', () => {
|
|
61
|
-
const schema = Schema.Union(Schema.String, Schema.
|
|
61
|
+
const schema = Schema.Union([Schema.String, Schema.Finite])
|
|
62
62
|
const a = 'hello'
|
|
63
63
|
const b = 1
|
|
64
64
|
const diff = debugDiff(schema)(a, b)
|
|
@@ -74,10 +74,10 @@ describe('debug-diff', () => {
|
|
|
74
74
|
})
|
|
75
75
|
|
|
76
76
|
test('tagged union', () => {
|
|
77
|
-
const schema = Schema.Union(
|
|
77
|
+
const schema = Schema.Union([
|
|
78
78
|
Schema.TaggedStruct('a', { a: Schema.String }),
|
|
79
|
-
Schema.TaggedStruct('b', { b: Schema.
|
|
80
|
-
)
|
|
79
|
+
Schema.TaggedStruct('b', { b: Schema.Finite }),
|
|
80
|
+
])
|
|
81
81
|
const a = { _tag: 'a', a: 'hello' } as const
|
|
82
82
|
const b = { _tag: 'b', b: 1 } as const
|
|
83
83
|
const diff = debugDiff(schema)(a, b)
|
|
@@ -11,7 +11,7 @@ export type DiffItem = {
|
|
|
11
11
|
* Diffs two values for a given schema and traverses downwards and returns a list of differences.
|
|
12
12
|
*/
|
|
13
13
|
export const debugDiff =
|
|
14
|
-
<A, I, R>(base: Schema.
|
|
14
|
+
<A, I, R>(base: Schema.Top) =>
|
|
15
15
|
(a: A, b: A): DiffItem[] => {
|
|
16
16
|
const bag = [] as DiffItem[]
|
|
17
17
|
debugDiffImpl(base.ast, a, b, '', bag)
|
|
@@ -19,7 +19,7 @@ export const debugDiff =
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
const debugDiffImpl = (ast: SchemaAST.AST, a: any, b: any, path: string, bag: DiffItem[]) => {
|
|
22
|
-
const eq = Schema.
|
|
22
|
+
const eq = Schema.toEquivalence({ ast } as any)
|
|
23
23
|
if (eq(a, b) === false) {
|
|
24
24
|
// bag.push({ path, a, b, ast })
|
|
25
25
|
|
|
@@ -35,9 +35,8 @@ const debugDiffImpl = (ast: SchemaAST.AST, a: any, b: any, path: string, bag: Di
|
|
|
35
35
|
} catch {}
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
} else if (SchemaAST.
|
|
39
|
-
const
|
|
40
|
-
for (const prop of props) {
|
|
38
|
+
} else if (SchemaAST.isObjects(ast) === true) {
|
|
39
|
+
for (const prop of ast.propertySignatures) {
|
|
41
40
|
debugDiffImpl(prop.type, a[prop.name], b[prop.name], `${path}.${prop.name.toString()}`, bag)
|
|
42
41
|
}
|
|
43
42
|
} else {
|
|
@@ -50,9 +49,8 @@ const debugDiffImpl = (ast: SchemaAST.AST, a: any, b: any, path: string, bag: Di
|
|
|
50
49
|
const isTaggedUnion = (ast: SchemaAST.AST): boolean => {
|
|
51
50
|
if (SchemaAST.isUnion(ast) === true) {
|
|
52
51
|
return ast.types.every((type) => {
|
|
53
|
-
if (SchemaAST.
|
|
54
|
-
|
|
55
|
-
return props.some((prop) => prop.name.toString() === '_tag')
|
|
52
|
+
if (SchemaAST.isObjects(type) === false) return false
|
|
53
|
+
return type.propertySignatures.some((prop) => prop.name.toString() === '_tag')
|
|
56
54
|
})
|
|
57
55
|
}
|
|
58
56
|
return false
|
|
@@ -1,18 +1,115 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import {
|
|
2
|
+
Array,
|
|
3
|
+
Effect,
|
|
4
|
+
Function,
|
|
5
|
+
Hash,
|
|
6
|
+
Option,
|
|
7
|
+
Result,
|
|
8
|
+
Schema,
|
|
9
|
+
SchemaAST,
|
|
10
|
+
SchemaGetter,
|
|
11
|
+
SchemaIssue,
|
|
12
|
+
SchemaTransformation,
|
|
13
|
+
Struct,
|
|
14
|
+
} from 'effect'
|
|
15
|
+
import { Transferable } from 'effect/unstable/workers'
|
|
16
|
+
|
|
17
|
+
import { shouldNeverHappen } from '../../misc.ts'
|
|
8
18
|
|
|
9
19
|
export * from 'effect/Schema'
|
|
10
20
|
export * from './debug-diff.ts'
|
|
11
21
|
|
|
22
|
+
type PluckSchema<Fields extends Schema.Struct.Fields, K extends keyof Fields> = Schema.Codec<
|
|
23
|
+
Fields[K]['Type'],
|
|
24
|
+
Schema.Struct<Pick<Fields, K>>['Encoded'],
|
|
25
|
+
Schema.Struct<Pick<Fields, K>>['DecodingServices'],
|
|
26
|
+
Schema.Struct<Pick<Fields, K>>['EncodingServices']
|
|
27
|
+
>
|
|
28
|
+
|
|
29
|
+
export const pluck =
|
|
30
|
+
<const K extends PropertyKey>(key: K) =>
|
|
31
|
+
<Fields extends { readonly [P in K]: Schema.Top }>(
|
|
32
|
+
schema: Schema.Struct<Fields>,
|
|
33
|
+
): PluckSchema<Fields, K & keyof Fields> => {
|
|
34
|
+
const field = schema.fields[key] as Fields[K & keyof Fields]
|
|
35
|
+
|
|
36
|
+
return schema.mapFields(Struct.pick([key])).pipe(
|
|
37
|
+
Schema.decodeTo(Schema.toType(field), {
|
|
38
|
+
decode: SchemaGetter.transform((whole: any) => whole[key]),
|
|
39
|
+
encode: SchemaGetter.transform((value) => ({ [key]: value }) as any),
|
|
40
|
+
}),
|
|
41
|
+
) as unknown as PluckSchema<Fields, K & keyof Fields>
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Like {@link fromJsonString}, but the ENCODED form is an *indented* JSON string
|
|
46
|
+
* (default 2-space) instead of compact — for committed/human-read JSON files
|
|
47
|
+
* (package.json, release plans, CI previews) that must stay diff-friendly while
|
|
48
|
+
* still round-tripping through the schema.
|
|
49
|
+
*
|
|
50
|
+
* Use a concrete schema for known shapes (adds validation) or `Schema.Unknown`
|
|
51
|
+
* for open-ended ones (the indented analogue of `fromJsonString(Schema.Unknown)`).
|
|
52
|
+
*
|
|
53
|
+
* TODO collapse into `fromJsonString(schema, { space })` now that Effect 4 accepts a
|
|
54
|
+
* `space` option; kept separate here to keep the Effect upgrade free of release-tooling changes.
|
|
55
|
+
*/
|
|
56
|
+
export const jsonStringIndented = <S extends Schema.Top>(schema: S, space: number | string = 2) =>
|
|
57
|
+
schema.pipe(
|
|
58
|
+
Schema.encodeTo(Schema.String, {
|
|
59
|
+
decode: SchemaGetter.parseJson(),
|
|
60
|
+
encode: SchemaGetter.stringifyJson({ space }),
|
|
61
|
+
}),
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
export const head = <S extends Schema.Top>(
|
|
65
|
+
array: Schema.$Array<S>,
|
|
66
|
+
): Schema.decodeTo<Schema.Option<Schema.toType<S>>, Schema.$Array<S>> =>
|
|
67
|
+
array.pipe(
|
|
68
|
+
Schema.decodeTo(
|
|
69
|
+
Schema.Option(Schema.toType(array.value)),
|
|
70
|
+
SchemaTransformation.transform({
|
|
71
|
+
decode: Array.head,
|
|
72
|
+
encode: Option.match({
|
|
73
|
+
onNone: () => [],
|
|
74
|
+
onSome: Array.of,
|
|
75
|
+
}),
|
|
76
|
+
}),
|
|
77
|
+
),
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
type HeadOrElse<S extends Schema.Top> = Schema.decodeTo<Schema.toType<S>, Schema.$Array<S>>
|
|
81
|
+
|
|
82
|
+
export const headOrElse: {
|
|
83
|
+
<S extends Schema.Top>(array: Schema.$Array<S>, orElse?: () => S['Type']): HeadOrElse<S>
|
|
84
|
+
(): <S extends Schema.Top>(array: Schema.$Array<S>) => HeadOrElse<S>
|
|
85
|
+
<S extends Schema.Top>(orElse: () => S['Type']): (array: Schema.$Array<S>) => HeadOrElse<S>
|
|
86
|
+
} = Function.dual(
|
|
87
|
+
(args) => Schema.isSchema(args[0]),
|
|
88
|
+
<S extends Schema.Top>(array: Schema.$Array<S>, orElse?: () => S['Type']): HeadOrElse<S> =>
|
|
89
|
+
array.pipe(
|
|
90
|
+
Schema.decodeTo(
|
|
91
|
+
Schema.toType(array.value),
|
|
92
|
+
SchemaTransformation.transformOrFail({
|
|
93
|
+
decode: (array) =>
|
|
94
|
+
Array.isReadonlyArrayNonEmpty(array) === true
|
|
95
|
+
? Effect.succeed(Array.headNonEmpty(array))
|
|
96
|
+
: orElse === undefined
|
|
97
|
+
? Effect.fail(
|
|
98
|
+
new SchemaIssue.InvalidValue({
|
|
99
|
+
message: 'Unable to retrieve the first element of an empty array',
|
|
100
|
+
}),
|
|
101
|
+
)
|
|
102
|
+
: Effect.succeed(orElse()),
|
|
103
|
+
encode: (value) => Effect.succeed(Array.of(value)),
|
|
104
|
+
}),
|
|
105
|
+
),
|
|
106
|
+
),
|
|
107
|
+
)
|
|
108
|
+
|
|
12
109
|
// NOTE this is a temporary workaround until Effect schema has a better way to hash schemas
|
|
13
110
|
// https://github.com/Effect-TS/effect/issues/2719
|
|
14
111
|
// TODO remove this once the issue is resolved
|
|
15
|
-
export const hash = (schema: Schema.
|
|
112
|
+
export const hash = (schema: Schema.Top) => {
|
|
16
113
|
try {
|
|
17
114
|
return Hash.string(JSON.stringify(schema.ast, null, 2))
|
|
18
115
|
} catch {
|
|
@@ -23,80 +120,44 @@ export const hash = (schema: Schema.Schema<any>) => {
|
|
|
23
120
|
}
|
|
24
121
|
}
|
|
25
122
|
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return ast
|
|
123
|
+
export const getResolvedPropertySignatures = (schema: Schema.Top): ReadonlyArray<SchemaAST.PropertySignature> => {
|
|
124
|
+
const resolvedAst = SchemaAST.toType(schema.ast)
|
|
125
|
+
return SchemaAST.isObjects(resolvedAst) === true ? resolvedAst.propertySignatures : []
|
|
32
126
|
}
|
|
33
127
|
|
|
34
|
-
export const getResolvedPropertySignatures = (
|
|
35
|
-
schema: Schema.Schema.AnyNoContext,
|
|
36
|
-
): ReadonlyArray<SchemaAST.PropertySignature> => {
|
|
37
|
-
const resolvedAst = resolveStructAst(schema.ast)
|
|
38
|
-
return SchemaAST.getPropertySignatures(resolvedAst)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/** Objects that can be transferred between contexts (workers, etc.) */
|
|
42
|
-
type TransferableObject = ArrayBuffer | MessagePort
|
|
43
|
-
|
|
44
128
|
export const encodeWithTransferables =
|
|
45
|
-
<A, I
|
|
46
|
-
(a: A, overrideOptions?: ParseOptions)
|
|
129
|
+
<A, I>(schema: Schema.Codec<A, I>, options?: SchemaAST.ParseOptions) =>
|
|
130
|
+
(a: A, overrideOptions?: SchemaAST.ParseOptions) =>
|
|
47
131
|
Effect.gen(function* () {
|
|
48
132
|
const collector = yield* Transferable.makeCollector
|
|
49
133
|
|
|
50
|
-
const encoded
|
|
134
|
+
const encoded = yield* Schema.encodeEffect(schema, options)(a, overrideOptions).pipe(
|
|
51
135
|
Effect.provideService(Transferable.Collector, collector),
|
|
52
136
|
)
|
|
53
137
|
|
|
54
|
-
return [encoded, collector.
|
|
138
|
+
return [encoded, collector.readUnsafe()] as const
|
|
55
139
|
})
|
|
56
140
|
|
|
57
141
|
export const decodeSyncDebug: <A, I>(
|
|
58
|
-
schema: Schema.
|
|
142
|
+
schema: Schema.Codec<A, I>,
|
|
59
143
|
options?: SchemaAST.ParseOptions,
|
|
60
144
|
) => (i: I, overrideOptions?: SchemaAST.ParseOptions) => A = (schema, options) => (input, overrideOptions) => {
|
|
61
|
-
const res = Schema.
|
|
62
|
-
if (res
|
|
63
|
-
return shouldNeverHappen(`decodeSyncDebug failed:`, res.
|
|
145
|
+
const res = Schema.decodeResult(schema, options)(input, overrideOptions)
|
|
146
|
+
if (Result.isFailure(res) === true) {
|
|
147
|
+
return shouldNeverHappen(`decodeSyncDebug failed:`, res.failure)
|
|
64
148
|
} else {
|
|
65
|
-
return res.
|
|
149
|
+
return res.success
|
|
66
150
|
}
|
|
67
151
|
}
|
|
68
152
|
|
|
69
153
|
export const encodeSyncDebug: <A, I>(
|
|
70
|
-
schema: Schema.
|
|
154
|
+
schema: Schema.Codec<A, I>,
|
|
71
155
|
options?: SchemaAST.ParseOptions,
|
|
72
156
|
) => (a: A, overrideOptions?: SchemaAST.ParseOptions) => I = (schema, options) => (input, overrideOptions) => {
|
|
73
|
-
const res = Schema.
|
|
74
|
-
if (res
|
|
75
|
-
return shouldNeverHappen(`encodeSyncDebug failed:`, res.
|
|
157
|
+
const res = Schema.encodeResult(schema, options)(input, overrideOptions)
|
|
158
|
+
if (Result.isFailure(res) === true) {
|
|
159
|
+
return shouldNeverHappen(`encodeSyncDebug failed:`, res.failure)
|
|
76
160
|
} else {
|
|
77
|
-
return res.
|
|
161
|
+
return res.success
|
|
78
162
|
}
|
|
79
163
|
}
|
|
80
|
-
|
|
81
|
-
export const swap = <A, I, R>(schema: Schema.Schema<A, I, R>): Schema.Schema<I, A, R> =>
|
|
82
|
-
Schema.transformOrFail(Schema.typeSchema(schema), Schema.encodedSchema(schema), {
|
|
83
|
-
decode: ParseResult.encode(schema),
|
|
84
|
-
encode: ParseResult.decode(schema),
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
export const Base64FromUint8Array: Schema.Schema<string, Uint8Array> = swap(Schema.Uint8ArrayFromBase64)
|
|
88
|
-
|
|
89
|
-
export interface JsonArray extends ReadonlyArray<JsonValue> {}
|
|
90
|
-
export interface JsonObject {
|
|
91
|
-
[key: string]: JsonValue
|
|
92
|
-
}
|
|
93
|
-
export type JsonValue = string | number | boolean | null | JsonObject | JsonArray
|
|
94
|
-
|
|
95
|
-
export const JsonValue: Schema.Schema<JsonValue> = Schema.Union(
|
|
96
|
-
Schema.String,
|
|
97
|
-
Schema.Number,
|
|
98
|
-
Schema.Boolean,
|
|
99
|
-
Schema.Null,
|
|
100
|
-
Schema.Array(Schema.suspend(() => JsonValue)),
|
|
101
|
-
Schema.Record({ key: Schema.String, value: Schema.suspend(() => JsonValue) }),
|
|
102
|
-
).annotations({ identifier: 'JsonValue' })
|
|
@@ -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
|
}
|