@kaito-http/core 4.0.0-beta.3 → 4.0.0-beta.31
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-DRJX3OJG.js +1003 -0
- package/dist/chunk-HJ5HIYGW.js +92 -0
- package/dist/cors/cors.cjs +85 -17
- package/dist/cors/cors.d.cts +122 -26
- package/dist/cors/cors.d.ts +122 -26
- package/dist/cors/cors.js +85 -17
- package/dist/index.cjs +1218 -106
- package/dist/index.d.cts +137 -107
- package/dist/index.d.ts +137 -107
- package/dist/index.js +218 -105
- package/dist/schema/schema.cjs +1046 -0
- package/dist/schema/schema.d.cts +391 -0
- package/dist/schema/schema.d.ts +391 -0
- package/dist/schema/schema.js +44 -0
- package/dist/stream/stream.cjs +11 -23
- package/dist/stream/stream.d.cts +14 -11
- package/dist/stream/stream.d.ts +14 -11
- package/dist/stream/stream.js +7 -96
- package/package.json +6 -9
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
import { SchemaObject, ReferenceObject } from 'openapi3-ts/oas31';
|
|
2
|
+
|
|
3
|
+
type JSONPrimitive = string | number | boolean | null;
|
|
4
|
+
type JSONValue = JSONPrimitive | JSONValue[] | {
|
|
5
|
+
[key: string]: JSONValue;
|
|
6
|
+
};
|
|
7
|
+
declare function isPrimitiveJSONValue(value: unknown): value is JSONPrimitive;
|
|
8
|
+
interface BaseSchemaDef<Input extends JSONValue> {
|
|
9
|
+
example?: Input | undefined;
|
|
10
|
+
description?: string | undefined;
|
|
11
|
+
}
|
|
12
|
+
interface Issue {
|
|
13
|
+
message: string;
|
|
14
|
+
path: string[];
|
|
15
|
+
}
|
|
16
|
+
type ParseResult<T> = {
|
|
17
|
+
success: true;
|
|
18
|
+
result: T;
|
|
19
|
+
} | {
|
|
20
|
+
success: false;
|
|
21
|
+
issues: Set<Issue>;
|
|
22
|
+
};
|
|
23
|
+
declare class SchemaError extends Error {
|
|
24
|
+
readonly issues: Set<Issue>;
|
|
25
|
+
constructor(issues: Set<Issue>);
|
|
26
|
+
}
|
|
27
|
+
declare class ParseContext {
|
|
28
|
+
#private;
|
|
29
|
+
private static readonly ISSUE;
|
|
30
|
+
readonly ISSUE: typeof ParseContext.ISSUE;
|
|
31
|
+
addIssue(message: string, path: string[]): typeof ParseContext.ISSUE;
|
|
32
|
+
addIssues(issues: Iterable<Issue>, path: string[]): typeof ParseContext.ISSUE;
|
|
33
|
+
get issues(): Set<Issue>;
|
|
34
|
+
static result<T>(fn: (ctx: ParseContext) => T | typeof ParseContext.ISSUE): ParseResult<T>;
|
|
35
|
+
static with<T>(fn: (ctx: ParseContext) => T | typeof ParseContext.ISSUE): {
|
|
36
|
+
type: "FATAL";
|
|
37
|
+
issues: Set<Issue>;
|
|
38
|
+
data?: never;
|
|
39
|
+
} | {
|
|
40
|
+
type: "PARSED";
|
|
41
|
+
issues: Set<Issue>;
|
|
42
|
+
data: T;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
type AnySchemaFor<T extends JSONValue> = BaseSchema<T, T, BaseSchemaDef<T>>;
|
|
46
|
+
declare abstract class BaseSchema<Input extends JSONValue, Output, Def extends BaseSchemaDef<Input>> {
|
|
47
|
+
/** @internal */
|
|
48
|
+
readonly _input: Input;
|
|
49
|
+
/** @internal */
|
|
50
|
+
readonly _output: Output;
|
|
51
|
+
abstract parse(json: unknown): Output;
|
|
52
|
+
abstract parseSafe(json: unknown): ParseResult<Output>;
|
|
53
|
+
abstract serialize(value: Output): Input;
|
|
54
|
+
protected readonly def: Def;
|
|
55
|
+
abstract toOpenAPI(): SchemaObject | ReferenceObject;
|
|
56
|
+
protected getSchemaObject(): {
|
|
57
|
+
description?: string;
|
|
58
|
+
example?: Input;
|
|
59
|
+
};
|
|
60
|
+
protected clone(def: Partial<Def>): this;
|
|
61
|
+
protected constructor(def: Def);
|
|
62
|
+
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"]>;
|
|
63
|
+
example(example: Input): this;
|
|
64
|
+
example(): Input | undefined;
|
|
65
|
+
description(description: string): this;
|
|
66
|
+
description(): string | undefined;
|
|
67
|
+
/**
|
|
68
|
+
* Traverse immediate children schemas.
|
|
69
|
+
*/
|
|
70
|
+
abstract visit(visitor: (schema: BaseSchema<any, any, any>) => void): void;
|
|
71
|
+
}
|
|
72
|
+
type Check<T extends string, P extends {} = {}> = {
|
|
73
|
+
type: T;
|
|
74
|
+
message?: string | undefined;
|
|
75
|
+
} & Omit<P, 'message'>;
|
|
76
|
+
type StringFormat = 'date' | 'date-time' | 'password' | 'byte' | 'binary' | 'email' | 'uuid' | 'uri' | 'hostname' | 'ipv4' | 'ipv6';
|
|
77
|
+
declare const STRING_FORMAT_REGEXES: {
|
|
78
|
+
readonly uuid: RegExp;
|
|
79
|
+
readonly email: RegExp;
|
|
80
|
+
readonly ipv4: RegExp;
|
|
81
|
+
readonly ipv6: RegExp;
|
|
82
|
+
readonly date: RegExp;
|
|
83
|
+
readonly uri: RegExp;
|
|
84
|
+
readonly hostname: RegExp;
|
|
85
|
+
};
|
|
86
|
+
interface StringChecks {
|
|
87
|
+
min?: Check<'min', {
|
|
88
|
+
val: number;
|
|
89
|
+
}>;
|
|
90
|
+
max?: Check<'max', {
|
|
91
|
+
val: number;
|
|
92
|
+
}>;
|
|
93
|
+
regex?: Check<'regex', {
|
|
94
|
+
regex: RegExp;
|
|
95
|
+
}>;
|
|
96
|
+
format?: Check<'format', {
|
|
97
|
+
format: StringFormat;
|
|
98
|
+
}>;
|
|
99
|
+
startsWith?: Check<'startsWith', {
|
|
100
|
+
prefix: string;
|
|
101
|
+
}>;
|
|
102
|
+
endsWith?: Check<'endsWith', {
|
|
103
|
+
suffix: string;
|
|
104
|
+
}>;
|
|
105
|
+
}
|
|
106
|
+
interface StringDef extends BaseSchemaDef<string>, StringChecks {
|
|
107
|
+
}
|
|
108
|
+
declare class KString extends BaseSchema<string, string, StringDef> {
|
|
109
|
+
static create: () => KString;
|
|
110
|
+
serialize(value: string): string;
|
|
111
|
+
private setCheck;
|
|
112
|
+
toOpenAPI(): SchemaObject | ReferenceObject;
|
|
113
|
+
/**
|
|
114
|
+
* Sets the minimum length of the string
|
|
115
|
+
*
|
|
116
|
+
* @param min The minimum length of the string
|
|
117
|
+
* @returns A clone of the schema with the minimum length set
|
|
118
|
+
*/
|
|
119
|
+
min(min: number, message?: string): this;
|
|
120
|
+
/**
|
|
121
|
+
* Sets the maximum length of the string
|
|
122
|
+
*
|
|
123
|
+
* @param max The maximum length of the string
|
|
124
|
+
* @returns A clone of the schema with the maximum length set
|
|
125
|
+
*/
|
|
126
|
+
max(max: number, message?: string): this;
|
|
127
|
+
regex(regex: RegExp, message?: string): this;
|
|
128
|
+
startsWith(prefix: string, message?: string): this;
|
|
129
|
+
endsWith(suffix: string, message?: string): this;
|
|
130
|
+
private format;
|
|
131
|
+
uri(message?: string): this;
|
|
132
|
+
/**
|
|
133
|
+
* Deprecated because OpenAPI uses the term "uri"
|
|
134
|
+
* but this method exists for making migration from
|
|
135
|
+
* Zod easier.
|
|
136
|
+
*
|
|
137
|
+
* @deprecated Use {@link uri} instead
|
|
138
|
+
*/
|
|
139
|
+
url(message?: string): this;
|
|
140
|
+
email(message?: string): this;
|
|
141
|
+
uuid(message?: string): this;
|
|
142
|
+
ipv4(message?: string): this;
|
|
143
|
+
ipv6(message?: string): this;
|
|
144
|
+
date(message?: string): this;
|
|
145
|
+
dateTime(message?: string): this;
|
|
146
|
+
password(message?: string): this;
|
|
147
|
+
byte(message?: string): this;
|
|
148
|
+
binary(message?: string): this;
|
|
149
|
+
hostname(message?: string): this;
|
|
150
|
+
parseSafe(json: unknown): ParseResult<string>;
|
|
151
|
+
parse(json: unknown): string;
|
|
152
|
+
visit(): void;
|
|
153
|
+
}
|
|
154
|
+
type NumberFormat = 'float' | 'double' | 'int32' | 'int64';
|
|
155
|
+
interface NumberChecks {
|
|
156
|
+
min?: Check<'min', {
|
|
157
|
+
val: number;
|
|
158
|
+
}>;
|
|
159
|
+
max?: Check<'max', {
|
|
160
|
+
val: number;
|
|
161
|
+
}>;
|
|
162
|
+
integer?: Check<'integer'>;
|
|
163
|
+
multipleOf?: Check<'multipleOf', {
|
|
164
|
+
val: number;
|
|
165
|
+
}>;
|
|
166
|
+
format?: Check<'format', {
|
|
167
|
+
format: NumberFormat;
|
|
168
|
+
}>;
|
|
169
|
+
}
|
|
170
|
+
interface NumberDef extends BaseSchemaDef<number>, NumberChecks {
|
|
171
|
+
}
|
|
172
|
+
declare class KNumber extends BaseSchema<number, number, NumberDef> {
|
|
173
|
+
static create: () => KNumber;
|
|
174
|
+
serialize(value: number): number;
|
|
175
|
+
private setCheck;
|
|
176
|
+
toOpenAPI(): SchemaObject | ReferenceObject;
|
|
177
|
+
min(min: number): this;
|
|
178
|
+
max(max: number): this;
|
|
179
|
+
integer(): this;
|
|
180
|
+
multipleOf(multipleOf: number): this;
|
|
181
|
+
float(): this;
|
|
182
|
+
double(): this;
|
|
183
|
+
int32(): this;
|
|
184
|
+
int64(): this;
|
|
185
|
+
parseSafe(json: unknown): ParseResult<number>;
|
|
186
|
+
parse(json: unknown): number;
|
|
187
|
+
visit(): void;
|
|
188
|
+
}
|
|
189
|
+
interface BooleanDef extends BaseSchemaDef<boolean> {
|
|
190
|
+
}
|
|
191
|
+
declare class KBoolean extends BaseSchema<boolean, boolean, BooleanDef> {
|
|
192
|
+
static create: () => KBoolean;
|
|
193
|
+
serialize(value: boolean): boolean;
|
|
194
|
+
toOpenAPI(): SchemaObject | ReferenceObject;
|
|
195
|
+
parseSafe(json: unknown): ParseResult<boolean>;
|
|
196
|
+
parse(json: unknown): boolean;
|
|
197
|
+
visit(): void;
|
|
198
|
+
}
|
|
199
|
+
interface ArrayChecks {
|
|
200
|
+
minItems?: Check<'minItems', {
|
|
201
|
+
val: number;
|
|
202
|
+
}>;
|
|
203
|
+
maxItems?: Check<'maxItems', {
|
|
204
|
+
val: number;
|
|
205
|
+
}>;
|
|
206
|
+
uniqueItems?: Check<'uniqueItems', {
|
|
207
|
+
val: boolean;
|
|
208
|
+
}>;
|
|
209
|
+
}
|
|
210
|
+
interface ArrayDef<Input extends JSONValue, Output> extends BaseSchemaDef<Input[]>, ArrayChecks {
|
|
211
|
+
items: BaseSchema<Input, Output, BaseSchemaDef<Input>>;
|
|
212
|
+
}
|
|
213
|
+
declare class KArray<Input extends JSONValue, Output> extends BaseSchema<Input[], Output[], ArrayDef<Input, Output>> {
|
|
214
|
+
static create: <ItemsInput extends JSONValue, ItemsOutput, Def extends BaseSchemaDef<ItemsInput>>(items: BaseSchema<ItemsInput, ItemsOutput, Def>) => KArray<ItemsInput, ItemsOutput>;
|
|
215
|
+
serialize(value: Output[]): Input[];
|
|
216
|
+
private setCheck;
|
|
217
|
+
toOpenAPI(): SchemaObject | ReferenceObject;
|
|
218
|
+
min(minItems: number): this;
|
|
219
|
+
max(maxItems: number): this;
|
|
220
|
+
unique(): this;
|
|
221
|
+
notUnique(): this;
|
|
222
|
+
parseSafe(json: unknown): ParseResult<Output[]>;
|
|
223
|
+
parse(json: unknown): Output[];
|
|
224
|
+
visit(visitor: (schema: BaseSchema<any, any, any>) => void): void;
|
|
225
|
+
}
|
|
226
|
+
interface NullDef extends BaseSchemaDef<null> {
|
|
227
|
+
}
|
|
228
|
+
declare class KNull extends BaseSchema<null, null, NullDef> {
|
|
229
|
+
static create: () => KNull;
|
|
230
|
+
serialize(value: null): null;
|
|
231
|
+
toOpenAPI(): SchemaObject | ReferenceObject;
|
|
232
|
+
parseSafe(json: unknown): ParseResult<null>;
|
|
233
|
+
parse(json: unknown): null;
|
|
234
|
+
visit(): void;
|
|
235
|
+
}
|
|
236
|
+
interface ObjectDef<Input extends Record<keyof Output, JSONValue>, Output extends Record<keyof Input, JSONValue>> extends BaseSchemaDef<Input> {
|
|
237
|
+
shape: {
|
|
238
|
+
[K in keyof Input]: BaseSchema<Input[K], Output[K], BaseSchemaDef<Input[K]>>;
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
declare class KObject<Input extends Record<keyof Output, JSONValue>, Output extends Record<keyof Input, any>> extends BaseSchema<Input, Output, ObjectDef<Input, Output>> {
|
|
242
|
+
static create: <Input_1 extends Record<keyof Output_1, any>, Output_1 extends Record<keyof Input_1, any>>(shape: { [K in keyof Input_1 | keyof Output_1]: BaseSchema<Input_1[K], Output_1[K], BaseSchemaDef<Input_1[K]>>; }) => KObject<Input_1, Output_1>;
|
|
243
|
+
serialize(value: Output): Input;
|
|
244
|
+
toOpenAPI(): SchemaObject;
|
|
245
|
+
parseSafe(json: unknown): ParseResult<Output>;
|
|
246
|
+
parse(json: unknown): Output;
|
|
247
|
+
get shape(): { [K in keyof Input]: BaseSchema<Input[K], Output[K], BaseSchemaDef<Input[K]>>; };
|
|
248
|
+
visit(visitor: (schema: BaseSchema<any, any, any>) => void): void;
|
|
249
|
+
}
|
|
250
|
+
declare class KObjectFromURLSearchParams<Input extends Record<keyof Output, JSONValue>, Output extends Record<keyof Input, JSONValue>> extends KObject<Input, Output> {
|
|
251
|
+
static create: <Input_1 extends Record<keyof Output_1, JSONValue>, Output_1 extends Record<keyof Input_1, JSONValue>>(shape: { [K in keyof Input_1 | keyof Output_1]: BaseSchema<Input_1[K], Output_1[K], BaseSchemaDef<Input_1[K]>>; }) => KObjectFromURLSearchParams<Input_1, Output_1>;
|
|
252
|
+
serialize(value: Output): Input;
|
|
253
|
+
toOpenAPI(): SchemaObject;
|
|
254
|
+
parseSafe(json: unknown): ParseResult<Output>;
|
|
255
|
+
}
|
|
256
|
+
interface RefDef<Input extends Record<keyof Output, JSONValue>, Output extends Record<keyof Input, JSONValue>> extends ObjectDef<Input, Output> {
|
|
257
|
+
name: string;
|
|
258
|
+
summary?: string | undefined;
|
|
259
|
+
}
|
|
260
|
+
declare class KRef<Input extends Record<keyof Output, JSONValue>, Output extends Record<keyof Input, any>> extends BaseSchema<Input, Output, RefDef<Input, Output>> {
|
|
261
|
+
static create: <Input_1 extends Record<keyof Output_1, JSONValue>, Output_1 extends Record<keyof Input_1, any>>(name: string, shape: { [K in keyof Input_1 | keyof Output_1]: BaseSchema<Input_1[K], Output_1[K], BaseSchemaDef<Input_1[K]>>; }) => KRef<Input_1, Output_1>;
|
|
262
|
+
serialize(value: Output): Input;
|
|
263
|
+
visit(visitor: (schema: BaseSchema<any, any, any>) => void): void;
|
|
264
|
+
example(): never;
|
|
265
|
+
toOpenAPI(): ReferenceObject;
|
|
266
|
+
parseSafe(json: unknown): ParseResult<Output>;
|
|
267
|
+
parse(json: unknown): Output;
|
|
268
|
+
summary(): string | undefined;
|
|
269
|
+
summary(summary: string): this;
|
|
270
|
+
get shape(): { [K in keyof Input]: BaseSchema<Input[K], Output[K], BaseSchemaDef<Input[K]>>; };
|
|
271
|
+
get name(): string;
|
|
272
|
+
}
|
|
273
|
+
interface ScalarOptions<ClientRepresentation extends JSONValue, ServerRepresentation> {
|
|
274
|
+
/**
|
|
275
|
+
* Parse the value from the unsafe JSON
|
|
276
|
+
*/
|
|
277
|
+
schema: BaseSchema<ClientRepresentation, ClientRepresentation, BaseSchemaDef<ClientRepresentation>>;
|
|
278
|
+
/**
|
|
279
|
+
* Turn the parsed JSON value into something the server can use
|
|
280
|
+
* @param jsonValue The parsed JSON value
|
|
281
|
+
* @returns The server representation
|
|
282
|
+
*/
|
|
283
|
+
toServer: (jsonValue: ClientRepresentation) => ServerRepresentation;
|
|
284
|
+
/**
|
|
285
|
+
* Turn the server respresentation back into a JSON value
|
|
286
|
+
* @param serverValue The value from the server we want to convert back into the client
|
|
287
|
+
* @returns Convert the data back into a JSON value that the server can understand
|
|
288
|
+
*/
|
|
289
|
+
toClient: (serverValue: ServerRepresentation) => ClientRepresentation;
|
|
290
|
+
}
|
|
291
|
+
interface ScalarDef<ClientRepresentation extends JSONPrimitive, ServerRepresentation> extends BaseSchemaDef<ClientRepresentation>, ScalarOptions<ClientRepresentation, ServerRepresentation> {
|
|
292
|
+
}
|
|
293
|
+
declare class KScalar<ClientRepresentation extends JSONPrimitive, ServerRepresentation> extends BaseSchema<ClientRepresentation, ServerRepresentation, ScalarDef<ClientRepresentation, ServerRepresentation>> {
|
|
294
|
+
static create: <ClientRepresentation_1 extends JSONPrimitive, ServerRepresentation_1>(options: ScalarOptions<ClientRepresentation_1, ServerRepresentation_1>) => KScalar<ClientRepresentation_1, ServerRepresentation_1>;
|
|
295
|
+
constructor(def: ScalarDef<ClientRepresentation, ServerRepresentation>);
|
|
296
|
+
serialize(value: ServerRepresentation): ClientRepresentation;
|
|
297
|
+
toOpenAPI(): SchemaObject | ReferenceObject;
|
|
298
|
+
parseSafe(json: unknown): ParseResult<ServerRepresentation>;
|
|
299
|
+
parse(json: unknown): ServerRepresentation;
|
|
300
|
+
visit(visitor: (schema: BaseSchema<any, any, any>) => void): void;
|
|
301
|
+
}
|
|
302
|
+
interface UnionDef<Input extends JSONValue, Output> extends BaseSchemaDef<Input> {
|
|
303
|
+
items: [
|
|
304
|
+
a: BaseSchema<Input, Output, BaseSchemaDef<Input>>,
|
|
305
|
+
b: BaseSchema<Input, Output, BaseSchemaDef<Input>>,
|
|
306
|
+
...remaining: BaseSchema<Input, Output, BaseSchemaDef<Input>>[]
|
|
307
|
+
];
|
|
308
|
+
}
|
|
309
|
+
declare class KUnion<Input extends JSONValue, Output> extends BaseSchema<Input, Output, UnionDef<Input, Output>> {
|
|
310
|
+
static create: <Items extends [a: BaseSchema<JSONValue, unknown, BaseSchemaDef<JSONValue>>, b: BaseSchema<JSONValue, unknown, BaseSchemaDef<JSONValue>>, ...remaining: BaseSchema<JSONValue, unknown, BaseSchemaDef<JSONValue>>[]]>(items: Items) => KUnion<Items[number]["_input"], Items[number]["_output"]>;
|
|
311
|
+
static enum: <const T extends readonly [string, ...string[]]>(values: T) => KUnion<T[number], T[number]>;
|
|
312
|
+
serialize(value: Output): Input;
|
|
313
|
+
toOpenAPI(): SchemaObject | ReferenceObject;
|
|
314
|
+
parseSafe(json: unknown): ParseResult<Output>;
|
|
315
|
+
parse(json: unknown): Output;
|
|
316
|
+
visit(visitor: (schema: BaseSchema<any, any, any>) => void): void;
|
|
317
|
+
}
|
|
318
|
+
interface LiteralDef<Value extends string | number | boolean> extends BaseSchemaDef<Value> {
|
|
319
|
+
value: Value;
|
|
320
|
+
}
|
|
321
|
+
declare class KLiteral<Value extends string | number | boolean> extends BaseSchema<Value, Value, LiteralDef<Value>> {
|
|
322
|
+
parse(json: unknown): Value;
|
|
323
|
+
static create: <Value_1 extends string | number | boolean>(value: Value_1) => KLiteral<Value_1>;
|
|
324
|
+
serialize(value: Value): Value;
|
|
325
|
+
toOpenAPI(): SchemaObject;
|
|
326
|
+
parseSafe(json: unknown): ParseResult<Value>;
|
|
327
|
+
visit(): void;
|
|
328
|
+
}
|
|
329
|
+
interface NativeEnumDef<T extends Record<string, string | number>> extends BaseSchemaDef<T[keyof T]> {
|
|
330
|
+
enum: T;
|
|
331
|
+
}
|
|
332
|
+
declare class KNativeEnum<T extends Record<string, string | number>> extends BaseSchema<T[keyof T], T[keyof T], NativeEnumDef<T>> {
|
|
333
|
+
static create: <T_1 extends Record<string, string | number>>(enumObject: T_1) => KNativeEnum<T_1>;
|
|
334
|
+
serialize(value: T[keyof T]): T[keyof T];
|
|
335
|
+
toOpenAPI(): SchemaObject;
|
|
336
|
+
parseSafe(json: unknown): ParseResult<T[keyof T]>;
|
|
337
|
+
parse(json: unknown): T[keyof T];
|
|
338
|
+
visit(): void;
|
|
339
|
+
}
|
|
340
|
+
interface RecordDef<KeyInput extends string, KeyOutput extends string, ValueInput extends JSONValue, ValueOutput> extends BaseSchemaDef<Record<KeyInput, ValueInput>> {
|
|
341
|
+
keys: BaseSchema<KeyInput, KeyOutput, BaseSchemaDef<KeyInput>>;
|
|
342
|
+
values: BaseSchema<ValueInput, ValueOutput, BaseSchemaDef<ValueInput>>;
|
|
343
|
+
}
|
|
344
|
+
declare class KRecord<KeyInput extends string, KeyOutput extends string, ValueInput extends JSONValue, ValueOutput> extends BaseSchema<Record<KeyInput, ValueInput>, Record<KeyOutput, ValueOutput>, RecordDef<KeyInput, KeyOutput, ValueInput, ValueOutput>> {
|
|
345
|
+
static create: <KeyInput_1 extends string, KeyOutput_1 extends string, ValueInput_1 extends JSONValue, ValueOutput_1>(keys: BaseSchema<KeyInput_1, KeyOutput_1, BaseSchemaDef<KeyInput_1>>, values: BaseSchema<ValueInput_1, ValueOutput_1, BaseSchemaDef<ValueInput_1>>) => KRecord<KeyInput_1, KeyOutput_1, ValueInput_1, ValueOutput_1>;
|
|
346
|
+
serialize(value: Record<KeyOutput, ValueOutput>): Record<KeyInput, ValueInput>;
|
|
347
|
+
toOpenAPI(): SchemaObject;
|
|
348
|
+
parseSafe(json: unknown): ParseResult<Record<KeyOutput, ValueOutput>>;
|
|
349
|
+
parse(json: unknown): Record<KeyOutput, ValueOutput>;
|
|
350
|
+
visit(visitor: (schema: BaseSchema<any, any, any>) => void): void;
|
|
351
|
+
}
|
|
352
|
+
interface LazyDef<Input extends JSONValue, Output> extends BaseSchemaDef<Input> {
|
|
353
|
+
getter: () => BaseSchema<Input, Output, BaseSchemaDef<Input>>;
|
|
354
|
+
}
|
|
355
|
+
declare class KLazy<Input extends JSONValue, Output> extends BaseSchema<Input, Output, LazyDef<Input, Output>> {
|
|
356
|
+
private schema?;
|
|
357
|
+
static create: <Input_1 extends JSONValue, Output_1>(getter: () => BaseSchema<Input_1, Output_1, BaseSchemaDef<Input_1>>) => KLazy<Input_1, Output_1>;
|
|
358
|
+
private getSchema;
|
|
359
|
+
serialize(value: Output): Input;
|
|
360
|
+
toOpenAPI(): SchemaObject | ReferenceObject;
|
|
361
|
+
parseSafe(json: unknown): ParseResult<Output>;
|
|
362
|
+
parse(json: unknown): Output;
|
|
363
|
+
visit(visitor: (schema: BaseSchema<any, any, any>) => void): void;
|
|
364
|
+
}
|
|
365
|
+
declare const k: {
|
|
366
|
+
string: () => KString;
|
|
367
|
+
number: () => KNumber;
|
|
368
|
+
boolean: () => KBoolean;
|
|
369
|
+
array: <ItemsInput extends JSONValue, ItemsOutput, Def extends BaseSchemaDef<ItemsInput>>(items: BaseSchema<ItemsInput, ItemsOutput, Def>) => KArray<ItemsInput, ItemsOutput>;
|
|
370
|
+
null: () => KNull;
|
|
371
|
+
ref: <Input extends Record<keyof Output, JSONValue>, Output extends Record<keyof Input, any>>(name: string, shape: { [K in keyof Input | keyof Output]: BaseSchema<Input[K], Output[K], BaseSchemaDef<Input[K]>>; }) => KRef<Input, Output>;
|
|
372
|
+
record: <KeyInput extends string, KeyOutput extends string, ValueInput extends JSONValue, ValueOutput>(keys: BaseSchema<KeyInput, KeyOutput, BaseSchemaDef<KeyInput>>, values: BaseSchema<ValueInput, ValueOutput, BaseSchemaDef<ValueInput>>) => KRecord<KeyInput, KeyOutput, ValueInput, ValueOutput>;
|
|
373
|
+
object: <Input extends Record<keyof Output, any>, Output extends Record<keyof Input, any>>(shape: { [K in keyof Input | keyof Output]: BaseSchema<Input[K], Output[K], BaseSchemaDef<Input[K]>>; }) => KObject<Input, Output>;
|
|
374
|
+
scalar: <ClientRepresentation extends JSONPrimitive, ServerRepresentation>(options: ScalarOptions<ClientRepresentation, ServerRepresentation>) => KScalar<ClientRepresentation, ServerRepresentation>;
|
|
375
|
+
literal: <Value extends string | number | boolean>(value: Value) => KLiteral<Value>;
|
|
376
|
+
enum: <const T extends readonly [string, ...string[]]>(values: T) => KUnion<T[number], T[number]>;
|
|
377
|
+
nativeEnum: <T extends Record<string, string | number>>(enumObject: T) => KNativeEnum<T>;
|
|
378
|
+
union: <Items extends [a: BaseSchema<JSONValue, unknown, BaseSchemaDef<JSONValue>>, b: BaseSchema<JSONValue, unknown, BaseSchemaDef<JSONValue>>, ...remaining: BaseSchema<JSONValue, unknown, BaseSchemaDef<JSONValue>>[]]>(items: Items) => KUnion<Items[number]["_input"], Items[number]["_output"]>;
|
|
379
|
+
lazy: <Input extends JSONValue, Output>(getter: () => BaseSchema<Input, Output, BaseSchemaDef<Input>>) => KLazy<Input, Output>;
|
|
380
|
+
/**
|
|
381
|
+
* Schema for any valid JSON value
|
|
382
|
+
*/
|
|
383
|
+
json: () => BaseSchema<JSONValue, JSONValue, BaseSchemaDef<JSONValue>>;
|
|
384
|
+
/**
|
|
385
|
+
* @internal
|
|
386
|
+
* @experimental
|
|
387
|
+
*/
|
|
388
|
+
objectFromURLSearchParams: <Input extends Record<keyof Output, JSONValue>, Output extends Record<keyof Input, JSONValue>>(shape: { [K in keyof Input | keyof Output]: BaseSchema<Input[K], Output[K], BaseSchemaDef<Input[K]>>; }) => KObjectFromURLSearchParams<Input, Output>;
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
export { type AnySchemaFor, type ArrayChecks, type ArrayDef, BaseSchema, type BaseSchemaDef, type BooleanDef, type Issue, type JSONPrimitive, type JSONValue, KArray, KBoolean, KLazy, KLiteral, KNativeEnum, KNull, KNumber, KObject, KObjectFromURLSearchParams, KRecord, KRef, KScalar, KString, KUnion, type LazyDef, type LiteralDef, type NativeEnumDef, type NullDef, type NumberChecks, type NumberDef, type NumberFormat, type ObjectDef, ParseContext, type ParseResult, type RecordDef, type RefDef, STRING_FORMAT_REGEXES, type ScalarDef, type ScalarOptions, SchemaError, type StringChecks, type StringDef, type StringFormat, type UnionDef, isPrimitiveJSONValue, k };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BaseSchema,
|
|
3
|
+
KArray,
|
|
4
|
+
KBoolean,
|
|
5
|
+
KLazy,
|
|
6
|
+
KLiteral,
|
|
7
|
+
KNativeEnum,
|
|
8
|
+
KNull,
|
|
9
|
+
KNumber,
|
|
10
|
+
KObject,
|
|
11
|
+
KObjectFromURLSearchParams,
|
|
12
|
+
KRecord,
|
|
13
|
+
KRef,
|
|
14
|
+
KScalar,
|
|
15
|
+
KString,
|
|
16
|
+
KUnion,
|
|
17
|
+
ParseContext,
|
|
18
|
+
STRING_FORMAT_REGEXES,
|
|
19
|
+
SchemaError,
|
|
20
|
+
isPrimitiveJSONValue,
|
|
21
|
+
k
|
|
22
|
+
} from "../chunk-DRJX3OJG.js";
|
|
23
|
+
export {
|
|
24
|
+
BaseSchema,
|
|
25
|
+
KArray,
|
|
26
|
+
KBoolean,
|
|
27
|
+
KLazy,
|
|
28
|
+
KLiteral,
|
|
29
|
+
KNativeEnum,
|
|
30
|
+
KNull,
|
|
31
|
+
KNumber,
|
|
32
|
+
KObject,
|
|
33
|
+
KObjectFromURLSearchParams,
|
|
34
|
+
KRecord,
|
|
35
|
+
KRef,
|
|
36
|
+
KScalar,
|
|
37
|
+
KString,
|
|
38
|
+
KUnion,
|
|
39
|
+
ParseContext,
|
|
40
|
+
STRING_FORMAT_REGEXES,
|
|
41
|
+
SchemaError,
|
|
42
|
+
isPrimitiveJSONValue,
|
|
43
|
+
k
|
|
44
|
+
};
|
package/dist/stream/stream.cjs
CHANGED
|
@@ -27,39 +27,27 @@ __export(stream_exports, {
|
|
|
27
27
|
sseFromAnyReadable: () => sseFromAnyReadable
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(stream_exports);
|
|
30
|
-
var KaitoSSEResponse = class
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
headers.set("Cache-Control", "no-cache");
|
|
35
|
-
headers.set("Connection", "keep-alive");
|
|
36
|
-
super(body, {
|
|
37
|
-
...init,
|
|
38
|
-
headers
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
get [Symbol.toStringTag]() {
|
|
42
|
-
return "KaitoSSEResponse";
|
|
30
|
+
var KaitoSSEResponse = class {
|
|
31
|
+
events;
|
|
32
|
+
constructor(events) {
|
|
33
|
+
this.events = events;
|
|
43
34
|
}
|
|
44
35
|
};
|
|
45
36
|
function sseEventToString(event) {
|
|
46
|
-
|
|
37
|
+
const lines = [];
|
|
47
38
|
if (event.event) {
|
|
48
|
-
|
|
49
|
-
`;
|
|
39
|
+
lines.push(`event:${event.event}`);
|
|
50
40
|
}
|
|
51
41
|
if (event.id) {
|
|
52
|
-
|
|
53
|
-
`;
|
|
42
|
+
lines.push(`id:${event.id}`);
|
|
54
43
|
}
|
|
55
44
|
if (event.retry) {
|
|
56
|
-
|
|
57
|
-
`;
|
|
45
|
+
lines.push(`retry:${event.retry}`);
|
|
58
46
|
}
|
|
59
47
|
if (event.data !== void 0) {
|
|
60
|
-
|
|
48
|
+
lines.push(`data:${JSON.stringify(event.data)}`);
|
|
61
49
|
}
|
|
62
|
-
return
|
|
50
|
+
return lines.join("\n");
|
|
63
51
|
}
|
|
64
52
|
var SSEController = class {
|
|
65
53
|
controller;
|
|
@@ -67,7 +55,7 @@ var SSEController = class {
|
|
|
67
55
|
this.controller = controller;
|
|
68
56
|
}
|
|
69
57
|
enqueue(event) {
|
|
70
|
-
this.controller.enqueue(
|
|
58
|
+
this.controller.enqueue(event);
|
|
71
59
|
}
|
|
72
60
|
close() {
|
|
73
61
|
this.controller.close();
|
package/dist/stream/stream.d.cts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { JSONValue } from '../schema/schema.cjs';
|
|
2
|
+
import 'openapi3-ts/oas31';
|
|
3
|
+
|
|
4
|
+
declare class KaitoSSEResponse<T> {
|
|
5
|
+
readonly events: ReadableStream<T>;
|
|
6
|
+
constructor(events: ReadableStream<T>);
|
|
4
7
|
}
|
|
5
8
|
type SSEEvent<T, E extends string> = ({
|
|
6
9
|
data: T;
|
|
@@ -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, E extends string, T extends SSEEvent<U, E>> implements Disposable {
|
|
22
25
|
private readonly controller;
|
|
23
|
-
constructor(controller: ReadableStreamDefaultController<
|
|
24
|
-
enqueue(event:
|
|
26
|
+
constructor(controller: ReadableStreamDefaultController<T>);
|
|
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, 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>;
|
|
36
|
+
declare function sse<U, E extends string, T extends SSEEvent<U, E>>(source: SSESource<U, E, T> | AsyncGenerator<T, unknown, unknown> | (() => AsyncGenerator<T, unknown, unknown>)): KaitoSSEResponse<T>;
|
|
34
37
|
declare function sseFromAnyReadable<R, U, 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,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { JSONValue } from '../schema/schema.js';
|
|
2
|
+
import 'openapi3-ts/oas31';
|
|
3
|
+
|
|
4
|
+
declare class KaitoSSEResponse<T> {
|
|
5
|
+
readonly events: ReadableStream<T>;
|
|
6
|
+
constructor(events: ReadableStream<T>);
|
|
4
7
|
}
|
|
5
8
|
type SSEEvent<T, E extends string> = ({
|
|
6
9
|
data: T;
|
|
@@ -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, E extends string, T extends SSEEvent<U, E>> implements Disposable {
|
|
22
25
|
private readonly controller;
|
|
23
|
-
constructor(controller: ReadableStreamDefaultController<
|
|
24
|
-
enqueue(event:
|
|
26
|
+
constructor(controller: ReadableStreamDefaultController<T>);
|
|
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, 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>;
|
|
36
|
+
declare function sse<U, E extends string, T extends SSEEvent<U, E>>(source: SSESource<U, E, T> | AsyncGenerator<T, unknown, unknown> | (() => AsyncGenerator<T, unknown, unknown>)): KaitoSSEResponse<T>;
|
|
34
37
|
declare function sseFromAnyReadable<R, U, 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 };
|