te.js 1.3.0 → 1.3.1
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 +1 -1
- package/server/targets/registry.js +57 -55
package/package.json
CHANGED
|
@@ -1,55 +1,57 @@
|
|
|
1
|
-
import isMiddlewareValid from './middleware-validator.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
this.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
1
|
+
import isMiddlewareValid from './middleware-validator.js';
|
|
2
|
+
import { standardizePath } from './path-validator.js';
|
|
3
|
+
|
|
4
|
+
class TargetRegistry {
|
|
5
|
+
constructor() {
|
|
6
|
+
if (TargetRegistry.instance) {
|
|
7
|
+
return TargetRegistry.instance;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
TargetRegistry.instance = this;
|
|
11
|
+
|
|
12
|
+
// TODO - Add a default target
|
|
13
|
+
this.targets = [];
|
|
14
|
+
this.globalMiddlewares = [];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
addGlobalMiddleware() {
|
|
18
|
+
if (!arguments) return;
|
|
19
|
+
|
|
20
|
+
const middlewares = [...arguments];
|
|
21
|
+
const validMiddlewares = middlewares.filter(isMiddlewareValid);
|
|
22
|
+
this.globalMiddlewares = this.globalMiddlewares.concat(validMiddlewares);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @param {Array || Object} targets
|
|
27
|
+
*/
|
|
28
|
+
register(targets) {
|
|
29
|
+
if (Array.isArray(targets)) {
|
|
30
|
+
this.targets = this.targets.concat(targets);
|
|
31
|
+
} else {
|
|
32
|
+
this.targets.push(targets);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
aim(endpoint) {
|
|
37
|
+
return this.targets.find((target) => {
|
|
38
|
+
const standardizedEndpoint = standardizePath(endpoint);
|
|
39
|
+
return target.getPath() === standardizedEndpoint;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
getAllEndpoints(grouped) {
|
|
44
|
+
if (grouped) {
|
|
45
|
+
return this.targets.reduce((acc, target) => {
|
|
46
|
+
const group = target.getPath().split('/')[1];
|
|
47
|
+
if (!acc[group]) acc[group] = [];
|
|
48
|
+
acc[group].push(target.getPath());
|
|
49
|
+
return acc;
|
|
50
|
+
}, {});
|
|
51
|
+
} else {
|
|
52
|
+
return this.targets.map((target) => target.getPath());
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export default TargetRegistry;
|