wao 0.4.8 → 0.4.9
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 +106 -25
- package/esm/tao.js +58 -4
- package/package.json +1 -1
package/cjs/tao.js
CHANGED
|
@@ -31,6 +31,31 @@ 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 _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; } } }; }
|
|
35
|
+
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; } }
|
|
36
|
+
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; }
|
|
37
|
+
var log = "\nlocal json = require(\"json\")\nao = ao or {}\n\nfunction ao.log(txt)\n if type(txt) == 'table' then\n txt = json.encode(txt)\n end\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";
|
|
38
|
+
var renderLogs = function renderLogs(logs) {
|
|
39
|
+
if ((0, _ramda.is)(Array, logs) && logs.length > 0) {
|
|
40
|
+
var _iterator = _createForOfIteratorHelper(logs),
|
|
41
|
+
_step;
|
|
42
|
+
try {
|
|
43
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
44
|
+
var v = _step.value;
|
|
45
|
+
var l = v;
|
|
46
|
+
try {
|
|
47
|
+
var p = JSON.parse(v);
|
|
48
|
+
if (JSON.stringify(p) === v) l = p;
|
|
49
|
+
} catch (e) {}
|
|
50
|
+
console.log(l);
|
|
51
|
+
}
|
|
52
|
+
} catch (err) {
|
|
53
|
+
_iterator.e(err);
|
|
54
|
+
} finally {
|
|
55
|
+
_iterator.f();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
34
59
|
var AO = /*#__PURE__*/function (_MAO) {
|
|
35
60
|
function AO() {
|
|
36
61
|
var _this;
|
|
@@ -53,11 +78,67 @@ var AO = /*#__PURE__*/function (_MAO) {
|
|
|
53
78
|
mem = _connect.mem;
|
|
54
79
|
_this.module = mem.modules.aos2_0_1;
|
|
55
80
|
_this.assign = assign;
|
|
56
|
-
_this.result =
|
|
81
|
+
_this.result = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
82
|
+
var res,
|
|
83
|
+
_args = arguments;
|
|
84
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
85
|
+
while (1) switch (_context.prev = _context.next) {
|
|
86
|
+
case 0:
|
|
87
|
+
_context.next = 2;
|
|
88
|
+
return result.apply(void 0, _args);
|
|
89
|
+
case 2:
|
|
90
|
+
res = _context.sent;
|
|
91
|
+
renderLogs(res.Output);
|
|
92
|
+
return _context.abrupt("return", res);
|
|
93
|
+
case 5:
|
|
94
|
+
case "end":
|
|
95
|
+
return _context.stop();
|
|
96
|
+
}
|
|
97
|
+
}, _callee);
|
|
98
|
+
}));
|
|
57
99
|
_this.results = results;
|
|
58
100
|
_this.message = message;
|
|
59
|
-
_this.spawn =
|
|
60
|
-
|
|
101
|
+
_this.spawn = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
102
|
+
var res,
|
|
103
|
+
_args2 = arguments;
|
|
104
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
105
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
106
|
+
case 0:
|
|
107
|
+
_context2.next = 2;
|
|
108
|
+
return spawn.apply(void 0, _args2);
|
|
109
|
+
case 2:
|
|
110
|
+
res = _context2.sent;
|
|
111
|
+
_context2.next = 5;
|
|
112
|
+
return _this.load({
|
|
113
|
+
data: log,
|
|
114
|
+
pid: res
|
|
115
|
+
});
|
|
116
|
+
case 5:
|
|
117
|
+
return _context2.abrupt("return", res);
|
|
118
|
+
case 6:
|
|
119
|
+
case "end":
|
|
120
|
+
return _context2.stop();
|
|
121
|
+
}
|
|
122
|
+
}, _callee2);
|
|
123
|
+
}));
|
|
124
|
+
_this.dryrun = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
125
|
+
var res,
|
|
126
|
+
_args3 = arguments;
|
|
127
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
128
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
129
|
+
case 0:
|
|
130
|
+
_context3.next = 2;
|
|
131
|
+
return dryrun.apply(void 0, _args3);
|
|
132
|
+
case 2:
|
|
133
|
+
res = _context3.sent;
|
|
134
|
+
renderLogs(res.Output);
|
|
135
|
+
return _context3.abrupt("return", res);
|
|
136
|
+
case 5:
|
|
137
|
+
case "end":
|
|
138
|
+
return _context3.stop();
|
|
139
|
+
}
|
|
140
|
+
}, _callee3);
|
|
141
|
+
}));
|
|
61
142
|
_this.monitor = monitor;
|
|
62
143
|
_this.unmonitor = unmonitor;
|
|
63
144
|
_this.mem = mem;
|
|
@@ -70,20 +151,20 @@ var AO = /*#__PURE__*/function (_MAO) {
|
|
|
70
151
|
return _createClass(AO, [{
|
|
71
152
|
key: "init",
|
|
72
153
|
value: function () {
|
|
73
|
-
var _init = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
74
|
-
return _regeneratorRuntime().wrap(function
|
|
75
|
-
while (1) switch (
|
|
154
|
+
var _init = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(jwk) {
|
|
155
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
156
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
76
157
|
case 0:
|
|
77
158
|
if (!jwk && this.acc[0]) jwk = this.acc[0].jwk;
|
|
78
|
-
|
|
159
|
+
_context4.next = 3;
|
|
79
160
|
return this.ar.init(jwk);
|
|
80
161
|
case 3:
|
|
81
|
-
return
|
|
162
|
+
return _context4.abrupt("return", this);
|
|
82
163
|
case 4:
|
|
83
164
|
case "end":
|
|
84
|
-
return
|
|
165
|
+
return _context4.stop();
|
|
85
166
|
}
|
|
86
|
-
},
|
|
167
|
+
}, _callee4, this);
|
|
87
168
|
}));
|
|
88
169
|
function init(_x) {
|
|
89
170
|
return _init.apply(this, arguments);
|
|
@@ -93,26 +174,26 @@ var AO = /*#__PURE__*/function (_MAO) {
|
|
|
93
174
|
}, {
|
|
94
175
|
key: "postModule",
|
|
95
176
|
value: function () {
|
|
96
|
-
var _postModule = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
97
|
-
var data,
|
|
98
|
-
return _regeneratorRuntime().wrap(function
|
|
99
|
-
while (1) switch (
|
|
177
|
+
var _postModule = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref4) {
|
|
178
|
+
var data, _ref4$tags, tags, jwk, err, _yield$this$ar$checkW, t, _tags, signer, _yield$this$ar$datait, id, owner;
|
|
179
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
180
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
100
181
|
case 0:
|
|
101
|
-
data =
|
|
182
|
+
data = _ref4.data, _ref4$tags = _ref4.tags, tags = _ref4$tags === void 0 ? {} : _ref4$tags, jwk = _ref4.jwk;
|
|
102
183
|
err = null;
|
|
103
|
-
|
|
184
|
+
_context5.next = 4;
|
|
104
185
|
return this.ar.checkWallet({
|
|
105
186
|
jwk: jwk
|
|
106
187
|
});
|
|
107
188
|
case 4:
|
|
108
|
-
_yield$this$ar$checkW =
|
|
189
|
+
_yield$this$ar$checkW = _context5.sent;
|
|
109
190
|
jwk = _yield$this$ar$checkW.jwk;
|
|
110
191
|
err = _yield$this$ar$checkW.err;
|
|
111
192
|
if (!err) {
|
|
112
|
-
|
|
193
|
+
_context5.next = 9;
|
|
113
194
|
break;
|
|
114
195
|
}
|
|
115
|
-
return
|
|
196
|
+
return _context5.abrupt("return", {
|
|
116
197
|
err: err
|
|
117
198
|
});
|
|
118
199
|
case 9:
|
|
@@ -128,17 +209,17 @@ var AO = /*#__PURE__*/function (_MAO) {
|
|
|
128
209
|
});
|
|
129
210
|
_tags = (0, _utils.buildTags)(null, t);
|
|
130
211
|
signer = (0, _aoconnect.createDataItemSigner)(jwk);
|
|
131
|
-
|
|
212
|
+
_context5.next = 14;
|
|
132
213
|
return this.ar.dataitem({
|
|
133
214
|
tags: _tags,
|
|
134
215
|
data: data,
|
|
135
216
|
signer: signer
|
|
136
217
|
});
|
|
137
218
|
case 14:
|
|
138
|
-
_yield$this$ar$datait =
|
|
219
|
+
_yield$this$ar$datait = _context5.sent;
|
|
139
220
|
id = _yield$this$ar$datait.id;
|
|
140
221
|
owner = _yield$this$ar$datait.owner;
|
|
141
|
-
|
|
222
|
+
_context5.next = 19;
|
|
142
223
|
return this.ar.post({
|
|
143
224
|
data: data,
|
|
144
225
|
tags: t,
|
|
@@ -149,12 +230,12 @@ var AO = /*#__PURE__*/function (_MAO) {
|
|
|
149
230
|
data: data,
|
|
150
231
|
format: t["Module-Format"]
|
|
151
232
|
};
|
|
152
|
-
return
|
|
233
|
+
return _context5.abrupt("return", id);
|
|
153
234
|
case 21:
|
|
154
235
|
case "end":
|
|
155
|
-
return
|
|
236
|
+
return _context5.stop();
|
|
156
237
|
}
|
|
157
|
-
},
|
|
238
|
+
}, _callee5, this);
|
|
158
239
|
}));
|
|
159
240
|
function postModule(_x2) {
|
|
160
241
|
return _postModule.apply(this, arguments);
|
package/esm/tao.js
CHANGED
|
@@ -4,8 +4,49 @@ 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
8
|
|
|
9
|
+
let log = `
|
|
10
|
+
local json = require("json")
|
|
11
|
+
ao = ao or {}
|
|
12
|
+
|
|
13
|
+
function ao.log(txt)
|
|
14
|
+
if type(txt) == 'table' then
|
|
15
|
+
txt = json.encode(txt)
|
|
16
|
+
end
|
|
17
|
+
if type(ao.outbox.Output) == 'string' then
|
|
18
|
+
ao.outbox.Output = {ao.outbox.Output}
|
|
19
|
+
end
|
|
20
|
+
table.insert(ao.outbox.Output, txt)
|
|
21
|
+
ao.outbox.Logs = ao.outbox.Logs or {}
|
|
22
|
+
table.insert(ao.outbox.Logs, txt)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
function ao.result(result)
|
|
26
|
+
if ao.outbox.Error or result.Error then
|
|
27
|
+
return { Error = result.Error or ao.outbox.Error, Output = ao.outbox.Logs }
|
|
28
|
+
end
|
|
29
|
+
return {
|
|
30
|
+
Output = ao.outbox.Logs or result.Output or ao.outbox.Output,
|
|
31
|
+
Messages = ao.outbox.Messages,
|
|
32
|
+
Spawns = ao.outbox.Spawns,
|
|
33
|
+
Assignments = ao.outbox.Assignments,
|
|
34
|
+
}
|
|
35
|
+
end
|
|
36
|
+
`
|
|
37
|
+
|
|
38
|
+
const renderLogs = logs => {
|
|
39
|
+
if (is(Array, logs) && logs.length > 0) {
|
|
40
|
+
for (const v of logs) {
|
|
41
|
+
let l = v
|
|
42
|
+
try {
|
|
43
|
+
const p = JSON.parse(v)
|
|
44
|
+
if (JSON.stringify(p) === v) l = p
|
|
45
|
+
} catch (e) {}
|
|
46
|
+
console.log(l)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
9
50
|
class AO extends MAO {
|
|
10
51
|
constructor(opt = {}) {
|
|
11
52
|
super({ ...opt, in_memory: true })
|
|
@@ -24,11 +65,24 @@ class AO extends MAO {
|
|
|
24
65
|
} = connect(opt.mem)
|
|
25
66
|
this.module = mem.modules.aos2_0_1
|
|
26
67
|
this.assign = assign
|
|
27
|
-
this.result =
|
|
68
|
+
this.result = async (...opt) => {
|
|
69
|
+
const res = await result(...opt)
|
|
70
|
+
renderLogs(res.Output)
|
|
71
|
+
return res
|
|
72
|
+
}
|
|
73
|
+
|
|
28
74
|
this.results = results
|
|
29
75
|
this.message = message
|
|
30
|
-
this.spawn =
|
|
31
|
-
|
|
76
|
+
this.spawn = async (...opt) => {
|
|
77
|
+
const res = await spawn(...opt)
|
|
78
|
+
await this.load({ data: log, pid: res })
|
|
79
|
+
return res
|
|
80
|
+
}
|
|
81
|
+
this.dryrun = async (...opt) => {
|
|
82
|
+
const res = await dryrun(...opt)
|
|
83
|
+
renderLogs(res.Output)
|
|
84
|
+
return res
|
|
85
|
+
}
|
|
32
86
|
this.monitor = monitor
|
|
33
87
|
this.unmonitor = unmonitor
|
|
34
88
|
this.mem = mem
|