@ts-kizuna/fastify 1.55.0 → 1.56.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/index.cjs +8 -5
- package/dist/index.mjs +8 -5
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -52,7 +52,7 @@ const adapter = (0, _ts_kizuna_core_adapter.createAdapter)({
|
|
|
52
52
|
writeWebResponse(result.response, reply);
|
|
53
53
|
return;
|
|
54
54
|
}
|
|
55
|
-
const rendered = (0, _ts_kizuna_core_adapter.renderJsonResult)(result, formatError, reply.request);
|
|
55
|
+
const rendered = (0, _ts_kizuna_core_adapter.renderJsonResult)(result, formatError, reply.request, reply.request.method);
|
|
56
56
|
for (const [key, value] of Object.entries(rendered.headers)) reply.header(key, value);
|
|
57
57
|
if (rendered.body === void 0) reply.status(rendered.status).send();
|
|
58
58
|
else if (rendered.raw) {
|
|
@@ -76,9 +76,9 @@ const fastifyKizuna = (0, fastify_plugin.default)(async (app, options) => {
|
|
|
76
76
|
const pluginExports = (0, _ts_kizuna_core_adapter.pluginExportsOf)(api);
|
|
77
77
|
const jobsMeta = api[_ts_kizuna_core_adapter.JOBS_META];
|
|
78
78
|
const jobRunner = (0, _ts_kizuna_core_adapter.jobRunnerFrom)(jobsMeta);
|
|
79
|
-
const mountRoute = (routeKey, route, lane, resolvedRouter) => {
|
|
79
|
+
const mountRoute = (routeKey, route, lane, resolvedRouter, method = route.method) => {
|
|
80
80
|
app.route({
|
|
81
|
-
method
|
|
81
|
+
method,
|
|
82
82
|
url: route.path,
|
|
83
83
|
preHandler: [async (request) => {
|
|
84
84
|
request.kizunaRoute = route;
|
|
@@ -116,8 +116,11 @@ const fastifyKizuna = (0, fastify_plugin.default)(async (app, options) => {
|
|
|
116
116
|
});
|
|
117
117
|
};
|
|
118
118
|
const mountLane = (lane, resolvedRouter) => {
|
|
119
|
-
const declaredRoutes = [...adapter.eachRoute(lane, resolvedRouter)]
|
|
120
|
-
|
|
119
|
+
const declaredRoutes = [...adapter.eachRoute(lane, resolvedRouter)];
|
|
120
|
+
const headPaths = new Set(declaredRoutes.filter(({ route }) => route.method === "HEAD").map(({ route }) => route.path));
|
|
121
|
+
for (const { routeKey, route } of declaredRoutes) if (route.method === "HEAD") mountRoute(routeKey, route, lane, resolvedRouter);
|
|
122
|
+
for (const { routeKey, route } of declaredRoutes) if (route.method === "GET" && !headPaths.has(route.path)) mountRoute(routeKey, route, lane, resolvedRouter, "HEAD");
|
|
123
|
+
for (const { routeKey, route } of declaredRoutes) if (route.method !== "HEAD") mountRoute(routeKey, route, lane, resolvedRouter);
|
|
121
124
|
};
|
|
122
125
|
mountLane(api.routes, api[_ts_kizuna_core_adapter.ROUTER_META]);
|
|
123
126
|
mountLane((0, _ts_kizuna_core_adapter.pluginRoutesOf)(api), (0, _ts_kizuna_core_adapter.pluginRouterOf)(api));
|
package/dist/index.mjs
CHANGED
|
@@ -28,7 +28,7 @@ const adapter = createAdapter({
|
|
|
28
28
|
writeWebResponse(result.response, reply);
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
31
|
-
const rendered = renderJsonResult(result, formatError, reply.request);
|
|
31
|
+
const rendered = renderJsonResult(result, formatError, reply.request, reply.request.method);
|
|
32
32
|
for (const [key, value] of Object.entries(rendered.headers)) reply.header(key, value);
|
|
33
33
|
if (rendered.body === void 0) reply.status(rendered.status).send();
|
|
34
34
|
else if (rendered.raw) {
|
|
@@ -52,9 +52,9 @@ const fastifyKizuna = fastifyPlugin(async (app, options) => {
|
|
|
52
52
|
const pluginExports = pluginExportsOf(api);
|
|
53
53
|
const jobsMeta = api[JOBS_META];
|
|
54
54
|
const jobRunner = jobRunnerFrom(jobsMeta);
|
|
55
|
-
const mountRoute = (routeKey, route, lane, resolvedRouter) => {
|
|
55
|
+
const mountRoute = (routeKey, route, lane, resolvedRouter, method = route.method) => {
|
|
56
56
|
app.route({
|
|
57
|
-
method
|
|
57
|
+
method,
|
|
58
58
|
url: route.path,
|
|
59
59
|
preHandler: [async (request) => {
|
|
60
60
|
request.kizunaRoute = route;
|
|
@@ -92,8 +92,11 @@ const fastifyKizuna = fastifyPlugin(async (app, options) => {
|
|
|
92
92
|
});
|
|
93
93
|
};
|
|
94
94
|
const mountLane = (lane, resolvedRouter) => {
|
|
95
|
-
const declaredRoutes = [...adapter.eachRoute(lane, resolvedRouter)]
|
|
96
|
-
|
|
95
|
+
const declaredRoutes = [...adapter.eachRoute(lane, resolvedRouter)];
|
|
96
|
+
const headPaths = new Set(declaredRoutes.filter(({ route }) => route.method === "HEAD").map(({ route }) => route.path));
|
|
97
|
+
for (const { routeKey, route } of declaredRoutes) if (route.method === "HEAD") mountRoute(routeKey, route, lane, resolvedRouter);
|
|
98
|
+
for (const { routeKey, route } of declaredRoutes) if (route.method === "GET" && !headPaths.has(route.path)) mountRoute(routeKey, route, lane, resolvedRouter, "HEAD");
|
|
99
|
+
for (const { routeKey, route } of declaredRoutes) if (route.method !== "HEAD") mountRoute(routeKey, route, lane, resolvedRouter);
|
|
97
100
|
};
|
|
98
101
|
mountLane(api.routes, api[ROUTER_META]);
|
|
99
102
|
mountLane(pluginRoutesOf(api), pluginRouterOf(api));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ts-kizuna/fastify",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.56.0",
|
|
4
4
|
"description": "Fastify adapter for ts-kizuna",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ts-kizuna",
|
|
@@ -60,14 +60,14 @@
|
|
|
60
60
|
"peerDependencies": {
|
|
61
61
|
"fastify": "^5.0.0",
|
|
62
62
|
"zod": "^4.0.0",
|
|
63
|
-
"@ts-kizuna/core": "1.
|
|
63
|
+
"@ts-kizuna/core": "1.56.0"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"fastify": "^5.0.0",
|
|
67
67
|
"tsdown": "^0.21.0",
|
|
68
68
|
"typescript": "^6.0.3",
|
|
69
69
|
"zod": "^4.0.0",
|
|
70
|
-
"@ts-kizuna/core": "1.
|
|
70
|
+
"@ts-kizuna/core": "1.56.0"
|
|
71
71
|
},
|
|
72
72
|
"scripts": {
|
|
73
73
|
"build": "tsdown src/index.ts --format esm,cjs --dts --clean --external @ts-kizuna/core --external fastify --external fastify-plugin --external zod",
|