@modern-js/plugin-bff 2.68.12 → 2.68.13
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.js +2 -1
- package/dist/cjs/runtime/hono/adapter.js +17 -0
- package/dist/cjs/utils/clientGenerator.js +9 -0
- package/dist/cjs/utils/createHonoRoutes.js +40 -48
- package/dist/esm/cli.js +2 -1
- package/dist/esm/runtime/hono/adapter.js +60 -1
- package/dist/esm/utils/clientGenerator.js +9 -2
- package/dist/esm/utils/createHonoRoutes.js +10 -45
- package/dist/esm-node/cli.js +2 -1
- package/dist/esm-node/runtime/hono/adapter.js +18 -1
- package/dist/esm-node/utils/clientGenerator.js +9 -0
- package/dist/esm-node/utils/createHonoRoutes.js +40 -48
- package/dist/types/utils/createHonoRoutes.d.ts +3 -3
- package/package.json +13 -13
package/dist/cjs/cli.js
CHANGED
|
@@ -78,6 +78,23 @@ class HonoAdapter {
|
|
|
78
78
|
const handlers = this.wrapInArray(handler);
|
|
79
79
|
(_this_apiServer = this.apiServer) === null || _this_apiServer === void 0 ? void 0 : _this_apiServer[method](path, ...handlers);
|
|
80
80
|
});
|
|
81
|
+
this.apiServer.onError(async (err, c) => {
|
|
82
|
+
try {
|
|
83
|
+
const serverConfig = this.api.useConfigContext();
|
|
84
|
+
const onErrorHandler = serverConfig === null || serverConfig === void 0 ? void 0 : serverConfig.onError;
|
|
85
|
+
if (onErrorHandler) {
|
|
86
|
+
const result = await onErrorHandler(err, c);
|
|
87
|
+
if (result instanceof Response) {
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
} catch (configError) {
|
|
92
|
+
import_utils.logger.error(`Error in serverConfig.onError handler: ${configError}`);
|
|
93
|
+
}
|
|
94
|
+
return c.json({
|
|
95
|
+
message: (err === null || err === void 0 ? void 0 : err.message) || "[BFF] Internal Server Error"
|
|
96
|
+
}, (err === null || err === void 0 ? void 0 : err.status) || 500);
|
|
97
|
+
});
|
|
81
98
|
};
|
|
82
99
|
this.registerMiddleware = async (options) => {
|
|
83
100
|
const { prefix } = options;
|
|
@@ -129,6 +129,9 @@ async function setPackage(files, appDirectory, relativeDistPath) {
|
|
|
129
129
|
]
|
|
130
130
|
};
|
|
131
131
|
}, {
|
|
132
|
+
[`${API_DIR}/*`]: [
|
|
133
|
+
toPosixPath(`./${relativeDistPath}/${CLIENT_DIR}/*.d.ts`)
|
|
134
|
+
],
|
|
132
135
|
[RUNTIME_DIR]: [
|
|
133
136
|
toPosixPath(`./${relativeDistPath}/${RUNTIME_DIR}/index.d.ts`)
|
|
134
137
|
],
|
|
@@ -148,12 +151,18 @@ async function setPackage(files, appDirectory, relativeDistPath) {
|
|
|
148
151
|
}
|
|
149
152
|
};
|
|
150
153
|
}, {
|
|
154
|
+
[toPosixPath(`./${API_DIR}/*`)]: {
|
|
155
|
+
import: toPosixPath(`./${relativeDistPath}/${CLIENT_DIR}/*.js`),
|
|
156
|
+
types: toPosixPath(`./${relativeDistPath}/${CLIENT_DIR}/*.d.ts`)
|
|
157
|
+
},
|
|
151
158
|
[toPosixPath(`./${PLUGIN_DIR}`)]: {
|
|
159
|
+
import: toPosixPath(`./${relativeDistPath}/${PLUGIN_DIR}/index.js`),
|
|
152
160
|
require: toPosixPath(`./${relativeDistPath}/${PLUGIN_DIR}/index.js`),
|
|
153
161
|
types: toPosixPath(`./${relativeDistPath}/${PLUGIN_DIR}/index.d.ts`)
|
|
154
162
|
},
|
|
155
163
|
[toPosixPath(`./${RUNTIME_DIR}`)]: {
|
|
156
164
|
import: toPosixPath(`./${relativeDistPath}/${RUNTIME_DIR}/index.js`),
|
|
165
|
+
require: toPosixPath(`./${relativeDistPath}/${RUNTIME_DIR}/index.js`),
|
|
157
166
|
types: toPosixPath(`./${relativeDistPath}/${RUNTIME_DIR}/index.d.ts`)
|
|
158
167
|
}
|
|
159
168
|
});
|
|
@@ -71,57 +71,49 @@ const handleResponseMeta = (c, handler) => {
|
|
|
71
71
|
return null;
|
|
72
72
|
};
|
|
73
73
|
const createHonoHandler = (handler) => {
|
|
74
|
-
return async (c
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return response;
|
|
82
|
-
}
|
|
83
|
-
if (c.finalized)
|
|
84
|
-
return;
|
|
85
|
-
const result = await handler(input);
|
|
86
|
-
if (result instanceof Response) {
|
|
87
|
-
return result;
|
|
88
|
-
}
|
|
89
|
-
return result && typeof result === "object" ? c.json(result) : c.body(result);
|
|
90
|
-
} catch (error) {
|
|
91
|
-
if (error instanceof import_bff_core.ValidationError) {
|
|
92
|
-
c.status(error.status);
|
|
93
|
-
return c.json({
|
|
94
|
-
message: error.message
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
throw error;
|
|
74
|
+
return async (c) => {
|
|
75
|
+
const input = await getHonoInput(c);
|
|
76
|
+
if ((0, import_bff_core.isWithMetaHandler)(handler)) {
|
|
77
|
+
try {
|
|
78
|
+
const response = handleResponseMeta(c, handler);
|
|
79
|
+
if (response) {
|
|
80
|
+
return response;
|
|
98
81
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
82
|
+
if (c.finalized)
|
|
83
|
+
return;
|
|
84
|
+
const result = await handler(input);
|
|
85
|
+
if (result instanceof Response) {
|
|
86
|
+
return result;
|
|
87
|
+
}
|
|
88
|
+
return result && typeof result === "object" ? c.json(result) : c.body(result);
|
|
89
|
+
} catch (error) {
|
|
90
|
+
if (error instanceof import_bff_core.ValidationError) {
|
|
91
|
+
c.status(error.status);
|
|
92
|
+
return c.json({
|
|
93
|
+
message: error.message
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
98
|
+
} else {
|
|
99
|
+
var _routePath_match;
|
|
100
|
+
const routePath = c.req.routePath;
|
|
101
|
+
const paramNames = ((_routePath_match = routePath.match(/:\w+/g)) === null || _routePath_match === void 0 ? void 0 : _routePath_match.map((s) => s.slice(1))) || [];
|
|
102
|
+
const params = Object.fromEntries(paramNames.map((name) => [
|
|
103
|
+
name,
|
|
104
|
+
input.params[name]
|
|
105
|
+
]));
|
|
106
|
+
const args = Object.values(params).concat(input);
|
|
107
|
+
const body = await handler(...args);
|
|
108
|
+
if (c.finalized) {
|
|
109
|
+
return await Promise.resolve();
|
|
110
|
+
}
|
|
111
|
+
if (typeof body !== "undefined") {
|
|
112
|
+
if (body instanceof Response) {
|
|
113
|
+
return body;
|
|
121
114
|
}
|
|
115
|
+
return c.json(body);
|
|
122
116
|
}
|
|
123
|
-
} catch (error) {
|
|
124
|
-
next();
|
|
125
117
|
}
|
|
126
118
|
};
|
|
127
119
|
};
|
package/dist/esm/cli.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
2
|
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
|
|
3
|
+
import { _ as _instanceof } from "@swc/helpers/_/_instanceof";
|
|
3
4
|
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
4
5
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
5
6
|
import { Hono } from "@modern-js/server-core";
|
|
6
|
-
import { isProd } from "@modern-js/utils";
|
|
7
|
+
import { isProd, logger } from "@modern-js/utils";
|
|
7
8
|
import createHonoRoutes from "../../utils/createHonoRoutes";
|
|
8
9
|
var before = [
|
|
9
10
|
"custom-server-hook",
|
|
@@ -61,6 +62,64 @@ var HonoAdapter = /* @__PURE__ */ function() {
|
|
|
61
62
|
path
|
|
62
63
|
].concat(_to_consumable_array(handlers)));
|
|
63
64
|
});
|
|
65
|
+
_this.apiServer.onError(function() {
|
|
66
|
+
var _ref = _async_to_generator(function(err, c) {
|
|
67
|
+
var serverConfig, onErrorHandler, result, configError;
|
|
68
|
+
return _ts_generator(this, function(_state2) {
|
|
69
|
+
switch (_state2.label) {
|
|
70
|
+
case 0:
|
|
71
|
+
_state2.trys.push([
|
|
72
|
+
0,
|
|
73
|
+
3,
|
|
74
|
+
,
|
|
75
|
+
4
|
|
76
|
+
]);
|
|
77
|
+
serverConfig = _this.api.useConfigContext();
|
|
78
|
+
onErrorHandler = serverConfig === null || serverConfig === void 0 ? void 0 : serverConfig.onError;
|
|
79
|
+
if (!onErrorHandler)
|
|
80
|
+
return [
|
|
81
|
+
3,
|
|
82
|
+
2
|
|
83
|
+
];
|
|
84
|
+
return [
|
|
85
|
+
4,
|
|
86
|
+
onErrorHandler(err, c)
|
|
87
|
+
];
|
|
88
|
+
case 1:
|
|
89
|
+
result = _state2.sent();
|
|
90
|
+
if (_instanceof(result, Response)) {
|
|
91
|
+
return [
|
|
92
|
+
2,
|
|
93
|
+
result
|
|
94
|
+
];
|
|
95
|
+
}
|
|
96
|
+
_state2.label = 2;
|
|
97
|
+
case 2:
|
|
98
|
+
return [
|
|
99
|
+
3,
|
|
100
|
+
4
|
|
101
|
+
];
|
|
102
|
+
case 3:
|
|
103
|
+
configError = _state2.sent();
|
|
104
|
+
logger.error("Error in serverConfig.onError handler: ".concat(configError));
|
|
105
|
+
return [
|
|
106
|
+
3,
|
|
107
|
+
4
|
|
108
|
+
];
|
|
109
|
+
case 4:
|
|
110
|
+
return [
|
|
111
|
+
2,
|
|
112
|
+
c.json({
|
|
113
|
+
message: (err === null || err === void 0 ? void 0 : err.message) || "[BFF] Internal Server Error"
|
|
114
|
+
}, (err === null || err === void 0 ? void 0 : err.status) || 500)
|
|
115
|
+
];
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
return function(err, c) {
|
|
120
|
+
return _ref.apply(this, arguments);
|
|
121
|
+
};
|
|
122
|
+
}());
|
|
64
123
|
return [
|
|
65
124
|
2
|
|
66
125
|
];
|
|
@@ -252,7 +252,9 @@ function _setPackage() {
|
|
|
252
252
|
return _object_spread_props(_object_spread({}, acc), _define_property({}, toPosixPath("".concat(TYPE_PREFIX).concat(file.exportKey)), [
|
|
253
253
|
typeFilePath
|
|
254
254
|
]));
|
|
255
|
-
}, (_obj = {}, _define_property(_obj,
|
|
255
|
+
}, (_obj = {}, _define_property(_obj, "".concat(API_DIR, "/*"), [
|
|
256
|
+
toPosixPath("./".concat(relativeDistPath, "/").concat(CLIENT_DIR, "/*.d.ts"))
|
|
257
|
+
]), _define_property(_obj, RUNTIME_DIR, [
|
|
256
258
|
toPosixPath("./".concat(relativeDistPath, "/").concat(RUNTIME_DIR, "/index.d.ts"))
|
|
257
259
|
]), _define_property(_obj, PLUGIN_DIR, [
|
|
258
260
|
toPosixPath("./".concat(relativeDistPath, "/").concat(PLUGIN_DIR, "/index.d.ts"))
|
|
@@ -265,11 +267,16 @@ function _setPackage() {
|
|
|
265
267
|
import: jsFilePath,
|
|
266
268
|
types: toPosixPath(jsFilePath.replace(/\.js$/, ".d.ts"))
|
|
267
269
|
}));
|
|
268
|
-
}, (_obj1 = {}, _define_property(_obj1, toPosixPath("./".concat(
|
|
270
|
+
}, (_obj1 = {}, _define_property(_obj1, toPosixPath("./".concat(API_DIR, "/*")), {
|
|
271
|
+
import: toPosixPath("./".concat(relativeDistPath, "/").concat(CLIENT_DIR, "/*.js")),
|
|
272
|
+
types: toPosixPath("./".concat(relativeDistPath, "/").concat(CLIENT_DIR, "/*.d.ts"))
|
|
273
|
+
}), _define_property(_obj1, toPosixPath("./".concat(PLUGIN_DIR)), {
|
|
274
|
+
import: toPosixPath("./".concat(relativeDistPath, "/").concat(PLUGIN_DIR, "/index.js")),
|
|
269
275
|
require: toPosixPath("./".concat(relativeDistPath, "/").concat(PLUGIN_DIR, "/index.js")),
|
|
270
276
|
types: toPosixPath("./".concat(relativeDistPath, "/").concat(PLUGIN_DIR, "/index.d.ts"))
|
|
271
277
|
}), _define_property(_obj1, toPosixPath("./".concat(RUNTIME_DIR)), {
|
|
272
278
|
import: toPosixPath("./".concat(relativeDistPath, "/").concat(RUNTIME_DIR, "/index.js")),
|
|
279
|
+
require: toPosixPath("./".concat(relativeDistPath, "/").concat(RUNTIME_DIR, "/index.js")),
|
|
273
280
|
types: toPosixPath("./".concat(relativeDistPath, "/").concat(RUNTIME_DIR, "/index.d.ts"))
|
|
274
281
|
}), _obj1));
|
|
275
282
|
mergePackageJson(packageJson, addFiles, typesVersions, exports);
|
|
@@ -79,17 +79,11 @@ var handleResponseMeta = function(c, handler) {
|
|
|
79
79
|
};
|
|
80
80
|
var createHonoHandler = function(handler) {
|
|
81
81
|
return function() {
|
|
82
|
-
var _ref = _async_to_generator(function(c
|
|
83
|
-
var input, response, result, error, _routePath_match, routePath, paramNames, params, args, body
|
|
82
|
+
var _ref = _async_to_generator(function(c) {
|
|
83
|
+
var input, response, result, error, _routePath_match, routePath, paramNames, params, args, body;
|
|
84
84
|
return _ts_generator(this, function(_state) {
|
|
85
85
|
switch (_state.label) {
|
|
86
86
|
case 0:
|
|
87
|
-
_state.trys.push([
|
|
88
|
-
0,
|
|
89
|
-
13,
|
|
90
|
-
,
|
|
91
|
-
14
|
|
92
|
-
]);
|
|
93
87
|
return [
|
|
94
88
|
4,
|
|
95
89
|
getHonoInput(c)
|
|
@@ -151,7 +145,7 @@ var createHonoHandler = function(handler) {
|
|
|
151
145
|
case 5:
|
|
152
146
|
return [
|
|
153
147
|
3,
|
|
154
|
-
|
|
148
|
+
10
|
|
155
149
|
];
|
|
156
150
|
case 6:
|
|
157
151
|
routePath = c.req.routePath;
|
|
@@ -165,35 +159,27 @@ var createHonoHandler = function(handler) {
|
|
|
165
159
|
];
|
|
166
160
|
}));
|
|
167
161
|
args = Object.values(params).concat(input);
|
|
168
|
-
_state.label = 7;
|
|
169
|
-
case 7:
|
|
170
|
-
_state.trys.push([
|
|
171
|
-
7,
|
|
172
|
-
11,
|
|
173
|
-
,
|
|
174
|
-
12
|
|
175
|
-
]);
|
|
176
162
|
return [
|
|
177
163
|
4,
|
|
178
164
|
handler.apply(void 0, _to_consumable_array(args))
|
|
179
165
|
];
|
|
180
|
-
case
|
|
166
|
+
case 7:
|
|
181
167
|
body = _state.sent();
|
|
182
168
|
if (!c.finalized)
|
|
183
169
|
return [
|
|
184
170
|
3,
|
|
185
|
-
|
|
171
|
+
9
|
|
186
172
|
];
|
|
187
173
|
return [
|
|
188
174
|
4,
|
|
189
175
|
Promise.resolve()
|
|
190
176
|
];
|
|
191
|
-
case
|
|
177
|
+
case 8:
|
|
192
178
|
return [
|
|
193
179
|
2,
|
|
194
180
|
_state.sent()
|
|
195
181
|
];
|
|
196
|
-
case
|
|
182
|
+
case 9:
|
|
197
183
|
if (typeof body !== "undefined") {
|
|
198
184
|
if (_instanceof(body, Response)) {
|
|
199
185
|
return [
|
|
@@ -206,36 +192,15 @@ var createHonoHandler = function(handler) {
|
|
|
206
192
|
c.json(body)
|
|
207
193
|
];
|
|
208
194
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
12
|
|
212
|
-
];
|
|
213
|
-
case 11:
|
|
214
|
-
e = _state.sent();
|
|
215
|
-
return [
|
|
216
|
-
2,
|
|
217
|
-
next()
|
|
218
|
-
];
|
|
219
|
-
case 12:
|
|
220
|
-
return [
|
|
221
|
-
3,
|
|
222
|
-
14
|
|
223
|
-
];
|
|
224
|
-
case 13:
|
|
225
|
-
error1 = _state.sent();
|
|
226
|
-
next();
|
|
227
|
-
return [
|
|
228
|
-
3,
|
|
229
|
-
14
|
|
230
|
-
];
|
|
231
|
-
case 14:
|
|
195
|
+
_state.label = 10;
|
|
196
|
+
case 10:
|
|
232
197
|
return [
|
|
233
198
|
2
|
|
234
199
|
];
|
|
235
200
|
}
|
|
236
201
|
});
|
|
237
202
|
});
|
|
238
|
-
return function(c
|
|
203
|
+
return function(c) {
|
|
239
204
|
return _ref.apply(this, arguments);
|
|
240
205
|
};
|
|
241
206
|
}();
|
package/dist/esm-node/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Hono } from "@modern-js/server-core";
|
|
2
|
-
import { isProd } from "@modern-js/utils";
|
|
2
|
+
import { isProd, logger } from "@modern-js/utils";
|
|
3
3
|
import createHonoRoutes from "../../utils/createHonoRoutes";
|
|
4
4
|
const before = [
|
|
5
5
|
"custom-server-hook",
|
|
@@ -45,6 +45,23 @@ class HonoAdapter {
|
|
|
45
45
|
const handlers = this.wrapInArray(handler);
|
|
46
46
|
(_this_apiServer = this.apiServer) === null || _this_apiServer === void 0 ? void 0 : _this_apiServer[method](path, ...handlers);
|
|
47
47
|
});
|
|
48
|
+
this.apiServer.onError(async (err, c) => {
|
|
49
|
+
try {
|
|
50
|
+
const serverConfig = this.api.useConfigContext();
|
|
51
|
+
const onErrorHandler = serverConfig === null || serverConfig === void 0 ? void 0 : serverConfig.onError;
|
|
52
|
+
if (onErrorHandler) {
|
|
53
|
+
const result = await onErrorHandler(err, c);
|
|
54
|
+
if (result instanceof Response) {
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
} catch (configError) {
|
|
59
|
+
logger.error(`Error in serverConfig.onError handler: ${configError}`);
|
|
60
|
+
}
|
|
61
|
+
return c.json({
|
|
62
|
+
message: (err === null || err === void 0 ? void 0 : err.message) || "[BFF] Internal Server Error"
|
|
63
|
+
}, (err === null || err === void 0 ? void 0 : err.status) || 500);
|
|
64
|
+
});
|
|
48
65
|
};
|
|
49
66
|
this.registerMiddleware = async (options) => {
|
|
50
67
|
const { prefix } = options;
|
|
@@ -94,6 +94,9 @@ async function setPackage(files, appDirectory, relativeDistPath) {
|
|
|
94
94
|
]
|
|
95
95
|
};
|
|
96
96
|
}, {
|
|
97
|
+
[`${API_DIR}/*`]: [
|
|
98
|
+
toPosixPath(`./${relativeDistPath}/${CLIENT_DIR}/*.d.ts`)
|
|
99
|
+
],
|
|
97
100
|
[RUNTIME_DIR]: [
|
|
98
101
|
toPosixPath(`./${relativeDistPath}/${RUNTIME_DIR}/index.d.ts`)
|
|
99
102
|
],
|
|
@@ -113,12 +116,18 @@ async function setPackage(files, appDirectory, relativeDistPath) {
|
|
|
113
116
|
}
|
|
114
117
|
};
|
|
115
118
|
}, {
|
|
119
|
+
[toPosixPath(`./${API_DIR}/*`)]: {
|
|
120
|
+
import: toPosixPath(`./${relativeDistPath}/${CLIENT_DIR}/*.js`),
|
|
121
|
+
types: toPosixPath(`./${relativeDistPath}/${CLIENT_DIR}/*.d.ts`)
|
|
122
|
+
},
|
|
116
123
|
[toPosixPath(`./${PLUGIN_DIR}`)]: {
|
|
124
|
+
import: toPosixPath(`./${relativeDistPath}/${PLUGIN_DIR}/index.js`),
|
|
117
125
|
require: toPosixPath(`./${relativeDistPath}/${PLUGIN_DIR}/index.js`),
|
|
118
126
|
types: toPosixPath(`./${relativeDistPath}/${PLUGIN_DIR}/index.d.ts`)
|
|
119
127
|
},
|
|
120
128
|
[toPosixPath(`./${RUNTIME_DIR}`)]: {
|
|
121
129
|
import: toPosixPath(`./${relativeDistPath}/${RUNTIME_DIR}/index.js`),
|
|
130
|
+
require: toPosixPath(`./${relativeDistPath}/${RUNTIME_DIR}/index.js`),
|
|
122
131
|
types: toPosixPath(`./${relativeDistPath}/${RUNTIME_DIR}/index.d.ts`)
|
|
123
132
|
}
|
|
124
133
|
});
|
|
@@ -37,57 +37,49 @@ const handleResponseMeta = (c, handler) => {
|
|
|
37
37
|
return null;
|
|
38
38
|
};
|
|
39
39
|
const createHonoHandler = (handler) => {
|
|
40
|
-
return async (c
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return response;
|
|
48
|
-
}
|
|
49
|
-
if (c.finalized)
|
|
50
|
-
return;
|
|
51
|
-
const result = await handler(input);
|
|
52
|
-
if (result instanceof Response) {
|
|
53
|
-
return result;
|
|
54
|
-
}
|
|
55
|
-
return result && typeof result === "object" ? c.json(result) : c.body(result);
|
|
56
|
-
} catch (error) {
|
|
57
|
-
if (error instanceof ValidationError) {
|
|
58
|
-
c.status(error.status);
|
|
59
|
-
return c.json({
|
|
60
|
-
message: error.message
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
throw error;
|
|
40
|
+
return async (c) => {
|
|
41
|
+
const input = await getHonoInput(c);
|
|
42
|
+
if (isWithMetaHandler(handler)) {
|
|
43
|
+
try {
|
|
44
|
+
const response = handleResponseMeta(c, handler);
|
|
45
|
+
if (response) {
|
|
46
|
+
return response;
|
|
64
47
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
48
|
+
if (c.finalized)
|
|
49
|
+
return;
|
|
50
|
+
const result = await handler(input);
|
|
51
|
+
if (result instanceof Response) {
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
return result && typeof result === "object" ? c.json(result) : c.body(result);
|
|
55
|
+
} catch (error) {
|
|
56
|
+
if (error instanceof ValidationError) {
|
|
57
|
+
c.status(error.status);
|
|
58
|
+
return c.json({
|
|
59
|
+
message: error.message
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
var _routePath_match;
|
|
66
|
+
const routePath = c.req.routePath;
|
|
67
|
+
const paramNames = ((_routePath_match = routePath.match(/:\w+/g)) === null || _routePath_match === void 0 ? void 0 : _routePath_match.map((s) => s.slice(1))) || [];
|
|
68
|
+
const params = Object.fromEntries(paramNames.map((name) => [
|
|
69
|
+
name,
|
|
70
|
+
input.params[name]
|
|
71
|
+
]));
|
|
72
|
+
const args = Object.values(params).concat(input);
|
|
73
|
+
const body = await handler(...args);
|
|
74
|
+
if (c.finalized) {
|
|
75
|
+
return await Promise.resolve();
|
|
76
|
+
}
|
|
77
|
+
if (typeof body !== "undefined") {
|
|
78
|
+
if (body instanceof Response) {
|
|
79
|
+
return body;
|
|
87
80
|
}
|
|
81
|
+
return c.json(body);
|
|
88
82
|
}
|
|
89
|
-
} catch (error) {
|
|
90
|
-
next();
|
|
91
83
|
}
|
|
92
84
|
};
|
|
93
85
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { APIHandlerInfo } from '@modern-js/bff-core';
|
|
2
|
-
import type { Context
|
|
2
|
+
import type { Context } from '@modern-js/server-core';
|
|
3
3
|
type Handler = APIHandlerInfo['handler'];
|
|
4
4
|
declare const createHonoRoutes: (handlerInfos?: APIHandlerInfo[]) => {
|
|
5
5
|
method: any;
|
|
6
6
|
path: string;
|
|
7
|
-
handler: any[] | ((c: Context
|
|
7
|
+
handler: any[] | ((c: Context) => Promise<void | Response>);
|
|
8
8
|
}[];
|
|
9
|
-
export declare const createHonoHandler: (handler: Handler) => (c: Context
|
|
9
|
+
export declare const createHonoHandler: (handler: Handler) => (c: Context) => Promise<void | Response>;
|
|
10
10
|
export default createHonoRoutes;
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.68.
|
|
18
|
+
"version": "2.68.13",
|
|
19
19
|
"jsnext:source": "./src/cli.ts",
|
|
20
20
|
"types": "./dist/types/cli.d.ts",
|
|
21
21
|
"main": "./dist/cjs/cli.js",
|
|
@@ -76,14 +76,14 @@
|
|
|
76
76
|
"@babel/core": "^7.26.0",
|
|
77
77
|
"@swc/helpers": "^0.5.17",
|
|
78
78
|
"type-is": "^1.6.18",
|
|
79
|
-
"@modern-js/bff-core": "2.68.
|
|
80
|
-
"@modern-js/create-request": "2.68.
|
|
81
|
-
"@modern-js/server-core": "2.68.
|
|
82
|
-
"@modern-js/server-utils": "2.68.
|
|
83
|
-
"@modern-js/utils": "2.68.
|
|
79
|
+
"@modern-js/bff-core": "2.68.13",
|
|
80
|
+
"@modern-js/create-request": "2.68.13",
|
|
81
|
+
"@modern-js/server-core": "2.68.13",
|
|
82
|
+
"@modern-js/server-utils": "2.68.13",
|
|
83
|
+
"@modern-js/utils": "2.68.13"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
|
-
"@rsbuild/core": "1.5.
|
|
86
|
+
"@rsbuild/core": "1.5.6",
|
|
87
87
|
"@types/babel__core": "^7.20.5",
|
|
88
88
|
"@types/jest": "^29",
|
|
89
89
|
"@types/node": "^18",
|
|
@@ -94,12 +94,12 @@
|
|
|
94
94
|
"typescript": "^5",
|
|
95
95
|
"webpack": "^5.101.3",
|
|
96
96
|
"zod": "^3.22.3",
|
|
97
|
-
"@modern-js/
|
|
98
|
-
"@modern-js/
|
|
99
|
-
"@modern-js/core": "2.68.
|
|
100
|
-
"@modern-js/plugin-v2": "2.68.
|
|
101
|
-
"@modern-js/runtime": "2.68.
|
|
102
|
-
"@modern-js/types": "2.68.
|
|
97
|
+
"@modern-js/app-tools": "2.68.13",
|
|
98
|
+
"@modern-js/bff-runtime": "2.68.13",
|
|
99
|
+
"@modern-js/core": "2.68.13",
|
|
100
|
+
"@modern-js/plugin-v2": "2.68.13",
|
|
101
|
+
"@modern-js/runtime": "2.68.13",
|
|
102
|
+
"@modern-js/types": "2.68.13",
|
|
103
103
|
"@scripts/build": "2.66.0",
|
|
104
104
|
"@scripts/jest-config": "2.66.0"
|
|
105
105
|
},
|