@kaito-http/core 4.0.0-beta.32 → 4.0.0-beta.33
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 +10 -8
- package/dist/index.d.cts +5 -6
- package/dist/index.d.ts +5 -6
- package/dist/index.js +10 -8
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1170,7 +1170,7 @@ var isNodeLikeDev = typeof process !== "undefined" && typeof process.env !== "un
|
|
|
1170
1170
|
// src/router/router.ts
|
|
1171
1171
|
var Router = class _Router {
|
|
1172
1172
|
#state;
|
|
1173
|
-
static create = (config = {}) => new _Router({
|
|
1173
|
+
static create = (config = {}) => new _Router({ pipe: (context) => context, routes: /* @__PURE__ */ new Set(), config });
|
|
1174
1174
|
constructor(state) {
|
|
1175
1175
|
this.#state = state;
|
|
1176
1176
|
}
|
|
@@ -1252,9 +1252,11 @@ var Router = class _Router {
|
|
|
1252
1252
|
try {
|
|
1253
1253
|
const body = route.body ? await route.body.parse(await req.json()) : void 0;
|
|
1254
1254
|
const query = route.fastQuerySchema ? route.fastQuerySchema.parse(url.searchParams) : {};
|
|
1255
|
-
const ctx = await route.router.#state.
|
|
1255
|
+
const ctx = await route.router.#state.pipe(
|
|
1256
1256
|
await this.#state.config.getContext?.(request, head, ...args) ?? null,
|
|
1257
|
-
rawParams
|
|
1257
|
+
rawParams,
|
|
1258
|
+
request,
|
|
1259
|
+
head
|
|
1258
1260
|
);
|
|
1259
1261
|
const result = await route.run({
|
|
1260
1262
|
ctx,
|
|
@@ -1481,15 +1483,15 @@ var Router = class _Router {
|
|
|
1481
1483
|
delete = this.method("DELETE");
|
|
1482
1484
|
head = this.method("HEAD");
|
|
1483
1485
|
options = this.method("OPTIONS");
|
|
1484
|
-
|
|
1486
|
+
pipe = (pipe) => {
|
|
1485
1487
|
return new _Router({
|
|
1486
1488
|
...this.#state,
|
|
1487
|
-
|
|
1488
|
-
const next = this.#state.
|
|
1489
|
+
pipe: (context, params, request, head) => {
|
|
1490
|
+
const next = this.#state.pipe(context, params, request, head);
|
|
1489
1491
|
if (next instanceof Promise) {
|
|
1490
|
-
return next.then((next2) =>
|
|
1492
|
+
return next.then((next2) => pipe(next2, params, request, head));
|
|
1491
1493
|
}
|
|
1492
|
-
return
|
|
1494
|
+
return pipe(next, params, request, head);
|
|
1493
1495
|
}
|
|
1494
1496
|
});
|
|
1495
1497
|
};
|
package/dist/index.d.cts
CHANGED
|
@@ -74,13 +74,13 @@ declare class KaitoHead {
|
|
|
74
74
|
get touched(): boolean;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
type
|
|
78
|
-
type PrefixRoutesPath<Prefix extends `/${string}`, R extends AnyRoute> = R extends R ? PrefixRoutesPathInner<R, Prefix> : never;
|
|
77
|
+
type PrefixRoutesPath<Prefix extends `/${string}`, R extends AnyRoute> = R extends R ? R extends Route<infer ContextFrom, infer ContextTo, infer RouterInput, infer ResultOutput, infer Path, infer AdditionalParams, infer Method, infer Query, infer BodyInput, infer BodyOutput> ? Route<ContextFrom, ContextTo, RouterInput, ResultOutput, `${Prefix}${Path extends '/' ? '' : Path}`, AdditionalParams, Method, Query, BodyInput, BodyOutput> : never : never;
|
|
79
78
|
type RouterState<ContextFrom, ContextTo, RequiredParams extends string, Routes extends AnyRoute, Input extends readonly unknown[]> = {
|
|
80
79
|
routes: Set<Routes>;
|
|
81
|
-
|
|
80
|
+
pipe: (context: ContextFrom, params: Record<RequiredParams, string>, request: KaitoRequest, head: KaitoHead) => Promise<ContextTo> | ContextTo;
|
|
82
81
|
config: KaitoConfig<ContextFrom, Input>;
|
|
83
82
|
};
|
|
83
|
+
type Params<P extends string = string> = Record<P, string>;
|
|
84
84
|
declare class Router<ContextFrom, ContextTo, RequiredParams extends string, Routes extends AnyRoute, Input extends readonly unknown[]> {
|
|
85
85
|
#private;
|
|
86
86
|
static create: <Context = null, Input_1 extends readonly unknown[] = []>(config?: KaitoConfig<Context, Input_1>) => Router<Context, Context, never, never, Input_1>;
|
|
@@ -144,7 +144,7 @@ declare class Router<ContextFrom, ContextTo, RequiredParams extends string, Rout
|
|
|
144
144
|
readonly options: <Path extends string, ResultOutput = never, Query extends AnyQuery = {}, BodyInput extends JSONValue = never, BodyOutput = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, BodyOutput>) => ResultOutput | Promise<ResultOutput>) | (Omit<Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "OPTIONS", Query, BodyInput, BodyOutput>, "path" | "method" | "router" | "openapi"> & {
|
|
145
145
|
openapi?: OpenAPISpecFor<ResultOutput>;
|
|
146
146
|
})) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "OPTIONS", Query, BodyInput, BodyOutput>, Input>;
|
|
147
|
-
|
|
147
|
+
pipe: <NextContext>(pipe: (context: ContextTo, params: Record<RequiredParams, string>, request: KaitoRequest, head: KaitoHead) => MaybePromise<NextContext>) => Router<ContextFrom, NextContext, RequiredParams, Routes, Input>;
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
type RouteRunData<Params extends string, Context, QueryOutput, BodyOutput> = {
|
|
@@ -156,7 +156,6 @@ type RouteRunData<Params extends string, Context, QueryOutput, BodyOutput> = {
|
|
|
156
156
|
type AnyQuery = {
|
|
157
157
|
[key in string]: any;
|
|
158
158
|
};
|
|
159
|
-
type Through<From, To, RequiredParams extends string> = (context: From, params: Record<RequiredParams, string>) => Promise<To>;
|
|
160
159
|
/**
|
|
161
160
|
* Wraps BaseSchema to prevent the schema from participating in inference for `Output`.
|
|
162
161
|
*
|
|
@@ -309,4 +308,4 @@ interface KaitoConfig<ContextFrom, Input extends readonly unknown[]> {
|
|
|
309
308
|
*/
|
|
310
309
|
declare const create: <Context = null, Input extends readonly unknown[] = []>(config?: KaitoConfig<Context, Input>) => Router<Context, Context, never, never, Input>;
|
|
311
310
|
|
|
312
|
-
export { type AnyOutputSpec, type AnyQuery, type AnyRoute, AnySchemaFor, BaseSchema, BaseSchemaDef, type ExtractRouteParams, type GetContext, type InferRoutes, type JSONOutputSpec, JSONValue, type KaitoConfig, KaitoError, KaitoHead, type KaitoMethod, KaitoRequest, type MaybePromise, type OpenAPISpecFor, type ResponseOutputSpec, type Route, type RouteRunData, Router, type RouterState, type SSEOutputSpec, type SSEOutputSpecWithSchema, type SSEOutputSpecWithoutSchema,
|
|
311
|
+
export { type AnyOutputSpec, type AnyQuery, type AnyRoute, AnySchemaFor, BaseSchema, BaseSchemaDef, type ExtractRouteParams, type GetContext, type InferRoutes, type JSONOutputSpec, JSONValue, type KaitoConfig, KaitoError, KaitoHead, type KaitoMethod, KaitoRequest, type MaybePromise, type OpenAPISpecFor, type Params, type ResponseOutputSpec, type Route, type RouteRunData, Router, type RouterState, type SSEOutputSpec, type SSEOutputSpecWithSchema, type SSEOutputSpecWithoutSchema, WrappedError, create, isNodeLikeDev };
|
package/dist/index.d.ts
CHANGED
|
@@ -74,13 +74,13 @@ declare class KaitoHead {
|
|
|
74
74
|
get touched(): boolean;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
type
|
|
78
|
-
type PrefixRoutesPath<Prefix extends `/${string}`, R extends AnyRoute> = R extends R ? PrefixRoutesPathInner<R, Prefix> : never;
|
|
77
|
+
type PrefixRoutesPath<Prefix extends `/${string}`, R extends AnyRoute> = R extends R ? R extends Route<infer ContextFrom, infer ContextTo, infer RouterInput, infer ResultOutput, infer Path, infer AdditionalParams, infer Method, infer Query, infer BodyInput, infer BodyOutput> ? Route<ContextFrom, ContextTo, RouterInput, ResultOutput, `${Prefix}${Path extends '/' ? '' : Path}`, AdditionalParams, Method, Query, BodyInput, BodyOutput> : never : never;
|
|
79
78
|
type RouterState<ContextFrom, ContextTo, RequiredParams extends string, Routes extends AnyRoute, Input extends readonly unknown[]> = {
|
|
80
79
|
routes: Set<Routes>;
|
|
81
|
-
|
|
80
|
+
pipe: (context: ContextFrom, params: Record<RequiredParams, string>, request: KaitoRequest, head: KaitoHead) => Promise<ContextTo> | ContextTo;
|
|
82
81
|
config: KaitoConfig<ContextFrom, Input>;
|
|
83
82
|
};
|
|
83
|
+
type Params<P extends string = string> = Record<P, string>;
|
|
84
84
|
declare class Router<ContextFrom, ContextTo, RequiredParams extends string, Routes extends AnyRoute, Input extends readonly unknown[]> {
|
|
85
85
|
#private;
|
|
86
86
|
static create: <Context = null, Input_1 extends readonly unknown[] = []>(config?: KaitoConfig<Context, Input_1>) => Router<Context, Context, never, never, Input_1>;
|
|
@@ -144,7 +144,7 @@ declare class Router<ContextFrom, ContextTo, RequiredParams extends string, Rout
|
|
|
144
144
|
readonly options: <Path extends string, ResultOutput = never, Query extends AnyQuery = {}, BodyInput extends JSONValue = never, BodyOutput = never>(path: Path, route: ((data: RouteRunData<RequiredParams | ExtractRouteParams<Path>, ContextTo, Query, BodyOutput>) => ResultOutput | Promise<ResultOutput>) | (Omit<Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "OPTIONS", Query, BodyInput, BodyOutput>, "path" | "method" | "router" | "openapi"> & {
|
|
145
145
|
openapi?: OpenAPISpecFor<ResultOutput>;
|
|
146
146
|
})) => Router<ContextFrom, ContextTo, RequiredParams, Routes | Route<ContextFrom, ContextTo, Input, ResultOutput, Path, RequiredParams, "OPTIONS", Query, BodyInput, BodyOutput>, Input>;
|
|
147
|
-
|
|
147
|
+
pipe: <NextContext>(pipe: (context: ContextTo, params: Record<RequiredParams, string>, request: KaitoRequest, head: KaitoHead) => MaybePromise<NextContext>) => Router<ContextFrom, NextContext, RequiredParams, Routes, Input>;
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
type RouteRunData<Params extends string, Context, QueryOutput, BodyOutput> = {
|
|
@@ -156,7 +156,6 @@ type RouteRunData<Params extends string, Context, QueryOutput, BodyOutput> = {
|
|
|
156
156
|
type AnyQuery = {
|
|
157
157
|
[key in string]: any;
|
|
158
158
|
};
|
|
159
|
-
type Through<From, To, RequiredParams extends string> = (context: From, params: Record<RequiredParams, string>) => Promise<To>;
|
|
160
159
|
/**
|
|
161
160
|
* Wraps BaseSchema to prevent the schema from participating in inference for `Output`.
|
|
162
161
|
*
|
|
@@ -309,4 +308,4 @@ interface KaitoConfig<ContextFrom, Input extends readonly unknown[]> {
|
|
|
309
308
|
*/
|
|
310
309
|
declare const create: <Context = null, Input extends readonly unknown[] = []>(config?: KaitoConfig<Context, Input>) => Router<Context, Context, never, never, Input>;
|
|
311
310
|
|
|
312
|
-
export { type AnyOutputSpec, type AnyQuery, type AnyRoute, AnySchemaFor, BaseSchema, BaseSchemaDef, type ExtractRouteParams, type GetContext, type InferRoutes, type JSONOutputSpec, JSONValue, type KaitoConfig, KaitoError, KaitoHead, type KaitoMethod, KaitoRequest, type MaybePromise, type OpenAPISpecFor, type ResponseOutputSpec, type Route, type RouteRunData, Router, type RouterState, type SSEOutputSpec, type SSEOutputSpecWithSchema, type SSEOutputSpecWithoutSchema,
|
|
311
|
+
export { type AnyOutputSpec, type AnyQuery, type AnyRoute, AnySchemaFor, BaseSchema, BaseSchemaDef, type ExtractRouteParams, type GetContext, type InferRoutes, type JSONOutputSpec, JSONValue, type KaitoConfig, KaitoError, KaitoHead, type KaitoMethod, KaitoRequest, type MaybePromise, type OpenAPISpecFor, type Params, type ResponseOutputSpec, type Route, type RouteRunData, Router, type RouterState, type SSEOutputSpec, type SSEOutputSpecWithSchema, type SSEOutputSpecWithoutSchema, WrappedError, create, isNodeLikeDev };
|
package/dist/index.js
CHANGED
|
@@ -140,7 +140,7 @@ var isNodeLikeDev = typeof process !== "undefined" && typeof process.env !== "un
|
|
|
140
140
|
// src/router/router.ts
|
|
141
141
|
var Router = class _Router {
|
|
142
142
|
#state;
|
|
143
|
-
static create = (config = {}) => new _Router({
|
|
143
|
+
static create = (config = {}) => new _Router({ pipe: (context) => context, routes: /* @__PURE__ */ new Set(), config });
|
|
144
144
|
constructor(state) {
|
|
145
145
|
this.#state = state;
|
|
146
146
|
}
|
|
@@ -222,9 +222,11 @@ var Router = class _Router {
|
|
|
222
222
|
try {
|
|
223
223
|
const body = route.body ? await route.body.parse(await req.json()) : void 0;
|
|
224
224
|
const query = route.fastQuerySchema ? route.fastQuerySchema.parse(url.searchParams) : {};
|
|
225
|
-
const ctx = await route.router.#state.
|
|
225
|
+
const ctx = await route.router.#state.pipe(
|
|
226
226
|
await this.#state.config.getContext?.(request, head, ...args) ?? null,
|
|
227
|
-
rawParams
|
|
227
|
+
rawParams,
|
|
228
|
+
request,
|
|
229
|
+
head
|
|
228
230
|
);
|
|
229
231
|
const result = await route.run({
|
|
230
232
|
ctx,
|
|
@@ -451,15 +453,15 @@ var Router = class _Router {
|
|
|
451
453
|
delete = this.method("DELETE");
|
|
452
454
|
head = this.method("HEAD");
|
|
453
455
|
options = this.method("OPTIONS");
|
|
454
|
-
|
|
456
|
+
pipe = (pipe) => {
|
|
455
457
|
return new _Router({
|
|
456
458
|
...this.#state,
|
|
457
|
-
|
|
458
|
-
const next = this.#state.
|
|
459
|
+
pipe: (context, params, request, head) => {
|
|
460
|
+
const next = this.#state.pipe(context, params, request, head);
|
|
459
461
|
if (next instanceof Promise) {
|
|
460
|
-
return next.then((next2) =>
|
|
462
|
+
return next.then((next2) => pipe(next2, params, request, head));
|
|
461
463
|
}
|
|
462
|
-
return
|
|
464
|
+
return pipe(next, params, request, head);
|
|
463
465
|
}
|
|
464
466
|
});
|
|
465
467
|
};
|