tune-sdk 0.2.12 → 0.2.13
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/dist/cli.js +20 -19
- package/dist/tune.js +43 -15
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
var assert, tune, rpc, path, fs, os, cp, stream;
|
|
2
2
|
assert = require("assert");
|
|
3
3
|
|
|
4
|
+
function tpl(str) {
|
|
5
|
+
var _i;
|
|
6
|
+
var params = 2 <= arguments.length ? [].slice.call(arguments, 1, _i = arguments.length - 0) : (_i = 1, []);
|
|
7
|
+
return (function(paramIndex, params) {
|
|
8
|
+
var _ref;
|
|
9
|
+
try {
|
|
10
|
+
_ref = str.replace(/{(\W*)(\w*)(\W*)}/gm, (function(_, pre, name, post) {
|
|
11
|
+
return (function(res) {
|
|
12
|
+
paramIndex += 1;
|
|
13
|
+
return ((typeof res !== 'undefined') ? ((pre || "") + res + (post || "")) : "");
|
|
14
|
+
})(params[name || paramIndex]);
|
|
15
|
+
}));
|
|
16
|
+
} catch (e) {
|
|
17
|
+
_ref = console.log.apply(console, [].concat([e, str]).concat(params));
|
|
18
|
+
}
|
|
19
|
+
return _ref;
|
|
20
|
+
})(0, (((typeof params[0] === "object") && (params.length === 1)) ? params[0] : params));
|
|
21
|
+
}
|
|
22
|
+
|
|
4
23
|
function showHelp() {
|
|
5
24
|
console.log("TUNE-CLI - Command Line Interface for Tune SDK");
|
|
6
25
|
console.log("");
|
|
@@ -408,31 +427,13 @@ async function main() {
|
|
|
408
427
|
_ref = await run(args);
|
|
409
428
|
}
|
|
410
429
|
} catch (e) {
|
|
411
|
-
console.error(e);
|
|
430
|
+
console.error(e.stack);
|
|
412
431
|
_ref = process.exit(1);
|
|
413
432
|
}
|
|
414
433
|
return _ref;
|
|
415
434
|
}
|
|
416
435
|
main;
|
|
417
436
|
|
|
418
|
-
function tpl(str) {
|
|
419
|
-
var _i;
|
|
420
|
-
var params = 2 <= arguments.length ? [].slice.call(arguments, 1, _i = arguments.length - 0) : (_i = 1, []);
|
|
421
|
-
return (function(paramIndex, params) {
|
|
422
|
-
var _ref;
|
|
423
|
-
try {
|
|
424
|
-
_ref = str.replace(/{(\W*)(\w*)(\W*)}/gm, (function(_, pre, name, post) {
|
|
425
|
-
return (function(res) {
|
|
426
|
-
paramIndex += 1;
|
|
427
|
-
return ((typeof res !== 'undefined') ? ((pre || "") + res + (post || "")) : "");
|
|
428
|
-
})(params[name || paramIndex]);
|
|
429
|
-
}));
|
|
430
|
-
} catch (e) {
|
|
431
|
-
_ref = console.log.apply(console, [].concat([e, str]).concat(params));
|
|
432
|
-
}
|
|
433
|
-
return _ref;
|
|
434
|
-
})(0, (((typeof params[0] === "object") && (params.length === 1)) ? params[0] : params));
|
|
435
|
-
}
|
|
436
437
|
tpl;
|
|
437
438
|
exports.parseArgs = parseArgs;
|
|
438
439
|
exports.rpc = rpc;
|
package/dist/tune.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var util, $roles;
|
|
1
|
+
var util, AsyncLocalStorage, als, $roles;
|
|
2
2
|
|
|
3
3
|
function extend() {
|
|
4
4
|
var _i;
|
|
@@ -38,7 +38,18 @@ AsyncIter.prototype.next = (async function() {
|
|
|
38
38
|
if (self.err) throw self.err;
|
|
39
39
|
return result;
|
|
40
40
|
});
|
|
41
|
-
if ((typeof require !== 'undefined'))
|
|
41
|
+
if ((typeof require !== 'undefined')) {
|
|
42
|
+
util = require("util");
|
|
43
|
+
AsyncLocalStorage = require("node:async_hooks").AsyncLocalStorage;
|
|
44
|
+
als = new AsyncLocalStorage();
|
|
45
|
+
} else {
|
|
46
|
+
als = {
|
|
47
|
+
getStore: (function() {}),
|
|
48
|
+
run: (async function(store, func) {
|
|
49
|
+
return func();
|
|
50
|
+
})
|
|
51
|
+
};
|
|
52
|
+
}
|
|
42
53
|
|
|
43
54
|
function TuneError(message, filename, row, col, stack, originalError) {
|
|
44
55
|
var lastItem;
|
|
@@ -1079,29 +1090,46 @@ Context.prototype.use = (function(middleware) {
|
|
|
1079
1090
|
return _ref0;
|
|
1080
1091
|
});
|
|
1081
1092
|
async function resolve(ctx, name, args, middlewares) {
|
|
1082
|
-
var i, output, match, type, result, res, md;
|
|
1093
|
+
var i, output, match, type, result, res, resolveStack, md;
|
|
1083
1094
|
middlewares = middlewares || ctx.ms;
|
|
1084
1095
|
if (!middlewares.length) return;
|
|
1096
|
+
if (((typeof name !== "string") && !(name instanceof String))) throw Error(tpl("resolve '{name}' is not a string", {
|
|
1097
|
+
name: name
|
|
1098
|
+
}));
|
|
1085
1099
|
var i;
|
|
1086
1100
|
var output;
|
|
1087
1101
|
var match;
|
|
1088
1102
|
var type;
|
|
1089
1103
|
var result;
|
|
1090
1104
|
var res;
|
|
1105
|
+
var resolveStack;
|
|
1091
1106
|
i = 0;
|
|
1092
1107
|
output = (((typeof args !== "undefined") && (args !== null) && !Number.isNaN(args) && (typeof args.output !== "undefined") && (args.output !== null) && !Number.isNaN(args.output)) ? args.output : (((typeof "first" !== "undefined") && ("first" !== null) && !Number.isNaN("first")) ? "first" : undefined));
|
|
1093
1108
|
match = (((typeof args !== "undefined") && (args !== null) && !Number.isNaN(args) && (typeof args.match !== "undefined") && (args.match !== null) && !Number.isNaN(args.match)) ? args.match : (((typeof "exact" !== "undefined") && ("exact" !== null) && !Number.isNaN("exact")) ? "exact" : undefined));
|
|
1094
1109
|
type = (((typeof args !== "undefined") && (args !== null) && !Number.isNaN(args) && (typeof args.type !== "undefined") && (args.type !== null) && !Number.isNaN(args.type)) ? args.type : (((typeof "any" !== "undefined") && ("any" !== null) && !Number.isNaN("any")) ? "any" : undefined));
|
|
1095
1110
|
result = [];
|
|
1096
1111
|
res = undefined;
|
|
1112
|
+
resolveStack = als.getStore() || [];
|
|
1097
1113
|
while (i < middlewares.length) {
|
|
1098
1114
|
var md;
|
|
1099
1115
|
md = middlewares[i];
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1116
|
+
if (resolveStack.some((function(item) {
|
|
1117
|
+
return ((item.md === md) && (item.name === name));
|
|
1118
|
+
}))) {
|
|
1119
|
+
i++;
|
|
1120
|
+
continue;
|
|
1121
|
+
}
|
|
1122
|
+
if ((resolveStack.length > 50)) throw Error("resolve stack overflow");
|
|
1123
|
+
res = await als.run(resolveStack.concat(Array({
|
|
1124
|
+
md: md,
|
|
1125
|
+
name: name
|
|
1126
|
+
})), (async function() {
|
|
1127
|
+
return md.call(ctx, name, {
|
|
1128
|
+
output: output,
|
|
1129
|
+
match: match,
|
|
1130
|
+
type: type
|
|
1131
|
+
});
|
|
1132
|
+
}));
|
|
1105
1133
|
if (!res) {
|
|
1106
1134
|
i++;
|
|
1107
1135
|
continue;
|
|
@@ -1151,7 +1179,7 @@ Context.prototype.file2run = (function(opts, params) {
|
|
|
1151
1179
|
Context.prototype.text2ast = (async function(text) {
|
|
1152
1180
|
return text2ast(text, this);
|
|
1153
1181
|
});
|
|
1154
|
-
Context.prototype.
|
|
1182
|
+
Context.prototype.text2payload = (async function(text) {
|
|
1155
1183
|
return text2payload(text, this);
|
|
1156
1184
|
});
|
|
1157
1185
|
Context.prototype.msg2text = msg2text;
|
|
@@ -2174,7 +2202,7 @@ function text2run(text, ctx, opts) {
|
|
|
2174
2202
|
}
|
|
2175
2203
|
text2run;
|
|
2176
2204
|
async function file2run(args, params, ctx) {
|
|
2177
|
-
var lctx, text, stop, node, response, res, r, chunk,
|
|
2205
|
+
var lctx, text, stop, node, response, res, r, chunk, itergnVy4sP, _ref;
|
|
2178
2206
|
var lctx;
|
|
2179
2207
|
lctx = ctx.clone();
|
|
2180
2208
|
if (params) lctx.ms.unshift(envmd(params));
|
|
@@ -2241,7 +2269,7 @@ async function file2run(args, params, ctx) {
|
|
|
2241
2269
|
stream: true
|
|
2242
2270
|
});
|
|
2243
2271
|
chunk = {};
|
|
2244
|
-
|
|
2272
|
+
itergnVy4sP = new AsyncIter();
|
|
2245
2273
|
(async function($lastRes) {
|
|
2246
2274
|
var _ref;
|
|
2247
2275
|
try {
|
|
@@ -2250,20 +2278,20 @@ async function file2run(args, params, ctx) {
|
|
|
2250
2278
|
res = (chunk.value || "");
|
|
2251
2279
|
if (chunk.done) await save();
|
|
2252
2280
|
$lastRes = transformOutput(res) || $lastRes;
|
|
2253
|
-
|
|
2281
|
+
itergnVy4sP.result = {
|
|
2254
2282
|
value: $lastRes
|
|
2255
2283
|
}
|
|
2256
2284
|
}
|
|
2257
|
-
_ref =
|
|
2285
|
+
_ref = itergnVy4sP.result = {
|
|
2258
2286
|
value: $lastRes,
|
|
2259
2287
|
done: true
|
|
2260
2288
|
}
|
|
2261
2289
|
} catch (e) {
|
|
2262
|
-
_ref = (
|
|
2290
|
+
_ref = (itergnVy4sP.err = e);
|
|
2263
2291
|
}
|
|
2264
2292
|
return _ref;
|
|
2265
2293
|
})();
|
|
2266
|
-
_ref =
|
|
2294
|
+
_ref = itergnVy4sP;
|
|
2267
2295
|
}
|
|
2268
2296
|
return _ref;
|
|
2269
2297
|
}
|