@hono/node-server 1.17.0 → 1.17.1

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,2 +1,2 @@
1
1
 
2
- export { }
2
+ export { }
package/dist/globals.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
 
2
- export { }
2
+ export { }
package/dist/index.js CHANGED
@@ -295,26 +295,23 @@ function writeFromReadableStream(stream, writable) {
295
295
  if (stream.locked) {
296
296
  throw new TypeError("ReadableStream is locked.");
297
297
  } else if (writable.destroyed) {
298
- stream.cancel();
299
298
  return;
300
299
  }
301
300
  const reader = stream.getReader();
302
- writable.on("close", cancel);
303
- writable.on("error", cancel);
304
- reader.read().then(flow, cancel);
301
+ const handleError = () => {
302
+ };
303
+ writable.on("error", handleError);
304
+ reader.read().then(flow, handleStreamError);
305
305
  return reader.closed.finally(() => {
306
- writable.off("close", cancel);
307
- writable.off("error", cancel);
306
+ writable.off("error", handleError);
308
307
  });
309
- function cancel(error) {
310
- reader.cancel(error).catch(() => {
311
- });
308
+ function handleStreamError(error) {
312
309
  if (error) {
313
310
  writable.destroy(error);
314
311
  }
315
312
  }
316
313
  function onDrain() {
317
- reader.read().then(flow, cancel);
314
+ reader.read().then(flow, handleStreamError);
318
315
  }
319
316
  function flow({ done, value }) {
320
317
  try {
@@ -323,10 +320,10 @@ function writeFromReadableStream(stream, writable) {
323
320
  } else if (!writable.write(value)) {
324
321
  writable.once("drain", onDrain);
325
322
  } else {
326
- return reader.read().then(flow, cancel);
323
+ return reader.read().then(flow, handleStreamError);
327
324
  }
328
325
  } catch (e) {
329
- cancel(e);
326
+ handleStreamError(e);
330
327
  }
331
328
  }
332
329
  }
package/dist/index.mjs CHANGED
@@ -256,26 +256,23 @@ function writeFromReadableStream(stream, writable) {
256
256
  if (stream.locked) {
257
257
  throw new TypeError("ReadableStream is locked.");
258
258
  } else if (writable.destroyed) {
259
- stream.cancel();
260
259
  return;
261
260
  }
262
261
  const reader = stream.getReader();
263
- writable.on("close", cancel);
264
- writable.on("error", cancel);
265
- reader.read().then(flow, cancel);
262
+ const handleError = () => {
263
+ };
264
+ writable.on("error", handleError);
265
+ reader.read().then(flow, handleStreamError);
266
266
  return reader.closed.finally(() => {
267
- writable.off("close", cancel);
268
- writable.off("error", cancel);
267
+ writable.off("error", handleError);
269
268
  });
270
- function cancel(error) {
271
- reader.cancel(error).catch(() => {
272
- });
269
+ function handleStreamError(error) {
273
270
  if (error) {
274
271
  writable.destroy(error);
275
272
  }
276
273
  }
277
274
  function onDrain() {
278
- reader.read().then(flow, cancel);
275
+ reader.read().then(flow, handleStreamError);
279
276
  }
280
277
  function flow({ done, value }) {
281
278
  try {
@@ -284,10 +281,10 @@ function writeFromReadableStream(stream, writable) {
284
281
  } else if (!writable.write(value)) {
285
282
  writable.once("drain", onDrain);
286
283
  } else {
287
- return reader.read().then(flow, cancel);
284
+ return reader.read().then(flow, handleStreamError);
288
285
  }
289
286
  } catch (e) {
290
- cancel(e);
287
+ handleStreamError(e);
291
288
  }
292
289
  }
293
290
  }
package/dist/listener.js CHANGED
@@ -287,26 +287,23 @@ function writeFromReadableStream(stream, writable) {
287
287
  if (stream.locked) {
288
288
  throw new TypeError("ReadableStream is locked.");
289
289
  } else if (writable.destroyed) {
290
- stream.cancel();
291
290
  return;
292
291
  }
293
292
  const reader = stream.getReader();
294
- writable.on("close", cancel);
295
- writable.on("error", cancel);
296
- reader.read().then(flow, cancel);
293
+ const handleError = () => {
294
+ };
295
+ writable.on("error", handleError);
296
+ reader.read().then(flow, handleStreamError);
297
297
  return reader.closed.finally(() => {
298
- writable.off("close", cancel);
299
- writable.off("error", cancel);
298
+ writable.off("error", handleError);
300
299
  });
301
- function cancel(error) {
302
- reader.cancel(error).catch(() => {
303
- });
300
+ function handleStreamError(error) {
304
301
  if (error) {
305
302
  writable.destroy(error);
306
303
  }
307
304
  }
308
305
  function onDrain() {
309
- reader.read().then(flow, cancel);
306
+ reader.read().then(flow, handleStreamError);
310
307
  }
311
308
  function flow({ done, value }) {
312
309
  try {
@@ -315,10 +312,10 @@ function writeFromReadableStream(stream, writable) {
315
312
  } else if (!writable.write(value)) {
316
313
  writable.once("drain", onDrain);
317
314
  } else {
318
- return reader.read().then(flow, cancel);
315
+ return reader.read().then(flow, handleStreamError);
319
316
  }
320
317
  } catch (e) {
321
- cancel(e);
318
+ handleStreamError(e);
322
319
  }
323
320
  }
324
321
  }
package/dist/listener.mjs CHANGED
@@ -253,26 +253,23 @@ function writeFromReadableStream(stream, writable) {
253
253
  if (stream.locked) {
254
254
  throw new TypeError("ReadableStream is locked.");
255
255
  } else if (writable.destroyed) {
256
- stream.cancel();
257
256
  return;
258
257
  }
259
258
  const reader = stream.getReader();
260
- writable.on("close", cancel);
261
- writable.on("error", cancel);
262
- reader.read().then(flow, cancel);
259
+ const handleError = () => {
260
+ };
261
+ writable.on("error", handleError);
262
+ reader.read().then(flow, handleStreamError);
263
263
  return reader.closed.finally(() => {
264
- writable.off("close", cancel);
265
- writable.off("error", cancel);
264
+ writable.off("error", handleError);
266
265
  });
267
- function cancel(error) {
268
- reader.cancel(error).catch(() => {
269
- });
266
+ function handleStreamError(error) {
270
267
  if (error) {
271
268
  writable.destroy(error);
272
269
  }
273
270
  }
274
271
  function onDrain() {
275
- reader.read().then(flow, cancel);
272
+ reader.read().then(flow, handleStreamError);
276
273
  }
277
274
  function flow({ done, value }) {
278
275
  try {
@@ -281,10 +278,10 @@ function writeFromReadableStream(stream, writable) {
281
278
  } else if (!writable.write(value)) {
282
279
  writable.once("drain", onDrain);
283
280
  } else {
284
- return reader.read().then(flow, cancel);
281
+ return reader.read().then(flow, handleStreamError);
285
282
  }
286
283
  } catch (e) {
287
- cancel(e);
284
+ handleStreamError(e);
288
285
  }
289
286
  }
290
287
  }
@@ -22,4 +22,4 @@ declare const abortControllerKey: unique symbol;
22
22
  declare const getAbortController: unique symbol;
23
23
  declare const newRequest: (incoming: IncomingMessage | Http2ServerRequest, defaultHostname?: string) => any;
24
24
 
25
- export { GlobalRequest, type IncomingMessageWithWrapBodyStream, Request, RequestError, abortControllerKey, getAbortController, newRequest, toRequestError, wrapBodyStream };
25
+ export { GlobalRequest, IncomingMessageWithWrapBodyStream, Request, RequestError, abortControllerKey, getAbortController, newRequest, toRequestError, wrapBodyStream };
package/dist/request.d.ts CHANGED
@@ -22,4 +22,4 @@ declare const abortControllerKey: unique symbol;
22
22
  declare const getAbortController: unique symbol;
23
23
  declare const newRequest: (incoming: IncomingMessage | Http2ServerRequest, defaultHostname?: string) => any;
24
24
 
25
- export { GlobalRequest, type IncomingMessageWithWrapBodyStream, Request, RequestError, abortControllerKey, getAbortController, newRequest, toRequestError, wrapBodyStream };
25
+ export { GlobalRequest, IncomingMessageWithWrapBodyStream, Request, RequestError, abortControllerKey, getAbortController, newRequest, toRequestError, wrapBodyStream };
@@ -23,4 +23,4 @@ declare class Response {
23
23
  get ok(): boolean;
24
24
  }
25
25
 
26
- export { GlobalResponse, type InternalCache, Response, cacheKey };
26
+ export { GlobalResponse, InternalCache, Response, cacheKey };
@@ -23,4 +23,4 @@ declare class Response {
23
23
  get ok(): boolean;
24
24
  }
25
25
 
26
- export { GlobalResponse, type InternalCache, Response, cacheKey };
26
+ export { GlobalResponse, InternalCache, Response, cacheKey };
@@ -14,4 +14,4 @@ type ServeStaticOptions<E extends Env = Env> = {
14
14
  };
15
15
  declare const serveStatic: <E extends Env = any>(options?: ServeStaticOptions<E>) => MiddlewareHandler<E>;
16
16
 
17
- export { type ServeStaticOptions, serveStatic };
17
+ export { ServeStaticOptions, serveStatic };
@@ -14,4 +14,4 @@ type ServeStaticOptions<E extends Env = Env> = {
14
14
  };
15
15
  declare const serveStatic: <E extends Env = any>(options?: ServeStaticOptions<E>) => MiddlewareHandler<E>;
16
16
 
17
- export { type ServeStaticOptions, serveStatic };
17
+ export { ServeStaticOptions, serveStatic };
@@ -58,37 +58,34 @@ var getStats = (path) => {
58
58
  return stats;
59
59
  };
60
60
  var serveStatic = (options = { root: "" }) => {
61
- const root = (0, import_node_path.resolve)(options.root || ".");
61
+ const root = options.root || "";
62
62
  const optionPath = options.path;
63
63
  return async (c, next) => {
64
64
  if (c.finalized) {
65
65
  return next();
66
66
  }
67
67
  let filename;
68
- try {
69
- const rawPath = optionPath ?? c.req.path;
70
- if (!optionPath) {
71
- const decodedPath = decodeURIComponent(rawPath);
72
- if (decodedPath.includes("..")) {
73
- await options.onNotFound?.(rawPath, c);
74
- return next();
68
+ if (optionPath) {
69
+ filename = optionPath;
70
+ } else {
71
+ try {
72
+ filename = decodeURIComponent(c.req.path);
73
+ if (/(?:^|[\/\\])\.\.(?:$|[\/\\])/.test(filename)) {
74
+ throw new Error();
75
75
  }
76
+ } catch {
77
+ await options.onNotFound?.(c.req.path, c);
78
+ return next();
76
79
  }
77
- filename = optionPath ?? decodeURIComponent(c.req.path);
78
- } catch {
79
- await options.onNotFound?.(c.req.path, c);
80
- return next();
81
80
  }
82
- const requestPath = options.rewriteRequestPath ? options.rewriteRequestPath(filename, c) : filename;
83
- let path = optionPath ? options.root ? (0, import_node_path.resolve)((0, import_node_path.join)(root, optionPath)) : optionPath : (0, import_node_path.resolve)((0, import_node_path.join)(root, requestPath));
81
+ let path = (0, import_node_path.join)(
82
+ root,
83
+ !optionPath && options.rewriteRequestPath ? options.rewriteRequestPath(filename, c) : filename
84
+ );
84
85
  let stats = getStats(path);
85
86
  if (stats && stats.isDirectory()) {
86
87
  const indexFile = options.index ?? "index.html";
87
- path = (0, import_node_path.resolve)((0, import_node_path.join)(path, indexFile));
88
- if (!optionPath && !path.startsWith(root)) {
89
- await options.onNotFound?.(path, c);
90
- return next();
91
- }
88
+ path = (0, import_node_path.join)(path, indexFile);
92
89
  stats = getStats(path);
93
90
  }
94
91
  if (!stats) {
@@ -1,7 +1,7 @@
1
1
  // src/serve-static.ts
2
2
  import { getMimeType } from "hono/utils/mime";
3
3
  import { createReadStream, lstatSync } from "fs";
4
- import { join, resolve } from "path";
4
+ import { join } from "path";
5
5
  var COMPRESSIBLE_CONTENT_TYPE_REGEX = /^\s*(?:text\/[^;\s]+|application\/(?:javascript|json|xml|xml-dtd|ecmascript|dart|postscript|rtf|tar|toml|vnd\.dart|vnd\.ms-fontobject|vnd\.ms-opentype|wasm|x-httpd-php|x-javascript|x-ns-proxy-autoconfig|x-sh|x-tar|x-virtualbox-hdd|x-virtualbox-ova|x-virtualbox-ovf|x-virtualbox-vbox|x-virtualbox-vdi|x-virtualbox-vhd|x-virtualbox-vmdk|x-www-form-urlencoded)|font\/(?:otf|ttf)|image\/(?:bmp|vnd\.adobe\.photoshop|vnd\.microsoft\.icon|vnd\.ms-dds|x-icon|x-ms-bmp)|message\/rfc822|model\/gltf-binary|x-shader\/x-fragment|x-shader\/x-vertex|[^;\s]+?\+(?:json|text|xml|yaml))(?:[;\s]|$)/i;
6
6
  var ENCODINGS = {
7
7
  br: ".br",
@@ -34,37 +34,34 @@ var getStats = (path) => {
34
34
  return stats;
35
35
  };
36
36
  var serveStatic = (options = { root: "" }) => {
37
- const root = resolve(options.root || ".");
37
+ const root = options.root || "";
38
38
  const optionPath = options.path;
39
39
  return async (c, next) => {
40
40
  if (c.finalized) {
41
41
  return next();
42
42
  }
43
43
  let filename;
44
- try {
45
- const rawPath = optionPath ?? c.req.path;
46
- if (!optionPath) {
47
- const decodedPath = decodeURIComponent(rawPath);
48
- if (decodedPath.includes("..")) {
49
- await options.onNotFound?.(rawPath, c);
50
- return next();
44
+ if (optionPath) {
45
+ filename = optionPath;
46
+ } else {
47
+ try {
48
+ filename = decodeURIComponent(c.req.path);
49
+ if (/(?:^|[\/\\])\.\.(?:$|[\/\\])/.test(filename)) {
50
+ throw new Error();
51
51
  }
52
+ } catch {
53
+ await options.onNotFound?.(c.req.path, c);
54
+ return next();
52
55
  }
53
- filename = optionPath ?? decodeURIComponent(c.req.path);
54
- } catch {
55
- await options.onNotFound?.(c.req.path, c);
56
- return next();
57
56
  }
58
- const requestPath = options.rewriteRequestPath ? options.rewriteRequestPath(filename, c) : filename;
59
- let path = optionPath ? options.root ? resolve(join(root, optionPath)) : optionPath : resolve(join(root, requestPath));
57
+ let path = join(
58
+ root,
59
+ !optionPath && options.rewriteRequestPath ? options.rewriteRequestPath(filename, c) : filename
60
+ );
60
61
  let stats = getStats(path);
61
62
  if (stats && stats.isDirectory()) {
62
63
  const indexFile = options.index ?? "index.html";
63
- path = resolve(join(path, indexFile));
64
- if (!optionPath && !path.startsWith(root)) {
65
- await options.onNotFound?.(path, c);
66
- return next();
67
- }
64
+ path = join(path, indexFile);
68
65
  stats = getStats(path);
69
66
  }
70
67
  if (!stats) {
package/dist/server.js CHANGED
@@ -291,26 +291,23 @@ function writeFromReadableStream(stream, writable) {
291
291
  if (stream.locked) {
292
292
  throw new TypeError("ReadableStream is locked.");
293
293
  } else if (writable.destroyed) {
294
- stream.cancel();
295
294
  return;
296
295
  }
297
296
  const reader = stream.getReader();
298
- writable.on("close", cancel);
299
- writable.on("error", cancel);
300
- reader.read().then(flow, cancel);
297
+ const handleError = () => {
298
+ };
299
+ writable.on("error", handleError);
300
+ reader.read().then(flow, handleStreamError);
301
301
  return reader.closed.finally(() => {
302
- writable.off("close", cancel);
303
- writable.off("error", cancel);
302
+ writable.off("error", handleError);
304
303
  });
305
- function cancel(error) {
306
- reader.cancel(error).catch(() => {
307
- });
304
+ function handleStreamError(error) {
308
305
  if (error) {
309
306
  writable.destroy(error);
310
307
  }
311
308
  }
312
309
  function onDrain() {
313
- reader.read().then(flow, cancel);
310
+ reader.read().then(flow, handleStreamError);
314
311
  }
315
312
  function flow({ done, value }) {
316
313
  try {
@@ -319,10 +316,10 @@ function writeFromReadableStream(stream, writable) {
319
316
  } else if (!writable.write(value)) {
320
317
  writable.once("drain", onDrain);
321
318
  } else {
322
- return reader.read().then(flow, cancel);
319
+ return reader.read().then(flow, handleStreamError);
323
320
  }
324
321
  } catch (e) {
325
- cancel(e);
322
+ handleStreamError(e);
326
323
  }
327
324
  }
328
325
  }
package/dist/server.mjs CHANGED
@@ -256,26 +256,23 @@ function writeFromReadableStream(stream, writable) {
256
256
  if (stream.locked) {
257
257
  throw new TypeError("ReadableStream is locked.");
258
258
  } else if (writable.destroyed) {
259
- stream.cancel();
260
259
  return;
261
260
  }
262
261
  const reader = stream.getReader();
263
- writable.on("close", cancel);
264
- writable.on("error", cancel);
265
- reader.read().then(flow, cancel);
262
+ const handleError = () => {
263
+ };
264
+ writable.on("error", handleError);
265
+ reader.read().then(flow, handleStreamError);
266
266
  return reader.closed.finally(() => {
267
- writable.off("close", cancel);
268
- writable.off("error", cancel);
267
+ writable.off("error", handleError);
269
268
  });
270
- function cancel(error) {
271
- reader.cancel(error).catch(() => {
272
- });
269
+ function handleStreamError(error) {
273
270
  if (error) {
274
271
  writable.destroy(error);
275
272
  }
276
273
  }
277
274
  function onDrain() {
278
- reader.read().then(flow, cancel);
275
+ reader.read().then(flow, handleStreamError);
279
276
  }
280
277
  function flow({ done, value }) {
281
278
  try {
@@ -284,10 +281,10 @@ function writeFromReadableStream(stream, writable) {
284
281
  } else if (!writable.write(value)) {
285
282
  writable.once("drain", onDrain);
286
283
  } else {
287
- return reader.read().then(flow, cancel);
284
+ return reader.read().then(flow, handleStreamError);
288
285
  }
289
286
  } catch (e) {
290
- cancel(e);
287
+ handleStreamError(e);
291
288
  }
292
289
  }
293
290
  }
package/dist/types.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { IncomingMessage, ServerResponse, ServerOptions as ServerOptions$1, createServer, Server } from 'node:http';
2
- import { Http2ServerRequest, Http2ServerResponse, ServerOptions as ServerOptions$3, createServer as createServer$2, SecureServerOptions, createSecureServer, Http2Server, Http2SecureServer } from 'node:http2';
1
+ import { IncomingMessage, ServerResponse, Server, ServerOptions as ServerOptions$1, createServer } from 'node:http';
2
+ import { Http2ServerRequest, Http2ServerResponse, Http2Server, Http2SecureServer, ServerOptions as ServerOptions$3, createServer as createServer$2, SecureServerOptions, createSecureServer } from 'node:http2';
3
3
  import { ServerOptions as ServerOptions$2, createServer as createServer$1 } from 'node:https';
4
4
 
5
5
  type HttpBindings = {
@@ -41,4 +41,4 @@ type Options = {
41
41
  } & ServerOptions;
42
42
  type CustomErrorHandler = (err: unknown) => void | Response | Promise<void | Response>;
43
43
 
44
- export type { CustomErrorHandler, FetchCallback, Http2Bindings, HttpBindings, NextHandlerOption, Options, ServerOptions, ServerType };
44
+ export { CustomErrorHandler, FetchCallback, Http2Bindings, HttpBindings, NextHandlerOption, Options, ServerOptions, ServerType };
package/dist/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { IncomingMessage, ServerResponse, ServerOptions as ServerOptions$1, createServer, Server } from 'node:http';
2
- import { Http2ServerRequest, Http2ServerResponse, ServerOptions as ServerOptions$3, createServer as createServer$2, SecureServerOptions, createSecureServer, Http2Server, Http2SecureServer } from 'node:http2';
1
+ import { IncomingMessage, ServerResponse, Server, ServerOptions as ServerOptions$1, createServer } from 'node:http';
2
+ import { Http2ServerRequest, Http2ServerResponse, Http2Server, Http2SecureServer, ServerOptions as ServerOptions$3, createServer as createServer$2, SecureServerOptions, createSecureServer } from 'node:http2';
3
3
  import { ServerOptions as ServerOptions$2, createServer as createServer$1 } from 'node:https';
4
4
 
5
5
  type HttpBindings = {
@@ -41,4 +41,4 @@ type Options = {
41
41
  } & ServerOptions;
42
42
  type CustomErrorHandler = (err: unknown) => void | Response | Promise<void | Response>;
43
43
 
44
- export type { CustomErrorHandler, FetchCallback, Http2Bindings, HttpBindings, NextHandlerOption, Options, ServerOptions, ServerType };
44
+ export { CustomErrorHandler, FetchCallback, Http2Bindings, HttpBindings, NextHandlerOption, Options, ServerOptions, ServerType };
package/dist/utils.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { OutgoingHttpHeaders } from 'node:http';
2
2
  import { Writable } from 'node:stream';
3
3
 
4
- declare function writeFromReadableStream(stream: ReadableStream<Uint8Array>, writable: Writable): Promise<undefined> | undefined;
4
+ declare function writeFromReadableStream(stream: ReadableStream<Uint8Array>, writable: Writable): Promise<void> | undefined;
5
5
  declare const buildOutgoingHttpHeaders: (headers: Headers | HeadersInit | null | undefined) => OutgoingHttpHeaders;
6
6
 
7
7
  export { buildOutgoingHttpHeaders, writeFromReadableStream };
package/dist/utils.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { OutgoingHttpHeaders } from 'node:http';
2
2
  import { Writable } from 'node:stream';
3
3
 
4
- declare function writeFromReadableStream(stream: ReadableStream<Uint8Array>, writable: Writable): Promise<undefined> | undefined;
4
+ declare function writeFromReadableStream(stream: ReadableStream<Uint8Array>, writable: Writable): Promise<void> | undefined;
5
5
  declare const buildOutgoingHttpHeaders: (headers: Headers | HeadersInit | null | undefined) => OutgoingHttpHeaders;
6
6
 
7
7
  export { buildOutgoingHttpHeaders, writeFromReadableStream };
package/dist/utils.js CHANGED
@@ -28,26 +28,23 @@ function writeFromReadableStream(stream, writable) {
28
28
  if (stream.locked) {
29
29
  throw new TypeError("ReadableStream is locked.");
30
30
  } else if (writable.destroyed) {
31
- stream.cancel();
32
31
  return;
33
32
  }
34
33
  const reader = stream.getReader();
35
- writable.on("close", cancel);
36
- writable.on("error", cancel);
37
- reader.read().then(flow, cancel);
34
+ const handleError = () => {
35
+ };
36
+ writable.on("error", handleError);
37
+ reader.read().then(flow, handleStreamError);
38
38
  return reader.closed.finally(() => {
39
- writable.off("close", cancel);
40
- writable.off("error", cancel);
39
+ writable.off("error", handleError);
41
40
  });
42
- function cancel(error) {
43
- reader.cancel(error).catch(() => {
44
- });
41
+ function handleStreamError(error) {
45
42
  if (error) {
46
43
  writable.destroy(error);
47
44
  }
48
45
  }
49
46
  function onDrain() {
50
- reader.read().then(flow, cancel);
47
+ reader.read().then(flow, handleStreamError);
51
48
  }
52
49
  function flow({ done, value }) {
53
50
  try {
@@ -56,10 +53,10 @@ function writeFromReadableStream(stream, writable) {
56
53
  } else if (!writable.write(value)) {
57
54
  writable.once("drain", onDrain);
58
55
  } else {
59
- return reader.read().then(flow, cancel);
56
+ return reader.read().then(flow, handleStreamError);
60
57
  }
61
58
  } catch (e) {
62
- cancel(e);
59
+ handleStreamError(e);
63
60
  }
64
61
  }
65
62
  }
package/dist/utils.mjs CHANGED
@@ -3,26 +3,23 @@ function writeFromReadableStream(stream, writable) {
3
3
  if (stream.locked) {
4
4
  throw new TypeError("ReadableStream is locked.");
5
5
  } else if (writable.destroyed) {
6
- stream.cancel();
7
6
  return;
8
7
  }
9
8
  const reader = stream.getReader();
10
- writable.on("close", cancel);
11
- writable.on("error", cancel);
12
- reader.read().then(flow, cancel);
9
+ const handleError = () => {
10
+ };
11
+ writable.on("error", handleError);
12
+ reader.read().then(flow, handleStreamError);
13
13
  return reader.closed.finally(() => {
14
- writable.off("close", cancel);
15
- writable.off("error", cancel);
14
+ writable.off("error", handleError);
16
15
  });
17
- function cancel(error) {
18
- reader.cancel(error).catch(() => {
19
- });
16
+ function handleStreamError(error) {
20
17
  if (error) {
21
18
  writable.destroy(error);
22
19
  }
23
20
  }
24
21
  function onDrain() {
25
- reader.read().then(flow, cancel);
22
+ reader.read().then(flow, handleStreamError);
26
23
  }
27
24
  function flow({ done, value }) {
28
25
  try {
@@ -31,10 +28,10 @@ function writeFromReadableStream(stream, writable) {
31
28
  } else if (!writable.write(value)) {
32
29
  writable.once("drain", onDrain);
33
30
  } else {
34
- return reader.read().then(flow, cancel);
31
+ return reader.read().then(flow, handleStreamError);
35
32
  }
36
33
  } catch (e) {
37
- cancel(e);
34
+ handleStreamError(e);
38
35
  }
39
36
  }
40
37
  }
package/dist/vercel.js CHANGED
@@ -289,26 +289,23 @@ function writeFromReadableStream(stream, writable) {
289
289
  if (stream.locked) {
290
290
  throw new TypeError("ReadableStream is locked.");
291
291
  } else if (writable.destroyed) {
292
- stream.cancel();
293
292
  return;
294
293
  }
295
294
  const reader = stream.getReader();
296
- writable.on("close", cancel);
297
- writable.on("error", cancel);
298
- reader.read().then(flow, cancel);
295
+ const handleError = () => {
296
+ };
297
+ writable.on("error", handleError);
298
+ reader.read().then(flow, handleStreamError);
299
299
  return reader.closed.finally(() => {
300
- writable.off("close", cancel);
301
- writable.off("error", cancel);
300
+ writable.off("error", handleError);
302
301
  });
303
- function cancel(error) {
304
- reader.cancel(error).catch(() => {
305
- });
302
+ function handleStreamError(error) {
306
303
  if (error) {
307
304
  writable.destroy(error);
308
305
  }
309
306
  }
310
307
  function onDrain() {
311
- reader.read().then(flow, cancel);
308
+ reader.read().then(flow, handleStreamError);
312
309
  }
313
310
  function flow({ done, value }) {
314
311
  try {
@@ -317,10 +314,10 @@ function writeFromReadableStream(stream, writable) {
317
314
  } else if (!writable.write(value)) {
318
315
  writable.once("drain", onDrain);
319
316
  } else {
320
- return reader.read().then(flow, cancel);
317
+ return reader.read().then(flow, handleStreamError);
321
318
  }
322
319
  } catch (e) {
323
- cancel(e);
320
+ handleStreamError(e);
324
321
  }
325
322
  }
326
323
  }
package/dist/vercel.mjs CHANGED
@@ -253,26 +253,23 @@ function writeFromReadableStream(stream, writable) {
253
253
  if (stream.locked) {
254
254
  throw new TypeError("ReadableStream is locked.");
255
255
  } else if (writable.destroyed) {
256
- stream.cancel();
257
256
  return;
258
257
  }
259
258
  const reader = stream.getReader();
260
- writable.on("close", cancel);
261
- writable.on("error", cancel);
262
- reader.read().then(flow, cancel);
259
+ const handleError = () => {
260
+ };
261
+ writable.on("error", handleError);
262
+ reader.read().then(flow, handleStreamError);
263
263
  return reader.closed.finally(() => {
264
- writable.off("close", cancel);
265
- writable.off("error", cancel);
264
+ writable.off("error", handleError);
266
265
  });
267
- function cancel(error) {
268
- reader.cancel(error).catch(() => {
269
- });
266
+ function handleStreamError(error) {
270
267
  if (error) {
271
268
  writable.destroy(error);
272
269
  }
273
270
  }
274
271
  function onDrain() {
275
- reader.read().then(flow, cancel);
272
+ reader.read().then(flow, handleStreamError);
276
273
  }
277
274
  function flow({ done, value }) {
278
275
  try {
@@ -281,10 +278,10 @@ function writeFromReadableStream(stream, writable) {
281
278
  } else if (!writable.write(value)) {
282
279
  writable.once("drain", onDrain);
283
280
  } else {
284
- return reader.read().then(flow, cancel);
281
+ return reader.read().then(flow, handleStreamError);
285
282
  }
286
283
  } catch (e) {
287
- cancel(e);
284
+ handleStreamError(e);
288
285
  }
289
286
  }
290
287
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hono/node-server",
3
- "version": "1.17.0",
3
+ "version": "1.17.1",
4
4
  "description": "Node.js Adapter for Hono",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",