@kaito-http/core 4.0.0-beta.31 → 4.0.0-beta.32
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/index.cjs +7 -8
- package/dist/index.d.cts +26 -14
- package/dist/index.d.ts +26 -14
- package/dist/index.js +7 -8
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1263,8 +1263,7 @@ var Router = class _Router {
|
|
|
1263
1263
|
params: rawParams
|
|
1264
1264
|
});
|
|
1265
1265
|
if (result instanceof KaitoSSEResponse) {
|
|
1266
|
-
const
|
|
1267
|
-
const schema = body2 && "schema" in body2 ? body2.schema : void 0;
|
|
1266
|
+
const schema = route.openapi && "schema" in route.openapi ? route.openapi.schema : void 0;
|
|
1268
1267
|
const stringStream = result.events.pipeThrough(
|
|
1269
1268
|
new TransformStream({
|
|
1270
1269
|
transform(event, controller) {
|
|
@@ -1296,8 +1295,8 @@ var Router = class _Router {
|
|
|
1296
1295
|
}
|
|
1297
1296
|
return result;
|
|
1298
1297
|
}
|
|
1299
|
-
if (route.openapi && "schema" in route.openapi
|
|
1300
|
-
const parsed = route.openapi.
|
|
1298
|
+
if (route.openapi && "schema" in route.openapi && route.openapi.schema) {
|
|
1299
|
+
const parsed = route.openapi.schema.serialize(result);
|
|
1301
1300
|
return head.toResponse(parsed);
|
|
1302
1301
|
}
|
|
1303
1302
|
if (result === void 0) {
|
|
@@ -1417,7 +1416,7 @@ var Router = class _Router {
|
|
|
1417
1416
|
paths[pathWithColonParamsReplaceWithCurlyBraces] = {};
|
|
1418
1417
|
}
|
|
1419
1418
|
let contentType;
|
|
1420
|
-
const type = route.openapi.
|
|
1419
|
+
const type = route.openapi.type;
|
|
1421
1420
|
switch (type) {
|
|
1422
1421
|
case "json":
|
|
1423
1422
|
contentType = "application/json";
|
|
@@ -1431,15 +1430,15 @@ var Router = class _Router {
|
|
|
1431
1430
|
default:
|
|
1432
1431
|
throw new Error(`Unknown output type in route ${route.method} ${route.path}: ${type}`);
|
|
1433
1432
|
}
|
|
1434
|
-
if ("schema" in route.openapi
|
|
1433
|
+
if ("schema" in route.openapi && route.openapi.schema) visit(route.openapi.schema);
|
|
1435
1434
|
if (route.body) visit(route.body);
|
|
1436
|
-
const responseSchema = "schema" in route.openapi
|
|
1435
|
+
const responseSchema = "schema" in route.openapi && route.openapi.schema ? route.openapi.schema.toOpenAPI() : { type: "string" };
|
|
1437
1436
|
const item = {
|
|
1438
1437
|
...route.openapi.summary ? { summary: route.openapi.summary } : {},
|
|
1439
1438
|
description: route.openapi?.description ?? "Successful response",
|
|
1440
1439
|
responses: {
|
|
1441
1440
|
200: {
|
|
1442
|
-
description: route.openapi.
|
|
1441
|
+
description: route.openapi.description ?? "Successful response",
|
|
1443
1442
|
content: {
|
|
1444
1443
|
[contentType]: {
|
|
1445
1444
|
schema: responseSchema
|
package/dist/index.d.cts
CHANGED
|
@@ -157,33 +157,45 @@ type AnyQuery = {
|
|
|
157
157
|
[key in string]: any;
|
|
158
158
|
};
|
|
159
159
|
type Through<From, To, RequiredParams extends string> = (context: From, params: Record<RequiredParams, string>) => Promise<To>;
|
|
160
|
-
|
|
160
|
+
/**
|
|
161
|
+
* Wraps BaseSchema to prevent the schema from participating in inference for `Output`.
|
|
162
|
+
*
|
|
163
|
+
* BaseSchema's `_output` is covariant (readonly), which means when both `run()` and the schema
|
|
164
|
+
* compete to infer `ResultOutput`, TypeScript widens to the less specific type (e.g. `string`
|
|
165
|
+
* instead of `"us-east-1"`). `NoInfer` ensures `Output` is only inferred from
|
|
166
|
+
* `run()`, and the schema only checks against it via the contravariant `serialize` property.
|
|
167
|
+
*
|
|
168
|
+
* @see https://github.com/microsoft/TypeScript/issues/51756
|
|
169
|
+
*/
|
|
170
|
+
type OutputSchema<Output> = BaseSchema<any, any, any> & {
|
|
171
|
+
serialize: (value: NoInfer<Output>) => JSONValue;
|
|
172
|
+
};
|
|
173
|
+
type SSEOutputSpecWithSchema<Output> = {
|
|
161
174
|
type: 'sse';
|
|
162
|
-
schema:
|
|
175
|
+
schema: OutputSchema<Output>;
|
|
176
|
+
summary?: string | undefined;
|
|
163
177
|
description?: string | undefined;
|
|
164
178
|
};
|
|
165
179
|
type SSEOutputSpecWithoutSchema = {
|
|
166
180
|
type: 'sse';
|
|
167
181
|
schema?: undefined;
|
|
182
|
+
summary?: string | undefined;
|
|
168
183
|
description?: string | undefined;
|
|
169
184
|
};
|
|
170
|
-
type SSEOutputSpec = SSEOutputSpecWithSchema | SSEOutputSpecWithoutSchema;
|
|
171
|
-
type JSONOutputSpec = {
|
|
185
|
+
type SSEOutputSpec<Output> = SSEOutputSpecWithSchema<Output> | SSEOutputSpecWithoutSchema;
|
|
186
|
+
type JSONOutputSpec<Output> = {
|
|
172
187
|
type: 'json';
|
|
173
|
-
schema:
|
|
188
|
+
schema: OutputSchema<Output>;
|
|
189
|
+
summary?: string | undefined;
|
|
174
190
|
description?: string | undefined;
|
|
175
191
|
};
|
|
176
192
|
type ResponseOutputSpec = {
|
|
177
193
|
type: 'response';
|
|
194
|
+
summary?: string | undefined;
|
|
178
195
|
description?: string | undefined;
|
|
179
196
|
};
|
|
180
|
-
type
|
|
181
|
-
type
|
|
182
|
-
summary?: string;
|
|
183
|
-
description?: string;
|
|
184
|
-
body: Body;
|
|
185
|
-
};
|
|
186
|
-
type OpenAPISpecFor<ResultOutput> = 0 extends 1 & ResultOutput ? OpenAPISpec : [ResultOutput] extends [never] ? OpenAPISpec : [ResultOutput] extends [KaitoSSEResponse<any>] ? [ResultOutput extends KaitoSSEResponse<SSEEvent<infer U, any>> ? U : never] extends [JSONValue] ? OpenAPISpec<SSEOutputSpec> : OpenAPISpec<SSEOutputSpecWithSchema> : [ResultOutput] extends [Response] ? OpenAPISpec<ResponseOutputSpec> : OpenAPISpec<JSONOutputSpec>;
|
|
197
|
+
type AnyOutputSpec = SSEOutputSpec<any> | JSONOutputSpec<any> | ResponseOutputSpec;
|
|
198
|
+
type OpenAPISpecFor<ResultOutput> = [ResultOutput] extends [never] ? AnyOutputSpec : [ResultOutput] extends [KaitoSSEResponse<infer Event>] ? Event extends SSEEvent<infer U, any> ? [U] extends [JSONValue] ? SSEOutputSpec<Event> : SSEOutputSpecWithSchema<Event> : SSEOutputSpec<any> : [ResultOutput] extends [Response] ? ResponseOutputSpec : JSONOutputSpec<ResultOutput>;
|
|
187
199
|
type Route<ContextFrom, ContextTo, RouterInput extends readonly unknown[], ResultOutput, Path extends string, AdditionalParams extends string, Method extends KaitoMethod, Query extends Record<string, JSONValue>, BodyInput extends JSONValue, BodyOutput> = {
|
|
188
200
|
body?: BaseSchema<BodyInput, BodyOutput, BaseSchemaDef<BodyInput>>;
|
|
189
201
|
query?: {
|
|
@@ -191,7 +203,7 @@ type Route<ContextFrom, ContextTo, RouterInput extends readonly unknown[], Resul
|
|
|
191
203
|
};
|
|
192
204
|
path: Path;
|
|
193
205
|
method: Method;
|
|
194
|
-
openapi?:
|
|
206
|
+
openapi?: AnyOutputSpec;
|
|
195
207
|
router: Router<ContextFrom, ContextTo, AdditionalParams, AnyRoute, RouterInput>;
|
|
196
208
|
run(data: RouteRunData<ExtractRouteParams<Path> | AdditionalParams, ContextTo, Query, BodyOutput>): Promise<ResultOutput> | ResultOutput;
|
|
197
209
|
};
|
|
@@ -297,4 +309,4 @@ interface KaitoConfig<ContextFrom, Input extends readonly unknown[]> {
|
|
|
297
309
|
*/
|
|
298
310
|
declare const create: <Context = null, Input extends readonly unknown[] = []>(config?: KaitoConfig<Context, Input>) => Router<Context, Context, never, never, Input>;
|
|
299
311
|
|
|
300
|
-
export { type AnyQuery, type AnyRoute, AnySchemaFor, BaseSchema, BaseSchemaDef, type ExtractRouteParams, type GetContext, type InferRoutes, type JSONOutputSpec, JSONValue, type KaitoConfig, KaitoError, KaitoHead, type KaitoMethod, KaitoRequest, type MaybePromise, type
|
|
312
|
+
export { type AnyOutputSpec, type AnyQuery, type AnyRoute, AnySchemaFor, BaseSchema, BaseSchemaDef, type ExtractRouteParams, type GetContext, type InferRoutes, type JSONOutputSpec, JSONValue, type KaitoConfig, KaitoError, KaitoHead, type KaitoMethod, KaitoRequest, type MaybePromise, type OpenAPISpecFor, type ResponseOutputSpec, type Route, type RouteRunData, Router, type RouterState, type SSEOutputSpec, type SSEOutputSpecWithSchema, type SSEOutputSpecWithoutSchema, type Through, WrappedError, create, isNodeLikeDev };
|
package/dist/index.d.ts
CHANGED
|
@@ -157,33 +157,45 @@ type AnyQuery = {
|
|
|
157
157
|
[key in string]: any;
|
|
158
158
|
};
|
|
159
159
|
type Through<From, To, RequiredParams extends string> = (context: From, params: Record<RequiredParams, string>) => Promise<To>;
|
|
160
|
-
|
|
160
|
+
/**
|
|
161
|
+
* Wraps BaseSchema to prevent the schema from participating in inference for `Output`.
|
|
162
|
+
*
|
|
163
|
+
* BaseSchema's `_output` is covariant (readonly), which means when both `run()` and the schema
|
|
164
|
+
* compete to infer `ResultOutput`, TypeScript widens to the less specific type (e.g. `string`
|
|
165
|
+
* instead of `"us-east-1"`). `NoInfer` ensures `Output` is only inferred from
|
|
166
|
+
* `run()`, and the schema only checks against it via the contravariant `serialize` property.
|
|
167
|
+
*
|
|
168
|
+
* @see https://github.com/microsoft/TypeScript/issues/51756
|
|
169
|
+
*/
|
|
170
|
+
type OutputSchema<Output> = BaseSchema<any, any, any> & {
|
|
171
|
+
serialize: (value: NoInfer<Output>) => JSONValue;
|
|
172
|
+
};
|
|
173
|
+
type SSEOutputSpecWithSchema<Output> = {
|
|
161
174
|
type: 'sse';
|
|
162
|
-
schema:
|
|
175
|
+
schema: OutputSchema<Output>;
|
|
176
|
+
summary?: string | undefined;
|
|
163
177
|
description?: string | undefined;
|
|
164
178
|
};
|
|
165
179
|
type SSEOutputSpecWithoutSchema = {
|
|
166
180
|
type: 'sse';
|
|
167
181
|
schema?: undefined;
|
|
182
|
+
summary?: string | undefined;
|
|
168
183
|
description?: string | undefined;
|
|
169
184
|
};
|
|
170
|
-
type SSEOutputSpec = SSEOutputSpecWithSchema | SSEOutputSpecWithoutSchema;
|
|
171
|
-
type JSONOutputSpec = {
|
|
185
|
+
type SSEOutputSpec<Output> = SSEOutputSpecWithSchema<Output> | SSEOutputSpecWithoutSchema;
|
|
186
|
+
type JSONOutputSpec<Output> = {
|
|
172
187
|
type: 'json';
|
|
173
|
-
schema:
|
|
188
|
+
schema: OutputSchema<Output>;
|
|
189
|
+
summary?: string | undefined;
|
|
174
190
|
description?: string | undefined;
|
|
175
191
|
};
|
|
176
192
|
type ResponseOutputSpec = {
|
|
177
193
|
type: 'response';
|
|
194
|
+
summary?: string | undefined;
|
|
178
195
|
description?: string | undefined;
|
|
179
196
|
};
|
|
180
|
-
type
|
|
181
|
-
type
|
|
182
|
-
summary?: string;
|
|
183
|
-
description?: string;
|
|
184
|
-
body: Body;
|
|
185
|
-
};
|
|
186
|
-
type OpenAPISpecFor<ResultOutput> = 0 extends 1 & ResultOutput ? OpenAPISpec : [ResultOutput] extends [never] ? OpenAPISpec : [ResultOutput] extends [KaitoSSEResponse<any>] ? [ResultOutput extends KaitoSSEResponse<SSEEvent<infer U, any>> ? U : never] extends [JSONValue] ? OpenAPISpec<SSEOutputSpec> : OpenAPISpec<SSEOutputSpecWithSchema> : [ResultOutput] extends [Response] ? OpenAPISpec<ResponseOutputSpec> : OpenAPISpec<JSONOutputSpec>;
|
|
197
|
+
type AnyOutputSpec = SSEOutputSpec<any> | JSONOutputSpec<any> | ResponseOutputSpec;
|
|
198
|
+
type OpenAPISpecFor<ResultOutput> = [ResultOutput] extends [never] ? AnyOutputSpec : [ResultOutput] extends [KaitoSSEResponse<infer Event>] ? Event extends SSEEvent<infer U, any> ? [U] extends [JSONValue] ? SSEOutputSpec<Event> : SSEOutputSpecWithSchema<Event> : SSEOutputSpec<any> : [ResultOutput] extends [Response] ? ResponseOutputSpec : JSONOutputSpec<ResultOutput>;
|
|
187
199
|
type Route<ContextFrom, ContextTo, RouterInput extends readonly unknown[], ResultOutput, Path extends string, AdditionalParams extends string, Method extends KaitoMethod, Query extends Record<string, JSONValue>, BodyInput extends JSONValue, BodyOutput> = {
|
|
188
200
|
body?: BaseSchema<BodyInput, BodyOutput, BaseSchemaDef<BodyInput>>;
|
|
189
201
|
query?: {
|
|
@@ -191,7 +203,7 @@ type Route<ContextFrom, ContextTo, RouterInput extends readonly unknown[], Resul
|
|
|
191
203
|
};
|
|
192
204
|
path: Path;
|
|
193
205
|
method: Method;
|
|
194
|
-
openapi?:
|
|
206
|
+
openapi?: AnyOutputSpec;
|
|
195
207
|
router: Router<ContextFrom, ContextTo, AdditionalParams, AnyRoute, RouterInput>;
|
|
196
208
|
run(data: RouteRunData<ExtractRouteParams<Path> | AdditionalParams, ContextTo, Query, BodyOutput>): Promise<ResultOutput> | ResultOutput;
|
|
197
209
|
};
|
|
@@ -297,4 +309,4 @@ interface KaitoConfig<ContextFrom, Input extends readonly unknown[]> {
|
|
|
297
309
|
*/
|
|
298
310
|
declare const create: <Context = null, Input extends readonly unknown[] = []>(config?: KaitoConfig<Context, Input>) => Router<Context, Context, never, never, Input>;
|
|
299
311
|
|
|
300
|
-
export { type AnyQuery, type AnyRoute, AnySchemaFor, BaseSchema, BaseSchemaDef, type ExtractRouteParams, type GetContext, type InferRoutes, type JSONOutputSpec, JSONValue, type KaitoConfig, KaitoError, KaitoHead, type KaitoMethod, KaitoRequest, type MaybePromise, type
|
|
312
|
+
export { type AnyOutputSpec, type AnyQuery, type AnyRoute, AnySchemaFor, BaseSchema, BaseSchemaDef, type ExtractRouteParams, type GetContext, type InferRoutes, type JSONOutputSpec, JSONValue, type KaitoConfig, KaitoError, KaitoHead, type KaitoMethod, KaitoRequest, type MaybePromise, type OpenAPISpecFor, type ResponseOutputSpec, type Route, type RouteRunData, Router, type RouterState, type SSEOutputSpec, type SSEOutputSpecWithSchema, type SSEOutputSpecWithoutSchema, type Through, WrappedError, create, isNodeLikeDev };
|
package/dist/index.js
CHANGED
|
@@ -233,8 +233,7 @@ var Router = class _Router {
|
|
|
233
233
|
params: rawParams
|
|
234
234
|
});
|
|
235
235
|
if (result instanceof KaitoSSEResponse) {
|
|
236
|
-
const
|
|
237
|
-
const schema = body2 && "schema" in body2 ? body2.schema : void 0;
|
|
236
|
+
const schema = route.openapi && "schema" in route.openapi ? route.openapi.schema : void 0;
|
|
238
237
|
const stringStream = result.events.pipeThrough(
|
|
239
238
|
new TransformStream({
|
|
240
239
|
transform(event, controller) {
|
|
@@ -266,8 +265,8 @@ var Router = class _Router {
|
|
|
266
265
|
}
|
|
267
266
|
return result;
|
|
268
267
|
}
|
|
269
|
-
if (route.openapi && "schema" in route.openapi
|
|
270
|
-
const parsed = route.openapi.
|
|
268
|
+
if (route.openapi && "schema" in route.openapi && route.openapi.schema) {
|
|
269
|
+
const parsed = route.openapi.schema.serialize(result);
|
|
271
270
|
return head.toResponse(parsed);
|
|
272
271
|
}
|
|
273
272
|
if (result === void 0) {
|
|
@@ -387,7 +386,7 @@ var Router = class _Router {
|
|
|
387
386
|
paths[pathWithColonParamsReplaceWithCurlyBraces] = {};
|
|
388
387
|
}
|
|
389
388
|
let contentType;
|
|
390
|
-
const type = route.openapi.
|
|
389
|
+
const type = route.openapi.type;
|
|
391
390
|
switch (type) {
|
|
392
391
|
case "json":
|
|
393
392
|
contentType = "application/json";
|
|
@@ -401,15 +400,15 @@ var Router = class _Router {
|
|
|
401
400
|
default:
|
|
402
401
|
throw new Error(`Unknown output type in route ${route.method} ${route.path}: ${type}`);
|
|
403
402
|
}
|
|
404
|
-
if ("schema" in route.openapi
|
|
403
|
+
if ("schema" in route.openapi && route.openapi.schema) visit(route.openapi.schema);
|
|
405
404
|
if (route.body) visit(route.body);
|
|
406
|
-
const responseSchema = "schema" in route.openapi
|
|
405
|
+
const responseSchema = "schema" in route.openapi && route.openapi.schema ? route.openapi.schema.toOpenAPI() : { type: "string" };
|
|
407
406
|
const item = {
|
|
408
407
|
...route.openapi.summary ? { summary: route.openapi.summary } : {},
|
|
409
408
|
description: route.openapi?.description ?? "Successful response",
|
|
410
409
|
responses: {
|
|
411
410
|
200: {
|
|
412
|
-
description: route.openapi.
|
|
411
|
+
description: route.openapi.description ?? "Successful response",
|
|
413
412
|
content: {
|
|
414
413
|
[contentType]: {
|
|
415
414
|
schema: responseSchema
|