/** * Collection — Named keyed array for the prefab wire format. * * Collections carry row data with a key field. They serialize into `state` * as an array and produce `Ref` lazy lookup expressions via `.by(signal)`. * * @example * ```ts * const patients = collection('patients', fhirPatients, { key: 'id' }) * const selectedId = signal('selectedPatientId', patients.firstKey()) * const selectedPatient = patients.by(selectedId) * // selectedPatient.expr → "{{ patients | find:'id',selectedPatientId }}" * ``` */ import { Rx } from './rx.js'; import type { Signal, SignalValue } from './signal.js'; /** * A lazy, serializable reference to a row in a collection. * The expression is evaluated at runtime by the renderer's pipe evaluator. */ export declare class Ref { readonly expr: string; readonly type: "ref"; /** @internal */ readonly _phantom?: T; constructor(expr: string); /** Rx expression for use in component props */ toRx(): Rx; toString(): string; toJSON(): string; /** * Type-safe property access on the referenced row. * Returns `Ref` so downstream type checking works. * * `ref.dot('name')` → `Ref` with expr `{{ ... | dot:'name' }}` */ dot(field: K): Ref; /** Untyped escape hatch for dynamic/computed field names. */ dot(field: string): Ref; /** * Shorthand for `.dot(field).pipe(pipeName, ...args)`. * Compiles to `{{ expr | dot:'field' | pipeName }}`. * * Use for FHIR datatype formatting: * `ref.formatted('name', 'humanName')` → `{{ ... | dot:'name' | humanName }}` */ formatted(field: keyof T & string | string, pipeName: string, ...args: unknown[]): Rx; /** * Append a pipe filter to the ref expression. * `ref.pipe('humanName')` → `{{ expr | humanName }}` * `ref.pipe('date', 'long')` → `{{ expr | date:'long' }}` */ pipe(name: string, ...args: unknown[]): Rx; } /** * A named keyed array. Serializes rows into state and provides * typed lookup helpers that compile to pipe expressions. */ export declare class Collection = Record> { readonly stateKey: string; readonly keyField: string; readonly rows: T[]; constructor(stateKey: string, rows: T[], keyField: string); /** Key of the first row, or null if empty. */ firstKey(): string | null; /** Key of the last row, or null if empty. */ lastKey(): string | null; /** Number of rows. */ get length(): number; /** * Create a Ref that lazily resolves a row by signal key. * Compiles to: `{{ stateKey | find:'keyField',signal.key }}` */ by(key: Signal): Ref; /** Rx expression referencing the full array: `{{ stateKey }}` */ toRx(): Rx; toString(): string; toJSON(): string; /** State entry for PrefabApp: `{ stateKey: rows }` */ toState(): Record; } /** * Create a named keyed collection. * * @param stateKey Stable state path (e.g. 'patients') * @param rows Source array * @param options Must include `key` — the field name used for identity lookup */ export declare function collection>(stateKey: string, rows: T[], options: { key: string; }): Collection; //# sourceMappingURL=collection.d.ts.map