wao 0.40.1 → 0.41.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.
Files changed (76) hide show
  1. package/cjs/accounts-web.js +25 -0
  2. package/cjs/accounts.js +38 -0
  3. package/cjs/adaptor-base.js +504 -287
  4. package/cjs/adaptor-cf.js +42 -0
  5. package/cjs/ao-loader.js +1 -1
  6. package/cjs/ao.js +22 -10
  7. package/cjs/aoconnect-base.js +1010 -546
  8. package/cjs/aoconnect-cf.js +24 -0
  9. package/cjs/ar-remote.js +277 -0
  10. package/cjs/armem-base.js +822 -211
  11. package/cjs/armem-cf.js +128 -0
  12. package/cjs/armem.js +11 -5
  13. package/cjs/bar.js +511 -173
  14. package/cjs/car.js +37 -0
  15. package/cjs/cf-env.js +54 -0
  16. package/cjs/cf.js +76 -0
  17. package/cjs/cli.js +12 -6
  18. package/cjs/create.js +1 -1
  19. package/cjs/devs.js +53 -0
  20. package/cjs/dodb.js +116 -0
  21. package/cjs/hb.js +136 -53
  22. package/cjs/hyperbeam.js +85 -44
  23. package/cjs/keygen.js +94 -0
  24. package/cjs/run.js +4 -1
  25. package/cjs/server.js +40 -9
  26. package/cjs/storage-multi.js +525 -0
  27. package/cjs/tgql-d1.js +664 -0
  28. package/cjs/tgql.js +293 -172
  29. package/cjs/workspace/.claude/agents/tester.md +2 -2
  30. package/cjs/workspace/.claude/skills/build/SKILL.md +2 -2
  31. package/cjs/workspace/.claude/skills/test/SKILL.md +3 -2
  32. package/cjs/workspace/CLAUDE.md +2 -2
  33. package/cjs/workspace/README.md +1 -1
  34. package/cjs/workspace/docs/debug.md +9 -4
  35. package/cjs/workspace/docs/hyperbeam-devices.md +50 -1
  36. package/cjs/workspace/docs/wao-sdk.md +1 -1
  37. package/cjs/workspace/package.json +4 -4
  38. package/esm/accounts-web.js +14 -0
  39. package/esm/accounts.js +27 -0
  40. package/esm/adaptor-base.js +129 -31
  41. package/esm/adaptor-cf.js +11 -0
  42. package/esm/ao-loader.js +1 -1
  43. package/esm/ao.js +24 -5
  44. package/esm/aoconnect-base.js +248 -7
  45. package/esm/aoconnect-cf.js +9 -0
  46. package/esm/ar-remote.js +87 -0
  47. package/esm/armem-base.js +304 -53
  48. package/esm/armem-cf.js +67 -0
  49. package/esm/armem.js +7 -2
  50. package/esm/bar.js +126 -16
  51. package/esm/car.js +10 -0
  52. package/esm/cf-env.js +29 -0
  53. package/esm/cf.js +11 -0
  54. package/esm/cli.js +6 -2
  55. package/esm/create.js +1 -1
  56. package/esm/devs.js +15 -0
  57. package/esm/dodb.js +26 -0
  58. package/esm/hb.js +93 -16
  59. package/esm/hyperbeam.js +68 -30
  60. package/esm/keygen.js +47 -0
  61. package/esm/run.js +4 -1
  62. package/esm/server.js +29 -9
  63. package/esm/storage-multi.js +183 -0
  64. package/esm/tgql-d1.js +407 -0
  65. package/esm/tgql.js +29 -10
  66. package/esm/workspace/.claude/agents/tester.md +2 -2
  67. package/esm/workspace/.claude/skills/build/SKILL.md +2 -2
  68. package/esm/workspace/.claude/skills/test/SKILL.md +3 -2
  69. package/esm/workspace/CLAUDE.md +2 -2
  70. package/esm/workspace/README.md +1 -1
  71. package/esm/workspace/docs/debug.md +9 -4
  72. package/esm/workspace/docs/hyperbeam-devices.md +50 -1
  73. package/esm/workspace/docs/wao-sdk.md +1 -1
  74. package/esm/workspace/package.json +4 -4
  75. package/package.json +10 -3
  76. package/postinstall.cjs +84 -0
@@ -28,18 +28,47 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
28
28
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
29
29
  var Adaptor = /*#__PURE__*/function () {
30
30
  function Adaptor(_ref) {
31
+ var _this = this,
32
+ _this$_chunkCleanupIn;
31
33
  var hb_url = _ref.hb_url,
32
34
  aoconnect = _ref.aoconnect,
33
35
  _ref$log = _ref.log,
34
36
  log = _ref$log === void 0 ? false : _ref$log,
35
37
  db = _ref.db,
38
+ storage = _ref.storage,
36
39
  connect = _ref.connect,
37
40
  GQL = _ref.GQL,
38
41
  cu = _ref.cu,
39
42
  su = _ref.su,
40
- mu = _ref.mu;
43
+ mu = _ref.mu,
44
+ d1 = _ref.d1,
45
+ r2 = _ref.r2,
46
+ kv = _ref.kv,
47
+ _ref$network = _ref.network,
48
+ network = _ref$network === void 0 ? "ao.DN.1" : _ref$network;
41
49
  _classCallCheck(this, Adaptor);
50
+ this.network = network;
42
51
  this.data = {};
52
+ this._dataTimestamps = {};
53
+ // Clean up abandoned chunk uploads every 60 seconds.
54
+ // unref() so this interval doesn't keep the Node event loop alive after
55
+ // the host server closes — without it, test processes that use Server
56
+ // (e.g. test/hyperbeam/relay.test.js) hang indefinitely waiting on this
57
+ // timer even after every other handle is cleaned up.
58
+ this._chunkCleanupInterval = setInterval(function () {
59
+ var now = Date.now();
60
+ for (var _i = 0, _Object$keys = Object.keys(_this._dataTimestamps); _i < _Object$keys.length; _i++) {
61
+ var key = _Object$keys[_i];
62
+ if (now - _this._dataTimestamps[key] > 5 * 60 * 1000) {
63
+ // 5 min timeout
64
+ delete _this.data[key];
65
+ delete _this._dataTimestamps[key];
66
+ }
67
+ }
68
+ }, 60 * 1000);
69
+ if (typeof ((_this$_chunkCleanupIn = this._chunkCleanupInterval) === null || _this$_chunkCleanupIn === void 0 ? void 0 : _this$_chunkCleanupIn.unref) === "function") {
70
+ this._chunkCleanupInterval.unref();
71
+ }
43
72
  var hb = null;
44
73
  if (hb_url) hb = new _hb["default"]({
45
74
  url: hb_url
@@ -47,7 +76,11 @@ var Adaptor = /*#__PURE__*/function () {
47
76
  var _connect = connect(aoconnect, {
48
77
  log: log,
49
78
  cache: db,
50
- hb: hb
79
+ storage: storage,
80
+ hb: hb,
81
+ d1: d1,
82
+ r2: r2,
83
+ kv: kv
51
84
  }),
52
85
  _ar = _connect.ar,
53
86
  message = _connect.message,
@@ -58,13 +91,15 @@ var Adaptor = /*#__PURE__*/function () {
58
91
  mem = _connect.mem,
59
92
  monitor = _connect.monitor,
60
93
  unmonitor = _connect.unmonitor,
61
- recover = _connect.recover;
94
+ recover = _connect.recover,
95
+ evaluate = _connect.evaluate;
62
96
  this.su_signer = su;
63
97
  this.cu_signer = cu;
64
98
  this.mu_signer = mu;
65
99
  this.recover = recover;
66
100
  this.monitor = monitor;
67
101
  this.unmonitor = unmonitor;
102
+ this.evaluate = evaluate;
68
103
  this.spawn = spawn;
69
104
  this._ar = _ar;
70
105
  this.message = message;
@@ -73,7 +108,8 @@ var Adaptor = /*#__PURE__*/function () {
73
108
  this.results = results;
74
109
  this.mem = mem;
75
110
  this.gql = new GQL({
76
- mem: mem
111
+ mem: mem,
112
+ d1: d1 || null
77
113
  });
78
114
  }
79
115
  return _createClass(Adaptor, [{
@@ -88,9 +124,7 @@ var Adaptor = /*#__PURE__*/function () {
88
124
  _context.n = 1;
89
125
  return this[req.device](req);
90
126
  case 1:
91
- _t(_context.v);
92
- case 2:
93
- return _context.a(2);
127
+ return _context.a(2, _t(_context.v));
94
128
  }
95
129
  }, _callee, this);
96
130
  }));
@@ -572,7 +606,7 @@ var Adaptor = /*#__PURE__*/function () {
572
606
  while (1) switch (_context15.n) {
573
607
  case 0:
574
608
  _t1 = req.path;
575
- _context15.n = _t1 === "/result/:mid" ? 1 : _t1 === "/dry-run" ? 3 : 5;
609
+ _context15.n = _t1 === "/result/:mid" ? 1 : _t1 === "/dry-run" ? 3 : _t1 === "/evaluate" ? 5 : 7;
576
610
  break;
577
611
  case 1:
578
612
  _context15.n = 2;
@@ -586,10 +620,15 @@ var Adaptor = /*#__PURE__*/function () {
586
620
  return _context15.a(2, _context15.v);
587
621
  case 5:
588
622
  _context15.n = 6;
589
- return this.bad();
623
+ return this.cu_post_evaluate(req);
590
624
  case 6:
591
625
  return _context15.a(2, _context15.v);
592
626
  case 7:
627
+ _context15.n = 8;
628
+ return this.bad();
629
+ case 8:
630
+ return _context15.a(2, _context15.v);
631
+ case 9:
593
632
  return _context15.a(2);
594
633
  }
595
634
  }, _callee15, this);
@@ -790,27 +829,31 @@ var Adaptor = /*#__PURE__*/function () {
790
829
  key: "cu_get_state",
791
830
  value: function () {
792
831
  var _cu_get_state = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee19(_ref5) {
793
- var _this$mem$env$pid$mem, _this$mem$env$pid;
794
- var query, params, body, headers, method, pid, memory;
832
+ var _p$memory;
833
+ var query, params, body, headers, method, pid, p, memory;
795
834
  return _regenerator().w(function (_context19) {
796
835
  while (1) switch (_context19.n) {
797
836
  case 0:
798
837
  query = _ref5.query, params = _ref5.params, body = _ref5.body, headers = _ref5.headers, method = _ref5.method;
799
838
  pid = params.pid;
800
- memory = (_this$mem$env$pid$mem = (_this$mem$env$pid = this.mem.env[pid]) === null || _this$mem$env$pid === void 0 ? void 0 : _this$mem$env$pid.memory) !== null && _this$mem$env$pid$mem !== void 0 ? _this$mem$env$pid$mem : null;
839
+ _context19.n = 1;
840
+ return this.mem.get("env", pid);
841
+ case 1:
842
+ p = _context19.v;
843
+ memory = (_p$memory = p === null || p === void 0 ? void 0 : p.memory) !== null && _p$memory !== void 0 ? _p$memory : null;
801
844
  if (memory) {
802
- _context19.n = 1;
845
+ _context19.n = 2;
803
846
  break;
804
847
  }
805
848
  return _context19.a(2, {
806
849
  status: 404,
807
850
  error: "TransactionNotFound: Process ".concat(pid, " was not found on gateway")
808
851
  });
809
- case 1:
852
+ case 2:
810
853
  return _context19.a(2, {
811
854
  send: Buffer.from(memory)
812
855
  });
813
- case 2:
856
+ case 3:
814
857
  return _context19.a(2);
815
858
  }
816
859
  }, _callee19, this);
@@ -868,78 +911,86 @@ var Adaptor = /*#__PURE__*/function () {
868
911
  key: "cu_get_results",
869
912
  value: function () {
870
913
  var _cu_get_results = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee21(_ref7) {
871
- var _this$mem$env$pid$res, _this$mem$env$pid2;
872
- var query, params, body, headers, method, pid, _query$from, from, _query$to, to, _query$sort, sort, _query$limit, limit, results, _res, i, count, started, _iterator4, _step4, v, _this$mem$msgs$v, _t12;
914
+ var _p$results;
915
+ var query, params, body, headers, method, pid, _query$from, from, _query$to, to, _query$sort, sort, _query$limit, limit, p, results, _res, i, count, started, _iterator4, _step4, v, msg, _t12;
873
916
  return _regenerator().w(function (_context21) {
874
917
  while (1) switch (_context21.p = _context21.n) {
875
918
  case 0:
876
919
  query = _ref7.query, params = _ref7.params, body = _ref7.body, headers = _ref7.headers, method = _ref7.method;
877
920
  pid = params.pid;
878
921
  _query$from = query.from, from = _query$from === void 0 ? null : _query$from, _query$to = query.to, to = _query$to === void 0 ? null : _query$to, _query$sort = query.sort, sort = _query$sort === void 0 ? "ASC" : _query$sort, _query$limit = query.limit, limit = _query$limit === void 0 ? 25 : _query$limit;
879
- results = (_this$mem$env$pid$res = (_this$mem$env$pid2 = this.mem.env[pid]) === null || _this$mem$env$pid2 === void 0 ? void 0 : _this$mem$env$pid2.results) !== null && _this$mem$env$pid$res !== void 0 ? _this$mem$env$pid$res : [];
922
+ _context21.n = 1;
923
+ return this.mem.get("env", pid);
924
+ case 1:
925
+ p = _context21.v;
926
+ results = (_p$results = p === null || p === void 0 ? void 0 : p.results) !== null && _p$results !== void 0 ? _p$results : [];
880
927
  if (sort === "DESC") results = (0, _ramda.reverse)(results);
881
928
  _res = [];
882
929
  i = 1;
883
930
  count = 0;
884
931
  started = (0, _ramda.isNil)(from);
885
932
  _iterator4 = _createForOfIteratorHelper(results);
886
- _context21.p = 1;
933
+ _context21.p = 2;
887
934
  _iterator4.s();
888
- case 2:
935
+ case 3:
889
936
  if ((_step4 = _iterator4.n()).done) {
890
- _context21.n = 8;
937
+ _context21.n = 10;
891
938
  break;
892
939
  }
893
940
  v = _step4.value;
894
941
  if (!started) {
895
- _context21.n = 5;
942
+ _context21.n = 7;
896
943
  break;
897
944
  }
945
+ _context21.n = 4;
946
+ return this.mem.get("msgs", v);
947
+ case 4:
948
+ msg = _context21.v;
898
949
  _res.push({
899
950
  cursor: v,
900
- node: (_this$mem$msgs$v = this.mem.msgs[v]) === null || _this$mem$msgs$v === void 0 ? void 0 : _this$mem$msgs$v.res
951
+ node: msg === null || msg === void 0 ? void 0 : msg.res
901
952
  });
902
953
  count++;
903
954
  if (!(!(0, _ramda.isNil)(to) && v === to)) {
904
- _context21.n = 3;
955
+ _context21.n = 5;
905
956
  break;
906
957
  }
907
- return _context21.a(3, 8);
908
- case 3:
958
+ return _context21.a(3, 10);
959
+ case 5:
909
960
  if (!(limit <= count)) {
910
- _context21.n = 4;
961
+ _context21.n = 6;
911
962
  break;
912
963
  }
913
- return _context21.a(3, 8);
914
- case 4:
915
- _context21.n = 6;
964
+ return _context21.a(3, 10);
965
+ case 6:
966
+ _context21.n = 8;
916
967
  break;
917
- case 5:
968
+ case 7:
918
969
  if (from === v) started = true;
919
- case 6:
970
+ case 8:
920
971
  i++;
921
- case 7:
922
- _context21.n = 2;
972
+ case 9:
973
+ _context21.n = 3;
923
974
  break;
924
- case 8:
925
- _context21.n = 10;
975
+ case 10:
976
+ _context21.n = 12;
926
977
  break;
927
- case 9:
928
- _context21.p = 9;
978
+ case 11:
979
+ _context21.p = 11;
929
980
  _t12 = _context21.v;
930
981
  _iterator4.e(_t12);
931
- case 10:
932
- _context21.p = 10;
982
+ case 12:
983
+ _context21.p = 12;
933
984
  _iterator4.f();
934
- return _context21.f(10);
935
- case 11:
985
+ return _context21.f(12);
986
+ case 13:
936
987
  return _context21.a(2, {
937
988
  json: {
938
989
  edges: _res
939
990
  }
940
991
  });
941
992
  }
942
- }, _callee21, this, [[1, 9, 10, 11]]);
993
+ }, _callee21, this, [[2, 11, 12, 13]]);
943
994
  }));
944
995
  function cu_get_results(_x22) {
945
996
  return _cu_get_results.apply(this, arguments);
@@ -950,24 +1001,28 @@ var Adaptor = /*#__PURE__*/function () {
950
1001
  key: "cu_get_result",
951
1002
  value: function () {
952
1003
  var _cu_get_result = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee22(_ref8) {
953
- var query, params, body, headers, method, message, process, _yield$this$recover, success, slot, _this$mem$env$process, _this$mem$env$process2, res2;
1004
+ var query, params, body, headers, method, message, process, p, _yield$this$recover, success, slot, _p, _p2, res2;
954
1005
  return _regenerator().w(function (_context22) {
955
1006
  while (1) switch (_context22.n) {
956
1007
  case 0:
957
1008
  query = _ref8.query, params = _ref8.params, body = _ref8.body, headers = _ref8.headers, method = _ref8.method;
958
1009
  message = params.mid;
959
1010
  process = query["process-id"]; // check if recovery is ongoing and
960
- if (!(0, _ramda.isNil)(this.mem.env[process])) {
961
- _context22.n = 2;
1011
+ _context22.n = 1;
1012
+ return this.mem.get("env", process);
1013
+ case 1:
1014
+ p = _context22.v;
1015
+ if (!(0, _ramda.isNil)(p)) {
1016
+ _context22.n = 5;
962
1017
  break;
963
1018
  }
964
- _context22.n = 1;
1019
+ _context22.n = 2;
965
1020
  return this.recover(process);
966
- case 1:
1021
+ case 2:
967
1022
  _yield$this$recover = _context22.v;
968
1023
  success = _yield$this$recover.success;
969
1024
  if (success) {
970
- _context22.n = 2;
1025
+ _context22.n = 3;
971
1026
  break;
972
1027
  }
973
1028
  console.log("process not found:", query["process-id"]);
@@ -975,34 +1030,43 @@ var Adaptor = /*#__PURE__*/function () {
975
1030
  status: 404,
976
1031
  error: "not Found"
977
1032
  });
978
- case 2:
1033
+ case 3:
1034
+ _context22.n = 4;
1035
+ return this.mem.get("env", process);
1036
+ case 4:
1037
+ p = _context22.v;
1038
+ case 5:
979
1039
  slot = message;
980
1040
  if (!/^[0-9a-zA-Z_-]{43,44}$/.test(message)) {
981
- message = (_this$mem$env$process = this.mem.env[process]) === null || _this$mem$env$process === void 0 || (_this$mem$env$process = _this$mem$env$process.results) === null || _this$mem$env$process === void 0 ? void 0 : _this$mem$env$process[slot];
1041
+ message = (_p = p) === null || _p === void 0 || (_p = _p.results) === null || _p === void 0 ? void 0 : _p[slot];
982
1042
  }
983
1043
  if (!(0, _ramda.isNil)(message)) {
984
- _context22.n = 4;
1044
+ _context22.n = 8;
985
1045
  break;
986
1046
  }
987
- _context22.n = 3;
1047
+ _context22.n = 6;
988
1048
  return this.recover(process);
989
- case 3:
990
- message = (_this$mem$env$process2 = this.mem.env[process]) === null || _this$mem$env$process2 === void 0 || (_this$mem$env$process2 = _this$mem$env$process2.results) === null || _this$mem$env$process2 === void 0 ? void 0 : _this$mem$env$process2[slot];
1049
+ case 6:
1050
+ _context22.n = 7;
1051
+ return this.mem.get("env", process);
1052
+ case 7:
1053
+ p = _context22.v;
1054
+ message = (_p2 = p) === null || _p2 === void 0 || (_p2 = _p2.results) === null || _p2 === void 0 ? void 0 : _p2[slot];
991
1055
  if (!(0, _ramda.isNil)(message)) {
992
- _context22.n = 4;
1056
+ _context22.n = 8;
993
1057
  break;
994
1058
  }
995
1059
  return _context22.a(2, {
996
1060
  status: 404,
997
1061
  error: "not Found"
998
1062
  });
999
- case 4:
1000
- _context22.n = 5;
1063
+ case 8:
1064
+ _context22.n = 9;
1001
1065
  return this.result({
1002
1066
  message: message,
1003
1067
  process: process
1004
1068
  });
1005
- case 5:
1069
+ case 9:
1006
1070
  res2 = _context22.v;
1007
1071
  return _context22.a(2, {
1008
1072
  json: res2
@@ -1036,49 +1100,118 @@ var Adaptor = /*#__PURE__*/function () {
1036
1100
  return cu_post_result;
1037
1101
  }()
1038
1102
  }, {
1039
- key: "su_get_root",
1103
+ key: "cu_post_evaluate",
1040
1104
  value: function () {
1041
- var _su_get_root = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee24(_ref9) {
1042
- var query, params, body, headers, method;
1105
+ var _cu_post_evaluate = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee24(_ref9) {
1106
+ var query, params, body, headers, method, message, process, data, msgTags, from, is_spawn, _tags2, _tags3, res, _t13;
1043
1107
  return _regenerator().w(function (_context24) {
1044
- while (1) switch (_context24.n) {
1108
+ while (1) switch (_context24.p = _context24.n) {
1045
1109
  case 0:
1046
1110
  query = _ref9.query, params = _ref9.params, body = _ref9.body, headers = _ref9.headers, method = _ref9.method;
1111
+ message = body.message, process = body.process, data = body.data, msgTags = body.tags, from = body.from, is_spawn = body.is_spawn;
1112
+ if (process) {
1113
+ _context24.n = 1;
1114
+ break;
1115
+ }
1047
1116
  return _context24.a(2, {
1117
+ status: 400,
1048
1118
  json: {
1049
- Unit: "Scheduler",
1050
- Timestamp: Date.now(),
1051
- Address: this.su_signer.addr,
1052
- Processes: (0, _ramda.keys)(this.mem.env)
1119
+ error: "process required"
1120
+ }
1121
+ });
1122
+ case 1:
1123
+ _context24.p = 1;
1124
+ _context24.n = 2;
1125
+ return this.evaluate({
1126
+ message: message,
1127
+ process: process,
1128
+ data: data || "",
1129
+ tags: msgTags,
1130
+ from: from,
1131
+ is_spawn: is_spawn,
1132
+ module: body.module || msgTags && ((_tags2 = (0, _utils.tags)(msgTags)) === null || _tags2 === void 0 ? void 0 : _tags2.Module),
1133
+ scheduler: body.scheduler || msgTags && ((_tags3 = (0, _utils.tags)(msgTags)) === null || _tags3 === void 0 ? void 0 : _tags3.Scheduler)
1134
+ });
1135
+ case 2:
1136
+ res = _context24.v;
1137
+ return _context24.a(2, {
1138
+ json: res || {}
1139
+ });
1140
+ case 3:
1141
+ _context24.p = 3;
1142
+ _t13 = _context24.v;
1143
+ console.log("cu_post_evaluate error:", _t13);
1144
+ return _context24.a(2, {
1145
+ status: 500,
1146
+ json: {
1147
+ error: _t13.message
1053
1148
  }
1054
1149
  });
1055
1150
  }
1056
- }, _callee24, this);
1151
+ }, _callee24, this, [[1, 3]]);
1057
1152
  }));
1058
- function su_get_root(_x24) {
1059
- return _su_get_root.apply(this, arguments);
1153
+ function cu_post_evaluate(_x24) {
1154
+ return _cu_post_evaluate.apply(this, arguments);
1060
1155
  }
1061
- return su_get_root;
1156
+ return cu_post_evaluate;
1062
1157
  }()
1063
1158
  }, {
1064
- key: "su_get_timestamp",
1159
+ key: "su_get_root",
1065
1160
  value: function () {
1066
- var _su_get_timestamp = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee25(_ref0) {
1067
- var query, params, body, headers, method;
1161
+ var _su_get_root = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee25(_ref0) {
1162
+ var query, params, body, headers, method, _t14, _t15, _t16, _t17;
1068
1163
  return _regenerator().w(function (_context25) {
1069
1164
  while (1) switch (_context25.n) {
1070
1165
  case 0:
1071
1166
  query = _ref0.query, params = _ref0.params, body = _ref0.body, headers = _ref0.headers, method = _ref0.method;
1167
+ _t14 = Date.now();
1168
+ _t15 = this.su_signer.addr;
1169
+ _context25.n = 1;
1170
+ return this.mem.getFieldKeys("env");
1171
+ case 1:
1172
+ _t16 = _context25.v;
1173
+ _t17 = {
1174
+ Unit: "Scheduler",
1175
+ Timestamp: _t14,
1176
+ Address: _t15,
1177
+ Processes: _t16
1178
+ };
1072
1179
  return _context25.a(2, {
1073
- json: {
1074
- timestamp: Date.now(),
1075
- block_height: this.mem.height
1076
- }
1180
+ json: _t17
1077
1181
  });
1078
1182
  }
1079
1183
  }, _callee25, this);
1080
1184
  }));
1081
- function su_get_timestamp(_x25) {
1185
+ function su_get_root(_x25) {
1186
+ return _su_get_root.apply(this, arguments);
1187
+ }
1188
+ return su_get_root;
1189
+ }()
1190
+ }, {
1191
+ key: "su_get_timestamp",
1192
+ value: function () {
1193
+ var _su_get_timestamp = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee26(_ref1) {
1194
+ var query, params, body, headers, method, _t18, _t19, _t20;
1195
+ return _regenerator().w(function (_context26) {
1196
+ while (1) switch (_context26.n) {
1197
+ case 0:
1198
+ query = _ref1.query, params = _ref1.params, body = _ref1.body, headers = _ref1.headers, method = _ref1.method;
1199
+ _t18 = Date.now();
1200
+ _context26.n = 1;
1201
+ return this.mem.get("height");
1202
+ case 1:
1203
+ _t19 = _context26.v;
1204
+ _t20 = {
1205
+ timestamp: _t18,
1206
+ block_height: _t19
1207
+ };
1208
+ return _context26.a(2, {
1209
+ json: _t20
1210
+ });
1211
+ }
1212
+ }, _callee26, this);
1213
+ }));
1214
+ function su_get_timestamp(_x26) {
1082
1215
  return _su_get_timestamp.apply(this, arguments);
1083
1216
  }
1084
1217
  return su_get_timestamp;
@@ -1086,40 +1219,51 @@ var Adaptor = /*#__PURE__*/function () {
1086
1219
  }, {
1087
1220
  key: "su_get_pid",
1088
1221
  value: function () {
1089
- var _su_get_pid = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee27(_ref1) {
1090
- var _this = this,
1091
- _this$mem$env$pid$res2,
1092
- _this$mem$env$pid3;
1093
- var query, params, body, headers, method, pid, edges;
1094
- return _regenerator().w(function (_context27) {
1095
- while (1) switch (_context27.n) {
1222
+ var _su_get_pid = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee28(_ref10) {
1223
+ var _this2 = this,
1224
+ _p$results2;
1225
+ var query, params, body, headers, method, pid, p, edges;
1226
+ return _regenerator().w(function (_context28) {
1227
+ while (1) switch (_context28.n) {
1096
1228
  case 0:
1097
- query = _ref1.query, params = _ref1.params, body = _ref1.body, headers = _ref1.headers, method = _ref1.method;
1229
+ query = _ref10.query, params = _ref10.params, body = _ref10.body, headers = _ref10.headers, method = _ref10.method;
1098
1230
  pid = params.pid;
1231
+ _context28.n = 1;
1232
+ return this.mem.get("env", pid);
1233
+ case 1:
1234
+ p = _context28.v;
1099
1235
  edges = (0, _ramda.map)(/*#__PURE__*/function () {
1100
- var _ref10 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee26(v) {
1236
+ var _ref11 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee27(v) {
1101
1237
  var _mtx$anchor, _tx$anchor;
1102
- var tx, _tags, mid, mtx;
1103
- return _regenerator().w(function (_context26) {
1104
- while (1) switch (_context26.n) {
1238
+ var tx, _tags, mid, mtx, mtxOwner, txOwner;
1239
+ return _regenerator().w(function (_context27) {
1240
+ while (1) switch (_context27.n) {
1105
1241
  case 0:
1106
- _context26.n = 1;
1107
- return _this.mem.getTx(v);
1242
+ _context27.n = 1;
1243
+ return _this2.mem.getTx(v);
1108
1244
  case 1:
1109
- tx = _context26.v;
1245
+ tx = _context27.v;
1110
1246
  _tags = (0, _utils.tags)(v.tags);
1111
1247
  mid = _tags.Message;
1112
- _context26.n = 2;
1113
- return _this.mem.getTx(mid);
1248
+ _context27.n = 2;
1249
+ return _this2.mem.getTx(mid);
1114
1250
  case 2:
1115
- mtx = _context26.v;
1116
- return _context26.a(2, {
1251
+ mtx = _context27.v;
1252
+ _context27.n = 3;
1253
+ return _this2.mem.get("addrmap", mtx.owner);
1254
+ case 3:
1255
+ mtxOwner = _context27.v;
1256
+ _context27.n = 4;
1257
+ return _this2.mem.get("addrmap", tx.owner);
1258
+ case 4:
1259
+ txOwner = _context27.v;
1260
+ return _context27.a(2, {
1117
1261
  cursor: v,
1118
1262
  node: {
1119
1263
  message: {
1120
1264
  id: mtx.id,
1121
1265
  tags: mtx.tags,
1122
- owner: _this.mem.addrmap[mtx.owner],
1266
+ owner: mtxOwner,
1123
1267
  anchor: (_mtx$anchor = mtx.anchor) !== null && _mtx$anchor !== void 0 ? _mtx$anchor : null,
1124
1268
  target: pid,
1125
1269
  signature: mtx.signature,
@@ -1128,7 +1272,7 @@ var Adaptor = /*#__PURE__*/function () {
1128
1272
  assignment: {
1129
1273
  id: tx.id,
1130
1274
  tags: tx.tags,
1131
- owner: _this.mem.addrmap[tx.owner],
1275
+ owner: txOwner,
1132
1276
  anchor: (_tx$anchor = tx.anchor) !== null && _tx$anchor !== void 0 ? _tx$anchor : null,
1133
1277
  target: null,
1134
1278
  signature: tx.signature
@@ -1136,13 +1280,13 @@ var Adaptor = /*#__PURE__*/function () {
1136
1280
  }
1137
1281
  });
1138
1282
  }
1139
- }, _callee26);
1283
+ }, _callee27);
1140
1284
  }));
1141
- return function (_x27) {
1142
- return _ref10.apply(this, arguments);
1285
+ return function (_x28) {
1286
+ return _ref11.apply(this, arguments);
1143
1287
  };
1144
- }())((0, _ramda.reverse)((_this$mem$env$pid$res2 = (_this$mem$env$pid3 = this.mem.env[pid]) === null || _this$mem$env$pid3 === void 0 ? void 0 : _this$mem$env$pid3.results) !== null && _this$mem$env$pid$res2 !== void 0 ? _this$mem$env$pid$res2 : [])); // need mod
1145
- return _context27.a(2, {
1288
+ }())((0, _ramda.reverse)((_p$results2 = p === null || p === void 0 ? void 0 : p.results) !== null && _p$results2 !== void 0 ? _p$results2 : [])); // need mod
1289
+ return _context28.a(2, {
1146
1290
  json: {
1147
1291
  page_info: {
1148
1292
  has_next_page: false
@@ -1151,9 +1295,9 @@ var Adaptor = /*#__PURE__*/function () {
1151
1295
  }
1152
1296
  });
1153
1297
  }
1154
- }, _callee27, this);
1298
+ }, _callee28, this);
1155
1299
  }));
1156
- function su_get_pid(_x26) {
1300
+ function su_get_pid(_x27) {
1157
1301
  return _su_get_pid.apply(this, arguments);
1158
1302
  }
1159
1303
  return su_get_pid;
@@ -1161,19 +1305,19 @@ var Adaptor = /*#__PURE__*/function () {
1161
1305
  }, {
1162
1306
  key: "mu_get_root",
1163
1307
  value: function () {
1164
- var _mu_get_root = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee28(_ref11) {
1308
+ var _mu_get_root = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee29(_ref12) {
1165
1309
  var query, params, body, headers, method;
1166
- return _regenerator().w(function (_context28) {
1167
- while (1) switch (_context28.n) {
1310
+ return _regenerator().w(function (_context29) {
1311
+ while (1) switch (_context29.n) {
1168
1312
  case 0:
1169
- query = _ref11.query, params = _ref11.params, body = _ref11.body, headers = _ref11.headers, method = _ref11.method;
1170
- return _context28.a(2, {
1313
+ query = _ref12.query, params = _ref12.params, body = _ref12.body, headers = _ref12.headers, method = _ref12.method;
1314
+ return _context29.a(2, {
1171
1315
  send: "ao messenger unit"
1172
1316
  });
1173
1317
  }
1174
- }, _callee28);
1318
+ }, _callee29);
1175
1319
  }));
1176
- function mu_get_root(_x28) {
1320
+ function mu_get_root(_x29) {
1177
1321
  return _mu_get_root.apply(this, arguments);
1178
1322
  }
1179
1323
  return mu_get_root;
@@ -1181,87 +1325,144 @@ var Adaptor = /*#__PURE__*/function () {
1181
1325
  }, {
1182
1326
  key: "mu_post_root",
1183
1327
  value: function () {
1184
- var _mu_post_root = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee29(_ref12) {
1185
- var query, params, body, headers, method, valid, type, item, _tags, err, res, _t13;
1186
- return _regenerator().w(function (_context29) {
1187
- while (1) switch (_context29.p = _context29.n) {
1328
+ var _mu_post_root = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee30(_ref13) {
1329
+ var query, params, body, headers, method, valid, type, item, _tags, _allowedNetworks, err, res, _t21, _t22, _t23, _t24;
1330
+ return _regenerator().w(function (_context30) {
1331
+ while (1) switch (_context30.p = _context30.n) {
1188
1332
  case 0:
1189
- query = _ref12.query, params = _ref12.params, body = _ref12.body, headers = _ref12.headers, method = _ref12.method;
1333
+ query = _ref13.query, params = _ref13.params, body = _ref13.body, headers = _ref13.headers, method = _ref13.method;
1190
1334
  if (body.type === "Buffer" && Array.isArray(body.data)) {
1191
1335
  body = new Uint8Array(body.data);
1192
1336
  }
1193
1337
  valid = false; // todo: cannot verify node -> broser items
1194
- _context29.p = 1;
1195
- _context29.n = 2;
1338
+ _context30.p = 1;
1339
+ _context30.n = 2;
1196
1340
  return _arbundles.DataItem.verify(body);
1197
1341
  case 2:
1198
- valid = _context29.v;
1199
- _context29.n = 4;
1342
+ valid = _context30.v;
1343
+ _context30.n = 4;
1200
1344
  break;
1201
1345
  case 3:
1202
- _context29.p = 3;
1203
- _t13 = _context29.v;
1204
- console.log(_t13);
1346
+ _context30.p = 3;
1347
+ _t21 = _context30.v;
1205
1348
  case 4:
1206
1349
  type = null;
1207
1350
  item = null;
1208
1351
  if (valid || true) item = new _arbundles.DataItem(body);
1209
- _context29.n = 5;
1352
+ _context30.n = 5;
1210
1353
  return item.setSignature(item.rawSignature);
1211
1354
  case 5:
1212
- _tags = (0, _utils.tags)(item.tags);
1355
+ _tags = (0, _utils.tags)(item.tags); // Allow both ao.TN.1 (legacy testnet) and ao.DN.1 (WAO Devnet) variants
1356
+ // through the local emulator. The variant is informational here; the
1357
+ // local emulator doesn't actually need to enforce a strict network.
1358
+ _allowedNetworks = new Set([this.network, "ao.TN.1", "ao.DN.1"]);
1359
+ if (!(_tags.Variant && !_allowedNetworks.has(_tags.Variant))) {
1360
+ _context30.n = 6;
1361
+ break;
1362
+ }
1363
+ return _context30.a(2, {
1364
+ status: 400,
1365
+ json: {
1366
+ error: "Variant mismatch: expected ".concat(this.network, ", got ").concat(_tags.Variant)
1367
+ }
1368
+ });
1369
+ case 6:
1213
1370
  err = null;
1214
1371
  if (!(_tags.Type === "Process")) {
1215
- _context29.n = 7;
1372
+ _context30.n = 11;
1216
1373
  break;
1217
1374
  }
1218
- _context29.n = 6;
1375
+ _context30.p = 7;
1376
+ _context30.n = 8;
1219
1377
  return this.spawn({
1220
1378
  item: item,
1221
1379
  module: _tags.Module,
1222
- scheduler: _tags.Scheduler
1380
+ scheduler: _tags.Scheduler,
1381
+ _cu_url: _tags["CU-URL"] || undefined
1223
1382
  });
1224
- case 6:
1225
- res = _context29.v;
1383
+ case 8:
1384
+ res = _context30.v;
1226
1385
  if (!res) err = "bad requrest";
1227
- _context29.n = 10;
1386
+ _context30.n = 10;
1228
1387
  break;
1229
- case 7:
1388
+ case 9:
1389
+ _context30.p = 9;
1390
+ _t22 = _context30.v;
1391
+ console.error("MU spawn error:", _t22.message, _t22.stack);
1392
+ return _context30.a(2, {
1393
+ status: 500,
1394
+ json: {
1395
+ error: _t22.message,
1396
+ stack: (_t22.stack || "").split("\n").slice(0, 8)
1397
+ }
1398
+ });
1399
+ case 10:
1400
+ _context30.n = 22;
1401
+ break;
1402
+ case 11:
1230
1403
  if (!(_tags.Type === "Message")) {
1231
- _context29.n = 9;
1404
+ _context30.n = 16;
1232
1405
  break;
1233
1406
  }
1234
- _context29.n = 8;
1407
+ _context30.p = 12;
1408
+ _context30.n = 13;
1235
1409
  return this.message({
1236
1410
  item: item,
1237
1411
  process: item.target
1238
1412
  });
1239
- case 8:
1240
- _context29.n = 10;
1413
+ case 13:
1414
+ _context30.n = 15;
1241
1415
  break;
1242
- case 9:
1416
+ case 14:
1417
+ _context30.p = 14;
1418
+ _t23 = _context30.v;
1419
+ console.error("MU message error:", _t23.message, _t23.stack);
1420
+ err = _t23.message;
1421
+ case 15:
1422
+ _context30.n = 22;
1423
+ break;
1424
+ case 16:
1425
+ if (!(_tags.Type === "Scheduler-Location" || _tags.Type === "Scheduler-Transfer")) {
1426
+ _context30.n = 21;
1427
+ break;
1428
+ }
1429
+ _context30.p = 17;
1430
+ _context30.n = 18;
1431
+ return this._ar.postItems(item, this.su_signer.jwk);
1432
+ case 18:
1433
+ _context30.n = 20;
1434
+ break;
1435
+ case 19:
1436
+ _context30.p = 19;
1437
+ _t24 = _context30.v;
1438
+ console.error("MU ".concat(_tags.Type, " error:"), _t24.message, _t24.stack);
1439
+ err = _t24.message;
1440
+ case 20:
1441
+ _context30.n = 22;
1442
+ break;
1443
+ case 21:
1243
1444
  err = true;
1244
- case 10:
1445
+ case 22:
1245
1446
  if (!err) {
1246
- _context29.n = 11;
1447
+ _context30.n = 23;
1247
1448
  break;
1248
1449
  }
1249
- return _context29.a(2, {
1450
+ return _context30.a(2, {
1250
1451
  status: 400,
1251
1452
  error: err
1252
1453
  });
1253
- case 11:
1254
- return _context29.a(2, {
1454
+ case 23:
1455
+ return _context30.a(2, {
1255
1456
  json: {
1256
1457
  id: item.id
1257
1458
  }
1258
1459
  });
1259
- case 12:
1260
- return _context29.a(2);
1460
+ case 24:
1461
+ return _context30.a(2);
1261
1462
  }
1262
- }, _callee29, this, [[1, 3]]);
1463
+ }, _callee30, this, [[17, 19], [12, 14], [7, 9], [1, 3]]);
1263
1464
  }));
1264
- function mu_post_root(_x29) {
1465
+ function mu_post_root(_x30) {
1265
1466
  return _mu_post_root.apply(this, arguments);
1266
1467
  }
1267
1468
  return mu_post_root;
@@ -1269,27 +1470,27 @@ var Adaptor = /*#__PURE__*/function () {
1269
1470
  }, {
1270
1471
  key: "mu_post_monitor",
1271
1472
  value: function () {
1272
- var _mu_post_monitor = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee30(_ref13) {
1473
+ var _mu_post_monitor = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee31(_ref14) {
1273
1474
  var query, params, body, headers, method;
1274
- return _regenerator().w(function (_context30) {
1275
- while (1) switch (_context30.n) {
1475
+ return _regenerator().w(function (_context31) {
1476
+ while (1) switch (_context31.n) {
1276
1477
  case 0:
1277
- query = _ref13.query, params = _ref13.params, body = _ref13.body, headers = _ref13.headers, method = _ref13.method;
1278
- _context30.n = 1;
1478
+ query = _ref14.query, params = _ref14.params, body = _ref14.body, headers = _ref14.headers, method = _ref14.method;
1479
+ _context31.n = 1;
1279
1480
  return this.monitor({
1280
1481
  process: params.pid
1281
1482
  });
1282
1483
  case 1:
1283
- return _context30.a(2, {
1484
+ return _context31.a(2, {
1284
1485
  json: {
1285
1486
  id: params.pid,
1286
1487
  messag: "cron monitored!"
1287
1488
  }
1288
1489
  });
1289
1490
  }
1290
- }, _callee30, this);
1491
+ }, _callee31, this);
1291
1492
  }));
1292
- function mu_post_monitor(_x30) {
1493
+ function mu_post_monitor(_x31) {
1293
1494
  return _mu_post_monitor.apply(this, arguments);
1294
1495
  }
1295
1496
  return mu_post_monitor;
@@ -1297,27 +1498,27 @@ var Adaptor = /*#__PURE__*/function () {
1297
1498
  }, {
1298
1499
  key: "mu_delete_monitor",
1299
1500
  value: function () {
1300
- var _mu_delete_monitor = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee31(_ref14) {
1501
+ var _mu_delete_monitor = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee32(_ref15) {
1301
1502
  var query, params, body, headers, method;
1302
- return _regenerator().w(function (_context31) {
1303
- while (1) switch (_context31.n) {
1503
+ return _regenerator().w(function (_context32) {
1504
+ while (1) switch (_context32.n) {
1304
1505
  case 0:
1305
- query = _ref14.query, params = _ref14.params, body = _ref14.body, headers = _ref14.headers, method = _ref14.method;
1306
- _context31.n = 1;
1506
+ query = _ref15.query, params = _ref15.params, body = _ref15.body, headers = _ref15.headers, method = _ref15.method;
1507
+ _context32.n = 1;
1307
1508
  return this.unmonitor({
1308
1509
  process: params.pid
1309
1510
  });
1310
1511
  case 1:
1311
- return _context31.a(2, {
1512
+ return _context32.a(2, {
1312
1513
  json: {
1313
1514
  id: params.pid,
1314
1515
  message: "cron deleted!"
1315
1516
  }
1316
1517
  });
1317
1518
  }
1318
- }, _callee31, this);
1519
+ }, _callee32, this);
1319
1520
  }));
1320
- function mu_delete_monitor(_x31) {
1521
+ function mu_delete_monitor(_x32) {
1321
1522
  return _mu_delete_monitor.apply(this, arguments);
1322
1523
  }
1323
1524
  return mu_delete_monitor;
@@ -1325,25 +1526,33 @@ var Adaptor = /*#__PURE__*/function () {
1325
1526
  }, {
1326
1527
  key: "ar_get_root",
1327
1528
  value: function () {
1328
- var _ar_get_root = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee32(_ref15) {
1329
- var query, params, body, headers, method;
1330
- return _regenerator().w(function (_context32) {
1331
- while (1) switch (_context32.n) {
1529
+ var _ar_get_root = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee33(_ref16) {
1530
+ var query, params, body, headers, method, _t25, _t26, _t27, _t28, _t29;
1531
+ return _regenerator().w(function (_context33) {
1532
+ while (1) switch (_context33.n) {
1332
1533
  case 0:
1333
- query = _ref15.query, params = _ref15.params, body = _ref15.body, headers = _ref15.headers, method = _ref15.method;
1334
- return _context32.a(2, {
1335
- json: {
1336
- version: 1,
1337
- timestamp: Date.now(),
1338
- height: this.mem.height,
1339
- network: "wao.LN.1",
1340
- current: this.mem.getAnchor()
1341
- }
1534
+ query = _ref16.query, params = _ref16.params, body = _ref16.body, headers = _ref16.headers, method = _ref16.method;
1535
+ _t25 = Date.now();
1536
+ _context33.n = 1;
1537
+ return this.mem.get("height");
1538
+ case 1:
1539
+ _t26 = _context33.v;
1540
+ _t27 = this.network;
1541
+ _t28 = this.mem.getAnchor();
1542
+ _t29 = {
1543
+ version: 1,
1544
+ timestamp: _t25,
1545
+ height: _t26,
1546
+ network: _t27,
1547
+ current: _t28
1548
+ };
1549
+ return _context33.a(2, {
1550
+ json: _t29
1342
1551
  });
1343
1552
  }
1344
- }, _callee32, this);
1553
+ }, _callee33, this);
1345
1554
  }));
1346
- function ar_get_root(_x32) {
1555
+ function ar_get_root(_x33) {
1347
1556
  return _ar_get_root.apply(this, arguments);
1348
1557
  }
1349
1558
  return ar_get_root;
@@ -1351,19 +1560,19 @@ var Adaptor = /*#__PURE__*/function () {
1351
1560
  }, {
1352
1561
  key: "ar_get_wallet_balance",
1353
1562
  value: function () {
1354
- var _ar_get_wallet_balance = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee33(_ref16) {
1563
+ var _ar_get_wallet_balance = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee34(_ref17) {
1355
1564
  var query, params, body, headers, method;
1356
- return _regenerator().w(function (_context33) {
1357
- while (1) switch (_context33.n) {
1565
+ return _regenerator().w(function (_context34) {
1566
+ while (1) switch (_context34.n) {
1358
1567
  case 0:
1359
- query = _ref16.query, params = _ref16.params, body = _ref16.body, headers = _ref16.headers, method = _ref16.method;
1360
- return _context33.a(2, {
1568
+ query = _ref17.query, params = _ref17.params, body = _ref17.body, headers = _ref17.headers, method = _ref17.method;
1569
+ return _context34.a(2, {
1361
1570
  send: "0"
1362
1571
  });
1363
1572
  }
1364
- }, _callee33);
1573
+ }, _callee34);
1365
1574
  }));
1366
- function ar_get_wallet_balance(_x33) {
1575
+ function ar_get_wallet_balance(_x34) {
1367
1576
  return _ar_get_wallet_balance.apply(this, arguments);
1368
1577
  }
1369
1578
  return ar_get_wallet_balance;
@@ -1371,21 +1580,21 @@ var Adaptor = /*#__PURE__*/function () {
1371
1580
  }, {
1372
1581
  key: "ar_get_mint",
1373
1582
  value: function () {
1374
- var _ar_get_mint = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee34(_ref17) {
1583
+ var _ar_get_mint = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee35(_ref18) {
1375
1584
  var query, params, body, headers, method;
1376
- return _regenerator().w(function (_context34) {
1377
- while (1) switch (_context34.n) {
1585
+ return _regenerator().w(function (_context35) {
1586
+ while (1) switch (_context35.n) {
1378
1587
  case 0:
1379
- query = _ref17.query, params = _ref17.params, body = _ref17.body, headers = _ref17.headers, method = _ref17.method;
1380
- return _context34.a(2, {
1588
+ query = _ref18.query, params = _ref18.params, body = _ref18.body, headers = _ref18.headers, method = _ref18.method;
1589
+ return _context35.a(2, {
1381
1590
  json: {
1382
1591
  id: "0"
1383
1592
  }
1384
1593
  });
1385
1594
  }
1386
- }, _callee34);
1595
+ }, _callee35);
1387
1596
  }));
1388
- function ar_get_mint(_x34) {
1597
+ function ar_get_mint(_x35) {
1389
1598
  return _ar_get_mint.apply(this, arguments);
1390
1599
  }
1391
1600
  return ar_get_mint;
@@ -1393,20 +1602,20 @@ var Adaptor = /*#__PURE__*/function () {
1393
1602
  }, {
1394
1603
  key: "ar_get_tx_offset",
1395
1604
  value: function () {
1396
- var _ar_get_tx_offset = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee35(_ref18) {
1605
+ var _ar_get_tx_offset = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee36(_ref19) {
1397
1606
  var query, params, body, headers, method;
1398
- return _regenerator().w(function (_context35) {
1399
- while (1) switch (_context35.n) {
1607
+ return _regenerator().w(function (_context36) {
1608
+ while (1) switch (_context36.n) {
1400
1609
  case 0:
1401
- query = _ref18.query, params = _ref18.params, body = _ref18.body, headers = _ref18.headers, method = _ref18.method;
1402
- return _context35.a(2, {
1610
+ query = _ref19.query, params = _ref19.params, body = _ref19.body, headers = _ref19.headers, method = _ref19.method;
1611
+ return _context36.a(2, {
1403
1612
  status: 400,
1404
1613
  send: null
1405
1614
  });
1406
1615
  }
1407
- }, _callee35);
1616
+ }, _callee36);
1408
1617
  }));
1409
- function ar_get_tx_offset(_x35) {
1618
+ function ar_get_tx_offset(_x36) {
1410
1619
  return _ar_get_tx_offset.apply(this, arguments);
1411
1620
  }
1412
1621
  return ar_get_tx_offset;
@@ -1414,19 +1623,19 @@ var Adaptor = /*#__PURE__*/function () {
1414
1623
  }, {
1415
1624
  key: "ar_get_tx_anchor",
1416
1625
  value: function () {
1417
- var _ar_get_tx_anchor = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee36(_ref19) {
1626
+ var _ar_get_tx_anchor = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee37(_ref20) {
1418
1627
  var query, params, body, headers, method;
1419
- return _regenerator().w(function (_context36) {
1420
- while (1) switch (_context36.n) {
1628
+ return _regenerator().w(function (_context37) {
1629
+ while (1) switch (_context37.n) {
1421
1630
  case 0:
1422
- query = _ref19.query, params = _ref19.params, body = _ref19.body, headers = _ref19.headers, method = _ref19.method;
1423
- return _context36.a(2, {
1631
+ query = _ref20.query, params = _ref20.params, body = _ref20.body, headers = _ref20.headers, method = _ref20.method;
1632
+ return _context37.a(2, {
1424
1633
  send: this.mem.getAnchor()
1425
1634
  });
1426
1635
  }
1427
- }, _callee36, this);
1636
+ }, _callee37, this);
1428
1637
  }));
1429
- function ar_get_tx_anchor(_x36) {
1638
+ function ar_get_tx_anchor(_x37) {
1430
1639
  return _ar_get_tx_anchor.apply(this, arguments);
1431
1640
  }
1432
1641
  return ar_get_tx_anchor;
@@ -1434,19 +1643,19 @@ var Adaptor = /*#__PURE__*/function () {
1434
1643
  }, {
1435
1644
  key: "ar_get_mine",
1436
1645
  value: function () {
1437
- var _ar_get_mine = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee37(_ref20) {
1646
+ var _ar_get_mine = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee38(_ref21) {
1438
1647
  var query, params, body, headers, method;
1439
- return _regenerator().w(function (_context37) {
1440
- while (1) switch (_context37.n) {
1648
+ return _regenerator().w(function (_context38) {
1649
+ while (1) switch (_context38.n) {
1441
1650
  case 0:
1442
- query = _ref20.query, params = _ref20.params, body = _ref20.body, headers = _ref20.headers, method = _ref20.method;
1443
- return _context37.a(2, {
1651
+ query = _ref21.query, params = _ref21.params, body = _ref21.body, headers = _ref21.headers, method = _ref21.method;
1652
+ return _context38.a(2, {
1444
1653
  json: params
1445
1654
  });
1446
1655
  }
1447
- }, _callee37);
1656
+ }, _callee38);
1448
1657
  }));
1449
- function ar_get_mine(_x37) {
1658
+ function ar_get_mine(_x38) {
1450
1659
  return _ar_get_mine.apply(this, arguments);
1451
1660
  }
1452
1661
  return ar_get_mine;
@@ -1454,34 +1663,49 @@ var Adaptor = /*#__PURE__*/function () {
1454
1663
  }, {
1455
1664
  key: "ar_get_id",
1456
1665
  value: function () {
1457
- var _ar_get_id = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee38(_ref21) {
1458
- var query, params, body, headers, method, _data;
1459
- return _regenerator().w(function (_context38) {
1460
- while (1) switch (_context38.n) {
1666
+ var _ar_get_id = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee39(_ref22) {
1667
+ var _tx$_data;
1668
+ var query, params, body, headers, method, _data, tx, contentType, ctTag, send;
1669
+ return _regenerator().w(function (_context39) {
1670
+ while (1) switch (_context39.n) {
1461
1671
  case 0:
1462
- query = _ref21.query, params = _ref21.params, body = _ref21.body, headers = _ref21.headers, method = _ref21.method;
1463
- _context38.n = 1;
1672
+ query = _ref22.query, params = _ref22.params, body = _ref22.body, headers = _ref22.headers, method = _ref22.method;
1673
+ _context39.n = 1;
1464
1674
  return this._ar.data(params.id);
1465
1675
  case 1:
1466
- _data = _context38.v;
1676
+ _data = _context39.v;
1467
1677
  if (_data) {
1468
- _context38.n = 2;
1678
+ _context39.n = 2;
1469
1679
  break;
1470
1680
  }
1471
- return _context38.a(2, {
1681
+ return _context39.a(2, {
1472
1682
  status: 404,
1473
1683
  send: null
1474
1684
  });
1475
1685
  case 2:
1476
- return _context38.a(2, {
1477
- send: Buffer.from(_data, "base64")
1478
- });
1686
+ _context39.n = 3;
1687
+ return this.mem.getTx(params.id);
1479
1688
  case 3:
1480
- return _context38.a(2);
1689
+ tx = _context39.v;
1690
+ contentType = (tx === null || tx === void 0 || (_tx$_data = tx._data) === null || _tx$_data === void 0 ? void 0 : _tx$_data.type) || "";
1691
+ if (!contentType && tx !== null && tx !== void 0 && tx.tags) {
1692
+ ctTag = tx.tags.find(function (t) {
1693
+ return t.name === "Content-Type";
1694
+ });
1695
+ if (ctTag) contentType = ctTag.value;
1696
+ }
1697
+ if (!contentType) contentType = "application/octet-stream";
1698
+ send = Buffer.isBuffer(_data) || _data instanceof Uint8Array ? _data : Buffer.from(String(_data), "base64");
1699
+ return _context39.a(2, {
1700
+ send: send,
1701
+ headers: {
1702
+ "Content-Type": contentType
1703
+ }
1704
+ });
1481
1705
  }
1482
- }, _callee38, this);
1706
+ }, _callee39, this);
1483
1707
  }));
1484
- function ar_get_id(_x38) {
1708
+ function ar_get_id(_x39) {
1485
1709
  return _ar_get_id.apply(this, arguments);
1486
1710
  }
1487
1711
  return ar_get_id;
@@ -1489,19 +1713,19 @@ var Adaptor = /*#__PURE__*/function () {
1489
1713
  }, {
1490
1714
  key: "ar_get_price",
1491
1715
  value: function () {
1492
- var _ar_get_price = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee39(_ref22) {
1716
+ var _ar_get_price = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee40(_ref23) {
1493
1717
  var query, params, body, headers, method;
1494
- return _regenerator().w(function (_context39) {
1495
- while (1) switch (_context39.n) {
1718
+ return _regenerator().w(function (_context40) {
1719
+ while (1) switch (_context40.n) {
1496
1720
  case 0:
1497
- query = _ref22.query, params = _ref22.params, body = _ref22.body, headers = _ref22.headers, method = _ref22.method;
1498
- return _context39.a(2, {
1721
+ query = _ref23.query, params = _ref23.params, body = _ref23.body, headers = _ref23.headers, method = _ref23.method;
1722
+ return _context40.a(2, {
1499
1723
  send: "0"
1500
1724
  });
1501
1725
  }
1502
- }, _callee39);
1726
+ }, _callee40);
1503
1727
  }));
1504
- function ar_get_price(_x39) {
1728
+ function ar_get_price(_x40) {
1505
1729
  return _ar_get_price.apply(this, arguments);
1506
1730
  }
1507
1731
  return ar_get_price;
@@ -1509,67 +1733,57 @@ var Adaptor = /*#__PURE__*/function () {
1509
1733
  }, {
1510
1734
  key: "ar_post_graphql",
1511
1735
  value: function () {
1512
- var _ar_post_graphql = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee40(_ref23) {
1513
- var query, params, body, headers, method, _query, variables, _toGraphObj, tar, args, res2, edges, _t14;
1514
- return _regenerator().w(function (_context40) {
1515
- while (1) switch (_context40.p = _context40.n) {
1736
+ var _ar_post_graphql = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee41(_ref24) {
1737
+ var query, params, body, headers, method, _args$first, _query, variables, _toGraphObj, tar, args, first, res2, fn, hasNextPage, edges, _t30;
1738
+ return _regenerator().w(function (_context41) {
1739
+ while (1) switch (_context41.p = _context41.n) {
1516
1740
  case 0:
1517
- query = _ref23.query, params = _ref23.params, body = _ref23.body, headers = _ref23.headers, method = _ref23.method;
1518
- _context40.p = 1;
1741
+ query = _ref24.query, params = _ref24.params, body = _ref24.body, headers = _ref24.headers, method = _ref24.method;
1742
+ _context41.p = 1;
1519
1743
  _query = body.query, variables = body.variables;
1520
1744
  _toGraphObj = (0, _utils.toGraphObj)({
1521
1745
  query: _query,
1522
1746
  variables: variables
1523
1747
  }), tar = _toGraphObj.tar, args = _toGraphObj.args;
1748
+ first = (_args$first = args.first) !== null && _args$first !== void 0 ? _args$first : 10;
1524
1749
  res2 = null;
1525
- if (!(tar === "transactions")) {
1526
- _context40.n = 3;
1527
- break;
1528
- }
1529
- _context40.n = 2;
1530
- return this.gql.txs(_objectSpread({}, args));
1750
+ fn = tar === "blocks" ? "blocks" : "txs";
1751
+ _context41.n = 2;
1752
+ return this.gql[fn](_objectSpread(_objectSpread({}, args), {}, {
1753
+ first: first + 1
1754
+ }));
1531
1755
  case 2:
1532
- res2 = _context40.v;
1533
- _context40.n = 5;
1534
- break;
1535
- case 3:
1536
- if (!(tar === "blocks")) {
1537
- _context40.n = 5;
1538
- break;
1539
- }
1540
- _context40.n = 4;
1541
- return this.gql.blocks(_objectSpread({}, args));
1542
- case 4:
1543
- res2 = _context40.v;
1544
- case 5:
1756
+ res2 = _context41.v;
1757
+ hasNextPage = res2.length > first;
1758
+ if (hasNextPage) res2 = res2.slice(0, first);
1545
1759
  edges = (0, _ramda.map)(function (v) {
1546
1760
  return {
1547
1761
  node: v,
1548
1762
  cursor: v.cursor
1549
1763
  };
1550
1764
  }, res2);
1551
- return _context40.a(2, {
1765
+ return _context41.a(2, {
1552
1766
  json: {
1553
1767
  data: _defineProperty({}, tar, {
1554
1768
  pageInfo: {
1555
- hasNextPage: true
1769
+ hasNextPage: hasNextPage
1556
1770
  },
1557
1771
  edges: edges
1558
1772
  })
1559
1773
  }
1560
1774
  });
1561
- case 6:
1562
- _context40.p = 6;
1563
- _t14 = _context40.v;
1564
- console.log(_t14);
1565
- return _context40.a(2, {
1775
+ case 3:
1776
+ _context41.p = 3;
1777
+ _t30 = _context41.v;
1778
+ console.log(_t30);
1779
+ return _context41.a(2, {
1566
1780
  status: 400,
1567
1781
  error: "bad request"
1568
1782
  });
1569
1783
  }
1570
- }, _callee40, this, [[1, 6]]);
1784
+ }, _callee41, this, [[1, 3]]);
1571
1785
  }));
1572
- function ar_post_graphql(_x40) {
1786
+ function ar_post_graphql(_x41) {
1573
1787
  return _ar_post_graphql.apply(this, arguments);
1574
1788
  }
1575
1789
  return ar_post_graphql;
@@ -1577,20 +1791,21 @@ var Adaptor = /*#__PURE__*/function () {
1577
1791
  }, {
1578
1792
  key: "ar_post_id",
1579
1793
  value: function () {
1580
- var _ar_post_id = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee41(_ref24) {
1794
+ var _ar_post_id = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee42(_ref25) {
1581
1795
  var query, params, body, headers, method, buf;
1582
- return _regenerator().w(function (_context41) {
1583
- while (1) switch (_context41.n) {
1796
+ return _regenerator().w(function (_context42) {
1797
+ while (1) switch (_context42.n) {
1584
1798
  case 0:
1585
- query = _ref24.query, params = _ref24.params, body = _ref24.body, headers = _ref24.headers, method = _ref24.method;
1799
+ query = _ref25.query, params = _ref25.params, body = _ref25.body, headers = _ref25.headers, method = _ref25.method;
1586
1800
  if (!body.chunk) {
1587
- _context41.n = 3;
1801
+ _context42.n = 3;
1588
1802
  break;
1589
1803
  }
1590
1804
  if (!this.data[body.data_root]) {
1591
- _context41.n = 2;
1805
+ _context42.n = 2;
1592
1806
  break;
1593
1807
  }
1808
+ this._dataTimestamps[body.data_root] = Date.now();
1594
1809
  this.data[body.data_root].data += body.chunk;
1595
1810
  buf = Buffer.from(body.chunk, "base64");
1596
1811
  if (!this.data[body.data_root].chunks) {
@@ -1600,43 +1815,45 @@ var Adaptor = /*#__PURE__*/function () {
1600
1815
  }
1601
1816
  delete body.chunk;
1602
1817
  if (!(this.data[body.data_root].data_size <= this.data[body.data_root].chunks.length)) {
1603
- _context41.n = 2;
1818
+ _context42.n = 2;
1604
1819
  break;
1605
1820
  }
1606
1821
  this.data[body.data_root].data = this.data[body.data_root].chunks.toString("base64");
1607
- _context41.n = 1;
1822
+ _context42.n = 1;
1608
1823
  return this._ar.postTx(this.data[body.data_root]);
1609
1824
  case 1:
1610
1825
  delete this.data[body.data_root];
1826
+ delete this._dataTimestamps[body.data_root];
1611
1827
  case 2:
1612
- return _context41.a(2, {
1828
+ return _context42.a(2, {
1613
1829
  json: {
1614
1830
  id: body.id
1615
1831
  }
1616
1832
  });
1617
1833
  case 3:
1618
1834
  if (!(body.data_root && body.data === "")) {
1619
- _context41.n = 4;
1835
+ _context42.n = 4;
1620
1836
  break;
1621
1837
  }
1622
1838
  this.data[body.data_root] = body;
1623
- _context41.n = 5;
1839
+ this._dataTimestamps[body.data_root] = Date.now();
1840
+ _context42.n = 5;
1624
1841
  break;
1625
1842
  case 4:
1626
- _context41.n = 5;
1843
+ _context42.n = 5;
1627
1844
  return this._ar.postTx(body);
1628
1845
  case 5:
1629
- return _context41.a(2, {
1846
+ return _context42.a(2, {
1630
1847
  json: {
1631
1848
  id: body.id
1632
1849
  }
1633
1850
  });
1634
1851
  case 6:
1635
- return _context41.a(2);
1852
+ return _context42.a(2);
1636
1853
  }
1637
- }, _callee41, this);
1854
+ }, _callee42, this);
1638
1855
  }));
1639
- function ar_post_id(_x41) {
1856
+ function ar_post_id(_x42) {
1640
1857
  return _ar_post_id.apply(this, arguments);
1641
1858
  }
1642
1859
  return ar_post_id;