@nmshd/typescript-rest 3.0.5

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 (62) hide show
  1. package/.ci/runChecks.sh +7 -0
  2. package/.eslintrc.js +226 -0
  3. package/.github/dependabot.yml +27 -0
  4. package/.github/workflows/publish.yml +33 -0
  5. package/.github/workflows/test.yml +31 -0
  6. package/.prettierrc +27 -0
  7. package/.vscode/settings.json +31 -0
  8. package/LICENSE +22 -0
  9. package/README.md +128 -0
  10. package/dist/decorators/methods.d.ts +165 -0
  11. package/dist/decorators/methods.js +263 -0
  12. package/dist/decorators/methods.js.map +1 -0
  13. package/dist/decorators/parameters.d.ts +295 -0
  14. package/dist/decorators/parameters.js +423 -0
  15. package/dist/decorators/parameters.js.map +1 -0
  16. package/dist/decorators/services.d.ts +199 -0
  17. package/dist/decorators/services.js +367 -0
  18. package/dist/decorators/services.js.map +1 -0
  19. package/dist/server/config.d.ts +4 -0
  20. package/dist/server/config.js +43 -0
  21. package/dist/server/config.js.map +1 -0
  22. package/dist/server/model/errors.d.ts +111 -0
  23. package/dist/server/model/errors.js +178 -0
  24. package/dist/server/model/errors.js.map +1 -0
  25. package/dist/server/model/metadata.d.ts +91 -0
  26. package/dist/server/model/metadata.js +80 -0
  27. package/dist/server/model/metadata.js.map +1 -0
  28. package/dist/server/model/return-types.d.ts +86 -0
  29. package/dist/server/model/return-types.js +110 -0
  30. package/dist/server/model/return-types.js.map +1 -0
  31. package/dist/server/model/server-types.d.ts +118 -0
  32. package/dist/server/model/server-types.js +47 -0
  33. package/dist/server/model/server-types.js.map +1 -0
  34. package/dist/server/parameter-processor.d.ts +13 -0
  35. package/dist/server/parameter-processor.js +84 -0
  36. package/dist/server/parameter-processor.js.map +1 -0
  37. package/dist/server/server-container.d.ts +55 -0
  38. package/dist/server/server-container.js +432 -0
  39. package/dist/server/server-container.js.map +1 -0
  40. package/dist/server/server.d.ts +136 -0
  41. package/dist/server/server.js +278 -0
  42. package/dist/server/server.js.map +1 -0
  43. package/dist/server/service-invoker.d.ts +28 -0
  44. package/dist/server/service-invoker.js +270 -0
  45. package/dist/server/service-invoker.js.map +1 -0
  46. package/dist/typescript-rest.d.ts +9 -0
  47. package/dist/typescript-rest.js +31 -0
  48. package/dist/typescript-rest.js.map +1 -0
  49. package/package.json +113 -0
  50. package/src/decorators/methods.ts +279 -0
  51. package/src/decorators/parameters.ts +442 -0
  52. package/src/decorators/services.ts +390 -0
  53. package/src/server/config.ts +40 -0
  54. package/src/server/model/errors.ts +178 -0
  55. package/src/server/model/metadata.ts +118 -0
  56. package/src/server/model/return-types.ts +109 -0
  57. package/src/server/model/server-types.ts +130 -0
  58. package/src/server/parameter-processor.ts +105 -0
  59. package/src/server/server-container.ts +504 -0
  60. package/src/server/server.ts +340 -0
  61. package/src/server/service-invoker.ts +266 -0
  62. package/src/typescript-rest.ts +16 -0
@@ -0,0 +1,423 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Context = Context;
4
+ exports.ContextRequest = ContextRequest;
5
+ exports.ContextResponse = ContextResponse;
6
+ exports.ContextNext = ContextNext;
7
+ exports.ContextLanguage = ContextLanguage;
8
+ exports.ContextAccept = ContextAccept;
9
+ exports.PathParam = PathParam;
10
+ exports.FileParam = FileParam;
11
+ exports.FilesParam = FilesParam;
12
+ exports.QueryParam = QueryParam;
13
+ exports.HeaderParam = HeaderParam;
14
+ exports.CookieParam = CookieParam;
15
+ exports.FormParam = FormParam;
16
+ exports.Param = Param;
17
+ const _ = require("lodash");
18
+ require("reflect-metadata");
19
+ const metadata_1 = require("../server/model/metadata");
20
+ const server_container_1 = require("../server/server-container");
21
+ /**
22
+ * A decorator to be used on class properties or on service method arguments
23
+ * to inform that the decorated property or argument should be bound to the
24
+ * [[ServiceContext]] object associated to the current request.
25
+ *
26
+ * For example:
27
+ *
28
+ * ```
29
+ * @ Path('context')
30
+ * class TestService {
31
+ * @ Context
32
+ * context: ServiceContext;
33
+ * // ...
34
+ * }
35
+ * ```
36
+ *
37
+ * The field context on the above class will point to the current
38
+ * [[ServiceContext]] instance.
39
+ */
40
+ function Context(...args) {
41
+ return new ParameterDecorator('Context').withType(metadata_1.ParamType.context).decorateParameterOrProperty(args);
42
+ }
43
+ /**
44
+ * A decorator to be used on class properties or on service method arguments
45
+ * to inform that the decorated property or argument should be bound to the
46
+ * the current request.
47
+ *
48
+ * For example:
49
+ *
50
+ * ```
51
+ * @ Path('context')
52
+ * class TestService {
53
+ * @ ContextRequest
54
+ * request: express.Request;
55
+ * // ...
56
+ * }
57
+ * ```
58
+ *
59
+ * The field request on the above class will point to the current
60
+ * request.
61
+ */
62
+ function ContextRequest(...args) {
63
+ return new ParameterDecorator('ContextRequest')
64
+ .withType(metadata_1.ParamType.context_request)
65
+ .decorateParameterOrProperty(args);
66
+ }
67
+ /**
68
+ * A decorator to be used on class properties or on service method arguments
69
+ * to inform that the decorated property or argument should be bound to the
70
+ * the current response object.
71
+ *
72
+ * For example:
73
+ *
74
+ * ```
75
+ * @ Path('context')
76
+ * class TestService {
77
+ * @ ContextResponse
78
+ * response: express.Response;
79
+ * // ...
80
+ * }
81
+ * ```
82
+ *
83
+ * The field response on the above class will point to the current
84
+ * response object.
85
+ */
86
+ function ContextResponse(...args) {
87
+ return new ParameterDecorator('ContextResponse')
88
+ .withType(metadata_1.ParamType.context_response)
89
+ .decorateParameterOrProperty(args);
90
+ }
91
+ /**
92
+ * A decorator to be used on class properties or on service method arguments
93
+ * to inform that the decorated property or argument should be bound to the
94
+ * the next function.
95
+ *
96
+ * For example:
97
+ *
98
+ * ```
99
+ * @ Path('context')
100
+ * class TestService {
101
+ * @ ContextNext
102
+ * next: express.NextFunction
103
+ * // ...
104
+ * }
105
+ * ```
106
+ *
107
+ * The next function can be used to delegate to the next registered
108
+ * middleware the current request processing.
109
+ */
110
+ function ContextNext(...args) {
111
+ return new ParameterDecorator('ContextNext').withType(metadata_1.ParamType.context_next).decorateParameterOrProperty(args);
112
+ }
113
+ /**
114
+ * A decorator to be used on class properties or on service method arguments
115
+ * to inform that the decorated property or argument should be bound to the
116
+ * the current context language.
117
+ *
118
+ * For example:
119
+ *
120
+ * ```
121
+ * @ Path('context')
122
+ * class TestService {
123
+ * @ ContextLanguage
124
+ * language: string
125
+ * // ...
126
+ * }
127
+ * ```
128
+ */
129
+ function ContextLanguage(...args) {
130
+ return new ParameterDecorator('ContextLanguage')
131
+ .withType(metadata_1.ParamType.context_accept_language)
132
+ .decorateParameterOrProperty(args);
133
+ }
134
+ /**
135
+ * A decorator to be used on class properties or on service method arguments
136
+ * to inform that the decorated property or argument should be bound to the
137
+ * the preferred media type for the current request.
138
+ *
139
+ * For example:
140
+ *
141
+ * ```
142
+ * @ Path('context')
143
+ * class TestService {
144
+ * @ ContextAccept
145
+ * media: string
146
+ * // ...
147
+ * }
148
+ * ```
149
+ */
150
+ function ContextAccept(...args) {
151
+ return new ParameterDecorator('ContextAccept').withType(metadata_1.ParamType.context_accept).decorateParameterOrProperty(args);
152
+ }
153
+ /**
154
+ * Creates a mapping between a fragment of the requested path and
155
+ * a method argument.
156
+ *
157
+ * For example:
158
+ *
159
+ * ```
160
+ * @ Path('people')
161
+ * class PeopleService {
162
+ * @ GET
163
+ * @ Path(':id')
164
+ * getPerson(@ PathParam('id') id: string) {
165
+ * // ...
166
+ * }
167
+ * }
168
+ * ```
169
+ *
170
+ * Will create a service that listen for requests like:
171
+ *
172
+ * ```
173
+ * GET http://mydomain/people/123
174
+ * ```
175
+ *
176
+ * And pass 123 as the id argument on getPerson method's call.
177
+ */
178
+ function PathParam(name) {
179
+ return new ParameterDecorator('PathParam')
180
+ .withType(metadata_1.ParamType.path)
181
+ .withName(name)
182
+ .decorateNamedParameterOrProperty();
183
+ }
184
+ /**
185
+ * Creates a mapping between a file on a multipart request and a method
186
+ * argument.
187
+ *
188
+ * For example:
189
+ *
190
+ * ```
191
+ * @ Path('people')
192
+ * class PeopleService {
193
+ * @ POST
194
+ * @ Path('id')
195
+ * addAvatar(@ PathParam('id') id: string,
196
+ * @ FileParam('avatar') file: Express.Multer.File) {
197
+ * // ...
198
+ * }
199
+ * }
200
+ * ```
201
+ *
202
+ * Will create a service that listen for requests and bind the
203
+ * file with name 'avatar' on the requested form to the file
204
+ * argument on addAvatar method's call.
205
+ */
206
+ function FileParam(name) {
207
+ return new ParameterDecorator('FileParam')
208
+ .withType(metadata_1.ParamType.file)
209
+ .withName(name)
210
+ .decorateNamedParameterOrProperty();
211
+ }
212
+ /**
213
+ * Creates a mapping between a list of files on a multipart request and a method
214
+ * argument.
215
+ *
216
+ * For example:
217
+ *
218
+ * ```
219
+ * @ Path('people')
220
+ * class PeopleService {
221
+ * @ POST
222
+ * @ Path('id')
223
+ * addAvatar(@ PathParam('id') id: string,
224
+ * @ FilesParam('avatar[]') files: Array<Express.Multer.File>) {
225
+ * // ...
226
+ * }
227
+ * }
228
+ * ```
229
+ *
230
+ * Will create a service that listen for requests and bind the
231
+ * files with name 'avatar' on the request form to the file
232
+ * argument on addAvatar method's call.
233
+ */
234
+ function FilesParam(name) {
235
+ return new ParameterDecorator('FilesParam')
236
+ .withType(metadata_1.ParamType.files)
237
+ .withName(name)
238
+ .decorateNamedParameterOrProperty();
239
+ }
240
+ /**
241
+ * Creates a mapping between a query parameter on request and a method
242
+ * argument.
243
+ *
244
+ * For example:
245
+ *
246
+ * ```
247
+ * @ Path('people')
248
+ * class PeopleService {
249
+ * @ GET
250
+ * getPeople(@ QueryParam('name') name: string) {
251
+ * // ...
252
+ * }
253
+ * }
254
+ * ```
255
+ *
256
+ * Will create a service that listen for requests like:
257
+ *
258
+ * ```
259
+ * GET http://mydomain/people?name=joe
260
+ * ```
261
+ *
262
+ * And pass 'joe' as the name argument on getPerson method's call.
263
+ */
264
+ function QueryParam(name) {
265
+ return new ParameterDecorator('QueryParam')
266
+ .withType(metadata_1.ParamType.query)
267
+ .withName(name)
268
+ .decorateNamedParameterOrProperty();
269
+ }
270
+ /**
271
+ * Creates a mapping between a header on request and a method
272
+ * argument.
273
+ *
274
+ * For example:
275
+ *
276
+ * ```
277
+ * @ Path('people')
278
+ * class PeopleService {
279
+ * @ GET
280
+ * getPeople(@ HeaderParam('header') header: string) {
281
+ * // ...
282
+ * }
283
+ * }
284
+ * ```
285
+ *
286
+ * Will create a service that listen for requests and bind the
287
+ * header called 'header' to the header argument on getPerson method's call.
288
+ */
289
+ function HeaderParam(name) {
290
+ return new ParameterDecorator('HeaderParam')
291
+ .withType(metadata_1.ParamType.header)
292
+ .withName(name)
293
+ .decorateNamedParameterOrProperty();
294
+ }
295
+ /**
296
+ * Creates a mapping between a cookie on request and a method
297
+ * argument.
298
+ *
299
+ * For example:
300
+ *
301
+ * ```
302
+ * @ Path('people')
303
+ * class PeopleService {
304
+ * @ GET
305
+ * getPeople(@ CookieParam('cookie') cookie: string) {
306
+ * // ...
307
+ * }
308
+ * }
309
+ * ```
310
+ *
311
+ * Will create a service that listen for requests and bind the
312
+ * cookie called 'cookie' to the cookie argument on getPerson method's call.
313
+ */
314
+ function CookieParam(name) {
315
+ return new ParameterDecorator('CookieParam')
316
+ .withType(metadata_1.ParamType.cookie)
317
+ .withName(name)
318
+ .decorateNamedParameterOrProperty();
319
+ }
320
+ /**
321
+ * Creates a mapping between a form parameter on request and a method
322
+ * argument.
323
+ *
324
+ * For example:
325
+ *
326
+ * ```
327
+ * @ Path('people')
328
+ * class PeopleService {
329
+ * @ GET
330
+ * getPeople(@ FormParam('name') name: string) {
331
+ * // ...
332
+ * }
333
+ * }
334
+ * ```
335
+ *
336
+ * Will create a service that listen for requests and bind the
337
+ * request paramenter called 'name' to the name argument on getPerson
338
+ * method's call.
339
+ */
340
+ function FormParam(name) {
341
+ return new ParameterDecorator('FormParam')
342
+ .withType(metadata_1.ParamType.form)
343
+ .withName(name)
344
+ .decorateNamedParameterOrProperty();
345
+ }
346
+ /**
347
+ * Creates a mapping between a parameter on request and a method
348
+ * argument.
349
+ *
350
+ * For example:
351
+ *
352
+ * ```
353
+ * @ Path('people')
354
+ * class PeopleService {
355
+ * @ GET
356
+ * getPeople(@ Param('name') name: string) {
357
+ * // ...
358
+ * }
359
+ * }
360
+ * ```
361
+ *
362
+ * Will create a service that listen for requests and bind the
363
+ * request paramenter called 'name' to the name argument on getPerson
364
+ * method's call. It will work to query parameters or form parameters
365
+ * received in the current request.
366
+ */
367
+ function Param(name) {
368
+ return new ParameterDecorator('Param').withType(metadata_1.ParamType.param).withName(name).decorateNamedParameterOrProperty();
369
+ }
370
+ class ParameterDecorator {
371
+ constructor(decorator) {
372
+ this.nameRequired = false;
373
+ this.name = null;
374
+ this.decorator = decorator;
375
+ }
376
+ withType(paramType) {
377
+ this.paramType = paramType;
378
+ return this;
379
+ }
380
+ withName(name) {
381
+ this.nameRequired = true;
382
+ this.name = name ? name.trim() : '';
383
+ return this;
384
+ }
385
+ decorateParameterOrProperty(args) {
386
+ if (!this.nameRequired || this.name) {
387
+ args = _.without(args, undefined);
388
+ if (args.length < 3 || typeof args[2] === 'undefined') {
389
+ return this.decorateProperty(args[0], args[1]);
390
+ }
391
+ else if (args.length === 3 && typeof args[2] === 'number') {
392
+ return this.decorateParameter(args[0], args[1], args[2]);
393
+ }
394
+ }
395
+ throw new Error(`Invalid @${this.decorator} Decorator declaration.`);
396
+ }
397
+ decorateNamedParameterOrProperty() {
398
+ return (...args) => {
399
+ return this.decorateParameterOrProperty(args);
400
+ };
401
+ }
402
+ decorateParameter(target, propertyKey, parameterIndex) {
403
+ const serviceMethod = server_container_1.ServerContainer.get().registerServiceMethod(target.constructor, propertyKey);
404
+ if (serviceMethod) {
405
+ // does not intercept constructor
406
+ const paramTypes = Reflect.getOwnMetadata('design:paramtypes', target, propertyKey);
407
+ while (paramTypes && serviceMethod.parameters.length < paramTypes.length) {
408
+ serviceMethod.parameters.push(new metadata_1.MethodParam(null, paramTypes[serviceMethod.parameters.length], metadata_1.ParamType.body));
409
+ }
410
+ serviceMethod.parameters[parameterIndex] = new metadata_1.MethodParam(this.name, paramTypes[parameterIndex], this.paramType);
411
+ }
412
+ }
413
+ decorateProperty(target, key) {
414
+ const classData = server_container_1.ServerContainer.get().registerServiceClass(target.constructor);
415
+ const propertyType = Reflect.getMetadata('design:type', target, key);
416
+ classData.addProperty(key, {
417
+ name: this.name,
418
+ propertyType: propertyType,
419
+ type: this.paramType
420
+ });
421
+ }
422
+ }
423
+ //# sourceMappingURL=parameters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parameters.js","sourceRoot":"","sources":["../../src/decorators/parameters.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AA0Bb,0BAEC;AAqBD,wCAIC;AAqBD,0CAIC;AAqBD,kCAEC;AAkBD,0CAIC;AAkBD,sCAEC;AA2BD,8BAKC;AAwBD,8BAKC;AAwBD,gCAKC;AA0BD,gCAKC;AAqBD,kCAKC;AAqBD,kCAKC;AAsBD,8BAKC;AAuBD,sBAEC;AA9WD,4BAA4B;AAC5B,4BAA0B;AAC1B,uDAA+F;AAC/F,iEAA6D;AAE7D;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,OAAO,CAAC,GAAG,IAAgB;IACvC,OAAO,IAAI,kBAAkB,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,oBAAS,CAAC,OAAO,CAAC,CAAC,2BAA2B,CAAC,IAAI,CAAC,CAAC;AAC3G,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,cAAc,CAAC,GAAG,IAAgB;IAC9C,OAAO,IAAI,kBAAkB,CAAC,gBAAgB,CAAC;SAC1C,QAAQ,CAAC,oBAAS,CAAC,eAAe,CAAC;SACnC,2BAA2B,CAAC,IAAI,CAAC,CAAC;AAC3C,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,eAAe,CAAC,GAAG,IAAgB;IAC/C,OAAO,IAAI,kBAAkB,CAAC,iBAAiB,CAAC;SAC3C,QAAQ,CAAC,oBAAS,CAAC,gBAAgB,CAAC;SACpC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AI,EAAE,IAAI,CAAC,SAAS;SACvB,CAAC,CAAC;IACP,CAAC;CACJ"}
@@ -0,0 +1,199 @@
1
+ import 'reflect-metadata';
2
+ import { ParserType, ServiceProcessor } from '../server/model/server-types';
3
+ /**
4
+ * A decorator to tell the [[Server]] that a class or a method
5
+ * should be bound to a given path.
6
+ *
7
+ * For example:
8
+ *
9
+ * ```
10
+ * @ Path('people')
11
+ * class PeopleService {
12
+ * @ PUT
13
+ * @ Path(':id')
14
+ * savePerson(person:Person) {
15
+ * // ...
16
+ * }
17
+ *
18
+ * @ GET
19
+ * @ Path(':id')
20
+ * getPerson():Person {
21
+ * // ...
22
+ * }
23
+ * }
24
+ * ```
25
+ *
26
+ * Will create services that listen for requests like:
27
+ *
28
+ * ```
29
+ * PUT http://mydomain/people/123 or
30
+ * GET http://mydomain/people/123
31
+ * ```
32
+ */
33
+ export declare function Path(path: string): (...args: Array<any>) => void;
34
+ /**
35
+ * A decorator to tell the [[Server]] that a class or a method
36
+ * should include a determined role
37
+ * or all authorized users (token) using passport
38
+ *
39
+ * For example:
40
+ *
41
+ * ```
42
+ * @ Path('people')
43
+ * @ Security()
44
+ * class PeopleService {
45
+ * @ PUT
46
+ * @ Path(':id', true)
47
+ * @ Security(['ROLE_ADMIN'])
48
+ * savePerson(person:Person) {
49
+ * // ...
50
+ * }
51
+ *
52
+ * @ GET
53
+ * @ Path(':id', true)
54
+ * getPerson():Person {
55
+ * // ...
56
+ * }
57
+ * }
58
+ * ```
59
+ *
60
+ * Will create services that listen for requests like:
61
+ *
62
+ * ```
63
+ * PUT http://mydomain/people/123 (Only for ADMIN roles) or
64
+ * GET http://mydomain/people/123 (For all authorized users)
65
+ * ```
66
+ */
67
+ export declare function Security(roles?: string | Array<string>, name?: string): (...args: Array<any>) => void;
68
+ /**
69
+ * A decorator to tell the [[Server]] that a class or a method
70
+ * should include a pre-processor in its request pipelines.
71
+ *
72
+ * For example:
73
+ * ```
74
+ * function validator(req: express.Request): express.Request {
75
+ * if (!req.body.userId) {
76
+ * throw new Errors.BadRequestError("userId not present");
77
+ * }
78
+ * }
79
+ * ```
80
+ * And:
81
+ *
82
+ * ```
83
+ * @ Path('people')
84
+ * class PeopleService {
85
+ * @ PUT
86
+ * @ Path(':id')
87
+ * @ PreProcessor(validator)
88
+ * savePerson(person:Person) {
89
+ * // ...
90
+ * }
91
+ * }
92
+ * ```
93
+ */
94
+ export declare function PreProcessor(preprocessor: ServiceProcessor): (...args: Array<any>) => void;
95
+ /**
96
+ * A decorator to tell the [[Server]] that a class or a method
97
+ * should include a post-processor in its request pipelines.
98
+ *
99
+ * For example:
100
+ * ```
101
+ * function processor(req: express.Request): express.Request {
102
+ * if (!req.body.userId) {
103
+ * throw new Errors.BadRequestError("userId not present");
104
+ * }
105
+ * }
106
+ * ```
107
+ * And:
108
+ *
109
+ * ```
110
+ * @ Path('people')
111
+ * class PeopleService {
112
+ * @ PUT
113
+ * @ Path(':id')
114
+ * @ PostProcessor(validator)
115
+ * savePerson(person:Person) {
116
+ * // ...
117
+ * }
118
+ * }
119
+ * ```
120
+ */
121
+ export declare function PostProcessor(postprocessor: ServiceProcessor): (...args: Array<any>) => void;
122
+ /**
123
+ * A decorator to tell the [[Server]] that a class or a method
124
+ * should only accept requests from clients that accepts one of
125
+ * the supported languages.
126
+ *
127
+ * For example:
128
+ *
129
+ * ```
130
+ * @ Path('accept')
131
+ * @ AcceptLanguage('en', 'pt-BR')
132
+ * class TestAcceptService {
133
+ * // ...
134
+ * }
135
+ * ```
136
+ *
137
+ * Will reject requests that only accepts languages that are not
138
+ * English or Brazilian portuguese
139
+ *
140
+ * If the language requested is not supported, a status code 406 returned
141
+ */
142
+ export declare function AcceptLanguage(...languages: Array<string>): (...args: Array<any>) => void;
143
+ /**
144
+ * A decorator to tell the [[Server]] that a class or a method
145
+ * should only accept requests from clients that accepts one of
146
+ * the supported mime types.
147
+ *
148
+ * For example:
149
+ *
150
+ * ```
151
+ * @ Path('accept')
152
+ * @ Accept('application/json')
153
+ * class TestAcceptService {
154
+ * // ...
155
+ * }
156
+ * ```
157
+ *
158
+ * Will reject requests that only accepts mime types that are not
159
+ * 'application/json'
160
+ *
161
+ * If the mime type requested is not supported, a status code 406 returned
162
+ */
163
+ export declare function Accept(...accepts: Array<string>): (...args: Array<any>) => void;
164
+ /**
165
+ * A decorator to inform options to pe passed to bodyParser.
166
+ * You can inform any property accepted by
167
+ * [[bodyParser]](https://www.npmjs.com/package/body-parser)
168
+ */
169
+ export declare function BodyOptions(options: any): (...args: Array<any>) => void;
170
+ /**
171
+ * A decorator to inform the type of parser to be used to parse the body.
172
+ * The default type is json.
173
+ */
174
+ export declare function BodyType(type: ParserType): (...args: Array<any>) => void;
175
+ /**
176
+ * A decorator to inform that server should ignore other middlewares.
177
+ * It makes server does not call next function after service invocation.
178
+ */
179
+ export declare function IgnoreNextMiddlewares(...args: Array<any>): void;
180
+ /**
181
+ * Mark the annotated service class as an abstract service. Abstract services has none of its
182
+ * methods exposed as rest enpoints, even if the class is in the services list to be exposed.
183
+ *
184
+ * For example:
185
+ *
186
+ * ```
187
+ * @ Abstract
188
+ * abstract class PeopleService {
189
+ * @ GET
190
+ * getPeople(@ Param('name') name: string) {
191
+ * // ...
192
+ * }
193
+ * }
194
+ * ```
195
+ *
196
+ * No endpoint will be registered for PeopleService. It is useful if you only plain that subclasses of
197
+ * PeopleService exposes the getPeople method.
198
+ */
199
+ export declare function Abstract(...args: Array<any>): void;