UNPKG

@emanuelsan/mosaic-js

Version:

Composable Markdown-based AI instruction engine for Node.js

49 lines 2.76 kB
import { Effect } from "effect"; import { ParsedMarkdownTemplate } from "./parseMarkdownTemplate"; /** * Represents a node in the template tree structure. * Extends ParsedMarkdownTemplate with additional properties for tree traversal and loop detection. * * @interface TemplateTreeNode * @extends ParsedMarkdownTemplate * @property {string} path - The relative path identifier for this template node * @property {string[]} ancestors - Array of ancestor paths used for loop detection during traversal * @property {TemplateTreeNode[]} [children] - Optional array of child nodes that this template references */ interface TemplateTreeNode extends ParsedMarkdownTemplate { path: string; ancestors: string[]; children?: TemplateTreeNode[]; } /** * Processes a template selector and a list of ancestor selectors to generate a sanitized TemplateTreeNode. * * This function takes a root selector (the identifier for a template node) and an optional list of ancestor selectors. * It parses the template, then applies loop detection and cleanup logic using the provided ancestors list. * Any self-references or ancestor loops in the node's `references` array are detected and removed, * ensuring the returned node is free from circular references. Warnings are logged for any loops that are found and removed. * Note: The ancestors list is used only for loop detection and is not attached to the returned node. * * @param {string} rootSelector - The selector identifying the root template node to process. * @param {string[]} [ancestors=[]] - An array of ancestor selectors representing the traversal path to this node (used for loop detection only). * @returns {Effect.Effect<TemplateTreeNode>} An Effect that yields a TemplateTreeNode with all reference and ancestor loops removed. */ export declare const getNodeFromSelector: (rootSelector: string, ancestors?: string[]) => Effect.Effect<TemplateTreeNode, never, import("./normalizeToRelativeSelector").Directory>; /** * Builds a complete template tree by recursively expanding and flattening all references. * Takes a root selector and returns a fully resolved template node with all content expanded. * * @param rootSelector - The selector identifying the root template to build * @returns Effect that yields a fully expanded TemplateTreeNode with all references resolved */ export declare const buildTemplateTree: (rootSelector: string) => Effect.Effect<{ content: string; path: string; ancestors: string[]; children?: TemplateTreeNode[]; frontmatter: Record<string, any> | null; variables: string[]; references: string[]; }, never, import("./normalizeToRelativeSelector").Directory>; export {}; //# sourceMappingURL=buildTemplateTree.d.ts.map