hono 4.2.3 → 4.2.4

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/cloudflare-workers/utils.ts
2
2
  var getContentFromKVAsset = async (path, options) => {
3
- let ASSET_MANIFEST = {};
3
+ let ASSET_MANIFEST;
4
4
  if (options && options.manifest) {
5
5
  if (typeof options.manifest === "string") {
6
6
  ASSET_MANIFEST = JSON.parse(options.manifest);
@@ -22,7 +22,7 @@ __export(utils_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(utils_exports);
24
24
  const getContentFromKVAsset = async (path, options) => {
25
- let ASSET_MANIFEST = {};
25
+ let ASSET_MANIFEST;
26
26
  if (options && options.manifest) {
27
27
  if (typeof options.manifest === "string") {
28
28
  ASSET_MANIFEST = JSON.parse(options.manifest);
@@ -85,7 +85,6 @@ class ClientRequestImpl {
85
85
  }
86
86
  }
87
87
  let methodUpperCase = this.method.toUpperCase();
88
- let setBody = !(methodUpperCase === "GET" || methodUpperCase === "HEAD");
89
88
  const headerValues = {
90
89
  ...args?.header ?? {},
91
90
  ...typeof opt?.headers === "function" ? await opt.headers() : opt?.headers ? opt.headers : {}
@@ -108,7 +107,7 @@ class ClientRequestImpl {
108
107
  url = url + "?" + this.queryParams.toString();
109
108
  }
110
109
  methodUpperCase = this.method.toUpperCase();
111
- setBody = !(methodUpperCase === "GET" || methodUpperCase === "HEAD");
110
+ const setBody = !(methodUpperCase === "GET" || methodUpperCase === "HEAD");
112
111
  return (opt?.fetch || fetch)(url, {
113
112
  body: setBody ? this.rBody : void 0,
114
113
  method: methodUpperCase,
@@ -165,7 +165,7 @@ const saveContentToFile = async (data, fsModule, outDir, extensionMap) => {
165
165
  return filePath;
166
166
  };
167
167
  const toSSG = async (app, fs, options) => {
168
- let result = void 0;
168
+ let result;
169
169
  const getInfoPromises = [];
170
170
  const savePromises = [];
171
171
  try {
@@ -26,7 +26,7 @@ const testClient = (app, Env, executionCtx) => {
26
26
  const customFetch = (input, init) => {
27
27
  return app.request(input, init, Env, executionCtx);
28
28
  };
29
- return (0, import_client.hc)("", { fetch: customFetch });
29
+ return (0, import_client.hc)("http://localhost", { fetch: customFetch });
30
30
  };
31
31
  // Annotate the CommonJS export names for ESM import in node:
32
32
  0 && (module.exports = {
@@ -110,36 +110,46 @@ d.replaceWith(c.content)
110
110
  };
111
111
  Suspense[import_constants.DOM_RENDERER] = import_components2.Suspense;
112
112
  const textEncoder = new TextEncoder();
113
- const renderToReadableStream = (str) => {
113
+ const renderToReadableStream = (str, onError = console.trace) => {
114
114
  const reader = new ReadableStream({
115
115
  async start(controller) {
116
- const tmp = str instanceof Promise ? await str : await str.toString();
117
- const context = typeof tmp === "object" ? tmp : {};
118
- const resolved = await (0, import_html2.resolveCallback)(
119
- tmp,
120
- import_html2.HtmlEscapedCallbackPhase.BeforeStream,
121
- true,
122
- context
123
- );
124
- controller.enqueue(textEncoder.encode(resolved));
125
- let resolvedCount = 0;
126
- const callbacks = [];
127
- const then = (promise) => {
128
- callbacks.push(
129
- promise.catch((err) => {
130
- console.trace(err);
131
- return "";
132
- }).then(async (res) => {
133
- res = await (0, import_html2.resolveCallback)(res, import_html2.HtmlEscapedCallbackPhase.BeforeStream, true, context);
134
- res.callbacks?.map((c) => c({ phase: import_html2.HtmlEscapedCallbackPhase.Stream, context })).filter(Boolean).forEach(then);
135
- resolvedCount++;
136
- controller.enqueue(textEncoder.encode(res));
137
- })
116
+ try {
117
+ const tmp = str instanceof Promise ? await str : await str.toString();
118
+ const context = typeof tmp === "object" ? tmp : {};
119
+ const resolved = await (0, import_html2.resolveCallback)(
120
+ tmp,
121
+ import_html2.HtmlEscapedCallbackPhase.BeforeStream,
122
+ true,
123
+ context
138
124
  );
139
- };
140
- resolved.callbacks?.map((c) => c({ phase: import_html2.HtmlEscapedCallbackPhase.Stream, context })).filter(Boolean).forEach(then);
141
- while (resolvedCount !== callbacks.length) {
142
- await Promise.all(callbacks);
125
+ controller.enqueue(textEncoder.encode(resolved));
126
+ let resolvedCount = 0;
127
+ const callbacks = [];
128
+ const then = (promise) => {
129
+ callbacks.push(
130
+ promise.catch((err) => {
131
+ console.log(err);
132
+ onError(err);
133
+ return "";
134
+ }).then(async (res) => {
135
+ res = await (0, import_html2.resolveCallback)(
136
+ res,
137
+ import_html2.HtmlEscapedCallbackPhase.BeforeStream,
138
+ true,
139
+ context
140
+ );
141
+ res.callbacks?.map((c) => c({ phase: import_html2.HtmlEscapedCallbackPhase.Stream, context })).filter(Boolean).forEach(then);
142
+ resolvedCount++;
143
+ controller.enqueue(textEncoder.encode(res));
144
+ })
145
+ );
146
+ };
147
+ resolved.callbacks?.map((c) => c({ phase: import_html2.HtmlEscapedCallbackPhase.Stream, context })).filter(Boolean).forEach(then);
148
+ while (resolvedCount !== callbacks.length) {
149
+ await Promise.all(callbacks);
150
+ }
151
+ } catch (e) {
152
+ onError(e);
143
153
  }
144
154
  controller.close();
145
155
  }
@@ -62,7 +62,7 @@ const serveStatic = (options) => {
62
62
  }
63
63
  }
64
64
  if (content) {
65
- let mimeType = void 0;
65
+ let mimeType;
66
66
  if (options.mimes) {
67
67
  mimeType = (0, import_mime.getMimeType)(path, options.mimes) ?? (0, import_mime.getMimeType)(path);
68
68
  } else {
@@ -47,11 +47,9 @@ class Node {
47
47
  let curNode = this;
48
48
  const parts = (0, import_url.splitRoutingPath)(path);
49
49
  const possibleKeys = [];
50
- const parentPatterns = [];
51
50
  for (let i = 0, len = parts.length; i < len; i++) {
52
51
  const p = parts[i];
53
52
  if (Object.keys(curNode.children).includes(p)) {
54
- parentPatterns.push(...curNode.patterns);
55
53
  curNode = curNode.children[p];
56
54
  const pattern2 = (0, import_url.getPattern)(p);
57
55
  if (pattern2) {
@@ -63,10 +61,8 @@ class Node {
63
61
  const pattern = (0, import_url.getPattern)(p);
64
62
  if (pattern) {
65
63
  curNode.patterns.push(pattern);
66
- parentPatterns.push(...curNode.patterns);
67
64
  possibleKeys.push(pattern[1]);
68
65
  }
69
- parentPatterns.push(...curNode.patterns);
70
66
  curNode = curNode.children[p];
71
67
  }
72
68
  if (!curNode.methods.length) {
@@ -34,7 +34,7 @@ const encodeJwtPart = (part) => (0, import_encode.encodeBase64Url)(import_utf8.u
34
34
  const encodeSignaturePart = (buf) => (0, import_encode.encodeBase64Url)(buf).replace(/=/g, "");
35
35
  const decodeJwtPart = (part) => JSON.parse(import_utf8.utf8Decoder.decode((0, import_encode.decodeBase64Url)(part)));
36
36
  function isTokenHeader(obj) {
37
- return typeof obj === "object" && obj !== null && "alg" in obj && Object.values(import_jwa.AlgorithmTypes).includes(obj.alg) && "typ" in obj && obj.typ === "JWT";
37
+ return typeof obj === "object" && obj !== null && "alg" in obj && Object.values(import_jwa.AlgorithmTypes).includes(obj.alg) && (!("typ" in obj) || obj.typ === "JWT");
38
38
  }
39
39
  const sign = async (payload, privateKey, alg = "HS256") => {
40
40
  const encodedPayload = encodeJwtPart(payload);
@@ -69,7 +69,6 @@ var ClientRequestImpl = class {
69
69
  }
70
70
  }
71
71
  let methodUpperCase = this.method.toUpperCase();
72
- let setBody = !(methodUpperCase === "GET" || methodUpperCase === "HEAD");
73
72
  const headerValues = {
74
73
  ...args?.header ?? {},
75
74
  ...typeof opt?.headers === "function" ? await opt.headers() : opt?.headers ? opt.headers : {}
@@ -92,7 +91,7 @@ var ClientRequestImpl = class {
92
91
  url = url + "?" + this.queryParams.toString();
93
92
  }
94
93
  methodUpperCase = this.method.toUpperCase();
95
- setBody = !(methodUpperCase === "GET" || methodUpperCase === "HEAD");
94
+ const setBody = !(methodUpperCase === "GET" || methodUpperCase === "HEAD");
96
95
  return (opt?.fetch || fetch)(url, {
97
96
  body: setBody ? this.rBody : void 0,
98
97
  method: methodUpperCase,
@@ -140,7 +140,7 @@ var saveContentToFile = async (data, fsModule, outDir, extensionMap) => {
140
140
  return filePath;
141
141
  };
142
142
  var toSSG = async (app, fs, options) => {
143
- let result = void 0;
143
+ let result;
144
144
  const getInfoPromises = [];
145
145
  const savePromises = [];
146
146
  try {
@@ -4,7 +4,7 @@ var testClient = (app, Env, executionCtx) => {
4
4
  const customFetch = (input, init) => {
5
5
  return app.request(input, init, Env, executionCtx);
6
6
  };
7
- return hc("", { fetch: customFetch });
7
+ return hc("http://localhost", { fetch: customFetch });
8
8
  };
9
9
  export {
10
10
  testClient
@@ -87,36 +87,46 @@ d.replaceWith(c.content)
87
87
  };
88
88
  Suspense[DOM_RENDERER] = SuspenseDomRenderer;
89
89
  var textEncoder = new TextEncoder();
90
- var renderToReadableStream = (str) => {
90
+ var renderToReadableStream = (str, onError = console.trace) => {
91
91
  const reader = new ReadableStream({
92
92
  async start(controller) {
93
- const tmp = str instanceof Promise ? await str : await str.toString();
94
- const context = typeof tmp === "object" ? tmp : {};
95
- const resolved = await resolveCallback(
96
- tmp,
97
- HtmlEscapedCallbackPhase.BeforeStream,
98
- true,
99
- context
100
- );
101
- controller.enqueue(textEncoder.encode(resolved));
102
- let resolvedCount = 0;
103
- const callbacks = [];
104
- const then = (promise) => {
105
- callbacks.push(
106
- promise.catch((err) => {
107
- console.trace(err);
108
- return "";
109
- }).then(async (res) => {
110
- res = await resolveCallback(res, HtmlEscapedCallbackPhase.BeforeStream, true, context);
111
- res.callbacks?.map((c) => c({ phase: HtmlEscapedCallbackPhase.Stream, context })).filter(Boolean).forEach(then);
112
- resolvedCount++;
113
- controller.enqueue(textEncoder.encode(res));
114
- })
93
+ try {
94
+ const tmp = str instanceof Promise ? await str : await str.toString();
95
+ const context = typeof tmp === "object" ? tmp : {};
96
+ const resolved = await resolveCallback(
97
+ tmp,
98
+ HtmlEscapedCallbackPhase.BeforeStream,
99
+ true,
100
+ context
115
101
  );
116
- };
117
- resolved.callbacks?.map((c) => c({ phase: HtmlEscapedCallbackPhase.Stream, context })).filter(Boolean).forEach(then);
118
- while (resolvedCount !== callbacks.length) {
119
- await Promise.all(callbacks);
102
+ controller.enqueue(textEncoder.encode(resolved));
103
+ let resolvedCount = 0;
104
+ const callbacks = [];
105
+ const then = (promise) => {
106
+ callbacks.push(
107
+ promise.catch((err) => {
108
+ console.log(err);
109
+ onError(err);
110
+ return "";
111
+ }).then(async (res) => {
112
+ res = await resolveCallback(
113
+ res,
114
+ HtmlEscapedCallbackPhase.BeforeStream,
115
+ true,
116
+ context
117
+ );
118
+ res.callbacks?.map((c) => c({ phase: HtmlEscapedCallbackPhase.Stream, context })).filter(Boolean).forEach(then);
119
+ resolvedCount++;
120
+ controller.enqueue(textEncoder.encode(res));
121
+ })
122
+ );
123
+ };
124
+ resolved.callbacks?.map((c) => c({ phase: HtmlEscapedCallbackPhase.Stream, context })).filter(Boolean).forEach(then);
125
+ while (resolvedCount !== callbacks.length) {
126
+ await Promise.all(callbacks);
127
+ }
128
+ } catch (e) {
129
+ onError(e);
120
130
  }
121
131
  controller.close();
122
132
  }
@@ -40,7 +40,7 @@ var serveStatic = (options) => {
40
40
  }
41
41
  }
42
42
  if (content) {
43
- let mimeType = void 0;
43
+ let mimeType;
44
44
  if (options.mimes) {
45
45
  mimeType = getMimeType(path, options.mimes) ?? getMimeType(path);
46
46
  } else {
@@ -25,11 +25,9 @@ var Node = class {
25
25
  let curNode = this;
26
26
  const parts = splitRoutingPath(path);
27
27
  const possibleKeys = [];
28
- const parentPatterns = [];
29
28
  for (let i = 0, len = parts.length; i < len; i++) {
30
29
  const p = parts[i];
31
30
  if (Object.keys(curNode.children).includes(p)) {
32
- parentPatterns.push(...curNode.patterns);
33
31
  curNode = curNode.children[p];
34
32
  const pattern2 = getPattern(p);
35
33
  if (pattern2) {
@@ -41,10 +39,8 @@ var Node = class {
41
39
  const pattern = getPattern(p);
42
40
  if (pattern) {
43
41
  curNode.patterns.push(pattern);
44
- parentPatterns.push(...curNode.patterns);
45
42
  possibleKeys.push(pattern[1]);
46
43
  }
47
- parentPatterns.push(...curNode.patterns);
48
44
  curNode = curNode.children[p];
49
45
  }
50
46
  if (!curNode.methods.length) {
@@ -13,4 +13,4 @@ export declare const Suspense: FC<PropsWithChildren<{
13
13
  * `renderToReadableStream()` is an experimental feature.
14
14
  * The API might be changed.
15
15
  */
16
- export declare const renderToReadableStream: (str: HtmlEscapedString | Promise<HtmlEscapedString>) => ReadableStream<Uint8Array>;
16
+ export declare const renderToReadableStream: (str: HtmlEscapedString | Promise<HtmlEscapedString>, onError?: (e: unknown) => void) => ReadableStream<Uint8Array>;
@@ -3,7 +3,7 @@ import type { SignatureKey } from './jws';
3
3
  import { type JWTPayload } from './types';
4
4
  export interface TokenHeader {
5
5
  alg: SignatureAlgorithm;
6
- typ: 'JWT';
6
+ typ?: 'JWT';
7
7
  }
8
8
  export declare function isTokenHeader(obj: any): obj is TokenHeader;
9
9
  export declare const sign: (payload: JWTPayload, privateKey: SignatureKey, alg?: SignatureAlgorithm) => Promise<string>;
@@ -5,10 +5,10 @@ type ValidationTargetByMethod<M> = M extends 'get' | 'head' ? Exclude<keyof Vali
5
5
  export type ValidationFunction<InputType, OutputType, E extends Env = {}, P extends string = string> = (value: InputType, c: Context<E, P>) => OutputType | Response | Promise<OutputType> | Promise<Response>;
6
6
  type ExcludeResponseType<T> = T extends Response & TypedResponse<any> ? never : T;
7
7
  export declare const validator: <InputType, P extends string, M extends string, U extends ValidationTargetByMethod<M>, OutputType = ValidationTargets[U], OutputTypeExcludeResponseType = ExcludeResponseType<OutputType>, P2 extends string = P, V extends {
8
- in: { [K in U]: K extends "json" ? InputType : { [K2 in keyof OutputTypeExcludeResponseType]: ValidationTargets[K][K2]; }; };
8
+ in: { [K in U]: K extends "json" ? unknown extends InputType ? OutputTypeExcludeResponseType : InputType : { [K2 in keyof OutputTypeExcludeResponseType]: ValidationTargets[K][K2]; }; };
9
9
  out: { [K_1 in U]: OutputTypeExcludeResponseType; };
10
10
  } = {
11
- in: { [K_2 in U]: K_2 extends "json" ? InputType : { [K2_1 in keyof OutputTypeExcludeResponseType]: ValidationTargets[K_2][K2_1]; }; };
11
+ in: { [K_2 in U]: K_2 extends "json" ? unknown extends InputType ? OutputTypeExcludeResponseType : InputType : { [K2_1 in keyof OutputTypeExcludeResponseType]: ValidationTargets[K_2][K2_1]; }; };
12
12
  out: { [K_3 in U]: OutputTypeExcludeResponseType; };
13
13
  }, E extends Env = any>(target: U, validationFunc: ValidationFunction<unknown extends InputType ? ValidationTargets[U] : InputType, OutputType, E, P2>) => MiddlewareHandler<E, P, V>;
14
14
  export {};
@@ -15,7 +15,7 @@ var encodeJwtPart = (part) => encodeBase64Url(utf8Encoder.encode(JSON.stringify(
15
15
  var encodeSignaturePart = (buf) => encodeBase64Url(buf).replace(/=/g, "");
16
16
  var decodeJwtPart = (part) => JSON.parse(utf8Decoder.decode(decodeBase64Url(part)));
17
17
  function isTokenHeader(obj) {
18
- return typeof obj === "object" && obj !== null && "alg" in obj && Object.values(AlgorithmTypes).includes(obj.alg) && "typ" in obj && obj.typ === "JWT";
18
+ return typeof obj === "object" && obj !== null && "alg" in obj && Object.values(AlgorithmTypes).includes(obj.alg) && (!("typ" in obj) || obj.typ === "JWT");
19
19
  }
20
20
  var sign = async (payload, privateKey, alg = "HS256") => {
21
21
  const encodedPayload = encodeJwtPart(payload);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono",
3
- "version": "4.2.3",
3
+ "version": "4.2.4",
4
4
  "description": "Ultrafast web framework for the Edges",
5
5
  "main": "dist/cjs/index.js",
6
6
  "type": "module",