wao 0.4.8 → 0.4.10
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/tao.js +113 -25
- package/esm/tao.js +60 -4
- package/package.json +1 -1
package/cjs/tao.js
CHANGED
|
@@ -31,6 +31,38 @@ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.
|
|
|
31
31
|
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
|
|
32
32
|
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); }
|
|
33
33
|
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
|
|
34
|
+
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
35
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
36
|
+
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
37
|
+
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
38
|
+
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; } } }; }
|
|
39
|
+
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; } }
|
|
40
|
+
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; }
|
|
41
|
+
var log = "\nlocal json = require(\"json\")\nao = ao or {}\n\nfunction ao.log(...)\n local args = {...}\n local txt = json.encode(args)\n if type(ao.outbox.Output) == 'string' then\n ao.outbox.Output = {ao.outbox.Output}\n end\n table.insert(ao.outbox.Output, txt)\n ao.outbox.Logs = ao.outbox.Logs or {}\n table.insert(ao.outbox.Logs, txt)\nend\n\nfunction ao.result(result)\n if ao.outbox.Error or result.Error then\n return { Error = result.Error or ao.outbox.Error, Output = ao.outbox.Logs }\n end\n return {\n Output = ao.outbox.Logs or result.Output or ao.outbox.Output,\n Messages = ao.outbox.Messages,\n Spawns = ao.outbox.Spawns,\n Assignments = ao.outbox.Assignments,\n }\nend\n";
|
|
42
|
+
var renderLogs = function renderLogs(logs) {
|
|
43
|
+
if ((0, _ramda.is)(Array, logs) && logs.length > 0) {
|
|
44
|
+
var _iterator = _createForOfIteratorHelper(logs),
|
|
45
|
+
_step;
|
|
46
|
+
try {
|
|
47
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
48
|
+
var v = _step.value;
|
|
49
|
+
var l = v;
|
|
50
|
+
try {
|
|
51
|
+
var _console;
|
|
52
|
+
var p = JSON.parse(v);
|
|
53
|
+
if (JSON.stringify(p) === v) l = p;
|
|
54
|
+
(_console = console).log.apply(_console, _toConsumableArray(l));
|
|
55
|
+
} catch (e) {
|
|
56
|
+
console.log(l);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
} catch (err) {
|
|
60
|
+
_iterator.e(err);
|
|
61
|
+
} finally {
|
|
62
|
+
_iterator.f();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
34
66
|
var AO = /*#__PURE__*/function (_MAO) {
|
|
35
67
|
function AO() {
|
|
36
68
|
var _this;
|
|
@@ -53,11 +85,67 @@ var AO = /*#__PURE__*/function (_MAO) {
|
|
|
53
85
|
mem = _connect.mem;
|
|
54
86
|
_this.module = mem.modules.aos2_0_1;
|
|
55
87
|
_this.assign = assign;
|
|
56
|
-
_this.result =
|
|
88
|
+
_this.result = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
89
|
+
var res,
|
|
90
|
+
_args = arguments;
|
|
91
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
92
|
+
while (1) switch (_context.prev = _context.next) {
|
|
93
|
+
case 0:
|
|
94
|
+
_context.next = 2;
|
|
95
|
+
return result.apply(void 0, _args);
|
|
96
|
+
case 2:
|
|
97
|
+
res = _context.sent;
|
|
98
|
+
renderLogs(res.Output);
|
|
99
|
+
return _context.abrupt("return", res);
|
|
100
|
+
case 5:
|
|
101
|
+
case "end":
|
|
102
|
+
return _context.stop();
|
|
103
|
+
}
|
|
104
|
+
}, _callee);
|
|
105
|
+
}));
|
|
57
106
|
_this.results = results;
|
|
58
107
|
_this.message = message;
|
|
59
|
-
_this.spawn =
|
|
60
|
-
|
|
108
|
+
_this.spawn = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
109
|
+
var res,
|
|
110
|
+
_args2 = arguments;
|
|
111
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
112
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
113
|
+
case 0:
|
|
114
|
+
_context2.next = 2;
|
|
115
|
+
return spawn.apply(void 0, _args2);
|
|
116
|
+
case 2:
|
|
117
|
+
res = _context2.sent;
|
|
118
|
+
_context2.next = 5;
|
|
119
|
+
return _this.load({
|
|
120
|
+
data: log,
|
|
121
|
+
pid: res
|
|
122
|
+
});
|
|
123
|
+
case 5:
|
|
124
|
+
return _context2.abrupt("return", res);
|
|
125
|
+
case 6:
|
|
126
|
+
case "end":
|
|
127
|
+
return _context2.stop();
|
|
128
|
+
}
|
|
129
|
+
}, _callee2);
|
|
130
|
+
}));
|
|
131
|
+
_this.dryrun = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
132
|
+
var res,
|
|
133
|
+
_args3 = arguments;
|
|
134
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
135
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
136
|
+
case 0:
|
|
137
|
+
_context3.next = 2;
|
|
138
|
+
return dryrun.apply(void 0, _args3);
|
|
139
|
+
case 2:
|
|
140
|
+
res = _context3.sent;
|
|
141
|
+
renderLogs(res.Output);
|
|
142
|
+
return _context3.abrupt("return", res);
|
|
143
|
+
case 5:
|
|
144
|
+
case "end":
|
|
145
|
+
return _context3.stop();
|
|
146
|
+
}
|
|
147
|
+
}, _callee3);
|
|
148
|
+
}));
|
|
61
149
|
_this.monitor = monitor;
|
|
62
150
|
_this.unmonitor = unmonitor;
|
|
63
151
|
_this.mem = mem;
|
|
@@ -70,20 +158,20 @@ var AO = /*#__PURE__*/function (_MAO) {
|
|
|
70
158
|
return _createClass(AO, [{
|
|
71
159
|
key: "init",
|
|
72
160
|
value: function () {
|
|
73
|
-
var _init = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
74
|
-
return _regeneratorRuntime().wrap(function
|
|
75
|
-
while (1) switch (
|
|
161
|
+
var _init = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(jwk) {
|
|
162
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
163
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
76
164
|
case 0:
|
|
77
165
|
if (!jwk && this.acc[0]) jwk = this.acc[0].jwk;
|
|
78
|
-
|
|
166
|
+
_context4.next = 3;
|
|
79
167
|
return this.ar.init(jwk);
|
|
80
168
|
case 3:
|
|
81
|
-
return
|
|
169
|
+
return _context4.abrupt("return", this);
|
|
82
170
|
case 4:
|
|
83
171
|
case "end":
|
|
84
|
-
return
|
|
172
|
+
return _context4.stop();
|
|
85
173
|
}
|
|
86
|
-
},
|
|
174
|
+
}, _callee4, this);
|
|
87
175
|
}));
|
|
88
176
|
function init(_x) {
|
|
89
177
|
return _init.apply(this, arguments);
|
|
@@ -93,26 +181,26 @@ var AO = /*#__PURE__*/function (_MAO) {
|
|
|
93
181
|
}, {
|
|
94
182
|
key: "postModule",
|
|
95
183
|
value: function () {
|
|
96
|
-
var _postModule = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
97
|
-
var data,
|
|
98
|
-
return _regeneratorRuntime().wrap(function
|
|
99
|
-
while (1) switch (
|
|
184
|
+
var _postModule = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref4) {
|
|
185
|
+
var data, _ref4$tags, tags, jwk, err, _yield$this$ar$checkW, t, _tags, signer, _yield$this$ar$datait, id, owner;
|
|
186
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
187
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
100
188
|
case 0:
|
|
101
|
-
data =
|
|
189
|
+
data = _ref4.data, _ref4$tags = _ref4.tags, tags = _ref4$tags === void 0 ? {} : _ref4$tags, jwk = _ref4.jwk;
|
|
102
190
|
err = null;
|
|
103
|
-
|
|
191
|
+
_context5.next = 4;
|
|
104
192
|
return this.ar.checkWallet({
|
|
105
193
|
jwk: jwk
|
|
106
194
|
});
|
|
107
195
|
case 4:
|
|
108
|
-
_yield$this$ar$checkW =
|
|
196
|
+
_yield$this$ar$checkW = _context5.sent;
|
|
109
197
|
jwk = _yield$this$ar$checkW.jwk;
|
|
110
198
|
err = _yield$this$ar$checkW.err;
|
|
111
199
|
if (!err) {
|
|
112
|
-
|
|
200
|
+
_context5.next = 9;
|
|
113
201
|
break;
|
|
114
202
|
}
|
|
115
|
-
return
|
|
203
|
+
return _context5.abrupt("return", {
|
|
116
204
|
err: err
|
|
117
205
|
});
|
|
118
206
|
case 9:
|
|
@@ -128,17 +216,17 @@ var AO = /*#__PURE__*/function (_MAO) {
|
|
|
128
216
|
});
|
|
129
217
|
_tags = (0, _utils.buildTags)(null, t);
|
|
130
218
|
signer = (0, _aoconnect.createDataItemSigner)(jwk);
|
|
131
|
-
|
|
219
|
+
_context5.next = 14;
|
|
132
220
|
return this.ar.dataitem({
|
|
133
221
|
tags: _tags,
|
|
134
222
|
data: data,
|
|
135
223
|
signer: signer
|
|
136
224
|
});
|
|
137
225
|
case 14:
|
|
138
|
-
_yield$this$ar$datait =
|
|
226
|
+
_yield$this$ar$datait = _context5.sent;
|
|
139
227
|
id = _yield$this$ar$datait.id;
|
|
140
228
|
owner = _yield$this$ar$datait.owner;
|
|
141
|
-
|
|
229
|
+
_context5.next = 19;
|
|
142
230
|
return this.ar.post({
|
|
143
231
|
data: data,
|
|
144
232
|
tags: t,
|
|
@@ -149,12 +237,12 @@ var AO = /*#__PURE__*/function (_MAO) {
|
|
|
149
237
|
data: data,
|
|
150
238
|
format: t["Module-Format"]
|
|
151
239
|
};
|
|
152
|
-
return
|
|
240
|
+
return _context5.abrupt("return", id);
|
|
153
241
|
case 21:
|
|
154
242
|
case "end":
|
|
155
|
-
return
|
|
243
|
+
return _context5.stop();
|
|
156
244
|
}
|
|
157
|
-
},
|
|
245
|
+
}, _callee5, this);
|
|
158
246
|
}));
|
|
159
247
|
function postModule(_x2) {
|
|
160
248
|
return _postModule.apply(this, arguments);
|
package/esm/tao.js
CHANGED
|
@@ -4,7 +4,50 @@ import { srcs, buildTags } from "./utils.js"
|
|
|
4
4
|
import AR from "./tar.js"
|
|
5
5
|
import { connect } from "./aoconnect.js"
|
|
6
6
|
import { acc } from "./test.js"
|
|
7
|
-
import { mergeLeft } from "ramda"
|
|
7
|
+
import { mergeLeft, is, map } from "ramda"
|
|
8
|
+
|
|
9
|
+
let log = `
|
|
10
|
+
local json = require("json")
|
|
11
|
+
ao = ao or {}
|
|
12
|
+
|
|
13
|
+
function ao.log(...)
|
|
14
|
+
local args = {...}
|
|
15
|
+
local txt = json.encode(args)
|
|
16
|
+
if type(ao.outbox.Output) == 'string' then
|
|
17
|
+
ao.outbox.Output = {ao.outbox.Output}
|
|
18
|
+
end
|
|
19
|
+
table.insert(ao.outbox.Output, txt)
|
|
20
|
+
ao.outbox.Logs = ao.outbox.Logs or {}
|
|
21
|
+
table.insert(ao.outbox.Logs, txt)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
function ao.result(result)
|
|
25
|
+
if ao.outbox.Error or result.Error then
|
|
26
|
+
return { Error = result.Error or ao.outbox.Error, Output = ao.outbox.Logs }
|
|
27
|
+
end
|
|
28
|
+
return {
|
|
29
|
+
Output = ao.outbox.Logs or result.Output or ao.outbox.Output,
|
|
30
|
+
Messages = ao.outbox.Messages,
|
|
31
|
+
Spawns = ao.outbox.Spawns,
|
|
32
|
+
Assignments = ao.outbox.Assignments,
|
|
33
|
+
}
|
|
34
|
+
end
|
|
35
|
+
`
|
|
36
|
+
|
|
37
|
+
const renderLogs = logs => {
|
|
38
|
+
if (is(Array, logs) && logs.length > 0) {
|
|
39
|
+
for (const v of logs) {
|
|
40
|
+
let l = v
|
|
41
|
+
try {
|
|
42
|
+
const p = JSON.parse(v)
|
|
43
|
+
if (JSON.stringify(p) === v) l = p
|
|
44
|
+
console.log(...l)
|
|
45
|
+
} catch (e) {
|
|
46
|
+
console.log(l)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
8
51
|
|
|
9
52
|
class AO extends MAO {
|
|
10
53
|
constructor(opt = {}) {
|
|
@@ -24,11 +67,24 @@ class AO extends MAO {
|
|
|
24
67
|
} = connect(opt.mem)
|
|
25
68
|
this.module = mem.modules.aos2_0_1
|
|
26
69
|
this.assign = assign
|
|
27
|
-
this.result =
|
|
70
|
+
this.result = async (...opt) => {
|
|
71
|
+
const res = await result(...opt)
|
|
72
|
+
renderLogs(res.Output)
|
|
73
|
+
return res
|
|
74
|
+
}
|
|
75
|
+
|
|
28
76
|
this.results = results
|
|
29
77
|
this.message = message
|
|
30
|
-
this.spawn =
|
|
31
|
-
|
|
78
|
+
this.spawn = async (...opt) => {
|
|
79
|
+
const res = await spawn(...opt)
|
|
80
|
+
await this.load({ data: log, pid: res })
|
|
81
|
+
return res
|
|
82
|
+
}
|
|
83
|
+
this.dryrun = async (...opt) => {
|
|
84
|
+
const res = await dryrun(...opt)
|
|
85
|
+
renderLogs(res.Output)
|
|
86
|
+
return res
|
|
87
|
+
}
|
|
32
88
|
this.monitor = monitor
|
|
33
89
|
this.unmonitor = unmonitor
|
|
34
90
|
this.mem = mem
|