1 | /**
|
2 | * Constructs compatibility layer.
|
3 | *
|
4 | * This file includes types that shadow types in the "constructs" module in
|
5 | * order to allow backwards-compatiblity in the AWS CDK v1.0 release line.
|
6 | *
|
7 | * There are pretty ugly hacks here, which mostly involve downcasting types to
|
8 | * adhere to legacy AWS CDK APIs.
|
9 | *
|
10 | * This file, in its entirety, is expected to be removed in v2.0.
|
11 | */
|
12 | import * as cxapi from '@aws-cdk/cx-api';
|
13 | import * as constructs from 'constructs';
|
14 | import { IAspect } from './aspect';
|
15 | import { IDependable } from './dependency';
|
16 | /**
|
17 | * Represents a construct.
|
18 | */
|
19 | export interface IConstruct extends constructs.IConstruct, IDependable {
|
20 | /**
|
21 | * The construct tree node for this construct.
|
22 | */
|
23 | readonly node: ConstructNode;
|
24 | }
|
25 | /**
|
26 | * Represents a single session of synthesis. Passed into `Construct.synthesize()` methods.
|
27 | */
|
28 | export interface ISynthesisSession {
|
29 | /**
|
30 | * The output directory for this synthesis session.
|
31 | */
|
32 | outdir: string;
|
33 | /**
|
34 | * Cloud assembly builder.
|
35 | */
|
36 | assembly: cxapi.CloudAssemblyBuilder;
|
37 | /**
|
38 | * Whether the stack should be validated after synthesis to check for error metadata
|
39 | *
|
40 | * @default - false
|
41 | */
|
42 | validateOnSynth?: boolean;
|
43 | }
|
44 | /**
|
45 | * Represents the building block of the construct graph.
|
46 | *
|
47 | * All constructs besides the root construct must be created within the scope of
|
48 | * another construct.
|
49 | */
|
50 | export declare class Construct extends constructs.Construct implements IConstruct {
|
51 | /**
|
52 | * Return whether the given object is a Construct
|
53 | */
|
54 | static isConstruct(x: any): x is Construct;
|
55 | /**
|
56 | * The construct tree node associated with this construct.
|
57 | */
|
58 | readonly node: ConstructNode;
|
59 | constructor(scope: constructs.Construct, id: string);
|
60 | /**
|
61 | * Validate the current construct.
|
62 | *
|
63 | * This method can be implemented by derived constructs in order to perform
|
64 | * validation logic. It is called on all constructs before synthesis.
|
65 | *
|
66 | * @returns An array of validation error messages, or an empty array if the construct is valid.
|
67 | */
|
68 | protected onValidate(): string[];
|
69 | /**
|
70 | * Perform final modifications before synthesis
|
71 | *
|
72 | * This method can be implemented by derived constructs in order to perform
|
73 | * final changes before synthesis. prepare() will be called after child
|
74 | * constructs have been prepared.
|
75 | *
|
76 | * This is an advanced framework feature. Only use this if you
|
77 | * understand the implications.
|
78 | */
|
79 | protected onPrepare(): void;
|
80 | /**
|
81 | * Allows this construct to emit artifacts into the cloud assembly during synthesis.
|
82 | *
|
83 | * This method is usually implemented by framework-level constructs such as `Stack` and `Asset`
|
84 | * as they participate in synthesizing the cloud assembly.
|
85 | *
|
86 | * @param session The synthesis session.
|
87 | */
|
88 | protected onSynthesize(session: constructs.ISynthesisSession): void;
|
89 | /**
|
90 | * Validate the current construct.
|
91 | *
|
92 | * This method can be implemented by derived constructs in order to perform
|
93 | * validation logic. It is called on all constructs before synthesis.
|
94 | *
|
95 | * @returns An array of validation error messages, or an empty array if the construct is valid.
|
96 | */
|
97 | protected validate(): string[];
|
98 | /**
|
99 | * Perform final modifications before synthesis
|
100 | *
|
101 | * This method can be implemented by derived constructs in order to perform
|
102 | * final changes before synthesis. prepare() will be called after child
|
103 | * constructs have been prepared.
|
104 | *
|
105 | * This is an advanced framework feature. Only use this if you
|
106 | * understand the implications.
|
107 | */
|
108 | protected prepare(): void;
|
109 | /**
|
110 | * Allows this construct to emit artifacts into the cloud assembly during synthesis.
|
111 | *
|
112 | * This method is usually implemented by framework-level constructs such as `Stack` and `Asset`
|
113 | * as they participate in synthesizing the cloud assembly.
|
114 | *
|
115 | * @param session The synthesis session.
|
116 | */
|
117 | protected synthesize(session: ISynthesisSession): void;
|
118 | }
|
119 | /**
|
120 | * In what order to return constructs
|
121 | */
|
122 | export declare enum ConstructOrder {
|
123 | /**
|
124 | * Depth-first, pre-order
|
125 | */
|
126 | PREORDER = 0,
|
127 | /**
|
128 | * Depth-first, post-order (leaf nodes first)
|
129 | */
|
130 | POSTORDER = 1
|
131 | }
|
132 | /**
|
133 | * Options for synthesis.
|
134 | *
|
135 | * @deprecated use `app.synth()` or `stage.synth()` instead
|
136 | */
|
137 | export interface SynthesisOptions extends cxapi.AssemblyBuildOptions {
|
138 | /**
|
139 | * The output directory into which to synthesize the cloud assembly.
|
140 | * @default - creates a temporary directory
|
141 | */
|
142 | readonly outdir?: string;
|
143 | /**
|
144 | * Whether synthesis should skip the validation phase.
|
145 | * @default false
|
146 | */
|
147 | readonly skipValidation?: boolean;
|
148 | /**
|
149 | * Whether the stack should be validated after synthesis to check for error metadata
|
150 | *
|
151 | * @default - false
|
152 | */
|
153 | readonly validateOnSynthesis?: boolean;
|
154 | }
|
155 | /**
|
156 | * Represents the construct node in the scope tree.
|
157 | */
|
158 | export declare class ConstructNode {
|
159 | /**
|
160 | * Separator used to delimit construct path components.
|
161 | */
|
162 | static readonly PATH_SEP = "/";
|
163 | /**
|
164 | * Returns the wrapping `@aws-cdk/core.ConstructNode` instance from a `constructs.ConstructNode`.
|
165 | *
|
166 | * @internal
|
167 | */
|
168 | static _unwrap(c: constructs.Node): ConstructNode;
|
169 | /**
|
170 | * Synthesizes a CloudAssembly from a construct tree.
|
171 | * @param node The root of the construct tree.
|
172 | * @param options Synthesis options.
|
173 | * @deprecated Use `app.synth()` or `stage.synth()` instead
|
174 | */
|
175 | static synth(node: ConstructNode, options?: SynthesisOptions): cxapi.CloudAssembly;
|
176 | /**
|
177 | * Invokes "prepare" on all constructs (depth-first, post-order) in the tree under `node`.
|
178 | * @param node The root node
|
179 | * @deprecated Use `app.synth()` instead
|
180 | */
|
181 | static prepare(node: ConstructNode): void;
|
182 | /**
|
183 | * Invokes "validate" on all constructs in the tree (depth-first, pre-order) and returns
|
184 | * the list of all errors. An empty list indicates that there are no errors.
|
185 | *
|
186 | * @param node The root node
|
187 | */
|
188 | static validate(node: ConstructNode): ValidationError[];
|
189 | /**
|
190 | * @internal
|
191 | */
|
192 | readonly _actualNode: constructs.Node;
|
193 | /**
|
194 | * The Construct class that hosts this API.
|
195 | */
|
196 | private readonly host;
|
197 | constructor(host: Construct, scope: IConstruct, id: string);
|
198 | /**
|
199 | * Returns the scope in which this construct is defined.
|
200 | *
|
201 | * The value is `undefined` at the root of the construct scope tree.
|
202 | */
|
203 | get scope(): IConstruct | undefined;
|
204 | /**
|
205 | * The id of this construct within the current scope.
|
206 | *
|
207 | * This is a a scope-unique id. To obtain an app-unique id for this construct, use `uniqueId`.
|
208 | */
|
209 | get id(): string;
|
210 | /**
|
211 | * The full, absolute path of this construct in the tree.
|
212 | *
|
213 | * Components are separated by '/'.
|
214 | */
|
215 | get path(): string;
|
216 | /**
|
217 | * A tree-global unique alphanumeric identifier for this construct. Includes
|
218 | * all components of the tree.
|
219 | *
|
220 | * @deprecated use `node.addr` to obtain a consistent 42 character address for
|
221 | * this node (see https://github.com/aws/constructs/pull/314).
|
222 | * Alternatively, to get a CloudFormation-compatible unique identifier, use
|
223 | * `Names.uniqueId()`.
|
224 | */
|
225 | get uniqueId(): string;
|
226 | /**
|
227 | * Returns an opaque tree-unique address for this construct.
|
228 | *
|
229 | * Addresses are 42 characters hexadecimal strings. They begin with "c8"
|
230 | * followed by 40 lowercase hexadecimal characters (0-9a-f).
|
231 | *
|
232 | * Addresses are calculated using a SHA-1 of the components of the construct
|
233 | * path.
|
234 | *
|
235 | * To enable refactorings of construct trees, constructs with the ID `Default`
|
236 | * will be excluded from the calculation. In those cases constructs in the
|
237 | * same tree may have the same addreess.
|
238 | *
|
239 | * Example value: `c83a2846e506bcc5f10682b564084bca2d275709ee`
|
240 | */
|
241 | get addr(): string;
|
242 | /**
|
243 | * Return a direct child by id, or undefined
|
244 | *
|
245 | * @param id Identifier of direct child
|
246 | * @returns the child if found, or undefined
|
247 | */
|
248 | tryFindChild(id: string): IConstruct | undefined;
|
249 | /**
|
250 | * Return a direct child by id
|
251 | *
|
252 | * Throws an error if the child is not found.
|
253 | *
|
254 | * @param id Identifier of direct child
|
255 | * @returns Child with the given id.
|
256 | */
|
257 | findChild(id: string): IConstruct;
|
258 | /**
|
259 | * Returns the child construct that has the id `Default` or `Resource"`.
|
260 | * This is usually the construct that provides the bulk of the underlying functionality.
|
261 | * Useful for modifications of the underlying construct that are not available at the higher levels.
|
262 | *
|
263 | * @throws if there is more than one child
|
264 | * @returns a construct or undefined if there is no default child
|
265 | */
|
266 | get defaultChild(): IConstruct | undefined;
|
267 | /**
|
268 | * Override the defaultChild property.
|
269 | *
|
270 | * This should only be used in the cases where the correct
|
271 | * default child is not named 'Resource' or 'Default' as it
|
272 | * should be.
|
273 | *
|
274 | * If you set this to undefined, the default behavior of finding
|
275 | * the child named 'Resource' or 'Default' will be used.
|
276 | */
|
277 | set defaultChild(value: IConstruct | undefined);
|
278 | /**
|
279 | * All direct children of this construct.
|
280 | */
|
281 | get children(): IConstruct[];
|
282 | /**
|
283 | * Return this construct and all of its children in the given order
|
284 | */
|
285 | findAll(order?: ConstructOrder): IConstruct[];
|
286 | /**
|
287 | * This can be used to set contextual values.
|
288 | * Context must be set before any children are added, since children may consult context info during construction.
|
289 | * If the key already exists, it will be overridden.
|
290 | * @param key The context key
|
291 | * @param value The context value
|
292 | */
|
293 | setContext(key: string, value: any): void;
|
294 | /**
|
295 | * Retrieves a value from tree context.
|
296 | *
|
297 | * Context is usually initialized at the root, but can be overridden at any point in the tree.
|
298 | *
|
299 | * @param key The context key
|
300 | * @returns The context value or `undefined` if there is no context value for the key.
|
301 | */
|
302 | tryGetContext(key: string): any;
|
303 | /**
|
304 | * DEPRECATED
|
305 | * @deprecated use `metadataEntry`
|
306 | */
|
307 | get metadata(): cxapi.MetadataEntry[];
|
308 | /**
|
309 | * An immutable array of metadata objects associated with this construct.
|
310 | * This can be used, for example, to implement support for deprecation notices, source mapping, etc.
|
311 | */
|
312 | get metadataEntry(): constructs.MetadataEntry[];
|
313 | /**
|
314 | * Adds a metadata entry to this construct.
|
315 | * Entries are arbitrary values and will also include a stack trace to allow tracing back to
|
316 | * the code location for when the entry was added. It can be used, for example, to include source
|
317 | * mapping in CloudFormation templates to improve diagnostics.
|
318 | *
|
319 | * @param type a string denoting the type of metadata
|
320 | * @param data the value of the metadata (can be a Token). If null/undefined, metadata will not be added.
|
321 | * @param fromFunction a function under which to restrict the metadata entry's stack trace (defaults to this.addMetadata)
|
322 | */
|
323 | addMetadata(type: string, data: any, fromFunction?: any): void;
|
324 | /**
|
325 | * DEPRECATED: Adds a { "info": <message> } metadata entry to this construct.
|
326 | * The toolkit will display the info message when apps are synthesized.
|
327 | * @param message The info message.
|
328 | * @deprecated use `Annotations.of(construct).addInfo()`
|
329 | */
|
330 | addInfo(message: string): void;
|
331 | /**
|
332 | * DEPRECATED: Adds a { "warning": <message> } metadata entry to this construct.
|
333 | * The toolkit will display the warning when an app is synthesized, or fail
|
334 | * if run in --strict mode.
|
335 | * @param message The warning message.
|
336 | * @deprecated use `Annotations.of(construct).addWarning()`
|
337 | */
|
338 | addWarning(message: string): void;
|
339 | /**
|
340 | * DEPRECATED: Adds an { "error": <message> } metadata entry to this construct.
|
341 | * The toolkit will fail synthesis when errors are reported.
|
342 | * @param message The error message.
|
343 | * @deprecated use `Annotations.of(construct).addError()`
|
344 | */
|
345 | addError(message: string): void;
|
346 | /**
|
347 | * DEPRECATED: Applies the aspect to this Constructs node
|
348 | *
|
349 | * @deprecated This API is going to be removed in the next major version of
|
350 | * the AWS CDK. Please use `Aspects.of(scope).add()` instead.
|
351 | */
|
352 | applyAspect(aspect: IAspect): void;
|
353 | /**
|
354 | * Add a validator to this construct Node
|
355 | */
|
356 | addValidation(validation: constructs.IValidation): void;
|
357 | /**
|
358 | * All parent scopes of this construct.
|
359 | *
|
360 | * @returns a list of parent scopes. The last element in the list will always
|
361 | * be the current construct and the first element will be the root of the
|
362 | * tree.
|
363 | */
|
364 | get scopes(): IConstruct[];
|
365 | /**
|
366 | * @returns The root of the construct tree.
|
367 | */
|
368 | get root(): IConstruct;
|
369 | /**
|
370 | * Returns true if this construct or the scopes in which it is defined are
|
371 | * locked.
|
372 | */
|
373 | get locked(): boolean;
|
374 | /**
|
375 | * Add an ordering dependency on another Construct.
|
376 | *
|
377 | * All constructs in the dependency's scope will be deployed before any
|
378 | * construct in this construct's scope.
|
379 | */
|
380 | addDependency(...dependencies: IDependable[]): void;
|
381 | /**
|
382 | * Return all dependencies registered on this node or any of its children
|
383 | */
|
384 | get dependencies(): Dependency[];
|
385 | /**
|
386 | * Remove the child with the given name, if present.
|
387 | *
|
388 | * @returns Whether a child with the given name was deleted.
|
389 | */
|
390 | tryRemoveChild(childName: string): boolean;
|
391 | }
|
392 | /**
|
393 | * An error returned during the validation phase.
|
394 | */
|
395 | export interface ValidationError {
|
396 | /**
|
397 | * The construct which emitted the error.
|
398 | */
|
399 | readonly source: Construct;
|
400 | /**
|
401 | * The error message.
|
402 | */
|
403 | readonly message: string;
|
404 | }
|
405 | /**
|
406 | * A single dependency
|
407 | */
|
408 | export interface Dependency {
|
409 | /**
|
410 | * Source the dependency
|
411 | */
|
412 | readonly source: IConstruct;
|
413 | /**
|
414 | * Target of the dependency
|
415 | */
|
416 | readonly target: IConstruct;
|
417 | }
|
418 |
|
\ | No newline at end of file |