@kaito-http/core 2.9.4 → 3.0.0-beta.1
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/README.md +1 -4
- package/dist/declarations/src/index.d.ts +7 -7
- package/dist/declarations/src/req.d.ts +0 -1
- package/dist/declarations/src/res.d.ts +0 -1
- package/dist/declarations/src/route.d.ts +11 -7
- package/dist/declarations/src/router.d.ts +20 -27
- package/dist/declarations/src/server.d.ts +9 -10
- package/dist/declarations/src/util.d.ts +9 -7
- package/dist/kaito-http-core.d.ts +2 -0
- package/dist/{kaito-http-core.esm.js → kaito-http-core.js} +38 -23
- package/package.json +11 -13
- package/dist/kaito-http-core.cjs.d.ts +0 -1
- package/dist/kaito-http-core.cjs.dev.js +0 -557
- package/dist/kaito-http-core.cjs.js +0 -7
- package/dist/kaito-http-core.cjs.prod.js +0 -553
package/README.md
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
# `kaito-http`
|
|
2
2
|
|
|
3
|
-
[](https://vercel.com?utm_source=kaito-http&utm_campaign=oss)
|
|
4
|
-
|
|
5
3
|
#### An HTTP Framework for TypeScript
|
|
6
4
|
|
|
7
5
|
View the [documentation here](https://kaito.cloud)
|
|
8
6
|
|
|
9
7
|
#### Credits
|
|
10
8
|
|
|
11
|
-
- [
|
|
12
|
-
- [Alistair Smith](https://twitter.com/aabbccsmith)
|
|
9
|
+
- [Alistair Smith](https://twitter.com/alistaiir)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export type { HTTPMethod } from 'find-my-way';
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
2
|
+
export * from "./error.js";
|
|
3
|
+
export * from "./req.js";
|
|
4
|
+
export * from "./res.js";
|
|
5
|
+
export * from "./route.js";
|
|
6
|
+
export * from "./router.js";
|
|
7
|
+
export * from "./server.js";
|
|
8
|
+
export * from "./util.js";
|
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { ExtractRouteParams, KaitoMethod } from './util';
|
|
1
|
+
import type { ExtractRouteParams, KaitoMethod, Parsable } from "./util.js";
|
|
3
2
|
export type RouteArgument<Path extends string, Context, QueryOutput, BodyOutput> = {
|
|
4
3
|
ctx: Context;
|
|
5
4
|
body: BodyOutput;
|
|
6
5
|
query: QueryOutput;
|
|
7
6
|
params: ExtractRouteParams<Path>;
|
|
8
7
|
};
|
|
9
|
-
export type AnyQueryDefinition = Record<string,
|
|
10
|
-
export type
|
|
8
|
+
export type AnyQueryDefinition = Record<string, Parsable<any>>;
|
|
9
|
+
export type InferQuery<T extends AnyQueryDefinition> = {
|
|
10
|
+
[Key in keyof T]: InferParsable<T[Key]>;
|
|
11
|
+
};
|
|
12
|
+
export type InferParsable<T> = T extends Parsable<infer U> ? U : never;
|
|
13
|
+
export type RouteRunner<Result, Path extends string, Context, QueryOutput, BodyOutput> = (args: RouteArgument<Path, Context, QueryOutput, BodyOutput>) => Promise<Result>;
|
|
14
|
+
export type Route<ContextFrom, ContextTo, Result, Path extends string, Method extends KaitoMethod, Query extends AnyQueryDefinition, BodyOutput> = {
|
|
11
15
|
through: (context: ContextFrom) => Promise<ContextTo>;
|
|
12
|
-
body?:
|
|
16
|
+
body?: Parsable<BodyOutput>;
|
|
13
17
|
query?: Query;
|
|
14
18
|
path: Path;
|
|
15
19
|
method: Method;
|
|
16
|
-
run(
|
|
20
|
+
run(arg: RouteArgument<Path, ContextTo, InferQuery<Query>, BodyOutput>): Promise<Result>;
|
|
17
21
|
};
|
|
18
|
-
export type AnyRoute<FromContext = any, ToContext = any> = Route<FromContext, ToContext, any, any, any, AnyQueryDefinition, any
|
|
22
|
+
export type AnyRoute<FromContext = any, ToContext = any> = Route<FromContext, ToContext, any, any, any, AnyQueryDefinition, any>;
|
|
@@ -1,41 +1,34 @@
|
|
|
1
1
|
import fmw from 'find-my-way';
|
|
2
|
-
import {
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
-
|
|
6
|
-
type
|
|
7
|
-
type RemapRoutePrefix<R extends AnyRoute, Prefix extends `/${string}`> = R extends Route<infer ContextFrom, infer ContextTo, infer Result, infer Path, infer Method, infer Query, infer BodyOutput, infer BodyDef, infer BodyInput> ? Route<ContextFrom, ContextTo, Result, `${Prefix}${Path}`, Method, Query, BodyOutput, BodyDef, BodyInput> : never;
|
|
8
|
-
type PrefixRoutesPath<Prefix extends `/${string}`, R extends Routes> = R extends [infer First, ...infer Rest] ? [
|
|
9
|
-
RemapRoutePrefix<Extract<First, AnyRoute>, Prefix>,
|
|
10
|
-
...PrefixRoutesPath<Prefix, Extract<Rest, readonly AnyRoute[]>>
|
|
11
|
-
] : [];
|
|
2
|
+
import type { AnyQueryDefinition, AnyRoute, Route } from "./route.js";
|
|
3
|
+
import type { ServerConfig } from "./server.js";
|
|
4
|
+
import type { KaitoMethod } from "./util.js";
|
|
5
|
+
type PrefixRoutesPathInner<R extends AnyRoute, Prefix extends `/${string}`> = R extends Route<infer ContextFrom, infer ContextTo, infer Result, infer Path, infer Method, infer Query, infer BodyOutput> ? Route<ContextFrom, ContextTo, Result, `${Prefix}${Path}`, Method, Query, BodyOutput> : never;
|
|
6
|
+
type PrefixRoutesPath<Prefix extends `/${string}`, R extends AnyRoute> = R extends R ? PrefixRoutesPathInner<R, Prefix> : never;
|
|
12
7
|
export type RouterOptions<ContextFrom, ContextTo> = {
|
|
13
8
|
through: (context: ContextFrom) => Promise<ContextTo>;
|
|
14
9
|
};
|
|
15
|
-
export declare class Router<ContextFrom, ContextTo, R extends
|
|
10
|
+
export declare class Router<ContextFrom, ContextTo, R extends AnyRoute> {
|
|
16
11
|
private readonly routerOptions;
|
|
17
|
-
readonly routes: R
|
|
18
|
-
static create: <Context>() => Router<Context, Context,
|
|
12
|
+
readonly routes: Set<R>;
|
|
13
|
+
static create: <Context>() => Router<Context, Context, never>;
|
|
14
|
+
private static parseQuery;
|
|
19
15
|
private static handle;
|
|
20
|
-
constructor(routes: R
|
|
16
|
+
constructor(routes: Iterable<R>, options: RouterOptions<ContextFrom, ContextTo>);
|
|
21
17
|
/**
|
|
22
18
|
* Adds a new route to the router
|
|
23
|
-
* @
|
|
24
|
-
* @param path The path to add a route for
|
|
25
|
-
* @param route The route specification to add to this router
|
|
26
|
-
* @returns A new router with this route added
|
|
19
|
+
* @deprecated Use the method-specific methods instead
|
|
27
20
|
*/
|
|
28
|
-
add: <Result, Path extends string, Method extends KaitoMethod, Query extends AnyQueryDefinition = {}, BodyOutput = never
|
|
29
|
-
readonly merge: <PathPrefix extends `/${string}`, OtherRoutes extends
|
|
21
|
+
add: <Result, Path extends string, Method extends KaitoMethod, Query extends AnyQueryDefinition = {}, BodyOutput = never>(method: Method, path: Path, route: (Method extends "GET" ? Omit<Route<ContextFrom, ContextTo, Result, Path, Method, Query, BodyOutput>, "body" | "path" | "method" | "through"> : Omit<Route<ContextFrom, ContextTo, Result, Path, Method, Query, BodyOutput>, "path" | "method" | "through">) | Route<ContextFrom, ContextTo, Result, Path, Method, Query, BodyOutput>["run"]) => Router<ContextFrom, ContextTo, R | Route<ContextFrom, ContextTo, Result, Path, Method, Query, BodyOutput>>;
|
|
22
|
+
readonly merge: <PathPrefix extends `/${string}`, OtherRoutes extends AnyRoute>(pathPrefix: PathPrefix, other: Router<ContextFrom, unknown, OtherRoutes>) => Router<ContextFrom, ContextTo, Extract<R | PrefixRoutesPath<PathPrefix, OtherRoutes>, AnyRoute>>;
|
|
30
23
|
freeze: (server: ServerConfig<ContextFrom, any>) => fmw.Instance<fmw.HTTPVersion.V1>;
|
|
31
24
|
private readonly method;
|
|
32
|
-
get: <Result, Path extends string, Query extends AnyQueryDefinition = {}, BodyOutput = never
|
|
33
|
-
post: <Result, Path extends string, Query extends AnyQueryDefinition = {}, BodyOutput = never
|
|
34
|
-
put: <Result, Path extends string, Query extends AnyQueryDefinition = {}, BodyOutput = never
|
|
35
|
-
patch: <Result, Path extends string, Query extends AnyQueryDefinition = {}, BodyOutput = never
|
|
36
|
-
delete: <Result, Path extends string, Query extends AnyQueryDefinition = {}, BodyOutput = never
|
|
37
|
-
head: <Result, Path extends string, Query extends AnyQueryDefinition = {}, BodyOutput = never
|
|
38
|
-
options: <Result, Path extends string, Query extends AnyQueryDefinition = {}, BodyOutput = never
|
|
25
|
+
get: <Result, Path extends string, Query extends AnyQueryDefinition = {}, BodyOutput = never>(path: Path, route: ((arg: import("./route.js").RouteArgument<Path, ContextTo, import("./route.js").InferQuery<Query>, BodyOutput>) => Promise<Result>) | Omit<Route<ContextFrom, ContextTo, Result, Path, 'GET', Query, BodyOutput>, 'body' | 'path' | 'method' | 'through'>) => Router<ContextFrom, ContextTo, R | Route<ContextFrom, ContextTo, Result, Path, 'GET', Query, BodyOutput>>;
|
|
26
|
+
post: <Result, Path extends string, Query extends AnyQueryDefinition = {}, BodyOutput = never>(path: Path, route: ((arg: import("./route.js").RouteArgument<Path, ContextTo, import("./route.js").InferQuery<Query>, BodyOutput>) => Promise<Result>) | Omit<Route<ContextFrom, ContextTo, Result, Path, "POST", Query, BodyOutput>, "path" | "method" | "through">) => Router<ContextFrom, ContextTo, R | Route<ContextFrom, ContextTo, Result, Path, "POST", Query, BodyOutput>>;
|
|
27
|
+
put: <Result, Path extends string, Query extends AnyQueryDefinition = {}, BodyOutput = never>(path: Path, route: ((arg: import("./route.js").RouteArgument<Path, ContextTo, import("./route.js").InferQuery<Query>, BodyOutput>) => Promise<Result>) | Omit<Route<ContextFrom, ContextTo, Result, Path, "PUT", Query, BodyOutput>, "path" | "method" | "through">) => Router<ContextFrom, ContextTo, R | Route<ContextFrom, ContextTo, Result, Path, "PUT", Query, BodyOutput>>;
|
|
28
|
+
patch: <Result, Path extends string, Query extends AnyQueryDefinition = {}, BodyOutput = never>(path: Path, route: ((arg: import("./route.js").RouteArgument<Path, ContextTo, import("./route.js").InferQuery<Query>, BodyOutput>) => Promise<Result>) | Omit<Route<ContextFrom, ContextTo, Result, Path, "PATCH", Query, BodyOutput>, "path" | "method" | "through">) => Router<ContextFrom, ContextTo, R | Route<ContextFrom, ContextTo, Result, Path, "PATCH", Query, BodyOutput>>;
|
|
29
|
+
delete: <Result, Path extends string, Query extends AnyQueryDefinition = {}, BodyOutput = never>(path: Path, route: ((arg: import("./route.js").RouteArgument<Path, ContextTo, import("./route.js").InferQuery<Query>, BodyOutput>) => Promise<Result>) | Omit<Route<ContextFrom, ContextTo, Result, Path, "DELETE", Query, BodyOutput>, "path" | "method" | "through">) => Router<ContextFrom, ContextTo, R | Route<ContextFrom, ContextTo, Result, Path, "DELETE", Query, BodyOutput>>;
|
|
30
|
+
head: <Result, Path extends string, Query extends AnyQueryDefinition = {}, BodyOutput = never>(path: Path, route: ((arg: import("./route.js").RouteArgument<Path, ContextTo, import("./route.js").InferQuery<Query>, BodyOutput>) => Promise<Result>) | Omit<Route<ContextFrom, ContextTo, Result, Path, "HEAD", Query, BodyOutput>, "path" | "method" | "through">) => Router<ContextFrom, ContextTo, R | Route<ContextFrom, ContextTo, Result, Path, "HEAD", Query, BodyOutput>>;
|
|
31
|
+
options: <Result, Path extends string, Query extends AnyQueryDefinition = {}, BodyOutput = never>(path: Path, route: ((arg: import("./route.js").RouteArgument<Path, ContextTo, import("./route.js").InferQuery<Query>, BodyOutput>) => Promise<Result>) | Omit<Route<ContextFrom, ContextTo, Result, Path, "OPTIONS", Query, BodyOutput>, "path" | "method" | "through">) => Router<ContextFrom, ContextTo, R | Route<ContextFrom, ContextTo, Result, Path, "OPTIONS", Query, BodyOutput>>;
|
|
39
32
|
through: <NextContext>(transform: (context: ContextTo) => Promise<NextContext>) => Router<ContextFrom, NextContext, R>;
|
|
40
33
|
}
|
|
41
34
|
export {};
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import * as http from 'node:http';
|
|
3
|
-
import type { KaitoError } from
|
|
4
|
-
import type { KaitoRequest } from
|
|
5
|
-
import type { KaitoResponse } from
|
|
6
|
-
import type { Router } from
|
|
7
|
-
import type { GetContext, KaitoMethod } from
|
|
2
|
+
import type { KaitoError } from "./error.js";
|
|
3
|
+
import type { KaitoRequest } from "./req.js";
|
|
4
|
+
import type { KaitoResponse } from "./res.js";
|
|
5
|
+
import type { Router } from "./router.js";
|
|
6
|
+
import type { GetContext, KaitoMethod } from "./util.js";
|
|
8
7
|
export type Before<BeforeAfterContext> = (req: http.IncomingMessage, res: http.ServerResponse) => Promise<BeforeAfterContext>;
|
|
9
8
|
export type HandlerResult = {
|
|
10
9
|
success: true;
|
|
@@ -23,9 +22,9 @@ export type ServerConfigWithBefore<BeforeAfterContext> = {
|
|
|
23
22
|
} | {
|
|
24
23
|
before?: undefined;
|
|
25
24
|
};
|
|
26
|
-
export type ServerConfig<
|
|
27
|
-
router: Router<
|
|
28
|
-
getContext: GetContext<
|
|
25
|
+
export type ServerConfig<ContextFrom, BeforeAfterContext> = ServerConfigWithBefore<BeforeAfterContext> & {
|
|
26
|
+
router: Router<ContextFrom, unknown, any>;
|
|
27
|
+
getContext: GetContext<ContextFrom>;
|
|
29
28
|
rawRoutes?: Partial<Record<KaitoMethod, Array<{
|
|
30
29
|
path: string;
|
|
31
30
|
handler: (request: http.IncomingMessage, response: http.ServerResponse) => unknown;
|
|
@@ -41,6 +40,6 @@ export type ServerConfig<Context, BeforeAfterContext> = ServerConfigWithBefore<B
|
|
|
41
40
|
};
|
|
42
41
|
export declare function createFMWServer<Context, BeforeAfterContext = null>(config: ServerConfig<Context, BeforeAfterContext>): {
|
|
43
42
|
readonly server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
|
44
|
-
readonly fmw:
|
|
43
|
+
readonly fmw: import("find-my-way").Instance<import("find-my-way").HTTPVersion.V1>;
|
|
45
44
|
};
|
|
46
45
|
export declare function createServer<Context, BeforeAfterContext = null>(config: ServerConfig<Context, BeforeAfterContext>): http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { HTTPMethod } from 'find-my-way';
|
|
2
|
-
import type { KaitoRequest } from
|
|
3
|
-
import type { KaitoResponse } from
|
|
4
|
-
import { Router } from
|
|
2
|
+
import type { KaitoRequest } from "./req.js";
|
|
3
|
+
import type { KaitoResponse } from "./res.js";
|
|
4
|
+
import { Router } from "./router.js";
|
|
5
5
|
export type ExtractRouteParams<T extends string> = string extends T ? Record<string, string> : T extends `${string}:${infer Param}/${infer Rest}` ? {
|
|
6
6
|
[k in Param | keyof ExtractRouteParams<Rest>]: string;
|
|
7
7
|
} : T extends `${string}:${infer Param}` ? {
|
|
@@ -33,14 +33,16 @@ export declare function createGetContext<Context>(callback: GetContext<Context>)
|
|
|
33
33
|
*/
|
|
34
34
|
export declare function createUtilities<Context>(getContext: GetContext<Context>): {
|
|
35
35
|
getContext: GetContext<Context>;
|
|
36
|
-
router: () => Router<Context, Context,
|
|
36
|
+
router: () => Router<Context, Context, never>;
|
|
37
37
|
};
|
|
38
38
|
export type InferContext<T> = T extends (req: KaitoRequest, res: KaitoResponse) => Promise<infer U> ? U : never;
|
|
39
39
|
export declare function getLastEntryInMultiHeaderValue(headerValue: string | string[]): string;
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
export interface Parsable<T> {
|
|
41
|
+
parse: (value: unknown) => T;
|
|
42
|
+
}
|
|
43
|
+
export type RemoveEndSlashes<T extends string> = T extends `${infer U}/` ? U : T;
|
|
44
|
+
export type AddStartSlashes<T extends string> = T extends `/${infer U}` ? `/${U}` : `/${T}`;
|
|
42
45
|
export type NormalizePath<T extends string> = AddStartSlashes<RemoveEndSlashes<T>>;
|
|
43
46
|
export type Values<T> = T[keyof T];
|
|
44
47
|
export type NoEmpty<T> = [keyof T] extends [never] ? never : T;
|
|
45
48
|
export declare function getBody(req: KaitoRequest): Promise<unknown>;
|
|
46
|
-
export {};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export * from "./declarations/src/index";
|
|
2
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoia2FpdG8taHR0cC1jb3JlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuL2RlY2xhcmF0aW9ucy9zcmMvaW5kZXguZC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSJ9
|
|
@@ -4,7 +4,6 @@ import { Readable } from 'node:stream';
|
|
|
4
4
|
import { json } from 'node:stream/consumers';
|
|
5
5
|
import getRawBody from 'raw-body';
|
|
6
6
|
import fmw from 'find-my-way';
|
|
7
|
-
import { z } from 'zod';
|
|
8
7
|
import { serialize } from 'cookie';
|
|
9
8
|
import * as http from 'node:http';
|
|
10
9
|
|
|
@@ -149,6 +148,7 @@ class KaitoResponse {
|
|
|
149
148
|
}
|
|
150
149
|
}
|
|
151
150
|
|
|
151
|
+
var _Router;
|
|
152
152
|
var getSend = res => (status, response) => {
|
|
153
153
|
if (res.raw.headersSent) {
|
|
154
154
|
return;
|
|
@@ -156,6 +156,21 @@ var getSend = res => (status, response) => {
|
|
|
156
156
|
res.status(status).json(response);
|
|
157
157
|
};
|
|
158
158
|
class Router {
|
|
159
|
+
static parseQuery(schema, url) {
|
|
160
|
+
if (!schema) {
|
|
161
|
+
return {};
|
|
162
|
+
}
|
|
163
|
+
var result = {};
|
|
164
|
+
for (var [key, value] of url.searchParams.entries()) {
|
|
165
|
+
var parsable = schema[key];
|
|
166
|
+
if (!parsable) {
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
var parsed = parsable.parse(value);
|
|
170
|
+
result[key] = parsed;
|
|
171
|
+
}
|
|
172
|
+
return result;
|
|
173
|
+
}
|
|
159
174
|
static handle(
|
|
160
175
|
// Allow for any server to be passed
|
|
161
176
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -167,7 +182,7 @@ class Router {
|
|
|
167
182
|
var rootCtx = yield server.getContext(options.req, options.res);
|
|
168
183
|
var ctx = yield route.through(rootCtx);
|
|
169
184
|
var body = (_yield$route$body$par = yield (_route$body = route.body) === null || _route$body === void 0 ? void 0 : _route$body.parse(yield getBody(options.req))) !== null && _yield$route$body$par !== void 0 ? _yield$route$body$par : undefined;
|
|
170
|
-
var query =
|
|
185
|
+
var query = Router.parseQuery(route.query, options.req.url);
|
|
171
186
|
var result = yield route.run({
|
|
172
187
|
ctx,
|
|
173
188
|
body,
|
|
@@ -227,6 +242,10 @@ class Router {
|
|
|
227
242
|
}
|
|
228
243
|
constructor(routes, options) {
|
|
229
244
|
var _this = this;
|
|
245
|
+
/**
|
|
246
|
+
* Adds a new route to the router
|
|
247
|
+
* @deprecated Use the method-specific methods instead
|
|
248
|
+
*/
|
|
230
249
|
_defineProperty(this, "add", (method, path, route) => {
|
|
231
250
|
var merged = _objectSpread2(_objectSpread2({}, typeof route === 'object' ? route : {
|
|
232
251
|
run: route
|
|
@@ -238,11 +257,13 @@ class Router {
|
|
|
238
257
|
return new Router([...this.routes, merged], this.routerOptions);
|
|
239
258
|
});
|
|
240
259
|
_defineProperty(this, "merge", (pathPrefix, other) => {
|
|
241
|
-
var newRoutes = other.routes.map(route => _objectSpread2(_objectSpread2({}, route), {}, {
|
|
260
|
+
var newRoutes = [...other.routes].map(route => _objectSpread2(_objectSpread2({}, route), {}, {
|
|
242
261
|
path: "".concat(pathPrefix).concat(route.path)
|
|
243
262
|
}));
|
|
244
263
|
return new Router([...this.routes, ...newRoutes], this.routerOptions);
|
|
245
264
|
});
|
|
265
|
+
// Allow for any server context to be passed
|
|
266
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
246
267
|
_defineProperty(this, "freeze", server => {
|
|
247
268
|
var instance = fmw({
|
|
248
269
|
ignoreTrailingSlash: true,
|
|
@@ -266,12 +287,12 @@ class Router {
|
|
|
266
287
|
})();
|
|
267
288
|
}
|
|
268
289
|
});
|
|
269
|
-
var _loop = function _loop(
|
|
290
|
+
var _loop = function _loop(_route) {
|
|
270
291
|
var handler = /*#__PURE__*/function () {
|
|
271
292
|
var _ref = _asyncToGenerator(function* (incomingMessage, serverResponse, params) {
|
|
272
293
|
var req = new KaitoRequest(incomingMessage);
|
|
273
294
|
var res = new KaitoResponse(serverResponse);
|
|
274
|
-
return Router.handle(server,
|
|
295
|
+
return Router.handle(server, _route, {
|
|
275
296
|
params,
|
|
276
297
|
req,
|
|
277
298
|
res
|
|
@@ -281,19 +302,20 @@ class Router {
|
|
|
281
302
|
return _ref.apply(this, arguments);
|
|
282
303
|
};
|
|
283
304
|
}();
|
|
284
|
-
if (
|
|
285
|
-
instance.all(
|
|
286
|
-
return
|
|
305
|
+
if (_route.method === '*') {
|
|
306
|
+
instance.all(_route.path, handler);
|
|
307
|
+
return 1; // continue
|
|
287
308
|
}
|
|
288
|
-
instance.on(
|
|
309
|
+
instance.on(_route.method, _route.path, handler);
|
|
289
310
|
};
|
|
290
|
-
for (var
|
|
291
|
-
|
|
292
|
-
if (_ret === "continue") continue;
|
|
311
|
+
for (var _route2 of this.routes) {
|
|
312
|
+
if (_loop(_route2)) continue;
|
|
293
313
|
}
|
|
294
314
|
return instance;
|
|
295
315
|
});
|
|
296
|
-
_defineProperty(this, "method", method => (path, route) =>
|
|
316
|
+
_defineProperty(this, "method", method => (path, route) => {
|
|
317
|
+
return this.add(method, path, route);
|
|
318
|
+
});
|
|
297
319
|
_defineProperty(this, "get", this.method('GET'));
|
|
298
320
|
_defineProperty(this, "post", this.method('POST'));
|
|
299
321
|
_defineProperty(this, "put", this.method('PUT'));
|
|
@@ -314,18 +336,11 @@ class Router {
|
|
|
314
336
|
}()
|
|
315
337
|
}));
|
|
316
338
|
this.routerOptions = options;
|
|
317
|
-
this.routes = routes;
|
|
339
|
+
this.routes = new Set(routes);
|
|
318
340
|
}
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
* Adds a new route to the router
|
|
322
|
-
* @param method The HTTP method to add a route for
|
|
323
|
-
* @param path The path to add a route for
|
|
324
|
-
* @param route The route specification to add to this router
|
|
325
|
-
* @returns A new router with this route added
|
|
326
|
-
*/
|
|
327
341
|
}
|
|
328
|
-
|
|
342
|
+
_Router = Router;
|
|
343
|
+
_defineProperty(Router, "create", () => new _Router([], {
|
|
329
344
|
through: function () {
|
|
330
345
|
var _through2 = _asyncToGenerator(function* (context) {
|
|
331
346
|
return context;
|
package/package.json
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaito-http/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-beta.1",
|
|
4
4
|
"description": "Functional HTTP Framework for TypeScript",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": "./dist/kaito-http-core.js",
|
|
7
|
+
"./package.json": "./package.json"
|
|
8
|
+
},
|
|
5
9
|
"repository": "https://github.com/kaito-http/kaito",
|
|
6
10
|
"author": "Alistair Smith <hi@alistair.sh>",
|
|
7
11
|
"license": "MIT",
|
|
8
|
-
"
|
|
9
|
-
"module": "dist/kaito-http-core.esm.js",
|
|
10
|
-
"types": "dist/kaito-http-core.cjs.d.ts",
|
|
12
|
+
"type": "module",
|
|
11
13
|
"devDependencies": {
|
|
12
14
|
"@types/content-type": "^1.1.5",
|
|
13
15
|
"@types/cookie": "^0.5.1",
|
|
14
16
|
"@types/node": "^18.11.9",
|
|
15
|
-
"typescript": "
|
|
16
|
-
"zod": "^3.19.1"
|
|
17
|
+
"typescript": "^5.6.2"
|
|
17
18
|
},
|
|
18
19
|
"files": [
|
|
19
20
|
"package.json",
|
|
@@ -24,18 +25,15 @@
|
|
|
24
25
|
"url": "https://github.com/kaito-http/kaito/issues"
|
|
25
26
|
},
|
|
26
27
|
"homepage": "https://github.com/kaito-http/kaito",
|
|
27
|
-
"peerDependencies": {
|
|
28
|
-
"zod": "*"
|
|
29
|
-
},
|
|
30
28
|
"keywords": [
|
|
31
29
|
"typescript",
|
|
32
30
|
"http",
|
|
33
31
|
"framework"
|
|
34
32
|
],
|
|
35
33
|
"dependencies": {
|
|
36
|
-
"content-type": "^1.0.
|
|
37
|
-
"cookie": "^0.
|
|
38
|
-
"find-my-way": "^
|
|
39
|
-
"raw-body": "^
|
|
34
|
+
"content-type": "^1.0.5",
|
|
35
|
+
"cookie": "^0.6.0",
|
|
36
|
+
"find-my-way": "^9.1.0",
|
|
37
|
+
"raw-body": "^3.0.0"
|
|
40
38
|
}
|
|
41
39
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./declarations/src/index";
|