@dxos/effect 0.8.4-main.b97322e → 0.8.4-main.f5c0578
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 +11 -3
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +11 -3
- 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 +1 -1
- package/dist/types/src/ast.d.ts.map +1 -1
- package/dist/types/src/jsonPath.d.ts.map +1 -1
- package/dist/types/src/layers.test.d.ts +2 -0
- package/dist/types/src/layers.test.d.ts.map +1 -0
- package/dist/types/src/testing.d.ts +9 -0
- package/dist/types/src/testing.d.ts.map +1 -1
- package/dist/types/src/url.d.ts +1 -1
- package/dist/types/src/url.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -7
- package/src/ast.test.ts +3 -3
- package/src/ast.ts +1 -1
- package/src/jsonPath.test.ts +1 -1
- package/src/jsonPath.ts +1 -1
- package/src/layers.test.ts +106 -0
- package/src/resource.test.ts +2 -1
- package/src/testing.ts +21 -0
- package/src/url.ts +1 -1
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.f5c0578",
|
|
4
4
|
"description": "Effect utils.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"type": "module",
|
|
10
10
|
"exports": {
|
|
11
11
|
".": {
|
|
12
|
+
"source": "./src/index.ts",
|
|
12
13
|
"types": "./dist/types/src/index.d.ts",
|
|
13
14
|
"browser": "./dist/lib/browser/index.mjs",
|
|
14
15
|
"node": "./dist/lib/node-esm/index.mjs"
|
|
@@ -24,14 +25,14 @@
|
|
|
24
25
|
],
|
|
25
26
|
"dependencies": {
|
|
26
27
|
"jsonpath-plus": "10.2.0",
|
|
27
|
-
"@dxos/context": "0.8.4-main.
|
|
28
|
-
"@dxos/
|
|
29
|
-
"@dxos/
|
|
30
|
-
"@dxos/
|
|
28
|
+
"@dxos/context": "0.8.4-main.f5c0578",
|
|
29
|
+
"@dxos/invariant": "0.8.4-main.f5c0578",
|
|
30
|
+
"@dxos/node-std": "0.8.4-main.f5c0578",
|
|
31
|
+
"@dxos/util": "0.8.4-main.f5c0578"
|
|
31
32
|
},
|
|
32
33
|
"devDependencies": {
|
|
33
|
-
"effect": "3.17.
|
|
34
|
-
"@dxos/log": "0.8.4-main.
|
|
34
|
+
"effect": "3.17.7",
|
|
35
|
+
"@dxos/log": "0.8.4-main.f5c0578"
|
|
35
36
|
},
|
|
36
37
|
"peerDependencies": {
|
|
37
38
|
"effect": "^3.13.3"
|
package/src/ast.test.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { Schema, SchemaAST } from 'effect';
|
|
6
6
|
import { describe, test } from 'vitest';
|
|
7
7
|
|
|
8
8
|
import { invariant } from '@dxos/invariant';
|
|
@@ -12,13 +12,13 @@ import {
|
|
|
12
12
|
findNode,
|
|
13
13
|
findProperty,
|
|
14
14
|
getAnnotation,
|
|
15
|
-
getDiscriminatingProps,
|
|
16
15
|
getDiscriminatedType,
|
|
16
|
+
getDiscriminatingProps,
|
|
17
17
|
getSimpleType,
|
|
18
|
+
isArrayType,
|
|
18
19
|
isOption,
|
|
19
20
|
isSimpleType,
|
|
20
21
|
visit,
|
|
21
|
-
isArrayType,
|
|
22
22
|
} from './ast';
|
|
23
23
|
import { type JsonPath, type JsonProp } from './jsonPath';
|
|
24
24
|
|
package/src/ast.ts
CHANGED
package/src/jsonPath.test.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { describe, expect, test } from 'vitest';
|
|
6
6
|
|
|
7
|
-
import { createJsonPath, getField, isJsonPath,
|
|
7
|
+
import { type JsonPath, createJsonPath, getField, isJsonPath, splitJsonPath } from './jsonPath';
|
|
8
8
|
|
|
9
9
|
describe('createJsonPath', () => {
|
|
10
10
|
test('supported path subset', () => {
|
package/src/jsonPath.ts
CHANGED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { it } from '@effect/vitest';
|
|
6
|
+
import { Context, Duration, Effect, Layer, ManagedRuntime } from 'effect';
|
|
7
|
+
import { test } from 'vitest';
|
|
8
|
+
|
|
9
|
+
class ClientConfig extends Context.Tag('ClientConfig')<ClientConfig, { endpoint: string }>() {}
|
|
10
|
+
|
|
11
|
+
class Client extends Context.Tag('Client')<Client, { call: () => Effect.Effect<void> }>() {
|
|
12
|
+
static layer = Layer.effect(
|
|
13
|
+
Client,
|
|
14
|
+
Effect.gen(function* () {
|
|
15
|
+
const config = yield* ClientConfig;
|
|
16
|
+
return {
|
|
17
|
+
call: () => {
|
|
18
|
+
console.log('called', config.endpoint);
|
|
19
|
+
return Effect.void;
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
}),
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const ServerLive = Layer.scoped(
|
|
27
|
+
ClientConfig,
|
|
28
|
+
Effect.gen(function* () {
|
|
29
|
+
console.log('start server');
|
|
30
|
+
|
|
31
|
+
yield* Effect.sleep(Duration.millis(100));
|
|
32
|
+
|
|
33
|
+
yield* Effect.addFinalizer(
|
|
34
|
+
Effect.fn(function* () {
|
|
35
|
+
yield* Effect.sleep(Duration.millis(100));
|
|
36
|
+
console.log('stop server');
|
|
37
|
+
}),
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
endpoint: 'http://localhost:8080',
|
|
42
|
+
};
|
|
43
|
+
}),
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
it.effect.skip(
|
|
47
|
+
'test',
|
|
48
|
+
Effect.fn(
|
|
49
|
+
function* ({ expect: _ }) {
|
|
50
|
+
const client = yield* Client;
|
|
51
|
+
yield* client.call();
|
|
52
|
+
},
|
|
53
|
+
Effect.provide(Layer.provide(Client.layer, ServerLive)),
|
|
54
|
+
),
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
class ServerPlugin {
|
|
58
|
+
#runtime = ManagedRuntime.make(ServerLive);
|
|
59
|
+
|
|
60
|
+
readonly clientConfigLayer = Layer.effectContext(
|
|
61
|
+
this.#runtime.runtimeEffect.pipe(Effect.map((rt) => rt.context.pipe(Context.pick(ClientConfig)))),
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
async dispose() {
|
|
65
|
+
await this.#runtime.dispose();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
class ClientPlugin {
|
|
70
|
+
constructor(private readonly _serverPlugin: ServerPlugin) {}
|
|
71
|
+
|
|
72
|
+
async run() {
|
|
73
|
+
const layer = Layer.provide(Client.layer, this._serverPlugin.clientConfigLayer);
|
|
74
|
+
|
|
75
|
+
await Effect.runPromise(
|
|
76
|
+
Effect.gen(function* () {
|
|
77
|
+
const client = yield* Client;
|
|
78
|
+
yield* client.call();
|
|
79
|
+
}).pipe(Effect.provide(layer)),
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
test.skip('plugins', async () => {
|
|
85
|
+
const serverPlugin = new ServerPlugin();
|
|
86
|
+
console.log('ServerPlugin created');
|
|
87
|
+
|
|
88
|
+
await Effect.runPromise(Effect.sleep(Duration.millis(500)));
|
|
89
|
+
console.log('wake up');
|
|
90
|
+
|
|
91
|
+
{
|
|
92
|
+
const clientPlugin1 = new ClientPlugin(serverPlugin);
|
|
93
|
+
console.log('ClientPlugin1 created');
|
|
94
|
+
await clientPlugin1.run();
|
|
95
|
+
console.log('client1 run');
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
{
|
|
99
|
+
const clientPlugin2 = new ClientPlugin(serverPlugin);
|
|
100
|
+
console.log('ClientPlugin2 created');
|
|
101
|
+
await clientPlugin2.run();
|
|
102
|
+
console.log('client2 run');
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
await serverPlugin.dispose();
|
|
106
|
+
});
|
package/src/resource.test.ts
CHANGED
|
@@ -11,7 +11,6 @@ it.effect(
|
|
|
11
11
|
'acquire-release',
|
|
12
12
|
Effect.fn(function* ({ expect }) {
|
|
13
13
|
const events: string[] = [];
|
|
14
|
-
|
|
15
14
|
const makeResource = accuireReleaseResource(() => ({
|
|
16
15
|
open: () => {
|
|
17
16
|
events.push('open');
|
|
@@ -20,11 +19,13 @@ it.effect(
|
|
|
20
19
|
events.push('close');
|
|
21
20
|
},
|
|
22
21
|
}));
|
|
22
|
+
|
|
23
23
|
yield* Effect.gen(function* () {
|
|
24
24
|
events.push('1');
|
|
25
25
|
const _resource = yield* makeResource;
|
|
26
26
|
events.push('2');
|
|
27
27
|
}).pipe(Effect.scoped);
|
|
28
|
+
|
|
28
29
|
events.push('3');
|
|
29
30
|
expect(events).to.deep.equal(['1', 'open', '2', 'close', '3']);
|
|
30
31
|
}),
|
package/src/testing.ts
CHANGED
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
import { Effect } from 'effect';
|
|
6
6
|
import type { TestContext } from 'vitest';
|
|
7
7
|
|
|
8
|
+
// TODO(dmaretskyi): Add all different test tags here.
|
|
9
|
+
export type TestTag = 'flaky' | 'llm';
|
|
10
|
+
|
|
8
11
|
export namespace TestHelpers {
|
|
9
12
|
/**
|
|
10
13
|
* Skip the test if the condition is false.
|
|
@@ -55,4 +58,22 @@ export namespace TestHelpers {
|
|
|
55
58
|
return yield* effect;
|
|
56
59
|
}
|
|
57
60
|
});
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Skips this test if the tag is not in the list of tags to run.
|
|
64
|
+
* Tags are specified in the `DX_TEST_TAGS` environment variable.
|
|
65
|
+
*
|
|
66
|
+
* @param tag
|
|
67
|
+
* @returns
|
|
68
|
+
*/
|
|
69
|
+
export const taggedTest =
|
|
70
|
+
(tag: TestTag) =>
|
|
71
|
+
<A, E, R>(effect: Effect.Effect<A, E, R>, ctx: TestContext): Effect.Effect<A, E, R> =>
|
|
72
|
+
Effect.gen(function* () {
|
|
73
|
+
if (!process.env.DX_TEST_TAGS?.includes(tag)) {
|
|
74
|
+
ctx.skip();
|
|
75
|
+
} else {
|
|
76
|
+
return yield* effect;
|
|
77
|
+
}
|
|
78
|
+
});
|
|
58
79
|
}
|