@modern-js/plugin-express 2.27.0 → 2.29.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/CHANGELOG.md CHANGED
@@ -1,5 +1,30 @@
1
1
  # @modern-js/plugin-express
2
2
 
3
+ ## 2.29.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [e6b5355]
8
+ - Updated dependencies [93db783]
9
+ - Updated dependencies [cba7675]
10
+ - Updated dependencies [99052ea]
11
+ - Updated dependencies [1d71d2e]
12
+ - @modern-js/utils@2.29.0
13
+ - @modern-js/types@2.29.0
14
+ - @modern-js/bff-core@2.29.0
15
+ - @modern-js/bff-runtime@2.29.0
16
+
17
+ ## 2.28.0
18
+
19
+ ### Patch Changes
20
+
21
+ - Updated dependencies [4e3ce96]
22
+ - Updated dependencies [00b58a7]
23
+ - @modern-js/types@2.28.0
24
+ - @modern-js/utils@2.28.0
25
+ - @modern-js/bff-core@2.28.0
26
+ - @modern-js/bff-runtime@2.28.0
27
+
3
28
  ## 2.27.0
4
29
 
5
30
  ### Patch Changes
@@ -58,117 +58,114 @@ const initApp = (app) => {
58
58
  app.use(_express.default.json());
59
59
  return app;
60
60
  };
61
- const _default = () => {
62
- return {
63
- name: "@modern-js/plugin-express",
64
- pre: [
65
- "@modern-js/plugin-bff"
66
- ],
67
- post: [
68
- "@modern-js/plugin-server"
69
- ],
70
- setup: (api) => {
71
- return {
72
- async prepareApiServer({ pwd, config, render }) {
73
- var _userConfig_bff;
74
- let app;
75
- const appContext = api.useAppContext();
76
- const apiHandlerInfos = appContext.apiHandlerInfos;
77
- const apiDirectory = appContext.apiDirectory;
78
- const apiDir = apiDirectory || _path.join(pwd, "./api");
79
- const mode = appContext.apiMode;
80
- const userConfig = api.useConfigContext();
81
- if (mode === "framework") {
82
- const appModule = await findAppModule(apiDir);
83
- app = appModule[0];
84
- const hooks = appModule[1];
85
- if (!(app === null || app === void 0 ? void 0 : app.use)) {
86
- app = (0, _express.default)();
87
- }
88
- initApp(app);
89
- if (config) {
90
- const { middleware } = config;
91
- initMiddlewares(middleware, app);
92
- }
93
- useRun(app);
94
- (0, _registerRoutes.default)(app, apiHandlerInfos);
95
- if (hooks) {
96
- const { afterLambdaRegisted } = hooks;
97
- if (afterLambdaRegisted) {
98
- afterLambdaRegisted(app);
99
- }
100
- }
101
- } else if (mode === "function") {
102
- app = (0, _express.default)();
103
- initApp(app);
104
- if (config) {
105
- const { middleware } = config;
106
- initMiddlewares(middleware, app);
107
- }
108
- useRun(app);
109
- (0, _registerRoutes.default)(app, apiHandlerInfos);
110
- } else {
111
- throw new Error(`mode must be function or framework`);
61
+ const _default = () => ({
62
+ name: "@modern-js/plugin-express",
63
+ pre: [
64
+ "@modern-js/plugin-bff"
65
+ ],
66
+ post: [
67
+ "@modern-js/plugin-server"
68
+ ],
69
+ setup: (api) => ({
70
+ async prepareApiServer({ pwd, config, render }) {
71
+ var _userConfig_bff;
72
+ let app;
73
+ const appContext = api.useAppContext();
74
+ const apiHandlerInfos = appContext.apiHandlerInfos;
75
+ const apiDirectory = appContext.apiDirectory;
76
+ const apiDir = apiDirectory || _path.join(pwd, "./api");
77
+ const mode = appContext.apiMode;
78
+ const userConfig = api.useConfigContext();
79
+ if (mode === "framework") {
80
+ var _app;
81
+ const appModule = await findAppModule(apiDir);
82
+ app = appModule[0];
83
+ const hooks = appModule[1];
84
+ if (!((_app = app) === null || _app === void 0 ? void 0 : _app.use)) {
85
+ app = (0, _express.default)();
86
+ }
87
+ initApp(app);
88
+ if (config) {
89
+ const { middleware } = config;
90
+ initMiddlewares(middleware, app);
91
+ }
92
+ useRun(app);
93
+ (0, _registerRoutes.default)(app, apiHandlerInfos);
94
+ if (hooks) {
95
+ const { afterLambdaRegisted } = hooks;
96
+ if (afterLambdaRegisted) {
97
+ afterLambdaRegisted(app);
112
98
  }
113
- if (((_userConfig_bff = userConfig.bff) === null || _userConfig_bff === void 0 ? void 0 : _userConfig_bff.enableHandleWeb) && render) {
114
- app.use(async (req, res, next) => {
115
- const html = await render(req, res);
116
- if (html) {
117
- res.end(html);
118
- }
119
- next();
120
- });
99
+ }
100
+ } else if (mode === "function") {
101
+ app = (0, _express.default)();
102
+ initApp(app);
103
+ if (config) {
104
+ const { middleware } = config;
105
+ initMiddlewares(middleware, app);
106
+ }
107
+ useRun(app);
108
+ (0, _registerRoutes.default)(app, apiHandlerInfos);
109
+ } else {
110
+ throw new Error(`mode must be function or framework`);
111
+ }
112
+ if (((_userConfig_bff = userConfig.bff) === null || _userConfig_bff === void 0 ? void 0 : _userConfig_bff.enableHandleWeb) && render) {
113
+ app.use(async (req, res, next) => {
114
+ const html = await render(req, res);
115
+ if (html) {
116
+ res.end(html);
121
117
  }
122
- return (req, res) => new Promise((resolve, reject) => {
123
- const handler = (err) => {
124
- if (err) {
125
- return reject(err);
126
- }
127
- return (0, _finalhandler.default)(req, res, {})(null);
128
- };
129
- res.on("finish", (err) => {
130
- if (err) {
131
- return reject(err);
132
- }
133
- return resolve();
134
- });
135
- return app(req, res, handler);
136
- });
137
- },
138
- prepareWebServer({ config }, next) {
139
- var _userConfig_server;
140
- const userConfig = api.useConfigContext();
141
- if (!(userConfig === null || userConfig === void 0 ? void 0 : (_userConfig_server = userConfig.server) === null || _userConfig_server === void 0 ? void 0 : _userConfig_server.enableFrameworkExt)) {
142
- return next();
118
+ next();
119
+ });
120
+ }
121
+ return (req, res) => new Promise((resolve, reject) => {
122
+ const handler = (err) => {
123
+ if (err) {
124
+ return reject(err);
143
125
  }
144
- const app = (0, _express.default)();
145
- initApp(app);
146
- if (config) {
147
- const { middleware } = config;
148
- debug("web middleware", middleware);
149
- initMiddlewares(middleware, app);
126
+ return (0, _finalhandler.default)(req, res, {})(null);
127
+ };
128
+ res.on("finish", (err) => {
129
+ if (err) {
130
+ return reject(err);
150
131
  }
151
- return (ctx) => new Promise((resolve, reject) => {
152
- const { source: { req, res } } = ctx;
153
- const handler = (err) => {
154
- if (err) {
155
- return reject(err);
156
- }
157
- if (res.headersSent && res.statusCode !== 200) {
158
- (0, _finalhandler.default)(req, res, {})(null);
159
- }
160
- return resolve();
161
- };
162
- res.on("finish", (err) => {
163
- if (err) {
164
- return reject(err);
165
- }
166
- return resolve();
167
- });
168
- return app(req, res, handler);
169
- });
170
- }
171
- };
132
+ return resolve();
133
+ });
134
+ return app(req, res, handler);
135
+ });
136
+ },
137
+ prepareWebServer({ config }, next) {
138
+ var _userConfig_server, _userConfig;
139
+ const userConfig = api.useConfigContext();
140
+ if (!((_userConfig = userConfig) === null || _userConfig === void 0 ? void 0 : (_userConfig_server = _userConfig.server) === null || _userConfig_server === void 0 ? void 0 : _userConfig_server.enableFrameworkExt)) {
141
+ return next();
142
+ }
143
+ const app = (0, _express.default)();
144
+ initApp(app);
145
+ if (config) {
146
+ const { middleware } = config;
147
+ debug("web middleware", middleware);
148
+ initMiddlewares(middleware, app);
149
+ }
150
+ return (ctx) => new Promise((resolve, reject) => {
151
+ const { source: { req, res } } = ctx;
152
+ const handler = (err) => {
153
+ if (err) {
154
+ return reject(err);
155
+ }
156
+ if (res.headersSent && res.statusCode !== 200) {
157
+ (0, _finalhandler.default)(req, res, {})(null);
158
+ }
159
+ return resolve();
160
+ };
161
+ res.on("finish", (err) => {
162
+ if (err) {
163
+ return reject(err);
164
+ }
165
+ return resolve();
166
+ });
167
+ return app(req, res, handler);
168
+ });
172
169
  }
173
- };
174
- };
170
+ })
171
+ });
package/dist/cjs/utils.js CHANGED
@@ -84,8 +84,8 @@ const createRouteHandler = (handler) => {
84
84
  }
85
85
  } else if ((0, _bffcore.isInputParamsDeciderHandler)(handler)) {
86
86
  try {
87
- var _input_data;
88
- const args = (input === null || input === void 0 ? void 0 : (_input_data = input.data) === null || _input_data === void 0 ? void 0 : _input_data.args) || [];
87
+ var _input_data, _input;
88
+ const args = ((_input = input) === null || _input === void 0 ? void 0 : (_input_data = _input.data) === null || _input_data === void 0 ? void 0 : _input_data.args) || [];
89
89
  const body = await handler(...args);
90
90
  if (typeof body !== "undefined") {
91
91
  if (typeof body === "object") {
@@ -136,7 +136,7 @@ export default function() {
136
136
  prepareApiServer: function prepareApiServer(param) {
137
137
  var pwd = param.pwd, config = param.config, render = param.render;
138
138
  return _async_to_generator(function() {
139
- var _userConfig_bff, app, appContext, apiHandlerInfos, apiDirectory, apiDir, mode, userConfig, appModule, hooks, middleware, afterLambdaRegisted, middleware1;
139
+ var _userConfig_bff, app, appContext, apiHandlerInfos, apiDirectory, apiDir, mode, userConfig, _app, appModule, hooks, middleware, afterLambdaRegisted, middleware1;
140
140
  return _ts_generator(this, function(_state) {
141
141
  switch (_state.label) {
142
142
  case 0:
@@ -159,7 +159,7 @@ export default function() {
159
159
  appModule = _state.sent();
160
160
  app = appModule[0];
161
161
  hooks = appModule[1];
162
- if (!(app === null || app === void 0 ? void 0 : app.use)) {
162
+ if (!((_app = app) === null || _app === void 0 ? void 0 : _app.use)) {
163
163
  app = express();
164
164
  }
165
165
  initApp(app);
@@ -248,9 +248,9 @@ export default function() {
248
248
  },
249
249
  prepareWebServer: function prepareWebServer(param, next) {
250
250
  var config = param.config;
251
- var _userConfig_server;
251
+ var _userConfig_server, _userConfig;
252
252
  var userConfig = api.useConfigContext();
253
- if (!(userConfig === null || userConfig === void 0 ? void 0 : (_userConfig_server = userConfig.server) === null || _userConfig_server === void 0 ? void 0 : _userConfig_server.enableFrameworkExt)) {
253
+ if (!((_userConfig = userConfig) === null || _userConfig === void 0 ? void 0 : (_userConfig_server = _userConfig.server) === null || _userConfig_server === void 0 ? void 0 : _userConfig_server.enableFrameworkExt)) {
254
254
  return next();
255
255
  }
256
256
  var app = express();
package/dist/esm/utils.js CHANGED
@@ -70,7 +70,7 @@ var handleResponseMeta = function(res, handler) {
70
70
  export var createRouteHandler = function(handler) {
71
71
  var apiHandler = function() {
72
72
  var _ref = _async_to_generator(function(req, res, next) {
73
- var input, result, error, result1, _input_data, args, body, e, args1, body1, e1;
73
+ var input, result, error, result1, _input_data, _input, args, body, e, args1, body1, e1;
74
74
  return _ts_generator(this, function(_state) {
75
75
  switch (_state.label) {
76
76
  case 0:
@@ -179,7 +179,7 @@ export var createRouteHandler = function(handler) {
179
179
  ,
180
180
  12
181
181
  ]);
182
- args = (input === null || input === void 0 ? void 0 : (_input_data = input.data) === null || _input_data === void 0 ? void 0 : _input_data.args) || [];
182
+ args = ((_input = input) === null || _input === void 0 ? void 0 : (_input_data = _input.data) === null || _input_data === void 0 ? void 0 : _input_data.args) || [];
183
183
  return [
184
184
  4,
185
185
  handler.apply(void 0, _to_consumable_array(args))
@@ -46,117 +46,114 @@ const initApp = (app) => {
46
46
  app.use(express.json());
47
47
  return app;
48
48
  };
49
- export default () => {
50
- return {
51
- name: "@modern-js/plugin-express",
52
- pre: [
53
- "@modern-js/plugin-bff"
54
- ],
55
- post: [
56
- "@modern-js/plugin-server"
57
- ],
58
- setup: (api) => {
59
- return {
60
- async prepareApiServer({ pwd, config, render }) {
61
- var _userConfig_bff;
62
- let app;
63
- const appContext = api.useAppContext();
64
- const apiHandlerInfos = appContext.apiHandlerInfos;
65
- const apiDirectory = appContext.apiDirectory;
66
- const apiDir = apiDirectory || path.join(pwd, "./api");
67
- const mode = appContext.apiMode;
68
- const userConfig = api.useConfigContext();
69
- if (mode === "framework") {
70
- const appModule = await findAppModule(apiDir);
71
- app = appModule[0];
72
- const hooks = appModule[1];
73
- if (!(app === null || app === void 0 ? void 0 : app.use)) {
74
- app = express();
75
- }
76
- initApp(app);
77
- if (config) {
78
- const { middleware } = config;
79
- initMiddlewares(middleware, app);
80
- }
81
- useRun(app);
82
- registerRoutes(app, apiHandlerInfos);
83
- if (hooks) {
84
- const { afterLambdaRegisted } = hooks;
85
- if (afterLambdaRegisted) {
86
- afterLambdaRegisted(app);
87
- }
88
- }
89
- } else if (mode === "function") {
90
- app = express();
91
- initApp(app);
92
- if (config) {
93
- const { middleware } = config;
94
- initMiddlewares(middleware, app);
95
- }
96
- useRun(app);
97
- registerRoutes(app, apiHandlerInfos);
98
- } else {
99
- throw new Error(`mode must be function or framework`);
49
+ export default () => ({
50
+ name: "@modern-js/plugin-express",
51
+ pre: [
52
+ "@modern-js/plugin-bff"
53
+ ],
54
+ post: [
55
+ "@modern-js/plugin-server"
56
+ ],
57
+ setup: (api) => ({
58
+ async prepareApiServer({ pwd, config, render }) {
59
+ var _userConfig_bff;
60
+ let app;
61
+ const appContext = api.useAppContext();
62
+ const apiHandlerInfos = appContext.apiHandlerInfos;
63
+ const apiDirectory = appContext.apiDirectory;
64
+ const apiDir = apiDirectory || path.join(pwd, "./api");
65
+ const mode = appContext.apiMode;
66
+ const userConfig = api.useConfigContext();
67
+ if (mode === "framework") {
68
+ var _app;
69
+ const appModule = await findAppModule(apiDir);
70
+ app = appModule[0];
71
+ const hooks = appModule[1];
72
+ if (!((_app = app) === null || _app === void 0 ? void 0 : _app.use)) {
73
+ app = express();
74
+ }
75
+ initApp(app);
76
+ if (config) {
77
+ const { middleware } = config;
78
+ initMiddlewares(middleware, app);
79
+ }
80
+ useRun(app);
81
+ registerRoutes(app, apiHandlerInfos);
82
+ if (hooks) {
83
+ const { afterLambdaRegisted } = hooks;
84
+ if (afterLambdaRegisted) {
85
+ afterLambdaRegisted(app);
100
86
  }
101
- if (((_userConfig_bff = userConfig.bff) === null || _userConfig_bff === void 0 ? void 0 : _userConfig_bff.enableHandleWeb) && render) {
102
- app.use(async (req, res, next) => {
103
- const html = await render(req, res);
104
- if (html) {
105
- res.end(html);
106
- }
107
- next();
108
- });
87
+ }
88
+ } else if (mode === "function") {
89
+ app = express();
90
+ initApp(app);
91
+ if (config) {
92
+ const { middleware } = config;
93
+ initMiddlewares(middleware, app);
94
+ }
95
+ useRun(app);
96
+ registerRoutes(app, apiHandlerInfos);
97
+ } else {
98
+ throw new Error(`mode must be function or framework`);
99
+ }
100
+ if (((_userConfig_bff = userConfig.bff) === null || _userConfig_bff === void 0 ? void 0 : _userConfig_bff.enableHandleWeb) && render) {
101
+ app.use(async (req, res, next) => {
102
+ const html = await render(req, res);
103
+ if (html) {
104
+ res.end(html);
109
105
  }
110
- return (req, res) => new Promise((resolve, reject) => {
111
- const handler = (err) => {
112
- if (err) {
113
- return reject(err);
114
- }
115
- return finalhandler(req, res, {})(null);
116
- };
117
- res.on("finish", (err) => {
118
- if (err) {
119
- return reject(err);
120
- }
121
- return resolve();
122
- });
123
- return app(req, res, handler);
124
- });
125
- },
126
- prepareWebServer({ config }, next) {
127
- var _userConfig_server;
128
- const userConfig = api.useConfigContext();
129
- if (!(userConfig === null || userConfig === void 0 ? void 0 : (_userConfig_server = userConfig.server) === null || _userConfig_server === void 0 ? void 0 : _userConfig_server.enableFrameworkExt)) {
130
- return next();
106
+ next();
107
+ });
108
+ }
109
+ return (req, res) => new Promise((resolve, reject) => {
110
+ const handler = (err) => {
111
+ if (err) {
112
+ return reject(err);
131
113
  }
132
- const app = express();
133
- initApp(app);
134
- if (config) {
135
- const { middleware } = config;
136
- debug("web middleware", middleware);
137
- initMiddlewares(middleware, app);
114
+ return finalhandler(req, res, {})(null);
115
+ };
116
+ res.on("finish", (err) => {
117
+ if (err) {
118
+ return reject(err);
138
119
  }
139
- return (ctx) => new Promise((resolve, reject) => {
140
- const { source: { req, res } } = ctx;
141
- const handler = (err) => {
142
- if (err) {
143
- return reject(err);
144
- }
145
- if (res.headersSent && res.statusCode !== 200) {
146
- finalhandler(req, res, {})(null);
147
- }
148
- return resolve();
149
- };
150
- res.on("finish", (err) => {
151
- if (err) {
152
- return reject(err);
153
- }
154
- return resolve();
155
- });
156
- return app(req, res, handler);
157
- });
158
- }
159
- };
120
+ return resolve();
121
+ });
122
+ return app(req, res, handler);
123
+ });
124
+ },
125
+ prepareWebServer({ config }, next) {
126
+ var _userConfig_server, _userConfig;
127
+ const userConfig = api.useConfigContext();
128
+ if (!((_userConfig = userConfig) === null || _userConfig === void 0 ? void 0 : (_userConfig_server = _userConfig.server) === null || _userConfig_server === void 0 ? void 0 : _userConfig_server.enableFrameworkExt)) {
129
+ return next();
130
+ }
131
+ const app = express();
132
+ initApp(app);
133
+ if (config) {
134
+ const { middleware } = config;
135
+ debug("web middleware", middleware);
136
+ initMiddlewares(middleware, app);
137
+ }
138
+ return (ctx) => new Promise((resolve, reject) => {
139
+ const { source: { req, res } } = ctx;
140
+ const handler = (err) => {
141
+ if (err) {
142
+ return reject(err);
143
+ }
144
+ if (res.headersSent && res.statusCode !== 200) {
145
+ finalhandler(req, res, {})(null);
146
+ }
147
+ return resolve();
148
+ };
149
+ res.on("finish", (err) => {
150
+ if (err) {
151
+ return reject(err);
152
+ }
153
+ return resolve();
154
+ });
155
+ return app(req, res, handler);
156
+ });
160
157
  }
161
- };
162
- };
158
+ })
159
+ });
@@ -64,8 +64,8 @@ export const createRouteHandler = (handler) => {
64
64
  }
65
65
  } else if (isInputParamsDeciderHandler(handler)) {
66
66
  try {
67
- var _input_data;
68
- const args = (input === null || input === void 0 ? void 0 : (_input_data = input.data) === null || _input_data === void 0 ? void 0 : _input_data.args) || [];
67
+ var _input_data, _input;
68
+ const args = ((_input = input) === null || _input === void 0 ? void 0 : (_input_data = _input.data) === null || _input_data === void 0 ? void 0 : _input_data.args) || [];
69
69
  const body = await handler(...args);
70
70
  if (typeof body !== "undefined") {
71
71
  if (typeof body === "object") {
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.27.0",
18
+ "version": "2.29.0",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/cli/index.d.ts",
21
21
  "main": "./dist/cjs/cli/index.js",
@@ -49,10 +49,10 @@
49
49
  "reflect-metadata": "^0.1.13",
50
50
  "type-is": "^1.6.18",
51
51
  "@swc/helpers": "0.5.1",
52
- "@modern-js/bff-runtime": "2.27.0",
53
- "@modern-js/types": "2.27.0",
54
- "@modern-js/utils": "2.27.0",
55
- "@modern-js/bff-core": "2.27.0"
52
+ "@modern-js/bff-runtime": "2.29.0",
53
+ "@modern-js/bff-core": "2.29.0",
54
+ "@modern-js/types": "2.29.0",
55
+ "@modern-js/utils": "2.29.0"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@types/cookie-parser": "^1.4.2",
@@ -68,11 +68,11 @@
68
68
  "supertest": "^6.1.6",
69
69
  "typescript": "^5",
70
70
  "zod": "^3.17.3",
71
- "@modern-js/core": "2.27.0",
72
- "@modern-js/app-tools": "2.27.0",
73
- "@modern-js/server-core": "2.27.0",
74
- "@scripts/build": "2.27.0",
75
- "@scripts/jest-config": "2.27.0"
71
+ "@modern-js/core": "2.29.0",
72
+ "@modern-js/app-tools": "2.29.0",
73
+ "@modern-js/server-core": "2.29.0",
74
+ "@scripts/build": "2.29.0",
75
+ "@scripts/jest-config": "2.29.0"
76
76
  },
77
77
  "peerDependencies": {
78
78
  "express": "^4.17.1"