jsir 3.0.2 → 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
@@ -582,7 +582,10 @@ function busyPick(busyItems) {
582
582
  }
583
583
 
584
584
  async function reqFn(fnKey, args = []) {
585
- let targets = setting.serviceFns[fnKey] || []
585
+ let targets = setting.serviceFns[fnKey]
586
+ if (!targets) {
587
+ throw `service function ${fnKey} instance not found`;
588
+ }
586
589
  targets = targets
587
590
  .filter(i => i.active)
588
591
  .filter(i => !isDisableConnect(i.node, i.port));
@@ -590,7 +593,7 @@ async function reqFn(fnKey, args = []) {
590
593
  if (targets.length > 0) {
591
594
  target = busyPick(targets);
592
595
  } else {
593
- throw `service function ${fnKey} not found`;
596
+ throw `service function ${fnKey} instance not enable`;
594
597
  }
595
598
  let resp = await reqNode(target.node, 'post',
596
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) {
@@ -2280,7 +2280,7 @@ module.exports = {
2280
2280
  removeFirst,
2281
2281
  sleep,
2282
2282
  timeLimit,
2283
- dayJs,
2283
+ dayjs,
2284
2284
  setCbText,
2285
2285
  randomInt,
2286
2286
  vl,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsir",
3
- "version": "3.0.2",
3
+ "version": "3.0.3",
4
4
  "description": "JavaScript Script Management Tool",
5
5
  "main": "index.js",
6
6
  "scripts": {