@orpc/shared 2.0.0-beta.34 → 2.0.0-beta.36
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/README.md +30 -20
- package/dist/index.d.mts +75 -27
- package/dist/index.d.ts +75 -27
- package/dist/index.mjs +109 -111
- package/package.json +2 -11
package/README.md
CHANGED
|
@@ -46,29 +46,30 @@ You can read the documentation [here](https://orpc.dev).
|
|
|
46
46
|
|
|
47
47
|
**Built-in features**
|
|
48
48
|
|
|
49
|
-
| Package
|
|
50
|
-
|
|
|
51
|
-
| [@orpc/publisher](https://www.npmjs.com/package/@orpc/publisher)
|
|
52
|
-
| [@orpc/ratelimit](https://www.npmjs.com/package/@orpc/ratelimit)
|
|
53
|
-
| [@orpc/
|
|
54
|
-
| [@orpc/
|
|
49
|
+
| Package | Purpose | Docs |
|
|
50
|
+
| -------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------- |
|
|
51
|
+
| [@orpc/publisher](https://www.npmjs.com/package/@orpc/publisher) | Pub/Sub with memory, Redis, and Upstash adapters. | [Publisher](https://orpc.dev/docs/helpers/publisher) |
|
|
52
|
+
| [@orpc/ratelimit](https://www.npmjs.com/package/@orpc/ratelimit) | Rate limiting with memory, Redis, and Upstash adapters. | [Rate Limit](https://orpc.dev/docs/helpers/ratelimit) |
|
|
53
|
+
| [@orpc/experimental-lock](https://www.npmjs.com/package/@orpc/experimental-lock) | Locking with memory, Redis, and Upstash adapters. | [Lock](https://orpc.dev/docs/helpers/lock) |
|
|
54
|
+
| [@orpc/hibernation](https://www.npmjs.com/package/@orpc/hibernation) | Leverage Hibernation APIs like [Cloudflare's Hibernation WebSocket](https://developers.cloudflare.com/durable-objects/best-practices/websockets/#durable-objects-hibernation-websocket-api). | [Hibernation](https://orpc.dev/docs/integrations/hibernation) |
|
|
55
|
+
| [@orpc/json-schema](https://www.npmjs.com/package/@orpc/json-schema) | Smart coercion for OpenAPI requests. | [Smart Coercion](https://orpc.dev/docs/plugins/smart-coercion) |
|
|
55
56
|
|
|
56
57
|
**Framework & ecosystem integrations**
|
|
57
58
|
|
|
58
|
-
| Package | Purpose
|
|
59
|
-
| ------------------------------------------------------------------------------------ |
|
|
60
|
-
| [@orpc/next](https://www.npmjs.com/package/@orpc/next) | Integrate with [Next.js Server Functions](https://nextjs.org/docs/app/getting-started/mutating-data).
|
|
61
|
-
| [@orpc/ai-sdk](https://www.npmjs.com/package/@orpc/ai-sdk) | Turn contracts and procedures into [AI SDK](https://ai-sdk.dev/) tools.
|
|
62
|
-
| [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query) | Integrate with [TanStack Query](https://tanstack.com/query/latest).
|
|
63
|
-
| [@orpc/pinia-colada](https://www.npmjs.com/package/@orpc/pinia-colada) | Integrate with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
64
|
-
| [@orpc/swr](https://www.npmjs.com/package/@orpc/swr) | Integrate with [SWR](https://swr.vercel.app/).
|
|
65
|
-
| [@orpc/experimental-msw](https://www.npmjs.com/package/@orpc/experimental-msw) | Mock procedures with [Mock Service Worker](https://mswjs.io/).
|
|
66
|
-
| [@orpc/experimental-effect](https://www.npmjs.com/package/@orpc/experimental-effect) | Integrate with [Effect](https://effect.website/).
|
|
67
|
-
| [@orpc/nest](https://www.npmjs.com/package/@orpc/nest) | Implement your contract with [NestJS](https://nestjs.com/).
|
|
68
|
-
| [@orpc/node](https://www.npmjs.com/package/@orpc/node) | [Node.js](https://nodejs.org/) plugins for static file serving and large uploads.
|
|
69
|
-
| [@orpc/bun](https://www.npmjs.com/package/@orpc/bun) | Adapters for [Bun's Redis](https://bun.sh/).
|
|
70
|
-
| [@orpc/cloudflare](https://www.npmjs.com/package/@orpc/cloudflare) | Adapters for [Cloudflare
|
|
71
|
-
| [@orpc/trpc](https://www.npmjs.com/package/@orpc/trpc) | Reuse existing [tRPC](https://trpc.io/) routers within oRPC.
|
|
59
|
+
| Package | Purpose | Docs |
|
|
60
|
+
| ------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
61
|
+
| [@orpc/next](https://www.npmjs.com/package/@orpc/next) | Integrate with [Next.js Server Functions](https://nextjs.org/docs/app/getting-started/mutating-data). | [Next.js](https://orpc.dev/docs/integrations/next) |
|
|
62
|
+
| [@orpc/ai-sdk](https://www.npmjs.com/package/@orpc/ai-sdk) | Turn contracts and procedures into [AI SDK](https://ai-sdk.dev/) tools. | [AI SDK](https://orpc.dev/docs/integrations/ai-sdk) |
|
|
63
|
+
| [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query) | Integrate with [TanStack Query](https://tanstack.com/query/latest). | [TanStack Query](https://orpc.dev/docs/integrations/tanstack-query) |
|
|
64
|
+
| [@orpc/pinia-colada](https://www.npmjs.com/package/@orpc/pinia-colada) | Integrate with [Pinia Colada](https://pinia-colada.esm.dev/). | [Pinia Colada](https://orpc.dev/docs/integrations/pinia-colada) |
|
|
65
|
+
| [@orpc/swr](https://www.npmjs.com/package/@orpc/swr) | Integrate with [SWR](https://swr.vercel.app/). | [SWR](https://orpc.dev/docs/integrations/swr) |
|
|
66
|
+
| [@orpc/experimental-msw](https://www.npmjs.com/package/@orpc/experimental-msw) | Mock procedures with [Mock Service Worker](https://mswjs.io/). | [MSW](https://orpc.dev/docs/integrations/msw) |
|
|
67
|
+
| [@orpc/experimental-effect](https://www.npmjs.com/package/@orpc/experimental-effect) | Integrate with [Effect](https://effect.website/). | [Effect](https://orpc.dev/docs/integrations/effect) |
|
|
68
|
+
| [@orpc/nest](https://www.npmjs.com/package/@orpc/nest) | Implement your contract with [NestJS](https://nestjs.com/). | [NestJS](https://orpc.dev/docs/integrations/nest) |
|
|
69
|
+
| [@orpc/node](https://www.npmjs.com/package/@orpc/node) | [Node.js](https://nodejs.org/) plugins for static file serving and large uploads. | [Static File](https://orpc.dev/docs/plugins/static-file), [Tmp File Upload](https://orpc.dev/docs/plugins/tmp-file-upload), [Batch Response Compression](https://orpc.dev/docs/plugins/batch-response-compression) |
|
|
70
|
+
| [@orpc/bun](https://www.npmjs.com/package/@orpc/bun) | Adapters for [Bun's Redis](https://bun.sh/). | [Publisher](https://orpc.dev/docs/helpers/publisher), [Rate Limit](https://orpc.dev/docs/helpers/ratelimit), [Lock](https://orpc.dev/docs/helpers/lock) |
|
|
71
|
+
| [@orpc/cloudflare](https://www.npmjs.com/package/@orpc/cloudflare) | Adapters for [Cloudflare Workers](https://developers.cloudflare.com/workers/). | [Publisher](https://orpc.dev/docs/helpers/publisher), [Rate Limit](https://orpc.dev/docs/helpers/ratelimit), [Lock](https://orpc.dev/docs/helpers/lock), [Traces](https://orpc.dev/docs/integrations/cloudflare-traces) |
|
|
72
|
+
| [@orpc/trpc](https://www.npmjs.com/package/@orpc/trpc) | Reuse existing [tRPC](https://trpc.io/) routers within oRPC. | [tRPC](https://orpc.dev/docs/integrations/trpc) |
|
|
72
73
|
|
|
73
74
|
**Observability**
|
|
74
75
|
|
|
@@ -94,6 +95,14 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
|
|
|
94
95
|
</tr>
|
|
95
96
|
</table>
|
|
96
97
|
|
|
98
|
+
### Special Sponsors
|
|
99
|
+
|
|
100
|
+
<table>
|
|
101
|
+
<tr>
|
|
102
|
+
<td align="center"><a href="http://twitter.com/rauchg?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Guillermo Rauch"><img src="https://avatars.githubusercontent.com/u/13041?u=1ee8d111657cdd02ff6d253df00978d17ee6d722&v=4" width="279" alt="Guillermo Rauch"/><br />Guillermo Rauch</a></td>
|
|
103
|
+
</tr>
|
|
104
|
+
</table>
|
|
105
|
+
|
|
97
106
|
### Organization Sponsors
|
|
98
107
|
|
|
99
108
|
<table>
|
|
@@ -127,6 +136,7 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
|
|
|
127
136
|
<td align="center"><a href="https://github.com/ellis-driscoll?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Ellis Driscoll"><img src="https://avatars.githubusercontent.com/u/70685966?u=c5f95bc33b5991d9744abe00052542e4a2ed3cb9&v=4" width="139" alt="Ellis Driscoll"/><br />Ellis Driscoll</a></td>
|
|
128
137
|
<td align="center"><a href="https://github.com/hoangbn?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Hoang Nguyen"><img src="https://avatars.githubusercontent.com/u/38968280?u=c90084c6de65c56facabab7ba13a72a49ddbc3e4&v=4" width="139" alt="Hoang Nguyen"/><br />Hoang Nguyen</a></td>
|
|
129
138
|
<td align="center"><a href="https://opencollective.com/guest-ac41de3b?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Orestis Ioannou"><img src="https://images.opencollective.com/guest-ac41de3b/avatar/460.png" width="139" alt="Orestis Ioannou"/><br />Orestis Ioannou</a></td>
|
|
139
|
+
<td align="center"><a href="https://automatio.ai/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Stefan Smiljkovic"><img src="https://avatars.githubusercontent.com/u/1984909?u=b7bf5bc40ed49df3c22f69d2da7b8d78709c49ed&v=4" width="139" alt="Stefan Smiljkovic"/><br />Stefan Smiljkovic</a></td>
|
|
130
140
|
</tr>
|
|
131
141
|
</table>
|
|
132
142
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Arrayable, Promisable } from 'type-fest';
|
|
2
2
|
export { Arrayable, IsEqual, PartialDeep, Promisable, Writable } from 'type-fest';
|
|
3
|
-
import { Tracer, TraceAPI, ContextAPI, PropagationAPI, SpanOptions, Context, Span, AttributeValue, Exception } from '@opentelemetry/api';
|
|
4
3
|
import { AsyncIteratorClass } from '@standard-server/shared';
|
|
5
4
|
export { AbortError, AsyncCleanupFn, AsyncIteratorClass, AsyncIteratorClassNextFn, SequentialIdGenerator, getOrBind, isAsyncIteratorObject, isTypescriptObject, parseEmptyableJSON, sequential, sleep, stringifyJSON, toArray } from '@standard-server/shared';
|
|
6
5
|
|
|
@@ -152,40 +151,78 @@ declare function onReadableStreamError<T, TOptions extends {
|
|
|
152
151
|
}, TRest extends any[]>(callback: NoInfer<(error: ThrowableError | (ReturnType<TOptions['next']> extends PromiseWithError<any, infer E> ? E : ThrowableError), options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => T | Promise<Awaited<ReturnType<TOptions['next']>>>;
|
|
153
152
|
declare function intercept<TOptions extends InterceptableOptions, TResult>(interceptors: undefined | Interceptor<TOptions, TResult>[], options: NoInfer<TOptions>, main: NoInfer<(options: TOptions) => TResult>): TResult;
|
|
154
153
|
|
|
154
|
+
type TracingAttributeValue = string | number | boolean | string[] | number[] | boolean[];
|
|
155
|
+
interface TracingException {
|
|
156
|
+
name?: string;
|
|
157
|
+
message: string;
|
|
158
|
+
stack?: string;
|
|
159
|
+
code?: string | number;
|
|
160
|
+
}
|
|
161
|
+
type TracingHeaders = Record<string, string | string[] | undefined>;
|
|
162
|
+
type TracingExceptionLevel = 'error' | 'info';
|
|
163
|
+
interface TracingSpan {
|
|
164
|
+
setAttribute(key: string, value: TracingAttributeValue): void;
|
|
165
|
+
/**
|
|
166
|
+
* Renames the span. Backends that cannot rename spans ignore it.
|
|
167
|
+
*/
|
|
168
|
+
updateName(name: string): void;
|
|
169
|
+
/**
|
|
170
|
+
* Adds an event to the span. Backends without span events ignore it.
|
|
171
|
+
*/
|
|
172
|
+
addEvent(name: string): void;
|
|
173
|
+
/**
|
|
174
|
+
* Records an exception on the span. The `error` level also marks the span as failed.
|
|
175
|
+
*/
|
|
176
|
+
recordException(level: TracingExceptionLevel, exception: TracingException): void;
|
|
177
|
+
end(): void;
|
|
178
|
+
}
|
|
155
179
|
/**
|
|
156
|
-
*
|
|
180
|
+
* The tracing backend oRPC records spans with, see `@orpc/opentelemetry` and `@orpc/cloudflare`.
|
|
181
|
+
*
|
|
182
|
+
* A `parent` defaults to the active span of the backend when omitted.
|
|
157
183
|
*/
|
|
158
|
-
|
|
159
|
-
interface OpenTelemetryConfig {
|
|
160
|
-
tracer: Tracer;
|
|
161
|
-
trace: TraceAPI;
|
|
162
|
-
context: ContextAPI;
|
|
184
|
+
interface Tracer {
|
|
163
185
|
/**
|
|
164
|
-
*
|
|
186
|
+
* Starts a span without making it active. The caller must end it.
|
|
165
187
|
*/
|
|
166
|
-
|
|
188
|
+
startSpan(name: string, parent?: TracingSpan): TracingSpan;
|
|
189
|
+
/**
|
|
190
|
+
* Starts a span, makes it active while `fn` runs, and passes it to `fn`. The caller must end it.
|
|
191
|
+
*/
|
|
192
|
+
startActiveSpan<T>(name: string, parent: TracingSpan | undefined, fn: (span: TracingSpan) => Promise<T>): Promise<T>;
|
|
193
|
+
getActiveSpan(): TracingSpan | undefined;
|
|
194
|
+
/**
|
|
195
|
+
* Runs `fn` with `span` as the active span. Backends that cannot activate a span run `fn` directly.
|
|
196
|
+
*/
|
|
197
|
+
withActiveSpan<T>(span: TracingSpan, fn: () => Promisable<T>): Promisable<T>;
|
|
198
|
+
/**
|
|
199
|
+
* Writes the trace context of `span` into `headers`. Absent when the backend does not propagate context.
|
|
200
|
+
*/
|
|
201
|
+
inject?(span: TracingSpan, headers: TracingHeaders): void;
|
|
202
|
+
/**
|
|
203
|
+
* Reads the remote parent from `headers`. Absent when the backend does not propagate context.
|
|
204
|
+
*/
|
|
205
|
+
extract?(headers: TracingHeaders): TracingSpan | undefined;
|
|
167
206
|
}
|
|
168
|
-
declare function
|
|
169
|
-
declare function
|
|
170
|
-
interface StartSpanOptions
|
|
207
|
+
declare function setTracer(tracer: Tracer | undefined): void;
|
|
208
|
+
declare function getTracer(): Tracer | undefined;
|
|
209
|
+
interface StartSpanOptions {
|
|
171
210
|
/**
|
|
172
211
|
* The name of the span to create.
|
|
173
212
|
*/
|
|
174
213
|
name: string;
|
|
175
214
|
/**
|
|
176
|
-
*
|
|
215
|
+
* The span to use as parent. Defaults to the active span of the backend.
|
|
177
216
|
*/
|
|
178
|
-
|
|
217
|
+
parent?: TracingSpan | undefined;
|
|
179
218
|
}
|
|
180
|
-
declare function startSpan(options: StartSpanOptions | string):
|
|
181
|
-
declare function recordSpanError(span:
|
|
182
|
-
declare function setSpanAttributeIfDefined(span:
|
|
183
|
-
declare function
|
|
219
|
+
declare function startSpan(options: StartSpanOptions | string): TracingSpan | undefined;
|
|
220
|
+
declare function recordSpanError(span: TracingSpan | undefined, error: unknown): void;
|
|
221
|
+
declare function setSpanAttributeIfDefined(span: TracingSpan | undefined, key: string, value: TracingAttributeValue | undefined): void;
|
|
222
|
+
declare function toTracingException(error: unknown): TracingException;
|
|
184
223
|
declare function toSpanAttributeValue(data: unknown): string;
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
declare function runWithSpan<T>(options: string | RunWithSpanOptions, fn: (span?: Span) => Promisable<T>): Promise<T>;
|
|
188
|
-
declare function runInSpanContext<T>(span: Span | undefined, fn: () => Promisable<T>): Promise<T>;
|
|
224
|
+
declare function runWithSpan<T>(options: string | StartSpanOptions, fn: (span?: TracingSpan) => Promisable<T>): Promise<T>;
|
|
225
|
+
declare function runInSpanContext<T>(span: TracingSpan | undefined, fn: () => Promisable<T>): Promisable<T>;
|
|
189
226
|
|
|
190
227
|
interface WrapAsyncIteratorOptions<TYield, TReturn, TMappedYield, TMappedReturn> {
|
|
191
228
|
/**
|
|
@@ -193,7 +230,7 @@ interface WrapAsyncIteratorOptions<TYield, TReturn, TMappedYield, TMappedReturn>
|
|
|
193
230
|
* Useful when you want execution to happen within a specific context,
|
|
194
231
|
* such as AsyncLocalStorage.
|
|
195
232
|
*/
|
|
196
|
-
runWith?: <T>(run: () => Promise<T>) =>
|
|
233
|
+
runWith?: <T>(run: () => Promise<T>) => Promisable<T>;
|
|
197
234
|
mapResult?: (result: IteratorResult<TYield, TReturn>) => Promisable<IteratorResult<TMappedYield, TMappedReturn>>;
|
|
198
235
|
mapError?: (error: ThrowableError) => Promisable<ThrowableError>;
|
|
199
236
|
onError?: (error: ThrowableError) => Promisable<void>;
|
|
@@ -266,6 +303,10 @@ declare function get(object: unknown, path: readonly PropertyKey[]): unknown;
|
|
|
266
303
|
* Sets a value at the given path, creating plain objects for intermediate keys as needed.
|
|
267
304
|
*/
|
|
268
305
|
declare function set(root: object, path: [PropertyKey, ...PropertyKey[]] | [...PropertyKey[], PropertyKey], value: unknown): void;
|
|
306
|
+
/**
|
|
307
|
+
* Sets `object[key]`, defining `__proto__` as an own property instead of re-parenting the object.
|
|
308
|
+
*/
|
|
309
|
+
declare function setOwn(object: object, key: PropertyKey, value: unknown): void;
|
|
269
310
|
/**
|
|
270
311
|
* Merges two values by copying the second over the first, repeating the merge one level deeper for
|
|
271
312
|
* nested plain objects. Anything that is not a pair of plain objects is replaced by the second one.
|
|
@@ -380,7 +421,7 @@ interface WrapReadableStreamOptions<T, TMapped> {
|
|
|
380
421
|
* Useful when you want execution to happen within a specific context,
|
|
381
422
|
* such as AsyncLocalStorage.
|
|
382
423
|
*/
|
|
383
|
-
runWith?: <T>(run: () => Promise<T>) =>
|
|
424
|
+
runWith?: <T>(run: () => Promise<T>) => Promisable<T>;
|
|
384
425
|
mapResult?: (result: ReadableStreamReadResult<T>) => Promisable<ReadableStreamReadResult<TMapped>>;
|
|
385
426
|
mapError?: (error: ThrowableError) => Promisable<ThrowableError>;
|
|
386
427
|
onError?: (error: ThrowableError) => Promisable<void>;
|
|
@@ -411,7 +452,14 @@ declare function asyncIteratorToStream<T>(iterator: AsyncIterator<T>): ReadableS
|
|
|
411
452
|
*/
|
|
412
453
|
declare function asyncIteratorToUnproxiedDataStream<T>(iterator: AsyncIterator<T>): ReadableStream<T>;
|
|
413
454
|
|
|
414
|
-
|
|
455
|
+
/**
|
|
456
|
+
* `encodeURIComponent` that never throws, lone surrogates become U+FFFD.
|
|
457
|
+
*/
|
|
458
|
+
declare function safeEncodeURIComponent(value: string): string;
|
|
459
|
+
/**
|
|
460
|
+
* `decodeURIComponent` that never throws, malformed input is returned unchanged.
|
|
461
|
+
*/
|
|
462
|
+
declare function safeDecodeURIComponent(value: string): string;
|
|
415
463
|
|
|
416
|
-
export { AsyncIdQueue, NullProtoObj, ORPC_NAME, allAbortSignal, anyAbortSignal, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, bindMethods, clone, compareSequentialIds, consumeAsyncIterator, defer, findDeepMatches, get, getConstructor, getConstructors,
|
|
417
|
-
export type { AnyFunction, AsyncIdQueueCloseOptions, ConsumeAsyncIteratorOptions, InterceptableOptions, Interceptor, InterceptorOptions, IntersectPick, MaybeOptionalOptions, OnFinishState,
|
|
464
|
+
export { AsyncIdQueue, NullProtoObj, ORPC_NAME, allAbortSignal, anyAbortSignal, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, bindMethods, clone, compareSequentialIds, consumeAsyncIterator, defer, findDeepMatches, get, getConstructor, getConstructors, getOwn, getTracer, intercept, isAbortError, isAsyncGeneratorFunction, isCompressibleContentType, isDeepEqual, isNoTransformCacheControl, isPlainObject, isPropertyKey, loadBytes, matchesHttpPath, matchesHttpPathPrefix, mergeHttpPath, mergeTwoLevels, normalizeHttpPath, omit, onAsyncIteratorObjectError, onError, onFinish, onReadableStreamError, onStart, onSuccess, once, override, parseAcceptEncodingQualities, pathToHttpPath, promiseWithResolvers, recordSpanError, replicateAsyncIterator, replicateReadableStream, resolveMaybeOptionalOptions, runInSpanContext, runWithSignal, runWithSpan, safeDecodeURIComponent, safeEncodeURIComponent, set, setOwn, setSpanAttributeIfDefined, setTracer, sortPlugins, splitInHalf, startSpan, streamToAsyncIteratorObject, toSpanAttributeValue, toStringOrBytes, toTracingException, traceAsyncIterator, traceReadableStream, tryOrUndefined, value, varyByAcceptEncoding, wrapAsyncIterator, wrapReadableStream };
|
|
465
|
+
export type { AnyFunction, AsyncIdQueueCloseOptions, ConsumeAsyncIteratorOptions, InterceptableOptions, Interceptor, InterceptorOptions, IntersectPick, MaybeOptionalOptions, OnFinishState, OrderablePlugin, PromiseWithError, Public, ReadableStreamReadResult, Registry, Segment, StartSpanOptions, ThrowableError, Tracer, TracingAttributeValue, TracingException, TracingExceptionLevel, TracingHeaders, TracingSpan, Value, WrapAsyncIteratorOptions, WrapReadableStreamOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Arrayable, Promisable } from 'type-fest';
|
|
2
2
|
export { Arrayable, IsEqual, PartialDeep, Promisable, Writable } from 'type-fest';
|
|
3
|
-
import { Tracer, TraceAPI, ContextAPI, PropagationAPI, SpanOptions, Context, Span, AttributeValue, Exception } from '@opentelemetry/api';
|
|
4
3
|
import { AsyncIteratorClass } from '@standard-server/shared';
|
|
5
4
|
export { AbortError, AsyncCleanupFn, AsyncIteratorClass, AsyncIteratorClassNextFn, SequentialIdGenerator, getOrBind, isAsyncIteratorObject, isTypescriptObject, parseEmptyableJSON, sequential, sleep, stringifyJSON, toArray } from '@standard-server/shared';
|
|
6
5
|
|
|
@@ -152,40 +151,78 @@ declare function onReadableStreamError<T, TOptions extends {
|
|
|
152
151
|
}, TRest extends any[]>(callback: NoInfer<(error: ThrowableError | (ReturnType<TOptions['next']> extends PromiseWithError<any, infer E> ? E : ThrowableError), options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => T | Promise<Awaited<ReturnType<TOptions['next']>>>;
|
|
153
152
|
declare function intercept<TOptions extends InterceptableOptions, TResult>(interceptors: undefined | Interceptor<TOptions, TResult>[], options: NoInfer<TOptions>, main: NoInfer<(options: TOptions) => TResult>): TResult;
|
|
154
153
|
|
|
154
|
+
type TracingAttributeValue = string | number | boolean | string[] | number[] | boolean[];
|
|
155
|
+
interface TracingException {
|
|
156
|
+
name?: string;
|
|
157
|
+
message: string;
|
|
158
|
+
stack?: string;
|
|
159
|
+
code?: string | number;
|
|
160
|
+
}
|
|
161
|
+
type TracingHeaders = Record<string, string | string[] | undefined>;
|
|
162
|
+
type TracingExceptionLevel = 'error' | 'info';
|
|
163
|
+
interface TracingSpan {
|
|
164
|
+
setAttribute(key: string, value: TracingAttributeValue): void;
|
|
165
|
+
/**
|
|
166
|
+
* Renames the span. Backends that cannot rename spans ignore it.
|
|
167
|
+
*/
|
|
168
|
+
updateName(name: string): void;
|
|
169
|
+
/**
|
|
170
|
+
* Adds an event to the span. Backends without span events ignore it.
|
|
171
|
+
*/
|
|
172
|
+
addEvent(name: string): void;
|
|
173
|
+
/**
|
|
174
|
+
* Records an exception on the span. The `error` level also marks the span as failed.
|
|
175
|
+
*/
|
|
176
|
+
recordException(level: TracingExceptionLevel, exception: TracingException): void;
|
|
177
|
+
end(): void;
|
|
178
|
+
}
|
|
155
179
|
/**
|
|
156
|
-
*
|
|
180
|
+
* The tracing backend oRPC records spans with, see `@orpc/opentelemetry` and `@orpc/cloudflare`.
|
|
181
|
+
*
|
|
182
|
+
* A `parent` defaults to the active span of the backend when omitted.
|
|
157
183
|
*/
|
|
158
|
-
|
|
159
|
-
interface OpenTelemetryConfig {
|
|
160
|
-
tracer: Tracer;
|
|
161
|
-
trace: TraceAPI;
|
|
162
|
-
context: ContextAPI;
|
|
184
|
+
interface Tracer {
|
|
163
185
|
/**
|
|
164
|
-
*
|
|
186
|
+
* Starts a span without making it active. The caller must end it.
|
|
165
187
|
*/
|
|
166
|
-
|
|
188
|
+
startSpan(name: string, parent?: TracingSpan): TracingSpan;
|
|
189
|
+
/**
|
|
190
|
+
* Starts a span, makes it active while `fn` runs, and passes it to `fn`. The caller must end it.
|
|
191
|
+
*/
|
|
192
|
+
startActiveSpan<T>(name: string, parent: TracingSpan | undefined, fn: (span: TracingSpan) => Promise<T>): Promise<T>;
|
|
193
|
+
getActiveSpan(): TracingSpan | undefined;
|
|
194
|
+
/**
|
|
195
|
+
* Runs `fn` with `span` as the active span. Backends that cannot activate a span run `fn` directly.
|
|
196
|
+
*/
|
|
197
|
+
withActiveSpan<T>(span: TracingSpan, fn: () => Promisable<T>): Promisable<T>;
|
|
198
|
+
/**
|
|
199
|
+
* Writes the trace context of `span` into `headers`. Absent when the backend does not propagate context.
|
|
200
|
+
*/
|
|
201
|
+
inject?(span: TracingSpan, headers: TracingHeaders): void;
|
|
202
|
+
/**
|
|
203
|
+
* Reads the remote parent from `headers`. Absent when the backend does not propagate context.
|
|
204
|
+
*/
|
|
205
|
+
extract?(headers: TracingHeaders): TracingSpan | undefined;
|
|
167
206
|
}
|
|
168
|
-
declare function
|
|
169
|
-
declare function
|
|
170
|
-
interface StartSpanOptions
|
|
207
|
+
declare function setTracer(tracer: Tracer | undefined): void;
|
|
208
|
+
declare function getTracer(): Tracer | undefined;
|
|
209
|
+
interface StartSpanOptions {
|
|
171
210
|
/**
|
|
172
211
|
* The name of the span to create.
|
|
173
212
|
*/
|
|
174
213
|
name: string;
|
|
175
214
|
/**
|
|
176
|
-
*
|
|
215
|
+
* The span to use as parent. Defaults to the active span of the backend.
|
|
177
216
|
*/
|
|
178
|
-
|
|
217
|
+
parent?: TracingSpan | undefined;
|
|
179
218
|
}
|
|
180
|
-
declare function startSpan(options: StartSpanOptions | string):
|
|
181
|
-
declare function recordSpanError(span:
|
|
182
|
-
declare function setSpanAttributeIfDefined(span:
|
|
183
|
-
declare function
|
|
219
|
+
declare function startSpan(options: StartSpanOptions | string): TracingSpan | undefined;
|
|
220
|
+
declare function recordSpanError(span: TracingSpan | undefined, error: unknown): void;
|
|
221
|
+
declare function setSpanAttributeIfDefined(span: TracingSpan | undefined, key: string, value: TracingAttributeValue | undefined): void;
|
|
222
|
+
declare function toTracingException(error: unknown): TracingException;
|
|
184
223
|
declare function toSpanAttributeValue(data: unknown): string;
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
declare function runWithSpan<T>(options: string | RunWithSpanOptions, fn: (span?: Span) => Promisable<T>): Promise<T>;
|
|
188
|
-
declare function runInSpanContext<T>(span: Span | undefined, fn: () => Promisable<T>): Promise<T>;
|
|
224
|
+
declare function runWithSpan<T>(options: string | StartSpanOptions, fn: (span?: TracingSpan) => Promisable<T>): Promise<T>;
|
|
225
|
+
declare function runInSpanContext<T>(span: TracingSpan | undefined, fn: () => Promisable<T>): Promisable<T>;
|
|
189
226
|
|
|
190
227
|
interface WrapAsyncIteratorOptions<TYield, TReturn, TMappedYield, TMappedReturn> {
|
|
191
228
|
/**
|
|
@@ -193,7 +230,7 @@ interface WrapAsyncIteratorOptions<TYield, TReturn, TMappedYield, TMappedReturn>
|
|
|
193
230
|
* Useful when you want execution to happen within a specific context,
|
|
194
231
|
* such as AsyncLocalStorage.
|
|
195
232
|
*/
|
|
196
|
-
runWith?: <T>(run: () => Promise<T>) =>
|
|
233
|
+
runWith?: <T>(run: () => Promise<T>) => Promisable<T>;
|
|
197
234
|
mapResult?: (result: IteratorResult<TYield, TReturn>) => Promisable<IteratorResult<TMappedYield, TMappedReturn>>;
|
|
198
235
|
mapError?: (error: ThrowableError) => Promisable<ThrowableError>;
|
|
199
236
|
onError?: (error: ThrowableError) => Promisable<void>;
|
|
@@ -266,6 +303,10 @@ declare function get(object: unknown, path: readonly PropertyKey[]): unknown;
|
|
|
266
303
|
* Sets a value at the given path, creating plain objects for intermediate keys as needed.
|
|
267
304
|
*/
|
|
268
305
|
declare function set(root: object, path: [PropertyKey, ...PropertyKey[]] | [...PropertyKey[], PropertyKey], value: unknown): void;
|
|
306
|
+
/**
|
|
307
|
+
* Sets `object[key]`, defining `__proto__` as an own property instead of re-parenting the object.
|
|
308
|
+
*/
|
|
309
|
+
declare function setOwn(object: object, key: PropertyKey, value: unknown): void;
|
|
269
310
|
/**
|
|
270
311
|
* Merges two values by copying the second over the first, repeating the merge one level deeper for
|
|
271
312
|
* nested plain objects. Anything that is not a pair of plain objects is replaced by the second one.
|
|
@@ -380,7 +421,7 @@ interface WrapReadableStreamOptions<T, TMapped> {
|
|
|
380
421
|
* Useful when you want execution to happen within a specific context,
|
|
381
422
|
* such as AsyncLocalStorage.
|
|
382
423
|
*/
|
|
383
|
-
runWith?: <T>(run: () => Promise<T>) =>
|
|
424
|
+
runWith?: <T>(run: () => Promise<T>) => Promisable<T>;
|
|
384
425
|
mapResult?: (result: ReadableStreamReadResult<T>) => Promisable<ReadableStreamReadResult<TMapped>>;
|
|
385
426
|
mapError?: (error: ThrowableError) => Promisable<ThrowableError>;
|
|
386
427
|
onError?: (error: ThrowableError) => Promisable<void>;
|
|
@@ -411,7 +452,14 @@ declare function asyncIteratorToStream<T>(iterator: AsyncIterator<T>): ReadableS
|
|
|
411
452
|
*/
|
|
412
453
|
declare function asyncIteratorToUnproxiedDataStream<T>(iterator: AsyncIterator<T>): ReadableStream<T>;
|
|
413
454
|
|
|
414
|
-
|
|
455
|
+
/**
|
|
456
|
+
* `encodeURIComponent` that never throws, lone surrogates become U+FFFD.
|
|
457
|
+
*/
|
|
458
|
+
declare function safeEncodeURIComponent(value: string): string;
|
|
459
|
+
/**
|
|
460
|
+
* `decodeURIComponent` that never throws, malformed input is returned unchanged.
|
|
461
|
+
*/
|
|
462
|
+
declare function safeDecodeURIComponent(value: string): string;
|
|
415
463
|
|
|
416
|
-
export { AsyncIdQueue, NullProtoObj, ORPC_NAME, allAbortSignal, anyAbortSignal, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, bindMethods, clone, compareSequentialIds, consumeAsyncIterator, defer, findDeepMatches, get, getConstructor, getConstructors,
|
|
417
|
-
export type { AnyFunction, AsyncIdQueueCloseOptions, ConsumeAsyncIteratorOptions, InterceptableOptions, Interceptor, InterceptorOptions, IntersectPick, MaybeOptionalOptions, OnFinishState,
|
|
464
|
+
export { AsyncIdQueue, NullProtoObj, ORPC_NAME, allAbortSignal, anyAbortSignal, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, bindMethods, clone, compareSequentialIds, consumeAsyncIterator, defer, findDeepMatches, get, getConstructor, getConstructors, getOwn, getTracer, intercept, isAbortError, isAsyncGeneratorFunction, isCompressibleContentType, isDeepEqual, isNoTransformCacheControl, isPlainObject, isPropertyKey, loadBytes, matchesHttpPath, matchesHttpPathPrefix, mergeHttpPath, mergeTwoLevels, normalizeHttpPath, omit, onAsyncIteratorObjectError, onError, onFinish, onReadableStreamError, onStart, onSuccess, once, override, parseAcceptEncodingQualities, pathToHttpPath, promiseWithResolvers, recordSpanError, replicateAsyncIterator, replicateReadableStream, resolveMaybeOptionalOptions, runInSpanContext, runWithSignal, runWithSpan, safeDecodeURIComponent, safeEncodeURIComponent, set, setOwn, setSpanAttributeIfDefined, setTracer, sortPlugins, splitInHalf, startSpan, streamToAsyncIteratorObject, toSpanAttributeValue, toStringOrBytes, toTracingException, traceAsyncIterator, traceReadableStream, tryOrUndefined, value, varyByAcceptEncoding, wrapAsyncIterator, wrapReadableStream };
|
|
465
|
+
export type { AnyFunction, AsyncIdQueueCloseOptions, ConsumeAsyncIteratorOptions, InterceptableOptions, Interceptor, InterceptorOptions, IntersectPick, MaybeOptionalOptions, OnFinishState, OrderablePlugin, PromiseWithError, Public, ReadableStreamReadResult, Registry, Segment, StartSpanOptions, ThrowableError, Tracer, TracingAttributeValue, TracingException, TracingExceptionLevel, TracingHeaders, TracingSpan, Value, WrapAsyncIteratorOptions, WrapReadableStreamOptions };
|
package/dist/index.mjs
CHANGED
|
@@ -142,7 +142,18 @@ function tryOrUndefined(fn) {
|
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
|
|
145
|
+
const LONE_SURROGATE_REGEX = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g;
|
|
146
|
+
function safeEncodeURIComponent(value) {
|
|
147
|
+
try {
|
|
148
|
+
return encodeURIComponent(value);
|
|
149
|
+
} catch {
|
|
150
|
+
return encodeURIComponent(value.replace(LONE_SURROGATE_REGEX, "\uFFFD"));
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function safeDecodeURIComponent(value) {
|
|
154
|
+
if (!value.includes("%")) {
|
|
155
|
+
return value;
|
|
156
|
+
}
|
|
146
157
|
try {
|
|
147
158
|
return decodeURIComponent(value);
|
|
148
159
|
} catch {
|
|
@@ -151,14 +162,14 @@ function tryDecodeURIComponent(value) {
|
|
|
151
162
|
}
|
|
152
163
|
|
|
153
164
|
function pathToHttpPath(path) {
|
|
154
|
-
return `/${path.map(
|
|
165
|
+
return `/${path.map(safeEncodeURIComponent).join("/")}`;
|
|
155
166
|
}
|
|
156
167
|
function normalizeHttpPath(path) {
|
|
157
168
|
const paths = path.split("/");
|
|
158
169
|
if (paths.at(0) === "") {
|
|
159
170
|
paths.shift();
|
|
160
171
|
}
|
|
161
|
-
return pathToHttpPath(paths.map(
|
|
172
|
+
return pathToHttpPath(paths.map(safeDecodeURIComponent));
|
|
162
173
|
}
|
|
163
174
|
function mergeHttpPath(a, b) {
|
|
164
175
|
return `${a.endsWith("/") ? a.slice(0, -1) : a}${b}`;
|
|
@@ -228,106 +239,6 @@ function compareSequentialIds(a, b) {
|
|
|
228
239
|
return a < b ? -1 : a > b ? 1 : 0;
|
|
229
240
|
}
|
|
230
241
|
|
|
231
|
-
const SPAN_ERROR_STATUS = 2;
|
|
232
|
-
const OPENTELEMETRY_CONFIG_SYMBOL = Symbol.for("ORPC_OPENTELEMETRY_CONFIG");
|
|
233
|
-
function setOpenTelemetryConfig(config) {
|
|
234
|
-
globalThis[OPENTELEMETRY_CONFIG_SYMBOL] = config;
|
|
235
|
-
}
|
|
236
|
-
function getOpenTelemetryConfig() {
|
|
237
|
-
return globalThis[OPENTELEMETRY_CONFIG_SYMBOL];
|
|
238
|
-
}
|
|
239
|
-
function startSpan(options) {
|
|
240
|
-
const tracer = getOpenTelemetryConfig()?.tracer;
|
|
241
|
-
if (!tracer) {
|
|
242
|
-
return void 0;
|
|
243
|
-
}
|
|
244
|
-
const { name, context, ...spanOptions } = typeof options === "string" ? { name: options } : options;
|
|
245
|
-
return tracer.startSpan(name, spanOptions, context);
|
|
246
|
-
}
|
|
247
|
-
function recordSpanError(span, error) {
|
|
248
|
-
if (!span) {
|
|
249
|
-
return;
|
|
250
|
-
}
|
|
251
|
-
const exception = toOtelException(error);
|
|
252
|
-
span.recordException(exception);
|
|
253
|
-
if (!isAbortError(error)) {
|
|
254
|
-
span.setStatus({
|
|
255
|
-
code: SPAN_ERROR_STATUS,
|
|
256
|
-
message: exception.message
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
function setSpanAttributeIfDefined(span, key, value) {
|
|
261
|
-
if (!span || value === void 0) {
|
|
262
|
-
return;
|
|
263
|
-
}
|
|
264
|
-
span.setAttribute(key, value);
|
|
265
|
-
}
|
|
266
|
-
function toOtelException(error) {
|
|
267
|
-
if (error instanceof Error) {
|
|
268
|
-
const exception = {
|
|
269
|
-
message: error.message,
|
|
270
|
-
name: error.name,
|
|
271
|
-
stack: error.stack
|
|
272
|
-
};
|
|
273
|
-
if ("code" in error && (typeof error.code === "string" || typeof error.code === "number")) {
|
|
274
|
-
exception.code = error.code;
|
|
275
|
-
}
|
|
276
|
-
return exception;
|
|
277
|
-
}
|
|
278
|
-
return { message: String(error) };
|
|
279
|
-
}
|
|
280
|
-
function toSpanAttributeValue(data) {
|
|
281
|
-
if (data === void 0) {
|
|
282
|
-
return "undefined";
|
|
283
|
-
}
|
|
284
|
-
try {
|
|
285
|
-
return JSON.stringify(data, (_, value) => {
|
|
286
|
-
if (typeof value === "bigint") {
|
|
287
|
-
return value.toString();
|
|
288
|
-
}
|
|
289
|
-
if (value instanceof Map || value instanceof Set) {
|
|
290
|
-
return Array.from(value);
|
|
291
|
-
}
|
|
292
|
-
return value;
|
|
293
|
-
});
|
|
294
|
-
} catch {
|
|
295
|
-
return String(data);
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
async function runWithSpan(options, fn) {
|
|
299
|
-
const tracer = getOpenTelemetryConfig()?.tracer;
|
|
300
|
-
if (!tracer) {
|
|
301
|
-
return fn();
|
|
302
|
-
}
|
|
303
|
-
if (typeof options === "string") {
|
|
304
|
-
options = { name: options };
|
|
305
|
-
}
|
|
306
|
-
const callback = async (span) => {
|
|
307
|
-
try {
|
|
308
|
-
return await fn(span);
|
|
309
|
-
} catch (e) {
|
|
310
|
-
recordSpanError(span, e);
|
|
311
|
-
throw e;
|
|
312
|
-
} finally {
|
|
313
|
-
span.end();
|
|
314
|
-
}
|
|
315
|
-
};
|
|
316
|
-
if (options.context) {
|
|
317
|
-
return tracer.startActiveSpan(options.name, options, options.context, callback);
|
|
318
|
-
} else {
|
|
319
|
-
return tracer.startActiveSpan(options.name, options, callback);
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
async function runInSpanContext(span, fn) {
|
|
323
|
-
const otelConfig = getOpenTelemetryConfig();
|
|
324
|
-
if (!span || !otelConfig) {
|
|
325
|
-
return fn();
|
|
326
|
-
}
|
|
327
|
-
const ctx = otelConfig.trace.setSpan(otelConfig.context.active(), span);
|
|
328
|
-
return otelConfig.context.with(ctx, fn);
|
|
329
|
-
}
|
|
330
|
-
|
|
331
242
|
class AsyncIdQueue {
|
|
332
243
|
openIds = /* @__PURE__ */ new Set();
|
|
333
244
|
queues = /* @__PURE__ */ new Map();
|
|
@@ -402,6 +313,93 @@ class AsyncIdQueue {
|
|
|
402
313
|
}
|
|
403
314
|
}
|
|
404
315
|
|
|
316
|
+
const TRACER_SYMBOL = Symbol.for("ORPC_TRACER");
|
|
317
|
+
function setTracer(tracer) {
|
|
318
|
+
globalThis[TRACER_SYMBOL] = tracer;
|
|
319
|
+
}
|
|
320
|
+
function getTracer() {
|
|
321
|
+
return globalThis[TRACER_SYMBOL];
|
|
322
|
+
}
|
|
323
|
+
function startSpan(options) {
|
|
324
|
+
const tracer = getTracer();
|
|
325
|
+
if (!tracer) {
|
|
326
|
+
return void 0;
|
|
327
|
+
}
|
|
328
|
+
if (typeof options === "string") {
|
|
329
|
+
return tracer.startSpan(options);
|
|
330
|
+
}
|
|
331
|
+
return tracer.startSpan(options.name, options.parent);
|
|
332
|
+
}
|
|
333
|
+
function recordSpanError(span, error) {
|
|
334
|
+
if (!span) {
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
span.recordException(isAbortError(error) ? "info" : "error", toTracingException(error));
|
|
338
|
+
}
|
|
339
|
+
function setSpanAttributeIfDefined(span, key, value) {
|
|
340
|
+
if (!span || value === void 0) {
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
span.setAttribute(key, value);
|
|
344
|
+
}
|
|
345
|
+
function toTracingException(error) {
|
|
346
|
+
if (error instanceof Error) {
|
|
347
|
+
const exception = {
|
|
348
|
+
message: error.message,
|
|
349
|
+
name: error.name,
|
|
350
|
+
stack: error.stack
|
|
351
|
+
};
|
|
352
|
+
if ("code" in error && (typeof error.code === "string" || typeof error.code === "number")) {
|
|
353
|
+
exception.code = error.code;
|
|
354
|
+
}
|
|
355
|
+
return exception;
|
|
356
|
+
}
|
|
357
|
+
return { message: String(error) };
|
|
358
|
+
}
|
|
359
|
+
function toSpanAttributeValue(data) {
|
|
360
|
+
if (data === void 0) {
|
|
361
|
+
return "undefined";
|
|
362
|
+
}
|
|
363
|
+
try {
|
|
364
|
+
return JSON.stringify(data, (_, value) => {
|
|
365
|
+
if (typeof value === "bigint") {
|
|
366
|
+
return value.toString();
|
|
367
|
+
}
|
|
368
|
+
if (value instanceof Map || value instanceof Set) {
|
|
369
|
+
return Array.from(value);
|
|
370
|
+
}
|
|
371
|
+
return value;
|
|
372
|
+
});
|
|
373
|
+
} catch {
|
|
374
|
+
return String(data);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
async function runWithSpan(options, fn) {
|
|
378
|
+
const tracer = getTracer();
|
|
379
|
+
if (!tracer) {
|
|
380
|
+
return fn();
|
|
381
|
+
}
|
|
382
|
+
const name = typeof options === "string" ? options : options.name;
|
|
383
|
+
const parent = typeof options === "string" ? void 0 : options.parent;
|
|
384
|
+
return tracer.startActiveSpan(name, parent, async (span) => {
|
|
385
|
+
try {
|
|
386
|
+
return await fn(span);
|
|
387
|
+
} catch (e) {
|
|
388
|
+
recordSpanError(span, e);
|
|
389
|
+
throw e;
|
|
390
|
+
} finally {
|
|
391
|
+
span.end();
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
function runInSpanContext(span, fn) {
|
|
396
|
+
const tracer = getTracer();
|
|
397
|
+
if (!span || !tracer) {
|
|
398
|
+
return fn();
|
|
399
|
+
}
|
|
400
|
+
return tracer.withActiveSpan(span, fn);
|
|
401
|
+
}
|
|
402
|
+
|
|
405
403
|
function wrapAsyncIterator(iterator, { runWith, mapResult, mapError, onError, onFinish }) {
|
|
406
404
|
runWith ??= (run) => run();
|
|
407
405
|
let isDone;
|
|
@@ -556,8 +554,8 @@ function findDeepMatches(check, payload, segments = [], maps = [], values = [])
|
|
|
556
554
|
findDeepMatches(check, v, [...segments, i], maps, values);
|
|
557
555
|
});
|
|
558
556
|
} else if (isPlainObject(payload)) {
|
|
559
|
-
for (const key
|
|
560
|
-
findDeepMatches(check,
|
|
557
|
+
for (const [key, value] of Object.entries(payload)) {
|
|
558
|
+
findDeepMatches(check, value, [...segments, key], maps, values);
|
|
561
559
|
}
|
|
562
560
|
}
|
|
563
561
|
return { maps, values };
|
|
@@ -593,10 +591,10 @@ function getOwn(object, key) {
|
|
|
593
591
|
function get(object, path) {
|
|
594
592
|
let current = object;
|
|
595
593
|
for (const key of path) {
|
|
596
|
-
if (!isTypescriptObject(current)
|
|
594
|
+
if (!isTypescriptObject(current)) {
|
|
597
595
|
return void 0;
|
|
598
596
|
}
|
|
599
|
-
current = current
|
|
597
|
+
current = getOwn(current, key);
|
|
600
598
|
}
|
|
601
599
|
return current;
|
|
602
600
|
}
|
|
@@ -604,7 +602,7 @@ function set(root, path, value) {
|
|
|
604
602
|
let current = root;
|
|
605
603
|
for (let i = 0; i < path.length - 1; i++) {
|
|
606
604
|
const key = path[i];
|
|
607
|
-
const next =
|
|
605
|
+
const next = getOwn(current, key);
|
|
608
606
|
if (!isTypescriptObject(next)) {
|
|
609
607
|
const child = {};
|
|
610
608
|
setOwn(current, key, child);
|
|
@@ -674,8 +672,8 @@ function cloneWithVisited(value, visited) {
|
|
|
674
672
|
}
|
|
675
673
|
const result = {};
|
|
676
674
|
visited.set(value, result);
|
|
677
|
-
for (const key
|
|
678
|
-
setOwn(result, key, cloneWithVisited(
|
|
675
|
+
for (const [key, item] of Object.entries(value)) {
|
|
676
|
+
setOwn(result, key, cloneWithVisited(item, visited));
|
|
679
677
|
}
|
|
680
678
|
for (const sym of Object.getOwnPropertySymbols(value)) {
|
|
681
679
|
setOwn(result, sym, cloneWithVisited(value[sym], visited));
|
|
@@ -1092,4 +1090,4 @@ async function runWithSignal(signal, fn) {
|
|
|
1092
1090
|
}
|
|
1093
1091
|
}
|
|
1094
1092
|
|
|
1095
|
-
export { AsyncIdQueue, NullProtoObj, ORPC_NAME, allAbortSignal, anyAbortSignal, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, bindMethods, clone, compareSequentialIds, consumeAsyncIterator, defer, findDeepMatches, get, getConstructor, getConstructors,
|
|
1093
|
+
export { AsyncIdQueue, NullProtoObj, ORPC_NAME, allAbortSignal, anyAbortSignal, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, bindMethods, clone, compareSequentialIds, consumeAsyncIterator, defer, findDeepMatches, get, getConstructor, getConstructors, getOwn, getTracer, intercept, isAbortError, isAsyncGeneratorFunction, isCompressibleContentType, isDeepEqual, isNoTransformCacheControl, isPlainObject, isPropertyKey, loadBytes, matchesHttpPath, matchesHttpPathPrefix, mergeHttpPath, mergeTwoLevels, normalizeHttpPath, omit, onAsyncIteratorObjectError, onError, onFinish, onReadableStreamError, onStart, onSuccess, once, override, parseAcceptEncodingQualities, pathToHttpPath, promiseWithResolvers, recordSpanError, replicateAsyncIterator, replicateReadableStream, resolveMaybeOptionalOptions, runInSpanContext, runWithSignal, runWithSpan, safeDecodeURIComponent, safeEncodeURIComponent, set, setOwn, setSpanAttributeIfDefined, setTracer, sortPlugins, splitInHalf, startSpan, streamToAsyncIteratorObject, toSpanAttributeValue, toStringOrBytes, toTracingException, traceAsyncIterator, traceReadableStream, tryOrUndefined, value, varyByAcceptEncoding, wrapAsyncIterator, wrapReadableStream };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/shared",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.36",
|
|
5
5
|
"description": "Internal utilities shared across oRPC packages",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": [
|
|
@@ -29,23 +29,14 @@
|
|
|
29
29
|
"files": [
|
|
30
30
|
"dist"
|
|
31
31
|
],
|
|
32
|
-
"peerDependencies": {
|
|
33
|
-
"@opentelemetry/api": ">=1.9.0"
|
|
34
|
-
},
|
|
35
|
-
"peerDependenciesMeta": {
|
|
36
|
-
"@opentelemetry/api": {
|
|
37
|
-
"optional": true
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
32
|
"dependencies": {
|
|
41
33
|
"@standard-server/shared": "~0.9.0",
|
|
42
34
|
"radash": "^12.1.1",
|
|
43
35
|
"type-fest": "^5.3.1"
|
|
44
36
|
},
|
|
45
37
|
"devDependencies": {
|
|
46
|
-
"@opentelemetry/api": "^1.9.1",
|
|
47
38
|
"arktype": "^2.2.1",
|
|
48
|
-
"valibot": "^1.
|
|
39
|
+
"valibot": "^1.5.0",
|
|
49
40
|
"zod": "^4.5.4"
|
|
50
41
|
},
|
|
51
42
|
"scripts": {
|