@dxos/effect 0.7.1 → 0.7.2-main.f1adc9f
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 +36 -14
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +37 -14
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +36 -14
- 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 +17 -11
- package/dist/types/src/ast.d.ts.map +1 -1
- package/dist/types/src/sanity.test.d.ts +2 -0
- package/dist/types/src/sanity.test.d.ts.map +1 -0
- package/package.json +6 -5
- package/src/ast.test.ts +2 -3
- package/src/ast.ts +75 -28
- package/src/sanity.test.ts +69 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Effect, pipe } from 'effect';
|
|
6
|
+
import { describe, test } from 'vitest';
|
|
7
|
+
|
|
8
|
+
import { log } from '@dxos/log';
|
|
9
|
+
|
|
10
|
+
describe('sanity tests', () => {
|
|
11
|
+
test('function pipeline', async ({ expect }) => {
|
|
12
|
+
const result = pipe(
|
|
13
|
+
10,
|
|
14
|
+
(value) => value + 3,
|
|
15
|
+
(value) => value * 2,
|
|
16
|
+
);
|
|
17
|
+
expect(result).to.eq(26);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test('effect pipeline (mixing types)', async ({ expect }) => {
|
|
21
|
+
const result = await Effect.runPromise(
|
|
22
|
+
pipe(
|
|
23
|
+
Effect.promise(() => Promise.resolve(100)),
|
|
24
|
+
Effect.tap((value) => log('tap', { value })),
|
|
25
|
+
Effect.map((value: number) => String(value)),
|
|
26
|
+
Effect.tap((value) => log('tap', { value })),
|
|
27
|
+
Effect.map((value: string) => value.length),
|
|
28
|
+
Effect.tap((value) => log('tap', { value })),
|
|
29
|
+
),
|
|
30
|
+
);
|
|
31
|
+
expect(result).to.eq(3);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('effect pipeline (mixing sync/async)', async ({ expect }) => {
|
|
35
|
+
const result = await Effect.runPromise(
|
|
36
|
+
pipe(
|
|
37
|
+
Effect.succeed(100),
|
|
38
|
+
Effect.tap((value) => log('tap', { value })),
|
|
39
|
+
Effect.flatMap((value) => Effect.promise(() => Promise.resolve(String(value)))),
|
|
40
|
+
Effect.tap((value) => log('tap', { value })),
|
|
41
|
+
Effect.map((value) => value.length),
|
|
42
|
+
Effect.tap((value) => log('tap', { value })),
|
|
43
|
+
),
|
|
44
|
+
);
|
|
45
|
+
expect(result).to.eq(3);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test('error handling', async ({ expect }) => {
|
|
49
|
+
Effect.runPromise(
|
|
50
|
+
pipe(
|
|
51
|
+
Effect.succeed(10),
|
|
52
|
+
Effect.map((value) => value * 2),
|
|
53
|
+
Effect.flatMap((value) =>
|
|
54
|
+
Effect.promise(() => {
|
|
55
|
+
if (value > 10) {
|
|
56
|
+
return Promise.reject(new Error('error message'));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return Promise.resolve(value);
|
|
60
|
+
}),
|
|
61
|
+
),
|
|
62
|
+
),
|
|
63
|
+
)
|
|
64
|
+
.then(() => expect.fail())
|
|
65
|
+
.catch((error) => {
|
|
66
|
+
expect(error).to.be.instanceOf(Error);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
});
|