wao 0.18.10 → 0.19.1
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/cli.js +21 -0
- package/cjs/hub/bundler.js +236 -0
- package/cjs/hub/cu.js +138 -0
- package/cjs/hub/fs.js +150 -0
- package/cjs/hub/index.js +100 -0
- package/cjs/hub/utils.js +66 -0
- package/cjs/hub/ws-proxy.js +138 -0
- package/esm/cli.js +16 -1
- package/esm/hub/bundler.js +123 -0
- package/esm/hub/cu.js +74 -0
- package/esm/hub/fs.js +155 -0
- package/esm/hub/index.js +84 -0
- package/esm/hub/utils.js +64 -0
- package/esm/hub/ws-proxy.js +67 -0
- package/package.json +5 -4
package/cjs/cli.js
CHANGED
|
@@ -5,11 +5,32 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
|
|
|
5
5
|
var _pm = _interopRequireDefault(require("pm2"));
|
|
6
6
|
var _utils = require("./utils.js");
|
|
7
7
|
var _path = require("path");
|
|
8
|
+
var _args$;
|
|
8
9
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
9
10
|
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; }
|
|
10
11
|
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); }
|
|
11
12
|
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); }); }; }
|
|
12
13
|
var args = process.argv.slice(2);
|
|
14
|
+
var cmds = {
|
|
15
|
+
wao: {
|
|
16
|
+
script: "run.js"
|
|
17
|
+
},
|
|
18
|
+
hub: {
|
|
19
|
+
script: "hub/index.js"
|
|
20
|
+
},
|
|
21
|
+
fs: {
|
|
22
|
+
script: "hub/fs.js"
|
|
23
|
+
},
|
|
24
|
+
proxy: {
|
|
25
|
+
script: "hub/ws-proxy.js"
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
var cmd = cmds[(_args$ = args[0]) !== null && _args$ !== void 0 ? _args$ : "wao"];
|
|
29
|
+
if (args[0]) args.shift();
|
|
30
|
+
if (!cmd) {
|
|
31
|
+
console.log("The wrong command");
|
|
32
|
+
process.exit();
|
|
33
|
+
}
|
|
13
34
|
_pm["default"].connect(false, /*#__PURE__*/function () {
|
|
14
35
|
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(err) {
|
|
15
36
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
"use strict";
|
|
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); }
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports["default"] = void 0;
|
|
8
|
+
var _express = _interopRequireDefault(require("express"));
|
|
9
|
+
var _cors = _interopRequireDefault(require("cors"));
|
|
10
|
+
var _bodyParser = _interopRequireDefault(require("body-parser"));
|
|
11
|
+
var _arweave = _interopRequireDefault(require("arweave"));
|
|
12
|
+
var _utils = require("./utils.js");
|
|
13
|
+
var _Arweave$default;
|
|
14
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
15
|
+
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; }
|
|
16
|
+
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; } } }; }
|
|
17
|
+
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; } }
|
|
18
|
+
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; }
|
|
19
|
+
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
|
+
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
|
+
var Arweave = (_Arweave$default = _arweave["default"]["default"]) !== null && _Arweave$default !== void 0 ? _Arweave$default : _arweave["default"];
|
|
22
|
+
var arweave = Arweave.init();
|
|
23
|
+
// todo: bundler is unusable due to incorrect ids and signature
|
|
24
|
+
var bundler = function bundler(sus, cbs, hbs) {
|
|
25
|
+
var app = (0, _express["default"])();
|
|
26
|
+
app.use((0, _cors["default"])());
|
|
27
|
+
app.use("/tx", _bodyParser["default"].raw({
|
|
28
|
+
type: "*/*",
|
|
29
|
+
limit: "100mb"
|
|
30
|
+
}));
|
|
31
|
+
app.post("/tx", /*#__PURE__*/function () {
|
|
32
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(req, res) {
|
|
33
|
+
var _hbs$address;
|
|
34
|
+
var lines, sigs, currentKey, _iterator, _step, line, trimmed, headerMatch, _key, value, input, key, address, item, _iterator2, _step2, v, _iterator3, _step3, _v;
|
|
35
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
36
|
+
while (1) switch (_context.prev = _context.next) {
|
|
37
|
+
case 0:
|
|
38
|
+
if (Buffer.isBuffer(req.body)) {
|
|
39
|
+
_context.next = 3;
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
console.log("BD: Invalid body | expected raw Buffer");
|
|
43
|
+
return _context.abrupt("return", res.status(400).send("Invalid body: expected raw Buffer"));
|
|
44
|
+
case 3:
|
|
45
|
+
lines = req.body.toString("utf8").split(/\r?\n/);
|
|
46
|
+
sigs = {};
|
|
47
|
+
currentKey = null;
|
|
48
|
+
_iterator = _createForOfIteratorHelper(lines);
|
|
49
|
+
_context.prev = 7;
|
|
50
|
+
_iterator.s();
|
|
51
|
+
case 9:
|
|
52
|
+
if ((_step = _iterator.n()).done) {
|
|
53
|
+
_context.next = 19;
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
line = _step.value;
|
|
57
|
+
trimmed = line.trim();
|
|
58
|
+
if (!/^--[a-zA-Z0-9_\-=]+/.test(trimmed)) {
|
|
59
|
+
_context.next = 15;
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
currentKey = null;
|
|
63
|
+
return _context.abrupt("continue", 17);
|
|
64
|
+
case 15:
|
|
65
|
+
headerMatch = trimmed.match(/^([a-zA-Z0-9_-]+):\s*(.*)$/);
|
|
66
|
+
if (headerMatch && !headerMatch[2].includes(": ")) {
|
|
67
|
+
_key = headerMatch[1];
|
|
68
|
+
value = headerMatch[2];
|
|
69
|
+
sigs[_key] = value;
|
|
70
|
+
currentKey = _key;
|
|
71
|
+
} else if (currentKey) sigs[currentKey] += "\n" + line;
|
|
72
|
+
case 17:
|
|
73
|
+
_context.next = 9;
|
|
74
|
+
break;
|
|
75
|
+
case 19:
|
|
76
|
+
_context.next = 24;
|
|
77
|
+
break;
|
|
78
|
+
case 21:
|
|
79
|
+
_context.prev = 21;
|
|
80
|
+
_context.t0 = _context["catch"](7);
|
|
81
|
+
_iterator.e(_context.t0);
|
|
82
|
+
case 24:
|
|
83
|
+
_context.prev = 24;
|
|
84
|
+
_iterator.f();
|
|
85
|
+
return _context.finish(24);
|
|
86
|
+
case 27:
|
|
87
|
+
sigs.target = req.headers.process;
|
|
88
|
+
sigs.slot = req.headers.slot;
|
|
89
|
+
input = (0, _utils.parseSignatureInput)(req.headers["signature-input"]);
|
|
90
|
+
key = {
|
|
91
|
+
kty: "RSA",
|
|
92
|
+
n: input.keyid,
|
|
93
|
+
e: "AQAB"
|
|
94
|
+
};
|
|
95
|
+
_context.next = 33;
|
|
96
|
+
return arweave.wallets.jwkToAddress(key);
|
|
97
|
+
case 33:
|
|
98
|
+
address = _context.sent;
|
|
99
|
+
(_hbs$address = hbs[address]) !== null && _hbs$address !== void 0 ? _hbs$address : hbs[address] = {};
|
|
100
|
+
hbs[address].update = Date.now();
|
|
101
|
+
/*
|
|
102
|
+
const verifier = createVerifier(
|
|
103
|
+
createPublicKey({ key, format: "jwk" }),
|
|
104
|
+
"rsa-pss-sha512"
|
|
105
|
+
)*/
|
|
106
|
+
_context.prev = 36;
|
|
107
|
+
/*const isValid = await verifyMessage(
|
|
108
|
+
{ keyLookup: params => ({ verify: verifier }) },
|
|
109
|
+
{
|
|
110
|
+
method: req.method,
|
|
111
|
+
headers: req.headers,
|
|
112
|
+
url: `http://ao.com${req.headers.path}`,
|
|
113
|
+
}
|
|
114
|
+
)*/
|
|
115
|
+
item = (0, _utils.toANS104Request)(sigs).item;
|
|
116
|
+
if (!((sigs.slot === "0" || sigs.type === "Process") && sigs.module)) {
|
|
117
|
+
_context.next = 45;
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
_iterator2 = _createForOfIteratorHelper(item.tags);
|
|
121
|
+
try {
|
|
122
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
123
|
+
v = _step2.value;
|
|
124
|
+
if (v.name === "Type") v.value = "Process";
|
|
125
|
+
}
|
|
126
|
+
} catch (err) {
|
|
127
|
+
_iterator2.e(err);
|
|
128
|
+
} finally {
|
|
129
|
+
_iterator2.f();
|
|
130
|
+
}
|
|
131
|
+
_context.next = 43;
|
|
132
|
+
return message({
|
|
133
|
+
http_msg: item,
|
|
134
|
+
module: sigs.module,
|
|
135
|
+
scheduler: sigs.scheduler,
|
|
136
|
+
address: address
|
|
137
|
+
}, res);
|
|
138
|
+
case 43:
|
|
139
|
+
_context.next = 53;
|
|
140
|
+
break;
|
|
141
|
+
case 45:
|
|
142
|
+
if (!(sigs.type === "Message")) {
|
|
143
|
+
_context.next = 52;
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
_iterator3 = _createForOfIteratorHelper(item.tags);
|
|
147
|
+
try {
|
|
148
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
149
|
+
_v = _step3.value;
|
|
150
|
+
if (_v.name === "id") item.target = _v.value;
|
|
151
|
+
}
|
|
152
|
+
} catch (err) {
|
|
153
|
+
_iterator3.e(err);
|
|
154
|
+
} finally {
|
|
155
|
+
_iterator3.f();
|
|
156
|
+
}
|
|
157
|
+
_context.next = 50;
|
|
158
|
+
return message({
|
|
159
|
+
slot: sigs.slot,
|
|
160
|
+
http_msg: item,
|
|
161
|
+
process: sigs.target,
|
|
162
|
+
address: address
|
|
163
|
+
}, res);
|
|
164
|
+
case 50:
|
|
165
|
+
_context.next = 53;
|
|
166
|
+
break;
|
|
167
|
+
case 52:
|
|
168
|
+
return _context.abrupt("return", res.status(500).send("unknown error"));
|
|
169
|
+
case 53:
|
|
170
|
+
_context.next = 58;
|
|
171
|
+
break;
|
|
172
|
+
case 55:
|
|
173
|
+
_context.prev = 55;
|
|
174
|
+
_context.t1 = _context["catch"](36);
|
|
175
|
+
return _context.abrupt("return", res.status(500).send("unknown error"));
|
|
176
|
+
case 58:
|
|
177
|
+
case "end":
|
|
178
|
+
return _context.stop();
|
|
179
|
+
}
|
|
180
|
+
}, _callee, null, [[7, 21, 24, 27], [36, 55]]);
|
|
181
|
+
}));
|
|
182
|
+
return function (_x, _x2) {
|
|
183
|
+
return _ref.apply(this, arguments);
|
|
184
|
+
};
|
|
185
|
+
}());
|
|
186
|
+
function message(_x3, _x4) {
|
|
187
|
+
return _message.apply(this, arguments);
|
|
188
|
+
}
|
|
189
|
+
function _message() {
|
|
190
|
+
_message = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(opt, res) {
|
|
191
|
+
var id, exists, k, hb, pid, p, socket;
|
|
192
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
193
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
194
|
+
case 0:
|
|
195
|
+
id = (0, _utils.generateId)();
|
|
196
|
+
cbs[id] = res;
|
|
197
|
+
exists = false;
|
|
198
|
+
for (k in sus) {
|
|
199
|
+
hb = sus[k].accept.hb[opt.address];
|
|
200
|
+
pid = opt.process;
|
|
201
|
+
p = sus[k].accept.pid[pid];
|
|
202
|
+
if (hb !== null && hb !== void 0 && hb["*"] || hb !== null && hb !== void 0 && hb[pid] || p !== null && p !== void 0 && p["*"] || p !== null && p !== void 0 && p[opt.address]) {
|
|
203
|
+
socket = sus[k].socket;
|
|
204
|
+
/*exists = true
|
|
205
|
+
socket.send(
|
|
206
|
+
JSON.stringify({ type: "msg", subtype: "message", id, message: opt })
|
|
207
|
+
)*/
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
res.status(200).send("success");
|
|
211
|
+
delete cbs[id];
|
|
212
|
+
/*
|
|
213
|
+
if (!exists) {
|
|
214
|
+
res.status(200).send("success")
|
|
215
|
+
delete cbs[id]
|
|
216
|
+
} else {
|
|
217
|
+
setTimeout(() => {
|
|
218
|
+
if (cbs[id]) {
|
|
219
|
+
res.status(200).send("success")
|
|
220
|
+
delete cbs[id]
|
|
221
|
+
}
|
|
222
|
+
}, 10000)
|
|
223
|
+
}*/
|
|
224
|
+
case 6:
|
|
225
|
+
case "end":
|
|
226
|
+
return _context2.stop();
|
|
227
|
+
}
|
|
228
|
+
}, _callee2);
|
|
229
|
+
}));
|
|
230
|
+
return _message.apply(this, arguments);
|
|
231
|
+
}
|
|
232
|
+
var server = app.listen(4001, function () {
|
|
233
|
+
return console.log("BD on port 4001");
|
|
234
|
+
});
|
|
235
|
+
};
|
|
236
|
+
var _default = exports["default"] = bundler;
|
package/cjs/hub/cu.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
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); }
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports["default"] = void 0;
|
|
8
|
+
var _express = _interopRequireDefault(require("express"));
|
|
9
|
+
var _cors = _interopRequireDefault(require("cors"));
|
|
10
|
+
var _bodyParser = _interopRequireDefault(require("body-parser"));
|
|
11
|
+
var _utils = require("./utils.js");
|
|
12
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
13
|
+
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; }
|
|
14
|
+
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); }
|
|
15
|
+
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); }); }; }
|
|
16
|
+
var app2 = (0, _express["default"])();
|
|
17
|
+
var cu = function cu(sus, cbs) {
|
|
18
|
+
app2.use((0, _cors["default"])());
|
|
19
|
+
app2.use(_bodyParser["default"].json());
|
|
20
|
+
app2.post("/result/:mid", result);
|
|
21
|
+
app2.get("/result/:mid", result);
|
|
22
|
+
app2.post("/dry-run", /*#__PURE__*/function () {
|
|
23
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(req, res) {
|
|
24
|
+
var process, _req$body, id, owner, tags, data;
|
|
25
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
26
|
+
while (1) switch (_context.prev = _context.next) {
|
|
27
|
+
case 0:
|
|
28
|
+
process = req.query["process-id"];
|
|
29
|
+
_req$body = req.body, id = _req$body.Id, owner = _req$body.Owner, tags = _req$body.Tags, data = _req$body.Data;
|
|
30
|
+
dryrun({
|
|
31
|
+
id: id,
|
|
32
|
+
owner: owner,
|
|
33
|
+
tags: tags,
|
|
34
|
+
data: data,
|
|
35
|
+
process: process
|
|
36
|
+
}, res);
|
|
37
|
+
case 3:
|
|
38
|
+
case "end":
|
|
39
|
+
return _context.stop();
|
|
40
|
+
}
|
|
41
|
+
}, _callee);
|
|
42
|
+
}));
|
|
43
|
+
return function (_x, _x2) {
|
|
44
|
+
return _ref.apply(this, arguments);
|
|
45
|
+
};
|
|
46
|
+
}());
|
|
47
|
+
var server2 = app2.listen(4004, function () {
|
|
48
|
+
return console.log("CU on port 4004");
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// todo: request doesn't contain any info about hb node, how to handle it?
|
|
52
|
+
function result(_x3, _x4) {
|
|
53
|
+
return _result.apply(this, arguments);
|
|
54
|
+
} // todo: request doesn't contain any info about hb node, how to handle it?
|
|
55
|
+
function _result() {
|
|
56
|
+
_result = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(req, res) {
|
|
57
|
+
var id, message, exists, process, k, socket;
|
|
58
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
59
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
60
|
+
case 0:
|
|
61
|
+
id = (0, _utils.generateId)();
|
|
62
|
+
cbs[id] = res;
|
|
63
|
+
message = req.params.mid;
|
|
64
|
+
exists = false;
|
|
65
|
+
process = req.query["process-id"];
|
|
66
|
+
for (k in sus) {
|
|
67
|
+
socket = sus[k].socket;
|
|
68
|
+
exists = true;
|
|
69
|
+
socket.send(JSON.stringify({
|
|
70
|
+
type: "msg",
|
|
71
|
+
subtype: "result",
|
|
72
|
+
message: message,
|
|
73
|
+
process: process,
|
|
74
|
+
id: id
|
|
75
|
+
}));
|
|
76
|
+
}
|
|
77
|
+
if (!exists) {
|
|
78
|
+
res.status(404).send("success");
|
|
79
|
+
delete cbs[id];
|
|
80
|
+
} else {
|
|
81
|
+
setTimeout(function () {
|
|
82
|
+
if (cbs[id]) {
|
|
83
|
+
res.status(404).send("success");
|
|
84
|
+
delete cbs[id];
|
|
85
|
+
}
|
|
86
|
+
}, 10000);
|
|
87
|
+
}
|
|
88
|
+
case 7:
|
|
89
|
+
case "end":
|
|
90
|
+
return _context2.stop();
|
|
91
|
+
}
|
|
92
|
+
}, _callee2);
|
|
93
|
+
}));
|
|
94
|
+
return _result.apply(this, arguments);
|
|
95
|
+
}
|
|
96
|
+
function dryrun(_x5, _x6) {
|
|
97
|
+
return _dryrun.apply(this, arguments);
|
|
98
|
+
}
|
|
99
|
+
function _dryrun() {
|
|
100
|
+
_dryrun = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(opt, res) {
|
|
101
|
+
var id, exists, k, socket;
|
|
102
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
103
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
104
|
+
case 0:
|
|
105
|
+
id = (0, _utils.generateId)();
|
|
106
|
+
cbs[id] = res;
|
|
107
|
+
exists = false;
|
|
108
|
+
for (k in sus) {
|
|
109
|
+
socket = sus[k].socket;
|
|
110
|
+
exists = true;
|
|
111
|
+
socket.send(JSON.stringify({
|
|
112
|
+
type: "msg",
|
|
113
|
+
subtype: "dryrun",
|
|
114
|
+
message: opt,
|
|
115
|
+
id: id
|
|
116
|
+
}));
|
|
117
|
+
}
|
|
118
|
+
if (!exists) {
|
|
119
|
+
res.status(404).send("success");
|
|
120
|
+
delete cbs[id];
|
|
121
|
+
} else {
|
|
122
|
+
setTimeout(function () {
|
|
123
|
+
if (cbs[id]) {
|
|
124
|
+
res.status(404).send("success");
|
|
125
|
+
delete cbs[id];
|
|
126
|
+
}
|
|
127
|
+
}, 3000);
|
|
128
|
+
}
|
|
129
|
+
case 5:
|
|
130
|
+
case "end":
|
|
131
|
+
return _context3.stop();
|
|
132
|
+
}
|
|
133
|
+
}, _callee3);
|
|
134
|
+
}));
|
|
135
|
+
return _dryrun.apply(this, arguments);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
var _default = exports["default"] = cu;
|
package/cjs/hub/fs.js
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _chokidar = _interopRequireDefault(require("chokidar"));
|
|
4
|
+
var _utils = require("./utils.js");
|
|
5
|
+
var _ws = _interopRequireDefault(require("ws"));
|
|
6
|
+
var _ramda = require("ramda");
|
|
7
|
+
var _path = require("path");
|
|
8
|
+
var _fs = require("fs");
|
|
9
|
+
var _process$argv$;
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
11
|
+
var ws_server = new _ws["default"].Server({
|
|
12
|
+
port: 9090
|
|
13
|
+
});
|
|
14
|
+
var _dir = (_process$argv$ = process.argv[2]) !== null && _process$argv$ !== void 0 ? _process$argv$ : "./";
|
|
15
|
+
var sus = {};
|
|
16
|
+
var cbs = {};
|
|
17
|
+
var dir = null;
|
|
18
|
+
var _socket = null;
|
|
19
|
+
var cwd = process.cwd();
|
|
20
|
+
ws_server.on("connection", function (socket) {
|
|
21
|
+
_socket = socket;
|
|
22
|
+
var clientId = (0, _utils.generateId)();
|
|
23
|
+
console.log("new ws:", clientId);
|
|
24
|
+
sus[clientId] = {
|
|
25
|
+
socket: socket,
|
|
26
|
+
su: false,
|
|
27
|
+
connections: {},
|
|
28
|
+
address: null
|
|
29
|
+
};
|
|
30
|
+
socket.send(JSON.stringify({
|
|
31
|
+
type: "registered",
|
|
32
|
+
id: clientId,
|
|
33
|
+
dir: dir
|
|
34
|
+
}));
|
|
35
|
+
socket.on("message", function (message) {
|
|
36
|
+
var data = JSON.parse(message);
|
|
37
|
+
if (data.type === "save") {
|
|
38
|
+
(0, _fs.writeFileSync)((0, _path.resolve)(cwd, _dir, data.path.replace(/^\//, "")), data.content);
|
|
39
|
+
} else if (data.type === "data") {
|
|
40
|
+
var content = (0, _fs.readFileSync)((0, _path.resolve)(cwd, _dir, data.path.replace(/^\//, "")), "utf8");
|
|
41
|
+
socket.send(JSON.stringify({
|
|
42
|
+
content: content,
|
|
43
|
+
type: "msg",
|
|
44
|
+
path: data.path,
|
|
45
|
+
subtype: "content"
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
socket.on("close", function () {
|
|
50
|
+
console.log("ws disconnected", clientId);
|
|
51
|
+
delete sus[clientId];
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
var sendDir = function sendDir() {
|
|
55
|
+
if (_socket) {
|
|
56
|
+
_socket.send(JSON.stringify({
|
|
57
|
+
type: "msg",
|
|
58
|
+
subtype: "dir_change",
|
|
59
|
+
dir: dir
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
var sendContent = function sendContent(content, path) {
|
|
64
|
+
if (_socket) {
|
|
65
|
+
_socket.send(JSON.stringify({
|
|
66
|
+
content: content,
|
|
67
|
+
type: "msg",
|
|
68
|
+
path: path,
|
|
69
|
+
subtype: "content"
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
console.log("WAO FS running on port 9090");
|
|
74
|
+
var wd = (0, _path.resolve)(cwd, _dir);
|
|
75
|
+
console.log("Directory:", wd);
|
|
76
|
+
_chokidar["default"].watch(wd, {
|
|
77
|
+
ignored: function ignored(e, stats) {
|
|
78
|
+
var _e = (0, _path.resolve)(cwd, e);
|
|
79
|
+
return new RegExp(wd + "/node_modules").test(_e);
|
|
80
|
+
}
|
|
81
|
+
}).on("change", function (e, p) {
|
|
82
|
+
var _e = (0, _path.resolve)(cwd, e);
|
|
83
|
+
var rel = _e.replace(new RegExp(wd + "/"), "");
|
|
84
|
+
var paths = rel.split("/");
|
|
85
|
+
var _dir = dir;
|
|
86
|
+
var content = (0, _fs.readFileSync)((0, _path.resolve)(cwd, _dir, _e), "utf8");
|
|
87
|
+
sendContent(content, e.replace(wd, ""));
|
|
88
|
+
}).on("add", function (e, p) {
|
|
89
|
+
var _e = (0, _path.resolve)(cwd, e);
|
|
90
|
+
var rel = _e.replace(new RegExp(wd + "/"), "");
|
|
91
|
+
var paths = rel.split("/");
|
|
92
|
+
var _dir = dir;
|
|
93
|
+
while (paths.length > 0) {
|
|
94
|
+
var _p = paths.shift();
|
|
95
|
+
if (paths.length === 0) {
|
|
96
|
+
_dir[_p] = Date.now();
|
|
97
|
+
} else {
|
|
98
|
+
_dir = _dir[_p];
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
sendDir();
|
|
102
|
+
}).on("addDir", function (e, p) {
|
|
103
|
+
var _e = (0, _path.resolve)(cwd, e);
|
|
104
|
+
if (_e === wd) {
|
|
105
|
+
dir = {};
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
var rel = _e.replace(new RegExp(wd + "/"), "");
|
|
109
|
+
var paths = rel.split("/");
|
|
110
|
+
var _dir = dir;
|
|
111
|
+
while (paths.length > 0) {
|
|
112
|
+
var _dir2, _dir2$_p;
|
|
113
|
+
var _p2 = paths.shift();
|
|
114
|
+
(_dir2$_p = (_dir2 = _dir)[_p2]) !== null && _dir2$_p !== void 0 ? _dir2$_p : _dir2[_p2] = {};
|
|
115
|
+
_dir = _dir[_p2];
|
|
116
|
+
}
|
|
117
|
+
sendDir();
|
|
118
|
+
}).on("unlink", function (e, p) {
|
|
119
|
+
var _e = (0, _path.resolve)(cwd, e);
|
|
120
|
+
var rel = _e.replace(new RegExp(wd + "/"), "");
|
|
121
|
+
var paths = rel.split("/");
|
|
122
|
+
var _dir = dir;
|
|
123
|
+
while (paths.length > 0) {
|
|
124
|
+
var _p3 = paths.shift();
|
|
125
|
+
if (paths.length === 0) {
|
|
126
|
+
delete _dir[_p3];
|
|
127
|
+
} else {
|
|
128
|
+
_dir = _dir[_p3];
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
sendDir();
|
|
132
|
+
}).on("unlinkDir", function (e, p) {
|
|
133
|
+
var _e = (0, _path.resolve)(cwd, e);
|
|
134
|
+
if (_e === wd) {
|
|
135
|
+
dir = null;
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
var rel = _e.replace(new RegExp(wd + "/"), "");
|
|
139
|
+
var paths = rel.split("/");
|
|
140
|
+
var _dir = dir;
|
|
141
|
+
while (paths.length > 0) {
|
|
142
|
+
var _p4 = paths.shift();
|
|
143
|
+
if (paths.length === 0) {
|
|
144
|
+
delete _dir[_p4];
|
|
145
|
+
} else {
|
|
146
|
+
_dir = _dir[_p4];
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
sendDir();
|
|
150
|
+
});
|