@kaito-http/core 4.0.0-beta.16 → 4.0.0-beta.17
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 +21 -19
- package/dist/index.d.cts +3 -4
- package/dist/index.d.ts +3 -4
- package/dist/index.js +21 -19
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1151,36 +1151,38 @@ var Router = class _Router {
|
|
|
1151
1151
|
const OPENAPI_VERSION = "3.1.0";
|
|
1152
1152
|
const paths = {};
|
|
1153
1153
|
for (const route of this.#state.routes) {
|
|
1154
|
-
const path = route.path;
|
|
1155
1154
|
if (!route.openapi) {
|
|
1156
1155
|
continue;
|
|
1157
1156
|
}
|
|
1158
|
-
const pathWithColonParamsReplaceWithCurlyBraces = path.replace(/:(\w+)/g, "{$1}");
|
|
1157
|
+
const pathWithColonParamsReplaceWithCurlyBraces = route.path.replace(/:(\w+)/g, "{$1}");
|
|
1159
1158
|
if (!paths[pathWithColonParamsReplaceWithCurlyBraces]) {
|
|
1160
1159
|
paths[pathWithColonParamsReplaceWithCurlyBraces] = {};
|
|
1161
1160
|
}
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
}
|
|
1174
|
-
"text/event-stream": {
|
|
1175
|
-
schema: route.openapi.body.schema.toOpenAPI()
|
|
1176
|
-
}
|
|
1177
|
-
};
|
|
1161
|
+
let contentType;
|
|
1162
|
+
const type = route.openapi.type;
|
|
1163
|
+
switch (type) {
|
|
1164
|
+
case "json":
|
|
1165
|
+
contentType = "application/json";
|
|
1166
|
+
break;
|
|
1167
|
+
case "sse":
|
|
1168
|
+
contentType = "text/event-stream";
|
|
1169
|
+
break;
|
|
1170
|
+
default:
|
|
1171
|
+
throw new Error(`Unknown output type in route ${route.method} ${route.path}: ${type}`);
|
|
1172
|
+
}
|
|
1178
1173
|
const item = {
|
|
1179
1174
|
description: route.openapi?.description ?? "Successful response",
|
|
1180
1175
|
responses: {
|
|
1181
1176
|
200: {
|
|
1182
1177
|
description: route.openapi?.description ?? "Successful response",
|
|
1183
|
-
content
|
|
1178
|
+
content: {
|
|
1179
|
+
[contentType]: {
|
|
1180
|
+
schema: k.object({
|
|
1181
|
+
success: k.literal(true),
|
|
1182
|
+
data: route.openapi.schema
|
|
1183
|
+
}).toOpenAPI()
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1184
1186
|
}
|
|
1185
1187
|
}
|
|
1186
1188
|
};
|
package/dist/index.d.cts
CHANGED
|
@@ -132,9 +132,8 @@ type JSONOutputSpec<Result extends JSONValue> = {
|
|
|
132
132
|
schema: AnySchemaFor<Result>;
|
|
133
133
|
description?: string;
|
|
134
134
|
};
|
|
135
|
-
type OutputSpec<Result> = {
|
|
135
|
+
type OutputSpec<Result> = Result extends KaitoSSEResponse<infer R> ? SSEOutputSpec<Extract<R, JSONValue>> : JSONOutputSpec<Extract<Result, JSONValue>> & {
|
|
136
136
|
description?: string;
|
|
137
|
-
body: Result extends KaitoSSEResponse<infer R> ? SSEOutputSpec<Extract<R, JSONValue>> : JSONOutputSpec<Extract<Result, JSONValue>>;
|
|
138
137
|
};
|
|
139
138
|
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
139
|
body?: AnySchemaFor<Body>;
|
|
@@ -143,11 +142,11 @@ type Route<ContextFrom, ContextTo, RouterInput extends readonly unknown[], Resul
|
|
|
143
142
|
};
|
|
144
143
|
path: Path;
|
|
145
144
|
method: Method;
|
|
146
|
-
openapi?: OutputSpec<
|
|
145
|
+
openapi?: NoInfer<OutputSpec<Result>>;
|
|
147
146
|
router: Router<ContextFrom, ContextTo, AdditionalParams, AnyRoute, RouterInput>;
|
|
148
147
|
run(data: RouteRunData<ExtractRouteParams<Path> | AdditionalParams, ContextTo, Query, Body>): Promise<Result> | Result;
|
|
149
148
|
};
|
|
150
|
-
type AnyRoute = Route<any, any, any, any,
|
|
149
|
+
type AnyRoute = Route<any, any, any, any, string, any, KaitoMethod, any, any>;
|
|
151
150
|
|
|
152
151
|
/**
|
|
153
152
|
* A helper to check if the environment is Node.js-like and the `NODE_ENV` environment variable is set to `'development'`
|
package/dist/index.d.ts
CHANGED
|
@@ -132,9 +132,8 @@ type JSONOutputSpec<Result extends JSONValue> = {
|
|
|
132
132
|
schema: AnySchemaFor<Result>;
|
|
133
133
|
description?: string;
|
|
134
134
|
};
|
|
135
|
-
type OutputSpec<Result> = {
|
|
135
|
+
type OutputSpec<Result> = Result extends KaitoSSEResponse<infer R> ? SSEOutputSpec<Extract<R, JSONValue>> : JSONOutputSpec<Extract<Result, JSONValue>> & {
|
|
136
136
|
description?: string;
|
|
137
|
-
body: Result extends KaitoSSEResponse<infer R> ? SSEOutputSpec<Extract<R, JSONValue>> : JSONOutputSpec<Extract<Result, JSONValue>>;
|
|
138
137
|
};
|
|
139
138
|
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
139
|
body?: AnySchemaFor<Body>;
|
|
@@ -143,11 +142,11 @@ type Route<ContextFrom, ContextTo, RouterInput extends readonly unknown[], Resul
|
|
|
143
142
|
};
|
|
144
143
|
path: Path;
|
|
145
144
|
method: Method;
|
|
146
|
-
openapi?: OutputSpec<
|
|
145
|
+
openapi?: NoInfer<OutputSpec<Result>>;
|
|
147
146
|
router: Router<ContextFrom, ContextTo, AdditionalParams, AnyRoute, RouterInput>;
|
|
148
147
|
run(data: RouteRunData<ExtractRouteParams<Path> | AdditionalParams, ContextTo, Query, Body>): Promise<Result> | Result;
|
|
149
148
|
};
|
|
150
|
-
type AnyRoute = Route<any, any, any, any,
|
|
149
|
+
type AnyRoute = Route<any, any, any, any, string, any, KaitoMethod, any, any>;
|
|
151
150
|
|
|
152
151
|
/**
|
|
153
152
|
* A helper to check if the environment is Node.js-like and the `NODE_ENV` environment variable is set to `'development'`
|
package/dist/index.js
CHANGED
|
@@ -318,36 +318,38 @@ var Router = class _Router {
|
|
|
318
318
|
const OPENAPI_VERSION = "3.1.0";
|
|
319
319
|
const paths = {};
|
|
320
320
|
for (const route of this.#state.routes) {
|
|
321
|
-
const path = route.path;
|
|
322
321
|
if (!route.openapi) {
|
|
323
322
|
continue;
|
|
324
323
|
}
|
|
325
|
-
const pathWithColonParamsReplaceWithCurlyBraces = path.replace(/:(\w+)/g, "{$1}");
|
|
324
|
+
const pathWithColonParamsReplaceWithCurlyBraces = route.path.replace(/:(\w+)/g, "{$1}");
|
|
326
325
|
if (!paths[pathWithColonParamsReplaceWithCurlyBraces]) {
|
|
327
326
|
paths[pathWithColonParamsReplaceWithCurlyBraces] = {};
|
|
328
327
|
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
}
|
|
341
|
-
"text/event-stream": {
|
|
342
|
-
schema: route.openapi.body.schema.toOpenAPI()
|
|
343
|
-
}
|
|
344
|
-
};
|
|
328
|
+
let contentType;
|
|
329
|
+
const type = route.openapi.type;
|
|
330
|
+
switch (type) {
|
|
331
|
+
case "json":
|
|
332
|
+
contentType = "application/json";
|
|
333
|
+
break;
|
|
334
|
+
case "sse":
|
|
335
|
+
contentType = "text/event-stream";
|
|
336
|
+
break;
|
|
337
|
+
default:
|
|
338
|
+
throw new Error(`Unknown output type in route ${route.method} ${route.path}: ${type}`);
|
|
339
|
+
}
|
|
345
340
|
const item = {
|
|
346
341
|
description: route.openapi?.description ?? "Successful response",
|
|
347
342
|
responses: {
|
|
348
343
|
200: {
|
|
349
344
|
description: route.openapi?.description ?? "Successful response",
|
|
350
|
-
content
|
|
345
|
+
content: {
|
|
346
|
+
[contentType]: {
|
|
347
|
+
schema: k.object({
|
|
348
|
+
success: k.literal(true),
|
|
349
|
+
data: route.openapi.schema
|
|
350
|
+
}).toOpenAPI()
|
|
351
|
+
}
|
|
352
|
+
}
|
|
351
353
|
}
|
|
352
354
|
}
|
|
353
355
|
};
|