@modern-js/plugin-koa 2.35.0 → 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 +57 -36
- package/dist/cjs/registerRoutes.js +23 -10
- package/dist/cjs/runtime.js +29 -18
- package/dist/cjs/utils.js +48 -29
- 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.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 +6 -3
- package/dist/esm-node/registerRoutes.js +4 -1
- package/dist/esm-node/runtime.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 koaPlugin;
|
|
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
|
+
koaPlugin: () => koaPlugin
|
|
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 koaPlugin = () => ({
|
|
24
38
|
name: "@modern-js/plugin-koa",
|
|
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 = "@modern-js/plugin-koa/runtime";
|
|
34
48
|
const alias = process.env.NODE_ENV === "production" ? runtimePath : require.resolve(runtimePath);
|
|
35
49
|
return {
|
|
@@ -56,8 +70,8 @@ const koaPlugin = () => ({
|
|
|
56
70
|
},
|
|
57
71
|
addRuntimeExports(input) {
|
|
58
72
|
const currentFile = bffExportsUtils.getPath();
|
|
59
|
-
const relativeRuntimeModulePath =
|
|
60
|
-
const relativeFramePath =
|
|
73
|
+
const relativeRuntimeModulePath = path.relative(path.dirname(currentFile), runtimeModulePath);
|
|
74
|
+
const relativeFramePath = path.relative(path.dirname(currentFile), require.resolve("koa"));
|
|
61
75
|
bffExportsUtils.addExport(`const pluginRuntime = require('${relativeRuntimeModulePath}');
|
|
62
76
|
const Koa = require('${relativeFramePath}')
|
|
63
77
|
module.exports = {
|
|
@@ -70,4 +84,8 @@ const koaPlugin = () => ({
|
|
|
70
84
|
};
|
|
71
85
|
}
|
|
72
86
|
});
|
|
73
|
-
|
|
87
|
+
var cli_default = koaPlugin;
|
|
88
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
89
|
+
0 && (module.exports = {
|
|
90
|
+
koaPlugin
|
|
91
|
+
});
|
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,43 +1,64 @@
|
|
|
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 _registerRoutes = /* @__PURE__ */ _interop_require_default._(require("./registerRoutes"));
|
|
33
|
+
module.exports = __toCommonJS(plugin_exports);
|
|
34
|
+
var path = __toESM(require("path"));
|
|
35
|
+
var import_koa = __toESM(require("koa"));
|
|
36
|
+
var import_koa_router = __toESM(require("koa-router"));
|
|
37
|
+
var import_koa_body = __toESM(require("koa-body"));
|
|
38
|
+
var import_utils = require("@modern-js/utils");
|
|
39
|
+
var import_context = require("./context");
|
|
40
|
+
var import_registerRoutes = __toESM(require("./registerRoutes"));
|
|
20
41
|
const findAppModule = async (apiDir) => {
|
|
21
42
|
const exts = [
|
|
22
43
|
".ts",
|
|
23
44
|
".js"
|
|
24
45
|
];
|
|
25
|
-
const paths = exts.map((ext) =>
|
|
46
|
+
const paths = exts.map((ext) => path.join(apiDir, `app${ext}`));
|
|
26
47
|
for (const filename of paths) {
|
|
27
|
-
if (await
|
|
48
|
+
if (await import_utils.fs.pathExists(filename)) {
|
|
28
49
|
delete require.cache[filename];
|
|
29
|
-
return (0,
|
|
50
|
+
return (0, import_utils.compatRequire)(filename);
|
|
30
51
|
}
|
|
31
52
|
}
|
|
32
53
|
return null;
|
|
33
54
|
};
|
|
34
55
|
const initMiddlewares = (middleware, app) => {
|
|
35
56
|
middleware.forEach((middlewareItem) => {
|
|
36
|
-
const middlewareFunc = typeof middlewareItem === "string" ? (0,
|
|
57
|
+
const middlewareFunc = typeof middlewareItem === "string" ? (0, import_utils.compatRequire)(middlewareItem) : middlewareItem;
|
|
37
58
|
app.use(middlewareFunc);
|
|
38
59
|
});
|
|
39
60
|
};
|
|
40
|
-
|
|
61
|
+
var plugin_default = () => ({
|
|
41
62
|
name: "@modern-js/plugin-koa",
|
|
42
63
|
pre: [
|
|
43
64
|
"@modern-js/plugin-bff"
|
|
@@ -49,17 +70,17 @@ const _default = () => ({
|
|
|
49
70
|
async prepareApiServer({ pwd, config, render }) {
|
|
50
71
|
var _userConfig_bff;
|
|
51
72
|
let app;
|
|
52
|
-
const router = new
|
|
53
|
-
const apiDir =
|
|
73
|
+
const router = new import_koa_router.default();
|
|
74
|
+
const apiDir = path.join(pwd, "./api");
|
|
54
75
|
const appContext = api.useAppContext();
|
|
55
76
|
const apiHandlerInfos = appContext.apiHandlerInfos;
|
|
56
77
|
const mode = appContext.apiMode;
|
|
57
78
|
const userConfig = api.useConfigContext();
|
|
58
79
|
if (mode === "framework") {
|
|
59
80
|
app = await findAppModule(apiDir);
|
|
60
|
-
if (!(app instanceof
|
|
61
|
-
app = new
|
|
62
|
-
app.use((0,
|
|
81
|
+
if (!(app instanceof import_koa.default)) {
|
|
82
|
+
app = new import_koa.default();
|
|
83
|
+
app.use((0, import_koa_body.default)({
|
|
63
84
|
multipart: true
|
|
64
85
|
}));
|
|
65
86
|
}
|
|
@@ -67,19 +88,19 @@ const _default = () => ({
|
|
|
67
88
|
const { middleware } = config;
|
|
68
89
|
initMiddlewares(middleware, app);
|
|
69
90
|
}
|
|
70
|
-
app.use(
|
|
71
|
-
(0,
|
|
91
|
+
app.use(import_context.run);
|
|
92
|
+
(0, import_registerRoutes.default)(router, apiHandlerInfos);
|
|
72
93
|
} else if (mode === "function") {
|
|
73
|
-
app = new
|
|
74
|
-
app.use((0,
|
|
94
|
+
app = new import_koa.default();
|
|
95
|
+
app.use((0, import_koa_body.default)({
|
|
75
96
|
multipart: true
|
|
76
97
|
}));
|
|
77
98
|
if (config) {
|
|
78
99
|
const { middleware } = config;
|
|
79
100
|
initMiddlewares(middleware, app);
|
|
80
101
|
}
|
|
81
|
-
app.use(
|
|
82
|
-
(0,
|
|
102
|
+
app.use(import_context.run);
|
|
103
|
+
(0, import_registerRoutes.default)(router, apiHandlerInfos);
|
|
83
104
|
} else {
|
|
84
105
|
throw new Error(`mode must be function or framework`);
|
|
85
106
|
}
|
|
@@ -98,12 +119,12 @@ const _default = () => ({
|
|
|
98
119
|
};
|
|
99
120
|
},
|
|
100
121
|
prepareWebServer({ config }, next) {
|
|
101
|
-
var _userConfig_server
|
|
122
|
+
var _userConfig_server;
|
|
102
123
|
const userConfig = api.useConfigContext();
|
|
103
|
-
if (!(
|
|
124
|
+
if (!(userConfig === null || userConfig === void 0 ? void 0 : (_userConfig_server = userConfig.server) === null || _userConfig_server === void 0 ? void 0 : _userConfig_server.enableFrameworkExt)) {
|
|
104
125
|
return next();
|
|
105
126
|
}
|
|
106
|
-
const app = new
|
|
127
|
+
const app = new import_koa.default();
|
|
107
128
|
app.use(async (ctx, next2) => {
|
|
108
129
|
await next2();
|
|
109
130
|
if (!ctx.body) {
|
|
@@ -113,7 +134,7 @@ const _default = () => ({
|
|
|
113
134
|
ctx.respond = false;
|
|
114
135
|
}
|
|
115
136
|
});
|
|
116
|
-
app.use((0,
|
|
137
|
+
app.use((0, import_koa_body.default)());
|
|
117
138
|
if (config) {
|
|
118
139
|
const { middleware } = config;
|
|
119
140
|
initMiddlewares(middleware, app);
|
|
@@ -1,19 +1,32 @@
|
|
|
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
|
-
|
|
23
|
+
module.exports = __toCommonJS(registerRoutes_exports);
|
|
24
|
+
var import_utils = require("./utils");
|
|
12
25
|
const registerRoutes = (router, handlerInfos) => {
|
|
13
26
|
handlerInfos.forEach(({ routePath, handler, httpMethod }) => {
|
|
14
|
-
const routeHandler = (0,
|
|
27
|
+
const routeHandler = (0, import_utils.createRouteHandler)(handler);
|
|
15
28
|
const method = httpMethod.toLowerCase();
|
|
16
29
|
router[method](routePath, routeHandler);
|
|
17
30
|
});
|
|
18
31
|
};
|
|
19
|
-
|
|
32
|
+
var registerRoutes_default = registerRoutes;
|
package/dist/cjs/runtime.js
CHANGED
|
@@ -1,23 +1,34 @@
|
|
|
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 hook;
|
|
15
|
-
},
|
|
16
|
-
useContext: function() {
|
|
17
|
-
return _context.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 __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: () => hook,
|
|
23
|
+
useContext: () => import_context.useContext
|
|
19
24
|
});
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
25
|
+
module.exports = __toCommonJS(runtime_exports);
|
|
26
|
+
var import_context = require("./context");
|
|
27
|
+
__reExport(runtime_exports, require("@modern-js/bff-core"), module.exports);
|
|
23
28
|
const hook = (attacher) => attacher;
|
|
29
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
30
|
+
0 && (module.exports = {
|
|
31
|
+
hook,
|
|
32
|
+
useContext,
|
|
33
|
+
...require("@modern-js/bff-core")
|
|
34
|
+
});
|
package/dist/cjs/utils.js
CHANGED
|
@@ -1,46 +1,60 @@
|
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
34
|
+
module.exports = __toCommonJS(utils_exports);
|
|
35
|
+
var import_bff_core = require("@modern-js/bff-core");
|
|
36
|
+
var import_bff_runtime = require("@modern-js/bff-runtime");
|
|
37
|
+
var import_type_is = __toESM(require("type-is"));
|
|
24
38
|
const handleResponseMeta = (ctx, handler) => {
|
|
25
|
-
const responseMeta = Reflect.getMetadata(
|
|
39
|
+
const responseMeta = Reflect.getMetadata(import_bff_core.HttpMetadata.Response, handler);
|
|
26
40
|
if (Array.isArray(responseMeta)) {
|
|
27
41
|
for (const meta of responseMeta) {
|
|
28
42
|
const metaType = meta.type;
|
|
29
43
|
const metaValue = meta.value;
|
|
30
44
|
switch (metaType) {
|
|
31
|
-
case
|
|
45
|
+
case import_bff_core.ResponseMetaType.Headers:
|
|
32
46
|
for (const [key, value] of Object.entries(metaValue)) {
|
|
33
47
|
if (typeof value === "string") {
|
|
34
48
|
ctx.append(key, value);
|
|
35
49
|
}
|
|
36
50
|
}
|
|
37
51
|
break;
|
|
38
|
-
case
|
|
52
|
+
case import_bff_core.ResponseMetaType.Redirect:
|
|
39
53
|
if (typeof metaValue === "string") {
|
|
40
54
|
ctx.redirect(metaValue);
|
|
41
55
|
}
|
|
42
56
|
break;
|
|
43
|
-
case
|
|
57
|
+
case import_bff_core.ResponseMetaType.StatusCode:
|
|
44
58
|
if (typeof metaValue === "number") {
|
|
45
59
|
ctx.status = metaValue;
|
|
46
60
|
}
|
|
@@ -54,7 +68,7 @@ const handleResponseMeta = (ctx, handler) => {
|
|
|
54
68
|
const createRouteHandler = (handler) => {
|
|
55
69
|
const apiHandler = async (ctx) => {
|
|
56
70
|
const input = await getInputFromRequest(ctx);
|
|
57
|
-
if ((0,
|
|
71
|
+
if ((0, import_bff_core.isWithMetaHandler)(handler)) {
|
|
58
72
|
try {
|
|
59
73
|
handleResponseMeta(ctx, handler);
|
|
60
74
|
const body = await handler(input);
|
|
@@ -74,7 +88,7 @@ const createRouteHandler = (handler) => {
|
|
|
74
88
|
};
|
|
75
89
|
}
|
|
76
90
|
}
|
|
77
|
-
} else if ((0,
|
|
91
|
+
} else if ((0, import_bff_runtime.isSchemaHandler)(handler)) {
|
|
78
92
|
const result = await handler(input);
|
|
79
93
|
if (result.type !== "HandleSuccess") {
|
|
80
94
|
if (result.type === "InputValidationError") {
|
|
@@ -97,7 +111,7 @@ const createRouteHandler = (handler) => {
|
|
|
97
111
|
Object.defineProperties(apiHandler, Object.getOwnPropertyDescriptors(handler));
|
|
98
112
|
return apiHandler;
|
|
99
113
|
};
|
|
100
|
-
const isNormalMethod = (httpMethod) =>
|
|
114
|
+
const isNormalMethod = (httpMethod) => import_bff_core.httpMethods.includes(httpMethod);
|
|
101
115
|
const getInputFromRequest = async (ctx) => {
|
|
102
116
|
const draft = {
|
|
103
117
|
params: ctx.params,
|
|
@@ -105,15 +119,15 @@ const getInputFromRequest = async (ctx) => {
|
|
|
105
119
|
headers: ctx.headers,
|
|
106
120
|
cookies: ctx.headers.cookie
|
|
107
121
|
};
|
|
108
|
-
if (
|
|
122
|
+
if (import_type_is.default.is(ctx.request.type, [
|
|
109
123
|
"application/json"
|
|
110
124
|
])) {
|
|
111
125
|
draft.data = ctx.request.body;
|
|
112
|
-
} else if (
|
|
126
|
+
} else if (import_type_is.default.is(ctx.request.type, [
|
|
113
127
|
"multipart/form-data"
|
|
114
128
|
])) {
|
|
115
129
|
draft.formData = ctx.request.files;
|
|
116
|
-
} else if (
|
|
130
|
+
} else if (import_type_is.default.is(ctx.request.type, [
|
|
117
131
|
"application/x-www-form-urlencoded"
|
|
118
132
|
])) {
|
|
119
133
|
draft.formUrlencoded = ctx.request.body;
|
|
@@ -122,3 +136,8 @@ const getInputFromRequest = async (ctx) => {
|
|
|
122
136
|
}
|
|
123
137
|
return draft;
|
|
124
138
|
};
|
|
139
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
140
|
+
0 && (module.exports = {
|
|
141
|
+
createRouteHandler,
|
|
142
|
+
isNormalMethod
|
|
143
|
+
});
|
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 koaPlugin = function() {
|
|
4
4
|
return {
|
|
5
5
|
name: "@modern-js/plugin-koa",
|
|
6
6
|
setup: function(api) {
|
|
@@ -33,7 +33,7 @@ export var koaPlugin = function() {
|
|
|
33
33
|
"@modern-js/plugin-koa": "@modern-js/plugin-koa/server"
|
|
34
34
|
});
|
|
35
35
|
return {
|
|
36
|
-
plugins
|
|
36
|
+
plugins
|
|
37
37
|
};
|
|
38
38
|
},
|
|
39
39
|
addRuntimeExports: function addRuntimeExports(input) {
|
|
@@ -47,4 +47,8 @@ export var koaPlugin = function() {
|
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
49
|
};
|
|
50
|
-
|
|
50
|
+
var cli_default = koaPlugin;
|
|
51
|
+
export {
|
|
52
|
+
cli_default as default,
|
|
53
|
+
koaPlugin
|
|
54
|
+
};
|
package/dist/esm/context.js
CHANGED
package/dist/esm/index.js
CHANGED
package/dist/esm/plugin.js
CHANGED
|
@@ -102,7 +102,7 @@ var initMiddlewares = function(middleware, app) {
|
|
|
102
102
|
app.use(middlewareFunc);
|
|
103
103
|
});
|
|
104
104
|
};
|
|
105
|
-
|
|
105
|
+
function plugin_default() {
|
|
106
106
|
return {
|
|
107
107
|
name: "@modern-js/plugin-koa",
|
|
108
108
|
pre: [
|
|
@@ -216,9 +216,9 @@ export default function() {
|
|
|
216
216
|
},
|
|
217
217
|
prepareWebServer: function prepareWebServer(param, next) {
|
|
218
218
|
var config = param.config;
|
|
219
|
-
var _userConfig_server
|
|
219
|
+
var _userConfig_server;
|
|
220
220
|
var userConfig = api.useConfigContext();
|
|
221
|
-
if (!(
|
|
221
|
+
if (!(userConfig === null || userConfig === void 0 ? void 0 : (_userConfig_server = userConfig.server) === null || _userConfig_server === void 0 ? void 0 : _userConfig_server.enableFrameworkExt)) {
|
|
222
222
|
return next();
|
|
223
223
|
}
|
|
224
224
|
var app = new Koa();
|
|
@@ -269,3 +269,6 @@ export default function() {
|
|
|
269
269
|
};
|
|
270
270
|
}
|
|
271
271
|
;
|
|
272
|
+
export {
|
|
273
|
+
plugin_default as default
|
|
274
|
+
};
|
package/dist/esm/runtime.js
CHANGED
package/dist/esm/utils.js
CHANGED
|
@@ -70,7 +70,7 @@ var handleResponseMeta = function(ctx, handler) {
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
};
|
|
73
|
-
|
|
73
|
+
var createRouteHandler = function(handler) {
|
|
74
74
|
var apiHandler = function() {
|
|
75
75
|
var _ref = _async_to_generator(function(ctx) {
|
|
76
76
|
var input, body, error, result, args, body1;
|
|
@@ -187,7 +187,7 @@ export var createRouteHandler = function(handler) {
|
|
|
187
187
|
Object.defineProperties(apiHandler, Object.getOwnPropertyDescriptors(handler));
|
|
188
188
|
return apiHandler;
|
|
189
189
|
};
|
|
190
|
-
|
|
190
|
+
var isNormalMethod = function(httpMethod) {
|
|
191
191
|
return httpMethods.includes(httpMethod);
|
|
192
192
|
};
|
|
193
193
|
var getInputFromRequest = function() {
|
|
@@ -225,3 +225,7 @@ var getInputFromRequest = function() {
|
|
|
225
225
|
return _ref.apply(this, arguments);
|
|
226
226
|
};
|
|
227
227
|
}();
|
|
228
|
+
export {
|
|
229
|
+
createRouteHandler,
|
|
230
|
+
isNormalMethod
|
|
231
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as path from "path";
|
|
2
2
|
import { createRuntimeExportsUtils } from "@modern-js/utils";
|
|
3
|
-
|
|
3
|
+
const koaPlugin = () => ({
|
|
4
4
|
name: "@modern-js/plugin-koa",
|
|
5
5
|
setup: (api) => {
|
|
6
6
|
let bffExportsUtils;
|
|
@@ -50,4 +50,8 @@ export const koaPlugin = () => ({
|
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
52
|
});
|
|
53
|
-
|
|
53
|
+
var cli_default = koaPlugin;
|
|
54
|
+
export {
|
|
55
|
+
cli_default as default,
|
|
56
|
+
koaPlugin
|
|
57
|
+
};
|
package/dist/esm-node/context.js
CHANGED
package/dist/esm-node/index.js
CHANGED
package/dist/esm-node/plugin.js
CHANGED
|
@@ -25,7 +25,7 @@ const initMiddlewares = (middleware, app) => {
|
|
|
25
25
|
app.use(middlewareFunc);
|
|
26
26
|
});
|
|
27
27
|
};
|
|
28
|
-
|
|
28
|
+
var plugin_default = () => ({
|
|
29
29
|
name: "@modern-js/plugin-koa",
|
|
30
30
|
pre: [
|
|
31
31
|
"@modern-js/plugin-bff"
|
|
@@ -86,9 +86,9 @@ export default () => ({
|
|
|
86
86
|
};
|
|
87
87
|
},
|
|
88
88
|
prepareWebServer({ config }, next) {
|
|
89
|
-
var _userConfig_server
|
|
89
|
+
var _userConfig_server;
|
|
90
90
|
const userConfig = api.useConfigContext();
|
|
91
|
-
if (!(
|
|
91
|
+
if (!(userConfig === null || userConfig === void 0 ? void 0 : (_userConfig_server = userConfig.server) === null || _userConfig_server === void 0 ? void 0 : _userConfig_server.enableFrameworkExt)) {
|
|
92
92
|
return next();
|
|
93
93
|
}
|
|
94
94
|
const app = new Koa();
|
|
@@ -118,3 +118,6 @@ export default () => ({
|
|
|
118
118
|
}
|
|
119
119
|
})
|
|
120
120
|
});
|
|
121
|
+
export {
|
|
122
|
+
plugin_default as default
|
|
123
|
+
};
|
package/dist/esm-node/runtime.js
CHANGED
package/dist/esm-node/utils.js
CHANGED
|
@@ -31,7 +31,7 @@ const handleResponseMeta = (ctx, handler) => {
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
};
|
|
34
|
-
|
|
34
|
+
const createRouteHandler = (handler) => {
|
|
35
35
|
const apiHandler = async (ctx) => {
|
|
36
36
|
const input = await getInputFromRequest(ctx);
|
|
37
37
|
if (isWithMetaHandler(handler)) {
|
|
@@ -77,7 +77,7 @@ export const createRouteHandler = (handler) => {
|
|
|
77
77
|
Object.defineProperties(apiHandler, Object.getOwnPropertyDescriptors(handler));
|
|
78
78
|
return apiHandler;
|
|
79
79
|
};
|
|
80
|
-
|
|
80
|
+
const isNormalMethod = (httpMethod) => httpMethods.includes(httpMethod);
|
|
81
81
|
const getInputFromRequest = async (ctx) => {
|
|
82
82
|
const draft = {
|
|
83
83
|
params: ctx.params,
|
|
@@ -102,3 +102,7 @@ const getInputFromRequest = async (ctx) => {
|
|
|
102
102
|
}
|
|
103
103
|
return draft;
|
|
104
104
|
};
|
|
105
|
+
export {
|
|
106
|
+
createRouteHandler,
|
|
107
|
+
isNormalMethod
|
|
108
|
+
};
|
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",
|
|
@@ -67,10 +67,10 @@
|
|
|
67
67
|
"koa-router": "^10.0.0",
|
|
68
68
|
"type-is": "^1.6.18",
|
|
69
69
|
"@swc/helpers": "0.5.1",
|
|
70
|
-
"@modern-js/
|
|
71
|
-
"@modern-js/bff-
|
|
72
|
-
"@modern-js/
|
|
73
|
-
"@modern-js/
|
|
70
|
+
"@modern-js/bff-core": "2.36.0",
|
|
71
|
+
"@modern-js/bff-runtime": "2.36.0",
|
|
72
|
+
"@modern-js/utils": "2.36.0",
|
|
73
|
+
"@modern-js/types": "2.36.0"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
76
|
"@types/jest": "^29",
|
|
@@ -83,12 +83,12 @@
|
|
|
83
83
|
"koa": "^2.13.3",
|
|
84
84
|
"supertest": "^6.1.6",
|
|
85
85
|
"typescript": "^5",
|
|
86
|
-
"zod": "^3.
|
|
87
|
-
"@modern-js/core": "2.
|
|
88
|
-
"@modern-js/server-core": "2.
|
|
89
|
-
"@modern-js/app-tools": "2.
|
|
90
|
-
"@scripts/build": "2.
|
|
91
|
-
"@scripts/jest-config": "2.
|
|
86
|
+
"zod": "^3.22.3",
|
|
87
|
+
"@modern-js/core": "2.36.0",
|
|
88
|
+
"@modern-js/server-core": "2.36.0",
|
|
89
|
+
"@modern-js/app-tools": "2.36.0",
|
|
90
|
+
"@scripts/build": "2.36.0",
|
|
91
|
+
"@scripts/jest-config": "2.36.0"
|
|
92
92
|
},
|
|
93
93
|
"peerDependencies": {
|
|
94
94
|
"koa": "^2.13.3"
|