@h3ravel/shared 0.10.0 → 0.12.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/CHANGELOG.md +12 -0
- package/dist/index.d.cts +20 -12
- package/dist/index.d.ts +20 -12
- package/package.json +1 -1
- package/src/Contracts/IHttp.ts +2 -2
- package/src/Contracts/IRequest.ts +17 -11
- package/src/Contracts/IResponse.ts +6 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @h3ravel/shared
|
|
2
2
|
|
|
3
|
+
## 0.12.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- feat: add the current app instance to the Request and Response object
|
|
8
|
+
|
|
9
|
+
## 0.11.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- remove 'name' from RouterEnd and only join in apiResource.
|
|
14
|
+
|
|
3
15
|
## 0.10.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/dist/index.d.cts
CHANGED
|
@@ -103,17 +103,9 @@ type DotNestedValue<T, Path extends string> = Path extends `${infer Key}.${infer
|
|
|
103
103
|
*/
|
|
104
104
|
interface IRequest {
|
|
105
105
|
/**
|
|
106
|
-
*
|
|
107
|
-
* @returns A promise resolving to an object containing all input data.
|
|
108
|
-
*/
|
|
109
|
-
all<T = Record<string, unknown>>(): Promise<T>;
|
|
110
|
-
/**
|
|
111
|
-
* Gets a single input field from query or body.
|
|
112
|
-
* @param key - The key of the input field.
|
|
113
|
-
* @param defaultValue - Optional default value if the key is not found.
|
|
114
|
-
* @returns A promise resolving to the value of the input field or the default value.
|
|
106
|
+
* The current app instance
|
|
115
107
|
*/
|
|
116
|
-
|
|
108
|
+
app: IApplication;
|
|
117
109
|
/**
|
|
118
110
|
* Gets route parameters.
|
|
119
111
|
* @returns An object containing route parameters.
|
|
@@ -129,6 +121,18 @@ interface IRequest {
|
|
|
129
121
|
* @returns An object containing request headers.
|
|
130
122
|
*/
|
|
131
123
|
headers: TypedHeaders<Record<keyof ResponseHeaderMap, string>>;
|
|
124
|
+
/**
|
|
125
|
+
* Gets all input data (query parameters, route parameters, and body).
|
|
126
|
+
* @returns A promise resolving to an object containing all input data.
|
|
127
|
+
*/
|
|
128
|
+
all<T = Record<string, unknown>>(): Promise<T>;
|
|
129
|
+
/**
|
|
130
|
+
* Gets a single input field from query or body.
|
|
131
|
+
* @param key - The key of the input field.
|
|
132
|
+
* @param defaultValue - Optional default value if the key is not found.
|
|
133
|
+
* @returns A promise resolving to the value of the input field or the default value.
|
|
134
|
+
*/
|
|
135
|
+
input<T = unknown>(key: string, defaultValue?: T): Promise<T>;
|
|
132
136
|
/**
|
|
133
137
|
* Gets the underlying event object or a specific property of it.
|
|
134
138
|
* @param key - Optional key to access a nested property of the event.
|
|
@@ -142,6 +146,10 @@ interface IRequest {
|
|
|
142
146
|
* Interface for the Response contract, defining methods for handling HTTP responses.
|
|
143
147
|
*/
|
|
144
148
|
interface IResponse {
|
|
149
|
+
/**
|
|
150
|
+
* The current app instance
|
|
151
|
+
*/
|
|
152
|
+
app: IApplication;
|
|
145
153
|
/**
|
|
146
154
|
* Sets the HTTP status code for the response.
|
|
147
155
|
* @param code - The HTTP status code.
|
|
@@ -189,7 +197,7 @@ interface IResponse {
|
|
|
189
197
|
getEvent<K extends DotNestedKeys<H3Event>>(key: K): DotNestedValue<H3Event, K>;
|
|
190
198
|
}
|
|
191
199
|
|
|
192
|
-
type RouterEnd = 'get' | 'delete' | 'put' | 'post' | 'apiResource' | '
|
|
200
|
+
type RouterEnd = 'get' | 'delete' | 'put' | 'post' | 'apiResource' | 'group' | 'route';
|
|
193
201
|
/**
|
|
194
202
|
* Interface for the Router contract, defining methods for HTTP routing.
|
|
195
203
|
*/
|
|
@@ -232,7 +240,7 @@ interface IRouter {
|
|
|
232
240
|
* @param controller - The controller class handling the resource.
|
|
233
241
|
* @param middleware - Optional middleware array.
|
|
234
242
|
*/
|
|
235
|
-
apiResource(path: string, controller: new (app: IApplication) => IController, middleware?: IMiddleware[]): Omit<this, RouterEnd>;
|
|
243
|
+
apiResource(path: string, controller: new (app: IApplication) => IController, middleware?: IMiddleware[]): Omit<this, RouterEnd | 'name'>;
|
|
236
244
|
/**
|
|
237
245
|
* Generates a URL for a named route.
|
|
238
246
|
* @param name - The name of the route.
|
package/dist/index.d.ts
CHANGED
|
@@ -103,17 +103,9 @@ type DotNestedValue<T, Path extends string> = Path extends `${infer Key}.${infer
|
|
|
103
103
|
*/
|
|
104
104
|
interface IRequest {
|
|
105
105
|
/**
|
|
106
|
-
*
|
|
107
|
-
* @returns A promise resolving to an object containing all input data.
|
|
108
|
-
*/
|
|
109
|
-
all<T = Record<string, unknown>>(): Promise<T>;
|
|
110
|
-
/**
|
|
111
|
-
* Gets a single input field from query or body.
|
|
112
|
-
* @param key - The key of the input field.
|
|
113
|
-
* @param defaultValue - Optional default value if the key is not found.
|
|
114
|
-
* @returns A promise resolving to the value of the input field or the default value.
|
|
106
|
+
* The current app instance
|
|
115
107
|
*/
|
|
116
|
-
|
|
108
|
+
app: IApplication;
|
|
117
109
|
/**
|
|
118
110
|
* Gets route parameters.
|
|
119
111
|
* @returns An object containing route parameters.
|
|
@@ -129,6 +121,18 @@ interface IRequest {
|
|
|
129
121
|
* @returns An object containing request headers.
|
|
130
122
|
*/
|
|
131
123
|
headers: TypedHeaders<Record<keyof ResponseHeaderMap, string>>;
|
|
124
|
+
/**
|
|
125
|
+
* Gets all input data (query parameters, route parameters, and body).
|
|
126
|
+
* @returns A promise resolving to an object containing all input data.
|
|
127
|
+
*/
|
|
128
|
+
all<T = Record<string, unknown>>(): Promise<T>;
|
|
129
|
+
/**
|
|
130
|
+
* Gets a single input field from query or body.
|
|
131
|
+
* @param key - The key of the input field.
|
|
132
|
+
* @param defaultValue - Optional default value if the key is not found.
|
|
133
|
+
* @returns A promise resolving to the value of the input field or the default value.
|
|
134
|
+
*/
|
|
135
|
+
input<T = unknown>(key: string, defaultValue?: T): Promise<T>;
|
|
132
136
|
/**
|
|
133
137
|
* Gets the underlying event object or a specific property of it.
|
|
134
138
|
* @param key - Optional key to access a nested property of the event.
|
|
@@ -142,6 +146,10 @@ interface IRequest {
|
|
|
142
146
|
* Interface for the Response contract, defining methods for handling HTTP responses.
|
|
143
147
|
*/
|
|
144
148
|
interface IResponse {
|
|
149
|
+
/**
|
|
150
|
+
* The current app instance
|
|
151
|
+
*/
|
|
152
|
+
app: IApplication;
|
|
145
153
|
/**
|
|
146
154
|
* Sets the HTTP status code for the response.
|
|
147
155
|
* @param code - The HTTP status code.
|
|
@@ -189,7 +197,7 @@ interface IResponse {
|
|
|
189
197
|
getEvent<K extends DotNestedKeys<H3Event>>(key: K): DotNestedValue<H3Event, K>;
|
|
190
198
|
}
|
|
191
199
|
|
|
192
|
-
type RouterEnd = 'get' | 'delete' | 'put' | 'post' | 'apiResource' | '
|
|
200
|
+
type RouterEnd = 'get' | 'delete' | 'put' | 'post' | 'apiResource' | 'group' | 'route';
|
|
193
201
|
/**
|
|
194
202
|
* Interface for the Router contract, defining methods for HTTP routing.
|
|
195
203
|
*/
|
|
@@ -232,7 +240,7 @@ interface IRouter {
|
|
|
232
240
|
* @param controller - The controller class handling the resource.
|
|
233
241
|
* @param middleware - Optional middleware array.
|
|
234
242
|
*/
|
|
235
|
-
apiResource(path: string, controller: new (app: IApplication) => IController, middleware?: IMiddleware[]): Omit<this, RouterEnd>;
|
|
243
|
+
apiResource(path: string, controller: new (app: IApplication) => IController, middleware?: IMiddleware[]): Omit<this, RouterEnd | 'name'>;
|
|
236
244
|
/**
|
|
237
245
|
* Generates a URL for a named route.
|
|
238
246
|
* @param name - The name of the route.
|
package/package.json
CHANGED
package/src/Contracts/IHttp.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { IApplication } from './IApplication'
|
|
|
4
4
|
import { IRequest } from './IRequest'
|
|
5
5
|
import { IResponse } from './IResponse'
|
|
6
6
|
|
|
7
|
-
export type RouterEnd = 'get' | 'delete' | 'put' | 'post' | 'apiResource' | '
|
|
7
|
+
export type RouterEnd = 'get' | 'delete' | 'put' | 'post' | 'apiResource' | 'group' | 'route';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Interface for the Router contract, defining methods for HTTP routing.
|
|
@@ -76,7 +76,7 @@ export interface IRouter {
|
|
|
76
76
|
path: string,
|
|
77
77
|
controller: new (app: IApplication) => IController,
|
|
78
78
|
middleware?: IMiddleware[]
|
|
79
|
-
): Omit<this, RouterEnd>;
|
|
79
|
+
): Omit<this, RouterEnd | 'name'>;
|
|
80
80
|
|
|
81
81
|
/**
|
|
82
82
|
* Generates a URL for a named route.
|
|
@@ -2,24 +2,16 @@ import { DotNestedKeys, DotNestedValue } from './ObjContract'
|
|
|
2
2
|
import type { ResponseHeaderMap, TypedHeaders } from 'fetchdts'
|
|
3
3
|
|
|
4
4
|
import type { H3Event } from 'h3'
|
|
5
|
+
import type { IApplication } from './IApplication';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Interface for the Request contract, defining methods for handling HTTP request data.
|
|
8
9
|
*/
|
|
9
10
|
export interface IRequest {
|
|
10
11
|
/**
|
|
11
|
-
*
|
|
12
|
-
* @returns A promise resolving to an object containing all input data.
|
|
12
|
+
* The current app instance
|
|
13
13
|
*/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Gets a single input field from query or body.
|
|
18
|
-
* @param key - The key of the input field.
|
|
19
|
-
* @param defaultValue - Optional default value if the key is not found.
|
|
20
|
-
* @returns A promise resolving to the value of the input field or the default value.
|
|
21
|
-
*/
|
|
22
|
-
input<T = unknown> (key: string, defaultValue?: T): Promise<T>;
|
|
14
|
+
app: IApplication
|
|
23
15
|
|
|
24
16
|
/**
|
|
25
17
|
* Gets route parameters.
|
|
@@ -39,6 +31,20 @@ export interface IRequest {
|
|
|
39
31
|
*/
|
|
40
32
|
headers: TypedHeaders<Record<keyof ResponseHeaderMap, string>>;
|
|
41
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Gets all input data (query parameters, route parameters, and body).
|
|
36
|
+
* @returns A promise resolving to an object containing all input data.
|
|
37
|
+
*/
|
|
38
|
+
all<T = Record<string, unknown>> (): Promise<T>;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Gets a single input field from query or body.
|
|
42
|
+
* @param key - The key of the input field.
|
|
43
|
+
* @param defaultValue - Optional default value if the key is not found.
|
|
44
|
+
* @returns A promise resolving to the value of the input field or the default value.
|
|
45
|
+
*/
|
|
46
|
+
input<T = unknown> (key: string, defaultValue?: T): Promise<T>;
|
|
47
|
+
|
|
42
48
|
/**
|
|
43
49
|
* Gets the underlying event object or a specific property of it.
|
|
44
50
|
* @param key - Optional key to access a nested property of the event.
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import { DotNestedKeys, DotNestedValue } from './ObjContract'
|
|
2
2
|
|
|
3
3
|
import type { H3Event } from 'h3'
|
|
4
|
+
import type { IApplication } from './IApplication';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Interface for the Response contract, defining methods for handling HTTP responses.
|
|
7
8
|
*/
|
|
8
9
|
export interface IResponse {
|
|
10
|
+
/**
|
|
11
|
+
* The current app instance
|
|
12
|
+
*/
|
|
13
|
+
app: IApplication
|
|
14
|
+
|
|
9
15
|
/**
|
|
10
16
|
* Sets the HTTP status code for the response.
|
|
11
17
|
* @param code - The HTTP status code.
|