@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.
- package/README.md +118 -118
- package/dist/cjs/index.cjs +346 -360
- package/dist/esm/controller-registry.js +28 -28
- package/dist/esm/debuggable-service.d.ts +10 -1
- package/dist/esm/debuggable-service.js +14 -3
- package/dist/esm/decorators/after-action/after-action-decorator.d.ts +9 -0
- package/dist/esm/decorators/{after/after-decorator.js → after-action/after-action-decorator.js} +7 -7
- package/dist/esm/decorators/{before/before-decorator.spec.js → after-action/after-action-decorator.spec.js} +19 -19
- package/dist/esm/decorators/{after/after-metadata.d.ts → after-action/after-action-metadata.d.ts} +4 -4
- package/dist/esm/decorators/after-action/after-action-metadata.js +5 -0
- package/dist/esm/decorators/{after/after-reflector.d.ts → after-action/after-action-reflector.d.ts} +5 -5
- package/dist/esm/decorators/{before/before-reflector.js → after-action/after-action-reflector.js} +6 -6
- package/dist/esm/decorators/{before/before-reflector.spec.js → after-action/after-action-reflector.spec.js} +23 -23
- package/dist/esm/decorators/after-action/index.d.ts +3 -0
- package/dist/esm/decorators/after-action/index.js +3 -0
- package/dist/esm/decorators/before-action/before-action-decorator.d.ts +9 -0
- package/dist/esm/decorators/{before/before-decorator.js → before-action/before-action-decorator.js} +7 -7
- package/dist/esm/decorators/{after/after-decorator.spec.js → before-action/before-action-decorator.spec.js} +19 -19
- package/dist/esm/decorators/{before/before-metadata.d.ts → before-action/before-action-metadata.d.ts} +4 -4
- package/dist/esm/decorators/before-action/before-action-metadata.js +5 -0
- package/dist/esm/decorators/{before/before-reflector.d.ts → before-action/before-action-reflector.d.ts} +5 -5
- package/dist/esm/decorators/{after/after-reflector.js → before-action/before-action-reflector.js} +6 -6
- package/dist/esm/decorators/{after/after-reflector.spec.js → before-action/before-action-reflector.spec.js} +23 -23
- package/dist/esm/decorators/before-action/index.d.ts +3 -0
- package/dist/esm/decorators/before-action/index.js +3 -0
- package/dist/esm/decorators/index.d.ts +4 -4
- package/dist/esm/decorators/index.js +4 -4
- package/dist/esm/decorators/request-context/request-context-decorator.d.ts +4 -4
- package/dist/esm/decorators/request-context/request-context-decorator.js +4 -4
- package/dist/esm/decorators/request-context/request-context-decorator.spec.js +6 -0
- package/dist/esm/decorators/request-data/request-data-decorator.d.ts +10 -10
- package/dist/esm/decorators/request-data/request-data-decorator.js +10 -10
- package/dist/esm/decorators/request-data/request-data-decorator.spec.js +44 -32
- package/dist/esm/decorators/request-data/request-data-metadata.d.ts +1 -1
- package/dist/esm/decorators/rest-action/index.d.ts +3 -0
- package/dist/esm/decorators/rest-action/index.js +3 -0
- package/dist/esm/decorators/rest-action/rest-action-decorator.d.ts +57 -0
- package/dist/esm/decorators/rest-action/rest-action-decorator.js +52 -0
- package/dist/esm/decorators/rest-action/rest-action-decorator.spec.js +401 -0
- package/dist/esm/decorators/{action/action-metadata.d.ts → rest-action/rest-action-metadata.d.ts} +6 -6
- package/dist/esm/decorators/rest-action/rest-action-metadata.js +5 -0
- package/dist/esm/decorators/rest-action/rest-action-reflector.d.ts +22 -0
- package/dist/esm/decorators/{action/action-reflector.js → rest-action/rest-action-reflector.js} +6 -6
- package/dist/esm/decorators/{action/action-reflector.spec.js → rest-action/rest-action-reflector.spec.js} +13 -13
- package/dist/esm/decorators/rest-controller/index.d.ts +3 -0
- package/dist/esm/decorators/rest-controller/index.js +3 -0
- package/dist/esm/decorators/rest-controller/rest-controller-decorator.d.ts +14 -0
- package/dist/esm/decorators/{controller/controller-decorator.js → rest-controller/rest-controller-decorator.js} +5 -5
- package/dist/esm/decorators/{controller/controller-decorator.spec.js → rest-controller/rest-controller-decorator.spec.js} +15 -15
- package/dist/esm/decorators/{controller/controller-metadata.d.ts → rest-controller/rest-controller-metadata.d.ts} +5 -5
- package/dist/esm/decorators/rest-controller/rest-controller-metadata.js +5 -0
- package/dist/esm/decorators/rest-controller/rest-controller-reflector.d.ts +20 -0
- package/dist/esm/decorators/rest-controller/rest-controller-reflector.js +24 -0
- package/dist/esm/decorators/{controller/controller-reflector.spec.js → rest-controller/rest-controller-reflector.spec.js} +12 -12
- package/dist/esm/errors/not-a-controller-error.js +1 -1
- package/dist/esm/types.d.ts +0 -10
- package/dist/esm/utils/index.d.ts +0 -1
- package/dist/esm/utils/index.js +0 -1
- package/package.json +19 -19
- package/src/controller-registry.spec.ts +122 -122
- package/src/controller-registry.ts +33 -35
- package/src/debuggable-service.ts +17 -4
- package/src/decorators/{after/after-decorator.spec.ts → after-action/after-action-decorator.spec.ts} +19 -19
- package/src/decorators/{before/before-decorator.ts → after-action/after-action-decorator.ts} +9 -9
- package/src/decorators/{after/after-metadata.ts → after-action/after-action-metadata.ts} +5 -5
- package/src/decorators/{before/before-reflector.spec.ts → after-action/after-action-reflector.spec.ts} +33 -23
- package/src/decorators/{before/before-reflector.ts → after-action/after-action-reflector.ts} +13 -9
- package/src/decorators/after-action/index.ts +3 -0
- package/src/decorators/{before/before-decorator.spec.ts → before-action/before-action-decorator.spec.ts} +19 -19
- package/src/decorators/{after/after-decorator.ts → before-action/before-action-decorator.ts} +9 -9
- package/src/decorators/before-action/before-action-metadata.ts +17 -0
- package/src/decorators/{after/after-reflector.spec.ts → before-action/before-action-reflector.spec.ts} +40 -23
- package/src/decorators/{after/after-reflector.ts → before-action/before-action-reflector.ts} +18 -9
- package/src/decorators/before-action/index.ts +3 -0
- package/src/decorators/index.ts +4 -4
- package/src/decorators/request-context/request-context-decorator.spec.ts +7 -0
- package/src/decorators/request-context/request-context-decorator.ts +4 -4
- package/src/decorators/request-data/request-data-decorator.spec.ts +45 -32
- package/src/decorators/request-data/request-data-decorator.ts +10 -10
- package/src/decorators/request-data/request-data-metadata.ts +1 -1
- package/src/decorators/rest-action/index.ts +3 -0
- package/src/decorators/rest-action/rest-action-decorator.spec.ts +325 -0
- package/src/decorators/rest-action/rest-action-decorator.ts +166 -0
- package/src/decorators/{action/action-metadata.ts → rest-action/rest-action-metadata.ts} +7 -7
- package/src/decorators/{action/action-reflector.spec.ts → rest-action/rest-action-reflector.spec.ts} +13 -13
- package/src/decorators/rest-action/rest-action-reflector.ts +41 -0
- package/src/decorators/rest-controller/index.ts +3 -0
- package/src/decorators/{controller/controller-decorator.spec.ts → rest-controller/rest-controller-decorator.spec.ts} +16 -16
- package/src/decorators/{controller/controller-decorator.ts → rest-controller/rest-controller-decorator.ts} +14 -10
- package/src/decorators/{controller/controller-metadata.ts → rest-controller/rest-controller-metadata.ts} +6 -7
- package/src/decorators/{controller/controller-reflector.spec.ts → rest-controller/rest-controller-reflector.spec.ts} +21 -12
- package/src/decorators/rest-controller/rest-controller-reflector.ts +32 -0
- package/src/errors/not-a-controller-error.ts +4 -1
- package/src/types.ts +0 -10
- package/src/utils/index.ts +0 -1
- package/README-ru.md +0 -268
- package/dist/esm/decorators/action/action-decorator.d.ts +0 -52
- package/dist/esm/decorators/action/action-decorator.js +0 -62
- package/dist/esm/decorators/action/action-decorator.spec.js +0 -59
- package/dist/esm/decorators/action/action-metadata.js +0 -5
- package/dist/esm/decorators/action/action-reflector.d.ts +0 -22
- package/dist/esm/decorators/action/index.d.ts +0 -3
- package/dist/esm/decorators/action/index.js +0 -3
- package/dist/esm/decorators/after/after-decorator.d.ts +0 -9
- package/dist/esm/decorators/after/after-metadata.js +0 -5
- package/dist/esm/decorators/after/index.d.ts +0 -3
- package/dist/esm/decorators/after/index.js +0 -3
- package/dist/esm/decorators/before/before-decorator.d.ts +0 -9
- package/dist/esm/decorators/before/before-metadata.js +0 -5
- package/dist/esm/decorators/before/index.d.ts +0 -3
- package/dist/esm/decorators/before/index.js +0 -3
- package/dist/esm/decorators/controller/controller-decorator.d.ts +0 -14
- package/dist/esm/decorators/controller/controller-metadata.js +0 -5
- package/dist/esm/decorators/controller/controller-reflector.d.ts +0 -20
- package/dist/esm/decorators/controller/controller-reflector.js +0 -24
- package/dist/esm/decorators/controller/index.d.ts +0 -3
- package/dist/esm/decorators/controller/index.js +0 -3
- package/dist/esm/utils/create-debugger.d.ts +0 -44
- package/dist/esm/utils/create-debugger.js +0 -81
- package/dist/esm/utils/create-debugger.spec.d.ts +0 -1
- package/dist/esm/utils/create-debugger.spec.js +0 -8
- package/src/decorators/action/action-decorator.spec.ts +0 -42
- package/src/decorators/action/action-decorator.ts +0 -98
- package/src/decorators/action/action-reflector.ts +0 -38
- package/src/decorators/action/index.ts +0 -3
- package/src/decorators/after/index.ts +0 -3
- package/src/decorators/before/before-metadata.ts +0 -17
- package/src/decorators/before/index.ts +0 -3
- package/src/decorators/controller/controller-reflector.ts +0 -28
- package/src/decorators/controller/index.ts +0 -3
- package/src/utils/create-debugger.spec.ts +0 -9
- package/src/utils/create-debugger.ts +0 -98
- /package/dist/esm/decorators/{action/action-decorator.spec.d.ts → after-action/after-action-decorator.spec.d.ts} +0 -0
- /package/dist/esm/decorators/{action/action-reflector.spec.d.ts → after-action/after-action-reflector.spec.d.ts} +0 -0
- /package/dist/esm/decorators/{after/after-decorator.spec.d.ts → before-action/before-action-decorator.spec.d.ts} +0 -0
- /package/dist/esm/decorators/{after/after-reflector.spec.d.ts → before-action/before-action-reflector.spec.d.ts} +0 -0
- /package/dist/esm/decorators/{before/before-decorator.spec.d.ts → rest-action/rest-action-decorator.spec.d.ts} +0 -0
- /package/dist/esm/decorators/{before/before-reflector.spec.d.ts → rest-action/rest-action-reflector.spec.d.ts} +0 -0
- /package/dist/esm/decorators/{controller/controller-decorator.spec.d.ts → rest-controller/rest-controller-decorator.spec.d.ts} +0 -0
- /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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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)
|
@@ -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
|
+
}
|