wao 0.25.3 → 0.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/esm/hb.js CHANGED
@@ -4,6 +4,8 @@ import { toAddr, buildTags } from "./utils.js"
4
4
  import { send as _send, createRequest } from "./signer.js"
5
5
  import { resolve } from "path"
6
6
  import { readFileSync } from "fs"
7
+ import hyper_aos from "./lua/hyper-aos.js"
8
+ import aos_wamr from "./lua/aos_wamr.js"
7
9
 
8
10
  const seed = num => {
9
11
  const array = new Uint8Array(num)
@@ -29,7 +31,6 @@ class HB {
29
31
  )
30
32
  },
31
33
  }
32
-
33
34
  this.dev.json = {
34
35
  commit: async args => {
35
36
  return await this.post({ path: "/~json@1.0/commit", ...args })
@@ -97,18 +98,14 @@ class HB {
97
98
  }
98
99
 
99
100
  async getImage() {
100
- const wasm = readFileSync(
101
- resolve(import.meta.dirname, "./lua/aos2-wamr.wasm")
102
- )
101
+ const wasm = Buffer.from(aos_wamr, "base64")
103
102
  const id = await this.cacheModule(wasm, "application/wasm")
104
103
  this.image ??= id
105
104
  return id
106
105
  }
107
106
 
108
107
  async getLua() {
109
- const lua = readFileSync(
110
- resolve(import.meta.dirname, "./lua/hyper-aos.lua")
111
- )
108
+ const lua = Buffer.from(hyper_aos, "base64")
112
109
  const id = await this.cacheModule(lua, "application/lua")
113
110
  this.lua ??= id
114
111
  return id
@@ -281,6 +278,7 @@ class HB {
281
278
  Type: "Process",
282
279
  image,
283
280
  "execution-device": "stack@1.0",
281
+ "push-device": "push@1.0",
284
282
  "device-stack": [
285
283
  "wasi@1.0",
286
284
  "json-iface@1.0",
@@ -315,6 +313,7 @@ class HB {
315
313
  Type: "Process",
316
314
  module: lua,
317
315
  "execution-device": "lua@5.3a",
316
+ "push-device": "push@1.0",
318
317
  "patch-from": "/results/outbox",
319
318
  })
320
319
  const pid = res.headers.process
@@ -357,6 +356,10 @@ class HB {
357
356
  if (path && !/^\//.test(path)) path = "/" + path
358
357
  return await this.getJSON({ path: `/${pid}/now${path}` })
359
358
  }
359
+ async slot({ pid, path = "" }) {
360
+ if (path && !/^\//.test(path)) path = "/" + path
361
+ return await this.getJSON({ path: `/${pid}/slot${path}` })
362
+ }
360
363
 
361
364
  async messages({ pid, from, to, limit } = {}) {
362
365
  let params = `target=${pid}`
@@ -376,8 +379,7 @@ class HB {
376
379
  }
377
380
 
378
381
  async spawnLegacy({ module, tags = {}, data } = {}) {
379
- tags = mergeLeft(tags, {
380
- data,
382
+ let t = {
381
383
  Type: "Process",
382
384
  "Data-Protocol": "ao",
383
385
  Variant: "ao.TN.1",
@@ -385,24 +387,44 @@ class HB {
385
387
  Authority: this._info.address,
386
388
  "scheduler-location": this._info.address,
387
389
  "random-seed": seed(16),
388
- module: "ISShJH1ij-hPPt9St5UFFr_8Ys3Kj5cyg7zrMGt7H9s",
390
+ module: module ?? "ISShJH1ij-hPPt9St5UFFr_8Ys3Kj5cyg7zrMGt7H9s",
389
391
  device: "process@1.0",
390
392
  "scheduler-device": "scheduler@1.0",
391
393
  "execution-device": "stack@1.0",
394
+ "push-device": "push@1.0",
392
395
  "device-stack": ["genesis-wasm@1.0", "patch@1.0"],
393
396
  "patch-from": "/results/outbox",
394
397
  "stack-keys": ["init", "compute", "snapshot", "normalize"],
395
- })
398
+ }
399
+ if (data) t.data = data
400
+ tags = mergeLeft(tags, t)
396
401
  return await this.spawn(tags)
397
402
  }
398
-
403
+ async results({ process, limit, sort = "DESC", from, to } = {}) {
404
+ let params = ""
405
+ const addParam = (key, val) => {
406
+ params += params === "" ? "?" : "&"
407
+ params += `${key}=${val}`
408
+ }
409
+ if (limit) addParam("limit", limit)
410
+ if (sort) addParam("sort", sort)
411
+ if (from) addParam("from", from)
412
+ if (to) addParam("to", to)
413
+ const res = await this.post({
414
+ path: "/~relay@1.0/call",
415
+ method: "GET",
416
+ "relay-path": `${this.cu}/results/${process}${params}`,
417
+ "content-type": "application/json",
418
+ })
419
+ return JSON.parse(res.body)
420
+ }
399
421
  async dryrun({ tags = {}, pid, action, data } = {}) {
400
422
  if (typeof action === "string") tags.Action = action
401
423
  let json = { Tags: buildTags({ ...tags }), Owner: this.addr }
402
424
  if (data) json.Data = data
403
425
  const res = await this.post({
404
426
  path: "/~relay@1.0/call",
405
- "relay-method": "POST",
427
+ method: "POST",
406
428
  "relay-path": `${this.cu}/dry-run?process-id=${pid}`,
407
429
  "content-type": "application/json",
408
430
  "relay-body": JSON.stringify(json),
package/esm/hyperbeam.js CHANGED
@@ -15,14 +15,15 @@ export default class HyperBEAM {
15
15
  cwd = "./HyperBEAM",
16
16
  c,
17
17
  cmake,
18
- legacy = false,
19
18
  faff,
20
19
  simplePay = false,
21
20
  simplePayPrice,
22
21
  p4_lua,
23
22
  store_prefix,
24
23
  operator,
24
+ console = true,
25
25
  } = {}) {
26
+ this.console = console
26
27
  if (clearCache) {
27
28
  const dirname = resolve(process.cwd(), cwd)
28
29
  for (let v of readdirSync(dirname)) {
@@ -69,14 +70,16 @@ export default class HyperBEAM {
69
70
  cwd: resolve(process.cwd(), this.cwd),
70
71
  }
71
72
  )
72
- this.hbeam.stdout.on("data", chunk => console.log(chunk.toString()))
73
- this.hbeam.stderr.on("data", err => console.error(err.toString()))
74
- this.hbeam.on("error", err =>
75
- console.error(`failed to start process: ${err}`)
76
- )
77
- this.hbeam.on("close", code =>
78
- console.log(`child process exited with code ${code}`)
79
- )
73
+ if (this.console) {
74
+ this.hbeam.stdout.on("data", chunk => console.log(chunk.toString()))
75
+ this.hbeam.stderr.on("data", err => console.error(err.toString()))
76
+ this.hbeam.on("error", err =>
77
+ console.error(`failed to start process: ${err}`)
78
+ )
79
+ this.hbeam.on("close", code =>
80
+ console.log(`child process exited with code ${code}`)
81
+ )
82
+ }
80
83
  }
81
84
  async ok() {
82
85
  try {