1 | import { IDependable } from './dependency';
|
2 | import { MetadataEntry } from './metadata';
|
3 |
|
4 |
|
5 |
|
6 | export interface IConstruct extends IDependable {
|
7 | |
8 |
|
9 |
|
10 | readonly node: Node;
|
11 | }
|
12 |
|
13 |
|
14 |
|
15 | export declare class Node {
|
16 | private readonly host;
|
17 | |
18 |
|
19 |
|
20 | static readonly PATH_SEP = "/";
|
21 | |
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | static of(construct: IConstruct): Node;
|
28 | |
29 |
|
30 |
|
31 |
|
32 |
|
33 | readonly scope?: IConstruct;
|
34 | |
35 |
|
36 |
|
37 |
|
38 |
|
39 | readonly id: string;
|
40 | private _locked;
|
41 | private readonly _children;
|
42 | private readonly _context;
|
43 | private readonly _metadata;
|
44 | private readonly _dependencies;
|
45 | private _defaultChild;
|
46 | private readonly _validations;
|
47 | private _addr?;
|
48 | constructor(host: Construct, scope: IConstruct, id: string);
|
49 | /**
|
50 | * The full, absolute path of this construct in the tree.
|
51 | *
|
52 | * Components are separated by '/'.
|
53 | */
|
54 | get path(): string;
|
55 | /**
|
56 | * Returns an opaque tree-unique address for this construct.
|
57 | *
|
58 | * Addresses are 42 characters hexadecimal strings. They begin with "c8"
|
59 | * followed by 40 lowercase hexadecimal characters (0-9a-f).
|
60 | *
|
61 | * Addresses are calculated using a SHA-1 of the components of the construct
|
62 | * path.
|
63 | *
|
64 | * To enable refactorings of construct trees, constructs with the ID `Default`
|
65 | * will be excluded from the calculation. In those cases constructs in the
|
66 | * same tree may have the same addreess.
|
67 | *
|
68 | * @example c83a2846e506bcc5f10682b564084bca2d275709ee
|
69 | */
|
70 | get addr(): string;
|
71 | /**
|
72 | * Return a direct child by id, or undefined
|
73 | *
|
74 | * @param id Identifier of direct child
|
75 | * @returns the child if found, or undefined
|
76 | */
|
77 | tryFindChild(id: string): IConstruct | undefined;
|
78 | /**
|
79 | * Return a direct child by id
|
80 | *
|
81 | * Throws an error if the child is not found.
|
82 | *
|
83 | * @param id Identifier of direct child
|
84 | * @returns Child with the given id.
|
85 | */
|
86 | findChild(id: string): IConstruct;
|
87 | /**
|
88 | * Returns the child construct that has the id `Default` or `Resource"`.
|
89 | * This is usually the construct that provides the bulk of the underlying functionality.
|
90 | * Useful for modifications of the underlying construct that are not available at the higher levels.
|
91 | *
|
92 | * @throws if there is more than one child
|
93 | * @returns a construct or undefined if there is no default child
|
94 | */
|
95 | get defaultChild(): IConstruct | undefined;
|
96 | /**
|
97 | * Override the defaultChild property.
|
98 | *
|
99 | * This should only be used in the cases where the correct
|
100 | * default child is not named 'Resource' or 'Default' as it
|
101 | * should be.
|
102 | *
|
103 | * If you set this to undefined, the default behavior of finding
|
104 | * the child named 'Resource' or 'Default' will be used.
|
105 | */
|
106 | set defaultChild(value: IConstruct | undefined);
|
107 | /**
|
108 | * All direct children of this construct.
|
109 | */
|
110 | get children(): IConstruct[];
|
111 | /**
|
112 | * Return this construct and all of its children in the given order
|
113 | */
|
114 | findAll(order?: ConstructOrder): IConstruct[];
|
115 | /**
|
116 | * This can be used to set contextual values.
|
117 | * Context must be set before any children are added, since children may consult context info during construction.
|
118 | * If the key already exists, it will be overridden.
|
119 | * @param key The context key
|
120 | * @param value The context value
|
121 | */
|
122 | setContext(key: string, value: any): void;
|
123 | /**
|
124 | * Retrieves a value from tree context if present. Otherwise, would throw an error.
|
125 | *
|
126 | * Context is usually initialized at the root, but can be overridden at any point in the tree.
|
127 | *
|
128 | * @param key The context key
|
129 | * @returns The context value or throws error if there is no context value for this key
|
130 | */
|
131 | getContext(key: string): any;
|
132 | /**
|
133 | * Retrieves the all context of a node from tree context.
|
134 | *
|
135 | * Context is usually initialized at the root, but can be overridden at any point in the tree.
|
136 | *
|
137 | * @param defaults Any keys to override the retrieved context
|
138 | * @returns The context object or an empty object if there is discovered context
|
139 | */
|
140 | getAllContext(defaults?: object): any;
|
141 | /**
|
142 | * Retrieves a value from tree context.
|
143 | *
|
144 | * Context is usually initialized at the root, but can be overridden at any point in the tree.
|
145 | *
|
146 | * @param key The context key
|
147 | * @returns The context value or `undefined` if there is no context value for this key.
|
148 | */
|
149 | tryGetContext(key: string): any;
|
150 | /**
|
151 | * An immutable array of metadata objects associated with this construct.
|
152 | * This can be used, for example, to implement support for deprecation notices, source mapping, etc.
|
153 | */
|
154 | get metadata(): MetadataEntry[];
|
155 | /**
|
156 | * Adds a metadata entry to this construct.
|
157 | * Entries are arbitrary values and will also include a stack trace to allow tracing back to
|
158 | * the code location for when the entry was added. It can be used, for example, to include source
|
159 | * mapping in CloudFormation templates to improve diagnostics.
|
160 | *
|
161 | * @param type a string denoting the type of metadata
|
162 | * @param data the value of the metadata (can be a Token). If null/undefined, metadata will not be added.
|
163 | * @param options options
|
164 | */
|
165 | addMetadata(type: string, data: any, options?: MetadataOptions): void;
|
166 | /**
|
167 | * All parent scopes of this construct.
|
168 | *
|
169 | * @returns a list of parent scopes. The last element in the list will always
|
170 | * be the current construct and the first element will be the root of the
|
171 | * tree.
|
172 | */
|
173 | get scopes(): IConstruct[];
|
174 | /**
|
175 | * Returns the root of the construct tree.
|
176 | * @returns The root of the construct tree.
|
177 | */
|
178 | get root(): IConstruct;
|
179 | /**
|
180 | * Returns true if this construct or the scopes in which it is defined are
|
181 | * locked.
|
182 | */
|
183 | get locked(): boolean;
|
184 | /**
|
185 | * Add an ordering dependency on another construct.
|
186 | *
|
187 | * An `IDependable`
|
188 | */
|
189 | addDependency(...deps: IDependable[]): void;
|
190 | /**
|
191 | * Return all dependencies registered on this node (non-recursive).
|
192 | */
|
193 | get dependencies(): IConstruct[];
|
194 | /**
|
195 | * Remove the child with the given name, if present.
|
196 | *
|
197 | * @returns Whether a child with the given name was deleted.
|
198 | * @experimental
|
199 | */
|
200 | tryRemoveChild(childName: string): boolean;
|
201 | /**
|
202 | * Adds a validation to this construct.
|
203 | *
|
204 | * When `node.validate()` is called, the `validate()` method will be called on
|
205 | * all validations and all errors will be returned.
|
206 | *
|
207 | * @param validation The validation object
|
208 | */
|
209 | addValidation(validation: IValidation): void;
|
210 | /**
|
211 | * Validates this construct.
|
212 | *
|
213 | * Invokes the `validate()` method on all validations added through
|
214 | * `addValidation()`.
|
215 | *
|
216 | * @returns an array of validation error messages associated with this
|
217 | * construct.
|
218 | */
|
219 | validate(): string[];
|
220 | /**
|
221 | * Locks this construct from allowing more children to be added. After this
|
222 | * call, no more children can be added to this construct or to any children.
|
223 | */
|
224 | lock(): void;
|
225 | /**
|
226 | * Adds a child construct to this node.
|
227 | *
|
228 | * @param child The child construct
|
229 | * @param childName The type name of the child construct.
|
230 | * @returns The resolved path part name of the child
|
231 | */
|
232 | private addChild;
|
233 | }
|
234 | /**
|
235 | * Represents the building block of the construct graph.
|
236 | *
|
237 | * All constructs besides the root construct must be created within the scope of
|
238 | * another construct.
|
239 | */
|
240 | export declare class Construct implements IConstruct {
|
241 | |
242 |
|
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 |
|
249 |
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 |
|
259 |
|
260 |
|
261 | static isConstruct(x: any): x is Construct;
|
262 | |
263 |
|
264 |
|
265 | readonly node: Node;
|
266 | |
267 |
|
268 |
|
269 |
|
270 |
|
271 |
|
272 |
|
273 |
|
274 | constructor(scope: Construct, id: string);
|
275 | /**
|
276 | * Returns a string representation of this construct.
|
277 | */
|
278 | toString(): string;
|
279 | }
|
280 | /**
|
281 | * Implement this interface in order for the construct to be able to validate itself.
|
282 | */
|
283 | export interface IValidation {
|
284 | |
285 |
|
286 |
|
287 |
|
288 |
|
289 |
|
290 |
|
291 |
|
292 | validate(): string[];
|
293 | }
|
294 |
|
295 |
|
296 |
|
297 | export declare enum ConstructOrder {
|
298 | |
299 |
|
300 |
|
301 | PREORDER = 0,
|
302 | |
303 |
|
304 |
|
305 | POSTORDER = 1
|
306 | }
|
307 |
|
308 |
|
309 |
|
310 | export interface MetadataOptions {
|
311 | |
312 |
|
313 |
|
314 |
|
315 | readonly stackTrace?: boolean;
|
316 | |
317 |
|
318 |
|
319 |
|
320 |
|
321 |
|
322 |
|
323 | readonly traceFromFunction?: any;
|
324 | }
|