@e22m4u/ts-rest-router 0.1.1 → 0.2.0

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 (140) hide show
  1. package/README.md +118 -118
  2. package/dist/cjs/index.cjs +346 -360
  3. package/dist/esm/controller-registry.js +28 -28
  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/{after/after-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/{before/before-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 -23
  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/{before/before-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/{after/after-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 -23
  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-data/request-data-decorator.d.ts +10 -10
  32. package/dist/esm/decorators/request-data/request-data-decorator.js +10 -10
  33. package/dist/esm/decorators/request-data/request-data-decorator.spec.js +44 -32
  34. package/dist/esm/decorators/request-data/request-data-metadata.d.ts +1 -1
  35. package/dist/esm/decorators/rest-action/index.d.ts +3 -0
  36. package/dist/esm/decorators/rest-action/index.js +3 -0
  37. package/dist/esm/decorators/rest-action/rest-action-decorator.d.ts +57 -0
  38. package/dist/esm/decorators/rest-action/rest-action-decorator.js +52 -0
  39. package/dist/esm/decorators/rest-action/rest-action-decorator.spec.js +401 -0
  40. package/dist/esm/decorators/{action/action-metadata.d.ts → rest-action/rest-action-metadata.d.ts} +6 -6
  41. package/dist/esm/decorators/rest-action/rest-action-metadata.js +5 -0
  42. package/dist/esm/decorators/rest-action/rest-action-reflector.d.ts +22 -0
  43. package/dist/esm/decorators/{action/action-reflector.js → rest-action/rest-action-reflector.js} +6 -6
  44. package/dist/esm/decorators/{action/action-reflector.spec.js → rest-action/rest-action-reflector.spec.js} +13 -13
  45. package/dist/esm/decorators/rest-controller/index.d.ts +3 -0
  46. package/dist/esm/decorators/rest-controller/index.js +3 -0
  47. package/dist/esm/decorators/rest-controller/rest-controller-decorator.d.ts +14 -0
  48. package/dist/esm/decorators/{controller/controller-decorator.js → rest-controller/rest-controller-decorator.js} +5 -5
  49. package/dist/esm/decorators/{controller/controller-decorator.spec.js → rest-controller/rest-controller-decorator.spec.js} +15 -15
  50. package/dist/esm/decorators/{controller/controller-metadata.d.ts → rest-controller/rest-controller-metadata.d.ts} +5 -5
  51. package/dist/esm/decorators/rest-controller/rest-controller-metadata.js +5 -0
  52. package/dist/esm/decorators/rest-controller/rest-controller-reflector.d.ts +20 -0
  53. package/dist/esm/decorators/rest-controller/rest-controller-reflector.js +24 -0
  54. package/dist/esm/decorators/{controller/controller-reflector.spec.js → rest-controller/rest-controller-reflector.spec.js} +12 -12
  55. package/dist/esm/errors/not-a-controller-error.js +1 -1
  56. package/dist/esm/types.d.ts +0 -10
  57. package/dist/esm/utils/index.d.ts +0 -1
  58. package/dist/esm/utils/index.js +0 -1
  59. package/package.json +19 -19
  60. package/src/controller-registry.spec.ts +122 -122
  61. package/src/controller-registry.ts +33 -35
  62. package/src/debuggable-service.ts +17 -4
  63. package/src/decorators/{after/after-decorator.spec.ts → after-action/after-action-decorator.spec.ts} +19 -19
  64. package/src/decorators/{before/before-decorator.ts → after-action/after-action-decorator.ts} +9 -9
  65. package/src/decorators/{after/after-metadata.ts → after-action/after-action-metadata.ts} +5 -5
  66. package/src/decorators/{before/before-reflector.spec.ts → after-action/after-action-reflector.spec.ts} +33 -23
  67. package/src/decorators/{before/before-reflector.ts → after-action/after-action-reflector.ts} +13 -9
  68. package/src/decorators/after-action/index.ts +3 -0
  69. package/src/decorators/{before/before-decorator.spec.ts → before-action/before-action-decorator.spec.ts} +19 -19
  70. package/src/decorators/{after/after-decorator.ts → before-action/before-action-decorator.ts} +9 -9
  71. package/src/decorators/before-action/before-action-metadata.ts +17 -0
  72. package/src/decorators/{after/after-reflector.spec.ts → before-action/before-action-reflector.spec.ts} +40 -23
  73. package/src/decorators/{after/after-reflector.ts → before-action/before-action-reflector.ts} +18 -9
  74. package/src/decorators/before-action/index.ts +3 -0
  75. package/src/decorators/index.ts +4 -4
  76. package/src/decorators/request-context/request-context-decorator.spec.ts +7 -0
  77. package/src/decorators/request-context/request-context-decorator.ts +4 -4
  78. package/src/decorators/request-data/request-data-decorator.spec.ts +45 -32
  79. package/src/decorators/request-data/request-data-decorator.ts +10 -10
  80. package/src/decorators/request-data/request-data-metadata.ts +1 -1
  81. package/src/decorators/rest-action/index.ts +3 -0
  82. package/src/decorators/rest-action/rest-action-decorator.spec.ts +325 -0
  83. package/src/decorators/rest-action/rest-action-decorator.ts +166 -0
  84. package/src/decorators/{action/action-metadata.ts → rest-action/rest-action-metadata.ts} +7 -7
  85. package/src/decorators/{action/action-reflector.spec.ts → rest-action/rest-action-reflector.spec.ts} +13 -13
  86. package/src/decorators/rest-action/rest-action-reflector.ts +41 -0
  87. package/src/decorators/rest-controller/index.ts +3 -0
  88. package/src/decorators/{controller/controller-decorator.spec.ts → rest-controller/rest-controller-decorator.spec.ts} +16 -16
  89. package/src/decorators/{controller/controller-decorator.ts → rest-controller/rest-controller-decorator.ts} +14 -10
  90. package/src/decorators/{controller/controller-metadata.ts → rest-controller/rest-controller-metadata.ts} +6 -7
  91. package/src/decorators/{controller/controller-reflector.spec.ts → rest-controller/rest-controller-reflector.spec.ts} +21 -12
  92. package/src/decorators/rest-controller/rest-controller-reflector.ts +32 -0
  93. package/src/errors/not-a-controller-error.ts +4 -1
  94. package/src/types.ts +0 -10
  95. package/src/utils/index.ts +0 -1
  96. package/README-ru.md +0 -268
  97. package/dist/esm/decorators/action/action-decorator.d.ts +0 -52
  98. package/dist/esm/decorators/action/action-decorator.js +0 -62
  99. package/dist/esm/decorators/action/action-decorator.spec.js +0 -59
  100. package/dist/esm/decorators/action/action-metadata.js +0 -5
  101. package/dist/esm/decorators/action/action-reflector.d.ts +0 -22
  102. package/dist/esm/decorators/action/index.d.ts +0 -3
  103. package/dist/esm/decorators/action/index.js +0 -3
  104. package/dist/esm/decorators/after/after-decorator.d.ts +0 -9
  105. package/dist/esm/decorators/after/after-metadata.js +0 -5
  106. package/dist/esm/decorators/after/index.d.ts +0 -3
  107. package/dist/esm/decorators/after/index.js +0 -3
  108. package/dist/esm/decorators/before/before-decorator.d.ts +0 -9
  109. package/dist/esm/decorators/before/before-metadata.js +0 -5
  110. package/dist/esm/decorators/before/index.d.ts +0 -3
  111. package/dist/esm/decorators/before/index.js +0 -3
  112. package/dist/esm/decorators/controller/controller-decorator.d.ts +0 -14
  113. package/dist/esm/decorators/controller/controller-metadata.js +0 -5
  114. package/dist/esm/decorators/controller/controller-reflector.d.ts +0 -20
  115. package/dist/esm/decorators/controller/controller-reflector.js +0 -24
  116. package/dist/esm/decorators/controller/index.d.ts +0 -3
  117. package/dist/esm/decorators/controller/index.js +0 -3
  118. package/dist/esm/utils/create-debugger.d.ts +0 -44
  119. package/dist/esm/utils/create-debugger.js +0 -81
  120. package/dist/esm/utils/create-debugger.spec.d.ts +0 -1
  121. package/dist/esm/utils/create-debugger.spec.js +0 -8
  122. package/src/decorators/action/action-decorator.spec.ts +0 -42
  123. package/src/decorators/action/action-decorator.ts +0 -98
  124. package/src/decorators/action/action-reflector.ts +0 -38
  125. package/src/decorators/action/index.ts +0 -3
  126. package/src/decorators/after/index.ts +0 -3
  127. package/src/decorators/before/before-metadata.ts +0 -17
  128. package/src/decorators/before/index.ts +0 -3
  129. package/src/decorators/controller/controller-reflector.ts +0 -28
  130. package/src/decorators/controller/index.ts +0 -3
  131. package/src/utils/create-debugger.spec.ts +0 -9
  132. package/src/utils/create-debugger.ts +0 -98
  133. /package/dist/esm/decorators/{action/action-decorator.spec.d.ts → after-action/after-action-decorator.spec.d.ts} +0 -0
  134. /package/dist/esm/decorators/{action/action-reflector.spec.d.ts → after-action/after-action-reflector.spec.d.ts} +0 -0
  135. /package/dist/esm/decorators/{after/after-decorator.spec.d.ts → before-action/before-action-decorator.spec.d.ts} +0 -0
  136. /package/dist/esm/decorators/{after/after-reflector.spec.d.ts → before-action/before-action-reflector.spec.d.ts} +0 -0
  137. /package/dist/esm/decorators/{before/before-decorator.spec.d.ts → rest-action/rest-action-decorator.spec.d.ts} +0 -0
  138. /package/dist/esm/decorators/{before/before-reflector.spec.d.ts → rest-action/rest-action-reflector.spec.d.ts} +0 -0
  139. /package/dist/esm/decorators/{controller/controller-decorator.spec.d.ts → rest-controller/rest-controller-decorator.spec.d.ts} +0 -0
  140. /package/dist/esm/decorators/{controller/controller-reflector.spec.d.ts → rest-controller/rest-controller-reflector.spec.d.ts} +0 -0
@@ -0,0 +1,401 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { expect } from 'chai';
11
+ import { HttpMethod } from '@e22m4u/js-trie-router';
12
+ import { getAction } from './rest-action-decorator.js';
13
+ import { putAction } from './rest-action-decorator.js';
14
+ import { restAction } from './rest-action-decorator.js';
15
+ import { postAction } from './rest-action-decorator.js';
16
+ import { patchAction } from './rest-action-decorator.js';
17
+ import { deleteAction } from './rest-action-decorator.js';
18
+ import { RestActionReflector } from './rest-action-reflector.js';
19
+ describe('restAction', function () {
20
+ it('hasAliases', function () {
21
+ expect(getAction).to.be.instanceOf(Function);
22
+ expect(postAction).to.be.instanceOf(Function);
23
+ expect(putAction).to.be.instanceOf(Function);
24
+ expect(patchAction).to.be.instanceOf(Function);
25
+ expect(deleteAction).to.be.instanceOf(Function);
26
+ });
27
+ it('sets given options to the target metadata', function () {
28
+ const options = {
29
+ method: HttpMethod.GET,
30
+ path: 'myPath',
31
+ before: () => undefined,
32
+ after: () => undefined,
33
+ customOption: 'customOption',
34
+ };
35
+ class Target {
36
+ method() { }
37
+ }
38
+ __decorate([
39
+ restAction(options),
40
+ __metadata("design:type", Function),
41
+ __metadata("design:paramtypes", []),
42
+ __metadata("design:returntype", void 0)
43
+ ], Target.prototype, "method", null);
44
+ const res = RestActionReflector.getMetadata(Target);
45
+ expect(res.get('method')).to.be.eql({
46
+ ...options,
47
+ propertyKey: 'method',
48
+ });
49
+ });
50
+ it('overrides a given "propertyKey" option by the target method name', function () {
51
+ const options = {
52
+ propertyKey: 'myMethod',
53
+ method: HttpMethod.GET,
54
+ path: 'myPath',
55
+ };
56
+ class Target {
57
+ method() { }
58
+ }
59
+ __decorate([
60
+ restAction(options),
61
+ __metadata("design:type", Function),
62
+ __metadata("design:paramtypes", []),
63
+ __metadata("design:returntype", void 0)
64
+ ], Target.prototype, "method", null);
65
+ const res = RestActionReflector.getMetadata(Target);
66
+ expect(res.get('method')).to.be.eql({
67
+ ...options,
68
+ propertyKey: 'method',
69
+ });
70
+ });
71
+ describe('getAction', function () {
72
+ it('allows no arguments', function () {
73
+ class Target {
74
+ method() { }
75
+ }
76
+ __decorate([
77
+ getAction(),
78
+ __metadata("design:type", Function),
79
+ __metadata("design:paramtypes", []),
80
+ __metadata("design:returntype", void 0)
81
+ ], Target.prototype, "method", null);
82
+ const res = RestActionReflector.getMetadata(Target);
83
+ expect(res.get('method')).to.be.eql({
84
+ propertyKey: 'method',
85
+ method: HttpMethod.GET,
86
+ path: '',
87
+ });
88
+ });
89
+ it('allows options as first argument', function () {
90
+ const options = {
91
+ path: 'myPath',
92
+ before: () => undefined,
93
+ after: () => undefined,
94
+ customOption: 'customOption',
95
+ };
96
+ class Target {
97
+ method() { }
98
+ }
99
+ __decorate([
100
+ getAction(options),
101
+ __metadata("design:type", Function),
102
+ __metadata("design:paramtypes", []),
103
+ __metadata("design:returntype", void 0)
104
+ ], Target.prototype, "method", null);
105
+ const res = RestActionReflector.getMetadata(Target);
106
+ expect(res.get('method')).to.be.eql({
107
+ ...options,
108
+ propertyKey: 'method',
109
+ method: HttpMethod.GET,
110
+ });
111
+ });
112
+ it('allows path and options arguments', function () {
113
+ const options = {
114
+ path: 'myPath2',
115
+ before: () => undefined,
116
+ after: () => undefined,
117
+ customOption: 'customOption',
118
+ };
119
+ class Target {
120
+ method() { }
121
+ }
122
+ __decorate([
123
+ getAction('myPath1', options),
124
+ __metadata("design:type", Function),
125
+ __metadata("design:paramtypes", []),
126
+ __metadata("design:returntype", void 0)
127
+ ], Target.prototype, "method", null);
128
+ const res = RestActionReflector.getMetadata(Target);
129
+ expect(res.get('method')).to.be.eql({
130
+ ...options,
131
+ propertyKey: 'method',
132
+ method: HttpMethod.GET,
133
+ path: 'myPath1',
134
+ });
135
+ });
136
+ });
137
+ describe('postAction', function () {
138
+ it('allows no arguments', function () {
139
+ class Target {
140
+ method() { }
141
+ }
142
+ __decorate([
143
+ postAction(),
144
+ __metadata("design:type", Function),
145
+ __metadata("design:paramtypes", []),
146
+ __metadata("design:returntype", void 0)
147
+ ], Target.prototype, "method", null);
148
+ const res = RestActionReflector.getMetadata(Target);
149
+ expect(res.get('method')).to.be.eql({
150
+ propertyKey: 'method',
151
+ method: HttpMethod.POST,
152
+ path: '',
153
+ });
154
+ });
155
+ it('allows options as first argument', function () {
156
+ const options = {
157
+ path: 'myPath',
158
+ before: () => undefined,
159
+ after: () => undefined,
160
+ customOption: 'customOption',
161
+ };
162
+ class Target {
163
+ method() { }
164
+ }
165
+ __decorate([
166
+ postAction(options),
167
+ __metadata("design:type", Function),
168
+ __metadata("design:paramtypes", []),
169
+ __metadata("design:returntype", void 0)
170
+ ], Target.prototype, "method", null);
171
+ const res = RestActionReflector.getMetadata(Target);
172
+ expect(res.get('method')).to.be.eql({
173
+ ...options,
174
+ propertyKey: 'method',
175
+ method: HttpMethod.POST,
176
+ });
177
+ });
178
+ it('allows path and options arguments', function () {
179
+ const options = {
180
+ path: 'myPath2',
181
+ before: () => undefined,
182
+ after: () => undefined,
183
+ customOption: 'customOption',
184
+ };
185
+ class Target {
186
+ method() { }
187
+ }
188
+ __decorate([
189
+ postAction('myPath1', options),
190
+ __metadata("design:type", Function),
191
+ __metadata("design:paramtypes", []),
192
+ __metadata("design:returntype", void 0)
193
+ ], Target.prototype, "method", null);
194
+ const res = RestActionReflector.getMetadata(Target);
195
+ expect(res.get('method')).to.be.eql({
196
+ ...options,
197
+ propertyKey: 'method',
198
+ method: HttpMethod.POST,
199
+ path: 'myPath1',
200
+ });
201
+ });
202
+ });
203
+ describe('putAction', function () {
204
+ it('allows no arguments', function () {
205
+ class Target {
206
+ method() { }
207
+ }
208
+ __decorate([
209
+ putAction(),
210
+ __metadata("design:type", Function),
211
+ __metadata("design:paramtypes", []),
212
+ __metadata("design:returntype", void 0)
213
+ ], Target.prototype, "method", null);
214
+ const res = RestActionReflector.getMetadata(Target);
215
+ expect(res.get('method')).to.be.eql({
216
+ propertyKey: 'method',
217
+ method: HttpMethod.PUT,
218
+ path: '',
219
+ });
220
+ });
221
+ it('allows options as first argument', function () {
222
+ const options = {
223
+ path: 'myPath',
224
+ before: () => undefined,
225
+ after: () => undefined,
226
+ customOption: 'customOption',
227
+ };
228
+ class Target {
229
+ method() { }
230
+ }
231
+ __decorate([
232
+ putAction(options),
233
+ __metadata("design:type", Function),
234
+ __metadata("design:paramtypes", []),
235
+ __metadata("design:returntype", void 0)
236
+ ], Target.prototype, "method", null);
237
+ const res = RestActionReflector.getMetadata(Target);
238
+ expect(res.get('method')).to.be.eql({
239
+ ...options,
240
+ propertyKey: 'method',
241
+ method: HttpMethod.PUT,
242
+ });
243
+ });
244
+ it('allows path and options arguments', function () {
245
+ const options = {
246
+ path: 'myPath2',
247
+ before: () => undefined,
248
+ after: () => undefined,
249
+ customOption: 'customOption',
250
+ };
251
+ class Target {
252
+ method() { }
253
+ }
254
+ __decorate([
255
+ putAction('myPath1', options),
256
+ __metadata("design:type", Function),
257
+ __metadata("design:paramtypes", []),
258
+ __metadata("design:returntype", void 0)
259
+ ], Target.prototype, "method", null);
260
+ const res = RestActionReflector.getMetadata(Target);
261
+ expect(res.get('method')).to.be.eql({
262
+ ...options,
263
+ propertyKey: 'method',
264
+ method: HttpMethod.PUT,
265
+ path: 'myPath1',
266
+ });
267
+ });
268
+ });
269
+ describe('patchAction', function () {
270
+ it('allows no arguments', function () {
271
+ class Target {
272
+ method() { }
273
+ }
274
+ __decorate([
275
+ patchAction(),
276
+ __metadata("design:type", Function),
277
+ __metadata("design:paramtypes", []),
278
+ __metadata("design:returntype", void 0)
279
+ ], Target.prototype, "method", null);
280
+ const res = RestActionReflector.getMetadata(Target);
281
+ expect(res.get('method')).to.be.eql({
282
+ propertyKey: 'method',
283
+ method: HttpMethod.PATCH,
284
+ path: '',
285
+ });
286
+ });
287
+ it('allows options as first argument', function () {
288
+ const options = {
289
+ path: 'myPath',
290
+ before: () => undefined,
291
+ after: () => undefined,
292
+ customOption: 'customOption',
293
+ };
294
+ class Target {
295
+ method() { }
296
+ }
297
+ __decorate([
298
+ patchAction(options),
299
+ __metadata("design:type", Function),
300
+ __metadata("design:paramtypes", []),
301
+ __metadata("design:returntype", void 0)
302
+ ], Target.prototype, "method", null);
303
+ const res = RestActionReflector.getMetadata(Target);
304
+ expect(res.get('method')).to.be.eql({
305
+ ...options,
306
+ propertyKey: 'method',
307
+ method: HttpMethod.PATCH,
308
+ });
309
+ });
310
+ it('allows path and options arguments', function () {
311
+ const options = {
312
+ path: 'myPath2',
313
+ before: () => undefined,
314
+ after: () => undefined,
315
+ customOption: 'customOption',
316
+ };
317
+ class Target {
318
+ method() { }
319
+ }
320
+ __decorate([
321
+ patchAction('myPath1', options),
322
+ __metadata("design:type", Function),
323
+ __metadata("design:paramtypes", []),
324
+ __metadata("design:returntype", void 0)
325
+ ], Target.prototype, "method", null);
326
+ const res = RestActionReflector.getMetadata(Target);
327
+ expect(res.get('method')).to.be.eql({
328
+ ...options,
329
+ propertyKey: 'method',
330
+ method: HttpMethod.PATCH,
331
+ path: 'myPath1',
332
+ });
333
+ });
334
+ });
335
+ describe('deleteAction', function () {
336
+ it('allows no arguments', function () {
337
+ class Target {
338
+ method() { }
339
+ }
340
+ __decorate([
341
+ deleteAction(),
342
+ __metadata("design:type", Function),
343
+ __metadata("design:paramtypes", []),
344
+ __metadata("design:returntype", void 0)
345
+ ], Target.prototype, "method", null);
346
+ const res = RestActionReflector.getMetadata(Target);
347
+ expect(res.get('method')).to.be.eql({
348
+ propertyKey: 'method',
349
+ method: HttpMethod.DELETE,
350
+ path: '',
351
+ });
352
+ });
353
+ it('allows options as first argument', function () {
354
+ const options = {
355
+ path: 'myPath',
356
+ before: () => undefined,
357
+ after: () => undefined,
358
+ customOption: 'customOption',
359
+ };
360
+ class Target {
361
+ method() { }
362
+ }
363
+ __decorate([
364
+ deleteAction(options),
365
+ __metadata("design:type", Function),
366
+ __metadata("design:paramtypes", []),
367
+ __metadata("design:returntype", void 0)
368
+ ], Target.prototype, "method", null);
369
+ const res = RestActionReflector.getMetadata(Target);
370
+ expect(res.get('method')).to.be.eql({
371
+ ...options,
372
+ propertyKey: 'method',
373
+ method: HttpMethod.DELETE,
374
+ });
375
+ });
376
+ it('allows path and options arguments', function () {
377
+ const options = {
378
+ path: 'myPath2',
379
+ before: () => undefined,
380
+ after: () => undefined,
381
+ customOption: 'customOption',
382
+ };
383
+ class Target {
384
+ method() { }
385
+ }
386
+ __decorate([
387
+ deleteAction('myPath1', options),
388
+ __metadata("design:type", Function),
389
+ __metadata("design:paramtypes", []),
390
+ __metadata("design:returntype", void 0)
391
+ ], Target.prototype, "method", null);
392
+ const res = RestActionReflector.getMetadata(Target);
393
+ expect(res.get('method')).to.be.eql({
394
+ ...options,
395
+ propertyKey: 'method',
396
+ method: HttpMethod.DELETE,
397
+ path: 'myPath1',
398
+ });
399
+ });
400
+ });
401
+ });
@@ -3,9 +3,9 @@ import { HttpMethod } from '@e22m4u/js-trie-router';
3
3
  import { RoutePreHandler } from '@e22m4u/js-trie-router';
4
4
  import { RoutePostHandler } from '@e22m4u/js-trie-router';
5
5
  /**
6
- * Action metadata.
6
+ * Rest action metadata.
7
7
  */
8
- export type ActionMetadata = {
8
+ export type RestActionMetadata = {
9
9
  propertyKey: string;
10
10
  method: HttpMethod;
11
11
  path: string;
@@ -13,10 +13,10 @@ export type ActionMetadata = {
13
13
  after?: RoutePostHandler | RoutePostHandler[];
14
14
  };
15
15
  /**
16
- * Action metadata map.
16
+ * Rest action metadata map.
17
17
  */
18
- export type ActionMetadataMap = Map<string, ActionMetadata>;
18
+ export type RestActionMetadataMap = Map<string, RestActionMetadata>;
19
19
  /**
20
- * Actions metadata key.
20
+ * Rest actions metadata key.
21
21
  */
22
- export declare const ACTIONS_METADATA_KEY: MetadataKey<ActionMetadataMap>;
22
+ export declare const REST_ACTIONS_METADATA_KEY: MetadataKey<RestActionMetadataMap>;
@@ -0,0 +1,5 @@
1
+ import { MetadataKey } from '@e22m4u/ts-reflector';
2
+ /**
3
+ * Rest actions metadata key.
4
+ */
5
+ export const REST_ACTIONS_METADATA_KEY = new MetadataKey('restActionsMetadataKey');
@@ -0,0 +1,22 @@
1
+ import { Constructor } from '../../types.js';
2
+ import { RestActionMetadata } from './rest-action-metadata.js';
3
+ import { RestActionMetadataMap } from './rest-action-metadata.js';
4
+ /**
5
+ * Rest action reflector.
6
+ */
7
+ export declare class RestActionReflector {
8
+ /**
9
+ * Set metadata.
10
+ *
11
+ * @param metadata
12
+ * @param target
13
+ * @param propertyKey
14
+ */
15
+ static setMetadata(metadata: RestActionMetadata, target: Constructor, propertyKey: string): void;
16
+ /**
17
+ * Get metadata.
18
+ *
19
+ * @param target
20
+ */
21
+ static getMetadata(target: Constructor): RestActionMetadataMap;
22
+ }
@@ -1,9 +1,9 @@
1
1
  import { Reflector } from '@e22m4u/ts-reflector';
2
- import { ACTIONS_METADATA_KEY } from './action-metadata.js';
2
+ import { REST_ACTIONS_METADATA_KEY } from './rest-action-metadata.js';
3
3
  /**
4
- * Action reflector.
4
+ * Rest action reflector.
5
5
  */
6
- export class ActionReflector {
6
+ export class RestActionReflector {
7
7
  /**
8
8
  * Set metadata.
9
9
  *
@@ -12,10 +12,10 @@ export class ActionReflector {
12
12
  * @param propertyKey
13
13
  */
14
14
  static setMetadata(metadata, target, propertyKey) {
15
- const oldMap = Reflector.getOwnMetadata(ACTIONS_METADATA_KEY, target);
15
+ const oldMap = Reflector.getOwnMetadata(REST_ACTIONS_METADATA_KEY, target);
16
16
  const newMap = new Map(oldMap);
17
17
  newMap.set(propertyKey, metadata);
18
- Reflector.defineMetadata(ACTIONS_METADATA_KEY, newMap, target);
18
+ Reflector.defineMetadata(REST_ACTIONS_METADATA_KEY, newMap, target);
19
19
  }
20
20
  /**
21
21
  * Get metadata.
@@ -23,7 +23,7 @@ export class ActionReflector {
23
23
  * @param target
24
24
  */
25
25
  static getMetadata(target) {
26
- const metadata = Reflector.getOwnMetadata(ACTIONS_METADATA_KEY, target);
26
+ const metadata = Reflector.getOwnMetadata(REST_ACTIONS_METADATA_KEY, target);
27
27
  return metadata ?? new Map();
28
28
  }
29
29
  }
@@ -2,9 +2,9 @@ import { expect } from 'chai';
2
2
  import { describe } from 'mocha';
3
3
  import { Reflector } from '@e22m4u/ts-reflector';
4
4
  import { HttpMethod } from '@e22m4u/js-trie-router';
5
- import { ActionReflector } from './action-reflector.js';
6
- import { ACTIONS_METADATA_KEY } from './action-metadata.js';
7
- describe('ActionReflector', function () {
5
+ import { RestActionReflector } from './rest-action-reflector.js';
6
+ import { REST_ACTIONS_METADATA_KEY } from './rest-action-metadata.js';
7
+ describe('RestActionReflector', function () {
8
8
  describe('setMetadata', function () {
9
9
  it('sets a given value as target metadata', function () {
10
10
  class Target {
@@ -19,9 +19,9 @@ describe('ActionReflector', function () {
19
19
  method: HttpMethod.GET,
20
20
  path: '/bar',
21
21
  };
22
- ActionReflector.setMetadata(md1, Target, 'propertyKey1');
23
- ActionReflector.setMetadata(md2, Target, 'propertyKey2');
24
- const res = Reflector.getOwnMetadata(ACTIONS_METADATA_KEY, Target);
22
+ RestActionReflector.setMetadata(md1, Target, 'propertyKey1');
23
+ RestActionReflector.setMetadata(md2, Target, 'propertyKey2');
24
+ const res = Reflector.getOwnMetadata(REST_ACTIONS_METADATA_KEY, Target);
25
25
  expect(res).to.be.instanceof(Map);
26
26
  expect(res.get('propertyKey1')).to.be.eq(md1);
27
27
  expect(res.get('propertyKey2')).to.be.eq(md2);
@@ -39,12 +39,12 @@ describe('ActionReflector', function () {
39
39
  method: HttpMethod.POST,
40
40
  path: '/bar',
41
41
  };
42
- ActionReflector.setMetadata(md1, Target, 'propertyKey');
43
- const res1 = Reflector.getOwnMetadata(ACTIONS_METADATA_KEY, Target);
42
+ RestActionReflector.setMetadata(md1, Target, 'propertyKey');
43
+ const res1 = Reflector.getOwnMetadata(REST_ACTIONS_METADATA_KEY, Target);
44
44
  expect(res1).to.be.instanceof(Map);
45
45
  expect(res1.get('propertyKey')).to.be.eq(md1);
46
- ActionReflector.setMetadata(md2, Target, 'propertyKey');
47
- const res2 = Reflector.getOwnMetadata(ACTIONS_METADATA_KEY, Target);
46
+ RestActionReflector.setMetadata(md2, Target, 'propertyKey');
47
+ const res2 = Reflector.getOwnMetadata(REST_ACTIONS_METADATA_KEY, Target);
48
48
  expect(res2).to.be.instanceof(Map);
49
49
  expect(res2.get('propertyKey')).to.be.eq(md2);
50
50
  });
@@ -67,8 +67,8 @@ describe('ActionReflector', function () {
67
67
  ['propertyKey1', md1],
68
68
  ['propertyKey2', md2],
69
69
  ]);
70
- Reflector.defineMetadata(ACTIONS_METADATA_KEY, mdMap, Target);
71
- const res = ActionReflector.getMetadata(Target);
70
+ Reflector.defineMetadata(REST_ACTIONS_METADATA_KEY, mdMap, Target);
71
+ const res = RestActionReflector.getMetadata(Target);
72
72
  expect(res).to.be.instanceof(Map);
73
73
  expect(res.get('propertyKey1')).to.be.eq(md1);
74
74
  expect(res.get('propertyKey2')).to.be.eq(md2);
@@ -76,7 +76,7 @@ describe('ActionReflector', function () {
76
76
  it('returns an empty map if no metadata', function () {
77
77
  class Target {
78
78
  }
79
- const res = ActionReflector.getMetadata(Target);
79
+ const res = RestActionReflector.getMetadata(Target);
80
80
  expect(res).to.be.instanceof(Map);
81
81
  expect(res).to.be.empty;
82
82
  });
@@ -0,0 +1,3 @@
1
+ export * from './rest-controller-metadata.js';
2
+ export * from './rest-controller-decorator.js';
3
+ export * from './rest-controller-reflector.js';
@@ -0,0 +1,3 @@
1
+ export * from './rest-controller-metadata.js';
2
+ export * from './rest-controller-decorator.js';
3
+ export * from './rest-controller-reflector.js';
@@ -0,0 +1,14 @@
1
+ import { Flatten } from '../../types.js';
2
+ import { Constructor } from '../../types.js';
3
+ import { RestControllerMetadata } from './rest-controller-metadata.js';
4
+ /**
5
+ * Rest controller options.
6
+ */
7
+ export type RestControllerOptions = Flatten<Omit<RestControllerMetadata, 'className'>>;
8
+ /**
9
+ * Rest controller decorator.
10
+ *
11
+ * @param pathOrOptions
12
+ * @param options
13
+ */
14
+ export declare function restController<T extends object>(pathOrOptions?: string | RestControllerOptions, options?: RestControllerOptions): (target: Constructor<T>) => void;
@@ -1,17 +1,17 @@
1
1
  import { DecoratorTargetType } from '@e22m4u/ts-reflector';
2
2
  import { getDecoratorTargetType } from '@e22m4u/ts-reflector';
3
- import { ControllerReflector } from './controller-reflector.js';
3
+ import { RestControllerReflector } from './rest-controller-reflector.js';
4
4
  /**
5
- * Controller decorator.
5
+ * Rest controller decorator.
6
6
  *
7
7
  * @param pathOrOptions
8
8
  * @param options
9
9
  */
10
- export function controller(pathOrOptions, options) {
10
+ export function restController(pathOrOptions, options) {
11
11
  return function (target) {
12
12
  const decoratorType = getDecoratorTargetType(target);
13
13
  if (decoratorType !== DecoratorTargetType.CONSTRUCTOR)
14
- throw new Error('@controller decorator is only supported on a class.');
14
+ throw new Error('@restController decorator is only supported on a class.');
15
15
  // если первый аргумент является строкой,
16
16
  // то значение используется в качестве
17
17
  // базового пути контроллера
@@ -36,6 +36,6 @@ export function controller(pathOrOptions, options) {
36
36
  else if (typeof pathOrOptions === 'object') {
37
37
  options = pathOrOptions;
38
38
  }
39
- ControllerReflector.setMetadata({ ...options, className: target.name }, target);
39
+ RestControllerReflector.setMetadata({ ...options, className: target.name }, target);
40
40
  };
41
41
  }