@e22m4u/ts-rest-router 0.3.0 → 0.4.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.
@@ -607,9 +607,9 @@ __name(httpResponse, "httpResponse");
607
607
  var import_ts_data_schema4 = require("@e22m4u/ts-data-schema");
608
608
  var _ControllerRegistry = class _ControllerRegistry extends DebuggableService {
609
609
  /**
610
- * Controllers.
610
+ * Controller map.
611
611
  */
612
- controllers = /* @__PURE__ */ new Set();
612
+ controllerMap = /* @__PURE__ */ new Map();
613
613
  /**
614
614
  * Add controller.
615
615
  *
@@ -672,7 +672,7 @@ var _ControllerRegistry = class _ControllerRegistry extends DebuggableService {
672
672
  });
673
673
  debug("Route %s %v is added.", actionMd.method.toUpperCase(), prefixedRoutePath);
674
674
  });
675
- this.controllers.add(ctor);
675
+ this.controllerMap.set(ctor, options);
676
676
  return this;
677
677
  }
678
678
  /**
@@ -681,7 +681,7 @@ var _ControllerRegistry = class _ControllerRegistry extends DebuggableService {
681
681
  * @param ctor
682
682
  */
683
683
  hasController(ctor) {
684
- return this.controllers.has(ctor);
684
+ return this.controllerMap.has(ctor);
685
685
  }
686
686
  /**
687
687
  * Get path prefix from controller root options.
@@ -11,14 +11,20 @@ export type ControllerRootOptions = {
11
11
  before?: RoutePreHandler | RoutePreHandler[];
12
12
  after?: RoutePostHandler | RoutePostHandler[];
13
13
  };
14
+ /**
15
+ * В данном Map ключом является контроллер, а значением
16
+ * его опции верхнего уровня, которые могут отсутствовать,
17
+ * если пользователь их не определил.
18
+ */
19
+ export type ControllerRootOptionsMap = Map<Constructor<object>, ControllerRootOptions | undefined>;
14
20
  /**
15
21
  * Controller registry.
16
22
  */
17
23
  export declare class ControllerRegistry extends DebuggableService {
18
24
  /**
19
- * Controllers.
25
+ * Controller map.
20
26
  */
21
- controllers: Set<Constructor<object>>;
27
+ controllerMap: ControllerRootOptionsMap;
22
28
  /**
23
29
  * Add controller.
24
30
  *
@@ -17,9 +17,9 @@ import { RequestContextReflector } from './decorators/index.js';
17
17
  */
18
18
  export class ControllerRegistry extends DebuggableService {
19
19
  /**
20
- * Controllers.
20
+ * Controller map.
21
21
  */
22
- controllers = new Set();
22
+ controllerMap = new Map();
23
23
  /**
24
24
  * Add controller.
25
25
  *
@@ -100,7 +100,7 @@ export class ControllerRegistry extends DebuggableService {
100
100
  });
101
101
  debug('Route %s %v is added.', actionMd.method.toUpperCase(), prefixedRoutePath);
102
102
  });
103
- this.controllers.add(ctor);
103
+ this.controllerMap.set(ctor, options);
104
104
  return this;
105
105
  }
106
106
  /**
@@ -109,7 +109,7 @@ export class ControllerRegistry extends DebuggableService {
109
109
  * @param ctor
110
110
  */
111
111
  hasController(ctor) {
112
- return this.controllers.has(ctor);
112
+ return this.controllerMap.has(ctor);
113
113
  }
114
114
  /**
115
115
  * Get path prefix from controller root options.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e22m4u/ts-rest-router",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
4
4
  "description": "REST маршрутизатор на основе контроллеров для TypeScript",
5
5
  "author": "e22m4u <e22m4u@yandex.ru>",
6
6
  "license": "MIT",
@@ -42,10 +42,11 @@ const POST_HANDLER_1 = () => undefined;
42
42
  const POST_HANDLER_2 = () => undefined;
43
43
 
44
44
  describe('ControllerRegistry', function () {
45
- it('has a public property with set of controllers', function () {
45
+ it('has a public property `controllerMap` with an empty Map', function () {
46
46
  const S = new ControllerRegistry();
47
- expect(S).to.have.property('controllers');
48
- expect(S.controllers).to.be.instanceof(Set);
47
+ expect(S).to.have.property('controllerMap');
48
+ expect(S.controllerMap).to.be.instanceof(Map);
49
+ expect(S.controllerMap).to.be.empty;
49
50
  });
50
51
 
51
52
  describe('addController', function () {
@@ -57,7 +58,7 @@ describe('ControllerRegistry', function () {
57
58
  expect(res).to.be.eq(S);
58
59
  });
59
60
 
60
- it('adds a given controller to controllers set', function () {
61
+ it('adds a given controller to controllers map', function () {
61
62
  const S = new ControllerRegistry();
62
63
  @restController()
63
64
  class MyController {}
@@ -28,14 +28,24 @@ export type ControllerRootOptions = {
28
28
  after?: RoutePostHandler | RoutePostHandler[];
29
29
  };
30
30
 
31
+ /**
32
+ * В данном Map ключом является контроллер, а значением
33
+ * его опции верхнего уровня, которые могут отсутствовать,
34
+ * если пользователь их не определил.
35
+ */
36
+ export type ControllerRootOptionsMap = Map<
37
+ Constructor<object>,
38
+ ControllerRootOptions | undefined
39
+ >;
40
+
31
41
  /**
32
42
  * Controller registry.
33
43
  */
34
44
  export class ControllerRegistry extends DebuggableService {
35
45
  /**
36
- * Controllers.
46
+ * Controller map.
37
47
  */
38
- controllers: Set<Constructor<object>> = new Set();
48
+ controllerMap: ControllerRootOptionsMap = new Map();
39
49
 
40
50
  /**
41
51
  * Add controller.
@@ -123,7 +133,7 @@ export class ControllerRegistry extends DebuggableService {
123
133
  prefixedRoutePath,
124
134
  );
125
135
  });
126
- this.controllers.add(ctor);
136
+ this.controllerMap.set(ctor, options);
127
137
  return this;
128
138
  }
129
139
 
@@ -133,7 +143,7 @@ export class ControllerRegistry extends DebuggableService {
133
143
  * @param ctor
134
144
  */
135
145
  hasController<T extends object>(ctor: Constructor<T>) {
136
- return this.controllers.has(ctor);
146
+ return this.controllerMap.has(ctor);
137
147
  }
138
148
 
139
149
  /**