class Node
Language | Type name |
---|---|
![]() | Constructs.Node |
![]() | software.constructs.Node |
![]() | constructs.Node |
![]() | 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 | IConstruct [] | Return all dependencies registered on this node (non-recursive). |
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. |
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 refactoring 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 address.
Example
c83a2846e506bcc5f10682b564084bca2d275709ee
children
Type:
IConstruct
[]
All direct children of this construct.
dependencies
Type:
IConstruct
[]
Return all dependencies registered on this node (non-recursive).
id
Type:
string
The id of this construct within the current scope.
This is a scope-unique id. To obtain an app-unique id for this construct, use addr
.
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.
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 a metadata entry to this construct. |
add | Adds a validation to this construct. |
find | Return this construct and all of its children in the given order. |
find | Return a direct child by id. |
get | Retrieves the all context of a node from tree context. |
get | Retrieves a value from tree context if present. Otherwise, would throw an error. |
lock() | Locks this construct from allowing more children to be added. |
set | This can be used to set contextual values. |
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 this construct. |
static of(construct) | Returns the node associated with a construct. |
addDependency(...deps)
public addDependency(...deps: IDependable[]): void
Parameters
- deps
IDependable
Add an ordering dependency on another construct.
An IDependable
addMetadata(type, data, options?)
public addMetadata(type: string, data: any, options?: MetadataOptions): void
Parameters
- type
string
— a string denoting the type of metadata. - data
any
— the value of the metadata (can be a Token). - options
Metadata
— options.Options
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.
Note that construct metadata is not the same as CloudFormation resource metadata and is never written to the CloudFormation template.
The metadata entries are written to the Cloud Assembly Manifest if the treeMetadata
property is specified in the props of the App that contains this Construct.
addValidation(validation)
public addValidation(validation: IValidation): void
Parameters
- validation
IValidation
— The validation object.
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.
findAll(order?)
public findAll(order?: ConstructOrder): IConstruct[]
Parameters
- order
Construct
Order
Returns
Return this construct and all of its children in the given order.
findChild(id)
public 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.
getAllContext(defaults?)
public getAllContext(defaults?: json): any
Parameters
- defaults
json
— Any keys to override the retrieved context.
Returns
any
Retrieves the all context of a node from tree context.
Context is usually initialized at the root, but can be overridden at any point in the tree.
getContext(key)
public getContext(key: string): any
Parameters
- key
string
— The context key.
Returns
any
Retrieves a value from tree context if present. Otherwise, would throw an error.
Context is usually initialized at the root, but can be overridden at any point in the tree.
lock()
public lock(): void
Locks this construct from allowing more children to be added.
After this call, no more children can be added to this construct or to any children.
setContext(key, value)
public 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.
tryFindChild(id)
public tryFindChild(id: string): IConstruct
Parameters
- id
string
— Identifier of direct child.
Returns
Return a direct child by id, or undefined.
tryGetContext(key)
public 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.
tryRemoveChild(childName)
public tryRemoveChild(childName: string): boolean
Parameters
- childName
string
Returns
boolean
Remove the child with the given name, if present.
validate()
public validate(): string[]
Returns
string[]
Validates this construct.
Invokes the validate()
method on all validations added through
addValidation()
.
static of(construct)
public static of(construct: IConstruct): Node
⚠️ Deprecated: use construct.node
instead
Parameters
- construct
IConstruct
— the construct.
Returns
Returns the node associated with a construct.