@modern-js/bff-core 2.11.0 → 2.11.1-alpha.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.
- package/dist/cjs/router/utils.js +1 -0
- package/dist/esm/router/utils.js +1 -0
- package/dist/js/modern/api.js +69 -0
- package/dist/js/modern/client/generate-client.js +79 -0
- package/dist/js/modern/client/index.js +1 -0
- package/dist/js/modern/client/result.js +22 -0
- package/dist/js/modern/errors/http.js +16 -0
- package/dist/js/modern/index.js +23 -0
- package/dist/js/modern/operators/http.js +210 -0
- package/dist/js/modern/router/constants.js +32 -0
- package/dist/js/modern/router/index.js +236 -0
- package/dist/js/modern/router/types.js +0 -0
- package/dist/js/modern/router/utils.js +83 -0
- package/dist/js/modern/types.js +45 -0
- package/dist/js/modern/utils/alias.js +76 -0
- package/dist/js/modern/utils/debug.js +5 -0
- package/dist/js/modern/utils/index.js +8 -0
- package/dist/js/modern/utils/meta.js +8 -0
- package/dist/js/modern/utils/storage.js +42 -0
- package/dist/js/modern/utils/validate.js +43 -0
- package/dist/js/node/api.js +98 -0
- package/dist/js/node/client/generate-client.js +109 -0
- package/dist/js/node/client/index.js +17 -0
- package/dist/js/node/client/result.js +46 -0
- package/dist/js/node/errors/http.js +40 -0
- package/dist/js/node/index.js +48 -0
- package/dist/js/node/operators/http.js +241 -0
- package/dist/js/node/router/constants.js +61 -0
- package/dist/js/node/router/index.js +256 -0
- package/dist/js/node/router/types.js +15 -0
- package/dist/js/node/router/utils.js +116 -0
- package/dist/js/node/types.js +73 -0
- package/dist/js/node/utils/alias.js +107 -0
- package/dist/js/node/utils/debug.js +28 -0
- package/dist/js/node/utils/index.js +32 -0
- package/dist/js/node/utils/meta.js +32 -0
- package/dist/js/node/utils/storage.js +71 -0
- package/dist/js/node/utils/validate.js +74 -0
- package/package.json +3 -3
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var router_exports = {};
|
|
26
|
+
__export(router_exports, {
|
|
27
|
+
ApiRouter: () => ApiRouter
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(router_exports);
|
|
30
|
+
var import_path = __toESM(require("path"));
|
|
31
|
+
var import_utils = require("@modern-js/utils");
|
|
32
|
+
var import_reflect_metadata = require("reflect-metadata");
|
|
33
|
+
var import_types = require("../types");
|
|
34
|
+
var import_utils2 = require("../utils");
|
|
35
|
+
var import_constants = require("./constants");
|
|
36
|
+
var import_utils3 = require("./utils");
|
|
37
|
+
__reExport(router_exports, require("./types"), module.exports);
|
|
38
|
+
__reExport(router_exports, require("./constants"), module.exports);
|
|
39
|
+
class ApiRouter {
|
|
40
|
+
constructor({
|
|
41
|
+
apiDir,
|
|
42
|
+
lambdaDir,
|
|
43
|
+
prefix
|
|
44
|
+
}) {
|
|
45
|
+
this.apiFiles = [];
|
|
46
|
+
this.getExactApiMode = (apiDir) => {
|
|
47
|
+
const exist = this.createExistChecker(apiDir);
|
|
48
|
+
const existLambdaDir = exist(import_constants.FRAMEWORK_MODE_LAMBDA_DIR);
|
|
49
|
+
const existAppDir = exist(import_constants.FRAMEWORK_MODE_APP_DIR);
|
|
50
|
+
const existAppFile = exist("app.ts") || exist("app.js");
|
|
51
|
+
if (existLambdaDir || existAppDir || existAppFile) {
|
|
52
|
+
return import_constants.APIMode.FARMEWORK;
|
|
53
|
+
}
|
|
54
|
+
return import_constants.APIMode.FUNCTION;
|
|
55
|
+
};
|
|
56
|
+
this.createExistChecker = (base) => (target) => import_utils.fs.pathExistsSync(import_path.default.resolve(base, target));
|
|
57
|
+
this.getExactLambdaDir = (apiDir) => {
|
|
58
|
+
if (this.lambdaDir) {
|
|
59
|
+
return this.lambdaDir;
|
|
60
|
+
}
|
|
61
|
+
const lambdaDir = this.apiMode === import_constants.APIMode.FARMEWORK ? import_path.default.join(apiDir, import_constants.FRAMEWORK_MODE_LAMBDA_DIR) : apiDir;
|
|
62
|
+
return lambdaDir;
|
|
63
|
+
};
|
|
64
|
+
this.validateAbsolute(apiDir, "apiDir");
|
|
65
|
+
this.validateAbsolute(lambdaDir, "lambdaDir");
|
|
66
|
+
this.prefix = this.initPrefix(prefix);
|
|
67
|
+
this.apiDir = apiDir;
|
|
68
|
+
this.apiMode = this.getExactApiMode(apiDir);
|
|
69
|
+
this.lambdaDir = lambdaDir || this.getExactLambdaDir(this.apiDir);
|
|
70
|
+
this.existLambdaDir = import_utils.fs.existsSync(this.lambdaDir);
|
|
71
|
+
}
|
|
72
|
+
isExistLambda() {
|
|
73
|
+
return this.existLambdaDir;
|
|
74
|
+
}
|
|
75
|
+
getApiMode() {
|
|
76
|
+
return this.apiMode;
|
|
77
|
+
}
|
|
78
|
+
getLambdaDir() {
|
|
79
|
+
return this.lambdaDir;
|
|
80
|
+
}
|
|
81
|
+
isApiFile(filename) {
|
|
82
|
+
if (this.existLambdaDir) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
if (!this.apiFiles.includes(filename)) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
getSingleModuleHandlers(filename) {
|
|
91
|
+
const moduleInfo = this.getModuleInfo(filename);
|
|
92
|
+
if (moduleInfo) {
|
|
93
|
+
return this.getModuleHandlerInfos(moduleInfo);
|
|
94
|
+
}
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
getHandlerInfo(filename, originFuncName, handler) {
|
|
98
|
+
const httpMethod = this.getHttpMethod(originFuncName, handler);
|
|
99
|
+
const routeName = this.getRouteName(filename, handler);
|
|
100
|
+
if (httpMethod && routeName) {
|
|
101
|
+
return {
|
|
102
|
+
handler,
|
|
103
|
+
name: originFuncName,
|
|
104
|
+
httpMethod,
|
|
105
|
+
routeName,
|
|
106
|
+
filename,
|
|
107
|
+
routePath: this.getRoutePath(this.prefix, routeName)
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
getSafeRoutePath(filename, handler) {
|
|
113
|
+
this.loadApiFiles();
|
|
114
|
+
this.validateValidApifile(filename);
|
|
115
|
+
return this.getRouteName(filename, handler);
|
|
116
|
+
}
|
|
117
|
+
getRouteName(filename, handler) {
|
|
118
|
+
if (handler) {
|
|
119
|
+
const trigger = Reflect.getMetadata(import_types.OperatorType.Trigger, handler);
|
|
120
|
+
if (trigger && trigger.type === import_types.TriggerType.Http) {
|
|
121
|
+
if (!trigger.path) {
|
|
122
|
+
throw new Error(
|
|
123
|
+
`The http trigger ${trigger.name} needs to specify a path`
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
return trigger.path;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
const routePath = (0, import_utils3.getPathFromFilename)(this.lambdaDir, filename);
|
|
130
|
+
return routePath;
|
|
131
|
+
}
|
|
132
|
+
getHttpMethod(originHandlerName, handler) {
|
|
133
|
+
if (handler) {
|
|
134
|
+
const trigger = Reflect.getMetadata(import_types.OperatorType.Trigger, handler);
|
|
135
|
+
if (trigger && import_types.httpMethods.includes(trigger.method)) {
|
|
136
|
+
return trigger.method;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const upperName = originHandlerName.toUpperCase();
|
|
140
|
+
switch (upperName) {
|
|
141
|
+
case "GET":
|
|
142
|
+
return import_types.HttpMethod.Get;
|
|
143
|
+
case "POST":
|
|
144
|
+
return import_types.HttpMethod.Post;
|
|
145
|
+
case "PUT":
|
|
146
|
+
return import_types.HttpMethod.Put;
|
|
147
|
+
case "DELETE":
|
|
148
|
+
case "DEL":
|
|
149
|
+
return import_types.HttpMethod.Delete;
|
|
150
|
+
case "CONNECT":
|
|
151
|
+
return import_types.HttpMethod.Connect;
|
|
152
|
+
case "TRACE":
|
|
153
|
+
return import_types.HttpMethod.Trace;
|
|
154
|
+
case "PATCH":
|
|
155
|
+
return import_types.HttpMethod.Patch;
|
|
156
|
+
case "OPTION":
|
|
157
|
+
return import_types.HttpMethod.Option;
|
|
158
|
+
case "DEFAULT": {
|
|
159
|
+
return import_types.HttpMethod.Get;
|
|
160
|
+
}
|
|
161
|
+
default:
|
|
162
|
+
import_utils.logger.warn(
|
|
163
|
+
`Only api handlers are allowd to be exported, please remove the function ${originHandlerName} from exports`
|
|
164
|
+
);
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
loadApiFiles() {
|
|
169
|
+
if (!this.existLambdaDir) {
|
|
170
|
+
return [];
|
|
171
|
+
}
|
|
172
|
+
const apiFiles = this.apiFiles = (0, import_utils3.getFiles)(this.lambdaDir, import_constants.API_FILE_RULES);
|
|
173
|
+
return apiFiles;
|
|
174
|
+
}
|
|
175
|
+
getApiFiles() {
|
|
176
|
+
if (!this.existLambdaDir) {
|
|
177
|
+
return [];
|
|
178
|
+
}
|
|
179
|
+
if (this.apiFiles.length > 0) {
|
|
180
|
+
return this.apiFiles;
|
|
181
|
+
}
|
|
182
|
+
return this.loadApiFiles();
|
|
183
|
+
}
|
|
184
|
+
getApiHandlers() {
|
|
185
|
+
const filenames = this.getApiFiles();
|
|
186
|
+
const moduleInfos = this.getModuleInfos(filenames);
|
|
187
|
+
const apiHandlers = this.getHandlerInfos(moduleInfos);
|
|
188
|
+
(0, import_utils2.debug)("apiHandlers", apiHandlers.length, apiHandlers);
|
|
189
|
+
return apiHandlers;
|
|
190
|
+
}
|
|
191
|
+
initPrefix(prefix) {
|
|
192
|
+
if (prefix === "/") {
|
|
193
|
+
return "";
|
|
194
|
+
}
|
|
195
|
+
return prefix || "/api";
|
|
196
|
+
}
|
|
197
|
+
validateAbsolute(filename, paramsName) {
|
|
198
|
+
if (typeof filename === "string" && !import_path.default.isAbsolute(filename)) {
|
|
199
|
+
throw new Error(`The ${paramsName} ${filename} is not a abolute path`);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
getModuleInfos(filenames) {
|
|
203
|
+
return filenames.map((filename) => this.getModuleInfo(filename)).filter((moduleInfo) => Boolean(moduleInfo));
|
|
204
|
+
}
|
|
205
|
+
getModuleInfo(filename) {
|
|
206
|
+
try {
|
|
207
|
+
const module2 = (0, import_utils3.requireHandlerModule)(filename);
|
|
208
|
+
return {
|
|
209
|
+
filename,
|
|
210
|
+
module: module2
|
|
211
|
+
};
|
|
212
|
+
} catch (err) {
|
|
213
|
+
if (process.env.NODE_ENV === "production") {
|
|
214
|
+
throw err;
|
|
215
|
+
} else {
|
|
216
|
+
console.error(err);
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
getHandlerInfos(moduleInfos) {
|
|
222
|
+
let apiHandlers = [];
|
|
223
|
+
moduleInfos.forEach((moduleInfo) => {
|
|
224
|
+
const handlerInfos = this.getModuleHandlerInfos(moduleInfo);
|
|
225
|
+
if (handlerInfos) {
|
|
226
|
+
apiHandlers = apiHandlers.concat(handlerInfos);
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
const sortedHandlers = (0, import_utils3.sortRoutes)(apiHandlers);
|
|
230
|
+
return sortedHandlers;
|
|
231
|
+
}
|
|
232
|
+
getModuleHandlerInfos(moduleInfo) {
|
|
233
|
+
const { module: module2, filename } = moduleInfo;
|
|
234
|
+
return Object.entries(module2).filter(([, handler]) => typeof handler === "function").map(([key]) => {
|
|
235
|
+
const handler = module2[key];
|
|
236
|
+
const handlerInfo = this.getHandlerInfo(filename, key, handler);
|
|
237
|
+
return handlerInfo;
|
|
238
|
+
}).filter((handlerInfo) => Boolean(handlerInfo));
|
|
239
|
+
}
|
|
240
|
+
validateValidApifile(filename) {
|
|
241
|
+
if (!this.apiFiles.includes(filename)) {
|
|
242
|
+
throw new Error(`The ${filename} is not a valid api file.`);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
getRoutePath(prefix, routeName) {
|
|
246
|
+
const finalRouteName = routeName === "/" ? "" : routeName;
|
|
247
|
+
if (prefix === "" && finalRouteName === "") {
|
|
248
|
+
return "/";
|
|
249
|
+
}
|
|
250
|
+
return `${prefix}${finalRouteName}`;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
254
|
+
0 && (module.exports = {
|
|
255
|
+
ApiRouter
|
|
256
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
var types_exports = {};
|
|
15
|
+
module.exports = __toCommonJS(types_exports);
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
var utils_exports = {};
|
|
25
|
+
__export(utils_exports, {
|
|
26
|
+
getFiles: () => getFiles,
|
|
27
|
+
getPathFromFilename: () => getPathFromFilename,
|
|
28
|
+
isHandler: () => isHandler,
|
|
29
|
+
requireHandlerModule: () => requireHandlerModule,
|
|
30
|
+
sortRoutes: () => sortRoutes
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(utils_exports);
|
|
33
|
+
var import_path = __toESM(require("path"));
|
|
34
|
+
var import_utils = require("@modern-js/utils");
|
|
35
|
+
var import_constants = require("./constants");
|
|
36
|
+
const getFiles = (lambdaDir, rules) => import_utils.globby.sync(rules, {
|
|
37
|
+
cwd: lambdaDir,
|
|
38
|
+
gitignore: true
|
|
39
|
+
}).map((file) => import_path.default.resolve(lambdaDir, file));
|
|
40
|
+
const getPathFromFilename = (baseDir, filename) => {
|
|
41
|
+
const relativeName = filename.substring(baseDir.length);
|
|
42
|
+
const relativePath = relativeName.split(".").slice(0, -1).join(".");
|
|
43
|
+
const nameSplit = relativePath.split(import_path.default.sep).map((item) => {
|
|
44
|
+
if (item.length > 2) {
|
|
45
|
+
if (item.startsWith("[") && item.endsWith("]")) {
|
|
46
|
+
return `:${item.substring(1, item.length - 1)}`;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return item;
|
|
50
|
+
});
|
|
51
|
+
const name = nameSplit.join("/");
|
|
52
|
+
const finalName = name.endsWith(import_constants.INDEX_SUFFIX) ? name.substring(0, name.length - import_constants.INDEX_SUFFIX.length) : name;
|
|
53
|
+
return clearRouteName(finalName);
|
|
54
|
+
};
|
|
55
|
+
const clearRouteName = (routeName) => {
|
|
56
|
+
let finalRouteName = routeName.trim();
|
|
57
|
+
if (!finalRouteName.startsWith("/")) {
|
|
58
|
+
finalRouteName = `/${finalRouteName}`;
|
|
59
|
+
}
|
|
60
|
+
if (finalRouteName.length > 1 && finalRouteName.endsWith("/")) {
|
|
61
|
+
finalRouteName = finalRouteName.substring(0, finalRouteName.length - 1);
|
|
62
|
+
}
|
|
63
|
+
return finalRouteName;
|
|
64
|
+
};
|
|
65
|
+
const isHandler = (input) => input && typeof input === "function";
|
|
66
|
+
const enableRegister = (requireFn) => {
|
|
67
|
+
let existTsLoader = false;
|
|
68
|
+
let firstCall = true;
|
|
69
|
+
return (modulePath) => {
|
|
70
|
+
if (firstCall) {
|
|
71
|
+
existTsLoader = Boolean(require.extensions[".ts"]);
|
|
72
|
+
firstCall = false;
|
|
73
|
+
}
|
|
74
|
+
if (!existTsLoader) {
|
|
75
|
+
const {
|
|
76
|
+
register
|
|
77
|
+
} = require("esbuild-register/dist/node");
|
|
78
|
+
const { unregister } = register({
|
|
79
|
+
extensions: [".ts"]
|
|
80
|
+
});
|
|
81
|
+
const requiredModule2 = requireFn(modulePath);
|
|
82
|
+
unregister();
|
|
83
|
+
return requiredModule2;
|
|
84
|
+
}
|
|
85
|
+
const requiredModule = requireFn(modulePath);
|
|
86
|
+
return requiredModule;
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
const isFunction = (input) => input && {}.toString.call(input) === "[object Function]";
|
|
90
|
+
const requireHandlerModule = enableRegister((modulePath) => {
|
|
91
|
+
const originRequire = process.env.NODE_ENV === "test" ? jest.requireActual : require;
|
|
92
|
+
const module2 = originRequire(modulePath);
|
|
93
|
+
if (isFunction(module2)) {
|
|
94
|
+
return { default: module2 };
|
|
95
|
+
}
|
|
96
|
+
return module2;
|
|
97
|
+
});
|
|
98
|
+
const routeValue = (routePath) => {
|
|
99
|
+
if (routePath.includes(":")) {
|
|
100
|
+
return 11;
|
|
101
|
+
}
|
|
102
|
+
return 1;
|
|
103
|
+
};
|
|
104
|
+
const sortRoutes = (apiHandlers) => {
|
|
105
|
+
return apiHandlers.sort((handlerA, handlerB) => {
|
|
106
|
+
return routeValue(handlerA.routeName) - routeValue(handlerB.routeName);
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
110
|
+
0 && (module.exports = {
|
|
111
|
+
getFiles,
|
|
112
|
+
getPathFromFilename,
|
|
113
|
+
isHandler,
|
|
114
|
+
requireHandlerModule,
|
|
115
|
+
sortRoutes
|
|
116
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var types_exports = {};
|
|
19
|
+
__export(types_exports, {
|
|
20
|
+
HttpMetadata: () => HttpMetadata,
|
|
21
|
+
HttpMethod: () => HttpMethod,
|
|
22
|
+
OperatorType: () => OperatorType,
|
|
23
|
+
ResponseMetaType: () => ResponseMetaType,
|
|
24
|
+
TriggerType: () => TriggerType,
|
|
25
|
+
httpMethods: () => httpMethods
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(types_exports);
|
|
28
|
+
var OperatorType = /* @__PURE__ */ ((OperatorType2) => {
|
|
29
|
+
OperatorType2[OperatorType2["Trigger"] = 0] = "Trigger";
|
|
30
|
+
OperatorType2[OperatorType2["Middleware"] = 1] = "Middleware";
|
|
31
|
+
return OperatorType2;
|
|
32
|
+
})(OperatorType || {});
|
|
33
|
+
var TriggerType = /* @__PURE__ */ ((TriggerType2) => {
|
|
34
|
+
TriggerType2[TriggerType2["Http"] = 0] = "Http";
|
|
35
|
+
return TriggerType2;
|
|
36
|
+
})(TriggerType || {});
|
|
37
|
+
var HttpMetadata = /* @__PURE__ */ ((HttpMetadata2) => {
|
|
38
|
+
HttpMetadata2["Method"] = "METHOD";
|
|
39
|
+
HttpMetadata2["Data"] = "DATA";
|
|
40
|
+
HttpMetadata2["Query"] = "QUERY";
|
|
41
|
+
HttpMetadata2["Params"] = "PARAMS";
|
|
42
|
+
HttpMetadata2["Headers"] = "HEADERS";
|
|
43
|
+
HttpMetadata2["Response"] = "RESPONSE";
|
|
44
|
+
return HttpMetadata2;
|
|
45
|
+
})(HttpMetadata || {});
|
|
46
|
+
var ResponseMetaType = /* @__PURE__ */ ((ResponseMetaType2) => {
|
|
47
|
+
ResponseMetaType2[ResponseMetaType2["StatusCode"] = 0] = "StatusCode";
|
|
48
|
+
ResponseMetaType2[ResponseMetaType2["Redirect"] = 1] = "Redirect";
|
|
49
|
+
ResponseMetaType2[ResponseMetaType2["Headers"] = 2] = "Headers";
|
|
50
|
+
return ResponseMetaType2;
|
|
51
|
+
})(ResponseMetaType || {});
|
|
52
|
+
var HttpMethod = /* @__PURE__ */ ((HttpMethod2) => {
|
|
53
|
+
HttpMethod2["Get"] = "GET";
|
|
54
|
+
HttpMethod2["Post"] = "POST";
|
|
55
|
+
HttpMethod2["Put"] = "PUT";
|
|
56
|
+
HttpMethod2["Delete"] = "DELETE";
|
|
57
|
+
HttpMethod2["Connect"] = "CONNECT";
|
|
58
|
+
HttpMethod2["Trace"] = "TRACE";
|
|
59
|
+
HttpMethod2["Patch"] = "PATCH";
|
|
60
|
+
HttpMethod2["Option"] = "OPTION";
|
|
61
|
+
HttpMethod2["Head"] = "HEAD";
|
|
62
|
+
return HttpMethod2;
|
|
63
|
+
})(HttpMethod || {});
|
|
64
|
+
const httpMethods = Object.values(HttpMethod);
|
|
65
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
66
|
+
0 && (module.exports = {
|
|
67
|
+
HttpMetadata,
|
|
68
|
+
HttpMethod,
|
|
69
|
+
OperatorType,
|
|
70
|
+
ResponseMetaType,
|
|
71
|
+
TriggerType,
|
|
72
|
+
httpMethods
|
|
73
|
+
});
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
var alias_exports = {};
|
|
25
|
+
__export(alias_exports, {
|
|
26
|
+
createMatchPath: () => createMatchPath,
|
|
27
|
+
getRelativeRuntimePath: () => getRelativeRuntimePath,
|
|
28
|
+
registerPaths: () => registerPaths
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(alias_exports);
|
|
31
|
+
var path = __toESM(require("path"));
|
|
32
|
+
var os = __toESM(require("os"));
|
|
33
|
+
var import_fs = __toESM(require("fs"));
|
|
34
|
+
var import_module = __toESM(require("module"));
|
|
35
|
+
const getRelativeRuntimePath = (appDirectory, serverRuntimePath) => {
|
|
36
|
+
let relativeRuntimePath = "";
|
|
37
|
+
if (os.platform() === "win32") {
|
|
38
|
+
relativeRuntimePath = `../${path.relative(
|
|
39
|
+
appDirectory,
|
|
40
|
+
serverRuntimePath
|
|
41
|
+
)}`;
|
|
42
|
+
} else {
|
|
43
|
+
relativeRuntimePath = path.join(
|
|
44
|
+
"../",
|
|
45
|
+
path.relative(appDirectory, serverRuntimePath)
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
if (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") {
|
|
49
|
+
relativeRuntimePath = `./${path.relative(appDirectory, serverRuntimePath)}`;
|
|
50
|
+
}
|
|
51
|
+
return relativeRuntimePath;
|
|
52
|
+
};
|
|
53
|
+
const sortByLongestPrefix = (arr) => {
|
|
54
|
+
return arr.concat().sort((a, b) => b.length - a.length);
|
|
55
|
+
};
|
|
56
|
+
const createMatchPath = (paths) => {
|
|
57
|
+
const sortedKeys = sortByLongestPrefix(Object.keys(paths));
|
|
58
|
+
const sortedPaths = {};
|
|
59
|
+
sortedKeys.forEach((key) => {
|
|
60
|
+
sortedPaths[key] = paths[key];
|
|
61
|
+
});
|
|
62
|
+
return (request) => {
|
|
63
|
+
const found = Object.keys(sortedPaths).find((key) => {
|
|
64
|
+
return request.startsWith(key);
|
|
65
|
+
});
|
|
66
|
+
if (found) {
|
|
67
|
+
let foundPaths = sortedPaths[found];
|
|
68
|
+
if (!Array.isArray(foundPaths)) {
|
|
69
|
+
foundPaths = [foundPaths];
|
|
70
|
+
}
|
|
71
|
+
foundPaths = foundPaths.filter((foundPath) => path.isAbsolute(foundPath));
|
|
72
|
+
for (const p of foundPaths) {
|
|
73
|
+
const foundPath = request.replace(found, p);
|
|
74
|
+
if (import_fs.default.existsSync(foundPath)) {
|
|
75
|
+
return foundPath;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return request.replace(found, foundPaths[0]);
|
|
79
|
+
}
|
|
80
|
+
return null;
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
const registerPaths = (paths) => {
|
|
84
|
+
const originalResolveFilename = import_module.default._resolveFilename;
|
|
85
|
+
const { builtinModules } = import_module.default;
|
|
86
|
+
const matchPath = createMatchPath(paths);
|
|
87
|
+
import_module.default._resolveFilename = function(request, _parent) {
|
|
88
|
+
const isCoreModule = builtinModules.includes(request);
|
|
89
|
+
if (!isCoreModule) {
|
|
90
|
+
const matched = matchPath(request);
|
|
91
|
+
if (matched) {
|
|
92
|
+
const modifiedArguments = [matched, ...[].slice.call(arguments, 1)];
|
|
93
|
+
return originalResolveFilename.apply(this, modifiedArguments);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return originalResolveFilename.apply(this, arguments);
|
|
97
|
+
};
|
|
98
|
+
return () => {
|
|
99
|
+
import_module.default._resolveFilename = originalResolveFilename;
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
103
|
+
0 && (module.exports = {
|
|
104
|
+
createMatchPath,
|
|
105
|
+
getRelativeRuntimePath,
|
|
106
|
+
registerPaths
|
|
107
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var debug_exports = {};
|
|
19
|
+
__export(debug_exports, {
|
|
20
|
+
debug: () => debug
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(debug_exports);
|
|
23
|
+
var import_utils = require("@modern-js/utils");
|
|
24
|
+
const debug = (0, import_utils.createDebugger)("bff");
|
|
25
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
26
|
+
0 && (module.exports = {
|
|
27
|
+
debug
|
|
28
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var utils_exports = {};
|
|
20
|
+
__export(utils_exports, {
|
|
21
|
+
debug: () => import_debug.debug
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(utils_exports);
|
|
24
|
+
__reExport(utils_exports, require("./storage"), module.exports);
|
|
25
|
+
__reExport(utils_exports, require("./alias"), module.exports);
|
|
26
|
+
var import_debug = require("./debug");
|
|
27
|
+
__reExport(utils_exports, require("./meta"), module.exports);
|
|
28
|
+
__reExport(utils_exports, require("./validate"), module.exports);
|
|
29
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
30
|
+
0 && (module.exports = {
|
|
31
|
+
debug
|
|
32
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var meta_exports = {};
|
|
19
|
+
__export(meta_exports, {
|
|
20
|
+
HANDLER_WITH_META: () => HANDLER_WITH_META,
|
|
21
|
+
isWithMetaHandler: () => isWithMetaHandler
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(meta_exports);
|
|
24
|
+
const HANDLER_WITH_META = "HANDLER_WITH_META";
|
|
25
|
+
const isWithMetaHandler = (handler) => {
|
|
26
|
+
return typeof handler === "function" && handler[HANDLER_WITH_META];
|
|
27
|
+
};
|
|
28
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
29
|
+
0 && (module.exports = {
|
|
30
|
+
HANDLER_WITH_META,
|
|
31
|
+
isWithMetaHandler
|
|
32
|
+
});
|