@kiyasov/platform-hono 1.1.4 → 1.1.6

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.
@@ -1,16 +1,16 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
- import { Server } from 'node:net';
4
- import { HttpBindings } from '@hono/node-server';
5
- import { RequestMethod } from '@nestjs/common';
6
- import { ErrorHandler, NestApplicationOptions, RequestHandler } from '@nestjs/common/interfaces';
7
- import { ServeStaticOptions } from '@hono/node-server/serve-static';
8
- import { AbstractHttpAdapter } from '@nestjs/core/adapters/http-adapter';
9
- import { Context, HonoRequest } from 'hono';
10
- import { Hono } from 'hono';
11
- import { RedirectStatusCode, StatusCode } from 'hono/utils/http-status';
12
- import { Http2SecureServer, Http2Server } from 'http2';
13
- import { TypeBodyParser } from '../interfaces';
3
+ import { Server } from "node:net";
4
+ import { HttpBindings } from "@hono/node-server";
5
+ import { RequestMethod } from "@nestjs/common";
6
+ import { ErrorHandler, NestApplicationOptions, RequestHandler } from "@nestjs/common/interfaces";
7
+ import { ServeStaticOptions } from "@hono/node-server/serve-static";
8
+ import { AbstractHttpAdapter } from "@nestjs/core/adapters/http-adapter";
9
+ import { Context, HonoRequest } from "hono";
10
+ import { Hono } from "hono";
11
+ import { RedirectStatusCode, StatusCode } from "hono/utils/http-status";
12
+ import { Http2SecureServer, Http2Server } from "http2";
13
+ import { TypeBodyParser } from "../interfaces";
14
14
  type HonoHandler = RequestHandler<HonoRequest, Context>;
15
15
  type ServerType = Server | Http2Server | Http2SecureServer;
16
16
  export declare class HonoAdapter extends AbstractHttpAdapter<ServerType, HonoRequest, Context> {
@@ -1,21 +1,21 @@
1
- import { createAdaptorServer } from '@hono/node-server';
2
- import { RESPONSE_ALREADY_SENT } from '@hono/node-server/utils/response';
3
- import { RequestMethod } from '@nestjs/common';
4
- import { HttpStatus, Logger } from '@nestjs/common';
5
- import { bodyLimit } from 'hono/body-limit';
6
- import { serveStatic, } from '@hono/node-server/serve-static';
7
- import { AbstractHttpAdapter } from '@nestjs/core/adapters/http-adapter';
8
- import { Hono } from 'hono';
9
- import { cors } from 'hono/cors';
10
- import * as http from 'http';
11
- import * as https from 'https';
1
+ import { createAdaptorServer } from "@hono/node-server";
2
+ import { RESPONSE_ALREADY_SENT } from "@hono/node-server/utils/response";
3
+ import { RequestMethod } from "@nestjs/common";
4
+ import { HttpStatus, Logger } from "@nestjs/common";
5
+ import { bodyLimit } from "hono/body-limit";
6
+ import { serveStatic, } from "@hono/node-server/serve-static";
7
+ import { AbstractHttpAdapter } from "@nestjs/core/adapters/http-adapter";
8
+ import { Hono } from "hono";
9
+ import { cors } from "hono/cors";
10
+ import * as http from "http";
11
+ import * as https from "https";
12
12
  export class HonoAdapter extends AbstractHttpAdapter {
13
13
  constructor() {
14
14
  super(new Hono());
15
15
  }
16
16
  getRouteAndHandler(pathOrHandler, handler) {
17
- let path = typeof pathOrHandler === 'function' ? '' : pathOrHandler;
18
- handler = typeof pathOrHandler === 'function' ? pathOrHandler : handler;
17
+ let path = typeof pathOrHandler === "function" ? "" : pathOrHandler;
18
+ handler = typeof pathOrHandler === "function" ? pathOrHandler : handler;
19
19
  return [path, handler];
20
20
  }
21
21
  createRouteHandler(routeHandler) {
@@ -25,8 +25,8 @@ export class HonoAdapter extends AbstractHttpAdapter {
25
25
  };
26
26
  }
27
27
  send(ctx) {
28
- const body = ctx.get('body');
29
- return typeof body === 'string' ? ctx.text(body) : ctx.json(body);
28
+ const body = ctx.get("body");
29
+ return typeof body === "string" ? ctx.text(body) : ctx.json(body);
30
30
  }
31
31
  get(pathOrHandler, handler) {
32
32
  const [routePath, routeHandler] = this.getRouteAndHandler(pathOrHandler, handler);
@@ -59,13 +59,13 @@ export class HonoAdapter extends AbstractHttpAdapter {
59
59
  async reply(ctx, body, statusCode) {
60
60
  if (statusCode)
61
61
  ctx.status(statusCode);
62
- const responseContentType = this.getHeader(ctx, 'Content-Type');
63
- if (!responseContentType?.startsWith('application/json') &&
62
+ const responseContentType = this.getHeader(ctx, "Content-Type");
63
+ if (!responseContentType?.startsWith("application/json") &&
64
64
  body?.statusCode >= HttpStatus.BAD_REQUEST) {
65
65
  Logger.warn("Content-Type doesn't match Reply body, you might need a custom ExceptionFilter for non-JSON responses");
66
- this.setHeader(ctx, 'Content-Type', 'application/json');
66
+ this.setHeader(ctx, "Content-Type", "application/json");
67
67
  }
68
- ctx.set('body', body);
68
+ ctx.set("body", body);
69
69
  }
70
70
  status(ctx, statusCode) {
71
71
  ctx.status(statusCode);
@@ -74,7 +74,7 @@ export class HonoAdapter extends AbstractHttpAdapter {
74
74
  return RESPONSE_ALREADY_SENT;
75
75
  }
76
76
  render(response, view, options) {
77
- throw new Error('Method not implemented.');
77
+ throw new Error("Method not implemented.");
78
78
  }
79
79
  redirect(ctx, statusCode, url) {
80
80
  ctx.redirect(url, statusCode);
@@ -92,11 +92,11 @@ export class HonoAdapter extends AbstractHttpAdapter {
92
92
  });
93
93
  }
94
94
  useStaticAssets(path, options) {
95
- Logger.log('Registering static assets middleware');
95
+ Logger.log("Registering static assets middleware");
96
96
  this.instance.use(path, serveStatic(options));
97
97
  }
98
98
  setViewEngine(options) {
99
- throw new Error('Method not implemented.');
99
+ throw new Error("Method not implemented.");
100
100
  }
101
101
  isHeadersSent(ctx) {
102
102
  return true;
@@ -123,16 +123,16 @@ export class HonoAdapter extends AbstractHttpAdapter {
123
123
  this.instance.use(cors(options));
124
124
  }
125
125
  useBodyParser(type, bodyLimit = 1e6) {
126
- Logger.log('Registering body parser middleware');
126
+ Logger.log("Registering body parser middleware");
127
127
  this.instance.use(this.bodyLimit(bodyLimit), async (ctx, next) => {
128
- const contentType = ctx.req.header('content-type');
128
+ const contentType = ctx.req.header("content-type");
129
129
  switch (type) {
130
- case 'application/json':
131
- if (contentType === 'application/json')
130
+ case "application/json":
131
+ if (contentType === "application/json")
132
132
  ctx.req.body = await ctx.req.json();
133
133
  break;
134
- case 'text/plain':
135
- if (contentType === 'text/plain') {
134
+ case "text/plain":
135
+ if (contentType === "text/plain") {
136
136
  ctx.req.rawBody = Buffer.from(await ctx.req.text());
137
137
  ctx.req.body = await ctx.req.json();
138
138
  }
@@ -159,13 +159,13 @@ export class HonoAdapter extends AbstractHttpAdapter {
159
159
  });
160
160
  }
161
161
  getType() {
162
- return 'hono';
162
+ return "hono";
163
163
  }
164
164
  registerParserMiddleware(prefix, rawBody) {
165
- Logger.log('Registering parser middleware');
166
- this.useBodyParser('application/x-www-form-urlencoded');
167
- this.useBodyParser('application/json');
168
- this.useBodyParser('text/plain');
165
+ Logger.log("Registering parser middleware");
166
+ this.useBodyParser("application/x-www-form-urlencoded");
167
+ this.useBodyParser("application/json");
168
+ this.useBodyParser("text/plain");
169
169
  }
170
170
  async createMiddlewareFactory(requestMethod) {
171
171
  return (path, callback) => {
@@ -185,7 +185,7 @@ export class HonoAdapter extends AbstractHttpAdapter {
185
185
  };
186
186
  }
187
187
  applyVersionFilter() {
188
- throw new Error('Versioning not yet supported in Hono');
188
+ throw new Error("Versioning not yet supported in Hono");
189
189
  }
190
190
  listen(port, ...args) {
191
191
  return this.httpServer.listen(port, ...args);
@@ -194,7 +194,7 @@ export class HonoAdapter extends AbstractHttpAdapter {
194
194
  return bodyLimit({
195
195
  maxSize,
196
196
  onError: () => {
197
- throw new Error('Body too large');
197
+ throw new Error("Body too large");
198
198
  },
199
199
  });
200
200
  }
@@ -2,7 +2,6 @@ import { BadRequestException } from "@nestjs/common";
2
2
  export const getMultipartRequest = (ctx) => {
3
3
  const req = ctx.getRequest();
4
4
  if (!req.header("content-type")?.startsWith("multipart/form-data")) {
5
- throw new BadRequestException("Not a multipart request");
6
5
  }
7
6
  return req;
8
7
  };
@@ -1 +1 @@
1
- {"version":3,"file":"request.js","sourceRoot":"","sources":["../../../../../src/multer/multipart/request.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAerD,MAAM,CAAC,MAAM,mBAAmB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