wao 0.5.6 → 0.6.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/helpers.js CHANGED
@@ -4,7 +4,7 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.setup = exports.ok = exports.fail = exports.Src = void 0;
7
+ exports.setup = exports.ok = exports.fail = exports.Testnet = exports.Src = void 0;
8
8
  var _index = require("./index.js");
9
9
  var _assert = _interopRequireDefault(require("assert"));
10
10
  var _aoconnect3 = require("@permaweb/aoconnect");
@@ -77,6 +77,45 @@ var Src = exports.Src = /*#__PURE__*/function () {
77
77
  });
78
78
  }
79
79
  return _createClass(Src, [{
80
+ key: "init",
81
+ value: function () {
82
+ var _init = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(dir) {
83
+ var _dir;
84
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
85
+ while (1) switch (_context2.prev = _context2.next) {
86
+ case 0:
87
+ if (this.dir) {
88
+ _context2.next = 9;
89
+ break;
90
+ }
91
+ if (!((_dir = dir) !== null && _dir !== void 0)) {
92
+ _context2.next = 5;
93
+ break;
94
+ }
95
+ _dir;
96
+ _context2.next = 8;
97
+ break;
98
+ case 5:
99
+ _context2.next = 7;
100
+ return dirname();
101
+ case 7:
102
+ dir = _context2.sent;
103
+ case 8:
104
+ this.dir = (0, _path.resolve)(dir, "lua");
105
+ case 9:
106
+ return _context2.abrupt("return", this);
107
+ case 10:
108
+ case "end":
109
+ return _context2.stop();
110
+ }
111
+ }, _callee2, this);
112
+ }));
113
+ function init(_x) {
114
+ return _init.apply(this, arguments);
115
+ }
116
+ return init;
117
+ }()
118
+ }, {
80
119
  key: "data",
81
120
  value: function data(file) {
82
121
  var ext = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "lua";
@@ -85,43 +124,141 @@ var Src = exports.Src = /*#__PURE__*/function () {
85
124
  }, {
86
125
  key: "upload",
87
126
  value: function () {
88
- var _upload = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(file) {
127
+ var _upload = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(file) {
89
128
  var ext,
90
129
  res,
91
- _args2 = arguments;
92
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
93
- while (1) switch (_context2.prev = _context2.next) {
130
+ _args3 = arguments;
131
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
132
+ while (1) switch (_context3.prev = _context3.next) {
94
133
  case 0:
95
- ext = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : "lua";
96
- _context2.next = 3;
134
+ ext = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : "lua";
135
+ _context3.next = 3;
97
136
  return this.ar.post({
98
137
  data: this.data(file, ext)
99
138
  });
100
139
  case 3:
101
- res = _context2.sent;
102
- return _context2.abrupt("return", res.err ? null : res.id);
140
+ res = _context3.sent;
141
+ return _context3.abrupt("return", res.err ? null : res.id);
103
142
  case 5:
104
143
  case "end":
105
- return _context2.stop();
144
+ return _context3.stop();
106
145
  }
107
- }, _callee2, this);
146
+ }, _callee3, this);
108
147
  }));
109
- function upload(_x) {
148
+ function upload(_x2) {
110
149
  return _upload.apply(this, arguments);
111
150
  }
112
151
  return upload;
113
152
  }()
114
153
  }]);
115
154
  }();
155
+ var Testnet = exports.Testnet = /*#__PURE__*/function () {
156
+ function Testnet() {
157
+ var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
158
+ _ref3$port = _ref3.port,
159
+ port = _ref3$port === void 0 ? 4000 : _ref3$port,
160
+ arweave = _ref3.arweave,
161
+ aoconnect = _ref3.aoconnect,
162
+ _ref3$docker = _ref3.docker,
163
+ docker = _ref3$docker === void 0 ? false : _ref3$docker;
164
+ _classCallCheck(this, Testnet);
165
+ this.docker = docker;
166
+ this.arweave = arweave !== null && arweave !== void 0 ? arweave : {
167
+ port: port
168
+ };
169
+ this.aoconnect = aoconnect !== null && aoconnect !== void 0 ? aoconnect : {
170
+ MU_URL: "http://localhost:".concat(port + 2),
171
+ SU_URL: "http://localhost:".concat(port + 3),
172
+ CU_URL: "http://localhost:".concat(port + 4),
173
+ GATEWAY_URL: "http://localhost:".concat(port)
174
+ };
175
+ this.ar = new _index.AR(this.arweave);
176
+ }
177
+ return _createClass(Testnet, [{
178
+ key: "init",
179
+ value: function () {
180
+ var _init2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(jwk) {
181
+ var _yield$this$ao$postMo, id, _yield$this$ao$postSc, scheduler;
182
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
183
+ while (1) switch (_context4.prev = _context4.next) {
184
+ case 0:
185
+ _context4.next = 2;
186
+ return fetch(this.aoconnect.SU_URL).then(function (r) {
187
+ return r.json();
188
+ });
189
+ case 2:
190
+ this.authority = _context4.sent.address;
191
+ _context4.next = 5;
192
+ return new Src({
193
+ ar: this.ar
194
+ }).init();
195
+ case 5:
196
+ this.src = _context4.sent;
197
+ _context4.next = 8;
198
+ return this.ar.init(jwk);
199
+ case 8:
200
+ this.jwk = this.ar.jwk;
201
+ this.addr = this.ar.a;
202
+ this.gql = this.ar.gql;
203
+ _context4.next = 13;
204
+ return this.src.upload("aos2_0_1", "wasm");
205
+ case 13:
206
+ this.module_src = _context4.sent;
207
+ _context4.next = 16;
208
+ return new _index.AO({
209
+ ar: this.ar,
210
+ aoconnect: this.aoconnect,
211
+ authority: this.authority
212
+ }).init(this.ar.jwk);
213
+ case 16:
214
+ this.ao = _context4.sent;
215
+ _context4.t0 = this.ao;
216
+ _context4.next = 20;
217
+ return this.ar.data(this.module_src);
218
+ case 20:
219
+ _context4.t1 = _context4.sent;
220
+ _context4.t2 = {
221
+ data: _context4.t1,
222
+ overwrite: true
223
+ };
224
+ _context4.next = 24;
225
+ return _context4.t0.postModule.call(_context4.t0, _context4.t2);
226
+ case 24:
227
+ _yield$this$ao$postMo = _context4.sent;
228
+ id = _yield$this$ao$postMo.id;
229
+ this.module = id;
230
+ _context4.next = 29;
231
+ return this.ao.postScheduler({
232
+ url: this.docker ? "http://su" : this.aoconnect.SU_URL,
233
+ overwrite: true
234
+ });
235
+ case 29:
236
+ _yield$this$ao$postSc = _context4.sent;
237
+ scheduler = _yield$this$ao$postSc.scheduler;
238
+ this.scheduler = scheduler;
239
+ return _context4.abrupt("return", this);
240
+ case 33:
241
+ case "end":
242
+ return _context4.stop();
243
+ }
244
+ }, _callee4, this);
245
+ }));
246
+ function init(_x3) {
247
+ return _init2.apply(this, arguments);
248
+ }
249
+ return init;
250
+ }()
251
+ }]);
252
+ }();
116
253
  var setup = exports.setup = /*#__PURE__*/function () {
117
- var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
254
+ var _ref4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
118
255
  var _arweave, _aoconnect, _aoconnect$CU_URL, _aoconnect2;
119
- var _ref4,
256
+ var _ref5,
120
257
  aoconnect,
121
258
  arweave,
122
- _ref4$cacheDir,
259
+ _ref5$cacheDir,
123
260
  cacheDir,
124
- _ref4$targets,
261
+ _ref5$targets,
125
262
  targets,
126
263
  opt,
127
264
  dir,
@@ -146,32 +283,32 @@ var setup = exports.setup = /*#__PURE__*/function () {
146
283
  _yield$ao$postSchedul,
147
284
  scheduler,
148
285
  ao2,
149
- _args3 = arguments;
150
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
151
- while (1) switch (_context3.prev = _context3.next) {
286
+ _args5 = arguments;
287
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
288
+ while (1) switch (_context5.prev = _context5.next) {
152
289
  case 0:
153
- _ref4 = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : {}, aoconnect = _ref4.aoconnect, arweave = _ref4.arweave, _ref4$cacheDir = _ref4.cacheDir, cacheDir = _ref4$cacheDir === void 0 ? ".cache" : _ref4$cacheDir, _ref4$targets = _ref4.targets, targets = _ref4$targets === void 0 ? {
290
+ _ref5 = _args5.length > 0 && _args5[0] !== undefined ? _args5[0] : {}, aoconnect = _ref5.aoconnect, arweave = _ref5.arweave, _ref5$cacheDir = _ref5.cacheDir, cacheDir = _ref5$cacheDir === void 0 ? ".cache" : _ref5$cacheDir, _ref5$targets = _ref5.targets, targets = _ref5$targets === void 0 ? {
154
291
  profile: false,
155
292
  note: false,
156
293
  asset: false
157
- } : _ref4$targets;
294
+ } : _ref5$targets;
158
295
  if (targets.asset || targets.note) targets.profile = true;
159
296
  opt = null;
160
297
  console.error = function () {};
161
298
  console.warn = function () {};
162
- _context3.t0 = _path.resolve;
163
- _context3.next = 8;
299
+ _context5.t0 = _path.resolve;
300
+ _context5.next = 8;
164
301
  return dirname();
165
302
  case 8:
166
- _context3.t1 = _context3.sent;
167
- dir = (0, _context3.t0)(_context3.t1, "lua");
168
- _context3.t2 = _path.resolve;
169
- _context3.next = 13;
303
+ _context5.t1 = _context5.sent;
304
+ dir = (0, _context5.t0)(_context5.t1, "lua");
305
+ _context5.t2 = _path.resolve;
306
+ _context5.next = 13;
170
307
  return dirname();
171
308
  case 13:
172
- _context3.t3 = _context3.sent;
173
- _context3.t4 = cacheDir;
174
- _cacheDir = (0, _context3.t2)(_context3.t3, _context3.t4);
309
+ _context5.t3 = _context5.sent;
310
+ _context5.t4 = cacheDir;
311
+ _cacheDir = (0, _context5.t2)(_context5.t3, _context5.t4);
175
312
  optPath = "".concat(_cacheDir, "/opt.json");
176
313
  if (cache && !reset) {
177
314
  try {
@@ -185,29 +322,28 @@ var setup = exports.setup = /*#__PURE__*/function () {
185
322
  }
186
323
  }
187
324
  if (!opt) {
188
- _context3.next = 32;
325
+ _context5.next = 32;
189
326
  break;
190
327
  }
191
- _context3.next = 21;
328
+ _context5.next = 21;
192
329
  return new _index.AR(opt.ar).init(opt.jwk);
193
330
  case 21:
194
- _ar = _context3.sent;
331
+ _ar = _context5.sent;
195
332
  _src = new Src({
196
333
  ar: _ar,
197
- readFileSync: _fs.readFileSync,
198
334
  dir: dir
199
335
  });
200
- _context3.next = 25;
336
+ _context5.next = 25;
201
337
  return new _index.AO(opt.ao).init(opt.jwk);
202
338
  case 25:
203
- _ao = _context3.sent;
204
- _context3.next = 28;
339
+ _ao = _context5.sent;
340
+ _context5.next = 28;
205
341
  return new _index.AO(opt.ao2).init(opt.jwk);
206
342
  case 28:
207
- _ao2 = _context3.sent;
343
+ _ao2 = _context5.sent;
208
344
  console.log("cache:\t", optPath);
209
345
  console.log("addr:\t", _ar.addr);
210
- return _context3.abrupt("return", {
346
+ return _context5.abrupt("return", {
211
347
  opt: opt,
212
348
  ar: _ar,
213
349
  ao2: _ao2,
@@ -225,12 +361,11 @@ var setup = exports.setup = /*#__PURE__*/function () {
225
361
  GATEWAY_URL: "http://localhost:4000"
226
362
  };
227
363
  ar = new _index.AR(arweave);
228
- _context3.next = 37;
364
+ _context5.next = 37;
229
365
  return ar.gen("10");
230
366
  case 37:
231
367
  src = new Src({
232
368
  ar: ar,
233
- readFileSync: _fs.readFileSync,
234
369
  dir: dir
235
370
  });
236
371
  opt = {
@@ -238,81 +373,81 @@ var setup = exports.setup = /*#__PURE__*/function () {
238
373
  jwk: ar.jwk
239
374
  };
240
375
  if (!(!auth && /localhost/.test((_aoconnect$CU_URL = (_aoconnect2 = aoconnect) === null || _aoconnect2 === void 0 ? void 0 : _aoconnect2.CU_URL) !== null && _aoconnect$CU_URL !== void 0 ? _aoconnect$CU_URL : ""))) {
241
- _context3.next = 43;
376
+ _context5.next = 43;
242
377
  break;
243
378
  }
244
- _context3.next = 42;
379
+ _context5.next = 42;
245
380
  return fetch(aoconnect.CU_URL).then(function (r) {
246
381
  return r.json();
247
382
  });
248
383
  case 42:
249
- auth = _context3.sent.address;
384
+ auth = _context5.sent.address;
250
385
  case 43:
251
- _context3.next = 45;
386
+ _context5.next = 45;
252
387
  return src.upload("sqlite", "wasm");
253
388
  case 45:
254
- wasm = _context3.sent;
255
- _context3.next = 48;
389
+ wasm = _context5.sent;
390
+ _context5.next = 48;
256
391
  return src.upload("aos", "wasm");
257
392
  case 48:
258
- wasm2 = _context3.sent;
259
- _context3.next = 51;
393
+ wasm2 = _context5.sent;
394
+ _context5.next = 51;
260
395
  return src.upload("aos2_0_1", "wasm");
261
396
  case 51:
262
- wasm_aos2 = _context3.sent;
397
+ wasm_aos2 = _context5.sent;
263
398
  ao = new _index.AO({
264
399
  aoconnect: aoconnect,
265
400
  ar: ar,
266
401
  authority: auth
267
402
  });
268
- _context3.t5 = ao;
269
- _context3.next = 56;
403
+ _context5.t5 = ao;
404
+ _context5.next = 56;
270
405
  return ar.data(wasm_aos2);
271
406
  case 56:
272
- _context3.t6 = _context3.sent;
273
- _context3.t7 = {
274
- data: _context3.t6
407
+ _context5.t6 = _context5.sent;
408
+ _context5.t7 = {
409
+ data: _context5.t6
275
410
  };
276
- _context3.next = 60;
277
- return _context3.t5.postModule.call(_context3.t5, _context3.t7);
411
+ _context5.next = 60;
412
+ return _context5.t5.postModule.call(_context5.t5, _context5.t7);
278
413
  case 60:
279
- _yield$ao$postModule = _context3.sent;
414
+ _yield$ao$postModule = _context5.sent;
280
415
  module_aos2 = _yield$ao$postModule.id;
281
- _context3.t8 = ao;
282
- _context3.next = 65;
416
+ _context5.t8 = ao;
417
+ _context5.next = 65;
283
418
  return ar.data(wasm);
284
419
  case 65:
285
- _context3.t9 = _context3.sent;
286
- _context3.t10 = {
287
- data: _context3.t9,
420
+ _context5.t9 = _context5.sent;
421
+ _context5.t10 = {
422
+ data: _context5.t9,
288
423
  overwrite: true
289
424
  };
290
- _context3.next = 69;
291
- return _context3.t8.postModule.call(_context3.t8, _context3.t10);
425
+ _context5.next = 69;
426
+ return _context5.t8.postModule.call(_context5.t8, _context5.t10);
292
427
  case 69:
293
- _yield$ao$postModule2 = _context3.sent;
428
+ _yield$ao$postModule2 = _context5.sent;
294
429
  module_sqlite = _yield$ao$postModule2.id;
295
- _context3.t11 = ao;
296
- _context3.next = 74;
430
+ _context5.t11 = ao;
431
+ _context5.next = 74;
297
432
  return ar.data(wasm2);
298
433
  case 74:
299
- _context3.t12 = _context3.sent;
300
- _context3.t13 = {
301
- data: _context3.t12,
434
+ _context5.t12 = _context5.sent;
435
+ _context5.t13 = {
436
+ data: _context5.t12,
302
437
  overwrite: true
303
438
  };
304
- _context3.next = 78;
305
- return _context3.t11.postModule.call(_context3.t11, _context3.t13);
439
+ _context5.next = 78;
440
+ return _context5.t11.postModule.call(_context5.t11, _context5.t13);
306
441
  case 78:
307
- _yield$ao$postModule3 = _context3.sent;
442
+ _yield$ao$postModule3 = _context5.sent;
308
443
  module = _yield$ao$postModule3.id;
309
- _context3.next = 82;
444
+ _context5.next = 82;
310
445
  return ao.postScheduler({
311
446
  url: "http://su",
312
447
  overwrite: true
313
448
  });
314
449
  case 82:
315
- _yield$ao$postSchedul = _context3.sent;
450
+ _yield$ao$postSchedul = _context5.sent;
316
451
  scheduler = _yield$ao$postSchedul.scheduler;
317
452
  opt.ao = {
318
453
  module: module_sqlite,
@@ -323,7 +458,7 @@ var setup = exports.setup = /*#__PURE__*/function () {
323
458
  };
324
459
 
325
460
  // ao2
326
- _context3.next = 87;
461
+ _context5.next = 87;
327
462
  return new _index.AO({
328
463
  aoconnect: aoconnect,
329
464
  ar: ar,
@@ -332,7 +467,7 @@ var setup = exports.setup = /*#__PURE__*/function () {
332
467
  scheduler: scheduler
333
468
  }).init(ar.jwk);
334
469
  case 87:
335
- ao2 = _context3.sent;
470
+ ao2 = _context5.sent;
336
471
  opt.ao2 = {
337
472
  module: module_aos2,
338
473
  scheduler: scheduler,
@@ -352,7 +487,7 @@ var setup = exports.setup = /*#__PURE__*/function () {
352
487
  if (!(0, _fs.existsSync)(_cacheDir)) (0, _fs.mkdirSync)(_cacheDir);
353
488
  (0, _fs.writeFileSync)(optPath, JSON.stringify(opt));
354
489
  }
355
- return _context3.abrupt("return", {
490
+ return _context5.abrupt("return", {
356
491
  opt: opt,
357
492
  ao: ao,
358
493
  ar: ar,
@@ -361,12 +496,12 @@ var setup = exports.setup = /*#__PURE__*/function () {
361
496
  });
362
497
  case 95:
363
498
  case "end":
364
- return _context3.stop();
499
+ return _context5.stop();
365
500
  }
366
- }, _callee3);
501
+ }, _callee5);
367
502
  }));
368
503
  return function setup() {
369
- return _ref3.apply(this, arguments);
504
+ return _ref4.apply(this, arguments);
370
505
  };
371
506
  }();
372
507
  var ok = exports.ok = function ok(obj) {
Binary file
package/cjs/run.js CHANGED
@@ -12,7 +12,9 @@ var main = /*#__PURE__*/function () {
12
12
  return _regeneratorRuntime().wrap(function _callee$(_context) {
13
13
  while (1) switch (_context.prev = _context.next) {
14
14
  case 0:
15
- return _context.abrupt("return", new _server["default"]());
15
+ return _context.abrupt("return", new _server["default"]({
16
+ log: true
17
+ }));
16
18
  case 1:
17
19
  case "end":
18
20
  return _context.stop();