@orpc/shared 2.0.0-beta.49 → 2.0.0-beta.50
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/args.d.ts +1 -1
- package/dist/args.js +4 -2
- package/dist/array.d.ts +4 -1
- package/dist/array.js +11 -5
- package/dist/bigint.d.ts +1 -1
- package/dist/bigint.js +12 -16
- package/dist/buffer.d.ts +4 -4
- package/dist/buffer.js +44 -67
- package/dist/compare.d.ts +1 -1
- package/dist/compare.js +23 -42
- package/dist/consts.d.ts +1 -1
- package/dist/consts.js +3 -1
- package/dist/error.d.ts +1 -1
- package/dist/error.js +4 -2
- package/dist/function.d.ts +1 -1
- package/dist/function.js +27 -32
- package/dist/http.d.ts +29 -0
- package/dist/http.js +128 -94
- package/dist/id.d.ts +1 -1
- package/dist/id.js +11 -11
- package/dist/index.d.ts +26 -34
- package/dist/index.js +23 -32
- package/dist/interceptor.d.ts +17 -17
- package/dist/interceptor.js +106 -126
- package/dist/iterator.d.ts +41 -41
- package/dist/iterator.js +136 -152
- package/dist/object.d.ts +10 -8
- package/dist/object.js +176 -227
- package/dist/plugin.d.ts +7 -7
- package/dist/plugin.js +41 -57
- package/dist/promise.d.ts +4 -4
- package/dist/promise.js +28 -28
- package/dist/proxy.d.ts +2 -2
- package/dist/proxy.js +23 -22
- package/dist/queue.d.ts +13 -13
- package/dist/queue.js +64 -79
- package/dist/regex.d.ts +9 -0
- package/dist/regex.js +11 -0
- package/dist/signal.d.ts +7 -2
- package/dist/signal.js +83 -80
- package/dist/stream.d.ts +23 -23
- package/dist/stream.js +118 -144
- package/dist/tracing.d.ts +50 -50
- package/dist/tracing.js +60 -85
- package/dist/types.d.ts +7 -10
- package/dist/value.d.ts +1 -1
- package/dist/value.js +5 -5
- package/package.json +2 -2
- package/dist/types.js +0 -1
package/dist/stream.js
CHANGED
|
@@ -1,155 +1,129 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return replicated;
|
|
1
|
+
import { once } from "./function.js";
|
|
2
|
+
import { isPlainObject } from "./object.js";
|
|
3
|
+
import { promiseWithResolvers } from "./promise.js";
|
|
4
|
+
import { recordSpanError, runInSpanContext, startSpan } from "./tracing.js";
|
|
5
|
+
import { AsyncIteratorClass } from "@standard-server/shared";
|
|
6
|
+
// src/stream.ts
|
|
7
|
+
function replicateReadableStream(stream, count) {
|
|
8
|
+
if (count <= 0) return [];
|
|
9
|
+
const replicated = [];
|
|
10
|
+
let pending = stream;
|
|
11
|
+
for (let index = 0; index < count - 1; index++) {
|
|
12
|
+
const [replica, remainder] = pending.tee();
|
|
13
|
+
replicated.push(replica);
|
|
14
|
+
pending = remainder;
|
|
15
|
+
}
|
|
16
|
+
replicated.push(pending);
|
|
17
|
+
return replicated;
|
|
19
18
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
catch (error) {
|
|
58
|
-
await onError?.(error);
|
|
59
|
-
throw error;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
finally {
|
|
63
|
-
await finish();
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
|
-
}, { highWaterMark: 0 });
|
|
19
|
+
function wrapReadableStream(stream, { runWith, mapResult, mapError, onError, onFinish }) {
|
|
20
|
+
runWith ??= (run) => run();
|
|
21
|
+
const reader = once(() => stream.getReader());
|
|
22
|
+
const finish = once(async () => onFinish?.());
|
|
23
|
+
return new ReadableStream({
|
|
24
|
+
async pull(controller) {
|
|
25
|
+
let result;
|
|
26
|
+
try {
|
|
27
|
+
const readResult = await runWith(() => reader().read());
|
|
28
|
+
result = mapResult ? await mapResult(readResult) : readResult;
|
|
29
|
+
} catch (error) {
|
|
30
|
+
try {
|
|
31
|
+
await onError?.(error);
|
|
32
|
+
controller.error(mapError ? await mapError(error) : error);
|
|
33
|
+
} finally {
|
|
34
|
+
await finish();
|
|
35
|
+
}
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (result.done) {
|
|
39
|
+
controller.close();
|
|
40
|
+
await finish();
|
|
41
|
+
} else controller.enqueue(result.value);
|
|
42
|
+
},
|
|
43
|
+
async cancel(reason) {
|
|
44
|
+
try {
|
|
45
|
+
try {
|
|
46
|
+
await runWith(() => reader().cancel(reason));
|
|
47
|
+
} catch (error) {
|
|
48
|
+
await onError?.(error);
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
} finally {
|
|
52
|
+
await finish();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}, { highWaterMark: 0 });
|
|
67
56
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
57
|
+
function traceReadableStream(options, stream) {
|
|
58
|
+
const getSpan = once(() => startSpan(options));
|
|
59
|
+
return wrapReadableStream(stream, {
|
|
60
|
+
runWith: (run) => runInSpanContext(getSpan(), run),
|
|
61
|
+
mapResult(result) {
|
|
62
|
+
getSpan()?.addEvent(result.done ? "closed" : "enqueued");
|
|
63
|
+
return result;
|
|
64
|
+
},
|
|
65
|
+
onError(error) {
|
|
66
|
+
recordSpanError(getSpan(), error);
|
|
67
|
+
},
|
|
68
|
+
onFinish() {
|
|
69
|
+
getSpan()?.end();
|
|
70
|
+
}
|
|
71
|
+
});
|
|
83
72
|
}
|
|
84
73
|
/**
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
finally {
|
|
113
|
-
signal.removeEventListener('abort', onAbort);
|
|
114
|
-
}
|
|
115
|
-
}, async ({ kind, error }) => {
|
|
116
|
-
if (kind === 'cancelled' || (kind === 'error' && cancelledBySignal)) {
|
|
117
|
-
await reader.cancel(error);
|
|
118
|
-
}
|
|
119
|
-
});
|
|
74
|
+
* Converts a {@link ReadableStream} into an {@link AsyncIteratorClass}.
|
|
75
|
+
*
|
|
76
|
+
* @see {@link https://orpc.dev/docs/integrations/ai-sdk | AI SDK Integration}
|
|
77
|
+
*/
|
|
78
|
+
function streamToAsyncIteratorObject(stream, { signal } = {}) {
|
|
79
|
+
const reader = stream.getReader();
|
|
80
|
+
let cancelledBySignal = false;
|
|
81
|
+
return new AsyncIteratorClass(async () => {
|
|
82
|
+
if (signal?.aborted) {
|
|
83
|
+
cancelledBySignal = true;
|
|
84
|
+
throw signal.reason;
|
|
85
|
+
}
|
|
86
|
+
if (!signal) return reader.read();
|
|
87
|
+
const { promise, reject } = promiseWithResolvers();
|
|
88
|
+
const onAbort = () => reject(signal.reason);
|
|
89
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
90
|
+
try {
|
|
91
|
+
return await Promise.race([reader.read(), promise.catch(async (reason) => {
|
|
92
|
+
cancelledBySignal = true;
|
|
93
|
+
throw reason;
|
|
94
|
+
})]);
|
|
95
|
+
} finally {
|
|
96
|
+
signal.removeEventListener("abort", onAbort);
|
|
97
|
+
}
|
|
98
|
+
}, async ({ kind, error }) => {
|
|
99
|
+
if (kind === "cancelled" || kind === "error" && cancelledBySignal) await reader.cancel(error);
|
|
100
|
+
});
|
|
120
101
|
}
|
|
121
102
|
/**
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
103
|
+
* Converts an `AsyncIterator` into a `ReadableStream`.
|
|
104
|
+
*/
|
|
105
|
+
function asyncIteratorToStream(iterator) {
|
|
106
|
+
return createIteratorStream(iterator, (value) => value);
|
|
126
107
|
}
|
|
127
108
|
/**
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
? { ...value }
|
|
136
|
-
: Array.isArray(value)
|
|
137
|
-
? value.map((i) => i) // use .map instead of ... to deal with sparse arrays
|
|
138
|
-
: value);
|
|
109
|
+
* Converts an `AsyncIterator` into a `ReadableStream`, ensuring that
|
|
110
|
+
* all emitted object values are *unproxied* before enqueuing.
|
|
111
|
+
*
|
|
112
|
+
* @see {@link https://orpc.dev/docs/integrations/ai-sdk | AI SDK Integration}
|
|
113
|
+
*/
|
|
114
|
+
function asyncIteratorToUnproxiedDataStream(iterator) {
|
|
115
|
+
return createIteratorStream(iterator, (value) => isPlainObject(value) ? { ...value } : Array.isArray(value) ? value.map((i) => i) : value);
|
|
139
116
|
}
|
|
140
117
|
function createIteratorStream(iterator, map) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
async cancel() {
|
|
152
|
-
await iterator.return?.();
|
|
153
|
-
},
|
|
154
|
-
}, { highWaterMark: 0 });
|
|
118
|
+
return new ReadableStream({
|
|
119
|
+
async pull(controller) {
|
|
120
|
+
const { done, value } = await iterator.next();
|
|
121
|
+
if (done) controller.close();
|
|
122
|
+
else controller.enqueue(map(value));
|
|
123
|
+
},
|
|
124
|
+
async cancel() {
|
|
125
|
+
await iterator.return?.();
|
|
126
|
+
}
|
|
127
|
+
}, { highWaterMark: 0 });
|
|
155
128
|
}
|
|
129
|
+
export { asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, replicateReadableStream, streamToAsyncIteratorObject, traceReadableStream, wrapReadableStream };
|
package/dist/tracing.d.ts
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Promisable } from "type-fest";
|
|
2
2
|
export type TracingAttributeValue = string | number | boolean | string[] | number[] | boolean[];
|
|
3
3
|
export interface TracingException {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
name?: string;
|
|
5
|
+
message: string;
|
|
6
|
+
stack?: string;
|
|
7
|
+
code?: string | number;
|
|
8
8
|
}
|
|
9
9
|
export type TracingHeaders = Record<string, string | string[] | undefined>;
|
|
10
|
-
export type TracingExceptionLevel =
|
|
10
|
+
export type TracingExceptionLevel = "error" | "info";
|
|
11
11
|
export interface TracingSpan {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
12
|
+
setAttribute(key: string, value: TracingAttributeValue): void;
|
|
13
|
+
/**
|
|
14
|
+
* Renames the span. Backends that cannot rename spans ignore it.
|
|
15
|
+
*/
|
|
16
|
+
updateName(name: string): void;
|
|
17
|
+
/**
|
|
18
|
+
* Adds an event to the span. Backends without span events ignore it.
|
|
19
|
+
*/
|
|
20
|
+
addEvent(name: string): void;
|
|
21
|
+
/**
|
|
22
|
+
* Records an exception on the span. The `error` level also marks the span as failed.
|
|
23
|
+
*/
|
|
24
|
+
recordException(level: TracingExceptionLevel, exception: TracingException): void;
|
|
25
|
+
end(): void;
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
28
|
* The tracing backend oRPC records spans with, see `@orpc/opentelemetry` and `@orpc/cloudflare`.
|
|
@@ -30,39 +30,39 @@ export interface TracingSpan {
|
|
|
30
30
|
* A `parent` defaults to the active span of the backend when omitted.
|
|
31
31
|
*/
|
|
32
32
|
export interface Tracer {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Starts a span without making it active. The caller must end it.
|
|
35
|
+
*/
|
|
36
|
+
startSpan(name: string, parent?: TracingSpan): TracingSpan;
|
|
37
|
+
/**
|
|
38
|
+
* Starts a span, makes it active while `fn` runs, and passes it to `fn`. The caller must end it.
|
|
39
|
+
*/
|
|
40
|
+
startActiveSpan<T>(name: string, parent: TracingSpan | undefined, fn: (span: TracingSpan) => Promise<T>): Promise<T>;
|
|
41
|
+
getActiveSpan(): TracingSpan | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Runs `fn` with `span` as the active span. Backends that cannot activate a span run `fn` directly.
|
|
44
|
+
*/
|
|
45
|
+
withActiveSpan<T>(span: TracingSpan, fn: () => Promisable<T>): Promisable<T>;
|
|
46
|
+
/**
|
|
47
|
+
* Writes the trace context of `span` into `headers`. Absent when the backend does not propagate context.
|
|
48
|
+
*/
|
|
49
|
+
inject?(span: TracingSpan, headers: TracingHeaders): void;
|
|
50
|
+
/**
|
|
51
|
+
* Reads the remote parent from `headers`. Absent when the backend does not propagate context.
|
|
52
|
+
*/
|
|
53
|
+
extract?(headers: TracingHeaders): TracingSpan | undefined;
|
|
54
54
|
}
|
|
55
55
|
export declare function setTracer(tracer: Tracer | undefined): void;
|
|
56
56
|
export declare function getTracer(): Tracer | undefined;
|
|
57
57
|
export interface StartSpanOptions {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
58
|
+
/**
|
|
59
|
+
* The name of the span to create.
|
|
60
|
+
*/
|
|
61
|
+
name: string;
|
|
62
|
+
/**
|
|
63
|
+
* The span to use as parent. Defaults to the active span of the backend.
|
|
64
|
+
*/
|
|
65
|
+
parent?: TracingSpan | undefined;
|
|
66
66
|
}
|
|
67
67
|
export declare function startSpan(options: StartSpanOptions | string): TracingSpan | undefined;
|
|
68
68
|
export declare function recordSpanError(span: TracingSpan | undefined, error: unknown): void;
|
|
@@ -70,4 +70,4 @@ export declare function setSpanAttributeIfDefined(span: TracingSpan | undefined,
|
|
|
70
70
|
export declare function toTracingException(error: unknown): TracingException;
|
|
71
71
|
export declare function toSpanAttributeValue(data: unknown): string;
|
|
72
72
|
export declare function runWithSpan<T>(options: string | StartSpanOptions, fn: (span?: TracingSpan) => Promisable<T>): Promise<T>;
|
|
73
|
-
export declare function runInSpanContext<T>(span: TracingSpan | undefined, fn: () => Promisable<T>): Promisable<T>;
|
|
73
|
+
export declare function runInSpanContext<T>(span: TracingSpan | undefined, fn: () => Promisable<T>): Promisable<T>;
|
package/dist/tracing.js
CHANGED
|
@@ -1,94 +1,69 @@
|
|
|
1
|
-
import { isAbortError } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { isAbortError } from "./error.js";
|
|
2
|
+
// src/tracing.ts
|
|
3
|
+
const TRACER_SYMBOL = /* @__PURE__ */ Symbol.for("ORPC_TRACER");
|
|
4
|
+
function setTracer(tracer) {
|
|
5
|
+
globalThis[TRACER_SYMBOL] = tracer;
|
|
6
6
|
}
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
function getTracer() {
|
|
8
|
+
return globalThis[TRACER_SYMBOL];
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (typeof options === 'string') {
|
|
16
|
-
return tracer.startSpan(options);
|
|
17
|
-
}
|
|
18
|
-
return tracer.startSpan(options.name, options.parent);
|
|
10
|
+
function startSpan(options) {
|
|
11
|
+
const tracer = getTracer();
|
|
12
|
+
if (!tracer) return;
|
|
13
|
+
if (typeof options === "string") return tracer.startSpan(options);
|
|
14
|
+
return tracer.startSpan(options.name, options.parent);
|
|
19
15
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
// DO NOT treat aborted error as error if happen during business logic (assumed)
|
|
25
|
-
span.recordException(isAbortError(error) ? 'info' : 'error', toTracingException(error));
|
|
16
|
+
function recordSpanError(span, error) {
|
|
17
|
+
if (!span) return;
|
|
18
|
+
span.recordException(isAbortError(error) ? "info" : "error", toTracingException(error));
|
|
26
19
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
span.setAttribute(key, value);
|
|
20
|
+
function setSpanAttributeIfDefined(span, key, value) {
|
|
21
|
+
if (!span || value === void 0) return;
|
|
22
|
+
span.setAttribute(key, value);
|
|
32
23
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
return { message: String(error) };
|
|
24
|
+
function toTracingException(error) {
|
|
25
|
+
if (error instanceof Error) {
|
|
26
|
+
const exception = {
|
|
27
|
+
message: error.message,
|
|
28
|
+
name: error.name,
|
|
29
|
+
stack: error.stack
|
|
30
|
+
};
|
|
31
|
+
if ("code" in error && (typeof error.code === "string" || typeof error.code === "number")) exception.code = error.code;
|
|
32
|
+
return exception;
|
|
33
|
+
}
|
|
34
|
+
return { message: String(error) };
|
|
46
35
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
return Array.from(value);
|
|
59
|
-
}
|
|
60
|
-
return value;
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
catch {
|
|
64
|
-
// oxlint-disable-next-line typescript/no-base-to-string
|
|
65
|
-
return String(data);
|
|
66
|
-
}
|
|
36
|
+
function toSpanAttributeValue(data) {
|
|
37
|
+
if (data === void 0) return "undefined";
|
|
38
|
+
try {
|
|
39
|
+
return JSON.stringify(data, (_, value) => {
|
|
40
|
+
if (typeof value === "bigint") return value.toString();
|
|
41
|
+
if (value instanceof Map || value instanceof Set) return Array.from(value);
|
|
42
|
+
return value;
|
|
43
|
+
});
|
|
44
|
+
} catch {
|
|
45
|
+
return String(data);
|
|
46
|
+
}
|
|
67
47
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
finally {
|
|
84
|
-
span.end();
|
|
85
|
-
}
|
|
86
|
-
});
|
|
48
|
+
async function runWithSpan(options, fn) {
|
|
49
|
+
const tracer = getTracer();
|
|
50
|
+
if (!tracer) return fn();
|
|
51
|
+
const name = typeof options === "string" ? options : options.name;
|
|
52
|
+
const parent = typeof options === "string" ? void 0 : options.parent;
|
|
53
|
+
return tracer.startActiveSpan(name, parent, async (span) => {
|
|
54
|
+
try {
|
|
55
|
+
return await fn(span);
|
|
56
|
+
} catch (e) {
|
|
57
|
+
recordSpanError(span, e);
|
|
58
|
+
throw e;
|
|
59
|
+
} finally {
|
|
60
|
+
span.end();
|
|
61
|
+
}
|
|
62
|
+
});
|
|
87
63
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
return tracer.withActiveSpan(span, fn);
|
|
64
|
+
function runInSpanContext(span, fn) {
|
|
65
|
+
const tracer = getTracer();
|
|
66
|
+
if (!span || !tracer) return fn();
|
|
67
|
+
return tracer.withActiveSpan(span, fn);
|
|
94
68
|
}
|
|
69
|
+
export { getTracer, recordSpanError, runInSpanContext, runWithSpan, setSpanAttributeIfDefined, setTracer, startSpan, toSpanAttributeValue, toTracingException };
|
package/dist/types.d.ts
CHANGED
|
@@ -2,25 +2,22 @@ export type IntersectPick<T, U> = Pick<T, keyof T & keyof U>;
|
|
|
2
2
|
/**
|
|
3
3
|
* Like `Omit`, but distributes over unions and keeps known keys beside index signatures.
|
|
4
4
|
*/
|
|
5
|
-
export type DistributiveOmit<T, K extends PropertyKey> = {
|
|
6
|
-
[P in keyof T as P extends K ? never : P]: T[P];
|
|
7
|
-
};
|
|
5
|
+
export type DistributiveOmit<T, K extends PropertyKey> = { [P in keyof T as P extends K ? never : P]: T[P]; };
|
|
8
6
|
/**
|
|
9
7
|
* Remove protected/private properties/methods
|
|
10
8
|
*/
|
|
11
9
|
export type Public<T> = Pick<T, keyof T>;
|
|
12
10
|
export type PromiseWithError<T, TError> = Promise<T> & {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
__error?: {
|
|
12
|
+
type: TError;
|
|
13
|
+
};
|
|
16
14
|
};
|
|
17
15
|
/**
|
|
18
16
|
* The place where you can config the orpc types.
|
|
19
17
|
*
|
|
20
18
|
* - `ThrowableError` the error type that represent throwable errors should be `Error` or `null | undefined | {}` if you want more strict.
|
|
21
19
|
*/
|
|
22
|
-
export interface Registry {
|
|
23
|
-
}
|
|
20
|
+
export interface Registry {}
|
|
24
21
|
export type ThrowableError = Registry extends {
|
|
25
|
-
|
|
26
|
-
} ? T : Error;
|
|
22
|
+
ThrowableError: infer T;
|
|
23
|
+
} ? T : Error;
|
package/dist/value.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export type Value<T, TArgs extends any[] = []> = T | ((...args: TArgs) => T);
|
|
2
|
-
export declare function value<T, TArgs extends any[]>(value: Value<T, TArgs>, ...args: NoInfer<TArgs>): T extends Value<infer U, any> ? U : never;
|
|
2
|
+
export declare function value<T, TArgs extends any[]>(value: Value<T, TArgs>, ...args: NoInfer<TArgs>): T extends Value<infer U, any> ? U : never;
|
package/dist/value.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
return value;
|
|
1
|
+
// src/value.ts
|
|
2
|
+
function value(value, ...args) {
|
|
3
|
+
if (typeof value === "function") return value(...args);
|
|
4
|
+
return value;
|
|
6
5
|
}
|
|
6
|
+
export { value };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/shared",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.50",
|
|
4
4
|
"description": "Internal utilities shared across oRPC packages",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"orpc"
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
}
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@standard-server/shared": "~0.
|
|
33
|
+
"@standard-server/shared": "~0.16.0",
|
|
34
34
|
"type-fest": "^5.10.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
package/dist/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|