@modern-js/plugin-express 2.0.0-beta.3 → 2.0.0-beta.4
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 +44 -0
- package/dist/js/modern/cli/index.js +34 -23
- package/dist/js/modern/context.js +4 -4
- package/dist/js/modern/index.js +4 -1
- package/dist/js/modern/plugin.js +105 -108
- 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 +82 -45
- package/dist/js/node/cli/index.js +57 -30
- package/dist/js/node/context.js +24 -12
- package/dist/js/node/index.js +31 -22
- package/dist/js/node/plugin.js +136 -124
- package/dist/js/node/registerRoutes.js +27 -16
- package/dist/js/node/runtime/hook.js +22 -7
- package/dist/js/node/runtime/index.js +25 -44
- package/dist/js/node/runtime/operators.js +74 -48
- package/dist/js/node/utils.js +106 -59
- package/dist/js/treeshaking/cli/index.js +49 -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 +2 -0
- package/dist/types/plugin.d.ts +2 -0
- package/package.json +9 -14
- package/types.d.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,49 @@
|
|
|
1
1
|
# @modern-js/plugin-express
|
|
2
2
|
|
|
3
|
+
## 2.0.0-beta.4
|
|
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 [7879e8f]
|
|
16
|
+
- Updated dependencies [6aca875]
|
|
17
|
+
- Updated dependencies [2e6031955e]
|
|
18
|
+
- Updated dependencies [2344eb26ed]
|
|
19
|
+
- Updated dependencies [a2509bfbdb]
|
|
20
|
+
- Updated dependencies [7b7d12c]
|
|
21
|
+
- Updated dependencies [92f0eade39]
|
|
22
|
+
- Updated dependencies [edd1cfb1af]
|
|
23
|
+
- Updated dependencies [cc971eabfc]
|
|
24
|
+
- Updated dependencies [5b9049f2e9]
|
|
25
|
+
- Updated dependencies [6bda14ed71]
|
|
26
|
+
- Updated dependencies [92004d1906]
|
|
27
|
+
- Updated dependencies [b8bbe036c7]
|
|
28
|
+
- Updated dependencies [40ed5874c6]
|
|
29
|
+
- Updated dependencies [87c1ff86b9]
|
|
30
|
+
- Updated dependencies [d5a31df781]
|
|
31
|
+
- Updated dependencies [dda38c9c3e]
|
|
32
|
+
- Updated dependencies [102d32e4ba]
|
|
33
|
+
- Updated dependencies [8b8e1bb571]
|
|
34
|
+
- Updated dependencies [3bbea92b2a]
|
|
35
|
+
- Updated dependencies [b710adb843]
|
|
36
|
+
- Updated dependencies [ea7cf06]
|
|
37
|
+
- Updated dependencies [bbe4c4a]
|
|
38
|
+
- Updated dependencies [e4558a0]
|
|
39
|
+
- Updated dependencies [abf3421a75]
|
|
40
|
+
- Updated dependencies [543be9558e]
|
|
41
|
+
- Updated dependencies [14b712da84]
|
|
42
|
+
- @modern-js/types@2.0.0-beta.4
|
|
43
|
+
- @modern-js/utils@2.0.0-beta.4
|
|
44
|
+
- @modern-js/bff-core@2.0.0-beta.4
|
|
45
|
+
- @modern-js/bff-runtime@2.0.0-beta.4
|
|
46
|
+
|
|
3
47
|
## 2.0.0-beta.3
|
|
4
48
|
|
|
5
49
|
### Major Changes
|
|
@@ -1,29 +1,31 @@
|
|
|
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
|
-
|
|
18
|
-
|
|
13
|
+
const { appDirectory } = appContext;
|
|
14
|
+
bffExportsUtils = createRuntimeExportsUtils(
|
|
15
|
+
appContext.internalDirectory,
|
|
16
|
+
"server"
|
|
17
|
+
);
|
|
19
18
|
const serverRuntimePath = bffExportsUtils.getPath();
|
|
20
|
-
const relativeRuntimePath = getRelativeRuntimePath(
|
|
21
|
-
|
|
19
|
+
const relativeRuntimePath = getRelativeRuntimePath(
|
|
20
|
+
appDirectory,
|
|
21
|
+
serverRuntimePath
|
|
22
|
+
);
|
|
23
|
+
if (process.env.NODE_ENV === "production") {
|
|
22
24
|
return {
|
|
23
25
|
source: {
|
|
24
26
|
alias: {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
"@modern-js/runtime/server": relativeRuntimePath,
|
|
28
|
+
"@modern-js/runtime/express": relativeRuntimePath
|
|
27
29
|
}
|
|
28
30
|
}
|
|
29
31
|
};
|
|
@@ -31,8 +33,8 @@ export default (() => ({
|
|
|
31
33
|
return {
|
|
32
34
|
source: {
|
|
33
35
|
alias: {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
"@modern-js/runtime/server": serverRuntimePath,
|
|
37
|
+
"@modern-js/runtime/express": serverRuntimePath
|
|
36
38
|
}
|
|
37
39
|
}
|
|
38
40
|
};
|
|
@@ -40,8 +42,14 @@ export default (() => ({
|
|
|
40
42
|
},
|
|
41
43
|
addRuntimeExports(input) {
|
|
42
44
|
const currentFile = bffExportsUtils.getPath();
|
|
43
|
-
const relativeRuntimeModulePath = path.relative(
|
|
44
|
-
|
|
45
|
+
const relativeRuntimeModulePath = path.relative(
|
|
46
|
+
path.dirname(currentFile),
|
|
47
|
+
runtimeModulePath
|
|
48
|
+
);
|
|
49
|
+
const relativeFramePath = path.relative(
|
|
50
|
+
path.dirname(currentFile),
|
|
51
|
+
require.resolve("express")
|
|
52
|
+
);
|
|
45
53
|
bffExportsUtils.addExport(`const pluginRuntime = require('${relativeRuntimeModulePath}');
|
|
46
54
|
const express = require('${relativeFramePath}')
|
|
47
55
|
module.exports = {
|
|
@@ -53,4 +61,7 @@ export default (() => ({
|
|
|
53
61
|
}
|
|
54
62
|
};
|
|
55
63
|
}
|
|
56
|
-
})
|
|
64
|
+
});
|
|
65
|
+
export {
|
|
66
|
+
cli_default as default
|
|
67
|
+
};
|
package/dist/js/modern/index.js
CHANGED
package/dist/js/modern/plugin.js
CHANGED
|
@@ -1,143 +1,139 @@
|
|
|
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
|
-
const paths = exts.map(ext => path.resolve(apiDir, `app${ext}`));
|
|
28
|
+
const debug = createDebugger("express");
|
|
29
|
+
const findAppModule = (apiDir) => __async(void 0, null, function* () {
|
|
30
|
+
const exts = [".ts", ".js"];
|
|
31
|
+
const paths = exts.map((ext) => path.resolve(apiDir, `app${ext}`));
|
|
12
32
|
for (const filename of paths) {
|
|
13
|
-
if (
|
|
14
|
-
// 每次获取 app.ts 的时候,避免使用缓存的 app.ts
|
|
33
|
+
if (yield fs.pathExists(filename)) {
|
|
15
34
|
delete require.cache[filename];
|
|
16
35
|
return [compatRequire(filename), require(filename)];
|
|
17
36
|
}
|
|
18
37
|
}
|
|
19
38
|
return [];
|
|
20
|
-
};
|
|
39
|
+
});
|
|
21
40
|
const initMiddlewares = (middleware, app) => {
|
|
22
|
-
middleware.forEach(middlewareItem => {
|
|
23
|
-
const middlewareFunc = typeof middlewareItem ===
|
|
41
|
+
middleware.forEach((middlewareItem) => {
|
|
42
|
+
const middlewareFunc = typeof middlewareItem === "string" ? compatRequire(middlewareItem) : middlewareItem;
|
|
24
43
|
app.use(middlewareFunc);
|
|
25
44
|
});
|
|
26
45
|
};
|
|
27
|
-
const useRun = app => {
|
|
46
|
+
const useRun = (app) => {
|
|
28
47
|
app.use((req, res, next) => {
|
|
29
|
-
run({
|
|
30
|
-
req,
|
|
31
|
-
res
|
|
32
|
-
}, next);
|
|
48
|
+
run({ req, res }, next);
|
|
33
49
|
});
|
|
34
50
|
};
|
|
35
|
-
const initApp = app => {
|
|
51
|
+
const initApp = (app) => {
|
|
36
52
|
app.use(cookieParser());
|
|
37
53
|
app.use(express.text());
|
|
38
|
-
app.use(express.urlencoded({
|
|
39
|
-
extended: true
|
|
40
|
-
}));
|
|
54
|
+
app.use(express.urlencoded({ extended: true }));
|
|
41
55
|
app.use(express.json());
|
|
42
56
|
return app;
|
|
43
57
|
};
|
|
44
|
-
|
|
45
|
-
name:
|
|
46
|
-
pre: [
|
|
47
|
-
post: [
|
|
48
|
-
setup: api => ({
|
|
49
|
-
|
|
50
|
-
pwd,
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (!app || !app.use) {
|
|
63
|
-
// console.warn('There is not api/app.ts.');
|
|
64
|
-
app = express();
|
|
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);
|
|
58
|
+
var plugin_default = () => ({
|
|
59
|
+
name: "@modern-js/plugin-express",
|
|
60
|
+
pre: ["@modern-js/plugin-bff"],
|
|
61
|
+
post: ["@modern-js/plugin-server"],
|
|
62
|
+
setup: (api) => ({
|
|
63
|
+
prepareApiServer(_0) {
|
|
64
|
+
return __async(this, arguments, function* ({ pwd, config }) {
|
|
65
|
+
let app;
|
|
66
|
+
const apiDir = path.join(pwd, "./api");
|
|
67
|
+
const appContext = api.useAppContext();
|
|
68
|
+
const apiHandlerInfos = appContext.apiHandlerInfos;
|
|
69
|
+
const mode = appContext.apiMode;
|
|
70
|
+
if (mode === "framework") {
|
|
71
|
+
const appModule = yield findAppModule(apiDir);
|
|
72
|
+
app = appModule[0];
|
|
73
|
+
const hooks = appModule[1];
|
|
74
|
+
if (!app || !app.use) {
|
|
75
|
+
app = express();
|
|
81
76
|
}
|
|
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);
|
|
77
|
+
initApp(app);
|
|
78
|
+
if (config) {
|
|
79
|
+
const { middleware } = config;
|
|
80
|
+
initMiddlewares(middleware, app);
|
|
101
81
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
return reject(err);
|
|
82
|
+
useRun(app);
|
|
83
|
+
registerRoutes(app, apiHandlerInfos);
|
|
84
|
+
if (hooks) {
|
|
85
|
+
const { afterLambdaRegisted } = hooks;
|
|
86
|
+
if (afterLambdaRegisted) {
|
|
87
|
+
afterLambdaRegisted(app);
|
|
88
|
+
}
|
|
110
89
|
}
|
|
111
|
-
|
|
90
|
+
} else if (mode === "function") {
|
|
91
|
+
app = express();
|
|
92
|
+
initApp(app);
|
|
93
|
+
if (config) {
|
|
94
|
+
const { middleware } = config;
|
|
95
|
+
initMiddlewares(middleware, app);
|
|
96
|
+
}
|
|
97
|
+
useRun(app);
|
|
98
|
+
registerRoutes(app, apiHandlerInfos);
|
|
99
|
+
} else {
|
|
100
|
+
throw new Error(`mode must be function or framework`);
|
|
101
|
+
}
|
|
102
|
+
return (req, res) => new Promise((resolve, reject) => {
|
|
103
|
+
const handler = (err) => {
|
|
104
|
+
if (err) {
|
|
105
|
+
return reject(err);
|
|
106
|
+
}
|
|
107
|
+
return finalhandler(req, res, {})(null);
|
|
108
|
+
};
|
|
109
|
+
res.on("finish", (err) => {
|
|
110
|
+
if (err) {
|
|
111
|
+
return reject(err);
|
|
112
|
+
}
|
|
113
|
+
return resolve();
|
|
114
|
+
});
|
|
115
|
+
return app(req, res, handler);
|
|
112
116
|
});
|
|
113
|
-
return app(req, res, handler);
|
|
114
117
|
});
|
|
115
118
|
},
|
|
116
|
-
prepareWebServer({
|
|
117
|
-
|
|
118
|
-
}, next) {
|
|
119
|
-
var _userConfig$server;
|
|
119
|
+
prepareWebServer({ config }, next) {
|
|
120
|
+
var _a2;
|
|
120
121
|
const userConfig = api.useConfigContext();
|
|
121
|
-
if (userConfig
|
|
122
|
+
if ((_a2 = userConfig == null ? void 0 : userConfig.server) == null ? void 0 : _a2.disableFrameworkExt) {
|
|
122
123
|
return next();
|
|
123
124
|
}
|
|
124
125
|
const app = express();
|
|
125
126
|
initApp(app);
|
|
126
127
|
if (config) {
|
|
127
|
-
const {
|
|
128
|
-
|
|
129
|
-
} = config;
|
|
130
|
-
debug('web middleware', middleware);
|
|
128
|
+
const { middleware } = config;
|
|
129
|
+
debug("web middleware", middleware);
|
|
131
130
|
initMiddlewares(middleware, app);
|
|
132
131
|
}
|
|
133
|
-
return ctx => new Promise((resolve, reject) => {
|
|
132
|
+
return (ctx) => new Promise((resolve, reject) => {
|
|
134
133
|
const {
|
|
135
|
-
source: {
|
|
136
|
-
req,
|
|
137
|
-
res
|
|
138
|
-
}
|
|
134
|
+
source: { req, res }
|
|
139
135
|
} = ctx;
|
|
140
|
-
const handler = err => {
|
|
136
|
+
const handler = (err) => {
|
|
141
137
|
if (err) {
|
|
142
138
|
return reject(err);
|
|
143
139
|
}
|
|
@@ -146,9 +142,7 @@ export default (() => ({
|
|
|
146
142
|
}
|
|
147
143
|
return resolve();
|
|
148
144
|
};
|
|
149
|
-
|
|
150
|
-
// when user call res.send
|
|
151
|
-
res.on('finish', err => {
|
|
145
|
+
res.on("finish", (err) => {
|
|
152
146
|
if (err) {
|
|
153
147
|
return reject(err);
|
|
154
148
|
}
|
|
@@ -158,4 +152,7 @@ export default (() => ({
|
|
|
158
152
|
});
|
|
159
153
|
}
|
|
160
154
|
})
|
|
161
|
-
})
|
|
155
|
+
});
|
|
156
|
+
export {
|
|
157
|
+
plugin_default as default
|
|
158
|
+
};
|
|
@@ -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
|
+
};
|