jsir 3.0.1 → 3.0.3

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/oaa.js CHANGED
@@ -2364,17 +2364,23 @@ async function _requireSource(currSpace, cmdMatchStr, force = false) {
2364
2364
  } else {
2365
2365
  if (setting.serviceReg.test(uniqueName)) {
2366
2366
  let serviceKey = `${pair[0]}/${trimJsirFileName(pair[1])}`
2367
- if (setting.services[serviceKey]) {
2368
- let serviceObj = {};
2369
- for (let fn of setting.services[serviceKey]) {
2370
- serviceObj[fn] = async (...args) => {
2371
- return await Room.reqFn(`${serviceKey}/${fn}`, args);
2367
+ return new Proxy({}, {
2368
+ get(target, prop) {
2369
+ if (prop === 'then') {
2370
+ return undefined;
2371
+ }
2372
+ let fns = setting.services[serviceKey]
2373
+ if (!fns) {
2374
+ throw `invoke ${prop} failed cause service ${serviceKey} not found`;
2375
+ }
2376
+ if (!fns.includes(prop)) {
2377
+ throw `service function ${serviceKey}/${prop} not found`;
2378
+ }
2379
+ return async (...args) => {
2380
+ return await Room.reqFn(`${serviceKey}/${prop}`, args);
2372
2381
  }
2373
2382
  }
2374
- return serviceObj
2375
- } else {
2376
- throw `service ${serviceKey} not found`;
2377
- }
2383
+ })
2378
2384
  } else {
2379
2385
  result = await evalText(text, uniqueName)
2380
2386
  }
package/deps/room.js CHANGED
@@ -368,11 +368,11 @@ async function syncConfigs() {
368
368
  let currText = String(await fp.readFile(path));
369
369
  if (currText !== text) {
370
370
  await fp.writeFile(path, text)
371
- console.$debug(`sync ${key} success`);
371
+ console.$debug(`update config ${key} success`);
372
372
  }
373
373
  } else {
374
374
  await fp.writeFile(path, text)
375
- console.$debug(`sync ${key} success`);
375
+ console.$debug(`create config ${key} success`);
376
376
  }
377
377
  });
378
378
  }
@@ -535,10 +535,12 @@ async function reqNode(node, method, url, port, body) {
535
535
  });
536
536
 
537
537
  // 设置超时逻辑
538
- if (setting.reqNodeTimeouts[url]) {
538
+ let timeoutMs = setting.reqNodeTimeouts[url];
539
+ if (timeoutMs) {
539
540
  timeout = setTimeout(() => {
540
541
  req.destroy(); // 中断请求
541
- }, setting.reqNodeTimeouts[url]); // 10秒超时
542
+ reject(new Error(`Timeout ${timeoutMs}ms`))
543
+ }, timeoutMs); // 10秒超时
542
544
  }
543
545
 
544
546
  // 错误处理
@@ -580,7 +582,10 @@ function busyPick(busyItems) {
580
582
  }
581
583
 
582
584
  async function reqFn(fnKey, args = []) {
583
- let targets = setting.serviceFns[fnKey] || []
585
+ let targets = setting.serviceFns[fnKey]
586
+ if (!targets) {
587
+ throw `service function ${fnKey} instance not found`;
588
+ }
584
589
  targets = targets
585
590
  .filter(i => i.active)
586
591
  .filter(i => !isDisableConnect(i.node, i.port));
@@ -588,7 +593,7 @@ async function reqFn(fnKey, args = []) {
588
593
  if (targets.length > 0) {
589
594
  target = busyPick(targets);
590
595
  } else {
591
- throw `service function ${fnKey} not found`;
596
+ throw `service function ${fnKey} instance not enable`;
592
597
  }
593
598
  let resp = await reqNode(target.node, 'post',
594
599
  `/${fnKey}`, target.port, JSON.stringify(args || []))
package/deps/util.js CHANGED
@@ -6,7 +6,7 @@ const fs = require('fs')
6
6
  const fp = require('fs').promises
7
7
  const BigNumber = require('bignumber.js');
8
8
  const crypto = require('crypto');
9
- const dayJs = require('dayjs')
9
+ const dayjs = require('dayjs')
10
10
  const table = require('console.table')
11
11
  const initModulePaths = Object.assign([], module.paths)
12
12
  const path = require('path')
@@ -678,7 +678,7 @@ function getFileOpenExe() {
678
678
  }
679
679
 
680
680
  function timeStr(fmt, date) {
681
- return dayJs(date || new Date()).format(fmt || 'YYYY-MM-DD HH:mm:ss')
681
+ return dayjs(date || new Date()).format(fmt || 'YYYY-MM-DD HH:mm:ss')
682
682
  }
683
683
 
684
684
  function vl(obj) {
@@ -844,7 +844,8 @@ function createLimitLogger(fileName, {
844
844
  setting.newError = true;
845
845
  }
846
846
  if (time) {
847
- text = `${timeStr('YYYY-MM-DD HH:mm:ss.SSS')} ${String(process.pid%1000).padStart(3, '0')}> ${text}`
847
+ let prefix = debugStr(`${timeStr('YYYY-MM-DD HH:mm:ss.SSS')} ${String(process.pid%1000).padStart(3, '0')}>`)
848
+ text = `${prefix} ${text}`
848
849
  }
849
850
  fp.appendFile(logPath, text + '\n')
850
851
  let _minNum = (Date.now()/(1000 * 60 * 10)).toFixed(0)
@@ -2279,7 +2280,7 @@ module.exports = {
2279
2280
  removeFirst,
2280
2281
  sleep,
2281
2282
  timeLimit,
2282
- dayJs,
2283
+ dayjs,
2283
2284
  setCbText,
2284
2285
  randomInt,
2285
2286
  vl,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsir",
3
- "version": "3.0.1",
3
+ "version": "3.0.3",
4
4
  "description": "JavaScript Script Management Tool",
5
5
  "main": "index.js",
6
6
  "scripts": {