@orpc/shared 2.0.0-beta.47 → 2.0.0-beta.48
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 +2 -3
- package/dist/args.d.mts +2 -0
- package/dist/args.mjs +3 -0
- package/dist/array.d.mts +2 -0
- package/dist/array.mjs +7 -0
- package/dist/bigint.d.mts +9 -0
- package/dist/bigint.mjs +12 -0
- package/dist/buffer.d.mts +18 -0
- package/dist/buffer.mjs +66 -0
- package/dist/compare.d.mts +1 -0
- package/dist/compare.mjs +43 -0
- package/dist/consts.d.mts +1 -0
- package/dist/consts.mjs +1 -0
- package/dist/error.d.mts +1 -0
- package/dist/error.mjs +3 -0
- package/dist/function.d.mts +12 -0
- package/dist/function.mjs +31 -0
- package/dist/http.d.mts +29 -0
- package/dist/http.mjs +83 -0
- package/dist/id.d.mts +8 -0
- package/dist/id.mjs +7 -0
- package/dist/index.d.mts +25 -492
- package/dist/index.mjs +23 -1117
- package/dist/interceptor.d.mts +96 -0
- package/dist/interceptor.mjs +102 -0
- package/dist/iterator.d.mts +82 -0
- package/dist/iterator.mjs +151 -0
- package/dist/object.d.mts +64 -0
- package/dist/object.mjs +221 -0
- package/dist/plugin.d.mts +12 -0
- package/dist/plugin.mjs +58 -0
- package/dist/promise.d.mts +17 -0
- package/dist/promise.mjs +23 -0
- package/dist/proxy.d.mts +15 -0
- package/dist/proxy.mjs +15 -0
- package/dist/queue.d.mts +16 -0
- package/dist/queue.mjs +74 -0
- package/dist/signal.d.mts +13 -0
- package/dist/signal.mjs +74 -0
- package/dist/stream.d.mts +54 -0
- package/dist/stream.mjs +138 -0
- package/dist/tracing.d.mts +73 -0
- package/dist/tracing.mjs +89 -0
- package/dist/types.d.mts +32 -0
- package/dist/types.mjs +1 -0
- package/dist/value.d.mts +8 -0
- package/dist/value.mjs +6 -0
- package/package.json +3 -4
- package/dist/index.d.ts +0 -492
package/dist/index.d.ts
DELETED
|
@@ -1,492 +0,0 @@
|
|
|
1
|
-
import { Arrayable, Promisable } from 'type-fest';
|
|
2
|
-
export { Arrayable, IsEqual, PartialDeep, Promisable, Writable } from 'type-fest';
|
|
3
|
-
import { AsyncIteratorClass } from '@standard-server/shared';
|
|
4
|
-
export { AbortError, AsyncCleanupFn, AsyncIteratorClass, AsyncIteratorClassNextFn, SequentialIdGenerator, getOrBind, isAsyncIteratorObject, isTypescriptObject, parseEmptyableJSON, safeDecodeURIComponent, safeEncodeURIComponent, sequential, sleep, stringifyJSON, throwIfAborted, toArray } from '@standard-server/shared';
|
|
5
|
-
|
|
6
|
-
type MaybeOptionalOptions<TOptions> = object extends TOptions ? [options?: TOptions] : [options: TOptions];
|
|
7
|
-
declare function resolveMaybeOptionalOptions<T>(rest: MaybeOptionalOptions<T>): T;
|
|
8
|
-
|
|
9
|
-
declare function splitInHalf<T>(arr: readonly T[]): [T[], T[]];
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Default maximum digits, excluding a leading `-`, when parsing a `bigint` from a string.
|
|
13
|
-
*/
|
|
14
|
-
declare const DEFAULT_MAX_BIGINT_DIGITS = 4300;
|
|
15
|
-
/**
|
|
16
|
-
* Parses a `bigint.toString()` string, or returns `undefined` if it is invalid or has more than `maxDigits` digits.
|
|
17
|
-
* The length is checked first, since `BigInt()` is super-linear in the digit count.
|
|
18
|
-
*/
|
|
19
|
-
declare function parseBigIntString(value: string, maxDigits: number): bigint | undefined;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Load Request/Response/Blob/File/.. to a buffer (Uint8Array<ArrayBuffer>).
|
|
23
|
-
*
|
|
24
|
-
* Prefers the newer `.bytes` method when available as it more efficient but not widely supported yet.
|
|
25
|
-
*/
|
|
26
|
-
declare function loadBytes(source: Pick<Blob, 'arrayBuffer' | 'bytes'>): ReturnType<Blob['bytes']>;
|
|
27
|
-
/**
|
|
28
|
-
* Normalize text or binary-like inputs to either:
|
|
29
|
-
* - the original string value, or
|
|
30
|
-
* - a Uint8Array view over the source bytes.
|
|
31
|
-
*/
|
|
32
|
-
declare function toStringOrBytes(source: Arrayable<string | ArrayBuffer | Pick<Uint8Array<ArrayBuffer>, 'buffer' | 'byteOffset' | 'byteLength'>>): string | Awaited<ReturnType<Blob['bytes']>>;
|
|
33
|
-
/**
|
|
34
|
-
* Encodes bytes to standard, padded base64, as data URLs and many protocols require.
|
|
35
|
-
* Prefers the native `toBase64` or `Buffer`, which are far faster for large outputs.
|
|
36
|
-
*/
|
|
37
|
-
declare function encodeBase64(bytes: Uint8Array): string;
|
|
38
|
-
|
|
39
|
-
declare function isDeepEqual(a: unknown, b: unknown): boolean;
|
|
40
|
-
|
|
41
|
-
declare const ORPC_NAME = "orpc";
|
|
42
|
-
|
|
43
|
-
declare function isAbortError(error: unknown): error is Error;
|
|
44
|
-
|
|
45
|
-
type AnyFunction = (...args: any[]) => any;
|
|
46
|
-
/**
|
|
47
|
-
* Checks whether a value is an async generator function (`async function*`).
|
|
48
|
-
*/
|
|
49
|
-
declare function isAsyncGeneratorFunction(value: unknown): value is (...args: any[]) => AsyncGenerator;
|
|
50
|
-
declare function once<T>(fn: () => T): () => T;
|
|
51
|
-
/**
|
|
52
|
-
* Executes the callback function after the current call stack has been cleared,
|
|
53
|
-
* waiting at least `delay` ms when `setTimeout` is available.
|
|
54
|
-
*/
|
|
55
|
-
declare function defer(callback: () => void, delay?: number): void;
|
|
56
|
-
declare function tryOrUndefined<T>(fn: () => T): undefined | T;
|
|
57
|
-
|
|
58
|
-
declare function pathToHttpPath(path: readonly string[]): `/${string}`;
|
|
59
|
-
declare function normalizeHttpPath(path: string): `/${string}`;
|
|
60
|
-
declare function mergeHttpPath(a: `/${string}`, b: `/${string}`): `/${string}`;
|
|
61
|
-
declare function matchesHttpPathPrefix(url: `/${string}`, prefix: `/${string}`): boolean;
|
|
62
|
-
declare function matchesHttpPath(url: `/${string}`, path: `/${string}`): boolean;
|
|
63
|
-
/**
|
|
64
|
-
* Parse Accept-Encoding into each coding's q-value, where `0` means the coding is explicitly
|
|
65
|
-
* unacceptable. The `*` wildcard is kept under its own key; use {@link isAcceptableEncoding}
|
|
66
|
-
* to decide whether a coding is acceptable.
|
|
67
|
-
*
|
|
68
|
-
* @see https://www.rfc-editor.org/rfc/rfc9110.html#name-accept-encoding
|
|
69
|
-
*/
|
|
70
|
-
declare function parseAcceptEncodingQualities(header: string | undefined): Map<string, number>;
|
|
71
|
-
/**
|
|
72
|
-
* Whether the client accepts a coding, given qualities from {@link parseAcceptEncodingQualities}.
|
|
73
|
-
* An explicit q-value takes precedence over the `*` wildcard, so `gzip;q=0, *` never accepts gzip.
|
|
74
|
-
*
|
|
75
|
-
* @see https://www.rfc-editor.org/rfc/rfc9110.html#name-accept-encoding
|
|
76
|
-
*/
|
|
77
|
-
declare function isAcceptableEncoding(qualities: Map<string, number>, coding: string): boolean;
|
|
78
|
-
/**
|
|
79
|
-
* Add `accept-encoding` to a Vary header value. The encoding is chosen from the request, so a
|
|
80
|
-
* shared cache must key on it or it will hand a compressed body to a client that cannot decode it.
|
|
81
|
-
*
|
|
82
|
-
* @see https://www.rfc-editor.org/rfc/rfc9110.html#name-vary
|
|
83
|
-
*/
|
|
84
|
-
declare function varyByAcceptEncoding(vary: string | undefined): string;
|
|
85
|
-
declare function isNoTransformCacheControl(cacheControl: string | undefined): boolean;
|
|
86
|
-
declare function isCompressibleContentType(contentType: string | null | undefined): boolean;
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Compares two sequential IDs.
|
|
90
|
-
* Returns:
|
|
91
|
-
* - negative if `a` < `b`
|
|
92
|
-
* - positive if `a` > `b`
|
|
93
|
-
* - 0 if equal
|
|
94
|
-
*/
|
|
95
|
-
declare function compareSequentialIds(a: string, b: string): number;
|
|
96
|
-
|
|
97
|
-
type IntersectPick<T, U> = Pick<T, keyof T & keyof U>;
|
|
98
|
-
/**
|
|
99
|
-
* Like `Omit`, but distributes over unions and keeps known keys beside index signatures.
|
|
100
|
-
*/
|
|
101
|
-
type DistributiveOmit<T, K extends PropertyKey> = {
|
|
102
|
-
[P in keyof T as P extends K ? never : P]: T[P];
|
|
103
|
-
};
|
|
104
|
-
/**
|
|
105
|
-
* Remove protected/private properties/methods
|
|
106
|
-
*/
|
|
107
|
-
type Public<T> = Pick<T, keyof T>;
|
|
108
|
-
type PromiseWithError<T, TError> = Promise<T> & {
|
|
109
|
-
__error?: {
|
|
110
|
-
type: TError;
|
|
111
|
-
};
|
|
112
|
-
};
|
|
113
|
-
/**
|
|
114
|
-
* The place where you can config the orpc types.
|
|
115
|
-
*
|
|
116
|
-
* - `ThrowableError` the error type that represent throwable errors should be `Error` or `null | undefined | {}` if you want more strict.
|
|
117
|
-
*/
|
|
118
|
-
interface Registry {
|
|
119
|
-
}
|
|
120
|
-
type ThrowableError = Registry extends {
|
|
121
|
-
ThrowableError: infer T;
|
|
122
|
-
} ? T : Error;
|
|
123
|
-
|
|
124
|
-
type InterceptableOptions = Record<string, any>;
|
|
125
|
-
type InterceptorOptions<TOptions extends InterceptableOptions, TResult> = Omit<TOptions, 'next'> & {
|
|
126
|
-
next(options?: TOptions): TResult;
|
|
127
|
-
};
|
|
128
|
-
type Interceptor<TOptions extends InterceptableOptions, TResult> = (options: InterceptorOptions<TOptions, TResult>) => TResult;
|
|
129
|
-
/**
|
|
130
|
-
* Can used for interceptors or middlewares
|
|
131
|
-
*/
|
|
132
|
-
declare function onStart<T, TOptions extends {
|
|
133
|
-
next: () => any;
|
|
134
|
-
}, TRest extends any[]>(callback: NoInfer<(options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => T | Promise<Awaited<ReturnType<TOptions['next']>>>;
|
|
135
|
-
/**
|
|
136
|
-
* Can used for interceptors or middlewares
|
|
137
|
-
*/
|
|
138
|
-
declare function onSuccess<T, TOptions extends {
|
|
139
|
-
next: () => any;
|
|
140
|
-
}, TRest extends any[]>(callback: NoInfer<(result: Awaited<ReturnType<TOptions['next']>>, options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => T | Promise<Awaited<ReturnType<TOptions['next']>>>;
|
|
141
|
-
/**
|
|
142
|
-
* Creates an interceptor or middleware that invokes a callback whenever an error
|
|
143
|
-
* is thrown. The error is rethrown after the callback completes.
|
|
144
|
-
*
|
|
145
|
-
* @see {@link https://orpc.dev/docs/adapters/fetch-api | Fetch API Adapter}
|
|
146
|
-
*/
|
|
147
|
-
declare function onError<T, TOptions extends {
|
|
148
|
-
next: () => any;
|
|
149
|
-
}, TRest extends any[]>(callback: NoInfer<(error: 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']>>>;
|
|
150
|
-
type OnFinishState<TResult, TError> = [error: TError, data: undefined, isSuccess: false] | [error: null, data: TResult, isSuccess: true];
|
|
151
|
-
/**
|
|
152
|
-
* Can used for interceptors or middlewares
|
|
153
|
-
*/
|
|
154
|
-
declare function onFinish<T, TOptions extends {
|
|
155
|
-
next: () => any;
|
|
156
|
-
}, TRest extends any[]>(callback: NoInfer<(state: OnFinishState<Awaited<ReturnType<TOptions['next']>>, 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']>>>;
|
|
157
|
-
/**
|
|
158
|
-
* Creates a middleware or interceptor that invokes a callback when the returned async
|
|
159
|
-
* iterator object throws an error while being consumed.
|
|
160
|
-
*
|
|
161
|
-
* This does not replace the `onError`. `onError` only fires on the
|
|
162
|
-
* initial call (before the interceptor returns the iterator), whereas this
|
|
163
|
-
* callback only fires while consuming the iterator. Use both together to
|
|
164
|
-
* catch all possible errors.
|
|
165
|
-
*/
|
|
166
|
-
declare function onAsyncIteratorObjectError<T, TOptions extends {
|
|
167
|
-
next: () => any;
|
|
168
|
-
}, 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']>>>;
|
|
169
|
-
/**
|
|
170
|
-
* Creates an interceptor that invokes a callback when the returned readable
|
|
171
|
-
* stream errors while being consumed.
|
|
172
|
-
*
|
|
173
|
-
* This does not replace the `onError`. `onError` only fires on the
|
|
174
|
-
* initial call (before the interceptor returns the stream), whereas this
|
|
175
|
-
* callback only fires while consuming the stream. Use both together to catch
|
|
176
|
-
* all possible errors.
|
|
177
|
-
*/
|
|
178
|
-
declare function onReadableStreamError<T, TOptions extends {
|
|
179
|
-
next: () => any;
|
|
180
|
-
}, 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']>>>;
|
|
181
|
-
declare function intercept<TOptions extends InterceptableOptions, TResult>(interceptors: undefined | Interceptor<TOptions, TResult>[], options: NoInfer<TOptions>, main: NoInfer<(options: TOptions) => TResult>): TResult;
|
|
182
|
-
|
|
183
|
-
type TracingAttributeValue = string | number | boolean | string[] | number[] | boolean[];
|
|
184
|
-
interface TracingException {
|
|
185
|
-
name?: string;
|
|
186
|
-
message: string;
|
|
187
|
-
stack?: string;
|
|
188
|
-
code?: string | number;
|
|
189
|
-
}
|
|
190
|
-
type TracingHeaders = Record<string, string | string[] | undefined>;
|
|
191
|
-
type TracingExceptionLevel = 'error' | 'info';
|
|
192
|
-
interface TracingSpan {
|
|
193
|
-
setAttribute(key: string, value: TracingAttributeValue): void;
|
|
194
|
-
/**
|
|
195
|
-
* Renames the span. Backends that cannot rename spans ignore it.
|
|
196
|
-
*/
|
|
197
|
-
updateName(name: string): void;
|
|
198
|
-
/**
|
|
199
|
-
* Adds an event to the span. Backends without span events ignore it.
|
|
200
|
-
*/
|
|
201
|
-
addEvent(name: string): void;
|
|
202
|
-
/**
|
|
203
|
-
* Records an exception on the span. The `error` level also marks the span as failed.
|
|
204
|
-
*/
|
|
205
|
-
recordException(level: TracingExceptionLevel, exception: TracingException): void;
|
|
206
|
-
end(): void;
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* The tracing backend oRPC records spans with, see `@orpc/opentelemetry` and `@orpc/cloudflare`.
|
|
210
|
-
*
|
|
211
|
-
* A `parent` defaults to the active span of the backend when omitted.
|
|
212
|
-
*/
|
|
213
|
-
interface Tracer {
|
|
214
|
-
/**
|
|
215
|
-
* Starts a span without making it active. The caller must end it.
|
|
216
|
-
*/
|
|
217
|
-
startSpan(name: string, parent?: TracingSpan): TracingSpan;
|
|
218
|
-
/**
|
|
219
|
-
* Starts a span, makes it active while `fn` runs, and passes it to `fn`. The caller must end it.
|
|
220
|
-
*/
|
|
221
|
-
startActiveSpan<T>(name: string, parent: TracingSpan | undefined, fn: (span: TracingSpan) => Promise<T>): Promise<T>;
|
|
222
|
-
getActiveSpan(): TracingSpan | undefined;
|
|
223
|
-
/**
|
|
224
|
-
* Runs `fn` with `span` as the active span. Backends that cannot activate a span run `fn` directly.
|
|
225
|
-
*/
|
|
226
|
-
withActiveSpan<T>(span: TracingSpan, fn: () => Promisable<T>): Promisable<T>;
|
|
227
|
-
/**
|
|
228
|
-
* Writes the trace context of `span` into `headers`. Absent when the backend does not propagate context.
|
|
229
|
-
*/
|
|
230
|
-
inject?(span: TracingSpan, headers: TracingHeaders): void;
|
|
231
|
-
/**
|
|
232
|
-
* Reads the remote parent from `headers`. Absent when the backend does not propagate context.
|
|
233
|
-
*/
|
|
234
|
-
extract?(headers: TracingHeaders): TracingSpan | undefined;
|
|
235
|
-
}
|
|
236
|
-
declare function setTracer(tracer: Tracer | undefined): void;
|
|
237
|
-
declare function getTracer(): Tracer | undefined;
|
|
238
|
-
interface StartSpanOptions {
|
|
239
|
-
/**
|
|
240
|
-
* The name of the span to create.
|
|
241
|
-
*/
|
|
242
|
-
name: string;
|
|
243
|
-
/**
|
|
244
|
-
* The span to use as parent. Defaults to the active span of the backend.
|
|
245
|
-
*/
|
|
246
|
-
parent?: TracingSpan | undefined;
|
|
247
|
-
}
|
|
248
|
-
declare function startSpan(options: StartSpanOptions | string): TracingSpan | undefined;
|
|
249
|
-
declare function recordSpanError(span: TracingSpan | undefined, error: unknown): void;
|
|
250
|
-
declare function setSpanAttributeIfDefined(span: TracingSpan | undefined, key: string, value: TracingAttributeValue | undefined): void;
|
|
251
|
-
declare function toTracingException(error: unknown): TracingException;
|
|
252
|
-
declare function toSpanAttributeValue(data: unknown): string;
|
|
253
|
-
declare function runWithSpan<T>(options: string | StartSpanOptions, fn: (span?: TracingSpan) => Promisable<T>): Promise<T>;
|
|
254
|
-
declare function runInSpanContext<T>(span: TracingSpan | undefined, fn: () => Promisable<T>): Promisable<T>;
|
|
255
|
-
|
|
256
|
-
interface WrapAsyncIteratorOptions<TYield, TReturn, TMappedYield, TMappedReturn> {
|
|
257
|
-
/**
|
|
258
|
-
* Any call to the original iterator will be executed inside this function.
|
|
259
|
-
* Useful when you want execution to happen within a specific context,
|
|
260
|
-
* such as AsyncLocalStorage.
|
|
261
|
-
*/
|
|
262
|
-
runWith?: (<T>(run: () => Promise<T>) => Promisable<T>) | undefined;
|
|
263
|
-
mapResult?: ((result: IteratorResult<TYield, TReturn>) => Promisable<IteratorResult<TMappedYield, TMappedReturn>>) | undefined;
|
|
264
|
-
mapError?: ((error: ThrowableError) => Promisable<ThrowableError>) | undefined;
|
|
265
|
-
onError?: ((error: ThrowableError) => Promisable<void>) | undefined;
|
|
266
|
-
/**
|
|
267
|
-
* Execute after the stream finishes or is cancelled.
|
|
268
|
-
*/
|
|
269
|
-
onFinish?: (() => Promisable<void>) | undefined;
|
|
270
|
-
}
|
|
271
|
-
declare function wrapAsyncIterator<TYield, TReturn, TMappedYield = TYield, TMappedReturn = TReturn>(iterator: AsyncIterator<TYield, TReturn>, { runWith, mapResult, mapError, onError, onFinish }: WrapAsyncIteratorOptions<TYield, TReturn, TMappedYield, TMappedReturn>): NoInfer<AsyncIteratorClass<TMappedYield, TMappedReturn>>;
|
|
272
|
-
declare function traceAsyncIterator<T, TReturn, TNext>(options: StartSpanOptions | string, iterator: AsyncIterator<T, TReturn, TNext>): AsyncIteratorClass<T, TReturn, TNext>;
|
|
273
|
-
declare function replicateAsyncIterator<T, TReturn, TNext>(source: AsyncIterator<T, TReturn, TNext>, count: number): (AsyncIteratorClass<T, TReturn, TNext>)[];
|
|
274
|
-
interface ConsumeAsyncIteratorOptions<T, TReturn, TError> {
|
|
275
|
-
/**
|
|
276
|
-
* Called on each event
|
|
277
|
-
*/
|
|
278
|
-
onEvent: (event: T) => void;
|
|
279
|
-
/**
|
|
280
|
-
* Called once error happens
|
|
281
|
-
*/
|
|
282
|
-
onError?: ((error: TError) => void) | undefined;
|
|
283
|
-
/**
|
|
284
|
-
* Called once AsyncIteratorObject is done
|
|
285
|
-
*
|
|
286
|
-
* @remarks
|
|
287
|
-
* **Note**: If iterator is canceled, `undefined` can be passed on success
|
|
288
|
-
*/
|
|
289
|
-
onSuccess?: ((value: TReturn | undefined) => void) | undefined;
|
|
290
|
-
/**
|
|
291
|
-
* Called once after onError or onSuccess
|
|
292
|
-
*
|
|
293
|
-
* @remarks
|
|
294
|
-
* **Note**: If iterator is canceled, `undefined` can be passed on success
|
|
295
|
-
*/
|
|
296
|
-
onFinish?: ((state: [error: TError, data: undefined, isSuccess: false] | [error: null, data: TReturn | undefined, isSuccess: true]) => void) | undefined;
|
|
297
|
-
}
|
|
298
|
-
/**
|
|
299
|
-
* Consumes an AsyncIteratorObject with lifecycle callbacks.
|
|
300
|
-
*
|
|
301
|
-
* @remarks
|
|
302
|
-
* **Warning**: If no `onError` or `onFinish` is provided, errors are thrown into the unhandled rejection channel.
|
|
303
|
-
*
|
|
304
|
-
* @returns An unsubscribe callback that stops consuming and cleans up the iterator.
|
|
305
|
-
* @see {@link https://orpc.dev/docs/client/async-iterator-object#using-consumeasynciterator | AsyncIteratorObject in Client - Using consumeAsyncIterator}
|
|
306
|
-
*/
|
|
307
|
-
declare function consumeAsyncIterator<T, TReturn, TError = ThrowableError>(iterator: AsyncIterator<T, TReturn> | PromiseWithError<AsyncIterator<T, TReturn>, TError>, options: ConsumeAsyncIteratorOptions<T, TReturn, TError | ThrowableError>): () => Promise<void>;
|
|
308
|
-
|
|
309
|
-
type Segment = string | number;
|
|
310
|
-
declare function findDeepMatches(check: (value: unknown) => boolean, payload: unknown, segments?: Segment[], maps?: Segment[][], values?: unknown[]): {
|
|
311
|
-
maps: Segment[][];
|
|
312
|
-
values: unknown[];
|
|
313
|
-
};
|
|
314
|
-
/**
|
|
315
|
-
* Get constructor of the value
|
|
316
|
-
*
|
|
317
|
-
*/
|
|
318
|
-
declare function getConstructor(value: unknown): Function | null | undefined;
|
|
319
|
-
declare function getConstructors(value: unknown): Generator<Function>;
|
|
320
|
-
/**
|
|
321
|
-
* Checks whether a value is a plain object, including objects created with
|
|
322
|
-
* `Object.create(null)`.
|
|
323
|
-
*/
|
|
324
|
-
declare function isPlainObject(value: unknown): value is Record<PropertyKey, unknown>;
|
|
325
|
-
/**
|
|
326
|
-
* Returns `object[key]` only when it is an own property, so keys like
|
|
327
|
-
* `toString` do not resolve through the prototype chain.
|
|
328
|
-
*/
|
|
329
|
-
declare function getOwn<T extends object>(object: T, key: PropertyKey): T[keyof T] | undefined;
|
|
330
|
-
declare function get(object: unknown, path: readonly PropertyKey[]): unknown;
|
|
331
|
-
/**
|
|
332
|
-
* Sets a value at the given path, creating plain objects for intermediate keys as needed.
|
|
333
|
-
*/
|
|
334
|
-
declare function set(root: object, path: [PropertyKey, ...PropertyKey[]] | [...PropertyKey[], PropertyKey], value: unknown): void;
|
|
335
|
-
/**
|
|
336
|
-
* Sets `object[key]`, defining `__proto__` as an own property instead of re-parenting the object.
|
|
337
|
-
*/
|
|
338
|
-
declare function setOwn(object: object, key: PropertyKey, value: unknown): void;
|
|
339
|
-
/**
|
|
340
|
-
* Merges two values by copying the second over the first, repeating the merge one level deeper for
|
|
341
|
-
* nested plain objects. Anything that is not a pair of plain objects is replaced by the second one.
|
|
342
|
-
*/
|
|
343
|
-
declare function mergeTwoLevels(first: unknown, second: unknown): unknown;
|
|
344
|
-
declare function omit<T extends object, K extends keyof T>(obj: T, keys: readonly K[]): Omit<T, K>;
|
|
345
|
-
declare function pick<T extends object, K extends keyof T>(obj: T, keys: readonly K[]): Pick<T, K>;
|
|
346
|
-
/**
|
|
347
|
-
* Deep clones arrays and plain objects, leaving every other value as is.
|
|
348
|
-
* Circular and shared references are preserved in the copy.
|
|
349
|
-
*/
|
|
350
|
-
declare function clone<T>(value: T): T;
|
|
351
|
-
declare function copyOnWrite(parent: object, key: PropertyKey, original: unknown): unknown;
|
|
352
|
-
declare function isPropertyKey(value: unknown): value is PropertyKey;
|
|
353
|
-
declare const NullProtoObj: ({
|
|
354
|
-
new <T extends Record<PropertyKey, unknown>>(): T;
|
|
355
|
-
});
|
|
356
|
-
/**
|
|
357
|
-
* Returns an object containing all methods of the given object, with each
|
|
358
|
-
* method bound to the original object instance.
|
|
359
|
-
*
|
|
360
|
-
* Methods are collected from both the object itself and its prototype chain
|
|
361
|
-
* (excluding `Object.prototype` and the `constructor` property).
|
|
362
|
-
*/
|
|
363
|
-
declare function bindMethods<T extends object>(obj: T, options?: {
|
|
364
|
-
unbound?: (keyof T)[];
|
|
365
|
-
}): Pick<T, {
|
|
366
|
-
[K in keyof T]: T[K] extends AnyFunction ? K : never;
|
|
367
|
-
}[keyof T]>;
|
|
368
|
-
|
|
369
|
-
interface OrderablePlugin {
|
|
370
|
-
/** Unique name of the plugin, used for ordering and identification. */
|
|
371
|
-
name: string;
|
|
372
|
-
/** Plugins this plugin should execute before. */
|
|
373
|
-
before?: string[] | undefined;
|
|
374
|
-
/** Plugins this plugin should execute after. */
|
|
375
|
-
after?: string[] | undefined;
|
|
376
|
-
}
|
|
377
|
-
/**
|
|
378
|
-
* Sorts plugins based on their `before` and `after` dependencies.
|
|
379
|
-
*/
|
|
380
|
-
declare function sortPlugins<T extends OrderablePlugin>(plugins: T[]): T[];
|
|
381
|
-
|
|
382
|
-
/**
|
|
383
|
-
* Creates a promise together with its associated `resolve` and `reject`
|
|
384
|
-
* functions.
|
|
385
|
-
*
|
|
386
|
-
* Equivalent to `Promise.withResolvers()`, but works in environments
|
|
387
|
-
* where that API is not yet available.
|
|
388
|
-
*/
|
|
389
|
-
declare function promiseWithResolvers<T>(): {
|
|
390
|
-
promise: Promise<T>;
|
|
391
|
-
resolve: (v: T) => void;
|
|
392
|
-
reject: (reason: unknown) => void;
|
|
393
|
-
};
|
|
394
|
-
/**
|
|
395
|
-
* Captures the current async context (such as AsyncLocalStorage) through a promise reaction, so no runtime API is needed.
|
|
396
|
-
* The returned function runs a callback inside it once; later calls reject.
|
|
397
|
-
*/
|
|
398
|
-
declare function captureAsyncContext(): <T>(callback: () => Promise<T>) => Promise<T>;
|
|
399
|
-
|
|
400
|
-
type Value<T, TArgs extends any[] = []> = T | ((...args: TArgs) => T);
|
|
401
|
-
declare function value<T, TArgs extends any[]>(value: Value<T, TArgs>, ...args: NoInfer<TArgs>): T extends Value<infer U, any> ? U : never;
|
|
402
|
-
|
|
403
|
-
/**
|
|
404
|
-
* Creates a proxy that overlays a `partial` object on top of a `target`.
|
|
405
|
-
*
|
|
406
|
-
* - Properties from `partial` take precedence.
|
|
407
|
-
* - Properties not present in `partial` fall back to the resolved `target`.
|
|
408
|
-
* - Methods are bound to the proxy to ensure a consistent `this` context.
|
|
409
|
-
*
|
|
410
|
-
* Useful for overriding specific properties of an object while delegating
|
|
411
|
-
* all other access to the original target without needing to know its full structure.
|
|
412
|
-
*/
|
|
413
|
-
declare function override<T extends object, U extends object>(target: Value<T>, partial: U): U & Omit<T, keyof U>;
|
|
414
|
-
|
|
415
|
-
interface AsyncIdQueueCloseOptions {
|
|
416
|
-
id?: string | undefined;
|
|
417
|
-
reason?: unknown;
|
|
418
|
-
}
|
|
419
|
-
declare class AsyncIdQueue<T> {
|
|
420
|
-
private readonly openIds;
|
|
421
|
-
private readonly queues;
|
|
422
|
-
private readonly waiters;
|
|
423
|
-
get size(): number;
|
|
424
|
-
open(id: string): void;
|
|
425
|
-
isOpen(id: string): boolean;
|
|
426
|
-
push(id: string, item: T): void;
|
|
427
|
-
pull(id: string): Promise<T>;
|
|
428
|
-
close({ id, reason }?: AsyncIdQueueCloseOptions): void;
|
|
429
|
-
private assertOpen;
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
/**
|
|
433
|
-
* Returns a signal that aborts only after all provided signals are aborted.
|
|
434
|
-
*/
|
|
435
|
-
declare function allAbortSignal(signals: readonly (AbortSignal | undefined)[]): AbortSignal | undefined;
|
|
436
|
-
/**
|
|
437
|
-
* Returns a signal that aborts as soon as any of the provided signals aborts,
|
|
438
|
-
* with the same abort reason.
|
|
439
|
-
*
|
|
440
|
-
* Prefers the native `AbortSignal.any` when available, and falls back to a manual
|
|
441
|
-
* implementation otherwise, including in runtimes without the `AbortSignal` global.
|
|
442
|
-
*/
|
|
443
|
-
declare function anyAbortSignal(signals: readonly (AbortSignal | undefined)[]): AbortSignal | undefined;
|
|
444
|
-
declare function runWithSignal<T>(signal: AbortSignal | undefined, fn: () => Promise<T>): Promise<T>;
|
|
445
|
-
|
|
446
|
-
declare function replicateReadableStream<T>(stream: ReadableStream<T>, count: number): ReadableStream<T>[];
|
|
447
|
-
type ReadableStreamReadResult<T> = {
|
|
448
|
-
done: false;
|
|
449
|
-
value: T;
|
|
450
|
-
} | {
|
|
451
|
-
done: true;
|
|
452
|
-
value?: T | undefined;
|
|
453
|
-
};
|
|
454
|
-
interface WrapReadableStreamOptions<T, TMapped> {
|
|
455
|
-
/**
|
|
456
|
-
* Any call to the original stream reader will be executed inside this function.
|
|
457
|
-
* Useful when you want execution to happen within a specific context,
|
|
458
|
-
* such as AsyncLocalStorage.
|
|
459
|
-
*/
|
|
460
|
-
runWith?: (<T>(run: () => Promise<T>) => Promisable<T>) | undefined;
|
|
461
|
-
mapResult?: ((result: ReadableStreamReadResult<T>) => Promisable<ReadableStreamReadResult<TMapped>>) | undefined;
|
|
462
|
-
mapError?: ((error: ThrowableError) => Promisable<ThrowableError>) | undefined;
|
|
463
|
-
onError?: ((error: ThrowableError) => Promisable<void>) | undefined;
|
|
464
|
-
/**
|
|
465
|
-
* Guaranteed to execute exactly once after the stream finishes or is cancelled.
|
|
466
|
-
*/
|
|
467
|
-
onFinish?: (() => Promisable<void>) | undefined;
|
|
468
|
-
}
|
|
469
|
-
declare function wrapReadableStream<T, TMapped = T>(stream: ReadableStream<T>, { runWith, mapResult, mapError, onError, onFinish }: WrapReadableStreamOptions<T, TMapped>): NoInfer<ReadableStream<TMapped>>;
|
|
470
|
-
declare function traceReadableStream<T>(options: StartSpanOptions | string, stream: ReadableStream<T>): ReadableStream<T>;
|
|
471
|
-
/**
|
|
472
|
-
* Converts a {@link ReadableStream} into an {@link AsyncIteratorClass}.
|
|
473
|
-
*
|
|
474
|
-
* @see {@link https://orpc.dev/docs/integrations/ai-sdk | AI SDK Integration}
|
|
475
|
-
*/
|
|
476
|
-
declare function streamToAsyncIteratorObject<T>(stream: ReadableStream<T>, { signal }?: {
|
|
477
|
-
signal?: AbortSignal | undefined;
|
|
478
|
-
}): AsyncIteratorClass<T>;
|
|
479
|
-
/**
|
|
480
|
-
* Converts an `AsyncIterator` into a `ReadableStream`.
|
|
481
|
-
*/
|
|
482
|
-
declare function asyncIteratorToStream<T>(iterator: AsyncIterator<T>): ReadableStream<T>;
|
|
483
|
-
/**
|
|
484
|
-
* Converts an `AsyncIterator` into a `ReadableStream`, ensuring that
|
|
485
|
-
* all emitted object values are *unproxied* before enqueuing.
|
|
486
|
-
*
|
|
487
|
-
* @see {@link https://orpc.dev/docs/integrations/ai-sdk | AI SDK Integration}
|
|
488
|
-
*/
|
|
489
|
-
declare function asyncIteratorToUnproxiedDataStream<T>(iterator: AsyncIterator<T>): ReadableStream<T>;
|
|
490
|
-
|
|
491
|
-
export { AsyncIdQueue, DEFAULT_MAX_BIGINT_DIGITS, NullProtoObj, ORPC_NAME, allAbortSignal, anyAbortSignal, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, bindMethods, captureAsyncContext, clone, compareSequentialIds, consumeAsyncIterator, copyOnWrite, defer, encodeBase64, findDeepMatches, get, getConstructor, getConstructors, getOwn, getTracer, intercept, isAbortError, isAcceptableEncoding, isAsyncGeneratorFunction, isCompressibleContentType, isDeepEqual, isNoTransformCacheControl, isPlainObject, isPropertyKey, loadBytes, matchesHttpPath, matchesHttpPathPrefix, mergeHttpPath, mergeTwoLevels, normalizeHttpPath, omit, onAsyncIteratorObjectError, onError, onFinish, onReadableStreamError, onStart, onSuccess, once, override, parseAcceptEncodingQualities, parseBigIntString, pathToHttpPath, pick, promiseWithResolvers, recordSpanError, replicateAsyncIterator, replicateReadableStream, resolveMaybeOptionalOptions, runInSpanContext, runWithSignal, runWithSpan, set, setOwn, setSpanAttributeIfDefined, setTracer, sortPlugins, splitInHalf, startSpan, streamToAsyncIteratorObject, toSpanAttributeValue, toStringOrBytes, toTracingException, traceAsyncIterator, traceReadableStream, tryOrUndefined, value, varyByAcceptEncoding, wrapAsyncIterator, wrapReadableStream };
|
|
492
|
-
export type { AnyFunction, AsyncIdQueueCloseOptions, ConsumeAsyncIteratorOptions, DistributiveOmit, InterceptableOptions, Interceptor, InterceptorOptions, IntersectPick, MaybeOptionalOptions, OnFinishState, OrderablePlugin, PromiseWithError, Public, ReadableStreamReadResult, Registry, Segment, StartSpanOptions, ThrowableError, Tracer, TracingAttributeValue, TracingException, TracingExceptionLevel, TracingHeaders, TracingSpan, Value, WrapAsyncIteratorOptions, WrapReadableStreamOptions };
|