@h3ravel/shared 0.8.0 → 0.9.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 +6 -0
- package/dist/index.d.cts +17 -15
- package/dist/index.d.ts +17 -15
- package/package.json +1 -1
- package/src/Contracts/IHttp.ts +23 -23
package/CHANGELOG.md
CHANGED
package/dist/index.d.cts
CHANGED
|
@@ -196,46 +196,42 @@ interface IRouter {
|
|
|
196
196
|
/**
|
|
197
197
|
* Registers a GET route.
|
|
198
198
|
* @param path - The route path.
|
|
199
|
-
* @param
|
|
200
|
-
* @param methodName - Optional controller method name.
|
|
199
|
+
* @param definition - The handler function or [controller class, method] array.
|
|
201
200
|
* @param name - Optional route name.
|
|
202
201
|
* @param middleware - Optional middleware array.
|
|
203
202
|
*/
|
|
204
|
-
get(path: string,
|
|
203
|
+
get(path: string, definition: EventHandler | [(new (...args: any[]) => IController), methodName: string], name?: string, middleware?: IMiddleware[]): this;
|
|
205
204
|
/**
|
|
206
205
|
* Registers a POST route.
|
|
207
206
|
* @param path - The route path.
|
|
208
|
-
* @param
|
|
209
|
-
* @param methodName - Optional controller method name.
|
|
207
|
+
* @param definition - The handler function or [controller class, method] array.
|
|
210
208
|
* @param name - Optional route name.
|
|
211
209
|
* @param middleware - Optional middleware array.
|
|
212
210
|
*/
|
|
213
|
-
post(path: string,
|
|
211
|
+
post(path: string, definition: EventHandler | [(new (...args: any[]) => IController), methodName: string], name?: string, middleware?: IMiddleware[]): this;
|
|
214
212
|
/**
|
|
215
213
|
* Registers a PUT route.
|
|
216
214
|
* @param path - The route path.
|
|
217
|
-
* @param
|
|
218
|
-
* @param methodName - Optional controller method name.
|
|
215
|
+
* @param definition - The handler function or [controller class, method] array.
|
|
219
216
|
* @param name - Optional route name.
|
|
220
217
|
* @param middleware - Optional middleware array.
|
|
221
218
|
*/
|
|
222
|
-
put(path: string,
|
|
219
|
+
put(path: string, definition: EventHandler | [(new (...args: any[]) => IController), methodName: string], name?: string, middleware?: IMiddleware[]): this;
|
|
223
220
|
/**
|
|
224
221
|
* Registers a DELETE route.
|
|
225
222
|
* @param path - The route path.
|
|
226
|
-
* @param
|
|
227
|
-
* @param methodName - Optional controller method name.
|
|
223
|
+
* @param definition - The handler function or [controller class, method] array.
|
|
228
224
|
* @param name - Optional route name.
|
|
229
225
|
* @param middleware - Optional middleware array.
|
|
230
226
|
*/
|
|
231
|
-
delete(path: string,
|
|
227
|
+
delete(path: string, definition: EventHandler | [(new (...args: any[]) => IController), methodName: string], name?: string, middleware?: IMiddleware[]): this;
|
|
232
228
|
/**
|
|
233
229
|
* Registers an API resource with standard CRUD routes.
|
|
234
230
|
* @param path - The base path for the resource.
|
|
235
231
|
* @param controller - The controller class handling the resource.
|
|
236
232
|
* @param middleware - Optional middleware array.
|
|
237
233
|
*/
|
|
238
|
-
apiResource(path: string, controller: new (app: IApplication) => IController, middleware?: IMiddleware[]):
|
|
234
|
+
apiResource(path: string, controller: new (app: IApplication) => IController, middleware?: IMiddleware[]): this;
|
|
239
235
|
/**
|
|
240
236
|
* Generates a URL for a named route.
|
|
241
237
|
* @param name - The name of the route.
|
|
@@ -243,6 +239,12 @@ interface IRouter {
|
|
|
243
239
|
* @returns The generated URL or undefined if the route is not found.
|
|
244
240
|
*/
|
|
245
241
|
route(name: string, params?: Record<string, string>): string | undefined;
|
|
242
|
+
/**
|
|
243
|
+
* Set the name of the current route
|
|
244
|
+
*
|
|
245
|
+
* @param name
|
|
246
|
+
*/
|
|
247
|
+
name(name: string): this;
|
|
246
248
|
/**
|
|
247
249
|
* Groups routes with shared prefix or middleware.
|
|
248
250
|
* @param options - Configuration for prefix or middleware.
|
|
@@ -251,14 +253,14 @@ interface IRouter {
|
|
|
251
253
|
group(options: {
|
|
252
254
|
prefix?: string;
|
|
253
255
|
middleware?: EventHandler[];
|
|
254
|
-
}, callback: () => void):
|
|
256
|
+
}, callback: () => void): this;
|
|
255
257
|
/**
|
|
256
258
|
* Registers middleware for a specific path.
|
|
257
259
|
* @param path - The path to apply the middleware.
|
|
258
260
|
* @param handler - The middleware handler.
|
|
259
261
|
* @param opts - Optional middleware options.
|
|
260
262
|
*/
|
|
261
|
-
middleware(path: string, handler: Middleware, opts?: MiddlewareOptions):
|
|
263
|
+
middleware(path: string | IMiddleware[], handler: Middleware, opts?: MiddlewareOptions): this;
|
|
262
264
|
}
|
|
263
265
|
interface HttpContext {
|
|
264
266
|
request: IRequest;
|
package/dist/index.d.ts
CHANGED
|
@@ -196,46 +196,42 @@ interface IRouter {
|
|
|
196
196
|
/**
|
|
197
197
|
* Registers a GET route.
|
|
198
198
|
* @param path - The route path.
|
|
199
|
-
* @param
|
|
200
|
-
* @param methodName - Optional controller method name.
|
|
199
|
+
* @param definition - The handler function or [controller class, method] array.
|
|
201
200
|
* @param name - Optional route name.
|
|
202
201
|
* @param middleware - Optional middleware array.
|
|
203
202
|
*/
|
|
204
|
-
get(path: string,
|
|
203
|
+
get(path: string, definition: EventHandler | [(new (...args: any[]) => IController), methodName: string], name?: string, middleware?: IMiddleware[]): this;
|
|
205
204
|
/**
|
|
206
205
|
* Registers a POST route.
|
|
207
206
|
* @param path - The route path.
|
|
208
|
-
* @param
|
|
209
|
-
* @param methodName - Optional controller method name.
|
|
207
|
+
* @param definition - The handler function or [controller class, method] array.
|
|
210
208
|
* @param name - Optional route name.
|
|
211
209
|
* @param middleware - Optional middleware array.
|
|
212
210
|
*/
|
|
213
|
-
post(path: string,
|
|
211
|
+
post(path: string, definition: EventHandler | [(new (...args: any[]) => IController), methodName: string], name?: string, middleware?: IMiddleware[]): this;
|
|
214
212
|
/**
|
|
215
213
|
* Registers a PUT route.
|
|
216
214
|
* @param path - The route path.
|
|
217
|
-
* @param
|
|
218
|
-
* @param methodName - Optional controller method name.
|
|
215
|
+
* @param definition - The handler function or [controller class, method] array.
|
|
219
216
|
* @param name - Optional route name.
|
|
220
217
|
* @param middleware - Optional middleware array.
|
|
221
218
|
*/
|
|
222
|
-
put(path: string,
|
|
219
|
+
put(path: string, definition: EventHandler | [(new (...args: any[]) => IController), methodName: string], name?: string, middleware?: IMiddleware[]): this;
|
|
223
220
|
/**
|
|
224
221
|
* Registers a DELETE route.
|
|
225
222
|
* @param path - The route path.
|
|
226
|
-
* @param
|
|
227
|
-
* @param methodName - Optional controller method name.
|
|
223
|
+
* @param definition - The handler function or [controller class, method] array.
|
|
228
224
|
* @param name - Optional route name.
|
|
229
225
|
* @param middleware - Optional middleware array.
|
|
230
226
|
*/
|
|
231
|
-
delete(path: string,
|
|
227
|
+
delete(path: string, definition: EventHandler | [(new (...args: any[]) => IController), methodName: string], name?: string, middleware?: IMiddleware[]): this;
|
|
232
228
|
/**
|
|
233
229
|
* Registers an API resource with standard CRUD routes.
|
|
234
230
|
* @param path - The base path for the resource.
|
|
235
231
|
* @param controller - The controller class handling the resource.
|
|
236
232
|
* @param middleware - Optional middleware array.
|
|
237
233
|
*/
|
|
238
|
-
apiResource(path: string, controller: new (app: IApplication) => IController, middleware?: IMiddleware[]):
|
|
234
|
+
apiResource(path: string, controller: new (app: IApplication) => IController, middleware?: IMiddleware[]): this;
|
|
239
235
|
/**
|
|
240
236
|
* Generates a URL for a named route.
|
|
241
237
|
* @param name - The name of the route.
|
|
@@ -243,6 +239,12 @@ interface IRouter {
|
|
|
243
239
|
* @returns The generated URL or undefined if the route is not found.
|
|
244
240
|
*/
|
|
245
241
|
route(name: string, params?: Record<string, string>): string | undefined;
|
|
242
|
+
/**
|
|
243
|
+
* Set the name of the current route
|
|
244
|
+
*
|
|
245
|
+
* @param name
|
|
246
|
+
*/
|
|
247
|
+
name(name: string): this;
|
|
246
248
|
/**
|
|
247
249
|
* Groups routes with shared prefix or middleware.
|
|
248
250
|
* @param options - Configuration for prefix or middleware.
|
|
@@ -251,14 +253,14 @@ interface IRouter {
|
|
|
251
253
|
group(options: {
|
|
252
254
|
prefix?: string;
|
|
253
255
|
middleware?: EventHandler[];
|
|
254
|
-
}, callback: () => void):
|
|
256
|
+
}, callback: () => void): this;
|
|
255
257
|
/**
|
|
256
258
|
* Registers middleware for a specific path.
|
|
257
259
|
* @param path - The path to apply the middleware.
|
|
258
260
|
* @param handler - The middleware handler.
|
|
259
261
|
* @param opts - Optional middleware options.
|
|
260
262
|
*/
|
|
261
|
-
middleware(path: string, handler: Middleware, opts?: MiddlewareOptions):
|
|
263
|
+
middleware(path: string | IMiddleware[], handler: Middleware, opts?: MiddlewareOptions): this;
|
|
262
264
|
}
|
|
263
265
|
interface HttpContext {
|
|
264
266
|
request: IRequest;
|
package/package.json
CHANGED
package/src/Contracts/IHttp.ts
CHANGED
|
@@ -11,66 +11,58 @@ export interface IRouter {
|
|
|
11
11
|
/**
|
|
12
12
|
* Registers a GET route.
|
|
13
13
|
* @param path - The route path.
|
|
14
|
-
* @param
|
|
15
|
-
* @param methodName - Optional controller method name.
|
|
14
|
+
* @param definition - The handler function or [controller class, method] array.
|
|
16
15
|
* @param name - Optional route name.
|
|
17
16
|
* @param middleware - Optional middleware array.
|
|
18
17
|
*/
|
|
19
18
|
get (
|
|
20
19
|
path: string,
|
|
21
|
-
|
|
22
|
-
methodName?: string,
|
|
20
|
+
definition: EventHandler | [(new (...args: any[]) => IController), methodName: string],
|
|
23
21
|
name?: string,
|
|
24
22
|
middleware?: IMiddleware[]
|
|
25
|
-
):
|
|
23
|
+
): this;
|
|
26
24
|
|
|
27
25
|
/**
|
|
28
26
|
* Registers a POST route.
|
|
29
27
|
* @param path - The route path.
|
|
30
|
-
* @param
|
|
31
|
-
* @param methodName - Optional controller method name.
|
|
28
|
+
* @param definition - The handler function or [controller class, method] array.
|
|
32
29
|
* @param name - Optional route name.
|
|
33
30
|
* @param middleware - Optional middleware array.
|
|
34
31
|
*/
|
|
35
32
|
post (
|
|
36
33
|
path: string,
|
|
37
|
-
|
|
38
|
-
methodName?: string,
|
|
34
|
+
definition: EventHandler | [(new (...args: any[]) => IController), methodName: string],
|
|
39
35
|
name?: string,
|
|
40
36
|
middleware?: IMiddleware[]
|
|
41
|
-
):
|
|
37
|
+
): this;
|
|
42
38
|
|
|
43
39
|
/**
|
|
44
40
|
* Registers a PUT route.
|
|
45
41
|
* @param path - The route path.
|
|
46
|
-
* @param
|
|
47
|
-
* @param methodName - Optional controller method name.
|
|
42
|
+
* @param definition - The handler function or [controller class, method] array.
|
|
48
43
|
* @param name - Optional route name.
|
|
49
44
|
* @param middleware - Optional middleware array.
|
|
50
45
|
*/
|
|
51
46
|
put (
|
|
52
47
|
path: string,
|
|
53
|
-
|
|
54
|
-
methodName?: string,
|
|
48
|
+
definition: EventHandler | [(new (...args: any[]) => IController), methodName: string],
|
|
55
49
|
name?: string,
|
|
56
50
|
middleware?: IMiddleware[]
|
|
57
|
-
):
|
|
51
|
+
): this;
|
|
58
52
|
|
|
59
53
|
/**
|
|
60
54
|
* Registers a DELETE route.
|
|
61
55
|
* @param path - The route path.
|
|
62
|
-
* @param
|
|
63
|
-
* @param methodName - Optional controller method name.
|
|
56
|
+
* @param definition - The handler function or [controller class, method] array.
|
|
64
57
|
* @param name - Optional route name.
|
|
65
58
|
* @param middleware - Optional middleware array.
|
|
66
59
|
*/
|
|
67
60
|
delete (
|
|
68
61
|
path: string,
|
|
69
|
-
|
|
70
|
-
methodName?: string,
|
|
62
|
+
definition: EventHandler | [(new (...args: any[]) => IController), methodName: string],
|
|
71
63
|
name?: string,
|
|
72
64
|
middleware?: IMiddleware[]
|
|
73
|
-
):
|
|
65
|
+
): this;
|
|
74
66
|
|
|
75
67
|
/**
|
|
76
68
|
* Registers an API resource with standard CRUD routes.
|
|
@@ -82,7 +74,7 @@ export interface IRouter {
|
|
|
82
74
|
path: string,
|
|
83
75
|
controller: new (app: IApplication) => IController,
|
|
84
76
|
middleware?: IMiddleware[]
|
|
85
|
-
):
|
|
77
|
+
): this;
|
|
86
78
|
|
|
87
79
|
/**
|
|
88
80
|
* Generates a URL for a named route.
|
|
@@ -92,12 +84,20 @@ export interface IRouter {
|
|
|
92
84
|
*/
|
|
93
85
|
route (name: string, params?: Record<string, string>): string | undefined;
|
|
94
86
|
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Set the name of the current route
|
|
90
|
+
*
|
|
91
|
+
* @param name
|
|
92
|
+
*/
|
|
93
|
+
name (name: string): this
|
|
94
|
+
|
|
95
95
|
/**
|
|
96
96
|
* Groups routes with shared prefix or middleware.
|
|
97
97
|
* @param options - Configuration for prefix or middleware.
|
|
98
98
|
* @param callback - Callback function defining grouped routes.
|
|
99
99
|
*/
|
|
100
|
-
group (options: { prefix?: string; middleware?: EventHandler[] }, callback: () => void):
|
|
100
|
+
group (options: { prefix?: string; middleware?: EventHandler[] }, callback: () => void): this;
|
|
101
101
|
|
|
102
102
|
/**
|
|
103
103
|
* Registers middleware for a specific path.
|
|
@@ -105,7 +105,7 @@ export interface IRouter {
|
|
|
105
105
|
* @param handler - The middleware handler.
|
|
106
106
|
* @param opts - Optional middleware options.
|
|
107
107
|
*/
|
|
108
|
-
middleware (path: string, handler: Middleware, opts?: MiddlewareOptions):
|
|
108
|
+
middleware (path: string | IMiddleware[], handler: Middleware, opts?: MiddlewareOptions): this;
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
export interface HttpContext {
|