@orpc/shared 1.14.11 → 1.14.13
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 +48 -52
- package/dist/index.d.mts +202 -211
- package/dist/index.d.ts +202 -211
- package/dist/index.mjs +358 -638
- package/package.json +7 -8
package/dist/index.d.ts
CHANGED
|
@@ -1,48 +1,108 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { Promisable } from 'type-fest';
|
|
2
|
+
export { IsEqual, IsNever, JsonValue, PartialDeep, Promisable } from 'type-fest';
|
|
3
3
|
import { Tracer, TraceAPI, ContextAPI, PropagationAPI, SpanOptions, Context, Span, AttributeValue, Exception } from '@opentelemetry/api';
|
|
4
|
-
|
|
5
|
-
export { AbortError, AsyncCleanupFn, AsyncIteratorClass, AsyncIteratorClassNextFn, SequentialIdGenerator, getOrBind, isAsyncIteratorObject, isTypescriptObject, parseEmptyableJSON, sequential, sleep, stringifyJSON, toArray } from '@standardserver/shared';
|
|
4
|
+
export { group, guard, mapEntries, mapValues, omit, retry, sleep } from 'radash';
|
|
6
5
|
|
|
7
|
-
type MaybeOptionalOptions<TOptions> =
|
|
6
|
+
type MaybeOptionalOptions<TOptions> = Record<never, never> extends TOptions ? [options?: TOptions] : [options: TOptions];
|
|
8
7
|
declare function resolveMaybeOptionalOptions<T>(rest: MaybeOptionalOptions<T>): T;
|
|
9
8
|
|
|
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
|
+
* Converts Request/Response/Blob/File/.. to a buffer (ArrayBuffer or Uint8Array).
|
|
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
|
|
17
|
+
declare function readAsBuffer(source: Pick<Blob, 'arrayBuffer' | 'bytes'>): Promise<ArrayBuffer | Uint8Array>;
|
|
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>;
|
|
18
22
|
/**
|
|
19
|
-
*
|
|
20
|
-
* - the original string value, or
|
|
21
|
-
* - a Uint8Array view over the source bytes.
|
|
23
|
+
* Executes the callback function after the current call stack has been cleared.
|
|
22
24
|
*/
|
|
23
|
-
declare function
|
|
25
|
+
declare function defer(callback: () => void): void;
|
|
24
26
|
|
|
25
|
-
|
|
27
|
+
type OmitChainMethodDeep<T extends object, K extends keyof any> = {
|
|
28
|
+
[P in keyof Omit<T, K>]: T[P] extends AnyFunction ? ((...args: Parameters<T[P]>) => OmitChainMethodDeep<ReturnType<T[P]>, K>) : T[P];
|
|
29
|
+
};
|
|
26
30
|
|
|
27
31
|
declare const ORPC_NAME = "orpc";
|
|
32
|
+
declare const ORPC_SHARED_PACKAGE_NAME = "@orpc/shared";
|
|
33
|
+
declare const ORPC_SHARED_PACKAGE_VERSION = "1.14.13";
|
|
28
34
|
|
|
29
|
-
declare function isAbortError(error: unknown): error is Error;
|
|
30
|
-
|
|
31
|
-
type AnyFunction = (...args: any[]) => any;
|
|
32
|
-
declare function once<T>(fn: () => T): () => T;
|
|
33
35
|
/**
|
|
34
|
-
*
|
|
36
|
+
* Error thrown when an operation is aborted.
|
|
37
|
+
* Uses the standardized 'AbortError' name for consistency with JavaScript APIs.
|
|
35
38
|
*/
|
|
36
|
-
declare
|
|
37
|
-
|
|
39
|
+
declare class AbortError extends Error {
|
|
40
|
+
constructor(...rest: ConstructorParameters<typeof Error>);
|
|
41
|
+
}
|
|
38
42
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
interface EventPublisherOptions {
|
|
44
|
+
/**
|
|
45
|
+
* Maximum number of events to buffer for async iterator subscribers.
|
|
46
|
+
*
|
|
47
|
+
* If the buffer exceeds this limit, the oldest event is dropped.
|
|
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
|
+
}
|
|
45
101
|
|
|
102
|
+
declare class SequentialIdGenerator {
|
|
103
|
+
private index;
|
|
104
|
+
generate(): string;
|
|
105
|
+
}
|
|
46
106
|
/**
|
|
47
107
|
* Compares two sequential IDs.
|
|
48
108
|
* Returns:
|
|
@@ -52,11 +112,8 @@ declare function isCompressibleContentType(contentType: string | null | undefine
|
|
|
52
112
|
*/
|
|
53
113
|
declare function compareSequentialIds(a: string, b: string): number;
|
|
54
114
|
|
|
115
|
+
type SetOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
55
116
|
type IntersectPick<T, U> = Pick<T, keyof T & keyof U>;
|
|
56
|
-
/**
|
|
57
|
-
* Remove protected/private properties/methods
|
|
58
|
-
*/
|
|
59
|
-
type Public<T> = Pick<T, keyof T>;
|
|
60
117
|
type PromiseWithError<T, TError> = Promise<T> & {
|
|
61
118
|
__error?: {
|
|
62
119
|
type: TError;
|
|
@@ -65,13 +122,14 @@ type PromiseWithError<T, TError> = Promise<T> & {
|
|
|
65
122
|
/**
|
|
66
123
|
* The place where you can config the orpc types.
|
|
67
124
|
*
|
|
68
|
-
* - `
|
|
125
|
+
* - `throwableError` the error type that represent throwable errors should be `Error` or `null | undefined | {}` if you want more strict.
|
|
69
126
|
*/
|
|
70
127
|
interface Registry {
|
|
71
128
|
}
|
|
72
129
|
type ThrowableError = Registry extends {
|
|
73
|
-
|
|
130
|
+
throwableError: infer T;
|
|
74
131
|
} ? T : Error;
|
|
132
|
+
type InferAsyncIterableYield<T> = T extends AsyncIterable<infer U> ? U : never;
|
|
75
133
|
|
|
76
134
|
type InterceptableOptions = Record<string, any>;
|
|
77
135
|
type InterceptorOptions<TOptions extends InterceptableOptions, TResult> = Omit<TOptions, 'next'> & {
|
|
@@ -79,138 +137,136 @@ type InterceptorOptions<TOptions extends InterceptableOptions, TResult> = Omit<T
|
|
|
79
137
|
};
|
|
80
138
|
type Interceptor<TOptions extends InterceptableOptions, TResult> = (options: InterceptorOptions<TOptions, TResult>) => TResult;
|
|
81
139
|
/**
|
|
82
|
-
* Can used for interceptors or middlewares
|
|
140
|
+
* Can be used for interceptors or middlewares
|
|
83
141
|
*/
|
|
84
142
|
declare function onStart<T, TOptions extends {
|
|
85
|
-
next
|
|
143
|
+
next(): any;
|
|
86
144
|
}, TRest extends any[]>(callback: NoInfer<(options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => T | Promise<Awaited<ReturnType<TOptions['next']>>>;
|
|
87
145
|
/**
|
|
88
|
-
* Can used for interceptors or middlewares
|
|
146
|
+
* Can be used for interceptors or middlewares
|
|
89
147
|
*/
|
|
90
148
|
declare function onSuccess<T, TOptions extends {
|
|
91
|
-
next
|
|
149
|
+
next(): any;
|
|
92
150
|
}, 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']>>>;
|
|
93
151
|
/**
|
|
94
|
-
* Can used for interceptors or middlewares
|
|
152
|
+
* Can be used for interceptors or middlewares
|
|
95
153
|
*/
|
|
96
154
|
declare function onError<T, TOptions extends {
|
|
97
|
-
next
|
|
155
|
+
next(): any;
|
|
98
156
|
}, 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']>>>;
|
|
99
157
|
type OnFinishState<TResult, TError> = [error: TError, data: undefined, isSuccess: false] | [error: null, data: TResult, isSuccess: true];
|
|
100
158
|
/**
|
|
101
|
-
* Can used for interceptors or middlewares
|
|
159
|
+
* Can be used for interceptors or middlewares
|
|
102
160
|
*/
|
|
103
161
|
declare function onFinish<T, TOptions extends {
|
|
104
|
-
next
|
|
162
|
+
next(): any;
|
|
105
163
|
}, 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']>>>;
|
|
106
|
-
|
|
107
|
-
* Creates a middleware or interceptor that invokes a callback when the returned async
|
|
108
|
-
* iterator object throws an error while being consumed.
|
|
109
|
-
*
|
|
110
|
-
* This does not replace the `onError`. `onError` only fires on the
|
|
111
|
-
* initial call (before the interceptor returns the iterator), whereas this
|
|
112
|
-
* callback only fires while consuming the iterator. Use both together to
|
|
113
|
-
* catch all possible errors.
|
|
114
|
-
*/
|
|
115
|
-
declare function onAsyncIteratorObjectError<T, TOptions extends {
|
|
116
|
-
next: () => any;
|
|
117
|
-
}, 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']>>>;
|
|
118
|
-
/**
|
|
119
|
-
* Creates an interceptor that invokes a callback when the returned readable
|
|
120
|
-
* stream errors while being consumed.
|
|
121
|
-
*
|
|
122
|
-
* This does not replace the `onError`. `onError` only fires on the
|
|
123
|
-
* initial call (before the interceptor returns the stream), whereas this
|
|
124
|
-
* callback only fires while consuming the stream. Use both together to catch
|
|
125
|
-
* all possible errors.
|
|
126
|
-
*/
|
|
127
|
-
declare function onReadableStreamError<T, TOptions extends {
|
|
128
|
-
next: () => any;
|
|
129
|
-
}, 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']>>>;
|
|
130
|
-
declare function intercept<TOptions extends InterceptableOptions, TResult>(interceptors: undefined | Interceptor<TOptions, TResult>[], options: NoInfer<TOptions>, main: NoInfer<(options: TOptions) => TResult>): TResult;
|
|
164
|
+
declare function intercept<TOptions extends InterceptableOptions, TResult>(interceptors: Interceptor<TOptions, TResult>[], options: NoInfer<TOptions>, main: NoInfer<(options: TOptions) => TResult>): TResult;
|
|
131
165
|
|
|
132
166
|
/**
|
|
133
167
|
* Only import types from @opentelemetry/api to avoid runtime dependencies.
|
|
134
168
|
*/
|
|
135
169
|
|
|
136
|
-
interface
|
|
170
|
+
interface OtelConfig {
|
|
137
171
|
tracer: Tracer;
|
|
138
172
|
trace: TraceAPI;
|
|
139
173
|
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 {
|
|
140
193
|
/**
|
|
141
|
-
*
|
|
194
|
+
* Span error status is not set if error is due to cancellation by the signal.
|
|
142
195
|
*/
|
|
143
|
-
|
|
196
|
+
signal?: AbortSignal;
|
|
144
197
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
198
|
+
/**
|
|
199
|
+
* Records and sets the error status on the given span.
|
|
200
|
+
* If the span is `undefined`, it does nothing.
|
|
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 {
|
|
148
213
|
/**
|
|
149
214
|
* The name of the span to create.
|
|
150
215
|
*/
|
|
151
216
|
name: string;
|
|
152
217
|
/**
|
|
153
|
-
* Context to use for the
|
|
218
|
+
* Context to use for the span.
|
|
154
219
|
*/
|
|
155
220
|
context?: Context;
|
|
156
221
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
declare function
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
222
|
+
/**
|
|
223
|
+
* Runs a function within the context of a new OpenTelemetry span.
|
|
224
|
+
* The span is ended automatically, and errors are recorded to the span.
|
|
225
|
+
*/
|
|
226
|
+
declare function runWithSpan<T>({ name, context, ...options }: RunWithSpanOptions, fn: (span?: Span) => Promisable<T>): Promise<T>;
|
|
227
|
+
/**
|
|
228
|
+
* Runs a function within the context of an existing OpenTelemetry span.
|
|
229
|
+
*/
|
|
165
230
|
declare function runInSpanContext<T>(span: Span | undefined, fn: () => Promisable<T>): Promise<T>;
|
|
166
231
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
232
|
+
declare function isAsyncIteratorObject(maybe: unknown): maybe is AsyncIteratorObject<any, any, any>;
|
|
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>>;
|
|
177
249
|
/**
|
|
178
|
-
*
|
|
250
|
+
* asyncDispose symbol only available in esnext, we should fallback to Symbol.for('asyncDispose')
|
|
179
251
|
*/
|
|
180
|
-
|
|
252
|
+
[asyncDisposeSymbol](): Promise<void>;
|
|
253
|
+
[Symbol.asyncIterator](): this;
|
|
181
254
|
}
|
|
182
|
-
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>>;
|
|
183
|
-
declare function traceAsyncIterator<T, TReturn, TNext>(options: StartSpanOptions | string, iterator: AsyncIterator<T, TReturn, TNext>): AsyncIteratorClass<T, TReturn, TNext>;
|
|
184
255
|
declare function replicateAsyncIterator<T, TReturn, TNext>(source: AsyncIterator<T, TReturn, TNext>, count: number): (AsyncIteratorClass<T, TReturn, TNext>)[];
|
|
185
|
-
interface
|
|
186
|
-
/**
|
|
187
|
-
* Called on each event
|
|
188
|
-
*/
|
|
189
|
-
onEvent: (event: T) => void;
|
|
256
|
+
interface AsyncIteratorWithSpanOptions extends SetSpanErrorOptions {
|
|
190
257
|
/**
|
|
191
|
-
*
|
|
192
|
-
*/
|
|
193
|
-
onError?: (error: TError) => void;
|
|
194
|
-
/**
|
|
195
|
-
* Called once AsyncIteratorObject is done
|
|
196
|
-
*
|
|
197
|
-
* @info If iterator is canceled, `undefined` can be passed on success
|
|
198
|
-
*/
|
|
199
|
-
onSuccess?: (value: TReturn | undefined) => void;
|
|
200
|
-
/**
|
|
201
|
-
* Called once after onError or onSuccess
|
|
202
|
-
*
|
|
203
|
-
* @info If iterator is canceled, `undefined` can be passed on success
|
|
258
|
+
* The name of the span to create.
|
|
204
259
|
*/
|
|
205
|
-
|
|
260
|
+
name: string;
|
|
206
261
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
262
|
+
declare function asyncIteratorWithSpan<T, TReturn, TNext>({ name, ...options }: AsyncIteratorWithSpanOptions, iterator: AsyncIterator<T, TReturn, TNext>): AsyncIteratorClass<T, TReturn, TNext>;
|
|
263
|
+
|
|
264
|
+
declare function parseEmptyableJSON(text: string | null | undefined): unknown;
|
|
265
|
+
declare function stringifyJSON<T>(value: T | {
|
|
266
|
+
toJSON(): T;
|
|
267
|
+
}): undefined extends T ? undefined | string : string;
|
|
268
|
+
|
|
269
|
+
declare function logError(error: unknown): void;
|
|
214
270
|
|
|
215
271
|
type Segment = string | number;
|
|
216
272
|
declare function findDeepMatches(check: (value: unknown) => boolean, payload: unknown, segments?: Segment[], maps?: Segment[][], values?: unknown[]): {
|
|
@@ -223,72 +279,43 @@ declare function findDeepMatches(check: (value: unknown) => boolean, payload: un
|
|
|
223
279
|
*/
|
|
224
280
|
declare function getConstructor(value: unknown): Function | null | undefined;
|
|
225
281
|
/**
|
|
226
|
-
*
|
|
227
|
-
* `Object.create(null)`.
|
|
282
|
+
* Check if the value is an object even it created by `Object.create(null)` or more tricky way.
|
|
228
283
|
*/
|
|
229
|
-
declare function
|
|
230
|
-
declare function get(object: unknown, path: readonly PropertyKey[]): unknown;
|
|
284
|
+
declare function isObject(value: unknown): value is Record<PropertyKey, unknown>;
|
|
231
285
|
/**
|
|
232
|
-
*
|
|
286
|
+
* Check if the value satisfy a `object` type in typescript
|
|
233
287
|
*/
|
|
234
|
-
declare function
|
|
235
|
-
declare function omit<T extends object, K extends keyof T>(obj: T, keys: readonly K[]): Omit<T, K>;
|
|
288
|
+
declare function isTypescriptObject(value: unknown): value is object & Record<PropertyKey, unknown>;
|
|
236
289
|
declare function clone<T>(value: T): T;
|
|
290
|
+
declare function get(object: unknown, path: readonly PropertyKey[]): unknown;
|
|
237
291
|
declare function isPropertyKey(value: unknown): value is PropertyKey;
|
|
238
292
|
declare const NullProtoObj: ({
|
|
239
293
|
new <T extends Record<PropertyKey, unknown>>(): T;
|
|
240
294
|
});
|
|
241
|
-
/**
|
|
242
|
-
* Returns an object containing all methods of the given object, with each
|
|
243
|
-
* method bound to the original object instance.
|
|
244
|
-
*
|
|
245
|
-
* Methods are collected from both the object itself and its prototype chain
|
|
246
|
-
* (excluding `Object.prototype` and the `constructor` property).
|
|
247
|
-
*/
|
|
248
|
-
declare function bindMethods<T extends object>(obj: T): Pick<T, {
|
|
249
|
-
[K in keyof T]: T[K] extends AnyFunction ? K : never;
|
|
250
|
-
}[keyof T]>;
|
|
251
295
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
name: string;
|
|
255
|
-
/** Plugins this plugin should execute before. */
|
|
256
|
-
before?: string[] | undefined;
|
|
257
|
-
/** Plugins this plugin should execute after. */
|
|
258
|
-
after?: string[] | undefined;
|
|
259
|
-
}
|
|
296
|
+
type Value<T, TArgs extends any[] = []> = T | ((...args: TArgs) => T);
|
|
297
|
+
declare function value<T, TArgs extends any[]>(value: Value<T, TArgs>, ...args: NoInfer<TArgs>): T extends Value<infer U, any> ? U : never;
|
|
260
298
|
/**
|
|
261
|
-
*
|
|
299
|
+
* Returns the value if it is defined, otherwise returns the fallback
|
|
262
300
|
*/
|
|
263
|
-
declare function
|
|
301
|
+
declare function fallback<T>(value: T | undefined, fallback: T): T;
|
|
264
302
|
|
|
265
303
|
/**
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
* Equivalent to `Promise.withResolvers()`, but works in environments
|
|
270
|
-
* where that API is not yet available.
|
|
304
|
+
* Prevents objects from being awaitable by intercepting the `then` method
|
|
305
|
+
* when called by the native await mechanism. This is useful for preventing
|
|
306
|
+
* accidental awaiting of objects that aren't meant to be promises.
|
|
271
307
|
*/
|
|
272
|
-
declare function
|
|
273
|
-
promise: Promise<T>;
|
|
274
|
-
resolve: (v: T) => void;
|
|
275
|
-
reject: (reason: unknown) => void;
|
|
276
|
-
};
|
|
277
|
-
|
|
278
|
-
type Value<T, TArgs extends any[] = []> = T | ((...args: TArgs) => T);
|
|
279
|
-
declare function value<T, TArgs extends any[]>(value: Value<T, TArgs>, ...args: NoInfer<TArgs>): T extends Value<infer U, any> ? U : never;
|
|
280
|
-
|
|
308
|
+
declare function preventNativeAwait<T extends object>(target: T): T;
|
|
281
309
|
/**
|
|
282
|
-
*
|
|
310
|
+
* Create a proxy that overlays one object (`overlay`) on top of another (`target`).
|
|
283
311
|
*
|
|
284
|
-
* - Properties from `
|
|
285
|
-
* - Properties not
|
|
286
|
-
* - Methods
|
|
312
|
+
* - Properties from `overlay` take precedence.
|
|
313
|
+
* - Properties not in `overlay` fall back to `target`.
|
|
314
|
+
* - Methods from either object are bound to `overlay` so `this` is consistent.
|
|
287
315
|
*
|
|
288
|
-
* Useful
|
|
289
|
-
* all other access to the original target without needing to know its full structure.
|
|
316
|
+
* Useful when you want to override or extend behavior without fully copying/merging objects.
|
|
290
317
|
*/
|
|
291
|
-
declare function
|
|
318
|
+
declare function overlayProxy<T extends object, U extends object>(target: Value<T>, partial: U): U & Omit<T, keyof U>;
|
|
292
319
|
|
|
293
320
|
interface AsyncIdQueueCloseOptions {
|
|
294
321
|
id?: string;
|
|
@@ -298,57 +325,21 @@ declare class AsyncIdQueue<T> {
|
|
|
298
325
|
private readonly openIds;
|
|
299
326
|
private readonly queues;
|
|
300
327
|
private readonly waiters;
|
|
301
|
-
get
|
|
328
|
+
get length(): number;
|
|
329
|
+
get waiterIds(): string[];
|
|
330
|
+
hasBufferedItems(id: string): boolean;
|
|
302
331
|
open(id: string): void;
|
|
303
332
|
isOpen(id: string): boolean;
|
|
304
333
|
push(id: string, item: T): void;
|
|
305
334
|
pull(id: string): Promise<T>;
|
|
306
335
|
close({ id, reason }?: AsyncIdQueueCloseOptions): void;
|
|
307
|
-
|
|
336
|
+
assertOpen(id: string): void;
|
|
308
337
|
}
|
|
309
338
|
|
|
310
339
|
/**
|
|
311
|
-
*
|
|
312
|
-
*/
|
|
313
|
-
declare function allAbortSignal(signals: readonly (AbortSignal | undefined)[]): AbortSignal | undefined;
|
|
314
|
-
/**
|
|
315
|
-
* Returns a signal that aborts as soon as any of the provided signals aborts,
|
|
316
|
-
* with the same abort reason.
|
|
317
|
-
*/
|
|
318
|
-
declare function anyAbortSignal(signals: readonly (AbortSignal | undefined)[]): AbortSignal | undefined;
|
|
319
|
-
declare function runWithSignal<T>(signal: AbortSignal | undefined, fn: () => Promise<T>): Promise<T>;
|
|
320
|
-
|
|
321
|
-
declare function replicateReadableStream<T>(stream: ReadableStream<T>, count: number): ReadableStream<T>[];
|
|
322
|
-
type ReadableStreamReadResult<T> = {
|
|
323
|
-
done: false;
|
|
324
|
-
value: T;
|
|
325
|
-
} | {
|
|
326
|
-
done: true;
|
|
327
|
-
value?: undefined | T;
|
|
328
|
-
};
|
|
329
|
-
interface WrapReadableStreamOptions<T, TMapped> {
|
|
330
|
-
/**
|
|
331
|
-
* Any call to the original stream reader will be executed inside this function.
|
|
332
|
-
* Useful when you want execution to happen within a specific context,
|
|
333
|
-
* such as AsyncLocalStorage.
|
|
334
|
-
*/
|
|
335
|
-
runWith?: <T>(run: () => Promise<T>) => Promise<T>;
|
|
336
|
-
mapResult?: (result: ReadableStreamReadResult<T>) => Promisable<ReadableStreamReadResult<TMapped>>;
|
|
337
|
-
mapError?: (error: ThrowableError) => Promisable<ThrowableError>;
|
|
338
|
-
onError?: (error: ThrowableError) => Promisable<void>;
|
|
339
|
-
/**
|
|
340
|
-
* Guaranteed to execute exactly once after the stream finishes or is cancelled.
|
|
341
|
-
*/
|
|
342
|
-
onFinish?: () => Promisable<void>;
|
|
343
|
-
}
|
|
344
|
-
declare function wrapReadableStream<T, TMapped = T>(stream: ReadableStream<T>, { runWith, mapResult, mapError, onError, onFinish }: WrapReadableStreamOptions<T, TMapped>): NoInfer<ReadableStream<TMapped>>;
|
|
345
|
-
declare function traceReadableStream<T>(options: StartSpanOptions | string, stream: ReadableStream<T>): ReadableStream<T>;
|
|
346
|
-
/**
|
|
347
|
-
* Converts a {@link ReadableStream} into an {@link AsyncIteratorClass}.
|
|
340
|
+
* Converts a `ReadableStream` into an `AsyncIteratorClass`.
|
|
348
341
|
*/
|
|
349
|
-
declare function
|
|
350
|
-
signal?: undefined | AbortSignal;
|
|
351
|
-
}): AsyncIteratorClass<T>;
|
|
342
|
+
declare function streamToAsyncIteratorClass<T>(stream: ReadableStream<T>): AsyncIteratorClass<T>;
|
|
352
343
|
/**
|
|
353
344
|
* Converts an `AsyncIterator` into a `ReadableStream`.
|
|
354
345
|
*/
|
|
@@ -361,5 +352,5 @@ declare function asyncIteratorToUnproxiedDataStream<T>(iterator: AsyncIterator<T
|
|
|
361
352
|
|
|
362
353
|
declare function tryDecodeURIComponent(value: string): string;
|
|
363
354
|
|
|
364
|
-
export { AsyncIdQueue, NullProtoObj, ORPC_NAME,
|
|
365
|
-
export type { AnyFunction, AsyncIdQueueCloseOptions,
|
|
355
|
+
export { AbortError, AsyncIdQueue, AsyncIteratorClass, EventPublisher, NullProtoObj, ORPC_NAME, ORPC_SHARED_PACKAGE_NAME, ORPC_SHARED_PACKAGE_VERSION, SequentialIdGenerator, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, asyncIteratorWithSpan, clone, compareSequentialIds, defer, fallback, findDeepMatches, get, getConstructor, getGlobalOtelConfig, intercept, isAsyncIteratorObject, isObject, isPropertyKey, isTypescriptObject, logError, onError, onFinish, onStart, onSuccess, once, overlayProxy, parseEmptyableJSON, preventNativeAwait, readAsBuffer, replicateAsyncIterator, resolveMaybeOptionalOptions, runInSpanContext, runWithSpan, sequential, setGlobalOtelConfig, setSpanAttribute, setSpanError, splitInHalf, startSpan, streamToAsyncIteratorClass, stringifyJSON, toArray, toOtelException, toSpanAttributeValue, tryDecodeURIComponent, value };
|
|
356
|
+
export type { AnyFunction, AsyncIdQueueCloseOptions, AsyncIteratorClassCleanupFn, AsyncIteratorClassNextFn, AsyncIteratorWithSpanOptions, EventPublisherOptions, EventPublisherSubscribeIteratorOptions, InferAsyncIterableYield, InterceptableOptions, Interceptor, InterceptorOptions, IntersectPick, MaybeOptionalOptions, OmitChainMethodDeep, OnFinishState, OtelConfig, PromiseWithError, Registry, RunWithSpanOptions, Segment, SetOptional, SetSpanErrorOptions, ThrowableError, Value };
|