@kaito-http/core 4.0.0-beta.14 → 4.0.0-beta.15
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/{chunk-THVWVAMX.js → chunk-EPB3QL2T.js} +3 -0
- package/dist/index.cjs +3 -0
- package/dist/index.d.cts +13 -13
- package/dist/index.d.ts +13 -13
- package/dist/index.js +1 -1
- package/dist/schema/schema.cjs +3 -0
- package/dist/schema/schema.d.cts +1 -0
- package/dist/schema/schema.d.ts +1 -0
- package/dist/schema/schema.js +1 -1
- package/dist/stream/stream.cjs +6 -9
- package/dist/stream/stream.d.cts +11 -8
- package/dist/stream/stream.d.ts +11 -8
- package/dist/stream/stream.js +6 -9
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
package/dist/index.d.cts
CHANGED
|
@@ -23,7 +23,7 @@ declare class KaitoRequest {
|
|
|
23
23
|
arrayBuffer(): Promise<ArrayBuffer>;
|
|
24
24
|
blob(): Promise<Blob>;
|
|
25
25
|
formData(): Promise<FormData>;
|
|
26
|
-
bytes(): Promise<Uint8Array
|
|
26
|
+
bytes(): Promise<Uint8Array<ArrayBuffer>>;
|
|
27
27
|
json(): Promise<unknown>;
|
|
28
28
|
text(): Promise<string>;
|
|
29
29
|
get request(): Request;
|
|
@@ -100,15 +100,15 @@ declare class Router<ContextFrom, ContextTo, RequiredParams extends string, R ex
|
|
|
100
100
|
openapi: ({ info, servers, }: {
|
|
101
101
|
info: OpenAPI.InfoObject;
|
|
102
102
|
servers?: Partial<Record<(`https://` | `http://`) | ({} & string), string>>;
|
|
103
|
-
}) => Router<ContextFrom, ContextTo, RequiredParams, R | Route<ContextFrom, ContextTo, Input,
|
|
103
|
+
}) => Router<ContextFrom, ContextTo, RequiredParams, R | Route<ContextFrom, ContextTo, Input, Response, "/openapi.json", RequiredParams, "GET", {}, never>, Input>;
|
|
104
104
|
private readonly method;
|
|
105
|
-
get: <
|
|
106
|
-
post: <
|
|
107
|
-
put: <
|
|
108
|
-
patch: <
|
|
109
|
-
delete: <
|
|
110
|
-
head: <
|
|
111
|
-
options: <
|
|
105
|
+
get: <Path extends string, Result, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => Result | Promise<Result>) | Omit<Route<ContextFrom, ContextTo, Input, Result, Path, RequiredParams, "GET", Query, Body>, "body" | "path" | "method" | "router">) => Router<ContextFrom, ContextTo, RequiredParams, R | Route<ContextFrom, ContextTo, Input, Result, Path, RequiredParams, "GET", Query, Body>, Input>;
|
|
106
|
+
post: <Path extends string, Result, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => Result | Promise<Result>) | Omit<Route<ContextFrom, ContextTo, Input, Result, Path, RequiredParams, "POST", Query, Body>, "path" | "method" | "router">) => Router<ContextFrom, ContextTo, RequiredParams, R | Route<ContextFrom, ContextTo, Input, Result, Path, RequiredParams, "POST", Query, Body>, Input>;
|
|
107
|
+
put: <Path extends string, Result, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => Result | Promise<Result>) | Omit<Route<ContextFrom, ContextTo, Input, Result, Path, RequiredParams, "PUT", Query, Body>, "path" | "method" | "router">) => Router<ContextFrom, ContextTo, RequiredParams, R | Route<ContextFrom, ContextTo, Input, Result, Path, RequiredParams, "PUT", Query, Body>, Input>;
|
|
108
|
+
patch: <Path extends string, Result, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => Result | Promise<Result>) | Omit<Route<ContextFrom, ContextTo, Input, Result, Path, RequiredParams, "PATCH", Query, Body>, "path" | "method" | "router">) => Router<ContextFrom, ContextTo, RequiredParams, R | Route<ContextFrom, ContextTo, Input, Result, Path, RequiredParams, "PATCH", Query, Body>, Input>;
|
|
109
|
+
delete: <Path extends string, Result, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => Result | Promise<Result>) | Omit<Route<ContextFrom, ContextTo, Input, Result, Path, RequiredParams, "DELETE", Query, Body>, "path" | "method" | "router">) => Router<ContextFrom, ContextTo, RequiredParams, R | Route<ContextFrom, ContextTo, Input, Result, Path, RequiredParams, "DELETE", Query, Body>, Input>;
|
|
110
|
+
head: <Path extends string, Result, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => Result | Promise<Result>) | Omit<Route<ContextFrom, ContextTo, Input, Result, Path, RequiredParams, "HEAD", Query, Body>, "path" | "method" | "router">) => Router<ContextFrom, ContextTo, RequiredParams, R | Route<ContextFrom, ContextTo, Input, Result, Path, RequiredParams, "HEAD", Query, Body>, Input>;
|
|
111
|
+
options: <Path extends string, Result, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => Result | Promise<Result>) | Omit<Route<ContextFrom, ContextTo, Input, Result, Path, RequiredParams, "OPTIONS", Query, Body>, "path" | "method" | "router">) => Router<ContextFrom, ContextTo, RequiredParams, R | Route<ContextFrom, ContextTo, Input, Result, Path, RequiredParams, "OPTIONS", Query, Body>, Input>;
|
|
112
112
|
through: <NextContext>(through: (context: ContextTo, params: Record<RequiredParams, string>) => MaybePromise<NextContext>) => Router<ContextFrom, NextContext, RequiredParams, R, Input>;
|
|
113
113
|
}
|
|
114
114
|
|
|
@@ -132,11 +132,11 @@ type JSONOutputSpec<Result extends JSONValue> = {
|
|
|
132
132
|
schema: AnySchemaFor<Result>;
|
|
133
133
|
description?: string;
|
|
134
134
|
};
|
|
135
|
-
type OutputSpec<Result
|
|
135
|
+
type OutputSpec<Result> = {
|
|
136
136
|
description?: string;
|
|
137
|
-
body: Result extends KaitoSSEResponse<infer R> ? SSEOutputSpec<Extract<R, JSONValue>> : JSONOutputSpec<Result
|
|
137
|
+
body: Result extends KaitoSSEResponse<infer R> ? SSEOutputSpec<Extract<R, JSONValue>> : JSONOutputSpec<Extract<Result, JSONValue>>;
|
|
138
138
|
};
|
|
139
|
-
type Route<ContextFrom, ContextTo, RouterInput extends readonly unknown[], Result
|
|
139
|
+
type Route<ContextFrom, ContextTo, RouterInput extends readonly unknown[], Result, Path extends string, AdditionalParams extends string, Method extends KaitoMethod, Query extends Record<string, JSONValue>, Body extends JSONValue> = {
|
|
140
140
|
body?: AnySchemaFor<Body>;
|
|
141
141
|
query?: {
|
|
142
142
|
[Key in keyof Query]: AnySchemaFor<Query[Key]>;
|
|
@@ -145,7 +145,7 @@ type Route<ContextFrom, ContextTo, RouterInput extends readonly unknown[], Resul
|
|
|
145
145
|
method: Method;
|
|
146
146
|
openapi?: OutputSpec<NoInfer<Result>>;
|
|
147
147
|
router: Router<ContextFrom, ContextTo, AdditionalParams, AnyRoute, RouterInput>;
|
|
148
|
-
run(data: RouteRunData<ExtractRouteParams<Path> | AdditionalParams, ContextTo, Query, Body>): Promise<Result
|
|
148
|
+
run(data: RouteRunData<ExtractRouteParams<Path> | AdditionalParams, ContextTo, Query, Body>): Promise<Result> | Result;
|
|
149
149
|
};
|
|
150
150
|
type AnyRoute = Route<any, any, any, any, any, any, any, any, any>;
|
|
151
151
|
|
package/dist/index.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ declare class KaitoRequest {
|
|
|
23
23
|
arrayBuffer(): Promise<ArrayBuffer>;
|
|
24
24
|
blob(): Promise<Blob>;
|
|
25
25
|
formData(): Promise<FormData>;
|
|
26
|
-
bytes(): Promise<Uint8Array
|
|
26
|
+
bytes(): Promise<Uint8Array<ArrayBuffer>>;
|
|
27
27
|
json(): Promise<unknown>;
|
|
28
28
|
text(): Promise<string>;
|
|
29
29
|
get request(): Request;
|
|
@@ -100,15 +100,15 @@ declare class Router<ContextFrom, ContextTo, RequiredParams extends string, R ex
|
|
|
100
100
|
openapi: ({ info, servers, }: {
|
|
101
101
|
info: OpenAPI.InfoObject;
|
|
102
102
|
servers?: Partial<Record<(`https://` | `http://`) | ({} & string), string>>;
|
|
103
|
-
}) => Router<ContextFrom, ContextTo, RequiredParams, R | Route<ContextFrom, ContextTo, Input,
|
|
103
|
+
}) => Router<ContextFrom, ContextTo, RequiredParams, R | Route<ContextFrom, ContextTo, Input, Response, "/openapi.json", RequiredParams, "GET", {}, never>, Input>;
|
|
104
104
|
private readonly method;
|
|
105
|
-
get: <
|
|
106
|
-
post: <
|
|
107
|
-
put: <
|
|
108
|
-
patch: <
|
|
109
|
-
delete: <
|
|
110
|
-
head: <
|
|
111
|
-
options: <
|
|
105
|
+
get: <Path extends string, Result, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => Result | Promise<Result>) | Omit<Route<ContextFrom, ContextTo, Input, Result, Path, RequiredParams, "GET", Query, Body>, "body" | "path" | "method" | "router">) => Router<ContextFrom, ContextTo, RequiredParams, R | Route<ContextFrom, ContextTo, Input, Result, Path, RequiredParams, "GET", Query, Body>, Input>;
|
|
106
|
+
post: <Path extends string, Result, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => Result | Promise<Result>) | Omit<Route<ContextFrom, ContextTo, Input, Result, Path, RequiredParams, "POST", Query, Body>, "path" | "method" | "router">) => Router<ContextFrom, ContextTo, RequiredParams, R | Route<ContextFrom, ContextTo, Input, Result, Path, RequiredParams, "POST", Query, Body>, Input>;
|
|
107
|
+
put: <Path extends string, Result, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => Result | Promise<Result>) | Omit<Route<ContextFrom, ContextTo, Input, Result, Path, RequiredParams, "PUT", Query, Body>, "path" | "method" | "router">) => Router<ContextFrom, ContextTo, RequiredParams, R | Route<ContextFrom, ContextTo, Input, Result, Path, RequiredParams, "PUT", Query, Body>, Input>;
|
|
108
|
+
patch: <Path extends string, Result, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => Result | Promise<Result>) | Omit<Route<ContextFrom, ContextTo, Input, Result, Path, RequiredParams, "PATCH", Query, Body>, "path" | "method" | "router">) => Router<ContextFrom, ContextTo, RequiredParams, R | Route<ContextFrom, ContextTo, Input, Result, Path, RequiredParams, "PATCH", Query, Body>, Input>;
|
|
109
|
+
delete: <Path extends string, Result, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => Result | Promise<Result>) | Omit<Route<ContextFrom, ContextTo, Input, Result, Path, RequiredParams, "DELETE", Query, Body>, "path" | "method" | "router">) => Router<ContextFrom, ContextTo, RequiredParams, R | Route<ContextFrom, ContextTo, Input, Result, Path, RequiredParams, "DELETE", Query, Body>, Input>;
|
|
110
|
+
head: <Path extends string, Result, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => Result | Promise<Result>) | Omit<Route<ContextFrom, ContextTo, Input, Result, Path, RequiredParams, "HEAD", Query, Body>, "path" | "method" | "router">) => Router<ContextFrom, ContextTo, RequiredParams, R | Route<ContextFrom, ContextTo, Input, Result, Path, RequiredParams, "HEAD", Query, Body>, Input>;
|
|
111
|
+
options: <Path extends string, Result, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => Result | Promise<Result>) | Omit<Route<ContextFrom, ContextTo, Input, Result, Path, RequiredParams, "OPTIONS", Query, Body>, "path" | "method" | "router">) => Router<ContextFrom, ContextTo, RequiredParams, R | Route<ContextFrom, ContextTo, Input, Result, Path, RequiredParams, "OPTIONS", Query, Body>, Input>;
|
|
112
112
|
through: <NextContext>(through: (context: ContextTo, params: Record<RequiredParams, string>) => MaybePromise<NextContext>) => Router<ContextFrom, NextContext, RequiredParams, R, Input>;
|
|
113
113
|
}
|
|
114
114
|
|
|
@@ -132,11 +132,11 @@ type JSONOutputSpec<Result extends JSONValue> = {
|
|
|
132
132
|
schema: AnySchemaFor<Result>;
|
|
133
133
|
description?: string;
|
|
134
134
|
};
|
|
135
|
-
type OutputSpec<Result
|
|
135
|
+
type OutputSpec<Result> = {
|
|
136
136
|
description?: string;
|
|
137
|
-
body: Result extends KaitoSSEResponse<infer R> ? SSEOutputSpec<Extract<R, JSONValue>> : JSONOutputSpec<Result
|
|
137
|
+
body: Result extends KaitoSSEResponse<infer R> ? SSEOutputSpec<Extract<R, JSONValue>> : JSONOutputSpec<Extract<Result, JSONValue>>;
|
|
138
138
|
};
|
|
139
|
-
type Route<ContextFrom, ContextTo, RouterInput extends readonly unknown[], Result
|
|
139
|
+
type Route<ContextFrom, ContextTo, RouterInput extends readonly unknown[], Result, Path extends string, AdditionalParams extends string, Method extends KaitoMethod, Query extends Record<string, JSONValue>, Body extends JSONValue> = {
|
|
140
140
|
body?: AnySchemaFor<Body>;
|
|
141
141
|
query?: {
|
|
142
142
|
[Key in keyof Query]: AnySchemaFor<Query[Key]>;
|
|
@@ -145,7 +145,7 @@ type Route<ContextFrom, ContextTo, RouterInput extends readonly unknown[], Resul
|
|
|
145
145
|
method: Method;
|
|
146
146
|
openapi?: OutputSpec<NoInfer<Result>>;
|
|
147
147
|
router: Router<ContextFrom, ContextTo, AdditionalParams, AnyRoute, RouterInput>;
|
|
148
|
-
run(data: RouteRunData<ExtractRouteParams<Path> | AdditionalParams, ContextTo, Query, Body>): Promise<Result
|
|
148
|
+
run(data: RouteRunData<ExtractRouteParams<Path> | AdditionalParams, ContextTo, Query, Body>): Promise<Result> | Result;
|
|
149
149
|
};
|
|
150
150
|
type AnyRoute = Route<any, any, any, any, any, any, any, any, any>;
|
|
151
151
|
|
package/dist/index.js
CHANGED
package/dist/schema/schema.cjs
CHANGED
package/dist/schema/schema.d.cts
CHANGED
|
@@ -55,6 +55,7 @@ declare abstract class BaseSchema<Input extends JSONValue, Output, Def extends B
|
|
|
55
55
|
protected readonly def: Def;
|
|
56
56
|
protected clone(def: Partial<Def>): this;
|
|
57
57
|
protected constructor(def: Def);
|
|
58
|
+
or<OtherInput extends JSONValue, OtherOutput, Def extends BaseSchemaDef<OtherInput>>(other: BaseSchema<OtherInput, OtherOutput, Def>): KUnion<(this | BaseSchema<OtherInput, OtherOutput, Def>)["_input"], (this | BaseSchema<OtherInput, OtherOutput, Def>)["_output"]>;
|
|
58
59
|
example(example: Input): this;
|
|
59
60
|
example(): Input | undefined;
|
|
60
61
|
description(description: string): this;
|
package/dist/schema/schema.d.ts
CHANGED
|
@@ -55,6 +55,7 @@ declare abstract class BaseSchema<Input extends JSONValue, Output, Def extends B
|
|
|
55
55
|
protected readonly def: Def;
|
|
56
56
|
protected clone(def: Partial<Def>): this;
|
|
57
57
|
protected constructor(def: Def);
|
|
58
|
+
or<OtherInput extends JSONValue, OtherOutput, Def extends BaseSchemaDef<OtherInput>>(other: BaseSchema<OtherInput, OtherOutput, Def>): KUnion<(this | BaseSchema<OtherInput, OtherOutput, Def>)["_input"], (this | BaseSchema<OtherInput, OtherOutput, Def>)["_output"]>;
|
|
58
59
|
example(example: Input): this;
|
|
59
60
|
example(): Input | undefined;
|
|
60
61
|
description(description: string): this;
|
package/dist/schema/schema.js
CHANGED
package/dist/stream/stream.cjs
CHANGED
|
@@ -43,23 +43,20 @@ var KaitoSSEResponse = class extends Response {
|
|
|
43
43
|
}
|
|
44
44
|
};
|
|
45
45
|
function sseEventToString(event) {
|
|
46
|
-
|
|
46
|
+
const lines = [];
|
|
47
47
|
if (event.event) {
|
|
48
|
-
|
|
49
|
-
`;
|
|
48
|
+
lines.push(`event:${event.event}`);
|
|
50
49
|
}
|
|
51
50
|
if (event.id) {
|
|
52
|
-
|
|
53
|
-
`;
|
|
51
|
+
lines.push(`id:${event.id}`);
|
|
54
52
|
}
|
|
55
53
|
if (event.retry) {
|
|
56
|
-
|
|
57
|
-
`;
|
|
54
|
+
lines.push(`retry:${event.retry}`);
|
|
58
55
|
}
|
|
59
56
|
if (event.data !== void 0) {
|
|
60
|
-
|
|
57
|
+
lines.push(`data:${JSON.stringify(event.data)}`);
|
|
61
58
|
}
|
|
62
|
-
return
|
|
59
|
+
return lines.join("\n");
|
|
63
60
|
}
|
|
64
61
|
var SSEController = class {
|
|
65
62
|
controller;
|
package/dist/stream/stream.d.cts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { JSONValue } from '../schema/schema.cjs';
|
|
2
|
+
import 'openapi3-ts/oas31';
|
|
3
|
+
|
|
1
4
|
declare class KaitoSSEResponse<_T> extends Response {
|
|
2
5
|
constructor(body: ReadableStream<string>, init?: ResponseInit);
|
|
3
6
|
get [Symbol.toStringTag](): string;
|
|
@@ -17,20 +20,20 @@ type SSEEvent<T, E extends string> = ({
|
|
|
17
20
|
* @param event The SSE Event
|
|
18
21
|
* @returns A stringified version
|
|
19
22
|
*/
|
|
20
|
-
declare function sseEventToString(event: SSEEvent<
|
|
21
|
-
declare class SSEController<U, E extends string
|
|
23
|
+
declare function sseEventToString(event: SSEEvent<JSONValue, string>): string;
|
|
24
|
+
declare class SSEController<U extends JSONValue, E extends string, T extends SSEEvent<U, E>> implements Disposable {
|
|
22
25
|
private readonly controller;
|
|
23
26
|
constructor(controller: ReadableStreamDefaultController<string>);
|
|
24
|
-
enqueue(event:
|
|
27
|
+
enqueue(event: T): void;
|
|
25
28
|
close(): void;
|
|
26
29
|
[Symbol.dispose](): void;
|
|
27
30
|
}
|
|
28
|
-
interface SSESource<U, E extends string
|
|
31
|
+
interface SSESource<U extends JSONValue, E extends string, T extends SSEEvent<U, E>> {
|
|
29
32
|
cancel?: UnderlyingSourceCancelCallback;
|
|
30
|
-
start?(controller: SSEController<U, E>): Promise<void>;
|
|
31
|
-
pull?(controller: SSEController<U, E>): Promise<void>;
|
|
33
|
+
start?(controller: SSEController<U, E, T>): Promise<void>;
|
|
34
|
+
pull?(controller: SSEController<U, E, T>): Promise<void>;
|
|
32
35
|
}
|
|
33
|
-
declare function sse<U, E extends string, T extends SSEEvent<U, E>>(source: SSESource<U, E> | AsyncGenerator<T, unknown, unknown> | (() => AsyncGenerator<T, unknown, unknown>)): KaitoSSEResponse<T>;
|
|
34
|
-
declare function sseFromAnyReadable<R, U, E extends string>(stream: ReadableStream<R>, transform: (chunk: R) => SSEEvent<U, E>): KaitoSSEResponse<SSEEvent<U, E>>;
|
|
36
|
+
declare function sse<U extends JSONValue, E extends string, T extends SSEEvent<U, E>>(source: SSESource<U, E, T> | AsyncGenerator<T, unknown, unknown> | (() => AsyncGenerator<T, unknown, unknown>)): KaitoSSEResponse<T>;
|
|
37
|
+
declare function sseFromAnyReadable<R, U extends JSONValue, E extends string>(stream: ReadableStream<R>, transform: (chunk: R) => SSEEvent<U, E>): KaitoSSEResponse<SSEEvent<U, E>>;
|
|
35
38
|
|
|
36
39
|
export { KaitoSSEResponse, SSEController, type SSEEvent, type SSESource, sse, sseEventToString, sseFromAnyReadable };
|
package/dist/stream/stream.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { JSONValue } from '../schema/schema.js';
|
|
2
|
+
import 'openapi3-ts/oas31';
|
|
3
|
+
|
|
1
4
|
declare class KaitoSSEResponse<_T> extends Response {
|
|
2
5
|
constructor(body: ReadableStream<string>, init?: ResponseInit);
|
|
3
6
|
get [Symbol.toStringTag](): string;
|
|
@@ -17,20 +20,20 @@ type SSEEvent<T, E extends string> = ({
|
|
|
17
20
|
* @param event The SSE Event
|
|
18
21
|
* @returns A stringified version
|
|
19
22
|
*/
|
|
20
|
-
declare function sseEventToString(event: SSEEvent<
|
|
21
|
-
declare class SSEController<U, E extends string
|
|
23
|
+
declare function sseEventToString(event: SSEEvent<JSONValue, string>): string;
|
|
24
|
+
declare class SSEController<U extends JSONValue, E extends string, T extends SSEEvent<U, E>> implements Disposable {
|
|
22
25
|
private readonly controller;
|
|
23
26
|
constructor(controller: ReadableStreamDefaultController<string>);
|
|
24
|
-
enqueue(event:
|
|
27
|
+
enqueue(event: T): void;
|
|
25
28
|
close(): void;
|
|
26
29
|
[Symbol.dispose](): void;
|
|
27
30
|
}
|
|
28
|
-
interface SSESource<U, E extends string
|
|
31
|
+
interface SSESource<U extends JSONValue, E extends string, T extends SSEEvent<U, E>> {
|
|
29
32
|
cancel?: UnderlyingSourceCancelCallback;
|
|
30
|
-
start?(controller: SSEController<U, E>): Promise<void>;
|
|
31
|
-
pull?(controller: SSEController<U, E>): Promise<void>;
|
|
33
|
+
start?(controller: SSEController<U, E, T>): Promise<void>;
|
|
34
|
+
pull?(controller: SSEController<U, E, T>): Promise<void>;
|
|
32
35
|
}
|
|
33
|
-
declare function sse<U, E extends string, T extends SSEEvent<U, E>>(source: SSESource<U, E> | AsyncGenerator<T, unknown, unknown> | (() => AsyncGenerator<T, unknown, unknown>)): KaitoSSEResponse<T>;
|
|
34
|
-
declare function sseFromAnyReadable<R, U, E extends string>(stream: ReadableStream<R>, transform: (chunk: R) => SSEEvent<U, E>): KaitoSSEResponse<SSEEvent<U, E>>;
|
|
36
|
+
declare function sse<U extends JSONValue, E extends string, T extends SSEEvent<U, E>>(source: SSESource<U, E, T> | AsyncGenerator<T, unknown, unknown> | (() => AsyncGenerator<T, unknown, unknown>)): KaitoSSEResponse<T>;
|
|
37
|
+
declare function sseFromAnyReadable<R, U extends JSONValue, E extends string>(stream: ReadableStream<R>, transform: (chunk: R) => SSEEvent<U, E>): KaitoSSEResponse<SSEEvent<U, E>>;
|
|
35
38
|
|
|
36
39
|
export { KaitoSSEResponse, SSEController, type SSEEvent, type SSESource, sse, sseEventToString, sseFromAnyReadable };
|
package/dist/stream/stream.js
CHANGED
|
@@ -15,23 +15,20 @@ var KaitoSSEResponse = class extends Response {
|
|
|
15
15
|
}
|
|
16
16
|
};
|
|
17
17
|
function sseEventToString(event) {
|
|
18
|
-
|
|
18
|
+
const lines = [];
|
|
19
19
|
if (event.event) {
|
|
20
|
-
|
|
21
|
-
`;
|
|
20
|
+
lines.push(`event:${event.event}`);
|
|
22
21
|
}
|
|
23
22
|
if (event.id) {
|
|
24
|
-
|
|
25
|
-
`;
|
|
23
|
+
lines.push(`id:${event.id}`);
|
|
26
24
|
}
|
|
27
25
|
if (event.retry) {
|
|
28
|
-
|
|
29
|
-
`;
|
|
26
|
+
lines.push(`retry:${event.retry}`);
|
|
30
27
|
}
|
|
31
28
|
if (event.data !== void 0) {
|
|
32
|
-
|
|
29
|
+
lines.push(`data:${JSON.stringify(event.data)}`);
|
|
33
30
|
}
|
|
34
|
-
return
|
|
31
|
+
return lines.join("\n");
|
|
35
32
|
}
|
|
36
33
|
var SSEController = class {
|
|
37
34
|
controller;
|