/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ /** * The fields a step can name (#933): the field catalog of a rows shape, and * the comparisons each kind of field takes (`Query Editor Spec.md` §4.4). * * @packageDocumentation */ import type { EastType } from "@elaraai/east"; import { type Shape } from "./shape.js"; import type { ComparisonKind } from "./values.js"; /** * What kind of value a field holds, as the builder offers it: text, a whole * number, a number, a date, yes or no, one of some cases, a list, a record, * a lookup table, a calculation, or anything else. */ export type FieldKind = "text" | "int" | "num" | "date" | "bool" | "case" | "list" | "record" | "dict" | "fn" | "other"; /** A field a step can name, in a shape. */ export interface StepField { /** How a step names it: `"total"`, `"status"`, `"status.shipped.date"`. */ readonly ref: string; /** The name a step gives a field made from it: `"total"`, `"status"`, `"shipped_date"`. */ readonly name: string; /** What kind of value it holds. */ readonly kind: FieldKind; /** The type a read of it gives here: a payload field not narrowed to its case is an option. */ readonly type: EastType; /** Whether it can be missing: an option, or a payload field not narrowed to its case. */ readonly optional: boolean; /** The fields jq reads it through from a row: `["total"]`, `["status", "type"]`, `["status", "value", "date"]`. */ readonly path: readonly string[]; /** A case field's cases. */ readonly cases?: readonly string[]; /** A payload field's variant field, the case whose payload has it, its name in the payload, and whether the rows are narrowed to that case. */ readonly payload?: { readonly parent: string; readonly case: string; readonly leaf: string; readonly narrowed: boolean; }; /** A list's item type. */ readonly element?: EastType; } /** * The kind of value a type holds. * * @param type - a field's type * @returns its kind, read through an option and a recursive wrapper */ export declare function kindOf(type: EastType): FieldKind; /** * The fields of a record, as steps name them: each field; for a variant * field, its case and each field of each struct case's payload. * * @param record - the record's type * @param narrowed - the variant fields narrowed to one case, with the case * @returns the fields, in the record's order, each variant's case before its payloads' fields */ export declare function fieldsOfRecord(record: EastType, narrowed: ReadonlyMap): StepField[]; /** * The field catalog of a shape: the fields of its rows. * * @param shape - the shape * @returns its rows' fields; none when it is not rows */ export declare function fieldsOf(shape: Shape): StepField[]; /** * The field a step names, in a shape. * * @param shape - the shape * @param ref - how the step names it * @returns the field, or `undefined` when the shape has none of that name */ export declare function fieldByRef(shape: Shape, ref: string): StepField | undefined; /** * The fields jq reads a field through, for one the shape does not have: a * name is read as itself, and `parent.case.leaf` as a payload's field, so the * check names what is wrong. * * @param ref - how a step names it * @returns the fields jq reads */ export declare function pathOfUnknown(ref: string): string[]; /** * The record each item of a list is, when the items are records. * * @param field - a list field * @returns its item record, or `undefined` */ export declare function itemRecordOf(field: StepField): EastType | undefined; /** * The comparisons a field takes (`Query Editor Spec.md` §4.4): its kind's, * and is missing and has a value for an optional field that is not a * payload's; a list takes has any where only when its items are records. * * @param field - the field * @returns the comparisons, in the order the builder offers them */ export declare function comparisonsFor(field: StepField): ComparisonKind[]; /** * The comparison a field starts with when it is picked: is in year for a * date, has at least for a list, is yes for yes or no, is at least for a * number, and is otherwise. * * @param field - the field * @returns the comparison */ export declare function defaultComparison(field: StepField): ComparisonKind; //# sourceMappingURL=fields.d.ts.map