@kiyasov/platform-hono 1.3.14 → 1.3.15
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/src/adapters/hono-adapter.d.ts +10 -8
- package/dist/cjs/src/adapters/hono-adapter.js +42 -11
- package/dist/cjs/src/adapters/hono-adapter.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/adapters/hono-adapter.d.ts +10 -8
- package/dist/esm/src/adapters/hono-adapter.js +42 -11
- package/dist/esm/src/adapters/hono-adapter.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/adapters/hono-adapter.ts +57 -12
- package/bun.lockb +0 -0
package/package.json
CHANGED
|
@@ -25,6 +25,7 @@ import { HonoRequest, TypeBodyParser } from "../interfaces";
|
|
|
25
25
|
type HonoHandler = RequestHandler<HonoRequest, Context>;
|
|
26
26
|
|
|
27
27
|
type ServerType = Server | Http2Server | Http2SecureServer;
|
|
28
|
+
type Ctx = Context | (() => Promise<Context>);
|
|
28
29
|
|
|
29
30
|
/**
|
|
30
31
|
* Adapter for using Hono with NestJS.
|
|
@@ -62,11 +63,23 @@ export class HonoAdapter extends AbstractHttpAdapter<
|
|
|
62
63
|
};
|
|
63
64
|
}
|
|
64
65
|
|
|
65
|
-
private send(ctx:
|
|
66
|
+
private async send(ctx: Ctx) {
|
|
67
|
+
if (typeof ctx === "function") {
|
|
68
|
+
ctx = await ctx();
|
|
69
|
+
}
|
|
70
|
+
|
|
66
71
|
const body = ctx.get("body");
|
|
67
72
|
return typeof body === "string" ? ctx.text(body) : ctx.json(body);
|
|
68
73
|
}
|
|
69
74
|
|
|
75
|
+
public all(pathOrHandler: string | HonoHandler, handler?: HonoHandler) {
|
|
76
|
+
const [routePath, routeHandler] = this.getRouteAndHandler(
|
|
77
|
+
pathOrHandler,
|
|
78
|
+
handler
|
|
79
|
+
);
|
|
80
|
+
this.instance.all(routePath, this.createRouteHandler(routeHandler));
|
|
81
|
+
}
|
|
82
|
+
|
|
70
83
|
public get(pathOrHandler: string | HonoHandler, handler?: HonoHandler) {
|
|
71
84
|
const [routePath, routeHandler] = this.getRouteAndHandler(
|
|
72
85
|
pathOrHandler,
|
|
@@ -123,10 +136,14 @@ export class HonoAdapter extends AbstractHttpAdapter<
|
|
|
123
136
|
this.instance.options(routePath, this.createRouteHandler(routeHandler));
|
|
124
137
|
}
|
|
125
138
|
|
|
126
|
-
public async reply(ctx:
|
|
139
|
+
public async reply(ctx: Ctx, body: any, statusCode?: StatusCode) {
|
|
140
|
+
if (typeof ctx === "function") {
|
|
141
|
+
ctx = await ctx();
|
|
142
|
+
}
|
|
143
|
+
|
|
127
144
|
if (statusCode) ctx.status(statusCode);
|
|
128
145
|
|
|
129
|
-
const responseContentType = this.getHeader(ctx, "Content-Type");
|
|
146
|
+
const responseContentType = await this.getHeader(ctx, "Content-Type");
|
|
130
147
|
if (
|
|
131
148
|
!responseContentType?.startsWith("application/json") &&
|
|
132
149
|
body?.statusCode >= HttpStatus.BAD_REQUEST
|
|
@@ -139,7 +156,11 @@ export class HonoAdapter extends AbstractHttpAdapter<
|
|
|
139
156
|
ctx.set("body", body);
|
|
140
157
|
}
|
|
141
158
|
|
|
142
|
-
public status(ctx:
|
|
159
|
+
public async status(ctx: Ctx, statusCode: StatusCode) {
|
|
160
|
+
if (typeof ctx === "function") {
|
|
161
|
+
ctx = await ctx();
|
|
162
|
+
}
|
|
163
|
+
|
|
143
164
|
ctx.status(statusCode);
|
|
144
165
|
}
|
|
145
166
|
|
|
@@ -151,7 +172,11 @@ export class HonoAdapter extends AbstractHttpAdapter<
|
|
|
151
172
|
throw new Error("Method not implemented.");
|
|
152
173
|
}
|
|
153
174
|
|
|
154
|
-
public redirect(ctx:
|
|
175
|
+
public async redirect(ctx: Ctx, statusCode: RedirectStatusCode, url: string) {
|
|
176
|
+
if (typeof ctx === "function") {
|
|
177
|
+
ctx = await ctx();
|
|
178
|
+
}
|
|
179
|
+
|
|
155
180
|
ctx.redirect(url, statusCode);
|
|
156
181
|
}
|
|
157
182
|
|
|
@@ -178,23 +203,43 @@ export class HonoAdapter extends AbstractHttpAdapter<
|
|
|
178
203
|
throw new Error("Method not implemented.");
|
|
179
204
|
}
|
|
180
205
|
|
|
181
|
-
public isHeadersSent(ctx:
|
|
182
|
-
|
|
206
|
+
public async isHeadersSent(ctx: Ctx): Promise<boolean> {
|
|
207
|
+
if (typeof ctx === "function") {
|
|
208
|
+
ctx = await ctx();
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return ctx.finalized;
|
|
183
212
|
}
|
|
184
213
|
|
|
185
|
-
public getHeader?(ctx:
|
|
214
|
+
public async getHeader?(ctx: Ctx, name: string) {
|
|
215
|
+
if (typeof ctx === "function") {
|
|
216
|
+
ctx = await ctx();
|
|
217
|
+
}
|
|
218
|
+
|
|
186
219
|
return ctx.req.header(name);
|
|
187
220
|
}
|
|
188
221
|
|
|
189
|
-
public setHeader(ctx:
|
|
222
|
+
public async setHeader(ctx: Ctx, name: string, value: string) {
|
|
223
|
+
if (typeof ctx === "function") {
|
|
224
|
+
ctx = await ctx();
|
|
225
|
+
}
|
|
226
|
+
|
|
190
227
|
ctx.header(name, value);
|
|
191
228
|
}
|
|
192
229
|
|
|
193
|
-
public appendHeader?(ctx:
|
|
230
|
+
public async appendHeader?(ctx: Ctx, name: string, value: string) {
|
|
231
|
+
if (typeof ctx === "function") {
|
|
232
|
+
ctx = await ctx();
|
|
233
|
+
}
|
|
234
|
+
|
|
194
235
|
ctx.res.headers.append(name, value);
|
|
195
236
|
}
|
|
196
237
|
|
|
197
|
-
public getRequestHostname(ctx:
|
|
238
|
+
public async getRequestHostname(ctx: Ctx): Promise<string> {
|
|
239
|
+
if (typeof ctx === "function") {
|
|
240
|
+
ctx = await ctx();
|
|
241
|
+
}
|
|
242
|
+
|
|
198
243
|
return ctx.req.header().host;
|
|
199
244
|
}
|
|
200
245
|
|
|
@@ -264,7 +309,7 @@ export class HonoAdapter extends AbstractHttpAdapter<
|
|
|
264
309
|
(ctx.req as any).body = await ctx.req.json();
|
|
265
310
|
}
|
|
266
311
|
|
|
267
|
-
|
|
312
|
+
await next();
|
|
268
313
|
});
|
|
269
314
|
const isHttpsEnabled = options?.httpsOptions;
|
|
270
315
|
const createServer = isHttpsEnabled
|
package/bun.lockb
DELETED
|
Binary file
|