wao 0.2.3 → 0.2.4

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/aoconnect.js CHANGED
@@ -81,6 +81,8 @@ var dirname = /*#__PURE__*/function () {
81
81
  }();
82
82
  var acc = exports.acc = _accounts["default"].users;
83
83
  var mu = exports.mu = _accounts["default"].mu;
84
+ var scheduler = "GQ33BkPtZrqxA84vM8Zk-N2aO0toNNu_C-l-rawrBA";
85
+ var env = {};
84
86
  var connect = exports.connect = function connect() {
85
87
  var wasms = {
86
88
  "Do_Uc2Sju_ffp6Ev0AnLVdPtot15rvMjP-a9VVaA5fM": {
@@ -97,14 +99,12 @@ var connect = exports.connect = function connect() {
97
99
  }
98
100
  };
99
101
  var modules = {
100
- aos_2_0_1: "Do_Uc2Sju_ffp6Ev0AnLVdPtot15rvMjP-a9VVaA5fM",
101
- aos_1: "cNlipBptaF9JeFAf4wUmpi43EojNanIBos3EfNrEOWo",
102
+ aos2_0_1: "Do_Uc2Sju_ffp6Ev0AnLVdPtot15rvMjP-a9VVaA5fM",
103
+ aos1: "cNlipBptaF9JeFAf4wUmpi43EojNanIBos3EfNrEOWo",
102
104
  sqlite: "ghSkge2sIUD_F00ym5sEimC63BDBuBrq4b5OcwxOjiw"
103
105
  };
104
106
  var modmap = {};
105
- var env = {
106
- msgs: {}
107
- };
107
+ var msgs = {};
108
108
  var transform = function transform(input) {
109
109
  var _input$Tags;
110
110
  var output = {
@@ -276,19 +276,92 @@ var connect = exports.connect = function connect() {
276
276
  return _ref7.apply(this, arguments);
277
277
  };
278
278
  }();
279
- var _message = /*#__PURE__*/function () {
280
- var _ref8 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(opt) {
281
- var p, ex, _iterator, _step, _v, _yield$parse2, id, owner, _opt$data2, _opt$from, _res$Messages, msg, _env, res, _iterator2, _step2, v;
279
+ var spawn = /*#__PURE__*/function () {
280
+ var _ref8 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
281
+ var _opt$module, _opt$tags;
282
+ var opt,
283
+ mod,
284
+ _dirname,
285
+ wasm,
286
+ handle,
287
+ _module,
288
+ ex,
289
+ _iterator,
290
+ _step,
291
+ v,
292
+ _yield$parse2,
293
+ id,
294
+ owner,
295
+ _tags,
296
+ res,
297
+ memory,
298
+ p,
299
+ _opt$data2,
300
+ _msgs$_tags$OnBoot$d,
301
+ _msgs$_tags$OnBoot,
302
+ data,
303
+ msg,
304
+ _env,
305
+ _t,
306
+ _tags$CronInterval$s,
307
+ _tags$CronInterval$s2,
308
+ num,
309
+ unit,
310
+ _int,
311
+ cronTags,
312
+ k,
313
+ _args4 = arguments;
282
314
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
283
315
  while (1) switch (_context4.prev = _context4.next) {
284
316
  case 0:
285
- p = env[opt.process];
317
+ opt = _args4.length > 0 && _args4[0] !== undefined ? _args4[0] : {};
318
+ if (opt.module) {
319
+ _context4.next = 3;
320
+ break;
321
+ }
322
+ throw Error("module missing");
323
+ case 3:
324
+ if (opt.scheduler) {
325
+ _context4.next = 5;
326
+ break;
327
+ }
328
+ throw Error("scheduler missing");
329
+ case 5:
330
+ mod = (_opt$module = opt.module) !== null && _opt$module !== void 0 ? _opt$module : modules["aos2_0_1"];
331
+ if (!(!modmap[mod] && wasms[mod])) {
332
+ _context4.next = 15;
333
+ break;
334
+ }
335
+ _context4.next = 9;
336
+ return dirname();
337
+ case 9:
338
+ _dirname = _context4.sent;
339
+ wasm = (0, _fs.readFileSync)((0, _path.resolve)(_dirname, "lua/".concat(wasms[mod].file, ".wasm")));
340
+ _context4.next = 13;
341
+ return (0, _aoLoader["default"])(wasm, {
342
+ format: wasms[mod].format
343
+ });
344
+ case 13:
345
+ handle = _context4.sent;
346
+ modmap[mod] = {
347
+ handle: handle,
348
+ id: mod
349
+ };
350
+ case 15:
351
+ if (mod) {
352
+ _context4.next = 17;
353
+ break;
354
+ }
355
+ throw Error("module not found");
356
+ case 17:
357
+ _module = modmap[mod];
286
358
  ex = false;
359
+ (_opt$tags = opt.tags) !== null && _opt$tags !== void 0 ? _opt$tags : opt.tags = [];
287
360
  _iterator = _createForOfIteratorHelper(opt.tags);
288
361
  try {
289
362
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
290
- _v = _step.value;
291
- if (_v.name === "Type") ex = true;
363
+ v = _step.value;
364
+ if (v.name === "Type") ex = true;
292
365
  }
293
366
  } catch (err) {
294
367
  _iterator.e(err);
@@ -297,48 +370,261 @@ var connect = exports.connect = function connect() {
297
370
  }
298
371
  if (!ex) opt.tags.push({
299
372
  name: "Type",
300
- value: "Message"
373
+ value: "Process"
301
374
  });
302
- _context4.next = 7;
375
+ _context4.next = 25;
303
376
  return parse(opt);
304
- case 7:
377
+ case 25:
305
378
  _yield$parse2 = _context4.sent;
306
379
  id = _yield$parse2.id;
307
380
  owner = _yield$parse2.owner;
308
- _context4.prev = 10;
309
- msg = genMsg(p, (_opt$data2 = opt.data) !== null && _opt$data2 !== void 0 ? _opt$data2 : "", opt.tags, (_opt$from = opt.from) !== null && _opt$from !== void 0 ? _opt$from : owner, mu.addr);
381
+ _tags = (0, _utils.tags)(opt.tags);
382
+ res = null;
383
+ memory = null;
384
+ p = {
385
+ id: id,
386
+ handle: _module.handle,
387
+ module: _module.id,
388
+ memory: memory,
389
+ owner: owner,
390
+ height: 0,
391
+ res: _defineProperty({}, id, res),
392
+ results: [id],
393
+ txs: [],
394
+ opt: opt
395
+ };
396
+ if (!_tags["On-Boot"]) {
397
+ _context4.next = 46;
398
+ break;
399
+ }
400
+ data = "";
401
+ if (_tags["On-Boot"] === "Data") data = (_opt$data2 = opt.data) !== null && _opt$data2 !== void 0 ? _opt$data2 : "";else data = (_msgs$_tags$OnBoot$d = (_msgs$_tags$OnBoot = msgs[_tags["On-Boot"]]) === null || _msgs$_tags$OnBoot === void 0 ? void 0 : _msgs$_tags$OnBoot.data) !== null && _msgs$_tags$OnBoot$d !== void 0 ? _msgs$_tags$OnBoot$d : "";
402
+ msg = genMsg(p, data, opt.tags, owner, mu.addr, true);
310
403
  _env = genEnv({
311
404
  pid: p.id,
312
405
  owner: p.owner,
313
406
  module: p.module,
314
407
  auth: mu.addr
315
408
  });
316
- _context4.next = 15;
317
- return p.handle(p.memory, msg, _env);
318
- case 15:
409
+ _t = (0, _utils.tags)(msg.Tags);
410
+ _context4.next = 40;
411
+ return _module.handle(null, msg, _env);
412
+ case 40:
319
413
  res = _context4.sent;
320
414
  p.memory = res.Memory;
321
415
  delete res.Memory;
322
416
  p.res[id] = res;
417
+ _context4.next = 47;
418
+ break;
419
+ case 46:
420
+ p.height += 1;
421
+ case 47:
422
+ msgs[id] = opt;
423
+ env[id] = p;
424
+ if (!_tags["Cron-Interval"]) {
425
+ _context4.next = 73;
426
+ break;
427
+ }
428
+ _tags$CronInterval$s = _tags["Cron-Interval"].split("-"), _tags$CronInterval$s2 = _slicedToArray(_tags$CronInterval$s, 2), num = _tags$CronInterval$s2[0], unit = _tags$CronInterval$s2[1];
429
+ _int = 0;
430
+ _context4.t0 = unit.replace(/s$/, "");
431
+ _context4.next = _context4.t0 === "millisecond" ? 55 : _context4.t0 === "second" ? 57 : _context4.t0 === "minute" ? 59 : _context4.t0 === "hour" ? 61 : _context4.t0 === "day" ? 63 : _context4.t0 === "month" ? 65 : _context4.t0 === "year" ? 67 : 69;
432
+ break;
433
+ case 55:
434
+ _int = num;
435
+ return _context4.abrupt("break", 69);
436
+ case 57:
437
+ _int = num * 1000;
438
+ return _context4.abrupt("break", 69);
439
+ case 59:
440
+ _int = num * 1000 * 60;
441
+ return _context4.abrupt("break", 69);
442
+ case 61:
443
+ _int = num * 1000 * 60 * 60;
444
+ return _context4.abrupt("break", 69);
445
+ case 63:
446
+ _int = num * 1000 * 60 * 60 * 24;
447
+ return _context4.abrupt("break", 69);
448
+ case 65:
449
+ _int = num * 1000 * 60 * 60 * 24 * 30;
450
+ return _context4.abrupt("break", 69);
451
+ case 67:
452
+ _int = num * 1000 * 60 * 60 * 24 * 365;
453
+ return _context4.abrupt("break", 69);
454
+ case 69:
455
+ cronTags = [];
456
+ for (k in _tags) {
457
+ if (/^Cron-Tag-/.test(k)) {
458
+ cronTags.push({
459
+ name: k.replace(/Cron-Tag-/, ""),
460
+ value: _tags[k]
461
+ });
462
+ }
463
+ }
464
+ env[id].cronTags = cronTags;
465
+ env[id].span = _int;
466
+ case 73:
467
+ return _context4.abrupt("return", id);
468
+ case 74:
469
+ case "end":
470
+ return _context4.stop();
471
+ }
472
+ }, _callee4);
473
+ }));
474
+ return function spawn() {
475
+ return _ref8.apply(this, arguments);
476
+ };
477
+ }();
478
+ var assign = /*#__PURE__*/function () {
479
+ var _ref9 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(opt) {
480
+ var p, _opt, _yield$parse3, id, owner, _opt$data3, _opt$from, _res$Messages, msg, _env, res, _iterator2, _step2, v;
481
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
482
+ while (1) switch (_context5.prev = _context5.next) {
483
+ case 0:
484
+ p = env[opt.process];
485
+ _opt = (0, _ramda.clone)(msgs[opt.message]);
486
+ _context5.next = 4;
487
+ return parse(_opt);
488
+ case 4:
489
+ _yield$parse3 = _context5.sent;
490
+ id = _yield$parse3.id;
491
+ owner = _yield$parse3.owner;
492
+ _context5.prev = 7;
493
+ msg = genMsg(p, (_opt$data3 = _opt.data) !== null && _opt$data3 !== void 0 ? _opt$data3 : "", _opt.tags, (_opt$from = _opt.from) !== null && _opt$from !== void 0 ? _opt$from : owner, mu.addr);
494
+ _env = genEnv({
495
+ pid: p.id,
496
+ owner: p.owner,
497
+ module: p.module,
498
+ auth: mu.addr
499
+ });
500
+ _context5.next = 12;
501
+ return p.handle(p.memory, msg, _env);
502
+ case 12:
503
+ res = _context5.sent;
504
+ p.memory = res.Memory;
505
+ delete res.Memory;
506
+ p.res[id] = res;
323
507
  p.results.push(id);
324
508
  p.txs.unshift(_objectSpread({
325
509
  id: id
326
- }, opt));
327
- env.msgs[id] = opt;
510
+ }, _opt));
511
+ msgs[id] = _opt;
328
512
  _iterator2 = _createForOfIteratorHelper((_res$Messages = res.Messages) !== null && _res$Messages !== void 0 ? _res$Messages : []);
329
- _context4.prev = 23;
513
+ _context5.prev = 20;
330
514
  _iterator2.s();
331
- case 25:
515
+ case 22:
332
516
  if ((_step2 = _iterator2.n()).done) {
333
- _context4.next = 32;
517
+ _context5.next = 29;
334
518
  break;
335
519
  }
336
520
  v = _step2.value;
337
521
  if (!env[v.Target]) {
338
- _context4.next = 30;
522
+ _context5.next = 27;
339
523
  break;
340
524
  }
341
- _context4.next = 30;
525
+ _context5.next = 27;
526
+ return _message({
527
+ process: v.Target,
528
+ tags: v.Tags,
529
+ data: v.Data,
530
+ signer: mu.signer,
531
+ from: opt.process
532
+ });
533
+ case 27:
534
+ _context5.next = 22;
535
+ break;
536
+ case 29:
537
+ _context5.next = 34;
538
+ break;
539
+ case 31:
540
+ _context5.prev = 31;
541
+ _context5.t0 = _context5["catch"](20);
542
+ _iterator2.e(_context5.t0);
543
+ case 34:
544
+ _context5.prev = 34;
545
+ _iterator2.f();
546
+ return _context5.finish(34);
547
+ case 37:
548
+ return _context5.abrupt("return", id);
549
+ case 40:
550
+ _context5.prev = 40;
551
+ _context5.t1 = _context5["catch"](7);
552
+ console.log(_context5.t1);
553
+ case 43:
554
+ return _context5.abrupt("return", null);
555
+ case 44:
556
+ case "end":
557
+ return _context5.stop();
558
+ }
559
+ }, _callee5, null, [[7, 40], [20, 31, 34, 37]]);
560
+ }));
561
+ return function assign(_x3) {
562
+ return _ref9.apply(this, arguments);
563
+ };
564
+ }();
565
+ var _message = /*#__PURE__*/function () {
566
+ var _ref10 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(opt) {
567
+ var p, ex, _iterator3, _step3, _v3, _yield$parse4, id, owner, _opt$data4, _opt$from2, _res$Messages2, _res$Spawns, _res$Assignments, msg, _env, res, _iterator4, _step4, v, _iterator5, _step5, _v, _tags, _iterator6, _step6, _v2, _iterator7, _step7, v2;
568
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
569
+ while (1) switch (_context6.prev = _context6.next) {
570
+ case 0:
571
+ p = env[opt.process];
572
+ ex = false;
573
+ _iterator3 = _createForOfIteratorHelper(opt.tags);
574
+ try {
575
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
576
+ _v3 = _step3.value;
577
+ if (_v3.name === "Type") ex = true;
578
+ }
579
+ } catch (err) {
580
+ _iterator3.e(err);
581
+ } finally {
582
+ _iterator3.f();
583
+ }
584
+ if (!ex) opt.tags.push({
585
+ name: "Type",
586
+ value: "Message"
587
+ });
588
+ _context6.next = 7;
589
+ return parse(opt);
590
+ case 7:
591
+ _yield$parse4 = _context6.sent;
592
+ id = _yield$parse4.id;
593
+ owner = _yield$parse4.owner;
594
+ _context6.prev = 10;
595
+ msg = genMsg(p, (_opt$data4 = opt.data) !== null && _opt$data4 !== void 0 ? _opt$data4 : "", opt.tags, (_opt$from2 = opt.from) !== null && _opt$from2 !== void 0 ? _opt$from2 : owner, mu.addr);
596
+ _env = genEnv({
597
+ pid: p.id,
598
+ owner: p.owner,
599
+ module: p.module,
600
+ auth: mu.addr
601
+ });
602
+ _context6.next = 15;
603
+ return p.handle(p.memory, msg, _env);
604
+ case 15:
605
+ res = _context6.sent;
606
+ p.memory = res.Memory;
607
+ delete res.Memory;
608
+ p.res[id] = res;
609
+ p.results.push(id);
610
+ p.txs.unshift(_objectSpread({
611
+ id: id
612
+ }, opt));
613
+ msgs[id] = opt;
614
+ _iterator4 = _createForOfIteratorHelper((_res$Messages2 = res.Messages) !== null && _res$Messages2 !== void 0 ? _res$Messages2 : []);
615
+ _context6.prev = 23;
616
+ _iterator4.s();
617
+ case 25:
618
+ if ((_step4 = _iterator4.n()).done) {
619
+ _context6.next = 32;
620
+ break;
621
+ }
622
+ v = _step4.value;
623
+ if (!env[v.Target]) {
624
+ _context6.next = 30;
625
+ break;
626
+ }
627
+ _context6.next = 30;
342
628
  return _message({
343
629
  process: v.Target,
344
630
  tags: v.Tags,
@@ -347,345 +633,260 @@ var connect = exports.connect = function connect() {
347
633
  from: opt.process
348
634
  });
349
635
  case 30:
350
- _context4.next = 25;
636
+ _context6.next = 25;
351
637
  break;
352
638
  case 32:
353
- _context4.next = 37;
639
+ _context6.next = 37;
354
640
  break;
355
641
  case 34:
356
- _context4.prev = 34;
357
- _context4.t0 = _context4["catch"](23);
358
- _iterator2.e(_context4.t0);
642
+ _context6.prev = 34;
643
+ _context6.t0 = _context6["catch"](23);
644
+ _iterator4.e(_context6.t0);
359
645
  case 37:
360
- _context4.prev = 37;
361
- _iterator2.f();
362
- return _context4.finish(37);
646
+ _context6.prev = 37;
647
+ _iterator4.f();
648
+ return _context6.finish(37);
363
649
  case 40:
364
- return _context4.abrupt("return", id);
650
+ _iterator5 = _createForOfIteratorHelper((_res$Spawns = res.Spawns) !== null && _res$Spawns !== void 0 ? _res$Spawns : []);
651
+ _context6.prev = 41;
652
+ _iterator5.s();
365
653
  case 43:
366
- _context4.prev = 43;
367
- _context4.t1 = _context4["catch"](10);
368
- console.log(_context4.t1);
369
- case 46:
370
- return _context4.abrupt("return", null);
371
- case 47:
654
+ if ((_step5 = _iterator5.n()).done) {
655
+ _context6.next = 50;
656
+ break;
657
+ }
658
+ _v = _step5.value;
659
+ _tags = (0, _utils.tags)(_v.Tags);
660
+ _context6.next = 48;
661
+ return spawn({
662
+ module: _tags.Module,
663
+ scheduler: scheduler,
664
+ tags: _v.Tags,
665
+ data: _v.Data,
666
+ from: _tags["From-Process"],
667
+ signer: mu.signer
668
+ });
669
+ case 48:
670
+ _context6.next = 43;
671
+ break;
672
+ case 50:
673
+ _context6.next = 55;
674
+ break;
675
+ case 52:
676
+ _context6.prev = 52;
677
+ _context6.t1 = _context6["catch"](41);
678
+ _iterator5.e(_context6.t1);
679
+ case 55:
680
+ _context6.prev = 55;
681
+ _iterator5.f();
682
+ return _context6.finish(55);
683
+ case 58:
684
+ _iterator6 = _createForOfIteratorHelper((_res$Assignments = res.Assignments) !== null && _res$Assignments !== void 0 ? _res$Assignments : []);
685
+ _context6.prev = 59;
686
+ _iterator6.s();
687
+ case 61:
688
+ if ((_step6 = _iterator6.n()).done) {
689
+ _context6.next = 82;
690
+ break;
691
+ }
692
+ _v2 = _step6.value;
693
+ _iterator7 = _createForOfIteratorHelper(_v2.Processes);
694
+ _context6.prev = 64;
695
+ _iterator7.s();
696
+ case 66:
697
+ if ((_step7 = _iterator7.n()).done) {
698
+ _context6.next = 72;
699
+ break;
700
+ }
701
+ v2 = _step7.value;
702
+ _context6.next = 70;
703
+ return assign({
704
+ message: _v2.Message,
705
+ process: v2,
706
+ from: opt.process,
707
+ signer: mu.signer
708
+ });
709
+ case 70:
710
+ _context6.next = 66;
711
+ break;
712
+ case 72:
713
+ _context6.next = 77;
714
+ break;
715
+ case 74:
716
+ _context6.prev = 74;
717
+ _context6.t2 = _context6["catch"](64);
718
+ _iterator7.e(_context6.t2);
719
+ case 77:
720
+ _context6.prev = 77;
721
+ _iterator7.f();
722
+ return _context6.finish(77);
723
+ case 80:
724
+ _context6.next = 61;
725
+ break;
726
+ case 82:
727
+ _context6.next = 87;
728
+ break;
729
+ case 84:
730
+ _context6.prev = 84;
731
+ _context6.t3 = _context6["catch"](59);
732
+ _iterator6.e(_context6.t3);
733
+ case 87:
734
+ _context6.prev = 87;
735
+ _iterator6.f();
736
+ return _context6.finish(87);
737
+ case 90:
738
+ return _context6.abrupt("return", id);
739
+ case 93:
740
+ _context6.prev = 93;
741
+ _context6.t4 = _context6["catch"](10);
742
+ console.log(_context6.t4);
743
+ case 96:
744
+ return _context6.abrupt("return", null);
745
+ case 97:
372
746
  case "end":
373
- return _context4.stop();
747
+ return _context6.stop();
374
748
  }
375
- }, _callee4, null, [[10, 43], [23, 34, 37, 40]]);
749
+ }, _callee6, null, [[10, 93], [23, 34, 37, 40], [41, 52, 55, 58], [59, 84, 87, 90], [64, 74, 77, 80]]);
376
750
  }));
377
- return function message(_x3) {
378
- return _ref8.apply(this, arguments);
751
+ return function message(_x4) {
752
+ return _ref10.apply(this, arguments);
379
753
  };
380
754
  }();
381
755
  return {
382
- scheduler: "GQ33BkPtZrqxA84vM8Zk-N2aO0toNNu_C-l-rawrBA",
756
+ scheduler: scheduler,
383
757
  modules: modules,
384
758
  accounts: acc,
759
+ mu: mu,
385
760
  message: _message,
386
- txs: function () {
387
- var _txs2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(pid) {
388
- var _txs, _iterator3, _step3, v;
389
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
390
- while (1) switch (_context5.prev = _context5.next) {
761
+ unmonitor: function () {
762
+ var _unmonitor = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(opt) {
763
+ var p;
764
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
765
+ while (1) switch (_context7.prev = _context7.next) {
391
766
  case 0:
392
- _txs = [];
393
- _iterator3 = _createForOfIteratorHelper(env[pid].txs);
767
+ p = env[opt.process];
394
768
  try {
395
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
396
- v = _step3.value;
397
- _txs.push({
398
- tags: v.tags,
399
- id: v.id
400
- });
401
- }
402
- } catch (err) {
403
- _iterator3.e(err);
404
- } finally {
405
- _iterator3.f();
406
- }
407
- return _context5.abrupt("return", _txs);
408
- case 4:
769
+ clearInterval(p.cron);
770
+ p.cron = null;
771
+ } catch (e) {}
772
+ case 2:
409
773
  case "end":
410
- return _context5.stop();
774
+ return _context7.stop();
411
775
  }
412
- }, _callee5);
776
+ }, _callee7);
413
777
  }));
414
- function txs(_x4) {
415
- return _txs2.apply(this, arguments);
778
+ function unmonitor(_x5) {
779
+ return _unmonitor.apply(this, arguments);
416
780
  }
417
- return txs;
781
+ return unmonitor;
418
782
  }(),
419
- spawn: function () {
420
- var _spawn = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
421
- var _opt$module, _opt$tags;
422
- var opt,
423
- mod,
424
- _dirname,
425
- wasm,
426
- handle,
427
- _module,
428
- ex,
429
- _iterator4,
430
- _step4,
431
- v,
432
- _yield$parse3,
433
- id,
434
- owner,
435
- _tags,
436
- res,
437
- memory,
438
- p,
439
- _opt$data3,
440
- _env$msgs$_tags$OnBo,
441
- _env$msgs$_tags$OnBo2,
442
- data,
443
- msg,
444
- _env,
445
- _args6 = arguments;
446
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
447
- while (1) switch (_context6.prev = _context6.next) {
783
+ monitor: function () {
784
+ var _monitor = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(opt) {
785
+ var p;
786
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
787
+ while (1) switch (_context9.prev = _context9.next) {
448
788
  case 0:
449
- opt = _args6.length > 0 && _args6[0] !== undefined ? _args6[0] : {};
450
- if (opt.module) {
451
- _context6.next = 3;
452
- break;
453
- }
454
- throw Error("module.missing");
455
- case 3:
456
- if (opt.scheduler) {
457
- _context6.next = 5;
458
- break;
459
- }
460
- throw Error("scheduler.missing");
461
- case 5:
462
- mod = (_opt$module = opt.module) !== null && _opt$module !== void 0 ? _opt$module : modules["aos_2_0_1"];
463
- if (!(!modmap[mod] && wasms[mod])) {
464
- _context6.next = 15;
465
- break;
466
- }
467
- _context6.next = 9;
468
- return dirname();
469
- case 9:
470
- _dirname = _context6.sent;
471
- wasm = (0, _fs.readFileSync)((0, _path.resolve)(_dirname, "lua/".concat(wasms[mod].file, ".wasm")));
472
- _context6.next = 13;
473
- return (0, _aoLoader["default"])(wasm, {
474
- format: wasms[mod].format
475
- });
476
- case 13:
477
- handle = _context6.sent;
478
- modmap[mod] = {
479
- handle: handle,
480
- id: mod
481
- };
482
- case 15:
483
- if (mod) {
484
- _context6.next = 17;
485
- break;
486
- }
487
- throw Error("module not found");
488
- case 17:
489
- _module = modmap[mod];
490
- ex = false;
491
- (_opt$tags = opt.tags) !== null && _opt$tags !== void 0 ? _opt$tags : opt.tags = [];
492
- _iterator4 = _createForOfIteratorHelper(opt.tags);
493
- try {
494
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
495
- v = _step4.value;
496
- if (v.name === "Type") ex = true;
497
- }
498
- } catch (err) {
499
- _iterator4.e(err);
500
- } finally {
501
- _iterator4.f();
502
- }
503
- if (!ex) opt.tags.push({
504
- name: "Type",
505
- value: "Process"
506
- });
507
- _context6.next = 25;
508
- return parse(opt);
509
- case 25:
510
- _yield$parse3 = _context6.sent;
511
- id = _yield$parse3.id;
512
- owner = _yield$parse3.owner;
513
- _tags = (0, _utils.tags)(opt.tags);
514
- res = null;
515
- memory = null;
516
- p = {
517
- id: id,
518
- handle: _module.handle,
519
- module: _module.id,
520
- memory: memory,
521
- owner: owner,
522
- height: 0,
523
- res: _defineProperty({}, id, res),
524
- results: [id],
525
- txs: []
526
- };
527
- if (!_tags["On-Boot"]) {
528
- _context6.next = 45;
529
- break;
789
+ p = env[opt.process];
790
+ if ((0, _ramda.isNil)(p.cron)) {
791
+ p.cron = setInterval(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
792
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
793
+ while (1) switch (_context8.prev = _context8.next) {
794
+ case 0:
795
+ _context8.next = 2;
796
+ return _message({
797
+ tags: p.cronTags,
798
+ process: opt.process,
799
+ signer: mu.signer,
800
+ from: mu.addr
801
+ });
802
+ case 2:
803
+ case "end":
804
+ return _context8.stop();
805
+ }
806
+ }, _callee8);
807
+ })), p.span);
530
808
  }
531
- data = "";
532
- if (_tags["On-Boot"] === "Data") data = (_opt$data3 = opt.data) !== null && _opt$data3 !== void 0 ? _opt$data3 : "";else data = (_env$msgs$_tags$OnBo = (_env$msgs$_tags$OnBo2 = env.msgs[_tags["On-Boot"]]) === null || _env$msgs$_tags$OnBo2 === void 0 ? void 0 : _env$msgs$_tags$OnBo2.data) !== null && _env$msgs$_tags$OnBo !== void 0 ? _env$msgs$_tags$OnBo : "";
533
- msg = genMsg(p, data, opt.tags, owner, mu.addr, true);
534
- _env = genEnv({
535
- pid: p.id,
536
- owner: p.owner,
537
- module: p.module,
538
- auth: mu.addr
539
- });
540
- _context6.next = 39;
541
- return _module.handle(null, msg, _env);
542
- case 39:
543
- res = _context6.sent;
544
- memory = res.Memory;
545
- delete res.Memory;
546
- p.res[id] = res;
547
- _context6.next = 46;
548
- break;
549
- case 45:
550
- p.height += 1;
551
- case 46:
552
- env.msgs[id] = opt;
553
- env[id] = p;
554
- return _context6.abrupt("return", id);
555
- case 49:
809
+ case 2:
556
810
  case "end":
557
- return _context6.stop();
811
+ return _context9.stop();
558
812
  }
559
- }, _callee6);
813
+ }, _callee9);
560
814
  }));
561
- function spawn() {
562
- return _spawn.apply(this, arguments);
815
+ function monitor(_x6) {
816
+ return _monitor.apply(this, arguments);
563
817
  }
564
- return spawn;
818
+ return monitor;
565
819
  }(),
566
- assign: function () {
567
- var _assign = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(opt) {
568
- var p, _opt, _yield$parse4, id, owner, _opt$data4, _opt$from2, _res$Messages2, msg, _env, res, _iterator5, _step5, v;
569
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
570
- while (1) switch (_context7.prev = _context7.next) {
820
+ txs: function () {
821
+ var _txs2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(pid) {
822
+ var _txs, _iterator8, _step8, v;
823
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
824
+ while (1) switch (_context10.prev = _context10.next) {
571
825
  case 0:
572
- p = env[opt.process];
573
- _opt = (0, _ramda.clone)(env.msgs[opt.message]);
574
- _context7.next = 4;
575
- return parse(_opt);
576
- case 4:
577
- _yield$parse4 = _context7.sent;
578
- id = _yield$parse4.id;
579
- owner = _yield$parse4.owner;
580
- _context7.prev = 7;
581
- msg = genMsg(p, (_opt$data4 = _opt.data) !== null && _opt$data4 !== void 0 ? _opt$data4 : "", _opt.tags, (_opt$from2 = _opt.from) !== null && _opt$from2 !== void 0 ? _opt$from2 : owner, mu.addr);
582
- _env = genEnv({
583
- pid: p.id,
584
- owner: p.owner,
585
- module: p.module,
586
- auth: mu.addr
587
- });
588
- _context7.next = 12;
589
- return p.handle(p.memory, msg, _env);
590
- case 12:
591
- res = _context7.sent;
592
- p.memory = res.Memory;
593
- delete res.Memory;
594
- p.res[id] = res;
595
- p.results.push(id);
596
- p.txs.unshift(_objectSpread({
597
- id: id
598
- }, _opt));
599
- env.msgs[id] = _opt;
600
- _iterator5 = _createForOfIteratorHelper((_res$Messages2 = res.Messages) !== null && _res$Messages2 !== void 0 ? _res$Messages2 : []);
601
- _context7.prev = 20;
602
- _iterator5.s();
603
- case 22:
604
- if ((_step5 = _iterator5.n()).done) {
605
- _context7.next = 29;
606
- break;
607
- }
608
- v = _step5.value;
609
- if (!env[v.Target]) {
610
- _context7.next = 27;
611
- break;
826
+ _txs = [];
827
+ _iterator8 = _createForOfIteratorHelper(env[pid].txs);
828
+ try {
829
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
830
+ v = _step8.value;
831
+ _txs.push({
832
+ tags: v.tags,
833
+ id: v.id
834
+ });
835
+ }
836
+ } catch (err) {
837
+ _iterator8.e(err);
838
+ } finally {
839
+ _iterator8.f();
612
840
  }
613
- _context7.next = 27;
614
- return _message({
615
- process: v.Target,
616
- tags: v.Tags,
617
- data: v.Data,
618
- signer: mu.signer,
619
- from: opt.process
620
- });
621
- case 27:
622
- _context7.next = 22;
623
- break;
624
- case 29:
625
- _context7.next = 34;
626
- break;
627
- case 31:
628
- _context7.prev = 31;
629
- _context7.t0 = _context7["catch"](20);
630
- _iterator5.e(_context7.t0);
631
- case 34:
632
- _context7.prev = 34;
633
- _iterator5.f();
634
- return _context7.finish(34);
635
- case 37:
636
- return _context7.abrupt("return", id);
637
- case 40:
638
- _context7.prev = 40;
639
- _context7.t1 = _context7["catch"](7);
640
- console.log(_context7.t1);
641
- case 43:
642
- return _context7.abrupt("return", null);
643
- case 44:
841
+ return _context10.abrupt("return", _txs);
842
+ case 4:
644
843
  case "end":
645
- return _context7.stop();
844
+ return _context10.stop();
646
845
  }
647
- }, _callee7, null, [[7, 40], [20, 31, 34, 37]]);
846
+ }, _callee10);
648
847
  }));
649
- function assign(_x5) {
650
- return _assign.apply(this, arguments);
848
+ function txs(_x7) {
849
+ return _txs2.apply(this, arguments);
651
850
  }
652
- return assign;
851
+ return txs;
653
852
  }(),
853
+ spawn: spawn,
854
+ assign: assign,
654
855
  result: function () {
655
- var _result = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(opt) {
656
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
657
- while (1) switch (_context8.prev = _context8.next) {
856
+ var _result = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(opt) {
857
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
858
+ while (1) switch (_context11.prev = _context11.next) {
658
859
  case 0:
659
- return _context8.abrupt("return", env[opt.process].res[opt.message]);
860
+ return _context11.abrupt("return", env[opt.process].res[opt.message]);
660
861
  case 1:
661
862
  case "end":
662
- return _context8.stop();
863
+ return _context11.stop();
663
864
  }
664
- }, _callee8);
865
+ }, _callee11);
665
866
  }));
666
- function result(_x6) {
867
+ function result(_x8) {
667
868
  return _result.apply(this, arguments);
668
869
  }
669
870
  return result;
670
871
  }(),
671
872
  results: function () {
672
- var _results = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(opt) {
873
+ var _results = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee12(opt) {
673
874
  var _opt$limit;
674
875
  var p, results, limit, i, _i;
675
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
676
- while (1) switch (_context9.prev = _context9.next) {
876
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
877
+ while (1) switch (_context12.prev = _context12.next) {
677
878
  case 0:
678
879
  p = env[opt.process];
679
880
  results = [];
680
881
  limit = (_opt$limit = opt.limit) !== null && _opt$limit !== void 0 ? _opt$limit : 25;
681
882
  if (!(opt.sort === "DESC")) {
682
- _context9.next = 14;
883
+ _context12.next = 14;
683
884
  break;
684
885
  }
685
886
  i = p.results.length - 1;
686
887
  case 5:
687
888
  if (!(0 < i)) {
688
- _context9.next = 12;
889
+ _context12.next = 12;
689
890
  break;
690
891
  }
691
892
  results.push({
@@ -693,65 +894,65 @@ var connect = exports.connect = function connect() {
693
894
  node: p.res[p.results[i]]
694
895
  });
695
896
  if (!(results.length >= limit)) {
696
- _context9.next = 9;
897
+ _context12.next = 9;
697
898
  break;
698
899
  }
699
- return _context9.abrupt("break", 12);
900
+ return _context12.abrupt("break", 12);
700
901
  case 9:
701
902
  i--;
702
- _context9.next = 5;
903
+ _context12.next = 5;
703
904
  break;
704
905
  case 12:
705
- _context9.next = 22;
906
+ _context12.next = 22;
706
907
  break;
707
908
  case 14:
708
909
  _i = 0;
709
910
  case 15:
710
911
  if (!(_i < p.results.length)) {
711
- _context9.next = 22;
912
+ _context12.next = 22;
712
913
  break;
713
914
  }
714
915
  results.push({
715
916
  node: p.res[p.results[_i]]
716
917
  });
717
918
  if (!(results.length >= limit)) {
718
- _context9.next = 19;
919
+ _context12.next = 19;
719
920
  break;
720
921
  }
721
- return _context9.abrupt("break", 22);
922
+ return _context12.abrupt("break", 22);
722
923
  case 19:
723
924
  _i++;
724
- _context9.next = 15;
925
+ _context12.next = 15;
725
926
  break;
726
927
  case 22:
727
- return _context9.abrupt("return", {
928
+ return _context12.abrupt("return", {
728
929
  edges: results
729
930
  });
730
931
  case 23:
731
932
  case "end":
732
- return _context9.stop();
933
+ return _context12.stop();
733
934
  }
734
- }, _callee9);
935
+ }, _callee12);
735
936
  }));
736
- function results(_x7) {
937
+ function results(_x9) {
737
938
  return _results.apply(this, arguments);
738
939
  }
739
940
  return results;
740
941
  }(),
741
942
  dryrun: function () {
742
- var _dryrun = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(opt) {
943
+ var _dryrun = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee13(opt) {
743
944
  var p, _yield$parse5, id, owner, _opt$data5, msg, _env, res;
744
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
745
- while (1) switch (_context10.prev = _context10.next) {
945
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
946
+ while (1) switch (_context13.prev = _context13.next) {
746
947
  case 0:
747
948
  p = env[opt.process];
748
- _context10.next = 3;
949
+ _context13.next = 3;
749
950
  return parse(opt);
750
951
  case 3:
751
- _yield$parse5 = _context10.sent;
952
+ _yield$parse5 = _context13.sent;
752
953
  id = _yield$parse5.id;
753
954
  owner = _yield$parse5.owner;
754
- _context10.prev = 6;
955
+ _context13.prev = 6;
755
956
  msg = genMsg(p, (_opt$data5 = opt.data) !== null && _opt$data5 !== void 0 ? _opt$data5 : "", opt.tags, owner, mu.addr, true);
756
957
  _env = genEnv({
757
958
  pid: p.id,
@@ -759,27 +960,30 @@ var connect = exports.connect = function connect() {
759
960
  module: p.module,
760
961
  auth: mu.addr
761
962
  });
762
- _context10.next = 11;
963
+ _context13.next = 11;
763
964
  return p.handle(p.memory, msg, _env);
764
965
  case 11:
765
- res = _context10.sent;
766
- return _context10.abrupt("return", res);
966
+ res = _context13.sent;
967
+ return _context13.abrupt("return", res);
767
968
  case 15:
768
- _context10.prev = 15;
769
- _context10.t0 = _context10["catch"](6);
770
- console.log(_context10.t0);
969
+ _context13.prev = 15;
970
+ _context13.t0 = _context13["catch"](6);
971
+ console.log(_context13.t0);
771
972
  case 18:
772
- return _context10.abrupt("return", null);
973
+ return _context13.abrupt("return", null);
773
974
  case 19:
774
975
  case "end":
775
- return _context10.stop();
976
+ return _context13.stop();
776
977
  }
777
- }, _callee10, null, [[6, 15]]);
978
+ }, _callee13, null, [[6, 15]]);
778
979
  }));
779
- function dryrun(_x8) {
980
+ function dryrun(_x10) {
780
981
  return _dryrun.apply(this, arguments);
781
982
  }
782
983
  return dryrun;
783
- }()
984
+ }(),
985
+ getProcesses: function getProcesses() {
986
+ return env;
987
+ }
784
988
  };
785
989
  };