@dxos/effect 0.8.4-main.b97322e → 0.8.4-main.c4373fc

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 (47) hide show
  1. package/dist/lib/browser/index.mjs +113 -51
  2. package/dist/lib/browser/index.mjs.map +3 -3
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/node-esm/index.mjs +113 -51
  5. package/dist/lib/node-esm/index.mjs.map +3 -3
  6. package/dist/lib/node-esm/meta.json +1 -1
  7. package/dist/types/src/ast.d.ts +2 -1
  8. package/dist/types/src/ast.d.ts.map +1 -1
  9. package/dist/types/src/context.d.ts +2 -1
  10. package/dist/types/src/context.d.ts.map +1 -1
  11. package/dist/types/src/errors.d.ts +31 -1
  12. package/dist/types/src/errors.d.ts.map +1 -1
  13. package/dist/types/src/interrupt.test.d.ts +2 -0
  14. package/dist/types/src/interrupt.test.d.ts.map +1 -0
  15. package/dist/types/src/jsonPath.d.ts +1 -1
  16. package/dist/types/src/jsonPath.d.ts.map +1 -1
  17. package/dist/types/src/layers.test.d.ts +2 -0
  18. package/dist/types/src/layers.test.d.ts.map +1 -0
  19. package/dist/types/src/otel.d.ts +17 -0
  20. package/dist/types/src/otel.d.ts.map +1 -0
  21. package/dist/types/src/otel.test.d.ts +2 -0
  22. package/dist/types/src/otel.test.d.ts.map +1 -0
  23. package/dist/types/src/resource.d.ts +1 -1
  24. package/dist/types/src/resource.d.ts.map +1 -1
  25. package/dist/types/src/testing.d.ts +33 -1
  26. package/dist/types/src/testing.d.ts.map +1 -1
  27. package/dist/types/src/url.d.ts +3 -1
  28. package/dist/types/src/url.d.ts.map +1 -1
  29. package/dist/types/tsconfig.tsbuildinfo +1 -1
  30. package/package.json +16 -7
  31. package/src/ast.test.ts +4 -3
  32. package/src/ast.ts +28 -16
  33. package/src/context.ts +2 -1
  34. package/src/errors.test.ts +1 -1
  35. package/src/errors.ts +73 -20
  36. package/src/interrupt.test.ts +33 -0
  37. package/src/jsonPath.test.ts +1 -1
  38. package/src/jsonPath.ts +2 -1
  39. package/src/layers.test.ts +110 -0
  40. package/src/otel.test.ts +125 -0
  41. package/src/otel.ts +45 -0
  42. package/src/resource.test.ts +3 -2
  43. package/src/resource.ts +1 -1
  44. package/src/sanity.test.ts +6 -5
  45. package/src/testing.ts +53 -1
  46. package/src/url.test.ts +1 -1
  47. package/src/url.ts +5 -2
package/src/resource.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { Effect } from 'effect';
5
+ import * as Effect from 'effect/Effect';
6
6
 
7
7
  import type { Lifecycle } from '@dxos/context';
8
8
 
@@ -2,14 +2,15 @@
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
 
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,9 +2,16 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { 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
 
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
+
8
15
  export namespace TestHelpers {
9
16
  /**
10
17
  * Skip the test if the condition is false.
@@ -55,4 +62,49 @@ export namespace TestHelpers {
55
62
  return yield* effect;
56
63
  }
57
64
  });
65
+
66
+ /**
67
+ * Skips this test if the tag is not in the list of tags to run.
68
+ * Tags are specified in the `DX_TEST_TAGS` environment variable.
69
+ *
70
+ * @param tag
71
+ * @returns
72
+ */
73
+ export const taggedTest =
74
+ (tag: TestTag) =>
75
+ <A, E, R>(effect: Effect.Effect<A, E, R>, ctx: TestContext): Effect.Effect<A, E, R> =>
76
+ Effect.gen(function* () {
77
+ if (!process.env.DX_TEST_TAGS?.includes(tag)) {
78
+ ctx.skip();
79
+ } else {
80
+ return yield* effect;
81
+ }
82
+ });
83
+
84
+ /**
85
+ * Provide TestContext from test parameters.
86
+ *
87
+ * Exmaple:
88
+ * ```ts
89
+ * it.effect(
90
+ * 'with context',
91
+ * Effect.fn(function* ({ expect }) {
92
+ * const ctx = yield* TestContextService;
93
+ * }),
94
+ * TestHelpers.provideTestContext,
95
+ * );
96
+ * ```
97
+ */
98
+ export const provideTestContext = <A, E, R>(
99
+ effect: Effect.Effect<A, E, R>,
100
+ ctx: TestContext,
101
+ ): Effect.Effect<A, E, Exclude<R, TestContextService>> => Effect.provideService(effect, TestContextService, ctx);
58
102
  }
103
+
104
+ /**
105
+ * Exposes vitest test context as an effect service.
106
+ */
107
+ export class TestContextService extends Context.Tag('@dxos/effect/TestContextService')<
108
+ TestContextService,
109
+ TestContext
110
+ >() {}
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';
package/src/url.ts CHANGED
@@ -2,7 +2,10 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import { SchemaAST, type Schema, Option, pipe } from 'effect';
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),