Process
You can go for even more concise syntax with Process
class.
Instantiate
const p = ao.p(pid)
or
const { p, pid } = await ao.deploy({ data, tags, src, fills })
msg
The first argument is Action
, the second argument is Tags
, and the third argument is the rest of the options.
const { mid, res, out, err } = await p.msg(
"Action",
{ Tag1: "value1", Tag2: "value2" },
{ get: true, check: { TagA: "valueA" }, jwk }
)
The default third argument is { get: true }
to return the JSON decoded Data
.
const { mid, out } = await p.msg("Action", { Tag1: "value1", Tag2: "value2" })
The third parameter defaults to get
if it's not an object.
const { mid, out } = await p.msg("Action", { Tag1: "value1" }, "TagA")
is equivalent to
const { mid, out } = await p.msg("Action", { Tag1: "value1" }, "TagA")
You can omit the second argument if there is no tag to pass to.
const { mid, out } = await p.msg("Action", { check: "success!" }}
m
You can only get out
with m
. This is the most extreme form.
const out = await p.m("Action", { Tag1: "value1", Tag2: "value2" })
This is a quite common pattern during testing. Doing the same with aoconnect
requires an enormous amount of code, especially if it involves async/await receive()
.
const { p } = await ao.deploy({ tags, src_data, fills })
const out = await p.m("Action", { Tag1: "value1", Tag2: "value2" }) // get Data
assert.equal(out, EXPECTED_JSON)
dry
const { mid, out } = await p.dry("Action", { Tag1: "value1", Tag2: "value2" })
d
const out = await p.d("Action", { Tag1: "value1", Tag2: "value2" })
res
const { err, res, out } = await p.res({ mid, check, get })
r
const out = await p.r({ mid, check, get })
v
v
is a shortcut for var to get a Lua variable with dryrun
.
const { p } = await ao.deploy({
src_data: `Table = { String = "Hello", Array = { "str", 3, true } }`,
})
const table = await p.v("Table") // { String: "Hello", Array: [ "str", 3, true ] }
To disable the auto JSON conversion and enable pretty print, use the 2nd and the 3rd arguments.
const table = await p.v("Table", false, true)