@dxos/effect 0.8.4-main.a4bbb77 → 0.8.4-main.abd8ff62ef

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.
Files changed (78) hide show
  1. package/dist/lib/browser/chunk-CGS2ULMK.mjs +11 -0
  2. package/dist/lib/browser/chunk-CGS2ULMK.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +478 -303
  4. package/dist/lib/browser/index.mjs.map +4 -4
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/testing.mjs +31 -0
  7. package/dist/lib/browser/testing.mjs.map +7 -0
  8. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
  9. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +7 -0
  10. package/dist/lib/node-esm/index.mjs +478 -303
  11. package/dist/lib/node-esm/index.mjs.map +4 -4
  12. package/dist/lib/node-esm/meta.json +1 -1
  13. package/dist/lib/node-esm/testing.mjs +31 -0
  14. package/dist/lib/node-esm/testing.mjs.map +7 -0
  15. package/dist/types/src/Performance.d.ts +25 -0
  16. package/dist/types/src/Performance.d.ts.map +1 -0
  17. package/dist/types/src/RuntimeProvider.d.ts +21 -0
  18. package/dist/types/src/RuntimeProvider.d.ts.map +1 -0
  19. package/dist/types/src/ast.d.ts +42 -22
  20. package/dist/types/src/ast.d.ts.map +1 -1
  21. package/dist/types/src/async-task-tagging.d.ts +6 -0
  22. package/dist/types/src/async-task-tagging.d.ts.map +1 -0
  23. package/dist/types/src/atom-kvs.d.ts +19 -0
  24. package/dist/types/src/atom-kvs.d.ts.map +1 -0
  25. package/dist/types/src/context.d.ts +2 -1
  26. package/dist/types/src/context.d.ts.map +1 -1
  27. package/dist/types/src/dynamic-runtime.d.ts +56 -0
  28. package/dist/types/src/dynamic-runtime.d.ts.map +1 -0
  29. package/dist/types/src/dynamic-runtime.test.d.ts +2 -0
  30. package/dist/types/src/dynamic-runtime.test.d.ts.map +1 -0
  31. package/dist/types/src/errors.d.ts +15 -1
  32. package/dist/types/src/errors.d.ts.map +1 -1
  33. package/dist/types/src/index.d.ts +8 -3
  34. package/dist/types/src/index.d.ts.map +1 -1
  35. package/dist/types/src/{jsonPath.d.ts → json-path.d.ts} +12 -4
  36. package/dist/types/src/json-path.d.ts.map +1 -0
  37. package/dist/types/src/json-path.test.d.ts +2 -0
  38. package/dist/types/src/json-path.test.d.ts.map +1 -0
  39. package/dist/types/src/otel.d.ts +5 -4
  40. package/dist/types/src/otel.d.ts.map +1 -1
  41. package/dist/types/src/resource.d.ts +6 -2
  42. package/dist/types/src/resource.d.ts.map +1 -1
  43. package/dist/types/src/testing.d.ts +5 -13
  44. package/dist/types/src/testing.d.ts.map +1 -1
  45. package/dist/types/src/types.d.ts +8 -0
  46. package/dist/types/src/types.d.ts.map +1 -0
  47. package/dist/types/src/url.d.ts +3 -1
  48. package/dist/types/src/url.d.ts.map +1 -1
  49. package/dist/types/tsconfig.tsbuildinfo +1 -1
  50. package/package.json +25 -14
  51. package/src/Performance.ts +45 -0
  52. package/src/RuntimeProvider.ts +35 -0
  53. package/src/ast.test.ts +37 -9
  54. package/src/ast.ts +136 -93
  55. package/src/async-task-tagging.ts +51 -0
  56. package/src/atom-kvs.ts +35 -0
  57. package/src/context.ts +2 -1
  58. package/src/dynamic-runtime.test.ts +465 -0
  59. package/src/dynamic-runtime.ts +195 -0
  60. package/src/errors.test.ts +1 -1
  61. package/src/errors.ts +77 -11
  62. package/src/index.ts +8 -3
  63. package/src/interrupt.test.ts +6 -2
  64. package/src/{jsonPath.test.ts → json-path.test.ts} +47 -8
  65. package/src/{jsonPath.ts → json-path.ts} +29 -4
  66. package/src/layers.test.ts +9 -3
  67. package/src/otel.test.ts +3 -1
  68. package/src/otel.ts +9 -5
  69. package/src/resource.test.ts +3 -3
  70. package/src/resource.ts +10 -5
  71. package/src/sanity.test.ts +30 -15
  72. package/src/testing.ts +5 -28
  73. package/src/types.ts +11 -0
  74. package/src/url.test.ts +1 -1
  75. package/src/url.ts +5 -2
  76. package/dist/types/src/jsonPath.d.ts.map +0 -1
  77. package/dist/types/src/jsonPath.test.d.ts +0 -2
  78. package/dist/types/src/jsonPath.test.d.ts.map +0 -1
package/src/errors.ts CHANGED
@@ -2,11 +2,16 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { Cause, Chunk, Effect, Exit, GlobalValue, Option } from 'effect';
6
- import type { AnySpan, Span } from 'effect/Tracer';
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 * as Runtime from 'effect/Runtime';
12
+ import type * as Tracer from 'effect/Tracer';
7
13
 
8
14
  const spanSymbol = Symbol.for('effect/SpanAnnotation');
9
- const originalSymbol = Symbol.for('effect/OriginalAnnotation');
10
15
  const spanToTrace = GlobalValue.globalValue('effect/Tracer/spanToTrace', () => new WeakMap());
11
16
  const locationRegex = /\((.*)\)/g;
12
17
 
@@ -16,12 +21,19 @@ const locationRegex = /\((.*)\)/g;
16
21
  * Unwraps error proxy.
17
22
  */
18
23
  const prettyErrorStack = (error: any, appendStacks: string[] = []): any => {
24
+ if (typeof error !== 'object' || error === null) {
25
+ return error;
26
+ }
27
+
19
28
  const span = error[spanSymbol];
20
29
 
21
30
  const lines = typeof error.stack === 'string' ? error.stack.split('\n') : [];
22
31
  const out = [];
23
32
 
24
- let atStack = false;
33
+ // Very hacky way to remove effect runtime internal stack frames.
34
+ let atStack = false,
35
+ inCore = false,
36
+ passedScheduler = false;
25
37
  for (let i = 0; i < lines.length; i++) {
26
38
  if (!atStack && !lines[i].startsWith(' at ')) {
27
39
  out.push(lines[i]);
@@ -39,6 +51,26 @@ const prettyErrorStack = (error: any, appendStacks: string[] = []): any => {
39
51
  if (lines[i].includes('effect_internal_function')) {
40
52
  break;
41
53
  }
54
+
55
+ const filename = lines[i].match(/\/([a-zA-Z0-9_\-.]+):\d+:\d+\)$/)?.[1];
56
+
57
+ if (!inCore && ['core-effect.ts'].includes(filename)) {
58
+ inCore = true;
59
+ }
60
+
61
+ if (inCore && !passedScheduler && ['Scheduler.ts'].includes(filename)) {
62
+ passedScheduler = true;
63
+ continue;
64
+ }
65
+
66
+ if (passedScheduler && !['Scheduler.ts'].includes(filename)) {
67
+ inCore = false;
68
+ }
69
+
70
+ if (inCore) {
71
+ continue;
72
+ }
73
+
42
74
  out.push(
43
75
  lines[i]
44
76
  .replace(/at .*effect_instruction_i.*\((.*)\)/, 'at $1')
@@ -48,7 +80,7 @@ const prettyErrorStack = (error: any, appendStacks: string[] = []): any => {
48
80
  }
49
81
 
50
82
  if (span) {
51
- let current: Span | AnySpan | undefined = span;
83
+ let current: Tracer.Span | Tracer.AnySpan | undefined = span;
52
84
  let i = 0;
53
85
  while (current && current._tag === 'Span' && i < 10) {
54
86
  const stackFn = spanToTrace.get(current);
@@ -77,9 +109,7 @@ const prettyErrorStack = (error: any, appendStacks: string[] = []): any => {
77
109
 
78
110
  out.push(...appendStacks);
79
111
 
80
- if (error[originalSymbol]) {
81
- error = error[originalSymbol];
82
- }
112
+ error = Cause.originalError(error);
83
113
  if (error.cause) {
84
114
  error.cause = prettyErrorStack(error.cause);
85
115
  }
@@ -113,9 +143,10 @@ export const causeToError = (cause: Cause.Cause<any>): Error => {
113
143
  const errors = [...Chunk.toArray(Cause.failures(cause)), ...Chunk.toArray(Cause.defects(cause))];
114
144
 
115
145
  const getStackFrames = (): string[] => {
116
- const o: { stack: string } = {} as any;
117
- Error.captureStackTrace(o, getStackFrames);
118
- return o.stack.split('\n').slice(1);
146
+ // Bun requies the target object for `captureStackTrace` to be an Error.
147
+ const o = new Error();
148
+ Error.captureStackTrace(o, causeToError);
149
+ return o.stack!.split('\n').slice(1);
119
150
  };
120
151
 
121
152
  const stackFrames = getStackFrames();
@@ -169,6 +200,41 @@ export const runAndForwardErrors = async <A, E>(
169
200
  return unwrapExit(exit);
170
201
  };
171
202
 
203
+ /**
204
+ * Runs the embedded effect asynchronously and throws any failures and defects as errors.
205
+ */
206
+ export const runInRuntime: {
207
+ <R>(
208
+ runtime: Runtime.Runtime<R>,
209
+ ): <A, E>(effect: Effect.Effect<A, E, R>, options?: { signal?: AbortSignal } | undefined) => Promise<A>;
210
+ <R, A, E>(
211
+ runtime: Runtime.Runtime<R>,
212
+ effect: Effect.Effect<A, E, R>,
213
+ options?: { signal?: AbortSignal } | undefined,
214
+ ): Promise<A>;
215
+ } = (...args: any[]): any => {
216
+ if (args.length === 1) {
217
+ const [runtime] = args as [Runtime.Runtime<any>];
218
+ return async (
219
+ effect: Effect.Effect<any, any, any>,
220
+ options?: { signal?: AbortSignal } | undefined,
221
+ ): Promise<any> => {
222
+ const exit = await Runtime.runPromiseExit(runtime, effect, options);
223
+ return unwrapExit(exit);
224
+ };
225
+ } else {
226
+ const [runtime, effect, options] = args as [
227
+ Runtime.Runtime<any>,
228
+ Effect.Effect<any, any, any>,
229
+ { signal?: AbortSignal } | undefined,
230
+ ];
231
+ return (async () => {
232
+ const exit = await Runtime.runPromiseExit(runtime, effect, options);
233
+ return unwrapExit(exit);
234
+ })();
235
+ }
236
+ };
237
+
172
238
  /**
173
239
  * Like `Effect.promise` but also caputes spans for defects.
174
240
  * Workaround for: https://github.com/Effect-TS/effect/issues/5436
package/src/index.ts CHANGED
@@ -3,9 +3,14 @@
3
3
  //
4
4
 
5
5
  export * from './ast';
6
- export * from './jsonPath';
7
- export * from './url';
6
+ export * from './atom-kvs';
8
7
  export * from './context';
8
+ export * as DynamicRuntime from './dynamic-runtime';
9
9
  export * from './errors';
10
- export * from './testing';
10
+ export * from './json-path';
11
11
  export * from './resource';
12
+ export * from './types';
13
+ export * from './url';
14
+ export * as RuntimeProvider from './RuntimeProvider';
15
+ export * as Performance from './Performance';
16
+ export * from './async-task-tagging';
@@ -3,7 +3,11 @@
3
3
  //
4
4
 
5
5
  import { it } from '@effect/vitest';
6
- import { Cause, Effect, Fiber } from 'effect';
6
+ import * as Cause from 'effect/Cause';
7
+ import * as Effect from 'effect/Effect';
8
+ import * as Fiber from 'effect/Fiber';
9
+
10
+ import { runAndForwardErrors } from './errors';
7
11
 
8
12
  const doWork = Effect.fn('doWork')(function* () {
9
13
  yield* Effect.sleep('1 minute');
@@ -16,7 +20,7 @@ it.effect.skip(
16
20
  function* (_) {
17
21
  const resultFiber = yield* doWork().pipe(Effect.fork);
18
22
  setTimeout(() => {
19
- void Effect.runPromise(Fiber.interrupt(resultFiber));
23
+ void runAndForwardErrors(Fiber.interrupt(resultFiber));
20
24
  }, 2_000);
21
25
 
22
26
  const result = yield* resultFiber;
@@ -4,7 +4,7 @@
4
4
 
5
5
  import { describe, expect, test } from 'vitest';
6
6
 
7
- import { type JsonPath, createJsonPath, getField, isJsonPath, splitJsonPath } from './jsonPath';
7
+ import { type JsonPath, createJsonPath, getField, getValue, isJsonPath, setValue, splitJsonPath } from './json-path';
8
8
 
9
9
  describe('createJsonPath', () => {
10
10
  test('supported path subset', () => {
@@ -32,9 +32,9 @@ describe('createJsonPath', () => {
32
32
 
33
33
  test('path splitting', () => {
34
34
  const cases = [
35
- ['foo.bar[0].baz', ['foo', 'bar', '0', 'baz']],
36
- ['users[1].name', ['users', '1', 'name']],
37
- ['data[0][1]', ['data', '0', '1']],
35
+ ['foo.bar[0].baz', ['foo', 'bar', 0, 'baz']],
36
+ ['users[1].name', ['users', 1, 'name']],
37
+ ['data[0][1]', ['data', 0, 1]],
38
38
  ['simple.path', ['simple', 'path']],
39
39
  ['root', ['root']],
40
40
  ] as const;
@@ -47,15 +47,15 @@ describe('createJsonPath', () => {
47
47
  test('path splitting - extended cases', () => {
48
48
  const cases = [
49
49
  // Multiple consecutive array indices.
50
- ['matrix[0][1][2]', ['matrix', '0', '1', '2']],
50
+ ['matrix[0][1][2]', ['matrix', 0, 1, 2]],
51
51
  // Properties with underscores and $.
52
52
  ['$_foo.bar_baz', ['$_foo', 'bar_baz']],
53
53
  // Deep nesting.
54
- ['very.deep.nested[0].property.path[5]', ['very', 'deep', 'nested', '0', 'property', 'path', '5']],
54
+ ['very.deep.nested[0].property.path[5]', ['very', 'deep', 'nested', 0, 'property', 'path', 5]],
55
55
  // Single character properties.
56
- ['a[0].b.c', ['a', '0', 'b', 'c']],
56
+ ['a[0].b.c', ['a', 0, 'b', 'c']],
57
57
  // Properties containing numbers.
58
- ['prop123.item456[7]', ['prop123', 'item456', '7']],
58
+ ['prop123.item456[7]', ['prop123', 'item456', 7]],
59
59
  ] as const;
60
60
 
61
61
  cases.forEach(([input, expected]) => {
@@ -99,3 +99,42 @@ describe('createJsonPath', () => {
99
99
  expect(getField({ a: 'foo' }, 'a' as JsonPath)).toBe('foo');
100
100
  });
101
101
  });
102
+
103
+ describe('Types', () => {
104
+ test('checks sanity', async ({ expect }) => {
105
+ const obj = {};
106
+ expect(obj).to.exist;
107
+ });
108
+ });
109
+
110
+ describe('get/set deep', () => {
111
+ test('get/set operations', ({ expect }) => {
112
+ const obj = {
113
+ name: 'test',
114
+ items: ['a', 'b', 'c'],
115
+ nested: {
116
+ prop: 'value',
117
+ arr: [1, 2, 3],
118
+ },
119
+ };
120
+
121
+ // Basic property access.
122
+ expect(getValue(obj, 'name' as JsonPath)).toBe('test');
123
+
124
+ // Array index access.
125
+ expect(getValue(obj, 'items[1]' as JsonPath)).toBe('b');
126
+
127
+ // Nested property access.
128
+ expect(getValue(obj, 'nested.prop' as JsonPath)).toBe('value');
129
+
130
+ // Nested array access.
131
+ expect(getValue(obj, 'nested.arr[2]' as JsonPath)).toBe(3);
132
+
133
+ // Setting values.
134
+ const updated1 = setValue(obj, 'items[1]' as JsonPath, 'x');
135
+ expect(updated1.items[1]).toBe('x');
136
+
137
+ const updated2 = setValue(obj, 'nested.arr[0]' as JsonPath, 99);
138
+ expect(updated2.nested.arr[0]).toBe(99);
139
+ });
140
+ });
@@ -2,20 +2,26 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { Option, Schema } from 'effect';
5
+ import * as Option from 'effect/Option';
6
+ import * as Schema from 'effect/Schema';
6
7
  import { JSONPath } from 'jsonpath-plus';
7
8
 
8
9
  import { invariant } from '@dxos/invariant';
10
+ import { getDeep, setDeep } from '@dxos/util';
9
11
 
10
12
  export type JsonProp = string & { __JsonPath: true; __JsonProp: true };
11
13
  export type JsonPath = string & { __JsonPath: true };
12
14
 
15
+ // TODO(burdon): Start with "$."?
16
+
13
17
  const PATH_REGEX = /^($|[a-zA-Z_$][\w$]*(?:\.[a-zA-Z_$][\w$]*|\[\d+\](?:\.)?)*$)/;
18
+
14
19
  const PROP_REGEX = /^\w+$/;
15
20
 
16
21
  /**
17
22
  * https://www.ietf.org/archive/id/draft-goessner-dispatch-jsonpath-00.html
18
23
  */
24
+ // TODO(burdon): Keys could be arbitrary strings.
19
25
  export const JsonPath = Schema.String.pipe(Schema.pattern(PATH_REGEX)).annotations({
20
26
  title: 'JSON path',
21
27
  description: 'JSON path to a property',
@@ -49,7 +55,7 @@ export const isJsonPath = (value: unknown): value is JsonPath => {
49
55
  * @param path Array of string or number segments
50
56
  * @returns Valid JsonPath or undefined if invalid
51
57
  */
52
- export const createJsonPath = (path: (string | number)[]): JsonPath => {
58
+ export const createJsonPath = (path: readonly (string | number)[]): JsonPath => {
53
59
  const candidatePath = path
54
60
  .map((p, i) => {
55
61
  if (typeof p === 'number') {
@@ -79,7 +85,7 @@ export const fromEffectValidationPath = (effectPath: string): JsonPath => {
79
85
  * Splits a JsonPath into its constituent parts.
80
86
  * Handles property access and array indexing.
81
87
  */
82
- export const splitJsonPath = (path: JsonPath): string[] => {
88
+ export const splitJsonPath = (path: JsonPath): (string | number)[] => {
83
89
  if (!isJsonPath(path)) {
84
90
  return [];
85
91
  }
@@ -87,14 +93,33 @@ export const splitJsonPath = (path: JsonPath): string[] => {
87
93
  return (
88
94
  path
89
95
  .match(/[a-zA-Z_$][\w$]*|\[\d+\]/g)
90
- ?.map((part) => (part.startsWith('[') ? part.replace(/[[\]]/g, '') : part)) ?? []
96
+ ?.map((part) => part.replace(/[[\]]/g, ''))
97
+ .map((part) => {
98
+ const parsed = Number.parseInt(part, 10);
99
+ return Number.isNaN(parsed) ? part : parsed;
100
+ }) ?? []
91
101
  );
92
102
  };
93
103
 
94
104
  /**
95
105
  * Applies a JsonPath to an object.
96
106
  */
107
+ // TODO(burdon): Reconcile with getValue.
97
108
  export const getField = (object: any, path: JsonPath): any => {
98
109
  // By default, JSONPath returns an array of results.
99
110
  return JSONPath({ path, json: object })[0];
100
111
  };
112
+
113
+ /**
114
+ * Get value from object using JsonPath.
115
+ */
116
+ export const getValue = <T extends object>(obj: T, path: JsonPath): any => {
117
+ return getDeep(obj, splitJsonPath(path));
118
+ };
119
+
120
+ /**
121
+ * Set value on object using JsonPath.
122
+ */
123
+ export const setValue = <T extends object>(obj: T, path: JsonPath, value: any): T => {
124
+ return setDeep(obj, splitJsonPath(path), value);
125
+ };
@@ -3,9 +3,15 @@
3
3
  //
4
4
 
5
5
  import { it } from '@effect/vitest';
6
- import { Context, Duration, Effect, Layer, ManagedRuntime } from 'effect';
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
 
13
+ import { runAndForwardErrors } from './errors';
14
+
9
15
  class ClientConfig extends Context.Tag('ClientConfig')<ClientConfig, { endpoint: string }>() {}
10
16
 
11
17
  class Client extends Context.Tag('Client')<Client, { call: () => Effect.Effect<void> }>() {
@@ -72,7 +78,7 @@ class ClientPlugin {
72
78
  async run() {
73
79
  const layer = Layer.provide(Client.layer, this._serverPlugin.clientConfigLayer);
74
80
 
75
- await Effect.runPromise(
81
+ await runAndForwardErrors(
76
82
  Effect.gen(function* () {
77
83
  const client = yield* Client;
78
84
  yield* client.call();
@@ -85,7 +91,7 @@ test.skip('plugins', async () => {
85
91
  const serverPlugin = new ServerPlugin();
86
92
  console.log('ServerPlugin created');
87
93
 
88
- await Effect.runPromise(Effect.sleep(Duration.millis(500)));
94
+ await runAndForwardErrors(Effect.sleep(Duration.millis(500)));
89
95
  console.log('wake up');
90
96
 
91
97
  {
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 { Duration, Effect } from 'effect';
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';
@@ -75,6 +76,7 @@ const makeOtelLogProcessor = (logger: Logger): LogProcessor => {
75
76
  });
76
77
  };
77
78
  };
79
+
78
80
  log.addProcessor(makeOtelLogProcessor(logger));
79
81
 
80
82
  beforeAll(() => {
package/src/otel.ts CHANGED
@@ -2,10 +2,12 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { Resource, Tracer } from '@effect/opentelemetry';
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 { Effect, Layer } from 'effect';
8
- import { type LazyArg } from 'effect/Function';
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
- } = (evaluate: LazyArg<Configuration> | Effect.Effect<Configuration, any, any>): Layer.Layer<Resource.Resource> =>
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),
@@ -3,15 +3,15 @@
3
3
  //
4
4
 
5
5
  import { it } from '@effect/vitest';
6
- import { Effect } from 'effect';
6
+ import * as Effect from 'effect/Effect';
7
7
 
8
- import { accuireReleaseResource } from './resource';
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 = accuireReleaseResource(() => ({
14
+ const makeResource = acquireReleaseResource(() => ({
15
15
  open: () => {
16
16
  events.push('open');
17
17
  },
package/src/resource.ts CHANGED
@@ -2,24 +2,29 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { Effect } from 'effect';
5
+ import * as Effect from 'effect/Effect';
6
+ import type * as Scope from 'effect/Scope';
6
7
 
7
8
  import type { Lifecycle } from '@dxos/context';
8
9
 
9
- // TODO(dmaretskyi): Extract to effect-utils.
10
- export const accuireReleaseResource = <T extends Lifecycle>(getResource: () => T) =>
10
+ /**
11
+ * Acquires a resource and releases it when the scope is closed.
12
+ */
13
+ export const acquireReleaseResource = <T extends Lifecycle>(
14
+ getResource: () => T,
15
+ ): Effect.Effect<T, never, Scope.Scope> =>
11
16
  Effect.acquireRelease(
12
17
  Effect.gen(function* () {
13
18
  const resource = getResource();
14
19
  yield* Effect.promise(async () => {
15
- resource.open?.();
20
+ await resource.open?.();
16
21
  return undefined;
17
22
  });
18
23
  return resource;
19
24
  }),
20
25
  (resource) =>
21
26
  Effect.promise(async () => {
22
- resource.close?.();
27
+ await resource.close?.();
23
28
  return undefined;
24
29
  }),
25
30
  );
@@ -2,14 +2,17 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import { Effect, pipe } from 'effect';
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
 
11
+ import { runAndForwardErrors } from './errors';
12
+
10
13
  describe('sanity tests', () => {
11
14
  test('function pipeline', async ({ expect }) => {
12
- const result = pipe(
15
+ const result = Function.pipe(
13
16
  10,
14
17
  (value) => value + 3,
15
18
  (value) => value * 2,
@@ -18,36 +21,48 @@ describe('sanity tests', () => {
18
21
  });
19
22
 
20
23
  test('effect pipeline (mixing types)', async ({ expect }) => {
21
- const result = await Effect.runPromise(
22
- pipe(
24
+ const result = await runAndForwardErrors(
25
+ Function.pipe(
23
26
  Effect.promise(() => Promise.resolve(100)),
24
- Effect.tap((value) => log('tap', { value })),
27
+ Effect.tap((value) => {
28
+ log('tap', { value });
29
+ }),
25
30
  Effect.map((value: number) => String(value)),
26
- Effect.tap((value) => log('tap', { value })),
31
+ Effect.tap((value) => {
32
+ log('tap', { value });
33
+ }),
27
34
  Effect.map((value: string) => value.length),
28
- Effect.tap((value) => log('tap', { value })),
35
+ Effect.tap((value) => {
36
+ log('tap', { value });
37
+ }),
29
38
  ),
30
39
  );
31
40
  expect(result).to.eq(3);
32
41
  });
33
42
 
34
43
  test('effect pipeline (mixing sync/async)', async ({ expect }) => {
35
- const result = await Effect.runPromise(
36
- pipe(
44
+ const result = await runAndForwardErrors(
45
+ Function.pipe(
37
46
  Effect.succeed(100),
38
- Effect.tap((value) => log('tap', { value })),
47
+ Effect.tap((value) => {
48
+ log('tap', { value });
49
+ }),
39
50
  Effect.flatMap((value) => Effect.promise(() => Promise.resolve(String(value)))),
40
- Effect.tap((value) => log('tap', { value })),
51
+ Effect.tap((value) => {
52
+ log('tap', { value });
53
+ }),
41
54
  Effect.map((value) => value.length),
42
- Effect.tap((value) => log('tap', { value })),
55
+ Effect.tap((value) => {
56
+ log('tap', { value });
57
+ }),
43
58
  ),
44
59
  );
45
60
  expect(result).to.eq(3);
46
61
  });
47
62
 
48
63
  test('error handling', async ({ expect }) => {
49
- Effect.runPromise(
50
- pipe(
64
+ runAndForwardErrors(
65
+ Function.pipe(
51
66
  Effect.succeed(10),
52
67
  Effect.map((value) => value * 2),
53
68
  Effect.flatMap((value) =>
@@ -62,7 +77,7 @@ describe('sanity tests', () => {
62
77
  ),
63
78
  )
64
79
  .then(() => expect.fail())
65
- .catch((error) => {
80
+ .catch((error: any) => {
66
81
  expect(error).to.be.instanceOf(Error);
67
82
  });
68
83
  });
package/src/testing.ts CHANGED
@@ -2,20 +2,15 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { Context, Effect } from 'effect';
5
+ import * as Context from 'effect/Context';
6
+ import * as Effect from 'effect/Effect';
6
7
  import type { TestContext } from 'vitest';
7
8
 
8
- // TODO(dmaretskyi): Add all different test tags here.
9
- export type TestTag =
10
- | 'flaky' // Flaky tests.
11
- | 'llm' // Tests with AI.
12
- | 'sync'; // Sync with external services.
13
-
14
9
  export namespace TestHelpers {
15
10
  /**
16
11
  * Skip the test if the condition is false.
17
12
  *
18
- * Exmaple:
13
+ * Example:
19
14
  * ```ts
20
15
  * it.effect(
21
16
  * 'should process an agentic loop using Claude',
@@ -40,7 +35,7 @@ export namespace TestHelpers {
40
35
  /**
41
36
  * Skip the test if the condition is true.
42
37
  *
43
- * Exmaple:
38
+ * Example:
44
39
  * ```ts
45
40
  * it.effect(
46
41
  * 'should process an agentic loop using Claude',
@@ -62,28 +57,10 @@ export namespace TestHelpers {
62
57
  }
63
58
  });
64
59
 
65
- /**
66
- * Skips this test if the tag is not in the list of tags to run.
67
- * Tags are specified in the `DX_TEST_TAGS` environment variable.
68
- *
69
- * @param tag
70
- * @returns
71
- */
72
- export const taggedTest =
73
- (tag: TestTag) =>
74
- <A, E, R>(effect: Effect.Effect<A, E, R>, ctx: TestContext): Effect.Effect<A, E, R> =>
75
- Effect.gen(function* () {
76
- if (!process.env.DX_TEST_TAGS?.includes(tag)) {
77
- ctx.skip();
78
- } else {
79
- return yield* effect;
80
- }
81
- });
82
-
83
60
  /**
84
61
  * Provide TestContext from test parameters.
85
62
  *
86
- * Exmaple:
63
+ * Example:
87
64
  * ```ts
88
65
  * it.effect(
89
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;
package/src/url.test.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import { Schema } from 'effect';
5
+ import * as Schema from 'effect/Schema';
6
6
  import { describe, expect, test } from 'vitest';
7
7
 
8
8
  import { ParamKeyAnnotation, UrlParser } from './url';