@dxos/effect 0.8.4-main.ef1bc66f44 → 0.8.4-main.f466a3d56e
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/index.mjs +113 -102
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing.mjs +0 -8
- package/dist/lib/browser/testing.mjs.map +3 -3
- package/dist/lib/node-esm/index.mjs +113 -102
- 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 +0 -8
- package/dist/lib/node-esm/testing.mjs.map +3 -3
- 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.map +1 -1
- package/dist/types/src/ast.d.ts +7 -1
- package/dist/types/src/ast.d.ts.map +1 -1
- package/dist/types/src/async-task-tagging.d.ts +6 -0
- package/dist/types/src/async-task-tagging.d.ts.map +1 -0
- package/dist/types/src/atom-kvs.d.ts.map +1 -1
- package/dist/types/src/errors.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +3 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/json-path.d.ts.map +1 -1
- package/dist/types/src/resource.d.ts.map +1 -1
- package/dist/types/src/testing.d.ts +3 -13
- 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/src/url.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +17 -24
- package/src/Performance.ts +45 -0
- package/src/ast.ts +34 -10
- package/src/async-task-tagging.ts +51 -0
- package/src/atom-kvs.ts +1 -1
- package/src/index.ts +3 -0
- package/src/testing.ts +3 -29
- package/src/types.ts +11 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/effect",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.f466a3d56e",
|
|
4
4
|
"description": "Effect utils.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "https://github.com/dxos/dxos"
|
|
10
10
|
},
|
|
11
|
-
"license": "
|
|
11
|
+
"license": "FSL-1.1-Apache-2.0",
|
|
12
12
|
"author": "info@dxos.org",
|
|
13
13
|
"type": "module",
|
|
14
14
|
"exports": {
|
|
@@ -26,13 +26,6 @@
|
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
"types": "dist/types/src/index.d.ts",
|
|
29
|
-
"typesVersions": {
|
|
30
|
-
"*": {
|
|
31
|
-
"testing": [
|
|
32
|
-
"./dist/types/src/testing.d.ts"
|
|
33
|
-
]
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
29
|
"files": [
|
|
37
30
|
"dist",
|
|
38
31
|
"src"
|
|
@@ -40,29 +33,29 @@
|
|
|
40
33
|
"dependencies": {
|
|
41
34
|
"@effect-atom/atom-react": "^0.5.0",
|
|
42
35
|
"@effect/opentelemetry": "^0.61.0",
|
|
43
|
-
"@opentelemetry/api": "^1.9.
|
|
44
|
-
"jsonpath-plus": "10.
|
|
45
|
-
"@dxos/
|
|
46
|
-
"@dxos/
|
|
47
|
-
"@dxos/
|
|
48
|
-
"@dxos/
|
|
36
|
+
"@opentelemetry/api": "^1.9.1",
|
|
37
|
+
"jsonpath-plus": "^10.3.0",
|
|
38
|
+
"@dxos/context": "0.8.4-main.f466a3d56e",
|
|
39
|
+
"@dxos/invariant": "0.8.4-main.f466a3d56e",
|
|
40
|
+
"@dxos/util": "0.8.4-main.f466a3d56e",
|
|
41
|
+
"@dxos/node-std": "0.8.4-main.f466a3d56e"
|
|
49
42
|
},
|
|
50
43
|
"devDependencies": {
|
|
51
44
|
"@effect/platform": "0.94.4",
|
|
52
45
|
"@effect/platform-browser": "0.74.0",
|
|
53
|
-
"@opentelemetry/api-logs": "^0.
|
|
54
|
-
"@opentelemetry/resources": "^2.1
|
|
55
|
-
"@opentelemetry/sdk-logs": "^0.
|
|
56
|
-
"@opentelemetry/sdk-node": "^0.
|
|
57
|
-
"@opentelemetry/sdk-trace-node": "^2.1
|
|
58
|
-
"@opentelemetry/semantic-conventions": "^1.
|
|
59
|
-
"effect": "3.
|
|
60
|
-
"@dxos/log": "0.8.4-main.
|
|
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.20.0",
|
|
53
|
+
"@dxos/log": "0.8.4-main.f466a3d56e"
|
|
61
54
|
},
|
|
62
55
|
"peerDependencies": {
|
|
63
56
|
"@effect/platform": "0.94.4",
|
|
64
57
|
"@effect/platform-browser": "0.74.0",
|
|
65
|
-
"effect": "3.
|
|
58
|
+
"effect": "3.20.0"
|
|
66
59
|
},
|
|
67
60
|
"publishConfig": {
|
|
68
61
|
"access": "public"
|
|
@@ -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
|
+
});
|
package/src/ast.ts
CHANGED
|
@@ -62,12 +62,22 @@ export type SchemaProperty = Pick<SchemaAST.PropertySignature, 'name' | 'type' |
|
|
|
62
62
|
*/
|
|
63
63
|
export const getProperties = (ast: SchemaAST.AST): SchemaProperty[] => {
|
|
64
64
|
const properties = SchemaAST.getPropertySignatures(ast);
|
|
65
|
-
return properties.map((prop) =>
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
65
|
+
return properties.map((prop) => {
|
|
66
|
+
const { type, refinements } = getBaseType(prop);
|
|
67
|
+
// Merge PropertySignature-level annotations (e.g., title, description set via .annotations())
|
|
68
|
+
// onto the unwrapped base type so downstream consumers see them.
|
|
69
|
+
const mergedType =
|
|
70
|
+
prop.annotations && Reflect.ownKeys(prop.annotations).length > 0
|
|
71
|
+
? ({ ...type, annotations: { ...type.annotations, ...prop.annotations } } as SchemaAST.AST)
|
|
72
|
+
: type;
|
|
73
|
+
return {
|
|
74
|
+
type: mergedType,
|
|
75
|
+
refinements,
|
|
76
|
+
name: prop.name,
|
|
77
|
+
isOptional: prop.isOptional,
|
|
78
|
+
isReadonly: prop.isReadonly,
|
|
79
|
+
};
|
|
80
|
+
});
|
|
71
81
|
};
|
|
72
82
|
|
|
73
83
|
//
|
|
@@ -254,10 +264,10 @@ export const findProperty = (
|
|
|
254
264
|
//
|
|
255
265
|
|
|
256
266
|
const defaultAnnotations: Record<string, SchemaAST.Annotated> = {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
267
|
+
ObjectKeyword: SchemaAST.objectKeyword,
|
|
268
|
+
StringKeyword: SchemaAST.stringKeyword,
|
|
269
|
+
NumberKeyword: SchemaAST.numberKeyword,
|
|
270
|
+
BooleanKeyword: SchemaAST.booleanKeyword,
|
|
261
271
|
};
|
|
262
272
|
|
|
263
273
|
/**
|
|
@@ -320,6 +330,20 @@ export const isLiteralUnion = (node: SchemaAST.AST): node is SchemaAST.Union<Sch
|
|
|
320
330
|
return SchemaAST.isUnion(node) && node.types.every(SchemaAST.isLiteral);
|
|
321
331
|
};
|
|
322
332
|
|
|
333
|
+
/**
|
|
334
|
+
* Extracts the literal values from a schema that is a union of literals
|
|
335
|
+
* (e.g. `Schema.Literal('a', 'b')` or `Schema.Union(Schema.Literal('a'), Schema.Literal('b'))`).
|
|
336
|
+
* Returns an empty array if the schema is not a literal union.
|
|
337
|
+
*/
|
|
338
|
+
export const getLiteralValues = <S extends Schema.Schema<any, any, any>>(
|
|
339
|
+
schema: S,
|
|
340
|
+
): ReadonlyArray<Schema.Schema.Type<S>> => {
|
|
341
|
+
if (!isLiteralUnion(schema.ast)) {
|
|
342
|
+
return [];
|
|
343
|
+
}
|
|
344
|
+
return schema.ast.types.map((node) => node.literal as Schema.Schema.Type<S>);
|
|
345
|
+
};
|
|
346
|
+
|
|
323
347
|
/**
|
|
324
348
|
* Determines if the node is an array type.
|
|
325
349
|
*/
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Context from 'effect/Context';
|
|
6
|
+
import * as Effect from 'effect/Effect';
|
|
7
|
+
import { pipe } from 'effect/Function';
|
|
8
|
+
import * as Layer from 'effect/Layer';
|
|
9
|
+
import * as Predicate from 'effect/Predicate';
|
|
10
|
+
import * as Tracer from 'effect/Tracer';
|
|
11
|
+
|
|
12
|
+
const runInTask = Symbol('runInTask');
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Traces effect frames using console.createTask so that the proper stack-trace is visible in Chrome Devtools debugger.
|
|
16
|
+
*/
|
|
17
|
+
export const asyncTaskTaggingLayer = () => {
|
|
18
|
+
if (Predicate.hasProperty(console, 'createTask') === false) {
|
|
19
|
+
return Layer.empty;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const makeTracer = Effect.gen(function* () {
|
|
23
|
+
const oldTracer = yield* Effect.tracer;
|
|
24
|
+
return Tracer.make({
|
|
25
|
+
span: (name, ...args) => {
|
|
26
|
+
const span = oldTracer.span(name, ...args);
|
|
27
|
+
const trace = (console as any).createTask(name);
|
|
28
|
+
(span as any)[runInTask] = (f: any) => trace.run(f);
|
|
29
|
+
return span;
|
|
30
|
+
},
|
|
31
|
+
context: (f, fiber) => {
|
|
32
|
+
const maybeParentSpan = Context.getOption(Tracer.ParentSpan)(fiber.currentContext);
|
|
33
|
+
|
|
34
|
+
if (maybeParentSpan._tag === 'None') {
|
|
35
|
+
return oldTracer.context(f, fiber);
|
|
36
|
+
}
|
|
37
|
+
const parentSpan = maybeParentSpan.value;
|
|
38
|
+
if (parentSpan._tag === 'ExternalSpan') {
|
|
39
|
+
return oldTracer.context(f, fiber);
|
|
40
|
+
}
|
|
41
|
+
const span = parentSpan;
|
|
42
|
+
if (runInTask in span && typeof span[runInTask] === 'function') {
|
|
43
|
+
return span[runInTask](() => oldTracer.context(f, fiber));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return oldTracer.context(f, fiber);
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
return pipe(makeTracer, Effect.map(Layer.setTracer), Layer.unwrapEffect);
|
|
51
|
+
};
|
package/src/atom-kvs.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import * as BrowserKeyValueStore from '@effect/platform-browser/BrowserKeyValueStore';
|
|
6
5
|
import { Atom } from '@effect-atom/atom-react';
|
|
6
|
+
import * as BrowserKeyValueStore from '@effect/platform-browser/BrowserKeyValueStore';
|
|
7
7
|
import type * as Schema from 'effect/Schema';
|
|
8
8
|
|
|
9
9
|
// TODO(wittjosiah): This is currently provided for convenience but maybe should be removed.
|
package/src/index.ts
CHANGED
|
@@ -9,5 +9,8 @@ export * as DynamicRuntime from './dynamic-runtime';
|
|
|
9
9
|
export * from './errors';
|
|
10
10
|
export * from './json-path';
|
|
11
11
|
export * from './resource';
|
|
12
|
+
export * from './types';
|
|
12
13
|
export * from './url';
|
|
13
14
|
export * as RuntimeProvider from './RuntimeProvider';
|
|
15
|
+
export * as Performance from './Performance';
|
|
16
|
+
export * from './async-task-tagging';
|
package/src/testing.ts
CHANGED
|
@@ -6,17 +6,11 @@ import * as Context from 'effect/Context';
|
|
|
6
6
|
import * as Effect from 'effect/Effect';
|
|
7
7
|
import type { TestContext } from 'vitest';
|
|
8
8
|
|
|
9
|
-
// TODO(dmaretskyi): Add all different test tags here.
|
|
10
|
-
export type TestTag =
|
|
11
|
-
| 'flaky' // Flaky tests.
|
|
12
|
-
| 'llm' // Tests with AI.
|
|
13
|
-
| 'sync'; // Sync with external services.
|
|
14
|
-
|
|
15
9
|
export namespace TestHelpers {
|
|
16
10
|
/**
|
|
17
11
|
* Skip the test if the condition is false.
|
|
18
12
|
*
|
|
19
|
-
*
|
|
13
|
+
* Example:
|
|
20
14
|
* ```ts
|
|
21
15
|
* it.effect(
|
|
22
16
|
* 'should process an agentic loop using Claude',
|
|
@@ -41,7 +35,7 @@ export namespace TestHelpers {
|
|
|
41
35
|
/**
|
|
42
36
|
* Skip the test if the condition is true.
|
|
43
37
|
*
|
|
44
|
-
*
|
|
38
|
+
* Example:
|
|
45
39
|
* ```ts
|
|
46
40
|
* it.effect(
|
|
47
41
|
* 'should process an agentic loop using Claude',
|
|
@@ -63,30 +57,10 @@ export namespace TestHelpers {
|
|
|
63
57
|
}
|
|
64
58
|
});
|
|
65
59
|
|
|
66
|
-
export const tagEnabled = (tag: TestTag) => process.env.DX_TEST_TAGS?.includes(tag);
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Skips this test if the tag is not in the list of tags to run.
|
|
70
|
-
* Tags are specified in the `DX_TEST_TAGS` environment variable.
|
|
71
|
-
*
|
|
72
|
-
* @param tag
|
|
73
|
-
* @returns
|
|
74
|
-
*/
|
|
75
|
-
export const taggedTest =
|
|
76
|
-
(tag: TestTag) =>
|
|
77
|
-
<A, E, R>(effect: Effect.Effect<A, E, R>, ctx: TestContext): Effect.Effect<A, E, R> =>
|
|
78
|
-
Effect.gen(function* () {
|
|
79
|
-
if (!tagEnabled(tag)) {
|
|
80
|
-
ctx.skip();
|
|
81
|
-
} else {
|
|
82
|
-
return yield* effect;
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
|
|
86
60
|
/**
|
|
87
61
|
* Provide TestContext from test parameters.
|
|
88
62
|
*
|
|
89
|
-
*
|
|
63
|
+
* Example:
|
|
90
64
|
* ```ts
|
|
91
65
|
* it.effect(
|
|
92
66
|
* 'with context',
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2026 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Flat intersection of up to five types. Behaves like `A & B & C & ...` but
|
|
7
|
+
* formats as a comma-separated tuple, which fits multi-line layouts more
|
|
8
|
+
* cleanly than chained `&` operators. Unused slots default to `unknown`,
|
|
9
|
+
* which is inert under intersection (`T & unknown = T`).
|
|
10
|
+
*/
|
|
11
|
+
export type Merge<A, B = unknown, C = unknown, D = unknown, E = unknown> = A & B & C & D & E;
|