/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ /** * Checking steps (#933): the printed program goes through east's checker * once, and each diagnostic is placed by its span on the step, condition and * slot it came from, with fixes as step edits. What the checker cannot see — * a step not finished, which is not in the program; a number a slot needs to * be whole — the steps check themselves (`Query Editor Spec.md` §4.6). * * @packageDocumentation */ import { type EastType } from "@elaraai/east"; import { type StepLayout, type StepSlot } from "./print.js"; import { type Shape } from "./shape.js"; import { type Condition, type StepQuery, type StepValue } from "./values.js"; /** A jq step's note, in the checker's manner: a part of the program the visual view keeps as jq. */ export declare const JQ_STEP_NOTE = "custom: not a visual step; it stays as jq in the visual editor."; /** * Where a diagnostic is placed in a step besides a condition: a step's * {@link StepSlot}; `cmp` and `inner`, a condition's comparison and inner * condition; `as` and `over`, the names a step gives; `source`, the data * source; `text`, a jq step's text. */ export type DiagnosticSlot = StepSlot | "cmp" | "inner" | "as" | "over" | "source" | "text"; /** A fix, as an edit of the steps, which `applyFix` applies. */ export type StepFix = /** Keep only the rows of a case first: `field is case` at the front of this filter, or a filter of it before this step. */ { readonly kind: "addCaseCondition"; readonly label: string; readonly stepId: string; readonly field: string; readonly case: string; } /** Use another field in a slot or a condition. */ | { readonly kind: "setField"; readonly label: string; readonly stepId: string; readonly slot: DiagnosticSlot; readonly condId?: string; readonly id?: string; readonly field: string; } /** Use another value in a condition. */ | { readonly kind: "setValue"; readonly label: string; readonly stepId: string; readonly condId: string; readonly value: StepValue; } /** Compare a variant's case, not the whole value. */ | { readonly kind: "unwhole"; readonly label: string; readonly stepId: string; readonly condId: string; } /** Take the step out. */ | { readonly kind: "removeStep"; readonly label: string; readonly stepId: string; } /** Edit a jq step's text: the checker's own fix, at offsets in the step's text. */ | { readonly kind: "editJq"; readonly label: string; readonly stepId: string; readonly edits: readonly { readonly from: number; readonly to: number; readonly insert: string; }[]; }; /** A problem in a query's steps, where it is, and how to fix it. */ export interface StepDiagnostic { /** The step it is in; `""` for the data source. */ readonly stepId: string; /** The condition it is in. */ readonly condId?: string; /** The slot it is on. */ readonly slot?: DiagnosticSlot; /** What the slot is for: a total's id, a field shown's, a field brought in, an input's name. */ readonly id?: string; /** An error stops the query running; a warning does not; a note says what a jq step is. */ readonly severity: "error" | "warning" | "note"; /** The checker's code; `incomplete` for a slot not filled in; `custom` for a jq step; `too_many_rows` for a range a run cuts off. */ readonly code: string; /** The checker's sentence, or the steps' own, in jq's words. */ readonly message: string; /** * What the builder's plain words need: `field` (the field's ref), `kind`, * `name` and, for a payload's field, `parent`, `case` and `leaf`; `value` * the condition's value; `suggestion` the checker's first; `what` what an * unfinished slot needs; `cmp` and `fn` the comparison and the total; * `dataset` a Look up's data source, with its `kind`; `rows` and `max` a * range's rows and the most a run returns. */ readonly context: Readonly>; /** Its fixes, best first. */ readonly fixes: readonly StepFix[]; } /** One step's shapes, as the check found them. */ export interface CheckedStepStage { /** The step's id. */ readonly stepId: string; /** The shape of the rows it takes. */ readonly before: Shape; /** The shape it gives: its input's when it is unfinished or does not check. */ readonly after: Shape; } /** What checking a query's steps found. */ export interface CheckedSteps { /** The printed program. */ readonly program: string; /** The shape the data source gives. */ readonly source: Shape; /** Each step's shapes, in order. */ readonly stages: readonly CheckedStepStage[]; /** The shape the query gives. */ readonly final: Shape; /** The problems, by step. */ readonly diagnostics: readonly StepDiagnostic[]; /** How many are errors. */ readonly errors: number; /** How many are warnings, unfinished slots included. */ readonly warnings: number; /** The layout the check was made on: the program's ranges, and east's check. */ readonly layout: StepLayout; } /** * The type of a data source of the root. * * @param root - the root's type: a struct of the data sources * @param name - the data source's name * @returns its type, or `undefined` when the root has none of that name */ export declare function datasetType(root: EastType, name: string): EastType | undefined; /** * A condition of a filter by its id, with the rows it tests: the step's, or * a list's items for a condition inside has any where. * * @param conds - the filter's conditions * @param id - the condition's id * @param shape - the rows the filter takes * @returns the condition and the rows it tests, or `undefined` when no condition has that id */ export declare function conditionIn(conds: readonly Condition[], id: string, shape: Shape): { condition: Condition; shape: Shape; } | undefined; /** * Checks a query's steps: once, through east's checker, with what the steps * check themselves. * * @param query - the query * @param root - the root's type: a struct of the data sources * @returns the program, each step's shapes, and the diagnostics by step * * @remarks * An unfinished slot is an `incomplete` warning, since an unfinished step is * not in the program. The checker's diagnostics keep their code and message, * placed by span on the step, condition and slot they came from; each jq * step gets a `custom` note. Where the steps find a problem themselves — a * field of the wrong kind in a slot, a comparison the field's kind does not * take, a Look up in a data source that is not a Dict — what the checker * finds in that slot, that condition or that step follows from it and is * left out, so one problem is reported once. */ export declare function checkSteps(query: StepQuery, root: EastType): CheckedSteps; //# sourceMappingURL=check.d.ts.map