API Reference
Resources
Container
- Implements: ISimulatorResource
Represents a container running in the Wing Simulator.
Initializers
bring sim;
new sim.Container(props: ContainerProps);
| Name | Type | Description |
|---|---|---|
| | No description. |
propsRequired
- Type: ContainerProps
Methods
Preflight Methods
| Name | Description |
|---|---|
| Convert this resource to a resource schema for the simulator. |
toSimulator
toSimulator(): ToSimulatorOutput
Convert this resource to a resource schema for the simulator.
Static Functions
| Name | Description |
|---|---|
| A hook called by the Wing compiler once for each inflight host that needs to use this type inflight. |
| Generates an asynchronous JavaScript statement which can be used to create an inflight client for a resource. |
onLiftType
bring sim;
sim.Container.onLiftType(host: IInflightHost, ops: MutArray<str>);
A hook called by the Wing compiler once for each inflight host that needs to use this type inflight.
The list of requested inflight methods
needed by the inflight host are given by ops.
This method is commonly used for adding permissions, environment variables, or other capabilities to the inflight host.
hostRequired
- Type: IInflightHost
opsRequired
- Type: MutArray<str>
toInflight
bring sim;
sim.Container.toInflight(obj: IResource);
Generates an asynchronous JavaScript statement which can be used to create an inflight client for a resource.
NOTE: This statement must be executed within an async context.
objRequired
- Type: IResource
Properties
| Name | Type | Description |
|---|---|---|
| constructs.Node | The tree node. |
| str | A token that resolves to the host port of this container. |
nodeRequired
node: Node;
- Type: constructs.Node
The tree node.
hostPortOptional
hostPort: str;
- Type: str
A token that resolves to the host port of this container.
Policy
- Implements: ISimulatorResource
Implementation of sim.Policy.
Initializers
bring sim;
new sim.Policy(props: PolicyProps);
| Name | Type | Description |
|---|---|---|
| | No description. |
propsRequired
- Type: PolicyProps
Methods
Preflight Methods
| Name | Description |
|---|---|
| Adds a statement to the policy. |
| Convert this resource to a resource schema for the simulator. |
addStatement
addStatement(resource: IResource, op: str): void
Adds a statement to the policy.
resourceRequired
- Type: IResource
opRequired
- Type: str
toSimulator
toSimulator(): ToSimulatorOutput
Convert this resource to a resource schema for the simulator.
Static Functions
| Name | Description |
|---|---|
| A hook called by the Wing compiler once for each inflight host that needs to use this type inflight. |
| Generates an asynchronous JavaScript statement which can be used to create an inflight client for a resource. |
onLiftType
bring sim;
sim.Policy.onLiftType(host: IInflightHost, ops: MutArray<str>);
A hook called by the Wing compiler once for each inflight host that needs to use this type inflight.
The list of requested inflight methods
needed by the inflight host are given by ops.
This method is commonly used for adding permissions, environment variables, or other capabilities to the inflight host.
hostRequired
- Type: IInflightHost
opsRequired
- Type: MutArray<str>
toInflight
bring sim;
sim.Policy.toInflight(obj: IResource);
Generates an asynchronous JavaScript statement which can be used to create an inflight client for a resource.
NOTE: This statement must be executed within an async context.
objRequired
- Type: IResource
Properties
| Name | Type | Description |
|---|---|---|
| constructs.Node | The tree node. |
nodeRequired
node: Node;
- Type: constructs.Node
The tree node.
Resource
- Implements: IResource, ISimulatorResource, IInflightHost, ISimulatorInflightHost
A backend for a simulated resource.
Initializers
bring sim;
new sim.Resource(factory: IResourceFactory);
| Name | Type | Description |
|---|---|---|
| | No description. |
factoryRequired
- Type: IResourceFactory
Methods
Preflight Methods
| Name | Description |
|---|---|
| Add an environment variable to make available to the inflight code. |
| Add a simulated permission to this inflight host. |
| Obtain a token that can be used to reference an attribute of this resource that is only resolved once the resource is started in the simulator. |
| Convert this resource to a resource schema for the simulator. |
Inflight Methods
| Name | Description |
|---|---|
| Call a method on the resource. |
addEnvironment
addEnvironment(name: str, value: str): void
Add an environment variable to make available to the inflight code.
nameRequired
- Type: str
valueRequired
- Type: str
addPermission
addPermission(resource: IResource, op: str): void
Add a simulated permission to this inflight host.
resourceRequired
- Type: IResource
opRequired
- Type: str
createToken
createToken(name: str): str
Obtain a token that can be used to reference an attribute of this resource that is only resolved once the resource is started in the simulator.
If the token is used in inflight code or in the configuration of a simulated resource (e.g. as an environment variable), the relevant resource will automatically take a dependency on the resource the token belongs to.
nameRequired
- Type: str
The name of the token.
toSimulator
toSimulator(): ToSimulatorOutput
Convert this resource to a resource schema for the simulator.
call
inflight call(method: str, args?: MutArray<Json>): Json
Call a method on the resource.
methodRequired
- Type: str
argsOptional
- Type: MutArray<Json>
Static Functions
| Name | Description |
|---|---|
| A hook called by the Wing compiler once for each inflight host that needs to use this type inflight. |
| Generates an asynchronous JavaScript statement which can be used to create an inflight client for a resource. |
onLiftType
bring sim;
sim.Resource.onLiftType(host: IInflightHost, ops: MutArray<str>);
A hook called by the Wing compiler once for each inflight host that needs to use this type inflight.
The list of requested inflight methods
needed by the inflight host are given by ops.
This method is commonly used for adding permissions, environment variables, or other capabilities to the inflight host.
hostRequired
- Type: IInflightHost
opsRequired
- Type: MutArray<str>
toInflight
bring sim;
sim.Resource.toInflight(obj: IResource);
Generates an asynchronous JavaScript statement which can be used to create an inflight client for a resource.
NOTE: This statement must be executed within an async context.
objRequired
- Type: IResource
Properties
| Name | Type | Description |
|---|---|---|
| constructs.Node | The tree node. |
nodeRequired
node: Node;
- Type: constructs.Node
The tree node.
State
- Implements: ISimulatorResource
Key/value in-memory state for the simulator.
Use the preflight method token(key) to obtain a token that can be used to reference the value
of the state at runtime.
During deployment (i.e. cloud.OnDeploy or cloud.Service startup), you must call the inflight
method set(key, value) to set the runtime value. The value will be available at runtime through
the inflight method get(key) (or resolved as a token).
See tests for examples.
Initializers
bring sim;
new sim.State();
| Name | Type | Description |
|---|
Methods
Preflight Methods
| Name | Description |
|---|---|
| Returns a token that can be used to retrieve the value of the state after the simulation has run. |
| Convert this resource to a resource schema for the simulator. |
Inflight Methods
| Name | Description |
|---|---|
| Gets the runtime state of this object. |
| Sets the state of runtime a runtime object. |
| Checks if runtime state exists for this object and returns it's value. |
token
token(key: str): str
Returns a token that can be used to retrieve the value of the state after the simulation has run.
keyRequired
- Type: str
The object key retrieved through the inflight state.get().
toSimulator
toSimulator(): ToSimulatorOutput
Convert this resource to a resource schema for the simulator.
get
inflight get(key: str): Json
Gets the runtime state of this object.
Throws if there is no value for the given key.
keyRequired
- Type: str
The object's key.
set
inflight set(key: str, value: Json): void
Sets the state of runtime a runtime object.
keyRequired
- Type: str
The object's key.
valueRequired
- Type: Json
The object's value.
tryGet
inflight tryGet(key: str): Json?
Checks if runtime state exists for this object and returns it's value.
If no value exists,
returns nil.
keyRequired
- Type: str
The object's key.
Static Functions
| Name | Description |
|---|---|
| A hook called by the Wing compiler once for each inflight host that needs to use this type inflight. |
| Generates an asynchronous JavaScript statement which can be used to create an inflight client for a resource. |
onLiftType
bring sim;
sim.State.onLiftType(host: IInflightHost, ops: MutArray<str>);
A hook called by the Wing compiler once for each inflight host that needs to use this type inflight.
The list of requested inflight methods
needed by the inflight host are given by ops.
This method is commonly used for adding permissions, environment variables, or other capabilities to the inflight host.
hostRequired
- Type: IInflightHost
opsRequired
- Type: MutArray<str>
toInflight
bring sim;
sim.State.toInflight(obj: IResource);
Generates an asynchronous JavaScript statement which can be used to create an inflight client for a resource.
NOTE: This statement must be executed within an async context.
objRequired
- Type: IResource
Properties
| Name | Type | Description |
|---|---|---|
| constructs.Node | The tree node. |
nodeRequired
node: Node;
- Type: constructs.Node
The tree node.
Structs
ContainerProps
Initialization properties for sim.Container.
Initializer
bring sim;
let ContainerProps = sim.ContainerProps{ ... };
Properties
| Name | Type | Description |
|---|---|---|
| str | A name of a public Docker image to pull and run or a path to a local directory with a Dockerfile. |
| str | A name for the container. |
| MutArray<str> | Container arguments. |
| num | Internal container port to expose. |
| str | Container entrypoint. |
| MutMap<str> | Environment variables to set in the container. |
| str | Docker network to use for the container - such as 'host', 'bridge', etc. |
| str | An explicit source hash that represents the container source. |
| str | A glob of local files to consider as input sources for the container, relative to the build context directory. |
| MutArray<str> | Volume mount points. |
imageRequired
image: str;
- Type: str
A name of a public Docker image to pull and run or a path to a local directory with a Dockerfile.
nameRequired
name: str;
- Type: str
A name for the container.
argsOptional
args: MutArray<str>;
- Type: MutArray<str>
- Default: []
Container arguments.
containerPortOptional
containerPort: num;
- Type: num
- Default: no port exposed
Internal container port to expose.
entrypointOptional
entrypoint: str;
- Type: str
- Default: default image entrypoint
Container entrypoint.
envOptional
env: MutMap<str>;
- Type: MutMap<str>
- Default: {}
Environment variables to set in the container.
networkOptional
network: str;
- Type: str
- Default: default docker network
Docker network to use for the container - such as 'host', 'bridge', etc.
Example
'host'
sourceHashOptional
sourceHash: str;
- Type: str
- Default: calculated based on the source files
An explicit source hash that represents the container source.
if not set, and sourcePattern
is set, the hash will be calculated based on the content of the source files.
sourcePatternOptional
sourcePattern: str;
- Type: str
- Default: all files
A glob of local files to consider as input sources for the container, relative to the build context directory.
volumesOptional
volumes: MutArray<str>;
- Type: MutArray<str>
- Default: []
Volume mount points.
Example
['/host:/container']
PolicyProps
Options for sim.Policy.
Initializer
bring sim;
let PolicyProps = sim.PolicyProps{ ... };
Properties
| Name | Type | Description |
|---|---|---|
| | The resource to which the policy is attached. |
principalRequired
principal: IResource;
- Type: IResource
The resource to which the policy is attached.
Protocols
IResource
- Implemented By: IResource
Contract that a resource backend must implement.
Methods
| Name | Description |
|---|---|
| Runs when the resource is stopped. |
onStop
onStop(): void
Runs when the resource is stopped.
IResourceContext
- Implemented By: IResourceContext
Context for implementing a simulator resource.
Methods
| Name | Description |
|---|---|
| Log a message at the current point in time. |
| Resolves a token value. |
| The directory for the resource's state. |
log
inflight log(message: str, level?: LogLevel): void
Log a message at the current point in time.
Defaults to info level.
messageRequired
- Type: str
The message to log.
levelOptional
- Type: LogLevel
The severity of the message.
resolveToken
inflight resolveToken(name: str, value: str): void
Resolves a token value.
All tokens must be resolved during the constructor of the resource.
nameRequired
- Type: str
The name of the token.
valueRequired
- Type: str
The value of the token.
statedir
statedir(): str
The directory for the resource's state.
IResourceFactory
-
Extends: IInflight
-
Implemented By: IResourceFactory
Inflight client: @winglang/sdk.sim.IResourceFactoryClient
A resource with an inflight "handle" method that can be passed to the sim.Resource constructor.
IResourceFactoryClient
- Implemented By: IResourceFactoryClient
A resource with an inflight "handle" method that can be passed to the sim.Resource constructor.
Methods
| Name | Description |
|---|---|
| Function that will be called to initialize the simulator resource. |
handle
inflight handle(context: IResourceContext): IResource?
Function that will be called to initialize the simulator resource.
To implement a shutdown sequence, return an object that implements the IResource inflight interface with an onStop() method.
contextRequired
- Type: IResourceContext
ISimulatorInflightHost
-
Extends: IInflightHost
-
Implemented By: Resource, ISimulatorInflightHost
Interfaces shared by all preflight classes that host inflight code.
Methods
| Name | Description |
|---|---|
| Add a simulated permission to this inflight host. |
addPermission
addPermission(resource: IResource, op: str): void
Add a simulated permission to this inflight host.
resourceRequired
- Type: IResource
The resource to add.
opRequired
- Type: str
The action to add.
Properties
| Name | Type | Description |
|---|---|---|
| constructs.Node | The tree node. |
nodeRequired
node: Node;
- Type: constructs.Node
The tree node.
ISimulatorResource
Interfaces shared by all preflight classes targeting the simulator.
Methods
| Name | Description |
|---|---|
| Convert this resource to a resource schema for the simulator. |
toSimulator
toSimulator(): ToSimulatorOutput
Convert this resource to a resource schema for the simulator.
Properties
| Name | Type | Description |
|---|---|---|
| constructs.Node | The tree node. |
nodeRequired
node: Node;
- Type: constructs.Node
The tree node.