import { CanvasSection } from '../../../../types/openapi'; /** * Opt-in lazy section loading — client-side hydration engine. * * When a canvas is fetched as a "shell" (`?lazy_sections=true` + the * `lazy_load_sections` setting), it carries ordered `section_ids` instead of the * heavy inline `sections`. This engine drains those IDs through the batch * endpoint progressively (bounded batches, capped concurrency) and feeds the * hydrated bodies back so the renderer fills in as they arrive. * * It is a PURE async queue — no Vue, no network knowledge — so it is unit * testable in isolation and reused unchanged by `useCanvas`. It is completely * dormant unless `start()` is called with a non-empty ID list, which only * happens for a shell canvas; the legacy fully-expanded path never touches it. */ /** Server-side `MAX_BATCH` in Django `sections_by_ids` / next-core by-ids route. */ export declare const MAX_SECTIONS_PER_BATCH = 100; export interface LazySectionLoaderOptions { /** Fetch the bodies for a slice of section IDs (≤ MAX_SECTIONS_PER_BATCH). */ fetchBatch: (sectionIds: string[]) => Promise; /** Called with each hydrated batch as it resolves (append into the canvas). */ onSections: (sections: CanvasSection[]) => void; /** Per-batch error sink. A failed batch is isolated; the drain continues. */ onError?: (error: unknown, sectionIds: string[]) => void; /** Sections per request. Clamped to [1, MAX_SECTIONS_PER_BATCH]. Default 50. */ batchSize?: number; /** Max in-flight batches. Default 2. */ concurrency?: number; } export interface LazySectionLoader { /** * Begin draining `allSectionIds`, skipping any already in `loadedSectionIds`. * Order is preserved (content order = reading order, top-down). Idempotent * per ID — an ID already queued/in-flight/done is never enqueued twice. */ start(allSectionIds: string[], loadedSectionIds?: Iterable): void; /** * Move the given IDs to the front of the remaining queue (e.g. the section a * deep-link / the rep's current page points at), so they hydrate first. * Unknown or already-loaded IDs are ignored. A section whose background batch * previously FAILED is revived here for an on-demand retry (bounded), so * navigating onto a transiently-failed section fetches it instead of leaving * it blank. */ prioritize(sectionIds: string[]): void; /** Resolves once the queue is fully drained (all batches settled). */ ensureAll(): Promise; /** Cancel everything in flight and clear the queue (new deck load). */ reset(): void; /** Remaining queued IDs not yet hydrated. */ pendingCount(): number; } export declare function createLazySectionLoader(options: LazySectionLoaderOptions): LazySectionLoader;