declare function toArray(value: T): T extends readonly any[] ? T : (T extends undefined | null ? never : T[]); /** * 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); } /** * Sequentially execute the function, if the previous execution is not completed, the next execution will be blocked */ declare function sequential(fn: (...args: A) => Promise): (...args: A) => Promise; declare class SequentialIdGenerator { private index; generate(): string; } type AsyncCleanupFnState = { kind: 'success'; error?: undefined; } | { kind: 'error'; error: unknown; } | { kind: 'cancelled'; error?: unknown; }; interface AsyncCleanupFn { (state: AsyncCleanupFnState): Promise; } declare function isAsyncIteratorObject(maybe: unknown): maybe is AsyncIteratorObject; interface AsyncIteratorClassNextFn { (): 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 isDone; private isExecuteComplete; private readonly cleanup; readonly next: AsyncIteratorClassNextFn; constructor(next: AsyncIteratorClassNextFn, cleanup: AsyncCleanupFn); return(value?: any): Promise>; throw(error: any): Promise>; /** * asyncDispose symbol only available in esnext, we should fallback to Symbol.for('asyncDispose') */ [asyncDisposeSymbol](): Promise; [Symbol.asyncIterator](): this; } declare function parseEmptyableJSON(text: string | null | undefined): unknown; declare function stringifyJSON(value: T | { toJSON(): T; }): undefined extends T ? undefined | string : string; /** * Checks whether the object has at least one property with a defined value. * Keys holding `undefined` are treated as absent, matching JSON semantics * where such entries disappear on serialization. */ declare function hasAnyDefinedValue(object: Record): boolean; /** * Checks whether the provided container is a typescript object (object or function). */ declare function isTypescriptObject(maybeObject: unknown): maybeObject is object & Record; /** * Creates a promise together with its associated `resolve` and `reject` * functions. * * Equivalent to `Promise.withResolvers()`, but works in environments * where that API is not yet available. */ declare function promiseWithResolvers(): { promise: Promise; resolve: (v: T) => void; reject: (reason: unknown) => void; }; interface GetOrBindOptions { /** * Whether to bind the function to the target before returning it. * * @default true */ bind?: boolean; } declare function getOrBind(target: T, property: K, { bind }?: GetOrBindOptions): K extends keyof T ? T[K] : unknown; declare class Queue { private readonly items; private readonly pendingPulls; private closed; /** * Pushes an item into the queue. * @throws when the queue is closed or aborted */ push(item: T): void; /** * Pulls the next item from the queue. * * @throws when the queue is closed or aborted. Note that buffered items can still be pulled after close until the buffer is drained. */ pull(): Promise; /** * Closes the queue and rejects any pending pulls. * Buffered items remain available to be pulled. Repeated calls are ignored. */ close(reason?: unknown): void; /** * Aborts the queue. * Unlike `close()`, this also discards any buffered items before closing. */ abort(reason?: unknown): void; } interface SleepOptions { signal?: AbortSignal | undefined; } /** * sleep for a specified amount of time */ declare function sleep(ms: number, { signal }?: SleepOptions): Promise; declare function tryDecodeURIComponent(value: string): string; export { AbortError, AsyncIteratorClass, Queue, SequentialIdGenerator, getOrBind, hasAnyDefinedValue, isAsyncIteratorObject, isTypescriptObject, parseEmptyableJSON, promiseWithResolvers, sequential, sleep, stringifyJSON, toArray, tryDecodeURIComponent }; export type { AsyncCleanupFn, AsyncCleanupFnState, AsyncIteratorClassNextFn, GetOrBindOptions, SleepOptions };