@kiyasov/platform-hono 1.3.14 → 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.14",
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\"",
@@ -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,9 +63,40 @@ 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
- 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);
92
+ }
93
+
94
+ public all(pathOrHandler: string | HonoHandler, handler?: HonoHandler) {
95
+ const [routePath, routeHandler] = this.getRouteAndHandler(
96
+ pathOrHandler,
97
+ handler
98
+ );
99
+ this.instance.all(routePath, this.createRouteHandler(routeHandler));
68
100
  }
69
101
 
70
102
  public get(pathOrHandler: string | HonoHandler, handler?: HonoHandler) {
@@ -123,10 +155,15 @@ export class HonoAdapter extends AbstractHttpAdapter<
123
155
  this.instance.options(routePath, this.createRouteHandler(routeHandler));
124
156
  }
125
157
 
126
- public async reply(ctx: Context, body: any, statusCode?: StatusCode) {
158
+ public async reply(ctx: Ctx, body: any, statusCode?: StatusCode) {
159
+ if (typeof ctx === "function") {
160
+ ctx = await ctx();
161
+ }
162
+
127
163
  if (statusCode) ctx.status(statusCode);
128
164
 
129
- const responseContentType = this.getHeader(ctx, "Content-Type");
165
+ const responseContentType = await this.getHeader(ctx, "Content-Type");
166
+
130
167
  if (
131
168
  !responseContentType?.startsWith("application/json") &&
132
169
  body?.statusCode >= HttpStatus.BAD_REQUEST
@@ -136,10 +173,15 @@ export class HonoAdapter extends AbstractHttpAdapter<
136
173
  );
137
174
  this.setHeader(ctx, "Content-Type", "application/json");
138
175
  }
176
+
139
177
  ctx.set("body", body);
140
178
  }
141
179
 
142
- public status(ctx: Context, statusCode: StatusCode) {
180
+ public async status(ctx: Ctx, statusCode: StatusCode) {
181
+ if (typeof ctx === "function") {
182
+ ctx = await ctx();
183
+ }
184
+
143
185
  ctx.status(statusCode);
144
186
  }
145
187
 
@@ -151,7 +193,11 @@ export class HonoAdapter extends AbstractHttpAdapter<
151
193
  throw new Error("Method not implemented.");
152
194
  }
153
195
 
154
- public redirect(ctx: Context, statusCode: RedirectStatusCode, url: string) {
196
+ public async redirect(ctx: Ctx, statusCode: RedirectStatusCode, url: string) {
197
+ if (typeof ctx === "function") {
198
+ ctx = await ctx();
199
+ }
200
+
155
201
  ctx.redirect(url, statusCode);
156
202
  }
157
203
 
@@ -178,23 +224,43 @@ export class HonoAdapter extends AbstractHttpAdapter<
178
224
  throw new Error("Method not implemented.");
179
225
  }
180
226
 
181
- public isHeadersSent(ctx: Context): boolean {
182
- return true;
227
+ public async isHeadersSent(ctx: Ctx): Promise<boolean> {
228
+ if (typeof ctx === "function") {
229
+ ctx = await ctx();
230
+ }
231
+
232
+ return ctx.finalized;
183
233
  }
184
234
 
185
- public getHeader?(ctx: Context, name: string) {
186
- return ctx.req.header(name);
235
+ public async getHeader?(ctx: Ctx, name: string) {
236
+ if (typeof ctx === "function") {
237
+ ctx = await ctx();
238
+ }
239
+
240
+ return ctx.res.headers.get(name);
187
241
  }
188
242
 
189
- public setHeader(ctx: Context, name: string, value: string) {
190
- ctx.header(name, value);
243
+ public async setHeader(ctx: Ctx, name: string, value: string) {
244
+ if (typeof ctx === "function") {
245
+ ctx = await ctx();
246
+ }
247
+
248
+ ctx.res.headers.set(name, value);
191
249
  }
192
250
 
193
- public appendHeader?(ctx: Context, name: string, value: string) {
251
+ public async appendHeader?(ctx: Ctx, name: string, value: string) {
252
+ if (typeof ctx === "function") {
253
+ ctx = await ctx();
254
+ }
255
+
194
256
  ctx.res.headers.append(name, value);
195
257
  }
196
258
 
197
- public getRequestHostname(ctx: Context): string {
259
+ public async getRequestHostname(ctx: Ctx): Promise<string> {
260
+ if (typeof ctx === "function") {
261
+ ctx = await ctx();
262
+ }
263
+
198
264
  return ctx.req.header().host;
199
265
  }
200
266
 
@@ -264,7 +330,7 @@ export class HonoAdapter extends AbstractHttpAdapter<
264
330
  (ctx.req as any).body = await ctx.req.json();
265
331
  }
266
332
 
267
- return next();
333
+ await next();
268
334
  });
269
335
  const isHttpsEnabled = options?.httpsOptions;
270
336
  const createServer = isHttpsEnabled
@@ -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;
package/bun.lockb DELETED
Binary file