jsir 1.2.8 → 1.2.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/cmd/ooa.js +123 -69
- package/ethWeb.js +2 -0
- package/package.json +1 -1
- package/util.js +68 -6
package/cmd/ooa.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
const {
|
|
3
3
|
run, getLibDataDir, trim, regEach, getConfig, mkdir, requireG, reget,
|
|
4
|
-
getCbText, e, sleep, objDataFile, setConfig,
|
|
4
|
+
getCbText, e, sleep, objDataFile, setConfig, vl, md5, BigNumber,
|
|
5
5
|
info, warn, error, arrayDataFile, infoStr, warnStr, errorStr, errorStack,
|
|
6
|
-
getInfo, ei, pad, msg, msgStr
|
|
6
|
+
getInfo, ei, pad, msg, msgStr, isError, getType, tableStr, nableStr, objProfileRows
|
|
7
7
|
} = require('../util')
|
|
8
8
|
|
|
9
9
|
const _types = {
|
|
@@ -11,7 +11,7 @@ const _types = {
|
|
|
11
11
|
'i': "init",
|
|
12
12
|
'f': "file"
|
|
13
13
|
}
|
|
14
|
-
const
|
|
14
|
+
const _chokidar = require('chokidar');
|
|
15
15
|
const _fs = require('fs')
|
|
16
16
|
const _libDataDir = getLibDataDir()
|
|
17
17
|
const _home = _libDataDir + '/ooa'
|
|
@@ -38,12 +38,11 @@ try {
|
|
|
38
38
|
error(e)
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
const _table = require('console.table')
|
|
42
41
|
console.table = (...args) => {
|
|
43
|
-
console.log(
|
|
42
|
+
console.log(tableStr(...args))
|
|
44
43
|
}
|
|
45
44
|
console.nable = (rows) => {
|
|
46
|
-
console.
|
|
45
|
+
console.log(nableStr(rows))
|
|
47
46
|
}
|
|
48
47
|
|
|
49
48
|
let _noAppendNextLine = true
|
|
@@ -107,6 +106,10 @@ const _mainCmdMap = {
|
|
|
107
106
|
lib: {
|
|
108
107
|
comment: "查看内置资源",
|
|
109
108
|
cmd: ['*$lib ']
|
|
109
|
+
},
|
|
110
|
+
deps: {
|
|
111
|
+
comment: "查看依赖",
|
|
112
|
+
cmd: ['@^']
|
|
110
113
|
}
|
|
111
114
|
}
|
|
112
115
|
|
|
@@ -166,19 +169,7 @@ run(async () => {
|
|
|
166
169
|
_cmdMap = objDataFile('ooaCmdMap.json')
|
|
167
170
|
}
|
|
168
171
|
|
|
169
|
-
if (isMainCmd(['run', 'edit', 'rm', 'diff', 'push', 'pull'])
|
|
170
|
-
&& _args[1] && !/^\d+$/.test(_args[1])) {
|
|
171
|
-
let name = toJsirFileName(`e ${_args[1]}`)
|
|
172
|
-
let path = _home + '/' + name
|
|
173
|
-
if (_fs.existsSync(path)) {
|
|
174
|
-
_cmdMap = {
|
|
175
|
-
'1': name
|
|
176
|
-
}
|
|
177
|
-
_args[1] = '1'
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
if (isMainCmd(['run', 'edit', 'rm', 'diff', 'push', 'pull'])
|
|
172
|
+
if (isMainCmd(['run', 'edit', 'rm', 'diff', 'push', 'pull', 'deps'])
|
|
182
173
|
&& _args[1] && !/^\d+$/.test(_args[1])) {
|
|
183
174
|
warn('wrong args')
|
|
184
175
|
return
|
|
@@ -203,7 +194,7 @@ run(async () => {
|
|
|
203
194
|
}
|
|
204
195
|
return i
|
|
205
196
|
}).join(' ').replace(/^@/, '')
|
|
206
|
-
if (isMainCmd(['run', 'edit', 'rm', 'diff', 'push', 'pull']) && !trim(argStr)) {
|
|
197
|
+
if (isMainCmd(['run', 'edit', 'rm', 'diff', 'push', 'pull', 'deps']) && !trim(argStr)) {
|
|
207
198
|
_args[0] = '@'
|
|
208
199
|
}
|
|
209
200
|
if (isMainCmd(['ls']) && !trim(argStr)) {
|
|
@@ -259,7 +250,7 @@ async function getFileWatcher(fileName, workFile, text) {
|
|
|
259
250
|
_fs.unlinkSync(workFile)
|
|
260
251
|
await sleep(1000)
|
|
261
252
|
_fs.writeFileSync(workFile, text)
|
|
262
|
-
let watcher =
|
|
253
|
+
let watcher = _chokidar.watch([workFile]);
|
|
263
254
|
_fileWatcherMap[workFile] = watcher;
|
|
264
255
|
return watcher
|
|
265
256
|
}
|
|
@@ -543,7 +534,7 @@ function hisToCmdMap() {
|
|
|
543
534
|
_cmdMap = cmdMap
|
|
544
535
|
}
|
|
545
536
|
|
|
546
|
-
function listCmd(
|
|
537
|
+
function listCmd(prefixKey, inputCmdMap) {
|
|
547
538
|
let currCmdMap = _cmdMap
|
|
548
539
|
if (inputCmdMap) {
|
|
549
540
|
currCmdMap =inputCmdMap;
|
|
@@ -565,7 +556,7 @@ function listCmd(prefix, inputCmdMap) {
|
|
|
565
556
|
}
|
|
566
557
|
}
|
|
567
558
|
let items = Object.values(currCmdMap)
|
|
568
|
-
.filter(item => _fs.existsSync(_home + "/" + item) && (!
|
|
559
|
+
.filter(item => _fs.existsSync(_home + "/" + item) && (!prefixKey || prefixMap[item].indexOf(prefixKey) !== -1))
|
|
569
560
|
.sort((a,b) => {
|
|
570
561
|
let typeKeys = Object.keys(_types);
|
|
571
562
|
let orderA = typeKeys.indexOf(a.split(/\s+/)[0]);
|
|
@@ -625,35 +616,6 @@ function listCmd(prefix, inputCmdMap) {
|
|
|
625
616
|
}
|
|
626
617
|
}
|
|
627
618
|
|
|
628
|
-
function printObjProfile(result) {
|
|
629
|
-
result = Object.keys(result).map(key => {
|
|
630
|
-
return {
|
|
631
|
-
key,
|
|
632
|
-
type: typeof result[key]
|
|
633
|
-
}})
|
|
634
|
-
.sort((a,b) => {
|
|
635
|
-
return a.type >= b.type ? 1:-1
|
|
636
|
-
})
|
|
637
|
-
|
|
638
|
-
let temp = []
|
|
639
|
-
for(let i = 0; i< Object.keys(result).length; i+=3) {
|
|
640
|
-
let item = {}
|
|
641
|
-
temp.push(item)
|
|
642
|
-
|
|
643
|
-
item['type'] = result[i].type
|
|
644
|
-
item['name']= result[i].key
|
|
645
|
-
if (result[i+1]) {
|
|
646
|
-
item['type '] = result[i+1].type
|
|
647
|
-
item['name ']= result[i+1].key
|
|
648
|
-
}
|
|
649
|
-
if (result[i+2]) {
|
|
650
|
-
item['type '] = result[i+2].type
|
|
651
|
-
item['name ']= result[i+2].key
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
console.table(temp)
|
|
655
|
-
}
|
|
656
|
-
|
|
657
619
|
function draftQuery(fLine) {
|
|
658
620
|
let lines = []
|
|
659
621
|
let text = String(_fs.readFileSync(getLibDataDir() + "/log/draft.log"))
|
|
@@ -677,15 +639,21 @@ function draftQuery(fLine) {
|
|
|
677
639
|
}
|
|
678
640
|
|
|
679
641
|
let results = []
|
|
680
|
-
if (
|
|
681
|
-
let
|
|
682
|
-
|
|
683
|
-
} else {
|
|
642
|
+
if (!/^\d+$/.test(fLine)) {
|
|
643
|
+
let ss = fLine.split(/\s+/)
|
|
644
|
+
fLine = ss[0]
|
|
684
645
|
for (let line of lines) {
|
|
685
|
-
if (
|
|
646
|
+
if (new RegExp(fLine, 'i').test(line)) {
|
|
686
647
|
results.push(line)
|
|
687
648
|
}
|
|
688
649
|
}
|
|
650
|
+
fLine = ss[1]
|
|
651
|
+
lines = results
|
|
652
|
+
results = []
|
|
653
|
+
}
|
|
654
|
+
if (fLine && /^\d+$/.test(fLine)) {
|
|
655
|
+
let index = Math.abs(parseInt(fLine));
|
|
656
|
+
results.push(...lines.slice(- index))
|
|
689
657
|
}
|
|
690
658
|
console.log(results.join("\n"))
|
|
691
659
|
}
|
|
@@ -753,7 +721,7 @@ async function _wrapperInput(str) {
|
|
|
753
721
|
if (is$) {
|
|
754
722
|
let result = await evalText('return ' + text)
|
|
755
723
|
if (result === $lib) {
|
|
756
|
-
|
|
724
|
+
console.table(objProfileRows(result))
|
|
757
725
|
} else {
|
|
758
726
|
console.log(result)
|
|
759
727
|
}
|
|
@@ -822,7 +790,6 @@ async function dealKeyword(str, strs, fstr, ostr) {
|
|
|
822
790
|
let path = _home + '/' + _cmdMap[fstr]
|
|
823
791
|
let sourceStr = String(_fs.readFileSync(path))
|
|
824
792
|
console.log(sourceStr)
|
|
825
|
-
// await setCbText(sourceStr)
|
|
826
793
|
}
|
|
827
794
|
} else if (/^-\d*$/.test(fstr)) {
|
|
828
795
|
let name = _cmdMap[String(Number(fstr) * -1)]
|
|
@@ -895,7 +862,6 @@ async function dealKeyword(str, strs, fstr, ostr) {
|
|
|
895
862
|
if (_fs.existsSync(sFile)) {
|
|
896
863
|
let sourceStr = String(_fs.readFileSync(sFile))
|
|
897
864
|
console.log(sourceStr)
|
|
898
|
-
// await setCbText(sourceStr)
|
|
899
865
|
}
|
|
900
866
|
} else {
|
|
901
867
|
warn('require config.jsLibSource')
|
|
@@ -960,6 +926,15 @@ async function dealKeyword(str, strs, fstr, ostr) {
|
|
|
960
926
|
warn('require config.jsLibSource')
|
|
961
927
|
}
|
|
962
928
|
}
|
|
929
|
+
} else if (/^\^\d*$/.test(fstr)) {
|
|
930
|
+
let name = _cmdMap[trim(fstr.replace(/^\^/, ''))]
|
|
931
|
+
if (!name) {
|
|
932
|
+
warn("no items")
|
|
933
|
+
} else {
|
|
934
|
+
let md5Keys = getScriptRequires(name);
|
|
935
|
+
_cmdMap = filterCmd(md5Keys)
|
|
936
|
+
listCmd()
|
|
937
|
+
}
|
|
963
938
|
} else if (/^e\d+$/.test(fstr)) {
|
|
964
939
|
await runCmd(trim(str.substring(1)).replace(/^e/, ''))
|
|
965
940
|
} else if (fstr === 'e' && ostr.length === 0) {
|
|
@@ -1003,6 +978,45 @@ async function dealKeyword(str, strs, fstr, ostr) {
|
|
|
1003
978
|
}
|
|
1004
979
|
}
|
|
1005
980
|
|
|
981
|
+
function getScriptMd5Map() {
|
|
982
|
+
let files = _fs.readdirSync(_home)
|
|
983
|
+
let md5Map = {}
|
|
984
|
+
for (let file of files) {
|
|
985
|
+
file = trim(file)
|
|
986
|
+
md5Map['0x' + md5(file).substr(0, 8)] = file;
|
|
987
|
+
}
|
|
988
|
+
return md5Map
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
function _getScriptRequires(md5Map, scriptName, md5Keys, links) {
|
|
992
|
+
let path = _home + '/' + scriptName;
|
|
993
|
+
let text = String(_fs.readFileSync(path))
|
|
994
|
+
let temp = []
|
|
995
|
+
regEach(text, /(0x[0-9a-f]{8})/g, r=> {
|
|
996
|
+
temp.push(r[1])
|
|
997
|
+
});
|
|
998
|
+
temp = [...new Set(temp)]
|
|
999
|
+
temp = temp.filter(i => {
|
|
1000
|
+
let have = md5Map[i];
|
|
1001
|
+
if (have && links.indexOf(i) !== -1) {
|
|
1002
|
+
let items = [...links, i];
|
|
1003
|
+
let errorStr = items.map(item => item === i ? warnStr(item):item).join("->")
|
|
1004
|
+
throw `circle deps: ${errorStr}`
|
|
1005
|
+
}
|
|
1006
|
+
return have;
|
|
1007
|
+
})
|
|
1008
|
+
md5Keys.push(...temp)
|
|
1009
|
+
for (let md5Key of temp) {
|
|
1010
|
+
_getScriptRequires(md5Map, md5Map[md5Key], md5Keys, [...links, md5Key])
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
function getScriptRequires(scriptName) {
|
|
1015
|
+
let md5Keys = [];
|
|
1016
|
+
_getScriptRequires(getScriptMd5Map(), scriptName, md5Keys, ['0x' + md5(scriptName).substr(0, 8)]);
|
|
1017
|
+
return md5Keys
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1006
1020
|
function getComments(cmdName, text, cols = [], col) {
|
|
1007
1021
|
let docLines = [infoStr('0x' + md5(cmdName).substr(0, 8))]
|
|
1008
1022
|
text = trim(text)
|
|
@@ -1194,7 +1208,7 @@ async function runCmd(str = '', scriptName = '', text = '') {
|
|
|
1194
1208
|
if (pair[1]) {
|
|
1195
1209
|
pair[1] = trim(pair[1])
|
|
1196
1210
|
}
|
|
1197
|
-
if (pair[0] &&
|
|
1211
|
+
if (pair[0] && argNames.indexOf(pair[0]) === -1) {
|
|
1198
1212
|
throw 'invalid argName ' + pair[0]
|
|
1199
1213
|
}
|
|
1200
1214
|
pair[1] = needTrans ? await evalText( 'return ' + pair[1]):pair[1]
|
|
@@ -1205,7 +1219,7 @@ async function runCmd(str = '', scriptName = '', text = '') {
|
|
|
1205
1219
|
if (argNames[curIdx]) {
|
|
1206
1220
|
scriptArgs[argNames[curIdx]] = pair[1]
|
|
1207
1221
|
}
|
|
1208
|
-
if (pair[0] &&
|
|
1222
|
+
if (pair[0] && argNames.indexOf(pair[0]) !== -1) {
|
|
1209
1223
|
delete scriptArgs[argNames[curIdx]]
|
|
1210
1224
|
exactArgs[pair[0]] = pair[1]
|
|
1211
1225
|
}
|
|
@@ -1214,6 +1228,7 @@ async function runCmd(str = '', scriptName = '', text = '') {
|
|
|
1214
1228
|
scriptArgs[key] = exactArgs[key]
|
|
1215
1229
|
}
|
|
1216
1230
|
let exit = false
|
|
1231
|
+
let scriptArgKeys = Object.keys(scriptArgs);
|
|
1217
1232
|
for(let name of argNames) {
|
|
1218
1233
|
let defStr = argDef[name]
|
|
1219
1234
|
let beginIdx = defStr.indexOf("^");
|
|
@@ -1222,10 +1237,10 @@ async function runCmd(str = '', scriptName = '', text = '') {
|
|
|
1222
1237
|
if (beginIdx !== -1 && endIdx !== -1 && beginIdx < endIdx) {
|
|
1223
1238
|
reg = new RegExp(defStr.substring(beginIdx, endIdx + 1));
|
|
1224
1239
|
}
|
|
1225
|
-
if (name.startsWith("_") &&
|
|
1240
|
+
if (name.startsWith("_") && scriptArgKeys.indexOf(name) === -1) {
|
|
1226
1241
|
continue
|
|
1227
1242
|
}
|
|
1228
|
-
if (
|
|
1243
|
+
if (scriptArgKeys.indexOf(name) === -1 || (reg && !reg.test(scriptArgs[name]))) {
|
|
1229
1244
|
exit = true
|
|
1230
1245
|
warn(`require ${warnStr(name)}` + (defStr ? ` <${defStr}>`:''))
|
|
1231
1246
|
}
|
|
@@ -1275,9 +1290,15 @@ function getArgDef(text) {
|
|
|
1275
1290
|
let argDef = {}
|
|
1276
1291
|
try {
|
|
1277
1292
|
argDef = eval(`(${exeStr || '{}'})`) || {}
|
|
1293
|
+
let array = []
|
|
1294
|
+
for (let key of Object.keys(argDef)) {
|
|
1295
|
+
if (array.hasOwnProperty(key)) {
|
|
1296
|
+
throw `invalid argName ${key}`
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1278
1299
|
} catch (e) {
|
|
1279
1300
|
$log(errorStack(e))
|
|
1280
|
-
argDef
|
|
1301
|
+
argDef = {'[ParseError]': String(e)}
|
|
1281
1302
|
}
|
|
1282
1303
|
if (typeof argDef !== 'object') {
|
|
1283
1304
|
argDef = {}
|
|
@@ -1376,6 +1397,24 @@ async function _requireSource(cmdMatchStr, ignoreLog = false) {
|
|
|
1376
1397
|
}
|
|
1377
1398
|
throw `invalid returned: ${cmdMatchStr}`
|
|
1378
1399
|
}
|
|
1400
|
+
if (typeof result === 'function') {
|
|
1401
|
+
let tmp = result;
|
|
1402
|
+
result = (...args) => {
|
|
1403
|
+
let resp
|
|
1404
|
+
try {
|
|
1405
|
+
resp = tmp(...args)
|
|
1406
|
+
} catch (e) {
|
|
1407
|
+
throw _errorAppend(e, cmdName);
|
|
1408
|
+
}
|
|
1409
|
+
if (getType(resp) === 'Promise') {
|
|
1410
|
+
return resp.catch(e => {
|
|
1411
|
+
return Promise.reject(_errorAppend(e, cmdName))
|
|
1412
|
+
})
|
|
1413
|
+
} else {
|
|
1414
|
+
return resp;
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1379
1418
|
return result
|
|
1380
1419
|
}
|
|
1381
1420
|
|
|
@@ -1400,6 +1439,18 @@ async function _requireSources(...matchItem) {
|
|
|
1400
1439
|
return result
|
|
1401
1440
|
}
|
|
1402
1441
|
|
|
1442
|
+
function _errorAppend(e, $cmdName) {
|
|
1443
|
+
if (!$cmdName) {
|
|
1444
|
+
return e;
|
|
1445
|
+
}
|
|
1446
|
+
if (!isError(e)) {
|
|
1447
|
+
e = new Error(e)
|
|
1448
|
+
e.stack = e.stack.split(/\n/)[0]
|
|
1449
|
+
}
|
|
1450
|
+
e.stack = e.stack + `\n at ${$cmdName}`
|
|
1451
|
+
return e
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1403
1454
|
function evalText($text = '', $cmdName = '', $args = []) {
|
|
1404
1455
|
const require = requireG;
|
|
1405
1456
|
const $nextLine = nextLine;
|
|
@@ -1418,13 +1469,16 @@ function evalText($text = '', $cmdName = '', $args = []) {
|
|
|
1418
1469
|
const $cmdMap = _cmdMap;
|
|
1419
1470
|
const $defArgs = () => $args;
|
|
1420
1471
|
const $require = _requireSources;
|
|
1472
|
+
const $tableStr = tableStr;
|
|
1473
|
+
const $nableStr = nableStr;
|
|
1474
|
+
const $table = console.table;
|
|
1475
|
+
const $nable = console.nable;
|
|
1421
1476
|
|
|
1422
|
-
|
|
1477
|
+
return eval(`(async ()=>{try {${$text};
|
|
1423
1478
|
} catch(e) {
|
|
1424
|
-
throw
|
|
1479
|
+
throw _errorAppend(e, $cmdName);
|
|
1425
1480
|
}
|
|
1426
|
-
})()`
|
|
1427
|
-
return eval(code)
|
|
1481
|
+
})()`)
|
|
1428
1482
|
}
|
|
1429
1483
|
|
|
1430
1484
|
process.on('uncaughtException',function(err){
|
package/ethWeb.js
CHANGED
package/package.json
CHANGED
package/util.js
CHANGED
|
@@ -16,6 +16,8 @@ const crypto = require('crypto');
|
|
|
16
16
|
const globalDirectories = require('global-dirs');
|
|
17
17
|
const emptyFn = ()=>{}
|
|
18
18
|
const dayJs = require('dayjs')
|
|
19
|
+
const table = require('console.table')
|
|
20
|
+
|
|
19
21
|
let _globalLog = createLimitLogger2(`${setting.name}.log`, null, false)
|
|
20
22
|
global.$log = str => {
|
|
21
23
|
str = trim(str)
|
|
@@ -47,7 +49,7 @@ global.$config = {
|
|
|
47
49
|
localConfig: {},
|
|
48
50
|
remoteConfig: {},
|
|
49
51
|
getLocal: (key, defaultVal) => {
|
|
50
|
-
if (key &&
|
|
52
|
+
if (key && Object.keys($config.localConfig).indexOf(key) === -1) {
|
|
51
53
|
getConfig(key)
|
|
52
54
|
}
|
|
53
55
|
return getVl($config.localConfig[key], defaultVal)
|
|
@@ -85,6 +87,14 @@ async function _buildConfig() {
|
|
|
85
87
|
$config._buildId = setTimeout(_buildConfig, 3000);
|
|
86
88
|
}
|
|
87
89
|
|
|
90
|
+
function tableStr(...args) {
|
|
91
|
+
return trim(table.getTable(...args))
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function nableStr(rows) {
|
|
95
|
+
return tableStr(wrapRows(rows))
|
|
96
|
+
}
|
|
97
|
+
|
|
88
98
|
function timeStr(fmt, date) {
|
|
89
99
|
return dayJs(date || new Date()).format(fmt || 'YYYY/MM/DD HH:mm:ss')
|
|
90
100
|
}
|
|
@@ -93,6 +103,9 @@ function vl(obj) {
|
|
|
93
103
|
if (typeof obj === 'number') {
|
|
94
104
|
return !Number.isNaN(obj)
|
|
95
105
|
}
|
|
106
|
+
if (typeof obj === 'string') {
|
|
107
|
+
obj = trim(obj)
|
|
108
|
+
}
|
|
96
109
|
return !(obj === null || obj === undefined || obj === '')
|
|
97
110
|
}
|
|
98
111
|
|
|
@@ -304,7 +317,16 @@ function requireG(module){
|
|
|
304
317
|
return require(path);
|
|
305
318
|
}
|
|
306
319
|
|
|
320
|
+
function validStr(str, name) {
|
|
321
|
+
if (!vl(str) || typeof str !== 'string') {
|
|
322
|
+
throw "invalid cipher " + name;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
307
326
|
function aesCipher(str, key){
|
|
327
|
+
validStr(str, "str");
|
|
328
|
+
validStr(key, "key");
|
|
329
|
+
|
|
308
330
|
key = trim(key);
|
|
309
331
|
if (!key || key.length > 16) {
|
|
310
332
|
throw "aesCipher key length should between 1 and 16"
|
|
@@ -314,11 +336,14 @@ function aesCipher(str, key){
|
|
|
314
336
|
return cipher.update(str, 'utf8', 'hex') + cipher.final('hex');
|
|
315
337
|
} catch(err) {
|
|
316
338
|
$log(errorStack(err))
|
|
317
|
-
throw 'aesCipher failed'
|
|
339
|
+
throw 'aesCipher failed: ' + String(err)
|
|
318
340
|
}
|
|
319
341
|
}
|
|
320
342
|
|
|
321
343
|
function aesDecipher(str, key){
|
|
344
|
+
validStr(str, "str");
|
|
345
|
+
validStr(key, "key");
|
|
346
|
+
|
|
322
347
|
key = trim(key);
|
|
323
348
|
if (!key || key.length > 16) {
|
|
324
349
|
throw "aesCipher key length should between 1 and 16"
|
|
@@ -328,7 +353,7 @@ function aesDecipher(str, key){
|
|
|
328
353
|
return decipher.update(str, 'hex', 'utf8') + decipher.final('utf8');
|
|
329
354
|
} catch(err) {
|
|
330
355
|
$log(errorStack(err))
|
|
331
|
-
throw 'aesDecipher failed'
|
|
356
|
+
throw 'aesDecipher failed: ' + String(err)
|
|
332
357
|
}
|
|
333
358
|
}
|
|
334
359
|
|
|
@@ -853,8 +878,8 @@ function warn(msg) {
|
|
|
853
878
|
console.warn(warnStr('[warn]'), msg)
|
|
854
879
|
}
|
|
855
880
|
|
|
856
|
-
function error(
|
|
857
|
-
console.error(errorStr(`[${
|
|
881
|
+
function error(msg, tag) {
|
|
882
|
+
console.error(errorStr(`[${tag || 'error'}]`), msg)
|
|
858
883
|
}
|
|
859
884
|
|
|
860
885
|
function infoStr(str) {
|
|
@@ -910,6 +935,10 @@ function errorStack(e) {
|
|
|
910
935
|
return String(e ? (e.stack || e):e)
|
|
911
936
|
}
|
|
912
937
|
|
|
938
|
+
function errorMsg(e) {
|
|
939
|
+
return trim(String(e).split("\n").map(trim).filter(i => i)[0])
|
|
940
|
+
}
|
|
941
|
+
|
|
913
942
|
function getType(obj) {
|
|
914
943
|
if (obj === '') {
|
|
915
944
|
return typeof obj;
|
|
@@ -1001,6 +1030,35 @@ async function batchAsync(fns = [], asyncNum = 1) {
|
|
|
1001
1030
|
return await Promise.all(pros)
|
|
1002
1031
|
}
|
|
1003
1032
|
|
|
1033
|
+
function objProfileRows(result) {
|
|
1034
|
+
result = Object.keys(result).map(key => {
|
|
1035
|
+
return {
|
|
1036
|
+
key,
|
|
1037
|
+
type: getType(result[key])
|
|
1038
|
+
}})
|
|
1039
|
+
.sort((a,b) => {
|
|
1040
|
+
return a.type >= b.type ? 1:-1
|
|
1041
|
+
})
|
|
1042
|
+
|
|
1043
|
+
let temp = []
|
|
1044
|
+
for(let i = 0; i< Object.keys(result).length; i+=3) {
|
|
1045
|
+
let item = {}
|
|
1046
|
+
temp.push(item)
|
|
1047
|
+
|
|
1048
|
+
item['type'] = result[i].type
|
|
1049
|
+
item['name']= result[i].key
|
|
1050
|
+
if (result[i+1]) {
|
|
1051
|
+
item['type '] = result[i+1].type
|
|
1052
|
+
item['name ']= result[i+1].key
|
|
1053
|
+
}
|
|
1054
|
+
if (result[i+2]) {
|
|
1055
|
+
item['type '] = result[i+2].type
|
|
1056
|
+
item['name ']= result[i+2].key
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
return temp
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1004
1062
|
module.exports = {
|
|
1005
1063
|
run,
|
|
1006
1064
|
reget,
|
|
@@ -1084,5 +1142,9 @@ module.exports = {
|
|
|
1084
1142
|
batchAsync,
|
|
1085
1143
|
ei,
|
|
1086
1144
|
msg,
|
|
1087
|
-
msgStr
|
|
1145
|
+
msgStr,
|
|
1146
|
+
errorMsg,
|
|
1147
|
+
tableStr,
|
|
1148
|
+
nableStr,
|
|
1149
|
+
objProfileRows
|
|
1088
1150
|
}
|