@modern-js/plugin-express 2.0.0-beta.4 → 2.0.0-beta.6
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 +45 -0
- package/dist/js/modern/cli/index.js +12 -16
- package/dist/js/modern/plugin.js +24 -11
- package/dist/js/modern/utils.js +20 -24
- package/dist/js/node/cli/index.js +17 -19
- package/dist/js/node/context.js +8 -3
- package/dist/js/node/index.js +6 -4
- package/dist/js/node/plugin.js +38 -23
- package/dist/js/node/registerRoutes.js +5 -3
- package/dist/js/node/runtime/hook.js +7 -3
- package/dist/js/node/runtime/index.js +10 -5
- package/dist/js/node/runtime/operators.js +12 -7
- package/dist/js/node/utils.js +49 -44
- package/dist/js/treeshaking/cli/index.js +9 -0
- package/dist/types/cli/index.d.ts +2 -1
- package/package.json +22 -17
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,50 @@
|
|
|
1
1
|
# @modern-js/plugin-express
|
|
2
2
|
|
|
3
|
+
## 2.0.0-beta.6
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- dda38c9c3e: chore: v2
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 8d24bed25b: fix: compat Hook API in /server namespace
|
|
12
|
+
fix: 在 @modern-js/runtime/server 命名空间下兼容 Hook API
|
|
13
|
+
- 3bbea92b2a: feat: support Hook、Middleware new API
|
|
14
|
+
feat: 支持 Hook、Middleware 的新 API
|
|
15
|
+
- Updated dependencies [7879e8f711]
|
|
16
|
+
- Updated dependencies [6aca875011]
|
|
17
|
+
- Updated dependencies [2e6031955e]
|
|
18
|
+
- Updated dependencies [2344eb26ed]
|
|
19
|
+
- Updated dependencies [a2509bfbdb]
|
|
20
|
+
- Updated dependencies [7b7d12cf8f]
|
|
21
|
+
- Updated dependencies [7efeed4]
|
|
22
|
+
- Updated dependencies [92f0eade39]
|
|
23
|
+
- Updated dependencies [edd1cfb1af]
|
|
24
|
+
- Updated dependencies [cc971eabfc]
|
|
25
|
+
- Updated dependencies [5b9049f2e9]
|
|
26
|
+
- Updated dependencies [6bda14ed71]
|
|
27
|
+
- Updated dependencies [92004d1906]
|
|
28
|
+
- Updated dependencies [b8bbe036c7]
|
|
29
|
+
- Updated dependencies [40ed5874c6]
|
|
30
|
+
- Updated dependencies [87c1ff86b9]
|
|
31
|
+
- Updated dependencies [d5a31df781]
|
|
32
|
+
- Updated dependencies [dda38c9c3e]
|
|
33
|
+
- Updated dependencies [102d32e4ba]
|
|
34
|
+
- Updated dependencies [8b8e1bb571]
|
|
35
|
+
- Updated dependencies [3bbea92b2a]
|
|
36
|
+
- Updated dependencies [b710adb843]
|
|
37
|
+
- Updated dependencies [ea7cf06257]
|
|
38
|
+
- Updated dependencies [bbe4c4ab64]
|
|
39
|
+
- Updated dependencies [e4558a0bc4]
|
|
40
|
+
- Updated dependencies [abf3421a75]
|
|
41
|
+
- Updated dependencies [543be9558e]
|
|
42
|
+
- Updated dependencies [14b712da84]
|
|
43
|
+
- @modern-js/types@2.0.0-beta.6
|
|
44
|
+
- @modern-js/utils@2.0.0-beta.6
|
|
45
|
+
- @modern-js/bff-core@2.0.0-beta.6
|
|
46
|
+
- @modern-js/bff-runtime@2.0.0-beta.6
|
|
47
|
+
|
|
3
48
|
## 2.0.0-beta.4
|
|
4
49
|
|
|
5
50
|
### Major Changes
|
|
@@ -11,15 +11,9 @@ var cli_default = () => ({
|
|
|
11
11
|
config() {
|
|
12
12
|
const appContext = useAppContext();
|
|
13
13
|
const { appDirectory } = appContext;
|
|
14
|
-
bffExportsUtils = createRuntimeExportsUtils(
|
|
15
|
-
appContext.internalDirectory,
|
|
16
|
-
"server"
|
|
17
|
-
);
|
|
14
|
+
bffExportsUtils = createRuntimeExportsUtils(appContext.internalDirectory, "server");
|
|
18
15
|
const serverRuntimePath = bffExportsUtils.getPath();
|
|
19
|
-
const relativeRuntimePath = getRelativeRuntimePath(
|
|
20
|
-
appDirectory,
|
|
21
|
-
serverRuntimePath
|
|
22
|
-
);
|
|
16
|
+
const relativeRuntimePath = getRelativeRuntimePath(appDirectory, serverRuntimePath);
|
|
23
17
|
if (process.env.NODE_ENV === "production") {
|
|
24
18
|
return {
|
|
25
19
|
source: {
|
|
@@ -40,16 +34,18 @@ var cli_default = () => ({
|
|
|
40
34
|
};
|
|
41
35
|
}
|
|
42
36
|
},
|
|
37
|
+
collectServerPlugins({ plugins }) {
|
|
38
|
+
plugins.push({
|
|
39
|
+
"@modern-js/plugin-express": "@modern-js/plugin-express/server"
|
|
40
|
+
});
|
|
41
|
+
return {
|
|
42
|
+
plugins
|
|
43
|
+
};
|
|
44
|
+
},
|
|
43
45
|
addRuntimeExports(input) {
|
|
44
46
|
const currentFile = bffExportsUtils.getPath();
|
|
45
|
-
const relativeRuntimeModulePath = path.relative(
|
|
46
|
-
|
|
47
|
-
runtimeModulePath
|
|
48
|
-
);
|
|
49
|
-
const relativeFramePath = path.relative(
|
|
50
|
-
path.dirname(currentFile),
|
|
51
|
-
require.resolve("express")
|
|
52
|
-
);
|
|
47
|
+
const relativeRuntimeModulePath = path.relative(path.dirname(currentFile), runtimeModulePath);
|
|
48
|
+
const relativeFramePath = path.relative(path.dirname(currentFile), require.resolve("express"));
|
|
53
49
|
bffExportsUtils.addExport(`const pluginRuntime = require('${relativeRuntimeModulePath}');
|
|
54
50
|
const express = require('${relativeFramePath}')
|
|
55
51
|
module.exports = {
|
package/dist/js/modern/plugin.js
CHANGED
|
@@ -27,12 +27,18 @@ import { run } from "./context";
|
|
|
27
27
|
import registerRoutes from "./registerRoutes";
|
|
28
28
|
const debug = createDebugger("express");
|
|
29
29
|
const findAppModule = (apiDir) => __async(void 0, null, function* () {
|
|
30
|
-
const exts = [
|
|
30
|
+
const exts = [
|
|
31
|
+
".ts",
|
|
32
|
+
".js"
|
|
33
|
+
];
|
|
31
34
|
const paths = exts.map((ext) => path.resolve(apiDir, `app${ext}`));
|
|
32
35
|
for (const filename of paths) {
|
|
33
36
|
if (yield fs.pathExists(filename)) {
|
|
34
37
|
delete require.cache[filename];
|
|
35
|
-
return [
|
|
38
|
+
return [
|
|
39
|
+
compatRequire(filename),
|
|
40
|
+
require(filename)
|
|
41
|
+
];
|
|
36
42
|
}
|
|
37
43
|
}
|
|
38
44
|
return [];
|
|
@@ -45,20 +51,29 @@ const initMiddlewares = (middleware, app) => {
|
|
|
45
51
|
};
|
|
46
52
|
const useRun = (app) => {
|
|
47
53
|
app.use((req, res, next) => {
|
|
48
|
-
run({
|
|
54
|
+
run({
|
|
55
|
+
req,
|
|
56
|
+
res
|
|
57
|
+
}, next);
|
|
49
58
|
});
|
|
50
59
|
};
|
|
51
60
|
const initApp = (app) => {
|
|
52
61
|
app.use(cookieParser());
|
|
53
62
|
app.use(express.text());
|
|
54
|
-
app.use(express.urlencoded({
|
|
63
|
+
app.use(express.urlencoded({
|
|
64
|
+
extended: true
|
|
65
|
+
}));
|
|
55
66
|
app.use(express.json());
|
|
56
67
|
return app;
|
|
57
68
|
};
|
|
58
69
|
var plugin_default = () => ({
|
|
59
70
|
name: "@modern-js/plugin-express",
|
|
60
|
-
pre: [
|
|
61
|
-
|
|
71
|
+
pre: [
|
|
72
|
+
"@modern-js/plugin-bff"
|
|
73
|
+
],
|
|
74
|
+
post: [
|
|
75
|
+
"@modern-js/plugin-server"
|
|
76
|
+
],
|
|
62
77
|
setup: (api) => ({
|
|
63
78
|
prepareApiServer(_0) {
|
|
64
79
|
return __async(this, arguments, function* ({ pwd, config }) {
|
|
@@ -91,8 +106,8 @@ var plugin_default = () => ({
|
|
|
91
106
|
app = express();
|
|
92
107
|
initApp(app);
|
|
93
108
|
if (config) {
|
|
94
|
-
const { middleware } = config;
|
|
95
|
-
initMiddlewares(
|
|
109
|
+
const { middleware: middleware1 } = config;
|
|
110
|
+
initMiddlewares(middleware1, app);
|
|
96
111
|
}
|
|
97
112
|
useRun(app);
|
|
98
113
|
registerRoutes(app, apiHandlerInfos);
|
|
@@ -130,9 +145,7 @@ var plugin_default = () => ({
|
|
|
130
145
|
initMiddlewares(middleware, app);
|
|
131
146
|
}
|
|
132
147
|
return (ctx) => new Promise((resolve, reject) => {
|
|
133
|
-
const {
|
|
134
|
-
source: { req, res }
|
|
135
|
-
} = ctx;
|
|
148
|
+
const { source: { req, res } } = ctx;
|
|
136
149
|
const handler = (err) => {
|
|
137
150
|
if (err) {
|
|
138
151
|
return reject(err);
|
package/dist/js/modern/utils.js
CHANGED
|
@@ -35,21 +35,12 @@ var __async = (__this, __arguments, generator) => {
|
|
|
35
35
|
});
|
|
36
36
|
};
|
|
37
37
|
import "reflect-metadata";
|
|
38
|
-
import {
|
|
39
|
-
httpMethods,
|
|
40
|
-
isWithMetaHandler,
|
|
41
|
-
HttpMetadata,
|
|
42
|
-
ResponseMetaType,
|
|
43
|
-
ValidationError
|
|
44
|
-
} from "@modern-js/bff-core";
|
|
38
|
+
import { httpMethods, isWithMetaHandler, HttpMetadata, ResponseMetaType, ValidationError } from "@modern-js/bff-core";
|
|
45
39
|
import { isSchemaHandler } from "@modern-js/bff-runtime";
|
|
46
40
|
import typeIs from "type-is";
|
|
47
41
|
import formidable from "formidable";
|
|
48
42
|
const handleResponseMeta = (res, handler) => {
|
|
49
|
-
const responseMeta = Reflect.getMetadata(
|
|
50
|
-
HttpMetadata.Response,
|
|
51
|
-
handler
|
|
52
|
-
);
|
|
43
|
+
const responseMeta = Reflect.getMetadata(HttpMetadata.Response, handler);
|
|
53
44
|
if (Array.isArray(responseMeta)) {
|
|
54
45
|
for (const meta of responseMeta) {
|
|
55
46
|
const metaType = meta.type;
|
|
@@ -95,17 +86,17 @@ const createRouteHandler = (handler) => {
|
|
|
95
86
|
throw error;
|
|
96
87
|
}
|
|
97
88
|
} else if (isSchemaHandler(handler)) {
|
|
98
|
-
const
|
|
99
|
-
if (
|
|
100
|
-
if (
|
|
89
|
+
const result1 = yield handler(input);
|
|
90
|
+
if (result1.type !== "HandleSuccess") {
|
|
91
|
+
if (result1.type === "InputValidationError") {
|
|
101
92
|
res.status(400);
|
|
102
93
|
} else {
|
|
103
94
|
res.status(500);
|
|
104
95
|
}
|
|
105
|
-
return res.json(
|
|
96
|
+
return res.json(result1.message);
|
|
106
97
|
} else {
|
|
107
98
|
res.status(200);
|
|
108
|
-
return res.json(
|
|
99
|
+
return res.json(result1.value);
|
|
109
100
|
}
|
|
110
101
|
} else {
|
|
111
102
|
const args = Object.values(input.params).concat(input);
|
|
@@ -122,10 +113,7 @@ const createRouteHandler = (handler) => {
|
|
|
122
113
|
}
|
|
123
114
|
}
|
|
124
115
|
});
|
|
125
|
-
Object.defineProperties(
|
|
126
|
-
apiHandler,
|
|
127
|
-
Object.getOwnPropertyDescriptors(handler)
|
|
128
|
-
);
|
|
116
|
+
Object.defineProperties(apiHandler, Object.getOwnPropertyDescriptors(handler));
|
|
129
117
|
return apiHandler;
|
|
130
118
|
};
|
|
131
119
|
const isNormalMethod = (httpMethod) => httpMethods.includes(httpMethod);
|
|
@@ -136,11 +124,17 @@ const getInputFromRequest = (request) => __async(void 0, null, function* () {
|
|
|
136
124
|
headers: request.headers,
|
|
137
125
|
cookies: request.headers.cookie
|
|
138
126
|
};
|
|
139
|
-
if (typeIs(request, [
|
|
127
|
+
if (typeIs(request, [
|
|
128
|
+
"application/json"
|
|
129
|
+
])) {
|
|
140
130
|
draft.data = request.body;
|
|
141
|
-
} else if (typeIs(request, [
|
|
131
|
+
} else if (typeIs(request, [
|
|
132
|
+
"multipart/form-data"
|
|
133
|
+
])) {
|
|
142
134
|
draft.formData = yield resolveFormData(request);
|
|
143
|
-
} else if (typeIs(request, [
|
|
135
|
+
} else if (typeIs(request, [
|
|
136
|
+
"application/x-www-form-urlencoded"
|
|
137
|
+
])) {
|
|
144
138
|
draft.formUrlencoded = request.body;
|
|
145
139
|
} else {
|
|
146
140
|
draft.body = request.body;
|
|
@@ -148,7 +142,9 @@ const getInputFromRequest = (request) => __async(void 0, null, function* () {
|
|
|
148
142
|
return draft;
|
|
149
143
|
});
|
|
150
144
|
const resolveFormData = (request) => {
|
|
151
|
-
const form = formidable({
|
|
145
|
+
const form = formidable({
|
|
146
|
+
multiples: true
|
|
147
|
+
});
|
|
152
148
|
return new Promise((resolve, reject) => {
|
|
153
149
|
form.parse(request, (err, fields, files) => {
|
|
154
150
|
if (err) {
|
|
@@ -21,11 +21,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
21
|
mod
|
|
22
22
|
));
|
|
23
23
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
-
var
|
|
25
|
-
__export(
|
|
24
|
+
var cli_exports = {};
|
|
25
|
+
__export(cli_exports, {
|
|
26
26
|
default: () => cli_default
|
|
27
27
|
});
|
|
28
|
-
module.exports = __toCommonJS(
|
|
28
|
+
module.exports = __toCommonJS(cli_exports);
|
|
29
29
|
var path = __toESM(require("path"));
|
|
30
30
|
var import_utils = require("@modern-js/utils");
|
|
31
31
|
var import_bff_core = require("@modern-js/bff-core");
|
|
@@ -39,15 +39,9 @@ var cli_default = () => ({
|
|
|
39
39
|
config() {
|
|
40
40
|
const appContext = useAppContext();
|
|
41
41
|
const { appDirectory } = appContext;
|
|
42
|
-
bffExportsUtils = (0, import_utils.createRuntimeExportsUtils)(
|
|
43
|
-
appContext.internalDirectory,
|
|
44
|
-
"server"
|
|
45
|
-
);
|
|
42
|
+
bffExportsUtils = (0, import_utils.createRuntimeExportsUtils)(appContext.internalDirectory, "server");
|
|
46
43
|
const serverRuntimePath = bffExportsUtils.getPath();
|
|
47
|
-
const relativeRuntimePath = (0, import_bff_core.getRelativeRuntimePath)(
|
|
48
|
-
appDirectory,
|
|
49
|
-
serverRuntimePath
|
|
50
|
-
);
|
|
44
|
+
const relativeRuntimePath = (0, import_bff_core.getRelativeRuntimePath)(appDirectory, serverRuntimePath);
|
|
51
45
|
if (process.env.NODE_ENV === "production") {
|
|
52
46
|
return {
|
|
53
47
|
source: {
|
|
@@ -68,16 +62,18 @@ var cli_default = () => ({
|
|
|
68
62
|
};
|
|
69
63
|
}
|
|
70
64
|
},
|
|
65
|
+
collectServerPlugins({ plugins }) {
|
|
66
|
+
plugins.push({
|
|
67
|
+
"@modern-js/plugin-express": "@modern-js/plugin-express/server"
|
|
68
|
+
});
|
|
69
|
+
return {
|
|
70
|
+
plugins
|
|
71
|
+
};
|
|
72
|
+
},
|
|
71
73
|
addRuntimeExports(input) {
|
|
72
74
|
const currentFile = bffExportsUtils.getPath();
|
|
73
|
-
const relativeRuntimeModulePath = path.relative(
|
|
74
|
-
|
|
75
|
-
runtimeModulePath
|
|
76
|
-
);
|
|
77
|
-
const relativeFramePath = path.relative(
|
|
78
|
-
path.dirname(currentFile),
|
|
79
|
-
require.resolve("express")
|
|
80
|
-
);
|
|
75
|
+
const relativeRuntimeModulePath = path.relative(path.dirname(currentFile), runtimeModulePath);
|
|
76
|
+
const relativeFramePath = path.relative(path.dirname(currentFile), require.resolve("express"));
|
|
81
77
|
bffExportsUtils.addExport(`const pluginRuntime = require('${relativeRuntimeModulePath}');
|
|
82
78
|
const express = require('${relativeFramePath}')
|
|
83
79
|
module.exports = {
|
|
@@ -90,3 +86,5 @@ var cli_default = () => ({
|
|
|
90
86
|
};
|
|
91
87
|
}
|
|
92
88
|
});
|
|
89
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
90
|
+
0 && (module.exports = {});
|
package/dist/js/node/context.js
CHANGED
|
@@ -15,11 +15,16 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
15
|
return to;
|
|
16
16
|
};
|
|
17
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var
|
|
19
|
-
__export(
|
|
18
|
+
var context_exports = {};
|
|
19
|
+
__export(context_exports, {
|
|
20
20
|
run: () => run,
|
|
21
21
|
useContext: () => useContext
|
|
22
22
|
});
|
|
23
|
-
module.exports = __toCommonJS(
|
|
23
|
+
module.exports = __toCommonJS(context_exports);
|
|
24
24
|
var import_bff_core = require("@modern-js/bff-core");
|
|
25
25
|
const { run, useContext } = (0, import_bff_core.createStorage)();
|
|
26
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
27
|
+
0 && (module.exports = {
|
|
28
|
+
run,
|
|
29
|
+
useContext
|
|
30
|
+
});
|
package/dist/js/node/index.js
CHANGED
|
@@ -22,11 +22,13 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
22
|
mod
|
|
23
23
|
));
|
|
24
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
-
var
|
|
26
|
-
__export(
|
|
25
|
+
var src_exports = {};
|
|
26
|
+
__export(src_exports, {
|
|
27
27
|
default: () => src_default
|
|
28
28
|
});
|
|
29
|
-
module.exports = __toCommonJS(
|
|
29
|
+
module.exports = __toCommonJS(src_exports);
|
|
30
30
|
var import_plugin = __toESM(require("./plugin"));
|
|
31
|
-
__reExport(
|
|
31
|
+
__reExport(src_exports, require("./context"), module.exports);
|
|
32
32
|
var src_default = import_plugin.default;
|
|
33
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
34
|
+
0 && (module.exports = {});
|
package/dist/js/node/plugin.js
CHANGED
|
@@ -21,18 +21,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
21
|
mod
|
|
22
22
|
));
|
|
23
23
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
-
var stdin_exports = {};
|
|
25
|
-
__export(stdin_exports, {
|
|
26
|
-
default: () => plugin_default
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(stdin_exports);
|
|
29
|
-
var path = __toESM(require("path"));
|
|
30
|
-
var import_express = __toESM(require("express"));
|
|
31
|
-
var import_cookie_parser = __toESM(require("cookie-parser"));
|
|
32
|
-
var import_utils = require("@modern-js/utils");
|
|
33
|
-
var import_finalhandler = __toESM(require("finalhandler"));
|
|
34
|
-
var import_context = require("./context");
|
|
35
|
-
var import_registerRoutes = __toESM(require("./registerRoutes"));
|
|
36
24
|
var __async = (__this, __arguments, generator) => {
|
|
37
25
|
return new Promise((resolve, reject) => {
|
|
38
26
|
var fulfilled = (value) => {
|
|
@@ -53,14 +41,32 @@ var __async = (__this, __arguments, generator) => {
|
|
|
53
41
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
54
42
|
});
|
|
55
43
|
};
|
|
44
|
+
var plugin_exports = {};
|
|
45
|
+
__export(plugin_exports, {
|
|
46
|
+
default: () => plugin_default
|
|
47
|
+
});
|
|
48
|
+
module.exports = __toCommonJS(plugin_exports);
|
|
49
|
+
var path = __toESM(require("path"));
|
|
50
|
+
var import_express = __toESM(require("express"));
|
|
51
|
+
var import_cookie_parser = __toESM(require("cookie-parser"));
|
|
52
|
+
var import_utils = require("@modern-js/utils");
|
|
53
|
+
var import_finalhandler = __toESM(require("finalhandler"));
|
|
54
|
+
var import_context = require("./context");
|
|
55
|
+
var import_registerRoutes = __toESM(require("./registerRoutes"));
|
|
56
56
|
const debug = (0, import_utils.createDebugger)("express");
|
|
57
57
|
const findAppModule = (apiDir) => __async(void 0, null, function* () {
|
|
58
|
-
const exts = [
|
|
58
|
+
const exts = [
|
|
59
|
+
".ts",
|
|
60
|
+
".js"
|
|
61
|
+
];
|
|
59
62
|
const paths = exts.map((ext) => path.resolve(apiDir, `app${ext}`));
|
|
60
63
|
for (const filename of paths) {
|
|
61
64
|
if (yield import_utils.fs.pathExists(filename)) {
|
|
62
65
|
delete require.cache[filename];
|
|
63
|
-
return [
|
|
66
|
+
return [
|
|
67
|
+
(0, import_utils.compatRequire)(filename),
|
|
68
|
+
require(filename)
|
|
69
|
+
];
|
|
64
70
|
}
|
|
65
71
|
}
|
|
66
72
|
return [];
|
|
@@ -73,20 +79,29 @@ const initMiddlewares = (middleware, app) => {
|
|
|
73
79
|
};
|
|
74
80
|
const useRun = (app) => {
|
|
75
81
|
app.use((req, res, next) => {
|
|
76
|
-
(0, import_context.run)({
|
|
82
|
+
(0, import_context.run)({
|
|
83
|
+
req,
|
|
84
|
+
res
|
|
85
|
+
}, next);
|
|
77
86
|
});
|
|
78
87
|
};
|
|
79
88
|
const initApp = (app) => {
|
|
80
89
|
app.use((0, import_cookie_parser.default)());
|
|
81
90
|
app.use(import_express.default.text());
|
|
82
|
-
app.use(import_express.default.urlencoded({
|
|
91
|
+
app.use(import_express.default.urlencoded({
|
|
92
|
+
extended: true
|
|
93
|
+
}));
|
|
83
94
|
app.use(import_express.default.json());
|
|
84
95
|
return app;
|
|
85
96
|
};
|
|
86
97
|
var plugin_default = () => ({
|
|
87
98
|
name: "@modern-js/plugin-express",
|
|
88
|
-
pre: [
|
|
89
|
-
|
|
99
|
+
pre: [
|
|
100
|
+
"@modern-js/plugin-bff"
|
|
101
|
+
],
|
|
102
|
+
post: [
|
|
103
|
+
"@modern-js/plugin-server"
|
|
104
|
+
],
|
|
90
105
|
setup: (api) => ({
|
|
91
106
|
prepareApiServer(_0) {
|
|
92
107
|
return __async(this, arguments, function* ({ pwd, config }) {
|
|
@@ -119,8 +134,8 @@ var plugin_default = () => ({
|
|
|
119
134
|
app = (0, import_express.default)();
|
|
120
135
|
initApp(app);
|
|
121
136
|
if (config) {
|
|
122
|
-
const { middleware } = config;
|
|
123
|
-
initMiddlewares(
|
|
137
|
+
const { middleware: middleware1 } = config;
|
|
138
|
+
initMiddlewares(middleware1, app);
|
|
124
139
|
}
|
|
125
140
|
useRun(app);
|
|
126
141
|
(0, import_registerRoutes.default)(app, apiHandlerInfos);
|
|
@@ -158,9 +173,7 @@ var plugin_default = () => ({
|
|
|
158
173
|
initMiddlewares(middleware, app);
|
|
159
174
|
}
|
|
160
175
|
return (ctx) => new Promise((resolve, reject) => {
|
|
161
|
-
const {
|
|
162
|
-
source: { req, res }
|
|
163
|
-
} = ctx;
|
|
176
|
+
const { source: { req, res } } = ctx;
|
|
164
177
|
const handler = (err) => {
|
|
165
178
|
if (err) {
|
|
166
179
|
return reject(err);
|
|
@@ -181,3 +194,5 @@ var plugin_default = () => ({
|
|
|
181
194
|
}
|
|
182
195
|
})
|
|
183
196
|
});
|
|
197
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
198
|
+
0 && (module.exports = {});
|
|
@@ -15,11 +15,11 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
15
|
return to;
|
|
16
16
|
};
|
|
17
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var
|
|
19
|
-
__export(
|
|
18
|
+
var registerRoutes_exports = {};
|
|
19
|
+
__export(registerRoutes_exports, {
|
|
20
20
|
default: () => registerRoutes_default
|
|
21
21
|
});
|
|
22
|
-
module.exports = __toCommonJS(
|
|
22
|
+
module.exports = __toCommonJS(registerRoutes_exports);
|
|
23
23
|
var import_reflect_metadata = require("reflect-metadata");
|
|
24
24
|
var import_utils = require("./utils");
|
|
25
25
|
const registerRoutes = (app, handlerInfos) => {
|
|
@@ -35,3 +35,5 @@ const registerRoutes = (app, handlerInfos) => {
|
|
|
35
35
|
});
|
|
36
36
|
};
|
|
37
37
|
var registerRoutes_default = registerRoutes;
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 && (module.exports = {});
|
|
@@ -15,9 +15,13 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
15
|
return to;
|
|
16
16
|
};
|
|
17
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var
|
|
19
|
-
__export(
|
|
18
|
+
var hook_exports = {};
|
|
19
|
+
__export(hook_exports, {
|
|
20
20
|
hook: () => hook
|
|
21
21
|
});
|
|
22
|
-
module.exports = __toCommonJS(
|
|
22
|
+
module.exports = __toCommonJS(hook_exports);
|
|
23
23
|
const hook = (attacher) => attacher;
|
|
24
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
25
|
+
0 && (module.exports = {
|
|
26
|
+
hook
|
|
27
|
+
});
|
|
@@ -16,13 +16,18 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
};
|
|
17
17
|
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
19
|
+
var runtime_exports = {};
|
|
20
|
+
__export(runtime_exports, {
|
|
21
21
|
hook: () => import_hook.hook,
|
|
22
22
|
useContext: () => import_context.useContext
|
|
23
23
|
});
|
|
24
|
-
module.exports = __toCommonJS(
|
|
25
|
-
__reExport(
|
|
24
|
+
module.exports = __toCommonJS(runtime_exports);
|
|
25
|
+
__reExport(runtime_exports, require("@modern-js/bff-core"), module.exports);
|
|
26
26
|
var import_context = require("../context");
|
|
27
27
|
var import_hook = require("./hook");
|
|
28
|
-
__reExport(
|
|
28
|
+
__reExport(runtime_exports, require("./operators"), module.exports);
|
|
29
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
30
|
+
0 && (module.exports = {
|
|
31
|
+
hook,
|
|
32
|
+
useContext
|
|
33
|
+
});
|
|
@@ -15,13 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
15
|
return to;
|
|
16
16
|
};
|
|
17
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var stdin_exports = {};
|
|
19
|
-
__export(stdin_exports, {
|
|
20
|
-
Middleware: () => Middleware,
|
|
21
|
-
Pipe: () => Pipe
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(stdin_exports);
|
|
24
|
-
var import_context = require("../context");
|
|
25
18
|
var __async = (__this, __arguments, generator) => {
|
|
26
19
|
return new Promise((resolve, reject) => {
|
|
27
20
|
var fulfilled = (value) => {
|
|
@@ -42,6 +35,13 @@ var __async = (__this, __arguments, generator) => {
|
|
|
42
35
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
43
36
|
});
|
|
44
37
|
};
|
|
38
|
+
var operators_exports = {};
|
|
39
|
+
__export(operators_exports, {
|
|
40
|
+
Middleware: () => Middleware,
|
|
41
|
+
Pipe: () => Pipe
|
|
42
|
+
});
|
|
43
|
+
module.exports = __toCommonJS(operators_exports);
|
|
44
|
+
var import_context = require("../context");
|
|
45
45
|
const Pipe = (func) => {
|
|
46
46
|
return {
|
|
47
47
|
name: "pipe",
|
|
@@ -85,3 +85,8 @@ const Middleware = (middleware) => {
|
|
|
85
85
|
}
|
|
86
86
|
};
|
|
87
87
|
};
|
|
88
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
89
|
+
0 && (module.exports = {
|
|
90
|
+
Middleware,
|
|
91
|
+
Pipe
|
|
92
|
+
});
|
package/dist/js/node/utils.js
CHANGED
|
@@ -2,8 +2,22 @@ var __create = Object.create;
|
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
6
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
+
var __spreadValues = (a, b) => {
|
|
11
|
+
for (var prop in b || (b = {}))
|
|
12
|
+
if (__hasOwnProp.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
if (__getOwnPropSymbols)
|
|
15
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
+
if (__propIsEnum.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
}
|
|
19
|
+
return a;
|
|
20
|
+
};
|
|
7
21
|
var __export = (target, all) => {
|
|
8
22
|
for (var name in all)
|
|
9
23
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -21,33 +35,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
35
|
mod
|
|
22
36
|
));
|
|
23
37
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
-
var stdin_exports = {};
|
|
25
|
-
__export(stdin_exports, {
|
|
26
|
-
createRouteHandler: () => createRouteHandler,
|
|
27
|
-
isNormalMethod: () => isNormalMethod
|
|
28
|
-
});
|
|
29
|
-
module.exports = __toCommonJS(stdin_exports);
|
|
30
|
-
var import_reflect_metadata = require("reflect-metadata");
|
|
31
|
-
var import_bff_core = require("@modern-js/bff-core");
|
|
32
|
-
var import_bff_runtime = require("@modern-js/bff-runtime");
|
|
33
|
-
var import_type_is = __toESM(require("type-is"));
|
|
34
|
-
var import_formidable = __toESM(require("formidable"));
|
|
35
|
-
var __defProp2 = Object.defineProperty;
|
|
36
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
37
|
-
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
38
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
39
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
40
|
-
var __spreadValues = (a, b) => {
|
|
41
|
-
for (var prop in b || (b = {}))
|
|
42
|
-
if (__hasOwnProp2.call(b, prop))
|
|
43
|
-
__defNormalProp(a, prop, b[prop]);
|
|
44
|
-
if (__getOwnPropSymbols)
|
|
45
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
46
|
-
if (__propIsEnum.call(b, prop))
|
|
47
|
-
__defNormalProp(a, prop, b[prop]);
|
|
48
|
-
}
|
|
49
|
-
return a;
|
|
50
|
-
};
|
|
51
38
|
var __async = (__this, __arguments, generator) => {
|
|
52
39
|
return new Promise((resolve, reject) => {
|
|
53
40
|
var fulfilled = (value) => {
|
|
@@ -68,11 +55,19 @@ var __async = (__this, __arguments, generator) => {
|
|
|
68
55
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
69
56
|
});
|
|
70
57
|
};
|
|
58
|
+
var utils_exports = {};
|
|
59
|
+
__export(utils_exports, {
|
|
60
|
+
createRouteHandler: () => createRouteHandler,
|
|
61
|
+
isNormalMethod: () => isNormalMethod
|
|
62
|
+
});
|
|
63
|
+
module.exports = __toCommonJS(utils_exports);
|
|
64
|
+
var import_reflect_metadata = require("reflect-metadata");
|
|
65
|
+
var import_bff_core = require("@modern-js/bff-core");
|
|
66
|
+
var import_bff_runtime = require("@modern-js/bff-runtime");
|
|
67
|
+
var import_type_is = __toESM(require("type-is"));
|
|
68
|
+
var import_formidable = __toESM(require("formidable"));
|
|
71
69
|
const handleResponseMeta = (res, handler) => {
|
|
72
|
-
const responseMeta = Reflect.getMetadata(
|
|
73
|
-
import_bff_core.HttpMetadata.Response,
|
|
74
|
-
handler
|
|
75
|
-
);
|
|
70
|
+
const responseMeta = Reflect.getMetadata(import_bff_core.HttpMetadata.Response, handler);
|
|
76
71
|
if (Array.isArray(responseMeta)) {
|
|
77
72
|
for (const meta of responseMeta) {
|
|
78
73
|
const metaType = meta.type;
|
|
@@ -118,17 +113,17 @@ const createRouteHandler = (handler) => {
|
|
|
118
113
|
throw error;
|
|
119
114
|
}
|
|
120
115
|
} else if ((0, import_bff_runtime.isSchemaHandler)(handler)) {
|
|
121
|
-
const
|
|
122
|
-
if (
|
|
123
|
-
if (
|
|
116
|
+
const result1 = yield handler(input);
|
|
117
|
+
if (result1.type !== "HandleSuccess") {
|
|
118
|
+
if (result1.type === "InputValidationError") {
|
|
124
119
|
res.status(400);
|
|
125
120
|
} else {
|
|
126
121
|
res.status(500);
|
|
127
122
|
}
|
|
128
|
-
return res.json(
|
|
123
|
+
return res.json(result1.message);
|
|
129
124
|
} else {
|
|
130
125
|
res.status(200);
|
|
131
|
-
return res.json(
|
|
126
|
+
return res.json(result1.value);
|
|
132
127
|
}
|
|
133
128
|
} else {
|
|
134
129
|
const args = Object.values(input.params).concat(input);
|
|
@@ -145,10 +140,7 @@ const createRouteHandler = (handler) => {
|
|
|
145
140
|
}
|
|
146
141
|
}
|
|
147
142
|
});
|
|
148
|
-
Object.defineProperties(
|
|
149
|
-
apiHandler,
|
|
150
|
-
Object.getOwnPropertyDescriptors(handler)
|
|
151
|
-
);
|
|
143
|
+
Object.defineProperties(apiHandler, Object.getOwnPropertyDescriptors(handler));
|
|
152
144
|
return apiHandler;
|
|
153
145
|
};
|
|
154
146
|
const isNormalMethod = (httpMethod) => import_bff_core.httpMethods.includes(httpMethod);
|
|
@@ -159,11 +151,17 @@ const getInputFromRequest = (request) => __async(void 0, null, function* () {
|
|
|
159
151
|
headers: request.headers,
|
|
160
152
|
cookies: request.headers.cookie
|
|
161
153
|
};
|
|
162
|
-
if ((0, import_type_is.default)(request, [
|
|
154
|
+
if ((0, import_type_is.default)(request, [
|
|
155
|
+
"application/json"
|
|
156
|
+
])) {
|
|
163
157
|
draft.data = request.body;
|
|
164
|
-
} else if ((0, import_type_is.default)(request, [
|
|
158
|
+
} else if ((0, import_type_is.default)(request, [
|
|
159
|
+
"multipart/form-data"
|
|
160
|
+
])) {
|
|
165
161
|
draft.formData = yield resolveFormData(request);
|
|
166
|
-
} else if ((0, import_type_is.default)(request, [
|
|
162
|
+
} else if ((0, import_type_is.default)(request, [
|
|
163
|
+
"application/x-www-form-urlencoded"
|
|
164
|
+
])) {
|
|
167
165
|
draft.formUrlencoded = request.body;
|
|
168
166
|
} else {
|
|
169
167
|
draft.body = request.body;
|
|
@@ -171,7 +169,9 @@ const getInputFromRequest = (request) => __async(void 0, null, function* () {
|
|
|
171
169
|
return draft;
|
|
172
170
|
});
|
|
173
171
|
const resolveFormData = (request) => {
|
|
174
|
-
const form = (0, import_formidable.default)({
|
|
172
|
+
const form = (0, import_formidable.default)({
|
|
173
|
+
multiples: true
|
|
174
|
+
});
|
|
175
175
|
return new Promise((resolve, reject) => {
|
|
176
176
|
form.parse(request, (err, fields, files) => {
|
|
177
177
|
if (err) {
|
|
@@ -181,3 +181,8 @@ const resolveFormData = (request) => {
|
|
|
181
181
|
});
|
|
182
182
|
});
|
|
183
183
|
};
|
|
184
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
185
|
+
0 && (module.exports = {
|
|
186
|
+
createRouteHandler,
|
|
187
|
+
isNormalMethod
|
|
188
|
+
});
|
|
@@ -35,6 +35,15 @@ var cli_default = function() {
|
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
|
+
collectServerPlugins: function collectServerPlugins(param) {
|
|
39
|
+
var plugins = param.plugins;
|
|
40
|
+
plugins.push({
|
|
41
|
+
"@modern-js/plugin-express": "@modern-js/plugin-express/server"
|
|
42
|
+
});
|
|
43
|
+
return {
|
|
44
|
+
plugins: plugins
|
|
45
|
+
};
|
|
46
|
+
},
|
|
38
47
|
addRuntimeExports: function addRuntimeExports(input) {
|
|
39
48
|
var currentFile = bffExportsUtils.getPath();
|
|
40
49
|
var relativeRuntimeModulePath = path.relative(path.dirname(currentFile), runtimeModulePath);
|
package/package.json
CHANGED
|
@@ -11,25 +11,29 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "2.0.0-beta.
|
|
14
|
+
"version": "2.0.0-beta.6",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
|
-
"types": "./dist/types/index.d.ts",
|
|
17
|
-
"main": "./dist/js/node/index.js",
|
|
18
|
-
"module": "./dist/js/treeshaking/index.js",
|
|
19
|
-
"jsnext:modern": "./dist/js/modern/index.js",
|
|
16
|
+
"types": "./dist/types/cli/index.d.ts",
|
|
17
|
+
"main": "./dist/js/node/cli/index.js",
|
|
18
|
+
"module": "./dist/js/treeshaking/cli/index.js",
|
|
19
|
+
"jsnext:modern": "./dist/js/modern/cli/index.js",
|
|
20
20
|
"exports": {
|
|
21
21
|
"./types": "./types.d.ts",
|
|
22
22
|
".": {
|
|
23
|
+
"jsnext:source": "./src/cli/index.ts",
|
|
24
|
+
"default": "./dist/js/node/cli/index.js"
|
|
25
|
+
},
|
|
26
|
+
"./cli": {
|
|
27
|
+
"jsnext:source": "./src/cli/index.ts",
|
|
28
|
+
"default": "./dist/js/node/cli/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./server": {
|
|
23
31
|
"node": {
|
|
24
32
|
"jsnext:source": "./src/index.ts",
|
|
25
33
|
"import": "./dist/js/modern/index.js",
|
|
26
34
|
"require": "./dist/js/node/index.js"
|
|
27
35
|
},
|
|
28
36
|
"default": "./dist/js/treeshaking/index.js"
|
|
29
|
-
},
|
|
30
|
-
"./cli": {
|
|
31
|
-
"jsnext:source": "./src/cli/index.ts",
|
|
32
|
-
"default": "./dist/js/node/cli/index.js"
|
|
33
37
|
}
|
|
34
38
|
},
|
|
35
39
|
"dependencies": {
|
|
@@ -39,10 +43,10 @@
|
|
|
39
43
|
"formidable": "^1.2.2",
|
|
40
44
|
"reflect-metadata": "^0.1.13",
|
|
41
45
|
"type-is": "^1.6.18",
|
|
42
|
-
"@modern-js/bff-core": "2.0.0-beta.
|
|
43
|
-
"@modern-js/bff-runtime": "2.0.0-beta.
|
|
44
|
-
"@modern-js/types": "2.0.0-beta.
|
|
45
|
-
"@modern-js/utils": "2.0.0-beta.
|
|
46
|
+
"@modern-js/bff-core": "2.0.0-beta.6",
|
|
47
|
+
"@modern-js/bff-runtime": "2.0.0-beta.6",
|
|
48
|
+
"@modern-js/types": "2.0.0-beta.6",
|
|
49
|
+
"@modern-js/utils": "2.0.0-beta.6"
|
|
46
50
|
},
|
|
47
51
|
"devDependencies": {
|
|
48
52
|
"@types/cookie-parser": "^1.4.2",
|
|
@@ -58,10 +62,11 @@
|
|
|
58
62
|
"supertest": "^6.1.6",
|
|
59
63
|
"typescript": "^4",
|
|
60
64
|
"zod": "^3.17.3",
|
|
61
|
-
"@modern-js/core": "2.0.0-beta.
|
|
62
|
-
"@modern-js/
|
|
63
|
-
"@
|
|
64
|
-
"@scripts/
|
|
65
|
+
"@modern-js/core": "2.0.0-beta.6",
|
|
66
|
+
"@modern-js/app-tools": "2.0.0-beta.6",
|
|
67
|
+
"@modern-js/server-core": "2.0.0-beta.6",
|
|
68
|
+
"@scripts/build": "2.0.0-beta.6",
|
|
69
|
+
"@scripts/jest-config": "2.0.0-beta.6"
|
|
65
70
|
},
|
|
66
71
|
"peerDependencies": {
|
|
67
72
|
"express": "^4.17.1"
|