@orpc/shared 2.0.0-beta.50 → 2.0.0-beta.52
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 +11 -10
- package/dist/args.d.ts +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +1 -1
- package/dist/interceptor.d.ts +20 -14
- package/dist/interceptor.js +2 -11
- package/dist/iterator.d.ts +1 -2
- package/dist/stream.d.ts +1 -2
- package/dist/tracing.d.ts +4 -10
- package/dist/tracing.js +11 -16
- package/dist/types.d.ts +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -78,13 +78,14 @@ Read the full documentation at [orpc.dev](https://orpc.dev), starting with the [
|
|
|
78
78
|
|
|
79
79
|
**Built-in features**
|
|
80
80
|
|
|
81
|
-
| Package
|
|
82
|
-
|
|
|
83
|
-
| [@orpc/publisher](https://www.npmjs.com/package/@orpc/publisher)
|
|
84
|
-
| [@orpc/ratelimit](https://www.npmjs.com/package/@orpc/ratelimit)
|
|
85
|
-
| [@orpc/experimental-lock](https://www.npmjs.com/package/@orpc/experimental-lock)
|
|
86
|
-
| [@orpc/
|
|
87
|
-
| [@orpc/
|
|
81
|
+
| Package | Purpose | Docs |
|
|
82
|
+
| ---------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
|
|
83
|
+
| [@orpc/publisher](https://www.npmjs.com/package/@orpc/publisher) | Pub/Sub with memory, Redis, and Upstash adapters. | [Publisher](https://orpc.dev/docs/helpers/publisher) |
|
|
84
|
+
| [@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) |
|
|
85
|
+
| [@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) |
|
|
86
|
+
| [@orpc/experimental-openapi-inference](https://www.npmjs.com/package/@orpc/experimental-openapi-inference) | Generate OpenAPI specs from TypeScript types, no output schemas required. | [Type Inference](https://orpc.dev/docs/openapi/specification#type-inference) |
|
|
87
|
+
| [@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) |
|
|
88
|
+
| [@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) |
|
|
88
89
|
|
|
89
90
|
**Framework & ecosystem integrations**
|
|
90
91
|
|
|
@@ -182,16 +183,16 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
|
|
|
182
183
|
<td align="center"><a href="https://github.com/pumpkinlink?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Denis"><img src="https://avatars.githubusercontent.com/u/11864620?u=5f47bbe6c65d0f6f5cf011021490238e4b0593d0&v=4" width="139" alt="Denis"/><br />Denis</a></td>
|
|
183
184
|
<td align="center"><a href="https://github.com/christopher-kapic?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Christopher Kapic"><img src="https://avatars.githubusercontent.com/u/59740769?u=e7ad4b72b5bf6c9eb1644c26dbf3332a8f987377&v=4" width="139" alt="Christopher Kapic"/><br />Christopher Kapic</a></td>
|
|
184
185
|
<td align="center"><a href="http://ballingt.com/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Tom Ballinger"><img src="https://avatars.githubusercontent.com/u/458879?u=4b045ac75d721b6ac2b42a74d7d37f61f0414031&v=4" width="139" alt="Tom Ballinger"/><br />Tom Ballinger</a></td>
|
|
185
|
-
<td align="center"><a href="https://lee-sam.com/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Sam"><img src="https://avatars.githubusercontent.com/u/102863520?u=3c89611f549d5070be232eb4532f690c8f2e7a65&v=4" width="139" alt="Sam"/><br />Sam</a></td>
|
|
186
186
|
<td align="center"><a href="https://github.com/Titoine?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Titoine"><img src="https://avatars.githubusercontent.com/u/3514286?u=1bb1e86b0c99c8a1121372e56d51a177eea12191&v=4" width="139" alt="Titoine"/><br />Titoine</a></td>
|
|
187
187
|
<td align="center"><a href="https://rigtch.fm/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Igor Makowski"><img src="https://avatars.githubusercontent.com/u/56691628?u=ee8c879478f7c151b9156aef6c74243fa3e247a8&v=4" width="139" alt="Igor Makowski"/><br />Igor Makowski</a></td>
|
|
188
|
+
<td align="center"><a href="https://blog.cwang.io/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="hanayashiki"><img src="https://avatars.githubusercontent.com/u/26056783?u=06c3b9205a16fd41a871e82da1cc2a09306d53f5&v=4" width="139" alt="hanayashiki"/><br />hanayashiki</a></td>
|
|
188
189
|
</tr>
|
|
189
190
|
<tr>
|
|
190
|
-
<td align="center"><a href="https://blog.cwang.io/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="hanayashiki"><img src="https://avatars.githubusercontent.com/u/26056783?u=06c3b9205a16fd41a871e82da1cc2a09306d53f5&v=4" width="139" alt="hanayashiki"/><br />hanayashiki</a></td>
|
|
191
191
|
<td align="center"><a href="https://dubinets.io/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Lev Dubinets"><img src="https://avatars.githubusercontent.com/u/3114081?u=f547f5d5012cab54851f1b1ad72d10e537f78fc2&v=4" width="139" alt="Lev Dubinets"/><br />Lev Dubinets</a></td>
|
|
192
192
|
<td align="center"><a href="https://kellychan.im/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Kelly Peilin Chan"><img src="https://avatars.githubusercontent.com/u/520852?u=6b0f7105f694e7b5cacf410a3f04c7044b469dc8&v=4" width="139" alt="Kelly Peilin Chan"/><br />Kelly Peilin Chan</a></td>
|
|
193
193
|
<td align="center"><a href="https://guyariely.com/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Guy Ariely"><img src="https://avatars.githubusercontent.com/u/42813496?u=edb6b7f563bf28e160a290832e7da57c0506f8ca&v=4" width="139" alt="Guy Ariely"/><br />Guy Ariely</a></td>
|
|
194
194
|
<td align="center"><a href="https://paulsenon.com/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="PaulSenon"><img src="https://avatars.githubusercontent.com/u/19531087?u=6385741eb91d200b8c513ec6045482e301767ca6&v=4" width="139" alt="PaulSenon"/><br />PaulSenon</a></td>
|
|
195
|
+
<td align="center"><a href="https://usagerail.com/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="UsageRail"><img src="https://avatars.githubusercontent.com/u/347653714?v=4" width="139" alt="UsageRail"/><br />UsageRail</a></td>
|
|
195
196
|
<td align="center"><a href="https://piscis.dev/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Alex"><img src="https://avatars.githubusercontent.com/u/326163?u=b245f368bd940cf51d08c0b6bf55f8257f359437&v=4" width="139" alt="Alex"/><br />Alex</a></td>
|
|
196
197
|
</tr>
|
|
197
198
|
<tr>
|
|
@@ -199,7 +200,7 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
|
|
|
199
200
|
</tr>
|
|
200
201
|
</table>
|
|
201
202
|
|
|
202
|
-
With thanks to [
|
|
203
|
+
With thanks to [41 past sponsors](https://orpc.dev/sponsors#past-sponsors) who helped get oRPC here.
|
|
203
204
|
|
|
204
205
|
## Open Source Programs
|
|
205
206
|
|
package/dist/args.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export type MaybeOptionalOptions<TOptions> =
|
|
1
|
+
export type MaybeOptionalOptions<TOptions> = {} extends TOptions ? [options?: TOptions] : [options: TOptions];
|
|
2
2
|
export declare function resolveMaybeOptionalOptions<T>(rest: MaybeOptionalOptions<T>): T;
|
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { isAbortError } from "./error.js";
|
|
|
8
8
|
import { AnyFunction, defer, isAsyncGeneratorFunction, once, tryOrUndefined } from "./function.js";
|
|
9
9
|
import { CompressionEncoding, estimateCompressibleFormDataSize, estimateUtf8ByteLength, isAcceptableEncoding, isCompressibleContentType, isCompressionEncoding, isNoTransformCacheControl, matchesHttpPath, matchesHttpPathPrefix, mergeHttpPath, normalizeHttpPath, parseAcceptEncodingQualities, parseContentEncodings, pathToHttpPath, stripHttpPathPrefix, varyByAcceptEncoding } from "./http.js";
|
|
10
10
|
import { compareSequentialIds } from "./id.js";
|
|
11
|
-
import { InterceptableOptions, Interceptor, InterceptorOptions, OnFinishState, intercept, onAsyncIteratorObjectError, onError, onFinish, onReadableStreamError, onStart, onSuccess } from "./interceptor.js";
|
|
11
|
+
import { InferNextError, InterceptableOptions, Interceptor, InterceptorOptions, OnFinishState, intercept, onAsyncIteratorObjectError, onError, onFinish, onReadableStreamError, onStart, onSuccess } from "./interceptor.js";
|
|
12
12
|
import { ConsumeAsyncIteratorOptions, WrapAsyncIteratorOptions, consumeAsyncIterator, replicateAsyncIterator, traceAsyncIterator, wrapAsyncIterator } from "./iterator.js";
|
|
13
13
|
import { NullProtoObj, Segment, bindMethods, clone, copyOnWrite, findDeepMatches, get, getConstructor, getConstructors, getOwn, isPlainObject, isPlainObjectOrArray, isPropertyKey, mergeTwoLevels, omit, pick, set, setOwn } from "./object.js";
|
|
14
14
|
import { OrderablePlugin, sortPlugins } from "./plugin.js";
|
|
@@ -18,9 +18,9 @@ import { AsyncIdQueue, AsyncIdQueueCloseOptions } from "./queue.js";
|
|
|
18
18
|
import { INTEGER_REGEX, NON_NEGATIVE_INTEGER_REGEX } from "./regex.js";
|
|
19
19
|
import { DisposableAllAbortSignal, anyAbortSignal, disposableAllAbortSignal, listenAbort, runWithSignal } from "./signal.js";
|
|
20
20
|
import { ReadableStreamReadResult, WrapReadableStreamOptions, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, replicateReadableStream, streamToAsyncIteratorObject, traceReadableStream, wrapReadableStream } from "./stream.js";
|
|
21
|
-
import { StartSpanOptions, Tracer, TracingAttributeValue,
|
|
22
|
-
import { DistributiveOmit, IntersectPick, PromiseWithError, Public, Registry, ThrowableError } from "./types.js";
|
|
21
|
+
import { StartSpanOptions, Tracer, TracingAttributeValue, TracingExceptionLevel, TracingHeaders, TracingSpan, getTracer, recordSpanError, runInSpanContext, runWithSpan, setSpanAttributeIfDefined, setTracer, startSpan, toSpanAttributeValue } from "./tracing.js";
|
|
22
|
+
import { DistributiveOmit, IntersectPick, Promisable, PromiseWithError, Public, Registry, ThrowableError } from "./types.js";
|
|
23
23
|
import { Value, value } from "./value.js";
|
|
24
24
|
import { AbortError, AsyncCleanupFn, AsyncIteratorClass, AsyncIteratorClassNextFn, SequentialIdGenerator, getOrBind, isAsyncIteratorObject, isNonPrimitive, isNonPrimitive as isTypescriptObject, parseEmptyableJSON, safeDecodeURIComponent, safeEncodeURIComponent, sequential, sleep, stringifyJSON, throwIfAborted, toArray } from "@standard-server/shared";
|
|
25
|
-
import { Arrayable, IsEqual, PartialDeep,
|
|
26
|
-
export { AbortError, AnyFunction, type Arrayable, type AsyncCleanupFn, AsyncIdQueue, AsyncIdQueueCloseOptions, AsyncIteratorClass, type AsyncIteratorClassNextFn, CompressionEncoding, ConsumeAsyncIteratorOptions, DEFAULT_MAX_BIGINT_DIGITS, DisposableAllAbortSignal, DistributiveOmit, INTEGER_REGEX, InterceptableOptions, Interceptor, InterceptorOptions, IntersectPick, type IsEqual, MaybeOptionalOptions, NON_NEGATIVE_INTEGER_REGEX, NullProtoObj, ORPC_NAME, OnFinishState, OrderablePlugin, type PartialDeep,
|
|
25
|
+
import { Arrayable, IsEqual, PartialDeep, Writable } from "type-fest";
|
|
26
|
+
export { AbortError, AnyFunction, type Arrayable, type AsyncCleanupFn, AsyncIdQueue, AsyncIdQueueCloseOptions, AsyncIteratorClass, type AsyncIteratorClassNextFn, CompressionEncoding, ConsumeAsyncIteratorOptions, DEFAULT_MAX_BIGINT_DIGITS, DisposableAllAbortSignal, DistributiveOmit, INTEGER_REGEX, InferNextError, InterceptableOptions, Interceptor, InterceptorOptions, IntersectPick, type IsEqual, MaybeOptionalOptions, NON_NEGATIVE_INTEGER_REGEX, NullProtoObj, ORPC_NAME, OnFinishState, OrderablePlugin, type PartialDeep, Promisable, PromiseWithError, Public, ReadableStreamReadResult, Registry, Segment, SequentialIdGenerator, StartSpanOptions, ThrowableError, Tracer, TracingAttributeValue, TracingExceptionLevel, TracingHeaders, TracingSpan, Value, WrapAsyncIteratorOptions, WrapReadableStreamOptions, type Writable, anyAbortSignal, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, bindMethods, captureAsyncContext, clone, compareSequentialIds, consumeAsyncIterator, copyOnWrite, defer, disposableAllAbortSignal, encodeBase64, estimateCompressibleFormDataSize, estimateUtf8ByteLength, findDeepMatches, get, getConstructor, getConstructors, getOrBind, getOwn, getTracer, intercept, isAbortError, isAcceptableEncoding, isAsyncGeneratorFunction, isAsyncIteratorObject, isCompressibleContentType, isCompressionEncoding, isDeepEqual, isNoTransformCacheControl, isNonPrimitive, isPlainObject as isObject, isPlainObject, isPlainObjectOrArray, isPropertyKey, isTypescriptObject, listenAbort, loadBytes, matchesHttpPath, matchesHttpPathPrefix, mergeHttpPath, mergeTwoLevels, normalizeHttpPath, omit, onAsyncIteratorObjectError, onError, onFinish, onReadableStreamError, onStart, onSuccess, once, override, parseAcceptEncodingQualities, parseBigIntString, parseContentEncodings, parseEmptyableJSON, pathToHttpPath, pick, promiseWithResolvers, recordSpanError, replicateAsyncIterator, replicateReadableStream, resolveMaybeOptionalOptions, runInSpanContext, runWithSignal, runWithSpan, safeDecodeURIComponent, safeEncodeURIComponent, sequential, set, setOwn, setSpanAttributeIfDefined, setTracer, sleep, sortPlugins, splitInHalf, startSpan, streamToAsyncIteratorObject, stringifyJSON, stripHttpPathPrefix, takeLast, throwIfAborted, toArray, toSpanAttributeValue, toStringOrBytes, traceAsyncIterator, traceReadableStream, tryOrUndefined, value, varyByAcceptEncoding, wrapAsyncIterator, wrapReadableStream };
|
package/dist/index.js
CHANGED
|
@@ -18,6 +18,6 @@ export { AsyncIdQueue } from "./queue.js";
|
|
|
18
18
|
export { INTEGER_REGEX, NON_NEGATIVE_INTEGER_REGEX } from "./regex.js";
|
|
19
19
|
export { anyAbortSignal, disposableAllAbortSignal, listenAbort, runWithSignal } from "./signal.js";
|
|
20
20
|
export { asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, replicateReadableStream, streamToAsyncIteratorObject, traceReadableStream, wrapReadableStream } from "./stream.js";
|
|
21
|
-
export { getTracer, recordSpanError, runInSpanContext, runWithSpan, setSpanAttributeIfDefined, setTracer, startSpan, toSpanAttributeValue
|
|
21
|
+
export { getTracer, recordSpanError, runInSpanContext, runWithSpan, setSpanAttributeIfDefined, setTracer, startSpan, toSpanAttributeValue } from "./tracing.js";
|
|
22
22
|
export { value } from "./value.js";
|
|
23
23
|
export { AbortError, AsyncIteratorClass, SequentialIdGenerator, getOrBind, isAsyncIteratorObject, isNonPrimitive, isNonPrimitive as isTypescriptObject, parseEmptyableJSON, safeDecodeURIComponent, safeEncodeURIComponent, sequential, sleep, stringifyJSON, throwIfAborted, toArray } from "@standard-server/shared";
|
package/dist/interceptor.d.ts
CHANGED
|
@@ -1,38 +1,44 @@
|
|
|
1
|
-
import { PromiseWithError, ThrowableError } from "./types.js";
|
|
2
|
-
import { Promisable } from "type-fest";
|
|
1
|
+
import { Promisable, PromiseWithError, ThrowableError } from "./types.js";
|
|
3
2
|
export type InterceptableOptions = Record<string, any>;
|
|
4
3
|
export type InterceptorOptions<TOptions extends InterceptableOptions, TResult> = Omit<TOptions, "next"> & {
|
|
5
4
|
next(options?: TOptions): TResult;
|
|
6
5
|
};
|
|
7
6
|
export type Interceptor<TOptions extends InterceptableOptions, TResult> = (options: InterceptorOptions<TOptions, TResult>) => TResult;
|
|
7
|
+
/**
|
|
8
|
+
* Infers the error type of `next()` from `PromiseWithError`, or `unknown` when
|
|
9
|
+
* `next()` doesn't carry a typed error (e.g. it returns a plain promise).
|
|
10
|
+
*/
|
|
11
|
+
export type InferNextError<TOptions extends {
|
|
12
|
+
next: () => any;
|
|
13
|
+
}> = ReturnType<TOptions["next"]> extends PromiseWithError<any, infer E> ? E : unknown;
|
|
8
14
|
/**
|
|
9
15
|
* Can used for interceptors or middlewares
|
|
10
16
|
*/
|
|
11
|
-
export declare function onStart<
|
|
17
|
+
export declare function onStart<TOptions extends {
|
|
12
18
|
next: () => any;
|
|
13
|
-
}, TRest extends any[]>(callback: NoInfer<(options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) =>
|
|
19
|
+
}, TRest extends any[]>(callback: NoInfer<(options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => Promise<Awaited<ReturnType<TOptions["next"]>>>;
|
|
14
20
|
/**
|
|
15
21
|
* Can used for interceptors or middlewares
|
|
16
22
|
*/
|
|
17
|
-
export declare function onSuccess<
|
|
23
|
+
export declare function onSuccess<TOptions extends {
|
|
18
24
|
next: () => any;
|
|
19
|
-
}, TRest extends any[]>(callback: NoInfer<(result: Awaited<ReturnType<TOptions["next"]>>, options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) =>
|
|
25
|
+
}, TRest extends any[]>(callback: NoInfer<(result: Awaited<ReturnType<TOptions["next"]>>, options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => Promise<Awaited<ReturnType<TOptions["next"]>>>;
|
|
20
26
|
/**
|
|
21
27
|
* Creates an interceptor or middleware that invokes a callback whenever an error
|
|
22
28
|
* is thrown. The error is rethrown after the callback completes.
|
|
23
29
|
*
|
|
24
30
|
* @see {@link https://orpc.dev/docs/adapters/fetch-api | Fetch API Adapter}
|
|
25
31
|
*/
|
|
26
|
-
export declare function onError<
|
|
32
|
+
export declare function onError<TOptions extends {
|
|
27
33
|
next: () => any;
|
|
28
|
-
}, TRest extends any[]>(callback: NoInfer<(error:
|
|
34
|
+
}, TRest extends any[]>(callback: NoInfer<(error: InferNextError<TOptions>, options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => Promise<Awaited<ReturnType<TOptions["next"]>>>;
|
|
29
35
|
export type OnFinishState<TResult, TError> = [error: TError, data: undefined, isSuccess: false] | [error: null, data: TResult, isSuccess: true];
|
|
30
36
|
/**
|
|
31
37
|
* Can used for interceptors or middlewares
|
|
32
38
|
*/
|
|
33
|
-
export declare function onFinish<
|
|
39
|
+
export declare function onFinish<TOptions extends {
|
|
34
40
|
next: () => any;
|
|
35
|
-
}, TRest extends any[]>(callback: NoInfer<(state: OnFinishState<Awaited<ReturnType<TOptions["next"]>>,
|
|
41
|
+
}, TRest extends any[]>(callback: NoInfer<(state: OnFinishState<Awaited<ReturnType<TOptions["next"]>>, InferNextError<TOptions>>, options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => Promise<Awaited<ReturnType<TOptions["next"]>>>;
|
|
36
42
|
/**
|
|
37
43
|
* Creates a middleware or interceptor that invokes a callback when the returned async
|
|
38
44
|
* iterator object throws an error while being consumed.
|
|
@@ -42,9 +48,9 @@ export declare function onFinish<T, TOptions extends {
|
|
|
42
48
|
* callback only fires while consuming the iterator. Use both together to
|
|
43
49
|
* catch all possible errors.
|
|
44
50
|
*/
|
|
45
|
-
export declare function onAsyncIteratorObjectError<
|
|
51
|
+
export declare function onAsyncIteratorObjectError<TOptions extends {
|
|
46
52
|
next: () => any;
|
|
47
|
-
}, TRest extends any[]>(callback: NoInfer<(error: ThrowableError |
|
|
53
|
+
}, TRest extends any[]>(callback: NoInfer<(error: ThrowableError | InferNextError<TOptions>, options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => Promise<Awaited<ReturnType<TOptions["next"]>>>;
|
|
48
54
|
/**
|
|
49
55
|
* Creates an interceptor that invokes a callback when the returned readable
|
|
50
56
|
* stream errors while being consumed.
|
|
@@ -54,7 +60,7 @@ export declare function onAsyncIteratorObjectError<T, TOptions extends {
|
|
|
54
60
|
* callback only fires while consuming the stream. Use both together to catch
|
|
55
61
|
* all possible errors.
|
|
56
62
|
*/
|
|
57
|
-
export declare function onReadableStreamError<
|
|
63
|
+
export declare function onReadableStreamError<TOptions extends {
|
|
58
64
|
next: () => any;
|
|
59
|
-
}, TRest extends any[]>(callback: NoInfer<(error: ThrowableError |
|
|
65
|
+
}, TRest extends any[]>(callback: NoInfer<(error: ThrowableError | InferNextError<TOptions>, options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => Promise<Awaited<ReturnType<TOptions["next"]>>>;
|
|
60
66
|
export declare function intercept<TOptions extends InterceptableOptions, TResult>(interceptors: undefined | Interceptor<TOptions, TResult>[], options: NoInfer<TOptions>, main: NoInfer<(options: TOptions) => TResult>): TResult;
|
package/dist/interceptor.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { wrapAsyncIterator } from "./iterator.js";
|
|
2
|
-
import { override } from "./proxy.js";
|
|
3
2
|
import { wrapReadableStream } from "./stream.js";
|
|
4
3
|
import { isAsyncIteratorObject } from "@standard-server/shared";
|
|
5
4
|
// src/interceptor.ts
|
|
@@ -77,11 +76,7 @@ function onAsyncIteratorObjectError(callback) {
|
|
|
77
76
|
return async (options, ...rest) => {
|
|
78
77
|
const output = await options.next();
|
|
79
78
|
if (!isAsyncIteratorObject(output)) return output;
|
|
80
|
-
|
|
81
|
-
* @warning
|
|
82
|
-
* Remember use `override` for AsyncIteratorObject to remain other special properties
|
|
83
|
-
*/
|
|
84
|
-
return override(output, wrapAsyncIterator(output, { onError: (error) => callback(error, options, ...rest) }));
|
|
79
|
+
return wrapAsyncIterator(output, { onError: (error) => callback(error, options, ...rest) });
|
|
85
80
|
};
|
|
86
81
|
}
|
|
87
82
|
/**
|
|
@@ -97,11 +92,7 @@ function onReadableStreamError(callback) {
|
|
|
97
92
|
return async (options, ...rest) => {
|
|
98
93
|
const output = await options.next();
|
|
99
94
|
if (!(output instanceof ReadableStream)) return output;
|
|
100
|
-
|
|
101
|
-
* @warning
|
|
102
|
-
* Remember use `override` for ReadableStream to remain other special properties
|
|
103
|
-
*/
|
|
104
|
-
return override(output, wrapReadableStream(output, { onError: (error) => callback(error, options, ...rest) }));
|
|
95
|
+
return wrapReadableStream(output, { onError: (error) => callback(error, options, ...rest) });
|
|
105
96
|
};
|
|
106
97
|
}
|
|
107
98
|
function intercept(interceptors, options, main) {
|
package/dist/iterator.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { StartSpanOptions } from "./tracing.js";
|
|
2
|
-
import { PromiseWithError, ThrowableError } from "./types.js";
|
|
2
|
+
import { Promisable, PromiseWithError, ThrowableError } from "./types.js";
|
|
3
3
|
import { AsyncIteratorClass } from "@standard-server/shared";
|
|
4
|
-
import { Promisable } from "type-fest";
|
|
5
4
|
export interface WrapAsyncIteratorOptions<TYield, TReturn, TMappedYield, TMappedReturn> {
|
|
6
5
|
/**
|
|
7
6
|
* Any call to the original iterator will be executed inside this function.
|
package/dist/stream.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { StartSpanOptions } from "./tracing.js";
|
|
2
|
-
import { ThrowableError } from "./types.js";
|
|
2
|
+
import { Promisable, ThrowableError } from "./types.js";
|
|
3
3
|
import { AsyncIteratorClass } from "@standard-server/shared";
|
|
4
|
-
import { Promisable } from "type-fest";
|
|
5
4
|
export declare function replicateReadableStream<T>(stream: ReadableStream<T>, count: number): ReadableStream<T>[];
|
|
6
5
|
export type ReadableStreamReadResult<T> = {
|
|
7
6
|
done: false;
|
package/dist/tracing.d.ts
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
import { Promisable } from "
|
|
1
|
+
import { Promisable } from "./types.js";
|
|
2
2
|
export type TracingAttributeValue = string | number | boolean | string[] | number[] | boolean[];
|
|
3
|
-
export interface TracingException {
|
|
4
|
-
name?: string;
|
|
5
|
-
message: string;
|
|
6
|
-
stack?: string;
|
|
7
|
-
code?: string | number;
|
|
8
|
-
}
|
|
9
3
|
export type TracingHeaders = Record<string, string | string[] | undefined>;
|
|
10
4
|
export type TracingExceptionLevel = "error" | "info";
|
|
11
5
|
export interface TracingSpan {
|
|
@@ -19,9 +13,10 @@ export interface TracingSpan {
|
|
|
19
13
|
*/
|
|
20
14
|
addEvent(name: string): void;
|
|
21
15
|
/**
|
|
22
|
-
* Records
|
|
16
|
+
* Records a thrown value on the span, the backend decides how to serialize it.
|
|
17
|
+
* The `error` level also marks the span as failed.
|
|
23
18
|
*/
|
|
24
|
-
recordException(level: TracingExceptionLevel,
|
|
19
|
+
recordException(level: TracingExceptionLevel, error: unknown): void;
|
|
25
20
|
end(): void;
|
|
26
21
|
}
|
|
27
22
|
/**
|
|
@@ -67,7 +62,6 @@ export interface StartSpanOptions {
|
|
|
67
62
|
export declare function startSpan(options: StartSpanOptions | string): TracingSpan | undefined;
|
|
68
63
|
export declare function recordSpanError(span: TracingSpan | undefined, error: unknown): void;
|
|
69
64
|
export declare function setSpanAttributeIfDefined(span: TracingSpan | undefined, key: string, value: TracingAttributeValue | undefined): void;
|
|
70
|
-
export declare function toTracingException(error: unknown): TracingException;
|
|
71
65
|
export declare function toSpanAttributeValue(data: unknown): string;
|
|
72
66
|
export declare function runWithSpan<T>(options: string | StartSpanOptions, fn: (span?: TracingSpan) => Promisable<T>): Promise<T>;
|
|
73
67
|
export declare function runInSpanContext<T>(span: TracingSpan | undefined, fn: () => Promisable<T>): Promisable<T>;
|
package/dist/tracing.js
CHANGED
|
@@ -15,24 +15,12 @@ function startSpan(options) {
|
|
|
15
15
|
}
|
|
16
16
|
function recordSpanError(span, error) {
|
|
17
17
|
if (!span) return;
|
|
18
|
-
span.recordException(isAbortError(error) ? "info" : "error",
|
|
18
|
+
span.recordException(isAbortError(error) ? "info" : "error", error);
|
|
19
19
|
}
|
|
20
20
|
function setSpanAttributeIfDefined(span, key, value) {
|
|
21
21
|
if (!span || value === void 0) return;
|
|
22
22
|
span.setAttribute(key, value);
|
|
23
23
|
}
|
|
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) };
|
|
35
|
-
}
|
|
36
24
|
function toSpanAttributeValue(data) {
|
|
37
25
|
if (data === void 0) return "undefined";
|
|
38
26
|
try {
|
|
@@ -45,9 +33,16 @@ function toSpanAttributeValue(data) {
|
|
|
45
33
|
return String(data);
|
|
46
34
|
}
|
|
47
35
|
}
|
|
48
|
-
|
|
36
|
+
function runWithSpan(options, fn) {
|
|
49
37
|
const tracer = getTracer();
|
|
50
|
-
if (!tracer)
|
|
38
|
+
if (!tracer) try {
|
|
39
|
+
return Promise.resolve(fn());
|
|
40
|
+
} catch (e) {
|
|
41
|
+
return Promise.reject(e);
|
|
42
|
+
}
|
|
43
|
+
return runWithTracerSpan(tracer, options, fn);
|
|
44
|
+
}
|
|
45
|
+
async function runWithTracerSpan(tracer, options, fn) {
|
|
51
46
|
const name = typeof options === "string" ? options : options.name;
|
|
52
47
|
const parent = typeof options === "string" ? void 0 : options.parent;
|
|
53
48
|
return tracer.startActiveSpan(name, parent, async (span) => {
|
|
@@ -66,4 +61,4 @@ function runInSpanContext(span, fn) {
|
|
|
66
61
|
if (!span || !tracer) return fn();
|
|
67
62
|
return tracer.withActiveSpan(span, fn);
|
|
68
63
|
}
|
|
69
|
-
export { getTracer, recordSpanError, runInSpanContext, runWithSpan, setSpanAttributeIfDefined, setTracer, startSpan, toSpanAttributeValue
|
|
64
|
+
export { getTracer, recordSpanError, runInSpanContext, runWithSpan, setSpanAttributeIfDefined, setTracer, startSpan, toSpanAttributeValue };
|
package/dist/types.d.ts
CHANGED
|
@@ -7,6 +7,10 @@ export type DistributiveOmit<T, K extends PropertyKey> = { [P in keyof T as P ex
|
|
|
7
7
|
* Remove protected/private properties/methods
|
|
8
8
|
*/
|
|
9
9
|
export type Public<T> = Pick<T, keyof T>;
|
|
10
|
+
/**
|
|
11
|
+
* A value, or a promise or thenable of it.
|
|
12
|
+
*/
|
|
13
|
+
export type Promisable<T> = Promise<T> | T | PromiseLike<T>;
|
|
10
14
|
export type PromiseWithError<T, TError> = Promise<T> & {
|
|
11
15
|
__error?: {
|
|
12
16
|
type: TError;
|