hono 4.6.5 → 4.6.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,6 +1,6 @@
1
1
  // src/adapter/deno/serve-static.ts
2
2
  import { serveStatic as baseServeStatic } from "../../middleware/serve-static/index.js";
3
- var { open, lstatSync } = Deno;
3
+ var { open, lstatSync, errors } = Deno;
4
4
  var serveStatic = (options) => {
5
5
  return async function serveStatic2(c, next) {
6
6
  const getContent = async (path) => {
@@ -8,7 +8,9 @@ var serveStatic = (options) => {
8
8
  const file = await open(path);
9
9
  return file ? file.readable : null;
10
10
  } catch (e) {
11
- console.warn(`${e}`);
11
+ if (!(e instanceof errors.NotFound)) {
12
+ console.warn(`${e}`);
13
+ }
12
14
  }
13
15
  };
14
16
  const pathResolve = (path) => {
@@ -22,7 +22,7 @@ __export(serve_static_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(serve_static_exports);
24
24
  var import_serve_static = require("../../middleware/serve-static");
25
- const { open, lstatSync } = Deno;
25
+ const { open, lstatSync, errors } = Deno;
26
26
  const serveStatic = (options) => {
27
27
  return async function serveStatic2(c, next) {
28
28
  const getContent = async (path) => {
@@ -30,7 +30,9 @@ const serveStatic = (options) => {
30
30
  const file = await open(path);
31
31
  return file ? file.readable : null;
32
32
  } catch (e) {
33
- console.warn(`${e}`);
33
+ if (!(e instanceof errors.NotFound)) {
34
+ console.warn(`${e}`);
35
+ }
34
36
  }
35
37
  };
36
38
  const pathResolve = (path) => {
@@ -55,19 +55,7 @@ class ClientRequestImpl {
55
55
  fetch = async (args, opt) => {
56
56
  if (args) {
57
57
  if (args.query) {
58
- for (const [k, v] of Object.entries(args.query)) {
59
- if (v === void 0) {
60
- continue;
61
- }
62
- this.queryParams ||= new URLSearchParams();
63
- if (Array.isArray(v)) {
64
- for (const v2 of v) {
65
- this.queryParams.append(k, v2);
66
- }
67
- } else {
68
- this.queryParams.set(k, v);
69
- }
70
- }
58
+ this.queryParams = (0, import_utils.buildSearchParams)(args.query);
71
59
  }
72
60
  if (args.form) {
73
61
  const form = new FormData();
@@ -146,10 +134,16 @@ const hc = (baseUrl, options) => createProxy(function proxyCallback(opts) {
146
134
  const path = parts.join("/");
147
135
  const url = (0, import_utils.mergePath)(baseUrl, path);
148
136
  if (method === "url") {
149
- if (opts.args[0] && opts.args[0].param) {
150
- return new URL((0, import_utils.replaceUrlParam)(url, opts.args[0].param));
137
+ let result = url;
138
+ if (opts.args[0]) {
139
+ if (opts.args[0].param) {
140
+ result = (0, import_utils.replaceUrlParam)(url, opts.args[0].param);
141
+ }
142
+ if (opts.args[0].query) {
143
+ result = result + "?" + (0, import_utils.buildSearchParams)(opts.args[0].query).toString();
144
+ }
151
145
  }
152
- return new URL(url);
146
+ return new URL(result);
153
147
  }
154
148
  if (method === "ws") {
155
149
  const webSocketUrl = (0, import_utils.replaceUrlProtocol)(
@@ -18,6 +18,7 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var utils_exports = {};
20
20
  __export(utils_exports, {
21
+ buildSearchParams: () => buildSearchParams,
21
22
  deepMerge: () => deepMerge,
22
23
  mergePath: () => mergePath,
23
24
  removeIndexString: () => removeIndexString,
@@ -38,6 +39,22 @@ const replaceUrlParam = (urlString, params) => {
38
39
  }
39
40
  return urlString;
40
41
  };
42
+ const buildSearchParams = (query) => {
43
+ const searchParams = new URLSearchParams();
44
+ for (const [k, v] of Object.entries(query)) {
45
+ if (v === void 0) {
46
+ continue;
47
+ }
48
+ if (Array.isArray(v)) {
49
+ for (const v2 of v) {
50
+ searchParams.append(k, v2);
51
+ }
52
+ } else {
53
+ searchParams.set(k, v);
54
+ }
55
+ }
56
+ return searchParams;
57
+ };
41
58
  const replaceUrlProtocol = (urlString, protocol) => {
42
59
  switch (protocol) {
43
60
  case "ws":
@@ -72,6 +89,7 @@ function deepMerge(target, source) {
72
89
  }
73
90
  // Annotate the CommonJS export names for ESM import in node:
74
91
  0 && (module.exports = {
92
+ buildSearchParams,
75
93
  deepMerge,
76
94
  mergePath,
77
95
  removeIndexString,
@@ -59,11 +59,12 @@ const generateNonce = () => {
59
59
  return (0, import_encode.encodeBase64)(buffer);
60
60
  };
61
61
  const NONCE = (ctx) => {
62
- const nonce = ctx.get("secureHeadersNonce") || (() => {
63
- const newNonce = generateNonce();
64
- ctx.set("secureHeadersNonce", newNonce);
65
- return newNonce;
66
- })();
62
+ const key = "secureHeadersNonce";
63
+ const init = ctx.get(key);
64
+ const nonce = init || generateNonce();
65
+ if (init == null) {
66
+ ctx.set(key, nonce);
67
+ }
67
68
  return `'nonce-${nonce}'`;
68
69
  };
69
70
  const secureHeaders = (customOptions) => {
@@ -1,6 +1,7 @@
1
1
  // src/client/client.ts
2
2
  import { serialize } from "../utils/cookie.js";
3
3
  import {
4
+ buildSearchParams,
4
5
  deepMerge,
5
6
  mergePath,
6
7
  removeIndexString,
@@ -39,19 +40,7 @@ var ClientRequestImpl = class {
39
40
  fetch = async (args, opt) => {
40
41
  if (args) {
41
42
  if (args.query) {
42
- for (const [k, v] of Object.entries(args.query)) {
43
- if (v === void 0) {
44
- continue;
45
- }
46
- this.queryParams ||= new URLSearchParams();
47
- if (Array.isArray(v)) {
48
- for (const v2 of v) {
49
- this.queryParams.append(k, v2);
50
- }
51
- } else {
52
- this.queryParams.set(k, v);
53
- }
54
- }
43
+ this.queryParams = buildSearchParams(args.query);
55
44
  }
56
45
  if (args.form) {
57
46
  const form = new FormData();
@@ -130,10 +119,16 @@ var hc = (baseUrl, options) => createProxy(function proxyCallback(opts) {
130
119
  const path = parts.join("/");
131
120
  const url = mergePath(baseUrl, path);
132
121
  if (method === "url") {
133
- if (opts.args[0] && opts.args[0].param) {
134
- return new URL(replaceUrlParam(url, opts.args[0].param));
122
+ let result = url;
123
+ if (opts.args[0]) {
124
+ if (opts.args[0].param) {
125
+ result = replaceUrlParam(url, opts.args[0].param);
126
+ }
127
+ if (opts.args[0].query) {
128
+ result = result + "?" + buildSearchParams(opts.args[0].query).toString();
129
+ }
135
130
  }
136
- return new URL(url);
131
+ return new URL(result);
137
132
  }
138
133
  if (method === "ws") {
139
134
  const webSocketUrl = replaceUrlProtocol(
@@ -12,6 +12,22 @@ var replaceUrlParam = (urlString, params) => {
12
12
  }
13
13
  return urlString;
14
14
  };
15
+ var buildSearchParams = (query) => {
16
+ const searchParams = new URLSearchParams();
17
+ for (const [k, v] of Object.entries(query)) {
18
+ if (v === void 0) {
19
+ continue;
20
+ }
21
+ if (Array.isArray(v)) {
22
+ for (const v2 of v) {
23
+ searchParams.append(k, v2);
24
+ }
25
+ } else {
26
+ searchParams.set(k, v);
27
+ }
28
+ }
29
+ return searchParams;
30
+ };
15
31
  var replaceUrlProtocol = (urlString, protocol) => {
16
32
  switch (protocol) {
17
33
  case "ws":
@@ -45,6 +61,7 @@ function deepMerge(target, source) {
45
61
  return merged;
46
62
  }
47
63
  export {
64
+ buildSearchParams,
48
65
  deepMerge,
49
66
  mergePath,
50
67
  removeIndexString,
@@ -36,11 +36,12 @@ var generateNonce = () => {
36
36
  return encodeBase64(buffer);
37
37
  };
38
38
  var NONCE = (ctx) => {
39
- const nonce = ctx.get("secureHeadersNonce") || (() => {
40
- const newNonce = generateNonce();
41
- ctx.set("secureHeadersNonce", newNonce);
42
- return newNonce;
43
- })();
39
+ const key = "secureHeadersNonce";
40
+ const init = ctx.get(key);
41
+ const nonce = init || generateNonce();
42
+ if (init == null) {
43
+ ctx.set(key, nonce);
44
+ }
44
45
  return `'nonce-${nonce}'`;
45
46
  };
46
47
  var secureHeaders = (customOptions) => {
@@ -28,8 +28,17 @@ export type ClientRequest<S extends Schema> = {
28
28
  input: infer R;
29
29
  } ? R extends {
30
30
  param: infer P;
31
+ } ? R extends {
32
+ query: infer Q;
31
33
  } ? {
32
34
  param: P;
35
+ query: Q;
36
+ } : {
37
+ param: P;
38
+ } : R extends {
39
+ query: infer Q;
40
+ } ? {
41
+ query: Q;
33
42
  } : {} : {}) => URL;
34
43
  } & (S["$get"] extends {
35
44
  outputFormat: "ws";
@@ -1,5 +1,6 @@
1
1
  export declare const mergePath: (base: string, path: string) => string;
2
2
  export declare const replaceUrlParam: (urlString: string, params: Record<string, string | undefined>) => string;
3
+ export declare const buildSearchParams: (query: Record<string, string | string[]>) => URLSearchParams;
3
4
  export declare const replaceUrlProtocol: (urlString: string, protocol: "ws" | "http") => string;
4
5
  export declare const removeIndexString: (urlSting: string) => string;
5
6
  export declare function deepMerge<T>(target: T, source: Record<string, unknown>): T;
@@ -4,7 +4,26 @@
4
4
  */
5
5
  import type { MiddlewareHandler } from '../../types';
6
6
  type PoweredByOptions = {
7
+ /**
8
+ * The value for X-Powered-By header.
9
+ * @default Hono
10
+ */
7
11
  serverName?: string;
8
12
  };
13
+ /**
14
+ * Powered By Middleware for Hono.
15
+ *
16
+ * @param options - The options for the Powered By Middleware.
17
+ * @returns {MiddlewareHandler} The middleware handler function.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * import { poweredBy } from 'hono/powered-by'
22
+ *
23
+ * const app = new Hono()
24
+ *
25
+ * app.use(poweredBy()) // With options: poweredBy({ serverName: "My Server" })
26
+ * ```
27
+ */
9
28
  export declare const poweredBy: (options?: PoweredByOptions) => MiddlewareHandler;
10
29
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono",
3
- "version": "4.6.5",
3
+ "version": "4.6.6",
4
4
  "description": "Web framework built on Web Standards",
5
5
  "main": "dist/cjs/index.js",
6
6
  "type": "module",