@kiyasov/platform-hono 1.3.12 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kiyasov/platform-hono",
3
- "version": "1.3.12",
3
+ "version": "1.3.15",
4
4
  "description": "Nest adapter for Hono",
5
5
  "author": "Islam Kiiasov",
6
6
  "repository": {
@@ -21,29 +21,29 @@
21
21
  },
22
22
  "dependencies": {
23
23
  "@apollo/server": "^4.11.0",
24
- "@hono/node-server": "^1.13.0",
25
- "@nestjs/apollo": "^12.2.0",
26
- "@nestjs/graphql": "^12.2.0",
27
- "hono": "^4.6.2"
24
+ "@hono/node-server": "^1.13.2",
25
+ "@nestjs/apollo": "^12.2.1",
26
+ "@nestjs/graphql": "^12.2.1",
27
+ "hono": "^4.6.6"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@nestjs/cli": "^10.4.5",
31
- "@nestjs/common": "^10.4.3",
32
- "@nestjs/core": "^10.4.3",
31
+ "@nestjs/common": "^10.4.6",
32
+ "@nestjs/core": "^10.4.6",
33
33
  "@swc/cli": "^0.4.0",
34
- "@swc/core": "^1.7.26",
34
+ "@swc/core": "^1.7.39",
35
35
  "@types/autocannon": "^7.12.5",
36
- "@types/bun": "^1.1.9",
36
+ "@types/bun": "^1.1.12",
37
37
  "@types/busboy": "^1.5.4",
38
38
  "autocannon": "^7.15.0",
39
- "bun": "^1.1.27",
39
+ "bun": "^1.1.32",
40
40
  "graphql": "^16.9.0",
41
41
  "graphql-subscriptions": "^2.0.0",
42
42
  "reflect-metadata": "^0.2.2",
43
43
  "rimraf": "^6.0.1",
44
44
  "rxjs": "^7.8.1",
45
45
  "tsc": "^2.0.4",
46
- "typescript": "^5.6.2"
46
+ "typescript": "^5.6.3"
47
47
  },
48
48
  "scripts": {
49
49
  "build:esm": "tsc --p tsconfig.esm.json",
@@ -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: Context) {
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: Context, body: any, statusCode?: StatusCode) {
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: Context, statusCode: StatusCode) {
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: Context, statusCode: RedirectStatusCode, url: string) {
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: Context): boolean {
182
- return true;
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: Context, name: string) {
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: Context, name: string, value: string) {
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: Context, name: string, value: string) {
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: Context): string {
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
- return next();
312
+ await next();
268
313
  });
269
314
  const isHttpsEnabled = options?.httpsOptions;
270
315
  const createServer = isHttpsEnabled
package/bun.lockb DELETED
Binary file