@modern-js/bff-core 2.35.1 → 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 +94 -65
- 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 +4 -1
- 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,15 +117,15 @@ 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
131
|
routePath += `${handler === null || handler === void 0 ? void 0 : handler.name}`;
|
|
@@ -114,8 +137,8 @@ class ApiRouter {
|
|
|
114
137
|
}
|
|
115
138
|
getHttpMethod(originHandlerName, handler) {
|
|
116
139
|
if (handler) {
|
|
117
|
-
const trigger = Reflect.getMetadata(
|
|
118
|
-
if (trigger &&
|
|
140
|
+
const trigger = Reflect.getMetadata(import_types.OperatorType.Trigger, handler);
|
|
141
|
+
if (trigger && import_types.httpMethods.includes(trigger.method)) {
|
|
119
142
|
return trigger.method;
|
|
120
143
|
}
|
|
121
144
|
}
|
|
@@ -123,28 +146,28 @@ class ApiRouter {
|
|
|
123
146
|
const upperName = originHandlerName.toUpperCase();
|
|
124
147
|
switch (upperName) {
|
|
125
148
|
case "GET":
|
|
126
|
-
return
|
|
149
|
+
return import_types.HttpMethod.Get;
|
|
127
150
|
case "POST":
|
|
128
|
-
return
|
|
151
|
+
return import_types.HttpMethod.Post;
|
|
129
152
|
case "PUT":
|
|
130
|
-
return
|
|
153
|
+
return import_types.HttpMethod.Put;
|
|
131
154
|
case "DELETE":
|
|
132
155
|
case "DEL":
|
|
133
|
-
return
|
|
156
|
+
return import_types.HttpMethod.Delete;
|
|
134
157
|
case "CONNECT":
|
|
135
|
-
return
|
|
158
|
+
return import_types.HttpMethod.Connect;
|
|
136
159
|
case "TRACE":
|
|
137
|
-
return
|
|
160
|
+
return import_types.HttpMethod.Trace;
|
|
138
161
|
case "PATCH":
|
|
139
|
-
return
|
|
162
|
+
return import_types.HttpMethod.Patch;
|
|
140
163
|
case "OPTIONS":
|
|
141
|
-
return
|
|
164
|
+
return import_types.HttpMethod.Options;
|
|
142
165
|
case "DEFAULT": {
|
|
143
|
-
return
|
|
166
|
+
return import_types.HttpMethod.Get;
|
|
144
167
|
}
|
|
145
168
|
default:
|
|
146
169
|
if (process.env.NODE_ENV !== "test") {
|
|
147
|
-
|
|
170
|
+
import_utils.logger.warn(`Only api handlers are allowd to be exported, please remove the function ${originHandlerName} from exports`);
|
|
148
171
|
}
|
|
149
172
|
return null;
|
|
150
173
|
}
|
|
@@ -153,16 +176,16 @@ class ApiRouter {
|
|
|
153
176
|
return null;
|
|
154
177
|
}
|
|
155
178
|
if (typeof handler === "function" && handler.length > 0) {
|
|
156
|
-
return
|
|
179
|
+
return import_types.HttpMethod.Post;
|
|
157
180
|
}
|
|
158
|
-
return
|
|
181
|
+
return import_types.HttpMethod.Get;
|
|
159
182
|
}
|
|
160
183
|
}
|
|
161
184
|
loadApiFiles() {
|
|
162
185
|
if (!this.existLambdaDir) {
|
|
163
186
|
return [];
|
|
164
187
|
}
|
|
165
|
-
const apiFiles = this.apiFiles = (0,
|
|
188
|
+
const apiFiles = this.apiFiles = (0, import_utils3.getFiles)(this.lambdaDir, import_constants.API_FILE_RULES);
|
|
166
189
|
return apiFiles;
|
|
167
190
|
}
|
|
168
191
|
getApiFiles() {
|
|
@@ -178,7 +201,7 @@ class ApiRouter {
|
|
|
178
201
|
const filenames = this.getApiFiles();
|
|
179
202
|
const moduleInfos = this.getModuleInfos(filenames);
|
|
180
203
|
const apiHandlers = this.getHandlerInfos(moduleInfos);
|
|
181
|
-
(0,
|
|
204
|
+
(0, import_utils2.debug)("apiHandlers", apiHandlers.length, apiHandlers);
|
|
182
205
|
return apiHandlers;
|
|
183
206
|
}
|
|
184
207
|
/**
|
|
@@ -192,7 +215,7 @@ class ApiRouter {
|
|
|
192
215
|
return prefix || "/api";
|
|
193
216
|
}
|
|
194
217
|
validateAbsolute(filename, paramsName) {
|
|
195
|
-
if (typeof filename === "string" && !
|
|
218
|
+
if (typeof filename === "string" && !import_path.default.isAbsolute(filename)) {
|
|
196
219
|
throw new Error(`The ${paramsName} ${filename} is not a abolute path`);
|
|
197
220
|
}
|
|
198
221
|
}
|
|
@@ -201,10 +224,10 @@ class ApiRouter {
|
|
|
201
224
|
}
|
|
202
225
|
getModuleInfo(filename) {
|
|
203
226
|
try {
|
|
204
|
-
const
|
|
227
|
+
const module2 = (0, import_utils3.requireHandlerModule)(filename);
|
|
205
228
|
return {
|
|
206
229
|
filename,
|
|
207
|
-
module
|
|
230
|
+
module: module2
|
|
208
231
|
};
|
|
209
232
|
} catch (err) {
|
|
210
233
|
if (process.env.NODE_ENV === "production") {
|
|
@@ -223,17 +246,17 @@ class ApiRouter {
|
|
|
223
246
|
apiHandlers = apiHandlers.concat(handlerInfos);
|
|
224
247
|
}
|
|
225
248
|
});
|
|
226
|
-
const sortedHandlers = (0,
|
|
249
|
+
const sortedHandlers = (0, import_utils3.sortRoutes)(apiHandlers);
|
|
227
250
|
return sortedHandlers;
|
|
228
251
|
}
|
|
229
252
|
getModuleHandlerInfos(moduleInfo) {
|
|
230
|
-
const { module, filename } = moduleInfo;
|
|
253
|
+
const { module: module2, filename } = moduleInfo;
|
|
231
254
|
const { httpMethodDecider } = this;
|
|
232
|
-
return Object.entries(
|
|
233
|
-
const handler =
|
|
255
|
+
return Object.entries(module2).filter(([, handler]) => typeof handler === "function").map(([key]) => {
|
|
256
|
+
const handler = module2[key];
|
|
234
257
|
if (httpMethodDecider === "inputParams") {
|
|
235
258
|
Object.assign(handler, {
|
|
236
|
-
[
|
|
259
|
+
[import_utils2.INPUT_PARAMS_DECIDER]: true
|
|
237
260
|
});
|
|
238
261
|
}
|
|
239
262
|
const handlerInfo = this.getHandlerInfo(filename, key, handler);
|
|
@@ -253,31 +276,31 @@ class ApiRouter {
|
|
|
253
276
|
return `${prefix}${finalRouteName}`;
|
|
254
277
|
}
|
|
255
278
|
constructor({ appDir, apiDir, lambdaDir, prefix, isBuild, httpMethodDecider = "functionName" }) {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
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) => {
|
|
266
289
|
const exist = this.createExistChecker(apiDir2);
|
|
267
|
-
const existLambdaDir = lambdaDir2 &&
|
|
268
|
-
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);
|
|
269
292
|
const existAppFile = exist("app.ts") || exist("app.js");
|
|
270
293
|
if (existLambdaDir || existAppDir || existAppFile) {
|
|
271
|
-
return
|
|
294
|
+
return import_constants.APIMode.FARMEWORK;
|
|
272
295
|
}
|
|
273
|
-
return
|
|
296
|
+
return import_constants.APIMode.FUNCTION;
|
|
274
297
|
});
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
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) {
|
|
278
301
|
return apiDir2;
|
|
279
302
|
}
|
|
280
|
-
return originLambdaDir ||
|
|
303
|
+
return originLambdaDir || import_path.default.join(apiDir2, import_constants.FRAMEWORK_MODE_LAMBDA_DIR);
|
|
281
304
|
});
|
|
282
305
|
this.validateAbsolute(apiDir, "apiDir");
|
|
283
306
|
this.validateAbsolute(lambdaDir, "lambdaDir");
|
|
@@ -288,8 +311,14 @@ class ApiRouter {
|
|
|
288
311
|
this.isBuild = isBuild;
|
|
289
312
|
this.apiMode = this.getExactApiMode(apiDir, lambdaDir);
|
|
290
313
|
this.lambdaDir = this.getExactLambdaDir(this.apiDir, lambdaDir);
|
|
291
|
-
this.existLambdaDir =
|
|
292
|
-
(0,
|
|
314
|
+
this.existLambdaDir = import_utils.fs.existsSync(this.lambdaDir);
|
|
315
|
+
(0, import_utils2.debug)(`apiDir:`, this.apiDir, `lambdaDir:`, this.lambdaDir);
|
|
293
316
|
this.enableRegister();
|
|
294
317
|
}
|
|
295
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
|
+
});
|