hono 4.9.7 → 4.9.8

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.
@@ -44,14 +44,14 @@ class HonoRequest {
44
44
  #getDecodedParam(key) {
45
45
  const paramKey = this.#matchResult[0][this.routeIndex][1][key];
46
46
  const param = this.#getParamValue(paramKey);
47
- return param ? /\%/.test(param) ? tryDecodeURIComponent(param) : param : void 0;
47
+ return param && /\%/.test(param) ? tryDecodeURIComponent(param) : param;
48
48
  }
49
49
  #getAllDecodedParams() {
50
50
  const decoded = {};
51
51
  const keys = Object.keys(this.#matchResult[0][this.routeIndex][1]);
52
52
  for (const key of keys) {
53
53
  const value = this.#getParamValue(this.#matchResult[0][this.routeIndex][1][key]);
54
- if (value && typeof value === "string") {
54
+ if (value !== void 0) {
55
55
  decoded[key] = /\%/.test(value) ? tryDecodeURIComponent(value) : value;
56
56
  }
57
57
  }
package/dist/request.js CHANGED
@@ -22,14 +22,14 @@ var HonoRequest = class {
22
22
  #getDecodedParam(key) {
23
23
  const paramKey = this.#matchResult[0][this.routeIndex][1][key];
24
24
  const param = this.#getParamValue(paramKey);
25
- return param ? /\%/.test(param) ? tryDecodeURIComponent(param) : param : void 0;
25
+ return param && /\%/.test(param) ? tryDecodeURIComponent(param) : param;
26
26
  }
27
27
  #getAllDecodedParams() {
28
28
  const decoded = {};
29
29
  const keys = Object.keys(this.#matchResult[0][this.routeIndex][1]);
30
30
  for (const key of keys) {
31
31
  const value = this.#getParamValue(this.#matchResult[0][this.routeIndex][1][key]);
32
- if (value && typeof value === "string") {
32
+ if (value !== void 0) {
33
33
  decoded[key] = /\%/.test(value) ? tryDecodeURIComponent(value) : value;
34
34
  }
35
35
  }
@@ -4,7 +4,7 @@ import type { Env, FetchEventLike, H, Input, NotFoundHandler, RouterRoute, Typed
4
4
  import type { ResponseHeader } from './utils/headers';
5
5
  import type { ContentfulStatusCode, RedirectStatusCode, StatusCode } from './utils/http-status';
6
6
  import type { BaseMime } from './utils/mime';
7
- import type { InvalidJSONValue, IsAny, JSONParsed, JSONValue, SimplifyDeepArray } from './utils/types';
7
+ import type { InvalidJSONValue, IsAny, JSONParsed, JSONValue } from './utils/types';
8
8
  type HeaderRecord = Record<"Content-Type", BaseMime> | Record<ResponseHeader, string | string[]> | Record<string, string | string[]>;
9
9
  /**
10
10
  * Data type can be a string, ArrayBuffer, Uint8Array (buffer), or ReadableStream.
@@ -128,16 +128,16 @@ interface TextRespond {
128
128
  * @returns {JSONRespondReturn<T, U>} - The response after rendering the JSON object, typed with the provided object and status code types.
129
129
  */
130
130
  interface JSONRespond {
131
- <T extends JSONValue | SimplifyDeepArray<unknown> | InvalidJSONValue, U extends ContentfulStatusCode = ContentfulStatusCode>(object: T, status?: U, headers?: HeaderRecord): JSONRespondReturn<T, U>;
132
- <T extends JSONValue | SimplifyDeepArray<unknown> | InvalidJSONValue, U extends ContentfulStatusCode = ContentfulStatusCode>(object: T, init?: ResponseOrInit<U>): JSONRespondReturn<T, U>;
131
+ <T extends JSONValue | {} | InvalidJSONValue, U extends ContentfulStatusCode = ContentfulStatusCode>(object: T, status?: U, headers?: HeaderRecord): JSONRespondReturn<T, U>;
132
+ <T extends JSONValue | {} | InvalidJSONValue, U extends ContentfulStatusCode = ContentfulStatusCode>(object: T, init?: ResponseOrInit<U>): JSONRespondReturn<T, U>;
133
133
  }
134
134
  /**
135
135
  * @template T - The type of the JSON value or simplified unknown type.
136
136
  * @template U - The type of the status code.
137
137
  *
138
- * @returns {Response & TypedResponse<SimplifyDeepArray<T> extends JSONValue ? (JSONValue extends SimplifyDeepArray<T> ? never : JSONParsed<T>) : never, U, 'json'>} - The response after rendering the JSON object, typed with the provided object and status code types.
138
+ * @returns {Response & TypedResponse<JSONParsed<T>, U, 'json'>} - The response after rendering the JSON object, typed with the provided object and status code types.
139
139
  */
140
- type JSONRespondReturn<T extends JSONValue | SimplifyDeepArray<unknown> | InvalidJSONValue, U extends ContentfulStatusCode> = Response & TypedResponse<SimplifyDeepArray<T> extends JSONValue ? JSONValue extends SimplifyDeepArray<T> ? never : JSONParsed<T> : never, U, "json">;
140
+ export type JSONRespondReturn<T extends JSONValue | {} | InvalidJSONValue, U extends ContentfulStatusCode> = Response & TypedResponse<JSONParsed<T>, U, "json">;
141
141
  /**
142
142
  * Interface representing a function that responds with HTML content.
143
143
  *
@@ -23,15 +23,28 @@ type OmitSymbolKeys<T> = {
23
23
  [K in keyof T as K extends symbol ? never : K]: T[K];
24
24
  };
25
25
  export type JSONValue = JSONObject | JSONArray | JSONPrimitive;
26
- export type JSONParsed<T> = T extends {
26
+ /**
27
+ * Convert a type to a JSON-compatible type.
28
+ *
29
+ * Non-JSON values such as `Date` implement `.toJSON()`,
30
+ * so they can be transformed to a value assignable to `JSONObject`
31
+ *
32
+ * `JSON.stringify()` throws a `TypeError` when it encounters a `bigint` value,
33
+ * unless a custom `replacer` function or `.toJSON()` method is provided.
34
+ *
35
+ * This behaviour can be controlled by the `TError` generic type parameter,
36
+ * which defaults to `bigint | ReadonlyArray<bigint>`.
37
+ * You can set it to `never` to disable this check.
38
+ */
39
+ export type JSONParsed<T, TError = bigint | ReadonlyArray<bigint>> = T extends TError ? never : T extends {
27
40
  toJSON(): infer J;
28
41
  } ? (() => J) extends () => JSONPrimitive ? J : (() => J) extends () => {
29
42
  toJSON(): unknown;
30
- } ? {} : JSONParsed<J> : T extends JSONPrimitive ? T : T extends InvalidJSONValue ? never : T extends ReadonlyArray<unknown> ? {
31
- [K in keyof T]: JSONParsed<InvalidToNull<T[K]>>;
32
- } : T extends Set<unknown> | Map<unknown, unknown> ? {} : T extends object ? {
33
- [K in keyof OmitSymbolKeys<T> as IsInvalid<T[K]> extends true ? never : K]: boolean extends IsInvalid<T[K]> ? JSONParsed<T[K]> | undefined : JSONParsed<T[K]>;
34
- } : never;
43
+ } ? {} : JSONParsed<J, TError> : T extends JSONPrimitive ? T : T extends InvalidJSONValue ? never : T extends ReadonlyArray<unknown> ? {
44
+ [K in keyof T]: JSONParsed<InvalidToNull<T[K]>, TError>;
45
+ } : T extends Set<unknown> | Map<unknown, unknown> | Record<string, never> ? {} : T extends object ? T[keyof T] extends TError ? never : {
46
+ [K in keyof OmitSymbolKeys<T> as IsInvalid<T[K]> extends true ? never : K]: boolean extends IsInvalid<T[K]> ? JSONParsed<T[K], TError> | undefined : JSONParsed<T[K], TError>;
47
+ } : T extends unknown ? JSONValue : never;
35
48
  /**
36
49
  * Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
37
50
  * @copyright from sindresorhus/type-fest
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono",
3
- "version": "4.9.7",
3
+ "version": "4.9.8",
4
4
  "description": "Web framework built on Web Standards",
5
5
  "main": "dist/cjs/index.js",
6
6
  "type": "module",