import type { Cursor as NativeCursor } from '@botejs/native'; import { type Path, type Segment } from './path.ts'; import { type IterStream } from './stream.ts'; import { type StandardSchemaV1 } from './validate.ts'; import { type IterOptions } from './args.ts'; type InferOutput = Sch extends StandardSchemaV1 ? O : never; type SelectMapShape = { -readonly [K in keyof S]: unknown; }; /** The key paired with each value when iterating with `withKey: true`: the member * name for an object, or the zero-based index for an array. */ export type IterKey = string | number; /** The largest {@link IterOptions.maxBatchCount} `iter` accepts; a larger value is a `RangeError`. */ export declare const MAX_BATCH_COUNT = 1000000; export declare const DEFAULT_MAX_BATCH_COUNT = 1000; export declare const DEFAULT_MAX_BATCH_BYTES: number; export interface Cursor { /** * Resolve `path` to a container and return a new cursor anchored there, or * `null` if it is absent. Child cursors share the root's source and lifetime; * closing the root closes them too. * * @example * const user = await root.hop('users', 0); * const name = await user?.get('name'); */ hop(...path: Segment[]): Promise; /** * Report whether a value exists at `path`. With a trailing Standard Schema, * also require the value to validate against it (a parse/validation miss * yields `false` rather than throwing). * * @example * await root.has('users', 0, 'email'); * await root.has('users', 0, 'age', z.number()); */ has(...path: Segment[]): Promise; has(...args: [...Segment[], StandardSchemaV1]): Promise; /** * Read and decode the value at `path`, or `undefined` if absent. With a * trailing Standard Schema, validate and return its parsed output, throwing * on failure. * * @example * const name = await root.get('users', 0, 'name'); * const age = await root.get('users', 0, 'age', z.number()); */ get(...path: Segment[]): Promise; get(...args: [...Segment[], Sch]): Promise>; /** * Stream the members of the array or object at `path` as an async iterable. * A trailing Standard Schema validates each item; a trailing {@link IterOptions} * object tunes the iteration (see its fields for the available knobs). * * @example * for await (const user of root.iter('users')) { * console.log(user); * } * * for await (const [i, name] of root.iter('users', { withKey: true, select: ['name'] })) { * console.log(i, name); * } */ iter(...path: Segment[]): IterStream; iter(...args: [...Segment[], Sch]): IterStream>; iter(...args: [...Segment[], IterOptions & { withKey: true; schema: Sch; }]): IterStream<[IterKey, InferOutput]>; iter(...args: [...Segment[], IterOptions & { schema: Sch; }]): IterStream>; iter>(...args: [...Segment[], IterOptions & { withKey: true; select: S; }]): IterStream<[IterKey, SelectMapShape]>; iter>(...args: [...Segment[], IterOptions & { select: S; }]): IterStream>; iter(...args: [...Segment[], IterOptions & { withKey: true; }]): IterStream<[IterKey, unknown]>; iter(...args: [...Segment[], IterOptions]): IterStream; } export interface RootCursor extends Cursor, AsyncDisposable { /** Close the underlying source. Idempotent. */ close(): Promise; } export type CursorState = { closed: boolean; }; export declare function wrap(native: NativeCursor, state: CursorState): Cursor; export declare function ensureOpen(state: CursorState): void; export {};