/** * This Source Code is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * Copyright (c) Infonomic Company Limited */ import type { Block, Field } from '../@types/index.js'; import type { PathResolution, PathSegment, ResolveOptions } from './path-types.js'; export interface WalkOptions { /** * Called for every block declaration encountered, immediately before its * fields are visited, with the segments addressing the block itself * (`content.photoBlock`). * * Blocks are declaration sites in their own right, and a block with no * fields is invisible to `visit` — so validation that must see every block * regardless of its contents needs this rather than inferring blocks from * the segments of the fields inside them. */ readonly onBlock?: (block: Block, segments: readonly PathSegment[]) => void; } /** * Visit every field declaration in a field set, depth first, handing each one * the segments that address it. * * Structure fields are visited themselves and then descended into. A `blocks` * field contributes two segments per hop — its own name and the block type — * which is what keeps two blocks declaring the same field name apart. * * This is the single canonical walk. Producers of declaration paths (the * upload hook registry, boot-validation error messages) should use it rather * than re-implementing the descent, which is how they drifted apart. */ export declare function walkFieldDeclarations(fields: readonly Field[], visit: (field: Field, segments: readonly PathSegment[]) => void, options?: WalkOptions): void; /** * Resolve a declaration path against a field set. * * Accepts either a path string or pre-parsed segments. Segments arriving as * `kind: 'field'` where the schema expects a block type are reclassified in * the returned `segments`, so callers get a correctly typed path back even * though the parser could not have known. * * Item selectors are rejected: a declaration path addresses a declaration, so * an index is a category error rather than something to ignore. */ export declare function resolveDeclarationPath(fields: readonly Field[], path: string | readonly PathSegment[], options?: ResolveOptions): PathResolution;