@modern-js/plugin-express 2.6.0 → 2.8.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 +34 -0
- package/README.md +2 -2
- package/dist/cjs/plugin.js +2 -1
- package/dist/cjs/utils.js +20 -6
- package/dist/esm/plugin.js +3 -2
- package/dist/esm/utils.js +64 -17
- package/dist/esm-node/plugin.js +2 -1
- package/dist/esm-node/utils.js +21 -7
- package/package.json +13 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
1
|
# @modern-js/plugin-express
|
|
2
2
|
|
|
3
|
+
## 2.8.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [1104a9f18b]
|
|
8
|
+
- Updated dependencies [70d82e1408]
|
|
9
|
+
- Updated dependencies [4cfea8ce49]
|
|
10
|
+
- Updated dependencies [1f6ca2c7fb]
|
|
11
|
+
- @modern-js/utils@2.8.0
|
|
12
|
+
- @modern-js/types@2.8.0
|
|
13
|
+
- @modern-js/bff-core@2.8.0
|
|
14
|
+
- @modern-js/bff-runtime@2.8.0
|
|
15
|
+
|
|
16
|
+
## 2.7.0
|
|
17
|
+
|
|
18
|
+
### Minor Changes
|
|
19
|
+
|
|
20
|
+
- 84bfb439b8: feat: support custom apiDir, lambdaDir and style of writing for bff
|
|
21
|
+
feat: 支持定制 api 目录,lambda 目录,bff 的写法
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- Updated dependencies [0f15fc597c]
|
|
26
|
+
- Updated dependencies [dcad887024]
|
|
27
|
+
- Updated dependencies [a4672f7c16]
|
|
28
|
+
- Updated dependencies [7bb1554194]
|
|
29
|
+
- Updated dependencies [7fff9020e1]
|
|
30
|
+
- Updated dependencies [1eea234fdd]
|
|
31
|
+
- Updated dependencies [84bfb439b8]
|
|
32
|
+
- @modern-js/utils@2.7.0
|
|
33
|
+
- @modern-js/types@2.7.0
|
|
34
|
+
- @modern-js/bff-core@2.7.0
|
|
35
|
+
- @modern-js/bff-runtime@2.7.0
|
|
36
|
+
|
|
3
37
|
## 2.6.0
|
|
4
38
|
|
|
5
39
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -19,8 +19,8 @@ Please follow [Quick Start](https://modernjs.dev/en/guides/get-started/quick-sta
|
|
|
19
19
|
|
|
20
20
|
## Contributing
|
|
21
21
|
|
|
22
|
-
Please read the [Contributing Guide](https://github.com/
|
|
22
|
+
Please read the [Contributing Guide](https://github.com/web-infra-dev/modern.js/blob/main/CONTRIBUTING.md).
|
|
23
23
|
|
|
24
24
|
## License
|
|
25
25
|
|
|
26
|
-
Modern.js is [MIT licensed](https://github.com/
|
|
26
|
+
Modern.js is [MIT licensed](https://github.com/web-infra-dev/modern.js/blob/main/LICENSE).
|
package/dist/cjs/plugin.js
CHANGED
|
@@ -89,9 +89,10 @@ var plugin_default = () => ({
|
|
|
89
89
|
setup: (api) => ({
|
|
90
90
|
async prepareApiServer({ pwd, config }) {
|
|
91
91
|
let app;
|
|
92
|
-
const apiDir = path.join(pwd, "./api");
|
|
93
92
|
const appContext = api.useAppContext();
|
|
94
93
|
const apiHandlerInfos = appContext.apiHandlerInfos;
|
|
94
|
+
const apiDirectory = appContext.apiDirectory;
|
|
95
|
+
const apiDir = apiDirectory || path.join(pwd, "./api");
|
|
95
96
|
const mode = appContext.apiMode;
|
|
96
97
|
if (mode === "framework") {
|
|
97
98
|
const appModule = await findAppModule(apiDir);
|
package/dist/cjs/utils.js
CHANGED
|
@@ -62,6 +62,7 @@ const handleResponseMeta = (res, handler) => {
|
|
|
62
62
|
};
|
|
63
63
|
const createRouteHandler = (handler) => {
|
|
64
64
|
const apiHandler = async (req, res, next) => {
|
|
65
|
+
var _a;
|
|
65
66
|
const input = await getInputFromRequest(req);
|
|
66
67
|
if ((0, import_bff_core.isWithMetaHandler)(handler)) {
|
|
67
68
|
try {
|
|
@@ -95,19 +96,32 @@ const createRouteHandler = (handler) => {
|
|
|
95
96
|
res.status(200);
|
|
96
97
|
return res.json(result1.value);
|
|
97
98
|
}
|
|
98
|
-
} else {
|
|
99
|
-
const args = Object.values(input.params).concat(input);
|
|
99
|
+
} else if ((0, import_bff_core.isInputParamsDeciderHandler)(handler)) {
|
|
100
100
|
try {
|
|
101
|
+
const args = ((_a = input == null ? void 0 : input.data) == null ? void 0 : _a.args) || [];
|
|
101
102
|
const body = await handler(...args);
|
|
102
|
-
if (res.headersSent) {
|
|
103
|
-
return await Promise.resolve();
|
|
104
|
-
}
|
|
105
103
|
if (typeof body !== "undefined") {
|
|
106
|
-
|
|
104
|
+
if (typeof body === "object") {
|
|
105
|
+
return res.json(body);
|
|
106
|
+
}
|
|
107
|
+
return res.send(body);
|
|
107
108
|
}
|
|
108
109
|
} catch (e) {
|
|
109
110
|
return next(e);
|
|
110
111
|
}
|
|
112
|
+
} else {
|
|
113
|
+
const args1 = Object.values(input.params).concat(input);
|
|
114
|
+
try {
|
|
115
|
+
const body1 = await handler(...args1);
|
|
116
|
+
if (res.headersSent) {
|
|
117
|
+
return await Promise.resolve();
|
|
118
|
+
}
|
|
119
|
+
if (typeof body1 !== "undefined") {
|
|
120
|
+
return res.json(body1);
|
|
121
|
+
}
|
|
122
|
+
} catch (e1) {
|
|
123
|
+
return next(e1);
|
|
124
|
+
}
|
|
111
125
|
}
|
|
112
126
|
};
|
|
113
127
|
Object.defineProperties(apiHandler, Object.getOwnPropertyDescriptors(handler));
|
package/dist/esm/plugin.js
CHANGED
|
@@ -257,13 +257,14 @@ var plugin_default = function() {
|
|
|
257
257
|
prepareApiServer: function prepareApiServer(param) {
|
|
258
258
|
var pwd = param.pwd, config = param.config;
|
|
259
259
|
return _asyncToGenerator(function() {
|
|
260
|
-
var app,
|
|
260
|
+
var app, appContext, apiHandlerInfos, apiDirectory, apiDir, mode, appModule, hooks, middleware, afterLambdaRegisted, middleware1;
|
|
261
261
|
return __generator(this, function(_state) {
|
|
262
262
|
switch(_state.label){
|
|
263
263
|
case 0:
|
|
264
|
-
apiDir = path.join(pwd, "./api");
|
|
265
264
|
appContext = api.useAppContext();
|
|
266
265
|
apiHandlerInfos = appContext.apiHandlerInfos;
|
|
266
|
+
apiDirectory = appContext.apiDirectory;
|
|
267
|
+
apiDir = apiDirectory || path.join(pwd, "./api");
|
|
267
268
|
mode = appContext.apiMode;
|
|
268
269
|
if (!(mode === "framework")) return [
|
|
269
270
|
3,
|
package/dist/esm/utils.js
CHANGED
|
@@ -216,7 +216,7 @@ var __generator = this && this.__generator || function(thisArg, body) {
|
|
|
216
216
|
}
|
|
217
217
|
};
|
|
218
218
|
import "reflect-metadata";
|
|
219
|
-
import { httpMethods, isWithMetaHandler, HttpMetadata, ResponseMetaType, ValidationError } from "@modern-js/bff-core";
|
|
219
|
+
import { httpMethods, isWithMetaHandler, isInputParamsDeciderHandler, HttpMetadata, ResponseMetaType, ValidationError } from "@modern-js/bff-core";
|
|
220
220
|
import { isSchemaHandler } from "@modern-js/bff-runtime";
|
|
221
221
|
import typeIs from "type-is";
|
|
222
222
|
import formidable from "formidable";
|
|
@@ -281,7 +281,7 @@ var handleResponseMeta = function(res, handler) {
|
|
|
281
281
|
var createRouteHandler = function(handler) {
|
|
282
282
|
var apiHandler = function() {
|
|
283
283
|
var _ref = _asyncToGenerator(function(req, res, next) {
|
|
284
|
-
var input, result, error, result1, args, body, e;
|
|
284
|
+
var input, result, error, result1, _input_data, args, body, e, args1, body1, e1;
|
|
285
285
|
return __generator(this, function(_state) {
|
|
286
286
|
switch(_state.label){
|
|
287
287
|
case 0:
|
|
@@ -340,7 +340,7 @@ var createRouteHandler = function(handler) {
|
|
|
340
340
|
case 5:
|
|
341
341
|
return [
|
|
342
342
|
3,
|
|
343
|
-
|
|
343
|
+
19
|
|
344
344
|
];
|
|
345
345
|
case 6:
|
|
346
346
|
if (!isSchemaHandler(handler)) return [
|
|
@@ -372,55 +372,102 @@ var createRouteHandler = function(handler) {
|
|
|
372
372
|
}
|
|
373
373
|
return [
|
|
374
374
|
3,
|
|
375
|
-
|
|
375
|
+
19
|
|
376
376
|
];
|
|
377
377
|
case 8:
|
|
378
|
-
|
|
378
|
+
if (!isInputParamsDeciderHandler(handler)) return [
|
|
379
|
+
3,
|
|
380
|
+
13
|
|
381
|
+
];
|
|
379
382
|
_state.label = 9;
|
|
380
383
|
case 9:
|
|
381
384
|
_state.trys.push([
|
|
382
385
|
9,
|
|
383
|
-
|
|
386
|
+
11,
|
|
384
387
|
,
|
|
385
|
-
|
|
388
|
+
12
|
|
386
389
|
]);
|
|
390
|
+
args = (input === null || input === void 0 ? void 0 : (_input_data = input.data) === null || _input_data === void 0 ? void 0 : _input_data.args) || [];
|
|
387
391
|
return [
|
|
388
392
|
4,
|
|
389
393
|
handler.apply(void 0, _toConsumableArray(args))
|
|
390
394
|
];
|
|
391
395
|
case 10:
|
|
392
396
|
body = _state.sent();
|
|
393
|
-
if (
|
|
397
|
+
if (typeof body !== "undefined") {
|
|
398
|
+
if (typeof body === "object") {
|
|
399
|
+
return [
|
|
400
|
+
2,
|
|
401
|
+
res.json(body)
|
|
402
|
+
];
|
|
403
|
+
}
|
|
404
|
+
return [
|
|
405
|
+
2,
|
|
406
|
+
res.send(body)
|
|
407
|
+
];
|
|
408
|
+
}
|
|
409
|
+
return [
|
|
394
410
|
3,
|
|
395
411
|
12
|
|
396
412
|
];
|
|
413
|
+
case 11:
|
|
414
|
+
e = _state.sent();
|
|
415
|
+
return [
|
|
416
|
+
2,
|
|
417
|
+
next(e)
|
|
418
|
+
];
|
|
419
|
+
case 12:
|
|
420
|
+
return [
|
|
421
|
+
3,
|
|
422
|
+
19
|
|
423
|
+
];
|
|
424
|
+
case 13:
|
|
425
|
+
args1 = Object.values(input.params).concat(input);
|
|
426
|
+
_state.label = 14;
|
|
427
|
+
case 14:
|
|
428
|
+
_state.trys.push([
|
|
429
|
+
14,
|
|
430
|
+
18,
|
|
431
|
+
,
|
|
432
|
+
19
|
|
433
|
+
]);
|
|
434
|
+
return [
|
|
435
|
+
4,
|
|
436
|
+
handler.apply(void 0, _toConsumableArray(args1))
|
|
437
|
+
];
|
|
438
|
+
case 15:
|
|
439
|
+
body1 = _state.sent();
|
|
440
|
+
if (!res.headersSent) return [
|
|
441
|
+
3,
|
|
442
|
+
17
|
|
443
|
+
];
|
|
397
444
|
return [
|
|
398
445
|
4,
|
|
399
446
|
Promise.resolve()
|
|
400
447
|
];
|
|
401
|
-
case
|
|
448
|
+
case 16:
|
|
402
449
|
return [
|
|
403
450
|
2,
|
|
404
451
|
_state.sent()
|
|
405
452
|
];
|
|
406
|
-
case
|
|
407
|
-
if (typeof
|
|
453
|
+
case 17:
|
|
454
|
+
if (typeof body1 !== "undefined") {
|
|
408
455
|
return [
|
|
409
456
|
2,
|
|
410
|
-
res.json(
|
|
457
|
+
res.json(body1)
|
|
411
458
|
];
|
|
412
459
|
}
|
|
413
460
|
return [
|
|
414
461
|
3,
|
|
415
|
-
|
|
462
|
+
19
|
|
416
463
|
];
|
|
417
|
-
case
|
|
418
|
-
|
|
464
|
+
case 18:
|
|
465
|
+
e1 = _state.sent();
|
|
419
466
|
return [
|
|
420
467
|
2,
|
|
421
|
-
next(
|
|
468
|
+
next(e1)
|
|
422
469
|
];
|
|
423
|
-
case
|
|
470
|
+
case 19:
|
|
424
471
|
return [
|
|
425
472
|
2
|
|
426
473
|
];
|
package/dist/esm-node/plugin.js
CHANGED
|
@@ -57,9 +57,10 @@ var plugin_default = () => ({
|
|
|
57
57
|
setup: (api) => ({
|
|
58
58
|
async prepareApiServer({ pwd, config }) {
|
|
59
59
|
let app;
|
|
60
|
-
const apiDir = path.join(pwd, "./api");
|
|
61
60
|
const appContext = api.useAppContext();
|
|
62
61
|
const apiHandlerInfos = appContext.apiHandlerInfos;
|
|
62
|
+
const apiDirectory = appContext.apiDirectory;
|
|
63
|
+
const apiDir = apiDirectory || path.join(pwd, "./api");
|
|
63
64
|
const mode = appContext.apiMode;
|
|
64
65
|
if (mode === "framework") {
|
|
65
66
|
const appModule = await findAppModule(apiDir);
|
package/dist/esm-node/utils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
|
-
import { httpMethods, isWithMetaHandler, HttpMetadata, ResponseMetaType, ValidationError } from "@modern-js/bff-core";
|
|
2
|
+
import { httpMethods, isWithMetaHandler, isInputParamsDeciderHandler, HttpMetadata, ResponseMetaType, ValidationError } from "@modern-js/bff-core";
|
|
3
3
|
import { isSchemaHandler } from "@modern-js/bff-runtime";
|
|
4
4
|
import typeIs from "type-is";
|
|
5
5
|
import formidable from "formidable";
|
|
@@ -29,6 +29,7 @@ const handleResponseMeta = (res, handler) => {
|
|
|
29
29
|
};
|
|
30
30
|
const createRouteHandler = (handler) => {
|
|
31
31
|
const apiHandler = async (req, res, next) => {
|
|
32
|
+
var _a;
|
|
32
33
|
const input = await getInputFromRequest(req);
|
|
33
34
|
if (isWithMetaHandler(handler)) {
|
|
34
35
|
try {
|
|
@@ -62,19 +63,32 @@ const createRouteHandler = (handler) => {
|
|
|
62
63
|
res.status(200);
|
|
63
64
|
return res.json(result1.value);
|
|
64
65
|
}
|
|
65
|
-
} else {
|
|
66
|
-
const args = Object.values(input.params).concat(input);
|
|
66
|
+
} else if (isInputParamsDeciderHandler(handler)) {
|
|
67
67
|
try {
|
|
68
|
+
const args = ((_a = input == null ? void 0 : input.data) == null ? void 0 : _a.args) || [];
|
|
68
69
|
const body = await handler(...args);
|
|
69
|
-
if (res.headersSent) {
|
|
70
|
-
return await Promise.resolve();
|
|
71
|
-
}
|
|
72
70
|
if (typeof body !== "undefined") {
|
|
73
|
-
|
|
71
|
+
if (typeof body === "object") {
|
|
72
|
+
return res.json(body);
|
|
73
|
+
}
|
|
74
|
+
return res.send(body);
|
|
74
75
|
}
|
|
75
76
|
} catch (e) {
|
|
76
77
|
return next(e);
|
|
77
78
|
}
|
|
79
|
+
} else {
|
|
80
|
+
const args1 = Object.values(input.params).concat(input);
|
|
81
|
+
try {
|
|
82
|
+
const body1 = await handler(...args1);
|
|
83
|
+
if (res.headersSent) {
|
|
84
|
+
return await Promise.resolve();
|
|
85
|
+
}
|
|
86
|
+
if (typeof body1 !== "undefined") {
|
|
87
|
+
return res.json(body1);
|
|
88
|
+
}
|
|
89
|
+
} catch (e1) {
|
|
90
|
+
return next(e1);
|
|
91
|
+
}
|
|
78
92
|
}
|
|
79
93
|
};
|
|
80
94
|
Object.defineProperties(apiHandler, Object.getOwnPropertyDescriptors(handler));
|
package/package.json
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
"name": "@modern-js/plugin-express",
|
|
3
3
|
"description": "A Progressive React Framework for modern web development.",
|
|
4
4
|
"homepage": "https://modernjs.dev",
|
|
5
|
-
"bugs": "https://github.com/
|
|
6
|
-
"repository": "
|
|
5
|
+
"bugs": "https://github.com/web-infra-dev/modern.js/issues",
|
|
6
|
+
"repository": "web-infra-dev/modern.js",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"keywords": [
|
|
9
9
|
"react",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "2.
|
|
14
|
+
"version": "2.8.0",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/cli/index.d.ts",
|
|
17
17
|
"main": "./dist/cjs/cli/index.js",
|
|
@@ -42,10 +42,10 @@
|
|
|
42
42
|
"formidable": "^1.2.2",
|
|
43
43
|
"reflect-metadata": "^0.1.13",
|
|
44
44
|
"type-is": "^1.6.18",
|
|
45
|
-
"@modern-js/bff-core": "2.
|
|
46
|
-
"@modern-js/bff-runtime": "2.
|
|
47
|
-
"@modern-js/types": "2.
|
|
48
|
-
"@modern-js/utils": "2.
|
|
45
|
+
"@modern-js/bff-core": "2.8.0",
|
|
46
|
+
"@modern-js/bff-runtime": "2.8.0",
|
|
47
|
+
"@modern-js/types": "2.8.0",
|
|
48
|
+
"@modern-js/utils": "2.8.0"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/cookie-parser": "^1.4.2",
|
|
@@ -61,11 +61,11 @@
|
|
|
61
61
|
"supertest": "^6.1.6",
|
|
62
62
|
"typescript": "^4",
|
|
63
63
|
"zod": "^3.17.3",
|
|
64
|
-
"@modern-js/core": "2.
|
|
65
|
-
"@modern-js/app-tools": "2.
|
|
66
|
-
"@modern-js/server-core": "2.
|
|
67
|
-
"@scripts/
|
|
68
|
-
"@scripts/
|
|
64
|
+
"@modern-js/core": "2.8.0",
|
|
65
|
+
"@modern-js/app-tools": "2.8.0",
|
|
66
|
+
"@modern-js/server-core": "2.8.0",
|
|
67
|
+
"@scripts/build": "2.8.0",
|
|
68
|
+
"@scripts/jest-config": "2.8.0"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
71
|
"express": "^4.17.1"
|
|
@@ -76,6 +76,7 @@
|
|
|
76
76
|
},
|
|
77
77
|
"scripts": {
|
|
78
78
|
"new": "modern-lib new",
|
|
79
|
+
"dev": "modern-lib build --watch",
|
|
79
80
|
"build": "modern-lib build",
|
|
80
81
|
"test": "jest --passWithNoTests"
|
|
81
82
|
}
|