@kiyasov/platform-hono 1.3.15 → 1.3.16

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.15",
3
+ "version": "1.3.16",
4
4
  "description": "Nest adapter for Hono",
5
5
  "author": "Islam Kiiasov",
6
6
  "repository": {
@@ -20,34 +20,34 @@
20
20
  "access": "public"
21
21
  },
22
22
  "dependencies": {
23
- "@apollo/server": "^4.11.0",
24
- "@hono/node-server": "^1.13.2",
25
- "@nestjs/apollo": "^12.2.1",
26
- "@nestjs/graphql": "^12.2.1",
27
- "hono": "^4.6.6"
23
+ "@apollo/server": "^4.11.2",
24
+ "@hono/node-server": "^1.13.7",
25
+ "@nestjs/apollo": "^12.2.2",
26
+ "@nestjs/graphql": "^12.2.2",
27
+ "hono": "^4.6.14"
28
28
  },
29
29
  "devDependencies": {
30
- "@nestjs/cli": "^10.4.5",
31
- "@nestjs/common": "^10.4.6",
32
- "@nestjs/core": "^10.4.6",
30
+ "@nestjs/cli": "^10.4.9",
31
+ "@nestjs/common": "^10.4.15",
32
+ "@nestjs/core": "^10.4.15",
33
33
  "@swc/cli": "^0.4.0",
34
- "@swc/core": "^1.7.39",
34
+ "@swc/core": "^1.10.1",
35
35
  "@types/autocannon": "^7.12.5",
36
- "@types/bun": "^1.1.12",
36
+ "@types/bun": "^1.1.14",
37
37
  "@types/busboy": "^1.5.4",
38
38
  "autocannon": "^7.15.0",
39
- "bun": "^1.1.32",
40
- "graphql": "^16.9.0",
39
+ "bun": "^1.1.42",
40
+ "graphql": "^16.10.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.3"
46
+ "typescript": "^5.7.2"
47
47
  },
48
48
  "scripts": {
49
- "build:esm": "tsc --p tsconfig.esm.json",
50
- "build:cjs": "tsc --p tsconfig.cjs.json",
49
+ "build:esm": "node_modules/.bin/tsc --p tsconfig.esm.json",
50
+ "build:cjs": "node_modules/.bin/tsc --p tsconfig.cjs.json",
51
51
  "build": "npm run build:esm && npm run build:cjs",
52
52
  "dev": "cd example && yarn nest start -w --copy-files",
53
53
  "dev:bun": "cd example && nest start -w --copy-files --exec \"bun run\"",
@@ -69,7 +69,26 @@ export class HonoAdapter extends AbstractHttpAdapter<
69
69
  }
70
70
 
71
71
  const body = ctx.get("body");
72
- return typeof body === "string" ? ctx.text(body) : ctx.json(body);
72
+ let responseContentType = await this.getHeader(ctx, "Content-Type");
73
+
74
+ if (responseContentType === "text/plain;charset=UTF-8") {
75
+ if (body instanceof Buffer) {
76
+ responseContentType = "application/octet-stream";
77
+ } else if (typeof body === "object") {
78
+ responseContentType = "application/json";
79
+ }
80
+
81
+ this.setHeader(ctx, "Content-Type", responseContentType);
82
+ }
83
+
84
+ if (
85
+ responseContentType === "application/json" &&
86
+ typeof body === "object"
87
+ ) {
88
+ return ctx.json(body);
89
+ }
90
+
91
+ return ctx.body(body);
73
92
  }
74
93
 
75
94
  public all(pathOrHandler: string | HonoHandler, handler?: HonoHandler) {
@@ -144,6 +163,7 @@ export class HonoAdapter extends AbstractHttpAdapter<
144
163
  if (statusCode) ctx.status(statusCode);
145
164
 
146
165
  const responseContentType = await this.getHeader(ctx, "Content-Type");
166
+
147
167
  if (
148
168
  !responseContentType?.startsWith("application/json") &&
149
169
  body?.statusCode >= HttpStatus.BAD_REQUEST
@@ -153,6 +173,7 @@ export class HonoAdapter extends AbstractHttpAdapter<
153
173
  );
154
174
  this.setHeader(ctx, "Content-Type", "application/json");
155
175
  }
176
+
156
177
  ctx.set("body", body);
157
178
  }
158
179
 
@@ -216,7 +237,7 @@ export class HonoAdapter extends AbstractHttpAdapter<
216
237
  ctx = await ctx();
217
238
  }
218
239
 
219
- return ctx.req.header(name);
240
+ return ctx.res.headers.get(name);
220
241
  }
221
242
 
222
243
  public async setHeader(ctx: Ctx, name: string, value: string) {
@@ -224,7 +245,7 @@ export class HonoAdapter extends AbstractHttpAdapter<
224
245
  ctx = await ctx();
225
246
  }
226
247
 
227
- ctx.header(name, value);
248
+ ctx.res.headers.set(name, value);
228
249
  }
229
250
 
230
251
  public async appendHeader?(ctx: Ctx, name: string, value: string) {
@@ -45,7 +45,7 @@ export class ReadStream extends Readable {
45
45
  // Using `allocUnsafe` here is OK because we return a slice the length of
46
46
  // `bytesRead`, and discard the rest. This prevents node from having to zero
47
47
  // out the entire allocation first.
48
- const buf = Buffer.allocUnsafe(n);
48
+ const buf = new Uint8Array(Buffer.allocUnsafe(n).buffer);
49
49
  read(this._writeStream["_fd"], buf, 0, n, this._pos, (error, bytesRead) => {
50
50
  if (error) this.destroy(error);
51
51
 
@@ -199,7 +199,13 @@ export class WriteStream extends Writable {
199
199
  return;
200
200
  }
201
201
 
202
- write(this._fd, chunk, 0, chunk.length, this._pos, (error) => {
202
+ const uint8Array = new Uint8Array(
203
+ chunk.buffer,
204
+ chunk.byteOffset,
205
+ chunk.byteLength
206
+ );
207
+
208
+ write(this._fd, uint8Array, 0, chunk.length, this._pos, (error) => {
203
209
  if (error) {
204
210
  callback(error);
205
211
  return;