@modern-js/bff-core 2.0.0-beta.0 → 2.0.0-beta.1

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.
@@ -4,26 +4,19 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.createStorage = void 0;
7
-
8
7
  var ah = _interopRequireWildcard(require("async_hooks"));
9
-
10
8
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
11
-
12
9
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
13
-
14
10
  const createStorage = () => {
15
11
  let storage;
16
-
17
12
  if (typeof ah.AsyncLocalStorage !== 'undefined') {
18
13
  storage = new ah.AsyncLocalStorage();
19
14
  }
20
-
21
15
  const run = (context, cb) => {
22
16
  if (!storage) {
23
17
  throw new Error(`Unable to use async_hook, please confirm the node version >= 12.17
24
18
  `);
25
19
  }
26
-
27
20
  return new Promise((resolve, reject) => {
28
21
  storage.run(context, () => {
29
22
  try {
@@ -34,26 +27,20 @@ const createStorage = () => {
34
27
  });
35
28
  });
36
29
  };
37
-
38
30
  const useContext = () => {
39
31
  if (!storage) {
40
32
  throw new Error(`Unable to use async_hook, please confirm the node version >= 12.17
41
33
  `);
42
34
  }
43
-
44
35
  const context = storage.getStore();
45
-
46
36
  if (!context) {
47
37
  throw new Error(`Can't call useContext out of scope, it should be placed in the bff function`);
48
38
  }
49
-
50
39
  return context;
51
40
  };
52
-
53
41
  return {
54
42
  run,
55
43
  useContext
56
44
  };
57
45
  };
58
-
59
46
  exports.createStorage = createStorage;
@@ -4,65 +4,50 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.validateFunction = exports.getTypeErrorMessage = exports.ERR_INVALID_ARG_TYPE = void 0;
7
-
8
7
  var _util = _interopRequireDefault(require("util"));
9
-
10
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
9
  // fork from https://github.com/nodejs/node/blob/master/lib/internal/errors.js
13
10
  const getTypeErrorMessage = actual => {
14
11
  let msg = '';
15
-
16
12
  if (actual == null) {
17
13
  msg += `. Received ${actual}`;
18
14
  } else if (typeof actual === 'function' && actual.name) {
19
15
  msg += `. Received function ${actual.name}`;
20
16
  } else if (typeof actual === 'object') {
21
17
  var _actual$constructor;
22
-
23
18
  if ((_actual$constructor = actual.constructor) !== null && _actual$constructor !== void 0 && _actual$constructor.name) {
24
19
  msg += `. Received an instance of ${actual.constructor.name}`;
25
20
  } else {
26
21
  const inspected = _util.default.inspect(actual, {
27
22
  depth: -1
28
23
  });
29
-
30
24
  msg += `. Received ${inspected}`;
31
25
  }
32
26
  } else {
33
27
  let inspected = _util.default.inspect(actual, {
34
28
  colors: false
35
29
  });
36
-
37
30
  if (inspected.length > 25) {
38
31
  inspected = `${inspected.slice(0, 25)}...`;
39
32
  }
40
-
41
33
  msg += `. Received type ${typeof actual} (${inspected})`;
42
34
  }
43
-
44
35
  return msg;
45
- }; // eslint-disable-next-line @typescript-eslint/naming-convention
46
-
36
+ };
47
37
 
38
+ // eslint-disable-next-line @typescript-eslint/naming-convention
48
39
  exports.getTypeErrorMessage = getTypeErrorMessage;
49
-
50
40
  class ERR_INVALID_ARG_TYPE extends Error {
51
41
  constructor(funcName, expectedType, actual) {
52
42
  const message = `[ERR_INVALID_ARG_TYPE]: The '${funcName}' argument must be of type ${expectedType}${getTypeErrorMessage(actual)}`;
53
43
  super(message);
54
44
  }
55
-
56
45
  }
57
-
58
46
  exports.ERR_INVALID_ARG_TYPE = ERR_INVALID_ARG_TYPE;
59
-
60
47
  const validateFunction = (maybeFunc, name) => {
61
48
  if (typeof maybeFunc !== 'function') {
62
49
  throw new ERR_INVALID_ARG_TYPE(name, 'function', maybeFunc);
63
50
  }
64
-
65
51
  return true;
66
52
  };
67
-
68
53
  exports.validateFunction = validateFunction;
@@ -4,7 +4,6 @@ export declare enum APIMode {
4
4
  * 框架模式
5
5
  */
6
6
  FARMEWORK = "framework",
7
-
8
7
  /**
9
8
  * 函数模式
10
9
  */
@@ -36,7 +36,6 @@ export declare class ApiRouter {
36
36
  * 如果用户未传入或传入空串,默认为 /api
37
37
  * 如果传入 /,则 prefix 为 /
38
38
  */
39
-
40
39
  private initPrefix;
41
40
  private validateAbsolute;
42
41
  private getExactApiMode;
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "2.0.0-beta.0",
14
+ "version": "2.0.0-beta.1",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -26,23 +26,23 @@
26
26
  },
27
27
  "dependencies": {
28
28
  "@babel/runtime": "^7.18.0",
29
- "@modern-js/bff-runtime": "2.0.0-beta.0",
30
- "@modern-js/utils": "2.0.0-beta.0",
31
29
  "esbuild": "0.15.7",
32
30
  "esbuild-register": "^3.3.3",
33
31
  "koa-compose": "^4.1.0",
34
- "reflect-metadata": "^0.1.13"
32
+ "reflect-metadata": "^0.1.13",
33
+ "@modern-js/bff-runtime": "2.0.0-beta.1",
34
+ "@modern-js/utils": "2.0.0-beta.1"
35
35
  },
36
36
  "devDependencies": {
37
- "@scripts/build": "2.0.0-beta.0",
38
- "@scripts/jest-config": "2.0.0-beta.0",
39
37
  "@types/jest": "^27",
40
38
  "@types/koa-compose": "^3.2.5",
41
39
  "@types/node": "^14",
42
40
  "jest": "^27",
43
41
  "type-fest": "2.15.0",
44
42
  "typescript": "^4",
45
- "zod": "^3.17.3"
43
+ "zod": "^3.17.3",
44
+ "@scripts/build": "2.0.0-beta.1",
45
+ "@scripts/jest-config": "2.0.0-beta.1"
46
46
  },
47
47
  "peerDependencies": {
48
48
  "zod": "^3.17.3"