@modern-js/bff-core 1.21.6 → 1.21.7-beta.0

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,24 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.registerPaths = exports.getRelativeRuntimePath = exports.createMatchPath = void 0;
7
-
8
7
  var path = _interopRequireWildcard(require("path"));
9
-
10
8
  var os = _interopRequireWildcard(require("os"));
11
-
12
9
  var _fs = _interopRequireDefault(require("fs"));
13
-
14
10
  var _module = _interopRequireDefault(require("module"));
15
-
16
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
12
  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); }
19
-
20
13
  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; }
21
-
22
14
  const getRelativeRuntimePath = (appDirectory, serverRuntimePath) => {
23
15
  let relativeRuntimePath = '';
24
-
25
16
  if (os.platform() === 'win32') {
26
17
  // isRelative function in babel-plugin-resolver plugin can't handle windows relative path correctly, see babel-plugin-resolver's utils.
27
18
  relativeRuntimePath = `../${path.relative(appDirectory, serverRuntimePath)}`;
@@ -29,20 +20,15 @@ const getRelativeRuntimePath = (appDirectory, serverRuntimePath) => {
29
20
  // Look up one level, because the artifacts after build have dist directories
30
21
  relativeRuntimePath = path.join('../', path.relative(appDirectory, serverRuntimePath));
31
22
  }
32
-
33
23
  if (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test') {
34
24
  relativeRuntimePath = `./${path.relative(appDirectory, serverRuntimePath)}`;
35
25
  }
36
-
37
26
  return relativeRuntimePath;
38
27
  };
39
-
40
28
  exports.getRelativeRuntimePath = getRelativeRuntimePath;
41
-
42
29
  const sortByLongestPrefix = arr => {
43
30
  return arr.concat().sort((a, b) => b.length - a.length);
44
31
  };
45
-
46
32
  const createMatchPath = paths => {
47
33
  const sortedKeys = sortByLongestPrefix(Object.keys(paths));
48
34
  const sortedPaths = {};
@@ -53,63 +39,48 @@ const createMatchPath = paths => {
53
39
  const found = Object.keys(sortedPaths).find(key => {
54
40
  return request.startsWith(key);
55
41
  });
56
-
57
42
  if (found) {
58
43
  let foundPaths = sortedPaths[found];
59
-
60
44
  if (!Array.isArray(foundPaths)) {
61
45
  foundPaths = [foundPaths];
62
46
  }
63
-
64
47
  foundPaths = foundPaths.filter(foundPath => path.isAbsolute(foundPath));
65
-
66
48
  for (const p of foundPaths) {
67
49
  const foundPath = request.replace(found, p);
68
-
69
50
  if (_fs.default.existsSync(foundPath)) {
70
51
  return foundPath;
71
52
  }
72
53
  }
73
-
74
54
  return request.replace(found, foundPaths[0]);
75
55
  }
76
-
77
56
  return null;
78
57
  };
79
- }; // every path must be a absolute path;
80
-
58
+ };
81
59
 
60
+ // every path must be a absolute path;
82
61
  exports.createMatchPath = createMatchPath;
83
-
84
62
  const registerPaths = paths => {
85
- const originalResolveFilename = _module.default._resolveFilename; // eslint-disable-next-line node/no-unsupported-features/node-builtins
86
-
63
+ const originalResolveFilename = _module.default._resolveFilename;
64
+ // eslint-disable-next-line node/no-unsupported-features/node-builtins
87
65
  const {
88
66
  builtinModules
89
67
  } = _module.default;
90
68
  const matchPath = createMatchPath(paths);
91
-
92
69
  _module.default._resolveFilename = function (request, _parent) {
93
70
  const isCoreModule = builtinModules.includes(request);
94
-
95
71
  if (!isCoreModule) {
96
72
  const matched = matchPath(request);
97
-
98
73
  if (matched) {
99
74
  // eslint-disable-next-line prefer-rest-params
100
75
  const modifiedArguments = [matched, ...[].slice.call(arguments, 1)]; // Passes all arguments. Even those that is not specified above.
101
-
102
76
  return originalResolveFilename.apply(this, modifiedArguments);
103
77
  }
104
- } // eslint-disable-next-line prefer-rest-params
105
-
106
-
78
+ }
79
+ // eslint-disable-next-line prefer-rest-params
107
80
  return originalResolveFilename.apply(this, arguments);
108
81
  };
109
-
110
82
  return () => {
111
83
  _module.default._resolveFilename = originalResolveFilename;
112
84
  };
113
85
  };
114
-
115
86
  exports.registerPaths = registerPaths;
@@ -4,8 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.debug = void 0;
7
-
8
7
  var _utils = require("@modern-js/utils");
9
-
10
8
  const debug = (0, _utils.createDebugger)('bff');
11
9
  exports.debug = debug;
@@ -12,9 +12,7 @@ Object.defineProperty(exports, "debug", {
12
12
  return _debug.debug;
13
13
  }
14
14
  });
15
-
16
15
  var _storage = require("./storage");
17
-
18
16
  Object.keys(_storage).forEach(function (key) {
19
17
  if (key === "default" || key === "__esModule") return;
20
18
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
@@ -26,9 +24,7 @@ Object.keys(_storage).forEach(function (key) {
26
24
  }
27
25
  });
28
26
  });
29
-
30
27
  var _alias = require("./alias");
31
-
32
28
  Object.keys(_alias).forEach(function (key) {
33
29
  if (key === "default" || key === "__esModule") return;
34
30
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
@@ -40,11 +36,8 @@ Object.keys(_alias).forEach(function (key) {
40
36
  }
41
37
  });
42
38
  });
43
-
44
39
  var _debug = require("./debug");
45
-
46
40
  var _meta = require("./meta");
47
-
48
41
  Object.keys(_meta).forEach(function (key) {
49
42
  if (key === "default" || key === "__esModule") return;
50
43
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
@@ -56,9 +49,7 @@ Object.keys(_meta).forEach(function (key) {
56
49
  }
57
50
  });
58
51
  });
59
-
60
52
  var _validate = require("./validate");
61
-
62
53
  Object.keys(_validate).forEach(function (key) {
63
54
  if (key === "default" || key === "__esModule") return;
64
55
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
@@ -6,9 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.isWithMetaHandler = exports.HANDLER_WITH_META = void 0;
7
7
  const HANDLER_WITH_META = 'HANDLER_WITH_META';
8
8
  exports.HANDLER_WITH_META = HANDLER_WITH_META;
9
-
10
9
  const isWithMetaHandler = handler => {
11
10
  return typeof handler === 'function' && handler[HANDLER_WITH_META];
12
11
  };
13
-
14
12
  exports.isWithMetaHandler = isWithMetaHandler;
@@ -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": "1.21.6",
14
+ "version": "1.21.7-beta.0",
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
- "esbuild": "^0.14.38",
29
+ "@modern-js/bff-runtime": "2.0.0-beta.2",
30
+ "@modern-js/utils": "2.0.0-beta.2",
31
+ "esbuild": "0.15.7",
30
32
  "esbuild-register": "^3.3.3",
31
33
  "koa-compose": "^4.1.0",
32
- "reflect-metadata": "^0.1.13",
33
- "@modern-js/bff-runtime": "1.21.6",
34
- "@modern-js/utils": "1.21.6"
34
+ "reflect-metadata": "^0.1.13"
35
35
  },
36
36
  "devDependencies": {
37
+ "@scripts/build": "2.0.0-beta.2",
38
+ "@scripts/jest-config": "2.0.0-beta.2",
37
39
  "@types/jest": "^27",
38
40
  "@types/koa-compose": "^3.2.5",
39
41
  "@types/node": "^14",
40
42
  "jest": "^27",
41
- "type-fest": "^2.13.0",
43
+ "type-fest": "2.15.0",
42
44
  "typescript": "^4",
43
- "zod": "^3.17.3",
44
- "@scripts/build": "1.21.6",
45
- "@scripts/jest-config": "1.21.6"
45
+ "zod": "^3.17.3"
46
46
  },
47
47
  "peerDependencies": {
48
48
  "zod": "^3.17.3"
@@ -61,32 +61,9 @@
61
61
  "registry": "https://registry.npmjs.org/",
62
62
  "access": "public"
63
63
  },
64
- "wireit": {
65
- "build": {
66
- "command": "modern build",
67
- "files": [
68
- "src/**/*",
69
- "tsconfig.json",
70
- "package.json"
71
- ],
72
- "output": [
73
- "dist/**/*"
74
- ]
75
- },
76
- "test": {
77
- "command": "jest --passWithNoTests",
78
- "files": [
79
- "src/**/*",
80
- "tsconfig.json",
81
- "package.json",
82
- "tests/**/*"
83
- ],
84
- "output": []
85
- }
86
- },
87
64
  "scripts": {
88
- "new": "modern new",
89
- "build": "wireit",
90
- "test": "wireit"
65
+ "new": "modern-lib new",
66
+ "build": "modern-lib build",
67
+ "test": "jest --passWithNoTests"
91
68
  }
92
69
  }