@modern-js/bff-core 2.15.0 → 2.16.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.
- package/CHANGELOG.md +14 -0
- package/dist/cjs/api.js +22 -42
- package/dist/cjs/client/generateClient.js +63 -66
- package/dist/cjs/client/index.js +18 -17
- package/dist/cjs/client/result.js +11 -24
- package/dist/cjs/errors/http.js +26 -24
- package/dist/cjs/index.js +41 -50
- package/dist/cjs/operators/http.js +95 -101
- package/dist/cjs/router/constants.js +32 -40
- package/dist/cjs/router/index.js +114 -116
- package/dist/cjs/router/types.js +4 -15
- package/dist/cjs/router/utils.js +33 -50
- package/dist/cjs/types.js +29 -46
- package/dist/cjs/utils/alias.js +78 -58
- package/dist/cjs/utils/debug.js +8 -26
- package/dist/cjs/utils/index.js +24 -30
- package/dist/cjs/utils/meta.js +13 -28
- package/dist/cjs/utils/storage.js +51 -41
- package/dist/cjs/utils/validate.js +27 -44
- package/dist/esm/api.js +5 -5
- package/dist/esm/client/generateClient.js +6 -30
- package/dist/esm/client/result.js +2 -6
- package/dist/esm/errors/http.js +17 -6
- package/dist/esm/index.js +3 -23
- package/dist/esm/operators/http.js +22 -55
- package/dist/esm/router/constants.js +21 -20
- package/dist/esm/router/index.js +58 -61
- package/dist/esm/router/types.js +1 -0
- package/dist/esm/router/utils.js +11 -14
- package/dist/esm/types.js +16 -24
- package/dist/esm/utils/alias.js +12 -18
- package/dist/esm/utils/debug.js +1 -4
- package/dist/esm/utils/index.js +1 -4
- package/dist/esm/utils/meta.js +4 -10
- package/dist/esm/utils/storage.js +2 -6
- package/dist/esm/utils/validate.js +12 -15
- package/package.json +11 -7
package/dist/cjs/router/index.js
CHANGED
|
@@ -1,80 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var router_exports = {};
|
|
30
|
-
__export(router_exports, {
|
|
31
|
-
ApiRouter: () => ApiRouter
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
32
4
|
});
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const existAppFile = exist("app.ts") || exist("app.js");
|
|
56
|
-
if (existLambdaDir || existAppDir || existAppFile) {
|
|
57
|
-
return import_constants.APIMode.FARMEWORK;
|
|
58
|
-
}
|
|
59
|
-
return import_constants.APIMode.FUNCTION;
|
|
60
|
-
};
|
|
61
|
-
this.createExistChecker = (base) => (target) => import_utils.fs.pathExistsSync(import_path.default.resolve(base, target));
|
|
62
|
-
this.getExactLambdaDir = (apiDir, originLambdaDir) => {
|
|
63
|
-
if (this.apiMode === import_constants.APIMode.FUNCTION) {
|
|
64
|
-
return apiDir;
|
|
65
|
-
}
|
|
66
|
-
return originLambdaDir || import_path.default.join(apiDir, import_constants.FRAMEWORK_MODE_LAMBDA_DIR);
|
|
67
|
-
};
|
|
68
|
-
this.validateAbsolute(apiDir, "apiDir");
|
|
69
|
-
this.validateAbsolute(lambdaDir, "lambdaDir");
|
|
70
|
-
this.prefix = this.initPrefix(prefix);
|
|
71
|
-
this.apiDir = apiDir;
|
|
72
|
-
this.httpMethodDecider = httpMethodDecider;
|
|
73
|
-
this.apiMode = this.getExactApiMode(apiDir, lambdaDir);
|
|
74
|
-
this.lambdaDir = this.getExactLambdaDir(this.apiDir, lambdaDir);
|
|
75
|
-
this.existLambdaDir = import_utils.fs.existsSync(this.lambdaDir);
|
|
76
|
-
(0, import_utils2.debug)(`apiDir:`, this.apiDir, `lambdaDir:`, this.lambdaDir);
|
|
5
|
+
Object.defineProperty(exports, "ApiRouter", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: () => ApiRouter
|
|
8
|
+
});
|
|
9
|
+
const _path = /* @__PURE__ */ _interop_require_default(require("path"));
|
|
10
|
+
const _utils = require("@modern-js/utils");
|
|
11
|
+
require("reflect-metadata");
|
|
12
|
+
const _types = require("../types");
|
|
13
|
+
const _utils1 = require("../utils");
|
|
14
|
+
const _constants = _export_star(require("./constants"), exports);
|
|
15
|
+
const _utils2 = require("./utils");
|
|
16
|
+
_export_star(require("./types"), exports);
|
|
17
|
+
function _define_property(obj, key, value) {
|
|
18
|
+
if (key in obj) {
|
|
19
|
+
Object.defineProperty(obj, key, {
|
|
20
|
+
value,
|
|
21
|
+
enumerable: true,
|
|
22
|
+
configurable: true,
|
|
23
|
+
writable: true
|
|
24
|
+
});
|
|
25
|
+
} else {
|
|
26
|
+
obj[key] = value;
|
|
77
27
|
}
|
|
28
|
+
return obj;
|
|
29
|
+
}
|
|
30
|
+
function _export_star(from, to) {
|
|
31
|
+
Object.keys(from).forEach(function(k) {
|
|
32
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
33
|
+
Object.defineProperty(to, k, {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
get: function() {
|
|
36
|
+
return from[k];
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
return from;
|
|
42
|
+
}
|
|
43
|
+
function _interop_require_default(obj) {
|
|
44
|
+
return obj && obj.__esModule ? obj : {
|
|
45
|
+
default: obj
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
class ApiRouter {
|
|
78
49
|
isExistLambda() {
|
|
79
50
|
return this.existLambdaDir;
|
|
80
51
|
}
|
|
@@ -120,30 +91,28 @@ class ApiRouter {
|
|
|
120
91
|
}
|
|
121
92
|
getRouteName(filename, handler) {
|
|
122
93
|
if (handler) {
|
|
123
|
-
const trigger = Reflect.getMetadata(
|
|
124
|
-
if (trigger && trigger.type ===
|
|
94
|
+
const trigger = Reflect.getMetadata(_types.OperatorType.Trigger, handler);
|
|
95
|
+
if (trigger && trigger.type === _types.TriggerType.Http) {
|
|
125
96
|
if (!trigger.path) {
|
|
126
|
-
throw new Error(
|
|
127
|
-
`The http trigger ${trigger.name} needs to specify a path`
|
|
128
|
-
);
|
|
97
|
+
throw new Error(`The http trigger ${trigger.name} needs to specify a path`);
|
|
129
98
|
}
|
|
130
99
|
return trigger.path;
|
|
131
100
|
}
|
|
132
101
|
}
|
|
133
|
-
let routePath = (0,
|
|
102
|
+
let routePath = (0, _utils2.getPathFromFilename)(this.lambdaDir, filename);
|
|
134
103
|
if (this.httpMethodDecider === "inputParams") {
|
|
135
104
|
if (routePath.endsWith("/")) {
|
|
136
|
-
routePath += `${handler
|
|
105
|
+
routePath += `${handler === null || handler === void 0 ? void 0 : handler.name}`;
|
|
137
106
|
} else {
|
|
138
|
-
routePath += `/${handler
|
|
107
|
+
routePath += `/${handler === null || handler === void 0 ? void 0 : handler.name}`;
|
|
139
108
|
}
|
|
140
109
|
}
|
|
141
110
|
return routePath;
|
|
142
111
|
}
|
|
143
112
|
getHttpMethod(originHandlerName, handler) {
|
|
144
113
|
if (handler) {
|
|
145
|
-
const trigger = Reflect.getMetadata(
|
|
146
|
-
if (trigger &&
|
|
114
|
+
const trigger = Reflect.getMetadata(_types.OperatorType.Trigger, handler);
|
|
115
|
+
if (trigger && _types.httpMethods.includes(trigger.method)) {
|
|
147
116
|
return trigger.method;
|
|
148
117
|
}
|
|
149
118
|
}
|
|
@@ -151,30 +120,28 @@ class ApiRouter {
|
|
|
151
120
|
const upperName = originHandlerName.toUpperCase();
|
|
152
121
|
switch (upperName) {
|
|
153
122
|
case "GET":
|
|
154
|
-
return
|
|
123
|
+
return _types.HttpMethod.Get;
|
|
155
124
|
case "POST":
|
|
156
|
-
return
|
|
125
|
+
return _types.HttpMethod.Post;
|
|
157
126
|
case "PUT":
|
|
158
|
-
return
|
|
127
|
+
return _types.HttpMethod.Put;
|
|
159
128
|
case "DELETE":
|
|
160
129
|
case "DEL":
|
|
161
|
-
return
|
|
130
|
+
return _types.HttpMethod.Delete;
|
|
162
131
|
case "CONNECT":
|
|
163
|
-
return
|
|
132
|
+
return _types.HttpMethod.Connect;
|
|
164
133
|
case "TRACE":
|
|
165
|
-
return
|
|
134
|
+
return _types.HttpMethod.Trace;
|
|
166
135
|
case "PATCH":
|
|
167
|
-
return
|
|
136
|
+
return _types.HttpMethod.Patch;
|
|
168
137
|
case "OPTIONS":
|
|
169
|
-
return
|
|
138
|
+
return _types.HttpMethod.Options;
|
|
170
139
|
case "DEFAULT": {
|
|
171
|
-
return
|
|
140
|
+
return _types.HttpMethod.Get;
|
|
172
141
|
}
|
|
173
142
|
default:
|
|
174
143
|
if (process.env.NODE_ENV !== "test") {
|
|
175
|
-
|
|
176
|
-
`Only api handlers are allowd to be exported, please remove the function ${originHandlerName} from exports`
|
|
177
|
-
);
|
|
144
|
+
_utils.logger.warn(`Only api handlers are allowd to be exported, please remove the function ${originHandlerName} from exports`);
|
|
178
145
|
}
|
|
179
146
|
return null;
|
|
180
147
|
}
|
|
@@ -183,16 +150,16 @@ class ApiRouter {
|
|
|
183
150
|
return null;
|
|
184
151
|
}
|
|
185
152
|
if (typeof handler === "function" && handler.length > 0) {
|
|
186
|
-
return
|
|
153
|
+
return _types.HttpMethod.Post;
|
|
187
154
|
}
|
|
188
|
-
return
|
|
155
|
+
return _types.HttpMethod.Get;
|
|
189
156
|
}
|
|
190
157
|
}
|
|
191
158
|
loadApiFiles() {
|
|
192
159
|
if (!this.existLambdaDir) {
|
|
193
160
|
return [];
|
|
194
161
|
}
|
|
195
|
-
const apiFiles = this.apiFiles = (0,
|
|
162
|
+
const apiFiles = this.apiFiles = (0, _utils2.getFiles)(this.lambdaDir, _constants.API_FILE_RULES);
|
|
196
163
|
return apiFiles;
|
|
197
164
|
}
|
|
198
165
|
getApiFiles() {
|
|
@@ -208,13 +175,13 @@ class ApiRouter {
|
|
|
208
175
|
const filenames = this.getApiFiles();
|
|
209
176
|
const moduleInfos = this.getModuleInfos(filenames);
|
|
210
177
|
const apiHandlers = this.getHandlerInfos(moduleInfos);
|
|
211
|
-
(0,
|
|
178
|
+
(0, _utils1.debug)("apiHandlers", apiHandlers.length, apiHandlers);
|
|
212
179
|
return apiHandlers;
|
|
213
180
|
}
|
|
214
181
|
/**
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
182
|
+
* 如果用户未传入或传入空串,默认为 /api
|
|
183
|
+
* 如果传入 /,则 prefix 为 /
|
|
184
|
+
*/
|
|
218
185
|
initPrefix(prefix) {
|
|
219
186
|
if (prefix === "/") {
|
|
220
187
|
return "";
|
|
@@ -222,7 +189,7 @@ class ApiRouter {
|
|
|
222
189
|
return prefix || "/api";
|
|
223
190
|
}
|
|
224
191
|
validateAbsolute(filename, paramsName) {
|
|
225
|
-
if (typeof filename === "string" && !
|
|
192
|
+
if (typeof filename === "string" && !_path.default.isAbsolute(filename)) {
|
|
226
193
|
throw new Error(`The ${paramsName} ${filename} is not a abolute path`);
|
|
227
194
|
}
|
|
228
195
|
}
|
|
@@ -231,10 +198,10 @@ class ApiRouter {
|
|
|
231
198
|
}
|
|
232
199
|
getModuleInfo(filename) {
|
|
233
200
|
try {
|
|
234
|
-
const
|
|
201
|
+
const module = (0, _utils2.requireHandlerModule)(filename);
|
|
235
202
|
return {
|
|
236
203
|
filename,
|
|
237
|
-
module
|
|
204
|
+
module
|
|
238
205
|
};
|
|
239
206
|
} catch (err) {
|
|
240
207
|
if (process.env.NODE_ENV === "production") {
|
|
@@ -253,17 +220,17 @@ class ApiRouter {
|
|
|
253
220
|
apiHandlers = apiHandlers.concat(handlerInfos);
|
|
254
221
|
}
|
|
255
222
|
});
|
|
256
|
-
const sortedHandlers = (0,
|
|
223
|
+
const sortedHandlers = (0, _utils2.sortRoutes)(apiHandlers);
|
|
257
224
|
return sortedHandlers;
|
|
258
225
|
}
|
|
259
226
|
getModuleHandlerInfos(moduleInfo) {
|
|
260
|
-
const { module
|
|
227
|
+
const { module, filename } = moduleInfo;
|
|
261
228
|
const { httpMethodDecider } = this;
|
|
262
|
-
return Object.entries(
|
|
263
|
-
const handler =
|
|
229
|
+
return Object.entries(module).filter(([, handler]) => typeof handler === "function").map(([key]) => {
|
|
230
|
+
const handler = module[key];
|
|
264
231
|
if (httpMethodDecider === "inputParams") {
|
|
265
232
|
Object.assign(handler, {
|
|
266
|
-
[
|
|
233
|
+
[_utils1.INPUT_PARAMS_DECIDER]: true
|
|
267
234
|
});
|
|
268
235
|
}
|
|
269
236
|
const handlerInfo = this.getHandlerInfo(filename, key, handler);
|
|
@@ -282,8 +249,39 @@ class ApiRouter {
|
|
|
282
249
|
}
|
|
283
250
|
return `${prefix}${finalRouteName}`;
|
|
284
251
|
}
|
|
252
|
+
constructor({ apiDir, lambdaDir, prefix, httpMethodDecider = "functionName" }) {
|
|
253
|
+
_define_property(this, "apiMode", void 0);
|
|
254
|
+
_define_property(this, "apiDir", void 0);
|
|
255
|
+
_define_property(this, "existLambdaDir", void 0);
|
|
256
|
+
_define_property(this, "httpMethodDecider", void 0);
|
|
257
|
+
_define_property(this, "lambdaDir", void 0);
|
|
258
|
+
_define_property(this, "prefix", void 0);
|
|
259
|
+
_define_property(this, "apiFiles", []);
|
|
260
|
+
_define_property(this, "getExactApiMode", (apiDir2, lambdaDir2) => {
|
|
261
|
+
const exist = this.createExistChecker(apiDir2);
|
|
262
|
+
const existLambdaDir = lambdaDir2 && _utils.fs.pathExistsSync(lambdaDir2) || exist(_constants.FRAMEWORK_MODE_LAMBDA_DIR);
|
|
263
|
+
const existAppDir = exist(_constants.FRAMEWORK_MODE_APP_DIR);
|
|
264
|
+
const existAppFile = exist("app.ts") || exist("app.js");
|
|
265
|
+
if (existLambdaDir || existAppDir || existAppFile) {
|
|
266
|
+
return _constants.APIMode.FARMEWORK;
|
|
267
|
+
}
|
|
268
|
+
return _constants.APIMode.FUNCTION;
|
|
269
|
+
});
|
|
270
|
+
_define_property(this, "createExistChecker", (base) => (target) => _utils.fs.pathExistsSync(_path.default.resolve(base, target)));
|
|
271
|
+
_define_property(this, "getExactLambdaDir", (apiDir2, originLambdaDir) => {
|
|
272
|
+
if (this.apiMode === _constants.APIMode.FUNCTION) {
|
|
273
|
+
return apiDir2;
|
|
274
|
+
}
|
|
275
|
+
return originLambdaDir || _path.default.join(apiDir2, _constants.FRAMEWORK_MODE_LAMBDA_DIR);
|
|
276
|
+
});
|
|
277
|
+
this.validateAbsolute(apiDir, "apiDir");
|
|
278
|
+
this.validateAbsolute(lambdaDir, "lambdaDir");
|
|
279
|
+
this.prefix = this.initPrefix(prefix);
|
|
280
|
+
this.apiDir = apiDir;
|
|
281
|
+
this.httpMethodDecider = httpMethodDecider;
|
|
282
|
+
this.apiMode = this.getExactApiMode(apiDir, lambdaDir);
|
|
283
|
+
this.lambdaDir = this.getExactLambdaDir(this.apiDir, lambdaDir);
|
|
284
|
+
this.existLambdaDir = _utils.fs.existsSync(this.lambdaDir);
|
|
285
|
+
(0, _utils1.debug)(`apiDir:`, this.apiDir, `lambdaDir:`, this.lambdaDir);
|
|
286
|
+
}
|
|
285
287
|
}
|
|
286
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
287
|
-
0 && (module.exports = {
|
|
288
|
-
ApiRouter
|
|
289
|
-
});
|
package/dist/cjs/router/types.js
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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);
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
package/dist/cjs/router/utils.js
CHANGED
|
@@ -1,50 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
8
6
|
for (var name in all)
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
var utils_exports = {};
|
|
29
|
-
__export(utils_exports, {
|
|
7
|
+
Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: all[name]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
30
13
|
getFiles: () => getFiles,
|
|
31
14
|
getPathFromFilename: () => getPathFromFilename,
|
|
32
15
|
isHandler: () => isHandler,
|
|
33
16
|
requireHandlerModule: () => requireHandlerModule,
|
|
34
17
|
sortRoutes: () => sortRoutes
|
|
35
18
|
});
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
19
|
+
const _path = /* @__PURE__ */ _interop_require_default(require("path"));
|
|
20
|
+
const _utils = require("@modern-js/utils");
|
|
21
|
+
const _constants = require("./constants");
|
|
22
|
+
function _interop_require_default(obj) {
|
|
23
|
+
return obj && obj.__esModule ? obj : {
|
|
24
|
+
default: obj
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
const getFiles = (lambdaDir, rules) => _utils.globby.sync(rules, {
|
|
41
28
|
cwd: lambdaDir,
|
|
42
29
|
gitignore: true
|
|
43
|
-
}).map((file) =>
|
|
30
|
+
}).map((file) => _path.default.resolve(lambdaDir, file));
|
|
44
31
|
const getPathFromFilename = (baseDir, filename) => {
|
|
45
32
|
const relativeName = filename.substring(baseDir.length);
|
|
46
33
|
const relativePath = relativeName.split(".").slice(0, -1).join(".");
|
|
47
|
-
const nameSplit = relativePath.split(
|
|
34
|
+
const nameSplit = relativePath.split(_path.default.sep).map((item) => {
|
|
48
35
|
if (item.length > 2) {
|
|
49
36
|
if (item.startsWith("[") && item.endsWith("]")) {
|
|
50
37
|
return `:${item.substring(1, item.length - 1)}`;
|
|
@@ -53,7 +40,7 @@ const getPathFromFilename = (baseDir, filename) => {
|
|
|
53
40
|
return item;
|
|
54
41
|
});
|
|
55
42
|
const name = nameSplit.join("/");
|
|
56
|
-
const finalName = name.endsWith(
|
|
43
|
+
const finalName = name.endsWith(_constants.INDEX_SUFFIX) ? name.substring(0, name.length - _constants.INDEX_SUFFIX.length) : name;
|
|
57
44
|
return clearRouteName(finalName);
|
|
58
45
|
};
|
|
59
46
|
const clearRouteName = (routeName) => {
|
|
@@ -77,7 +64,7 @@ const enableRegister = (requireFn) => {
|
|
|
77
64
|
}
|
|
78
65
|
if (!existTsLoader) {
|
|
79
66
|
try {
|
|
80
|
-
const projectSearchDir =
|
|
67
|
+
const projectSearchDir = _path.default.dirname(modulePath);
|
|
81
68
|
const tsNode = require("ts-node");
|
|
82
69
|
tsNode.register({
|
|
83
70
|
projectSearchDir,
|
|
@@ -86,7 +73,9 @@ const enableRegister = (requireFn) => {
|
|
|
86
73
|
},
|
|
87
74
|
scope: true,
|
|
88
75
|
transpileOnly: true,
|
|
89
|
-
ignore: [
|
|
76
|
+
ignore: [
|
|
77
|
+
"(?:^|/)node_modules/"
|
|
78
|
+
]
|
|
90
79
|
});
|
|
91
80
|
existTsLoader = true;
|
|
92
81
|
const tsConfigPaths = require("tsconfig-paths");
|
|
@@ -107,11 +96,13 @@ const enableRegister = (requireFn) => {
|
|
|
107
96
|
const isFunction = (input) => input && {}.toString.call(input) === "[object Function]";
|
|
108
97
|
const requireHandlerModule = enableRegister((modulePath) => {
|
|
109
98
|
const originRequire = process.env.NODE_ENV === "test" ? jest.requireActual : require;
|
|
110
|
-
const
|
|
111
|
-
if (isFunction(
|
|
112
|
-
return {
|
|
99
|
+
const module = originRequire(modulePath);
|
|
100
|
+
if (isFunction(module)) {
|
|
101
|
+
return {
|
|
102
|
+
default: module
|
|
103
|
+
};
|
|
113
104
|
}
|
|
114
|
-
return
|
|
105
|
+
return module;
|
|
115
106
|
});
|
|
116
107
|
const routeValue = (routePath) => {
|
|
117
108
|
if (routePath.includes(":")) {
|
|
@@ -124,11 +115,3 @@ const sortRoutes = (apiHandlers) => {
|
|
|
124
115
|
return routeValue(handlerA.routeName) - routeValue(handlerB.routeName);
|
|
125
116
|
});
|
|
126
117
|
};
|
|
127
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
128
|
-
0 && (module.exports = {
|
|
129
|
-
getFiles,
|
|
130
|
-
getPathFromFilename,
|
|
131
|
-
isHandler,
|
|
132
|
-
requireHandlerModule,
|
|
133
|
-
sortRoutes
|
|
134
|
-
});
|
package/dist/cjs/types.js
CHANGED
|
@@ -1,55 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
6
|
for (var name in all)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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,
|
|
7
|
+
Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: all[name]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
22
13
|
OperatorType: () => OperatorType,
|
|
23
|
-
ResponseMetaType: () => ResponseMetaType,
|
|
24
14
|
TriggerType: () => TriggerType,
|
|
15
|
+
HttpMetadata: () => HttpMetadata,
|
|
16
|
+
ResponseMetaType: () => ResponseMetaType,
|
|
17
|
+
HttpMethod: () => HttpMethod,
|
|
25
18
|
httpMethods: () => httpMethods
|
|
26
19
|
});
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
var OperatorType;
|
|
21
|
+
(function(OperatorType2) {
|
|
29
22
|
OperatorType2[OperatorType2["Trigger"] = 0] = "Trigger";
|
|
30
23
|
OperatorType2[OperatorType2["Middleware"] = 1] = "Middleware";
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
24
|
+
})(OperatorType || (OperatorType = {}));
|
|
25
|
+
var TriggerType;
|
|
26
|
+
(function(TriggerType2) {
|
|
34
27
|
TriggerType2[TriggerType2["Http"] = 0] = "Http";
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
28
|
+
})(TriggerType || (TriggerType = {}));
|
|
29
|
+
var HttpMetadata;
|
|
30
|
+
(function(HttpMetadata2) {
|
|
38
31
|
HttpMetadata2["Method"] = "METHOD";
|
|
39
32
|
HttpMetadata2["Data"] = "DATA";
|
|
40
33
|
HttpMetadata2["Query"] = "QUERY";
|
|
41
34
|
HttpMetadata2["Params"] = "PARAMS";
|
|
42
35
|
HttpMetadata2["Headers"] = "HEADERS";
|
|
43
36
|
HttpMetadata2["Response"] = "RESPONSE";
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
37
|
+
})(HttpMetadata || (HttpMetadata = {}));
|
|
38
|
+
var ResponseMetaType;
|
|
39
|
+
(function(ResponseMetaType2) {
|
|
47
40
|
ResponseMetaType2[ResponseMetaType2["StatusCode"] = 0] = "StatusCode";
|
|
48
41
|
ResponseMetaType2[ResponseMetaType2["Redirect"] = 1] = "Redirect";
|
|
49
42
|
ResponseMetaType2[ResponseMetaType2["Headers"] = 2] = "Headers";
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
43
|
+
})(ResponseMetaType || (ResponseMetaType = {}));
|
|
44
|
+
var HttpMethod;
|
|
45
|
+
(function(HttpMethod2) {
|
|
53
46
|
HttpMethod2["Get"] = "GET";
|
|
54
47
|
HttpMethod2["Post"] = "POST";
|
|
55
48
|
HttpMethod2["Put"] = "PUT";
|
|
@@ -59,15 +52,5 @@ var HttpMethod = /* @__PURE__ */ ((HttpMethod2) => {
|
|
|
59
52
|
HttpMethod2["Patch"] = "PATCH";
|
|
60
53
|
HttpMethod2["Options"] = "OPTIONS";
|
|
61
54
|
HttpMethod2["Head"] = "HEAD";
|
|
62
|
-
|
|
63
|
-
})(HttpMethod || {});
|
|
55
|
+
})(HttpMethod || (HttpMethod = {}));
|
|
64
56
|
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
|
-
});
|