bun-crumb 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +39 -8
- package/dist/types/route.d.ts +38 -7
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -48,7 +48,7 @@ type Validate = (data: unknown, schema: SchemaData) => boolean;
|
|
|
48
48
|
* const method: HttpMethod = 'GET';
|
|
49
49
|
* ```
|
|
50
50
|
*/
|
|
51
|
-
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS';
|
|
51
|
+
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD';
|
|
52
52
|
type RedirectStatusCode = 300 | 301 | 302 | 303 | 304 | 307 | 308;
|
|
53
53
|
/**
|
|
54
54
|
* HTTP Header struct.
|
|
@@ -58,16 +58,47 @@ type Header = {
|
|
|
58
58
|
value: string;
|
|
59
59
|
};
|
|
60
60
|
type Headers = ResponseInit['headers'];
|
|
61
|
+
type RouteRequestParams<T extends string | undefined = undefined> = [
|
|
62
|
+
T
|
|
63
|
+
] extends [string] ? {
|
|
64
|
+
[K in T]: string;
|
|
65
|
+
} : {
|
|
66
|
+
[key: string]: string | undefined;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
*
|
|
70
|
+
*
|
|
71
|
+
* Type of RouteRequest generic
|
|
72
|
+
*
|
|
73
|
+
*
|
|
74
|
+
*
|
|
75
|
+
*
|
|
76
|
+
*
|
|
77
|
+
*/
|
|
78
|
+
interface RouteRequestGeneric {
|
|
79
|
+
body?: unknown;
|
|
80
|
+
params?: string;
|
|
81
|
+
}
|
|
61
82
|
/**
|
|
62
83
|
* Type of route handler `request`
|
|
63
84
|
*/
|
|
64
|
-
interface RouteRequest<T extends {
|
|
65
|
-
|
|
66
|
-
} = {
|
|
67
|
-
body: unknown;
|
|
68
|
-
}> extends Omit<BunRequest, 'body'> {
|
|
85
|
+
interface RouteRequest<T extends RouteRequestGeneric = RouteRequestGeneric> extends Omit<BunRequest, 'params'> {
|
|
86
|
+
params: RouteRequestParams<T['params']>;
|
|
69
87
|
/**
|
|
70
|
-
*
|
|
88
|
+
* #### Parses and validates body of request.
|
|
89
|
+
*
|
|
90
|
+
* - Parses body to JSON or text
|
|
91
|
+
* - Validates body with `schemaValidator` if it is provided.
|
|
92
|
+
*
|
|
93
|
+
* @returns Promise with handled body
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
*
|
|
97
|
+
* ```typescript
|
|
98
|
+
* request.handleBody().then((bodyData) => {
|
|
99
|
+
* console.log(bodyData);
|
|
100
|
+
* })
|
|
101
|
+
* ```
|
|
71
102
|
*/
|
|
72
103
|
handleBody: () => Promise<T extends {
|
|
73
104
|
body: unknown;
|
|
@@ -203,4 +234,4 @@ declare const listen: (options?: ListenOptions) => void;
|
|
|
203
234
|
declare const createRoute: (routeOptions: RouteOptions) => void;
|
|
204
235
|
|
|
205
236
|
export { createRoute, listen };
|
|
206
|
-
export type { Header, Headers, HttpMethod, ListenOptions, RedirectStatusCode, ResponseOptions, Route, RouteHandler, RouteOptions, RouteRequest, RouteResponse, Schema, SchemaData, Validate };
|
|
237
|
+
export type { Header, Headers, HttpMethod, ListenOptions, RedirectStatusCode, ResponseOptions, Route, RouteHandler, RouteOptions, RouteRequest, RouteRequestGeneric, RouteRequestParams, RouteResponse, Schema, SchemaData, Validate };
|
package/dist/types/route.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import type { SchemaData } from './schema';
|
|
|
8
8
|
* const method: HttpMethod = 'GET';
|
|
9
9
|
* ```
|
|
10
10
|
*/
|
|
11
|
-
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS';
|
|
11
|
+
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD';
|
|
12
12
|
export type RedirectStatusCode = 300 | 301 | 302 | 303 | 304 | 307 | 308;
|
|
13
13
|
/**
|
|
14
14
|
* HTTP Header struct.
|
|
@@ -18,16 +18,47 @@ export type Header = {
|
|
|
18
18
|
value: string;
|
|
19
19
|
};
|
|
20
20
|
export type Headers = ResponseInit['headers'];
|
|
21
|
+
export type RouteRequestParams<T extends string | undefined = undefined> = [
|
|
22
|
+
T
|
|
23
|
+
] extends [string] ? {
|
|
24
|
+
[K in T]: string;
|
|
25
|
+
} : {
|
|
26
|
+
[key: string]: string | undefined;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
*
|
|
30
|
+
*
|
|
31
|
+
* Type of RouteRequest generic
|
|
32
|
+
*
|
|
33
|
+
*
|
|
34
|
+
*
|
|
35
|
+
*
|
|
36
|
+
*
|
|
37
|
+
*/
|
|
38
|
+
export interface RouteRequestGeneric {
|
|
39
|
+
body?: unknown;
|
|
40
|
+
params?: string;
|
|
41
|
+
}
|
|
21
42
|
/**
|
|
22
43
|
* Type of route handler `request`
|
|
23
44
|
*/
|
|
24
|
-
export interface RouteRequest<T extends {
|
|
25
|
-
|
|
26
|
-
} = {
|
|
27
|
-
body: unknown;
|
|
28
|
-
}> extends Omit<BunRequest, 'body'> {
|
|
45
|
+
export interface RouteRequest<T extends RouteRequestGeneric = RouteRequestGeneric> extends Omit<BunRequest, 'params'> {
|
|
46
|
+
params: RouteRequestParams<T['params']>;
|
|
29
47
|
/**
|
|
30
|
-
*
|
|
48
|
+
* #### Parses and validates body of request.
|
|
49
|
+
*
|
|
50
|
+
* - Parses body to JSON or text
|
|
51
|
+
* - Validates body with `schemaValidator` if it is provided.
|
|
52
|
+
*
|
|
53
|
+
* @returns Promise with handled body
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
*
|
|
57
|
+
* ```typescript
|
|
58
|
+
* request.handleBody().then((bodyData) => {
|
|
59
|
+
* console.log(bodyData);
|
|
60
|
+
* })
|
|
61
|
+
* ```
|
|
31
62
|
*/
|
|
32
63
|
handleBody: () => Promise<T extends {
|
|
33
64
|
body: unknown;
|