@kiyasov/platform-hono 1.5.7 → 1.5.9

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.5.7",
3
+ "version": "1.5.9",
4
4
  "description": "Nest adapter for Hono",
5
5
  "author": "Islam Kiiasov",
6
6
  "repository": {
@@ -46,26 +46,26 @@
46
46
  "@hono/node-server": "^1.19.7",
47
47
  "@nestjs/apollo": "^13.2.3",
48
48
  "@nestjs/graphql": "^13.2.3",
49
- "hono": "^4.11.0"
49
+ "hono": "^4.11.1"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@eslint/js": "^9.39.2",
53
53
  "@nestjs/cli": "^11.0.14",
54
- "@nestjs/common": "^11.1.9",
55
- "@nestjs/core": "^11.1.9",
54
+ "@nestjs/common": "^11.1.10",
55
+ "@nestjs/core": "^11.1.10",
56
56
  "@nestjs/swagger": "^11.2.3",
57
57
  "@swc/cli": "^0.7.9",
58
- "@swc/core": "^1.15.4",
58
+ "@swc/core": "^1.15.7",
59
59
  "@types/autocannon": "^7.12.7",
60
- "@types/bun": "^1.3.4",
60
+ "@types/bun": "^1.3.5",
61
61
  "@types/busboy": "^1.5.4",
62
62
  "autocannon": "^8.0.0",
63
- "bun": "^1.3.4",
63
+ "bun": "^1.3.5",
64
64
  "class-transformer": "^0.5.1",
65
65
  "class-validator": "^0.14.3",
66
66
  "eslint": "^9.39.2",
67
67
  "eslint-config-prettier": "^10.1.8",
68
- "eslint-plugin-perfectionist": "^4.15.1",
68
+ "eslint-plugin-perfectionist": "^5.1.0",
69
69
  "eslint-plugin-prettier": "^5.5.4",
70
70
  "globals": "^16.5.0",
71
71
  "graphql": "^16.12.0",
@@ -77,7 +77,7 @@
77
77
  "sharp": "^0.34.5",
78
78
  "tsc": "^2.0.4",
79
79
  "typescript": "^5.9.3",
80
- "typescript-eslint": "^8.49.0",
80
+ "typescript-eslint": "^8.50.1",
81
81
  "undici": "^7.16.0"
82
82
  },
83
83
  "scripts": {
@@ -11,6 +11,7 @@ import {
11
11
  NestApplicationOptions,
12
12
  RequestHandler,
13
13
  } from '@nestjs/common/interfaces';
14
+ import { isObject } from '@nestjs/common/utils/shared.utils';
14
15
  import { AbstractHttpAdapter } from '@nestjs/core/adapters/http-adapter';
15
16
  import { Context, Next, Hono } from 'hono';
16
17
  import { bodyLimit } from 'hono/body-limit';
@@ -24,9 +25,17 @@ import * as https from 'https';
24
25
  import { HonoRequest, TypeBodyParser } from '../interfaces';
25
26
 
26
27
  type HonoHandler = RequestHandler<HonoRequest, Context>;
27
-
28
28
  type ServerType = http.Server | http2.Http2Server | http2.Http2SecureServer;
29
29
  type Ctx = Context | (() => Promise<Context>);
30
+ type Method =
31
+ | 'all'
32
+ | 'get'
33
+ | 'post'
34
+ | 'put'
35
+ | 'delete'
36
+ | 'use'
37
+ | 'patch'
38
+ | 'options';
30
39
 
31
40
  /**
32
41
  * Adapter for using Hono with NestJS.
@@ -80,22 +89,28 @@ export class HonoAdapter extends AbstractHttpAdapter<
80
89
  private async getBody(ctx: Ctx, body?: Data) {
81
90
  ctx = await this.normalizeContext(ctx);
82
91
 
92
+ if (body === undefined && ctx.res && ctx.res.body !== null) {
93
+ return ctx.res;
94
+ }
95
+
83
96
  let responseContentType = await this.getHeader(ctx, 'Content-Type');
84
97
 
85
98
  if (!responseContentType || responseContentType.startsWith('text/plain')) {
86
- if (body instanceof Buffer) {
99
+ if (
100
+ body instanceof Buffer ||
101
+ body instanceof Uint8Array ||
102
+ body instanceof ArrayBuffer ||
103
+ body instanceof ReadableStream
104
+ ) {
87
105
  responseContentType = 'application/octet-stream';
88
- } else if (typeof body === 'object') {
106
+ } else if (isObject(body)) {
89
107
  responseContentType = 'application/json';
90
108
  }
91
109
 
92
- this.setHeader(ctx, 'Content-Type', responseContentType);
110
+ await this.setHeader(ctx, 'Content-Type', responseContentType);
93
111
  }
94
112
 
95
- if (
96
- responseContentType === 'application/json' &&
97
- typeof body === 'object'
98
- ) {
113
+ if (responseContentType === 'application/json' && isObject(body)) {
99
114
  return ctx.json(body);
100
115
  } else if (body === undefined) {
101
116
  return ctx.newResponse(null);
@@ -105,15 +120,7 @@ export class HonoAdapter extends AbstractHttpAdapter<
105
120
  }
106
121
 
107
122
  private registerRoute(
108
- method:
109
- | 'all'
110
- | 'get'
111
- | 'post'
112
- | 'put'
113
- | 'delete'
114
- | 'use'
115
- | 'patch'
116
- | 'options',
123
+ method: Method,
117
124
  pathOrHandler: string | HonoHandler,
118
125
  handler?: HonoHandler,
119
126
  ) {
@@ -191,18 +198,6 @@ export class HonoAdapter extends AbstractHttpAdapter<
191
198
  ctx.status(statusCode);
192
199
  }
193
200
 
194
- const responseContentType = await this.getHeader(ctx, 'Content-Type');
195
-
196
- if (
197
- !responseContentType?.startsWith('application/json') &&
198
- body?.statusCode >= HttpStatus.BAD_REQUEST
199
- ) {
200
- Logger.warn(
201
- "Content-Type doesn't match Reply body, you might need a custom ExceptionFilter for non-JSON responses",
202
- );
203
- this.setHeader(ctx, 'Content-Type', 'application/json');
204
- }
205
-
206
201
  ctx.res = await this.getBody(ctx, body);
207
202
  }
208
203