@kaito-http/core 4.0.0-beta.2 → 4.0.0-beta.4
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 +4 -1
- package/dist/index.d.cts +24 -23
- package/dist/index.d.ts +24 -23
- package/dist/index.js +3 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
KaitoError: () => KaitoError,
|
|
24
|
+
KaitoHead: () => KaitoHead,
|
|
24
25
|
KaitoRequest: () => KaitoRequest,
|
|
25
26
|
Router: () => Router,
|
|
26
27
|
WrappedError: () => WrappedError,
|
|
@@ -168,6 +169,7 @@ var Router = class _Router {
|
|
|
168
169
|
routes: /* @__PURE__ */ new Set([...this.state.routes, merged])
|
|
169
170
|
});
|
|
170
171
|
};
|
|
172
|
+
params = () => new _Router(this.state);
|
|
171
173
|
merge = (pathPrefix, other) => {
|
|
172
174
|
const newRoutes = [...other.state.routes].map((route) => ({
|
|
173
175
|
...route,
|
|
@@ -405,11 +407,12 @@ var Router = class _Router {
|
|
|
405
407
|
|
|
406
408
|
// src/create.ts
|
|
407
409
|
function create(config = {}) {
|
|
408
|
-
return
|
|
410
|
+
return Router.create(config);
|
|
409
411
|
}
|
|
410
412
|
// Annotate the CommonJS export names for ESM import in node:
|
|
411
413
|
0 && (module.exports = {
|
|
412
414
|
KaitoError,
|
|
415
|
+
KaitoHead,
|
|
413
416
|
KaitoRequest,
|
|
414
417
|
Router,
|
|
415
418
|
WrappedError,
|
package/dist/index.d.cts
CHANGED
|
@@ -27,7 +27,7 @@ declare class KaitoRequest {
|
|
|
27
27
|
get request(): Request;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
type KaitoMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS'
|
|
30
|
+
type KaitoMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS';
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* This class is merely a wrapper around a `Headers` object and a status code.
|
|
@@ -109,11 +109,11 @@ type ExtractRouteParams<T extends string> = string extends T ? Record<string, st
|
|
|
109
109
|
*/
|
|
110
110
|
type GetContext<Result> = (req: KaitoRequest, head: KaitoHead) => MaybePromise<Result>;
|
|
111
111
|
|
|
112
|
-
type RouteRunData<
|
|
112
|
+
type RouteRunData<Params, Context, QueryOutput, BodyOutput> = {
|
|
113
113
|
ctx: Context;
|
|
114
114
|
body: BodyOutput;
|
|
115
115
|
query: QueryOutput;
|
|
116
|
-
params:
|
|
116
|
+
params: Params;
|
|
117
117
|
};
|
|
118
118
|
type AnyQuery = {
|
|
119
119
|
[key in string]: any;
|
|
@@ -133,7 +133,7 @@ type OutputSpec<Result> = {
|
|
|
133
133
|
description?: string;
|
|
134
134
|
body: NoInfer<Result extends KaitoSSEResponse<infer R> ? SSEOutputSpec<R> : JSONOutputSpec<Result>>;
|
|
135
135
|
};
|
|
136
|
-
type Route<ContextTo, Result, Path extends string, Method extends KaitoMethod, Query, Body> = {
|
|
136
|
+
type Route<ContextTo, Result, Path extends string, AdditionalParams extends Record<string, string>, Method extends KaitoMethod, Query, Body> = {
|
|
137
137
|
through: Through<unknown, ContextTo>;
|
|
138
138
|
body?: z.Schema<Body>;
|
|
139
139
|
query?: {
|
|
@@ -142,11 +142,11 @@ type Route<ContextTo, Result, Path extends string, Method extends KaitoMethod, Q
|
|
|
142
142
|
path: Path;
|
|
143
143
|
method: Method;
|
|
144
144
|
openapi?: OutputSpec<NoInfer<Result>>;
|
|
145
|
-
run(data: RouteRunData<Path, ContextTo, Query, Body>): Promise<Result> | Result;
|
|
145
|
+
run(data: RouteRunData<ExtractRouteParams<Path> & AdditionalParams, ContextTo, Query, Body>): Promise<Result> | Result;
|
|
146
146
|
};
|
|
147
|
-
type AnyRoute = Route<any, any, any, any, any, any>;
|
|
147
|
+
type AnyRoute = Route<any, any, any, any, any, any, any>;
|
|
148
148
|
|
|
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;
|
|
149
|
+
type PrefixRoutesPathInner<R extends AnyRoute, Prefix extends `/${string}`> = R extends Route<infer ContextTo, infer Result, infer Path, infer AdditionalParams, infer Method, infer Query, infer BodyOutput> ? Route<ContextTo, Result, `${Prefix}${Path}`, AdditionalParams, Method, Query, BodyOutput> : never;
|
|
150
150
|
type PrefixRoutesPath<Prefix extends `/${string}`, R extends AnyRoute> = R extends R ? PrefixRoutesPathInner<R, Prefix> : never;
|
|
151
151
|
type RouterState<ContextFrom, ContextTo, Routes extends AnyRoute> = {
|
|
152
152
|
routes: Set<Routes>;
|
|
@@ -163,14 +163,15 @@ type RouterState<ContextFrom, ContextTo, Routes extends AnyRoute> = {
|
|
|
163
163
|
* type Routes = InferRoutes<typeof app>;
|
|
164
164
|
* ```
|
|
165
165
|
*/
|
|
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
|
|
166
|
+
type InferRoutes<R extends Router<any, any, any, any>> = R extends Router<any, any, infer R extends AnyRoute, any> ? R : never;
|
|
167
|
+
declare class Router<ContextFrom, ContextTo, R extends AnyRoute, RequiredParams extends Record<string, string>> {
|
|
168
168
|
private readonly state;
|
|
169
|
-
static create: <Context>(config: KaitoConfig<Context>) => Router<Context, Context, never>;
|
|
170
|
-
constructor(
|
|
169
|
+
static create: <Context>(config: KaitoConfig<Context>) => Router<Context, Context, never, {}>;
|
|
170
|
+
private constructor();
|
|
171
171
|
get routes(): Set<R>;
|
|
172
172
|
private add;
|
|
173
|
-
|
|
173
|
+
params: this extends Router<infer ContextFrom, infer ContextTo, infer R extends AnyRoute, infer Params extends Record<string, string>> ? [keyof Params] extends [never] ? <NextParams extends Record<string, string> = {}>() => Router<ContextFrom, ContextTo, R, NextParams> : 'You cannot define params() on a router that has already had params defined, as routes that already consume params can break.' : never;
|
|
174
|
+
readonly merge: <PathPrefix extends `/${string}`, OtherRoutes extends AnyRoute, NextRequiredParams extends Record<string, string>>(pathPrefix: keyof NextRequiredParams extends keyof ExtractRouteParams<PathPrefix> | keyof RequiredParams ? PathPrefix : `${string}:/${Exclude<Extract<keyof NextRequiredParams, string>, keyof RequiredParams>}${string}`, other: Router<ContextFrom, unknown, OtherRoutes, NextRequiredParams>) => Router<ContextFrom, ContextTo, Extract<R | PrefixRoutesPath<PathPrefix, Extract<OtherRoutes, AnyRoute>>, AnyRoute>, RequiredParams>;
|
|
174
175
|
protected static getFindRoute: <R_1>(routes: Map<KaitoMethod, Map<string, R_1>>) => (method: KaitoMethod, path: string) => {
|
|
175
176
|
route?: never;
|
|
176
177
|
params?: never;
|
|
@@ -187,16 +188,16 @@ declare class Router<ContextFrom, ContextTo, R extends AnyRoute> {
|
|
|
187
188
|
description?: string;
|
|
188
189
|
};
|
|
189
190
|
servers?: Partial<Record<(`https://` | `http://`) | ({} & string), string>>;
|
|
190
|
-
}) => Router<ContextFrom, ContextTo, R | Route<ContextTo, Response, "/openapi.json", "GET", AnyQuery, unknown
|
|
191
|
+
}) => Router<ContextFrom, ContextTo, R | Route<ContextTo, Response, "/openapi.json", RequiredParams, "GET", AnyQuery, unknown>, RequiredParams>;
|
|
191
192
|
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>;
|
|
193
|
+
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" | "through">) => Router<ContextFrom, ContextTo, R | Route<ContextTo, Result, Path, RequiredParams, "GET", Query, Body>, RequiredParams>;
|
|
194
|
+
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" | "through">) => Router<ContextFrom, ContextTo, R | Route<ContextTo, Result, Path, RequiredParams, "POST", Query, Body>, RequiredParams>;
|
|
195
|
+
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" | "through">) => Router<ContextFrom, ContextTo, R | Route<ContextTo, Result, Path, RequiredParams, "PUT", Query, Body>, RequiredParams>;
|
|
196
|
+
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" | "through">) => Router<ContextFrom, ContextTo, R | Route<ContextTo, Result, Path, RequiredParams, "PATCH", Query, Body>, RequiredParams>;
|
|
197
|
+
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" | "through">) => Router<ContextFrom, ContextTo, R | Route<ContextTo, Result, Path, RequiredParams, "DELETE", Query, Body>, RequiredParams>;
|
|
198
|
+
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" | "through">) => Router<ContextFrom, ContextTo, R | Route<ContextTo, Result, Path, RequiredParams, "HEAD", Query, Body>, RequiredParams>;
|
|
199
|
+
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" | "through">) => Router<ContextFrom, ContextTo, R | Route<ContextTo, Result, Path, RequiredParams, "OPTIONS", Query, Body>, RequiredParams>;
|
|
200
|
+
through: <NextContext>(through: (context: ContextTo) => MaybePromise<NextContext>) => Router<ContextFrom, NextContext, R, RequiredParams>;
|
|
200
201
|
}
|
|
201
202
|
|
|
202
203
|
type KaitoConfig<ContextFrom> = {
|
|
@@ -265,6 +266,6 @@ type KaitoConfig<ContextFrom> = {
|
|
|
265
266
|
* @param config - The configuration for the router
|
|
266
267
|
* @returns A new Kaito router
|
|
267
268
|
*/
|
|
268
|
-
declare function create<Context = null>(config?: KaitoConfig<Context>):
|
|
269
|
+
declare function create<Context = null>(config?: KaitoConfig<Context>): Router<Context, Context, never, {}>;
|
|
269
270
|
|
|
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 };
|
|
271
|
+
export { type APIResponse, type AnyQuery, type AnyResponse, type AnyRoute, type ErroredAPIResponse, type ExtractRouteParams, type GetContext, type InferRoutes, type JSONOutputSpec, type KaitoConfig, KaitoError, KaitoHead, 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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ declare class KaitoRequest {
|
|
|
27
27
|
get request(): Request;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
type KaitoMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS'
|
|
30
|
+
type KaitoMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS';
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* This class is merely a wrapper around a `Headers` object and a status code.
|
|
@@ -109,11 +109,11 @@ type ExtractRouteParams<T extends string> = string extends T ? Record<string, st
|
|
|
109
109
|
*/
|
|
110
110
|
type GetContext<Result> = (req: KaitoRequest, head: KaitoHead) => MaybePromise<Result>;
|
|
111
111
|
|
|
112
|
-
type RouteRunData<
|
|
112
|
+
type RouteRunData<Params, Context, QueryOutput, BodyOutput> = {
|
|
113
113
|
ctx: Context;
|
|
114
114
|
body: BodyOutput;
|
|
115
115
|
query: QueryOutput;
|
|
116
|
-
params:
|
|
116
|
+
params: Params;
|
|
117
117
|
};
|
|
118
118
|
type AnyQuery = {
|
|
119
119
|
[key in string]: any;
|
|
@@ -133,7 +133,7 @@ type OutputSpec<Result> = {
|
|
|
133
133
|
description?: string;
|
|
134
134
|
body: NoInfer<Result extends KaitoSSEResponse<infer R> ? SSEOutputSpec<R> : JSONOutputSpec<Result>>;
|
|
135
135
|
};
|
|
136
|
-
type Route<ContextTo, Result, Path extends string, Method extends KaitoMethod, Query, Body> = {
|
|
136
|
+
type Route<ContextTo, Result, Path extends string, AdditionalParams extends Record<string, string>, Method extends KaitoMethod, Query, Body> = {
|
|
137
137
|
through: Through<unknown, ContextTo>;
|
|
138
138
|
body?: z.Schema<Body>;
|
|
139
139
|
query?: {
|
|
@@ -142,11 +142,11 @@ type Route<ContextTo, Result, Path extends string, Method extends KaitoMethod, Q
|
|
|
142
142
|
path: Path;
|
|
143
143
|
method: Method;
|
|
144
144
|
openapi?: OutputSpec<NoInfer<Result>>;
|
|
145
|
-
run(data: RouteRunData<Path, ContextTo, Query, Body>): Promise<Result> | Result;
|
|
145
|
+
run(data: RouteRunData<ExtractRouteParams<Path> & AdditionalParams, ContextTo, Query, Body>): Promise<Result> | Result;
|
|
146
146
|
};
|
|
147
|
-
type AnyRoute = Route<any, any, any, any, any, any>;
|
|
147
|
+
type AnyRoute = Route<any, any, any, any, any, any, any>;
|
|
148
148
|
|
|
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;
|
|
149
|
+
type PrefixRoutesPathInner<R extends AnyRoute, Prefix extends `/${string}`> = R extends Route<infer ContextTo, infer Result, infer Path, infer AdditionalParams, infer Method, infer Query, infer BodyOutput> ? Route<ContextTo, Result, `${Prefix}${Path}`, AdditionalParams, Method, Query, BodyOutput> : never;
|
|
150
150
|
type PrefixRoutesPath<Prefix extends `/${string}`, R extends AnyRoute> = R extends R ? PrefixRoutesPathInner<R, Prefix> : never;
|
|
151
151
|
type RouterState<ContextFrom, ContextTo, Routes extends AnyRoute> = {
|
|
152
152
|
routes: Set<Routes>;
|
|
@@ -163,14 +163,15 @@ type RouterState<ContextFrom, ContextTo, Routes extends AnyRoute> = {
|
|
|
163
163
|
* type Routes = InferRoutes<typeof app>;
|
|
164
164
|
* ```
|
|
165
165
|
*/
|
|
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
|
|
166
|
+
type InferRoutes<R extends Router<any, any, any, any>> = R extends Router<any, any, infer R extends AnyRoute, any> ? R : never;
|
|
167
|
+
declare class Router<ContextFrom, ContextTo, R extends AnyRoute, RequiredParams extends Record<string, string>> {
|
|
168
168
|
private readonly state;
|
|
169
|
-
static create: <Context>(config: KaitoConfig<Context>) => Router<Context, Context, never>;
|
|
170
|
-
constructor(
|
|
169
|
+
static create: <Context>(config: KaitoConfig<Context>) => Router<Context, Context, never, {}>;
|
|
170
|
+
private constructor();
|
|
171
171
|
get routes(): Set<R>;
|
|
172
172
|
private add;
|
|
173
|
-
|
|
173
|
+
params: this extends Router<infer ContextFrom, infer ContextTo, infer R extends AnyRoute, infer Params extends Record<string, string>> ? [keyof Params] extends [never] ? <NextParams extends Record<string, string> = {}>() => Router<ContextFrom, ContextTo, R, NextParams> : 'You cannot define params() on a router that has already had params defined, as routes that already consume params can break.' : never;
|
|
174
|
+
readonly merge: <PathPrefix extends `/${string}`, OtherRoutes extends AnyRoute, NextRequiredParams extends Record<string, string>>(pathPrefix: keyof NextRequiredParams extends keyof ExtractRouteParams<PathPrefix> | keyof RequiredParams ? PathPrefix : `${string}:/${Exclude<Extract<keyof NextRequiredParams, string>, keyof RequiredParams>}${string}`, other: Router<ContextFrom, unknown, OtherRoutes, NextRequiredParams>) => Router<ContextFrom, ContextTo, Extract<R | PrefixRoutesPath<PathPrefix, Extract<OtherRoutes, AnyRoute>>, AnyRoute>, RequiredParams>;
|
|
174
175
|
protected static getFindRoute: <R_1>(routes: Map<KaitoMethod, Map<string, R_1>>) => (method: KaitoMethod, path: string) => {
|
|
175
176
|
route?: never;
|
|
176
177
|
params?: never;
|
|
@@ -187,16 +188,16 @@ declare class Router<ContextFrom, ContextTo, R extends AnyRoute> {
|
|
|
187
188
|
description?: string;
|
|
188
189
|
};
|
|
189
190
|
servers?: Partial<Record<(`https://` | `http://`) | ({} & string), string>>;
|
|
190
|
-
}) => Router<ContextFrom, ContextTo, R | Route<ContextTo, Response, "/openapi.json", "GET", AnyQuery, unknown
|
|
191
|
+
}) => Router<ContextFrom, ContextTo, R | Route<ContextTo, Response, "/openapi.json", RequiredParams, "GET", AnyQuery, unknown>, RequiredParams>;
|
|
191
192
|
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>;
|
|
193
|
+
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" | "through">) => Router<ContextFrom, ContextTo, R | Route<ContextTo, Result, Path, RequiredParams, "GET", Query, Body>, RequiredParams>;
|
|
194
|
+
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" | "through">) => Router<ContextFrom, ContextTo, R | Route<ContextTo, Result, Path, RequiredParams, "POST", Query, Body>, RequiredParams>;
|
|
195
|
+
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" | "through">) => Router<ContextFrom, ContextTo, R | Route<ContextTo, Result, Path, RequiredParams, "PUT", Query, Body>, RequiredParams>;
|
|
196
|
+
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" | "through">) => Router<ContextFrom, ContextTo, R | Route<ContextTo, Result, Path, RequiredParams, "PATCH", Query, Body>, RequiredParams>;
|
|
197
|
+
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" | "through">) => Router<ContextFrom, ContextTo, R | Route<ContextTo, Result, Path, RequiredParams, "DELETE", Query, Body>, RequiredParams>;
|
|
198
|
+
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" | "through">) => Router<ContextFrom, ContextTo, R | Route<ContextTo, Result, Path, RequiredParams, "HEAD", Query, Body>, RequiredParams>;
|
|
199
|
+
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" | "through">) => Router<ContextFrom, ContextTo, R | Route<ContextTo, Result, Path, RequiredParams, "OPTIONS", Query, Body>, RequiredParams>;
|
|
200
|
+
through: <NextContext>(through: (context: ContextTo) => MaybePromise<NextContext>) => Router<ContextFrom, NextContext, R, RequiredParams>;
|
|
200
201
|
}
|
|
201
202
|
|
|
202
203
|
type KaitoConfig<ContextFrom> = {
|
|
@@ -265,6 +266,6 @@ type KaitoConfig<ContextFrom> = {
|
|
|
265
266
|
* @param config - The configuration for the router
|
|
266
267
|
* @returns A new Kaito router
|
|
267
268
|
*/
|
|
268
|
-
declare function create<Context = null>(config?: KaitoConfig<Context>):
|
|
269
|
+
declare function create<Context = null>(config?: KaitoConfig<Context>): Router<Context, Context, never, {}>;
|
|
269
270
|
|
|
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 };
|
|
271
|
+
export { type APIResponse, type AnyQuery, type AnyResponse, type AnyRoute, type ErroredAPIResponse, type ExtractRouteParams, type GetContext, type InferRoutes, type JSONOutputSpec, type KaitoConfig, KaitoError, KaitoHead, 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 };
|
package/dist/index.js
CHANGED
|
@@ -137,6 +137,7 @@ var Router = class _Router {
|
|
|
137
137
|
routes: /* @__PURE__ */ new Set([...this.state.routes, merged])
|
|
138
138
|
});
|
|
139
139
|
};
|
|
140
|
+
params = () => new _Router(this.state);
|
|
140
141
|
merge = (pathPrefix, other) => {
|
|
141
142
|
const newRoutes = [...other.state.routes].map((route) => ({
|
|
142
143
|
...route,
|
|
@@ -374,10 +375,11 @@ var Router = class _Router {
|
|
|
374
375
|
|
|
375
376
|
// src/create.ts
|
|
376
377
|
function create(config = {}) {
|
|
377
|
-
return
|
|
378
|
+
return Router.create(config);
|
|
378
379
|
}
|
|
379
380
|
export {
|
|
380
381
|
KaitoError,
|
|
382
|
+
KaitoHead,
|
|
381
383
|
KaitoRequest,
|
|
382
384
|
Router,
|
|
383
385
|
WrappedError,
|