@temporary-name/shared 1.9.3-alpha.03e17aa3340f4b261a549bf9e3fe948b084e2309

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Stainless
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ ## `@temporary-name/shared`
2
+
3
+ Provides shared utilities for oRPC packages.
@@ -0,0 +1,509 @@
1
+ import { MaybeOptionalOptions as MaybeOptionalOptions$1, ThrowableError as ThrowableError$1 } from '@temporary-name/shared';
2
+ import { Tracer, TraceAPI, ContextAPI, PropagationAPI, SpanOptions, Context, Span, AttributeValue, Exception } from '@opentelemetry/api';
3
+ export { group, guard, mapEntries, mapValues, omit, retry, sleep } from 'radash';
4
+
5
+ type MaybeOptionalOptions<TOptions> = Record<never, never> extends TOptions ? [options?: TOptions] : [options: TOptions];
6
+ declare function resolveMaybeOptionalOptions<T>(rest: MaybeOptionalOptions<T>): T;
7
+
8
+ declare function toArray<T>(value: T): T extends readonly any[] ? T : Exclude<T, undefined | null>[];
9
+ declare function splitInHalf<T>(arr: readonly T[]): [T[], T[]];
10
+
11
+ /**
12
+ * Converts Request/Response/Blob/File/.. to a buffer (ArrayBuffer or Uint8Array).
13
+ *
14
+ * Prefers the newer `.bytes` method when available as it more efficient but not widely supported yet.
15
+ */
16
+ declare function readAsBuffer(source: Pick<Blob, 'arrayBuffer' | 'bytes'>): Promise<ArrayBuffer | Uint8Array>;
17
+
18
+ type AnyFunction = (...args: any[]) => any;
19
+ declare function once<T extends () => any>(fn: T): () => ReturnType<T>;
20
+ declare function sequential<A extends any[], R>(fn: (...args: A) => Promise<R>): (...args: A) => Promise<R>;
21
+ /**
22
+ * Executes the callback function after the current call stack has been cleared.
23
+ */
24
+ declare function defer(callback: () => void): void;
25
+
26
+ type OmitChainMethodDeep<T extends object, K extends keyof any> = {
27
+ [P in keyof Omit<T, K>]: T[P] extends AnyFunction ? (...args: Parameters<T[P]>) => OmitChainMethodDeep<ReturnType<T[P]>, K> : T[P];
28
+ };
29
+
30
+ declare const ORPC_NAME = "orpc";
31
+ declare const ORPC_SHARED_PACKAGE_NAME = "@temporary-name/shared";
32
+ declare const ORPC_SHARED_PACKAGE_VERSION = "1.9.3-alpha.03e17aa3340f4b261a549bf9e3fe948b084e2309";
33
+
34
+ declare const ORPC_CLIENT_PACKAGE_NAME = "__ORPC_CLIENT_PACKAGE_NAME_PLACEHOLDER__";
35
+ declare const ORPC_CLIENT_PACKAGE_VERSION = "__ORPC_CLIENT_PACKAGE_VERSION_PLACEHOLDER__";
36
+ declare const COMMON_ORPC_ERROR_DEFS: {
37
+ readonly BAD_REQUEST: {
38
+ readonly status: 400;
39
+ readonly message: "Bad Request";
40
+ };
41
+ readonly UNAUTHORIZED: {
42
+ readonly status: 401;
43
+ readonly message: "Unauthorized";
44
+ };
45
+ readonly FORBIDDEN: {
46
+ readonly status: 403;
47
+ readonly message: "Forbidden";
48
+ };
49
+ readonly NOT_FOUND: {
50
+ readonly status: 404;
51
+ readonly message: "Not Found";
52
+ };
53
+ readonly METHOD_NOT_SUPPORTED: {
54
+ readonly status: 405;
55
+ readonly message: "Method Not Supported";
56
+ };
57
+ readonly NOT_ACCEPTABLE: {
58
+ readonly status: 406;
59
+ readonly message: "Not Acceptable";
60
+ };
61
+ readonly TIMEOUT: {
62
+ readonly status: 408;
63
+ readonly message: "Request Timeout";
64
+ };
65
+ readonly CONFLICT: {
66
+ readonly status: 409;
67
+ readonly message: "Conflict";
68
+ };
69
+ readonly PRECONDITION_FAILED: {
70
+ readonly status: 412;
71
+ readonly message: "Precondition Failed";
72
+ };
73
+ readonly PAYLOAD_TOO_LARGE: {
74
+ readonly status: 413;
75
+ readonly message: "Payload Too Large";
76
+ };
77
+ readonly UNSUPPORTED_MEDIA_TYPE: {
78
+ readonly status: 415;
79
+ readonly message: "Unsupported Media Type";
80
+ };
81
+ readonly UNPROCESSABLE_CONTENT: {
82
+ readonly status: 422;
83
+ readonly message: "Unprocessable Content";
84
+ };
85
+ readonly TOO_MANY_REQUESTS: {
86
+ readonly status: 429;
87
+ readonly message: "Too Many Requests";
88
+ };
89
+ readonly CLIENT_CLOSED_REQUEST: {
90
+ readonly status: 499;
91
+ readonly message: "Client Closed Request";
92
+ };
93
+ readonly INTERNAL_SERVER_ERROR: {
94
+ readonly status: 500;
95
+ readonly message: "Internal Server Error";
96
+ };
97
+ readonly NOT_IMPLEMENTED: {
98
+ readonly status: 501;
99
+ readonly message: "Not Implemented";
100
+ };
101
+ readonly BAD_GATEWAY: {
102
+ readonly status: 502;
103
+ readonly message: "Bad Gateway";
104
+ };
105
+ readonly SERVICE_UNAVAILABLE: {
106
+ readonly status: 503;
107
+ readonly message: "Service Unavailable";
108
+ };
109
+ readonly GATEWAY_TIMEOUT: {
110
+ readonly status: 504;
111
+ readonly message: "Gateway Timeout";
112
+ };
113
+ };
114
+ type CommonORPCErrorCode = keyof typeof COMMON_ORPC_ERROR_DEFS;
115
+ type ORPCErrorCode = CommonORPCErrorCode | (string & {});
116
+ declare function fallbackORPCErrorStatus(code: ORPCErrorCode, status: number | undefined): number;
117
+ declare function fallbackORPCErrorMessage(code: ORPCErrorCode, message: string | undefined): string;
118
+ type ORPCErrorOptions<TData> = ErrorOptions & {
119
+ defined?: boolean;
120
+ status?: number;
121
+ message?: string;
122
+ } & (undefined extends TData ? {
123
+ data?: TData;
124
+ } : {
125
+ data: TData;
126
+ });
127
+ declare class ORPCError<TCode extends ORPCErrorCode, TData> extends Error {
128
+ readonly defined: boolean;
129
+ readonly code: TCode;
130
+ readonly status: number;
131
+ readonly data: TData;
132
+ constructor(code: TCode, ...rest: MaybeOptionalOptions$1<ORPCErrorOptions<TData>>);
133
+ toJSON(): ORPCErrorJSON<TCode, TData>;
134
+ /**
135
+ * Workaround for Next.js where different contexts use separate
136
+ * dependency graphs, causing multiple ORPCError constructors existing and breaking
137
+ * `instanceof` checks across contexts.
138
+ *
139
+ * This is particularly problematic with "Optimized SSR", where orpc-client
140
+ * executes in one context but is invoked from another. When an error is thrown
141
+ * in the execution context, `instanceof ORPCError` checks fail in the
142
+ * invocation context due to separate class constructors.
143
+ *
144
+ * @todo Remove this and related code if Next.js resolves the multiple dependency graph issue.
145
+ */
146
+ static [Symbol.hasInstance](instance: unknown): boolean;
147
+ }
148
+ type ORPCErrorJSON<TCode extends string, TData> = Pick<ORPCError<TCode, TData>, 'defined' | 'code' | 'status' | 'message' | 'data'>;
149
+ declare function isDefinedError<T>(error: T): error is Extract<T, ORPCError<any, any>>;
150
+ declare function toORPCError(error: unknown): ORPCError<any, any>;
151
+ declare function isORPCErrorStatus(status: number): boolean;
152
+ declare function isORPCErrorJson(json: unknown): json is ORPCErrorJSON<ORPCErrorCode, unknown>;
153
+ declare function createORPCErrorFromJson<TCode extends ORPCErrorCode, TData>(json: ORPCErrorJSON<TCode, TData>, options?: ErrorOptions): ORPCError<TCode, TData>;
154
+ /**
155
+ * Error thrown when an operation is aborted.
156
+ * Uses the standardized 'AbortError' name for consistency with JavaScript APIs.
157
+ */
158
+ declare class AbortError extends Error {
159
+ constructor(...rest: ConstructorParameters<typeof Error>);
160
+ }
161
+
162
+ interface EventPublisherOptions {
163
+ /**
164
+ * Maximum number of events to buffer for async iterator subscribers.
165
+ *
166
+ * If the buffer exceeds this limit, the oldest event is dropped.
167
+ * This prevents unbounded memory growth if consumers process events slowly.
168
+ *
169
+ * Set to:
170
+ * - `0`: Disable buffering. Events must be consumed before the next one arrives.
171
+ * - `1`: Only keep the latest event. Useful for real-time updates where only the most recent value matters.
172
+ * - `Infinity`: Keep all events. Ensures no data loss, but may lead to high memory usage.
173
+ *
174
+ * @default 100
175
+ */
176
+ maxBufferedEvents?: number;
177
+ }
178
+ interface EventPublisherSubscribeIteratorOptions extends EventPublisherOptions {
179
+ /**
180
+ * Aborts the async iterator. Throws if aborted before or during pulling.
181
+ */
182
+ signal?: AbortSignal | undefined;
183
+ }
184
+ declare class EventPublisher<T extends Record<PropertyKey, any>> {
185
+ #private;
186
+ constructor(options?: EventPublisherOptions);
187
+ get size(): number;
188
+ /**
189
+ * Emits an event and delivers the payload to all subscribed listeners.
190
+ */
191
+ publish<K extends keyof T>(event: K, payload: T[K]): void;
192
+ /**
193
+ * Subscribes to a specific event using a callback function.
194
+ * Returns an unsubscribe function to remove the listener.
195
+ *
196
+ * @example
197
+ * ```ts
198
+ * const unsubscribe = publisher.subscribe('event', (payload) => {
199
+ * console.log(payload)
200
+ * })
201
+ *
202
+ * // Later
203
+ * unsubscribe()
204
+ * ```
205
+ */
206
+ subscribe<K extends keyof T>(event: K, listener: (payload: T[K]) => void): () => void;
207
+ /**
208
+ * Subscribes to a specific event using an async iterator.
209
+ * Useful for `for await...of` loops with optional buffering and abort support.
210
+ *
211
+ * @example
212
+ * ```ts
213
+ * for await (const payload of publisher.subscribe('event', { signal })) {
214
+ * console.log(payload)
215
+ * }
216
+ * ```
217
+ */
218
+ subscribe<K extends keyof T>(event: K, options?: EventPublisherSubscribeIteratorOptions): AsyncGenerator<T[K]> & AsyncIteratorObject<T[K]>;
219
+ }
220
+
221
+ declare class SequentialIdGenerator {
222
+ private index;
223
+ generate(): string;
224
+ }
225
+
226
+ type HTTPPath = `/${string}`;
227
+ type HTTPMethod = 'HEAD' | 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
228
+ type ClientContext = Record<PropertyKey, any>;
229
+ interface ClientOptions<T extends ClientContext> {
230
+ signal?: AbortSignal;
231
+ lastEventId?: string | undefined;
232
+ context: T;
233
+ }
234
+ type FriendlyClientOptions<T extends ClientContext> = Omit<ClientOptions<T>, 'context'> & (Record<never, never> extends T ? {
235
+ context?: T;
236
+ } : {
237
+ context: T;
238
+ });
239
+ type ClientRest<TClientContext extends ClientContext, TInput> = Record<never, never> extends TClientContext ? undefined extends TInput ? [
240
+ input?: TInput,
241
+ options?: FriendlyClientOptions<TClientContext>
242
+ ] : [input: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options: FriendlyClientOptions<TClientContext>];
243
+ type ClientPromiseResult<TOutput, TError> = PromiseWithError<TOutput, TError>;
244
+ interface Client<TClientContext extends ClientContext, TInput, TOutput, TError> {
245
+ (...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
246
+ }
247
+ type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
248
+ [k: string]: NestedClient<TClientContext>;
249
+ };
250
+ type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
251
+ interface ClientLink<TClientContext extends ClientContext> {
252
+ call: (path: readonly string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
253
+ }
254
+ type SetOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
255
+ type IntersectPick<T, U> = Pick<T, keyof T & keyof U>;
256
+ type PromiseWithError<T, TError> = Promise<T> & {
257
+ __error?: {
258
+ type: TError;
259
+ };
260
+ };
261
+ /**
262
+ * The place where you can config the orpc types.
263
+ *
264
+ * - `throwableError` the error type that represent throwable errors should be `Error` or `null | undefined | {}` if you want more strict.
265
+ */
266
+ interface Registry {
267
+ }
268
+ type ThrowableError = Registry extends {
269
+ throwableError: infer T;
270
+ } ? T : Error;
271
+ type InferAsyncIterableYield<T> = T extends AsyncIterable<infer U> ? U : never;
272
+ type IsEqual<A, B> = (<G>() => G extends (A & G) | G ? 1 : 2) extends <G>() => G extends (B & G) | G ? 1 : 2 ? true : false;
273
+ type Promisable<T> = T | PromiseLike<T>;
274
+
275
+ type InterceptableOptions = Record<string, any>;
276
+ type InterceptorOptions<TOptions extends InterceptableOptions, TResult> = Omit<TOptions, 'next'> & {
277
+ next(options?: TOptions): TResult;
278
+ };
279
+ type Interceptor<TOptions extends InterceptableOptions, TResult> = (options: InterceptorOptions<TOptions, TResult>) => TResult;
280
+ /**
281
+ * Can used for interceptors or middlewares
282
+ */
283
+ declare function onStart<T, TOptions extends {
284
+ next(): any;
285
+ }, TRest extends any[]>(callback: NoInfer<(options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => T | Promise<Awaited<ReturnType<TOptions['next']>>>;
286
+ /**
287
+ * Can used for interceptors or middlewares
288
+ */
289
+ declare function onSuccess<T, TOptions extends {
290
+ next(): any;
291
+ }, 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']>>>;
292
+ /**
293
+ * Can used for interceptors or middlewares
294
+ */
295
+ declare function onError<T, TOptions extends {
296
+ next(): any;
297
+ }, 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']>>>;
298
+ type OnFinishState<TResult, TError> = [error: TError, data: undefined, isSuccess: false] | [error: null, data: TResult, isSuccess: true];
299
+ /**
300
+ * Can used for interceptors or middlewares
301
+ */
302
+ declare function onFinish<T, TOptions extends {
303
+ next(): any;
304
+ }, 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']>>>;
305
+ declare function intercept<TOptions extends InterceptableOptions, TResult>(interceptors: Interceptor<TOptions, TResult>[], options: NoInfer<TOptions>, main: NoInfer<(options: TOptions) => TResult>): TResult;
306
+
307
+ /**
308
+ * Only import types from @opentelemetry/api to avoid runtime dependencies.
309
+ */
310
+
311
+ interface OtelConfig {
312
+ tracer: Tracer;
313
+ trace: TraceAPI;
314
+ context: ContextAPI;
315
+ propagation: PropagationAPI;
316
+ }
317
+ /**
318
+ * Sets the global OpenTelemetry config.
319
+ * Call this once at app startup. Use `undefined` to disable tracing.
320
+ */
321
+ declare function setGlobalOtelConfig(config: OtelConfig | undefined): void;
322
+ /**
323
+ * Gets the global OpenTelemetry config.
324
+ * Returns `undefined` if OpenTelemetry is not configured, initialized, or enabled.
325
+ */
326
+ declare function getGlobalOtelConfig(): OtelConfig | undefined;
327
+ /**
328
+ * Starts a new OpenTelemetry span with the given name and options.
329
+ *
330
+ * @returns The new span, or `undefined` if no tracer is set.
331
+ */
332
+ declare function startSpan(name: string, options?: SpanOptions, context?: Context): Span | undefined;
333
+ interface SetSpanErrorOptions {
334
+ /**
335
+ * Span error status is not set if error is due to cancellation by the signal.
336
+ */
337
+ signal?: AbortSignal;
338
+ }
339
+ /**
340
+ * Records and sets the error status on the given span.
341
+ * If the span is `undefined`, it does nothing.
342
+ */
343
+ declare function setSpanError(span: Span | undefined, error: unknown, options?: SetSpanErrorOptions): void;
344
+ declare function setSpanAttribute(span: Span | undefined, key: string, value: AttributeValue | undefined): void;
345
+ /**
346
+ * Converts an error to an OpenTelemetry Exception.
347
+ */
348
+ declare function toOtelException(error: unknown): Exclude<Exception, string>;
349
+ /**
350
+ * Converts a value to a string suitable for OpenTelemetry span attributes.
351
+ */
352
+ declare function toSpanAttributeValue(data: unknown): string;
353
+ interface RunWithSpanOptions extends SpanOptions, SetSpanErrorOptions {
354
+ /**
355
+ * The name of the span to create.
356
+ */
357
+ name: string;
358
+ /**
359
+ * Context to use for the span.
360
+ */
361
+ context?: Context;
362
+ }
363
+ /**
364
+ * Runs a function within the context of a new OpenTelemetry span.
365
+ * The span is ended automatically, and errors are recorded to the span.
366
+ */
367
+ declare function runWithSpan<T>({ name, context, ...options }: RunWithSpanOptions, fn: (span?: Span) => Promisable<T>): Promise<T>;
368
+ /**
369
+ * Runs a function within the context of an existing OpenTelemetry span.
370
+ */
371
+ declare function runInSpanContext<T>(span: Span | undefined, fn: () => Promisable<T>): Promise<T>;
372
+
373
+ declare function isAsyncIteratorObject(maybe: unknown): maybe is AsyncIteratorObject<any, any, any>;
374
+ interface AsyncIteratorClassNextFn<T, TReturn> {
375
+ (): Promise<IteratorResult<T, TReturn>>;
376
+ }
377
+ interface AsyncIteratorClassCleanupFn {
378
+ (reason: 'return' | 'throw' | 'next' | 'dispose'): Promise<void>;
379
+ }
380
+ declare const fallbackAsyncDisposeSymbol: unique symbol;
381
+ declare const asyncDisposeSymbol: typeof Symbol extends {
382
+ asyncDispose: infer T;
383
+ } ? T : typeof fallbackAsyncDisposeSymbol;
384
+ declare class AsyncIteratorClass<T, TReturn = unknown, TNext = unknown> implements AsyncIteratorObject<T, TReturn, TNext>, AsyncGenerator<T, TReturn, TNext> {
385
+ #private;
386
+ constructor(next: AsyncIteratorClassNextFn<T, TReturn>, cleanup: AsyncIteratorClassCleanupFn);
387
+ next(): Promise<IteratorResult<T, TReturn>>;
388
+ return(value?: any): Promise<IteratorResult<T, TReturn>>;
389
+ throw(err: any): Promise<IteratorResult<T, TReturn>>;
390
+ /**
391
+ * asyncDispose symbol only available in esnext, we should fallback to Symbol.for('asyncDispose')
392
+ */
393
+ [asyncDisposeSymbol](): Promise<void>;
394
+ [Symbol.asyncIterator](): this;
395
+ }
396
+ declare function replicateAsyncIterator<T, TReturn, TNext>(source: AsyncIterator<T, TReturn, TNext>, count: number): AsyncIteratorClass<T, TReturn, TNext>[];
397
+ interface AsyncIteratorWithSpanOptions extends SetSpanErrorOptions {
398
+ /**
399
+ * The name of the span to create.
400
+ */
401
+ name: string;
402
+ }
403
+ declare function asyncIteratorWithSpan<T, TReturn, TNext>({ name, ...options }: AsyncIteratorWithSpanOptions, iterator: AsyncIterator<T, TReturn, TNext>): AsyncIteratorClass<T, TReturn, TNext>;
404
+
405
+ declare function parseEmptyableJSON(text: string | null | undefined): unknown;
406
+ declare function stringifyJSON<T>(value: T | {
407
+ toJSON(): T;
408
+ }): undefined extends T ? undefined | string : string;
409
+
410
+ type Segment = string | number;
411
+ declare function findDeepMatches(check: (value: unknown) => boolean, payload: unknown, segments?: Segment[], maps?: Segment[][], values?: unknown[]): {
412
+ maps: Segment[][];
413
+ values: unknown[];
414
+ };
415
+ /**
416
+ * Get constructor of the value
417
+ *
418
+ */
419
+ declare function getConstructor(value: unknown): Function | null | undefined;
420
+ /**
421
+ * Check if the value is an object even it created by `Object.create(null)` or more tricky way.
422
+ */
423
+ declare function isObject(value: unknown): value is Record<PropertyKey, unknown>;
424
+ /**
425
+ * Check if the value satisfy a `object` type in typescript
426
+ */
427
+ declare function isTypescriptObject(value: unknown): value is object & Record<PropertyKey, unknown>;
428
+ declare function clone<T>(value: T): T;
429
+ declare function get(object: unknown, path: readonly string[]): unknown;
430
+ declare function isPropertyKey(value: unknown): value is PropertyKey;
431
+ declare const NullProtoObj: {
432
+ new <T extends Record<PropertyKey, unknown>>(): T;
433
+ };
434
+
435
+ type Value<T, TArgs extends any[] = []> = T | ((...args: TArgs) => T);
436
+ declare function value<T, TArgs extends any[]>(value: Value<T, TArgs>, ...args: NoInfer<TArgs>): T extends Value<infer U, any> ? U : never;
437
+ /**
438
+ * Returns the value if it is defined, otherwise returns the fallback
439
+ */
440
+ declare function fallback<T>(value: T | undefined, fallback: T): T;
441
+
442
+ /**
443
+ * Prevents objects from being awaitable by intercepting the `then` method
444
+ * when called by the native await mechanism. This is useful for preventing
445
+ * accidental awaiting of objects that aren't meant to be promises.
446
+ */
447
+ declare function preventNativeAwait<T extends object>(target: T): T;
448
+ /**
449
+ * Create a proxy that overlays one object (`overlay`) on top of another (`target`).
450
+ *
451
+ * - Properties from `overlay` take precedence.
452
+ * - Properties not in `overlay` fall back to `target`.
453
+ * - Methods from either object are bound to `overlay` so `this` is consistent.
454
+ *
455
+ * Useful when you want to override or extend behavior without fully copying/merging objects.
456
+ */
457
+ declare function overlayProxy<T extends object, U extends object>(target: Value<T>, partial: U): U & Omit<T, keyof U>;
458
+
459
+ interface AsyncIdQueueCloseOptions {
460
+ id?: string;
461
+ reason?: unknown;
462
+ }
463
+ declare class AsyncIdQueue<T> {
464
+ private readonly openIds;
465
+ private readonly queues;
466
+ private readonly waiters;
467
+ get length(): number;
468
+ get waiterIds(): string[];
469
+ hasBufferedItems(id: string): boolean;
470
+ open(id: string): void;
471
+ isOpen(id: string): boolean;
472
+ push(id: string, item: T): void;
473
+ pull(id: string): Promise<T>;
474
+ close({ id, reason }?: AsyncIdQueueCloseOptions): void;
475
+ assertOpen(id: string): void;
476
+ }
477
+
478
+ declare function streamToAsyncIteratorClass<T>(stream: ReadableStream<T>): AsyncIteratorClass<T>;
479
+ declare function asyncIteratorToStream<T>(iterator: AsyncIterator<T>): ReadableStream<T>;
480
+
481
+ declare function tryDecodeURIComponent(value: string): string;
482
+
483
+ type SafeResult<TOutput, TError> = ([error: null, data: TOutput, isDefined: false, isSuccess: true] & {
484
+ error: null;
485
+ data: TOutput;
486
+ isDefined: false;
487
+ isSuccess: true;
488
+ }) | ([error: Exclude<TError, ORPCError<any, any>>, data: undefined, isDefined: false, isSuccess: false] & {
489
+ error: Exclude<TError, ORPCError<any, any>>;
490
+ data: undefined;
491
+ isDefined: false;
492
+ isSuccess: false;
493
+ }) | ([error: Extract<TError, ORPCError<any, any>>, data: undefined, isDefined: true, isSuccess: false] & {
494
+ error: Extract<TError, ORPCError<any, any>>;
495
+ data: undefined;
496
+ isDefined: true;
497
+ isSuccess: false;
498
+ });
499
+ /**
500
+ * Works like try/catch, but can infer error types.
501
+ *
502
+ * @info support both tuple `[error, data, isDefined, isSuccess]` and object `{ error, data, isDefined, isSuccess }` styles.
503
+ * @see {@link https://orpc.unnoq.com/docs/client/error-handling Client Error Handling Docs}
504
+ */
505
+ declare function safe<TOutput, TError = ThrowableError$1>(promise: ClientPromiseResult<TOutput, TError>): Promise<SafeResult<TOutput, TError>>;
506
+ declare function toHttpPath(path: readonly string[]): HTTPPath;
507
+
508
+ export { AbortError, AsyncIdQueue, AsyncIteratorClass, COMMON_ORPC_ERROR_DEFS, EventPublisher, NullProtoObj, ORPCError, ORPC_CLIENT_PACKAGE_NAME, ORPC_CLIENT_PACKAGE_VERSION, ORPC_NAME, ORPC_SHARED_PACKAGE_NAME, ORPC_SHARED_PACKAGE_VERSION, SequentialIdGenerator, asyncIteratorToStream, asyncIteratorWithSpan, clone, createORPCErrorFromJson, defer, fallback, fallbackORPCErrorMessage, fallbackORPCErrorStatus, findDeepMatches, get, getConstructor, getGlobalOtelConfig, intercept, isAsyncIteratorObject, isDefinedError, isORPCErrorJson, isORPCErrorStatus, isObject, isPropertyKey, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, overlayProxy, parseEmptyableJSON, preventNativeAwait, readAsBuffer, replicateAsyncIterator, resolveMaybeOptionalOptions, runInSpanContext, runWithSpan, safe, sequential, setGlobalOtelConfig, setSpanAttribute, setSpanError, splitInHalf, startSpan, streamToAsyncIteratorClass, stringifyJSON, toArray, toHttpPath, toORPCError, toOtelException, toSpanAttributeValue, tryDecodeURIComponent, value };
509
+ export type { AnyFunction, AsyncIdQueueCloseOptions, AsyncIteratorClassCleanupFn, AsyncIteratorClassNextFn, AsyncIteratorWithSpanOptions, Client, ClientContext, ClientLink, ClientOptions, ClientPromiseResult, ClientRest, CommonORPCErrorCode, EventPublisherOptions, EventPublisherSubscribeIteratorOptions, FriendlyClientOptions, HTTPMethod, HTTPPath, InferAsyncIterableYield, InferClientContext, InterceptableOptions, Interceptor, InterceptorOptions, IntersectPick, IsEqual, MaybeOptionalOptions, NestedClient, ORPCErrorCode, ORPCErrorJSON, ORPCErrorOptions, OmitChainMethodDeep, OnFinishState, OtelConfig, Promisable, PromiseWithError, Registry, RunWithSpanOptions, SafeResult, Segment, SetOptional, SetSpanErrorOptions, ThrowableError, Value };