@kiyasov/platform-hono 1.3.10 → 1.3.11

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.10",
3
+ "version": "1.3.11",
4
4
  "description": "Nest adapter for Hono",
5
5
  "author": "Islam Kiiasov",
6
6
  "repository": {
@@ -126,7 +126,7 @@ export class HonoAdapter extends AbstractHttpAdapter<
126
126
  public async reply(ctx: Context, body: any, statusCode?: StatusCode) {
127
127
  if (statusCode) ctx.status(statusCode);
128
128
 
129
- const responseContentType = await this.getHeader(ctx, "Content-Type");
129
+ const responseContentType = this.getHeader(ctx, "Content-Type");
130
130
  if (
131
131
  !responseContentType?.startsWith("application/json") &&
132
132
  body?.statusCode >= HttpStatus.BAD_REQUEST
@@ -139,19 +139,8 @@ export class HonoAdapter extends AbstractHttpAdapter<
139
139
  ctx.set("body", body);
140
140
  }
141
141
 
142
- public async status(
143
- ctx: Context | (() => Promise<Context>),
144
- statusCode: StatusCode
145
- ) {
146
- if (typeof ctx === "function") {
147
- ctx = await ctx();
148
- }
149
-
150
- if (ctx && typeof ctx.status === "function") {
151
- ctx.status(statusCode);
152
- } else {
153
- throw new Error("Invalid context: status method not found.");
154
- }
142
+ public status(ctx: Context, statusCode: StatusCode) {
143
+ ctx.status(statusCode);
155
144
  }
156
145
 
157
146
  public async end() {
@@ -162,20 +151,8 @@ export class HonoAdapter extends AbstractHttpAdapter<
162
151
  throw new Error("Method not implemented.");
163
152
  }
164
153
 
165
- public async redirect(
166
- ctx: Context | (() => Promise<Context>),
167
- statusCode: RedirectStatusCode,
168
- url: string
169
- ) {
170
- if (typeof ctx === "function") {
171
- ctx = await ctx();
172
- }
173
-
174
- if (ctx && typeof ctx.redirect === "function") {
175
- ctx.redirect(url, statusCode);
176
- } else {
177
- throw new Error("Invalid context: redirect method not found.");
178
- }
154
+ public redirect(ctx: Context, statusCode: RedirectStatusCode, url: string) {
155
+ ctx.redirect(url, statusCode);
179
156
  }
180
157
 
181
158
  public setErrorHandler(handler: ErrorHandler) {
@@ -205,63 +182,20 @@ export class HonoAdapter extends AbstractHttpAdapter<
205
182
  return true;
206
183
  }
207
184
 
208
- public async getHeader?(
209
- ctx: Context | (() => Promise<Context>),
210
- name: string
211
- ) {
212
- if (typeof ctx === "function") {
213
- ctx = await ctx();
214
- }
215
-
216
- if (ctx && typeof ctx.req.header === "function") {
217
- return ctx.req.header(name);
218
- } else {
219
- throw new Error("Invalid context: get method not found on context.");
220
- }
185
+ public getHeader?(ctx: Context, name: string) {
186
+ return ctx.req.header(name);
221
187
  }
222
188
 
223
- public async setHeader(
224
- ctx: Context | (() => Promise<Context>),
225
- name: string,
226
- value: string
227
- ) {
228
- if (typeof ctx === "function") {
229
- ctx = await ctx();
230
- }
231
-
232
- if (ctx && typeof ctx.header === "function") {
233
- ctx.header(name, value);
234
- } else {
235
- throw new Error("Invalid context: set method not found on context.");
236
- }
189
+ public setHeader(ctx: Context, name: string, value: string) {
190
+ ctx.header(name, value);
237
191
  }
238
192
 
239
- public async appendHeader?(
240
- ctx: Context | (() => Promise<Context>),
241
- name: string,
242
- value: string
243
- ) {
244
- if (typeof ctx === "function") {
245
- ctx = await ctx();
246
- }
247
-
248
- if (ctx && typeof ctx.res.headers.append === "function") {
249
- ctx.res.headers.append(name, value);
250
- } else {
251
- throw new Error("Invalid context: append method not found on context.");
252
- }
193
+ public appendHeader?(ctx: Context, name: string, value: string) {
194
+ ctx.res.headers.append(name, value);
253
195
  }
254
196
 
255
- public async getRequestHostname(ctx: Context | (() => Promise<Context>)) {
256
- if (typeof ctx === "function") {
257
- ctx = await ctx();
258
- }
259
-
260
- if (ctx && typeof ctx.req.header === "function") {
261
- return ctx.req.header("host");
262
- } else {
263
- throw new Error("Invalid context: get method not found on context.");
264
- }
197
+ public getRequestHostname(ctx: Context): string {
198
+ return ctx.req.header().host;
265
199
  }
266
200
 
267
201
  public getRequestMethod(request: HonoRequest): string {