@novice1/routing 1.1.1 → 1.1.4
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/index.d.ts +5 -5
- package/lib/layer.js +123 -123
- package/lib/route/createLayers.js +39 -39
- package/lib/route/metadataMiddleware.js +32 -32
- package/lib/route.js +205 -205
- package/lib/router/authMethods.js +36 -36
- package/lib/router/editLayersMethods.js +11 -11
- package/lib/router/metaMethods.js +13 -13
- package/lib/router/validatorsMethods.js +36 -36
- package/lib/router.d.ts +432 -432
- package/lib/router.js +314 -314
- package/lib/utils/toArray.js +28 -28
- package/package.json +32 -30
package/lib/route.js
CHANGED
|
@@ -1,206 +1,206 @@
|
|
|
1
|
-
var inherits = require('util').inherits
|
|
2
|
-
var ExpressRoute = require("express/lib/router/route");
|
|
3
|
-
var flatten = require('array-flatten');
|
|
4
|
-
var methods = require("methods");
|
|
5
|
-
|
|
6
|
-
var createMetadataMiddleware = require('./route/metadataMiddleware');
|
|
7
|
-
var createLayers = require('./route/createLayers');
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @classdesc Initialize `Route` with the given `path`,
|
|
11
|
-
* @class
|
|
12
|
-
* @augments ExpressRoute express/lib/router/route
|
|
13
|
-
*/
|
|
14
|
-
function Route() {
|
|
15
|
-
return ExpressRoute.apply(this, Array.from(arguments));
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
inherits(Route, ExpressRoute);
|
|
19
|
-
|
|
20
|
-
methods.concat('all').forEach(function(method){
|
|
21
|
-
/** @inheritdoc */
|
|
22
|
-
Route.prototype[method] = function(){
|
|
23
|
-
var handles = flatten(Array.prototype.slice.call(arguments));
|
|
24
|
-
|
|
25
|
-
// add middleware to serve route's metadata in 'req'
|
|
26
|
-
handles.unshift(createMetadataMiddleware(method, this.path, this.meta));
|
|
27
|
-
|
|
28
|
-
return ExpressRoute.prototype[method].apply(this, handles);
|
|
29
|
-
};
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* @param {object} layerOptions
|
|
34
|
-
* @param {Function[]} args
|
|
35
|
-
*/
|
|
36
|
-
Route.prototype.setAuth = function (layerOptions) {
|
|
37
|
-
var handles = flatten(Array.prototype.slice.call(arguments, 1));
|
|
38
|
-
|
|
39
|
-
this.removeAuth();
|
|
40
|
-
|
|
41
|
-
// insert new layers for those functions
|
|
42
|
-
if (
|
|
43
|
-
Array.isArray(this.stack) && this.methods && this.path
|
|
44
|
-
&& this.meta && this.meta.auth
|
|
45
|
-
&& handles.length){
|
|
46
|
-
Object.keys(this.methods).forEach(
|
|
47
|
-
method => {
|
|
48
|
-
createLayers('auth', method, layerOptions, handles, this.dispatch.bind(this)).forEach(
|
|
49
|
-
layer => {
|
|
50
|
-
this.stack.splice(1, 0, layer);
|
|
51
|
-
}
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* @param {object} layerOptions
|
|
60
|
-
* @param {Function[]} args
|
|
61
|
-
*/
|
|
62
|
-
Route.prototype.setPreValidators = function (layerOptions) {
|
|
63
|
-
var handles = flatten(Array.prototype.slice.call(arguments, 1));
|
|
64
|
-
|
|
65
|
-
this.removePreValidators();
|
|
66
|
-
|
|
67
|
-
// insert new layers for those functions
|
|
68
|
-
if (
|
|
69
|
-
Array.isArray(this.stack) && this.methods && this.path
|
|
70
|
-
&& handles.length){
|
|
71
|
-
Object.keys(this.methods).forEach(
|
|
72
|
-
method => {
|
|
73
|
-
createLayers('preValidator', method, layerOptions, handles, this.dispatch.bind(this)).forEach(
|
|
74
|
-
layer => {
|
|
75
|
-
// insert 'preValidator' layers after 'auth' layers
|
|
76
|
-
|
|
77
|
-
var pos = this.stack.length - 1;
|
|
78
|
-
|
|
79
|
-
for (pos; pos > 0; pos -= 1) {
|
|
80
|
-
if (this.stack[pos].type === 'auth') {
|
|
81
|
-
break;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
pos += 1;
|
|
86
|
-
|
|
87
|
-
// insert before
|
|
88
|
-
this.stack.splice(pos, 0, layer);
|
|
89
|
-
}
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* @alias setPreValidators
|
|
97
|
-
*/
|
|
98
|
-
Route.prototype.setPreValidation = Route.prototype.setPreValidators;
|
|
99
|
-
/**
|
|
100
|
-
* @alias setPreValidators
|
|
101
|
-
*/
|
|
102
|
-
Route.prototype.setPreValidators = Route.prototype.setPreValidators;
|
|
103
|
-
/**
|
|
104
|
-
* @alias setPreValidators
|
|
105
|
-
*/
|
|
106
|
-
Route.prototype.setAfterAuth = Route.prototype.setPreValidators;
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* @param {object} layerOptions
|
|
111
|
-
* @param {Function[]} args
|
|
112
|
-
*/
|
|
113
|
-
Route.prototype.setValidators = function (layerOptions) {
|
|
114
|
-
var handles = flatten(Array.prototype.slice.call(arguments, 1));
|
|
115
|
-
|
|
116
|
-
this.removeValidators();
|
|
117
|
-
|
|
118
|
-
// insert new layers for those functions
|
|
119
|
-
if (
|
|
120
|
-
Array.isArray(this.stack) && this.methods && this.path
|
|
121
|
-
&& handles.length){
|
|
122
|
-
Object.keys(this.methods).forEach(
|
|
123
|
-
method => {
|
|
124
|
-
createLayers('validator', method, layerOptions, handles, this.dispatch.bind(this)).forEach(
|
|
125
|
-
layer => {
|
|
126
|
-
// insert 'validator' layers after 'auth' layers
|
|
127
|
-
|
|
128
|
-
var pos = this.stack.length - 1;
|
|
129
|
-
|
|
130
|
-
for (pos; pos > 0; pos -= 1) {
|
|
131
|
-
if (this.stack[pos].type === 'auth' || this.stack[pos].type === 'preValidator') {
|
|
132
|
-
break;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
pos += 1;
|
|
137
|
-
|
|
138
|
-
// insert before
|
|
139
|
-
this.stack.splice(pos, 0, layer);
|
|
140
|
-
}
|
|
141
|
-
);
|
|
142
|
-
}
|
|
143
|
-
);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
*
|
|
149
|
-
*/
|
|
150
|
-
Route.prototype.hasAuth = function () {
|
|
151
|
-
return this.hasLayerType('auth');
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
*
|
|
156
|
-
*/
|
|
157
|
-
Route.prototype.hasValidators = function () {
|
|
158
|
-
return this.hasLayerType('validator');
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
*
|
|
163
|
-
*/
|
|
164
|
-
Route.prototype.hasPreValidators = function () {
|
|
165
|
-
return this.hasLayerType('preValidator');
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
Route.prototype.hasLayerType = function (type) {
|
|
169
|
-
if (Array.isArray(this.stack)){
|
|
170
|
-
return this.stack.some(
|
|
171
|
-
layer => layer.type === type
|
|
172
|
-
);
|
|
173
|
-
}
|
|
174
|
-
return false;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
*
|
|
179
|
-
*/
|
|
180
|
-
Route.prototype.removeAuth = function () {
|
|
181
|
-
this.removeLayerType('auth');
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
*
|
|
186
|
-
*/
|
|
187
|
-
Route.prototype.removeValidators = function () {
|
|
188
|
-
this.removeLayerType('validator');
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
*
|
|
193
|
-
*/
|
|
194
|
-
Route.prototype.removePreValidators = function () {
|
|
195
|
-
this.removeLayerType('preValidator');
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
Route.prototype.removeLayerType = function (type) {
|
|
199
|
-
if (Array.isArray(this.stack)){
|
|
200
|
-
this.stack = this.stack.filter(
|
|
201
|
-
layer => layer.type !== type
|
|
202
|
-
);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
1
|
+
var inherits = require('util').inherits
|
|
2
|
+
var ExpressRoute = require("express/lib/router/route");
|
|
3
|
+
var { flatten } = require('array-flatten');
|
|
4
|
+
var methods = require("methods");
|
|
5
|
+
|
|
6
|
+
var createMetadataMiddleware = require('./route/metadataMiddleware');
|
|
7
|
+
var createLayers = require('./route/createLayers');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @classdesc Initialize `Route` with the given `path`,
|
|
11
|
+
* @class
|
|
12
|
+
* @augments ExpressRoute express/lib/router/route
|
|
13
|
+
*/
|
|
14
|
+
function Route() {
|
|
15
|
+
return ExpressRoute.apply(this, Array.from(arguments));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
inherits(Route, ExpressRoute);
|
|
19
|
+
|
|
20
|
+
methods.concat('all').forEach(function(method){
|
|
21
|
+
/** @inheritdoc */
|
|
22
|
+
Route.prototype[method] = function(){
|
|
23
|
+
var handles = flatten(Array.prototype.slice.call(arguments));
|
|
24
|
+
|
|
25
|
+
// add middleware to serve route's metadata in 'req'
|
|
26
|
+
handles.unshift(createMetadataMiddleware(method, this.path, this.meta));
|
|
27
|
+
|
|
28
|
+
return ExpressRoute.prototype[method].apply(this, handles);
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @param {object} layerOptions
|
|
34
|
+
* @param {Function[]} args
|
|
35
|
+
*/
|
|
36
|
+
Route.prototype.setAuth = function (layerOptions) {
|
|
37
|
+
var handles = flatten(Array.prototype.slice.call(arguments, 1));
|
|
38
|
+
|
|
39
|
+
this.removeAuth();
|
|
40
|
+
|
|
41
|
+
// insert new layers for those functions
|
|
42
|
+
if (
|
|
43
|
+
Array.isArray(this.stack) && this.methods && this.path
|
|
44
|
+
&& this.meta && this.meta.auth
|
|
45
|
+
&& handles.length){
|
|
46
|
+
Object.keys(this.methods).forEach(
|
|
47
|
+
method => {
|
|
48
|
+
createLayers('auth', method, layerOptions, handles, this.dispatch.bind(this)).forEach(
|
|
49
|
+
layer => {
|
|
50
|
+
this.stack.splice(1, 0, layer);
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @param {object} layerOptions
|
|
60
|
+
* @param {Function[]} args
|
|
61
|
+
*/
|
|
62
|
+
Route.prototype.setPreValidators = function (layerOptions) {
|
|
63
|
+
var handles = flatten(Array.prototype.slice.call(arguments, 1));
|
|
64
|
+
|
|
65
|
+
this.removePreValidators();
|
|
66
|
+
|
|
67
|
+
// insert new layers for those functions
|
|
68
|
+
if (
|
|
69
|
+
Array.isArray(this.stack) && this.methods && this.path
|
|
70
|
+
&& handles.length){
|
|
71
|
+
Object.keys(this.methods).forEach(
|
|
72
|
+
method => {
|
|
73
|
+
createLayers('preValidator', method, layerOptions, handles, this.dispatch.bind(this)).forEach(
|
|
74
|
+
layer => {
|
|
75
|
+
// insert 'preValidator' layers after 'auth' layers
|
|
76
|
+
|
|
77
|
+
var pos = this.stack.length - 1;
|
|
78
|
+
|
|
79
|
+
for (pos; pos > 0; pos -= 1) {
|
|
80
|
+
if (this.stack[pos].type === 'auth') {
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
pos += 1;
|
|
86
|
+
|
|
87
|
+
// insert before
|
|
88
|
+
this.stack.splice(pos, 0, layer);
|
|
89
|
+
}
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* @alias setPreValidators
|
|
97
|
+
*/
|
|
98
|
+
Route.prototype.setPreValidation = Route.prototype.setPreValidators;
|
|
99
|
+
/**
|
|
100
|
+
* @alias setPreValidators
|
|
101
|
+
*/
|
|
102
|
+
Route.prototype.setPreValidators = Route.prototype.setPreValidators;
|
|
103
|
+
/**
|
|
104
|
+
* @alias setPreValidators
|
|
105
|
+
*/
|
|
106
|
+
Route.prototype.setAfterAuth = Route.prototype.setPreValidators;
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @param {object} layerOptions
|
|
111
|
+
* @param {Function[]} args
|
|
112
|
+
*/
|
|
113
|
+
Route.prototype.setValidators = function (layerOptions) {
|
|
114
|
+
var handles = flatten(Array.prototype.slice.call(arguments, 1));
|
|
115
|
+
|
|
116
|
+
this.removeValidators();
|
|
117
|
+
|
|
118
|
+
// insert new layers for those functions
|
|
119
|
+
if (
|
|
120
|
+
Array.isArray(this.stack) && this.methods && this.path
|
|
121
|
+
&& handles.length){
|
|
122
|
+
Object.keys(this.methods).forEach(
|
|
123
|
+
method => {
|
|
124
|
+
createLayers('validator', method, layerOptions, handles, this.dispatch.bind(this)).forEach(
|
|
125
|
+
layer => {
|
|
126
|
+
// insert 'validator' layers after 'auth' layers
|
|
127
|
+
|
|
128
|
+
var pos = this.stack.length - 1;
|
|
129
|
+
|
|
130
|
+
for (pos; pos > 0; pos -= 1) {
|
|
131
|
+
if (this.stack[pos].type === 'auth' || this.stack[pos].type === 'preValidator') {
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
pos += 1;
|
|
137
|
+
|
|
138
|
+
// insert before
|
|
139
|
+
this.stack.splice(pos, 0, layer);
|
|
140
|
+
}
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
*
|
|
149
|
+
*/
|
|
150
|
+
Route.prototype.hasAuth = function () {
|
|
151
|
+
return this.hasLayerType('auth');
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
*
|
|
156
|
+
*/
|
|
157
|
+
Route.prototype.hasValidators = function () {
|
|
158
|
+
return this.hasLayerType('validator');
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
*
|
|
163
|
+
*/
|
|
164
|
+
Route.prototype.hasPreValidators = function () {
|
|
165
|
+
return this.hasLayerType('preValidator');
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
Route.prototype.hasLayerType = function (type) {
|
|
169
|
+
if (Array.isArray(this.stack)){
|
|
170
|
+
return this.stack.some(
|
|
171
|
+
layer => layer.type === type
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
*
|
|
179
|
+
*/
|
|
180
|
+
Route.prototype.removeAuth = function () {
|
|
181
|
+
this.removeLayerType('auth');
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
*
|
|
186
|
+
*/
|
|
187
|
+
Route.prototype.removeValidators = function () {
|
|
188
|
+
this.removeLayerType('validator');
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
*
|
|
193
|
+
*/
|
|
194
|
+
Route.prototype.removePreValidators = function () {
|
|
195
|
+
this.removeLayerType('preValidator');
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
Route.prototype.removeLayerType = function (type) {
|
|
199
|
+
if (Array.isArray(this.stack)){
|
|
200
|
+
this.stack = this.stack.filter(
|
|
201
|
+
layer => layer.type !== type
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
206
|
module.exports = Route;
|
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
var flatten = require('array-flatten');
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @param {Function[]} args
|
|
5
|
-
*/
|
|
6
|
-
exports.setAuthHandlers = function(){
|
|
7
|
-
var handles = flatten(Array.prototype.slice.call(arguments));
|
|
8
|
-
this._auth = [].concat(handles);
|
|
9
|
-
this._ifNoAuth = false;
|
|
10
|
-
// add layer options
|
|
11
|
-
handles.unshift({
|
|
12
|
-
sensitive: this.caseSensitive,
|
|
13
|
-
strict: this.strict,
|
|
14
|
-
end: true
|
|
15
|
-
});
|
|
16
|
-
this.editLayers('set_auth', handles);
|
|
17
|
-
|
|
18
|
-
return this;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* @param {Function[]} args
|
|
23
|
-
*/
|
|
24
|
-
exports.setAuthHandlersIfNone = function(){
|
|
25
|
-
var handles = flatten(Array.prototype.slice.call(arguments));
|
|
26
|
-
this._auth = [].concat(handles);
|
|
27
|
-
this._ifNoAuth = true;
|
|
28
|
-
// add layer options
|
|
29
|
-
handles.unshift({
|
|
30
|
-
sensitive: this.caseSensitive,
|
|
31
|
-
strict: this.strict,
|
|
32
|
-
end: true
|
|
33
|
-
});
|
|
34
|
-
this.editLayers('set_auth_if_none', handles);
|
|
35
|
-
|
|
36
|
-
return this;
|
|
1
|
+
var { flatten } = require('array-flatten');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {Function[]} args
|
|
5
|
+
*/
|
|
6
|
+
exports.setAuthHandlers = function(){
|
|
7
|
+
var handles = flatten(Array.prototype.slice.call(arguments));
|
|
8
|
+
this._auth = [].concat(handles);
|
|
9
|
+
this._ifNoAuth = false;
|
|
10
|
+
// add layer options
|
|
11
|
+
handles.unshift({
|
|
12
|
+
sensitive: this.caseSensitive,
|
|
13
|
+
strict: this.strict,
|
|
14
|
+
end: true
|
|
15
|
+
});
|
|
16
|
+
this.editLayers('set_auth', handles);
|
|
17
|
+
|
|
18
|
+
return this;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @param {Function[]} args
|
|
23
|
+
*/
|
|
24
|
+
exports.setAuthHandlersIfNone = function(){
|
|
25
|
+
var handles = flatten(Array.prototype.slice.call(arguments));
|
|
26
|
+
this._auth = [].concat(handles);
|
|
27
|
+
this._ifNoAuth = true;
|
|
28
|
+
// add layer options
|
|
29
|
+
handles.unshift({
|
|
30
|
+
sensitive: this.caseSensitive,
|
|
31
|
+
strict: this.strict,
|
|
32
|
+
end: true
|
|
33
|
+
});
|
|
34
|
+
this.editLayers('set_auth_if_none', handles);
|
|
35
|
+
|
|
36
|
+
return this;
|
|
37
37
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
var flatten = require('array-flatten');
|
|
2
|
-
|
|
3
|
-
exports.editLayers = function(method) {
|
|
4
|
-
var args = flatten(Array.prototype.slice.call(arguments, 1));
|
|
5
|
-
this.stack.forEach(
|
|
6
|
-
routerLayer => {
|
|
7
|
-
if (typeof routerLayer[method] === 'function') {
|
|
8
|
-
routerLayer[method].apply(routerLayer, args);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
);
|
|
1
|
+
var { flatten } = require('array-flatten');
|
|
2
|
+
|
|
3
|
+
exports.editLayers = function(method) {
|
|
4
|
+
var args = flatten(Array.prototype.slice.call(arguments, 1));
|
|
5
|
+
this.stack.forEach(
|
|
6
|
+
routerLayer => {
|
|
7
|
+
if (typeof routerLayer[method] === 'function') {
|
|
8
|
+
routerLayer[method].apply(routerLayer, args);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
);
|
|
12
12
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
var flatten = require('array-flatten');
|
|
2
|
-
|
|
3
|
-
exports.getMeta = function() {
|
|
4
|
-
var v = [];
|
|
5
|
-
this.stack.forEach(
|
|
6
|
-
routerLayer => {
|
|
7
|
-
// only layers with method 'get_meta'
|
|
8
|
-
if (typeof routerLayer.get_meta === 'function') {
|
|
9
|
-
v.push.apply(v, flatten(routerLayer.get_meta()));
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
);
|
|
13
|
-
return v;
|
|
1
|
+
var { flatten } = require('array-flatten');
|
|
2
|
+
|
|
3
|
+
exports.getMeta = function() {
|
|
4
|
+
var v = [];
|
|
5
|
+
this.stack.forEach(
|
|
6
|
+
routerLayer => {
|
|
7
|
+
// only layers with method 'get_meta'
|
|
8
|
+
if (typeof routerLayer.get_meta === 'function') {
|
|
9
|
+
v.push.apply(v, flatten(routerLayer.get_meta()));
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
);
|
|
13
|
+
return v;
|
|
14
14
|
}
|
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
var flatten = require('array-flatten');
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @param {Function[]} args
|
|
5
|
-
*/
|
|
6
|
-
exports.setValidators = function(){
|
|
7
|
-
var handles = flatten(Array.prototype.slice.call(arguments));
|
|
8
|
-
this._validators = [].concat(handles);
|
|
9
|
-
this._ifNoValidators = false;
|
|
10
|
-
// add layer options
|
|
11
|
-
handles.unshift({
|
|
12
|
-
sensitive: this.caseSensitive,
|
|
13
|
-
strict: this.strict,
|
|
14
|
-
end: true
|
|
15
|
-
});
|
|
16
|
-
this.editLayers('set_validators', handles);
|
|
17
|
-
|
|
18
|
-
return this;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* @param {Function[]} args
|
|
23
|
-
*/
|
|
24
|
-
exports.setValidatorsIfNone = function(){
|
|
25
|
-
var handles = flatten(Array.prototype.slice.call(arguments));
|
|
26
|
-
this._validatorsIfNone = [].concat(handles);
|
|
27
|
-
this._ifNoValidators = true;
|
|
28
|
-
// add layer options
|
|
29
|
-
handles.unshift({
|
|
30
|
-
sensitive: this.caseSensitive,
|
|
31
|
-
strict: this.strict,
|
|
32
|
-
end: true
|
|
33
|
-
});
|
|
34
|
-
this.editLayers('set_validators_if_none', handles);
|
|
35
|
-
|
|
36
|
-
return this;
|
|
1
|
+
var { flatten } = require('array-flatten');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {Function[]} args
|
|
5
|
+
*/
|
|
6
|
+
exports.setValidators = function(){
|
|
7
|
+
var handles = flatten(Array.prototype.slice.call(arguments));
|
|
8
|
+
this._validators = [].concat(handles);
|
|
9
|
+
this._ifNoValidators = false;
|
|
10
|
+
// add layer options
|
|
11
|
+
handles.unshift({
|
|
12
|
+
sensitive: this.caseSensitive,
|
|
13
|
+
strict: this.strict,
|
|
14
|
+
end: true
|
|
15
|
+
});
|
|
16
|
+
this.editLayers('set_validators', handles);
|
|
17
|
+
|
|
18
|
+
return this;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @param {Function[]} args
|
|
23
|
+
*/
|
|
24
|
+
exports.setValidatorsIfNone = function(){
|
|
25
|
+
var handles = flatten(Array.prototype.slice.call(arguments));
|
|
26
|
+
this._validatorsIfNone = [].concat(handles);
|
|
27
|
+
this._ifNoValidators = true;
|
|
28
|
+
// add layer options
|
|
29
|
+
handles.unshift({
|
|
30
|
+
sensitive: this.caseSensitive,
|
|
31
|
+
strict: this.strict,
|
|
32
|
+
end: true
|
|
33
|
+
});
|
|
34
|
+
this.editLayers('set_validators_if_none', handles);
|
|
35
|
+
|
|
36
|
+
return this;
|
|
37
37
|
}
|