Skip to main content

API Reference

Classes

Node

The internal node of a construct.

Methods

NameDescription
addConnection
Adds a connection between two constructs.
addDependency
Add an ordering dependency on another construct.
addMetadata
Adds a metadata entry to this construct.
addValidation
Adds a validation to this construct.
findAll
Return this construct and all of its children in the given order.
findChild
Return a direct child by id.
getContext
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
This can be used to set contextual values.
tryFindChild
Return a direct child by id, or undefined.
tryGetContext
Retrieves a value from tree context.
tryRemoveChild
Remove the child with the given name, if present.
validate
Validates this construct.

addConnection
addConnection(props: AddConnectionProps): void

Adds a connection between two constructs.

A connection is a piece of metadata describing how one construct is related to another construct.

propsRequired

addDependency
addDependency(...deps: Array<IDependable>): void

Add an ordering dependency on another construct.

An IDependable

depsRequired
  • Type: constructs.IDependable

addMetadata
addMetadata(type: str, data: any, options?: MetadataOptions): void

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.

typeRequired
  • Type: str

a string denoting the type of metadata.


dataRequired
  • Type: any

the value of the metadata (can be a Token).

If null/undefined, metadata will not be added.


optionsOptional
  • Type: constructs.MetadataOptions

options.


addValidation
addValidation(validation: IValidation): void

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.

validationRequired
  • Type: constructs.IValidation

The validation object.


findAll
findAll(order?: ConstructOrder): MutArray<IConstruct>

Return this construct and all of its children in the given order.

orderOptional
  • Type: constructs.ConstructOrder

findChild
findChild(): IConstruct

Return a direct child by id.

Throws an error if the child is not found.

getContext
getContext(key: str): 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.

keyRequired
  • Type: str

The context key.


lock
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
setContext(key: str, value: any): void

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.

keyRequired
  • Type: str

The context key.


valueRequired
  • Type: any

The context value.


tryFindChild
tryFindChild(): IConstruct?

Return a direct child by id, or undefined.

tryGetContext
tryGetContext(key: str): any

Retrieves a value from tree context.

Context is usually initialized at the root, but can be overridden at any point in the tree.

keyRequired
  • Type: str

The context key.


tryRemoveChild
tryRemoveChild(childName: str): bool

Remove the child with the given name, if present.

childNameRequired
  • Type: str

validate
validate(): MutArray<str>

Validates this construct.

Invokes the validate() method on all validations added through addValidation().

Properties

NameTypeDescription
addr
strReturns an opaque tree-unique address for this construct.
app
IApp
Returns the root of the construct tree (the cloud.App object).
children
MutArray<constructs.IConstruct>All direct children of this construct.
dependencies
MutArray<constructs.IConstruct>Return all dependencies registered on this node (non-recursive).
id
strThe id of this construct within the current scope.
locked
boolReturns true if this construct or the scopes in which it is defined are locked.
metadata
MutArray<constructs.MetadataEntry>An immutable array of metadata objects associated with this construct.
path
strThe full, absolute path of this construct in the tree.
root
constructs.IConstructReturns the root of the construct tree (the cloud.App object).
scopes
MutArray<constructs.IConstruct>All parent scopes of this construct.
scope
constructs.IConstructReturns the scope in which this construct is defined.
color
strThe color of the construct for display purposes.
defaultChild
constructs.IConstructReturns the child construct that has the id Default or Resource".
description
strDescription of the construct for display purposes.
expanded
boolWhether the node is expanded or collapsed by default in the UI.
hidden
boolWhether the construct should be hidden by default in tree visualizations.
icon
strThe icon of the construct for display purposes.
sourceModule
strThe source file or library where the construct was defined.
title
strTitle of the construct for display purposes.

addrRequired
addr: str;
  • Type: str

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
appRequired
app: IApp;

Returns the root of the construct tree (the cloud.App object).

Similar to root.


childrenRequired
children: MutArray<IConstruct>;
  • Type: MutArray<constructs.IConstruct>

All direct children of this construct.


dependenciesRequired
dependencies: MutArray<IConstruct>;
  • Type: MutArray<constructs.IConstruct>

Return all dependencies registered on this node (non-recursive).


idRequired
id: str;
  • Type: str

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.


lockedRequired
locked: bool;
  • Type: bool

Returns true if this construct or the scopes in which it is defined are locked.


metadataRequired
metadata: MutArray<MetadataEntry>;
  • Type: MutArray<constructs.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.


pathRequired
path: str;
  • Type: str

The full, absolute path of this construct in the tree.

Components are separated by '/'.


rootRequired
root: IConstruct;
  • Type: constructs.IConstruct

Returns the root of the construct tree (the cloud.App object).

Similar to app.


scopesRequired
scopes: MutArray<IConstruct>;
  • Type: MutArray<constructs.IConstruct>

All parent scopes of this construct.


scopeOptional
scope: IConstruct;
  • Type: constructs.IConstruct

Returns the scope in which this construct is defined.

The value is undefined at the root of the construct scope tree.


colorOptional
color: str;
  • Type: str

The color of the construct for display purposes.

Supported colors are:

  • orange
  • sky
  • emerald
  • lime
  • pink
  • amber
  • cyan
  • purple
  • red
  • violet
  • slate

defaultChildOptional
defaultChild: IConstruct;
  • Type: constructs.IConstruct

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.


descriptionOptional
description: str;
  • Type: str

Description of the construct for display purposes.


expandedOptional
expanded: bool;
  • Type: bool
  • Default: false

Whether the node is expanded or collapsed by default in the UI.

By default, nodes are collapsed. Set this to true if you want the node to be expanded by default.


hiddenOptional
hidden: bool;
  • Type: bool

Whether the construct should be hidden by default in tree visualizations.


iconOptional
icon: str;
  • Type: str

The icon of the construct for display purposes.

Supported icons are from Heroicons:


sourceModuleOptional
sourceModule: str;
  • Type: str

The source file or library where the construct was defined.


titleOptional
title: str;
  • Type: str

Title of the construct for display purposes.


Structs

AddConnectionProps

Props for Node.addConnection.

Initializer

let AddConnectionProps = AddConnectionProps{ ... };

Properties

NameTypeDescription
name
strA name for the connection.
target
constructs.IConstructThe target of the connection.
source
constructs.IConstructThe source of the connection.
sourceOp
strAn operation that the source construct supports.
targetOp
strAn operation that the target construct supports.

nameRequired
name: str;
  • Type: str

A name for the connection.


targetRequired
target: IConstruct;
  • Type: constructs.IConstruct

The target of the connection.


sourceOptional
source: IConstruct;
  • Type: constructs.IConstruct
  • Default: this

The source of the connection.


sourceOpOptional
sourceOp: str;
  • Type: str
  • Default: no operation

An operation that the source construct supports.


targetOpOptional
targetOp: str;
  • Type: str
  • Default: no operation

An operation that the target construct supports.


Protocols

IApp

  • Extends: constructs.IConstruct

  • Implemented By: App, IApp

Represents a Wing application.

Methods

NameDescription
makeId
Generate a unique ID for the given scope and prefix.

makeId
makeId(prefix?: str): str

Generate a unique ID for the given scope and prefix.

The newly generated ID is guaranteed to be unique within the given scope. It will have the form '{prefix}{n}', where '{prefix}' is the given prefix and '{n}' is an ascending sequence of integers starting from '0'.

prefixOptional
  • Type: str

prepended to the unique identifier.


Properties

NameTypeDescription
node
constructs.NodeThe tree node.
entrypointDir
strThe directory of the entrypoint of the current Wing application.
isTestEnvironment
booltrue if this is a testing environment.
parameters
ParameterRegistrar
The application's parameter registrar.
workdir
strThe .wing directory into which you can emit intermediate artifacts during preflight.

nodeRequired
node: Node;
  • Type: constructs.Node

The tree node.


entrypointDirRequired
entrypointDir: str;
  • Type: str

The directory of the entrypoint of the current Wing application.


isTestEnvironmentRequired
isTestEnvironment: bool;
  • Type: bool

true if this is a testing environment.


parametersRequired
parameters: ParameterRegistrar;

The application's parameter registrar.


workdirRequired
workdir: str;
  • Type: str

The .wing directory into which you can emit intermediate artifacts during preflight.