/** * Reverse-projection — live Sitecore items → clean `Recipe` objects. * * This is the inverse of `src/recipe/compile/*`: where the compilers turn * recipes into the Sitecore items a push would create, `readCurrent` walks * the items a compiler *would have* produced and reconstructs the recipe. * It is the `readCurrent` half of the `recipe` recipe kind (see * `recipe-kind.ts` and docs/recipe-sync-architecture.md). * * ## Structure * * This file is the thin orchestration entry. The reverse-projection logic * lives in `read-current/`: * - `helpers.ts` — GUID/field accessors, handle recovery, sort ordering, * the Sitecore field-type ⇄ shape inverse maps, single-field * projection, the per-template field-shape walker, the GUID→handle * marker index, and layout-XML helpers. * - `decode.ts` — the wire-format decoders (date, image/link XML, * templates-mapping, and the `FieldShape`-dispatched value decoder). * - `content-helpers.ts` — per-(language, version) field-decoding helpers * shared by the page + content-item families. * - `project-templates.ts` — component/content/page templates, * component sections, enumerations, and their tree walkers. * - `project-pages.ts` — the layout-bearing kinds (partial-design, * page-design, page, placeholder) and their walkers. * - `project-content.ts` — content items (kind 10) and their walker. * * For backwards-compatibility the historic internal symbols are re-exported * from here (see the re-export block at the bottom). * * ## Scope * * Ten recipe kinds reverse-project here — those whose item layout is * stable and recoverable from the content tree alone: * * 1. `component-section` — a Template Folder directly under componentsRoot * 2. `component-template` — a Template with a matching rendering item * 3. `content-template` — a Template under contentModelsRoot, no rendering * 4. `page-template` — a Template carrying the SXA page base set * 5. `enumeration` — an Enumeration container under enumerationsRoot * 6. `partial-design` — an SXA Partial Design item under partialDesignsRoot * 7. `page-design` — an SXA Page Design item under pageDesignsRoot * 8. `page` — a page item under pagesRoot * 9. `placeholder` — a Placeholder Settings item under * placeholderSettingsRoot * 10. `content-item` — a concrete item under contentItemsRoot whose * template resolves to a known content/component * template * * Kinds 6–9 are the layout-bearing (and layout-adjacent) kinds: their * fidelity hinges on parsing Sitecore layout XML back into the recipe * `Layout` structure — `src/recipe/layout/parse.ts`, the inverse of * `layout/emit.ts`. GUIDs inside the layout XML reference renderings and * datasources; `readCurrent` builds a GUID→handle index off the * `Scai Handle` marker (see `buildGuidHandleIndex`) and resolves them. * * Kind 10 is the content-bearing kind: per-(language, version) field * decoding via a template-field-shape map. Multi-language fan-out uses * `getTenantLanguages` + `getItemPerLanguageBatch` so an L-language read * is one round trip, not L. Per-(language, version) historic capture * follows via `getItemAtVersionsBatch` — same one-round-trip shape. * * Items under the configured roots that match none of these patterns are * silently skipped — not an error. The remaining kinds (site, workflow, * webhook-authorization, …) live in trees this walk doesn't visit; * `readCurrent` just doesn't produce them. * * ## Fidelity — this projection is LOSSY by design * * Recipes carry high-level *intent* the item tree doesn't preserve. The * contract is a documented best-effort: reconstruct what the items * faithfully yield, and where a recipe field genuinely can't be recovered, * **omit it or use the schema default — never fabricate a value**. A * `readCurrent` → compile → `plan` round-trip on an unchanged environment * should be close to all-`noop`; perfect is the goal, best-effort is the * accepted v1 bar. See the per-kind JSDoc in `read-current/` for exactly * what is faithful vs. approximated vs. omitted. * * Layout-XML reverse parsing is itself lossy at the GUID-resolution step: * a layout `` element that references a GUID with no `Scai Handle` * marker is genuinely unrecoverable — the placement is dropped rather than * pointed at a fabricated handle. See `placementFromParsed`. * * ## v1 limitation * * `ref.id` is ignored — `readCurrent` pulls every reverse-projectable * subtree under the configured roots. Scoping the pull to a single item by * name is a future refinement; the orchestrator (`recipe-kind.ts`) passes * the whole-set `KindRef` today. */ import type { AuthoringApiClient } from "../api/client.js"; import type { Recipe } from "../schema/recipe.js"; /** * The compile-time content-tree roots `readCurrent` walks. Mirrors the * subset of `CompileContext` that the in-scope kinds actually live under. * `recipe-kind.ts` builds this off the resolved env profile — the same * fields `plan` reads. */ export interface ReadCurrentRoots { /** Legacy flat templates root. Content/component templates fall back here. */ templatesRoot: string; /** Renderings root — used to detect which templates have a rendering. */ renderingsRoot: string; /** Per-site Components bucket. Component templates + sections live here. */ componentsRoot?: string; /** Per-site Content Models bucket. Content templates live here. */ contentModelsRoot?: string; /** Page-templates root. Templates carrying the SXA page base set live here. */ pageTemplatesRoot?: string; /** Enumerations root. Enumeration containers + value items live here. */ enumerationsRoot?: string; /** Partial Designs root. SXA Partial Design items live here. */ partialDesignsRoot?: string; /** Page Designs root. SXA Page Design items live directly under it. */ pageDesignsRoot?: string; /** Pages root. Concrete page items live here (often the site Home node). */ pagesRoot?: string; /** Placeholder Settings root. Placeholder Settings items live under it. */ placeholderSettingsRoot?: string; /** * Content Items root. Concrete content-item items (the targets of `kind: * "shared"` datasource placements — site-logo, primary-nav, etc.) live * directly under it. */ contentItemsRoot?: string; } /** * Reverse-project every in-scope subtree under the configured roots into a * `Recipe[]` — all ten reverse-projectable kinds (see the module JSDoc). * * Order of work: the templates trees and enumerations first, then the * layout-bearing kinds. The layout-bearing walkers share a GUID→handle * marker index (`buildGuidHandleIndex`) built once up front — skipped * entirely when no layout-bearing root is configured, so an environment * without partial/page designs pays nothing for the index walk. * * Returns `null` only when the environment has *no* roots configured at all * — the signal `recipe-kind.ts` uses to report "this environment has no * recipe-projectable surface." Otherwise always returns the array, which may * legitimately be empty (roots configured but empty trees). * * @param roots Content-tree roots resolved off the env profile. * @param client Authoring API read client (`getItem` / `getChildren`). */ export declare const readCurrentRecipes: (roots: ReadCurrentRoots, client: AuthoringApiClient) => Promise; export { authorableFieldsOf, byTreeOrder, conformsTo, fieldFromItem, fieldsOfTemplate, fieldValue, fieldValueByName, finalLayoutXmlOf, getTemplateFieldShapes, guidEquals, handleOf, hasSxaComponentBases, hasSxaPageBases, indexMarkersUnder, layoutFromXml, layoutOfSnapshot, normalizeGuid, placementFromParsed, sharedLayoutXmlOf, shapeFromSitecoreType, sitecoreTypeFromLabel, type GuidHandleIndex, type TemplateFieldInfo, type TemplateFieldShapes, } from "./read-current/helpers.js"; export { collectSharedFields, dateOfSnapshot, decodeVersionedFieldsOf, fetchHistoricSnapshots, } from "./read-current/content-helpers.js"; export { decodeContentFieldValue, decodeExternalLinkXml, decodeImageXml, decodeInternalLinkXml, decodeSitecoreDateToIso, decodeTemplatesMapping, } from "./read-current/decode.js"; export { collectRenderingComponentNames, walkEnumerationsTree, walkTemplatesTree, } from "./read-current/project-templates.js"; export { walkPageDesignsTree, walkPagesTree, walkPartialDesignsTree, walkPlaceholderSettingsTree, } from "./read-current/project-pages.js"; export { walkContentItemsTree } from "./read-current/project-content.js";