@kaito-http/core 4.0.0-beta.11 → 4.0.0-beta.14
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 +797 -0
- package/dist/index.cjs +874 -90
- package/dist/index.d.cts +90 -109
- package/dist/index.d.ts +90 -109
- package/dist/index.js +98 -91
- package/dist/schema/schema.cjs +837 -0
- package/dist/schema/schema.d.cts +326 -0
- package/dist/schema/schema.d.ts +326 -0
- package/dist/schema/schema.js +38 -0
- package/package.json +6 -9
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as OpenAPI from 'openapi3-ts/oas31';
|
|
2
|
+
import { JSONValue, AnySchemaFor } from './schema/schema.cjs';
|
|
3
|
+
export { ArrayChecks, ArrayDef, BaseSchema, BaseSchemaDef, BooleanDef, Issue, JSONPrimitive, KArray, KBoolean, KLiteral, KNull, KNumber, KObject, KObjectFromURLSearchParams, KRef, KScalar, KString, KUnion, LiteralDef, NullDef, NumberChecks, NumberDef, NumberFormat, ObjectDef, ParseContext, ParseResult, RefDef, STRING_FORMAT_REGEXES, ScalarDef, ScalarOptions, SchemaError, StringChecks, StringDef, StringFormat, UnionDef, isPrimitiveJSONValue, k } from './schema/schema.cjs';
|
|
2
4
|
import { KaitoSSEResponse } from './stream/stream.cjs';
|
|
3
5
|
|
|
4
6
|
declare class WrappedError<T> extends Error {
|
|
@@ -72,90 +74,98 @@ declare class KaitoHead {
|
|
|
72
74
|
get touched(): boolean;
|
|
73
75
|
}
|
|
74
76
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
data: null;
|
|
82
|
-
message: string;
|
|
83
|
-
};
|
|
84
|
-
type SuccessfulAPIResponse<T> = {
|
|
85
|
-
success: true;
|
|
86
|
-
data: T;
|
|
87
|
-
};
|
|
88
|
-
type APIResponse<T> = ErroredAPIResponse | SuccessfulAPIResponse<T>;
|
|
89
|
-
type AnyResponse = APIResponse<unknown>;
|
|
90
|
-
type MakeOptional<T, K extends keyof T> = T extends T ? Omit<T, K> & Partial<Pick<T, K>> : never;
|
|
91
|
-
type MaybePromise<T> = T | Promise<T>;
|
|
92
|
-
type KaitoMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS';
|
|
93
|
-
type NotReadonly<T> = {
|
|
94
|
-
-readonly [K in keyof T]: T[K];
|
|
77
|
+
type PrefixRoutesPathInner<R extends AnyRoute, Prefix extends `/${string}`> = R extends Route<infer ContextFrom, infer ContextTo, infer RouterInput, infer Result, infer Path, infer AdditionalParams, infer Method, infer Query, infer BodyOutput> ? Route<ContextFrom, ContextTo, RouterInput, Result, `${Prefix}${Path extends '/' ? '' : Path}`, AdditionalParams, Method, Query, BodyOutput> : never;
|
|
78
|
+
type PrefixRoutesPath<Prefix extends `/${string}`, R extends AnyRoute> = R extends R ? PrefixRoutesPathInner<R, Prefix> : never;
|
|
79
|
+
type RouterState<ContextFrom, ContextTo, RequiredParams extends string, Routes extends AnyRoute, Input extends readonly unknown[]> = {
|
|
80
|
+
routes: Set<Routes>;
|
|
81
|
+
through: (context: ContextFrom, params: Record<RequiredParams, string>) => Promise<ContextTo> | ContextTo;
|
|
82
|
+
config: KaitoConfig<ContextFrom, Input>;
|
|
95
83
|
};
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
84
|
+
declare class Router<ContextFrom, ContextTo, RequiredParams extends string, R extends AnyRoute, Input extends readonly unknown[]> {
|
|
85
|
+
#private;
|
|
86
|
+
static create: <Context = null, Input_1 extends readonly unknown[] = []>(config?: KaitoConfig<Context, Input_1>) => Router<Context, Context, never, never, Input_1>;
|
|
87
|
+
protected constructor(state: RouterState<ContextFrom, ContextTo, RequiredParams, R, Input>);
|
|
88
|
+
get routes(): Set<R>;
|
|
89
|
+
private readonly add;
|
|
90
|
+
readonly params: [RequiredParams] extends [never] ? <NextParams extends string>() => Router<ContextFrom, ContextTo, NextParams, R, Input> : () => Router<ContextFrom, ContextTo, RequiredParams, R, Input>;
|
|
91
|
+
readonly merge: <PathPrefix extends `/${string}`, NextRequiredParams extends string, OtherRoutes extends AnyRoute>(pathPrefix: [NextRequiredParams] extends [ExtractRouteParams<PathPrefix> | RequiredParams] ? PathPrefix : `/:${Exclude<NextRequiredParams, ExtractRouteParams<PathPrefix> | RequiredParams>}`, other: Router<ContextFrom, ContextTo, NextRequiredParams, OtherRoutes, Input>) => Router<ContextFrom, ContextTo, RequiredParams, Extract<R | PrefixRoutesPath<PathPrefix, Extract<OtherRoutes, AnyRoute>>, AnyRoute>, Input>;
|
|
92
|
+
protected static getFindRoute: <R_1>(routes: Map<KaitoMethod, Map<string, R_1>>) => (method: KaitoMethod, path: string) => {
|
|
93
|
+
route?: never;
|
|
94
|
+
params?: never;
|
|
95
|
+
} | {
|
|
96
|
+
route: R_1;
|
|
97
|
+
params: Record<string, string>;
|
|
98
|
+
};
|
|
99
|
+
serve: () => (request: Request, ...args: Input) => Promise<Response>;
|
|
100
|
+
openapi: ({ info, servers, }: {
|
|
101
|
+
info: OpenAPI.InfoObject;
|
|
102
|
+
servers?: Partial<Record<(`https://` | `http://`) | ({} & string), string>>;
|
|
103
|
+
}) => Router<ContextFrom, ContextTo, RequiredParams, R | Route<ContextFrom, ContextTo, Input, JSONValue, "/openapi.json", RequiredParams, "GET", {}, never>, Input>;
|
|
104
|
+
private readonly method;
|
|
105
|
+
get: <Result extends JSONValue, Path extends string, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => Response | Result | Promise<Response | 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: <Result extends JSONValue, Path extends string, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => Response | Result | Promise<Response | 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: <Result extends JSONValue, Path extends string, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => Response | Result | Promise<Response | 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: <Result extends JSONValue, Path extends string, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => Response | Result | Promise<Response | 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: <Result extends JSONValue, Path extends string, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => Response | Result | Promise<Response | 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: <Result extends JSONValue, Path extends string, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => Response | Result | Promise<Response | 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: <Result extends JSONValue, Path extends string, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => Response | Result | Promise<Response | 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
|
+
through: <NextContext>(through: (context: ContextTo, params: Record<RequiredParams, string>) => MaybePromise<NextContext>) => Router<ContextFrom, NextContext, RequiredParams, R, Input>;
|
|
113
|
+
}
|
|
113
114
|
|
|
114
|
-
type RouteRunData<Params, Context, QueryOutput, BodyOutput> = {
|
|
115
|
+
type RouteRunData<Params extends string, Context, QueryOutput, BodyOutput> = {
|
|
116
|
+
params: Record<Params, string>;
|
|
115
117
|
ctx: Context;
|
|
116
|
-
body: BodyOutput;
|
|
117
118
|
query: QueryOutput;
|
|
118
|
-
|
|
119
|
+
body: BodyOutput;
|
|
119
120
|
};
|
|
120
121
|
type AnyQuery = {
|
|
121
122
|
[key in string]: any;
|
|
122
123
|
};
|
|
123
|
-
type Through<From, To, RequiredParams extends
|
|
124
|
-
type SSEOutputSpec<Result> = {
|
|
124
|
+
type Through<From, To, RequiredParams extends string> = (context: From, params: Record<RequiredParams, string>) => Promise<To>;
|
|
125
|
+
type SSEOutputSpec<Result extends JSONValue> = {
|
|
125
126
|
type: 'sse';
|
|
126
|
-
schema:
|
|
127
|
+
schema: AnySchemaFor<Result>;
|
|
127
128
|
description?: string;
|
|
128
129
|
};
|
|
129
|
-
type JSONOutputSpec<Result> = {
|
|
130
|
+
type JSONOutputSpec<Result extends JSONValue> = {
|
|
130
131
|
type: 'json';
|
|
131
|
-
schema:
|
|
132
|
+
schema: AnySchemaFor<Result>;
|
|
132
133
|
description?: string;
|
|
133
134
|
};
|
|
134
|
-
type OutputSpec<Result> = {
|
|
135
|
+
type OutputSpec<Result extends JSONValue> = {
|
|
135
136
|
description?: string;
|
|
136
|
-
body:
|
|
137
|
+
body: Result extends KaitoSSEResponse<infer R> ? SSEOutputSpec<Extract<R, JSONValue>> : JSONOutputSpec<Result>;
|
|
137
138
|
};
|
|
138
|
-
type Route<ContextTo, Result, Path extends string, AdditionalParams extends
|
|
139
|
-
body?:
|
|
139
|
+
type Route<ContextFrom, ContextTo, RouterInput extends readonly unknown[], Result extends JSONValue, Path extends string, AdditionalParams extends string, Method extends KaitoMethod, Query extends Record<string, JSONValue>, Body extends JSONValue> = {
|
|
140
|
+
body?: AnySchemaFor<Body>;
|
|
140
141
|
query?: {
|
|
141
|
-
[Key in keyof Query]:
|
|
142
|
+
[Key in keyof Query]: AnySchemaFor<Query[Key]>;
|
|
142
143
|
};
|
|
143
144
|
path: Path;
|
|
144
145
|
method: Method;
|
|
145
146
|
openapi?: OutputSpec<NoInfer<Result>>;
|
|
146
|
-
router: Router<
|
|
147
|
-
run(data: RouteRunData<ExtractRouteParams<Path>
|
|
147
|
+
router: Router<ContextFrom, ContextTo, AdditionalParams, AnyRoute, RouterInput>;
|
|
148
|
+
run(data: RouteRunData<ExtractRouteParams<Path> | AdditionalParams, ContextTo, Query, Body>): Promise<Result | Response> | Response | Result;
|
|
148
149
|
};
|
|
149
|
-
type AnyRoute = Route<any, any, any, any, any, any, any>;
|
|
150
|
+
type AnyRoute = Route<any, any, any, any, any, any, any, any, any>;
|
|
150
151
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
152
|
+
/**
|
|
153
|
+
* A helper to check if the environment is Node.js-like and the `NODE_ENV` environment variable is set to `'development'`
|
|
154
|
+
*/
|
|
155
|
+
declare const isNodeLikeDev: boolean;
|
|
156
|
+
type ErroredAPIResponse = {
|
|
157
|
+
success: false;
|
|
158
|
+
data: null;
|
|
159
|
+
message: string;
|
|
160
|
+
};
|
|
161
|
+
type SuccessfulAPIResponse<T> = {
|
|
162
|
+
success: true;
|
|
163
|
+
data: T;
|
|
158
164
|
};
|
|
165
|
+
type APIResponse<T> = ErroredAPIResponse | SuccessfulAPIResponse<T>;
|
|
166
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
167
|
+
type KaitoMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS';
|
|
168
|
+
type ExtractRouteParams<T extends string> = string extends T ? string : T extends `${string}:${infer Param}/${infer Rest}` ? Param | ExtractRouteParams<Rest> : T extends `${string}:${infer Param}` ? Param : never;
|
|
159
169
|
/**
|
|
160
170
|
* Accepts a router instance, and returns a union of all the routes in the router
|
|
161
171
|
*
|
|
@@ -166,46 +176,21 @@ type RouterState<ContextFrom, ContextTo, RequiredParams extends Record<string, u
|
|
|
166
176
|
* type Routes = InferRoutes<typeof app>;
|
|
167
177
|
* ```
|
|
168
178
|
*/
|
|
169
|
-
type InferRoutes<R extends Router<
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
params?: never;
|
|
183
|
-
} | {
|
|
184
|
-
route: R_1;
|
|
185
|
-
params: Record<string, string>;
|
|
186
|
-
};
|
|
187
|
-
private static buildQuerySchema;
|
|
188
|
-
serve: () => (request: Request, ...args: [Input] extends [never] ? [] : [input: Input]) => Promise<Response>;
|
|
189
|
-
openapi: (highLevelSpec: {
|
|
190
|
-
info: {
|
|
191
|
-
version: string;
|
|
192
|
-
title: string;
|
|
193
|
-
description?: string;
|
|
194
|
-
};
|
|
195
|
-
servers?: Partial<Record<(`https://` | `http://`) | ({} & string), string>>;
|
|
196
|
-
}) => Router<ContextFrom, ContextTo, RequiredParams, R | Route<ContextTo, Response, "/openapi.json", RequiredParams, "GET", {}, never>, Input>;
|
|
197
|
-
private readonly method;
|
|
198
|
-
get: <Result, Path extends string, Query extends AnyQuery = {}, Body = never>(path: Path, route: ((data: RouteRunData<ExtractRouteParams<Path> & RequiredParams, ContextTo, Query, Body>) => Result | Promise<Result>) | Omit<Route<ContextTo, Result, Path, RequiredParams, "GET", Query, Body>, "body" | "path" | "method" | "router">) => Router<ContextFrom, ContextTo, RequiredParams, R | Route<ContextTo, Result, Path, RequiredParams, "GET", Query, Body>, Input>;
|
|
199
|
-
post: <Result, Path extends string, Query extends AnyQuery = {}, Body = never>(path: Path, route: ((data: RouteRunData<ExtractRouteParams<Path> & RequiredParams, ContextTo, Query, Body>) => Result | Promise<Result>) | Omit<Route<ContextTo, Result, Path, RequiredParams, "POST", Query, Body>, "path" | "method" | "router">) => Router<ContextFrom, ContextTo, RequiredParams, R | Route<ContextTo, Result, Path, RequiredParams, "POST", Query, Body>, Input>;
|
|
200
|
-
put: <Result, Path extends string, Query extends AnyQuery = {}, Body = never>(path: Path, route: ((data: RouteRunData<ExtractRouteParams<Path> & RequiredParams, ContextTo, Query, Body>) => Result | Promise<Result>) | Omit<Route<ContextTo, Result, Path, RequiredParams, "PUT", Query, Body>, "path" | "method" | "router">) => Router<ContextFrom, ContextTo, RequiredParams, R | Route<ContextTo, Result, Path, RequiredParams, "PUT", Query, Body>, Input>;
|
|
201
|
-
patch: <Result, Path extends string, Query extends AnyQuery = {}, Body = never>(path: Path, route: ((data: RouteRunData<ExtractRouteParams<Path> & RequiredParams, ContextTo, Query, Body>) => Result | Promise<Result>) | Omit<Route<ContextTo, Result, Path, RequiredParams, "PATCH", Query, Body>, "path" | "method" | "router">) => Router<ContextFrom, ContextTo, RequiredParams, R | Route<ContextTo, Result, Path, RequiredParams, "PATCH", Query, Body>, Input>;
|
|
202
|
-
delete: <Result, Path extends string, Query extends AnyQuery = {}, Body = never>(path: Path, route: ((data: RouteRunData<ExtractRouteParams<Path> & RequiredParams, ContextTo, Query, Body>) => Result | Promise<Result>) | Omit<Route<ContextTo, Result, Path, RequiredParams, "DELETE", Query, Body>, "path" | "method" | "router">) => Router<ContextFrom, ContextTo, RequiredParams, R | Route<ContextTo, Result, Path, RequiredParams, "DELETE", Query, Body>, Input>;
|
|
203
|
-
head: <Result, Path extends string, Query extends AnyQuery = {}, Body = never>(path: Path, route: ((data: RouteRunData<ExtractRouteParams<Path> & RequiredParams, ContextTo, Query, Body>) => Result | Promise<Result>) | Omit<Route<ContextTo, Result, Path, RequiredParams, "HEAD", Query, Body>, "path" | "method" | "router">) => Router<ContextFrom, ContextTo, RequiredParams, R | Route<ContextTo, Result, Path, RequiredParams, "HEAD", Query, Body>, Input>;
|
|
204
|
-
options: <Result, Path extends string, Query extends AnyQuery = {}, Body = never>(path: Path, route: ((data: RouteRunData<ExtractRouteParams<Path> & RequiredParams, ContextTo, Query, Body>) => Result | Promise<Result>) | Omit<Route<ContextTo, Result, Path, RequiredParams, "OPTIONS", Query, Body>, "path" | "method" | "router">) => Router<ContextFrom, ContextTo, RequiredParams, R | Route<ContextTo, Result, Path, RequiredParams, "OPTIONS", Query, Body>, Input>;
|
|
205
|
-
through: <NextContext>(through: (context: ContextTo, params: RequiredParams) => MaybePromise<NextContext>) => Router<ContextFrom, NextContext, RequiredParams, R, Input>;
|
|
206
|
-
}
|
|
179
|
+
type InferRoutes<R extends Router<never, never, never, never, never>> = R extends Router<any, any, any, infer R extends AnyRoute, any> ? R : never;
|
|
180
|
+
/**
|
|
181
|
+
* A function that is called to get the context for a request.
|
|
182
|
+
*
|
|
183
|
+
* This is useful for things like authentication, to pass in a database connection, etc.
|
|
184
|
+
*
|
|
185
|
+
* It's fine for this function to throw; if it does, the error is passed to the `onError` function.
|
|
186
|
+
*
|
|
187
|
+
* @param req - The kaito request object, which contains the request method, url, headers, etc
|
|
188
|
+
* @param head - The kaito head object, which contains getters and setters for headers and status
|
|
189
|
+
* @returns The context for your routes
|
|
190
|
+
*/
|
|
191
|
+
type GetContext<Result, Input extends readonly unknown[]> = (req: KaitoRequest, head: KaitoHead, ...args: Input) => MaybePromise<Result>;
|
|
207
192
|
|
|
208
|
-
|
|
193
|
+
interface KaitoConfig<ContextFrom, Input extends readonly unknown[]> {
|
|
209
194
|
/**
|
|
210
195
|
* A function that is called to get the context for a request.
|
|
211
196
|
*
|
|
@@ -213,7 +198,7 @@ type KaitoConfig<ContextFrom, WithArgument> = {
|
|
|
213
198
|
*
|
|
214
199
|
* It's fine for this function to throw; if it does, the error is passed to the `onError` function.
|
|
215
200
|
*/
|
|
216
|
-
getContext?: GetContext<ContextFrom,
|
|
201
|
+
getContext?: GetContext<ContextFrom, Input>;
|
|
217
202
|
/**
|
|
218
203
|
* A function that is called when an error occurs inside a route handler.
|
|
219
204
|
*
|
|
@@ -262,7 +247,8 @@ type KaitoConfig<ContextFrom, WithArgument> = {
|
|
|
262
247
|
* ```
|
|
263
248
|
*/
|
|
264
249
|
transform?: (req: Request, res: Response) => MaybePromise<Response | void | undefined>;
|
|
265
|
-
}
|
|
250
|
+
}
|
|
251
|
+
|
|
266
252
|
/**
|
|
267
253
|
* Helper function for instantiating a Kaito router
|
|
268
254
|
*
|
|
@@ -271,11 +257,6 @@ type KaitoConfig<ContextFrom, WithArgument> = {
|
|
|
271
257
|
* @param config - The configuration for the router
|
|
272
258
|
* @returns A new Kaito router
|
|
273
259
|
*/
|
|
274
|
-
declare
|
|
275
|
-
declare namespace create {
|
|
276
|
-
var withInput: <Input = never>() => {
|
|
277
|
-
create: <Context>(config?: KaitoConfig<Context, Input>) => Router<Context, Context, {}, never, Input>;
|
|
278
|
-
};
|
|
279
|
-
}
|
|
260
|
+
declare const create: <Context = null, Input extends readonly unknown[] = []>(config?: KaitoConfig<Context, Input>) => Router<Context, Context, never, never, Input>;
|
|
280
261
|
|
|
281
|
-
export { type APIResponse, type AnyQuery, type
|
|
262
|
+
export { type APIResponse, type AnyQuery, type AnyRoute, AnySchemaFor, type ErroredAPIResponse, type ExtractRouteParams, type GetContext, type InferRoutes, type JSONOutputSpec, JSONValue, type KaitoConfig, KaitoError, KaitoHead, type KaitoMethod, KaitoRequest, type MaybePromise, type OutputSpec, type Route, type RouteRunData, Router, type RouterState, type SSEOutputSpec, type SuccessfulAPIResponse, type Through, WrappedError, create, isNodeLikeDev };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as OpenAPI from 'openapi3-ts/oas31';
|
|
2
|
+
import { JSONValue, AnySchemaFor } from './schema/schema.js';
|
|
3
|
+
export { ArrayChecks, ArrayDef, BaseSchema, BaseSchemaDef, BooleanDef, Issue, JSONPrimitive, KArray, KBoolean, KLiteral, KNull, KNumber, KObject, KObjectFromURLSearchParams, KRef, KScalar, KString, KUnion, LiteralDef, NullDef, NumberChecks, NumberDef, NumberFormat, ObjectDef, ParseContext, ParseResult, RefDef, STRING_FORMAT_REGEXES, ScalarDef, ScalarOptions, SchemaError, StringChecks, StringDef, StringFormat, UnionDef, isPrimitiveJSONValue, k } from './schema/schema.js';
|
|
2
4
|
import { KaitoSSEResponse } from './stream/stream.js';
|
|
3
5
|
|
|
4
6
|
declare class WrappedError<T> extends Error {
|
|
@@ -72,90 +74,98 @@ declare class KaitoHead {
|
|
|
72
74
|
get touched(): boolean;
|
|
73
75
|
}
|
|
74
76
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
data: null;
|
|
82
|
-
message: string;
|
|
83
|
-
};
|
|
84
|
-
type SuccessfulAPIResponse<T> = {
|
|
85
|
-
success: true;
|
|
86
|
-
data: T;
|
|
87
|
-
};
|
|
88
|
-
type APIResponse<T> = ErroredAPIResponse | SuccessfulAPIResponse<T>;
|
|
89
|
-
type AnyResponse = APIResponse<unknown>;
|
|
90
|
-
type MakeOptional<T, K extends keyof T> = T extends T ? Omit<T, K> & Partial<Pick<T, K>> : never;
|
|
91
|
-
type MaybePromise<T> = T | Promise<T>;
|
|
92
|
-
type KaitoMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS';
|
|
93
|
-
type NotReadonly<T> = {
|
|
94
|
-
-readonly [K in keyof T]: T[K];
|
|
77
|
+
type PrefixRoutesPathInner<R extends AnyRoute, Prefix extends `/${string}`> = R extends Route<infer ContextFrom, infer ContextTo, infer RouterInput, infer Result, infer Path, infer AdditionalParams, infer Method, infer Query, infer BodyOutput> ? Route<ContextFrom, ContextTo, RouterInput, Result, `${Prefix}${Path extends '/' ? '' : Path}`, AdditionalParams, Method, Query, BodyOutput> : never;
|
|
78
|
+
type PrefixRoutesPath<Prefix extends `/${string}`, R extends AnyRoute> = R extends R ? PrefixRoutesPathInner<R, Prefix> : never;
|
|
79
|
+
type RouterState<ContextFrom, ContextTo, RequiredParams extends string, Routes extends AnyRoute, Input extends readonly unknown[]> = {
|
|
80
|
+
routes: Set<Routes>;
|
|
81
|
+
through: (context: ContextFrom, params: Record<RequiredParams, string>) => Promise<ContextTo> | ContextTo;
|
|
82
|
+
config: KaitoConfig<ContextFrom, Input>;
|
|
95
83
|
};
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
84
|
+
declare class Router<ContextFrom, ContextTo, RequiredParams extends string, R extends AnyRoute, Input extends readonly unknown[]> {
|
|
85
|
+
#private;
|
|
86
|
+
static create: <Context = null, Input_1 extends readonly unknown[] = []>(config?: KaitoConfig<Context, Input_1>) => Router<Context, Context, never, never, Input_1>;
|
|
87
|
+
protected constructor(state: RouterState<ContextFrom, ContextTo, RequiredParams, R, Input>);
|
|
88
|
+
get routes(): Set<R>;
|
|
89
|
+
private readonly add;
|
|
90
|
+
readonly params: [RequiredParams] extends [never] ? <NextParams extends string>() => Router<ContextFrom, ContextTo, NextParams, R, Input> : () => Router<ContextFrom, ContextTo, RequiredParams, R, Input>;
|
|
91
|
+
readonly merge: <PathPrefix extends `/${string}`, NextRequiredParams extends string, OtherRoutes extends AnyRoute>(pathPrefix: [NextRequiredParams] extends [ExtractRouteParams<PathPrefix> | RequiredParams] ? PathPrefix : `/:${Exclude<NextRequiredParams, ExtractRouteParams<PathPrefix> | RequiredParams>}`, other: Router<ContextFrom, ContextTo, NextRequiredParams, OtherRoutes, Input>) => Router<ContextFrom, ContextTo, RequiredParams, Extract<R | PrefixRoutesPath<PathPrefix, Extract<OtherRoutes, AnyRoute>>, AnyRoute>, Input>;
|
|
92
|
+
protected static getFindRoute: <R_1>(routes: Map<KaitoMethod, Map<string, R_1>>) => (method: KaitoMethod, path: string) => {
|
|
93
|
+
route?: never;
|
|
94
|
+
params?: never;
|
|
95
|
+
} | {
|
|
96
|
+
route: R_1;
|
|
97
|
+
params: Record<string, string>;
|
|
98
|
+
};
|
|
99
|
+
serve: () => (request: Request, ...args: Input) => Promise<Response>;
|
|
100
|
+
openapi: ({ info, servers, }: {
|
|
101
|
+
info: OpenAPI.InfoObject;
|
|
102
|
+
servers?: Partial<Record<(`https://` | `http://`) | ({} & string), string>>;
|
|
103
|
+
}) => Router<ContextFrom, ContextTo, RequiredParams, R | Route<ContextFrom, ContextTo, Input, JSONValue, "/openapi.json", RequiredParams, "GET", {}, never>, Input>;
|
|
104
|
+
private readonly method;
|
|
105
|
+
get: <Result extends JSONValue, Path extends string, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => Response | Result | Promise<Response | 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: <Result extends JSONValue, Path extends string, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => Response | Result | Promise<Response | 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: <Result extends JSONValue, Path extends string, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => Response | Result | Promise<Response | 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: <Result extends JSONValue, Path extends string, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => Response | Result | Promise<Response | 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: <Result extends JSONValue, Path extends string, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => Response | Result | Promise<Response | 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: <Result extends JSONValue, Path extends string, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => Response | Result | Promise<Response | 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: <Result extends JSONValue, Path extends string, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => Response | Result | Promise<Response | 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
|
+
through: <NextContext>(through: (context: ContextTo, params: Record<RequiredParams, string>) => MaybePromise<NextContext>) => Router<ContextFrom, NextContext, RequiredParams, R, Input>;
|
|
113
|
+
}
|
|
113
114
|
|
|
114
|
-
type RouteRunData<Params, Context, QueryOutput, BodyOutput> = {
|
|
115
|
+
type RouteRunData<Params extends string, Context, QueryOutput, BodyOutput> = {
|
|
116
|
+
params: Record<Params, string>;
|
|
115
117
|
ctx: Context;
|
|
116
|
-
body: BodyOutput;
|
|
117
118
|
query: QueryOutput;
|
|
118
|
-
|
|
119
|
+
body: BodyOutput;
|
|
119
120
|
};
|
|
120
121
|
type AnyQuery = {
|
|
121
122
|
[key in string]: any;
|
|
122
123
|
};
|
|
123
|
-
type Through<From, To, RequiredParams extends
|
|
124
|
-
type SSEOutputSpec<Result> = {
|
|
124
|
+
type Through<From, To, RequiredParams extends string> = (context: From, params: Record<RequiredParams, string>) => Promise<To>;
|
|
125
|
+
type SSEOutputSpec<Result extends JSONValue> = {
|
|
125
126
|
type: 'sse';
|
|
126
|
-
schema:
|
|
127
|
+
schema: AnySchemaFor<Result>;
|
|
127
128
|
description?: string;
|
|
128
129
|
};
|
|
129
|
-
type JSONOutputSpec<Result> = {
|
|
130
|
+
type JSONOutputSpec<Result extends JSONValue> = {
|
|
130
131
|
type: 'json';
|
|
131
|
-
schema:
|
|
132
|
+
schema: AnySchemaFor<Result>;
|
|
132
133
|
description?: string;
|
|
133
134
|
};
|
|
134
|
-
type OutputSpec<Result> = {
|
|
135
|
+
type OutputSpec<Result extends JSONValue> = {
|
|
135
136
|
description?: string;
|
|
136
|
-
body:
|
|
137
|
+
body: Result extends KaitoSSEResponse<infer R> ? SSEOutputSpec<Extract<R, JSONValue>> : JSONOutputSpec<Result>;
|
|
137
138
|
};
|
|
138
|
-
type Route<ContextTo, Result, Path extends string, AdditionalParams extends
|
|
139
|
-
body?:
|
|
139
|
+
type Route<ContextFrom, ContextTo, RouterInput extends readonly unknown[], Result extends JSONValue, Path extends string, AdditionalParams extends string, Method extends KaitoMethod, Query extends Record<string, JSONValue>, Body extends JSONValue> = {
|
|
140
|
+
body?: AnySchemaFor<Body>;
|
|
140
141
|
query?: {
|
|
141
|
-
[Key in keyof Query]:
|
|
142
|
+
[Key in keyof Query]: AnySchemaFor<Query[Key]>;
|
|
142
143
|
};
|
|
143
144
|
path: Path;
|
|
144
145
|
method: Method;
|
|
145
146
|
openapi?: OutputSpec<NoInfer<Result>>;
|
|
146
|
-
router: Router<
|
|
147
|
-
run(data: RouteRunData<ExtractRouteParams<Path>
|
|
147
|
+
router: Router<ContextFrom, ContextTo, AdditionalParams, AnyRoute, RouterInput>;
|
|
148
|
+
run(data: RouteRunData<ExtractRouteParams<Path> | AdditionalParams, ContextTo, Query, Body>): Promise<Result | Response> | Response | Result;
|
|
148
149
|
};
|
|
149
|
-
type AnyRoute = Route<any, any, any, any, any, any, any>;
|
|
150
|
+
type AnyRoute = Route<any, any, any, any, any, any, any, any, any>;
|
|
150
151
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
152
|
+
/**
|
|
153
|
+
* A helper to check if the environment is Node.js-like and the `NODE_ENV` environment variable is set to `'development'`
|
|
154
|
+
*/
|
|
155
|
+
declare const isNodeLikeDev: boolean;
|
|
156
|
+
type ErroredAPIResponse = {
|
|
157
|
+
success: false;
|
|
158
|
+
data: null;
|
|
159
|
+
message: string;
|
|
160
|
+
};
|
|
161
|
+
type SuccessfulAPIResponse<T> = {
|
|
162
|
+
success: true;
|
|
163
|
+
data: T;
|
|
158
164
|
};
|
|
165
|
+
type APIResponse<T> = ErroredAPIResponse | SuccessfulAPIResponse<T>;
|
|
166
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
167
|
+
type KaitoMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS';
|
|
168
|
+
type ExtractRouteParams<T extends string> = string extends T ? string : T extends `${string}:${infer Param}/${infer Rest}` ? Param | ExtractRouteParams<Rest> : T extends `${string}:${infer Param}` ? Param : never;
|
|
159
169
|
/**
|
|
160
170
|
* Accepts a router instance, and returns a union of all the routes in the router
|
|
161
171
|
*
|
|
@@ -166,46 +176,21 @@ type RouterState<ContextFrom, ContextTo, RequiredParams extends Record<string, u
|
|
|
166
176
|
* type Routes = InferRoutes<typeof app>;
|
|
167
177
|
* ```
|
|
168
178
|
*/
|
|
169
|
-
type InferRoutes<R extends Router<
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
params?: never;
|
|
183
|
-
} | {
|
|
184
|
-
route: R_1;
|
|
185
|
-
params: Record<string, string>;
|
|
186
|
-
};
|
|
187
|
-
private static buildQuerySchema;
|
|
188
|
-
serve: () => (request: Request, ...args: [Input] extends [never] ? [] : [input: Input]) => Promise<Response>;
|
|
189
|
-
openapi: (highLevelSpec: {
|
|
190
|
-
info: {
|
|
191
|
-
version: string;
|
|
192
|
-
title: string;
|
|
193
|
-
description?: string;
|
|
194
|
-
};
|
|
195
|
-
servers?: Partial<Record<(`https://` | `http://`) | ({} & string), string>>;
|
|
196
|
-
}) => Router<ContextFrom, ContextTo, RequiredParams, R | Route<ContextTo, Response, "/openapi.json", RequiredParams, "GET", {}, never>, Input>;
|
|
197
|
-
private readonly method;
|
|
198
|
-
get: <Result, Path extends string, Query extends AnyQuery = {}, Body = never>(path: Path, route: ((data: RouteRunData<ExtractRouteParams<Path> & RequiredParams, ContextTo, Query, Body>) => Result | Promise<Result>) | Omit<Route<ContextTo, Result, Path, RequiredParams, "GET", Query, Body>, "body" | "path" | "method" | "router">) => Router<ContextFrom, ContextTo, RequiredParams, R | Route<ContextTo, Result, Path, RequiredParams, "GET", Query, Body>, Input>;
|
|
199
|
-
post: <Result, Path extends string, Query extends AnyQuery = {}, Body = never>(path: Path, route: ((data: RouteRunData<ExtractRouteParams<Path> & RequiredParams, ContextTo, Query, Body>) => Result | Promise<Result>) | Omit<Route<ContextTo, Result, Path, RequiredParams, "POST", Query, Body>, "path" | "method" | "router">) => Router<ContextFrom, ContextTo, RequiredParams, R | Route<ContextTo, Result, Path, RequiredParams, "POST", Query, Body>, Input>;
|
|
200
|
-
put: <Result, Path extends string, Query extends AnyQuery = {}, Body = never>(path: Path, route: ((data: RouteRunData<ExtractRouteParams<Path> & RequiredParams, ContextTo, Query, Body>) => Result | Promise<Result>) | Omit<Route<ContextTo, Result, Path, RequiredParams, "PUT", Query, Body>, "path" | "method" | "router">) => Router<ContextFrom, ContextTo, RequiredParams, R | Route<ContextTo, Result, Path, RequiredParams, "PUT", Query, Body>, Input>;
|
|
201
|
-
patch: <Result, Path extends string, Query extends AnyQuery = {}, Body = never>(path: Path, route: ((data: RouteRunData<ExtractRouteParams<Path> & RequiredParams, ContextTo, Query, Body>) => Result | Promise<Result>) | Omit<Route<ContextTo, Result, Path, RequiredParams, "PATCH", Query, Body>, "path" | "method" | "router">) => Router<ContextFrom, ContextTo, RequiredParams, R | Route<ContextTo, Result, Path, RequiredParams, "PATCH", Query, Body>, Input>;
|
|
202
|
-
delete: <Result, Path extends string, Query extends AnyQuery = {}, Body = never>(path: Path, route: ((data: RouteRunData<ExtractRouteParams<Path> & RequiredParams, ContextTo, Query, Body>) => Result | Promise<Result>) | Omit<Route<ContextTo, Result, Path, RequiredParams, "DELETE", Query, Body>, "path" | "method" | "router">) => Router<ContextFrom, ContextTo, RequiredParams, R | Route<ContextTo, Result, Path, RequiredParams, "DELETE", Query, Body>, Input>;
|
|
203
|
-
head: <Result, Path extends string, Query extends AnyQuery = {}, Body = never>(path: Path, route: ((data: RouteRunData<ExtractRouteParams<Path> & RequiredParams, ContextTo, Query, Body>) => Result | Promise<Result>) | Omit<Route<ContextTo, Result, Path, RequiredParams, "HEAD", Query, Body>, "path" | "method" | "router">) => Router<ContextFrom, ContextTo, RequiredParams, R | Route<ContextTo, Result, Path, RequiredParams, "HEAD", Query, Body>, Input>;
|
|
204
|
-
options: <Result, Path extends string, Query extends AnyQuery = {}, Body = never>(path: Path, route: ((data: RouteRunData<ExtractRouteParams<Path> & RequiredParams, ContextTo, Query, Body>) => Result | Promise<Result>) | Omit<Route<ContextTo, Result, Path, RequiredParams, "OPTIONS", Query, Body>, "path" | "method" | "router">) => Router<ContextFrom, ContextTo, RequiredParams, R | Route<ContextTo, Result, Path, RequiredParams, "OPTIONS", Query, Body>, Input>;
|
|
205
|
-
through: <NextContext>(through: (context: ContextTo, params: RequiredParams) => MaybePromise<NextContext>) => Router<ContextFrom, NextContext, RequiredParams, R, Input>;
|
|
206
|
-
}
|
|
179
|
+
type InferRoutes<R extends Router<never, never, never, never, never>> = R extends Router<any, any, any, infer R extends AnyRoute, any> ? R : never;
|
|
180
|
+
/**
|
|
181
|
+
* A function that is called to get the context for a request.
|
|
182
|
+
*
|
|
183
|
+
* This is useful for things like authentication, to pass in a database connection, etc.
|
|
184
|
+
*
|
|
185
|
+
* It's fine for this function to throw; if it does, the error is passed to the `onError` function.
|
|
186
|
+
*
|
|
187
|
+
* @param req - The kaito request object, which contains the request method, url, headers, etc
|
|
188
|
+
* @param head - The kaito head object, which contains getters and setters for headers and status
|
|
189
|
+
* @returns The context for your routes
|
|
190
|
+
*/
|
|
191
|
+
type GetContext<Result, Input extends readonly unknown[]> = (req: KaitoRequest, head: KaitoHead, ...args: Input) => MaybePromise<Result>;
|
|
207
192
|
|
|
208
|
-
|
|
193
|
+
interface KaitoConfig<ContextFrom, Input extends readonly unknown[]> {
|
|
209
194
|
/**
|
|
210
195
|
* A function that is called to get the context for a request.
|
|
211
196
|
*
|
|
@@ -213,7 +198,7 @@ type KaitoConfig<ContextFrom, WithArgument> = {
|
|
|
213
198
|
*
|
|
214
199
|
* It's fine for this function to throw; if it does, the error is passed to the `onError` function.
|
|
215
200
|
*/
|
|
216
|
-
getContext?: GetContext<ContextFrom,
|
|
201
|
+
getContext?: GetContext<ContextFrom, Input>;
|
|
217
202
|
/**
|
|
218
203
|
* A function that is called when an error occurs inside a route handler.
|
|
219
204
|
*
|
|
@@ -262,7 +247,8 @@ type KaitoConfig<ContextFrom, WithArgument> = {
|
|
|
262
247
|
* ```
|
|
263
248
|
*/
|
|
264
249
|
transform?: (req: Request, res: Response) => MaybePromise<Response | void | undefined>;
|
|
265
|
-
}
|
|
250
|
+
}
|
|
251
|
+
|
|
266
252
|
/**
|
|
267
253
|
* Helper function for instantiating a Kaito router
|
|
268
254
|
*
|
|
@@ -271,11 +257,6 @@ type KaitoConfig<ContextFrom, WithArgument> = {
|
|
|
271
257
|
* @param config - The configuration for the router
|
|
272
258
|
* @returns A new Kaito router
|
|
273
259
|
*/
|
|
274
|
-
declare
|
|
275
|
-
declare namespace create {
|
|
276
|
-
var withInput: <Input = never>() => {
|
|
277
|
-
create: <Context>(config?: KaitoConfig<Context, Input>) => Router<Context, Context, {}, never, Input>;
|
|
278
|
-
};
|
|
279
|
-
}
|
|
260
|
+
declare const create: <Context = null, Input extends readonly unknown[] = []>(config?: KaitoConfig<Context, Input>) => Router<Context, Context, never, never, Input>;
|
|
280
261
|
|
|
281
|
-
export { type APIResponse, type AnyQuery, type
|
|
262
|
+
export { type APIResponse, type AnyQuery, type AnyRoute, AnySchemaFor, type ErroredAPIResponse, type ExtractRouteParams, type GetContext, type InferRoutes, type JSONOutputSpec, JSONValue, type KaitoConfig, KaitoError, KaitoHead, type KaitoMethod, KaitoRequest, type MaybePromise, type OutputSpec, type Route, type RouteRunData, Router, type RouterState, type SSEOutputSpec, type SuccessfulAPIResponse, type Through, WrappedError, create, isNodeLikeDev };
|