wao 0.9.1 → 0.9.2

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/armem-web.js CHANGED
@@ -1,21 +1,15 @@
1
1
  "use strict";
2
2
 
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
7
  exports["default"] = void 0;
7
- var _arweave = _interopRequireDefault(require("arweave"));
8
- var _ramda = require("ramda");
9
- var _utils = require("./utils.js");
10
- var _localforage = _interopRequireDefault(require("localforage"));
11
8
  var _weavedbLite = _interopRequireDefault(require("./lua/weavedb-lite.js"));
12
- var _Arweave$default;
9
+ var _armemBase = _interopRequireDefault(require("./armem-base.js"));
10
+ var _lfdb = _interopRequireDefault(require("./lfdb.js"));
13
11
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
14
12
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
15
- function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
16
- function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
17
- function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
18
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
19
13
  function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
20
14
  function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
21
15
  function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
@@ -23,567 +17,42 @@ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o =
23
17
  function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
24
18
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
25
19
  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); }
26
- var Arweave = (_Arweave$default = _arweave["default"]["default"]) !== null && _Arweave$default !== void 0 ? _Arweave$default : _arweave["default"];
27
- var ArMem = exports["default"] = /*#__PURE__*/function () {
20
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
21
+ function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
22
+ function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
23
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
24
+ function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
25
+ function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
26
+ function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
27
+ var ArMem = exports["default"] = /*#__PURE__*/function (_Base) {
28
28
  function ArMem() {
29
- var _this = this;
30
- var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
31
- MU_URL = _ref.MU_URL,
32
- CU_URL = _ref.CU_URL,
33
- SU_URL = _ref.SU_URL,
34
- GATEWAY_URL = _ref.GATEWAY_URL,
35
- scheduler = _ref.scheduler,
36
- cache = _ref.cache;
29
+ var _this;
30
+ var args = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
37
31
  _classCallCheck(this, ArMem);
38
- this.__type__ = "mem";
39
- this.isInit = false;
40
- this.keyInit = false;
41
- this.keys = {};
42
- this.db = {
43
- put: function () {
44
- var _put = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(key, val) {
45
- var _val, k, _arr, _iterator, _step, v, __val, k2, _val2, _k;
46
- return _regeneratorRuntime().wrap(function _callee$(_context) {
47
- while (1) switch (_context.prev = _context.next) {
48
- case 0:
49
- _val = null;
50
- if (_typeof(val) === "object" && !(0, _ramda.is)(Array, val)) {
51
- _val = {};
52
- for (k in val) {
53
- if (typeof val[k] !== "function") {
54
- if ((0, _ramda.is)(Array, val[k])) {
55
- _arr = [];
56
- _iterator = _createForOfIteratorHelper(val[k]);
57
- try {
58
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
59
- v = _step.value;
60
- if (_typeof(v) === "object" && !(0, _ramda.is)(Array, v) && !(v instanceof Uint8Array) && !(v instanceof ArrayBuffer)) {
61
- __val = {};
62
- for (k2 in v) {
63
- if (typeof v[k2] !== "function") __val[k2] = v[k2];
64
- }
65
- _arr.push(__val);
66
- } else {
67
- _arr.push(v);
68
- }
69
- }
70
- } catch (err) {
71
- _iterator.e(err);
72
- } finally {
73
- _iterator.f();
74
- }
75
- _val[k] = _arr;
76
- } else if (_typeof(val[k]) === "object" && !(val[k] instanceof Uint8Array) && !(val[k] instanceof ArrayBuffer)) {
77
- _val2 = {};
78
- for (_k in val[k]) {
79
- if (typeof val[k][_k] !== "function") _val2[_k] = val[k][_k];
80
- }
81
- _val[k] = _val2;
82
- } else {
83
- _val[k] = val[k];
84
- }
85
- }
86
- }
87
- } else _val = val;
88
- _context.next = 4;
89
- return _localforage["default"].setItem(key, _val);
90
- case 4:
91
- _this.keys[key] = true;
92
- _context.next = 7;
93
- return _localforage["default"].setItem("keys", (0, _ramda.keys)(_this.keys));
94
- case 7:
95
- case "end":
96
- return _context.stop();
97
- }
98
- }, _callee);
99
- }));
100
- function put(_x, _x2) {
101
- return _put.apply(this, arguments);
102
- }
103
- return put;
104
- }(),
105
- get: function () {
106
- var _get = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(key) {
107
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
108
- while (1) switch (_context2.prev = _context2.next) {
109
- case 0:
110
- _context2.next = 2;
111
- return _localforage["default"].getItem(key);
112
- case 2:
113
- return _context2.abrupt("return", _context2.sent);
114
- case 3:
115
- case "end":
116
- return _context2.stop();
117
- }
118
- }, _callee2);
119
- }));
120
- function get(_x3) {
121
- return _get.apply(this, arguments);
122
- }
123
- return get;
124
- }(),
125
- getKeys: function () {
126
- var _getKeys = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref2) {
127
- var start, end, _yield$lf$getItem, _keys, _iterator2, _step2, v, __keys, k, sp;
128
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
129
- while (1) switch (_context3.prev = _context3.next) {
130
- case 0:
131
- start = _ref2.start, end = _ref2.end;
132
- if (_this.keyInit) {
133
- _context3.next = 17;
134
- break;
135
- }
136
- _context3.next = 4;
137
- return _localforage["default"].getItem("keys");
138
- case 4:
139
- _context3.t1 = _yield$lf$getItem = _context3.sent;
140
- _context3.t0 = _context3.t1 !== null;
141
- if (!_context3.t0) {
142
- _context3.next = 8;
143
- break;
144
- }
145
- _context3.t0 = _yield$lf$getItem !== void 0;
146
- case 8:
147
- if (!_context3.t0) {
148
- _context3.next = 12;
149
- break;
150
- }
151
- _context3.t2 = _yield$lf$getItem;
152
- _context3.next = 13;
153
- break;
154
- case 12:
155
- _context3.t2 = [];
156
- case 13:
157
- _keys = _context3.t2;
158
- _this.keys = {};
159
- _iterator2 = _createForOfIteratorHelper(_keys);
160
- try {
161
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
162
- v = _step2.value;
163
- _this.keys[v] = true;
164
- }
165
- } catch (err) {
166
- _iterator2.e(err);
167
- } finally {
168
- _iterator2.f();
169
- }
170
- case 17:
171
- __keys = [];
172
- for (k in _this.keys) {
173
- sp = k.split(".");
174
- if (sp[0] === start) __keys.push(k);
175
- }
176
- return _context3.abrupt("return", __keys);
177
- case 20:
178
- case "end":
179
- return _context3.stop();
180
- }
181
- }, _callee3);
182
- }));
183
- function getKeys(_x4) {
184
- return _getKeys.apply(this, arguments);
185
- }
186
- return getKeys;
187
- }()
188
- };
189
- this.arweave = Arweave.init();
190
- this.arweave.transactions.getTransactionAnchor = function () {
191
- return _this.getAnchor();
192
- };
193
- this.arweave.transactions.getPrice = function () {
194
- return 0;
195
- };
196
- this.scheduler = scheduler;
197
- this.SU_URL = SU_URL;
198
- this.initSync();
32
+ _this = _callSuper(this, ArMem, [args]);
33
+ _this.db = (0, _lfdb["default"])(_this);
34
+ _this.initSync();
35
+ return _this;
199
36
  }
37
+ _inherits(ArMem, _Base);
200
38
  return _createClass(ArMem, [{
201
- key: "putAll",
39
+ key: "_getWasm",
202
40
  value: function () {
203
- var _putAll = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(key) {
204
- var k;
205
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
206
- while (1) switch (_context4.prev = _context4.next) {
41
+ var _getWasm2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(file) {
42
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
43
+ while (1) switch (_context.prev = _context.next) {
207
44
  case 0:
208
- _context4.t0 = _regeneratorRuntime().keys(this[key]);
45
+ return _context.abrupt("return", Buffer.from(_weavedbLite["default"], "base64"));
209
46
  case 1:
210
- if ((_context4.t1 = _context4.t0()).done) {
211
- _context4.next = 7;
212
- break;
213
- }
214
- k = _context4.t1.value;
215
- _context4.next = 5;
216
- return this.set(this[key][k], key, k);
217
- case 5:
218
- _context4.next = 1;
219
- break;
220
- case 7:
221
- case "end":
222
- return _context4.stop();
223
- }
224
- }, _callee4, this);
225
- }));
226
- function putAll(_x5) {
227
- return _putAll.apply(this, arguments);
228
- }
229
- return putAll;
230
- }()
231
- }, {
232
- key: "init",
233
- value: function () {
234
- var _init = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
235
- var _i, _arr2, v, _i2, _arr3, _this$_v, _v, items, _iterator3, _step3, v2, key, field, _i3, _arr4, _v2, _i4, _arr5, _v3;
236
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
237
- while (1) switch (_context5.prev = _context5.next) {
238
- case 0:
239
- if (!this.isInit) {
240
- _context5.next = 2;
241
- break;
242
- }
243
- return _context5.abrupt("return");
244
- case 2:
245
- this.isInit = true;
246
- if (!this.db) {
247
- _context5.next = 46;
248
- break;
249
- }
250
- _i = 0, _arr2 = ["height", "blocks"];
251
- case 5:
252
- if (!(_i < _arr2.length)) {
253
- _context5.next = 13;
254
- break;
255
- }
256
- v = _arr2[_i];
257
- _context5.next = 9;
258
- return this.get(v);
259
- case 9:
260
- this[v] = _context5.sent;
261
- case 10:
262
- _i++;
263
- _context5.next = 5;
264
- break;
265
- case 13:
266
- _i2 = 0, _arr3 = ["txs", "jwks", "env", "modules", "wasms", "addrmap", "blockmap", "modmap", "msgs"];
267
- case 14:
268
- if (!(_i2 < _arr3.length)) {
269
- _context5.next = 44;
270
- break;
271
- }
272
- _v = _arr3[_i2];
273
- (_this$_v = this[_v]) !== null && _this$_v !== void 0 ? _this$_v : this[_v] = {};
274
- _context5.next = 19;
275
- return this.db.getKeys({
276
- start: _v,
277
- end: _v + "a"
278
- });
279
- case 19:
280
- items = _context5.sent;
281
- _iterator3 = _createForOfIteratorHelper(items || []);
282
- _context5.prev = 21;
283
- _iterator3.s();
284
- case 23:
285
- if ((_step3 = _iterator3.n()).done) {
286
- _context5.next = 33;
287
- break;
288
- }
289
- v2 = _step3.value;
290
- key = v2.split(".")[0];
291
- field = v2.split(".")[1];
292
- if (!(key === _v)) {
293
- _context5.next = 31;
294
- break;
295
- }
296
- _context5.next = 30;
297
- return this.db.get(v2);
298
- case 30:
299
- this[_v][field] = _context5.sent;
300
- case 31:
301
- _context5.next = 23;
302
- break;
303
- case 33:
304
- _context5.next = 38;
305
- break;
306
- case 35:
307
- _context5.prev = 35;
308
- _context5.t0 = _context5["catch"](21);
309
- _iterator3.e(_context5.t0);
310
- case 38:
311
- _context5.prev = 38;
312
- _iterator3.f();
313
- return _context5.finish(38);
314
- case 41:
315
- _i2++;
316
- _context5.next = 14;
317
- break;
318
- case 44:
319
- _context5.next = 62;
320
- break;
321
- case 46:
322
- _i3 = 0, _arr4 = ["height", "blocks"];
323
- case 47:
324
- if (!(_i3 < _arr4.length)) {
325
- _context5.next = 54;
326
- break;
327
- }
328
- _v2 = _arr4[_i3];
329
- _context5.next = 51;
330
- return this.set(this[_v2], _v2);
331
- case 51:
332
- _i3++;
333
- _context5.next = 47;
334
- break;
335
- case 54:
336
- _i4 = 0, _arr5 = ["modules", "wasms", "addrmap", "blockmap"];
337
- case 55:
338
- if (!(_i4 < _arr5.length)) {
339
- _context5.next = 62;
340
- break;
341
- }
342
- _v3 = _arr5[_i4];
343
- _context5.next = 59;
344
- return this.putAll(_v3);
345
- case 59:
346
- _i4++;
347
- _context5.next = 55;
348
- break;
349
- case 62:
350
- case "end":
351
- return _context5.stop();
352
- }
353
- }, _callee5, this, [[21, 35, 38, 41]]);
354
- }));
355
- function init() {
356
- return _init.apply(this, arguments);
357
- }
358
- return init;
359
- }()
360
- }, {
361
- key: "getWasm",
362
- value: function () {
363
- var _getWasm = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(module) {
364
- var _format;
365
- var mod, __dirname, format, _wasm, wasm, tx;
366
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
367
- while (1) switch (_context6.prev = _context6.next) {
368
- case 0:
369
- mod = module !== null && module !== void 0 ? module : this.modules.aos2_0_1;
370
- if (mod) {
371
- _context6.next = 3;
372
- break;
373
- }
374
- throw Error("module not found");
375
- case 3:
376
- _context6.next = 5;
377
- return (0, _utils.dirname)();
378
- case 5:
379
- __dirname = _context6.sent;
380
- format = null;
381
- _context6.next = 9;
382
- return this.wasms[mod];
383
- case 9:
384
- _wasm = _context6.sent;
385
- wasm = _wasm === null || _wasm === void 0 ? void 0 : _wasm.data;
386
- if (wasm) {
387
- _context6.next = 23;
388
- break;
389
- }
390
- if (!(_wasm !== null && _wasm !== void 0 && _wasm.file)) {
391
- _context6.next = 17;
392
- break;
393
- }
394
- wasm = Buffer.from(_weavedbLite["default"], "base64");
395
- format = _wasm.format;
396
- _context6.next = 21;
397
- break;
398
- case 17:
399
- _context6.next = 19;
400
- return this.get("txs", mod);
401
- case 19:
402
- tx = _context6.sent;
403
- if (tx) {
404
- wasm = Buffer.from(tx.data, "base64");
405
- format = (0, _utils.tags)(tx.tags)["Module-Format"];
406
- }
407
- case 21:
408
- _context6.next = 24;
409
- break;
410
- case 23:
411
- format = _wasm.format;
412
- case 24:
413
- (_format = format) !== null && _format !== void 0 ? _format : format = "wasm64-unknown-emscripten-draft_2024_02_15";
414
- return _context6.abrupt("return", {
415
- format: format,
416
- mod: mod,
417
- wasm: wasm
418
- });
419
- case 26:
420
- case "end":
421
- return _context6.stop();
422
- }
423
- }, _callee6, this);
424
- }));
425
- function getWasm(_x6) {
426
- return _getWasm.apply(this, arguments);
427
- }
428
- return getWasm;
429
- }()
430
- }, {
431
- key: "initSync",
432
- value: function initSync() {
433
- this.addrmap = {};
434
- this.txs = {};
435
- this.jwks = {};
436
- this.blocks = [];
437
- this.blockmap = {};
438
- this.env = {};
439
- this.modules = {
440
- aos2_0_1: "Do_Uc2Sju_ffp6Ev0AnLVdPtot15rvMjP-a9VVaA5fM",
441
- aos1: "cNlipBptaF9JeFAf4wUmpi43EojNanIBos3EfNrEOWo",
442
- sqlite: "ghSkge2sIUD_F00ym5sEimC63BDBuBrq4b5OcwxOjiw"
443
- };
444
- this.modmap = {};
445
- this.msgs = {};
446
- this.wasms = {
447
- "Do_Uc2Sju_ffp6Ev0AnLVdPtot15rvMjP-a9VVaA5fM": {
448
- file: "aos2_0_1",
449
- format: "wasm64-unknown-emscripten-draft_2024_02_15"
450
- },
451
- cNlipBptaF9JeFAf4wUmpi43EojNanIBos3EfNrEOWo: {
452
- file: "aos_1",
453
- format: "wasm64-unknown-emscripten-draft_2024_02_15"
454
- },
455
- ghSkge2sIUD_F00ym5sEimC63BDBuBrq4b5OcwxOjiw: {
456
- file: "sqlite",
457
- format: "wasm64-unknown-emscripten-draft_2024_02_15"
458
- }
459
- };
460
- var txs = [];
461
- for (var k in this.modules) {
462
- var key = this.modules[k];
463
- txs.push(key);
464
- this.txs[key] = {
465
- id: key,
466
- block: 0,
467
- tags: (0, _utils.buildTags)(null, {
468
- "Data-Protocol": "ao",
469
- Variant: "ao.TN.1",
470
- Type: "Module",
471
- "Module-Format": "wasm64-unknown-emscripten-draft_2024_02_15",
472
- "Input-Encoding": "JSON-V1",
473
- "Output-Encoding": "JSON-V1",
474
- "Memory-Limit": "1-gb",
475
- "Compute-Limit": "9000000000000",
476
- Extension: "WeaveDrive"
477
- })
478
- };
479
- }
480
- if (this.scheduler && this.SU_URL) {
481
- var _key = this.scheduler;
482
- txs.push(_key);
483
- this.addrmap[this.scheduler] = {
484
- address: this.scheduler
485
- };
486
- this.txs[_key] = {
487
- id: _key,
488
- block: 0,
489
- owner: this.scheduler,
490
- tags: (0, _utils.buildTags)(null, {
491
- "Data-Protocol": "ao",
492
- Variant: "ao.TN.1",
493
- Type: "Scheduler-Location",
494
- Url: this.SU_URL,
495
- "Time-To-Live": 1000 * 60 * 60 * 24 * 365 * 10
496
- })
497
- };
498
- }
499
- this.blockmap["0"] = {
500
- txs: txs,
501
- timestamp: Date.now(),
502
- height: 0,
503
- previous: "",
504
- id: "0"
505
- };
506
- this.blocks.push("0");
507
- this.height = 1;
508
- }
509
- }, {
510
- key: "getAnchor",
511
- value: function getAnchor() {
512
- return this.blocks.length === 0 ? "Do_Uc2Sju_ffp6Ev0AnLVdPtot15rvMjP-a9VVaA5fM" : (0, _ramda.last)(this.blockmap[(0, _ramda.last)(this.blocks)].txs);
513
- }
514
- }, {
515
- key: "get",
516
- value: function () {
517
- var _get2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(key, field) {
518
- var _this$key;
519
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
520
- while (1) switch (_context7.prev = _context7.next) {
521
- case 0:
522
- _context7.next = 2;
523
- return this.init();
524
- case 2:
525
- if (field) {
526
- _context7.next = 4;
527
- break;
528
- }
529
- return _context7.abrupt("return", this[key]);
530
- case 4:
531
- return _context7.abrupt("return", (_this$key = this[key]) === null || _this$key === void 0 ? void 0 : _this$key[field]);
532
- case 5:
533
- case "end":
534
- return _context7.stop();
535
- }
536
- }, _callee7, this);
537
- }));
538
- function get(_x7, _x8) {
539
- return _get2.apply(this, arguments);
540
- }
541
- return get;
542
- }()
543
- }, {
544
- key: "set",
545
- value: function () {
546
- var _set = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(val, key, field) {
547
- var _this$key2;
548
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
549
- while (1) switch (_context8.prev = _context8.next) {
550
- case 0:
551
- _context8.next = 2;
552
- return this.init();
553
- case 2:
554
- if (field) {
555
- _context8.next = 9;
556
- break;
557
- }
558
- this[key] = val;
559
- if (!this.db) {
560
- _context8.next = 7;
561
- break;
562
- }
563
- _context8.next = 7;
564
- return this.db.put("".concat(key), this[key]);
565
- case 7:
566
- _context8.next = 14;
567
- break;
568
- case 9:
569
- (_this$key2 = this[key]) !== null && _this$key2 !== void 0 ? _this$key2 : this[key] = {};
570
- this[key][field] = val;
571
- if (!this.db) {
572
- _context8.next = 14;
573
- break;
574
- }
575
- _context8.next = 14;
576
- return this.db.put("".concat(key, ".").concat(field), this[key][field]);
577
- case 14:
578
47
  case "end":
579
- return _context8.stop();
48
+ return _context.stop();
580
49
  }
581
- }, _callee8, this);
50
+ }, _callee);
582
51
  }));
583
- function set(_x9, _x10, _x11) {
584
- return _set.apply(this, arguments);
52
+ function _getWasm(_x) {
53
+ return _getWasm2.apply(this, arguments);
585
54
  }
586
- return set;
55
+ return _getWasm;
587
56
  }()
588
57
  }]);
589
- }();
58
+ }(_armemBase["default"]);