@orpc/shared
Advanced tools
+23
-8
@@ -94,3 +94,6 @@ import { Arrayable, Promisable } from 'type-fest'; | ||
| /** | ||
| * Can used for interceptors or middlewares | ||
| * Creates an interceptor or middleware that invokes a callback whenever an error | ||
| * is thrown. The error is rethrown after the callback completes. | ||
| * | ||
| * @see {@link https://orpc.dev/docs/adapters/fetch-api | Fetch API Adapter} | ||
| */ | ||
@@ -198,3 +201,4 @@ declare function onError<T, TOptions extends { | ||
| * | ||
| * @info If iterator is canceled, `undefined` can be passed on success | ||
| * @remarks | ||
| * **Note**: If iterator is canceled, `undefined` can be passed on success | ||
| */ | ||
@@ -205,3 +209,4 @@ onSuccess?: (value: TReturn | undefined) => void; | ||
| * | ||
| * @info If iterator is canceled, `undefined` can be passed on success | ||
| * @remarks | ||
| * **Note**: If iterator is canceled, `undefined` can be passed on success | ||
| */ | ||
@@ -211,6 +216,9 @@ onFinish?: (state: [error: TError, data: undefined, isSuccess: false] | [error: null, data: TReturn | undefined, isSuccess: true]) => void; | ||
| /** | ||
| * Consumes an AsyncIteratorObject with lifecycle callbacks | ||
| * Consumes an AsyncIteratorObject with lifecycle callbacks. | ||
| * | ||
| * @warning If no `onError` or `onFinish` is provided, error will be thrown into unhandled rejection channel. | ||
| * @return unsubscribe callback | ||
| * @remarks | ||
| * **Warning**: If no `onError` or `onFinish` is provided, errors are thrown into the unhandled rejection channel. | ||
| * | ||
| * @returns An unsubscribe callback that stops consuming and cleans up the iterator. | ||
| * @see {@link https://orpc.dev/docs/client/async-iterator-object#using-consumeasynciterator | AsyncIteratorObject in Client - Using consumeAsyncIterator} | ||
| */ | ||
@@ -229,2 +237,3 @@ declare function consumeAsyncIterator<T, TReturn, TError = ThrowableError>(iterator: AsyncIterator<T, TReturn> | PromiseWithError<AsyncIterator<T, TReturn>, TError>, options: ConsumeAsyncIteratorOptions<T, TReturn, TError | ThrowableError>): () => Promise<void>; | ||
| declare function getConstructor(value: unknown): Function | null | undefined; | ||
| declare function getConstructors(value: unknown): Generator<Function>; | ||
| /** | ||
@@ -253,3 +262,5 @@ * Checks whether a value is a plain object, including objects created with | ||
| */ | ||
| declare function bindMethods<T extends object>(obj: T): Pick<T, { | ||
| declare function bindMethods<T extends object>(obj: T, options?: { | ||
| unbound?: (keyof T)[]; | ||
| }): Pick<T, { | ||
| [K in keyof T]: T[K] extends AnyFunction ? K : never; | ||
@@ -354,2 +365,4 @@ }[keyof T]>; | ||
| * Converts a {@link ReadableStream} into an {@link AsyncIteratorClass}. | ||
| * | ||
| * @see {@link https://orpc.dev/docs/integrations/ai-sdk | AI SDK Integration} | ||
| */ | ||
@@ -366,2 +379,4 @@ declare function streamToAsyncIteratorObject<T>(stream: ReadableStream<T>, { signal }?: { | ||
| * all emitted object values are *unproxied* before enqueuing. | ||
| * | ||
| * @see {@link https://orpc.dev/docs/integrations/ai-sdk | AI SDK Integration} | ||
| */ | ||
@@ -372,3 +387,3 @@ declare function asyncIteratorToUnproxiedDataStream<T>(iterator: AsyncIterator<T>): ReadableStream<T>; | ||
| export { AsyncIdQueue, NullProtoObj, ORPC_NAME, allAbortSignal, anyAbortSignal, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, bindMethods, clone, compareSequentialIds, consumeAsyncIterator, defer, findDeepMatches, get, getConstructor, getOpenTelemetryConfig, intercept, isAbortError, isCompressibleContentType, isDeepEqual, isPlainObject, isPropertyKey, loadBytes, matchesHttpPath, matchesHttpPathPrefix, mergeHttpPath, normalizeHttpPath, omit, onAsyncIteratorObjectError, onError, onFinish, onReadableStreamError, onStart, onSuccess, once, override, pathToHttpPath, promiseWithResolvers, recordSpanError, replicateAsyncIterator, replicateReadableStream, resolveMaybeOptionalOptions, runInSpanContext, runWithSignal, runWithSpan, set, setOpenTelemetryConfig, setSpanAttributeIfDefined, sortPlugins, splitInHalf, startSpan, streamToAsyncIteratorObject, toOtelException, toSpanAttributeValue, toStringOrBytes, traceAsyncIterator, traceReadableStream, tryDecodeURIComponent, tryOrUndefined, value, wrapAsyncIterator, wrapReadableStream }; | ||
| export { AsyncIdQueue, NullProtoObj, ORPC_NAME, allAbortSignal, anyAbortSignal, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, bindMethods, clone, compareSequentialIds, consumeAsyncIterator, defer, findDeepMatches, get, getConstructor, getConstructors, getOpenTelemetryConfig, intercept, isAbortError, isCompressibleContentType, isDeepEqual, isPlainObject, isPropertyKey, loadBytes, matchesHttpPath, matchesHttpPathPrefix, mergeHttpPath, normalizeHttpPath, omit, onAsyncIteratorObjectError, onError, onFinish, onReadableStreamError, onStart, onSuccess, once, override, pathToHttpPath, promiseWithResolvers, recordSpanError, replicateAsyncIterator, replicateReadableStream, resolveMaybeOptionalOptions, runInSpanContext, runWithSignal, runWithSpan, set, setOpenTelemetryConfig, setSpanAttributeIfDefined, sortPlugins, splitInHalf, startSpan, streamToAsyncIteratorObject, toOtelException, toSpanAttributeValue, toStringOrBytes, traceAsyncIterator, traceReadableStream, tryDecodeURIComponent, tryOrUndefined, value, wrapAsyncIterator, wrapReadableStream }; | ||
| export type { AnyFunction, AsyncIdQueueCloseOptions, ConsumeAsyncIteratorOptions, InterceptableOptions, Interceptor, InterceptorOptions, IntersectPick, MaybeOptionalOptions, OnFinishState, OpenTelemetryConfig, OrderablePlugin, PromiseWithError, Public, ReadableStreamReadResult, Registry, RunWithSpanOptions, Segment, StartSpanOptions, ThrowableError, Value, WrapAsyncIteratorOptions, WrapReadableStreamOptions }; |
+23
-8
@@ -94,3 +94,6 @@ import { Arrayable, Promisable } from 'type-fest'; | ||
| /** | ||
| * Can used for interceptors or middlewares | ||
| * Creates an interceptor or middleware that invokes a callback whenever an error | ||
| * is thrown. The error is rethrown after the callback completes. | ||
| * | ||
| * @see {@link https://orpc.dev/docs/adapters/fetch-api | Fetch API Adapter} | ||
| */ | ||
@@ -198,3 +201,4 @@ declare function onError<T, TOptions extends { | ||
| * | ||
| * @info If iterator is canceled, `undefined` can be passed on success | ||
| * @remarks | ||
| * **Note**: If iterator is canceled, `undefined` can be passed on success | ||
| */ | ||
@@ -205,3 +209,4 @@ onSuccess?: (value: TReturn | undefined) => void; | ||
| * | ||
| * @info If iterator is canceled, `undefined` can be passed on success | ||
| * @remarks | ||
| * **Note**: If iterator is canceled, `undefined` can be passed on success | ||
| */ | ||
@@ -211,6 +216,9 @@ onFinish?: (state: [error: TError, data: undefined, isSuccess: false] | [error: null, data: TReturn | undefined, isSuccess: true]) => void; | ||
| /** | ||
| * Consumes an AsyncIteratorObject with lifecycle callbacks | ||
| * Consumes an AsyncIteratorObject with lifecycle callbacks. | ||
| * | ||
| * @warning If no `onError` or `onFinish` is provided, error will be thrown into unhandled rejection channel. | ||
| * @return unsubscribe callback | ||
| * @remarks | ||
| * **Warning**: If no `onError` or `onFinish` is provided, errors are thrown into the unhandled rejection channel. | ||
| * | ||
| * @returns An unsubscribe callback that stops consuming and cleans up the iterator. | ||
| * @see {@link https://orpc.dev/docs/client/async-iterator-object#using-consumeasynciterator | AsyncIteratorObject in Client - Using consumeAsyncIterator} | ||
| */ | ||
@@ -229,2 +237,3 @@ declare function consumeAsyncIterator<T, TReturn, TError = ThrowableError>(iterator: AsyncIterator<T, TReturn> | PromiseWithError<AsyncIterator<T, TReturn>, TError>, options: ConsumeAsyncIteratorOptions<T, TReturn, TError | ThrowableError>): () => Promise<void>; | ||
| declare function getConstructor(value: unknown): Function | null | undefined; | ||
| declare function getConstructors(value: unknown): Generator<Function>; | ||
| /** | ||
@@ -253,3 +262,5 @@ * Checks whether a value is a plain object, including objects created with | ||
| */ | ||
| declare function bindMethods<T extends object>(obj: T): Pick<T, { | ||
| declare function bindMethods<T extends object>(obj: T, options?: { | ||
| unbound?: (keyof T)[]; | ||
| }): Pick<T, { | ||
| [K in keyof T]: T[K] extends AnyFunction ? K : never; | ||
@@ -354,2 +365,4 @@ }[keyof T]>; | ||
| * Converts a {@link ReadableStream} into an {@link AsyncIteratorClass}. | ||
| * | ||
| * @see {@link https://orpc.dev/docs/integrations/ai-sdk | AI SDK Integration} | ||
| */ | ||
@@ -366,2 +379,4 @@ declare function streamToAsyncIteratorObject<T>(stream: ReadableStream<T>, { signal }?: { | ||
| * all emitted object values are *unproxied* before enqueuing. | ||
| * | ||
| * @see {@link https://orpc.dev/docs/integrations/ai-sdk | AI SDK Integration} | ||
| */ | ||
@@ -372,3 +387,3 @@ declare function asyncIteratorToUnproxiedDataStream<T>(iterator: AsyncIterator<T>): ReadableStream<T>; | ||
| export { AsyncIdQueue, NullProtoObj, ORPC_NAME, allAbortSignal, anyAbortSignal, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, bindMethods, clone, compareSequentialIds, consumeAsyncIterator, defer, findDeepMatches, get, getConstructor, getOpenTelemetryConfig, intercept, isAbortError, isCompressibleContentType, isDeepEqual, isPlainObject, isPropertyKey, loadBytes, matchesHttpPath, matchesHttpPathPrefix, mergeHttpPath, normalizeHttpPath, omit, onAsyncIteratorObjectError, onError, onFinish, onReadableStreamError, onStart, onSuccess, once, override, pathToHttpPath, promiseWithResolvers, recordSpanError, replicateAsyncIterator, replicateReadableStream, resolveMaybeOptionalOptions, runInSpanContext, runWithSignal, runWithSpan, set, setOpenTelemetryConfig, setSpanAttributeIfDefined, sortPlugins, splitInHalf, startSpan, streamToAsyncIteratorObject, toOtelException, toSpanAttributeValue, toStringOrBytes, traceAsyncIterator, traceReadableStream, tryDecodeURIComponent, tryOrUndefined, value, wrapAsyncIterator, wrapReadableStream }; | ||
| export { AsyncIdQueue, NullProtoObj, ORPC_NAME, allAbortSignal, anyAbortSignal, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, bindMethods, clone, compareSequentialIds, consumeAsyncIterator, defer, findDeepMatches, get, getConstructor, getConstructors, getOpenTelemetryConfig, intercept, isAbortError, isCompressibleContentType, isDeepEqual, isPlainObject, isPropertyKey, loadBytes, matchesHttpPath, matchesHttpPathPrefix, mergeHttpPath, normalizeHttpPath, omit, onAsyncIteratorObjectError, onError, onFinish, onReadableStreamError, onStart, onSuccess, once, override, pathToHttpPath, promiseWithResolvers, recordSpanError, replicateAsyncIterator, replicateReadableStream, resolveMaybeOptionalOptions, runInSpanContext, runWithSignal, runWithSpan, set, setOpenTelemetryConfig, setSpanAttributeIfDefined, sortPlugins, splitInHalf, startSpan, streamToAsyncIteratorObject, toOtelException, toSpanAttributeValue, toStringOrBytes, traceAsyncIterator, traceReadableStream, tryDecodeURIComponent, tryOrUndefined, value, wrapAsyncIterator, wrapReadableStream }; | ||
| export type { AnyFunction, AsyncIdQueueCloseOptions, ConsumeAsyncIteratorOptions, InterceptableOptions, Interceptor, InterceptorOptions, IntersectPick, MaybeOptionalOptions, OnFinishState, OpenTelemetryConfig, OrderablePlugin, PromiseWithError, Public, ReadableStreamReadResult, Registry, RunWithSpanOptions, Segment, StartSpanOptions, ThrowableError, Value, WrapAsyncIteratorOptions, WrapReadableStreamOptions }; |
+19
-6
@@ -538,2 +538,14 @@ import { AbortError, AsyncIteratorClass, getOrBind, isTypescriptObject, isAsyncIteratorObject } from '@standardserver/shared'; | ||
| } | ||
| function* getConstructors(value) { | ||
| if (!isTypescriptObject(value)) { | ||
| return; | ||
| } | ||
| let proto = Object.getPrototypeOf(value); | ||
| while (proto != null) { | ||
| if (proto.constructor) { | ||
| yield proto.constructor; | ||
| } | ||
| proto = Object.getPrototypeOf(proto); | ||
| } | ||
| } | ||
| function isPlainObject(value) { | ||
@@ -613,3 +625,4 @@ if (!value || typeof value !== "object") { | ||
| })(); | ||
| function bindMethods(obj) { | ||
| function bindMethods(obj, options = {}) { | ||
| const unbound = new Set(options.unbound); | ||
| const methods = new NullProtoObj(); | ||
@@ -622,5 +635,5 @@ let current = obj; | ||
| } | ||
| const val = obj[key]; | ||
| const val = getOrBind(obj, key, { bind: !unbound.has(key) }); | ||
| if (typeof val === "function") { | ||
| methods[key] = val.bind(obj); | ||
| methods[key] = val; | ||
| } | ||
@@ -632,5 +645,5 @@ } | ||
| } | ||
| const val = obj[sym]; | ||
| const val = getOrBind(obj, sym, { bind: !unbound.has(sym) }); | ||
| if (typeof val === "function") { | ||
| methods[sym] = val.bind(obj); | ||
| methods[sym] = val; | ||
| } | ||
@@ -1012,2 +1025,2 @@ } | ||
| export { AsyncIdQueue, NullProtoObj, ORPC_NAME, allAbortSignal, anyAbortSignal, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, bindMethods, clone, compareSequentialIds, consumeAsyncIterator, defer, findDeepMatches, get, getConstructor, getOpenTelemetryConfig, intercept, isAbortError, isCompressibleContentType, isDeepEqual, isPlainObject, isPropertyKey, loadBytes, matchesHttpPath, matchesHttpPathPrefix, mergeHttpPath, normalizeHttpPath, omit, onAsyncIteratorObjectError, onError, onFinish, onReadableStreamError, onStart, onSuccess, once, override, pathToHttpPath, promiseWithResolvers, recordSpanError, replicateAsyncIterator, replicateReadableStream, resolveMaybeOptionalOptions, runInSpanContext, runWithSignal, runWithSpan, set, setOpenTelemetryConfig, setSpanAttributeIfDefined, sortPlugins, splitInHalf, startSpan, streamToAsyncIteratorObject, toOtelException, toSpanAttributeValue, toStringOrBytes, traceAsyncIterator, traceReadableStream, tryDecodeURIComponent, tryOrUndefined, value, wrapAsyncIterator, wrapReadableStream }; | ||
| export { AsyncIdQueue, NullProtoObj, ORPC_NAME, allAbortSignal, anyAbortSignal, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, bindMethods, clone, compareSequentialIds, consumeAsyncIterator, defer, findDeepMatches, get, getConstructor, getConstructors, getOpenTelemetryConfig, intercept, isAbortError, isCompressibleContentType, isDeepEqual, isPlainObject, isPropertyKey, loadBytes, matchesHttpPath, matchesHttpPathPrefix, mergeHttpPath, normalizeHttpPath, omit, onAsyncIteratorObjectError, onError, onFinish, onReadableStreamError, onStart, onSuccess, once, override, pathToHttpPath, promiseWithResolvers, recordSpanError, replicateAsyncIterator, replicateReadableStream, resolveMaybeOptionalOptions, runInSpanContext, runWithSignal, runWithSpan, set, setOpenTelemetryConfig, setSpanAttributeIfDefined, sortPlugins, splitInHalf, startSpan, streamToAsyncIteratorObject, toOtelException, toSpanAttributeValue, toStringOrBytes, traceAsyncIterator, traceReadableStream, tryDecodeURIComponent, tryOrUndefined, value, wrapAsyncIterator, wrapReadableStream }; |
+2
-2
| { | ||
| "name": "@orpc/shared", | ||
| "type": "module", | ||
| "version": "2.0.0-beta.23", | ||
| "version": "2.0.0-beta.24", | ||
| "license": "MIT", | ||
@@ -36,3 +36,3 @@ "homepage": "https://orpc.dev", | ||
| "dependencies": { | ||
| "@standardserver/shared": "^0.6.0", | ||
| "@standardserver/shared": "^0.7.1", | ||
| "radash": "^12.1.1", | ||
@@ -39,0 +39,0 @@ "type-fest": "^5.3.1" |
+4
-1
@@ -47,2 +47,3 @@ <h1 align="center">oRPC - Typesafe APIs Made Simple 🪄</h1> | ||
| - [@orpc/ratelimit](https://www.npmjs.com/package/@orpc/ratelimit): Rate limiting with memory, Redis, and Upstash adapters. | ||
| - [@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). | ||
| - [@orpc/json-schema](https://www.npmjs.com/package/@orpc/json-schema): Smart coercion for OpenAPI requests. | ||
@@ -118,2 +119,3 @@ | ||
| <td align="center"><a href="https://github.com/itigoore01?ref=orpc" target="_blank" rel="noopener" title="shota"><img src="https://avatars.githubusercontent.com/u/11831107?u=c976a6dc7e055eb026304c46c99100ed22b0c8e0&v=4" width="139" alt="shota"/><br />shota</a></td> | ||
| <td align="center"><a href="https://github.com/ellis-driscoll?ref=orpc" target="_blank" rel="noopener" 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> | ||
| </tr> | ||
@@ -144,4 +146,5 @@ </table> | ||
| <tr> | ||
| <td align="center"><a href="https://github.com/guyariely?ref=orpc" target="_blank" rel="noopener" title="Guy Ariely"><img src="https://avatars.githubusercontent.com/u/42813496?u=edb6b7f563bf28e160a290832e7da57c0506f8ca&v=4" width="119" alt="Guy Ariely"/><br />Guy Ariely</a></td> | ||
| <td align="center"><a href="https://github.com/piscis?ref=orpc" target="_blank" rel="noopener" title="Alex"><img src="https://avatars.githubusercontent.com/u/326163?u=b245f368bd940cf51d08c0b6bf55f8257f359437&v=4" width="119" alt="Alex"/><br />Alex</a></td> | ||
| <td align="center"><a href="https://github.com/finom?ref=orpc" target="_blank" rel="noopener" title="Andrey Gubanov"><img src="https://avatars.githubusercontent.com/u/1082083?u=29e91400dbd4a9c217048a8f59562c4f740498e6&v=4" width="119" alt="Andrey Gubanov"/><br />Andrey Gubanov</a></td> | ||
| <td align="center"><a href="https://github.com/finom?ref=orpc" target="_blank" rel="noopener" title="Andrey Gubanov"><img src="https://avatars.githubusercontent.com/u/1082083?u=c5f2daf7ebece498e85c83367bb37b4e10e2649d&v=4" width="119" alt="Andrey Gubanov"/><br />Andrey Gubanov</a></td> | ||
| </tr> | ||
@@ -148,0 +151,0 @@ </table> |
93604
3.03%1369
2.09%203
1.5%+ Added
- Removed