import type { GraphQLSchema } from 'graphql'; import { type VariableCheck, type VariableDefinition } from './variableCheck.js'; /** * How a widget's saved settings become the variables of its page query, and the * check that follows (see `variableCheck.ts`). * * The page-query middleware does this per request from the build output. A save * has no build output to lean on (and `theme:active` runs without one), so a * widget's declarations are read from its compiled component file, with the same * parser the build uses. Both go through `resolveSettingRef`, so a setting * cannot mean one thing when it is saved and another when it is rendered. */ /** What a component's `export const query` / `export const variables` declare. */ export interface WidgetVariableSpec { defs: VariableDefinition[]; /** The declared value of each variable by alias: a literal, or a `getWidgetSetting_…` reference. */ raw: Record; } /** * Resolve one declared variable value against a widget's settings. * * - not a string: a literal, used as it is * - a string holding `getWidgetSetting("a.b")`: the setting at that path, or the * whole settings object when the path is empty * - any other string: not passed (the page-query middleware has always dropped it) */ export declare function resolveSettingRef(raw: unknown, settings: Record): { found: boolean; value?: unknown; }; /** * Read a widget's variable declarations from its compiled component file. Kept * per file version, so a rebuilt file is read again and nothing else is. * Returns null when the file cannot be read or parsed: a caller that only wants * to validate then skips the widget rather than blocking a save on tooling. */ export declare function getWidgetVariableSpec(componentPath: string): WidgetVariableSpec | null; /** The value each of the widget's variables would get from `settings`, by alias. */ export declare function widgetVariableValues(spec: WidgetVariableSpec, settings: Record): Record; /** Check a widget's settings against the schema as it is now. */ export declare function checkWidgetSettings(schema: GraphQLSchema, spec: WidgetVariableSpec, settings: Record): VariableCheck; /** * What a SAVE should refuse: every message, or none when the settings are fine. * * Pass `previous`, the settings already stored, when updating. Whatever the * stored settings already got wrong is not blamed on this update: a merchant who * edits one slide must not be locked out because an older version of the schema * let a key through that the page builder cannot show, let alone remove. Only * what the update itself introduces is refused. (The page still renders: the * render path drops such keys.) */ export declare function findSettingsProblems(schema: GraphQLSchema, spec: WidgetVariableSpec, settings: Record, previous?: Record | null): string[];