Producer APIs
Production APIs can be used to create Creations:
produceBase
: generates Base optionsproduceBlock
: runs a Block productionproduceInput
: runs an InputproducePreset
: runs a Preset production
Each production API takes in up to two arguments:
- The construct to be produced
- An object with properties from the construct’s context as well as System contexts
produceBase
Given a Base, creates an options object by running its produce()
.
produceBase
takes in up to two argument:
base
(required): a Basesettings
(optional): any properties from a Base Context, except fortake
For example, given this Base that declares an optional value
option that defaults to "default"
, produceBase
can run its produce()
with any provided options:
options
Any number of options defined by the base.
For example, this Base is run with a name
option:
produceBlock
Given a Block, creates a Creation output by running its produce()
.
produceBlock
takes in up to two arguments:
block
(required): a Blocksettings
(required): at leastoptions
, as well as any other properties from a Block Context
For example, given this Block that produces the start of a README.md file, produceBlock
can run its produce()
with any provided options:
args
Any number of Args defined by the Block.
For example, given this Block with a prefix
Arg and a name
Option, both can be specified in produceBlock
:
created
Any Creations to simulate having been made from previously-produced Blocks.
options
Any number of options defined by the Block’s Base.
For example, this Block is run with no Args and one name
Option:
produceInput
Given an Input, runs its produce()
with any provided args.
produceInput
takes in up to two arguments:
input
(required): an Inputsettings
(required): at leastoptions
, as well as any other properties from an Input Context other thantake
For example, this Input production reads data from an existing data.json
file on disk:
args
For example, this Input production reads data from a JSON file on disk by path:
producePreset
Given a Preset, creates a Creation output by running each of its Blocks produce()
.
producePreset
takes in up to two arguments:
preset
(required): a Presetsettings
(required):options
(required): Base options to run withoptionsAugment
(optional): a function to augment options from the Base- (optional) any other properties from a Block Context
producePreset
returns a Promise for the Preset’s Creation
.
Both direct creations and indirect creations will be present.
For example, given this Preset that includes the block from produceBlock
, producePreset
can run its produce()
with any provided options:
options
Any number of options defined by the Preset’s Base.
For example, this Preset is run with a name
option:
optionsAugment
A function that takes in the explicitly provided options and returns any remaining options.
Preset options are generated through three steps:
- Any options provided by
producePreset
’s second parameter’soptions
- Calling the Preset’s Base’s
produce
method, if it exists - Calling to an optional
optionsAugment
method ofproducePreset
’s second parameter
In other words, optionsAugment
runs after the Preset’s Base’s produce
method, if it exists.
This can be useful to prompt for any options not determined by produce()
.
For example, this optionsAugment
uses a Node.js prompt to fill in a name
option if it isn’t provided:
System Overrides
The properties specific to System Contexts can be overridden in production APIs.
This can be useful if you’d like a production’s Inputs to run in a virtual environment or otherwise augment system interactions.
For example, this Block production adds an authorization header to all network requests: