hono 4.4.9 → 4.4.10
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.
- package/dist/cjs/helper/streaming/sse.js +5 -0
- package/dist/cjs/helper/streaming/stream.js +5 -0
- package/dist/cjs/utils/stream.js +8 -1
- package/dist/helper/streaming/sse.js +5 -0
- package/dist/helper/streaming/stream.js +5 -0
- package/dist/types/client/types.d.ts +1 -1
- package/dist/types/utils/stream.d.ts +9 -0
- package/dist/utils/stream.js +8 -1
- package/package.json +2 -2
|
@@ -57,9 +57,14 @@ const run = async (stream, cb, onError) => {
|
|
|
57
57
|
stream.close();
|
|
58
58
|
}
|
|
59
59
|
};
|
|
60
|
+
const contextStash = /* @__PURE__ */ new WeakMap();
|
|
60
61
|
const streamSSE = (c, cb, onError) => {
|
|
61
62
|
const { readable, writable } = new TransformStream();
|
|
62
63
|
const stream = new SSEStreamingApi(writable, readable);
|
|
64
|
+
c.req.raw.signal.addEventListener("abort", () => {
|
|
65
|
+
stream.abort();
|
|
66
|
+
});
|
|
67
|
+
contextStash.set(stream.responseReadable, c);
|
|
63
68
|
c.header("Transfer-Encoding", "chunked");
|
|
64
69
|
c.header("Content-Type", "text/event-stream");
|
|
65
70
|
c.header("Cache-Control", "no-cache");
|
|
@@ -22,9 +22,14 @@ __export(stream_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(stream_exports);
|
|
24
24
|
var import_stream = require("../../utils/stream");
|
|
25
|
+
const contextStash = /* @__PURE__ */ new WeakMap();
|
|
25
26
|
const stream = (c, cb, onError) => {
|
|
26
27
|
const { readable, writable } = new TransformStream();
|
|
27
28
|
const stream2 = new import_stream.StreamingApi(writable, readable);
|
|
29
|
+
c.req.raw.signal.addEventListener("abort", () => {
|
|
30
|
+
stream2.abort();
|
|
31
|
+
});
|
|
32
|
+
contextStash.set(stream2.responseReadable, c);
|
|
28
33
|
(async () => {
|
|
29
34
|
try {
|
|
30
35
|
await cb(stream2);
|
package/dist/cjs/utils/stream.js
CHANGED
|
@@ -27,6 +27,7 @@ class StreamingApi {
|
|
|
27
27
|
writable;
|
|
28
28
|
abortSubscribers = [];
|
|
29
29
|
responseReadable;
|
|
30
|
+
aborted = false;
|
|
30
31
|
constructor(writable, _readable) {
|
|
31
32
|
this.writable = writable;
|
|
32
33
|
this.writer = writable.getWriter();
|
|
@@ -41,7 +42,7 @@ class StreamingApi {
|
|
|
41
42
|
done ? controller.close() : controller.enqueue(value);
|
|
42
43
|
},
|
|
43
44
|
cancel: () => {
|
|
44
|
-
this.
|
|
45
|
+
this.abort();
|
|
45
46
|
}
|
|
46
47
|
});
|
|
47
48
|
}
|
|
@@ -76,6 +77,12 @@ class StreamingApi {
|
|
|
76
77
|
onAbort(listener) {
|
|
77
78
|
this.abortSubscribers.push(listener);
|
|
78
79
|
}
|
|
80
|
+
abort() {
|
|
81
|
+
if (!this.aborted) {
|
|
82
|
+
this.aborted = true;
|
|
83
|
+
this.abortSubscribers.forEach((subscriber) => subscriber());
|
|
84
|
+
}
|
|
85
|
+
}
|
|
79
86
|
}
|
|
80
87
|
// Annotate the CommonJS export names for ESM import in node:
|
|
81
88
|
0 && (module.exports = {
|
|
@@ -34,9 +34,14 @@ var run = async (stream, cb, onError) => {
|
|
|
34
34
|
stream.close();
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
|
+
var contextStash = /* @__PURE__ */ new WeakMap();
|
|
37
38
|
var streamSSE = (c, cb, onError) => {
|
|
38
39
|
const { readable, writable } = new TransformStream();
|
|
39
40
|
const stream = new SSEStreamingApi(writable, readable);
|
|
41
|
+
c.req.raw.signal.addEventListener("abort", () => {
|
|
42
|
+
stream.abort();
|
|
43
|
+
});
|
|
44
|
+
contextStash.set(stream.responseReadable, c);
|
|
40
45
|
c.header("Transfer-Encoding", "chunked");
|
|
41
46
|
c.header("Content-Type", "text/event-stream");
|
|
42
47
|
c.header("Cache-Control", "no-cache");
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
// src/helper/streaming/stream.ts
|
|
2
2
|
import { StreamingApi } from "../../utils/stream.js";
|
|
3
|
+
var contextStash = /* @__PURE__ */ new WeakMap();
|
|
3
4
|
var stream = (c, cb, onError) => {
|
|
4
5
|
const { readable, writable } = new TransformStream();
|
|
5
6
|
const stream2 = new StreamingApi(writable, readable);
|
|
7
|
+
c.req.raw.signal.addEventListener("abort", () => {
|
|
8
|
+
stream2.abort();
|
|
9
|
+
});
|
|
10
|
+
contextStash.set(stream2.responseReadable, c);
|
|
6
11
|
(async () => {
|
|
7
12
|
try {
|
|
8
13
|
await cb(stream2);
|
|
@@ -79,7 +79,7 @@ type InferResponseTypeFromEndpoint<T extends Endpoint, U extends StatusCode> = T
|
|
|
79
79
|
} ? S extends U ? O : never : never;
|
|
80
80
|
export type InferRequestType<T> = T extends (args: infer R, options: any | undefined) => Promise<ClientResponse<unknown>> ? NonNullable<R> : never;
|
|
81
81
|
export type InferRequestOptionsType<T> = T extends (args: any, options: infer R) => Promise<ClientResponse<unknown>> ? NonNullable<R> : never;
|
|
82
|
-
type PathToChain<Path extends string, E extends Schema, Original extends string =
|
|
82
|
+
type PathToChain<Path extends string, E extends Schema, Original extends string = Path> = Path extends `/${infer P}` ? PathToChain<P, E, Path> : Path extends `${infer P}/${infer R}` ? {
|
|
83
83
|
[K in P]: PathToChain<R, E, Original>;
|
|
84
84
|
} : {
|
|
85
85
|
[K in Path extends '' ? 'index' : Path]: ClientRequest<E extends Record<string, unknown> ? E[Original] : never>;
|
|
@@ -8,6 +8,10 @@ export declare class StreamingApi {
|
|
|
8
8
|
private writable;
|
|
9
9
|
private abortSubscribers;
|
|
10
10
|
responseReadable: ReadableStream;
|
|
11
|
+
/**
|
|
12
|
+
* Whether the stream has been aborted.
|
|
13
|
+
*/
|
|
14
|
+
aborted: boolean;
|
|
11
15
|
constructor(writable: WritableStream, _readable: ReadableStream);
|
|
12
16
|
write(input: Uint8Array | string): Promise<StreamingApi>;
|
|
13
17
|
writeln(input: string): Promise<StreamingApi>;
|
|
@@ -15,4 +19,9 @@ export declare class StreamingApi {
|
|
|
15
19
|
close(): Promise<void>;
|
|
16
20
|
pipe(body: ReadableStream): Promise<void>;
|
|
17
21
|
onAbort(listener: () => void | Promise<void>): void;
|
|
22
|
+
/**
|
|
23
|
+
* Abort the stream.
|
|
24
|
+
* You can call this method when stream is aborted by external event.
|
|
25
|
+
*/
|
|
26
|
+
abort(): void;
|
|
18
27
|
}
|
package/dist/utils/stream.js
CHANGED
|
@@ -5,6 +5,7 @@ var StreamingApi = class {
|
|
|
5
5
|
writable;
|
|
6
6
|
abortSubscribers = [];
|
|
7
7
|
responseReadable;
|
|
8
|
+
aborted = false;
|
|
8
9
|
constructor(writable, _readable) {
|
|
9
10
|
this.writable = writable;
|
|
10
11
|
this.writer = writable.getWriter();
|
|
@@ -19,7 +20,7 @@ var StreamingApi = class {
|
|
|
19
20
|
done ? controller.close() : controller.enqueue(value);
|
|
20
21
|
},
|
|
21
22
|
cancel: () => {
|
|
22
|
-
this.
|
|
23
|
+
this.abort();
|
|
23
24
|
}
|
|
24
25
|
});
|
|
25
26
|
}
|
|
@@ -54,6 +55,12 @@ var StreamingApi = class {
|
|
|
54
55
|
onAbort(listener) {
|
|
55
56
|
this.abortSubscribers.push(listener);
|
|
56
57
|
}
|
|
58
|
+
abort() {
|
|
59
|
+
if (!this.aborted) {
|
|
60
|
+
this.aborted = true;
|
|
61
|
+
this.abortSubscribers.forEach((subscriber) => subscriber());
|
|
62
|
+
}
|
|
63
|
+
}
|
|
57
64
|
};
|
|
58
65
|
export {
|
|
59
66
|
StreamingApi
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hono",
|
|
3
|
-
"version": "4.4.
|
|
3
|
+
"version": "4.4.10",
|
|
4
4
|
"description": "Web framework built on Web Standards",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"scripts": {
|
|
13
13
|
"test": "tsc --noEmit && vitest --run && vitest -c .vitest.config/jsx-runtime-default.ts --run && vitest -c .vitest.config/jsx-runtime-dom.ts --run",
|
|
14
14
|
"test:watch": "vitest --watch",
|
|
15
|
-
"test:deno": "deno test --allow-read --allow-env --allow-write -c runtime_tests/deno/deno.json runtime_tests/deno && deno test --no-lock -c runtime_tests/deno-jsx/deno.precompile.json runtime_tests/deno-jsx && deno test --no-lock -c runtime_tests/deno-jsx/deno.react-jsx.json runtime_tests/deno-jsx",
|
|
15
|
+
"test:deno": "deno test --allow-read --allow-env --allow-write --allow-net -c runtime_tests/deno/deno.json runtime_tests/deno && deno test --no-lock -c runtime_tests/deno-jsx/deno.precompile.json runtime_tests/deno-jsx && deno test --no-lock -c runtime_tests/deno-jsx/deno.react-jsx.json runtime_tests/deno-jsx",
|
|
16
16
|
"test:bun": "bun test --jsx-import-source ../../src/jsx runtime_tests/bun/index.test.tsx",
|
|
17
17
|
"test:fastly": "vitest --run --config ./runtime_tests/fastly/vitest.config.ts",
|
|
18
18
|
"test:node": "vitest --run --config ./runtime_tests/node/vitest.config.ts",
|