@modern-js/bff-core 2.35.0 → 2.36.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/dist/cjs/api.js +40 -14
- package/dist/cjs/client/generateClient.js +42 -23
- package/dist/cjs/client/index.js +20 -4
- package/dist/cjs/client/result.js +25 -15
- package/dist/cjs/errors/http.js +28 -18
- package/dist/cjs/index.js +53 -47
- package/dist/cjs/operators/http.js +93 -89
- package/dist/cjs/router/constants.js +37 -32
- package/dist/cjs/router/index.js +96 -69
- package/dist/cjs/router/types.js +15 -3
- package/dist/cjs/router/utils.js +52 -36
- package/dist/cjs/types.js +33 -27
- package/dist/cjs/utils/alias.js +51 -34
- package/dist/cjs/utils/debug.js +26 -9
- package/dist/cjs/utils/index.js +34 -13
- package/dist/cjs/utils/meta.js +29 -21
- package/dist/cjs/utils/storage.js +37 -11
- package/dist/cjs/utils/validate.js +40 -22
- package/dist/esm/api.js +4 -1
- package/dist/esm/client/generateClient.js +6 -2
- package/dist/esm/client/result.js +6 -2
- package/dist/esm/errors/http.js +6 -2
- package/dist/esm/index.js +15 -3
- package/dist/esm/operators/http.js +36 -17
- package/dist/esm/router/constants.js +16 -7
- package/dist/esm/router/index.js +6 -5
- package/dist/esm/router/types.js +0 -1
- package/dist/esm/router/utils.js +12 -5
- package/dist/esm/types.js +14 -6
- package/dist/esm/utils/alias.js +8 -3
- package/dist/esm/utils/debug.js +4 -1
- package/dist/esm/utils/index.js +4 -1
- package/dist/esm/utils/meta.js +10 -4
- package/dist/esm/utils/storage.js +3 -1
- package/dist/esm/utils/validate.js +8 -3
- package/package.json +7 -7
|
@@ -1,39 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
6
7
|
for (var name in all)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return APIMode;
|
|
15
|
-
},
|
|
16
|
-
AllHttpMethods: function() {
|
|
17
|
-
return AllHttpMethods;
|
|
18
|
-
},
|
|
19
|
-
FRAMEWORK_MODE_LAMBDA_DIR: function() {
|
|
20
|
-
return FRAMEWORK_MODE_LAMBDA_DIR;
|
|
21
|
-
},
|
|
22
|
-
FRAMEWORK_MODE_APP_DIR: function() {
|
|
23
|
-
return FRAMEWORK_MODE_APP_DIR;
|
|
24
|
-
},
|
|
25
|
-
INDEX_SUFFIX: function() {
|
|
26
|
-
return INDEX_SUFFIX;
|
|
27
|
-
},
|
|
28
|
-
API_DIR: function() {
|
|
29
|
-
return API_DIR;
|
|
30
|
-
},
|
|
31
|
-
API_FILE_RULES: function() {
|
|
32
|
-
return API_FILE_RULES;
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
33
15
|
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var constants_exports = {};
|
|
20
|
+
__export(constants_exports, {
|
|
21
|
+
APIMode: () => APIMode,
|
|
22
|
+
API_DIR: () => API_DIR,
|
|
23
|
+
API_FILE_RULES: () => API_FILE_RULES,
|
|
24
|
+
AllHttpMethods: () => AllHttpMethods,
|
|
25
|
+
FRAMEWORK_MODE_APP_DIR: () => FRAMEWORK_MODE_APP_DIR,
|
|
26
|
+
FRAMEWORK_MODE_LAMBDA_DIR: () => FRAMEWORK_MODE_LAMBDA_DIR,
|
|
27
|
+
INDEX_SUFFIX: () => INDEX_SUFFIX
|
|
34
28
|
});
|
|
35
|
-
|
|
36
|
-
|
|
29
|
+
module.exports = __toCommonJS(constants_exports);
|
|
30
|
+
var import_types = require("../types");
|
|
31
|
+
const AllHttpMethods = Object.values(import_types.HttpMethod);
|
|
37
32
|
var APIMode;
|
|
38
33
|
(function(APIMode2) {
|
|
39
34
|
APIMode2[
|
|
@@ -65,3 +60,13 @@ const API_FILE_RULES = [
|
|
|
65
60
|
"!node_modules/**",
|
|
66
61
|
"!bootstrap.jsx"
|
|
67
62
|
];
|
|
63
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
64
|
+
0 && (module.exports = {
|
|
65
|
+
APIMode,
|
|
66
|
+
API_DIR,
|
|
67
|
+
API_FILE_RULES,
|
|
68
|
+
AllHttpMethods,
|
|
69
|
+
FRAMEWORK_MODE_APP_DIR,
|
|
70
|
+
FRAMEWORK_MODE_LAMBDA_DIR,
|
|
71
|
+
INDEX_SUFFIX
|
|
72
|
+
});
|
package/dist/cjs/router/index.js
CHANGED
|
@@ -1,24 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
9
17
|
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
var router_exports = {};
|
|
31
|
+
__export(router_exports, {
|
|
32
|
+
ApiRouter: () => ApiRouter
|
|
10
33
|
});
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
require("
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
34
|
+
module.exports = __toCommonJS(router_exports);
|
|
35
|
+
var import_define_property = require("@swc/helpers/_/_define_property");
|
|
36
|
+
var import_path = __toESM(require("path"));
|
|
37
|
+
var import_utils = require("@modern-js/utils");
|
|
38
|
+
var import_reflect_metadata = require("reflect-metadata");
|
|
39
|
+
var import_types = require("../types");
|
|
40
|
+
var import_utils2 = require("../utils");
|
|
41
|
+
var import_constants = require("./constants");
|
|
42
|
+
var import_utils3 = require("./utils");
|
|
43
|
+
__reExport(router_exports, require("./types"), module.exports);
|
|
44
|
+
__reExport(router_exports, require("./constants"), module.exports);
|
|
22
45
|
class ApiRouter {
|
|
23
46
|
enableRegister() {
|
|
24
47
|
const existTsLoader = Boolean(require.extensions[".ts"]);
|
|
@@ -94,30 +117,28 @@ class ApiRouter {
|
|
|
94
117
|
}
|
|
95
118
|
getRouteName(filename, handler) {
|
|
96
119
|
if (handler) {
|
|
97
|
-
const trigger = Reflect.getMetadata(
|
|
98
|
-
if (trigger && trigger.type ===
|
|
120
|
+
const trigger = Reflect.getMetadata(import_types.OperatorType.Trigger, handler);
|
|
121
|
+
if (trigger && trigger.type === import_types.TriggerType.Http) {
|
|
99
122
|
if (!trigger.path) {
|
|
100
123
|
throw new Error(`The http trigger ${trigger.name} needs to specify a path`);
|
|
101
124
|
}
|
|
102
125
|
return trigger.path;
|
|
103
126
|
}
|
|
104
127
|
}
|
|
105
|
-
let routePath = (0,
|
|
128
|
+
let routePath = (0, import_utils3.getPathFromFilename)(this.lambdaDir, filename);
|
|
106
129
|
if (this.httpMethodDecider === "inputParams") {
|
|
107
130
|
if (routePath.endsWith("/")) {
|
|
108
|
-
|
|
109
|
-
routePath += `${(_handler = handler) === null || _handler === void 0 ? void 0 : _handler.name}`;
|
|
131
|
+
routePath += `${handler === null || handler === void 0 ? void 0 : handler.name}`;
|
|
110
132
|
} else {
|
|
111
|
-
|
|
112
|
-
routePath += `/${(_handler1 = handler) === null || _handler1 === void 0 ? void 0 : _handler1.name}`;
|
|
133
|
+
routePath += `/${handler === null || handler === void 0 ? void 0 : handler.name}`;
|
|
113
134
|
}
|
|
114
135
|
}
|
|
115
136
|
return routePath;
|
|
116
137
|
}
|
|
117
138
|
getHttpMethod(originHandlerName, handler) {
|
|
118
139
|
if (handler) {
|
|
119
|
-
const trigger = Reflect.getMetadata(
|
|
120
|
-
if (trigger &&
|
|
140
|
+
const trigger = Reflect.getMetadata(import_types.OperatorType.Trigger, handler);
|
|
141
|
+
if (trigger && import_types.httpMethods.includes(trigger.method)) {
|
|
121
142
|
return trigger.method;
|
|
122
143
|
}
|
|
123
144
|
}
|
|
@@ -125,28 +146,28 @@ class ApiRouter {
|
|
|
125
146
|
const upperName = originHandlerName.toUpperCase();
|
|
126
147
|
switch (upperName) {
|
|
127
148
|
case "GET":
|
|
128
|
-
return
|
|
149
|
+
return import_types.HttpMethod.Get;
|
|
129
150
|
case "POST":
|
|
130
|
-
return
|
|
151
|
+
return import_types.HttpMethod.Post;
|
|
131
152
|
case "PUT":
|
|
132
|
-
return
|
|
153
|
+
return import_types.HttpMethod.Put;
|
|
133
154
|
case "DELETE":
|
|
134
155
|
case "DEL":
|
|
135
|
-
return
|
|
156
|
+
return import_types.HttpMethod.Delete;
|
|
136
157
|
case "CONNECT":
|
|
137
|
-
return
|
|
158
|
+
return import_types.HttpMethod.Connect;
|
|
138
159
|
case "TRACE":
|
|
139
|
-
return
|
|
160
|
+
return import_types.HttpMethod.Trace;
|
|
140
161
|
case "PATCH":
|
|
141
|
-
return
|
|
162
|
+
return import_types.HttpMethod.Patch;
|
|
142
163
|
case "OPTIONS":
|
|
143
|
-
return
|
|
164
|
+
return import_types.HttpMethod.Options;
|
|
144
165
|
case "DEFAULT": {
|
|
145
|
-
return
|
|
166
|
+
return import_types.HttpMethod.Get;
|
|
146
167
|
}
|
|
147
168
|
default:
|
|
148
169
|
if (process.env.NODE_ENV !== "test") {
|
|
149
|
-
|
|
170
|
+
import_utils.logger.warn(`Only api handlers are allowd to be exported, please remove the function ${originHandlerName} from exports`);
|
|
150
171
|
}
|
|
151
172
|
return null;
|
|
152
173
|
}
|
|
@@ -155,16 +176,16 @@ class ApiRouter {
|
|
|
155
176
|
return null;
|
|
156
177
|
}
|
|
157
178
|
if (typeof handler === "function" && handler.length > 0) {
|
|
158
|
-
return
|
|
179
|
+
return import_types.HttpMethod.Post;
|
|
159
180
|
}
|
|
160
|
-
return
|
|
181
|
+
return import_types.HttpMethod.Get;
|
|
161
182
|
}
|
|
162
183
|
}
|
|
163
184
|
loadApiFiles() {
|
|
164
185
|
if (!this.existLambdaDir) {
|
|
165
186
|
return [];
|
|
166
187
|
}
|
|
167
|
-
const apiFiles = this.apiFiles = (0,
|
|
188
|
+
const apiFiles = this.apiFiles = (0, import_utils3.getFiles)(this.lambdaDir, import_constants.API_FILE_RULES);
|
|
168
189
|
return apiFiles;
|
|
169
190
|
}
|
|
170
191
|
getApiFiles() {
|
|
@@ -180,7 +201,7 @@ class ApiRouter {
|
|
|
180
201
|
const filenames = this.getApiFiles();
|
|
181
202
|
const moduleInfos = this.getModuleInfos(filenames);
|
|
182
203
|
const apiHandlers = this.getHandlerInfos(moduleInfos);
|
|
183
|
-
(0,
|
|
204
|
+
(0, import_utils2.debug)("apiHandlers", apiHandlers.length, apiHandlers);
|
|
184
205
|
return apiHandlers;
|
|
185
206
|
}
|
|
186
207
|
/**
|
|
@@ -194,7 +215,7 @@ class ApiRouter {
|
|
|
194
215
|
return prefix || "/api";
|
|
195
216
|
}
|
|
196
217
|
validateAbsolute(filename, paramsName) {
|
|
197
|
-
if (typeof filename === "string" && !
|
|
218
|
+
if (typeof filename === "string" && !import_path.default.isAbsolute(filename)) {
|
|
198
219
|
throw new Error(`The ${paramsName} ${filename} is not a abolute path`);
|
|
199
220
|
}
|
|
200
221
|
}
|
|
@@ -203,10 +224,10 @@ class ApiRouter {
|
|
|
203
224
|
}
|
|
204
225
|
getModuleInfo(filename) {
|
|
205
226
|
try {
|
|
206
|
-
const
|
|
227
|
+
const module2 = (0, import_utils3.requireHandlerModule)(filename);
|
|
207
228
|
return {
|
|
208
229
|
filename,
|
|
209
|
-
module
|
|
230
|
+
module: module2
|
|
210
231
|
};
|
|
211
232
|
} catch (err) {
|
|
212
233
|
if (process.env.NODE_ENV === "production") {
|
|
@@ -225,17 +246,17 @@ class ApiRouter {
|
|
|
225
246
|
apiHandlers = apiHandlers.concat(handlerInfos);
|
|
226
247
|
}
|
|
227
248
|
});
|
|
228
|
-
const sortedHandlers = (0,
|
|
249
|
+
const sortedHandlers = (0, import_utils3.sortRoutes)(apiHandlers);
|
|
229
250
|
return sortedHandlers;
|
|
230
251
|
}
|
|
231
252
|
getModuleHandlerInfos(moduleInfo) {
|
|
232
|
-
const { module, filename } = moduleInfo;
|
|
253
|
+
const { module: module2, filename } = moduleInfo;
|
|
233
254
|
const { httpMethodDecider } = this;
|
|
234
|
-
return Object.entries(
|
|
235
|
-
const handler =
|
|
255
|
+
return Object.entries(module2).filter(([, handler]) => typeof handler === "function").map(([key]) => {
|
|
256
|
+
const handler = module2[key];
|
|
236
257
|
if (httpMethodDecider === "inputParams") {
|
|
237
258
|
Object.assign(handler, {
|
|
238
|
-
[
|
|
259
|
+
[import_utils2.INPUT_PARAMS_DECIDER]: true
|
|
239
260
|
});
|
|
240
261
|
}
|
|
241
262
|
const handlerInfo = this.getHandlerInfo(filename, key, handler);
|
|
@@ -255,31 +276,31 @@ class ApiRouter {
|
|
|
255
276
|
return `${prefix}${finalRouteName}`;
|
|
256
277
|
}
|
|
257
278
|
constructor({ appDir, apiDir, lambdaDir, prefix, isBuild, httpMethodDecider = "functionName" }) {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
279
|
+
(0, import_define_property._)(this, "apiMode", void 0);
|
|
280
|
+
(0, import_define_property._)(this, "appDir", void 0);
|
|
281
|
+
(0, import_define_property._)(this, "apiDir", void 0);
|
|
282
|
+
(0, import_define_property._)(this, "existLambdaDir", void 0);
|
|
283
|
+
(0, import_define_property._)(this, "httpMethodDecider", void 0);
|
|
284
|
+
(0, import_define_property._)(this, "lambdaDir", void 0);
|
|
285
|
+
(0, import_define_property._)(this, "prefix", void 0);
|
|
286
|
+
(0, import_define_property._)(this, "apiFiles", []);
|
|
287
|
+
(0, import_define_property._)(this, "isBuild", void 0);
|
|
288
|
+
(0, import_define_property._)(this, "getExactApiMode", (apiDir2, lambdaDir2) => {
|
|
268
289
|
const exist = this.createExistChecker(apiDir2);
|
|
269
|
-
const existLambdaDir = lambdaDir2 &&
|
|
270
|
-
const existAppDir = exist(
|
|
290
|
+
const existLambdaDir = lambdaDir2 && import_utils.fs.pathExistsSync(lambdaDir2) || exist(import_constants.FRAMEWORK_MODE_LAMBDA_DIR);
|
|
291
|
+
const existAppDir = exist(import_constants.FRAMEWORK_MODE_APP_DIR);
|
|
271
292
|
const existAppFile = exist("app.ts") || exist("app.js");
|
|
272
293
|
if (existLambdaDir || existAppDir || existAppFile) {
|
|
273
|
-
return
|
|
294
|
+
return import_constants.APIMode.FARMEWORK;
|
|
274
295
|
}
|
|
275
|
-
return
|
|
296
|
+
return import_constants.APIMode.FUNCTION;
|
|
276
297
|
});
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
if (this.apiMode ===
|
|
298
|
+
(0, import_define_property._)(this, "createExistChecker", (base) => (target) => import_utils.fs.pathExistsSync(import_path.default.resolve(base, target)));
|
|
299
|
+
(0, import_define_property._)(this, "getExactLambdaDir", (apiDir2, originLambdaDir) => {
|
|
300
|
+
if (this.apiMode === import_constants.APIMode.FUNCTION) {
|
|
280
301
|
return apiDir2;
|
|
281
302
|
}
|
|
282
|
-
return originLambdaDir ||
|
|
303
|
+
return originLambdaDir || import_path.default.join(apiDir2, import_constants.FRAMEWORK_MODE_LAMBDA_DIR);
|
|
283
304
|
});
|
|
284
305
|
this.validateAbsolute(apiDir, "apiDir");
|
|
285
306
|
this.validateAbsolute(lambdaDir, "lambdaDir");
|
|
@@ -290,8 +311,14 @@ class ApiRouter {
|
|
|
290
311
|
this.isBuild = isBuild;
|
|
291
312
|
this.apiMode = this.getExactApiMode(apiDir, lambdaDir);
|
|
292
313
|
this.lambdaDir = this.getExactLambdaDir(this.apiDir, lambdaDir);
|
|
293
|
-
this.existLambdaDir =
|
|
294
|
-
(0,
|
|
314
|
+
this.existLambdaDir = import_utils.fs.existsSync(this.lambdaDir);
|
|
315
|
+
(0, import_utils2.debug)(`apiDir:`, this.apiDir, `lambdaDir:`, this.lambdaDir);
|
|
295
316
|
this.enableRegister();
|
|
296
317
|
}
|
|
297
318
|
}
|
|
319
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
320
|
+
0 && (module.exports = {
|
|
321
|
+
ApiRouter,
|
|
322
|
+
...require("./types"),
|
|
323
|
+
...require("./constants")
|
|
324
|
+
});
|
package/dist/cjs/router/types.js
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_exports);
|
package/dist/cjs/router/utils.js
CHANGED
|
@@ -1,43 +1,51 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
6
9
|
for (var name in all)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return getFiles;
|
|
15
|
-
},
|
|
16
|
-
getPathFromFilename: function() {
|
|
17
|
-
return getPathFromFilename;
|
|
18
|
-
},
|
|
19
|
-
isHandler: function() {
|
|
20
|
-
return isHandler;
|
|
21
|
-
},
|
|
22
|
-
requireHandlerModule: function() {
|
|
23
|
-
return requireHandlerModule;
|
|
24
|
-
},
|
|
25
|
-
sortRoutes: function() {
|
|
26
|
-
return sortRoutes;
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
27
17
|
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
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 utils_exports = {};
|
|
30
|
+
__export(utils_exports, {
|
|
31
|
+
getFiles: () => getFiles,
|
|
32
|
+
getPathFromFilename: () => getPathFromFilename,
|
|
33
|
+
isHandler: () => isHandler,
|
|
34
|
+
requireHandlerModule: () => requireHandlerModule,
|
|
35
|
+
sortRoutes: () => sortRoutes
|
|
28
36
|
});
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const getFiles = (lambdaDir, rules) =>
|
|
37
|
+
module.exports = __toCommonJS(utils_exports);
|
|
38
|
+
var import_path = __toESM(require("path"));
|
|
39
|
+
var import_utils = require("@modern-js/utils");
|
|
40
|
+
var import_constants = require("./constants");
|
|
41
|
+
const getFiles = (lambdaDir, rules) => import_utils.globby.sync(rules, {
|
|
34
42
|
cwd: lambdaDir,
|
|
35
43
|
gitignore: true
|
|
36
|
-
}).map((file) =>
|
|
44
|
+
}).map((file) => import_path.default.resolve(lambdaDir, file));
|
|
37
45
|
const getPathFromFilename = (baseDir, filename) => {
|
|
38
46
|
const relativeName = filename.substring(baseDir.length);
|
|
39
47
|
const relativePath = relativeName.split(".").slice(0, -1).join(".");
|
|
40
|
-
const nameSplit = relativePath.split(
|
|
48
|
+
const nameSplit = relativePath.split(import_path.default.sep).map((item) => {
|
|
41
49
|
if (item.length > 2) {
|
|
42
50
|
if (item.startsWith("[") && item.endsWith("]")) {
|
|
43
51
|
return `:${item.substring(1, item.length - 1)}`;
|
|
@@ -46,7 +54,7 @@ const getPathFromFilename = (baseDir, filename) => {
|
|
|
46
54
|
return item;
|
|
47
55
|
});
|
|
48
56
|
const name = nameSplit.join("/");
|
|
49
|
-
const finalName = name.endsWith(
|
|
57
|
+
const finalName = name.endsWith(import_constants.INDEX_SUFFIX) ? name.substring(0, name.length - import_constants.INDEX_SUFFIX.length) : name;
|
|
50
58
|
return clearRouteName(finalName);
|
|
51
59
|
};
|
|
52
60
|
const clearRouteName = (routeName) => {
|
|
@@ -63,13 +71,13 @@ const isHandler = (input) => input && typeof input === "function";
|
|
|
63
71
|
const isFunction = (input) => input && {}.toString.call(input) === "[object Function]";
|
|
64
72
|
const requireHandlerModule = (modulePath) => {
|
|
65
73
|
const originRequire = process.env.NODE_ENV === "test" ? jest.requireActual : require;
|
|
66
|
-
const
|
|
67
|
-
if (isFunction(
|
|
74
|
+
const module2 = originRequire(modulePath);
|
|
75
|
+
if (isFunction(module2)) {
|
|
68
76
|
return {
|
|
69
|
-
default:
|
|
77
|
+
default: module2
|
|
70
78
|
};
|
|
71
79
|
}
|
|
72
|
-
return
|
|
80
|
+
return module2;
|
|
73
81
|
};
|
|
74
82
|
const routeValue = (routePath) => {
|
|
75
83
|
if (routePath.includes(":")) {
|
|
@@ -82,3 +90,11 @@ const sortRoutes = (apiHandlers) => {
|
|
|
82
90
|
return routeValue(handlerA.routeName) - routeValue(handlerB.routeName);
|
|
83
91
|
});
|
|
84
92
|
};
|
|
93
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
94
|
+
0 && (module.exports = {
|
|
95
|
+
getFiles,
|
|
96
|
+
getPathFromFilename,
|
|
97
|
+
isHandler,
|
|
98
|
+
requireHandlerModule,
|
|
99
|
+
sortRoutes
|
|
100
|
+
});
|
package/dist/cjs/types.js
CHANGED
|
@@ -1,34 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
6
7
|
for (var name in all)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return OperatorType;
|
|
15
|
-
},
|
|
16
|
-
TriggerType: function() {
|
|
17
|
-
return TriggerType;
|
|
18
|
-
},
|
|
19
|
-
HttpMetadata: function() {
|
|
20
|
-
return HttpMetadata;
|
|
21
|
-
},
|
|
22
|
-
ResponseMetaType: function() {
|
|
23
|
-
return ResponseMetaType;
|
|
24
|
-
},
|
|
25
|
-
HttpMethod: function() {
|
|
26
|
-
return HttpMethod;
|
|
27
|
-
},
|
|
28
|
-
httpMethods: function() {
|
|
29
|
-
return httpMethods;
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
30
15
|
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var types_exports = {};
|
|
20
|
+
__export(types_exports, {
|
|
21
|
+
HttpMetadata: () => HttpMetadata,
|
|
22
|
+
HttpMethod: () => HttpMethod,
|
|
23
|
+
OperatorType: () => OperatorType,
|
|
24
|
+
ResponseMetaType: () => ResponseMetaType,
|
|
25
|
+
TriggerType: () => TriggerType,
|
|
26
|
+
httpMethods: () => httpMethods
|
|
31
27
|
});
|
|
28
|
+
module.exports = __toCommonJS(types_exports);
|
|
32
29
|
var OperatorType;
|
|
33
30
|
(function(OperatorType2) {
|
|
34
31
|
OperatorType2[OperatorType2["Trigger"] = 0] = "Trigger";
|
|
@@ -66,3 +63,12 @@ var HttpMethod;
|
|
|
66
63
|
HttpMethod2["Head"] = "HEAD";
|
|
67
64
|
})(HttpMethod || (HttpMethod = {}));
|
|
68
65
|
const httpMethods = Object.values(HttpMethod);
|
|
66
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
67
|
+
0 && (module.exports = {
|
|
68
|
+
HttpMetadata,
|
|
69
|
+
HttpMethod,
|
|
70
|
+
OperatorType,
|
|
71
|
+
ResponseMetaType,
|
|
72
|
+
TriggerType,
|
|
73
|
+
httpMethods
|
|
74
|
+
});
|