constructs.Node

class Node

LanguageType name
.NETConstructs.Node
Javasoftware.constructs.Node
Pythonconstructs.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

NameTypeDescription
addrstringReturns an opaque tree-unique address for this construct.
childrenIConstruct[]All direct children of this construct.
dependenciesIConstruct[]Return all dependencies registered on this node (non-recursive).
idstringThe id of this construct within the current scope.
lockedbooleanReturns true if this construct or the scopes in which it is defined are locked.
metadataMetadataEntry[]An immutable array of metadata objects associated with this construct.
pathstringThe full, absolute path of this construct in the tree.
rootIConstructReturns the root of the construct tree.
scopesIConstruct[]All parent scopes of this construct.
defaultChild?IConstructReturns the child construct that has the id Default or Resource".
scope?IConstructReturns the scope in which this construct is defined.
static PATH_SEPstringSeparator 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: 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 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: MetadataEntry[]

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

NameDescription
addDependency(...deps)Add an ordering dependency on another construct.
addMetadata(type, data, options?)Adds a metadata entry to this construct.
addValidation(validation)Adds a validation to this construct.
findAll(order?)Return this construct and all of its children in the given order.
findChild(id)Return a direct child by id.
getContext(key)Retrieves a value from tree context if present. Otherwise, would throw an error.
lock()Locks this construct from allowing more children to be added.
setContext(key, value)This can be used to set contextual values.
tryFindChild(id)Return a direct child by id, or undefined.
tryGetContext(key)Retrieves a value from tree context.
tryRemoveChild(childName)🔹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 MetadataOptions — 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.


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 ConstructOrder

Returns

  • IConstruct[]

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

  • IConstruct

Return a direct child by id.

Throws an error if the child is not found.


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

  • IConstruct

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

  • Node

Returns the node associated with a construct.