@athenna/http 5.44.0 → 5.45.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/package.json
CHANGED
|
@@ -40,7 +40,11 @@ export declare class RouteResource extends Macroable {
|
|
|
40
40
|
* Route.resource('/test', 'TestController').middleware('auth')
|
|
41
41
|
* ```
|
|
42
42
|
*/
|
|
43
|
-
middleware(middleware: MiddlewareRouteType,
|
|
43
|
+
middleware(middleware: MiddlewareRouteType, options?: {
|
|
44
|
+
only?: RouteResourceTypes[];
|
|
45
|
+
except?: RouteResourceTypes[];
|
|
46
|
+
prepend?: boolean;
|
|
47
|
+
}): RouteResource;
|
|
44
48
|
/**
|
|
45
49
|
* Set a interceptor for the route resource.
|
|
46
50
|
*
|
|
@@ -49,7 +53,11 @@ export declare class RouteResource extends Macroable {
|
|
|
49
53
|
* Route.resource('/test', 'TestController').interceptor('response')
|
|
50
54
|
* ```
|
|
51
55
|
*/
|
|
52
|
-
interceptor(interceptor: InterceptorRouteType,
|
|
56
|
+
interceptor(interceptor: InterceptorRouteType, options?: {
|
|
57
|
+
only?: RouteResourceTypes[];
|
|
58
|
+
except?: RouteResourceTypes[];
|
|
59
|
+
prepend?: boolean;
|
|
60
|
+
}): RouteResource;
|
|
53
61
|
/**
|
|
54
62
|
* Set a terminator for the route resource.
|
|
55
63
|
*
|
|
@@ -58,7 +66,11 @@ export declare class RouteResource extends Macroable {
|
|
|
58
66
|
* Route.resource('/test', 'TestController').terminator('response')
|
|
59
67
|
* ```
|
|
60
68
|
*/
|
|
61
|
-
terminator(terminator: TerminatorRouteType,
|
|
69
|
+
terminator(terminator: TerminatorRouteType, options?: {
|
|
70
|
+
only?: RouteResourceTypes[];
|
|
71
|
+
except?: RouteResourceTypes[];
|
|
72
|
+
prepend?: boolean;
|
|
73
|
+
}): RouteResource;
|
|
62
74
|
/**
|
|
63
75
|
* Register only the methods in the array.
|
|
64
76
|
*
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
9
|
import { Route } from '#src/router/Route';
|
|
10
|
-
import { Is, String, Macroable } from '@athenna/common';
|
|
10
|
+
import { Is, String, Macroable, Options } from '@athenna/common';
|
|
11
11
|
export class RouteResource extends Macroable {
|
|
12
12
|
constructor(resource, controller) {
|
|
13
13
|
super();
|
|
@@ -39,8 +39,25 @@ export class RouteResource extends Macroable {
|
|
|
39
39
|
* Route.resource('/test', 'TestController').middleware('auth')
|
|
40
40
|
* ```
|
|
41
41
|
*/
|
|
42
|
-
middleware(middleware,
|
|
43
|
-
|
|
42
|
+
middleware(middleware, options = {}) {
|
|
43
|
+
options = Options.create(options, {
|
|
44
|
+
only: [],
|
|
45
|
+
except: [],
|
|
46
|
+
prepend: false
|
|
47
|
+
});
|
|
48
|
+
if (options.only.length) {
|
|
49
|
+
this.filter(options.only).forEach(route => {
|
|
50
|
+
route.middleware(middleware, options.prepend);
|
|
51
|
+
});
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
if (options.except.length) {
|
|
55
|
+
this.filter(options.except, true).forEach(route => {
|
|
56
|
+
route.middleware(middleware, options.prepend);
|
|
57
|
+
});
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
this.routes.forEach(route => route.middleware(middleware, options.prepend));
|
|
44
61
|
return this;
|
|
45
62
|
}
|
|
46
63
|
/**
|
|
@@ -51,8 +68,25 @@ export class RouteResource extends Macroable {
|
|
|
51
68
|
* Route.resource('/test', 'TestController').interceptor('response')
|
|
52
69
|
* ```
|
|
53
70
|
*/
|
|
54
|
-
interceptor(interceptor,
|
|
55
|
-
|
|
71
|
+
interceptor(interceptor, options = {}) {
|
|
72
|
+
options = Options.create(options, {
|
|
73
|
+
only: [],
|
|
74
|
+
except: [],
|
|
75
|
+
prepend: false
|
|
76
|
+
});
|
|
77
|
+
if (options.only.length) {
|
|
78
|
+
this.filter(options.only).forEach(route => {
|
|
79
|
+
route.interceptor(interceptor, options.prepend);
|
|
80
|
+
});
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
if (options.except.length) {
|
|
84
|
+
this.filter(options.except, true).forEach(route => {
|
|
85
|
+
route.interceptor(interceptor, options.prepend);
|
|
86
|
+
});
|
|
87
|
+
return this;
|
|
88
|
+
}
|
|
89
|
+
this.routes.forEach(route => route.interceptor(interceptor, options.prepend));
|
|
56
90
|
return this;
|
|
57
91
|
}
|
|
58
92
|
/**
|
|
@@ -63,8 +97,25 @@ export class RouteResource extends Macroable {
|
|
|
63
97
|
* Route.resource('/test', 'TestController').terminator('response')
|
|
64
98
|
* ```
|
|
65
99
|
*/
|
|
66
|
-
terminator(terminator,
|
|
67
|
-
|
|
100
|
+
terminator(terminator, options = {}) {
|
|
101
|
+
options = Options.create(options, {
|
|
102
|
+
only: [],
|
|
103
|
+
except: [],
|
|
104
|
+
prepend: false
|
|
105
|
+
});
|
|
106
|
+
if (options.only.length) {
|
|
107
|
+
this.filter(options.only).forEach(route => {
|
|
108
|
+
route.terminator(terminator, options.prepend);
|
|
109
|
+
});
|
|
110
|
+
return this;
|
|
111
|
+
}
|
|
112
|
+
if (options.except.length) {
|
|
113
|
+
this.filter(options.except, true).forEach(route => {
|
|
114
|
+
route.terminator(terminator, options.prepend);
|
|
115
|
+
});
|
|
116
|
+
return this;
|
|
117
|
+
}
|
|
118
|
+
this.routes.forEach(route => route.terminator(terminator, options.prepend));
|
|
68
119
|
return this;
|
|
69
120
|
}
|
|
70
121
|
/**
|