wao 0.4.11 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cjs/server.js ADDED
@@ -0,0 +1,632 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+ var _express = _interopRequireDefault(require("express"));
8
+ var _base64url = _interopRequireDefault(require("base64url"));
9
+ var _arbundles = require("arbundles");
10
+ var _utils = require("./utils.js");
11
+ var _aoconnect = require("./aoconnect.js");
12
+ var _test = require("./test.js");
13
+ var _bodyParser = _interopRequireDefault(require("body-parser"));
14
+ var _graphql = require("graphql");
15
+ var _ramda = require("ramda");
16
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
17
+ 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); }
18
+ 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; } } }; }
19
+ 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; } }
20
+ 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; }
21
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
22
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
23
+ 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; }
24
+ 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); }
25
+ 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); }); }; }
26
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
27
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
28
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
29
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
30
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
31
+ 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); }
32
+ var schema = (0, _graphql.buildSchema)("\n schema {\n query: Query\n }\n\n type Query {\n transactions(\n ids: [ID!]\n tags: [TagFilter!]\n block: BlockFilter\n after: String\n first: Int\n ): TransactionConnection!\n\n block(id: ID, height: Int): Block\n }\n\n type TransactionConnection {\n edges: [TransactionEdge!]!\n pageInfo: PageInfo!\n }\n\n type TransactionEdge {\n cursor: String!\n node: Transaction!\n }\n\n type Transaction {\n id: ID!\n anchor: String\n signature: String!\n recipient: String\n owner: Owner!\n fee: Quantity!\n quantity: Quantity!\n data: Data!\n tags: [Tag!]!\n block: Block\n parent: Transaction\n }\n\n type Owner {\n address: String!\n key: String!\n }\n\n type Quantity {\n winston: String!\n ar: String!\n }\n\n type Data {\n size: String!\n type: String\n }\n\n type Tag {\n name: String!\n value: String!\n }\n\n type Block {\n id: ID!\n timestamp: Int!\n height: Int!\n previous: String\n transactions: [Transaction!]!\n miner: String!\n reward: String!\n tags: [Tag!]!\n indepHash: String!\n nonce: String!\n }\n\n type PageInfo {\n hasNextPage: Boolean!\n }\n\n input TagFilter {\n name: String!\n values: [String!]!\n }\n\n input BlockFilter {\n min: Int\n max: Int\n }\n");
33
+ var root = {
34
+ transactions: function transactions(_ref) {
35
+ var first = _ref.first;
36
+ return {
37
+ edges: [],
38
+ pageInfo: {
39
+ hasNextPage: false
40
+ }
41
+ };
42
+ },
43
+ block: function block(_ref2) {
44
+ var id = _ref2.id;
45
+ return {
46
+ id: id,
47
+ timestamp: Date.now(),
48
+ height: 123456,
49
+ previous: "previous-block-id",
50
+ transactions: [],
51
+ miner: "example-miner",
52
+ reward: "1000",
53
+ tags: [],
54
+ indepHash: "example-indep-hash",
55
+ nonce: "000000"
56
+ };
57
+ }
58
+ };
59
+ var mapParsed = function mapParsed(parsedQuery, variables) {
60
+ var operation = parsedQuery.definitions[0];
61
+ if (operation.operation !== "query") {
62
+ throw new Error("Only 'query' operations are supported.");
63
+ }
64
+ var rootField = operation.selectionSet.selections[0];
65
+ var rootFieldName = rootField.name.value;
66
+ var _parseArgumentValue = function parseArgumentValue(argValue) {
67
+ if (argValue.kind === "Variable") {
68
+ return variables[argValue.name.value];
69
+ }
70
+ if (argValue.kind === "ListValue") {
71
+ return argValue.values.map(function (value) {
72
+ return _parseArgumentValue(value);
73
+ });
74
+ }
75
+ if (argValue.kind === "ObjectValue") {
76
+ return argValue.fields.reduce(function (obj, field) {
77
+ obj[field.name.value] = _parseArgumentValue(field.value);
78
+ return obj;
79
+ }, {});
80
+ }
81
+ return argValue.value;
82
+ };
83
+ var args = rootField.arguments.reduce(function (acc, arg) {
84
+ acc[arg.name.value] = _parseArgumentValue(arg.value);
85
+ return acc;
86
+ }, {});
87
+ var _extractFields = function extractFields(selectionSet) {
88
+ return selectionSet.selections.map(function (selection) {
89
+ var fieldName = selection.name.value;
90
+ if (selection.selectionSet) {
91
+ return _defineProperty({}, fieldName, _extractFields(selection.selectionSet));
92
+ }
93
+ return fieldName;
94
+ });
95
+ };
96
+ var fields = _extractFields(rootField.selectionSet);
97
+ return {
98
+ rootFieldName: rootFieldName,
99
+ args: args,
100
+ fields: fields
101
+ };
102
+ };
103
+ var Server = /*#__PURE__*/function () {
104
+ function Server() {
105
+ var _ref4 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
106
+ _ref4$ar = _ref4.ar,
107
+ ar = _ref4$ar === void 0 ? 4000 : _ref4$ar,
108
+ _ref4$mu = _ref4.mu,
109
+ mu = _ref4$mu === void 0 ? 4002 : _ref4$mu,
110
+ _ref4$su = _ref4.su,
111
+ su = _ref4$su === void 0 ? 4003 : _ref4$su,
112
+ _ref4$cu = _ref4.cu,
113
+ cu = _ref4$cu === void 0 ? 4004 : _ref4$cu,
114
+ aoconnect = _ref4.aoconnect;
115
+ _classCallCheck(this, Server);
116
+ var _connect = (0, _aoconnect.connect)(aoconnect),
117
+ _ar = _connect.ar,
118
+ message = _connect.message,
119
+ spawn = _connect.spawn,
120
+ dryrun = _connect.dryrun,
121
+ result = _connect.result,
122
+ results = _connect.results,
123
+ mem = _connect.mem,
124
+ monitor = _connect.monitor,
125
+ unmonitor = _connect.unmonitor;
126
+ this.monitor = monitor;
127
+ this.unmonitor = unmonitor;
128
+ this.spawn = spawn;
129
+ this._ar = _ar;
130
+ this.message = message;
131
+ this.dryrun = dryrun;
132
+ this.result = result;
133
+ this.results = results;
134
+ this.mem = mem;
135
+ this.gql = new _test.GQL({
136
+ mem: mem
137
+ });
138
+ this.ports = {
139
+ ar: ar,
140
+ mu: mu,
141
+ su: su,
142
+ cu: cu
143
+ };
144
+ this.servers = [];
145
+ this.ar();
146
+ this.mu();
147
+ this.su();
148
+ this.cu();
149
+ }
150
+ return _createClass(Server, [{
151
+ key: "ar",
152
+ value: function ar() {
153
+ var _this = this;
154
+ var app = (0, _express["default"])();
155
+ app.use(_bodyParser["default"].json({
156
+ limit: "100mb"
157
+ }));
158
+ app.get("/tx/:id/offset", /*#__PURE__*/function () {
159
+ var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(req, res) {
160
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
161
+ while (1) switch (_context.prev = _context.next) {
162
+ case 0:
163
+ res.status(500);
164
+ res.send(null);
165
+ case 2:
166
+ case "end":
167
+ return _context.stop();
168
+ }
169
+ }, _callee);
170
+ }));
171
+ return function (_x, _x2) {
172
+ return _ref5.apply(this, arguments);
173
+ };
174
+ }());
175
+ app.get("/tx_anchor", /*#__PURE__*/function () {
176
+ var _ref6 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(req, res) {
177
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
178
+ while (1) switch (_context2.prev = _context2.next) {
179
+ case 0:
180
+ res.send(_this.mem.getAnchor());
181
+ case 1:
182
+ case "end":
183
+ return _context2.stop();
184
+ }
185
+ }, _callee2);
186
+ }));
187
+ return function (_x3, _x4) {
188
+ return _ref6.apply(this, arguments);
189
+ };
190
+ }());
191
+ app.get("/mine", /*#__PURE__*/function () {
192
+ var _ref7 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(req, res) {
193
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
194
+ while (1) switch (_context3.prev = _context3.next) {
195
+ case 0:
196
+ res.json(req.params);
197
+ case 1:
198
+ case "end":
199
+ return _context3.stop();
200
+ }
201
+ }, _callee3);
202
+ }));
203
+ return function (_x5, _x6) {
204
+ return _ref7.apply(this, arguments);
205
+ };
206
+ }());
207
+ app.get("/:id", /*#__PURE__*/function () {
208
+ var _ref8 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(req, res) {
209
+ var _data;
210
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
211
+ while (1) switch (_context4.prev = _context4.next) {
212
+ case 0:
213
+ _context4.next = 2;
214
+ return _this._ar.data(req.params.id);
215
+ case 2:
216
+ _data = _context4.sent;
217
+ if (!_data) {
218
+ res.status(404);
219
+ res.send(null);
220
+ } else {
221
+ res.send(Buffer.from(_data, "base64"));
222
+ }
223
+ case 4:
224
+ case "end":
225
+ return _context4.stop();
226
+ }
227
+ }, _callee4);
228
+ }));
229
+ return function (_x7, _x8) {
230
+ return _ref8.apply(this, arguments);
231
+ };
232
+ }());
233
+ app.get("/price/:id", /*#__PURE__*/function () {
234
+ var _ref9 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(req, res) {
235
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
236
+ while (1) switch (_context5.prev = _context5.next) {
237
+ case 0:
238
+ res.send("0");
239
+ case 1:
240
+ case "end":
241
+ return _context5.stop();
242
+ }
243
+ }, _callee5);
244
+ }));
245
+ return function (_x9, _x10) {
246
+ return _ref9.apply(this, arguments);
247
+ };
248
+ }());
249
+ app.post("/graphql", /*#__PURE__*/function () {
250
+ var _ref10 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(req, res) {
251
+ var _req$body, query, variables, parsedQuery, errors, parsed, tar, fields, args, res2, edges;
252
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
253
+ while (1) switch (_context6.prev = _context6.next) {
254
+ case 0:
255
+ _req$body = req.body, query = _req$body.query, variables = _req$body.variables;
256
+ parsedQuery = (0, _graphql.parse)(query);
257
+ errors = (0, _graphql.validate)(schema, parsedQuery);
258
+ parsed = mapParsed(parsedQuery, variables);
259
+ tar = parsed.rootFieldName;
260
+ fields = parsed.fields[0].edges[0].node;
261
+ args = parsed.args;
262
+ res2 = null;
263
+ if (!(tar === "transactions")) {
264
+ _context6.next = 14;
265
+ break;
266
+ }
267
+ _context6.next = 11;
268
+ return _this.gql.txs(_objectSpread({}, args));
269
+ case 11:
270
+ res2 = _context6.sent;
271
+ _context6.next = 18;
272
+ break;
273
+ case 14:
274
+ if (!(tar === "blocks")) {
275
+ _context6.next = 18;
276
+ break;
277
+ }
278
+ _context6.next = 17;
279
+ return _this.gql.blocks();
280
+ case 17:
281
+ res2 = _context6.sent;
282
+ case 18:
283
+ edges = (0, _ramda.map)(function (v) {
284
+ return {
285
+ node: v,
286
+ cursor: v.cursor
287
+ };
288
+ }, res2);
289
+ res.json({
290
+ data: {
291
+ transactions: {
292
+ edges: edges
293
+ }
294
+ }
295
+ });
296
+ case 20:
297
+ case "end":
298
+ return _context6.stop();
299
+ }
300
+ }, _callee6);
301
+ }));
302
+ return function (_x11, _x12) {
303
+ return _ref10.apply(this, arguments);
304
+ };
305
+ }());
306
+ var data = {};
307
+ app.post("/:id", /*#__PURE__*/function () {
308
+ var _ref11 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(req, res) {
309
+ var buf;
310
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
311
+ while (1) switch (_context7.prev = _context7.next) {
312
+ case 0:
313
+ if (!req.body.chunk) {
314
+ _context7.next = 14;
315
+ break;
316
+ }
317
+ if (!data[req.body.data_root]) {
318
+ _context7.next = 11;
319
+ break;
320
+ }
321
+ data[req.body.data_root].data += req.body.chunk;
322
+ buf = Buffer.from(req.body.chunk, "base64");
323
+ if (!data[req.body.data_root].chunks) {
324
+ data[req.body.data_root].chunks = buf;
325
+ } else {
326
+ data[req.body.data_root].chunks = Buffer.concat([data[req.body.data_root].chunks, buf]);
327
+ }
328
+ delete req.body.chunk;
329
+ if (!(data[req.body.data_root].data_size <= data[req.body.data_root].chunks.length)) {
330
+ _context7.next = 11;
331
+ break;
332
+ }
333
+ data[req.body.data_root].data = data[req.body.data_root].chunks.toString("base64");
334
+ _context7.next = 10;
335
+ return _this._ar.postTx(data[req.body.data_root]);
336
+ case 10:
337
+ delete data[req.body.data_root];
338
+ case 11:
339
+ res.json({
340
+ id: req.body.id
341
+ });
342
+ _context7.next = 21;
343
+ break;
344
+ case 14:
345
+ if (!(req.body.data_root && req.body.data === "")) {
346
+ _context7.next = 18;
347
+ break;
348
+ }
349
+ data[req.body.data_root] = req.body;
350
+ _context7.next = 20;
351
+ break;
352
+ case 18:
353
+ _context7.next = 20;
354
+ return _this._ar.postTx(req.body);
355
+ case 20:
356
+ res.json({
357
+ id: req.body.id
358
+ });
359
+ case 21:
360
+ case "end":
361
+ return _context7.stop();
362
+ }
363
+ }, _callee7);
364
+ }));
365
+ return function (_x13, _x14) {
366
+ return _ref11.apply(this, arguments);
367
+ };
368
+ }());
369
+ app.post("/tx", /*#__PURE__*/function () {
370
+ var _ref12 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(req, res) {
371
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
372
+ while (1) switch (_context8.prev = _context8.next) {
373
+ case 0:
374
+ _context8.next = 2;
375
+ return _this._ar.postTx(req.body);
376
+ case 2:
377
+ res.json({
378
+ id: req.body.id
379
+ });
380
+ case 3:
381
+ case "end":
382
+ return _context8.stop();
383
+ }
384
+ }, _callee8);
385
+ }));
386
+ return function (_x15, _x16) {
387
+ return _ref12.apply(this, arguments);
388
+ };
389
+ }());
390
+ var server = app.listen(this.ports.ar, function () {
391
+ console.log("AR on port ".concat(_this.ports.ar));
392
+ });
393
+ this.servers.push(server);
394
+ }
395
+ }, {
396
+ key: "mu",
397
+ value: function mu() {
398
+ var _this2 = this;
399
+ var app = (0, _express["default"])();
400
+ app.use(_express["default"].raw({
401
+ type: "*/*"
402
+ }));
403
+ app.get("/", function (req, res) {
404
+ return res.send("ao messenger unit");
405
+ });
406
+ app.post("/monitor/:id", /*#__PURE__*/function () {
407
+ var _ref13 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(req, res) {
408
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
409
+ while (1) switch (_context9.prev = _context9.next) {
410
+ case 0:
411
+ _context9.next = 2;
412
+ return _this2.monitor({
413
+ process: req.params.id
414
+ });
415
+ case 2:
416
+ res.json({
417
+ id: req.params.id,
418
+ messag: "cron monitored!"
419
+ });
420
+ case 3:
421
+ case "end":
422
+ return _context9.stop();
423
+ }
424
+ }, _callee9);
425
+ }));
426
+ return function (_x17, _x18) {
427
+ return _ref13.apply(this, arguments);
428
+ };
429
+ }());
430
+ app["delete"]("/monitor/:id", /*#__PURE__*/function () {
431
+ var _ref14 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(req, res) {
432
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
433
+ while (1) switch (_context10.prev = _context10.next) {
434
+ case 0:
435
+ _context10.next = 2;
436
+ return _this2.unmonitor({
437
+ process: req.params.id
438
+ });
439
+ case 2:
440
+ res.json({
441
+ id: req.params.id,
442
+ message: "cron deleted!"
443
+ });
444
+ case 3:
445
+ case "end":
446
+ return _context10.stop();
447
+ }
448
+ }, _callee10);
449
+ }));
450
+ return function (_x19, _x20) {
451
+ return _ref14.apply(this, arguments);
452
+ };
453
+ }());
454
+ app.post("/", /*#__PURE__*/function () {
455
+ var _ref15 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(req, res) {
456
+ var binary, valid, type, item, _tags, err;
457
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
458
+ while (1) switch (_context11.prev = _context11.next) {
459
+ case 0:
460
+ binary = req.body;
461
+ _context11.next = 3;
462
+ return _arbundles.DataItem.verify(binary);
463
+ case 3:
464
+ valid = _context11.sent;
465
+ type = null;
466
+ item = null;
467
+ if (valid) item = new _arbundles.DataItem(binary);
468
+ _tags = (0, _utils.tags)(item.tags);
469
+ err = null;
470
+ if (!(_tags.Type === "Process")) {
471
+ _context11.next = 14;
472
+ break;
473
+ }
474
+ _context11.next = 12;
475
+ return _this2.spawn({
476
+ item: item,
477
+ module: _tags.Module,
478
+ scheduler: _tags.Scheduler
479
+ });
480
+ case 12:
481
+ _context11.next = 20;
482
+ break;
483
+ case 14:
484
+ if (!(_tags.Type === "Message")) {
485
+ _context11.next = 19;
486
+ break;
487
+ }
488
+ _context11.next = 17;
489
+ return _this2.message({
490
+ item: item,
491
+ process: item.target
492
+ });
493
+ case 17:
494
+ _context11.next = 20;
495
+ break;
496
+ case 19:
497
+ err = true;
498
+ case 20:
499
+ if (err) res.status(500);
500
+ res.send({
501
+ id: item.id
502
+ });
503
+ case 22:
504
+ case "end":
505
+ return _context11.stop();
506
+ }
507
+ }, _callee11);
508
+ }));
509
+ return function (_x21, _x22) {
510
+ return _ref15.apply(this, arguments);
511
+ };
512
+ }());
513
+ var server = app.listen(this.ports.mu, function () {
514
+ return console.log("MU on port ".concat(_this2.ports.mu));
515
+ });
516
+ this.servers.push(server);
517
+ }
518
+ }, {
519
+ key: "su",
520
+ value: function su() {
521
+ var _this3 = this;
522
+ var app = (0, _express["default"])();
523
+ app.use(_bodyParser["default"].json());
524
+ app.get("/", function (req, res) {
525
+ return res.json({
526
+ timestamp: Date.now()
527
+ });
528
+ });
529
+ var server = app.listen(this.ports.su, function () {
530
+ return console.log("SU on port ".concat(_this3.ports.su));
531
+ });
532
+ this.servers.push(server);
533
+ }
534
+ }, {
535
+ key: "cu",
536
+ value: function cu() {
537
+ var _this4 = this;
538
+ var app = (0, _express["default"])();
539
+ app.use(_bodyParser["default"].json());
540
+ app.get("/", function (req, res) {
541
+ return res.json({
542
+ timestamp: Date.now()
543
+ });
544
+ });
545
+ app.get("/result/:mid", /*#__PURE__*/function () {
546
+ var _ref16 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee12(req, res) {
547
+ var res2;
548
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
549
+ while (1) switch (_context12.prev = _context12.next) {
550
+ case 0:
551
+ _context12.next = 2;
552
+ return _this4.result({
553
+ message: req.params.mid,
554
+ process: req.query["process-id"]
555
+ });
556
+ case 2:
557
+ res2 = _context12.sent;
558
+ res.json(res2);
559
+ case 4:
560
+ case "end":
561
+ return _context12.stop();
562
+ }
563
+ }, _callee12);
564
+ }));
565
+ return function (_x23, _x24) {
566
+ return _ref16.apply(this, arguments);
567
+ };
568
+ }());
569
+ app.post("/dry-run", /*#__PURE__*/function () {
570
+ var _ref17 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee13(req, res) {
571
+ var process, _req$body2, id, owner, tags, data, res2;
572
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
573
+ while (1) switch (_context13.prev = _context13.next) {
574
+ case 0:
575
+ process = req.query["process-id"];
576
+ _req$body2 = req.body, id = _req$body2.Id, owner = _req$body2.Owner, tags = _req$body2.Tags, data = _req$body2.Data;
577
+ _context13.next = 4;
578
+ return _this4.dryrun({
579
+ id: id,
580
+ owner: owner,
581
+ tags: tags,
582
+ data: data,
583
+ process: process
584
+ });
585
+ case 4:
586
+ res2 = _context13.sent;
587
+ delete res2.Memory;
588
+ res.json(res2);
589
+ case 7:
590
+ case "end":
591
+ return _context13.stop();
592
+ }
593
+ }, _callee13);
594
+ }));
595
+ return function (_x25, _x26) {
596
+ return _ref17.apply(this, arguments);
597
+ };
598
+ }());
599
+ var server = app.listen(this.ports.cu, function () {
600
+ return console.log("CU on port ".concat(_this4.ports.cu));
601
+ });
602
+ this.servers.push(server);
603
+ }
604
+ }, {
605
+ key: "end",
606
+ value: function end() {
607
+ var _this5 = this;
608
+ return new Promise(function (res) {
609
+ var count = 0;
610
+ var _iterator = _createForOfIteratorHelper(_this5.servers),
611
+ _step;
612
+ try {
613
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
614
+ var v = _step.value;
615
+ v.close(function () {
616
+ count += 1;
617
+ if (count >= 4) {
618
+ console.log("servers closed!", count);
619
+ res();
620
+ }
621
+ });
622
+ }
623
+ } catch (err) {
624
+ _iterator.e(err);
625
+ } finally {
626
+ _iterator.f();
627
+ }
628
+ });
629
+ }
630
+ }]);
631
+ }();
632
+ var _default = exports["default"] = Server;
package/cjs/tao.js CHANGED
@@ -115,14 +115,8 @@ var AO = /*#__PURE__*/function (_MAO) {
115
115
  return spawn.apply(void 0, _args2);
116
116
  case 2:
117
117
  res = _context2.sent;
118
- _context2.next = 5;
119
- return _this.load({
120
- data: log,
121
- pid: res
122
- });
123
- case 5:
124
118
  return _context2.abrupt("return", res);
125
- case 6:
119
+ case 4:
126
120
  case "end":
127
121
  return _context2.stop();
128
122
  }
@@ -237,7 +231,9 @@ var AO = /*#__PURE__*/function (_MAO) {
237
231
  data: data,
238
232
  format: t["Module-Format"]
239
233
  };
240
- return _context5.abrupt("return", id);
234
+ return _context5.abrupt("return", {
235
+ id: id
236
+ });
241
237
  case 21:
242
238
  case "end":
243
239
  return _context5.stop();