@modern-js/plugin-express 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/cli/index.js +41 -23
- package/dist/cjs/context.js +27 -17
- package/dist/cjs/index.js +38 -12
- package/dist/cjs/plugin.js +56 -35
- package/dist/cjs/registerRoutes.js +24 -11
- package/dist/cjs/runtime/hook.js +24 -7
- package/dist/cjs/runtime/index.js +32 -20
- package/dist/cjs/runtime/operators.js +27 -17
- package/dist/cjs/utils.js +53 -34
- package/dist/esm/cli/index.js +7 -3
- package/dist/esm/context.js +4 -1
- package/dist/esm/index.js +4 -1
- package/dist/esm/plugin.js +6 -3
- package/dist/esm/registerRoutes.js +4 -1
- package/dist/esm/runtime/hook.js +4 -1
- package/dist/esm/runtime/index.js +6 -2
- package/dist/esm/runtime/operators.js +6 -2
- package/dist/esm/utils.js +6 -2
- package/dist/esm-node/cli/index.js +6 -2
- package/dist/esm-node/context.js +4 -1
- package/dist/esm-node/index.js +4 -1
- package/dist/esm-node/plugin.js +4 -1
- package/dist/esm-node/registerRoutes.js +4 -1
- package/dist/esm-node/runtime/hook.js +4 -1
- package/dist/esm-node/runtime/index.js +6 -2
- package/dist/esm-node/runtime/operators.js +6 -2
- package/dist/esm-node/utils.js +6 -2
- package/package.json +11 -11
package/dist/cjs/cli/index.js
CHANGED
|
@@ -1,35 +1,49 @@
|
|
|
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 expressPlugin;
|
|
15
|
-
},
|
|
16
|
-
default: function() {
|
|
17
|
-
return _default;
|
|
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 });
|
|
18
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 cli_exports = {};
|
|
30
|
+
__export(cli_exports, {
|
|
31
|
+
default: () => cli_default,
|
|
32
|
+
expressPlugin: () => expressPlugin
|
|
19
33
|
});
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
34
|
+
module.exports = __toCommonJS(cli_exports);
|
|
35
|
+
var path = __toESM(require("path"));
|
|
36
|
+
var import_utils = require("@modern-js/utils");
|
|
23
37
|
const expressPlugin = () => ({
|
|
24
38
|
name: "@modern-js/plugin-express",
|
|
25
39
|
setup: (api) => {
|
|
26
40
|
let bffExportsUtils;
|
|
27
41
|
const { useAppContext } = api;
|
|
28
|
-
const runtimeModulePath =
|
|
42
|
+
const runtimeModulePath = path.resolve(__dirname, "../runtime");
|
|
29
43
|
return {
|
|
30
44
|
config() {
|
|
31
45
|
const appContext = useAppContext();
|
|
32
|
-
bffExportsUtils = (0,
|
|
46
|
+
bffExportsUtils = (0, import_utils.createRuntimeExportsUtils)(appContext.internalDirectory, "server");
|
|
33
47
|
const runtimePath = process.env.NODE_ENV === "development" ? require.resolve("@modern-js/plugin-express/runtime") : "@modern-js/plugin-express/runtime";
|
|
34
48
|
return {
|
|
35
49
|
source: {
|
|
@@ -50,8 +64,8 @@ const expressPlugin = () => ({
|
|
|
50
64
|
},
|
|
51
65
|
addRuntimeExports(input) {
|
|
52
66
|
const currentFile = bffExportsUtils.getPath();
|
|
53
|
-
const relativeRuntimeModulePath =
|
|
54
|
-
const relativeFramePath =
|
|
67
|
+
const relativeRuntimeModulePath = path.relative(path.dirname(currentFile), runtimeModulePath);
|
|
68
|
+
const relativeFramePath = path.relative(path.dirname(currentFile), require.resolve("express"));
|
|
55
69
|
bffExportsUtils.addExport(`const pluginRuntime = require('${relativeRuntimeModulePath}');
|
|
56
70
|
const express = require('${relativeFramePath}')
|
|
57
71
|
module.exports = {
|
|
@@ -64,4 +78,8 @@ const expressPlugin = () => ({
|
|
|
64
78
|
};
|
|
65
79
|
}
|
|
66
80
|
});
|
|
67
|
-
|
|
81
|
+
var cli_default = expressPlugin;
|
|
82
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
83
|
+
0 && (module.exports = {
|
|
84
|
+
expressPlugin
|
|
85
|
+
});
|
package/dist/cjs/context.js
CHANGED
|
@@ -1,21 +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 run;
|
|
15
|
-
},
|
|
16
|
-
useContext: function() {
|
|
17
|
-
return useContext;
|
|
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 });
|
|
18
15
|
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var context_exports = {};
|
|
20
|
+
__export(context_exports, {
|
|
21
|
+
run: () => run,
|
|
22
|
+
useContext: () => useContext
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(context_exports);
|
|
25
|
+
var import_bff_core = require("@modern-js/bff-core");
|
|
26
|
+
const { run, useContext } = (0, import_bff_core.createStorage)();
|
|
27
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
28
|
+
0 && (module.exports = {
|
|
29
|
+
run,
|
|
30
|
+
useContext
|
|
19
31
|
});
|
|
20
|
-
const _bffcore = require("@modern-js/bff-core");
|
|
21
|
-
const { run, useContext } = (0, _bffcore.createStorage)();
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,15 +1,41 @@
|
|
|
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 src_exports = {};
|
|
31
|
+
__export(src_exports, {
|
|
32
|
+
default: () => src_default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(src_exports);
|
|
35
|
+
var import_plugin = __toESM(require("./plugin"));
|
|
36
|
+
__reExport(src_exports, require("./context"), module.exports);
|
|
37
|
+
var src_default = import_plugin.default;
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 && (module.exports = {
|
|
40
|
+
...require("./context")
|
|
10
41
|
});
|
|
11
|
-
const _export_star = require("@swc/helpers/_/_export_star");
|
|
12
|
-
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
|
13
|
-
const _plugin = /* @__PURE__ */ _interop_require_default._(require("./plugin"));
|
|
14
|
-
_export_star._(require("./context"), exports);
|
|
15
|
-
const _default = _plugin.default;
|
package/dist/cjs/plugin.js
CHANGED
|
@@ -1,34 +1,55 @@
|
|
|
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 __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 plugin_exports = {};
|
|
30
|
+
__export(plugin_exports, {
|
|
31
|
+
default: () => plugin_default
|
|
10
32
|
});
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
const debug = (0, _utils.createDebugger)("express");
|
|
33
|
+
module.exports = __toCommonJS(plugin_exports);
|
|
34
|
+
var path = __toESM(require("path"));
|
|
35
|
+
var import_express = __toESM(require("express"));
|
|
36
|
+
var import_cookie_parser = __toESM(require("cookie-parser"));
|
|
37
|
+
var import_utils = require("@modern-js/utils");
|
|
38
|
+
var import_finalhandler = __toESM(require("finalhandler"));
|
|
39
|
+
var import_context = require("./context");
|
|
40
|
+
var import_registerRoutes = __toESM(require("./registerRoutes"));
|
|
41
|
+
const debug = (0, import_utils.createDebugger)("express");
|
|
21
42
|
const findAppModule = async (apiDir) => {
|
|
22
43
|
const exts = [
|
|
23
44
|
".ts",
|
|
24
45
|
".js"
|
|
25
46
|
];
|
|
26
|
-
const paths = exts.map((ext) =>
|
|
47
|
+
const paths = exts.map((ext) => path.resolve(apiDir, `app${ext}`));
|
|
27
48
|
for (const filename of paths) {
|
|
28
|
-
if (await
|
|
49
|
+
if (await import_utils.fs.pathExists(filename)) {
|
|
29
50
|
delete require.cache[filename];
|
|
30
51
|
return [
|
|
31
|
-
(0,
|
|
52
|
+
(0, import_utils.compatRequire)(filename),
|
|
32
53
|
require(filename)
|
|
33
54
|
];
|
|
34
55
|
}
|
|
@@ -37,28 +58,28 @@ const findAppModule = async (apiDir) => {
|
|
|
37
58
|
};
|
|
38
59
|
const initMiddlewares = (middleware, app) => {
|
|
39
60
|
middleware.forEach((middlewareItem) => {
|
|
40
|
-
const middlewareFunc = typeof middlewareItem === "string" ? (0,
|
|
61
|
+
const middlewareFunc = typeof middlewareItem === "string" ? (0, import_utils.compatRequire)(middlewareItem) : middlewareItem;
|
|
41
62
|
app.use(middlewareFunc);
|
|
42
63
|
});
|
|
43
64
|
};
|
|
44
65
|
const useRun = (app) => {
|
|
45
66
|
app.use((req, res, next) => {
|
|
46
|
-
(0,
|
|
67
|
+
(0, import_context.run)({
|
|
47
68
|
req,
|
|
48
69
|
res
|
|
49
70
|
}, next);
|
|
50
71
|
});
|
|
51
72
|
};
|
|
52
73
|
const initApp = (app) => {
|
|
53
|
-
app.use((0,
|
|
54
|
-
app.use(
|
|
55
|
-
app.use(
|
|
74
|
+
app.use((0, import_cookie_parser.default)());
|
|
75
|
+
app.use(import_express.default.text());
|
|
76
|
+
app.use(import_express.default.urlencoded({
|
|
56
77
|
extended: true
|
|
57
78
|
}));
|
|
58
|
-
app.use(
|
|
79
|
+
app.use(import_express.default.json());
|
|
59
80
|
return app;
|
|
60
81
|
};
|
|
61
|
-
|
|
82
|
+
var plugin_default = () => ({
|
|
62
83
|
name: "@modern-js/plugin-express",
|
|
63
84
|
pre: [
|
|
64
85
|
"@modern-js/plugin-bff"
|
|
@@ -73,7 +94,7 @@ const _default = () => ({
|
|
|
73
94
|
const appContext = api.useAppContext();
|
|
74
95
|
const apiHandlerInfos = appContext.apiHandlerInfos;
|
|
75
96
|
const apiDirectory = appContext.apiDirectory;
|
|
76
|
-
const apiDir = apiDirectory ||
|
|
97
|
+
const apiDir = apiDirectory || path.join(pwd, "./api");
|
|
77
98
|
const mode = appContext.apiMode;
|
|
78
99
|
const userConfig = api.useConfigContext();
|
|
79
100
|
if (mode === "framework") {
|
|
@@ -81,7 +102,7 @@ const _default = () => ({
|
|
|
81
102
|
app = appModule[0];
|
|
82
103
|
const hooks = appModule[1];
|
|
83
104
|
if (!(app === null || app === void 0 ? void 0 : app.use)) {
|
|
84
|
-
app = (0,
|
|
105
|
+
app = (0, import_express.default)();
|
|
85
106
|
}
|
|
86
107
|
initApp(app);
|
|
87
108
|
if (config) {
|
|
@@ -89,7 +110,7 @@ const _default = () => ({
|
|
|
89
110
|
initMiddlewares(middleware, app);
|
|
90
111
|
}
|
|
91
112
|
useRun(app);
|
|
92
|
-
(0,
|
|
113
|
+
(0, import_registerRoutes.default)(app, apiHandlerInfos);
|
|
93
114
|
if (hooks) {
|
|
94
115
|
const { afterLambdaRegisted } = hooks;
|
|
95
116
|
if (afterLambdaRegisted) {
|
|
@@ -97,14 +118,14 @@ const _default = () => ({
|
|
|
97
118
|
}
|
|
98
119
|
}
|
|
99
120
|
} else if (mode === "function") {
|
|
100
|
-
app = (0,
|
|
121
|
+
app = (0, import_express.default)();
|
|
101
122
|
initApp(app);
|
|
102
123
|
if (config) {
|
|
103
124
|
const { middleware } = config;
|
|
104
125
|
initMiddlewares(middleware, app);
|
|
105
126
|
}
|
|
106
127
|
useRun(app);
|
|
107
|
-
(0,
|
|
128
|
+
(0, import_registerRoutes.default)(app, apiHandlerInfos);
|
|
108
129
|
} else {
|
|
109
130
|
throw new Error(`mode must be function or framework`);
|
|
110
131
|
}
|
|
@@ -122,7 +143,7 @@ const _default = () => ({
|
|
|
122
143
|
if (err) {
|
|
123
144
|
return reject(err);
|
|
124
145
|
}
|
|
125
|
-
return (0,
|
|
146
|
+
return (0, import_finalhandler.default)(req, res, {})(null);
|
|
126
147
|
};
|
|
127
148
|
res.on("finish", (err) => {
|
|
128
149
|
if (err) {
|
|
@@ -139,7 +160,7 @@ const _default = () => ({
|
|
|
139
160
|
if (!(userConfig === null || userConfig === void 0 ? void 0 : (_userConfig_server = userConfig.server) === null || _userConfig_server === void 0 ? void 0 : _userConfig_server.enableFrameworkExt)) {
|
|
140
161
|
return next();
|
|
141
162
|
}
|
|
142
|
-
const app = (0,
|
|
163
|
+
const app = (0, import_express.default)();
|
|
143
164
|
initApp(app);
|
|
144
165
|
if (config) {
|
|
145
166
|
const { middleware } = config;
|
|
@@ -153,7 +174,7 @@ const _default = () => ({
|
|
|
153
174
|
return reject(err);
|
|
154
175
|
}
|
|
155
176
|
if (res.headersSent && res.statusCode !== 200) {
|
|
156
|
-
(0,
|
|
177
|
+
(0, import_finalhandler.default)(req, res, {})(null);
|
|
157
178
|
}
|
|
158
179
|
return resolve();
|
|
159
180
|
};
|
|
@@ -1,18 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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) => {
|
|
7
|
+
for (var name in all)
|
|
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 });
|
|
9
15
|
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var registerRoutes_exports = {};
|
|
20
|
+
__export(registerRoutes_exports, {
|
|
21
|
+
default: () => registerRoutes_default
|
|
10
22
|
});
|
|
11
|
-
|
|
12
|
-
|
|
23
|
+
module.exports = __toCommonJS(registerRoutes_exports);
|
|
24
|
+
var import_reflect_metadata = require("reflect-metadata");
|
|
25
|
+
var import_utils = require("./utils");
|
|
13
26
|
const registerRoutes = (app, handlerInfos) => {
|
|
14
27
|
handlerInfos.forEach(({ routePath, handler, httpMethod }) => {
|
|
15
|
-
const routeHandler = (0,
|
|
28
|
+
const routeHandler = (0, import_utils.createRouteHandler)(handler);
|
|
16
29
|
const method = httpMethod.toLowerCase();
|
|
17
30
|
const routeMiddlwares = Reflect.getMetadata("middleware", handler) || [];
|
|
18
31
|
if (routeMiddlwares.length > 0) {
|
|
@@ -22,4 +35,4 @@ const registerRoutes = (app, handlerInfos) => {
|
|
|
22
35
|
}
|
|
23
36
|
});
|
|
24
37
|
};
|
|
25
|
-
|
|
38
|
+
var registerRoutes_default = registerRoutes;
|
package/dist/cjs/runtime/hook.js
CHANGED
|
@@ -1,11 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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) => {
|
|
7
|
+
for (var name in all)
|
|
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 });
|
|
9
15
|
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var hook_exports = {};
|
|
20
|
+
__export(hook_exports, {
|
|
21
|
+
hook: () => hook
|
|
10
22
|
});
|
|
23
|
+
module.exports = __toCommonJS(hook_exports);
|
|
11
24
|
const hook = (attacher) => attacher;
|
|
25
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
26
|
+
0 && (module.exports = {
|
|
27
|
+
hook
|
|
28
|
+
});
|
|
@@ -1,24 +1,36 @@
|
|
|
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 _context.useContext;
|
|
15
|
-
},
|
|
16
|
-
hook: function() {
|
|
17
|
-
return _hook.hook;
|
|
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 });
|
|
18
15
|
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var runtime_exports = {};
|
|
21
|
+
__export(runtime_exports, {
|
|
22
|
+
hook: () => import_hook.hook,
|
|
23
|
+
useContext: () => import_context.useContext
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(runtime_exports);
|
|
26
|
+
__reExport(runtime_exports, require("@modern-js/bff-core"), module.exports);
|
|
27
|
+
var import_context = require("../context");
|
|
28
|
+
var import_hook = require("./hook");
|
|
29
|
+
__reExport(runtime_exports, require("./operators"), module.exports);
|
|
30
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
31
|
+
0 && (module.exports = {
|
|
32
|
+
hook,
|
|
33
|
+
useContext,
|
|
34
|
+
...require("@modern-js/bff-core"),
|
|
35
|
+
...require("./operators")
|
|
19
36
|
});
|
|
20
|
-
const _export_star = require("@swc/helpers/_/_export_star");
|
|
21
|
-
_export_star._(require("@modern-js/bff-core"), exports);
|
|
22
|
-
const _context = require("../context");
|
|
23
|
-
const _hook = require("./hook");
|
|
24
|
-
_export_star._(require("./operators"), exports);
|
|
@@ -1,30 +1,35 @@
|
|
|
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 Pipe;
|
|
15
|
-
},
|
|
16
|
-
Middleware: function() {
|
|
17
|
-
return Middleware;
|
|
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 });
|
|
18
15
|
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var operators_exports = {};
|
|
20
|
+
__export(operators_exports, {
|
|
21
|
+
Middleware: () => Middleware,
|
|
22
|
+
Pipe: () => Pipe
|
|
19
23
|
});
|
|
20
|
-
|
|
24
|
+
module.exports = __toCommonJS(operators_exports);
|
|
25
|
+
var import_context = require("../context");
|
|
21
26
|
const Pipe = (func) => {
|
|
22
27
|
return {
|
|
23
28
|
name: "pipe",
|
|
24
29
|
// eslint-disable-next-line consistent-return
|
|
25
30
|
async execute(executeHelper, next) {
|
|
26
31
|
const { inputs } = executeHelper;
|
|
27
|
-
const ctx = (0,
|
|
32
|
+
const ctx = (0, import_context.useContext)();
|
|
28
33
|
const { res } = ctx;
|
|
29
34
|
if (typeof func === "function") {
|
|
30
35
|
let isPiped = true;
|
|
@@ -60,3 +65,8 @@ const Middleware = (middleware) => {
|
|
|
60
65
|
}
|
|
61
66
|
};
|
|
62
67
|
};
|
|
68
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
69
|
+
0 && (module.exports = {
|
|
70
|
+
Middleware,
|
|
71
|
+
Pipe
|
|
72
|
+
});
|
package/dist/cjs/utils.js
CHANGED
|
@@ -1,44 +1,58 @@
|
|
|
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 createRouteHandler;
|
|
15
|
-
},
|
|
16
|
-
isNormalMethod: function() {
|
|
17
|
-
return isNormalMethod;
|
|
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 });
|
|
18
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
|
+
createRouteHandler: () => createRouteHandler,
|
|
32
|
+
isNormalMethod: () => isNormalMethod
|
|
19
33
|
});
|
|
20
|
-
|
|
21
|
-
require("reflect-metadata");
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
34
|
+
module.exports = __toCommonJS(utils_exports);
|
|
35
|
+
var import_reflect_metadata = require("reflect-metadata");
|
|
36
|
+
var import_bff_core = require("@modern-js/bff-core");
|
|
37
|
+
var import_bff_runtime = require("@modern-js/bff-runtime");
|
|
38
|
+
var import_type_is = __toESM(require("type-is"));
|
|
39
|
+
var import_formidable = __toESM(require("formidable"));
|
|
26
40
|
const handleResponseMeta = (res, handler) => {
|
|
27
|
-
const responseMeta = Reflect.getMetadata(
|
|
41
|
+
const responseMeta = Reflect.getMetadata(import_bff_core.HttpMetadata.Response, handler);
|
|
28
42
|
if (Array.isArray(responseMeta)) {
|
|
29
43
|
for (const meta of responseMeta) {
|
|
30
44
|
const metaType = meta.type;
|
|
31
45
|
const metaValue = meta.value;
|
|
32
46
|
switch (metaType) {
|
|
33
|
-
case
|
|
47
|
+
case import_bff_core.ResponseMetaType.Headers:
|
|
34
48
|
for (const [key, value] of Object.entries(metaValue)) {
|
|
35
49
|
res.append(key, value);
|
|
36
50
|
}
|
|
37
51
|
break;
|
|
38
|
-
case
|
|
52
|
+
case import_bff_core.ResponseMetaType.Redirect:
|
|
39
53
|
res.redirect(metaValue);
|
|
40
54
|
break;
|
|
41
|
-
case
|
|
55
|
+
case import_bff_core.ResponseMetaType.StatusCode:
|
|
42
56
|
res.status(metaValue);
|
|
43
57
|
break;
|
|
44
58
|
default:
|
|
@@ -50,7 +64,7 @@ const handleResponseMeta = (res, handler) => {
|
|
|
50
64
|
const createRouteHandler = (handler) => {
|
|
51
65
|
const apiHandler = async (req, res, next) => {
|
|
52
66
|
const input = await getInputFromRequest(req);
|
|
53
|
-
if ((0,
|
|
67
|
+
if ((0, import_bff_core.isWithMetaHandler)(handler)) {
|
|
54
68
|
try {
|
|
55
69
|
handleResponseMeta(res, handler);
|
|
56
70
|
if (res.headersSent) {
|
|
@@ -61,7 +75,7 @@ const createRouteHandler = (handler) => {
|
|
|
61
75
|
return res.json(result);
|
|
62
76
|
}
|
|
63
77
|
} catch (error) {
|
|
64
|
-
if (error instanceof
|
|
78
|
+
if (error instanceof import_bff_core.ValidationError) {
|
|
65
79
|
res.status(error.status);
|
|
66
80
|
return res.json({
|
|
67
81
|
message: error.message
|
|
@@ -69,7 +83,7 @@ const createRouteHandler = (handler) => {
|
|
|
69
83
|
}
|
|
70
84
|
throw error;
|
|
71
85
|
}
|
|
72
|
-
} else if ((0,
|
|
86
|
+
} else if ((0, import_bff_runtime.isSchemaHandler)(handler)) {
|
|
73
87
|
const result = await handler(input);
|
|
74
88
|
if (result.type !== "HandleSuccess") {
|
|
75
89
|
if (result.type === "InputValidationError") {
|
|
@@ -82,7 +96,7 @@ const createRouteHandler = (handler) => {
|
|
|
82
96
|
res.status(200);
|
|
83
97
|
return res.json(result.value);
|
|
84
98
|
}
|
|
85
|
-
} else if ((0,
|
|
99
|
+
} else if ((0, import_bff_core.isInputParamsDeciderHandler)(handler)) {
|
|
86
100
|
try {
|
|
87
101
|
var _input_data;
|
|
88
102
|
const args = (input === null || input === void 0 ? void 0 : (_input_data = input.data) === null || _input_data === void 0 ? void 0 : _input_data.args) || [];
|
|
@@ -114,7 +128,7 @@ const createRouteHandler = (handler) => {
|
|
|
114
128
|
Object.defineProperties(apiHandler, Object.getOwnPropertyDescriptors(handler));
|
|
115
129
|
return apiHandler;
|
|
116
130
|
};
|
|
117
|
-
const isNormalMethod = (httpMethod) =>
|
|
131
|
+
const isNormalMethod = (httpMethod) => import_bff_core.httpMethods.includes(httpMethod);
|
|
118
132
|
const getInputFromRequest = async (request) => {
|
|
119
133
|
const draft = {
|
|
120
134
|
params: request.params,
|
|
@@ -122,15 +136,15 @@ const getInputFromRequest = async (request) => {
|
|
|
122
136
|
headers: request.headers,
|
|
123
137
|
cookies: request.headers.cookie
|
|
124
138
|
};
|
|
125
|
-
if ((0,
|
|
139
|
+
if ((0, import_type_is.default)(request, [
|
|
126
140
|
"application/json"
|
|
127
141
|
])) {
|
|
128
142
|
draft.data = request.body;
|
|
129
|
-
} else if ((0,
|
|
143
|
+
} else if ((0, import_type_is.default)(request, [
|
|
130
144
|
"multipart/form-data"
|
|
131
145
|
])) {
|
|
132
146
|
draft.formData = await resolveFormData(request);
|
|
133
|
-
} else if ((0,
|
|
147
|
+
} else if ((0, import_type_is.default)(request, [
|
|
134
148
|
"application/x-www-form-urlencoded"
|
|
135
149
|
])) {
|
|
136
150
|
draft.formUrlencoded = request.body;
|
|
@@ -140,7 +154,7 @@ const getInputFromRequest = async (request) => {
|
|
|
140
154
|
return draft;
|
|
141
155
|
};
|
|
142
156
|
const resolveFormData = (request) => {
|
|
143
|
-
const form = (0,
|
|
157
|
+
const form = (0, import_formidable.default)({
|
|
144
158
|
multiples: true
|
|
145
159
|
});
|
|
146
160
|
return new Promise((resolve, reject) => {
|
|
@@ -155,3 +169,8 @@ const resolveFormData = (request) => {
|
|
|
155
169
|
});
|
|
156
170
|
});
|
|
157
171
|
};
|
|
172
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
173
|
+
0 && (module.exports = {
|
|
174
|
+
createRouteHandler,
|
|
175
|
+
isNormalMethod
|
|
176
|
+
});
|
package/dist/esm/cli/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as path from "path";
|
|
2
2
|
import { createRuntimeExportsUtils } from "@modern-js/utils";
|
|
3
|
-
|
|
3
|
+
var expressPlugin = function() {
|
|
4
4
|
return {
|
|
5
5
|
name: "@modern-js/plugin-express",
|
|
6
6
|
setup: function(api) {
|
|
@@ -27,7 +27,7 @@ export var expressPlugin = function() {
|
|
|
27
27
|
"@modern-js/plugin-express": "@modern-js/plugin-express/server"
|
|
28
28
|
});
|
|
29
29
|
return {
|
|
30
|
-
plugins
|
|
30
|
+
plugins
|
|
31
31
|
};
|
|
32
32
|
},
|
|
33
33
|
addRuntimeExports: function addRuntimeExports(input) {
|
|
@@ -41,4 +41,8 @@ export var expressPlugin = function() {
|
|
|
41
41
|
}
|
|
42
42
|
};
|
|
43
43
|
};
|
|
44
|
-
|
|
44
|
+
var cli_default = expressPlugin;
|
|
45
|
+
export {
|
|
46
|
+
cli_default as default,
|
|
47
|
+
expressPlugin
|
|
48
|
+
};
|
package/dist/esm/context.js
CHANGED
package/dist/esm/index.js
CHANGED
package/dist/esm/plugin.js
CHANGED
|
@@ -108,8 +108,8 @@ var initMiddlewares = function(middleware, app) {
|
|
|
108
108
|
var useRun = function(app) {
|
|
109
109
|
app.use(function(req, res, next) {
|
|
110
110
|
run({
|
|
111
|
-
req
|
|
112
|
-
res
|
|
111
|
+
req,
|
|
112
|
+
res
|
|
113
113
|
}, next);
|
|
114
114
|
});
|
|
115
115
|
};
|
|
@@ -122,7 +122,7 @@ var initApp = function(app) {
|
|
|
122
122
|
app.use(express.json());
|
|
123
123
|
return app;
|
|
124
124
|
};
|
|
125
|
-
|
|
125
|
+
function plugin_default() {
|
|
126
126
|
return {
|
|
127
127
|
name: "@modern-js/plugin-express",
|
|
128
128
|
pre: [
|
|
@@ -287,3 +287,6 @@ export default function() {
|
|
|
287
287
|
};
|
|
288
288
|
}
|
|
289
289
|
;
|
|
290
|
+
export {
|
|
291
|
+
plugin_default as default
|
|
292
|
+
};
|
package/dist/esm/runtime/hook.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
2
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
3
3
|
import { useContext } from "../context";
|
|
4
|
-
|
|
4
|
+
var Pipe = function(func) {
|
|
5
5
|
return {
|
|
6
6
|
name: "pipe",
|
|
7
7
|
execute: (
|
|
@@ -66,7 +66,7 @@ export var Pipe = function(func) {
|
|
|
66
66
|
)
|
|
67
67
|
};
|
|
68
68
|
};
|
|
69
|
-
|
|
69
|
+
var Middleware = function(middleware) {
|
|
70
70
|
return {
|
|
71
71
|
name: "middleware",
|
|
72
72
|
metadata: function metadata(helper) {
|
|
@@ -76,3 +76,7 @@ export var Middleware = function(middleware) {
|
|
|
76
76
|
}
|
|
77
77
|
};
|
|
78
78
|
};
|
|
79
|
+
export {
|
|
80
|
+
Middleware,
|
|
81
|
+
Pipe
|
|
82
|
+
};
|
package/dist/esm/utils.js
CHANGED
|
@@ -67,7 +67,7 @@ var handleResponseMeta = function(res, handler) {
|
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
};
|
|
70
|
-
|
|
70
|
+
var createRouteHandler = function(handler) {
|
|
71
71
|
var apiHandler = function() {
|
|
72
72
|
var _ref = _async_to_generator(function(req, res, next) {
|
|
73
73
|
var input, result, error, result1, _input_data, args, body, e, args1, body1, e1;
|
|
@@ -274,7 +274,7 @@ export var createRouteHandler = function(handler) {
|
|
|
274
274
|
Object.defineProperties(apiHandler, Object.getOwnPropertyDescriptors(handler));
|
|
275
275
|
return apiHandler;
|
|
276
276
|
};
|
|
277
|
-
|
|
277
|
+
var isNormalMethod = function(httpMethod) {
|
|
278
278
|
return httpMethods.includes(httpMethod);
|
|
279
279
|
};
|
|
280
280
|
var getInputFromRequest = function() {
|
|
@@ -353,3 +353,7 @@ var resolveFormData = function(request) {
|
|
|
353
353
|
});
|
|
354
354
|
});
|
|
355
355
|
};
|
|
356
|
+
export {
|
|
357
|
+
createRouteHandler,
|
|
358
|
+
isNormalMethod
|
|
359
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as path from "path";
|
|
2
2
|
import { createRuntimeExportsUtils } from "@modern-js/utils";
|
|
3
|
-
|
|
3
|
+
const expressPlugin = () => ({
|
|
4
4
|
name: "@modern-js/plugin-express",
|
|
5
5
|
setup: (api) => {
|
|
6
6
|
let bffExportsUtils;
|
|
@@ -44,4 +44,8 @@ export const expressPlugin = () => ({
|
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
46
|
});
|
|
47
|
-
|
|
47
|
+
var cli_default = expressPlugin;
|
|
48
|
+
export {
|
|
49
|
+
cli_default as default,
|
|
50
|
+
expressPlugin
|
|
51
|
+
};
|
package/dist/esm-node/context.js
CHANGED
package/dist/esm-node/index.js
CHANGED
package/dist/esm-node/plugin.js
CHANGED
|
@@ -46,7 +46,7 @@ const initApp = (app) => {
|
|
|
46
46
|
app.use(express.json());
|
|
47
47
|
return app;
|
|
48
48
|
};
|
|
49
|
-
|
|
49
|
+
var plugin_default = () => ({
|
|
50
50
|
name: "@modern-js/plugin-express",
|
|
51
51
|
pre: [
|
|
52
52
|
"@modern-js/plugin-bff"
|
|
@@ -156,3 +156,6 @@ export default () => ({
|
|
|
156
156
|
}
|
|
157
157
|
})
|
|
158
158
|
});
|
|
159
|
+
export {
|
|
160
|
+
plugin_default as default
|
|
161
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useContext } from "../context";
|
|
2
|
-
|
|
2
|
+
const Pipe = (func) => {
|
|
3
3
|
return {
|
|
4
4
|
name: "pipe",
|
|
5
5
|
// eslint-disable-next-line consistent-return
|
|
@@ -31,7 +31,7 @@ export const Pipe = (func) => {
|
|
|
31
31
|
}
|
|
32
32
|
};
|
|
33
33
|
};
|
|
34
|
-
|
|
34
|
+
const Middleware = (middleware) => {
|
|
35
35
|
return {
|
|
36
36
|
name: "middleware",
|
|
37
37
|
metadata(helper) {
|
|
@@ -41,3 +41,7 @@ export const Middleware = (middleware) => {
|
|
|
41
41
|
}
|
|
42
42
|
};
|
|
43
43
|
};
|
|
44
|
+
export {
|
|
45
|
+
Middleware,
|
|
46
|
+
Pipe
|
|
47
|
+
};
|
package/dist/esm-node/utils.js
CHANGED
|
@@ -27,7 +27,7 @@ const handleResponseMeta = (res, handler) => {
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
};
|
|
30
|
-
|
|
30
|
+
const createRouteHandler = (handler) => {
|
|
31
31
|
const apiHandler = async (req, res, next) => {
|
|
32
32
|
const input = await getInputFromRequest(req);
|
|
33
33
|
if (isWithMetaHandler(handler)) {
|
|
@@ -94,7 +94,7 @@ export const createRouteHandler = (handler) => {
|
|
|
94
94
|
Object.defineProperties(apiHandler, Object.getOwnPropertyDescriptors(handler));
|
|
95
95
|
return apiHandler;
|
|
96
96
|
};
|
|
97
|
-
|
|
97
|
+
const isNormalMethod = (httpMethod) => httpMethods.includes(httpMethod);
|
|
98
98
|
const getInputFromRequest = async (request) => {
|
|
99
99
|
const draft = {
|
|
100
100
|
params: request.params,
|
|
@@ -135,3 +135,7 @@ const resolveFormData = (request) => {
|
|
|
135
135
|
});
|
|
136
136
|
});
|
|
137
137
|
};
|
|
138
|
+
export {
|
|
139
|
+
createRouteHandler,
|
|
140
|
+
isNormalMethod
|
|
141
|
+
};
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.
|
|
18
|
+
"version": "2.36.0",
|
|
19
19
|
"jsnext:source": "./src/index.ts",
|
|
20
20
|
"types": "./dist/types/cli/index.d.ts",
|
|
21
21
|
"main": "./dist/cjs/cli/index.js",
|
|
@@ -49,10 +49,10 @@
|
|
|
49
49
|
"reflect-metadata": "^0.1.13",
|
|
50
50
|
"type-is": "^1.6.18",
|
|
51
51
|
"@swc/helpers": "0.5.1",
|
|
52
|
-
"@modern-js/bff-core": "2.
|
|
53
|
-
"@modern-js/bff-runtime": "2.
|
|
54
|
-
"@modern-js/
|
|
55
|
-
"@modern-js/
|
|
52
|
+
"@modern-js/bff-core": "2.36.0",
|
|
53
|
+
"@modern-js/bff-runtime": "2.36.0",
|
|
54
|
+
"@modern-js/types": "2.36.0",
|
|
55
|
+
"@modern-js/utils": "2.36.0"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@types/cookie-parser": "^1.4.2",
|
|
@@ -67,12 +67,12 @@
|
|
|
67
67
|
"jest": "^29",
|
|
68
68
|
"supertest": "^6.1.6",
|
|
69
69
|
"typescript": "^5",
|
|
70
|
-
"zod": "^3.
|
|
71
|
-
"@modern-js/core": "2.
|
|
72
|
-
"@modern-js/
|
|
73
|
-
"@modern-js/
|
|
74
|
-
"@scripts/build": "2.
|
|
75
|
-
"@scripts/jest-config": "2.
|
|
70
|
+
"zod": "^3.22.3",
|
|
71
|
+
"@modern-js/core": "2.36.0",
|
|
72
|
+
"@modern-js/app-tools": "2.36.0",
|
|
73
|
+
"@modern-js/server-core": "2.36.0",
|
|
74
|
+
"@scripts/build": "2.36.0",
|
|
75
|
+
"@scripts/jest-config": "2.36.0"
|
|
76
76
|
},
|
|
77
77
|
"peerDependencies": {
|
|
78
78
|
"express": "^4.17.1"
|