@kaito-http/core 4.0.0-beta.2 → 4.0.0-beta.21

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.d.cts CHANGED
@@ -1,4 +1,6 @@
1
- import { z } from 'zod';
1
+ import * as OpenAPI from 'openapi3-ts/oas31';
2
+ import { JSONValue, AnySchemaFor, BaseSchema, BaseSchemaDef } from './schema/schema.cjs';
3
+ export { ArrayChecks, ArrayDef, 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 {
@@ -21,14 +23,12 @@ declare class KaitoRequest {
21
23
  arrayBuffer(): Promise<ArrayBuffer>;
22
24
  blob(): Promise<Blob>;
23
25
  formData(): Promise<FormData>;
24
- bytes(): Promise<Uint8Array>;
26
+ bytes(): Promise<Uint8Array<ArrayBuffer>>;
25
27
  json(): Promise<unknown>;
26
28
  text(): Promise<string>;
27
29
  get request(): Request;
28
30
  }
29
31
 
30
- type KaitoMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS' | 'TRACE';
31
-
32
32
  /**
33
33
  * This class is merely a wrapper around a `Headers` object and a status code.
34
34
  * It's used while the router is executing a route to store any mutations to the status
@@ -74,132 +74,124 @@ declare class KaitoHead {
74
74
  get touched(): boolean;
75
75
  }
76
76
 
77
- /**
78
- * A helper to check if the environment is Node.js-like and the NODE_ENV is development
79
- */
80
- declare const isNodeLikeDev: boolean;
81
- type ErroredAPIResponse = {
82
- success: false;
83
- data: null;
84
- message: string;
85
- };
86
- type SuccessfulAPIResponse<T> = {
87
- success: true;
88
- data: T;
77
+ type PrefixRoutesPathInner<R extends AnyRoute, Prefix extends `/${string}`> = R extends Route<infer ContextFrom, infer ContextTo, infer RouterInput, infer ResultInput, infer ResultOutput, infer Path, infer AdditionalParams, infer Method, infer Query, infer BodyOutput> ? Route<ContextFrom, ContextTo, RouterInput, ResultInput, ResultOutput, `${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>;
89
83
  };
90
- type APIResponse<T> = ErroredAPIResponse | SuccessfulAPIResponse<T>;
91
- type AnyResponse = APIResponse<unknown>;
92
- type MakeOptional<T, K extends keyof T> = T extends T ? Omit<T, K> & Partial<Pick<T, K>> : never;
93
- type MaybePromise<T> = T | Promise<T>;
94
- type ExtractRouteParams<T extends string> = string extends T ? Record<string, string> : T extends `${string}:${infer Param}/${infer Rest}` ? {
95
- [k in Param | keyof ExtractRouteParams<Rest>]: string;
96
- } : T extends `${string}:${infer Param}` ? {
97
- [k in Param]: string;
98
- } : {};
99
- /**
100
- * A function that is called to get the context for a request.
101
- *
102
- * This is useful for things like authentication, to pass in a database connection, etc.
103
- *
104
- * It's fine for this function to throw; if it does, the error is passed to the `onError` function.
105
- *
106
- * @param req - The kaito request object, which contains the request method, url, headers, etc
107
- * @param head - The kaito head object, which contains getters and setters for headers and status
108
- * @returns The context for your routes
109
- */
110
- type GetContext<Result> = (req: KaitoRequest, head: KaitoHead) => MaybePromise<Result>;
84
+ declare class Router<ContextFrom, ContextTo, RequiredParams extends string, Routes 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, Routes, Input>);
88
+ get routes(): Set<Routes>;
89
+ private readonly add;
90
+ readonly params: [RequiredParams] extends [never] ? <NextParams extends string>() => Router<ContextFrom, ContextTo, NextParams, Routes, Input> : () => Router<ContextFrom, ContextTo, RequiredParams, Routes, 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, Routes | PrefixRoutesPath<PathPrefix, OtherRoutes>, Input>;
92
+ protected static getFindRoute: <R>(routes: Map<KaitoMethod, Map<string, R>>) => (method: KaitoMethod, path: string) => {
93
+ route?: never;
94
+ params?: never;
95
+ } | {
96
+ route: R;
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, Routes | Route<ContextFrom, ContextTo, Input, never, Response, "/openapi.json", RequiredParams, "GET", {}, never>, Input>;
104
+ private readonly method;
105
+ readonly get: <Path extends string, ResultInput = never, ResultOutput = ResultInput, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => ResultOutput | Promise<ResultOutput>) | Omit<Route<ContextFrom, ContextTo, Input, ResultInput, ResultOutput, Path, RequiredParams, "GET", Query, Body>, "body" | "path" | "method" | "router">) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, ResultInput, ResultOutput, Path, RequiredParams, "GET", Query, Body>, Input>;
106
+ readonly post: <Path extends string, ResultInput = never, ResultOutput = ResultInput, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => ResultOutput | Promise<ResultOutput>) | Omit<Route<ContextFrom, ContextTo, Input, ResultInput, ResultOutput, Path, RequiredParams, "POST", Query, Body>, "path" | "method" | "router">) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, ResultInput, ResultOutput, Path, RequiredParams, "POST", Query, Body>, Input>;
107
+ readonly put: <Path extends string, ResultInput = never, ResultOutput = ResultInput, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => ResultOutput | Promise<ResultOutput>) | Omit<Route<ContextFrom, ContextTo, Input, ResultInput, ResultOutput, Path, RequiredParams, "PUT", Query, Body>, "path" | "method" | "router">) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, ResultInput, ResultOutput, Path, RequiredParams, "PUT", Query, Body>, Input>;
108
+ readonly patch: <Path extends string, ResultInput = never, ResultOutput = ResultInput, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => ResultOutput | Promise<ResultOutput>) | Omit<Route<ContextFrom, ContextTo, Input, ResultInput, ResultOutput, Path, RequiredParams, "PATCH", Query, Body>, "path" | "method" | "router">) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, ResultInput, ResultOutput, Path, RequiredParams, "PATCH", Query, Body>, Input>;
109
+ readonly delete: <Path extends string, ResultInput = never, ResultOutput = ResultInput, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => ResultOutput | Promise<ResultOutput>) | Omit<Route<ContextFrom, ContextTo, Input, ResultInput, ResultOutput, Path, RequiredParams, "DELETE", Query, Body>, "path" | "method" | "router">) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, ResultInput, ResultOutput, Path, RequiredParams, "DELETE", Query, Body>, Input>;
110
+ readonly head: <Path extends string, ResultInput = never, ResultOutput = ResultInput, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => ResultOutput | Promise<ResultOutput>) | Omit<Route<ContextFrom, ContextTo, Input, ResultInput, ResultOutput, Path, RequiredParams, "HEAD", Query, Body>, "path" | "method" | "router">) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, ResultInput, ResultOutput, Path, RequiredParams, "HEAD", Query, Body>, Input>;
111
+ readonly options: <Path extends string, ResultInput = never, ResultOutput = ResultInput, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => ResultOutput | Promise<ResultOutput>) | Omit<Route<ContextFrom, ContextTo, Input, ResultInput, ResultOutput, Path, RequiredParams, "OPTIONS", Query, Body>, "path" | "method" | "router">) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, ResultInput, ResultOutput, Path, RequiredParams, "OPTIONS", Query, Body>, Input>;
112
+ through: <NextContext>(through: (context: ContextTo, params: Record<RequiredParams, string>) => MaybePromise<NextContext>) => Router<ContextFrom, NextContext, RequiredParams, Routes, Input>;
113
+ }
111
114
 
112
- type RouteRunData<Path extends string, Context, QueryOutput, BodyOutput> = {
115
+ type RouteRunData<Params extends string, Context, QueryOutput, BodyOutput> = {
116
+ params: Record<Params, string>;
113
117
  ctx: Context;
114
- body: BodyOutput;
115
118
  query: QueryOutput;
116
- params: ExtractRouteParams<Path>;
119
+ body: BodyOutput;
117
120
  };
118
121
  type AnyQuery = {
119
122
  [key in string]: any;
120
123
  };
121
- type Through<From, To> = (context: From) => Promise<To>;
122
- 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> = {
123
126
  type: 'sse';
124
- schema: z.Schema<Result>;
125
- description?: string;
127
+ schema: AnySchemaFor<Result>;
128
+ description?: string | undefined;
126
129
  };
127
- type JSONOutputSpec<Result> = {
130
+ type JSONOutputSpec<ResultInput, ResultOutput extends JSONValue> = {
128
131
  type: 'json';
129
- schema: z.Schema<Result>;
130
- description?: string;
132
+ schema: BaseSchema<ResultOutput, ResultInput, BaseSchemaDef<ResultOutput>>;
133
+ description?: string | undefined;
131
134
  };
132
- type OutputSpec<Result> = {
135
+ type OutputSpec<ResultInput, ResultOutput> = ResultInput extends KaitoSSEResponse<infer R> ? SSEOutputSpec<Extract<R, JSONValue>> & {
136
+ description?: string;
137
+ } : JSONOutputSpec<ResultOutput, Extract<ResultInput, JSONValue>> & {
133
138
  description?: string;
134
- body: NoInfer<Result extends KaitoSSEResponse<infer R> ? SSEOutputSpec<R> : JSONOutputSpec<Result>>;
135
139
  };
136
- type Route<ContextTo, Result, Path extends string, Method extends KaitoMethod, Query, Body> = {
137
- through: Through<unknown, ContextTo>;
138
- body?: z.Schema<Body>;
140
+ type Route<ContextFrom, ContextTo, RouterInput extends readonly unknown[], ResultInput, ResultOutput, Path extends string, AdditionalParams extends string, Method extends KaitoMethod, Query extends Record<string, JSONValue>, Body extends JSONValue> = {
141
+ body?: AnySchemaFor<Body>;
139
142
  query?: {
140
- [Key in keyof Query]: z.Schema<Query[Key]>;
143
+ [Key in keyof Query]: AnySchemaFor<Query[Key]>;
141
144
  };
142
145
  path: Path;
143
146
  method: Method;
144
- openapi?: OutputSpec<NoInfer<Result>>;
145
- run(data: RouteRunData<Path, ContextTo, Query, Body>): Promise<Result> | Result;
147
+ openapi?: OutputSpec<ResultInput, ResultOutput>;
148
+ router: Router<ContextFrom, ContextTo, AdditionalParams, AnyRoute, RouterInput>;
149
+ run(data: RouteRunData<ExtractRouteParams<Path> | AdditionalParams, ContextTo, Query, Body>): Promise<ResultOutput> | ResultOutput;
146
150
  };
147
- type AnyRoute = Route<any, any, any, any, any, any>;
151
+ type AnyRoute = Route<any, any, any, any, any, any, any, any, any, any>;
148
152
 
149
- type PrefixRoutesPathInner<R extends AnyRoute, Prefix extends `/${string}`> = R extends Route<infer ContextTo, infer Result, infer Path, infer Method, infer Query, infer BodyOutput> ? Route<ContextTo, Result, `${Prefix}${Path}`, Method, Query, BodyOutput> : never;
150
- type PrefixRoutesPath<Prefix extends `/${string}`, R extends AnyRoute> = R extends R ? PrefixRoutesPathInner<R, Prefix> : never;
151
- type RouterState<ContextFrom, ContextTo, Routes extends AnyRoute> = {
152
- routes: Set<Routes>;
153
- through: (context: unknown) => Promise<ContextTo>;
154
- config: KaitoConfig<ContextFrom>;
153
+ /**
154
+ * A helper to check if the environment is Node.js-like and the `NODE_ENV` environment variable is set to `'development'`
155
+ */
156
+ declare const isNodeLikeDev: boolean;
157
+ type ErroredAPIResponse = {
158
+ success: false;
159
+ data: null;
160
+ message: string;
161
+ };
162
+ type SuccessfulAPIResponse<T> = {
163
+ success: true;
164
+ data: T;
155
165
  };
166
+ type APIResponse<T> = ErroredAPIResponse | SuccessfulAPIResponse<T>;
167
+ type MaybePromise<T> = T | Promise<T>;
168
+ type KaitoMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS';
169
+ 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;
156
170
  /**
157
171
  * Accepts a router instance, and returns a union of all the routes in the router
158
172
  *
159
173
  * @example
160
174
  * ```ts
161
- * const app = router().get('/', () => 'Hello, world!');
175
+ * const app = router.get('/', () => 'Hello, world!');
162
176
  *
163
177
  * type Routes = InferRoutes<typeof app>;
164
178
  * ```
165
179
  */
166
- type InferRoutes<R extends Router<any, any, any>> = R extends Router<any, any, infer R extends AnyRoute> ? R : never;
167
- declare class Router<ContextFrom, ContextTo, R extends AnyRoute> {
168
- private readonly state;
169
- static create: <Context>(config: KaitoConfig<Context>) => Router<Context, Context, never>;
170
- constructor(state: RouterState<ContextFrom, ContextTo, R>);
171
- get routes(): Set<R>;
172
- private add;
173
- readonly merge: <PathPrefix extends `/${string}`, OtherRoutes extends AnyRoute>(pathPrefix: PathPrefix, other: Router<ContextFrom, unknown, OtherRoutes>) => Router<ContextFrom, ContextTo, Extract<R | PrefixRoutesPath<PathPrefix, Extract<OtherRoutes, AnyRoute>>, AnyRoute>>;
174
- protected static getFindRoute: <R_1>(routes: Map<KaitoMethod, Map<string, R_1>>) => (method: KaitoMethod, path: string) => {
175
- route?: never;
176
- params?: never;
177
- } | {
178
- route: R_1;
179
- params: Record<string, string>;
180
- };
181
- private static buildQuerySchema;
182
- serve: () => (request: Request) => Promise<Response>;
183
- openapi: (highLevelSpec: {
184
- info: {
185
- version: string;
186
- title: string;
187
- description?: string;
188
- };
189
- servers?: Partial<Record<(`https://` | `http://`) | ({} & string), string>>;
190
- }) => Router<ContextFrom, ContextTo, R | Route<ContextTo, Response, "/openapi.json", "GET", AnyQuery, unknown>>;
191
- private readonly method;
192
- get: <Result, Path extends string, Query extends AnyQuery = {}, Body = never>(path: Path, route: ((data: RouteRunData<Path, ContextTo, Query, Body>) => Result | Promise<Result>) | Omit<Route<ContextTo, Result, Path, "GET", Query, Body>, "body" | "path" | "method" | "through">) => Router<ContextFrom, ContextTo, R | Route<ContextTo, Result, Path, "GET", Query, Body>>;
193
- post: <Result, Path extends string, Query extends AnyQuery = {}, Body = never>(path: Path, route: ((data: RouteRunData<Path, ContextTo, Query, Body>) => Result | Promise<Result>) | Omit<Route<ContextTo, Result, Path, "POST", Query, Body>, "path" | "method" | "through">) => Router<ContextFrom, ContextTo, R | Route<ContextTo, Result, Path, "POST", Query, Body>>;
194
- put: <Result, Path extends string, Query extends AnyQuery = {}, Body = never>(path: Path, route: ((data: RouteRunData<Path, ContextTo, Query, Body>) => Result | Promise<Result>) | Omit<Route<ContextTo, Result, Path, "PUT", Query, Body>, "path" | "method" | "through">) => Router<ContextFrom, ContextTo, R | Route<ContextTo, Result, Path, "PUT", Query, Body>>;
195
- patch: <Result, Path extends string, Query extends AnyQuery = {}, Body = never>(path: Path, route: ((data: RouteRunData<Path, ContextTo, Query, Body>) => Result | Promise<Result>) | Omit<Route<ContextTo, Result, Path, "PATCH", Query, Body>, "path" | "method" | "through">) => Router<ContextFrom, ContextTo, R | Route<ContextTo, Result, Path, "PATCH", Query, Body>>;
196
- delete: <Result, Path extends string, Query extends AnyQuery = {}, Body = never>(path: Path, route: ((data: RouteRunData<Path, ContextTo, Query, Body>) => Result | Promise<Result>) | Omit<Route<ContextTo, Result, Path, "DELETE", Query, Body>, "path" | "method" | "through">) => Router<ContextFrom, ContextTo, R | Route<ContextTo, Result, Path, "DELETE", Query, Body>>;
197
- head: <Result, Path extends string, Query extends AnyQuery = {}, Body = never>(path: Path, route: ((data: RouteRunData<Path, ContextTo, Query, Body>) => Result | Promise<Result>) | Omit<Route<ContextTo, Result, Path, "HEAD", Query, Body>, "path" | "method" | "through">) => Router<ContextFrom, ContextTo, R | Route<ContextTo, Result, Path, "HEAD", Query, Body>>;
198
- options: <Result, Path extends string, Query extends AnyQuery = {}, Body = never>(path: Path, route: ((data: RouteRunData<Path, ContextTo, Query, Body>) => Result | Promise<Result>) | Omit<Route<ContextTo, Result, Path, "OPTIONS", Query, Body>, "path" | "method" | "through">) => Router<ContextFrom, ContextTo, R | Route<ContextTo, Result, Path, "OPTIONS", Query, Body>>;
199
- through: <NextContext>(through: (context: ContextTo) => MaybePromise<NextContext>) => Router<ContextFrom, NextContext, R>;
200
- }
180
+ type InferRoutes<R extends Router<never, never, never, never, never>> = R extends Router<any, any, any, infer R extends AnyRoute, any> ? R : never;
181
+ /**
182
+ * A function that is called to get the context for a request.
183
+ *
184
+ * This is useful for things like authentication, to pass in a database connection, etc.
185
+ *
186
+ * It's fine for this function to throw; if it does, the error is passed to the `onError` function.
187
+ *
188
+ * @param req - The kaito request object, which contains the request method, url, headers, etc
189
+ * @param head - The kaito head object, which contains getters and setters for headers and status
190
+ * @returns The context for your routes
191
+ */
192
+ type GetContext<Result, Input extends readonly unknown[]> = (req: KaitoRequest, head: KaitoHead, ...args: Input) => MaybePromise<Result>;
201
193
 
202
- type KaitoConfig<ContextFrom> = {
194
+ interface KaitoConfig<ContextFrom, Input extends readonly unknown[]> {
203
195
  /**
204
196
  * A function that is called to get the context for a request.
205
197
  *
@@ -207,7 +199,7 @@ type KaitoConfig<ContextFrom> = {
207
199
  *
208
200
  * It's fine for this function to throw; if it does, the error is passed to the `onError` function.
209
201
  */
210
- getContext?: GetContext<ContextFrom>;
202
+ getContext?: GetContext<ContextFrom, Input>;
211
203
  /**
212
204
  * A function that is called when an error occurs inside a route handler.
213
205
  *
@@ -256,15 +248,16 @@ type KaitoConfig<ContextFrom> = {
256
248
  * ```
257
249
  */
258
250
  transform?: (req: Request, res: Response) => MaybePromise<Response | void | undefined>;
259
- };
251
+ }
252
+
260
253
  /**
261
- * Create a helper function for instantiating a Kaito router
254
+ * Helper function for instantiating a Kaito router
262
255
  *
263
256
  * This is the starting point for any Kaito application
264
257
  *
265
258
  * @param config - The configuration for the router
266
259
  * @returns A new Kaito router
267
260
  */
268
- declare function create<Context = null>(config?: KaitoConfig<Context>): () => Router<Context, Context, never>;
261
+ declare const create: <Context = null, Input extends readonly unknown[] = []>(config?: KaitoConfig<Context, Input>) => Router<Context, Context, never, never, Input>;
269
262
 
270
- export { type APIResponse, type AnyQuery, type AnyResponse, type AnyRoute, type ErroredAPIResponse, type ExtractRouteParams, type GetContext, type InferRoutes, type JSONOutputSpec, type KaitoConfig, KaitoError, type KaitoMethod, KaitoRequest, type MakeOptional, type MaybePromise, type OutputSpec, type Route, type RouteRunData, Router, type RouterState, type SSEOutputSpec, type SuccessfulAPIResponse, type Through, WrappedError, create, isNodeLikeDev };
263
+ export { type APIResponse, type AnyQuery, type AnyRoute, AnySchemaFor, BaseSchema, BaseSchemaDef, 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 { z } from 'zod';
1
+ import * as OpenAPI from 'openapi3-ts/oas31';
2
+ import { JSONValue, AnySchemaFor, BaseSchema, BaseSchemaDef } from './schema/schema.js';
3
+ export { ArrayChecks, ArrayDef, 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 {
@@ -21,14 +23,12 @@ declare class KaitoRequest {
21
23
  arrayBuffer(): Promise<ArrayBuffer>;
22
24
  blob(): Promise<Blob>;
23
25
  formData(): Promise<FormData>;
24
- bytes(): Promise<Uint8Array>;
26
+ bytes(): Promise<Uint8Array<ArrayBuffer>>;
25
27
  json(): Promise<unknown>;
26
28
  text(): Promise<string>;
27
29
  get request(): Request;
28
30
  }
29
31
 
30
- type KaitoMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS' | 'TRACE';
31
-
32
32
  /**
33
33
  * This class is merely a wrapper around a `Headers` object and a status code.
34
34
  * It's used while the router is executing a route to store any mutations to the status
@@ -74,132 +74,124 @@ declare class KaitoHead {
74
74
  get touched(): boolean;
75
75
  }
76
76
 
77
- /**
78
- * A helper to check if the environment is Node.js-like and the NODE_ENV is development
79
- */
80
- declare const isNodeLikeDev: boolean;
81
- type ErroredAPIResponse = {
82
- success: false;
83
- data: null;
84
- message: string;
85
- };
86
- type SuccessfulAPIResponse<T> = {
87
- success: true;
88
- data: T;
77
+ type PrefixRoutesPathInner<R extends AnyRoute, Prefix extends `/${string}`> = R extends Route<infer ContextFrom, infer ContextTo, infer RouterInput, infer ResultInput, infer ResultOutput, infer Path, infer AdditionalParams, infer Method, infer Query, infer BodyOutput> ? Route<ContextFrom, ContextTo, RouterInput, ResultInput, ResultOutput, `${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>;
89
83
  };
90
- type APIResponse<T> = ErroredAPIResponse | SuccessfulAPIResponse<T>;
91
- type AnyResponse = APIResponse<unknown>;
92
- type MakeOptional<T, K extends keyof T> = T extends T ? Omit<T, K> & Partial<Pick<T, K>> : never;
93
- type MaybePromise<T> = T | Promise<T>;
94
- type ExtractRouteParams<T extends string> = string extends T ? Record<string, string> : T extends `${string}:${infer Param}/${infer Rest}` ? {
95
- [k in Param | keyof ExtractRouteParams<Rest>]: string;
96
- } : T extends `${string}:${infer Param}` ? {
97
- [k in Param]: string;
98
- } : {};
99
- /**
100
- * A function that is called to get the context for a request.
101
- *
102
- * This is useful for things like authentication, to pass in a database connection, etc.
103
- *
104
- * It's fine for this function to throw; if it does, the error is passed to the `onError` function.
105
- *
106
- * @param req - The kaito request object, which contains the request method, url, headers, etc
107
- * @param head - The kaito head object, which contains getters and setters for headers and status
108
- * @returns The context for your routes
109
- */
110
- type GetContext<Result> = (req: KaitoRequest, head: KaitoHead) => MaybePromise<Result>;
84
+ declare class Router<ContextFrom, ContextTo, RequiredParams extends string, Routes 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, Routes, Input>);
88
+ get routes(): Set<Routes>;
89
+ private readonly add;
90
+ readonly params: [RequiredParams] extends [never] ? <NextParams extends string>() => Router<ContextFrom, ContextTo, NextParams, Routes, Input> : () => Router<ContextFrom, ContextTo, RequiredParams, Routes, 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, Routes | PrefixRoutesPath<PathPrefix, OtherRoutes>, Input>;
92
+ protected static getFindRoute: <R>(routes: Map<KaitoMethod, Map<string, R>>) => (method: KaitoMethod, path: string) => {
93
+ route?: never;
94
+ params?: never;
95
+ } | {
96
+ route: R;
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, Routes | Route<ContextFrom, ContextTo, Input, never, Response, "/openapi.json", RequiredParams, "GET", {}, never>, Input>;
104
+ private readonly method;
105
+ readonly get: <Path extends string, ResultInput = never, ResultOutput = ResultInput, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => ResultOutput | Promise<ResultOutput>) | Omit<Route<ContextFrom, ContextTo, Input, ResultInput, ResultOutput, Path, RequiredParams, "GET", Query, Body>, "body" | "path" | "method" | "router">) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, ResultInput, ResultOutput, Path, RequiredParams, "GET", Query, Body>, Input>;
106
+ readonly post: <Path extends string, ResultInput = never, ResultOutput = ResultInput, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => ResultOutput | Promise<ResultOutput>) | Omit<Route<ContextFrom, ContextTo, Input, ResultInput, ResultOutput, Path, RequiredParams, "POST", Query, Body>, "path" | "method" | "router">) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, ResultInput, ResultOutput, Path, RequiredParams, "POST", Query, Body>, Input>;
107
+ readonly put: <Path extends string, ResultInput = never, ResultOutput = ResultInput, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => ResultOutput | Promise<ResultOutput>) | Omit<Route<ContextFrom, ContextTo, Input, ResultInput, ResultOutput, Path, RequiredParams, "PUT", Query, Body>, "path" | "method" | "router">) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, ResultInput, ResultOutput, Path, RequiredParams, "PUT", Query, Body>, Input>;
108
+ readonly patch: <Path extends string, ResultInput = never, ResultOutput = ResultInput, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => ResultOutput | Promise<ResultOutput>) | Omit<Route<ContextFrom, ContextTo, Input, ResultInput, ResultOutput, Path, RequiredParams, "PATCH", Query, Body>, "path" | "method" | "router">) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, ResultInput, ResultOutput, Path, RequiredParams, "PATCH", Query, Body>, Input>;
109
+ readonly delete: <Path extends string, ResultInput = never, ResultOutput = ResultInput, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => ResultOutput | Promise<ResultOutput>) | Omit<Route<ContextFrom, ContextTo, Input, ResultInput, ResultOutput, Path, RequiredParams, "DELETE", Query, Body>, "path" | "method" | "router">) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, ResultInput, ResultOutput, Path, RequiredParams, "DELETE", Query, Body>, Input>;
110
+ readonly head: <Path extends string, ResultInput = never, ResultOutput = ResultInput, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => ResultOutput | Promise<ResultOutput>) | Omit<Route<ContextFrom, ContextTo, Input, ResultInput, ResultOutput, Path, RequiredParams, "HEAD", Query, Body>, "path" | "method" | "router">) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, ResultInput, ResultOutput, Path, RequiredParams, "HEAD", Query, Body>, Input>;
111
+ readonly options: <Path extends string, ResultInput = never, ResultOutput = ResultInput, Query extends AnyQuery = {}, Body extends JSONValue = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, Body>) => ResultOutput | Promise<ResultOutput>) | Omit<Route<ContextFrom, ContextTo, Input, ResultInput, ResultOutput, Path, RequiredParams, "OPTIONS", Query, Body>, "path" | "method" | "router">) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, ResultInput, ResultOutput, Path, RequiredParams, "OPTIONS", Query, Body>, Input>;
112
+ through: <NextContext>(through: (context: ContextTo, params: Record<RequiredParams, string>) => MaybePromise<NextContext>) => Router<ContextFrom, NextContext, RequiredParams, Routes, Input>;
113
+ }
111
114
 
112
- type RouteRunData<Path extends string, Context, QueryOutput, BodyOutput> = {
115
+ type RouteRunData<Params extends string, Context, QueryOutput, BodyOutput> = {
116
+ params: Record<Params, string>;
113
117
  ctx: Context;
114
- body: BodyOutput;
115
118
  query: QueryOutput;
116
- params: ExtractRouteParams<Path>;
119
+ body: BodyOutput;
117
120
  };
118
121
  type AnyQuery = {
119
122
  [key in string]: any;
120
123
  };
121
- type Through<From, To> = (context: From) => Promise<To>;
122
- 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> = {
123
126
  type: 'sse';
124
- schema: z.Schema<Result>;
125
- description?: string;
127
+ schema: AnySchemaFor<Result>;
128
+ description?: string | undefined;
126
129
  };
127
- type JSONOutputSpec<Result> = {
130
+ type JSONOutputSpec<ResultInput, ResultOutput extends JSONValue> = {
128
131
  type: 'json';
129
- schema: z.Schema<Result>;
130
- description?: string;
132
+ schema: BaseSchema<ResultOutput, ResultInput, BaseSchemaDef<ResultOutput>>;
133
+ description?: string | undefined;
131
134
  };
132
- type OutputSpec<Result> = {
135
+ type OutputSpec<ResultInput, ResultOutput> = ResultInput extends KaitoSSEResponse<infer R> ? SSEOutputSpec<Extract<R, JSONValue>> & {
136
+ description?: string;
137
+ } : JSONOutputSpec<ResultOutput, Extract<ResultInput, JSONValue>> & {
133
138
  description?: string;
134
- body: NoInfer<Result extends KaitoSSEResponse<infer R> ? SSEOutputSpec<R> : JSONOutputSpec<Result>>;
135
139
  };
136
- type Route<ContextTo, Result, Path extends string, Method extends KaitoMethod, Query, Body> = {
137
- through: Through<unknown, ContextTo>;
138
- body?: z.Schema<Body>;
140
+ type Route<ContextFrom, ContextTo, RouterInput extends readonly unknown[], ResultInput, ResultOutput, Path extends string, AdditionalParams extends string, Method extends KaitoMethod, Query extends Record<string, JSONValue>, Body extends JSONValue> = {
141
+ body?: AnySchemaFor<Body>;
139
142
  query?: {
140
- [Key in keyof Query]: z.Schema<Query[Key]>;
143
+ [Key in keyof Query]: AnySchemaFor<Query[Key]>;
141
144
  };
142
145
  path: Path;
143
146
  method: Method;
144
- openapi?: OutputSpec<NoInfer<Result>>;
145
- run(data: RouteRunData<Path, ContextTo, Query, Body>): Promise<Result> | Result;
147
+ openapi?: OutputSpec<ResultInput, ResultOutput>;
148
+ router: Router<ContextFrom, ContextTo, AdditionalParams, AnyRoute, RouterInput>;
149
+ run(data: RouteRunData<ExtractRouteParams<Path> | AdditionalParams, ContextTo, Query, Body>): Promise<ResultOutput> | ResultOutput;
146
150
  };
147
- type AnyRoute = Route<any, any, any, any, any, any>;
151
+ type AnyRoute = Route<any, any, any, any, any, any, any, any, any, any>;
148
152
 
149
- type PrefixRoutesPathInner<R extends AnyRoute, Prefix extends `/${string}`> = R extends Route<infer ContextTo, infer Result, infer Path, infer Method, infer Query, infer BodyOutput> ? Route<ContextTo, Result, `${Prefix}${Path}`, Method, Query, BodyOutput> : never;
150
- type PrefixRoutesPath<Prefix extends `/${string}`, R extends AnyRoute> = R extends R ? PrefixRoutesPathInner<R, Prefix> : never;
151
- type RouterState<ContextFrom, ContextTo, Routes extends AnyRoute> = {
152
- routes: Set<Routes>;
153
- through: (context: unknown) => Promise<ContextTo>;
154
- config: KaitoConfig<ContextFrom>;
153
+ /**
154
+ * A helper to check if the environment is Node.js-like and the `NODE_ENV` environment variable is set to `'development'`
155
+ */
156
+ declare const isNodeLikeDev: boolean;
157
+ type ErroredAPIResponse = {
158
+ success: false;
159
+ data: null;
160
+ message: string;
161
+ };
162
+ type SuccessfulAPIResponse<T> = {
163
+ success: true;
164
+ data: T;
155
165
  };
166
+ type APIResponse<T> = ErroredAPIResponse | SuccessfulAPIResponse<T>;
167
+ type MaybePromise<T> = T | Promise<T>;
168
+ type KaitoMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS';
169
+ 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;
156
170
  /**
157
171
  * Accepts a router instance, and returns a union of all the routes in the router
158
172
  *
159
173
  * @example
160
174
  * ```ts
161
- * const app = router().get('/', () => 'Hello, world!');
175
+ * const app = router.get('/', () => 'Hello, world!');
162
176
  *
163
177
  * type Routes = InferRoutes<typeof app>;
164
178
  * ```
165
179
  */
166
- type InferRoutes<R extends Router<any, any, any>> = R extends Router<any, any, infer R extends AnyRoute> ? R : never;
167
- declare class Router<ContextFrom, ContextTo, R extends AnyRoute> {
168
- private readonly state;
169
- static create: <Context>(config: KaitoConfig<Context>) => Router<Context, Context, never>;
170
- constructor(state: RouterState<ContextFrom, ContextTo, R>);
171
- get routes(): Set<R>;
172
- private add;
173
- readonly merge: <PathPrefix extends `/${string}`, OtherRoutes extends AnyRoute>(pathPrefix: PathPrefix, other: Router<ContextFrom, unknown, OtherRoutes>) => Router<ContextFrom, ContextTo, Extract<R | PrefixRoutesPath<PathPrefix, Extract<OtherRoutes, AnyRoute>>, AnyRoute>>;
174
- protected static getFindRoute: <R_1>(routes: Map<KaitoMethod, Map<string, R_1>>) => (method: KaitoMethod, path: string) => {
175
- route?: never;
176
- params?: never;
177
- } | {
178
- route: R_1;
179
- params: Record<string, string>;
180
- };
181
- private static buildQuerySchema;
182
- serve: () => (request: Request) => Promise<Response>;
183
- openapi: (highLevelSpec: {
184
- info: {
185
- version: string;
186
- title: string;
187
- description?: string;
188
- };
189
- servers?: Partial<Record<(`https://` | `http://`) | ({} & string), string>>;
190
- }) => Router<ContextFrom, ContextTo, R | Route<ContextTo, Response, "/openapi.json", "GET", AnyQuery, unknown>>;
191
- private readonly method;
192
- get: <Result, Path extends string, Query extends AnyQuery = {}, Body = never>(path: Path, route: ((data: RouteRunData<Path, ContextTo, Query, Body>) => Result | Promise<Result>) | Omit<Route<ContextTo, Result, Path, "GET", Query, Body>, "body" | "path" | "method" | "through">) => Router<ContextFrom, ContextTo, R | Route<ContextTo, Result, Path, "GET", Query, Body>>;
193
- post: <Result, Path extends string, Query extends AnyQuery = {}, Body = never>(path: Path, route: ((data: RouteRunData<Path, ContextTo, Query, Body>) => Result | Promise<Result>) | Omit<Route<ContextTo, Result, Path, "POST", Query, Body>, "path" | "method" | "through">) => Router<ContextFrom, ContextTo, R | Route<ContextTo, Result, Path, "POST", Query, Body>>;
194
- put: <Result, Path extends string, Query extends AnyQuery = {}, Body = never>(path: Path, route: ((data: RouteRunData<Path, ContextTo, Query, Body>) => Result | Promise<Result>) | Omit<Route<ContextTo, Result, Path, "PUT", Query, Body>, "path" | "method" | "through">) => Router<ContextFrom, ContextTo, R | Route<ContextTo, Result, Path, "PUT", Query, Body>>;
195
- patch: <Result, Path extends string, Query extends AnyQuery = {}, Body = never>(path: Path, route: ((data: RouteRunData<Path, ContextTo, Query, Body>) => Result | Promise<Result>) | Omit<Route<ContextTo, Result, Path, "PATCH", Query, Body>, "path" | "method" | "through">) => Router<ContextFrom, ContextTo, R | Route<ContextTo, Result, Path, "PATCH", Query, Body>>;
196
- delete: <Result, Path extends string, Query extends AnyQuery = {}, Body = never>(path: Path, route: ((data: RouteRunData<Path, ContextTo, Query, Body>) => Result | Promise<Result>) | Omit<Route<ContextTo, Result, Path, "DELETE", Query, Body>, "path" | "method" | "through">) => Router<ContextFrom, ContextTo, R | Route<ContextTo, Result, Path, "DELETE", Query, Body>>;
197
- head: <Result, Path extends string, Query extends AnyQuery = {}, Body = never>(path: Path, route: ((data: RouteRunData<Path, ContextTo, Query, Body>) => Result | Promise<Result>) | Omit<Route<ContextTo, Result, Path, "HEAD", Query, Body>, "path" | "method" | "through">) => Router<ContextFrom, ContextTo, R | Route<ContextTo, Result, Path, "HEAD", Query, Body>>;
198
- options: <Result, Path extends string, Query extends AnyQuery = {}, Body = never>(path: Path, route: ((data: RouteRunData<Path, ContextTo, Query, Body>) => Result | Promise<Result>) | Omit<Route<ContextTo, Result, Path, "OPTIONS", Query, Body>, "path" | "method" | "through">) => Router<ContextFrom, ContextTo, R | Route<ContextTo, Result, Path, "OPTIONS", Query, Body>>;
199
- through: <NextContext>(through: (context: ContextTo) => MaybePromise<NextContext>) => Router<ContextFrom, NextContext, R>;
200
- }
180
+ type InferRoutes<R extends Router<never, never, never, never, never>> = R extends Router<any, any, any, infer R extends AnyRoute, any> ? R : never;
181
+ /**
182
+ * A function that is called to get the context for a request.
183
+ *
184
+ * This is useful for things like authentication, to pass in a database connection, etc.
185
+ *
186
+ * It's fine for this function to throw; if it does, the error is passed to the `onError` function.
187
+ *
188
+ * @param req - The kaito request object, which contains the request method, url, headers, etc
189
+ * @param head - The kaito head object, which contains getters and setters for headers and status
190
+ * @returns The context for your routes
191
+ */
192
+ type GetContext<Result, Input extends readonly unknown[]> = (req: KaitoRequest, head: KaitoHead, ...args: Input) => MaybePromise<Result>;
201
193
 
202
- type KaitoConfig<ContextFrom> = {
194
+ interface KaitoConfig<ContextFrom, Input extends readonly unknown[]> {
203
195
  /**
204
196
  * A function that is called to get the context for a request.
205
197
  *
@@ -207,7 +199,7 @@ type KaitoConfig<ContextFrom> = {
207
199
  *
208
200
  * It's fine for this function to throw; if it does, the error is passed to the `onError` function.
209
201
  */
210
- getContext?: GetContext<ContextFrom>;
202
+ getContext?: GetContext<ContextFrom, Input>;
211
203
  /**
212
204
  * A function that is called when an error occurs inside a route handler.
213
205
  *
@@ -256,15 +248,16 @@ type KaitoConfig<ContextFrom> = {
256
248
  * ```
257
249
  */
258
250
  transform?: (req: Request, res: Response) => MaybePromise<Response | void | undefined>;
259
- };
251
+ }
252
+
260
253
  /**
261
- * Create a helper function for instantiating a Kaito router
254
+ * Helper function for instantiating a Kaito router
262
255
  *
263
256
  * This is the starting point for any Kaito application
264
257
  *
265
258
  * @param config - The configuration for the router
266
259
  * @returns A new Kaito router
267
260
  */
268
- declare function create<Context = null>(config?: KaitoConfig<Context>): () => Router<Context, Context, never>;
261
+ declare const create: <Context = null, Input extends readonly unknown[] = []>(config?: KaitoConfig<Context, Input>) => Router<Context, Context, never, never, Input>;
269
262
 
270
- export { type APIResponse, type AnyQuery, type AnyResponse, type AnyRoute, type ErroredAPIResponse, type ExtractRouteParams, type GetContext, type InferRoutes, type JSONOutputSpec, type KaitoConfig, KaitoError, type KaitoMethod, KaitoRequest, type MakeOptional, type MaybePromise, type OutputSpec, type Route, type RouteRunData, Router, type RouterState, type SSEOutputSpec, type SuccessfulAPIResponse, type Through, WrappedError, create, isNodeLikeDev };
263
+ export { type APIResponse, type AnyQuery, type AnyRoute, AnySchemaFor, BaseSchema, BaseSchemaDef, 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 };