@orpc/shared 2.0.0-beta.4 → 2.0.0-beta.40
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 +194 -43
- package/dist/index.d.ts +194 -43
- package/dist/index.mjs +506 -328
- 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, 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,6 +28,10 @@ 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
37
|
* Executes the callback function after the current call stack has been cleared.
|
|
@@ -41,6 +44,23 @@ declare function normalizeHttpPath(path: string): `/${string}`;
|
|
|
41
44
|
declare function mergeHttpPath(a: `/${string}`, b: `/${string}`): `/${string}`;
|
|
42
45
|
declare function matchesHttpPathPrefix(url: `/${string}`, prefix: `/${string}`): boolean;
|
|
43
46
|
declare function matchesHttpPath(url: `/${string}`, path: `/${string}`): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Parse Accept-Encoding into each coding's q-value, where `0` means the coding is explicitly
|
|
49
|
+
* unacceptable. The `*` wildcard is kept under its own key, so a caller can honour it while
|
|
50
|
+
* still letting a specific coding take precedence over it.
|
|
51
|
+
*
|
|
52
|
+
* @see https://www.rfc-editor.org/rfc/rfc9110.html#name-accept-encoding
|
|
53
|
+
*/
|
|
54
|
+
declare function parseAcceptEncodingQualities(header: string | undefined): Map<string, number>;
|
|
55
|
+
/**
|
|
56
|
+
* Add `accept-encoding` to a Vary header value. The encoding is chosen from the request, so a
|
|
57
|
+
* shared cache must key on it or it will hand a compressed body to a client that cannot decode it.
|
|
58
|
+
*
|
|
59
|
+
* @see https://www.rfc-editor.org/rfc/rfc9110.html#name-vary
|
|
60
|
+
*/
|
|
61
|
+
declare function varyByAcceptEncoding(vary: string | undefined): string;
|
|
62
|
+
declare function isNoTransformCacheControl(cacheControl: string | undefined): boolean;
|
|
63
|
+
declare function isCompressibleContentType(contentType: string | null | undefined): boolean;
|
|
44
64
|
|
|
45
65
|
/**
|
|
46
66
|
* Compares two sequential IDs.
|
|
@@ -90,7 +110,10 @@ declare function onSuccess<T, TOptions extends {
|
|
|
90
110
|
next: () => any;
|
|
91
111
|
}, 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
112
|
/**
|
|
93
|
-
*
|
|
113
|
+
* Creates an interceptor or middleware that invokes a callback whenever an error
|
|
114
|
+
* is thrown. The error is rethrown after the callback completes.
|
|
115
|
+
*
|
|
116
|
+
* @see {@link https://orpc.dev/docs/adapters/fetch-api | Fetch API Adapter}
|
|
94
117
|
*/
|
|
95
118
|
declare function onError<T, TOptions extends {
|
|
96
119
|
next: () => any;
|
|
@@ -102,42 +125,104 @@ type OnFinishState<TResult, TError> = [error: TError, data: undefined, isSuccess
|
|
|
102
125
|
declare function onFinish<T, TOptions extends {
|
|
103
126
|
next: () => any;
|
|
104
127
|
}, 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']>>>;
|
|
128
|
+
/**
|
|
129
|
+
* Creates a middleware or interceptor that invokes a callback when the returned async
|
|
130
|
+
* iterator object throws an error while being consumed.
|
|
131
|
+
*
|
|
132
|
+
* This does not replace the `onError`. `onError` only fires on the
|
|
133
|
+
* initial call (before the interceptor returns the iterator), whereas this
|
|
134
|
+
* callback only fires while consuming the iterator. Use both together to
|
|
135
|
+
* catch all possible errors.
|
|
136
|
+
*/
|
|
137
|
+
declare function onAsyncIteratorObjectError<T, TOptions extends {
|
|
138
|
+
next: () => any;
|
|
139
|
+
}, 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']>>>;
|
|
140
|
+
/**
|
|
141
|
+
* Creates an interceptor that invokes a callback when the returned readable
|
|
142
|
+
* stream errors while being consumed.
|
|
143
|
+
*
|
|
144
|
+
* This does not replace the `onError`. `onError` only fires on the
|
|
145
|
+
* initial call (before the interceptor returns the stream), whereas this
|
|
146
|
+
* callback only fires while consuming the stream. Use both together to catch
|
|
147
|
+
* all possible errors.
|
|
148
|
+
*/
|
|
149
|
+
declare function onReadableStreamError<T, TOptions extends {
|
|
150
|
+
next: () => any;
|
|
151
|
+
}, 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
152
|
declare function intercept<TOptions extends InterceptableOptions, TResult>(interceptors: undefined | Interceptor<TOptions, TResult>[], options: NoInfer<TOptions>, main: NoInfer<(options: TOptions) => TResult>): TResult;
|
|
106
153
|
|
|
154
|
+
type TracingAttributeValue = string | number | boolean | string[] | number[] | boolean[];
|
|
155
|
+
interface TracingException {
|
|
156
|
+
name?: string;
|
|
157
|
+
message: string;
|
|
158
|
+
stack?: string;
|
|
159
|
+
code?: string | number;
|
|
160
|
+
}
|
|
161
|
+
type TracingHeaders = Record<string, string | string[] | undefined>;
|
|
162
|
+
type TracingExceptionLevel = 'error' | 'info';
|
|
163
|
+
interface TracingSpan {
|
|
164
|
+
setAttribute(key: string, value: TracingAttributeValue): void;
|
|
165
|
+
/**
|
|
166
|
+
* Renames the span. Backends that cannot rename spans ignore it.
|
|
167
|
+
*/
|
|
168
|
+
updateName(name: string): void;
|
|
169
|
+
/**
|
|
170
|
+
* Adds an event to the span. Backends without span events ignore it.
|
|
171
|
+
*/
|
|
172
|
+
addEvent(name: string): void;
|
|
173
|
+
/**
|
|
174
|
+
* Records an exception on the span. The `error` level also marks the span as failed.
|
|
175
|
+
*/
|
|
176
|
+
recordException(level: TracingExceptionLevel, exception: TracingException): void;
|
|
177
|
+
end(): void;
|
|
178
|
+
}
|
|
107
179
|
/**
|
|
108
|
-
*
|
|
180
|
+
* The tracing backend oRPC records spans with, see `@orpc/opentelemetry` and `@orpc/cloudflare`.
|
|
181
|
+
*
|
|
182
|
+
* A `parent` defaults to the active span of the backend when omitted.
|
|
109
183
|
*/
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
184
|
+
interface Tracer {
|
|
185
|
+
/**
|
|
186
|
+
* Starts a span without making it active. The caller must end it.
|
|
187
|
+
*/
|
|
188
|
+
startSpan(name: string, parent?: TracingSpan): TracingSpan;
|
|
189
|
+
/**
|
|
190
|
+
* Starts a span, makes it active while `fn` runs, and passes it to `fn`. The caller must end it.
|
|
191
|
+
*/
|
|
192
|
+
startActiveSpan<T>(name: string, parent: TracingSpan | undefined, fn: (span: TracingSpan) => Promise<T>): Promise<T>;
|
|
193
|
+
getActiveSpan(): TracingSpan | undefined;
|
|
115
194
|
/**
|
|
116
|
-
*
|
|
195
|
+
* Runs `fn` with `span` as the active span. Backends that cannot activate a span run `fn` directly.
|
|
117
196
|
*/
|
|
118
|
-
|
|
197
|
+
withActiveSpan<T>(span: TracingSpan, fn: () => Promisable<T>): Promisable<T>;
|
|
198
|
+
/**
|
|
199
|
+
* Writes the trace context of `span` into `headers`. Absent when the backend does not propagate context.
|
|
200
|
+
*/
|
|
201
|
+
inject?(span: TracingSpan, headers: TracingHeaders): void;
|
|
202
|
+
/**
|
|
203
|
+
* Reads the remote parent from `headers`. Absent when the backend does not propagate context.
|
|
204
|
+
*/
|
|
205
|
+
extract?(headers: TracingHeaders): TracingSpan | undefined;
|
|
119
206
|
}
|
|
120
|
-
declare function
|
|
121
|
-
declare function
|
|
122
|
-
interface StartSpanOptions
|
|
207
|
+
declare function setTracer(tracer: Tracer | undefined): void;
|
|
208
|
+
declare function getTracer(): Tracer | undefined;
|
|
209
|
+
interface StartSpanOptions {
|
|
123
210
|
/**
|
|
124
211
|
* The name of the span to create.
|
|
125
212
|
*/
|
|
126
213
|
name: string;
|
|
127
214
|
/**
|
|
128
|
-
*
|
|
215
|
+
* The span to use as parent. Defaults to the active span of the backend.
|
|
129
216
|
*/
|
|
130
|
-
|
|
217
|
+
parent?: TracingSpan | undefined;
|
|
131
218
|
}
|
|
132
|
-
declare function startSpan(options: StartSpanOptions | string):
|
|
133
|
-
declare function recordSpanError(span:
|
|
134
|
-
declare function setSpanAttributeIfDefined(span:
|
|
135
|
-
declare function
|
|
219
|
+
declare function startSpan(options: StartSpanOptions | string): TracingSpan | undefined;
|
|
220
|
+
declare function recordSpanError(span: TracingSpan | undefined, error: unknown): void;
|
|
221
|
+
declare function setSpanAttributeIfDefined(span: TracingSpan | undefined, key: string, value: TracingAttributeValue | undefined): void;
|
|
222
|
+
declare function toTracingException(error: unknown): TracingException;
|
|
136
223
|
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>;
|
|
224
|
+
declare function runWithSpan<T>(options: string | StartSpanOptions, fn: (span?: TracingSpan) => Promisable<T>): Promise<T>;
|
|
225
|
+
declare function runInSpanContext<T>(span: TracingSpan | undefined, fn: () => Promisable<T>): Promisable<T>;
|
|
141
226
|
|
|
142
227
|
interface WrapAsyncIteratorOptions<TYield, TReturn, TMappedYield, TMappedReturn> {
|
|
143
228
|
/**
|
|
@@ -145,10 +230,10 @@ interface WrapAsyncIteratorOptions<TYield, TReturn, TMappedYield, TMappedReturn>
|
|
|
145
230
|
* Useful when you want execution to happen within a specific context,
|
|
146
231
|
* such as AsyncLocalStorage.
|
|
147
232
|
*/
|
|
148
|
-
runWith?: <T>(run: () => Promise<T>) =>
|
|
233
|
+
runWith?: <T>(run: () => Promise<T>) => Promisable<T>;
|
|
149
234
|
mapResult?: (result: IteratorResult<TYield, TReturn>) => Promisable<IteratorResult<TMappedYield, TMappedReturn>>;
|
|
150
|
-
mapError?: (error:
|
|
151
|
-
onError?: (error:
|
|
235
|
+
mapError?: (error: ThrowableError) => Promisable<ThrowableError>;
|
|
236
|
+
onError?: (error: ThrowableError) => Promisable<void>;
|
|
152
237
|
/**
|
|
153
238
|
* Execute after the stream finishes or is cancelled.
|
|
154
239
|
*/
|
|
@@ -157,6 +242,40 @@ interface WrapAsyncIteratorOptions<TYield, TReturn, TMappedYield, TMappedReturn>
|
|
|
157
242
|
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
243
|
declare function traceAsyncIterator<T, TReturn, TNext>(options: StartSpanOptions | string, iterator: AsyncIterator<T, TReturn, TNext>): AsyncIteratorClass<T, TReturn, TNext>;
|
|
159
244
|
declare function replicateAsyncIterator<T, TReturn, TNext>(source: AsyncIterator<T, TReturn, TNext>, count: number): (AsyncIteratorClass<T, TReturn, TNext>)[];
|
|
245
|
+
interface ConsumeAsyncIteratorOptions<T, TReturn, TError> {
|
|
246
|
+
/**
|
|
247
|
+
* Called on each event
|
|
248
|
+
*/
|
|
249
|
+
onEvent: (event: T) => void;
|
|
250
|
+
/**
|
|
251
|
+
* Called once error happens
|
|
252
|
+
*/
|
|
253
|
+
onError?: (error: TError) => void;
|
|
254
|
+
/**
|
|
255
|
+
* Called once AsyncIteratorObject is done
|
|
256
|
+
*
|
|
257
|
+
* @remarks
|
|
258
|
+
* **Note**: If iterator is canceled, `undefined` can be passed on success
|
|
259
|
+
*/
|
|
260
|
+
onSuccess?: (value: TReturn | undefined) => void;
|
|
261
|
+
/**
|
|
262
|
+
* Called once after onError or onSuccess
|
|
263
|
+
*
|
|
264
|
+
* @remarks
|
|
265
|
+
* **Note**: If iterator is canceled, `undefined` can be passed on success
|
|
266
|
+
*/
|
|
267
|
+
onFinish?: (state: [error: TError, data: undefined, isSuccess: false] | [error: null, data: TReturn | undefined, isSuccess: true]) => void;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Consumes an AsyncIteratorObject with lifecycle callbacks.
|
|
271
|
+
*
|
|
272
|
+
* @remarks
|
|
273
|
+
* **Warning**: If no `onError` or `onFinish` is provided, errors are thrown into the unhandled rejection channel.
|
|
274
|
+
*
|
|
275
|
+
* @returns An unsubscribe callback that stops consuming and cleans up the iterator.
|
|
276
|
+
* @see {@link https://orpc.dev/docs/client/async-iterator-object#using-consumeasynciterator | AsyncIteratorObject in Client - Using consumeAsyncIterator}
|
|
277
|
+
*/
|
|
278
|
+
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
279
|
|
|
161
280
|
type Segment = string | number;
|
|
162
281
|
declare function findDeepMatches(check: (value: unknown) => boolean, payload: unknown, segments?: Segment[], maps?: Segment[][], values?: unknown[]): {
|
|
@@ -168,18 +287,38 @@ declare function findDeepMatches(check: (value: unknown) => boolean, payload: un
|
|
|
168
287
|
*
|
|
169
288
|
*/
|
|
170
289
|
declare function getConstructor(value: unknown): Function | null | undefined;
|
|
290
|
+
declare function getConstructors(value: unknown): Generator<Function>;
|
|
171
291
|
/**
|
|
172
292
|
* Checks whether a value is a plain object, including objects created with
|
|
173
293
|
* `Object.create(null)`.
|
|
174
294
|
*/
|
|
175
295
|
declare function isPlainObject(value: unknown): value is Record<PropertyKey, unknown>;
|
|
296
|
+
/**
|
|
297
|
+
* Returns `object[key]` only when it is an own property, so keys like
|
|
298
|
+
* `toString` do not resolve through the prototype chain.
|
|
299
|
+
*/
|
|
300
|
+
declare function getOwn<T extends object>(object: T, key: PropertyKey): T[keyof T] | undefined;
|
|
176
301
|
declare function get(object: unknown, path: readonly PropertyKey[]): unknown;
|
|
177
302
|
/**
|
|
178
303
|
* Sets a value at the given path, creating plain objects for intermediate keys as needed.
|
|
179
304
|
*/
|
|
180
305
|
declare function set(root: object, path: [PropertyKey, ...PropertyKey[]] | [...PropertyKey[], PropertyKey], value: unknown): void;
|
|
306
|
+
/**
|
|
307
|
+
* Sets `object[key]`, defining `__proto__` as an own property instead of re-parenting the object.
|
|
308
|
+
*/
|
|
309
|
+
declare function setOwn(object: object, key: PropertyKey, value: unknown): void;
|
|
310
|
+
/**
|
|
311
|
+
* Merges two values by copying the second over the first, repeating the merge one level deeper for
|
|
312
|
+
* nested plain objects. Anything that is not a pair of plain objects is replaced by the second one.
|
|
313
|
+
*/
|
|
314
|
+
declare function mergeTwoLevels(first: unknown, second: unknown): unknown;
|
|
181
315
|
declare function omit<T extends object, K extends keyof T>(obj: T, keys: readonly K[]): Omit<T, K>;
|
|
316
|
+
/**
|
|
317
|
+
* Deep clones arrays and plain objects, leaving every other value as is.
|
|
318
|
+
* Circular and shared references are preserved in the copy.
|
|
319
|
+
*/
|
|
182
320
|
declare function clone<T>(value: T): T;
|
|
321
|
+
declare function copyOnWrite(parent: object, key: PropertyKey, original: unknown): unknown;
|
|
183
322
|
declare function isPropertyKey(value: unknown): value is PropertyKey;
|
|
184
323
|
declare const NullProtoObj: ({
|
|
185
324
|
new <T extends Record<PropertyKey, unknown>>(): T;
|
|
@@ -191,7 +330,9 @@ declare const NullProtoObj: ({
|
|
|
191
330
|
* Methods are collected from both the object itself and its prototype chain
|
|
192
331
|
* (excluding `Object.prototype` and the `constructor` property).
|
|
193
332
|
*/
|
|
194
|
-
declare function bindMethods<T extends object>(obj: T
|
|
333
|
+
declare function bindMethods<T extends object>(obj: T, options?: {
|
|
334
|
+
unbound?: (keyof T)[];
|
|
335
|
+
}): Pick<T, {
|
|
195
336
|
[K in keyof T]: T[K] extends AnyFunction ? K : never;
|
|
196
337
|
}[keyof T]>;
|
|
197
338
|
|
|
@@ -257,6 +398,14 @@ declare class AsyncIdQueue<T> {
|
|
|
257
398
|
* Returns a signal that aborts only after all provided signals are aborted.
|
|
258
399
|
*/
|
|
259
400
|
declare function allAbortSignal(signals: readonly (AbortSignal | undefined)[]): AbortSignal | undefined;
|
|
401
|
+
/**
|
|
402
|
+
* Returns a signal that aborts as soon as any of the provided signals aborts,
|
|
403
|
+
* with the same abort reason.
|
|
404
|
+
*
|
|
405
|
+
* Prefers the native `AbortSignal.any` when available, and falls back to a manual
|
|
406
|
+
* implementation otherwise, including in runtimes without the `AbortSignal` global.
|
|
407
|
+
*/
|
|
408
|
+
declare function anyAbortSignal(signals: readonly (AbortSignal | undefined)[]): AbortSignal | undefined;
|
|
260
409
|
declare function runWithSignal<T>(signal: AbortSignal | undefined, fn: () => Promise<T>): Promise<T>;
|
|
261
410
|
|
|
262
411
|
declare function replicateReadableStream<T>(stream: ReadableStream<T>, count: number): ReadableStream<T>[];
|
|
@@ -265,7 +414,7 @@ type ReadableStreamReadResult<T> = {
|
|
|
265
414
|
value: T;
|
|
266
415
|
} | {
|
|
267
416
|
done: true;
|
|
268
|
-
value
|
|
417
|
+
value?: undefined | T;
|
|
269
418
|
};
|
|
270
419
|
interface WrapReadableStreamOptions<T, TMapped> {
|
|
271
420
|
/**
|
|
@@ -273,10 +422,10 @@ interface WrapReadableStreamOptions<T, TMapped> {
|
|
|
273
422
|
* Useful when you want execution to happen within a specific context,
|
|
274
423
|
* such as AsyncLocalStorage.
|
|
275
424
|
*/
|
|
276
|
-
runWith?: <T>(run: () => Promise<T>) =>
|
|
425
|
+
runWith?: <T>(run: () => Promise<T>) => Promisable<T>;
|
|
277
426
|
mapResult?: (result: ReadableStreamReadResult<T>) => Promisable<ReadableStreamReadResult<TMapped>>;
|
|
278
|
-
mapError?: (error:
|
|
279
|
-
onError?: (error:
|
|
427
|
+
mapError?: (error: ThrowableError) => Promisable<ThrowableError>;
|
|
428
|
+
onError?: (error: ThrowableError) => Promisable<void>;
|
|
280
429
|
/**
|
|
281
430
|
* Guaranteed to execute exactly once after the stream finishes or is cancelled.
|
|
282
431
|
*/
|
|
@@ -285,9 +434,11 @@ interface WrapReadableStreamOptions<T, TMapped> {
|
|
|
285
434
|
declare function wrapReadableStream<T, TMapped = T>(stream: ReadableStream<T>, { runWith, mapResult, mapError, onError, onFinish }: WrapReadableStreamOptions<T, TMapped>): NoInfer<ReadableStream<TMapped>>;
|
|
286
435
|
declare function traceReadableStream<T>(options: StartSpanOptions | string, stream: ReadableStream<T>): ReadableStream<T>;
|
|
287
436
|
/**
|
|
288
|
-
* Converts a
|
|
437
|
+
* Converts a {@link ReadableStream} into an {@link AsyncIteratorClass}.
|
|
438
|
+
*
|
|
439
|
+
* @see {@link https://orpc.dev/docs/integrations/ai-sdk | AI SDK Integration}
|
|
289
440
|
*/
|
|
290
|
-
declare function
|
|
441
|
+
declare function streamToAsyncIteratorObject<T>(stream: ReadableStream<T>, { signal }?: {
|
|
291
442
|
signal?: undefined | AbortSignal;
|
|
292
443
|
}): AsyncIteratorClass<T>;
|
|
293
444
|
/**
|
|
@@ -297,10 +448,10 @@ declare function asyncIteratorToStream<T>(iterator: AsyncIterator<T>): ReadableS
|
|
|
297
448
|
/**
|
|
298
449
|
* Converts an `AsyncIterator` into a `ReadableStream`, ensuring that
|
|
299
450
|
* all emitted object values are *unproxied* before enqueuing.
|
|
451
|
+
*
|
|
452
|
+
* @see {@link https://orpc.dev/docs/integrations/ai-sdk | AI SDK Integration}
|
|
300
453
|
*/
|
|
301
454
|
declare function asyncIteratorToUnproxiedDataStream<T>(iterator: AsyncIterator<T>): ReadableStream<T>;
|
|
302
455
|
|
|
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 };
|
|
456
|
+
export { AsyncIdQueue, NullProtoObj, ORPC_NAME, allAbortSignal, anyAbortSignal, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, bindMethods, clone, compareSequentialIds, consumeAsyncIterator, copyOnWrite, defer, findDeepMatches, get, getConstructor, getConstructors, getOwn, getTracer, intercept, isAbortError, isAsyncGeneratorFunction, isCompressibleContentType, isDeepEqual, isNoTransformCacheControl, isPlainObject, isPropertyKey, loadBytes, matchesHttpPath, matchesHttpPathPrefix, mergeHttpPath, mergeTwoLevels, normalizeHttpPath, omit, onAsyncIteratorObjectError, onError, onFinish, onReadableStreamError, onStart, onSuccess, once, override, parseAcceptEncodingQualities, pathToHttpPath, 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 };
|
|
457
|
+
export type { AnyFunction, AsyncIdQueueCloseOptions, ConsumeAsyncIteratorOptions, InterceptableOptions, Interceptor, InterceptorOptions, IntersectPick, MaybeOptionalOptions, OnFinishState, OrderablePlugin, PromiseWithError, Public, ReadableStreamReadResult, Registry, Segment, StartSpanOptions, ThrowableError, Tracer, TracingAttributeValue, TracingException, TracingExceptionLevel, TracingHeaders, TracingSpan, Value, WrapAsyncIteratorOptions, WrapReadableStreamOptions };
|