wao 0.22.3 → 0.23.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/cjs/hyperbeam.js CHANGED
@@ -75,7 +75,11 @@ var HyperBEAM = exports["default"] = /*#__PURE__*/function () {
75
75
  legacy = _ref2$legacy === void 0 ? false : _ref2$legacy;
76
76
  var _wallet = ", priv_key_location => <<\"".concat(wallet, "\">>");
77
77
  var _gateway = gateway ? ", gateway => <<\"http://localhost:".concat(gateway, "\">>") : "";
78
- return !legacy ? "hb:start_mainnet(#{ port => ".concat(this.port).concat(_gateway).concat(_wallet, " }).") : "hb:start_mainnet(#{ port => ".concat(this.port).concat(_gateway).concat(_wallet, ", bundler_httpsig => <<\"http://localhost:4001\">>, routes => [ #{ <<\"template\">> => <<\"/result/.*\">>, <<\"node\">> => #{ <<\"prefix\">> => <<\"http://localhost:4004\">> } }, #{ <<\"template\">> => <<\"/dry-run\">>, <<\"node\">> => #{ <<\"prefix\">> => <<\"http://localhost:4004\">> } }, #{ <<\"template\">> => <<\"/graphql\">>, <<\"node\">> => #{ <<\"prefix\">> => <<\"http://localhost:4000\">>, <<\"opts\">> => #{ http_client => gun } } }, #{ <<\"template\">> => <<\"/raw\">>, <<\"node\">> => #{ <<\"prefix\">> => <<\"http://localhost:4000\">>, <<\"opts\">> => #{ http_client => gun } } } ] }).");
78
+ var _store = ", store => [#{ <<\"store-module\">> => hb_store_fs, <<\"prefix\">> => <<\"cache-mainnet\">> }, #{ <<\"store-module\">> => hb_store_gateway, <<\"subindex\">> => [#{ <<\"name\">> => <<\"Data-Protocol\">>, <<\"value\">> => <<\"ao\">> }], <<\"store\">> => [#{ <<\"store-module\">> => hb_store_fs, <<\"prefix\">> => <<\"cache-mainnet\">> }] }, #{ <<\"store-module\">> => hb_store_gateway, <<\"store\">> => [#{ <<\"store-module\">> => hb_store_fs, <<\"prefix\">> => <<\"cache-mainnet\">> }] }]";
79
+ var _bundler = ", bundler_httpsig => <<\"http://localhost:4001\">>";
80
+ var _routes = ", routes => [#{ <<\"template\">> => <<\"/result/.*\">>, <<\"node\">> => #{ <<\"prefix\">> => <<\"http://localhost:6363\">> } }, #{ <<\"template\">> => <<\"/graphql\">>, <<\"nodes\">> => [#{ <<\"prefix\">> => <<\"http://localhost:".concat(gateway, "\">>, <<\"opts\">> => #{ http_client => httpc, protocol => http2 } }, #{ <<\"prefix\">> => <<\"http://localhost:").concat(gateway, "\">>, <<\"opts\">> => #{ http_client => gun, protocol => http2 } }] }, #{ <<\"template\">> => <<\"/raw\">>, <<\"node\">> => #{ <<\"prefix\">> => <<\"http://localhost:").concat(gateway, "\">>, <<\"opts\">> => #{ http_client => gun, protocol => http2 } } }]");
81
+ var _port = "port => ".concat(this.port);
82
+ return !legacy ? "hb:start_mainnet(#{ ".concat(_port).concat(_gateway).concat(_wallet).concat(_store, " }).") : "hb:start_mainnet(#{ ".concat(_port).concat(_gateway).concat(_wallet).concat(_store).concat(_bundler).concat(_routes, " }).");
79
83
  }
80
84
  }, {
81
85
  key: "kill",
package/cjs/server.js CHANGED
@@ -88,7 +88,7 @@ var Server = /*#__PURE__*/function () {
88
88
  limit: "100mb"
89
89
  }));
90
90
  this.launch("AR", app, {
91
- get: ["/", "/wallet/:id/balance", "/mint/:id/:amount", "/tx/:id/offset", "/tx_anchor", "/mine", "/:id", "/price/:id"],
91
+ get: ["/", "/tx", "/wallet/:id/balance", "/mint/:id/:amount", "/tx/:id/offset", "/tx_anchor", "/mine", "/:id", "/price/:id"],
92
92
  post: ["/graphql", "/:id"]
93
93
  });
94
94
  }
@@ -90,6 +90,8 @@ class Adaptor {
90
90
  switch (req.path) {
91
91
  case "/":
92
92
  return await this.ar_get_root(req)
93
+ case "/tx":
94
+ return await this.ar_get_tx(req)
93
95
  case "/wallet/:id/balance":
94
96
  return await this.ar_get_wallet_balance(req)
95
97
  case "/mint/:id/:amount":
@@ -469,6 +471,7 @@ class Adaptor {
469
471
  async ar_post_graphql({ query, params, body, headers, method }) {
470
472
  try {
471
473
  const { query, variables } = body
474
+ console.log(query, variables)
472
475
  const { tar, args } = toGraphObj({ query, variables })
473
476
  let res2 = null
474
477
  if (tar === "transactions") {
package/esm/hb.js CHANGED
@@ -11,7 +11,8 @@ const seed = num => {
11
11
  class HB {
12
12
  constructor({ url = "http://localhost:10001", jwk } = {}) {
13
13
  this.url = url
14
- this.hyperbuddy = {
14
+ this.dev = {}
15
+ this.dev.hyperbuddy = {
15
16
  metrics: async (args = {}) => {
16
17
  return this.parseMetrics(
17
18
  await this.fetch(this.path("hyperbuddy", "metrics", false), false)
@@ -19,7 +20,7 @@ class HB {
19
20
  },
20
21
  }
21
22
 
22
- this.json = {
23
+ this.dev.json = {
23
24
  commit: async args => {
24
25
  return await this.send({ path: "/~json@1.0/commit", ...args })
25
26
  },
@@ -33,7 +34,7 @@ class HB {
33
34
  return await this.send({ path: "/~json@1.0/serialize", ...args })
34
35
  },
35
36
  }
36
- this.meta = {
37
+ this.dev.meta = {
37
38
  info: async (args = {}) => {
38
39
  let { method = "GET", json = true, key } = args
39
40
  if (method.toLowerCase() === "post") {
@@ -71,7 +72,7 @@ class HB {
71
72
 
72
73
  async init(jwk) {
73
74
  this._init(jwk)
74
- this._info = await this.meta.info({})
75
+ this._info = await this.dev.meta.info({})
75
76
  return this
76
77
  }
77
78
 
@@ -82,10 +83,21 @@ class HB {
82
83
  async getImage() {
83
84
  const result = await this.send({
84
85
  path: "/~wao@1.0/cache_wasm_image",
85
- method: "POST",
86
86
  filename: "test/aos-2-pure-xs.wasm",
87
87
  })
88
- return result.headers.get("image")
88
+ const image = result.headers.get("image")
89
+ this.image ??= image
90
+ return image
91
+ }
92
+
93
+ async getLua() {
94
+ const result = await this.send({
95
+ path: "/~wao@1.0/cache_lua_module",
96
+ filename: "test/hyper-aos.lua",
97
+ })
98
+ const lua = result.headers.get("id").split("/").pop()
99
+ this.lua ??= lua
100
+ return lua
89
101
  }
90
102
 
91
103
  async messageAOS({ pid, action = "Eval", tags = {}, data }) {
@@ -105,7 +117,7 @@ class HB {
105
117
  return { slot, outbox: await this.computeAOS({ pid, slot }) }
106
118
  }
107
119
 
108
- path(dev = "meta", path = "info", json = true, params = {}) {
120
+ path(dev = "message", path, json = true, params = {}, pid = "", tail = "") {
109
121
  if (!/@/.test(dev)) dev += "@1.0"
110
122
  let _params = ""
111
123
  if (!isEmpty(params)) {
@@ -115,15 +127,28 @@ class HB {
115
127
  i++
116
128
  }
117
129
  }
118
- return `${this.url}/~${dev}/${path}${json ? "/serialize~json@1.0" : ""}${_params}`
130
+ return `${this.url}/${pid}~${dev}${path ? `/${path}` : ""}${tail}${json ? "/~json@1.0/serialize" : ""}${_params}`
119
131
  }
120
132
 
121
- async text(dev, path) {
122
- return await this.fetch(this.path(dev, path, false), false)
133
+ async text(dev, path, params = {}, tail) {
134
+ let pid = ""
135
+ if (/^[a-zA-Z0-9_-]{43}$/.test(dev)) {
136
+ pid = dev
137
+ dev = "process"
138
+ }
139
+ return await this.fetch(
140
+ this.path(dev, path, false, params, pid, tail),
141
+ false
142
+ )
123
143
  }
124
144
 
125
- async json(dev, path) {
126
- return await this.fetch(this.path(dev, path))
145
+ async json(dev, path, params = {}, tail) {
146
+ let pid = ""
147
+ if (/^[a-zA-Z0-9_-]{43}$/.test(dev)) {
148
+ pid = dev
149
+ dev = "process"
150
+ }
151
+ return await this.fetch(this.path(dev, path, true, params, pid, tail))
127
152
  }
128
153
 
129
154
  async fetch(url, json = true) {
@@ -132,13 +157,19 @@ class HB {
132
157
 
133
158
  async computeAOS({ pid, slot }) {
134
159
  return await fetch(
135
- `${this.url}/${pid}/compute/results/outbox/serialize~json@1.0?slot=${slot}`
160
+ `${this.url}/${pid}/compute/results/outbox/~json@1.0/serialize?slot=${slot}`
161
+ ).then(r => r.json())
162
+ }
163
+
164
+ async computeLua({ pid, slot }) {
165
+ return await fetch(
166
+ `${this.url}/${pid}/compute/results/~json@1.0/serialize?slot=${slot}`
136
167
  ).then(r => r.json())
137
168
  }
138
169
 
139
170
  async compute({ pid, slot }) {
140
171
  return await fetch(
141
- `${this.url}/${pid}/compute/serialize~json@1.0?slot=${slot}`
172
+ `${this.url}/${pid}/compute/~json@1.0/serialize?slot=${slot}`
142
173
  ).then(r => r.json())
143
174
  }
144
175
 
@@ -148,7 +179,7 @@ class HB {
148
179
  }
149
180
 
150
181
  async spawn(tags = {}) {
151
- const addr = await this.meta.info({ key: "address" })
182
+ const addr = await this.dev.meta.info({ key: "address" })
152
183
  this.scheduler ??= addr
153
184
  const res = await this.send(
154
185
  mergeLeft(tags, {
@@ -180,6 +211,9 @@ class HB {
180
211
  if (action) tags.Action = action
181
212
  return await this.schedule({ pid, tags, data, scheduler })
182
213
  }
214
+ async scheduleLua(...args) {
215
+ return await this.scheduleLegacy(...args)
216
+ }
183
217
  async schedule({ pid, tags = {}, data, scheduler } = {}) {
184
218
  pid ??= this.pid
185
219
  scheduler ??= this.scheduler
@@ -196,7 +230,7 @@ class HB {
196
230
  }
197
231
 
198
232
  async spawnAOS(image) {
199
- const addr = await this.meta.info({ key: "address" })
233
+ const addr = await this.dev.meta.info({ key: "address" })
200
234
  this.scheduler ??= addr
201
235
  image ??= this.image ?? (await this.getImage())
202
236
  const res = await this.send({
@@ -228,6 +262,30 @@ class HB {
228
262
  return { pid, res }
229
263
  }
230
264
 
265
+ async spawnLua(lua = "8DvyaxF8xpHMgPdmpMnhcb1mjY-M8qr2kGxnCpGMb60") {
266
+ const addr = await this.dev.meta.info({ key: "address" })
267
+ this.scheduler ??= addr
268
+ lua ??= this.lua ?? (await this.getLua())
269
+ const res = await this.send({
270
+ device: "process@1.0",
271
+ path: "/schedule",
272
+ scheduler: this.scheduler,
273
+ "Data-Protocol": "ao",
274
+ Variant: "ao.N.1",
275
+ "scheduler-location": this.scheduler,
276
+ Authority: this.scheduler,
277
+ "random-seed": seed(16),
278
+ Type: "Process",
279
+ module: lua,
280
+ "scheduler-device": "scheduler@1.0",
281
+ "execution-device": "lua@5.3a",
282
+ "patch-from": "/results/outbox",
283
+ })
284
+ const pid = res.headers.get("process")
285
+ this.pid ??= pid
286
+ return { pid, res }
287
+ }
288
+
231
289
  parseMetrics(txt) {
232
290
  const parts = txt.split(/\r?\n/)
233
291
  let index = 0
@@ -296,17 +354,17 @@ class HB {
296
354
  }
297
355
 
298
356
  /*
299
- async scheduleLegacy({ tags = {}, data, process, action = "Eval" } = {}) {
357
+ async scheduleLegacy({ tags = {}, data, process, action = "Eval" } = {}) {
300
358
  tags = mergeLeft(tags, {
301
- path: `${process}/schedule`,
302
- type: "Message",
303
- action,
304
- data,
305
- "Data-Protocol": "ao",
306
- Variant: "ao.N.1",
359
+ path: `${process}/schedule`,
360
+ type: "Message",
361
+ action,
362
+ data,
363
+ "Data-Protocol": "ao",
364
+ Variant: "ao.N.1",
307
365
  })
308
366
  return (await this.post({ tags })).slot.text()
309
- }
367
+ }
310
368
  */
311
369
 
312
370
  async dryrun({ tags = {}, pid, action, data } = {}) {
package/esm/hyperbeam.js CHANGED
@@ -46,9 +46,13 @@ export default class HyperBEAM {
46
46
  const _gateway = gateway
47
47
  ? `, gateway => <<"http://localhost:${gateway}">>`
48
48
  : ""
49
+ const _store = `, store => [#{ <<"store-module">> => hb_store_fs, <<"prefix">> => <<"cache-mainnet">> }, #{ <<"store-module">> => hb_store_gateway, <<"subindex">> => [#{ <<"name">> => <<"Data-Protocol">>, <<"value">> => <<"ao">> }], <<"store">> => [#{ <<"store-module">> => hb_store_fs, <<"prefix">> => <<"cache-mainnet">> }] }, #{ <<"store-module">> => hb_store_gateway, <<"store">> => [#{ <<"store-module">> => hb_store_fs, <<"prefix">> => <<"cache-mainnet">> }] }]`
50
+ const _bundler = `, bundler_httpsig => <<"http://localhost:4001">>`
51
+ const _routes = `, routes => [#{ <<"template">> => <<"/result/.*">>, <<"node">> => #{ <<"prefix">> => <<"http://localhost:6363">> } }, #{ <<"template">> => <<"/graphql">>, <<"nodes">> => [#{ <<"prefix">> => <<"http://localhost:${gateway}">>, <<"opts">> => #{ http_client => httpc, protocol => http2 } }, #{ <<"prefix">> => <<"http://localhost:${gateway}">>, <<"opts">> => #{ http_client => gun, protocol => http2 } }] }, #{ <<"template">> => <<"/raw">>, <<"node">> => #{ <<"prefix">> => <<"http://localhost:${gateway}">>, <<"opts">> => #{ http_client => gun, protocol => http2 } } }]`
52
+ const _port = `port => ${this.port}`
49
53
  return !legacy
50
- ? `hb:start_mainnet(#{ port => ${this.port}${_gateway}${_wallet} }).`
51
- : `hb:start_mainnet(#{ port => ${this.port}${_gateway}${_wallet}, bundler_httpsig => <<\"http://localhost:4001\">>, routes => [ #{ <<\"template\">> => <<\"/result/.*\">>, <<\"node\">> => #{ <<\"prefix\">> => <<\"http://localhost:4004\">> } }, #{ <<\"template\">> => <<\"/dry-run\">>, <<\"node\">> => #{ <<\"prefix\">> => <<\"http://localhost:4004\">> } }, #{ <<\"template\">> => <<\"/graphql\">>, <<\"node\">> => #{ <<\"prefix\">> => <<\"http://localhost:4000\">>, <<\"opts\">> => #{ http_client => gun } } }, #{ <<\"template\">> => <<\"/raw\">>, <<\"node\">> => #{ <<\"prefix\">> => <<\"http://localhost:4000\">>, <<\"opts\">> => #{ http_client => gun } } } ] }).`
54
+ ? `hb:start_mainnet(#{ ${_port}${_gateway}${_wallet}${_store} }).`
55
+ : `hb:start_mainnet(#{ ${_port}${_gateway}${_wallet}${_store}${_bundler}${_routes} }).`
52
56
  }
53
57
 
54
58
  kill() {
package/esm/server.js CHANGED
@@ -47,6 +47,7 @@ class Server {
47
47
  this.launch("AR", app, {
48
48
  get: [
49
49
  "/",
50
+ "/tx",
50
51
  "/wallet/:id/balance",
51
52
  "/mint/:id/:amount",
52
53
  "/tx/:id/offset",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wao",
3
- "version": "0.22.3",
3
+ "version": "0.23.0",
4
4
  "bin": {
5
5
  "wao": "./cjs/cli.js",
6
6
  "wao-esm": "./esm/cli.js"