/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ import { type EastTypeValue, type ValueTypeOf, type option } from "@elaraai/east"; import type { SeekQueryType, SeekRangeType } from "@elaraai/east-ui"; import { RecordSliceWhereType, type DatasetKeyMatchRange, type DatasetKeyQuery, type RecordSliceBindType, type RecordSliceEntry } from "@elaraai/east-ui/internal"; import { type KeySearchJump, type KeySearchSource } from "@elaraai/east-ui-components"; import { type RowHidden, type RowHiding, type SourceHidden } from "./hidden.js"; import { type KindKeys } from "./kind-keys.js"; /** A record Slice's part: a source of the slice. */ type RecordPart = ValueTypeOf; /** * A token that moves as a tracked read answers another value: what tells the * box a source read whole was read again ({@link WholeSought.token}), where * the builder reads its rows through a binding — a read that answers the value * it answered before moves nothing. * * @param read - What the read answered; `none` while it is pending * @returns The token: `-` while the read is pending */ export declare function readToken(read: option): string; /** * Which of some rows of a source a narrowing holds, asked of e3 by their keys: * their rows read in one request, and which of them the narrowing holds in one * more — a tracked read, which answers once both have. What a builder asks of * rows it names by key and holds no page of: the rows of a source read whole * against its page's scope ({@link scopeHolds}), the resources a Calendar's * events are laid on against their source's narrowing. * * @param part - The source's part of the slice * @param where - The narrowing * @param ids - The rows' keys' texts, each once * @param keys - The rows' keys: each text read back at the record's key type; String's by default * @returns Whether the narrowing holds each row the record holds, by its key's text — none for a key the record holds no * row by, or a text no key prints as; `none` while e3 has not said */ export declare function rowsWithin(part: RecordPart, where: ValueTypeOf, ids: readonly string[], keys?: KindKeys): option>; /** * Which of some rows of a source its page's scope holds (#1621), asked of e3 * by their keys ({@link rowsWithin}): a key the record holds no row by is held * by none, as is a text no key prints as. * * @param part - The source's part of the slice, which holds a scope * @param ids - The rows' keys' texts, each once * @param keys - The rows' keys: each text read back at the record's key type; String's by default * @returns The texts of the keys the scope holds; `none` while e3 has not said */ export declare function scopeHolds(part: RecordPart, ids: readonly string[], keys?: KindKeys): option>; /** * {@link scopeHolds}, awaited: which of some rows of a source its page's scope * holds, once e3 has said. * * @param part - The source's part of the slice; `undefined` with none * @param ids - The rows' keys' texts, each once * @param keys - The rows' keys; String's by default * @returns The texts of the keys the scope holds; `undefined` with no part, or a page with no scope, which holds every row */ export declare function scopeHeld(part: RecordPart | undefined, ids: readonly string[], keys?: KindKeys): Promise | undefined>; /** A row a list shows of a source sought through e3, as the binding read it: what a builder reads its item from. */ export interface RecordRow { /** Its key's text: a String key as itself, any other as East prints it (#1549). */ readonly id: string; /** Its key, at the record's key type. */ readonly key: unknown; /** Its row, joined; `undefined` where the binding read none — a lean binding's, or a row the record holds no more. */ readonly row: unknown; /** Its entry, as the binding read it: the key of the index the row was read through among it. */ readonly entry: RecordSliceEntry; /** * Its place among the rows the page holds of the record — the record's own, or its scope's (#1621): where a builder * whose rows are those rows, in their order, goes to it (the Sheet). */ readonly place: bigint; } /** * A source Search Records seeks through e3 (see the module docs): its part of * the slice, whose record a query is placed in. * * @typeParam T - What the builder reads a found row as */ export interface RecordSought { /** Its part of the slice: the record sought, and the page's scope. */ readonly part: RecordPart; /** Its keys (#1549): the key type a query is read at, and each key's text. */ readonly keys: KindKeys; /** * Its hidden pick (`hidden.ts`): what asks e3 which choices hide a row a list shows that its narrowing leaves out; * none for a source whose own narrowing hides no row the builder lists, which asks nothing. */ readonly pick?: SourceHidden | undefined; /** * A row a list shows, as the builder reads it: a tracked read — `none` while it is pending; then `some(none)` for a * row it lists nothing of, whose place the list keeps, else `some(some(item))`. */ readonly read: (row: RecordRow) => option>; } /** * A source's read of the rows a list shows from the rows themselves * ({@link RecordSought.read}): a row the list read no row of — a lean * binding's, or one the record holds no more — lists nothing, its place kept; * any other is the builder's item. * * @param item - The builder's item, from a row's key's text and its row * @returns The read */ export declare function readsRows(item: (id: string, row: unknown) => T): RecordSought["read"]; /** * A source Search Records seeks among rows held whole (see the module docs). * * @typeParam T - What the builder reads a found row as */ export interface WholeSought { /** Every row it holds, as the builder reads it: a tracked read, `none` while it is pending. */ readonly rows: () => option; /** A row's key's text: a String key as itself, any other as East prints it. */ readonly idOf: (row: T) => string; /** Its keys: the key type a query is read at, each text read back at it, and their order. */ readonly keys: KindKeys; /** The part of the slice its rows are narrowed through, whose page's scope they are listed under (#1621); none with none. */ readonly scope?: RecordPart | undefined; /** What a query finds among its rows, in their keys' order; by default, those whose keys it finds ({@link keyMatches}). */ readonly matches?: ((rows: readonly T[], query: DatasetKeyQuery) => readonly T[]) | undefined; /** * What tells the box its rows were read again, tracked: a token that moves then — {@link readToken} of what a * binding answers; none for rows the builder holds, whose moves it names itself ({@link SearchRecordsOptions.requeryBy}). */ readonly token?: (() => string) | undefined; } /** A paged source as Search Records seeks it: its id, its key search, and the snapshot it serves where it names one. */ export interface SeekingSource { /** Its id: what tells it from another source. */ readonly id: string; /** Its key search, as the source answers it: a tracked read, `none` while it is pending. */ readonly seek: (query: ValueTypeOf) => option>; /** The snapshot it serves — a pinned or live source's — tracked; absent on a `paged` source, whose rows are its id's. */ readonly revision?: (() => option) | undefined; /** The narrowing it serves — a live source's — tracked. */ readonly query?: (() => string) | undefined; } /** * A paged source Search Records seeks by its own key search (see the module * docs): a host's `Data.bindPaged` a builder reads its rows from by their * place — the Sheet's — whose `seek` places a query's matches in one run among * them. * * @typeParam T - What the builder reads a found row as */ export interface PagedSought { /** Its keys: the key type a query is read at. */ readonly keys: KindKeys; /** The source: what a query is sought through, and what tells the box it moved to another snapshot. */ readonly paged: SeekingSource; /** Its rows `[from, from + count)` by their place, as the builder reads them: a tracked read, `none` while it is pending. */ readonly page: (from: bigint, count: bigint) => option; } /** A source Search Records seeks: through e3, by its own key search, or among rows held whole. */ export type SoughtSource = RecordSought | PagedSought | WholeSought; /** A source whose matches have places among the rows a builder draws of it: one sought through e3, or a paged source. */ export type PlacedSource = RecordSought | PagedSought; /** A row Search Records found: its place in the list, the builder's item, and what hides it. */ export interface Found { /** Its place in the list. */ readonly at: number; /** The row, as the builder reads it. */ readonly item: T; /** * What hides it, as far as e3 has said — each source the builder reads as hiding it, its own first, with what e3 said * hides it there; `undefined` for a row nothing hides. */ readonly hidden: readonly RowHidden[] | undefined; } /** A pick, as the builder takes it: how the box asked it, and whether it is the latest still. */ export interface PickTurn { /** How the box asked it: a `pick` hands the keyboard to the builder's view, a `step` leaves it in the box. */ readonly how: KeySearchJump; /** Whether it is the box's latest pick still: a newer pick, a new query or a clear leaves it behind. */ readonly current: () => boolean; } /** What a builder's Search Records is made of (see the module docs). */ export interface SearchRecordsOptions { /** Who seeks, as the console names it when a read fails: `Calendar`, `Schematic`. */ readonly name: string; /** What tells this box from another a toolbar holds. */ readonly resetKey: string; /** The sources, in the builder's order: their matches are listed in it. */ readonly sources: readonly SoughtSource[]; /** A found row's line: its words, and the text the box shows once it is picked — what its query is typed against. */ readonly line: (found: Found) => { readonly label: string; readonly text: string; }; /** Told the row a pick lands on, and the pick's turn. */ readonly onPick: (found: Found, turn: PickTurn) => void; /** * Told the place a pick lands on, among the rows its source's page holds ({@link pickPlace}), and the pick's turn — at * once, with nothing read — by a builder that names no other source as hiding a row ({@link hidings}): every pick of * a match of a source that places its matches, but a row the box listed as hidden under the narrowing as it stands, * which goes to {@link onPick} as the list read it. What a builder that goes to a row by its place gives (the Sheet): * its window is read where it goes, one that cannot be read is shown there, and a row its narrowing hides there is * its own to reveal. Without it a pick reads its row again ({@link onPick}). */ readonly onPickPlace?: ((place: bigint, turn: PickTurn) => void) | undefined; /** * Told the last pick stands no more: the search cleared, a new query asked in its place — never one asked again — or * the box named as another (`resetKey`). */ readonly onCleared?: (() => void) | undefined; /** What the box says where no key matches. */ readonly noMatchesText?: string | undefined; /** * The sources the builder reads as hiding each of some found rows, beside a source's own — the resource a layout lays * an event on, a bin's lane, the people the rail shows — each with the row of it the found row stands on. */ readonly hidings?: ((items: readonly T[]) => readonly (readonly RowHiding[])[] | Promise) | undefined; /** Whether the builder knows that each source it names hides the row it stands on, so a line says so at once; by default it does. */ readonly hidingsKnown?: boolean | undefined; /** What else the matches are read from, each another object as it moves: the box asks its query again then. */ readonly requeryBy?: readonly unknown[] | undefined; /** What else the lines read — the hidden picks the builder names, a layout, its words — each another object as it moves. */ readonly relistBy?: readonly unknown[] | undefined; } /** * A run of a source's matches: a block of them among the rows its page holds, * or a source read whole's matches. */ export interface FoundRun { /** The source. */ readonly source: SoughtSource; /** * Where it starts among the rows the source's page holds — the record's own, or its scope's (#1621) — or among a paged * source's rows; 0 for a source read whole. */ readonly start: bigint; /** How many matches it holds. */ readonly count: number; /** A source read whole's matches, in order; `undefined` for a block of a source sought through e3. */ readonly rows: readonly T[] | undefined; } /** A stretch of a list's rows, read from one run. */ export interface Stretch { /** The run. */ readonly run: R; /** The first of the run's matches it reads. */ readonly offset: number; /** How many. */ readonly n: number; /** The list's row it starts at. */ readonly at: number; } /** * The stretches a list's rows `[row, row + limit)` are read in, its matches one * run after another. * * @param runs - The runs, in the list's order, each with how many matches it holds * @param row - The list's first row * @param limit - How many rows it reads * @returns Each stretch, in the list's order */ export declare function stretchesAt(runs: readonly R[], row: number, limit: number): Stretch[]; /** * The rows a query finds among rows held whole, by their keys, in East's order * at their key type (#1549): as the server finds a key in a record's own order * (`findKeyInline`) — a key's start, a quoted key, a range. A text no key * prints as is no key a query finds; of rows whose key's text repeats, the * last stands for them. * * @param rows - The rows, in any order * @param idOf - A row's key's text * @param query - The query, as the source seeks it ({@link kindQuery}) * @param keys - The rows' keys: each text read back at their key type, and their order; String's by default * @returns The rows it finds, in their keys' order */ export declare function keyMatches(rows: readonly T[], idOf: (row: T) => string, query: DatasetKeyQuery, keys?: KindKeys): T[]; /** * The key type a box parses typed text at: the sources' where they share one, * else String — a source keyed otherwise reading the text as typed at its own * ({@link kindQuery}). * * @param keys - Each source's keys * @returns The key type */ export declare function boxKeyType(keys: readonly KindKeys[]): EastTypeValue; /** * A query the box parsed, as one source seeks it (#1549): as it is where the * box parses at the source's key type; else — the box at String, over sources * keyed by several types — the text as typed, read at the source's as the * shared key search reads it (`parseKeyInput`): `10` the key 10 of a source * keyed by Integer, `2..9` a range of them. * * @param query - The query the box parsed * @param box - The key type the box parses at * @param keyed - The source's keys * @returns The query the source is sought by; `undefined` where the text reads as no key of the source's, which finds * none of its rows */ export declare function kindQuery(query: DatasetKeyQuery, box: EastTypeValue, keyed: KindKeys): DatasetKeyQuery | undefined; /** A block of a record source's matches among the rows its page holds: where it starts there, and how many it holds. */ export interface MatchBlock { /** Where it starts among the rows the page holds of the record — the record's own, or its scope's (#1621). */ readonly start: bigint; /** How many matches it holds. */ readonly count: number; } /** * The blocks of a record source's matches of a query among the rows its page * holds — the record's own, or its scope's (#1621), a block for each of the * scope's values that holds one — through the source's own key search * (`recordSliceKeySearch`): none empty. * * @param part - The source's part of the slice * @param query - The query, as the source seeks it * @returns Each block, in the order of the rows the page holds */ export declare function recordMatchBlocks(part: RecordPart, query: DatasetKeyQuery): Promise; /** * What a find answers the box: whether its runs hold a match, and how many — * the list's rows, from its first. * * @param runs - The find's runs, in the list's order, each with how many matches it holds * @returns The box's match range */ export declare function foundRange(runs: readonly { readonly count: number; }[]): DatasetKeyMatchRange; /** * Seeks a query in each source, in order (see the module docs): a source * sought through e3 a block of matches at a time — one with no scope, one for * each of the scope's values that holds one — a paged source the one run its * own key search answers, and a source read whole its matches, on a scoped * page those its scope holds alone. * * @param sources - The sources, in the builder's order * @param query - The query the box parsed * @param box - The key type the box parses at ({@link boxKeyType}) * @returns Each run of matches, in the list's order: none for a source the query finds nothing of */ export declare function searchRuns(sources: readonly SoughtSource[], query: DatasetKeyQuery, box: EastTypeValue): Promise[]>; /** What a list reads beside what a find found ({@link listFound}). */ export interface ListOptions { /** * The sources as the builder names them now: a run of a source sought through e3 is read through the one sought * through the same part — its hidden pick, and so its narrowing, and its read the latest, as a narrowing that moved * since the find lists its lines again; by default, the sources the find sought. */ readonly sources?: readonly SoughtSource[] | undefined; /** The sources the builder reads as hiding each found row, beside a source's own ({@link SearchRecordsOptions.hidings}). */ readonly hidings?: SearchRecordsOptions["hidings"]; /** Whether the builder knows each source it names hides the row it stands on; by default it does. */ readonly known?: boolean | undefined; } /** * Where a list's row is among the rows its source's page holds, known with * nothing read (see the module docs): the row is a match of a source that * places its matches — a paged source, whose `seek` placed it, or one sought * through e3, whose record placed it — whatever its narrowing hides. A row held * whole has no place. * * @param runs - What the find found * @param row - The list's row * @returns Its place; `undefined` for a row the find did not find, and for a row held whole */ export declare function pickPlace(runs: readonly FoundRun[], row: number): bigint | undefined; /** * Reads the rows `[row, row + limit)` of what a find found, as a list shows them * (see the module docs): a source sought through e3 a page of the rows its page * holds at a time, each read as the builder reads it now, its place there with * it, and which its narrowing now hides asked of e3; a paged source a page of * its rows at a time, by their place; a source read whole's matches as they * were found; and what hides each row, the builder's sources beside a source's * own. * * @param runs - What the find found * @param row - The list's first row * @param limit - How many rows * @param options - The sources as the builder names them now, and the sources it reads as hiding a row * @returns Each row found, at its place in the list, in order: one a source lists nothing of leaves its place */ export declare function listFound(runs: readonly FoundRun[], row: number, limit: number, options?: ListOptions): Promise[]>; /** * Where a key is among a builder's rows, as the box seeks it (see the module * docs), for a builder that goes to a row by its key alone — the Sheet's Go to * issue: the place of the first match, among the rows its page holds of a * source sought through e3, or among a paged source's own rows. The latest ask * alone answers: an older one, one whose sources moved between the ask and * the answer — their records' revisions or their pages' scopes, a paged * source's snapshot, as each stood once it had said — and one the builder let * go of as it unmounted answer `undefined`, as one that finds nothing does. * * @param sources - The sources, in the builder's order * @returns What seeks a query, answering its first match's place; `undefined` with no source to seek */ export declare function useSeekPlace(sources: readonly PlacedSource[]): ((query: DatasetKeyQuery) => Promise) | undefined; /** * A builder's Search Records, for the shared key search's toolbar item (see * the module docs). * * @param options - The builder's sources, its lines, its pick and what else its matches and lines read * @returns The box's source; `undefined` with no source to seek */ export declare function useSearchRecords(options: SearchRecordsOptions): KeySearchSource | undefined; export {}; //# sourceMappingURL=search-records.d.ts.map