/** * 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 */ /** * Shared field-tree walker. * * `walkFieldTree(fields, data)` traverses a `(FieldSet, data)` pair in * lockstep, descending through `group` / `array` / `blocks` structure * fields and yielding every value-leaf it finds. Consumers filter by * `field.type` and apply their own domain checks (e.g. relation envelope * shape, populate-spec match, `_resolved` skip, richText null handling). * * Both `collectRelationLeaves` (populate.ts) and `collectRichTextLeaves` * (richtext-populate.ts) are thin filters over this primitive. */ import { type Field, type FieldSet } from '../@types/field-types.js'; /** * One value-leaf yielded by `walkFieldTree`. The walker hands back a * reference to the *parent container* (`parent[key]`) so consumers can * mutate or replace the value in place — `parent[key] === value` always * holds at yield time. * * `fieldPath` is the dotted path from the root of the walk, with array * indices spelled inline (`faq.0.answer`, `content.1.richText`). Suitable * for error messages and debug logging. */ export interface FieldLeaf { field: Field; value: unknown; parent: Record; key: string; fieldPath: string; } /** * Walk a field set and a matching reconstructed data tree in lockstep, * yielding every value-leaf the schema declares regardless of nesting * depth. * * **What counts as a leaf:** every non-structure field whose value is * non-null. Structure fields (`group` / `array` / `blocks`) are descended * into, never yielded themselves. Null / undefined values are skipped * silently — the schema is the source of truth for *where* a leaf might * be; the data is the source of truth for *whether one is currently set*. * * Tolerates malformed data gracefully: * - a `group` whose data is missing or non-object yields nothing * - an `array` whose data isn't an array yields nothing * - a `blocks` item with a missing or unknown `_type` is skipped * * The walker is synchronous and lazy (a generator). Async work — DB * fetches, hook fan-out — happens in the consumer after the walk yields. */ export declare function walkFieldTree(fields: FieldSet, data: Record | null | undefined, pathPrefix?: string): Generator;