UNPKG

aws-cdk-lib

Version:

Version 2 of the AWS Cloud Development Kit library

111 lines (110 loc) 3.76 kB
/** * Interface for applying properties to a target using a specific strategy */ export interface IMergeStrategy { /** * Apply properties from source to target for the given keys * * @param target - The construct to apply properties to * @param source - The property values to apply * @param allowedKeys - Only properties whose names are in this list will be * read from `source` and written to `target`. This acts as an allowlist * to ensure only known CloudFormation resource properties are applied. */ apply(target: object, source: object, allowedKeys: string[]): void; } /** * Interface for merging arrays */ export interface IArrayMergeStrategy { /** * Merge source array into target array */ merge(target: any[], source: any[]): any[]; } /** * Strategies for merging arrays in L1 property mixins. * Array elements are never deep-merged. */ export declare class ArrayMergeStrategy { /** * Replace the target array entirely with the source array. * * @example * // target: [1, 2, 3], source: [4, 5] → [4, 5] */ static replace(): IArrayMergeStrategy; /** * Append source elements after the existing target elements. * * @example * // target: [1, 2], source: [3, 4] → [1, 2, 3, 4] */ static append(): IArrayMergeStrategy; /** * Prepend source elements before the existing target elements. * * @example * // target: [1, 2], source: [3, 4] → [3, 4, 1, 2] */ static prepend(): IArrayMergeStrategy; /** * Overwrite target elements positionally with source elements. * Target elements beyond the source length are preserved. * * @example * // target: ['a', 'b', 'c', 'd'], source: ['x', 'y'] → ['x', 'y', 'c', 'd'] */ static replaceByIndex(): IArrayMergeStrategy; /** * Match source and target elements by a shared key property. * Matching target elements are replaced (not deep-merged). * Unmatched source elements are appended. * * Supports Box-backed elements: when target array elements are Boxes, the * match is deferred until the Boxes resolve. * * @param key - The property name to match elements on. * * @example * // key: 'id' * // target: [{id: 1, v: 'old'}, {id: 2, v: 'keep'}] * // source: [{id: 1, v: 'new'}, {id: 3, v: 'added'}] * // result: [{id: 1, v: 'new'}, {id: 2, v: 'keep'}, {id: 3, v: 'added'}] */ static replaceByKey(key: string): IArrayMergeStrategy; private constructor(); } /** * Options for the combine strategy */ export interface CombineStrategyOptions { /** * Strategy for merging arrays. * * @default ArrayMergeStrategy.replace() */ readonly arrays?: IArrayMergeStrategy; } /** * Strategy for handling nested properties in L1 property mixins */ export declare class PropertyMergeStrategy { /** * Replaces existing property values on the target with the values from the source. * Each allowed key is copied from source to target as-is, without * inspecting nested objects. Any previous value on the target is discarded. */ static override(): IMergeStrategy; /** * Deep merges nested objects from source into target. * When both the existing and new value for a key are plain objects, * their properties are merged recursively. Primitives, arrays, and * mismatched types are overridden by the source value. * * Supports Box-backed values: when the target value is a Box, the merge * is deferred until the Box resolves. */ static combine(options?: CombineStrategyOptions): IMergeStrategy; private constructor(); }