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