/**
 * 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 utilities for the Lexical adapter's server-side populate. Each
 * Lexical plugin contributes a `LexicalNodeVisitor` describing what it
 * looks for and how to refresh it; the driver below walks each rich-text
 * value once, dispatches across every visitor, batches per source
 * collection, and applies the refresh.
 *
 * Pure / framework-agnostic. No React, no DOM, no Lexical runtime — safe
 * to import from the package's `server` entry.
 */
import type { BylineClient } from '@byline/client';
import type { ReadContext } from '@byline/core';
/**
 * Lexical-shaped node — only the fields the visitors need to read or
 * mutate. Carries an unknown `children` array because nodes nest
 * (paragraphs, lists, tables, …). Per-node-type fields (link / inline-
 * image attributes) are spread flat onto the node and accessed
 * structurally rather than through a discriminated union, since each
 * visitor knows its own shape.
 */
export interface LexicalNodeLike {
    type?: string;
    children?: LexicalNodeLike[];
    targetDocumentId?: string;
    targetCollectionId?: string;
    targetCollectionPath?: string;
    document?: Record<string, any>;
    linkType?: 'custom' | 'internal';
    attributes?: Record<string, any>;
}
/**
 * Read a rich-text field value (Lexical JSON object or stringified) and
 * return its root node, or `null` if the value is not a parseable Lexical
 * tree. Tolerates both shapes Byline has shipped — the wrapped form
 * (`{ root: { … } }`) and the raw root node.
 */
export declare function getLexicalRoot(value: unknown): LexicalNodeLike | null;
/**
 * Top-down recursive walk over a Lexical tree. Yields every node including
 * the root. Mutating fields on yielded nodes is safe — the walk doesn't
 * revisit and is order-independent for our visitors.
 */
export declare function iterAllNodes(node: LexicalNodeLike): Generator<LexicalNodeLike, void, void>;
/**
 * One pending hydration unit. The visitor decides whether a node matches,
 * and if so produces a `PendingHydration` describing how to refresh it.
 */
export interface PendingHydration {
    node: LexicalNodeLike;
    collectionPath: string;
    documentId: string;
    /**
     * Apply the freshly-fetched target document to the node. Mutates `node`
     * in place; `target.fields` is the shaped collection record. Receives
     * the full target so the visitor can pick whatever projection it cares
     * about.
     */
    apply: (target: Record<string, any>) => void;
}
/**
 * Visitor contract — one per node type that participates in populate.
 * `match` is called for every node in the tree; when it returns a
 * `PendingHydration`, the driver enqueues it for batch fetch.
 */
export interface LexicalNodeVisitor {
    match: (node: LexicalNodeLike) => PendingHydration | null;
}
interface RunPopulateOptions {
    client: BylineClient;
    readContext: ReadContext;
    visitors: LexicalNodeVisitor[];
    /**
     * One or more rich-text values to walk. The framework's read pipeline
     * calls the registered populate function once per leaf, so the typical
     * shape here is a single-element array — but the driver supports
     * multiple values for batching across an entire document tree if a
     * future caller wants the optimisation.
     */
    values: unknown[];
}
/**
 * Walk every supplied rich-text value, collect the union of pending
 * hydrations across all visitors, batch-fetch by source collection, and
 * apply. Threading `readContext` keeps the visited-set / `afterReadFired`
 * / read-budget machinery in sync with relation populate and user-land
 * `afterRead` hooks.
 */
export declare function runLexicalPopulate(options: RunPopulateOptions): Promise<void>;
export {};
