import { Promisable } from 'type-fest'; export { IsEqual, IsNever, JsonValue, PartialDeep, Promisable } from 'type-fest'; import { Tracer, TraceAPI, ContextAPI, PropagationAPI, SpanOptions, Context, Span, AttributeValue, Exception } from '@opentelemetry/api'; export { group, guard, mapEntries, mapValues, omit, retry, sleep } from 'radash'; type MaybeOptionalOptions = Record extends TOptions ? [options?: TOptions] : [options: TOptions]; declare function resolveMaybeOptionalOptions(rest: MaybeOptionalOptions): T; declare function toArray(value: T): T extends readonly any[] ? T : Exclude[]; declare function splitInHalf(arr: readonly T[]): [T[], T[]]; /** * Converts Request/Response/Blob/File/.. to a buffer (ArrayBuffer or Uint8Array). * * Prefers the newer `.bytes` method when available as it more efficient but not widely supported yet. */ declare function readAsBuffer(source: Pick): Promise; type AnyFunction = (...args: any[]) => any; declare function once any>(fn: T): () => ReturnType; declare function sequential(fn: (...args: A) => Promise): (...args: A) => Promise; /** * Executes the callback function after the current call stack has been cleared. */ declare function defer(callback: () => void): void; type OmitChainMethodDeep = { [P in keyof Omit]: T[P] extends AnyFunction ? ((...args: Parameters) => OmitChainMethodDeep, K>) : T[P]; }; declare const ORPC_NAME = "orpc"; declare const ORPC_SHARED_PACKAGE_NAME = "@orpc/shared"; declare const ORPC_SHARED_PACKAGE_VERSION = "1.14.6"; /** * Error thrown when an operation is aborted. * Uses the standardized 'AbortError' name for consistency with JavaScript APIs. */ declare class AbortError extends Error { constructor(...rest: ConstructorParameters); } interface EventPublisherOptions { /** * Maximum number of events to buffer for async iterator subscribers. * * If the buffer exceeds this limit, the oldest event is dropped. * This prevents unbounded memory growth if consumers process events slowly. * * Set to: * - `0`: Disable buffering. Events must be consumed before the next one arrives. * - `1`: Only keep the latest event. Useful for real-time updates where only the most recent value matters. * - `Infinity`: Keep all events. Ensures no data loss, but may lead to high memory usage. * * @default 100 */ maxBufferedEvents?: number; } interface EventPublisherSubscribeIteratorOptions extends EventPublisherOptions { /** * Aborts the async iterator. Throws if aborted before or during pulling. */ signal?: AbortSignal | undefined; } declare class EventPublisher> { #private; constructor(options?: EventPublisherOptions); get size(): number; /** * Emits an event and delivers the payload to all subscribed listeners. */ publish(event: K, payload: T[K]): void; /** * Subscribes to a specific event using a callback function. * Returns an unsubscribe function to remove the listener. * * @example * ```ts * const unsubscribe = publisher.subscribe('event', (payload) => { * console.log(payload) * }) * * // Later * unsubscribe() * ``` */ subscribe(event: K, listener: (payload: T[K]) => void): () => void; /** * Subscribes to a specific event using an async iterator. * Useful for `for await...of` loops with optional buffering and abort support. * * @example * ```ts * for await (const payload of publisher.subscribe('event', { signal })) { * console.log(payload) * } * ``` */ subscribe(event: K, options?: EventPublisherSubscribeIteratorOptions): AsyncGenerator & AsyncIteratorObject; } declare class SequentialIdGenerator { private index; generate(): string; } /** * Compares two sequential IDs. * Returns: * - negative if `a` < `b` * - positive if `a` > `b` * - 0 if equal */ declare function compareSequentialIds(a: string, b: string): number; type SetOptional = Omit & Partial>; type IntersectPick = Pick; type PromiseWithError = Promise & { __error?: { type: TError; }; }; /** * The place where you can config the orpc types. * * - `throwableError` the error type that represent throwable errors should be `Error` or `null | undefined | {}` if you want more strict. */ interface Registry { } type ThrowableError = Registry extends { throwableError: infer T; } ? T : Error; type InferAsyncIterableYield = T extends AsyncIterable ? U : never; type InterceptableOptions = Record; type InterceptorOptions = Omit & { next(options?: TOptions): TResult; }; type Interceptor = (options: InterceptorOptions) => TResult; /** * Can be used for interceptors or middlewares */ declare function onStart(callback: NoInfer<(options: TOptions, ...rest: TRest) => Promisable>): (options: TOptions, ...rest: TRest) => T | Promise>>; /** * Can be used for interceptors or middlewares */ declare function onSuccess(callback: NoInfer<(result: Awaited>, options: TOptions, ...rest: TRest) => Promisable>): (options: TOptions, ...rest: TRest) => T | Promise>>; /** * Can be used for interceptors or middlewares */ declare function onError(callback: NoInfer<(error: ReturnType extends PromiseWithError ? E : ThrowableError, options: TOptions, ...rest: TRest) => Promisable>): (options: TOptions, ...rest: TRest) => T | Promise>>; type OnFinishState = [error: TError, data: undefined, isSuccess: false] | [error: null, data: TResult, isSuccess: true]; /** * Can be used for interceptors or middlewares */ declare function onFinish(callback: NoInfer<(state: OnFinishState>, ReturnType extends PromiseWithError ? E : ThrowableError>, options: TOptions, ...rest: TRest) => Promisable>): (options: TOptions, ...rest: TRest) => T | Promise>>; declare function intercept(interceptors: Interceptor[], options: NoInfer, main: NoInfer<(options: TOptions) => TResult>): TResult; /** * Only import types from @opentelemetry/api to avoid runtime dependencies. */ interface OtelConfig { tracer: Tracer; trace: TraceAPI; context: ContextAPI; propagation: PropagationAPI; } /** * Sets the global OpenTelemetry config. * Call this once at app startup. Use `undefined` to disable tracing. */ declare function setGlobalOtelConfig(config: OtelConfig | undefined): void; /** * Gets the global OpenTelemetry config. * Returns `undefined` if OpenTelemetry is not configured, initialized, or enabled. */ declare function getGlobalOtelConfig(): OtelConfig | undefined; /** * Starts a new OpenTelemetry span with the given name and options. * * @returns The new span, or `undefined` if no tracer is set. */ declare function startSpan(name: string, options?: SpanOptions, context?: Context): Span | undefined; interface SetSpanErrorOptions { /** * Span error status is not set if error is due to cancellation by the signal. */ signal?: AbortSignal; } /** * Records and sets the error status on the given span. * If the span is `undefined`, it does nothing. */ declare function setSpanError(span: Span | undefined, error: unknown, options?: SetSpanErrorOptions): void; declare function setSpanAttribute(span: Span | undefined, key: string, value: AttributeValue | undefined): void; /** * Converts an error to an OpenTelemetry Exception. */ declare function toOtelException(error: unknown): Exclude; /** * Converts a value to a string suitable for OpenTelemetry span attributes. */ declare function toSpanAttributeValue(data: unknown): string; interface RunWithSpanOptions extends SpanOptions, SetSpanErrorOptions { /** * The name of the span to create. */ name: string; /** * Context to use for the span. */ context?: Context; } /** * Runs a function within the context of a new OpenTelemetry span. * The span is ended automatically, and errors are recorded to the span. */ declare function runWithSpan({ name, context, ...options }: RunWithSpanOptions, fn: (span?: Span) => Promisable): Promise; /** * Runs a function within the context of an existing OpenTelemetry span. */ declare function runInSpanContext(span: Span | undefined, fn: () => Promisable): Promise; declare function isAsyncIteratorObject(maybe: unknown): maybe is AsyncIteratorObject; interface AsyncIteratorClassNextFn { (): Promise>; } interface AsyncIteratorClassCleanupFn { (reason: 'return' | 'throw' | 'next' | 'dispose'): Promise; } declare const fallbackAsyncDisposeSymbol: unique symbol; declare const asyncDisposeSymbol: typeof Symbol extends { asyncDispose: infer T; } ? T : typeof fallbackAsyncDisposeSymbol; declare class AsyncIteratorClass implements AsyncIteratorObject, AsyncGenerator { #private; constructor(next: AsyncIteratorClassNextFn, cleanup: AsyncIteratorClassCleanupFn); next(): Promise>; return(value?: any): Promise>; throw(err: any): Promise>; /** * asyncDispose symbol only available in esnext, we should fallback to Symbol.for('asyncDispose') */ [asyncDisposeSymbol](): Promise; [Symbol.asyncIterator](): this; } declare function replicateAsyncIterator(source: AsyncIterator, count: number): (AsyncIteratorClass)[]; interface AsyncIteratorWithSpanOptions extends SetSpanErrorOptions { /** * The name of the span to create. */ name: string; } declare function asyncIteratorWithSpan({ name, ...options }: AsyncIteratorWithSpanOptions, iterator: AsyncIterator): AsyncIteratorClass; declare function parseEmptyableJSON(text: string | null | undefined): unknown; declare function stringifyJSON(value: T | { toJSON(): T; }): undefined extends T ? undefined | string : string; type Segment = string | number; declare function findDeepMatches(check: (value: unknown) => boolean, payload: unknown, segments?: Segment[], maps?: Segment[][], values?: unknown[]): { maps: Segment[][]; values: unknown[]; }; /** * Get constructor of the value * */ declare function getConstructor(value: unknown): Function | null | undefined; /** * Check if the value is an object even it created by `Object.create(null)` or more tricky way. */ declare function isObject(value: unknown): value is Record; /** * Check if the value satisfy a `object` type in typescript */ declare function isTypescriptObject(value: unknown): value is object & Record; declare function clone(value: T): T; declare function get(object: unknown, path: readonly PropertyKey[]): unknown; declare function isPropertyKey(value: unknown): value is PropertyKey; declare const NullProtoObj: ({ new >(): T; }); type Value = T | ((...args: TArgs) => T); declare function value(value: Value, ...args: NoInfer): T extends Value ? U : never; /** * Returns the value if it is defined, otherwise returns the fallback */ declare function fallback(value: T | undefined, fallback: T): T; /** * Prevents objects from being awaitable by intercepting the `then` method * when called by the native await mechanism. This is useful for preventing * accidental awaiting of objects that aren't meant to be promises. */ declare function preventNativeAwait(target: T): T; /** * Create a proxy that overlays one object (`overlay`) on top of another (`target`). * * - Properties from `overlay` take precedence. * - Properties not in `overlay` fall back to `target`. * - Methods from either object are bound to `overlay` so `this` is consistent. * * Useful when you want to override or extend behavior without fully copying/merging objects. */ declare function overlayProxy(target: Value, partial: U): U & Omit; interface AsyncIdQueueCloseOptions { id?: string; reason?: unknown; } declare class AsyncIdQueue { private readonly openIds; private readonly queues; private readonly waiters; get length(): number; get waiterIds(): string[]; hasBufferedItems(id: string): boolean; open(id: string): void; isOpen(id: string): boolean; push(id: string, item: T): void; pull(id: string): Promise; close({ id, reason }?: AsyncIdQueueCloseOptions): void; assertOpen(id: string): void; } /** * Converts a `ReadableStream` into an `AsyncIteratorClass`. */ declare function streamToAsyncIteratorClass(stream: ReadableStream): AsyncIteratorClass; /** * Converts an `AsyncIterator` into a `ReadableStream`. */ declare function asyncIteratorToStream(iterator: AsyncIterator): ReadableStream; /** * Converts an `AsyncIterator` into a `ReadableStream`, ensuring that * all emitted object values are *unproxied* before enqueuing. */ declare function asyncIteratorToUnproxiedDataStream(iterator: AsyncIterator): ReadableStream; declare function tryDecodeURIComponent(value: string): string; 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, 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 }; 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 };