@e22m4u/ts-rest-router 0.1.2 → 0.2.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.
Files changed (145) hide show
  1. package/README.md +171 -74
  2. package/dist/cjs/index.cjs +352 -362
  3. package/dist/esm/controller-registry.js +37 -32
  4. package/dist/esm/debuggable-service.d.ts +10 -1
  5. package/dist/esm/debuggable-service.js +14 -3
  6. package/dist/esm/decorators/after-action/after-action-decorator.d.ts +9 -0
  7. package/dist/esm/decorators/{before/before-decorator.js → after-action/after-action-decorator.js} +7 -7
  8. package/dist/esm/decorators/{before/before-decorator.spec.js → after-action/after-action-decorator.spec.js} +19 -19
  9. package/dist/esm/decorators/{after/after-metadata.d.ts → after-action/after-action-metadata.d.ts} +4 -4
  10. package/dist/esm/decorators/after-action/after-action-metadata.js +5 -0
  11. package/dist/esm/decorators/{after/after-reflector.d.ts → after-action/after-action-reflector.d.ts} +5 -5
  12. package/dist/esm/decorators/{after/after-reflector.js → after-action/after-action-reflector.js} +6 -6
  13. package/dist/esm/decorators/{before/before-reflector.spec.js → after-action/after-action-reflector.spec.js} +23 -24
  14. package/dist/esm/decorators/after-action/index.d.ts +3 -0
  15. package/dist/esm/decorators/after-action/index.js +3 -0
  16. package/dist/esm/decorators/before-action/before-action-decorator.d.ts +9 -0
  17. package/dist/esm/decorators/{after/after-decorator.js → before-action/before-action-decorator.js} +7 -7
  18. package/dist/esm/decorators/{after/after-decorator.spec.js → before-action/before-action-decorator.spec.js} +19 -19
  19. package/dist/esm/decorators/{before/before-metadata.d.ts → before-action/before-action-metadata.d.ts} +4 -4
  20. package/dist/esm/decorators/before-action/before-action-metadata.js +5 -0
  21. package/dist/esm/decorators/{before/before-reflector.d.ts → before-action/before-action-reflector.d.ts} +5 -5
  22. package/dist/esm/decorators/{before/before-reflector.js → before-action/before-action-reflector.js} +6 -6
  23. package/dist/esm/decorators/{after/after-reflector.spec.js → before-action/before-action-reflector.spec.js} +23 -24
  24. package/dist/esm/decorators/before-action/index.d.ts +3 -0
  25. package/dist/esm/decorators/before-action/index.js +3 -0
  26. package/dist/esm/decorators/index.d.ts +4 -4
  27. package/dist/esm/decorators/index.js +4 -4
  28. package/dist/esm/decorators/request-context/request-context-decorator.d.ts +4 -4
  29. package/dist/esm/decorators/request-context/request-context-decorator.js +4 -4
  30. package/dist/esm/decorators/request-context/request-context-decorator.spec.js +6 -0
  31. package/dist/esm/decorators/request-context/request-context-reflector.spec.js +0 -1
  32. package/dist/esm/decorators/request-data/request-data-decorator.d.ts +10 -10
  33. package/dist/esm/decorators/request-data/request-data-decorator.js +10 -10
  34. package/dist/esm/decorators/request-data/request-data-decorator.spec.js +44 -32
  35. package/dist/esm/decorators/request-data/request-data-metadata.d.ts +1 -1
  36. package/dist/esm/decorators/request-data/request-data-reflector.spec.js +0 -1
  37. package/dist/esm/decorators/rest-action/index.d.ts +3 -0
  38. package/dist/esm/decorators/rest-action/index.js +3 -0
  39. package/dist/esm/decorators/rest-action/rest-action-decorator.d.ts +57 -0
  40. package/dist/esm/decorators/rest-action/rest-action-decorator.js +52 -0
  41. package/dist/esm/decorators/rest-action/rest-action-decorator.spec.js +401 -0
  42. package/dist/esm/decorators/{action/action-metadata.d.ts → rest-action/rest-action-metadata.d.ts} +6 -6
  43. package/dist/esm/decorators/rest-action/rest-action-metadata.js +5 -0
  44. package/dist/esm/decorators/rest-action/rest-action-reflector.d.ts +22 -0
  45. package/dist/esm/decorators/{action/action-reflector.js → rest-action/rest-action-reflector.js} +6 -6
  46. package/dist/esm/decorators/{action/action-reflector.spec.js → rest-action/rest-action-reflector.spec.js} +13 -14
  47. package/dist/esm/decorators/rest-controller/index.d.ts +3 -0
  48. package/dist/esm/decorators/rest-controller/index.js +3 -0
  49. package/dist/esm/decorators/rest-controller/rest-controller-decorator.d.ts +14 -0
  50. package/dist/esm/decorators/{controller/controller-decorator.js → rest-controller/rest-controller-decorator.js} +5 -5
  51. package/dist/esm/decorators/{controller/controller-decorator.spec.js → rest-controller/rest-controller-decorator.spec.js} +15 -15
  52. package/dist/esm/decorators/{controller/controller-metadata.d.ts → rest-controller/rest-controller-metadata.d.ts} +5 -5
  53. package/dist/esm/decorators/rest-controller/rest-controller-metadata.js +5 -0
  54. package/dist/esm/decorators/rest-controller/rest-controller-reflector.d.ts +20 -0
  55. package/dist/esm/decorators/rest-controller/rest-controller-reflector.js +24 -0
  56. package/dist/esm/decorators/{controller/controller-reflector.spec.js → rest-controller/rest-controller-reflector.spec.js} +12 -13
  57. package/dist/esm/errors/not-a-controller-error.js +1 -1
  58. package/dist/esm/types.d.ts +0 -10
  59. package/dist/esm/utils/index.d.ts +0 -1
  60. package/dist/esm/utils/index.js +0 -1
  61. package/eslint.config.js +1 -1
  62. package/package.json +15 -15
  63. package/src/controller-registry.spec.ts +192 -134
  64. package/src/controller-registry.ts +46 -39
  65. package/src/debuggable-service.spec.ts +0 -1
  66. package/src/debuggable-service.ts +17 -4
  67. package/src/decorators/{before/before-decorator.spec.ts → after-action/after-action-decorator.spec.ts} +19 -19
  68. package/src/decorators/{before/before-decorator.ts → after-action/after-action-decorator.ts} +9 -9
  69. package/src/decorators/{after/after-metadata.ts → after-action/after-action-metadata.ts} +5 -5
  70. package/src/decorators/{before/before-reflector.spec.ts → after-action/after-action-reflector.spec.ts} +33 -24
  71. package/src/decorators/{before/before-reflector.ts → after-action/after-action-reflector.ts} +13 -9
  72. package/src/decorators/after-action/index.ts +3 -0
  73. package/src/decorators/{after/after-decorator.spec.ts → before-action/before-action-decorator.spec.ts} +19 -19
  74. package/src/decorators/{after/after-decorator.ts → before-action/before-action-decorator.ts} +9 -9
  75. package/src/decorators/before-action/before-action-metadata.ts +17 -0
  76. package/src/decorators/{after/after-reflector.spec.ts → before-action/before-action-reflector.spec.ts} +40 -24
  77. package/src/decorators/{after/after-reflector.ts → before-action/before-action-reflector.ts} +18 -9
  78. package/src/decorators/before-action/index.ts +3 -0
  79. package/src/decorators/index.ts +4 -4
  80. package/src/decorators/request-context/request-context-decorator.spec.ts +7 -0
  81. package/src/decorators/request-context/request-context-decorator.ts +4 -4
  82. package/src/decorators/request-context/request-context-reflector.spec.ts +0 -1
  83. package/src/decorators/request-data/request-data-decorator.spec.ts +45 -32
  84. package/src/decorators/request-data/request-data-decorator.ts +10 -10
  85. package/src/decorators/request-data/request-data-metadata.ts +1 -1
  86. package/src/decorators/request-data/request-data-reflector.spec.ts +0 -1
  87. package/src/decorators/rest-action/index.ts +3 -0
  88. package/src/decorators/rest-action/rest-action-decorator.spec.ts +325 -0
  89. package/src/decorators/rest-action/rest-action-decorator.ts +166 -0
  90. package/src/decorators/{action/action-metadata.ts → rest-action/rest-action-metadata.ts} +7 -7
  91. package/src/decorators/{action/action-reflector.spec.ts → rest-action/rest-action-reflector.spec.ts} +13 -14
  92. package/src/decorators/rest-action/rest-action-reflector.ts +41 -0
  93. package/src/decorators/rest-controller/index.ts +3 -0
  94. package/src/decorators/{controller/controller-decorator.spec.ts → rest-controller/rest-controller-decorator.spec.ts} +16 -16
  95. package/src/decorators/{controller/controller-decorator.ts → rest-controller/rest-controller-decorator.ts} +14 -10
  96. package/src/decorators/{controller/controller-metadata.ts → rest-controller/rest-controller-metadata.ts} +6 -7
  97. package/src/decorators/{controller/controller-reflector.spec.ts → rest-controller/rest-controller-reflector.spec.ts} +21 -13
  98. package/src/decorators/rest-controller/rest-controller-reflector.ts +32 -0
  99. package/src/errors/not-a-controller-error.ts +4 -1
  100. package/src/types.ts +0 -10
  101. package/src/utils/index.ts +0 -1
  102. package/dist/esm/decorators/action/action-decorator.d.ts +0 -52
  103. package/dist/esm/decorators/action/action-decorator.js +0 -62
  104. package/dist/esm/decorators/action/action-decorator.spec.js +0 -59
  105. package/dist/esm/decorators/action/action-metadata.js +0 -5
  106. package/dist/esm/decorators/action/action-reflector.d.ts +0 -22
  107. package/dist/esm/decorators/action/index.d.ts +0 -3
  108. package/dist/esm/decorators/action/index.js +0 -3
  109. package/dist/esm/decorators/after/after-decorator.d.ts +0 -9
  110. package/dist/esm/decorators/after/after-metadata.js +0 -5
  111. package/dist/esm/decorators/after/index.d.ts +0 -3
  112. package/dist/esm/decorators/after/index.js +0 -3
  113. package/dist/esm/decorators/before/before-decorator.d.ts +0 -9
  114. package/dist/esm/decorators/before/before-metadata.js +0 -5
  115. package/dist/esm/decorators/before/index.d.ts +0 -3
  116. package/dist/esm/decorators/before/index.js +0 -3
  117. package/dist/esm/decorators/controller/controller-decorator.d.ts +0 -14
  118. package/dist/esm/decorators/controller/controller-metadata.js +0 -5
  119. package/dist/esm/decorators/controller/controller-reflector.d.ts +0 -20
  120. package/dist/esm/decorators/controller/controller-reflector.js +0 -24
  121. package/dist/esm/decorators/controller/index.d.ts +0 -3
  122. package/dist/esm/decorators/controller/index.js +0 -3
  123. package/dist/esm/utils/create-debugger.d.ts +0 -44
  124. package/dist/esm/utils/create-debugger.js +0 -81
  125. package/dist/esm/utils/create-debugger.spec.d.ts +0 -1
  126. package/dist/esm/utils/create-debugger.spec.js +0 -8
  127. package/src/decorators/action/action-decorator.spec.ts +0 -42
  128. package/src/decorators/action/action-decorator.ts +0 -98
  129. package/src/decorators/action/action-reflector.ts +0 -38
  130. package/src/decorators/action/index.ts +0 -3
  131. package/src/decorators/after/index.ts +0 -3
  132. package/src/decorators/before/before-metadata.ts +0 -17
  133. package/src/decorators/before/index.ts +0 -3
  134. package/src/decorators/controller/controller-reflector.ts +0 -28
  135. package/src/decorators/controller/index.ts +0 -3
  136. package/src/utils/create-debugger.spec.ts +0 -9
  137. package/src/utils/create-debugger.ts +0 -98
  138. /package/dist/esm/decorators/{action/action-decorator.spec.d.ts → after-action/after-action-decorator.spec.d.ts} +0 -0
  139. /package/dist/esm/decorators/{action/action-reflector.spec.d.ts → after-action/after-action-reflector.spec.d.ts} +0 -0
  140. /package/dist/esm/decorators/{after/after-decorator.spec.d.ts → before-action/before-action-decorator.spec.d.ts} +0 -0
  141. /package/dist/esm/decorators/{after/after-reflector.spec.d.ts → before-action/before-action-reflector.spec.d.ts} +0 -0
  142. /package/dist/esm/decorators/{before/before-decorator.spec.d.ts → rest-action/rest-action-decorator.spec.d.ts} +0 -0
  143. /package/dist/esm/decorators/{before/before-reflector.spec.d.ts → rest-action/rest-action-reflector.spec.d.ts} +0 -0
  144. /package/dist/esm/decorators/{controller/controller-decorator.spec.d.ts → rest-controller/rest-controller-decorator.spec.d.ts} +0 -0
  145. /package/dist/esm/decorators/{controller/controller-reflector.spec.d.ts → rest-controller/rest-controller-reflector.spec.d.ts} +0 -0
@@ -1,32 +1,38 @@
1
1
  /* eslint mocha/no-sibling-hooks: 0 */
2
+ import {
3
+ createRequestMock,
4
+ createResponseMock,
5
+ HookName,
6
+ HttpMethod,
7
+ ParsedCookie,
8
+ ParsedHeaders,
9
+ ParsedParams,
10
+ ParsedQuery,
11
+ RequestContext,
12
+ RequestParser,
13
+ RouteRegistry,
14
+ TrieRouter,
15
+ } from '@e22m4u/js-trie-router';
16
+ import {
17
+ afterAction,
18
+ beforeAction,
19
+ getAction,
20
+ postAction,
21
+ requestBody,
22
+ requestCookie,
23
+ requestCookies,
24
+ requestField,
25
+ requestHeader,
26
+ requestHeaders,
27
+ requestParam,
28
+ requestParams,
29
+ requestQueries,
30
+ requestQuery,
31
+ restController,
32
+ } from './decorators/index.js';
33
+
2
34
  import {expect} from 'chai';
3
- import {get} from './decorators/index.js';
4
- import {post} from './decorators/index.js';
5
- import {body} from './decorators/index.js';
6
- import {after} from './decorators/index.js';
7
- import {query} from './decorators/index.js';
8
- import {param} from './decorators/index.js';
9
- import {field} from './decorators/index.js';
10
- import {cookie} from './decorators/index.js';
11
- import {params} from './decorators/index.js';
12
- import {before} from './decorators/index.js';
13
- import {header} from './decorators/index.js';
14
- import {cookies} from './decorators/index.js';
15
- import {queries} from './decorators/index.js';
16
- import {headers} from './decorators/index.js';
17
- import {HookName} from '@e22m4u/js-trie-router';
18
- import {controller} from './decorators/index.js';
19
- import {TrieRouter} from '@e22m4u/js-trie-router';
20
- import {HttpMethod} from '@e22m4u/js-trie-router';
21
- import {ParsedQuery} from '@e22m4u/js-trie-router';
22
- import {ParsedCookie} from '@e22m4u/js-trie-router';
23
- import {ParsedParams} from '@e22m4u/js-trie-router';
24
- import {ParsedHeaders} from '@e22m4u/js-trie-router';
25
- import {RouteRegistry} from '@e22m4u/js-trie-router';
26
- import {RequestParser} from '@e22m4u/js-trie-router';
27
- import {RequestContext} from '@e22m4u/js-trie-router';
28
- import {createRequestMock} from '@e22m4u/js-trie-router';
29
- import {createResponseMock} from '@e22m4u/js-trie-router';
35
+ import {DataType} from '@e22m4u/ts-data-schema';
30
36
  import {ControllerRegistry} from './controller-registry.js';
31
37
 
32
38
  const PRE_HANDLER_1 = () => undefined;
@@ -45,7 +51,7 @@ describe('ControllerRegistry', function () {
45
51
  describe('addController', function () {
46
52
  it('returns itself', function () {
47
53
  const S = new ControllerRegistry();
48
- @controller()
54
+ @restController()
49
55
  class MyController {}
50
56
  const res = S.addController(MyController);
51
57
  expect(res).to.be.eq(S);
@@ -53,7 +59,7 @@ describe('ControllerRegistry', function () {
53
59
 
54
60
  it('adds a given controller to controllers set', function () {
55
61
  const S = new ControllerRegistry();
56
- @controller()
62
+ @restController()
57
63
  class MyController {}
58
64
  expect(S.hasController(MyController)).to.be.false;
59
65
  S.addController(MyController);
@@ -62,9 +68,9 @@ describe('ControllerRegistry', function () {
62
68
 
63
69
  it('uses http method and action path for a new route', function () {
64
70
  const S = new ControllerRegistry();
65
- @controller()
71
+ @restController()
66
72
  class MyController {
67
- @get('/myAction')
73
+ @getAction('/myAction')
68
74
  foo() {}
69
75
  }
70
76
  S.addController(MyController);
@@ -81,11 +87,11 @@ describe('ControllerRegistry', function () {
81
87
 
82
88
  it('adds multiple routes by the given controller', function () {
83
89
  const S = new ControllerRegistry();
84
- @controller()
90
+ @restController()
85
91
  class MyController {
86
- @get('/foo')
92
+ @getAction('/foo')
87
93
  foo() {}
88
- @post('/bar')
94
+ @postAction('/bar')
89
95
  bar() {}
90
96
  }
91
97
  S.addController(MyController);
@@ -106,9 +112,9 @@ describe('ControllerRegistry', function () {
106
112
 
107
113
  it('uses path prefix of controller root options', function () {
108
114
  const S = new ControllerRegistry();
109
- @controller()
115
+ @restController()
110
116
  class MyController {
111
- @get('/myAction')
117
+ @getAction('/myAction')
112
118
  myAction() {}
113
119
  }
114
120
  S.addController(MyController, {pathPrefix: '/myPrefix'});
@@ -121,11 +127,11 @@ describe('ControllerRegistry', function () {
121
127
  expect(matching).to.be.not.empty;
122
128
  });
123
129
 
124
- it('uses path prefix of @controller metadata', function () {
130
+ it('uses path prefix of @restController metadata', function () {
125
131
  const S = new ControllerRegistry();
126
- @controller('/myController')
132
+ @restController('/myController')
127
133
  class MyController {
128
- @get('/myAction')
134
+ @getAction('/myAction')
129
135
  myAction() {}
130
136
  }
131
137
  S.addController(MyController);
@@ -138,11 +144,11 @@ describe('ControllerRegistry', function () {
138
144
  expect(matching).to.be.not.empty;
139
145
  });
140
146
 
141
- it('uses path prefix of controller root options and @controller metadata', function () {
147
+ it('uses path prefix of controller root options and @restController metadata', function () {
142
148
  const S = new ControllerRegistry();
143
- @controller('/myController')
149
+ @restController('/myController')
144
150
  class MyController {
145
- @get('/myAction')
151
+ @getAction('/myAction')
146
152
  myAction() {}
147
153
  }
148
154
  S.addController(MyController, {pathPrefix: '/myPrefix'});
@@ -158,9 +164,9 @@ describe('ControllerRegistry', function () {
158
164
  describe('single pre-handler', function () {
159
165
  it('uses pre-handler of controller root options', function () {
160
166
  const S = new ControllerRegistry();
161
- @controller()
167
+ @restController()
162
168
  class MyController {
163
- @get('/myAction')
169
+ @getAction('/myAction')
164
170
  myAction() {}
165
171
  }
166
172
  S.addController(MyController, {before: PRE_HANDLER_1});
@@ -175,12 +181,12 @@ describe('ControllerRegistry', function () {
175
181
  expect(res).to.be.eql([PRE_HANDLER_1]);
176
182
  });
177
183
 
178
- it('uses pre-handler of @before metadata applied to controller', function () {
184
+ it('uses pre-handler of @beforeAction metadata applied to controller', function () {
179
185
  const S = new ControllerRegistry();
180
- @controller()
181
- @before(PRE_HANDLER_1)
186
+ @restController()
187
+ @beforeAction(PRE_HANDLER_1)
182
188
  class MyController {
183
- @get('/myAction')
189
+ @getAction('/myAction')
184
190
  myAction() {}
185
191
  }
186
192
  S.addController(MyController);
@@ -195,12 +201,12 @@ describe('ControllerRegistry', function () {
195
201
  expect(res).to.be.eql([PRE_HANDLER_1]);
196
202
  });
197
203
 
198
- it('uses pre-handler of @before metadata applied to action', function () {
204
+ it('uses pre-handler of @beforeAction metadata applied to action', function () {
199
205
  const S = new ControllerRegistry();
200
- @controller()
206
+ @restController()
201
207
  class MyController {
202
- @get('/myAction')
203
- @before(PRE_HANDLER_1)
208
+ @getAction('/myAction')
209
+ @beforeAction(PRE_HANDLER_1)
204
210
  myAction() {}
205
211
  }
206
212
  S.addController(MyController);
@@ -215,11 +221,11 @@ describe('ControllerRegistry', function () {
215
221
  expect(res).to.be.eql([PRE_HANDLER_1]);
216
222
  });
217
223
 
218
- it('uses pre-handler of @controller metadata', function () {
224
+ it('uses pre-handler of @restController metadata', function () {
219
225
  const S = new ControllerRegistry();
220
- @controller({before: PRE_HANDLER_1})
226
+ @restController({before: PRE_HANDLER_1})
221
227
  class MyController {
222
- @get('/myAction')
228
+ @getAction('/myAction')
223
229
  myAction() {}
224
230
  }
225
231
  S.addController(MyController);
@@ -236,9 +242,9 @@ describe('ControllerRegistry', function () {
236
242
 
237
243
  it('uses pre-handler of @action metadata', function () {
238
244
  const S = new ControllerRegistry();
239
- @controller()
245
+ @restController()
240
246
  class MyController {
241
- @get('/myAction', {before: PRE_HANDLER_1})
247
+ @getAction('/myAction', {before: PRE_HANDLER_1})
242
248
  myAction() {}
243
249
  }
244
250
  S.addController(MyController);
@@ -257,9 +263,9 @@ describe('ControllerRegistry', function () {
257
263
  describe('multiple pre-handlers', function () {
258
264
  it('uses pre-handlers of controller root options', function () {
259
265
  const S = new ControllerRegistry();
260
- @controller()
266
+ @restController()
261
267
  class MyController {
262
- @get('/myAction')
268
+ @getAction('/myAction')
263
269
  myAction() {}
264
270
  }
265
271
  S.addController(MyController, {
@@ -276,12 +282,12 @@ describe('ControllerRegistry', function () {
276
282
  expect(res).to.be.eql([PRE_HANDLER_1, PRE_HANDLER_2]);
277
283
  });
278
284
 
279
- it('uses pre-handlers of @before metadata applied to controller', function () {
285
+ it('uses pre-handlers of @beforeAction metadata applied to controller', function () {
280
286
  const S = new ControllerRegistry();
281
- @controller()
282
- @before([PRE_HANDLER_1, PRE_HANDLER_2])
287
+ @restController()
288
+ @beforeAction([PRE_HANDLER_1, PRE_HANDLER_2])
283
289
  class MyController {
284
- @get('/myAction')
290
+ @getAction('/myAction')
285
291
  myAction() {}
286
292
  }
287
293
  S.addController(MyController);
@@ -296,12 +302,12 @@ describe('ControllerRegistry', function () {
296
302
  expect(res).to.be.eql([PRE_HANDLER_1, PRE_HANDLER_2]);
297
303
  });
298
304
 
299
- it('uses pre-handlers of @before metadata applied to action', function () {
305
+ it('uses pre-handlers of @beforeAction metadata applied to action', function () {
300
306
  const S = new ControllerRegistry();
301
- @controller()
307
+ @restController()
302
308
  class MyController {
303
- @get('/myAction')
304
- @before([PRE_HANDLER_1, PRE_HANDLER_2])
309
+ @getAction('/myAction')
310
+ @beforeAction([PRE_HANDLER_1, PRE_HANDLER_2])
305
311
  myAction() {}
306
312
  }
307
313
  S.addController(MyController);
@@ -316,13 +322,13 @@ describe('ControllerRegistry', function () {
316
322
  expect(res).to.be.eql([PRE_HANDLER_1, PRE_HANDLER_2]);
317
323
  });
318
324
 
319
- it('uses pre-handlers of @controller metadata', function () {
325
+ it('uses pre-handlers of @restController metadata', function () {
320
326
  const S = new ControllerRegistry();
321
- @controller({
327
+ @restController({
322
328
  before: [PRE_HANDLER_1, PRE_HANDLER_2],
323
329
  })
324
330
  class MyController {
325
- @get('/myAction')
331
+ @getAction('/myAction')
326
332
  myAction() {}
327
333
  }
328
334
  S.addController(MyController);
@@ -339,9 +345,9 @@ describe('ControllerRegistry', function () {
339
345
 
340
346
  it('uses pre-handlers of @action metadata', function () {
341
347
  const S = new ControllerRegistry();
342
- @controller()
348
+ @restController()
343
349
  class MyController {
344
- @get('/myAction', {
350
+ @getAction('/myAction', {
345
351
  before: [PRE_HANDLER_1, PRE_HANDLER_2],
346
352
  })
347
353
  myAction() {}
@@ -362,9 +368,9 @@ describe('ControllerRegistry', function () {
362
368
  describe('single post-handler', function () {
363
369
  it('uses post-handler of controller root options', function () {
364
370
  const S = new ControllerRegistry();
365
- @controller()
371
+ @restController()
366
372
  class MyController {
367
- @get('/myAction')
373
+ @getAction('/myAction')
368
374
  myAction() {}
369
375
  }
370
376
  S.addController(MyController, {after: POST_HANDLER_1});
@@ -381,12 +387,12 @@ describe('ControllerRegistry', function () {
381
387
  expect(res).to.be.eql([POST_HANDLER_1]);
382
388
  });
383
389
 
384
- it('uses pre-handler of @after metadata applied to controller', function () {
390
+ it('uses pre-handler of @afterAction metadata applied to controller', function () {
385
391
  const S = new ControllerRegistry();
386
- @controller()
387
- @after(POST_HANDLER_1)
392
+ @restController()
393
+ @afterAction(POST_HANDLER_1)
388
394
  class MyController {
389
- @get('/myAction')
395
+ @getAction('/myAction')
390
396
  myAction() {}
391
397
  }
392
398
  S.addController(MyController);
@@ -403,12 +409,12 @@ describe('ControllerRegistry', function () {
403
409
  expect(res).to.be.eql([POST_HANDLER_1]);
404
410
  });
405
411
 
406
- it('uses pre-handler of @after metadata applied to action', function () {
412
+ it('uses pre-handler of @afterAction metadata applied to action', function () {
407
413
  const S = new ControllerRegistry();
408
- @controller()
414
+ @restController()
409
415
  class MyController {
410
- @get('/myAction')
411
- @after(POST_HANDLER_1)
416
+ @getAction('/myAction')
417
+ @afterAction(POST_HANDLER_1)
412
418
  myAction() {}
413
419
  }
414
420
  S.addController(MyController);
@@ -425,11 +431,11 @@ describe('ControllerRegistry', function () {
425
431
  expect(res).to.be.eql([POST_HANDLER_1]);
426
432
  });
427
433
 
428
- it('uses post-handler of @controller metadata', function () {
434
+ it('uses post-handler of @restController metadata', function () {
429
435
  const S = new ControllerRegistry();
430
- @controller({after: POST_HANDLER_1})
436
+ @restController({after: POST_HANDLER_1})
431
437
  class MyController {
432
- @get('/myAction')
438
+ @getAction('/myAction')
433
439
  myAction() {}
434
440
  }
435
441
  S.addController(MyController);
@@ -448,9 +454,9 @@ describe('ControllerRegistry', function () {
448
454
 
449
455
  it('uses post-handler of @action metadata', function () {
450
456
  const S = new ControllerRegistry();
451
- @controller()
457
+ @restController()
452
458
  class MyController {
453
- @get('/myAction', {after: POST_HANDLER_1})
459
+ @getAction('/myAction', {after: POST_HANDLER_1})
454
460
  myAction() {}
455
461
  }
456
462
  S.addController(MyController);
@@ -471,9 +477,9 @@ describe('ControllerRegistry', function () {
471
477
  describe('multiple post-handlers', function () {
472
478
  it('uses post-handlers of controller root options', function () {
473
479
  const S = new ControllerRegistry();
474
- @controller()
480
+ @restController()
475
481
  class MyController {
476
- @get('/myAction')
482
+ @getAction('/myAction')
477
483
  myAction() {}
478
484
  }
479
485
  S.addController(MyController, {
@@ -492,12 +498,12 @@ describe('ControllerRegistry', function () {
492
498
  expect(res).to.be.eql([POST_HANDLER_1, POST_HANDLER_2]);
493
499
  });
494
500
 
495
- it('uses pre-handlers of @after metadata applied to controller', function () {
501
+ it('uses pre-handlers of @afterAction metadata applied to controller', function () {
496
502
  const S = new ControllerRegistry();
497
- @controller()
498
- @after([POST_HANDLER_1, POST_HANDLER_2])
503
+ @restController()
504
+ @afterAction([POST_HANDLER_1, POST_HANDLER_2])
499
505
  class MyController {
500
- @get('/myAction')
506
+ @getAction('/myAction')
501
507
  myAction() {}
502
508
  }
503
509
  S.addController(MyController);
@@ -514,12 +520,12 @@ describe('ControllerRegistry', function () {
514
520
  expect(res).to.be.eql([POST_HANDLER_1, POST_HANDLER_2]);
515
521
  });
516
522
 
517
- it('uses pre-handlers of @after metadata applied to action', function () {
523
+ it('uses pre-handlers of @afterAction metadata applied to action', function () {
518
524
  const S = new ControllerRegistry();
519
- @controller()
525
+ @restController()
520
526
  class MyController {
521
- @get('/myAction')
522
- @after([POST_HANDLER_1, POST_HANDLER_2])
527
+ @getAction('/myAction')
528
+ @afterAction([POST_HANDLER_1, POST_HANDLER_2])
523
529
  myAction() {}
524
530
  }
525
531
  S.addController(MyController);
@@ -536,13 +542,13 @@ describe('ControllerRegistry', function () {
536
542
  expect(res).to.be.eql([POST_HANDLER_1, POST_HANDLER_2]);
537
543
  });
538
544
 
539
- it('uses post-handlers of @controller metadata', function () {
545
+ it('uses post-handlers of @restController metadata', function () {
540
546
  const S = new ControllerRegistry();
541
- @controller({
547
+ @restController({
542
548
  after: [POST_HANDLER_1, POST_HANDLER_2],
543
549
  })
544
550
  class MyController {
545
- @get('/myAction')
551
+ @getAction('/myAction')
546
552
  myAction() {}
547
553
  }
548
554
  S.addController(MyController);
@@ -561,9 +567,9 @@ describe('ControllerRegistry', function () {
561
567
 
562
568
  it('uses post-handlers of @action metadata', function () {
563
569
  const S = new ControllerRegistry();
564
- @controller()
570
+ @restController()
565
571
  class MyController {
566
- @get('/myAction', {
572
+ @getAction('/myAction', {
567
573
  after: [POST_HANDLER_1, POST_HANDLER_2],
568
574
  })
569
575
  myAction() {}
@@ -586,11 +592,11 @@ describe('ControllerRegistry', function () {
586
592
  it('injects parsed parameters', async function () {
587
593
  let checked = false;
588
594
  const S = new ControllerRegistry();
589
- @controller()
595
+ @restController()
590
596
  class MyController {
591
- @get('/myAction/:id')
597
+ @getAction('/myAction/:id')
592
598
  myAction(
593
- @params()
599
+ @requestParams()
594
600
  params: ParsedParams,
595
601
  ) {
596
602
  expect(params).to.be.eql({id: '123'});
@@ -615,11 +621,11 @@ describe('ControllerRegistry', function () {
615
621
  it('injects parsed parameter', async function () {
616
622
  let checked = false;
617
623
  const S = new ControllerRegistry();
618
- @controller()
624
+ @restController()
619
625
  class MyController {
620
- @get('/myAction/:id')
626
+ @getAction('/myAction/:id')
621
627
  myAction(
622
- @param('id')
628
+ @requestParam('id')
623
629
  param: string,
624
630
  ) {
625
631
  expect(param).to.be.eq('123');
@@ -644,11 +650,11 @@ describe('ControllerRegistry', function () {
644
650
  it('injects parsed queries', async function () {
645
651
  let checked = false;
646
652
  const S = new ControllerRegistry();
647
- @controller()
653
+ @restController()
648
654
  class MyController {
649
- @get('/myAction')
655
+ @getAction('/myAction')
650
656
  myAction(
651
- @queries()
657
+ @requestQueries()
652
658
  queries: ParsedQuery,
653
659
  ) {
654
660
  expect(queries).to.be.eql({foo: 'bar'});
@@ -674,11 +680,11 @@ describe('ControllerRegistry', function () {
674
680
  it('injects parsed query', async function () {
675
681
  let checked = false;
676
682
  const S = new ControllerRegistry();
677
- @controller()
683
+ @restController()
678
684
  class MyController {
679
- @get('/myAction')
685
+ @getAction('/myAction')
680
686
  myAction(
681
- @query('foo')
687
+ @requestQuery('foo')
682
688
  foo: string,
683
689
  ) {
684
690
  expect(foo).to.be.eql('bar');
@@ -704,11 +710,11 @@ describe('ControllerRegistry', function () {
704
710
  it('injects parsed headers', async function () {
705
711
  let checked = false;
706
712
  const S = new ControllerRegistry();
707
- @controller()
713
+ @restController()
708
714
  class MyController {
709
- @get('/myAction')
715
+ @getAction('/myAction')
710
716
  myAction(
711
- @headers()
717
+ @requestHeaders()
712
718
  headers: ParsedHeaders,
713
719
  ) {
714
720
  expect(headers).to.be.eql({
@@ -739,11 +745,11 @@ describe('ControllerRegistry', function () {
739
745
  it('injects parsed header', async function () {
740
746
  let checked = false;
741
747
  const S = new ControllerRegistry();
742
- @controller()
748
+ @restController()
743
749
  class MyController {
744
- @get('/myAction')
750
+ @getAction('/myAction')
745
751
  myAction(
746
- @header('foo')
752
+ @requestHeader('foo')
747
753
  foo: string,
748
754
  ) {
749
755
  expect(foo).to.be.eq('bar');
@@ -770,11 +776,11 @@ describe('ControllerRegistry', function () {
770
776
  it('injects parsed cookies', async function () {
771
777
  let checked = false;
772
778
  const S = new ControllerRegistry();
773
- @controller()
779
+ @restController()
774
780
  class MyController {
775
- @get('/myAction')
781
+ @getAction('/myAction')
776
782
  myAction(
777
- @cookies()
783
+ @requestCookies()
778
784
  cookies: ParsedCookie,
779
785
  ) {
780
786
  expect(cookies).to.be.eql({foo: 'bar'});
@@ -801,11 +807,11 @@ describe('ControllerRegistry', function () {
801
807
  it('injects parsed cookie', async function () {
802
808
  let checked = false;
803
809
  const S = new ControllerRegistry();
804
- @controller()
810
+ @restController()
805
811
  class MyController {
806
- @get('/myAction')
812
+ @getAction('/myAction')
807
813
  myAction(
808
- @cookie('foo')
814
+ @requestCookie('foo')
809
815
  foo: string,
810
816
  ) {
811
817
  expect(foo).to.be.eq('bar');
@@ -832,11 +838,11 @@ describe('ControllerRegistry', function () {
832
838
  it('injects parsed body', async function () {
833
839
  let checked = false;
834
840
  const S = new ControllerRegistry();
835
- @controller()
841
+ @restController()
836
842
  class MyController {
837
- @post('/myAction')
843
+ @postAction('/myAction')
838
844
  myAction(
839
- @body()
845
+ @requestBody()
840
846
  body: object,
841
847
  ) {
842
848
  expect(body).to.be.eql({foo: 'bar'});
@@ -864,11 +870,11 @@ describe('ControllerRegistry', function () {
864
870
  it('injects parsed body parameter', async function () {
865
871
  let checked = false;
866
872
  const S = new ControllerRegistry();
867
- @controller()
873
+ @restController()
868
874
  class MyController {
869
- @post('/myAction')
875
+ @postAction('/myAction')
870
876
  myAction(
871
- @field('foo')
877
+ @requestField('foo')
872
878
  foo: object,
873
879
  ) {
874
880
  expect(foo).to.be.eq('bar');
@@ -897,18 +903,70 @@ describe('ControllerRegistry', function () {
897
903
  describe('hasController', function () {
898
904
  it('returns false if a given controller is not registered', function () {
899
905
  const S = new ControllerRegistry();
900
- @controller()
906
+ @restController()
901
907
  class MyController {}
902
908
  expect(S.hasController(MyController)).to.be.false;
903
909
  });
904
910
 
905
911
  it('returns true if a given controller is registered', function () {
906
912
  const S = new ControllerRegistry();
907
- @controller()
913
+ @restController()
908
914
  class MyController {}
909
915
  expect(S.hasController(MyController)).to.be.false;
910
916
  S.addController(MyController);
911
917
  expect(S.hasController(MyController)).to.be.true;
912
918
  });
913
919
  });
920
+
921
+ describe('createRouteHandler', function () {
922
+ it('uses default values from schema as copy', async function () {
923
+ let invoked = false;
924
+ const defaultValue = {foo: 'bar'};
925
+ class MyController {
926
+ myAction(
927
+ @requestBody({
928
+ type: DataType.OBJECT,
929
+ default: defaultValue,
930
+ })
931
+ body: object,
932
+ ) {
933
+ expect(body).to.be.not.eq(defaultValue);
934
+ expect(body).to.be.eql(defaultValue);
935
+ invoked = true;
936
+ }
937
+ }
938
+ const S = new ControllerRegistry();
939
+ const req = createRequestMock();
940
+ const res = createResponseMock();
941
+ const ctx = new RequestContext(S.container, req, res);
942
+ const handler = S['createRouteHandler'](MyController, 'myAction');
943
+ await handler(ctx);
944
+ expect(invoked).to.be.true;
945
+ });
946
+
947
+ it('uses default values from factory function that defined in schema as copy', async function () {
948
+ let invoked = false;
949
+ const defaultValue = {foo: 'bar'};
950
+ class MyController {
951
+ myAction(
952
+ @requestBody({
953
+ type: DataType.OBJECT,
954
+ default: () => defaultValue,
955
+ })
956
+ body: object,
957
+ ) {
958
+ expect(body).to.be.not.eq(defaultValue);
959
+ expect(body).to.be.eql(defaultValue);
960
+ invoked = true;
961
+ }
962
+ }
963
+ const S = new ControllerRegistry();
964
+ const req = createRequestMock();
965
+ const res = createResponseMock();
966
+ const ctx = new RequestContext(S.container, req, res);
967
+ const handler = S['createRouteHandler'](MyController, 'myAction');
968
+ await handler(ctx);
969
+ expect(invoked).to.be.true;
970
+ });
971
+ });
914
972
  });