@orpc/shared 2.0.0-beta.50 → 2.0.0-beta.51
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 +10 -8
- package/dist/args.d.ts +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/interceptor.d.ts +20 -14
- package/dist/iterator.d.ts +1 -2
- package/dist/stream.d.ts +1 -2
- package/dist/tracing.d.ts +1 -1
- package/dist/tracing.js +9 -2
- 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
|
|
|
@@ -192,9 +193,10 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
|
|
|
192
193
|
<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
194
|
<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
195
|
<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://
|
|
196
|
+
<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>
|
|
196
197
|
</tr>
|
|
197
198
|
<tr>
|
|
199
|
+
<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>
|
|
198
200
|
<td align="center"><a href="https://opensource.gubanov.eu/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Andrey Gubanov"><img src="https://avatars.githubusercontent.com/u/1082083?u=c5f2daf7ebece498e85c83367bb37b4e10e2649d&v=4" width="139" alt="Andrey Gubanov"/><br />Andrey Gubanov</a></td>
|
|
199
201
|
</tr>
|
|
200
202
|
</table>
|
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";
|
|
@@ -19,8 +19,8 @@ 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
21
|
import { StartSpanOptions, Tracer, TracingAttributeValue, TracingException, TracingExceptionLevel, TracingHeaders, TracingSpan, getTracer, recordSpanError, runInSpanContext, runWithSpan, setSpanAttributeIfDefined, setTracer, startSpan, toSpanAttributeValue, toTracingException } from "./tracing.js";
|
|
22
|
-
import { DistributiveOmit, IntersectPick, PromiseWithError, Public, Registry, ThrowableError } from "./types.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, TracingException, 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, toTracingException, traceAsyncIterator, traceReadableStream, tryOrUndefined, value, varyByAcceptEncoding, wrapAsyncIterator, wrapReadableStream };
|
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/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
package/dist/tracing.js
CHANGED
|
@@ -45,9 +45,16 @@ function toSpanAttributeValue(data) {
|
|
|
45
45
|
return String(data);
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
-
|
|
48
|
+
function runWithSpan(options, fn) {
|
|
49
49
|
const tracer = getTracer();
|
|
50
|
-
if (!tracer)
|
|
50
|
+
if (!tracer) try {
|
|
51
|
+
return Promise.resolve(fn());
|
|
52
|
+
} catch (e) {
|
|
53
|
+
return Promise.reject(e);
|
|
54
|
+
}
|
|
55
|
+
return runWithTracerSpan(tracer, options, fn);
|
|
56
|
+
}
|
|
57
|
+
async function runWithTracerSpan(tracer, options, fn) {
|
|
51
58
|
const name = typeof options === "string" ? options : options.name;
|
|
52
59
|
const parent = typeof options === "string" ? void 0 : options.parent;
|
|
53
60
|
return tracer.startActiveSpan(name, parent, async (span) => {
|
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;
|