@kaito-http/core 2.3.3 → 2.3.6
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.
|
@@ -2,22 +2,56 @@ import fmw, { HTTPMethod, Instance } from 'find-my-way';
|
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { Route } from './route';
|
|
4
4
|
import { ServerConfig } from './server';
|
|
5
|
-
import { NormalizePath } from './util';
|
|
6
|
-
export declare type RoutesInit<Context
|
|
7
|
-
[Path in
|
|
5
|
+
import { NoEmpty, NormalizePath, Values } from './util';
|
|
6
|
+
export declare type RoutesInit<Context> = {
|
|
7
|
+
[Path in string]: Route<any, Path, HTTPMethod, Context, z.ZodSchema>;
|
|
8
8
|
};
|
|
9
9
|
export declare class Router<Context, Routes extends RoutesInit<Context>> {
|
|
10
|
-
static create<Context>(): Router<Context, {}>;
|
|
10
|
+
static create<Context = null>(): Router<Context, {}>;
|
|
11
11
|
private static handle;
|
|
12
|
-
readonly routes: Routes;
|
|
13
|
-
readonly
|
|
14
|
-
readonly
|
|
15
|
-
readonly
|
|
16
|
-
readonly
|
|
17
|
-
readonly
|
|
12
|
+
readonly 'routes': Routes;
|
|
13
|
+
readonly 'acl': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "ACL", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "ACL", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "ACL", Context, Input>; }>;
|
|
14
|
+
readonly 'bind': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "BIND", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "BIND", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "BIND", Context, Input>; }>;
|
|
15
|
+
readonly 'checkout': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "CHECKOUT", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "CHECKOUT", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "CHECKOUT", Context, Input>; }>;
|
|
16
|
+
readonly 'connect': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "CONNECT", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "CONNECT", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "CONNECT", Context, Input>; }>;
|
|
17
|
+
readonly 'copy': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "COPY", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "COPY", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "COPY", Context, Input>; }>;
|
|
18
|
+
readonly 'delete': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "DELETE", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "DELETE", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "DELETE", Context, Input>; }>;
|
|
19
|
+
readonly 'get': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "GET", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "GET", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "GET", Context, Input>; }>;
|
|
20
|
+
readonly 'head': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "HEAD", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "HEAD", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "HEAD", Context, Input>; }>;
|
|
21
|
+
readonly 'link': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "LINK", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "LINK", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "LINK", Context, Input>; }>;
|
|
22
|
+
readonly 'lock': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "LOCK", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "LOCK", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "LOCK", Context, Input>; }>;
|
|
23
|
+
readonly 'm_search': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "M-SEARCH", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "M-SEARCH", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "M-SEARCH", Context, Input>; }>;
|
|
24
|
+
readonly 'mkactivity': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "MKACTIVITY", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "MKACTIVITY", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "MKACTIVITY", Context, Input>; }>;
|
|
25
|
+
readonly 'mkcalendar': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "MKCALENDAR", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "MKCALENDAR", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "MKCALENDAR", Context, Input>; }>;
|
|
26
|
+
readonly 'mkcol': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "MKCOL", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "MKCOL", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "MKCOL", Context, Input>; }>;
|
|
27
|
+
readonly 'move': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "MOVE", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "MOVE", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "MOVE", Context, Input>; }>;
|
|
28
|
+
readonly 'notify': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "NOTIFY", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "NOTIFY", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "NOTIFY", Context, Input>; }>;
|
|
29
|
+
readonly 'options': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "OPTIONS", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "OPTIONS", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "OPTIONS", Context, Input>; }>;
|
|
30
|
+
readonly 'patch': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "PATCH", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "PATCH", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "PATCH", Context, Input>; }>;
|
|
31
|
+
readonly 'post': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "POST", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "POST", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "POST", Context, Input>; }>;
|
|
32
|
+
readonly 'propfind': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "PROPFIND", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "PROPFIND", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "PROPFIND", Context, Input>; }>;
|
|
33
|
+
readonly 'proppatch': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "PROPPATCH", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "PROPPATCH", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "PROPPATCH", Context, Input>; }>;
|
|
34
|
+
readonly 'purge': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "PURGE", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "PURGE", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "PURGE", Context, Input>; }>;
|
|
35
|
+
readonly 'put': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "PUT", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "PUT", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "PUT", Context, Input>; }>;
|
|
36
|
+
readonly 'rebind': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "REBIND", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "REBIND", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "REBIND", Context, Input>; }>;
|
|
37
|
+
readonly 'report': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "REPORT", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "REPORT", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "REPORT", Context, Input>; }>;
|
|
38
|
+
readonly 'search': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "SEARCH", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "SEARCH", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "SEARCH", Context, Input>; }>;
|
|
39
|
+
readonly 'source': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "SOURCE", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "SOURCE", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "SOURCE", Context, Input>; }>;
|
|
40
|
+
readonly 'subscribe': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "SUBSCRIBE", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "SUBSCRIBE", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "SUBSCRIBE", Context, Input>; }>;
|
|
41
|
+
readonly 'trace': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "TRACE", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "TRACE", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "TRACE", Context, Input>; }>;
|
|
42
|
+
readonly 'unbind': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "UNBIND", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "UNBIND", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "UNBIND", Context, Input>; }>;
|
|
43
|
+
readonly 'unlink': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "UNLINK", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "UNLINK", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "UNLINK", Context, Input>; }>;
|
|
44
|
+
readonly 'unlock': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "UNLOCK", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "UNLOCK", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "UNLOCK", Context, Input>; }>;
|
|
45
|
+
readonly 'unsubscribe': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "UNSUBSCRIBE", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "UNSUBSCRIBE", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "UNSUBSCRIBE", Context, Input>; }>;
|
|
18
46
|
private constructor();
|
|
19
|
-
merge<Prefix extends string, NewRoutes extends RoutesInit<Context>>(prefix: NormalizePath<Prefix>, router: Router<Context, NewRoutes>): Router<Context, Routes & { [Path in Extract<keyof NewRoutes, string> as `/${Prefix}${Path}`]: NewRoutes[Path]
|
|
47
|
+
merge<Prefix extends string, NewRoutes extends RoutesInit<Context>>(prefix: NormalizePath<Prefix>, router: Router<Context, NewRoutes>): Router<Context, Routes & { [Path in Extract<keyof NewRoutes, string> as `/${Prefix}${Path}`]: Values<{ [M in NewRoutes[Path]["method"]]: Omit<Extract<NewRoutes[Path], {
|
|
48
|
+
method: M;
|
|
49
|
+
}>, "method" | "path"> & {
|
|
50
|
+
path: `/${Prefix}${Path}`;
|
|
51
|
+
method: M;
|
|
52
|
+
}; }>; }>;
|
|
20
53
|
toFindMyWay(server: ServerConfig<Context>): Instance<fmw.HTTPVersion.V1>;
|
|
54
|
+
_copy<NewRoutes extends RoutesInit<Context>>(routes: NewRoutes): Router<Context, NewRoutes>;
|
|
21
55
|
private make;
|
|
22
56
|
}
|
|
23
57
|
/**
|
|
@@ -12,6 +12,7 @@ export declare function getLastEntryInMultiHeaderValue(headerValue: string | str
|
|
|
12
12
|
declare type RemoveEndSlashes<T extends string> = T extends `${infer U}/` ? U : T;
|
|
13
13
|
declare type AddStartSlashes<T extends string> = T extends `/${infer U}` ? `/${U}` : `/${T}`;
|
|
14
14
|
export declare type NormalizePath<T extends string> = AddStartSlashes<RemoveEndSlashes<T>>;
|
|
15
|
-
export declare
|
|
15
|
+
export declare type Values<T> = T[keyof T];
|
|
16
|
+
export declare type NoEmpty<T> = [keyof T] extends [never] ? never : T;
|
|
16
17
|
export declare function getInput(req: KaitoRequest): Promise<unknown>;
|
|
17
18
|
export {};
|
|
@@ -169,19 +169,6 @@ function getLastEntryInMultiHeaderValue(headerValue) {
|
|
|
169
169
|
var lastIndex = normalized.lastIndexOf(',');
|
|
170
170
|
return lastIndex === -1 ? normalized.trim() : normalized.slice(lastIndex + 1).trim();
|
|
171
171
|
}
|
|
172
|
-
function normalizePath(path) {
|
|
173
|
-
var result = path;
|
|
174
|
-
|
|
175
|
-
if (!result.startsWith('/')) {
|
|
176
|
-
result = "/".concat(result);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
if (result.endsWith('/')) {
|
|
180
|
-
result = result.slice(-1);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
return result;
|
|
184
|
-
}
|
|
185
172
|
function getInput(_x) {
|
|
186
173
|
return _getInput.apply(this, arguments);
|
|
187
174
|
}
|
|
@@ -346,15 +333,71 @@ class Router {
|
|
|
346
333
|
}
|
|
347
334
|
|
|
348
335
|
constructor(routes) {
|
|
349
|
-
_defineProperty(this,
|
|
336
|
+
_defineProperty(this, 'acl', this.make('ACL'));
|
|
337
|
+
|
|
338
|
+
_defineProperty(this, 'bind', this.make('BIND'));
|
|
339
|
+
|
|
340
|
+
_defineProperty(this, 'checkout', this.make('CHECKOUT'));
|
|
341
|
+
|
|
342
|
+
_defineProperty(this, 'connect', this.make('CONNECT'));
|
|
343
|
+
|
|
344
|
+
_defineProperty(this, 'copy', this.make('COPY'));
|
|
345
|
+
|
|
346
|
+
_defineProperty(this, 'delete', this.make('DELETE'));
|
|
347
|
+
|
|
348
|
+
_defineProperty(this, 'get', this.make('GET'));
|
|
349
|
+
|
|
350
|
+
_defineProperty(this, 'head', this.make('HEAD'));
|
|
351
|
+
|
|
352
|
+
_defineProperty(this, 'link', this.make('LINK'));
|
|
353
|
+
|
|
354
|
+
_defineProperty(this, 'lock', this.make('LOCK'));
|
|
355
|
+
|
|
356
|
+
_defineProperty(this, 'm_search', this.make('M-SEARCH'));
|
|
357
|
+
|
|
358
|
+
_defineProperty(this, 'mkactivity', this.make('MKACTIVITY'));
|
|
359
|
+
|
|
360
|
+
_defineProperty(this, 'mkcalendar', this.make('MKCALENDAR'));
|
|
361
|
+
|
|
362
|
+
_defineProperty(this, 'mkcol', this.make('MKCOL'));
|
|
363
|
+
|
|
364
|
+
_defineProperty(this, 'move', this.make('MOVE'));
|
|
365
|
+
|
|
366
|
+
_defineProperty(this, 'notify', this.make('NOTIFY'));
|
|
350
367
|
|
|
351
|
-
_defineProperty(this,
|
|
368
|
+
_defineProperty(this, 'options', this.make('OPTIONS'));
|
|
352
369
|
|
|
353
|
-
_defineProperty(this,
|
|
370
|
+
_defineProperty(this, 'patch', this.make('PATCH'));
|
|
354
371
|
|
|
355
|
-
_defineProperty(this,
|
|
372
|
+
_defineProperty(this, 'post', this.make('POST'));
|
|
356
373
|
|
|
357
|
-
_defineProperty(this,
|
|
374
|
+
_defineProperty(this, 'propfind', this.make('PROPFIND'));
|
|
375
|
+
|
|
376
|
+
_defineProperty(this, 'proppatch', this.make('PROPPATCH'));
|
|
377
|
+
|
|
378
|
+
_defineProperty(this, 'purge', this.make('PURGE'));
|
|
379
|
+
|
|
380
|
+
_defineProperty(this, 'put', this.make('PUT'));
|
|
381
|
+
|
|
382
|
+
_defineProperty(this, 'rebind', this.make('REBIND'));
|
|
383
|
+
|
|
384
|
+
_defineProperty(this, 'report', this.make('REPORT'));
|
|
385
|
+
|
|
386
|
+
_defineProperty(this, 'search', this.make('SEARCH'));
|
|
387
|
+
|
|
388
|
+
_defineProperty(this, 'source', this.make('SOURCE'));
|
|
389
|
+
|
|
390
|
+
_defineProperty(this, 'subscribe', this.make('SUBSCRIBE'));
|
|
391
|
+
|
|
392
|
+
_defineProperty(this, 'trace', this.make('TRACE'));
|
|
393
|
+
|
|
394
|
+
_defineProperty(this, 'unbind', this.make('UNBIND'));
|
|
395
|
+
|
|
396
|
+
_defineProperty(this, 'unlink', this.make('UNLINK'));
|
|
397
|
+
|
|
398
|
+
_defineProperty(this, 'unlock', this.make('UNLOCK'));
|
|
399
|
+
|
|
400
|
+
_defineProperty(this, 'unsubscribe', this.make('UNSUBSCRIBE'));
|
|
358
401
|
|
|
359
402
|
this.routes = routes;
|
|
360
403
|
}
|
|
@@ -364,7 +407,10 @@ class Router {
|
|
|
364
407
|
var [k, v] = _ref;
|
|
365
408
|
return ["".concat(prefix).concat(k), v];
|
|
366
409
|
}));
|
|
367
|
-
|
|
410
|
+
|
|
411
|
+
var merged = _objectSpread2(_objectSpread2({}, this.routes), newRoutes);
|
|
412
|
+
|
|
413
|
+
return this._copy(merged);
|
|
368
414
|
}
|
|
369
415
|
|
|
370
416
|
toFindMyWay(server) {
|
|
@@ -384,7 +430,8 @@ class Router {
|
|
|
384
430
|
});
|
|
385
431
|
}
|
|
386
432
|
|
|
387
|
-
});
|
|
433
|
+
});
|
|
434
|
+
var paths = Object.keys(this.routes);
|
|
388
435
|
|
|
389
436
|
var _loop = function _loop(path) {
|
|
390
437
|
var route = _this.routes[path];
|
|
@@ -406,22 +453,31 @@ class Router {
|
|
|
406
453
|
}());
|
|
407
454
|
};
|
|
408
455
|
|
|
409
|
-
for (var path
|
|
456
|
+
for (var path of paths) {
|
|
410
457
|
_loop(path);
|
|
411
458
|
}
|
|
412
459
|
|
|
413
460
|
return instance;
|
|
414
461
|
}
|
|
415
462
|
|
|
463
|
+
_copy(routes) {
|
|
464
|
+
return new Router(routes);
|
|
465
|
+
}
|
|
466
|
+
|
|
416
467
|
make(method) {
|
|
417
468
|
return (path, route) => {
|
|
418
|
-
var
|
|
469
|
+
var addedRoute = _objectSpread2(_objectSpread2({}, route), {}, {
|
|
419
470
|
method
|
|
471
|
+
}); // `as unknown` is required because otherwise
|
|
472
|
+
// this type just gets massive and too slow,
|
|
473
|
+
// so we have to write it out specifically
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
var merged = _objectSpread2(_objectSpread2({}, this.routes), {}, {
|
|
477
|
+
[path]: addedRoute
|
|
420
478
|
});
|
|
421
479
|
|
|
422
|
-
return
|
|
423
|
-
[path]: mergedRoute
|
|
424
|
-
}));
|
|
480
|
+
return this._copy(merged);
|
|
425
481
|
};
|
|
426
482
|
}
|
|
427
483
|
|
|
@@ -443,4 +499,3 @@ exports.createRouter = createRouter;
|
|
|
443
499
|
exports.createServer = createServer;
|
|
444
500
|
exports.getInput = getInput;
|
|
445
501
|
exports.getLastEntryInMultiHeaderValue = getLastEntryInMultiHeaderValue;
|
|
446
|
-
exports.normalizePath = normalizePath;
|
|
@@ -169,19 +169,6 @@ function getLastEntryInMultiHeaderValue(headerValue) {
|
|
|
169
169
|
var lastIndex = normalized.lastIndexOf(',');
|
|
170
170
|
return lastIndex === -1 ? normalized.trim() : normalized.slice(lastIndex + 1).trim();
|
|
171
171
|
}
|
|
172
|
-
function normalizePath(path) {
|
|
173
|
-
var result = path;
|
|
174
|
-
|
|
175
|
-
if (!result.startsWith('/')) {
|
|
176
|
-
result = "/".concat(result);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
if (result.endsWith('/')) {
|
|
180
|
-
result = result.slice(-1);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
return result;
|
|
184
|
-
}
|
|
185
172
|
function getInput(_x) {
|
|
186
173
|
return _getInput.apply(this, arguments);
|
|
187
174
|
}
|
|
@@ -346,15 +333,71 @@ class Router {
|
|
|
346
333
|
}
|
|
347
334
|
|
|
348
335
|
constructor(routes) {
|
|
349
|
-
_defineProperty(this,
|
|
336
|
+
_defineProperty(this, 'acl', this.make('ACL'));
|
|
337
|
+
|
|
338
|
+
_defineProperty(this, 'bind', this.make('BIND'));
|
|
339
|
+
|
|
340
|
+
_defineProperty(this, 'checkout', this.make('CHECKOUT'));
|
|
341
|
+
|
|
342
|
+
_defineProperty(this, 'connect', this.make('CONNECT'));
|
|
343
|
+
|
|
344
|
+
_defineProperty(this, 'copy', this.make('COPY'));
|
|
345
|
+
|
|
346
|
+
_defineProperty(this, 'delete', this.make('DELETE'));
|
|
347
|
+
|
|
348
|
+
_defineProperty(this, 'get', this.make('GET'));
|
|
349
|
+
|
|
350
|
+
_defineProperty(this, 'head', this.make('HEAD'));
|
|
351
|
+
|
|
352
|
+
_defineProperty(this, 'link', this.make('LINK'));
|
|
353
|
+
|
|
354
|
+
_defineProperty(this, 'lock', this.make('LOCK'));
|
|
355
|
+
|
|
356
|
+
_defineProperty(this, 'm_search', this.make('M-SEARCH'));
|
|
357
|
+
|
|
358
|
+
_defineProperty(this, 'mkactivity', this.make('MKACTIVITY'));
|
|
359
|
+
|
|
360
|
+
_defineProperty(this, 'mkcalendar', this.make('MKCALENDAR'));
|
|
361
|
+
|
|
362
|
+
_defineProperty(this, 'mkcol', this.make('MKCOL'));
|
|
363
|
+
|
|
364
|
+
_defineProperty(this, 'move', this.make('MOVE'));
|
|
365
|
+
|
|
366
|
+
_defineProperty(this, 'notify', this.make('NOTIFY'));
|
|
350
367
|
|
|
351
|
-
_defineProperty(this,
|
|
368
|
+
_defineProperty(this, 'options', this.make('OPTIONS'));
|
|
352
369
|
|
|
353
|
-
_defineProperty(this,
|
|
370
|
+
_defineProperty(this, 'patch', this.make('PATCH'));
|
|
354
371
|
|
|
355
|
-
_defineProperty(this,
|
|
372
|
+
_defineProperty(this, 'post', this.make('POST'));
|
|
356
373
|
|
|
357
|
-
_defineProperty(this,
|
|
374
|
+
_defineProperty(this, 'propfind', this.make('PROPFIND'));
|
|
375
|
+
|
|
376
|
+
_defineProperty(this, 'proppatch', this.make('PROPPATCH'));
|
|
377
|
+
|
|
378
|
+
_defineProperty(this, 'purge', this.make('PURGE'));
|
|
379
|
+
|
|
380
|
+
_defineProperty(this, 'put', this.make('PUT'));
|
|
381
|
+
|
|
382
|
+
_defineProperty(this, 'rebind', this.make('REBIND'));
|
|
383
|
+
|
|
384
|
+
_defineProperty(this, 'report', this.make('REPORT'));
|
|
385
|
+
|
|
386
|
+
_defineProperty(this, 'search', this.make('SEARCH'));
|
|
387
|
+
|
|
388
|
+
_defineProperty(this, 'source', this.make('SOURCE'));
|
|
389
|
+
|
|
390
|
+
_defineProperty(this, 'subscribe', this.make('SUBSCRIBE'));
|
|
391
|
+
|
|
392
|
+
_defineProperty(this, 'trace', this.make('TRACE'));
|
|
393
|
+
|
|
394
|
+
_defineProperty(this, 'unbind', this.make('UNBIND'));
|
|
395
|
+
|
|
396
|
+
_defineProperty(this, 'unlink', this.make('UNLINK'));
|
|
397
|
+
|
|
398
|
+
_defineProperty(this, 'unlock', this.make('UNLOCK'));
|
|
399
|
+
|
|
400
|
+
_defineProperty(this, 'unsubscribe', this.make('UNSUBSCRIBE'));
|
|
358
401
|
|
|
359
402
|
this.routes = routes;
|
|
360
403
|
}
|
|
@@ -364,7 +407,10 @@ class Router {
|
|
|
364
407
|
var [k, v] = _ref;
|
|
365
408
|
return ["".concat(prefix).concat(k), v];
|
|
366
409
|
}));
|
|
367
|
-
|
|
410
|
+
|
|
411
|
+
var merged = _objectSpread2(_objectSpread2({}, this.routes), newRoutes);
|
|
412
|
+
|
|
413
|
+
return this._copy(merged);
|
|
368
414
|
}
|
|
369
415
|
|
|
370
416
|
toFindMyWay(server) {
|
|
@@ -384,7 +430,8 @@ class Router {
|
|
|
384
430
|
});
|
|
385
431
|
}
|
|
386
432
|
|
|
387
|
-
});
|
|
433
|
+
});
|
|
434
|
+
var paths = Object.keys(this.routes);
|
|
388
435
|
|
|
389
436
|
var _loop = function _loop(path) {
|
|
390
437
|
var route = _this.routes[path];
|
|
@@ -406,22 +453,31 @@ class Router {
|
|
|
406
453
|
}());
|
|
407
454
|
};
|
|
408
455
|
|
|
409
|
-
for (var path
|
|
456
|
+
for (var path of paths) {
|
|
410
457
|
_loop(path);
|
|
411
458
|
}
|
|
412
459
|
|
|
413
460
|
return instance;
|
|
414
461
|
}
|
|
415
462
|
|
|
463
|
+
_copy(routes) {
|
|
464
|
+
return new Router(routes);
|
|
465
|
+
}
|
|
466
|
+
|
|
416
467
|
make(method) {
|
|
417
468
|
return (path, route) => {
|
|
418
|
-
var
|
|
469
|
+
var addedRoute = _objectSpread2(_objectSpread2({}, route), {}, {
|
|
419
470
|
method
|
|
471
|
+
}); // `as unknown` is required because otherwise
|
|
472
|
+
// this type just gets massive and too slow,
|
|
473
|
+
// so we have to write it out specifically
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
var merged = _objectSpread2(_objectSpread2({}, this.routes), {}, {
|
|
477
|
+
[path]: addedRoute
|
|
420
478
|
});
|
|
421
479
|
|
|
422
|
-
return
|
|
423
|
-
[path]: mergedRoute
|
|
424
|
-
}));
|
|
480
|
+
return this._copy(merged);
|
|
425
481
|
};
|
|
426
482
|
}
|
|
427
483
|
|
|
@@ -443,4 +499,3 @@ exports.createRouter = createRouter;
|
|
|
443
499
|
exports.createServer = createServer;
|
|
444
500
|
exports.getInput = getInput;
|
|
445
501
|
exports.getLastEntryInMultiHeaderValue = getLastEntryInMultiHeaderValue;
|
|
446
|
-
exports.normalizePath = normalizePath;
|
|
@@ -141,19 +141,6 @@ function getLastEntryInMultiHeaderValue(headerValue) {
|
|
|
141
141
|
var lastIndex = normalized.lastIndexOf(',');
|
|
142
142
|
return lastIndex === -1 ? normalized.trim() : normalized.slice(lastIndex + 1).trim();
|
|
143
143
|
}
|
|
144
|
-
function normalizePath(path) {
|
|
145
|
-
var result = path;
|
|
146
|
-
|
|
147
|
-
if (!result.startsWith('/')) {
|
|
148
|
-
result = "/".concat(result);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
if (result.endsWith('/')) {
|
|
152
|
-
result = result.slice(-1);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
return result;
|
|
156
|
-
}
|
|
157
144
|
function getInput(_x) {
|
|
158
145
|
return _getInput.apply(this, arguments);
|
|
159
146
|
}
|
|
@@ -318,15 +305,71 @@ class Router {
|
|
|
318
305
|
}
|
|
319
306
|
|
|
320
307
|
constructor(routes) {
|
|
321
|
-
_defineProperty(this,
|
|
308
|
+
_defineProperty(this, 'acl', this.make('ACL'));
|
|
309
|
+
|
|
310
|
+
_defineProperty(this, 'bind', this.make('BIND'));
|
|
311
|
+
|
|
312
|
+
_defineProperty(this, 'checkout', this.make('CHECKOUT'));
|
|
313
|
+
|
|
314
|
+
_defineProperty(this, 'connect', this.make('CONNECT'));
|
|
315
|
+
|
|
316
|
+
_defineProperty(this, 'copy', this.make('COPY'));
|
|
317
|
+
|
|
318
|
+
_defineProperty(this, 'delete', this.make('DELETE'));
|
|
319
|
+
|
|
320
|
+
_defineProperty(this, 'get', this.make('GET'));
|
|
321
|
+
|
|
322
|
+
_defineProperty(this, 'head', this.make('HEAD'));
|
|
323
|
+
|
|
324
|
+
_defineProperty(this, 'link', this.make('LINK'));
|
|
325
|
+
|
|
326
|
+
_defineProperty(this, 'lock', this.make('LOCK'));
|
|
327
|
+
|
|
328
|
+
_defineProperty(this, 'm_search', this.make('M-SEARCH'));
|
|
329
|
+
|
|
330
|
+
_defineProperty(this, 'mkactivity', this.make('MKACTIVITY'));
|
|
331
|
+
|
|
332
|
+
_defineProperty(this, 'mkcalendar', this.make('MKCALENDAR'));
|
|
333
|
+
|
|
334
|
+
_defineProperty(this, 'mkcol', this.make('MKCOL'));
|
|
335
|
+
|
|
336
|
+
_defineProperty(this, 'move', this.make('MOVE'));
|
|
337
|
+
|
|
338
|
+
_defineProperty(this, 'notify', this.make('NOTIFY'));
|
|
322
339
|
|
|
323
|
-
_defineProperty(this,
|
|
340
|
+
_defineProperty(this, 'options', this.make('OPTIONS'));
|
|
324
341
|
|
|
325
|
-
_defineProperty(this,
|
|
342
|
+
_defineProperty(this, 'patch', this.make('PATCH'));
|
|
326
343
|
|
|
327
|
-
_defineProperty(this,
|
|
344
|
+
_defineProperty(this, 'post', this.make('POST'));
|
|
328
345
|
|
|
329
|
-
_defineProperty(this,
|
|
346
|
+
_defineProperty(this, 'propfind', this.make('PROPFIND'));
|
|
347
|
+
|
|
348
|
+
_defineProperty(this, 'proppatch', this.make('PROPPATCH'));
|
|
349
|
+
|
|
350
|
+
_defineProperty(this, 'purge', this.make('PURGE'));
|
|
351
|
+
|
|
352
|
+
_defineProperty(this, 'put', this.make('PUT'));
|
|
353
|
+
|
|
354
|
+
_defineProperty(this, 'rebind', this.make('REBIND'));
|
|
355
|
+
|
|
356
|
+
_defineProperty(this, 'report', this.make('REPORT'));
|
|
357
|
+
|
|
358
|
+
_defineProperty(this, 'search', this.make('SEARCH'));
|
|
359
|
+
|
|
360
|
+
_defineProperty(this, 'source', this.make('SOURCE'));
|
|
361
|
+
|
|
362
|
+
_defineProperty(this, 'subscribe', this.make('SUBSCRIBE'));
|
|
363
|
+
|
|
364
|
+
_defineProperty(this, 'trace', this.make('TRACE'));
|
|
365
|
+
|
|
366
|
+
_defineProperty(this, 'unbind', this.make('UNBIND'));
|
|
367
|
+
|
|
368
|
+
_defineProperty(this, 'unlink', this.make('UNLINK'));
|
|
369
|
+
|
|
370
|
+
_defineProperty(this, 'unlock', this.make('UNLOCK'));
|
|
371
|
+
|
|
372
|
+
_defineProperty(this, 'unsubscribe', this.make('UNSUBSCRIBE'));
|
|
330
373
|
|
|
331
374
|
this.routes = routes;
|
|
332
375
|
}
|
|
@@ -336,7 +379,10 @@ class Router {
|
|
|
336
379
|
var [k, v] = _ref;
|
|
337
380
|
return ["".concat(prefix).concat(k), v];
|
|
338
381
|
}));
|
|
339
|
-
|
|
382
|
+
|
|
383
|
+
var merged = _objectSpread2(_objectSpread2({}, this.routes), newRoutes);
|
|
384
|
+
|
|
385
|
+
return this._copy(merged);
|
|
340
386
|
}
|
|
341
387
|
|
|
342
388
|
toFindMyWay(server) {
|
|
@@ -356,7 +402,8 @@ class Router {
|
|
|
356
402
|
});
|
|
357
403
|
}
|
|
358
404
|
|
|
359
|
-
});
|
|
405
|
+
});
|
|
406
|
+
var paths = Object.keys(this.routes);
|
|
360
407
|
|
|
361
408
|
var _loop = function _loop(path) {
|
|
362
409
|
var route = _this.routes[path];
|
|
@@ -378,22 +425,31 @@ class Router {
|
|
|
378
425
|
}());
|
|
379
426
|
};
|
|
380
427
|
|
|
381
|
-
for (var path
|
|
428
|
+
for (var path of paths) {
|
|
382
429
|
_loop(path);
|
|
383
430
|
}
|
|
384
431
|
|
|
385
432
|
return instance;
|
|
386
433
|
}
|
|
387
434
|
|
|
435
|
+
_copy(routes) {
|
|
436
|
+
return new Router(routes);
|
|
437
|
+
}
|
|
438
|
+
|
|
388
439
|
make(method) {
|
|
389
440
|
return (path, route) => {
|
|
390
|
-
var
|
|
441
|
+
var addedRoute = _objectSpread2(_objectSpread2({}, route), {}, {
|
|
391
442
|
method
|
|
443
|
+
}); // `as unknown` is required because otherwise
|
|
444
|
+
// this type just gets massive and too slow,
|
|
445
|
+
// so we have to write it out specifically
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
var merged = _objectSpread2(_objectSpread2({}, this.routes), {}, {
|
|
449
|
+
[path]: addedRoute
|
|
392
450
|
});
|
|
393
451
|
|
|
394
|
-
return
|
|
395
|
-
[path]: mergedRoute
|
|
396
|
-
}));
|
|
452
|
+
return this._copy(merged);
|
|
397
453
|
};
|
|
398
454
|
}
|
|
399
455
|
|
|
@@ -404,4 +460,4 @@ class Router {
|
|
|
404
460
|
|
|
405
461
|
var createRouter = Router.create;
|
|
406
462
|
|
|
407
|
-
export { KaitoError, KaitoRequest, KaitoResponse, Router, WrappedError, createFMWServer, createGetContext, createRouter, createServer, getInput, getLastEntryInMultiHeaderValue
|
|
463
|
+
export { KaitoError, KaitoRequest, KaitoResponse, Router, WrappedError, createFMWServer, createGetContext, createRouter, createServer, getInput, getLastEntryInMultiHeaderValue };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaito-http/core",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.6",
|
|
4
4
|
"description": "Functional HTTP Framework for TypeScript",
|
|
5
5
|
"repository": "https://github.com/kaito-http/kaito",
|
|
6
6
|
"author": "Alistair Smith <hi@alistair.sh>",
|
|
@@ -9,8 +9,7 @@
|
|
|
9
9
|
"module": "dist/kaito-http-core.esm.js",
|
|
10
10
|
"types": "dist/kaito-http-core.cjs.d.ts",
|
|
11
11
|
"devDependencies": {
|
|
12
|
-
"@types/
|
|
13
|
-
"@types/node": "^17.0.24",
|
|
12
|
+
"@types/node": "^17.0.25",
|
|
14
13
|
"typescript": "4.6",
|
|
15
14
|
"zod": "^3.14.4"
|
|
16
15
|
},
|