@modern-js/plugin-express 2.0.0-beta.3 → 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 +89 -0
- package/dist/js/modern/cli/index.js +28 -21
- package/dist/js/modern/context.js +4 -4
- package/dist/js/modern/index.js +4 -1
- package/dist/js/modern/plugin.js +114 -104
- package/dist/js/modern/registerRoutes.js +7 -8
- package/dist/js/modern/runtime/hook.js +4 -1
- package/dist/js/modern/runtime/index.js +8 -4
- package/dist/js/modern/runtime/operators.js +55 -41
- package/dist/js/modern/utils.js +75 -42
- package/dist/js/node/cli/index.js +54 -29
- package/dist/js/node/context.js +27 -10
- package/dist/js/node/index.js +33 -22
- package/dist/js/node/plugin.js +148 -121
- package/dist/js/node/registerRoutes.js +29 -16
- package/dist/js/node/runtime/hook.js +26 -7
- package/dist/js/node/runtime/index.js +29 -43
- package/dist/js/node/runtime/operators.js +79 -48
- package/dist/js/node/utils.js +110 -58
- package/dist/js/treeshaking/cli/index.js +58 -0
- package/dist/js/treeshaking/context.js +3 -0
- package/dist/js/treeshaking/index.js +4 -0
- package/dist/js/treeshaking/plugin.js +379 -0
- package/dist/js/treeshaking/registerRoutes.js +17 -0
- package/dist/js/treeshaking/runtime/hook.js +4 -0
- package/dist/js/treeshaking/runtime/index.js +5 -0
- package/dist/js/treeshaking/runtime/operators.js +197 -0
- package/dist/js/treeshaking/utils.js +514 -0
- package/dist/types/cli/index.d.ts +4 -1
- package/dist/types/plugin.d.ts +2 -0
- package/package.json +22 -22
- package/types.d.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,94 @@
|
|
|
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
|
+
|
|
48
|
+
## 2.0.0-beta.4
|
|
49
|
+
|
|
50
|
+
### Major Changes
|
|
51
|
+
|
|
52
|
+
- dda38c9c3e: chore: v2
|
|
53
|
+
|
|
54
|
+
### Patch Changes
|
|
55
|
+
|
|
56
|
+
- 8d24bed25b: fix: compat Hook API in /server namespace
|
|
57
|
+
fix: 在 @modern-js/runtime/server 命名空间下兼容 Hook API
|
|
58
|
+
- 3bbea92b2a: feat: support Hook、Middleware new API
|
|
59
|
+
feat: 支持 Hook、Middleware 的新 API
|
|
60
|
+
- Updated dependencies [7879e8f]
|
|
61
|
+
- Updated dependencies [6aca875]
|
|
62
|
+
- Updated dependencies [2e6031955e]
|
|
63
|
+
- Updated dependencies [2344eb26ed]
|
|
64
|
+
- Updated dependencies [a2509bfbdb]
|
|
65
|
+
- Updated dependencies [7b7d12c]
|
|
66
|
+
- Updated dependencies [92f0eade39]
|
|
67
|
+
- Updated dependencies [edd1cfb1af]
|
|
68
|
+
- Updated dependencies [cc971eabfc]
|
|
69
|
+
- Updated dependencies [5b9049f2e9]
|
|
70
|
+
- Updated dependencies [6bda14ed71]
|
|
71
|
+
- Updated dependencies [92004d1906]
|
|
72
|
+
- Updated dependencies [b8bbe036c7]
|
|
73
|
+
- Updated dependencies [40ed5874c6]
|
|
74
|
+
- Updated dependencies [87c1ff86b9]
|
|
75
|
+
- Updated dependencies [d5a31df781]
|
|
76
|
+
- Updated dependencies [dda38c9c3e]
|
|
77
|
+
- Updated dependencies [102d32e4ba]
|
|
78
|
+
- Updated dependencies [8b8e1bb571]
|
|
79
|
+
- Updated dependencies [3bbea92b2a]
|
|
80
|
+
- Updated dependencies [b710adb843]
|
|
81
|
+
- Updated dependencies [ea7cf06]
|
|
82
|
+
- Updated dependencies [bbe4c4a]
|
|
83
|
+
- Updated dependencies [e4558a0]
|
|
84
|
+
- Updated dependencies [abf3421a75]
|
|
85
|
+
- Updated dependencies [543be9558e]
|
|
86
|
+
- Updated dependencies [14b712da84]
|
|
87
|
+
- @modern-js/types@2.0.0-beta.4
|
|
88
|
+
- @modern-js/utils@2.0.0-beta.4
|
|
89
|
+
- @modern-js/bff-core@2.0.0-beta.4
|
|
90
|
+
- @modern-js/bff-runtime@2.0.0-beta.4
|
|
91
|
+
|
|
3
92
|
## 2.0.0-beta.3
|
|
4
93
|
|
|
5
94
|
### Major Changes
|
|
@@ -1,29 +1,25 @@
|
|
|
1
|
-
import * as path from
|
|
2
|
-
import { createRuntimeExportsUtils } from
|
|
3
|
-
import { getRelativeRuntimePath } from
|
|
4
|
-
|
|
5
|
-
name:
|
|
6
|
-
setup: api => {
|
|
1
|
+
import * as path from "path";
|
|
2
|
+
import { createRuntimeExportsUtils } from "@modern-js/utils";
|
|
3
|
+
import { getRelativeRuntimePath } from "@modern-js/bff-core";
|
|
4
|
+
var cli_default = () => ({
|
|
5
|
+
name: "@modern-js/plugin-express",
|
|
6
|
+
setup: (api) => {
|
|
7
7
|
let bffExportsUtils;
|
|
8
|
-
const {
|
|
9
|
-
|
|
10
|
-
} = api;
|
|
11
|
-
const runtimeModulePath = path.resolve(__dirname, '../runtime');
|
|
8
|
+
const { useAppContext } = api;
|
|
9
|
+
const runtimeModulePath = path.resolve(__dirname, "../runtime");
|
|
12
10
|
return {
|
|
13
11
|
config() {
|
|
14
12
|
const appContext = useAppContext();
|
|
15
|
-
const {
|
|
16
|
-
|
|
17
|
-
} = appContext;
|
|
18
|
-
bffExportsUtils = createRuntimeExportsUtils(appContext.internalDirectory, 'server');
|
|
13
|
+
const { appDirectory } = appContext;
|
|
14
|
+
bffExportsUtils = createRuntimeExportsUtils(appContext.internalDirectory, "server");
|
|
19
15
|
const serverRuntimePath = bffExportsUtils.getPath();
|
|
20
16
|
const relativeRuntimePath = getRelativeRuntimePath(appDirectory, serverRuntimePath);
|
|
21
|
-
if (process.env.NODE_ENV ===
|
|
17
|
+
if (process.env.NODE_ENV === "production") {
|
|
22
18
|
return {
|
|
23
19
|
source: {
|
|
24
20
|
alias: {
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
"@modern-js/runtime/server": relativeRuntimePath,
|
|
22
|
+
"@modern-js/runtime/express": relativeRuntimePath
|
|
27
23
|
}
|
|
28
24
|
}
|
|
29
25
|
};
|
|
@@ -31,17 +27,25 @@ export default (() => ({
|
|
|
31
27
|
return {
|
|
32
28
|
source: {
|
|
33
29
|
alias: {
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
"@modern-js/runtime/server": serverRuntimePath,
|
|
31
|
+
"@modern-js/runtime/express": serverRuntimePath
|
|
36
32
|
}
|
|
37
33
|
}
|
|
38
34
|
};
|
|
39
35
|
}
|
|
40
36
|
},
|
|
37
|
+
collectServerPlugins({ plugins }) {
|
|
38
|
+
plugins.push({
|
|
39
|
+
"@modern-js/plugin-express": "@modern-js/plugin-express/server"
|
|
40
|
+
});
|
|
41
|
+
return {
|
|
42
|
+
plugins
|
|
43
|
+
};
|
|
44
|
+
},
|
|
41
45
|
addRuntimeExports(input) {
|
|
42
46
|
const currentFile = bffExportsUtils.getPath();
|
|
43
47
|
const relativeRuntimeModulePath = path.relative(path.dirname(currentFile), runtimeModulePath);
|
|
44
|
-
const relativeFramePath = path.relative(path.dirname(currentFile), require.resolve(
|
|
48
|
+
const relativeFramePath = path.relative(path.dirname(currentFile), require.resolve("express"));
|
|
45
49
|
bffExportsUtils.addExport(`const pluginRuntime = require('${relativeRuntimeModulePath}');
|
|
46
50
|
const express = require('${relativeFramePath}')
|
|
47
51
|
module.exports = {
|
|
@@ -53,4 +57,7 @@ export default (() => ({
|
|
|
53
57
|
}
|
|
54
58
|
};
|
|
55
59
|
}
|
|
56
|
-
})
|
|
60
|
+
});
|
|
61
|
+
export {
|
|
62
|
+
cli_default as default
|
|
63
|
+
};
|
package/dist/js/modern/index.js
CHANGED
package/dist/js/modern/plugin.js
CHANGED
|
@@ -1,30 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
var __async = (__this, __arguments, generator) => {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
var fulfilled = (value) => {
|
|
4
|
+
try {
|
|
5
|
+
step(generator.next(value));
|
|
6
|
+
} catch (e) {
|
|
7
|
+
reject(e);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var rejected = (value) => {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.throw(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
import * as path from "path";
|
|
22
|
+
import express from "express";
|
|
23
|
+
import cookieParser from "cookie-parser";
|
|
24
|
+
import { fs, createDebugger, compatRequire } from "@modern-js/utils";
|
|
25
|
+
import finalhandler from "finalhandler";
|
|
6
26
|
import { run } from "./context";
|
|
7
27
|
import registerRoutes from "./registerRoutes";
|
|
8
|
-
const debug = createDebugger(
|
|
9
|
-
const findAppModule =
|
|
10
|
-
const exts = [
|
|
11
|
-
|
|
28
|
+
const debug = createDebugger("express");
|
|
29
|
+
const findAppModule = (apiDir) => __async(void 0, null, function* () {
|
|
30
|
+
const exts = [
|
|
31
|
+
".ts",
|
|
32
|
+
".js"
|
|
33
|
+
];
|
|
34
|
+
const paths = exts.map((ext) => path.resolve(apiDir, `app${ext}`));
|
|
12
35
|
for (const filename of paths) {
|
|
13
|
-
if (
|
|
14
|
-
// 每次获取 app.ts 的时候,避免使用缓存的 app.ts
|
|
36
|
+
if (yield fs.pathExists(filename)) {
|
|
15
37
|
delete require.cache[filename];
|
|
16
|
-
return [
|
|
38
|
+
return [
|
|
39
|
+
compatRequire(filename),
|
|
40
|
+
require(filename)
|
|
41
|
+
];
|
|
17
42
|
}
|
|
18
43
|
}
|
|
19
44
|
return [];
|
|
20
|
-
};
|
|
45
|
+
});
|
|
21
46
|
const initMiddlewares = (middleware, app) => {
|
|
22
|
-
middleware.forEach(middlewareItem => {
|
|
23
|
-
const middlewareFunc = typeof middlewareItem ===
|
|
47
|
+
middleware.forEach((middlewareItem) => {
|
|
48
|
+
const middlewareFunc = typeof middlewareItem === "string" ? compatRequire(middlewareItem) : middlewareItem;
|
|
24
49
|
app.use(middlewareFunc);
|
|
25
50
|
});
|
|
26
51
|
};
|
|
27
|
-
const useRun = app => {
|
|
52
|
+
const useRun = (app) => {
|
|
28
53
|
app.use((req, res, next) => {
|
|
29
54
|
run({
|
|
30
55
|
req,
|
|
@@ -32,7 +57,7 @@ const useRun = app => {
|
|
|
32
57
|
}, next);
|
|
33
58
|
});
|
|
34
59
|
};
|
|
35
|
-
const initApp = app => {
|
|
60
|
+
const initApp = (app) => {
|
|
36
61
|
app.use(cookieParser());
|
|
37
62
|
app.use(express.text());
|
|
38
63
|
app.use(express.urlencoded({
|
|
@@ -41,103 +66,87 @@ const initApp = app => {
|
|
|
41
66
|
app.use(express.json());
|
|
42
67
|
return app;
|
|
43
68
|
};
|
|
44
|
-
|
|
45
|
-
name:
|
|
46
|
-
pre: [
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
app
|
|
65
|
-
|
|
66
|
-
initApp(app);
|
|
67
|
-
if (config) {
|
|
68
|
-
const {
|
|
69
|
-
middleware
|
|
70
|
-
} = config;
|
|
71
|
-
initMiddlewares(middleware, app);
|
|
72
|
-
}
|
|
73
|
-
useRun(app);
|
|
74
|
-
registerRoutes(app, apiHandlerInfos);
|
|
75
|
-
if (hooks) {
|
|
76
|
-
const {
|
|
77
|
-
afterLambdaRegisted
|
|
78
|
-
} = hooks;
|
|
79
|
-
if (afterLambdaRegisted) {
|
|
80
|
-
afterLambdaRegisted(app);
|
|
69
|
+
var plugin_default = () => ({
|
|
70
|
+
name: "@modern-js/plugin-express",
|
|
71
|
+
pre: [
|
|
72
|
+
"@modern-js/plugin-bff"
|
|
73
|
+
],
|
|
74
|
+
post: [
|
|
75
|
+
"@modern-js/plugin-server"
|
|
76
|
+
],
|
|
77
|
+
setup: (api) => ({
|
|
78
|
+
prepareApiServer(_0) {
|
|
79
|
+
return __async(this, arguments, function* ({ pwd, config }) {
|
|
80
|
+
let app;
|
|
81
|
+
const apiDir = path.join(pwd, "./api");
|
|
82
|
+
const appContext = api.useAppContext();
|
|
83
|
+
const apiHandlerInfos = appContext.apiHandlerInfos;
|
|
84
|
+
const mode = appContext.apiMode;
|
|
85
|
+
if (mode === "framework") {
|
|
86
|
+
const appModule = yield findAppModule(apiDir);
|
|
87
|
+
app = appModule[0];
|
|
88
|
+
const hooks = appModule[1];
|
|
89
|
+
if (!app || !app.use) {
|
|
90
|
+
app = express();
|
|
81
91
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
if (config) {
|
|
87
|
-
const {
|
|
88
|
-
middleware
|
|
89
|
-
} = config;
|
|
90
|
-
initMiddlewares(middleware, app);
|
|
91
|
-
}
|
|
92
|
-
useRun(app);
|
|
93
|
-
registerRoutes(app, apiHandlerInfos);
|
|
94
|
-
} else {
|
|
95
|
-
throw new Error(`mode must be function or framework`);
|
|
96
|
-
}
|
|
97
|
-
return (req, res) => new Promise((resolve, reject) => {
|
|
98
|
-
const handler = err => {
|
|
99
|
-
if (err) {
|
|
100
|
-
return reject(err);
|
|
92
|
+
initApp(app);
|
|
93
|
+
if (config) {
|
|
94
|
+
const { middleware } = config;
|
|
95
|
+
initMiddlewares(middleware, app);
|
|
101
96
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
return reject(err);
|
|
97
|
+
useRun(app);
|
|
98
|
+
registerRoutes(app, apiHandlerInfos);
|
|
99
|
+
if (hooks) {
|
|
100
|
+
const { afterLambdaRegisted } = hooks;
|
|
101
|
+
if (afterLambdaRegisted) {
|
|
102
|
+
afterLambdaRegisted(app);
|
|
103
|
+
}
|
|
110
104
|
}
|
|
111
|
-
|
|
105
|
+
} else if (mode === "function") {
|
|
106
|
+
app = express();
|
|
107
|
+
initApp(app);
|
|
108
|
+
if (config) {
|
|
109
|
+
const { middleware: middleware1 } = config;
|
|
110
|
+
initMiddlewares(middleware1, app);
|
|
111
|
+
}
|
|
112
|
+
useRun(app);
|
|
113
|
+
registerRoutes(app, apiHandlerInfos);
|
|
114
|
+
} else {
|
|
115
|
+
throw new Error(`mode must be function or framework`);
|
|
116
|
+
}
|
|
117
|
+
return (req, res) => new Promise((resolve, reject) => {
|
|
118
|
+
const handler = (err) => {
|
|
119
|
+
if (err) {
|
|
120
|
+
return reject(err);
|
|
121
|
+
}
|
|
122
|
+
return finalhandler(req, res, {})(null);
|
|
123
|
+
};
|
|
124
|
+
res.on("finish", (err) => {
|
|
125
|
+
if (err) {
|
|
126
|
+
return reject(err);
|
|
127
|
+
}
|
|
128
|
+
return resolve();
|
|
129
|
+
});
|
|
130
|
+
return app(req, res, handler);
|
|
112
131
|
});
|
|
113
|
-
return app(req, res, handler);
|
|
114
132
|
});
|
|
115
133
|
},
|
|
116
|
-
prepareWebServer({
|
|
117
|
-
|
|
118
|
-
}, next) {
|
|
119
|
-
var _userConfig$server;
|
|
134
|
+
prepareWebServer({ config }, next) {
|
|
135
|
+
var _a2;
|
|
120
136
|
const userConfig = api.useConfigContext();
|
|
121
|
-
if (userConfig
|
|
137
|
+
if ((_a2 = userConfig == null ? void 0 : userConfig.server) == null ? void 0 : _a2.disableFrameworkExt) {
|
|
122
138
|
return next();
|
|
123
139
|
}
|
|
124
140
|
const app = express();
|
|
125
141
|
initApp(app);
|
|
126
142
|
if (config) {
|
|
127
|
-
const {
|
|
128
|
-
|
|
129
|
-
} = config;
|
|
130
|
-
debug('web middleware', middleware);
|
|
143
|
+
const { middleware } = config;
|
|
144
|
+
debug("web middleware", middleware);
|
|
131
145
|
initMiddlewares(middleware, app);
|
|
132
146
|
}
|
|
133
|
-
return ctx => new Promise((resolve, reject) => {
|
|
134
|
-
const {
|
|
135
|
-
|
|
136
|
-
req,
|
|
137
|
-
res
|
|
138
|
-
}
|
|
139
|
-
} = ctx;
|
|
140
|
-
const handler = err => {
|
|
147
|
+
return (ctx) => new Promise((resolve, reject) => {
|
|
148
|
+
const { source: { req, res } } = ctx;
|
|
149
|
+
const handler = (err) => {
|
|
141
150
|
if (err) {
|
|
142
151
|
return reject(err);
|
|
143
152
|
}
|
|
@@ -146,9 +155,7 @@ export default (() => ({
|
|
|
146
155
|
}
|
|
147
156
|
return resolve();
|
|
148
157
|
};
|
|
149
|
-
|
|
150
|
-
// when user call res.send
|
|
151
|
-
res.on('finish', err => {
|
|
158
|
+
res.on("finish", (err) => {
|
|
152
159
|
if (err) {
|
|
153
160
|
return reject(err);
|
|
154
161
|
}
|
|
@@ -158,4 +165,7 @@ export default (() => ({
|
|
|
158
165
|
});
|
|
159
166
|
}
|
|
160
167
|
})
|
|
161
|
-
})
|
|
168
|
+
});
|
|
169
|
+
export {
|
|
170
|
+
plugin_default as default
|
|
171
|
+
};
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "reflect-metadata";
|
|
2
2
|
import { createRouteHandler } from "./utils";
|
|
3
3
|
const registerRoutes = (app, handlerInfos) => {
|
|
4
|
-
handlerInfos.forEach(({
|
|
5
|
-
routePath,
|
|
6
|
-
handler,
|
|
7
|
-
httpMethod
|
|
8
|
-
}) => {
|
|
4
|
+
handlerInfos.forEach(({ routePath, handler, httpMethod }) => {
|
|
9
5
|
const routeHandler = createRouteHandler(handler);
|
|
10
6
|
const method = httpMethod.toLowerCase();
|
|
11
|
-
const routeMiddlwares = Reflect.getMetadata(
|
|
7
|
+
const routeMiddlwares = Reflect.getMetadata("middleware", handler) || [];
|
|
12
8
|
if (routeMiddlwares.length > 0) {
|
|
13
9
|
app[method](routePath, routeMiddlwares, routeHandler);
|
|
14
10
|
} else {
|
|
@@ -16,4 +12,7 @@ const registerRoutes = (app, handlerInfos) => {
|
|
|
16
12
|
}
|
|
17
13
|
});
|
|
18
14
|
};
|
|
19
|
-
|
|
15
|
+
var registerRoutes_default = registerRoutes;
|
|
16
|
+
export {
|
|
17
|
+
registerRoutes_default as default
|
|
18
|
+
};
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export * from "./operators";
|
|
1
|
+
export * from "@modern-js/bff-core";
|
|
2
|
+
import { useContext } from "../context";
|
|
3
|
+
import { hook } from "./hook";
|
|
4
|
+
export * from "./operators";
|
|
5
|
+
export {
|
|
6
|
+
hook,
|
|
7
|
+
useContext
|
|
8
|
+
};
|
|
@@ -1,54 +1,68 @@
|
|
|
1
|
+
var __async = (__this, __arguments, generator) => {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
var fulfilled = (value) => {
|
|
4
|
+
try {
|
|
5
|
+
step(generator.next(value));
|
|
6
|
+
} catch (e) {
|
|
7
|
+
reject(e);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var rejected = (value) => {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.throw(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
1
21
|
import { useContext } from "../context";
|
|
2
|
-
|
|
22
|
+
const Pipe = (func) => {
|
|
3
23
|
return {
|
|
4
|
-
name:
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if (output) {
|
|
28
|
-
return executeHelper.result = output;
|
|
29
|
-
} else {
|
|
30
|
-
// eslint-disable-next-line consistent-return
|
|
31
|
-
return;
|
|
24
|
+
name: "pipe",
|
|
25
|
+
execute(executeHelper, next) {
|
|
26
|
+
return __async(this, null, function* () {
|
|
27
|
+
const { inputs } = executeHelper;
|
|
28
|
+
const ctx = useContext();
|
|
29
|
+
const { res } = ctx;
|
|
30
|
+
if (typeof func === "function") {
|
|
31
|
+
let isPiped = true;
|
|
32
|
+
const end = (value) => {
|
|
33
|
+
isPiped = false;
|
|
34
|
+
if (typeof value === "function") {
|
|
35
|
+
value(res);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
return value;
|
|
39
|
+
};
|
|
40
|
+
const output = yield func(inputs, end);
|
|
41
|
+
if (!isPiped) {
|
|
42
|
+
if (output) {
|
|
43
|
+
return executeHelper.result = output;
|
|
44
|
+
} else {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
32
47
|
}
|
|
48
|
+
executeHelper.inputs = output;
|
|
49
|
+
yield next();
|
|
33
50
|
}
|
|
34
|
-
|
|
35
|
-
await next();
|
|
36
|
-
}
|
|
51
|
+
});
|
|
37
52
|
}
|
|
38
53
|
};
|
|
39
54
|
};
|
|
40
|
-
|
|
41
|
-
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
42
|
-
|
|
43
|
-
export const Middleware = middleware => {
|
|
55
|
+
const Middleware = (middleware) => {
|
|
44
56
|
return {
|
|
45
|
-
name:
|
|
57
|
+
name: "middleware",
|
|
46
58
|
metadata(helper) {
|
|
47
|
-
const middlewares = helper.getMetadata(
|
|
59
|
+
const middlewares = helper.getMetadata("pipe") || [];
|
|
48
60
|
middlewares.push(middleware);
|
|
49
|
-
helper.setMetadata(
|
|
61
|
+
helper.setMetadata("middleware", middlewares);
|
|
50
62
|
}
|
|
51
63
|
};
|
|
52
64
|
};
|
|
53
|
-
|
|
54
|
-
|
|
65
|
+
export {
|
|
66
|
+
Middleware,
|
|
67
|
+
Pipe
|
|
68
|
+
};
|