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