class Node
Language | Type name |
---|---|
.NET | Constructs.Node |
Java | software.constructs.Node |
Python | constructs.Node |
TypeScript (source) | constructs » Node |
Represents the construct node in the scope tree.
Initializer
new Node(host: Construct, scope: IConstruct, id: string)
Parameters
- host
Construct
- scope
IConstruct
- id
string
Properties
Name | Type | Description |
---|---|---|
addr | string | Returns an opaque tree-unique address for this construct. |
children | IConstruct [] | All direct children of this construct. |
dependencies | Dependency [] | Return all dependencies registered on this node or any of its children. |
id | string | The id of this construct within the current scope. |
locked | boolean | Returns true if this construct or the scopes in which it is defined are locked. |
metadata | Metadata [] | An immutable array of metadata objects associated with this construct. |
path | string | The full, absolute path of this construct in the tree. |
root | IConstruct | Returns the root of the construct tree. |
scopes | IConstruct [] | All parent scopes of this construct. |
unique | string | A tree-global unique alphanumeric identifier for this construct. |
default | IConstruct | Returns the child construct that has the id Default or Resource" . |
scope? | IConstruct | Returns the scope in which this construct is defined. |
static PATH_SEP | string | Separator used to delimit construct path components. |
addr
Type:
string
Returns an opaque tree-unique address for this construct.
Addresses are 42 characters hexadecimal strings. They begin with "c8" followed by 40 lowercase hexadecimal characters (0-9a-f).
Addresses are calculated using a SHA-1 of the components of the construct path.
To enable refactorings of construct trees, constructs with the ID Default
will be excluded from the calculation. In those cases constructs in the
same tree may have the same addreess.
Example
c83a2846e506bcc5f10682b564084bca2d275709ee
children
Type:
IConstruct
[]
All direct children of this construct.
dependencies
Type:
Dependency
[]
Return all dependencies registered on this node or any of its children.
id
Type:
string
The id of this construct within the current scope.
This is a a scope-unique id. To obtain an app-unique id for this construct, use uniqueId
.
locked
Type:
boolean
Returns true if this construct or the scopes in which it is defined are locked.
metadata
Type:
Metadata
[]
An immutable array of metadata objects associated with this construct.
This can be used, for example, to implement support for deprecation notices, source mapping, etc.
path
Type:
string
The full, absolute path of this construct in the tree.
Components are separated by '/'.
root
Type:
IConstruct
Returns the root of the construct tree.
scopes
Type:
IConstruct
[]
All parent scopes of this construct.
uniqueId
⚠️ Deprecated: please avoid using this property and use addr
to form unique names.
This algorithm uses MD5, which is not FIPS-complient and also excludes the
identity of the root construct from the calculation.
Type:
string
A tree-global unique alphanumeric identifier for this construct.
Includes all components of the tree.
defaultChild?
Type:
IConstruct
(optional)
Returns the child construct that has the id Default
or Resource"
.
This is usually the construct that provides the bulk of the underlying functionality. Useful for modifications of the underlying construct that are not available at the higher levels. Override the defaultChild property.
This should only be used in the cases where the correct default child is not named 'Resource' or 'Default' as it should be.
If you set this to undefined, the default behavior of finding the child named 'Resource' or 'Default' will be used.
scope?
Type:
IConstruct
(optional)
Returns the scope in which this construct is defined.
The value is undefined
at the root of the construct scope tree.
static PATH_SEP
Type:
string
Separator used to delimit construct path components.
Methods
Name | Description |
---|---|
add | Add an ordering dependency on another Construct. |
add | Adds an { "error": |
add | Adds a { "info": |
add | Adds a metadata entry to this construct. |
add | Adds a validation to this construct. |
add | Adds a { "warning": |
apply | Applies the aspect to this Constructs node. |
find | Return this construct and all of its children in the given order. |
find | Return a direct child by id. |
prepare() | Invokes "prepare" on all constructs (depth-first, post-order) in the tree under node . |
set | This can be used to set contextual values. |
synthesize(options) | Synthesizes a CloudAssembly from a construct tree. |
try | Return a direct child by id, or undefined. |
try | Retrieves a value from tree context. |
try | Remove the child with the given name, if present. |
validate() | Validates tree (depth-first, pre-order) and returns the list of all errors. |
static of(construct) | Returns the node associated with a construct. |
Dependency(...dependencies)
addpublic addDependency(...dependencies: IConstruct[]): void
Parameters
- dependencies
IConstruct
Add an ordering dependency on another Construct.
All constructs in the dependency's scope will be deployed before any construct in this construct's scope.
Error(message)
addpublic addError(message: string): void
Parameters
- message
string
— The error message.
Adds an { "error":
The toolkit will fail synthesis when errors are reported.
Info(message)
addpublic addInfo(message: string): void
Parameters
- message
string
— The info message.
Adds a { "info":
The toolkit will display the info message when apps are synthesized.
Metadata(type, data, fromFunction?)
addpublic addMetadata(type: string, data: any, fromFunction?: any): void
Parameters
- type
string
— a string denoting the type of metadata. - data
any
— the value of the metadata (can be a Token). - fromFunction
any
— a function under which to restrict the metadata entry's stack trace (defaults to this.addMetadata).
Adds a metadata entry to this construct.
Entries are arbitrary values and will also include a stack trace to allow tracing back to the code location for when the entry was added. It can be used, for example, to include source mapping in CloudFormation templates to improve diagnostics.
Validation(validation)
addpublic addValidation(validation: IValidation): void
Parameters
- validation
IValidation
Adds a validation to this construct.
When node.validate()
is called, the validate()
method will be called on
all validations and all errors will be returned.
Warning(message)
addpublic addWarning(message: string): void
Parameters
- message
string
— The warning message.
Adds a { "warning":
The toolkit will display the warning when an app is synthesized, or fail if run in --strict mode.
Aspect(aspect)
applypublic applyAspect(aspect: IAspect): void
Parameters
- aspect
IAspect
Applies the aspect to this Constructs node.
All(order?)
findpublic findAll(order?: ConstructOrder): IConstruct[]
Parameters
- order
Construct
Order
Returns
Return this construct and all of its children in the given order.
Child(id)
findpublic findChild(id: string): IConstruct
Parameters
- id
string
— Identifier of direct child.
Returns
Return a direct child by id.
Throws an error if the child is not found.
prepare()
public prepare(): void
Invokes "prepare" on all constructs (depth-first, post-order) in the tree under node
.
Context(key, value)
setpublic setContext(key: string, value: any): void
Parameters
- key
string
— The context key. - value
any
— The context value.
This can be used to set contextual values.
Context must be set before any children are added, since children may consult context info during construction. If the key already exists, it will be overridden.
synthesize(options)
public synthesize(options: SynthesisOptions): void
Parameters
- options
Synthesis
— Synthesis options.Options
Synthesizes a CloudAssembly from a construct tree.
FindChild(id)
trypublic tryFindChild(id: string): IConstruct
Parameters
- id
string
— Identifier of direct child.
Returns
Return a direct child by id, or undefined.
GetContext(key)
trypublic tryGetContext(key: string): any
Parameters
- key
string
— The context key.
Returns
any
Retrieves a value from tree context.
Context is usually initialized at the root, but can be overridden at any point in the tree.
RemoveChild(childName)
trypublic tryRemoveChild(childName: string): boolean
Parameters
- childName
string
Returns
boolean
Remove the child with the given name, if present.
validate()
public validate(): ValidationError[]
Returns
Validates tree (depth-first, pre-order) and returns the list of all errors.
An empty list indicates that there are no errors.
static of(construct)
public static of(construct: IConstruct): Node
Parameters
- construct
IConstruct
— the construct.
Returns
Returns the node associated with a construct.