hono 3.12.0 → 3.12.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.
@@ -23,7 +23,6 @@ __export(sse_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(sse_exports);
25
25
  var import_stream = require("../../utils/stream");
26
- var import__ = require(".");
27
26
  class SSEStreamingApi extends import_stream.StreamingApi {
28
27
  constructor(writable, readable) {
29
28
  super(writable, readable);
@@ -43,22 +42,11 @@ const setSSEHeaders = (context) => {
43
42
  context.header("Connection", "keep-alive");
44
43
  };
45
44
  const streamSSE = (c, cb) => {
46
- return (0, import__.stream)(c, async (originalStream) => {
47
- const { readable, writable } = new TransformStream();
48
- const stream2 = new SSEStreamingApi(writable, readable);
49
- originalStream.pipe(stream2.responseReadable).catch((err) => {
50
- console.error("Error in stream piping: ", err);
51
- stream2.close();
52
- });
53
- setSSEHeaders(c);
54
- try {
55
- await cb(stream2);
56
- } catch (err) {
57
- console.error("Error during streaming: ", err);
58
- } finally {
59
- await stream2.close();
60
- }
61
- });
45
+ const { readable, writable } = new TransformStream();
46
+ const stream = new SSEStreamingApi(writable, readable);
47
+ cb(stream).finally(() => stream.close());
48
+ setSSEHeaders(c);
49
+ return c.newResponse(stream.responseReadable);
62
50
  };
63
51
  // Annotate the CommonJS export names for ESM import in node:
64
52
  0 && (module.exports = {
@@ -25,7 +25,7 @@ module.exports = __toCommonJS(jsx_dev_runtime_exports);
25
25
  var import__ = require(".");
26
26
  var import__2 = require(".");
27
27
  function jsxDEV(tag, props) {
28
- if (!props?.children) {
28
+ if (!props || !("children" in props)) {
29
29
  return (0, import__.jsx)(tag, props);
30
30
  }
31
31
  const children = props.children;
@@ -1,6 +1,5 @@
1
1
  // src/helper/streaming/sse.ts
2
2
  import { StreamingApi } from "../../utils/stream.js";
3
- import { stream } from "./index.js";
4
3
  var SSEStreamingApi = class extends StreamingApi {
5
4
  constructor(writable, readable) {
6
5
  super(writable, readable);
@@ -20,22 +19,11 @@ var setSSEHeaders = (context) => {
20
19
  context.header("Connection", "keep-alive");
21
20
  };
22
21
  var streamSSE = (c, cb) => {
23
- return stream(c, async (originalStream) => {
24
- const { readable, writable } = new TransformStream();
25
- const stream2 = new SSEStreamingApi(writable, readable);
26
- originalStream.pipe(stream2.responseReadable).catch((err) => {
27
- console.error("Error in stream piping: ", err);
28
- stream2.close();
29
- });
30
- setSSEHeaders(c);
31
- try {
32
- await cb(stream2);
33
- } catch (err) {
34
- console.error("Error during streaming: ", err);
35
- } finally {
36
- await stream2.close();
37
- }
38
- });
22
+ const { readable, writable } = new TransformStream();
23
+ const stream = new SSEStreamingApi(writable, readable);
24
+ cb(stream).finally(() => stream.close());
25
+ setSSEHeaders(c);
26
+ return c.newResponse(stream.responseReadable);
39
27
  };
40
28
  export {
41
29
  SSEStreamingApi,
@@ -2,7 +2,7 @@
2
2
  import { jsx } from "./index.js";
3
3
  import { Fragment } from "./index.js";
4
4
  function jsxDEV(tag, props) {
5
- if (!props?.children) {
5
+ if (!props || !("children" in props)) {
6
6
  return jsx(tag, props);
7
7
  }
8
8
  const children = props.children;
@@ -1,13 +1,14 @@
1
1
  import type { Context } from '../context';
2
- import type { Env, ValidationTargets, MiddlewareHandler } from '../types';
2
+ import type { Env, ValidationTargets, MiddlewareHandler, TypedResponse } from '../types';
3
3
  type ValidationTargetKeysWithBody = 'form' | 'json';
4
4
  type ValidationTargetByMethod<M> = M extends 'get' | 'head' ? Exclude<keyof ValidationTargets, ValidationTargetKeysWithBody> : keyof ValidationTargets;
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
+ type ExcludeResponseType<T> = T extends Response & TypedResponse<any> ? never : T;
6
7
  export declare const validator: <InputType, P extends string, M extends string, U extends ValidationTargetByMethod<M>, OutputType = ValidationTargets[U], P2 extends string = P, V extends {
7
8
  in: { [K in U]: unknown extends InputType ? OutputType : InputType; };
8
- out: { [K_1 in U]: OutputType; };
9
+ out: { [K_1 in U]: ExcludeResponseType<OutputType>; };
9
10
  } = {
10
11
  in: { [K_2 in U]: unknown extends InputType ? OutputType : InputType; };
11
- out: { [K_3 in U]: OutputType; };
12
+ out: { [K_3 in U]: ExcludeResponseType<OutputType>; };
12
13
  }, E extends Env = any>(target: U, validationFunc: ValidationFunction<unknown extends InputType ? ValidationTargets[U] : InputType, OutputType, E, P2>) => MiddlewareHandler<E, P, V>;
13
14
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono",
3
- "version": "3.12.0",
3
+ "version": "3.12.1",
4
4
  "description": "Ultrafast web framework for the Edges",
5
5
  "main": "dist/cjs/index.js",
6
6
  "type": "module",
@@ -179,6 +179,11 @@
179
179
  "import": "./dist/validator/index.js",
180
180
  "require": "./dist/cjs/validator/index.js"
181
181
  },
182
+ "./router": {
183
+ "types": "./dist/types/router.d.ts",
184
+ "import": "./dist/router.js",
185
+ "require": "./dist/cjs/router.js"
186
+ },
182
187
  "./router/reg-exp-router": {
183
188
  "types": "./dist/types/router/reg-exp-router/index.d.ts",
184
189
  "import": "./dist/router/reg-exp-router/index.js",
@@ -366,6 +371,9 @@
366
371
  "validator": [
367
372
  "./dist/types/validator/index.d.ts"
368
373
  ],
374
+ "router": [
375
+ "./dist/types/router.d.ts"
376
+ ],
369
377
  "router/reg-exp-router": [
370
378
  "./dist/types/router/reg-exp-router/router.d.ts"
371
379
  ],