@orpc/shared 1.14.6 → 2.0.0-beta.2
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 +74 -86
- package/dist/index.d.mts +152 -200
- package/dist/index.d.ts +152 -200
- package/dist/index.mjs +541 -360
- package/package.json +6 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,108 +1,47 @@
|
|
|
1
1
|
import { Promisable } from 'type-fest';
|
|
2
|
-
export { IsEqual,
|
|
2
|
+
export { IsEqual, PartialDeep, Promisable, Writable } from 'type-fest';
|
|
3
3
|
import { Tracer, TraceAPI, ContextAPI, PropagationAPI, SpanOptions, Context, Span, AttributeValue, Exception } from '@opentelemetry/api';
|
|
4
|
-
|
|
4
|
+
import { AsyncIteratorClass } from '@standardserver/shared';
|
|
5
|
+
export { AbortError, AsyncCleanupFn, AsyncIteratorClass, AsyncIteratorClassNextFn, SequentialIdGenerator, getOrBind, isAsyncIteratorObject, isTypescriptObject, parseEmptyableJSON, sleep, stringifyJSON, toArray } from '@standardserver/shared';
|
|
5
6
|
|
|
6
|
-
type MaybeOptionalOptions<TOptions> =
|
|
7
|
+
type MaybeOptionalOptions<TOptions> = object extends TOptions ? [options?: TOptions] : [options: TOptions];
|
|
7
8
|
declare function resolveMaybeOptionalOptions<T>(rest: MaybeOptionalOptions<T>): T;
|
|
8
9
|
|
|
9
|
-
declare function toArray<T>(value: T): T extends readonly any[] ? T : Exclude<T, undefined | null>[];
|
|
10
10
|
declare function splitInHalf<T>(arr: readonly T[]): [T[], T[]];
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* Load Request/Response/Blob/File/.. to a buffer (Uint8Array<ArrayBuffer>).
|
|
14
14
|
*
|
|
15
15
|
* Prefers the newer `.bytes` method when available as it more efficient but not widely supported yet.
|
|
16
16
|
*/
|
|
17
|
-
declare function
|
|
18
|
-
|
|
19
|
-
type AnyFunction = (...args: any[]) => any;
|
|
20
|
-
declare function once<T extends () => any>(fn: T): () => ReturnType<T>;
|
|
21
|
-
declare function sequential<A extends any[], R>(fn: (...args: A) => Promise<R>): (...args: A) => Promise<R>;
|
|
17
|
+
declare function loadBytes(source: Pick<Blob, 'arrayBuffer' | 'bytes'>): Promise<Uint8Array<ArrayBuffer>>;
|
|
22
18
|
/**
|
|
23
|
-
*
|
|
19
|
+
* Normalize text or binary-like inputs to either:
|
|
20
|
+
* - the original string value, or
|
|
21
|
+
* - a Uint8Array view over the source bytes.
|
|
24
22
|
*/
|
|
25
|
-
declare function
|
|
23
|
+
declare function toStringOrBytes(source: string | ArrayBuffer | Blob | Exclude<ConstructorParameters<typeof Blob>[0], undefined>[0][] | Pick<Uint8Array<ArrayBuffer>, 'buffer' | 'byteOffset' | 'byteLength'>): Promise<string | Uint8Array<ArrayBuffer>>;
|
|
26
24
|
|
|
27
|
-
|
|
28
|
-
[P in keyof Omit<T, K>]: T[P] extends AnyFunction ? ((...args: Parameters<T[P]>) => OmitChainMethodDeep<ReturnType<T[P]>, K>) : T[P];
|
|
29
|
-
};
|
|
25
|
+
declare function isDeepEqual(a: unknown, b: unknown): boolean;
|
|
30
26
|
|
|
31
27
|
declare const ORPC_NAME = "orpc";
|
|
32
|
-
declare const ORPC_SHARED_PACKAGE_NAME = "@orpc/shared";
|
|
33
|
-
declare const ORPC_SHARED_PACKAGE_VERSION = "1.14.6";
|
|
34
28
|
|
|
29
|
+
declare function isAbortError(error: unknown): error is Error;
|
|
30
|
+
|
|
31
|
+
type AnyFunction = (...args: any[]) => any;
|
|
32
|
+
declare function once<T>(fn: () => T): () => T;
|
|
35
33
|
/**
|
|
36
|
-
*
|
|
37
|
-
* Uses the standardized 'AbortError' name for consistency with JavaScript APIs.
|
|
34
|
+
* Executes the callback function after the current call stack has been cleared.
|
|
38
35
|
*/
|
|
39
|
-
declare
|
|
40
|
-
|
|
41
|
-
}
|
|
36
|
+
declare function defer(callback: () => void): void;
|
|
37
|
+
declare function tryOrUndefined<T>(fn: () => T): undefined | T;
|
|
42
38
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
* This prevents unbounded memory growth if consumers process events slowly.
|
|
49
|
-
*
|
|
50
|
-
* Set to:
|
|
51
|
-
* - `0`: Disable buffering. Events must be consumed before the next one arrives.
|
|
52
|
-
* - `1`: Only keep the latest event. Useful for real-time updates where only the most recent value matters.
|
|
53
|
-
* - `Infinity`: Keep all events. Ensures no data loss, but may lead to high memory usage.
|
|
54
|
-
*
|
|
55
|
-
* @default 100
|
|
56
|
-
*/
|
|
57
|
-
maxBufferedEvents?: number;
|
|
58
|
-
}
|
|
59
|
-
interface EventPublisherSubscribeIteratorOptions extends EventPublisherOptions {
|
|
60
|
-
/**
|
|
61
|
-
* Aborts the async iterator. Throws if aborted before or during pulling.
|
|
62
|
-
*/
|
|
63
|
-
signal?: AbortSignal | undefined;
|
|
64
|
-
}
|
|
65
|
-
declare class EventPublisher<T extends Record<PropertyKey, any>> {
|
|
66
|
-
#private;
|
|
67
|
-
constructor(options?: EventPublisherOptions);
|
|
68
|
-
get size(): number;
|
|
69
|
-
/**
|
|
70
|
-
* Emits an event and delivers the payload to all subscribed listeners.
|
|
71
|
-
*/
|
|
72
|
-
publish<K extends keyof T>(event: K, payload: T[K]): void;
|
|
73
|
-
/**
|
|
74
|
-
* Subscribes to a specific event using a callback function.
|
|
75
|
-
* Returns an unsubscribe function to remove the listener.
|
|
76
|
-
*
|
|
77
|
-
* @example
|
|
78
|
-
* ```ts
|
|
79
|
-
* const unsubscribe = publisher.subscribe('event', (payload) => {
|
|
80
|
-
* console.log(payload)
|
|
81
|
-
* })
|
|
82
|
-
*
|
|
83
|
-
* // Later
|
|
84
|
-
* unsubscribe()
|
|
85
|
-
* ```
|
|
86
|
-
*/
|
|
87
|
-
subscribe<K extends keyof T>(event: K, listener: (payload: T[K]) => void): () => void;
|
|
88
|
-
/**
|
|
89
|
-
* Subscribes to a specific event using an async iterator.
|
|
90
|
-
* Useful for `for await...of` loops with optional buffering and abort support.
|
|
91
|
-
*
|
|
92
|
-
* @example
|
|
93
|
-
* ```ts
|
|
94
|
-
* for await (const payload of publisher.subscribe('event', { signal })) {
|
|
95
|
-
* console.log(payload)
|
|
96
|
-
* }
|
|
97
|
-
* ```
|
|
98
|
-
*/
|
|
99
|
-
subscribe<K extends keyof T>(event: K, options?: EventPublisherSubscribeIteratorOptions): AsyncGenerator<T[K]> & AsyncIteratorObject<T[K]>;
|
|
100
|
-
}
|
|
39
|
+
declare function pathToHttpPath(path: readonly string[]): `/${string}`;
|
|
40
|
+
declare function normalizeHttpPath(path: string): `/${string}`;
|
|
41
|
+
declare function mergeHttpPath(a: `/${string}`, b: `/${string}`): `/${string}`;
|
|
42
|
+
declare function matchesHttpPathPrefix(url: `/${string}`, prefix: `/${string}`): boolean;
|
|
43
|
+
declare function matchesHttpPath(url: `/${string}`, path: `/${string}`): boolean;
|
|
101
44
|
|
|
102
|
-
declare class SequentialIdGenerator {
|
|
103
|
-
private index;
|
|
104
|
-
generate(): string;
|
|
105
|
-
}
|
|
106
45
|
/**
|
|
107
46
|
* Compares two sequential IDs.
|
|
108
47
|
* Returns:
|
|
@@ -112,8 +51,11 @@ declare class SequentialIdGenerator {
|
|
|
112
51
|
*/
|
|
113
52
|
declare function compareSequentialIds(a: string, b: string): number;
|
|
114
53
|
|
|
115
|
-
type SetOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
116
54
|
type IntersectPick<T, U> = Pick<T, keyof T & keyof U>;
|
|
55
|
+
/**
|
|
56
|
+
* Remove protected/private properties/methods
|
|
57
|
+
*/
|
|
58
|
+
type Public<T> = Pick<T, keyof T>;
|
|
117
59
|
type PromiseWithError<T, TError> = Promise<T> & {
|
|
118
60
|
__error?: {
|
|
119
61
|
type: TError;
|
|
@@ -122,14 +64,13 @@ type PromiseWithError<T, TError> = Promise<T> & {
|
|
|
122
64
|
/**
|
|
123
65
|
* The place where you can config the orpc types.
|
|
124
66
|
*
|
|
125
|
-
* - `
|
|
67
|
+
* - `ThrowableError` the error type that represent throwable errors should be `Error` or `null | undefined | {}` if you want more strict.
|
|
126
68
|
*/
|
|
127
69
|
interface Registry {
|
|
128
70
|
}
|
|
129
71
|
type ThrowableError = Registry extends {
|
|
130
|
-
|
|
72
|
+
ThrowableError: infer T;
|
|
131
73
|
} ? T : Error;
|
|
132
|
-
type InferAsyncIterableYield<T> = T extends AsyncIterable<infer U> ? U : never;
|
|
133
74
|
|
|
134
75
|
type InterceptableOptions = Record<string, any>;
|
|
135
76
|
type InterceptorOptions<TOptions extends InterceptableOptions, TResult> = Omit<TOptions, 'next'> & {
|
|
@@ -137,134 +78,85 @@ type InterceptorOptions<TOptions extends InterceptableOptions, TResult> = Omit<T
|
|
|
137
78
|
};
|
|
138
79
|
type Interceptor<TOptions extends InterceptableOptions, TResult> = (options: InterceptorOptions<TOptions, TResult>) => TResult;
|
|
139
80
|
/**
|
|
140
|
-
* Can
|
|
81
|
+
* Can used for interceptors or middlewares
|
|
141
82
|
*/
|
|
142
83
|
declare function onStart<T, TOptions extends {
|
|
143
|
-
next()
|
|
84
|
+
next: () => any;
|
|
144
85
|
}, TRest extends any[]>(callback: NoInfer<(options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => T | Promise<Awaited<ReturnType<TOptions['next']>>>;
|
|
145
86
|
/**
|
|
146
|
-
* Can
|
|
87
|
+
* Can used for interceptors or middlewares
|
|
147
88
|
*/
|
|
148
89
|
declare function onSuccess<T, TOptions extends {
|
|
149
|
-
next()
|
|
90
|
+
next: () => any;
|
|
150
91
|
}, 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']>>>;
|
|
151
92
|
/**
|
|
152
|
-
* Can
|
|
93
|
+
* Can used for interceptors or middlewares
|
|
153
94
|
*/
|
|
154
95
|
declare function onError<T, TOptions extends {
|
|
155
|
-
next()
|
|
96
|
+
next: () => any;
|
|
156
97
|
}, 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']>>>;
|
|
157
98
|
type OnFinishState<TResult, TError> = [error: TError, data: undefined, isSuccess: false] | [error: null, data: TResult, isSuccess: true];
|
|
158
99
|
/**
|
|
159
|
-
* Can
|
|
100
|
+
* Can used for interceptors or middlewares
|
|
160
101
|
*/
|
|
161
102
|
declare function onFinish<T, TOptions extends {
|
|
162
|
-
next()
|
|
103
|
+
next: () => any;
|
|
163
104
|
}, 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']>>>;
|
|
164
|
-
declare function intercept<TOptions extends InterceptableOptions, TResult>(interceptors: Interceptor<TOptions, TResult>[], options: NoInfer<TOptions>, main: NoInfer<(options: TOptions) => TResult>): TResult;
|
|
105
|
+
declare function intercept<TOptions extends InterceptableOptions, TResult>(interceptors: undefined | Interceptor<TOptions, TResult>[], options: NoInfer<TOptions>, main: NoInfer<(options: TOptions) => TResult>): TResult;
|
|
165
106
|
|
|
166
107
|
/**
|
|
167
108
|
* Only import types from @opentelemetry/api to avoid runtime dependencies.
|
|
168
109
|
*/
|
|
169
110
|
|
|
170
|
-
interface
|
|
111
|
+
interface OpenTelemetryConfig {
|
|
171
112
|
tracer: Tracer;
|
|
172
113
|
trace: TraceAPI;
|
|
173
114
|
context: ContextAPI;
|
|
174
|
-
propagation: PropagationAPI;
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* Sets the global OpenTelemetry config.
|
|
178
|
-
* Call this once at app startup. Use `undefined` to disable tracing.
|
|
179
|
-
*/
|
|
180
|
-
declare function setGlobalOtelConfig(config: OtelConfig | undefined): void;
|
|
181
|
-
/**
|
|
182
|
-
* Gets the global OpenTelemetry config.
|
|
183
|
-
* Returns `undefined` if OpenTelemetry is not configured, initialized, or enabled.
|
|
184
|
-
*/
|
|
185
|
-
declare function getGlobalOtelConfig(): OtelConfig | undefined;
|
|
186
|
-
/**
|
|
187
|
-
* Starts a new OpenTelemetry span with the given name and options.
|
|
188
|
-
*
|
|
189
|
-
* @returns The new span, or `undefined` if no tracer is set.
|
|
190
|
-
*/
|
|
191
|
-
declare function startSpan(name: string, options?: SpanOptions, context?: Context): Span | undefined;
|
|
192
|
-
interface SetSpanErrorOptions {
|
|
193
115
|
/**
|
|
194
|
-
*
|
|
116
|
+
* propagation is optional, can reduce bundle size in some cases.
|
|
195
117
|
*/
|
|
196
|
-
|
|
118
|
+
propagation?: PropagationAPI | undefined;
|
|
197
119
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
*/
|
|
202
|
-
declare function setSpanError(span: Span | undefined, error: unknown, options?: SetSpanErrorOptions): void;
|
|
203
|
-
declare function setSpanAttribute(span: Span | undefined, key: string, value: AttributeValue | undefined): void;
|
|
204
|
-
/**
|
|
205
|
-
* Converts an error to an OpenTelemetry Exception.
|
|
206
|
-
*/
|
|
207
|
-
declare function toOtelException(error: unknown): Exclude<Exception, string>;
|
|
208
|
-
/**
|
|
209
|
-
* Converts a value to a string suitable for OpenTelemetry span attributes.
|
|
210
|
-
*/
|
|
211
|
-
declare function toSpanAttributeValue(data: unknown): string;
|
|
212
|
-
interface RunWithSpanOptions extends SpanOptions, SetSpanErrorOptions {
|
|
120
|
+
declare function setOpenTelemetryConfig(config: OpenTelemetryConfig | undefined): void;
|
|
121
|
+
declare function getOpenTelemetryConfig(): OpenTelemetryConfig | undefined;
|
|
122
|
+
interface StartSpanOptions extends SpanOptions {
|
|
213
123
|
/**
|
|
214
124
|
* The name of the span to create.
|
|
215
125
|
*/
|
|
216
126
|
name: string;
|
|
217
127
|
/**
|
|
218
|
-
* Context to use for the span.
|
|
128
|
+
* Context to use for the created span.
|
|
219
129
|
*/
|
|
220
130
|
context?: Context;
|
|
221
131
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
declare function
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
132
|
+
declare function startSpan(options: StartSpanOptions | string): Span | undefined;
|
|
133
|
+
declare function recordSpanError(span: Span | undefined, error: unknown): void;
|
|
134
|
+
declare function setSpanAttributeIfDefined(span: Span | undefined, key: string, value: AttributeValue | undefined): void;
|
|
135
|
+
declare function toOtelException(error: unknown): Exclude<Exception, string>;
|
|
136
|
+
declare function toSpanAttributeValue(data: unknown): string;
|
|
137
|
+
interface RunWithSpanOptions extends StartSpanOptions {
|
|
138
|
+
}
|
|
139
|
+
declare function runWithSpan<T>(options: string | RunWithSpanOptions, fn: (span?: Span) => Promisable<T>): Promise<T>;
|
|
230
140
|
declare function runInSpanContext<T>(span: Span | undefined, fn: () => Promisable<T>): Promise<T>;
|
|
231
141
|
|
|
232
|
-
|
|
233
|
-
interface AsyncIteratorClassNextFn<T, TReturn> {
|
|
234
|
-
(): Promise<IteratorResult<T, TReturn>>;
|
|
235
|
-
}
|
|
236
|
-
interface AsyncIteratorClassCleanupFn {
|
|
237
|
-
(reason: 'return' | 'throw' | 'next' | 'dispose'): Promise<void>;
|
|
238
|
-
}
|
|
239
|
-
declare const fallbackAsyncDisposeSymbol: unique symbol;
|
|
240
|
-
declare const asyncDisposeSymbol: typeof Symbol extends {
|
|
241
|
-
asyncDispose: infer T;
|
|
242
|
-
} ? T : typeof fallbackAsyncDisposeSymbol;
|
|
243
|
-
declare class AsyncIteratorClass<T, TReturn = unknown, TNext = unknown> implements AsyncIteratorObject<T, TReturn, TNext>, AsyncGenerator<T, TReturn, TNext> {
|
|
244
|
-
#private;
|
|
245
|
-
constructor(next: AsyncIteratorClassNextFn<T, TReturn>, cleanup: AsyncIteratorClassCleanupFn);
|
|
246
|
-
next(): Promise<IteratorResult<T, TReturn>>;
|
|
247
|
-
return(value?: any): Promise<IteratorResult<T, TReturn>>;
|
|
248
|
-
throw(err: any): Promise<IteratorResult<T, TReturn>>;
|
|
142
|
+
interface WrapAsyncIteratorOptions<TYield, TReturn, TMappedYield, TMappedReturn> {
|
|
249
143
|
/**
|
|
250
|
-
*
|
|
144
|
+
* Any call to the original iterator will be executed inside this function.
|
|
145
|
+
* Useful when you want execution to happen within a specific context,
|
|
146
|
+
* such as AsyncLocalStorage.
|
|
251
147
|
*/
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
interface AsyncIteratorWithSpanOptions extends SetSpanErrorOptions {
|
|
148
|
+
runWith?: <T>(run: () => Promise<T>) => Promise<T>;
|
|
149
|
+
mapResult?: (result: IteratorResult<TYield, TReturn>) => Promisable<IteratorResult<TMappedYield, TMappedReturn>>;
|
|
150
|
+
mapError?: (error: unknown) => Promisable<unknown>;
|
|
151
|
+
onError?: (error: unknown) => Promisable<void>;
|
|
257
152
|
/**
|
|
258
|
-
*
|
|
153
|
+
* Execute after the stream finishes or is cancelled.
|
|
259
154
|
*/
|
|
260
|
-
|
|
155
|
+
onFinish?: () => Promisable<void>;
|
|
261
156
|
}
|
|
262
|
-
declare function
|
|
263
|
-
|
|
264
|
-
declare function
|
|
265
|
-
declare function stringifyJSON<T>(value: T | {
|
|
266
|
-
toJSON(): T;
|
|
267
|
-
}): undefined extends T ? undefined | string : string;
|
|
157
|
+
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
|
+
declare function traceAsyncIterator<T, TReturn, TNext>(options: StartSpanOptions | string, iterator: AsyncIterator<T, TReturn, TNext>): AsyncIteratorClass<T, TReturn, TNext>;
|
|
159
|
+
declare function replicateAsyncIterator<T, TReturn, TNext>(source: AsyncIterator<T, TReturn, TNext>, count: number): (AsyncIteratorClass<T, TReturn, TNext>)[];
|
|
268
160
|
|
|
269
161
|
type Segment = string | number;
|
|
270
162
|
declare function findDeepMatches(check: (value: unknown) => boolean, payload: unknown, segments?: Segment[], maps?: Segment[][], values?: unknown[]): {
|
|
@@ -277,43 +169,72 @@ declare function findDeepMatches(check: (value: unknown) => boolean, payload: un
|
|
|
277
169
|
*/
|
|
278
170
|
declare function getConstructor(value: unknown): Function | null | undefined;
|
|
279
171
|
/**
|
|
280
|
-
*
|
|
172
|
+
* Checks whether a value is a plain object, including objects created with
|
|
173
|
+
* `Object.create(null)`.
|
|
281
174
|
*/
|
|
282
|
-
declare function
|
|
175
|
+
declare function isPlainObject(value: unknown): value is Record<PropertyKey, unknown>;
|
|
176
|
+
declare function get(object: unknown, path: readonly PropertyKey[]): unknown;
|
|
283
177
|
/**
|
|
284
|
-
*
|
|
178
|
+
* Sets a value at the given path, creating plain objects for intermediate keys as needed.
|
|
285
179
|
*/
|
|
286
|
-
declare function
|
|
180
|
+
declare function set(root: object, path: [PropertyKey, ...PropertyKey[]] | [...PropertyKey[], PropertyKey], value: unknown): void;
|
|
181
|
+
declare function omit<T extends object, K extends keyof T>(obj: T, keys: readonly K[]): Omit<T, K>;
|
|
287
182
|
declare function clone<T>(value: T): T;
|
|
288
|
-
declare function get(object: unknown, path: readonly PropertyKey[]): unknown;
|
|
289
183
|
declare function isPropertyKey(value: unknown): value is PropertyKey;
|
|
290
184
|
declare const NullProtoObj: ({
|
|
291
185
|
new <T extends Record<PropertyKey, unknown>>(): T;
|
|
292
186
|
});
|
|
187
|
+
/**
|
|
188
|
+
* Returns an object containing all methods of the given object, with each
|
|
189
|
+
* method bound to the original object instance.
|
|
190
|
+
*
|
|
191
|
+
* Methods are collected from both the object itself and its prototype chain
|
|
192
|
+
* (excluding `Object.prototype` and the `constructor` property).
|
|
193
|
+
*/
|
|
194
|
+
declare function bindMethods<T extends object>(obj: T): Pick<T, {
|
|
195
|
+
[K in keyof T]: T[K] extends AnyFunction ? K : never;
|
|
196
|
+
}[keyof T]>;
|
|
293
197
|
|
|
294
|
-
|
|
295
|
-
|
|
198
|
+
interface OrderablePlugin {
|
|
199
|
+
/** Unique name of the plugin, used for ordering and identification. */
|
|
200
|
+
name: string;
|
|
201
|
+
/** Plugins this plugin should execute before. */
|
|
202
|
+
before?: string[] | undefined;
|
|
203
|
+
/** Plugins this plugin should execute after. */
|
|
204
|
+
after?: string[] | undefined;
|
|
205
|
+
}
|
|
296
206
|
/**
|
|
297
|
-
*
|
|
207
|
+
* Sorts plugins based on their `before` and `after` dependencies.
|
|
298
208
|
*/
|
|
299
|
-
declare function
|
|
209
|
+
declare function sortPlugins<T extends OrderablePlugin>(plugins: T[]): T[];
|
|
300
210
|
|
|
301
211
|
/**
|
|
302
|
-
*
|
|
303
|
-
*
|
|
304
|
-
*
|
|
212
|
+
* Creates a promise together with its associated `resolve` and `reject`
|
|
213
|
+
* functions.
|
|
214
|
+
*
|
|
215
|
+
* Equivalent to `Promise.withResolvers()`, but works in environments
|
|
216
|
+
* where that API is not yet available.
|
|
305
217
|
*/
|
|
306
|
-
declare function
|
|
218
|
+
declare function promiseWithResolvers<T>(): {
|
|
219
|
+
promise: Promise<T>;
|
|
220
|
+
resolve: (v: T) => void;
|
|
221
|
+
reject: (reason: unknown) => void;
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
type Value<T, TArgs extends any[] = []> = T | ((...args: TArgs) => T);
|
|
225
|
+
declare function value<T, TArgs extends any[]>(value: Value<T, TArgs>, ...args: NoInfer<TArgs>): T extends Value<infer U, any> ? U : never;
|
|
226
|
+
|
|
307
227
|
/**
|
|
308
|
-
*
|
|
228
|
+
* Creates a proxy that overlays a `partial` object on top of a `target`.
|
|
309
229
|
*
|
|
310
|
-
* - Properties from `
|
|
311
|
-
* - Properties not in `
|
|
312
|
-
* - Methods
|
|
230
|
+
* - Properties from `partial` take precedence.
|
|
231
|
+
* - Properties not present in `partial` fall back to the resolved `target`.
|
|
232
|
+
* - Methods are bound to the proxy to ensure a consistent `this` context.
|
|
313
233
|
*
|
|
314
|
-
* Useful
|
|
234
|
+
* Useful for overriding specific properties of an object while delegating
|
|
235
|
+
* all other access to the original target without needing to know its full structure.
|
|
315
236
|
*/
|
|
316
|
-
declare function
|
|
237
|
+
declare function override<T extends object, U extends object>(target: Value<T>, partial: U): U & Omit<T, keyof U>;
|
|
317
238
|
|
|
318
239
|
interface AsyncIdQueueCloseOptions {
|
|
319
240
|
id?: string;
|
|
@@ -323,21 +244,52 @@ declare class AsyncIdQueue<T> {
|
|
|
323
244
|
private readonly openIds;
|
|
324
245
|
private readonly queues;
|
|
325
246
|
private readonly waiters;
|
|
326
|
-
get
|
|
327
|
-
get waiterIds(): string[];
|
|
328
|
-
hasBufferedItems(id: string): boolean;
|
|
247
|
+
get size(): number;
|
|
329
248
|
open(id: string): void;
|
|
330
249
|
isOpen(id: string): boolean;
|
|
331
250
|
push(id: string, item: T): void;
|
|
332
251
|
pull(id: string): Promise<T>;
|
|
333
252
|
close({ id, reason }?: AsyncIdQueueCloseOptions): void;
|
|
334
|
-
assertOpen
|
|
253
|
+
private assertOpen;
|
|
335
254
|
}
|
|
336
255
|
|
|
256
|
+
/**
|
|
257
|
+
* Returns a signal that aborts only after all provided signals are aborted.
|
|
258
|
+
*/
|
|
259
|
+
declare function allAbortSignal(signals: readonly (AbortSignal | undefined)[]): AbortSignal | undefined;
|
|
260
|
+
declare function runWithSignal<T>(signal: AbortSignal | undefined, fn: () => Promise<T>): Promise<T>;
|
|
261
|
+
|
|
262
|
+
declare function replicateReadableStream<T>(stream: ReadableStream<T>, count: number): ReadableStream<T>[];
|
|
263
|
+
type ReadableStreamReadResult<T> = {
|
|
264
|
+
done: false;
|
|
265
|
+
value: T;
|
|
266
|
+
} | {
|
|
267
|
+
done: true;
|
|
268
|
+
value: undefined | T;
|
|
269
|
+
};
|
|
270
|
+
interface WrapReadableStreamOptions<T, TMapped> {
|
|
271
|
+
/**
|
|
272
|
+
* Any call to the original stream reader will be executed inside this function.
|
|
273
|
+
* Useful when you want execution to happen within a specific context,
|
|
274
|
+
* such as AsyncLocalStorage.
|
|
275
|
+
*/
|
|
276
|
+
runWith?: <T>(run: () => Promise<T>) => Promise<T>;
|
|
277
|
+
mapResult?: (result: ReadableStreamReadResult<T>) => Promisable<ReadableStreamReadResult<TMapped>>;
|
|
278
|
+
mapError?: (error: unknown) => Promisable<unknown>;
|
|
279
|
+
onError?: (error: unknown) => Promisable<void>;
|
|
280
|
+
/**
|
|
281
|
+
* Guaranteed to execute exactly once after the stream finishes or is cancelled.
|
|
282
|
+
*/
|
|
283
|
+
onFinish?: () => Promisable<void>;
|
|
284
|
+
}
|
|
285
|
+
declare function wrapReadableStream<T, TMapped = T>(stream: ReadableStream<T>, { runWith, mapResult, mapError, onError, onFinish }: WrapReadableStreamOptions<T, TMapped>): NoInfer<ReadableStream<TMapped>>;
|
|
286
|
+
declare function traceReadableStream<T>(options: StartSpanOptions | string, stream: ReadableStream<T>): ReadableStream<T>;
|
|
337
287
|
/**
|
|
338
288
|
* Converts a `ReadableStream` into an `AsyncIteratorClass`.
|
|
339
289
|
*/
|
|
340
|
-
declare function streamToAsyncIteratorClass<T>(stream: ReadableStream<T
|
|
290
|
+
declare function streamToAsyncIteratorClass<T>(stream: ReadableStream<T>, { signal }?: {
|
|
291
|
+
signal?: undefined | AbortSignal;
|
|
292
|
+
}): AsyncIteratorClass<T>;
|
|
341
293
|
/**
|
|
342
294
|
* Converts an `AsyncIterator` into a `ReadableStream`.
|
|
343
295
|
*/
|
|
@@ -350,5 +302,5 @@ declare function asyncIteratorToUnproxiedDataStream<T>(iterator: AsyncIterator<T
|
|
|
350
302
|
|
|
351
303
|
declare function tryDecodeURIComponent(value: string): string;
|
|
352
304
|
|
|
353
|
-
export {
|
|
354
|
-
export type { AnyFunction, AsyncIdQueueCloseOptions,
|
|
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 };
|