@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/dist/js/node/plugin.js
CHANGED
|
@@ -1,163 +1,189 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
var __async = (__this, __arguments, generator) => {
|
|
25
|
+
return new Promise((resolve, reject) => {
|
|
26
|
+
var fulfilled = (value) => {
|
|
27
|
+
try {
|
|
28
|
+
step(generator.next(value));
|
|
29
|
+
} catch (e) {
|
|
30
|
+
reject(e);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var rejected = (value) => {
|
|
34
|
+
try {
|
|
35
|
+
step(generator.throw(value));
|
|
36
|
+
} catch (e) {
|
|
37
|
+
reject(e);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
41
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
var plugin_exports = {};
|
|
45
|
+
__export(plugin_exports, {
|
|
46
|
+
default: () => plugin_default
|
|
5
47
|
});
|
|
6
|
-
exports
|
|
7
|
-
var path =
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const paths = exts.map(ext => path.resolve(apiDir, `app${ext}`));
|
|
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
|
+
const debug = (0, import_utils.createDebugger)("express");
|
|
57
|
+
const findAppModule = (apiDir) => __async(void 0, null, function* () {
|
|
58
|
+
const exts = [
|
|
59
|
+
".ts",
|
|
60
|
+
".js"
|
|
61
|
+
];
|
|
62
|
+
const paths = exts.map((ext) => path.resolve(apiDir, `app${ext}`));
|
|
21
63
|
for (const filename of paths) {
|
|
22
|
-
if (
|
|
23
|
-
// 每次获取 app.ts 的时候,避免使用缓存的 app.ts
|
|
64
|
+
if (yield import_utils.fs.pathExists(filename)) {
|
|
24
65
|
delete require.cache[filename];
|
|
25
|
-
return [
|
|
66
|
+
return [
|
|
67
|
+
(0, import_utils.compatRequire)(filename),
|
|
68
|
+
require(filename)
|
|
69
|
+
];
|
|
26
70
|
}
|
|
27
71
|
}
|
|
28
72
|
return [];
|
|
29
|
-
};
|
|
73
|
+
});
|
|
30
74
|
const initMiddlewares = (middleware, app) => {
|
|
31
|
-
middleware.forEach(middlewareItem => {
|
|
32
|
-
const middlewareFunc = typeof middlewareItem ===
|
|
75
|
+
middleware.forEach((middlewareItem) => {
|
|
76
|
+
const middlewareFunc = typeof middlewareItem === "string" ? (0, import_utils.compatRequire)(middlewareItem) : middlewareItem;
|
|
33
77
|
app.use(middlewareFunc);
|
|
34
78
|
});
|
|
35
79
|
};
|
|
36
|
-
const useRun = app => {
|
|
80
|
+
const useRun = (app) => {
|
|
37
81
|
app.use((req, res, next) => {
|
|
38
|
-
(0,
|
|
82
|
+
(0, import_context.run)({
|
|
39
83
|
req,
|
|
40
84
|
res
|
|
41
85
|
}, next);
|
|
42
86
|
});
|
|
43
87
|
};
|
|
44
|
-
const initApp = app => {
|
|
45
|
-
app.use((0,
|
|
46
|
-
app.use(
|
|
47
|
-
app.use(
|
|
88
|
+
const initApp = (app) => {
|
|
89
|
+
app.use((0, import_cookie_parser.default)());
|
|
90
|
+
app.use(import_express.default.text());
|
|
91
|
+
app.use(import_express.default.urlencoded({
|
|
48
92
|
extended: true
|
|
49
93
|
}));
|
|
50
|
-
app.use(
|
|
94
|
+
app.use(import_express.default.json());
|
|
51
95
|
return app;
|
|
52
96
|
};
|
|
53
|
-
var
|
|
54
|
-
name:
|
|
55
|
-
pre: [
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
app
|
|
74
|
-
|
|
75
|
-
initApp(app);
|
|
76
|
-
if (config) {
|
|
77
|
-
const {
|
|
78
|
-
middleware
|
|
79
|
-
} = config;
|
|
80
|
-
initMiddlewares(middleware, app);
|
|
81
|
-
}
|
|
82
|
-
useRun(app);
|
|
83
|
-
(0, _registerRoutes.default)(app, apiHandlerInfos);
|
|
84
|
-
if (hooks) {
|
|
85
|
-
const {
|
|
86
|
-
afterLambdaRegisted
|
|
87
|
-
} = hooks;
|
|
88
|
-
if (afterLambdaRegisted) {
|
|
89
|
-
afterLambdaRegisted(app);
|
|
97
|
+
var plugin_default = () => ({
|
|
98
|
+
name: "@modern-js/plugin-express",
|
|
99
|
+
pre: [
|
|
100
|
+
"@modern-js/plugin-bff"
|
|
101
|
+
],
|
|
102
|
+
post: [
|
|
103
|
+
"@modern-js/plugin-server"
|
|
104
|
+
],
|
|
105
|
+
setup: (api) => ({
|
|
106
|
+
prepareApiServer(_0) {
|
|
107
|
+
return __async(this, arguments, function* ({ pwd, config }) {
|
|
108
|
+
let app;
|
|
109
|
+
const apiDir = path.join(pwd, "./api");
|
|
110
|
+
const appContext = api.useAppContext();
|
|
111
|
+
const apiHandlerInfos = appContext.apiHandlerInfos;
|
|
112
|
+
const mode = appContext.apiMode;
|
|
113
|
+
if (mode === "framework") {
|
|
114
|
+
const appModule = yield findAppModule(apiDir);
|
|
115
|
+
app = appModule[0];
|
|
116
|
+
const hooks = appModule[1];
|
|
117
|
+
if (!app || !app.use) {
|
|
118
|
+
app = (0, import_express.default)();
|
|
90
119
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
if (config) {
|
|
96
|
-
const {
|
|
97
|
-
middleware
|
|
98
|
-
} = config;
|
|
99
|
-
initMiddlewares(middleware, app);
|
|
100
|
-
}
|
|
101
|
-
useRun(app);
|
|
102
|
-
(0, _registerRoutes.default)(app, apiHandlerInfos);
|
|
103
|
-
} else {
|
|
104
|
-
throw new Error(`mode must be function or framework`);
|
|
105
|
-
}
|
|
106
|
-
return (req, res) => new Promise((resolve, reject) => {
|
|
107
|
-
const handler = err => {
|
|
108
|
-
if (err) {
|
|
109
|
-
return reject(err);
|
|
120
|
+
initApp(app);
|
|
121
|
+
if (config) {
|
|
122
|
+
const { middleware } = config;
|
|
123
|
+
initMiddlewares(middleware, app);
|
|
110
124
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
return reject(err);
|
|
125
|
+
useRun(app);
|
|
126
|
+
(0, import_registerRoutes.default)(app, apiHandlerInfos);
|
|
127
|
+
if (hooks) {
|
|
128
|
+
const { afterLambdaRegisted } = hooks;
|
|
129
|
+
if (afterLambdaRegisted) {
|
|
130
|
+
afterLambdaRegisted(app);
|
|
131
|
+
}
|
|
119
132
|
}
|
|
120
|
-
|
|
133
|
+
} else if (mode === "function") {
|
|
134
|
+
app = (0, import_express.default)();
|
|
135
|
+
initApp(app);
|
|
136
|
+
if (config) {
|
|
137
|
+
const { middleware: middleware1 } = config;
|
|
138
|
+
initMiddlewares(middleware1, app);
|
|
139
|
+
}
|
|
140
|
+
useRun(app);
|
|
141
|
+
(0, import_registerRoutes.default)(app, apiHandlerInfos);
|
|
142
|
+
} else {
|
|
143
|
+
throw new Error(`mode must be function or framework`);
|
|
144
|
+
}
|
|
145
|
+
return (req, res) => new Promise((resolve, reject) => {
|
|
146
|
+
const handler = (err) => {
|
|
147
|
+
if (err) {
|
|
148
|
+
return reject(err);
|
|
149
|
+
}
|
|
150
|
+
return (0, import_finalhandler.default)(req, res, {})(null);
|
|
151
|
+
};
|
|
152
|
+
res.on("finish", (err) => {
|
|
153
|
+
if (err) {
|
|
154
|
+
return reject(err);
|
|
155
|
+
}
|
|
156
|
+
return resolve();
|
|
157
|
+
});
|
|
158
|
+
return app(req, res, handler);
|
|
121
159
|
});
|
|
122
|
-
return app(req, res, handler);
|
|
123
160
|
});
|
|
124
161
|
},
|
|
125
|
-
prepareWebServer({
|
|
126
|
-
|
|
127
|
-
}, next) {
|
|
128
|
-
var _userConfig$server;
|
|
162
|
+
prepareWebServer({ config }, next) {
|
|
163
|
+
var _a2;
|
|
129
164
|
const userConfig = api.useConfigContext();
|
|
130
|
-
if (userConfig
|
|
165
|
+
if ((_a2 = userConfig == null ? void 0 : userConfig.server) == null ? void 0 : _a2.disableFrameworkExt) {
|
|
131
166
|
return next();
|
|
132
167
|
}
|
|
133
|
-
const app = (0,
|
|
168
|
+
const app = (0, import_express.default)();
|
|
134
169
|
initApp(app);
|
|
135
170
|
if (config) {
|
|
136
|
-
const {
|
|
137
|
-
|
|
138
|
-
} = config;
|
|
139
|
-
debug('web middleware', middleware);
|
|
171
|
+
const { middleware } = config;
|
|
172
|
+
debug("web middleware", middleware);
|
|
140
173
|
initMiddlewares(middleware, app);
|
|
141
174
|
}
|
|
142
|
-
return ctx => new Promise((resolve, reject) => {
|
|
143
|
-
const {
|
|
144
|
-
|
|
145
|
-
req,
|
|
146
|
-
res
|
|
147
|
-
}
|
|
148
|
-
} = ctx;
|
|
149
|
-
const handler = err => {
|
|
175
|
+
return (ctx) => new Promise((resolve, reject) => {
|
|
176
|
+
const { source: { req, res } } = ctx;
|
|
177
|
+
const handler = (err) => {
|
|
150
178
|
if (err) {
|
|
151
179
|
return reject(err);
|
|
152
180
|
}
|
|
153
181
|
if (res.headersSent && res.statusCode !== 200) {
|
|
154
|
-
(0,
|
|
182
|
+
(0, import_finalhandler.default)(req, res, {})(null);
|
|
155
183
|
}
|
|
156
184
|
return resolve();
|
|
157
185
|
};
|
|
158
|
-
|
|
159
|
-
// when user call res.send
|
|
160
|
-
res.on('finish', err => {
|
|
186
|
+
res.on("finish", (err) => {
|
|
161
187
|
if (err) {
|
|
162
188
|
return reject(err);
|
|
163
189
|
}
|
|
@@ -168,4 +194,5 @@ var _default = () => ({
|
|
|
168
194
|
}
|
|
169
195
|
})
|
|
170
196
|
});
|
|
171
|
-
|
|
197
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
198
|
+
0 && (module.exports = {});
|
|
@@ -1,20 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var registerRoutes_exports = {};
|
|
19
|
+
__export(registerRoutes_exports, {
|
|
20
|
+
default: () => registerRoutes_default
|
|
5
21
|
});
|
|
6
|
-
exports
|
|
7
|
-
require("reflect-metadata");
|
|
8
|
-
var
|
|
22
|
+
module.exports = __toCommonJS(registerRoutes_exports);
|
|
23
|
+
var import_reflect_metadata = require("reflect-metadata");
|
|
24
|
+
var import_utils = require("./utils");
|
|
9
25
|
const registerRoutes = (app, handlerInfos) => {
|
|
10
|
-
handlerInfos.forEach(({
|
|
11
|
-
|
|
12
|
-
handler,
|
|
13
|
-
httpMethod
|
|
14
|
-
}) => {
|
|
15
|
-
const routeHandler = (0, _utils.createRouteHandler)(handler);
|
|
26
|
+
handlerInfos.forEach(({ routePath, handler, httpMethod }) => {
|
|
27
|
+
const routeHandler = (0, import_utils.createRouteHandler)(handler);
|
|
16
28
|
const method = httpMethod.toLowerCase();
|
|
17
|
-
const routeMiddlwares = Reflect.getMetadata(
|
|
29
|
+
const routeMiddlwares = Reflect.getMetadata("middleware", handler) || [];
|
|
18
30
|
if (routeMiddlwares.length > 0) {
|
|
19
31
|
app[method](routePath, routeMiddlwares, routeHandler);
|
|
20
32
|
} else {
|
|
@@ -22,5 +34,6 @@ const registerRoutes = (app, handlerInfos) => {
|
|
|
22
34
|
}
|
|
23
35
|
});
|
|
24
36
|
};
|
|
25
|
-
var
|
|
26
|
-
|
|
37
|
+
var registerRoutes_default = registerRoutes;
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 && (module.exports = {});
|
|
@@ -1,8 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var hook_exports = {};
|
|
19
|
+
__export(hook_exports, {
|
|
20
|
+
hook: () => hook
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(hook_exports);
|
|
23
|
+
const hook = (attacher) => attacher;
|
|
24
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
25
|
+
0 && (module.exports = {
|
|
26
|
+
hook
|
|
5
27
|
});
|
|
6
|
-
exports.hook = void 0;
|
|
7
|
-
const hook = attacher => attacher;
|
|
8
|
-
exports.hook = hook;
|
|
@@ -1,47 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
hook: true
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
8
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
});
|
|
16
|
-
Object.defineProperty(exports, "useContext", {
|
|
17
|
-
enumerable: true,
|
|
18
|
-
get: function () {
|
|
19
|
-
return _context.useContext;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
20
14
|
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var runtime_exports = {};
|
|
20
|
+
__export(runtime_exports, {
|
|
21
|
+
hook: () => import_hook.hook,
|
|
22
|
+
useContext: () => import_context.useContext
|
|
21
23
|
});
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
});
|
|
24
|
+
module.exports = __toCommonJS(runtime_exports);
|
|
25
|
+
__reExport(runtime_exports, require("@modern-js/bff-core"), module.exports);
|
|
26
|
+
var import_context = require("../context");
|
|
27
|
+
var import_hook = require("./hook");
|
|
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
33
|
});
|
|
34
|
-
var _context = require("../context");
|
|
35
|
-
var _hook = require("./hook");
|
|
36
|
-
var _operators = require("./operators");
|
|
37
|
-
Object.keys(_operators).forEach(function (key) {
|
|
38
|
-
if (key === "default" || key === "__esModule") return;
|
|
39
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
40
|
-
if (key in exports && exports[key] === _operators[key]) return;
|
|
41
|
-
Object.defineProperty(exports, key, {
|
|
42
|
-
enumerable: true,
|
|
43
|
-
get: function () {
|
|
44
|
-
return _operators[key];
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
});
|
|
@@ -1,61 +1,92 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var __async = (__this, __arguments, generator) => {
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
var fulfilled = (value) => {
|
|
21
|
+
try {
|
|
22
|
+
step(generator.next(value));
|
|
23
|
+
} catch (e) {
|
|
24
|
+
reject(e);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
var rejected = (value) => {
|
|
28
|
+
try {
|
|
29
|
+
step(generator.throw(value));
|
|
30
|
+
} catch (e) {
|
|
31
|
+
reject(e);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
35
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
var operators_exports = {};
|
|
39
|
+
__export(operators_exports, {
|
|
40
|
+
Middleware: () => Middleware,
|
|
41
|
+
Pipe: () => Pipe
|
|
5
42
|
});
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
const Pipe = func => {
|
|
43
|
+
module.exports = __toCommonJS(operators_exports);
|
|
44
|
+
var import_context = require("../context");
|
|
45
|
+
const Pipe = (func) => {
|
|
9
46
|
return {
|
|
10
|
-
name:
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (output) {
|
|
34
|
-
return executeHelper.result = output;
|
|
35
|
-
} else {
|
|
36
|
-
// eslint-disable-next-line consistent-return
|
|
37
|
-
return;
|
|
47
|
+
name: "pipe",
|
|
48
|
+
execute(executeHelper, next) {
|
|
49
|
+
return __async(this, null, function* () {
|
|
50
|
+
const { inputs } = executeHelper;
|
|
51
|
+
const ctx = (0, import_context.useContext)();
|
|
52
|
+
const { res } = ctx;
|
|
53
|
+
if (typeof func === "function") {
|
|
54
|
+
let isPiped = true;
|
|
55
|
+
const end = (value) => {
|
|
56
|
+
isPiped = false;
|
|
57
|
+
if (typeof value === "function") {
|
|
58
|
+
value(res);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
return value;
|
|
62
|
+
};
|
|
63
|
+
const output = yield func(inputs, end);
|
|
64
|
+
if (!isPiped) {
|
|
65
|
+
if (output) {
|
|
66
|
+
return executeHelper.result = output;
|
|
67
|
+
} else {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
38
70
|
}
|
|
71
|
+
executeHelper.inputs = output;
|
|
72
|
+
yield next();
|
|
39
73
|
}
|
|
40
|
-
|
|
41
|
-
await next();
|
|
42
|
-
}
|
|
74
|
+
});
|
|
43
75
|
}
|
|
44
76
|
};
|
|
45
77
|
};
|
|
46
|
-
|
|
47
|
-
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
48
|
-
exports.Pipe = Pipe;
|
|
49
|
-
const Middleware = middleware => {
|
|
78
|
+
const Middleware = (middleware) => {
|
|
50
79
|
return {
|
|
51
|
-
name:
|
|
80
|
+
name: "middleware",
|
|
52
81
|
metadata(helper) {
|
|
53
|
-
const middlewares = helper.getMetadata(
|
|
82
|
+
const middlewares = helper.getMetadata("pipe") || [];
|
|
54
83
|
middlewares.push(middleware);
|
|
55
|
-
helper.setMetadata(
|
|
84
|
+
helper.setMetadata("middleware", middlewares);
|
|
56
85
|
}
|
|
57
86
|
};
|
|
58
87
|
};
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
88
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
89
|
+
0 && (module.exports = {
|
|
90
|
+
Middleware,
|
|
91
|
+
Pipe
|
|
92
|
+
});
|