Variables
Variables are placeholders for arbitrary data that can be inserted into Warp jobs and conditions. To make creating jobs easier, variables can be specified and input into job or query templates. After creating variables, you can add them to messages using their reference value in the form of $warp.variable.variable-name
.
You can use variables with templates to create complex reusable jobs.
Variables created in the Warp app are stored in your browser and are not written to the blockchain until they are inserted into templates.
VariableKind
The following are the different variable input types that can be used.
Static variables
Static variables are the simplest form of variable and are created with a value. Static variable values can be updated in loops using an UpdateFn
.
Query variables
Query variables allow you to select a value from the response of a specified query. Queries require a query message and a selector, which is used to select the correct portion of the query response. When looping, query variables can be updated or specified to be reinitialized.
Update functions and loops
Variables can be updated using an update function, which can change the value of the variable upon the success or failure of a job. By specifying whether a variable should update after completion, jobs can be looped. You can specify how a value should be updated upon success or failure, and you can use an update function to update the value. Update functions can include a NumValue
and an operator to update the value. A NumValue
can also reference an expression or variable such as a query, allowing for further looping and update capability. Update functions and loops can only be applied if recurring
is set to true
in the job message.
Reinitialize
Expression and Query variables contain a reinitialize
boolean, which specifies whether the query or external variable should be fetched again. If this boolean is set to true
, the job will be run again after completion (on success or failure) and the data will be fetched again upon each subsequent job. Variables cannot be updated using an UpdateFn
if the reinitialize
boolean is set to true
and if recurring
is set to true
in the job message.
Nesting variables
Variables can be nested or referenced, allowing a reference of a result of one variable to appear in a different variable. However, you can only nest or reference previous variables in a sequence. For example, in the following code, { vars: [var0, var1, var2, var3,] }
, var2
can only contain the variables that came before it, and cannot reference var3
.
External Variables
External variables are fetched from external sources such as APIs. They require an external reference input, which includes a URL, a method (Get
, Post
, Push
, Pass
, Delete
), a header, a body, and a JSON selector. External variables can be updated or specified to be reinitialized.