pure-effect 0.8.0 → 0.9.0
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/.claude/settings.local.json +9 -5
- package/.prettierrc +2 -1
- package/CLAUDE.md +135 -21
- package/README.md +257 -173
- package/examples/opentelemetry-example.js +164 -0
- package/examples/recording-example.js +104 -0
- package/index.d.ts +139 -5
- package/index.js +707 -14
- package/package.json +12 -6
- package/test/all.js +1519 -25
- package/test/types.test-d.ts +11 -0
- package/.dirac-symbol-index/data.db +0 -0
- package/opentelemetry-example.js +0 -91
package/test/types.test-d.ts
CHANGED
|
@@ -37,6 +37,17 @@ expectType<FailureState<string>>(f);
|
|
|
37
37
|
|
|
38
38
|
// --- Command ---
|
|
39
39
|
|
|
40
|
+
// next is optional, defaulting to Success
|
|
41
|
+
expectType<CommandState<number, number>>(Command(() => 42));
|
|
42
|
+
expectType<CommandState<number, string>>(
|
|
43
|
+
Command(
|
|
44
|
+
() => 42,
|
|
45
|
+
(n: number) => Success(String(n))
|
|
46
|
+
)
|
|
47
|
+
);
|
|
48
|
+
Command(() => 42, undefined, { name: 'readRow' });
|
|
49
|
+
expectError(Command());
|
|
50
|
+
|
|
40
51
|
const cmd = Command(
|
|
41
52
|
async () => ({ id: 1, email: 'a@b.com' }) as SavedUser,
|
|
42
53
|
(saved) => {
|
|
Binary file
|
package/opentelemetry-example.js
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
|
-
import { NodeSDK } from '@opentelemetry/sdk-node';
|
|
4
|
-
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto';
|
|
5
|
-
import { SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base';
|
|
6
|
-
import { trace, SpanStatusCode } from '@opentelemetry/api';
|
|
7
|
-
import { configureEffect } from './index.js';
|
|
8
|
-
|
|
9
|
-
/** @import { RunWrapper, StepRunner } from "./index.js" */
|
|
10
|
-
|
|
11
|
-
const traceExporter = new OTLPTraceExporter({
|
|
12
|
-
url: 'http://localhost:4318/v1/traces'
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
const sdk = new NodeSDK({
|
|
16
|
-
serviceName: 'pure-effect-test',
|
|
17
|
-
traceExporter,
|
|
18
|
-
spanProcessor: new SimpleSpanProcessor(traceExporter),
|
|
19
|
-
instrumentations: []
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
sdk.start();
|
|
23
|
-
|
|
24
|
-
process.on('SIGTERM', () => {
|
|
25
|
-
sdk.shutdown()
|
|
26
|
-
.then(() => console.log('Tracing terminated'))
|
|
27
|
-
.catch((error) => console.log('Error terminating tracing', error))
|
|
28
|
-
.finally(() => process.exit(0));
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
export function enableTelemetry() {
|
|
32
|
-
const tracer = trace.getTracer('pure-effect-test');
|
|
33
|
-
configureEffect({
|
|
34
|
-
/** @type RunWrapper */
|
|
35
|
-
onRun: (effect, pipeline, flowName) => {
|
|
36
|
-
return tracer.startActiveSpan('Effect Pipeline', async (rootSpan) => {
|
|
37
|
-
try {
|
|
38
|
-
rootSpan.setAttribute('effect.initialInput', JSON.stringify(effect.initialInput));
|
|
39
|
-
rootSpan.setAttribute('effect.flow', flowName || '');
|
|
40
|
-
|
|
41
|
-
const result = await pipeline();
|
|
42
|
-
|
|
43
|
-
if (result.type === 'Failure') {
|
|
44
|
-
rootSpan.setStatus({
|
|
45
|
-
code: SpanStatusCode.ERROR,
|
|
46
|
-
message: String(result.error)
|
|
47
|
-
});
|
|
48
|
-
} else {
|
|
49
|
-
rootSpan.setStatus({ code: SpanStatusCode.OK });
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return result;
|
|
53
|
-
} catch (/** @type any */ err) {
|
|
54
|
-
rootSpan.recordException(err);
|
|
55
|
-
rootSpan.setStatus({ code: SpanStatusCode.ERROR, message: err.message });
|
|
56
|
-
throw err;
|
|
57
|
-
} finally {
|
|
58
|
-
rootSpan.end();
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
},
|
|
62
|
-
/** @type StepRunner */
|
|
63
|
-
onStep: (name, type, op) => {
|
|
64
|
-
return tracer.startActiveSpan(name, async (span) => {
|
|
65
|
-
span.setAttribute('effect.type', type);
|
|
66
|
-
try {
|
|
67
|
-
const result = await op();
|
|
68
|
-
try {
|
|
69
|
-
if (result !== undefined) {
|
|
70
|
-
const outputString = typeof result === 'object' ? JSON.stringify(result) : String(result);
|
|
71
|
-
span.setAttribute('effect.output', outputString);
|
|
72
|
-
}
|
|
73
|
-
} catch (serializationError) {
|
|
74
|
-
span.setAttribute('effect.output', '[Circular or Non-Serializable Data]');
|
|
75
|
-
}
|
|
76
|
-
span.setStatus({ code: SpanStatusCode.OK });
|
|
77
|
-
return result;
|
|
78
|
-
} catch (/** @type any */ err) {
|
|
79
|
-
span.recordException(err);
|
|
80
|
-
span.setStatus({
|
|
81
|
-
code: SpanStatusCode.ERROR,
|
|
82
|
-
message: err.message
|
|
83
|
-
});
|
|
84
|
-
throw err;
|
|
85
|
-
} finally {
|
|
86
|
-
span.end();
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
}
|