@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
@@ -13,20 +13,32 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
13
13
  /* eslint-disable @typescript-eslint/no-unused-vars */
14
14
  import { expect } from 'chai';
15
15
  import { DataType } from '@e22m4u/ts-data-schema';
16
- import { body } from './request-data-decorator.js';
17
- import { param } from './request-data-decorator.js';
18
- import { query } from './request-data-decorator.js';
19
- import { field } from './request-data-decorator.js';
20
- import { cookie } from './request-data-decorator.js';
21
- import { header } from './request-data-decorator.js';
22
- import { params } from './request-data-decorator.js';
23
- import { queries } from './request-data-decorator.js';
24
- import { cookies } from './request-data-decorator.js';
25
- import { headers } from './request-data-decorator.js';
26
16
  import { requestData } from './request-data-decorator.js';
17
+ import { requestBody } from './request-data-decorator.js';
18
+ import { requestField } from './request-data-decorator.js';
19
+ import { requestParam } from './request-data-decorator.js';
20
+ import { requestQuery } from './request-data-decorator.js';
21
+ import { requestCookie } from './request-data-decorator.js';
22
+ import { requestHeader } from './request-data-decorator.js';
23
+ import { requestParams } from './request-data-decorator.js';
24
+ import { requestQueries } from './request-data-decorator.js';
25
+ import { requestHeaders } from './request-data-decorator.js';
26
+ import { requestCookies } from './request-data-decorator.js';
27
27
  import { RequestDataSource } from './request-data-metadata.js';
28
28
  import { RequestDataReflector } from './request-data-reflector.js';
29
29
  describe('requestData', function () {
30
+ it('has aliases', function () {
31
+ expect(requestParams).to.be.instanceOf(Function);
32
+ expect(requestParam).to.be.instanceOf(Function);
33
+ expect(requestQueries).to.be.instanceOf(Function);
34
+ expect(requestQuery).to.be.instanceOf(Function);
35
+ expect(requestHeaders).to.be.instanceOf(Function);
36
+ expect(requestHeader).to.be.instanceOf(Function);
37
+ expect(requestCookies).to.be.instanceOf(Function);
38
+ expect(requestCookie).to.be.instanceOf(Function);
39
+ expect(requestField).to.be.instanceOf(Function);
40
+ expect(requestBody).to.be.instanceOf(Function);
41
+ });
30
42
  it('sets given options to the target metadata', function () {
31
43
  const options = {
32
44
  source: RequestDataSource.BODY,
@@ -53,7 +65,7 @@ describe('requestData', function () {
53
65
  myMethod(prop) { }
54
66
  }
55
67
  __decorate([
56
- __param(0, params()),
68
+ __param(0, requestParams()),
57
69
  __metadata("design:type", Function),
58
70
  __metadata("design:paramtypes", [Object]),
59
71
  __metadata("design:returntype", void 0)
@@ -71,7 +83,7 @@ describe('requestData', function () {
71
83
  myMethod(prop) { }
72
84
  }
73
85
  __decorate([
74
- __param(0, queries()),
86
+ __param(0, requestQueries()),
75
87
  __metadata("design:type", Function),
76
88
  __metadata("design:paramtypes", [Object]),
77
89
  __metadata("design:returntype", void 0)
@@ -89,7 +101,7 @@ describe('requestData', function () {
89
101
  myMethod(prop) { }
90
102
  }
91
103
  __decorate([
92
- __param(0, headers()),
104
+ __param(0, requestHeaders()),
93
105
  __metadata("design:type", Function),
94
106
  __metadata("design:paramtypes", [Object]),
95
107
  __metadata("design:returntype", void 0)
@@ -107,7 +119,7 @@ describe('requestData', function () {
107
119
  myMethod(prop) { }
108
120
  }
109
121
  __decorate([
110
- __param(0, cookies()),
122
+ __param(0, requestCookies()),
111
123
  __metadata("design:type", Function),
112
124
  __metadata("design:paramtypes", [Object]),
113
125
  __metadata("design:returntype", void 0)
@@ -125,7 +137,7 @@ describe('requestData', function () {
125
137
  myMethod(prop) { }
126
138
  }
127
139
  __decorate([
128
- __param(0, body()),
140
+ __param(0, requestBody()),
129
141
  __metadata("design:type", Function),
130
142
  __metadata("design:paramtypes", [Object]),
131
143
  __metadata("design:returntype", void 0)
@@ -141,7 +153,7 @@ describe('requestData', function () {
141
153
  myMethod(prop) { }
142
154
  }
143
155
  __decorate([
144
- __param(0, body(DataType.STRING)),
156
+ __param(0, requestBody(DataType.STRING)),
145
157
  __metadata("design:type", Function),
146
158
  __metadata("design:paramtypes", [Object]),
147
159
  __metadata("design:returntype", void 0)
@@ -158,7 +170,7 @@ describe('requestData', function () {
158
170
  myMethod(prop) { }
159
171
  }
160
172
  __decorate([
161
- __param(0, body(schema)),
173
+ __param(0, requestBody(schema)),
162
174
  __metadata("design:type", Function),
163
175
  __metadata("design:paramtypes", [Object]),
164
176
  __metadata("design:returntype", void 0)
@@ -178,7 +190,7 @@ describe('requestData', function () {
178
190
  myMethod(prop) { }
179
191
  }
180
192
  __decorate([
181
- __param(0, param('myPropertyKey')),
193
+ __param(0, requestParam('myPropertyKey')),
182
194
  __metadata("design:type", Function),
183
195
  __metadata("design:paramtypes", [Object]),
184
196
  __metadata("design:returntype", void 0)
@@ -197,7 +209,7 @@ describe('requestData', function () {
197
209
  myMethod(prop) { }
198
210
  }
199
211
  __decorate([
200
- __param(0, param(propertyKey, propertyType)),
212
+ __param(0, requestParam(propertyKey, propertyType)),
201
213
  __metadata("design:type", Function),
202
214
  __metadata("design:paramtypes", [Object]),
203
215
  __metadata("design:returntype", void 0)
@@ -226,7 +238,7 @@ describe('requestData', function () {
226
238
  myMethod(prop) { }
227
239
  }
228
240
  __decorate([
229
- __param(0, param(propertyKey, schema)),
241
+ __param(0, requestParam(propertyKey, schema)),
230
242
  __metadata("design:type", Function),
231
243
  __metadata("design:paramtypes", [Object]),
232
244
  __metadata("design:returntype", void 0)
@@ -250,7 +262,7 @@ describe('requestData', function () {
250
262
  myMethod(prop) { }
251
263
  }
252
264
  __decorate([
253
- __param(0, query('myPropertyKey')),
265
+ __param(0, requestQuery('myPropertyKey')),
254
266
  __metadata("design:type", Function),
255
267
  __metadata("design:paramtypes", [Object]),
256
268
  __metadata("design:returntype", void 0)
@@ -269,7 +281,7 @@ describe('requestData', function () {
269
281
  myMethod(prop) { }
270
282
  }
271
283
  __decorate([
272
- __param(0, query(propertyKey, propertyType)),
284
+ __param(0, requestQuery(propertyKey, propertyType)),
273
285
  __metadata("design:type", Function),
274
286
  __metadata("design:paramtypes", [Object]),
275
287
  __metadata("design:returntype", void 0)
@@ -298,7 +310,7 @@ describe('requestData', function () {
298
310
  myMethod(prop) { }
299
311
  }
300
312
  __decorate([
301
- __param(0, query(propertyKey, schema)),
313
+ __param(0, requestQuery(propertyKey, schema)),
302
314
  __metadata("design:type", Function),
303
315
  __metadata("design:paramtypes", [Object]),
304
316
  __metadata("design:returntype", void 0)
@@ -322,7 +334,7 @@ describe('requestData', function () {
322
334
  myMethod(prop) { }
323
335
  }
324
336
  __decorate([
325
- __param(0, header('myPropertyKey')),
337
+ __param(0, requestHeader('myPropertyKey')),
326
338
  __metadata("design:type", Function),
327
339
  __metadata("design:paramtypes", [Object]),
328
340
  __metadata("design:returntype", void 0)
@@ -341,7 +353,7 @@ describe('requestData', function () {
341
353
  myMethod(prop) { }
342
354
  }
343
355
  __decorate([
344
- __param(0, header(propertyKey, propertyType)),
356
+ __param(0, requestHeader(propertyKey, propertyType)),
345
357
  __metadata("design:type", Function),
346
358
  __metadata("design:paramtypes", [Object]),
347
359
  __metadata("design:returntype", void 0)
@@ -370,7 +382,7 @@ describe('requestData', function () {
370
382
  myMethod(prop) { }
371
383
  }
372
384
  __decorate([
373
- __param(0, header(propertyKey, schema)),
385
+ __param(0, requestHeader(propertyKey, schema)),
374
386
  __metadata("design:type", Function),
375
387
  __metadata("design:paramtypes", [Object]),
376
388
  __metadata("design:returntype", void 0)
@@ -394,7 +406,7 @@ describe('requestData', function () {
394
406
  myMethod(prop) { }
395
407
  }
396
408
  __decorate([
397
- __param(0, cookie('myPropertyKey')),
409
+ __param(0, requestCookie('myPropertyKey')),
398
410
  __metadata("design:type", Function),
399
411
  __metadata("design:paramtypes", [Object]),
400
412
  __metadata("design:returntype", void 0)
@@ -413,7 +425,7 @@ describe('requestData', function () {
413
425
  myMethod(prop) { }
414
426
  }
415
427
  __decorate([
416
- __param(0, cookie(propertyKey, propertyType)),
428
+ __param(0, requestCookie(propertyKey, propertyType)),
417
429
  __metadata("design:type", Function),
418
430
  __metadata("design:paramtypes", [Object]),
419
431
  __metadata("design:returntype", void 0)
@@ -442,7 +454,7 @@ describe('requestData', function () {
442
454
  myMethod(prop) { }
443
455
  }
444
456
  __decorate([
445
- __param(0, cookie(propertyKey, schema)),
457
+ __param(0, requestCookie(propertyKey, schema)),
446
458
  __metadata("design:type", Function),
447
459
  __metadata("design:paramtypes", [Object]),
448
460
  __metadata("design:returntype", void 0)
@@ -466,7 +478,7 @@ describe('requestData', function () {
466
478
  myMethod(prop) { }
467
479
  }
468
480
  __decorate([
469
- __param(0, field('myPropertyKey')),
481
+ __param(0, requestField('myPropertyKey')),
470
482
  __metadata("design:type", Function),
471
483
  __metadata("design:paramtypes", [Object]),
472
484
  __metadata("design:returntype", void 0)
@@ -485,7 +497,7 @@ describe('requestData', function () {
485
497
  myMethod(prop) { }
486
498
  }
487
499
  __decorate([
488
- __param(0, field(propertyKey, propertyType)),
500
+ __param(0, requestField(propertyKey, propertyType)),
489
501
  __metadata("design:type", Function),
490
502
  __metadata("design:paramtypes", [Object]),
491
503
  __metadata("design:returntype", void 0)
@@ -514,7 +526,7 @@ describe('requestData', function () {
514
526
  myMethod(prop) { }
515
527
  }
516
528
  __decorate([
517
- __param(0, field(propertyKey, schema)),
529
+ __param(0, requestField(propertyKey, schema)),
518
530
  __metadata("design:type", Function),
519
531
  __metadata("design:paramtypes", [Object]),
520
532
  __metadata("design:returntype", void 0)
@@ -1,5 +1,5 @@
1
- import { DataSchema } from '@e22m4u/ts-data-schema';
2
1
  import { MetadataKey } from '@e22m4u/ts-reflector';
2
+ import { DataSchema } from '@e22m4u/ts-data-schema';
3
3
  /**
4
4
  * Request data source.
5
5
  */
@@ -0,0 +1,3 @@
1
+ export * from './rest-action-metadata.js';
2
+ export * from './rest-action-reflector.js';
3
+ export * from './rest-action-decorator.js';
@@ -0,0 +1,3 @@
1
+ export * from './rest-action-metadata.js';
2
+ export * from './rest-action-reflector.js';
3
+ export * from './rest-action-decorator.js';
@@ -0,0 +1,57 @@
1
+ import { Flatten, PartialBy } from '../../types.js';
2
+ import { Prototype } from '../../types.js';
3
+ import { RestActionMetadata } from './rest-action-metadata.js';
4
+ /**
5
+ * Rest action options.
6
+ */
7
+ export type RestActionOptions = Flatten<Omit<RestActionMetadata, 'propertyKey'>>;
8
+ /**
9
+ * Rest action decorator.
10
+ */
11
+ type RestActionDecorator = ReturnType<typeof restAction>;
12
+ /**
13
+ * Rest action decorator factory.
14
+ *
15
+ * @param options
16
+ */
17
+ export declare function restAction<T extends object>(options: RestActionOptions): (target: Prototype<T>, propertyKey: string, descriptor: PropertyDescriptor) => void;
18
+ /**
19
+ * Rest action method options.
20
+ */
21
+ export type RestActionAliasOptions = Flatten<PartialBy<Omit<RestActionOptions, 'method'>, 'path'>>;
22
+ /**
23
+ * Get action decorator.
24
+ */
25
+ export declare function getAction(): RestActionDecorator;
26
+ export declare function getAction(path: string): RestActionDecorator;
27
+ export declare function getAction(options: RestActionAliasOptions): RestActionDecorator;
28
+ export declare function getAction(path: string, options: RestActionAliasOptions): RestActionDecorator;
29
+ /**
30
+ * Post action decorator.
31
+ */
32
+ export declare function postAction(): RestActionDecorator;
33
+ export declare function postAction(path: string): RestActionDecorator;
34
+ export declare function postAction(options: RestActionAliasOptions): RestActionDecorator;
35
+ export declare function postAction(path: string, options: RestActionAliasOptions): RestActionDecorator;
36
+ /**
37
+ * Put action decorator.
38
+ */
39
+ export declare function putAction(): RestActionDecorator;
40
+ export declare function putAction(path: string): RestActionDecorator;
41
+ export declare function putAction(options: RestActionAliasOptions): RestActionDecorator;
42
+ export declare function putAction(path: string, options: RestActionAliasOptions): RestActionDecorator;
43
+ /**
44
+ * Patch action decorator.
45
+ */
46
+ export declare function patchAction(): RestActionDecorator;
47
+ export declare function patchAction(path: string): RestActionDecorator;
48
+ export declare function patchAction(options: RestActionAliasOptions): RestActionDecorator;
49
+ export declare function patchAction(path: string, options: RestActionAliasOptions): RestActionDecorator;
50
+ /**
51
+ * Delete action decorator.
52
+ */
53
+ export declare function deleteAction(): RestActionDecorator;
54
+ export declare function deleteAction(path: string): RestActionDecorator;
55
+ export declare function deleteAction(options: RestActionAliasOptions): RestActionDecorator;
56
+ export declare function deleteAction(path: string, options: RestActionAliasOptions): RestActionDecorator;
57
+ export {};
@@ -0,0 +1,52 @@
1
+ import { HttpMethod } from '@e22m4u/js-trie-router';
2
+ import { DecoratorTargetType } from '@e22m4u/ts-reflector';
3
+ import { getDecoratorTargetType } from '@e22m4u/ts-reflector';
4
+ import { RestActionReflector } from './rest-action-reflector.js';
5
+ /**
6
+ * Rest action decorator factory.
7
+ *
8
+ * @param options
9
+ */
10
+ export function restAction(options) {
11
+ return function (target, propertyKey, descriptor) {
12
+ const decoratorType = getDecoratorTargetType(target, propertyKey, descriptor);
13
+ if (decoratorType !== DecoratorTargetType.INSTANCE_METHOD)
14
+ throw new Error('@restAction decorator is only supported on an instance method.');
15
+ RestActionReflector.setMetadata({ ...options, propertyKey }, target.constructor, propertyKey);
16
+ };
17
+ }
18
+ export function getAction(pathOrOptions, options) {
19
+ let path = typeof pathOrOptions === 'string' ? pathOrOptions : '';
20
+ options = typeof pathOrOptions === 'object' ? pathOrOptions : options;
21
+ if (typeof options === 'object' && !path && options.path != null)
22
+ path = options.path;
23
+ return restAction({ ...options, path, method: HttpMethod.GET });
24
+ }
25
+ export function postAction(pathOrOptions, options) {
26
+ let path = typeof pathOrOptions === 'string' ? pathOrOptions : '';
27
+ options = typeof pathOrOptions === 'object' ? pathOrOptions : options;
28
+ if (typeof options === 'object' && !path && options.path != null)
29
+ path = options.path;
30
+ return restAction({ ...options, path, method: HttpMethod.POST });
31
+ }
32
+ export function putAction(pathOrOptions, options) {
33
+ let path = typeof pathOrOptions === 'string' ? pathOrOptions : '';
34
+ options = typeof pathOrOptions === 'object' ? pathOrOptions : options;
35
+ if (typeof options === 'object' && !path && options.path != null)
36
+ path = options.path;
37
+ return restAction({ ...options, path, method: HttpMethod.PUT });
38
+ }
39
+ export function patchAction(pathOrOptions, options) {
40
+ let path = typeof pathOrOptions === 'string' ? pathOrOptions : '';
41
+ options = typeof pathOrOptions === 'object' ? pathOrOptions : options;
42
+ if (typeof options === 'object' && !path && options.path != null)
43
+ path = options.path;
44
+ return restAction({ ...options, path, method: HttpMethod.PATCH });
45
+ }
46
+ export function deleteAction(pathOrOptions, options) {
47
+ let path = typeof pathOrOptions === 'string' ? pathOrOptions : '';
48
+ options = typeof pathOrOptions === 'object' ? pathOrOptions : options;
49
+ if (typeof options === 'object' && !path && options.path != null)
50
+ path = options.path;
51
+ return restAction({ ...options, path, method: HttpMethod.DELETE });
52
+ }