@modern-js/bff-core 2.0.0-beta.2 → 2.0.0-beta.4

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.
Files changed (40) hide show
  1. package/CHANGELOG.md +72 -0
  2. package/dist/js/modern/api.js +49 -25
  3. package/dist/js/modern/client/generate-client.js +51 -24
  4. package/dist/js/modern/client/index.js +1 -1
  5. package/dist/js/modern/client/result.js +9 -8
  6. package/dist/js/modern/errors/http.js +8 -7
  7. package/dist/js/modern/index.js +19 -3
  8. package/dist/js/modern/operators/http.js +139 -87
  9. package/dist/js/modern/router/constants.js +31 -11
  10. package/dist/js/modern/router/index.js +66 -69
  11. package/dist/js/modern/router/types.js +0 -1
  12. package/dist/js/modern/router/utils.js +36 -37
  13. package/dist/js/modern/types.js +45 -37
  14. package/dist/js/modern/utils/alias.js +32 -30
  15. package/dist/js/modern/utils/debug.js +5 -2
  16. package/dist/js/modern/utils/index.js +5 -2
  17. package/dist/js/modern/utils/meta.js +8 -4
  18. package/dist/js/modern/utils/storage.js +8 -4
  19. package/dist/js/modern/utils/validate.js +22 -23
  20. package/dist/js/node/api.js +74 -32
  21. package/dist/js/node/client/generate-client.js +79 -37
  22. package/dist/js/node/client/index.js +17 -16
  23. package/dist/js/node/client/result.js +26 -14
  24. package/dist/js/node/errors/http.js +23 -11
  25. package/dist/js/node/index.js +35 -112
  26. package/dist/js/node/operators/http.js +166 -124
  27. package/dist/js/node/router/constants.js +50 -24
  28. package/dist/js/node/router/index.js +108 -127
  29. package/dist/js/node/router/types.js +0 -5
  30. package/dist/js/node/router/utils.js +63 -51
  31. package/dist/js/node/types.js +62 -47
  32. package/dist/js/node/utils/alias.js +57 -42
  33. package/dist/js/node/utils/debug.js +23 -8
  34. package/dist/js/node/utils/index.js +25 -60
  35. package/dist/js/node/utils/meta.js +25 -10
  36. package/dist/js/node/utils/storage.js +32 -11
  37. package/dist/js/node/utils/validate.js +43 -28
  38. package/dist/types/router/constants.d.ts +1 -0
  39. package/dist/types/router/index.d.ts +1 -0
  40. package/package.json +5 -10
@@ -1,12 +1,32 @@
1
1
  import { HttpMethod } from "../types";
2
- export const AllHttpMethods = Object.values(HttpMethod);
3
- export let APIMode;
4
- (function (APIMode) {
5
- APIMode["FARMEWORK"] = "framework";
6
- APIMode["FUNCTION"] = "function";
7
- })(APIMode || (APIMode = {}));
8
- export const FRAMEWORK_MODE_LAMBDA_DIR = 'lambda';
9
- export const FRAMEWORK_MODE_APP_DIR = 'app';
10
- export const INDEX_SUFFIX = 'index';
11
- export const API_DIR = 'api';
12
- export const API_FILE_RULES = ['**/*.[tj]s', '!**/_*', '!**/_*/**/*.[tj]s', '!**/*.test.js', '!**/*.test.ts', '!**/*.d.ts', '!__test__/*.ts', '!__tests__/*.ts', '!node_modules/**', '!bootstrap.js'];
2
+ const AllHttpMethods = Object.values(HttpMethod);
3
+ var APIMode = /* @__PURE__ */ ((APIMode2) => {
4
+ APIMode2["FARMEWORK"] = "framework";
5
+ APIMode2["FUNCTION"] = "function";
6
+ return APIMode2;
7
+ })(APIMode || {});
8
+ const FRAMEWORK_MODE_LAMBDA_DIR = "lambda";
9
+ const FRAMEWORK_MODE_APP_DIR = "app";
10
+ const INDEX_SUFFIX = "index";
11
+ const API_DIR = "api";
12
+ const API_FILE_RULES = [
13
+ "**/*.[tj]s",
14
+ "!**/_*",
15
+ "!**/_*/**/*.[tj]s",
16
+ "!**/*.test.js",
17
+ "!**/*.test.ts",
18
+ "!**/*.d.ts",
19
+ "!__test__/*.ts",
20
+ "!__tests__/*.ts",
21
+ "!node_modules/**",
22
+ "!bootstrap.js"
23
+ ];
24
+ export {
25
+ APIMode,
26
+ API_DIR,
27
+ API_FILE_RULES,
28
+ AllHttpMethods,
29
+ FRAMEWORK_MODE_APP_DIR,
30
+ FRAMEWORK_MODE_LAMBDA_DIR,
31
+ INDEX_SUFFIX
32
+ };
@@ -1,51 +1,53 @@
1
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
- import path from 'path';
3
- import { fs, logger } from '@modern-js/utils';
4
- import 'reflect-metadata';
1
+ import path from "path";
2
+ import { fs, logger } from "@modern-js/utils";
3
+ import "reflect-metadata";
5
4
  import { HttpMethod, httpMethods, OperatorType, TriggerType } from "../types";
6
5
  import { debug } from "../utils";
7
- import { APIMode, FRAMEWORK_MODE_LAMBDA_DIR, API_FILE_RULES, FRAMEWORK_MODE_APP_DIR } from "./constants";
8
- import { getFiles, getPathFromFilename, requireHandlerModule, sortRoutes } from "./utils";
6
+ import {
7
+ APIMode,
8
+ FRAMEWORK_MODE_LAMBDA_DIR,
9
+ API_FILE_RULES,
10
+ FRAMEWORK_MODE_APP_DIR
11
+ } from "./constants";
12
+ import {
13
+ getFiles,
14
+ getPathFromFilename,
15
+ requireHandlerModule,
16
+ sortRoutes
17
+ } from "./utils";
9
18
  export * from "./types";
10
19
  export * from "./constants";
11
- export class ApiRouter {
12
- // lambdaDir is the dir which equal to the apiDir in function mode, and equal to the api/lambda dir in framework mode
13
-
20
+ class ApiRouter {
14
21
  constructor({
15
- apiDir: _apiDir,
16
- lambdaDir: _lambdaDir,
22
+ apiDir,
23
+ lambdaDir,
17
24
  prefix
18
25
  }) {
19
- _defineProperty(this, "apiMode", void 0);
20
- _defineProperty(this, "apiDir", void 0);
21
- _defineProperty(this, "existLambdaDir", void 0);
22
- _defineProperty(this, "lambdaDir", void 0);
23
- _defineProperty(this, "prefix", void 0);
24
- _defineProperty(this, "apiFiles", []);
25
- _defineProperty(this, "getExactApiMode", apiDir => {
26
+ this.apiFiles = [];
27
+ this.getExactApiMode = (apiDir) => {
26
28
  const exist = this.createExistChecker(apiDir);
27
29
  const existLambdaDir = exist(FRAMEWORK_MODE_LAMBDA_DIR);
28
30
  const existAppDir = exist(FRAMEWORK_MODE_APP_DIR);
29
- const existAppFile = exist('app.ts') || exist('app.js');
31
+ const existAppFile = exist("app.ts") || exist("app.js");
30
32
  if (existLambdaDir || existAppDir || existAppFile) {
31
33
  return APIMode.FARMEWORK;
32
34
  }
33
35
  return APIMode.FUNCTION;
34
- });
35
- _defineProperty(this, "createExistChecker", base => target => fs.pathExistsSync(path.resolve(base, target)));
36
- _defineProperty(this, "getExactLambdaDir", apiDir => {
36
+ };
37
+ this.createExistChecker = (base) => (target) => fs.pathExistsSync(path.resolve(base, target));
38
+ this.getExactLambdaDir = (apiDir) => {
37
39
  if (this.lambdaDir) {
38
40
  return this.lambdaDir;
39
41
  }
40
42
  const lambdaDir = this.apiMode === APIMode.FARMEWORK ? path.join(apiDir, FRAMEWORK_MODE_LAMBDA_DIR) : apiDir;
41
43
  return lambdaDir;
42
- });
43
- this.validateAbsolute(_apiDir, 'apiDir');
44
- this.validateAbsolute(_lambdaDir, 'lambdaDir');
44
+ };
45
+ this.validateAbsolute(apiDir, "apiDir");
46
+ this.validateAbsolute(lambdaDir, "lambdaDir");
45
47
  this.prefix = this.initPrefix(prefix);
46
- this.apiDir = _apiDir;
47
- this.apiMode = this.getExactApiMode(_apiDir);
48
- this.lambdaDir = _lambdaDir || this.getExactLambdaDir(this.apiDir);
48
+ this.apiDir = apiDir;
49
+ this.apiMode = this.getExactApiMode(apiDir);
50
+ this.lambdaDir = lambdaDir || this.getExactLambdaDir(this.apiDir);
49
51
  this.existLambdaDir = fs.existsSync(this.lambdaDir);
50
52
  }
51
53
  isExistLambda() {
@@ -88,8 +90,6 @@ export class ApiRouter {
88
90
  }
89
91
  return null;
90
92
  }
91
-
92
- // TODO: 性能提升,开发环境,判断下 lambda 目录修改时间
93
93
  getSafeRoutePath(filename, handler) {
94
94
  this.loadApiFiles();
95
95
  this.validateValidApifile(filename);
@@ -100,7 +100,9 @@ export class ApiRouter {
100
100
  const trigger = Reflect.getMetadata(OperatorType.Trigger, handler);
101
101
  if (trigger && trigger.type === TriggerType.Http) {
102
102
  if (!trigger.path) {
103
- throw new Error(`The http trigger ${trigger.name} needs to specify a path`);
103
+ throw new Error(
104
+ `The http trigger ${trigger.name} needs to specify a path`
105
+ );
104
106
  }
105
107
  return trigger.path;
106
108
  }
@@ -117,29 +119,30 @@ export class ApiRouter {
117
119
  }
118
120
  const upperName = originHandlerName.toUpperCase();
119
121
  switch (upperName) {
120
- case 'GET':
122
+ case "GET":
121
123
  return HttpMethod.Get;
122
- case 'POST':
124
+ case "POST":
123
125
  return HttpMethod.Post;
124
- case 'PUT':
126
+ case "PUT":
125
127
  return HttpMethod.Put;
126
- case 'DELETE':
127
- case 'DEL':
128
+ case "DELETE":
129
+ case "DEL":
128
130
  return HttpMethod.Delete;
129
- case 'CONNECT':
131
+ case "CONNECT":
130
132
  return HttpMethod.Connect;
131
- case 'TRACE':
133
+ case "TRACE":
132
134
  return HttpMethod.Trace;
133
- case 'PATCH':
135
+ case "PATCH":
134
136
  return HttpMethod.Patch;
135
- case 'OPTION':
137
+ case "OPTION":
136
138
  return HttpMethod.Option;
137
- case 'DEFAULT':
138
- {
139
- return HttpMethod.Get;
140
- }
139
+ case "DEFAULT": {
140
+ return HttpMethod.Get;
141
+ }
141
142
  default:
142
- logger.warn(`Only api handlers are allowd to be exported, please remove the function ${originHandlerName} from exports`);
143
+ logger.warn(
144
+ `Only api handlers are allowd to be exported, please remove the function ${originHandlerName} from exports`
145
+ );
143
146
  return null;
144
147
  }
145
148
  }
@@ -147,7 +150,6 @@ export class ApiRouter {
147
150
  if (!this.existLambdaDir) {
148
151
  return [];
149
152
  }
150
- // eslint-disable-next-line no-multi-assign
151
153
  const apiFiles = this.apiFiles = getFiles(this.lambdaDir, API_FILE_RULES);
152
154
  return apiFiles;
153
155
  }
@@ -164,27 +166,22 @@ export class ApiRouter {
164
166
  const filenames = this.getApiFiles();
165
167
  const moduleInfos = this.getModuleInfos(filenames);
166
168
  const apiHandlers = this.getHandlerInfos(moduleInfos);
167
- debug('apiHandlers', apiHandlers.length, apiHandlers);
169
+ debug("apiHandlers", apiHandlers.length, apiHandlers);
168
170
  return apiHandlers;
169
171
  }
170
-
171
- /**
172
- * 如果用户未传入或传入空串,默认为 /api
173
- * 如果传入 /,则 prefix 为 /
174
- */
175
172
  initPrefix(prefix) {
176
- if (prefix === '/') {
177
- return '';
173
+ if (prefix === "/") {
174
+ return "";
178
175
  }
179
- return prefix || '/api';
176
+ return prefix || "/api";
180
177
  }
181
178
  validateAbsolute(filename, paramsName) {
182
- if (typeof filename === 'string' && !path.isAbsolute(filename)) {
179
+ if (typeof filename === "string" && !path.isAbsolute(filename)) {
183
180
  throw new Error(`The ${paramsName} ${filename} is not a abolute path`);
184
181
  }
185
182
  }
186
183
  getModuleInfos(filenames) {
187
- return filenames.map(filename => this.getModuleInfo(filename)).filter(moduleInfo => Boolean(moduleInfo));
184
+ return filenames.map((filename) => this.getModuleInfo(filename)).filter((moduleInfo) => Boolean(moduleInfo));
188
185
  }
189
186
  getModuleInfo(filename) {
190
187
  try {
@@ -194,7 +191,7 @@ export class ApiRouter {
194
191
  module
195
192
  };
196
193
  } catch (err) {
197
- if (process.env.NODE_ENV === 'production') {
194
+ if (process.env.NODE_ENV === "production") {
198
195
  throw err;
199
196
  } else {
200
197
  console.error(err);
@@ -204,7 +201,7 @@ export class ApiRouter {
204
201
  }
205
202
  getHandlerInfos(moduleInfos) {
206
203
  let apiHandlers = [];
207
- moduleInfos.forEach(moduleInfo => {
204
+ moduleInfos.forEach((moduleInfo) => {
208
205
  const handlerInfos = this.getModuleHandlerInfos(moduleInfo);
209
206
  if (handlerInfos) {
210
207
  apiHandlers = apiHandlers.concat(handlerInfos);
@@ -214,15 +211,12 @@ export class ApiRouter {
214
211
  return sortedHandlers;
215
212
  }
216
213
  getModuleHandlerInfos(moduleInfo) {
217
- const {
218
- module,
219
- filename
220
- } = moduleInfo;
221
- return Object.entries(module).filter(([, handler]) => typeof handler === 'function').map(([key]) => {
214
+ const { module, filename } = moduleInfo;
215
+ return Object.entries(module).filter(([, handler]) => typeof handler === "function").map(([key]) => {
222
216
  const handler = module[key];
223
217
  const handlerInfo = this.getHandlerInfo(filename, key, handler);
224
218
  return handlerInfo;
225
- }).filter(handlerInfo => Boolean(handlerInfo));
219
+ }).filter((handlerInfo) => Boolean(handlerInfo));
226
220
  }
227
221
  validateValidApifile(filename) {
228
222
  if (!this.apiFiles.includes(filename)) {
@@ -230,10 +224,13 @@ export class ApiRouter {
230
224
  }
231
225
  }
232
226
  getRoutePath(prefix, routeName) {
233
- const finalRouteName = routeName === '/' ? '' : routeName;
234
- if (prefix === '' && finalRouteName === '') {
235
- return '/';
227
+ const finalRouteName = routeName === "/" ? "" : routeName;
228
+ if (prefix === "" && finalRouteName === "") {
229
+ return "/";
236
230
  }
237
231
  return `${prefix}${finalRouteName}`;
238
232
  }
239
- }
233
+ }
234
+ export {
235
+ ApiRouter
236
+ };
@@ -1 +0,0 @@
1
- export {};
@@ -1,84 +1,83 @@
1
- import path from 'path';
2
- import { globby } from '@modern-js/utils';
1
+ import path from "path";
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
- }).map(file => path.resolve(lambdaDir, file));
8
- export const getPathFromFilename = (baseDir, filename) => {
7
+ }).map((file) => path.resolve(lambdaDir, file));
8
+ const getPathFromFilename = (baseDir, filename) => {
9
9
  const relativeName = filename.substring(baseDir.length);
10
- const relativePath = relativeName.split('.').slice(0, -1).join('.');
11
- const nameSplit = relativePath.split(path.sep).map(item => {
10
+ const relativePath = relativeName.split(".").slice(0, -1).join(".");
11
+ const nameSplit = relativePath.split(path.sep).map((item) => {
12
12
  if (item.length > 2) {
13
- if (item.startsWith('[') && item.endsWith(']')) {
13
+ if (item.startsWith("[") && item.endsWith("]")) {
14
14
  return `:${item.substring(1, item.length - 1)}`;
15
15
  }
16
16
  }
17
17
  return item;
18
18
  });
19
- const name = nameSplit.join('/');
19
+ const name = nameSplit.join("/");
20
20
  const finalName = name.endsWith(INDEX_SUFFIX) ? name.substring(0, name.length - INDEX_SUFFIX.length) : name;
21
21
  return clearRouteName(finalName);
22
22
  };
23
- const clearRouteName = routeName => {
23
+ const clearRouteName = (routeName) => {
24
24
  let finalRouteName = routeName.trim();
25
- if (!finalRouteName.startsWith('/')) {
25
+ if (!finalRouteName.startsWith("/")) {
26
26
  finalRouteName = `/${finalRouteName}`;
27
27
  }
28
- if (finalRouteName.length > 1 && finalRouteName.endsWith('/')) {
28
+ if (finalRouteName.length > 1 && finalRouteName.endsWith("/")) {
29
29
  finalRouteName = finalRouteName.substring(0, finalRouteName.length - 1);
30
30
  }
31
31
  return finalRouteName;
32
32
  };
33
- export const isHandler = input => input && typeof input === 'function';
34
- const enableRegister = requireFn => {
35
- // esbuild-register 做 unRegister 时,不会删除 register 添加的 require.extensions,导致第二次调用时 require.extensions['.ts'] 是 nodejs 默认 loader
36
- // 所以这里根据第一次调用时,require.extensions 有没有,来判断是否需要使用 esbuild-register
33
+ const isHandler = (input) => input && typeof input === "function";
34
+ const enableRegister = (requireFn) => {
37
35
  let existTsLoader = false;
38
36
  let firstCall = true;
39
- return modulePath => {
37
+ return (modulePath) => {
40
38
  if (firstCall) {
41
- // eslint-disable-next-line node/no-deprecated-api
42
- existTsLoader = Boolean(require.extensions['.ts']);
39
+ existTsLoader = Boolean(require.extensions[".ts"]);
43
40
  firstCall = false;
44
41
  }
45
42
  if (!existTsLoader) {
46
43
  const {
47
44
  register
48
- } = require('esbuild-register/dist/node');
49
- const {
50
- unregister
51
- } = register({
52
- extensions: ['.ts']
45
+ } = require("esbuild-register/dist/node");
46
+ const { unregister } = register({
47
+ extensions: [".ts"]
53
48
  });
54
- const requiredModule = requireFn(modulePath);
49
+ const requiredModule2 = requireFn(modulePath);
55
50
  unregister();
56
- return requiredModule;
51
+ return requiredModule2;
57
52
  }
58
53
  const requiredModule = requireFn(modulePath);
59
54
  return requiredModule;
60
55
  };
61
56
  };
62
- const isFunction = input => input && {}.toString.call(input) === '[object Function]';
63
- export const requireHandlerModule = enableRegister(modulePath => {
64
- // 测试环境不走缓存,因为缓存的 h andler 文件,会被 mockAPI 函数进行 mock,升级 jest28,setupFilesAfterEnv 能做异步操作的话,可解此问题
65
- const originRequire = process.env.NODE_ENV === 'test' ? jest.requireActual : require;
57
+ const isFunction = (input) => input && {}.toString.call(input) === "[object Function]";
58
+ const requireHandlerModule = enableRegister((modulePath) => {
59
+ const originRequire = process.env.NODE_ENV === "test" ? jest.requireActual : require;
66
60
  const module = originRequire(modulePath);
67
61
  if (isFunction(module)) {
68
- return {
69
- default: module
70
- };
62
+ return { default: module };
71
63
  }
72
64
  return module;
73
65
  });
74
- const routeValue = routePath => {
75
- if (routePath.includes(':')) {
66
+ const routeValue = (routePath) => {
67
+ if (routePath.includes(":")) {
76
68
  return 11;
77
69
  }
78
70
  return 1;
79
71
  };
80
- export const sortRoutes = apiHandlers => {
72
+ const sortRoutes = (apiHandlers) => {
81
73
  return apiHandlers.sort((handlerA, handlerB) => {
82
74
  return routeValue(handlerA.routeName) - routeValue(handlerB.routeName);
83
75
  });
84
- };
76
+ };
77
+ export {
78
+ getFiles,
79
+ getPathFromFilename,
80
+ isHandler,
81
+ requireHandlerModule,
82
+ sortRoutes
83
+ };
@@ -1,37 +1,45 @@
1
- export let OperatorType;
2
- (function (OperatorType) {
3
- OperatorType[OperatorType["Trigger"] = 0] = "Trigger";
4
- OperatorType[OperatorType["Middleware"] = 1] = "Middleware";
5
- })(OperatorType || (OperatorType = {}));
6
- export let TriggerType;
7
- (function (TriggerType) {
8
- TriggerType[TriggerType["Http"] = 0] = "Http";
9
- })(TriggerType || (TriggerType = {}));
10
- export let HttpMetadata;
11
- (function (HttpMetadata) {
12
- HttpMetadata["Method"] = "METHOD";
13
- HttpMetadata["Data"] = "DATA";
14
- HttpMetadata["Query"] = "QUERY";
15
- HttpMetadata["Params"] = "PARAMS";
16
- HttpMetadata["Headers"] = "HEADERS";
17
- HttpMetadata["Response"] = "RESPONSE";
18
- })(HttpMetadata || (HttpMetadata = {}));
19
- export let ResponseMetaType;
20
- (function (ResponseMetaType) {
21
- ResponseMetaType[ResponseMetaType["StatusCode"] = 0] = "StatusCode";
22
- ResponseMetaType[ResponseMetaType["Redirect"] = 1] = "Redirect";
23
- ResponseMetaType[ResponseMetaType["Headers"] = 2] = "Headers";
24
- })(ResponseMetaType || (ResponseMetaType = {}));
25
- export let HttpMethod;
26
- (function (HttpMethod) {
27
- HttpMethod["Get"] = "GET";
28
- HttpMethod["Post"] = "POST";
29
- HttpMethod["Put"] = "PUT";
30
- HttpMethod["Delete"] = "DELETE";
31
- HttpMethod["Connect"] = "CONNECT";
32
- HttpMethod["Trace"] = "TRACE";
33
- HttpMethod["Patch"] = "PATCH";
34
- HttpMethod["Option"] = "OPTION";
35
- HttpMethod["Head"] = "HEAD";
36
- })(HttpMethod || (HttpMethod = {}));
37
- export const httpMethods = Object.values(HttpMethod);
1
+ var OperatorType = /* @__PURE__ */ ((OperatorType2) => {
2
+ OperatorType2[OperatorType2["Trigger"] = 0] = "Trigger";
3
+ OperatorType2[OperatorType2["Middleware"] = 1] = "Middleware";
4
+ return OperatorType2;
5
+ })(OperatorType || {});
6
+ var TriggerType = /* @__PURE__ */ ((TriggerType2) => {
7
+ TriggerType2[TriggerType2["Http"] = 0] = "Http";
8
+ return TriggerType2;
9
+ })(TriggerType || {});
10
+ var HttpMetadata = /* @__PURE__ */ ((HttpMetadata2) => {
11
+ HttpMetadata2["Method"] = "METHOD";
12
+ HttpMetadata2["Data"] = "DATA";
13
+ HttpMetadata2["Query"] = "QUERY";
14
+ HttpMetadata2["Params"] = "PARAMS";
15
+ HttpMetadata2["Headers"] = "HEADERS";
16
+ HttpMetadata2["Response"] = "RESPONSE";
17
+ return HttpMetadata2;
18
+ })(HttpMetadata || {});
19
+ var ResponseMetaType = /* @__PURE__ */ ((ResponseMetaType2) => {
20
+ ResponseMetaType2[ResponseMetaType2["StatusCode"] = 0] = "StatusCode";
21
+ ResponseMetaType2[ResponseMetaType2["Redirect"] = 1] = "Redirect";
22
+ ResponseMetaType2[ResponseMetaType2["Headers"] = 2] = "Headers";
23
+ return ResponseMetaType2;
24
+ })(ResponseMetaType || {});
25
+ var HttpMethod = /* @__PURE__ */ ((HttpMethod2) => {
26
+ HttpMethod2["Get"] = "GET";
27
+ HttpMethod2["Post"] = "POST";
28
+ HttpMethod2["Put"] = "PUT";
29
+ HttpMethod2["Delete"] = "DELETE";
30
+ HttpMethod2["Connect"] = "CONNECT";
31
+ HttpMethod2["Trace"] = "TRACE";
32
+ HttpMethod2["Patch"] = "PATCH";
33
+ HttpMethod2["Option"] = "OPTION";
34
+ HttpMethod2["Head"] = "HEAD";
35
+ return HttpMethod2;
36
+ })(HttpMethod || {});
37
+ const httpMethods = Object.values(HttpMethod);
38
+ export {
39
+ HttpMetadata,
40
+ HttpMethod,
41
+ OperatorType,
42
+ ResponseMetaType,
43
+ TriggerType,
44
+ httpMethods
45
+ };
@@ -1,32 +1,36 @@
1
- import * as path from 'path';
2
- import * as os from 'os';
3
- import fs from 'fs';
4
- import Module from 'module';
5
- export const getRelativeRuntimePath = (appDirectory, serverRuntimePath) => {
6
- let relativeRuntimePath = '';
7
- if (os.platform() === 'win32') {
8
- // isRelative function in babel-plugin-resolver plugin can't handle windows relative path correctly, see babel-plugin-resolver's utils.
9
- relativeRuntimePath = `../${path.relative(appDirectory, serverRuntimePath)}`;
1
+ import * as path from "path";
2
+ import * as os from "os";
3
+ import fs from "fs";
4
+ import Module from "module";
5
+ const getRelativeRuntimePath = (appDirectory, serverRuntimePath) => {
6
+ let relativeRuntimePath = "";
7
+ if (os.platform() === "win32") {
8
+ relativeRuntimePath = `../${path.relative(
9
+ appDirectory,
10
+ serverRuntimePath
11
+ )}`;
10
12
  } else {
11
- // Look up one level, because the artifacts after build have dist directories
12
- relativeRuntimePath = path.join('../', path.relative(appDirectory, serverRuntimePath));
13
+ relativeRuntimePath = path.join(
14
+ "../",
15
+ path.relative(appDirectory, serverRuntimePath)
16
+ );
13
17
  }
14
- if (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test') {
18
+ if (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") {
15
19
  relativeRuntimePath = `./${path.relative(appDirectory, serverRuntimePath)}`;
16
20
  }
17
21
  return relativeRuntimePath;
18
22
  };
19
- const sortByLongestPrefix = arr => {
23
+ const sortByLongestPrefix = (arr) => {
20
24
  return arr.concat().sort((a, b) => b.length - a.length);
21
25
  };
22
- export const createMatchPath = paths => {
26
+ const createMatchPath = (paths) => {
23
27
  const sortedKeys = sortByLongestPrefix(Object.keys(paths));
24
28
  const sortedPaths = {};
25
- sortedKeys.forEach(key => {
29
+ sortedKeys.forEach((key) => {
26
30
  sortedPaths[key] = paths[key];
27
31
  });
28
- return request => {
29
- const found = Object.keys(sortedPaths).find(key => {
32
+ return (request) => {
33
+ const found = Object.keys(sortedPaths).find((key) => {
30
34
  return request.startsWith(key);
31
35
  });
32
36
  if (found) {
@@ -34,7 +38,7 @@ export const createMatchPath = paths => {
34
38
  if (!Array.isArray(foundPaths)) {
35
39
  foundPaths = [foundPaths];
36
40
  }
37
- foundPaths = foundPaths.filter(foundPath => path.isAbsolute(foundPath));
41
+ foundPaths = foundPaths.filter((foundPath) => path.isAbsolute(foundPath));
38
42
  for (const p of foundPaths) {
39
43
  const foundPath = request.replace(found, p);
40
44
  if (fs.existsSync(foundPath)) {
@@ -46,29 +50,27 @@ export const createMatchPath = paths => {
46
50
  return null;
47
51
  };
48
52
  };
49
-
50
- // every path must be a absolute path;
51
- export const registerPaths = paths => {
53
+ const registerPaths = (paths) => {
52
54
  const originalResolveFilename = Module._resolveFilename;
53
- // eslint-disable-next-line node/no-unsupported-features/node-builtins
54
- const {
55
- builtinModules
56
- } = Module;
55
+ const { builtinModules } = Module;
57
56
  const matchPath = createMatchPath(paths);
58
- Module._resolveFilename = function (request, _parent) {
57
+ Module._resolveFilename = function(request, _parent) {
59
58
  const isCoreModule = builtinModules.includes(request);
60
59
  if (!isCoreModule) {
61
60
  const matched = matchPath(request);
62
61
  if (matched) {
63
- // eslint-disable-next-line prefer-rest-params
64
- const modifiedArguments = [matched, ...[].slice.call(arguments, 1)]; // Passes all arguments. Even those that is not specified above.
62
+ const modifiedArguments = [matched, ...[].slice.call(arguments, 1)];
65
63
  return originalResolveFilename.apply(this, modifiedArguments);
66
64
  }
67
65
  }
68
- // eslint-disable-next-line prefer-rest-params
69
66
  return originalResolveFilename.apply(this, arguments);
70
67
  };
71
68
  return () => {
72
69
  Module._resolveFilename = originalResolveFilename;
73
70
  };
74
- };
71
+ };
72
+ export {
73
+ createMatchPath,
74
+ getRelativeRuntimePath,
75
+ registerPaths
76
+ };
@@ -1,2 +1,5 @@
1
- import { createDebugger } from '@modern-js/utils';
2
- export const debug = createDebugger('bff');
1
+ import { createDebugger } from "@modern-js/utils";
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
- export * from "./validate";
5
+ export * from "./validate";
6
+ export {
7
+ debug
8
+ };
@@ -1,4 +1,8 @@
1
- export const HANDLER_WITH_META = 'HANDLER_WITH_META';
2
- export const isWithMetaHandler = handler => {
3
- return typeof handler === 'function' && handler[HANDLER_WITH_META];
4
- };
1
+ const HANDLER_WITH_META = "HANDLER_WITH_META";
2
+ const isWithMetaHandler = (handler) => {
3
+ return typeof handler === "function" && handler[HANDLER_WITH_META];
4
+ };
5
+ export {
6
+ HANDLER_WITH_META,
7
+ isWithMetaHandler
8
+ };