@reactionary/core 0.2.10 → 0.2.12
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.
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
import { trace } from "@opentelemetry/api";
|
|
1
|
+
import { SpanStatusCode, trace } from "@opentelemetry/api";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { getReactionaryMeter } from "../metrics/metrics.js";
|
|
4
4
|
import { error, success } from "../schemas/result.js";
|
|
5
5
|
const TRACER_NAME = "@reactionary";
|
|
6
6
|
const TRACER_VERSION = "0.0.1";
|
|
7
|
-
let globalTracer = null;
|
|
8
7
|
function getTracer() {
|
|
9
|
-
|
|
10
|
-
globalTracer = trace.getTracer(TRACER_NAME, TRACER_VERSION);
|
|
11
|
-
}
|
|
12
|
-
return globalTracer;
|
|
8
|
+
return trace.getTracer(TRACER_NAME, TRACER_VERSION);
|
|
13
9
|
}
|
|
14
10
|
class ReactionaryDecoratorOptions {
|
|
15
11
|
constructor() {
|
|
@@ -37,11 +33,11 @@ class ReactionaryDecoratorOptions {
|
|
|
37
33
|
/**
|
|
38
34
|
* The schema for the input (query or mutation) type, for validation purposes
|
|
39
35
|
*/
|
|
40
|
-
this.inputSchema = z.
|
|
36
|
+
this.inputSchema = z.unknown();
|
|
41
37
|
/**
|
|
42
38
|
* The schema for the primary output type, for validation purposes
|
|
43
39
|
*/
|
|
44
|
-
this.outputSchema = z.
|
|
40
|
+
this.outputSchema = z.unknown();
|
|
45
41
|
}
|
|
46
42
|
}
|
|
47
43
|
function Reactionary(options) {
|
|
@@ -102,9 +98,10 @@ function Reactionary(options) {
|
|
|
102
98
|
validatedResult.meta.cache.hit = !!fromCache;
|
|
103
99
|
validatedResult.meta.cache.key = cacheKey;
|
|
104
100
|
}
|
|
105
|
-
return
|
|
101
|
+
return validatedResult;
|
|
106
102
|
} catch (err) {
|
|
107
103
|
status = "error";
|
|
104
|
+
trace.getActiveSpan()?.setStatus({ code: SpanStatusCode.ERROR, message: errorToString(err) });
|
|
108
105
|
const result = error({
|
|
109
106
|
type: "Generic",
|
|
110
107
|
message: errorToString(err)
|
package/package.json
CHANGED
package/src/schemas/result.d.ts
CHANGED
|
@@ -19,7 +19,9 @@ export type Fail<E> = {
|
|
|
19
19
|
trace: string;
|
|
20
20
|
};
|
|
21
21
|
};
|
|
22
|
-
export type Result<T, E =
|
|
22
|
+
export type Result<T, E = {
|
|
23
|
+
type: string;
|
|
24
|
+
}> = Ok<T> | Fail<E>;
|
|
23
25
|
/**
|
|
24
26
|
* Utility function for asserting and unwrapping the value of a success.
|
|
25
27
|
* It is an assert, so treat it as such (similar to any unwrap, assert or similar function).
|