UNPKG

aws-cdk-lib

Version:

Version 2 of the AWS Cloud Development Kit library

78 lines (77 loc) 4.2 kB
import type { IConstruct } from 'constructs'; import { CfnResource } from '../cfn-resource'; /** * Safely traverses a nested property path on an object, returning a fallback * if any value along the path is an unresolved token (`IResolvable`). * * Array indexing is supported using numeric path segments (e.g. `'rules.0.name'`). * * Return value semantics: * - Returns the resolved value if the full path is reachable and no segment is a token. * - Returns `undefined` if a segment along the path is `null` or `undefined`, * meaning the property was never configured. * - Returns the `fallback` if a segment (or the leaf) is an `IResolvable` token, * meaning the property is configured but its value can't be inspected at synthesis time. * * @param obj - The root object to traverse. * @param path - Dot-separated property path. * @param fallback - Value to return when an unresolved token is encountered. */ export declare function resolvedGet<T>(obj: any, path: string, fallback: T): any | T; /** * Checks whether a nested property exists on an object, returning a * three-state result that accounts for unresolved tokens. * * - Returns `true` if the full path is reachable and the leaf value is not `undefined`. * - Returns `false` if a segment along the path is `null` or `undefined`. * - Returns `undefined` if any segment (or the leaf) is an `IResolvable` token, * or if `obj` itself is `null`/`undefined`. * * @param obj - The root object to traverse. * @param path - Dot-separated property path. */ export declare function resolvedExists(obj: any, path: string): boolean | undefined; /** * Checks whether a nested property equals an expected value, returning a * three-state result that accounts for unresolved tokens. * * - Returns `true` if the full path is reachable and the leaf equals `expected`. * - Returns `false` if the path is not configured or the leaf differs from `expected`. * - Returns `undefined` if any segment (or the leaf) is an `IResolvable` token, * or if `obj` itself is `null`/`undefined`. * * @param obj - The root object to traverse. * @param path - Dot-separated property path. * @param expected - The value to compare against. */ export declare function resolvedEquals(obj: any, path: string, expected: any): boolean | undefined; /** * Finds the closest related resource in the construct tree. * Searches children first (depth-first), then ancestors (breadth-first). * * @param primary - The construct to search a related resource for * @param relatedCfnResourceType - The CloudFormation resource type to search for * @param isConnected - Predicate to determine if a candidate is related to the primary * @returns The closest matching resource, or undefined if none found */ export declare function findClosestRelatedResource<TPrimary extends IConstruct, TRelated extends CfnResource>(primary: TPrimary, relatedCfnResourceType: string, isConnected: (primary: TPrimary, candidate: TRelated) => boolean): TRelated | undefined; /** * Attempts to find the L1 CfnResource for a given Ref interface. * Searches children first (for L2 wrappers), then the construct tree. * * @param ref - The Ref interface (e.g., IKeyRef, IBucketRef) * @param cfnResourceType - The CloudFormation resource type (e.g., 'AWS::KMS::Key') * @param extractId - Function to extract the identifying property from the ref * @param extractCfnId - Function to extract the identifying property from the CfnResource * @returns The L1 CfnResource if found, undefined otherwise */ export declare function findL1FromRef<TRef extends IConstruct, TCfn extends CfnResource>(ref: TRef, cfnResourceType: string, compareIdToCfnId: (cfn: TCfn, ref: TRef) => boolean): TCfn | undefined; /** * Finds the parent L2 construct scope if this construct is a default child. * L2 constructs create their L1 resource as a child with id 'Resource' or 'Default'. * Only these two ids have special meaning. * * @param construct - The construct to find the parent L2 scope for * @returns The parent L2 scope if the construct is a default child, undefined otherwise */ export declare function findParentL2Scope(construct: IConstruct): IConstruct | undefined;