@dxos/effect 0.8.4-main.fffef41 → 0.8.4-staging.60fe92afc8
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/LICENSE +102 -5
- package/README.md +1 -1
- package/dist/lib/browser/chunk-CGS2ULMK.mjs +11 -0
- package/dist/lib/browser/chunk-CGS2ULMK.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +530 -353
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing.mjs +31 -0
- package/dist/lib/browser/testing.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +530 -353
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing.mjs +31 -0
- package/dist/lib/node-esm/testing.mjs.map +7 -0
- package/dist/types/src/EffectEx.d.ts +5 -0
- package/dist/types/src/EffectEx.d.ts.map +1 -0
- package/dist/types/src/Performance.d.ts +25 -0
- package/dist/types/src/Performance.d.ts.map +1 -0
- package/dist/types/src/RuntimeProvider.d.ts +21 -0
- package/dist/types/src/RuntimeProvider.d.ts.map +1 -0
- package/dist/types/src/SchemaEx.d.ts +4 -0
- package/dist/types/src/SchemaEx.d.ts.map +1 -0
- package/dist/types/src/atom-kvs.d.ts +19 -0
- package/dist/types/src/atom-kvs.d.ts.map +1 -0
- package/dist/types/src/dynamic-runtime.d.ts +56 -0
- package/dist/types/src/dynamic-runtime.d.ts.map +1 -0
- package/dist/types/src/dynamic-runtime.test.d.ts +2 -0
- package/dist/types/src/dynamic-runtime.test.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +8 -7
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/{ast.d.ts → internal/ast.d.ts} +45 -21
- package/dist/types/src/internal/ast.d.ts.map +1 -0
- package/dist/types/src/internal/async-task-tagging.d.ts +6 -0
- package/dist/types/src/internal/async-task-tagging.d.ts.map +1 -0
- package/dist/types/src/internal/context.d.ts.map +1 -0
- package/dist/types/src/{errors.d.ts → internal/errors.d.ts} +16 -0
- package/dist/types/src/internal/errors.d.ts.map +1 -0
- package/dist/types/src/{jsonPath.d.ts → internal/json-path.d.ts} +11 -3
- package/dist/types/src/internal/json-path.d.ts.map +1 -0
- package/dist/types/src/internal/resource.d.ts.map +1 -0
- package/dist/types/src/internal/url.d.ts.map +1 -0
- package/dist/types/src/json-path.test.d.ts +2 -0
- package/dist/types/src/json-path.test.d.ts.map +1 -0
- package/dist/types/src/testing.d.ts +5 -14
- package/dist/types/src/testing.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +8 -0
- package/dist/types/src/types.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +33 -21
- package/src/EffectEx.ts +18 -0
- package/src/Performance.ts +45 -0
- package/src/RuntimeProvider.ts +35 -0
- package/src/SchemaEx.ts +46 -0
- package/src/ast.test.ts +36 -9
- package/src/atom-kvs.ts +35 -0
- package/src/dynamic-runtime.test.ts +465 -0
- package/src/dynamic-runtime.ts +195 -0
- package/src/index.ts +12 -7
- package/src/{ast.ts → internal/ast.ts} +121 -91
- package/src/internal/async-task-tagging.ts +51 -0
- package/src/{errors.ts → internal/errors.ts} +72 -8
- package/src/{jsonPath.ts → internal/json-path.ts} +26 -3
- package/src/{resource.ts → internal/resource.ts} +2 -2
- package/src/interrupt.test.ts +3 -1
- package/src/{jsonPath.test.ts → json-path.test.ts} +55 -8
- package/src/layers.test.ts +4 -2
- package/src/resource.test.ts +1 -1
- package/src/sanity.test.ts +6 -4
- package/src/testing.ts +5 -29
- package/src/types.ts +11 -0
- package/src/url.test.ts +1 -1
- package/dist/types/src/ast.d.ts.map +0 -1
- package/dist/types/src/context.d.ts.map +0 -1
- package/dist/types/src/errors.d.ts.map +0 -1
- package/dist/types/src/jsonPath.d.ts.map +0 -1
- package/dist/types/src/jsonPath.test.d.ts +0 -2
- package/dist/types/src/jsonPath.test.d.ts.map +0 -1
- package/dist/types/src/resource.d.ts.map +0 -1
- package/dist/types/src/url.d.ts.map +0 -1
- /package/dist/types/src/{context.d.ts → internal/context.d.ts} +0 -0
- /package/dist/types/src/{resource.d.ts → internal/resource.d.ts} +0 -0
- /package/dist/types/src/{url.d.ts → internal/url.d.ts} +0 -0
- /package/src/{context.ts → internal/context.ts} +0 -0
- /package/src/{url.ts → internal/url.ts} +0 -0
package/package.json
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/effect",
|
|
3
|
-
"version": "0.8.4-
|
|
3
|
+
"version": "0.8.4-staging.60fe92afc8",
|
|
4
4
|
"description": "Effect utils.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
7
|
-
"
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/dxos/dxos"
|
|
10
|
+
},
|
|
11
|
+
"license": "FSL-1.1-Apache-2.0",
|
|
8
12
|
"author": "info@dxos.org",
|
|
9
13
|
"type": "module",
|
|
10
14
|
"exports": {
|
|
@@ -13,37 +17,45 @@
|
|
|
13
17
|
"types": "./dist/types/src/index.d.ts",
|
|
14
18
|
"browser": "./dist/lib/browser/index.mjs",
|
|
15
19
|
"node": "./dist/lib/node-esm/index.mjs"
|
|
20
|
+
},
|
|
21
|
+
"./testing": {
|
|
22
|
+
"source": "./src/testing.ts",
|
|
23
|
+
"types": "./dist/types/src/testing.d.ts",
|
|
24
|
+
"browser": "./dist/lib/browser/testing.mjs",
|
|
25
|
+
"node": "./dist/lib/node-esm/testing.mjs"
|
|
16
26
|
}
|
|
17
27
|
},
|
|
18
28
|
"types": "dist/types/src/index.d.ts",
|
|
19
|
-
"typesVersions": {
|
|
20
|
-
"*": {}
|
|
21
|
-
},
|
|
22
29
|
"files": [
|
|
23
30
|
"dist",
|
|
24
31
|
"src"
|
|
25
32
|
],
|
|
26
33
|
"dependencies": {
|
|
27
|
-
"@effect/
|
|
28
|
-
"@opentelemetry
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"@dxos/
|
|
32
|
-
"@dxos/
|
|
33
|
-
"@dxos/util": "0.8.4-
|
|
34
|
+
"@effect-atom/atom-react": "^0.5.0",
|
|
35
|
+
"@effect/opentelemetry": "^0.63.0",
|
|
36
|
+
"@opentelemetry/api": "^1.9.1",
|
|
37
|
+
"jsonpath-plus": "^10.3.0",
|
|
38
|
+
"@dxos/node-std": "0.8.4-staging.60fe92afc8",
|
|
39
|
+
"@dxos/context": "0.8.4-staging.60fe92afc8",
|
|
40
|
+
"@dxos/util": "0.8.4-staging.60fe92afc8",
|
|
41
|
+
"@dxos/invariant": "0.8.4-staging.60fe92afc8"
|
|
34
42
|
},
|
|
35
43
|
"devDependencies": {
|
|
36
|
-
"@
|
|
37
|
-
"@
|
|
38
|
-
"@opentelemetry/
|
|
39
|
-
"@opentelemetry/
|
|
40
|
-
"@opentelemetry/sdk-
|
|
41
|
-
"@opentelemetry/
|
|
42
|
-
"
|
|
43
|
-
"@
|
|
44
|
+
"@effect/platform": "0.96.1",
|
|
45
|
+
"@effect/platform-browser": "0.76.0",
|
|
46
|
+
"@opentelemetry/api-logs": "^0.218.0",
|
|
47
|
+
"@opentelemetry/resources": "^2.7.1",
|
|
48
|
+
"@opentelemetry/sdk-logs": "^0.218.0",
|
|
49
|
+
"@opentelemetry/sdk-node": "^0.218.0",
|
|
50
|
+
"@opentelemetry/sdk-trace-node": "^2.7.1",
|
|
51
|
+
"@opentelemetry/semantic-conventions": "^1.41.1",
|
|
52
|
+
"effect": "3.21.3",
|
|
53
|
+
"@dxos/log": "0.8.4-staging.60fe92afc8"
|
|
44
54
|
},
|
|
45
55
|
"peerDependencies": {
|
|
46
|
-
"effect": "
|
|
56
|
+
"@effect/platform": "0.96.1",
|
|
57
|
+
"@effect/platform-browser": "0.76.0",
|
|
58
|
+
"effect": "3.21.3"
|
|
47
59
|
},
|
|
48
60
|
"publishConfig": {
|
|
49
61
|
"access": "public"
|
package/src/EffectEx.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
// @import-as-namespace
|
|
6
|
+
|
|
7
|
+
export { asyncTaskTaggingLayer } from './internal/async-task-tagging';
|
|
8
|
+
export { contextFromScope } from './internal/context';
|
|
9
|
+
export {
|
|
10
|
+
causeToError,
|
|
11
|
+
throwCause,
|
|
12
|
+
unwrapExit,
|
|
13
|
+
runAndForwardErrors,
|
|
14
|
+
runPromise,
|
|
15
|
+
runInRuntime,
|
|
16
|
+
promiseWithCauseCapture,
|
|
17
|
+
} from './internal/errors';
|
|
18
|
+
export { acquireReleaseResource } from './internal/resource';
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2026 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
6
|
+
import type * as Exit from 'effect/Exit';
|
|
7
|
+
|
|
8
|
+
export interface AddTrackEntryOptions {
|
|
9
|
+
name: string;
|
|
10
|
+
devtools?: {
|
|
11
|
+
/**
|
|
12
|
+
* @example 'track-entry'
|
|
13
|
+
*/
|
|
14
|
+
dataType: string;
|
|
15
|
+
track: string;
|
|
16
|
+
trackGroup: string;
|
|
17
|
+
/**
|
|
18
|
+
* @example 'tertiary-dark'
|
|
19
|
+
*/
|
|
20
|
+
color: string;
|
|
21
|
+
properties?: [string, any][];
|
|
22
|
+
tooltipText?: string;
|
|
23
|
+
};
|
|
24
|
+
detail?: Record<string, unknown>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Puts the effect span on the performance timeline in DevTools.
|
|
29
|
+
*/
|
|
30
|
+
export const addTrackEntry =
|
|
31
|
+
<A, E>(options: AddTrackEntryOptions | ((exit: Exit.Exit<A, E>) => AddTrackEntryOptions)) =>
|
|
32
|
+
<R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R> =>
|
|
33
|
+
Effect.gen(function* () {
|
|
34
|
+
const start = performance.now();
|
|
35
|
+
const exit = yield* Effect.exit(effect);
|
|
36
|
+
const resolvedOptions = typeof options === 'function' ? options(exit) : options;
|
|
37
|
+
performance.measure(resolvedOptions.name, {
|
|
38
|
+
start: start,
|
|
39
|
+
detail: {
|
|
40
|
+
...resolvedOptions.detail,
|
|
41
|
+
devtools: resolvedOptions.devtools,
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
return yield* exit;
|
|
45
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2026 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
6
|
+
import * as Runtime from 'effect/Runtime';
|
|
7
|
+
|
|
8
|
+
import { runAndForwardErrors, unwrapExit } from './internal/errors';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Provides effect runtime with services to run effects.
|
|
12
|
+
*/
|
|
13
|
+
export type RuntimeProvider<R> = Effect.Effect<Runtime.Runtime<R>>;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @returns Runtime provider from the current context.
|
|
17
|
+
*/
|
|
18
|
+
export const currentRuntime = <R = never>() => Effect.runtime<R>().pipe(Effect.map(Effect.succeed));
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Run effect, within runitme, clean errors and fix stack-traces.
|
|
22
|
+
*/
|
|
23
|
+
export const runPromise =
|
|
24
|
+
<R>(provider: RuntimeProvider<R>) =>
|
|
25
|
+
async <A>(effect: Effect.Effect<A, any, R>): Promise<A> => {
|
|
26
|
+
const runtime = await runAndForwardErrors(provider);
|
|
27
|
+
return unwrapExit(await effect.pipe(Runtime.runPromiseExit(runtime)));
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Provide services from runtime provider to effect.
|
|
32
|
+
*/
|
|
33
|
+
export const provide: {
|
|
34
|
+
<R2>(runtime: RuntimeProvider<R2>): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, R2>>;
|
|
35
|
+
} = (runtimeProvider) => (effect) => Effect.flatMap(runtimeProvider, (runtime) => Effect.provide(effect, runtime));
|
package/src/SchemaEx.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
// @import-as-namespace
|
|
6
|
+
|
|
7
|
+
export {
|
|
8
|
+
getBaseType,
|
|
9
|
+
type SchemaProperty,
|
|
10
|
+
getProperties,
|
|
11
|
+
VisitResult,
|
|
12
|
+
type Path,
|
|
13
|
+
type TestFn,
|
|
14
|
+
type VisitorFn,
|
|
15
|
+
visit,
|
|
16
|
+
findNode,
|
|
17
|
+
findProperty,
|
|
18
|
+
getAnnotation,
|
|
19
|
+
findAnnotation,
|
|
20
|
+
isOption,
|
|
21
|
+
isLiteralUnion,
|
|
22
|
+
getLiteralValues,
|
|
23
|
+
isArrayType,
|
|
24
|
+
getArrayElementType,
|
|
25
|
+
isTupleType,
|
|
26
|
+
isDiscriminatedUnion,
|
|
27
|
+
getDiscriminatingProps,
|
|
28
|
+
getDiscriminatedType,
|
|
29
|
+
isNestedType,
|
|
30
|
+
mapAst,
|
|
31
|
+
unwrapOptional,
|
|
32
|
+
} from './internal/ast';
|
|
33
|
+
|
|
34
|
+
export {
|
|
35
|
+
JsonPath,
|
|
36
|
+
JsonProp,
|
|
37
|
+
isJsonPath,
|
|
38
|
+
createJsonPath,
|
|
39
|
+
fromEffectValidationPath,
|
|
40
|
+
splitJsonPath,
|
|
41
|
+
getField,
|
|
42
|
+
getValue,
|
|
43
|
+
setValue,
|
|
44
|
+
} from './internal/json-path';
|
|
45
|
+
|
|
46
|
+
export { getParamKeyAnnotation, ParamKeyAnnotation, UrlParser } from './internal/url';
|
package/src/ast.test.ts
CHANGED
|
@@ -15,13 +15,13 @@ import {
|
|
|
15
15
|
getAnnotation,
|
|
16
16
|
getDiscriminatedType,
|
|
17
17
|
getDiscriminatingProps,
|
|
18
|
-
|
|
18
|
+
getProperties,
|
|
19
19
|
isArrayType,
|
|
20
|
+
isDiscriminatedUnion,
|
|
20
21
|
isOption,
|
|
21
|
-
isSimpleType,
|
|
22
22
|
visit,
|
|
23
|
-
} from './ast';
|
|
24
|
-
import { type JsonPath, type JsonProp } from './
|
|
23
|
+
} from './internal/ast';
|
|
24
|
+
import { type JsonPath, type JsonProp } from './internal/json-path';
|
|
25
25
|
|
|
26
26
|
const ZipCode = Schema.String.pipe(
|
|
27
27
|
Schema.pattern(/^\d{5}$/, {
|
|
@@ -65,10 +65,9 @@ describe('AST', () => {
|
|
|
65
65
|
|
|
66
66
|
const prop = findProperty(TestSchema, 'name' as JsonProp);
|
|
67
67
|
invariant(prop);
|
|
68
|
-
const node = findNode(prop,
|
|
68
|
+
const node = findNode(prop, (node) => node._tag === 'StringKeyword');
|
|
69
69
|
invariant(node);
|
|
70
|
-
|
|
71
|
-
expect(type).to.eq('string');
|
|
70
|
+
expect(node._tag).to.eq('StringKeyword');
|
|
72
71
|
});
|
|
73
72
|
|
|
74
73
|
test('findProperty', ({ expect }) => {
|
|
@@ -92,6 +91,30 @@ describe('AST', () => {
|
|
|
92
91
|
}
|
|
93
92
|
});
|
|
94
93
|
|
|
94
|
+
test('getProperties preserves annotation on property type after refinements', ({ expect }) => {
|
|
95
|
+
// When a property is e.g. Format.Text.pipe(nonEmptyString(), maxLength(), Schema.annotations({ title, description })),
|
|
96
|
+
// the form uses getProperties(schema.ast) and then Format.FormatAnnotation.getFromAst(property.type).
|
|
97
|
+
// Custom title and description from the outer Schema.annotations() must not be lost.
|
|
98
|
+
const WithRefinements = Schema.Struct({
|
|
99
|
+
message: Schema.String.annotations({ title: 'Feedback' }).pipe(
|
|
100
|
+
Schema.minLength(1),
|
|
101
|
+
Schema.maxLength(4096),
|
|
102
|
+
Schema.annotations({
|
|
103
|
+
title: 'Feedback label',
|
|
104
|
+
description: 'Feedback placeholder',
|
|
105
|
+
}),
|
|
106
|
+
),
|
|
107
|
+
});
|
|
108
|
+
const properties = getProperties(WithRefinements.ast);
|
|
109
|
+
const messageProp = properties.find((p) => p.name === 'message');
|
|
110
|
+
invariant(messageProp);
|
|
111
|
+
const title = findAnnotation(messageProp.type, SchemaAST.TitleAnnotationId);
|
|
112
|
+
const description = findAnnotation(messageProp.type, SchemaAST.DescriptionAnnotationId);
|
|
113
|
+
// Outer Schema.annotations() wins so form labels/placeholders are preserved.
|
|
114
|
+
expect(title).to.eq('Feedback label');
|
|
115
|
+
expect(description).to.eq('Feedback placeholder');
|
|
116
|
+
});
|
|
117
|
+
|
|
95
118
|
test('findAnnotation', ({ expect }) => {
|
|
96
119
|
const TestSchema = Schema.NonEmptyString.pipe(Schema.pattern(/^\d{5}$/)).annotations({
|
|
97
120
|
title: 'original title',
|
|
@@ -137,7 +160,11 @@ describe('AST', () => {
|
|
|
137
160
|
});
|
|
138
161
|
|
|
139
162
|
const props: string[] = [];
|
|
140
|
-
visit(
|
|
163
|
+
visit(
|
|
164
|
+
TestSchema.ast,
|
|
165
|
+
(_, path) => props.push(path.join('.')),
|
|
166
|
+
(node, path, depth) => depth < 3,
|
|
167
|
+
);
|
|
141
168
|
});
|
|
142
169
|
|
|
143
170
|
test('discriminated unions', ({ expect }) => {
|
|
@@ -152,7 +179,7 @@ describe('AST', () => {
|
|
|
152
179
|
expect(isOption(TestUnionSchema.ast)).to.be.false;
|
|
153
180
|
expect(getDiscriminatingProps(TestUnionSchema.ast)).to.deep.eq(['kind']);
|
|
154
181
|
|
|
155
|
-
const node = findNode(TestUnionSchema.ast,
|
|
182
|
+
const node = findNode(TestUnionSchema.ast, isDiscriminatedUnion);
|
|
156
183
|
expect(node).to.eq(TestUnionSchema.ast);
|
|
157
184
|
}
|
|
158
185
|
|
package/src/atom-kvs.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Atom } from '@effect-atom/atom-react';
|
|
6
|
+
import * as BrowserKeyValueStore from '@effect/platform-browser/BrowserKeyValueStore';
|
|
7
|
+
import type * as Schema from 'effect/Schema';
|
|
8
|
+
|
|
9
|
+
// TODO(wittjosiah): This is currently provided for convenience but maybe should be removed.
|
|
10
|
+
const defaultRuntime = Atom.runtime(BrowserKeyValueStore.layerLocalStorage);
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Creates a KVS-backed atom for structured settings using Atom.kvs.
|
|
14
|
+
* The entire object is stored as a single localStorage key with JSON serialization.
|
|
15
|
+
*
|
|
16
|
+
* @param options.key - The localStorage key to store the value under.
|
|
17
|
+
* @param options.schema - Effect Schema for the value type.
|
|
18
|
+
* @param options.defaultValue - Function returning the default value.
|
|
19
|
+
* @param options.runtime - Optional custom Atom runtime (defaults to localStorage).
|
|
20
|
+
* @returns A writable atom that persists to localStorage.
|
|
21
|
+
*/
|
|
22
|
+
export const createKvsStore = <T extends Record<string, any>>(options: {
|
|
23
|
+
key: string;
|
|
24
|
+
schema: Schema.Schema<T>;
|
|
25
|
+
defaultValue: () => T;
|
|
26
|
+
runtime?: ReturnType<typeof Atom.runtime>;
|
|
27
|
+
}): Atom.Writable<T> => {
|
|
28
|
+
const runtime = options.runtime ?? defaultRuntime;
|
|
29
|
+
return Atom.kvs({
|
|
30
|
+
runtime,
|
|
31
|
+
key: options.key,
|
|
32
|
+
schema: options.schema,
|
|
33
|
+
defaultValue: options.defaultValue,
|
|
34
|
+
}).pipe(Atom.keepAlive);
|
|
35
|
+
};
|