import type { ReadonlyJSONValue } from '../../shared/src/json.ts'; import { type IndexKey } from './db/index.ts'; import type { IterableUnion } from './iterable-union.ts'; import { type KeyTypeForScanOptions, type ScanIndexOptions, type ScanOptions } from './scan-options.ts'; import { type Closed } from './transaction-closed-error.ts'; import { type EntryForOptions } from './transactions.ts'; type ScanKey = string | IndexKey; /** * This class is used for the results of {@link ReadTransaction.scan | scan}. It * implements `AsyncIterable` which allows you to use it in a `for * await` loop. There are also methods to iterate over the {@link keys}, * {@link entries} or {@link values}. */ export declare class ScanResultImpl implements ScanResult, V> { #private; constructor(iter: AsyncIterable>, options: Options, dbDelegateOptions: Closed, onLimitKey: (inclusiveLimitKey: string) => void); /** The default AsyncIterable. This is the same as {@link values}. */ [Symbol.asyncIterator](): AsyncIterableIteratorToArray; /** Async iterator over the values of the {@link ReadTransaction.scan | scan} call. */ values(): AsyncIterableIteratorToArray; /** * Async iterator over the keys of the {@link ReadTransaction.scan | scan} * call. If the {@link ReadTransaction.scan | scan} is over an index the key * is a tuple of `[secondaryKey: string, primaryKey]` */ keys(): AsyncIterableIteratorToArray>; /** * Async iterator over the entries of the {@link ReadTransaction.scan | scan} * call. An entry is a tuple of key values. If the * {@link ReadTransaction.scan | scan} is over an index the key is a tuple of * `[secondaryKey: string, primaryKey]` */ entries(): AsyncIterableIteratorToArray, V]>; /** Returns all the values as an array. Same as `values().toArray()` */ toArray(): Promise; } export interface ScanResult extends AsyncIterable { /** The default AsyncIterable. This is the same as {@link values}. */ [Symbol.asyncIterator](): AsyncIterableIteratorToArray; /** Async iterator over the values of the {@link ReadTransaction.scan | scan} call. */ values(): AsyncIterableIteratorToArray; /** * Async iterator over the keys of the {@link ReadTransaction.scan | scan} * call. If the {@link ReadTransaction.scan | scan} is over an index the key * is a tuple of `[secondaryKey: string, primaryKey]` */ keys(): AsyncIterableIteratorToArray; /** * Async iterator over the entries of the {@link ReadTransaction.scan | scan} * call. An entry is a tuple of key values. If the * {@link ReadTransaction.scan | scan} is over an index the key is a tuple of * `[secondaryKey: string, primaryKey]` */ entries(): AsyncIterableIteratorToArray; /** Returns all the values as an array. Same as `values().toArray()` */ toArray(): Promise; } /** * An interface that adds a {@link toArray} method to `AsyncIterableIterator`. * * Usage: * * ```ts * const keys: string[] = await rep.scan().keys().toArray(); * ``` */ export interface AsyncIterableIteratorToArray extends AsyncIterableIterator { toArray(): Promise; } export type Entry = readonly [key: string, value: V]; /** * This is called when doing a {@link ReadTransaction.scan | scan} without an * `indexName`. * * @param fromKey The `fromKey` is computed by `scan` and is the key of the * first entry to return in the iterator. It is based on `prefix` and * `start.key` of the {@link ScanNoIndexOptions}. */ export type GetScanIterator = (fromKey: string) => IterableUnion>; /** * When using {@link makeScanResult} this is the type used for the function called when doing a {@link ReadTransaction.scan | scan} with an * `indexName`. * * @param indexName The name of the index we are scanning over. * @param fromSecondaryKey The `fromSecondaryKey` is computed by `scan` and is * the secondary key of the first entry to return in the iterator. It is based * on `prefix` and `start.key` of the {@link ScanIndexOptions}. * @param fromPrimaryKey The `fromPrimaryKey` is computed by `scan` and is the * primary key of the first entry to return in the iterator. It is based on * `prefix` and `start.key` of the {@link ScanIndexOptions}. */ export type GetIndexScanIterator = (indexName: string, fromSecondaryKey: string, fromPrimaryKey: string | undefined) => IterableUnion; /** * A helper function that makes it easier to implement {@link ReadTransaction.scan} * with a custom backend. * * If you are implementing a custom backend and have an in memory pending async * iterable we provide two helper functions to make it easier to merge these * together. {@link mergeAsyncIterables} and {@link filterAsyncIterable}. * * For example: * * ```ts * const scanResult = makeScanResult( * options, * options.indexName * ? () => { * throw Error('not implemented'); * } * : fromKey => { * const persisted: AsyncIterable> = ...; * const pending: AsyncIterable> = ...; * const iter = await mergeAsyncIterables(persisted, pending); * const filteredIter = await filterAsyncIterable( * iter, * entry => entry[1] !== undefined, * ); * return filteredIter; * }, * ); * ``` */ export declare function makeScanResult(options: Options, getScanIterator: Options extends ScanIndexOptions ? GetIndexScanIterator : GetScanIterator): ScanResult, ReadonlyJSONValue>; export declare function fromKeyForIndexScan(options: ScanIndexOptions): readonly [secondary: string, primary?: string | undefined]; export declare function fromKeyForIndexScanInternal(options: ScanIndexOptions): string; export {}; //# sourceMappingURL=scan-iterator.d.ts.map