@modern-js/bff-core 2.35.1 → 2.37.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.
@@ -1,6 +1,6 @@
1
1
  import { HttpMethod } from "../types";
2
- export const AllHttpMethods = Object.values(HttpMethod);
3
- export var APIMode;
2
+ const AllHttpMethods = Object.values(HttpMethod);
3
+ var APIMode;
4
4
  (function(APIMode2) {
5
5
  APIMode2[
6
6
  /**
@@ -15,11 +15,11 @@ export var APIMode;
15
15
  "FUNCTION"
16
16
  ] = "function";
17
17
  })(APIMode || (APIMode = {}));
18
- export const FRAMEWORK_MODE_LAMBDA_DIR = "lambda";
19
- export const FRAMEWORK_MODE_APP_DIR = "app";
20
- export const INDEX_SUFFIX = "index";
21
- export const API_DIR = "api";
22
- export const API_FILE_RULES = [
18
+ const FRAMEWORK_MODE_LAMBDA_DIR = "lambda";
19
+ const FRAMEWORK_MODE_APP_DIR = "app";
20
+ const INDEX_SUFFIX = "index";
21
+ const API_DIR = "api";
22
+ const API_FILE_RULES = [
23
23
  "**/*.[tj]s",
24
24
  "!**/_*",
25
25
  "!**/_*/**/*.[tj]s",
@@ -31,3 +31,12 @@ export const API_FILE_RULES = [
31
31
  "!node_modules/**",
32
32
  "!bootstrap.jsx"
33
33
  ];
34
+ export {
35
+ APIMode,
36
+ API_DIR,
37
+ API_FILE_RULES,
38
+ AllHttpMethods,
39
+ FRAMEWORK_MODE_APP_DIR,
40
+ FRAMEWORK_MODE_LAMBDA_DIR,
41
+ INDEX_SUFFIX
42
+ };
@@ -8,7 +8,7 @@ import { APIMode, FRAMEWORK_MODE_LAMBDA_DIR, API_FILE_RULES, FRAMEWORK_MODE_APP_
8
8
  import { getFiles, getPathFromFilename, requireHandlerModule, sortRoutes } from "./utils";
9
9
  export * from "./types";
10
10
  export * from "./constants";
11
- export class ApiRouter {
11
+ class ApiRouter {
12
12
  enableRegister() {
13
13
  const existTsLoader = Boolean(require.extensions[".ts"]);
14
14
  if (!existTsLoader && (process.env.NODE_ENV !== "production" || this.isBuild)) {
@@ -282,3 +282,6 @@ export class ApiRouter {
282
282
  this.enableRegister();
283
283
  }
284
284
  }
285
+ export {
286
+ ApiRouter
287
+ };
@@ -1 +0,0 @@
1
- export {};
@@ -1,11 +1,11 @@
1
1
  import path from "path";
2
2
  import { globby } from "@modern-js/utils";
3
3
  import { INDEX_SUFFIX } from "./constants";
4
- export const getFiles = (lambdaDir, rules) => globby.sync(rules, {
4
+ const getFiles = (lambdaDir, rules) => globby.sync(rules, {
5
5
  cwd: lambdaDir,
6
6
  gitignore: true
7
7
  }).map((file) => path.resolve(lambdaDir, file));
8
- export const getPathFromFilename = (baseDir, filename) => {
8
+ const getPathFromFilename = (baseDir, filename) => {
9
9
  const relativeName = filename.substring(baseDir.length);
10
10
  const relativePath = relativeName.split(".").slice(0, -1).join(".");
11
11
  const nameSplit = relativePath.split(path.sep).map((item) => {
@@ -30,9 +30,9 @@ const clearRouteName = (routeName) => {
30
30
  }
31
31
  return finalRouteName;
32
32
  };
33
- export const isHandler = (input) => input && typeof input === "function";
33
+ const isHandler = (input) => input && typeof input === "function";
34
34
  const isFunction = (input) => input && {}.toString.call(input) === "[object Function]";
35
- export const requireHandlerModule = (modulePath) => {
35
+ const requireHandlerModule = (modulePath) => {
36
36
  const originRequire = process.env.NODE_ENV === "test" ? jest.requireActual : require;
37
37
  const module = originRequire(modulePath);
38
38
  if (isFunction(module)) {
@@ -48,8 +48,15 @@ const routeValue = (routePath) => {
48
48
  }
49
49
  return 1;
50
50
  };
51
- export const sortRoutes = (apiHandlers) => {
51
+ const sortRoutes = (apiHandlers) => {
52
52
  return apiHandlers.sort((handlerA, handlerB) => {
53
53
  return routeValue(handlerA.routeName) - routeValue(handlerB.routeName);
54
54
  });
55
55
  };
56
+ export {
57
+ getFiles,
58
+ getPathFromFilename,
59
+ isHandler,
60
+ requireHandlerModule,
61
+ sortRoutes
62
+ };
package/dist/esm/types.js CHANGED
@@ -1,13 +1,13 @@
1
- export var OperatorType;
1
+ var OperatorType;
2
2
  (function(OperatorType2) {
3
3
  OperatorType2[OperatorType2["Trigger"] = 0] = "Trigger";
4
4
  OperatorType2[OperatorType2["Middleware"] = 1] = "Middleware";
5
5
  })(OperatorType || (OperatorType = {}));
6
- export var TriggerType;
6
+ var TriggerType;
7
7
  (function(TriggerType2) {
8
8
  TriggerType2[TriggerType2["Http"] = 0] = "Http";
9
9
  })(TriggerType || (TriggerType = {}));
10
- export var HttpMetadata;
10
+ var HttpMetadata;
11
11
  (function(HttpMetadata2) {
12
12
  HttpMetadata2["Method"] = "METHOD";
13
13
  HttpMetadata2["Data"] = "DATA";
@@ -16,13 +16,13 @@ export var HttpMetadata;
16
16
  HttpMetadata2["Headers"] = "HEADERS";
17
17
  HttpMetadata2["Response"] = "RESPONSE";
18
18
  })(HttpMetadata || (HttpMetadata = {}));
19
- export var ResponseMetaType;
19
+ var ResponseMetaType;
20
20
  (function(ResponseMetaType2) {
21
21
  ResponseMetaType2[ResponseMetaType2["StatusCode"] = 0] = "StatusCode";
22
22
  ResponseMetaType2[ResponseMetaType2["Redirect"] = 1] = "Redirect";
23
23
  ResponseMetaType2[ResponseMetaType2["Headers"] = 2] = "Headers";
24
24
  })(ResponseMetaType || (ResponseMetaType = {}));
25
- export var HttpMethod;
25
+ var HttpMethod;
26
26
  (function(HttpMethod2) {
27
27
  HttpMethod2["Get"] = "GET";
28
28
  HttpMethod2["Post"] = "POST";
@@ -34,4 +34,12 @@ export var HttpMethod;
34
34
  HttpMethod2["Options"] = "OPTIONS";
35
35
  HttpMethod2["Head"] = "HEAD";
36
36
  })(HttpMethod || (HttpMethod = {}));
37
- export const httpMethods = Object.values(HttpMethod);
37
+ const httpMethods = Object.values(HttpMethod);
38
+ export {
39
+ HttpMetadata,
40
+ HttpMethod,
41
+ OperatorType,
42
+ ResponseMetaType,
43
+ TriggerType,
44
+ httpMethods
45
+ };
@@ -2,7 +2,7 @@ import * as path from "path";
2
2
  import * as os from "os";
3
3
  import fs from "fs";
4
4
  import Module from "module";
5
- export const getRelativeRuntimePath = (appDirectory, serverRuntimePath) => {
5
+ const getRelativeRuntimePath = (appDirectory, serverRuntimePath) => {
6
6
  let relativeRuntimePath = "";
7
7
  if (os.platform() === "win32") {
8
8
  relativeRuntimePath = `../${path.relative(appDirectory, serverRuntimePath)}`;
@@ -17,7 +17,7 @@ export const getRelativeRuntimePath = (appDirectory, serverRuntimePath) => {
17
17
  const sortByLongestPrefix = (arr) => {
18
18
  return arr.concat().sort((a, b) => b.length - a.length);
19
19
  };
20
- export const createMatchPath = (paths) => {
20
+ const createMatchPath = (paths) => {
21
21
  const sortedKeys = sortByLongestPrefix(Object.keys(paths));
22
22
  const sortedPaths = {};
23
23
  sortedKeys.forEach((key) => {
@@ -46,7 +46,7 @@ export const createMatchPath = (paths) => {
46
46
  return null;
47
47
  };
48
48
  };
49
- export const registerPaths = (paths) => {
49
+ const registerPaths = (paths) => {
50
50
  const originalResolveFilename = Module._resolveFilename;
51
51
  const { builtinModules } = Module;
52
52
  const matchPath = createMatchPath(paths);
@@ -68,3 +68,8 @@ export const registerPaths = (paths) => {
68
68
  Module._resolveFilename = originalResolveFilename;
69
69
  };
70
70
  };
71
+ export {
72
+ createMatchPath,
73
+ getRelativeRuntimePath,
74
+ registerPaths
75
+ };
@@ -1,2 +1,5 @@
1
1
  import { createDebugger } from "@modern-js/utils";
2
- export const debug = createDebugger("bff");
2
+ const debug = createDebugger("bff");
3
+ export {
4
+ debug
5
+ };
@@ -1,5 +1,8 @@
1
1
  export * from "./storage";
2
2
  export * from "./alias";
3
- export { debug } from "./debug";
3
+ import { debug } from "./debug";
4
4
  export * from "./meta";
5
5
  export * from "./validate";
6
+ export {
7
+ debug
8
+ };
@@ -1,8 +1,14 @@
1
- export const HANDLER_WITH_META = "HANDLER_WITH_META";
2
- export const INPUT_PARAMS_DECIDER = "INPUT_PARAMS_DECIDER";
3
- export const isWithMetaHandler = (handler) => {
1
+ const HANDLER_WITH_META = "HANDLER_WITH_META";
2
+ const INPUT_PARAMS_DECIDER = "INPUT_PARAMS_DECIDER";
3
+ const isWithMetaHandler = (handler) => {
4
4
  return typeof handler === "function" && handler[HANDLER_WITH_META];
5
5
  };
6
- export const isInputParamsDeciderHandler = (handler) => {
6
+ const isInputParamsDeciderHandler = (handler) => {
7
7
  return typeof handler === "function" && handler[INPUT_PARAMS_DECIDER];
8
8
  };
9
+ export {
10
+ HANDLER_WITH_META,
11
+ INPUT_PARAMS_DECIDER,
12
+ isInputParamsDeciderHandler,
13
+ isWithMetaHandler
14
+ };
@@ -35,4 +35,6 @@ const createStorage = () => {
35
35
  useContext
36
36
  };
37
37
  };
38
- export { createStorage };
38
+ export {
39
+ createStorage
40
+ };
@@ -1,5 +1,5 @@
1
1
  import util from "util";
2
- export const getTypeErrorMessage = (actual) => {
2
+ const getTypeErrorMessage = (actual) => {
3
3
  let msg = "";
4
4
  if (actual == null) {
5
5
  msg += `. Received ${actual}`;
@@ -26,15 +26,20 @@ export const getTypeErrorMessage = (actual) => {
26
26
  }
27
27
  return msg;
28
28
  };
29
- export class ERR_INVALID_ARG_TYPE extends Error {
29
+ class ERR_INVALID_ARG_TYPE extends Error {
30
30
  constructor(funcName, expectedType, actual) {
31
31
  const message = `[ERR_INVALID_ARG_TYPE]: The '${funcName}' argument must be of type ${expectedType}${getTypeErrorMessage(actual)}`;
32
32
  super(message);
33
33
  }
34
34
  }
35
- export const validateFunction = (maybeFunc, name) => {
35
+ const validateFunction = (maybeFunc, name) => {
36
36
  if (typeof maybeFunc !== "function") {
37
37
  throw new ERR_INVALID_ARG_TYPE(name, "function", maybeFunc);
38
38
  }
39
39
  return true;
40
40
  };
41
+ export {
42
+ ERR_INVALID_ARG_TYPE,
43
+ getTypeErrorMessage,
44
+ validateFunction
45
+ };
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.35.1",
18
+ "version": "2.37.0",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -31,7 +31,7 @@
31
31
  "koa-compose": "^4.1.0",
32
32
  "reflect-metadata": "^0.1.13",
33
33
  "@swc/helpers": "0.5.1",
34
- "@modern-js/utils": "2.35.1"
34
+ "@modern-js/utils": "2.37.0"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@types/jest": "^29",
@@ -42,13 +42,13 @@
42
42
  "tsconfig-paths": "^4.1.2",
43
43
  "type-fest": "2.15.0",
44
44
  "typescript": "^5",
45
- "zod": "^3.17.3",
46
- "@modern-js/types": "2.35.1",
47
- "@scripts/jest-config": "2.35.1",
48
- "@scripts/build": "2.35.1"
45
+ "zod": "^3.22.3",
46
+ "@modern-js/types": "2.37.0",
47
+ "@scripts/build": "2.37.0",
48
+ "@scripts/jest-config": "2.37.0"
49
49
  },
50
50
  "peerDependencies": {
51
- "zod": "^3.17.3",
51
+ "zod": "^3.22.3",
52
52
  "ts-node": "^10.9.1",
53
53
  "tsconfig-paths": "^4.1.2"
54
54
  },