@dxos/effect 0.8.4-main.a4bbb77 → 0.8.4-main.ae835ea
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/lib/browser/index.mjs +44 -46
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +44 -46
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/ast.d.ts +2 -1
- package/dist/types/src/ast.d.ts.map +1 -1
- package/dist/types/src/context.d.ts +2 -1
- package/dist/types/src/context.d.ts.map +1 -1
- package/dist/types/src/errors.d.ts +3 -1
- package/dist/types/src/errors.d.ts.map +1 -1
- package/dist/types/src/jsonPath.d.ts +1 -1
- package/dist/types/src/jsonPath.d.ts.map +1 -1
- package/dist/types/src/otel.d.ts +5 -4
- package/dist/types/src/otel.d.ts.map +1 -1
- package/dist/types/src/resource.d.ts +2 -2
- package/dist/types/src/resource.d.ts.map +1 -1
- package/dist/types/src/testing.d.ts +2 -1
- package/dist/types/src/testing.d.ts.map +1 -1
- package/dist/types/src/url.d.ts +3 -1
- package/dist/types/src/url.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -7
- package/src/ast.test.ts +2 -1
- package/src/ast.ts +8 -5
- package/src/context.ts +2 -1
- package/src/errors.test.ts +1 -1
- package/src/errors.ts +8 -3
- package/src/interrupt.test.ts +3 -1
- package/src/jsonPath.ts +2 -1
- package/src/layers.test.ts +5 -1
- package/src/otel.test.ts +2 -1
- package/src/otel.ts +9 -5
- package/src/resource.test.ts +3 -3
- package/src/resource.ts +2 -2
- package/src/sanity.test.ts +6 -5
- package/src/testing.ts +2 -1
- package/src/url.test.ts +1 -1
- package/src/url.ts +5 -2
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.ae835ea",
|
|
4
4
|
"description": "Effect utils.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -26,12 +26,11 @@
|
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@effect/opentelemetry": "^0.58.0",
|
|
28
28
|
"@opentelemetry/api": "^1.9.0",
|
|
29
|
-
"@opentelemetry/core": "^2.1.0",
|
|
30
29
|
"jsonpath-plus": "10.2.0",
|
|
31
|
-
"@dxos/context": "0.8.4-main.
|
|
32
|
-
"@dxos/invariant": "0.8.4-main.
|
|
33
|
-
"@dxos/node-std": "0.8.4-main.
|
|
34
|
-
"@dxos/util": "0.8.4-main.
|
|
30
|
+
"@dxos/context": "0.8.4-main.ae835ea",
|
|
31
|
+
"@dxos/invariant": "0.8.4-main.ae835ea",
|
|
32
|
+
"@dxos/node-std": "0.8.4-main.ae835ea",
|
|
33
|
+
"@dxos/util": "0.8.4-main.ae835ea"
|
|
35
34
|
},
|
|
36
35
|
"devDependencies": {
|
|
37
36
|
"@opentelemetry/api-logs": "^0.203.0",
|
|
@@ -41,7 +40,7 @@
|
|
|
41
40
|
"@opentelemetry/sdk-trace-node": "^2.1.0",
|
|
42
41
|
"@opentelemetry/semantic-conventions": "^1.37.0",
|
|
43
42
|
"effect": "3.18.3",
|
|
44
|
-
"@dxos/log": "0.8.4-main.
|
|
43
|
+
"@dxos/log": "0.8.4-main.ae835ea"
|
|
45
44
|
},
|
|
46
45
|
"peerDependencies": {
|
|
47
46
|
"effect": "^3.13.3"
|
package/src/ast.test.ts
CHANGED
package/src/ast.ts
CHANGED
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
6
|
-
import
|
|
5
|
+
import * as Function from 'effect/Function';
|
|
6
|
+
import * as Option from 'effect/Option';
|
|
7
|
+
import * as Schema from 'effect/Schema';
|
|
8
|
+
import * as SchemaAST from 'effect/SchemaAST';
|
|
7
9
|
|
|
8
10
|
import { invariant } from '@dxos/invariant';
|
|
9
11
|
import { isNonNullable } from '@dxos/util';
|
|
@@ -289,8 +291,8 @@ export const getAnnotation =
|
|
|
289
291
|
<T>(annotationId: symbol, noDefault = true) =>
|
|
290
292
|
(node: SchemaAST.AST): T | undefined => {
|
|
291
293
|
// Title fallback seems to be the identifier.
|
|
292
|
-
const id = pipe(SchemaAST.getIdentifierAnnotation(node), Option.getOrUndefined);
|
|
293
|
-
const value = pipe(SchemaAST.getAnnotation<T>(annotationId)(node), Option.getOrUndefined);
|
|
294
|
+
const id = Function.pipe(SchemaAST.getIdentifierAnnotation(node), Option.getOrUndefined);
|
|
295
|
+
const value = Function.pipe(SchemaAST.getAnnotation<T>(annotationId)(node), Option.getOrUndefined);
|
|
294
296
|
if (noDefault && (value === defaultAnnotations[node._tag]?.annotations[annotationId] || value === id)) {
|
|
295
297
|
return undefined;
|
|
296
298
|
}
|
|
@@ -442,6 +444,7 @@ export const mapAst = (
|
|
|
442
444
|
),
|
|
443
445
|
),
|
|
444
446
|
ast.indexSignatures,
|
|
447
|
+
ast.annotations,
|
|
445
448
|
);
|
|
446
449
|
}
|
|
447
450
|
case 'Union': {
|
|
@@ -474,7 +477,7 @@ export const isArrayType = (node: SchemaAST.AST): boolean => {
|
|
|
474
477
|
SchemaAST.isTupleType(node) ||
|
|
475
478
|
(SchemaAST.isUnion(node) &&
|
|
476
479
|
node.types.some(isArrayType) &&
|
|
477
|
-
node.types.some(isUndefinedKeyword) &&
|
|
480
|
+
node.types.some(SchemaAST.isUndefinedKeyword) &&
|
|
478
481
|
node.types.length === 2)
|
|
479
482
|
);
|
|
480
483
|
};
|
package/src/context.ts
CHANGED
package/src/errors.test.ts
CHANGED
package/src/errors.ts
CHANGED
|
@@ -2,8 +2,13 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
6
|
-
import
|
|
5
|
+
import * as Cause from 'effect/Cause';
|
|
6
|
+
import * as Chunk from 'effect/Chunk';
|
|
7
|
+
import * as Effect from 'effect/Effect';
|
|
8
|
+
import * as Exit from 'effect/Exit';
|
|
9
|
+
import * as GlobalValue from 'effect/GlobalValue';
|
|
10
|
+
import * as Option from 'effect/Option';
|
|
11
|
+
import type * as Tracer from 'effect/Tracer';
|
|
7
12
|
|
|
8
13
|
const spanSymbol = Symbol.for('effect/SpanAnnotation');
|
|
9
14
|
const originalSymbol = Symbol.for('effect/OriginalAnnotation');
|
|
@@ -48,7 +53,7 @@ const prettyErrorStack = (error: any, appendStacks: string[] = []): any => {
|
|
|
48
53
|
}
|
|
49
54
|
|
|
50
55
|
if (span) {
|
|
51
|
-
let current: Span | AnySpan | undefined = span;
|
|
56
|
+
let current: Tracer.Span | Tracer.AnySpan | undefined = span;
|
|
52
57
|
let i = 0;
|
|
53
58
|
while (current && current._tag === 'Span' && i < 10) {
|
|
54
59
|
const stackFn = spanToTrace.get(current);
|
package/src/interrupt.test.ts
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { it } from '@effect/vitest';
|
|
6
|
-
import
|
|
6
|
+
import * as Cause from 'effect/Cause';
|
|
7
|
+
import * as Effect from 'effect/Effect';
|
|
8
|
+
import * as Fiber from 'effect/Fiber';
|
|
7
9
|
|
|
8
10
|
const doWork = Effect.fn('doWork')(function* () {
|
|
9
11
|
yield* Effect.sleep('1 minute');
|
package/src/jsonPath.ts
CHANGED
package/src/layers.test.ts
CHANGED
|
@@ -3,7 +3,11 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { it } from '@effect/vitest';
|
|
6
|
-
import
|
|
6
|
+
import * as Context from 'effect/Context';
|
|
7
|
+
import * as Duration from 'effect/Duration';
|
|
8
|
+
import * as Effect from 'effect/Effect';
|
|
9
|
+
import * as Layer from 'effect/Layer';
|
|
10
|
+
import * as ManagedRuntime from 'effect/ManagedRuntime';
|
|
7
11
|
import { test } from 'vitest';
|
|
8
12
|
|
|
9
13
|
class ClientConfig extends Context.Tag('ClientConfig')<ClientConfig, { endpoint: string }>() {}
|
package/src/otel.test.ts
CHANGED
|
@@ -15,7 +15,8 @@ import {
|
|
|
15
15
|
ATTR_CODE_STACKTRACE,
|
|
16
16
|
ATTR_SERVICE_NAME,
|
|
17
17
|
} from '@opentelemetry/semantic-conventions';
|
|
18
|
-
import
|
|
18
|
+
import * as Duration from 'effect/Duration';
|
|
19
|
+
import * as Effect from 'effect/Effect';
|
|
19
20
|
import { beforeEach } from 'vitest';
|
|
20
21
|
|
|
21
22
|
import { LogLevel, type LogProcessor, log } from '@dxos/log';
|
package/src/otel.ts
CHANGED
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import * as Resource from '@effect/opentelemetry/Resource';
|
|
6
|
+
import * as Tracer from '@effect/opentelemetry/Tracer';
|
|
6
7
|
import { type Attributes, trace } from '@opentelemetry/api';
|
|
7
|
-
import
|
|
8
|
-
import
|
|
8
|
+
import * as Effect from 'effect/Effect';
|
|
9
|
+
import type * as Function from 'effect/Function';
|
|
10
|
+
import * as Layer from 'effect/Layer';
|
|
9
11
|
|
|
10
12
|
export interface Configuration {
|
|
11
13
|
readonly resource?:
|
|
@@ -19,9 +21,11 @@ export interface Configuration {
|
|
|
19
21
|
|
|
20
22
|
// Based on https://github.com/Effect-TS/effect/blob/main/packages/opentelemetry/src/NodeSdk.ts
|
|
21
23
|
export const layerOtel: {
|
|
22
|
-
(evaluate: LazyArg<Configuration>): Layer.Layer<Resource.Resource>;
|
|
24
|
+
(evaluate: Function.LazyArg<Configuration>): Layer.Layer<Resource.Resource>;
|
|
23
25
|
<R, E>(evaluate: Effect.Effect<Configuration, E, R>): Layer.Layer<Resource.Resource, E, R>;
|
|
24
|
-
} = (
|
|
26
|
+
} = (
|
|
27
|
+
evaluate: Function.LazyArg<Configuration> | Effect.Effect<Configuration, any, any>,
|
|
28
|
+
): Layer.Layer<Resource.Resource> =>
|
|
25
29
|
Layer.unwrapEffect(
|
|
26
30
|
Effect.map(
|
|
27
31
|
Effect.isEffect(evaluate) ? (evaluate as Effect.Effect<Configuration>) : Effect.sync(evaluate),
|
package/src/resource.test.ts
CHANGED
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { it } from '@effect/vitest';
|
|
6
|
-
import
|
|
6
|
+
import * as Effect from 'effect/Effect';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { acquireReleaseResource } from './resource';
|
|
9
9
|
|
|
10
10
|
it.effect(
|
|
11
11
|
'acquire-release',
|
|
12
12
|
Effect.fn(function* ({ expect }) {
|
|
13
13
|
const events: string[] = [];
|
|
14
|
-
const makeResource =
|
|
14
|
+
const makeResource = acquireReleaseResource(() => ({
|
|
15
15
|
open: () => {
|
|
16
16
|
events.push('open');
|
|
17
17
|
},
|
package/src/resource.ts
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
6
6
|
|
|
7
7
|
import type { Lifecycle } from '@dxos/context';
|
|
8
8
|
|
|
9
9
|
// TODO(dmaretskyi): Extract to effect-utils.
|
|
10
|
-
export const
|
|
10
|
+
export const acquireReleaseResource = <T extends Lifecycle>(getResource: () => T) =>
|
|
11
11
|
Effect.acquireRelease(
|
|
12
12
|
Effect.gen(function* () {
|
|
13
13
|
const resource = getResource();
|
package/src/sanity.test.ts
CHANGED
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
6
|
+
import * as Function from 'effect/Function';
|
|
6
7
|
import { describe, test } from 'vitest';
|
|
7
8
|
|
|
8
9
|
import { log } from '@dxos/log';
|
|
9
10
|
|
|
10
11
|
describe('sanity tests', () => {
|
|
11
12
|
test('function pipeline', async ({ expect }) => {
|
|
12
|
-
const result = pipe(
|
|
13
|
+
const result = Function.pipe(
|
|
13
14
|
10,
|
|
14
15
|
(value) => value + 3,
|
|
15
16
|
(value) => value * 2,
|
|
@@ -19,7 +20,7 @@ describe('sanity tests', () => {
|
|
|
19
20
|
|
|
20
21
|
test('effect pipeline (mixing types)', async ({ expect }) => {
|
|
21
22
|
const result = await Effect.runPromise(
|
|
22
|
-
pipe(
|
|
23
|
+
Function.pipe(
|
|
23
24
|
Effect.promise(() => Promise.resolve(100)),
|
|
24
25
|
Effect.tap((value) => log('tap', { value })),
|
|
25
26
|
Effect.map((value: number) => String(value)),
|
|
@@ -33,7 +34,7 @@ describe('sanity tests', () => {
|
|
|
33
34
|
|
|
34
35
|
test('effect pipeline (mixing sync/async)', async ({ expect }) => {
|
|
35
36
|
const result = await Effect.runPromise(
|
|
36
|
-
pipe(
|
|
37
|
+
Function.pipe(
|
|
37
38
|
Effect.succeed(100),
|
|
38
39
|
Effect.tap((value) => log('tap', { value })),
|
|
39
40
|
Effect.flatMap((value) => Effect.promise(() => Promise.resolve(String(value)))),
|
|
@@ -47,7 +48,7 @@ describe('sanity tests', () => {
|
|
|
47
48
|
|
|
48
49
|
test('error handling', async ({ expect }) => {
|
|
49
50
|
Effect.runPromise(
|
|
50
|
-
pipe(
|
|
51
|
+
Function.pipe(
|
|
51
52
|
Effect.succeed(10),
|
|
52
53
|
Effect.map((value) => value * 2),
|
|
53
54
|
Effect.flatMap((value) =>
|
package/src/testing.ts
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import * as Context from 'effect/Context';
|
|
6
|
+
import * as Effect from 'effect/Effect';
|
|
6
7
|
import type { TestContext } from 'vitest';
|
|
7
8
|
|
|
8
9
|
// TODO(dmaretskyi): Add all different test tags here.
|
package/src/url.test.ts
CHANGED
package/src/url.ts
CHANGED
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import * as Function from 'effect/Function';
|
|
6
|
+
import * as Option from 'effect/Option';
|
|
7
|
+
import type * as Schema from 'effect/Schema';
|
|
8
|
+
import * as SchemaAST from 'effect/SchemaAST';
|
|
6
9
|
|
|
7
10
|
import { decamelize } from '@dxos/util';
|
|
8
11
|
|
|
@@ -59,7 +62,7 @@ export class UrlParser<T extends Record<string, any>> {
|
|
|
59
62
|
if (value !== undefined) {
|
|
60
63
|
const field = this._schema.fields[key];
|
|
61
64
|
if (field) {
|
|
62
|
-
const { key: serializedKey } = pipe(
|
|
65
|
+
const { key: serializedKey } = Function.pipe(
|
|
63
66
|
getParamKeyAnnotation(field.ast),
|
|
64
67
|
Option.getOrElse(() => ({
|
|
65
68
|
key: decamelize(key),
|