import type { CloudFormationStackArtifact } from './artifacts/cloudformation-artifact'; import type { CloudAssembly } from './cloud-assembly'; /** * A construct from tree.json joined with the CloudFormation metadata of the * stack it belongs to: the construct path/id plus, for CFN resources, the * logical ID and resource type. Readers that need more (for example a source * location) extend this and build the richer tree via {@link buildConstructTree}. */ export interface ConstructTreeNode { readonly path: string; readonly id: string; /** CFN resource type (e.g. "AWS::S3::Bucket"), if this construct is a CFN resource. */ readonly type?: string; /** CFN logical ID, if this construct maps to a CFN resource. */ readonly logicalId?: string; /** * Absolute path to the `*.template.json` that declares this construct's CFN * resource -- the nested template for resources inside a NestedStack. Set * only for CFN resources whose template is resolvable. */ readonly templateFile?: string; /** * Resolved CloudFormation resource properties (the synthesized values from * the `aws:cdk:cloudformation:props` attribute), if this is a CFN resource. */ readonly cfnProperties?: Record; readonly children: readonly ConstructTreeNode[]; } /** * The generic fields {@link buildConstructTree} computes for each node before a * consumer decorates it. `children` are already the decorated node type. */ export interface ConstructTreeNodeFields { readonly path: string; readonly id: string; readonly type?: string; readonly logicalId?: string; readonly templateFile?: string; readonly cfnProperties?: Record; readonly children: readonly T[]; } /** * Produces a node of type `T` from the generic fields, the owning stack * artifact (if any), and the construct path. Readers use the stack + path to * attach extra data (for example a source location traced from the stack). */ export type ConstructNodeDecorator = (fields: ConstructTreeNodeFields, stack: CloudFormationStackArtifact | undefined, constructPath: string) => T; /** * Async variant of {@link ConstructNodeDecorator}: the decorator may return a * `Promise`, so it can do non-blocking I/O (for example reading source maps * off disk with `fs.promises`) while building each node. Used by * {@link buildConstructTreeAsync}. */ export type AsyncConstructNodeDecorator = (fields: ConstructTreeNodeFields, stack: CloudFormationStackArtifact | undefined, constructPath: string) => T | Promise; /** * A pre-built index over a construct tree. Walks the tree once and exposes * O(1) path lookup plus pre-order iteration over every node, so callers never * re-implement the recursive descent over `children`. * * Generic over the concrete node type, so callers that store richer nodes get * those richer nodes back from `byPath()` and iteration. */ export declare class ConstructIndex implements Iterable { private readonly byPathMap; /** Build an index from the roots of a construct tree. */ static fromTree(tree: readonly T[]): ConstructIndex; private constructor(); /** The node at a given construct path, or undefined if absent. */ byPath(constructPath: string): T | undefined; /** Number of nodes in the tree. */ get size(): number; /** Pre-order iteration over every node in the tree. */ [Symbol.iterator](): Iterator; } /** * Read a cloud assembly's tree.json and join it with each stack's manifest * metadata to produce a construct tree where every CFN resource carries its * logicalId and CFN type. * * Supports: * - Flat assemblies (stacks directly under App). * - Stage-based apps: each Stage produces a nested cloud-assembly artifact * under assembly-STAGE/. stacksRecursively descends into them. * - NestedStack contents: aws-cdk-lib emits the per-resource metadata for * nested-stack constructs into the PARENT stack's artifact metadata, * keyed by full construct path. * * The `decorate` callback turns each node's generic fields and its metadata * entries into the concrete node type (e.g. attaching a resolved source location). * * This is the synchronous variant: `decorate` must return `T`. Callers whose * decoration needs non-blocking I/O should use {@link buildConstructTreeAsync}. */ export declare function buildConstructTree(assembly: CloudAssembly, decorate: ConstructNodeDecorator): T[]; /** * Async counterpart of {@link buildConstructTree}: the `decorate` callback may * return a `Promise`, letting it do non-blocking I/O per node (for example * tracing source locations with `fs.promises`) without blocking the calling * thread. Behaves identically otherwise; the tree is walked in pre-order and * each node's children are resolved before the node is decorated. */ export declare function buildConstructTreeAsync(assembly: CloudAssembly, decorate: AsyncConstructNodeDecorator): Promise;