@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,263 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GET = GET;
4
+ exports.POST = POST;
5
+ exports.PUT = PUT;
6
+ exports.DELETE = DELETE;
7
+ exports.HEAD = HEAD;
8
+ exports.OPTIONS = OPTIONS;
9
+ exports.PATCH = PATCH;
10
+ require("reflect-metadata");
11
+ const metadata_1 = require("../server/model/metadata");
12
+ const server_types_1 = require("../server/model/server-types");
13
+ const server_container_1 = require("../server/server-container");
14
+ /**
15
+ * A decorator to tell the [[Server]] that a method
16
+ * should be called to process HTTP GET requests.
17
+ *
18
+ * For example:
19
+ *
20
+ * ```
21
+ * @ Path('people')
22
+ * class PeopleService {
23
+ * @ GET
24
+ * getPeople() {
25
+ * // ...
26
+ * }
27
+ * }
28
+ * ```
29
+ *
30
+ * Will create a service that listen for requests like:
31
+ *
32
+ * ```
33
+ * GET http://mydomain/people
34
+ * ```
35
+ */
36
+ function GET(target, propertyKey) {
37
+ new MethodDecorator(server_types_1.HttpMethod.GET).decorateMethod(target, propertyKey);
38
+ }
39
+ /**
40
+ * A decorator to tell the [[Server]] that a method
41
+ * should be called to process HTTP POST requests.
42
+ *
43
+ * For example:
44
+ *
45
+ * ```
46
+ * @ Path('people')
47
+ * class PeopleService {
48
+ * @ POST
49
+ * addPerson() {
50
+ * // ...
51
+ * }
52
+ * }
53
+ * ```
54
+ *
55
+ * Will create a service that listen for requests like:
56
+ *
57
+ * ```
58
+ * POST http://mydomain/people
59
+ * ```
60
+ */
61
+ function POST(target, propertyKey) {
62
+ new MethodDecorator(server_types_1.HttpMethod.POST).decorateMethod(target, propertyKey);
63
+ }
64
+ /**
65
+ * A decorator to tell the [[Server]] that a method
66
+ * should be called to process HTTP PUT requests.
67
+ *
68
+ * For example:
69
+ *
70
+ * ```
71
+ * @ Path('people')
72
+ * class PeopleService {
73
+ * @ PUT
74
+ * @ Path(':id')
75
+ * savePerson(person: Person) {
76
+ * // ...
77
+ * }
78
+ * }
79
+ * ```
80
+ *
81
+ * Will create a service that listen for requests like:
82
+ *
83
+ * ```
84
+ * PUT http://mydomain/people/123
85
+ * ```
86
+ */
87
+ function PUT(target, propertyKey) {
88
+ new MethodDecorator(server_types_1.HttpMethod.PUT).decorateMethod(target, propertyKey);
89
+ }
90
+ /**
91
+ * A decorator to tell the [[Server]] that a method
92
+ * should be called to process HTTP DELETE requests.
93
+ *
94
+ * For example:
95
+ *
96
+ * ```
97
+ * @ Path('people')
98
+ * class PeopleService {
99
+ * @ DELETE
100
+ * @ Path(':id')
101
+ * removePerson(@ PathParam('id')id: string) {
102
+ * // ...
103
+ * }
104
+ * }
105
+ * ```
106
+ *
107
+ * Will create a service that listen for requests like:
108
+ *
109
+ * ```
110
+ * PUT http://mydomain/people/123
111
+ * ```
112
+ */
113
+ function DELETE(target, propertyKey) {
114
+ new MethodDecorator(server_types_1.HttpMethod.DELETE).decorateMethod(target, propertyKey);
115
+ }
116
+ /**
117
+ * A decorator to tell the [[Server]] that a method
118
+ * should be called to process HTTP HEAD requests.
119
+ *
120
+ * For example:
121
+ *
122
+ * ```
123
+ * @ Path('people')
124
+ * class PeopleService {
125
+ * @ HEAD
126
+ * headPerson() {
127
+ * // ...
128
+ * }
129
+ * }
130
+ * ```
131
+ *
132
+ * Will create a service that listen for requests like:
133
+ *
134
+ * ```
135
+ * HEAD http://mydomain/people/123
136
+ * ```
137
+ */
138
+ function HEAD(target, propertyKey) {
139
+ new MethodDecorator(server_types_1.HttpMethod.HEAD).decorateMethod(target, propertyKey);
140
+ }
141
+ /**
142
+ * A decorator to tell the [[Server]] that a method
143
+ * should be called to process HTTP OPTIONS requests.
144
+ *
145
+ * For example:
146
+ *
147
+ * ```
148
+ * @ Path('people')
149
+ * class PeopleService {
150
+ * @ OPTIONS
151
+ * optionsPerson() {
152
+ * // ...
153
+ * }
154
+ * }
155
+ * ```
156
+ *
157
+ * Will create a service that listen for requests like:
158
+ *
159
+ * ```
160
+ * OPTIONS http://mydomain/people/123
161
+ * ```
162
+ */
163
+ function OPTIONS(target, propertyKey) {
164
+ new MethodDecorator(server_types_1.HttpMethod.OPTIONS).decorateMethod(target, propertyKey);
165
+ }
166
+ /**
167
+ * A decorator to tell the [[Server]] that a method
168
+ * should be called to process HTTP PATCH requests.
169
+ *
170
+ * For example:
171
+ *
172
+ * ```
173
+ * @ Path('people')
174
+ * class PeopleService {
175
+ * @ PATCH
176
+ * @ Path(':id')
177
+ * savePerson(person: Person) {
178
+ * // ...
179
+ * }
180
+ * }
181
+ * ```
182
+ *
183
+ * Will create a service that listen for requests like:
184
+ *
185
+ * ```
186
+ * PATCH http://mydomain/people/123
187
+ * ```
188
+ */
189
+ function PATCH(target, propertyKey) {
190
+ new MethodDecorator(server_types_1.HttpMethod.PATCH).decorateMethod(target, propertyKey);
191
+ }
192
+ class MethodDecorator {
193
+ constructor(httpMethod) {
194
+ this.httpMethod = httpMethod;
195
+ }
196
+ decorateMethod(target, propertyKey) {
197
+ const serviceMethod = server_container_1.ServerContainer.get().registerServiceMethod(target.constructor, propertyKey);
198
+ if (serviceMethod) {
199
+ // does not intercept constructor
200
+ if (!serviceMethod.httpMethod) {
201
+ serviceMethod.httpMethod = this.httpMethod;
202
+ this.processServiceMethod(target, propertyKey, serviceMethod);
203
+ }
204
+ else if (serviceMethod.httpMethod !== this.httpMethod) {
205
+ throw new Error('Method is already annotated with @' +
206
+ server_types_1.HttpMethod[serviceMethod.httpMethod] +
207
+ '. You can only map a method to one HTTP verb.');
208
+ }
209
+ }
210
+ }
211
+ /**
212
+ * Extract metadata for rest methods
213
+ */
214
+ processServiceMethod(target, propertyKey, serviceMethod) {
215
+ serviceMethod.name = propertyKey;
216
+ const paramTypes = Reflect.getOwnMetadata('design:paramtypes', target, propertyKey);
217
+ this.registerUndecoratedParameters(paramTypes, serviceMethod);
218
+ serviceMethod.parameters.forEach((param) => {
219
+ const processor = MethodDecorator.PROCESSORS.get(param.paramType);
220
+ if (processor) {
221
+ processor(serviceMethod, param);
222
+ }
223
+ });
224
+ }
225
+ registerUndecoratedParameters(paramTypes, serviceMethod) {
226
+ while (paramTypes && paramTypes.length > serviceMethod.parameters.length) {
227
+ serviceMethod.parameters.push(new metadata_1.MethodParam(null, paramTypes[serviceMethod.parameters.length], metadata_1.ParamType.body));
228
+ }
229
+ }
230
+ }
231
+ MethodDecorator.PROCESSORS = getParameterProcessors();
232
+ function getParameterProcessors() {
233
+ const result = new Map();
234
+ result.set(metadata_1.ParamType.cookie, (serviceMethod) => {
235
+ serviceMethod.mustParseCookies = true;
236
+ });
237
+ result.set(metadata_1.ParamType.file, (serviceMethod, param) => {
238
+ serviceMethod.files.push(new metadata_1.FileParam(param.name, true));
239
+ });
240
+ result.set(metadata_1.ParamType.files, (serviceMethod, param) => {
241
+ serviceMethod.files.push(new metadata_1.FileParam(param.name, false));
242
+ });
243
+ result.set(metadata_1.ParamType.param, (serviceMethod) => {
244
+ serviceMethod.acceptMultiTypedParam = true;
245
+ });
246
+ result.set(metadata_1.ParamType.form, (serviceMethod) => {
247
+ if (serviceMethod.mustParseBody) {
248
+ throw Error('Can not use form parameters with a body parameter on the same method.');
249
+ }
250
+ serviceMethod.mustParseForms = true;
251
+ });
252
+ result.set(metadata_1.ParamType.body, (serviceMethod) => {
253
+ if (serviceMethod.mustParseForms) {
254
+ throw Error('Can not use form parameters with a body parameter on the same method.');
255
+ }
256
+ if (serviceMethod.mustParseBody) {
257
+ throw Error('Can not use more than one body parameter on the same method.');
258
+ }
259
+ serviceMethod.mustParseBody = true;
260
+ });
261
+ return result;
262
+ }
263
+ //# sourceMappingURL=methods.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"methods.js","sourceRoot":"","sources":["../../src/decorators/methods.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AA8Bb,kBAEC;AAwBD,oBAEC;AAyBD,kBAEC;AAyBD,wBAEC;AAwBD,oBAEC;AAwBD,0BAEC;AAyBD,sBAEC;AA5LD,4BAA0B;AAC1B,uDAA4F;AAC5F,+DAA0D;AAC1D,iEAA6D;AAE7D;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,SAAgB,GAAG,CAAC,MAAW,EAAE,WAAmB;IAChD,IAAI,eAAe,CAAC,yBAAU,CAAC,GAAG,CAAC,CAAC,cAAc,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;AAC5E,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,SAAgB,IAAI,CAAC,MAAW,EAAE,WAAmB;IACjD,IAAI,eAAe,CAAC,yBAAU,CAAC,IAAI,CAAC,CAAC,cAAc,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;AAC7E,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,SAAgB,GAAG,CAAC,MAAW,EAAE,WAAmB;IAChD,IAAI,eAAe,CAAC,yBAAU,CAAC,GAAG,CAAC,CAAC,cAAc,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;AAC5E,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,SAAgB,MAAM,CAAC,MAAW,EAAE,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OAAO,MAAM,CAAC;AAClB,CAAC"}
@@ -0,0 +1,295 @@
1
+ import 'reflect-metadata';
2
+ /**
3
+ * A decorator to be used on class properties or on service method arguments
4
+ * to inform that the decorated property or argument should be bound to the
5
+ * [[ServiceContext]] object associated to the current request.
6
+ *
7
+ * For example:
8
+ *
9
+ * ```
10
+ * @ Path('context')
11
+ * class TestService {
12
+ * @ Context
13
+ * context: ServiceContext;
14
+ * // ...
15
+ * }
16
+ * ```
17
+ *
18
+ * The field context on the above class will point to the current
19
+ * [[ServiceContext]] instance.
20
+ */
21
+ export declare function Context(...args: Array<any>): void;
22
+ /**
23
+ * A decorator to be used on class properties or on service method arguments
24
+ * to inform that the decorated property or argument should be bound to the
25
+ * the current request.
26
+ *
27
+ * For example:
28
+ *
29
+ * ```
30
+ * @ Path('context')
31
+ * class TestService {
32
+ * @ ContextRequest
33
+ * request: express.Request;
34
+ * // ...
35
+ * }
36
+ * ```
37
+ *
38
+ * The field request on the above class will point to the current
39
+ * request.
40
+ */
41
+ export declare function ContextRequest(...args: Array<any>): void;
42
+ /**
43
+ * A decorator to be used on class properties or on service method arguments
44
+ * to inform that the decorated property or argument should be bound to the
45
+ * the current response object.
46
+ *
47
+ * For example:
48
+ *
49
+ * ```
50
+ * @ Path('context')
51
+ * class TestService {
52
+ * @ ContextResponse
53
+ * response: express.Response;
54
+ * // ...
55
+ * }
56
+ * ```
57
+ *
58
+ * The field response on the above class will point to the current
59
+ * response object.
60
+ */
61
+ export declare function ContextResponse(...args: Array<any>): void;
62
+ /**
63
+ * A decorator to be used on class properties or on service method arguments
64
+ * to inform that the decorated property or argument should be bound to the
65
+ * the next function.
66
+ *
67
+ * For example:
68
+ *
69
+ * ```
70
+ * @ Path('context')
71
+ * class TestService {
72
+ * @ ContextNext
73
+ * next: express.NextFunction
74
+ * // ...
75
+ * }
76
+ * ```
77
+ *
78
+ * The next function can be used to delegate to the next registered
79
+ * middleware the current request processing.
80
+ */
81
+ export declare function ContextNext(...args: Array<any>): void;
82
+ /**
83
+ * A decorator to be used on class properties or on service method arguments
84
+ * to inform that the decorated property or argument should be bound to the
85
+ * the current context language.
86
+ *
87
+ * For example:
88
+ *
89
+ * ```
90
+ * @ Path('context')
91
+ * class TestService {
92
+ * @ ContextLanguage
93
+ * language: string
94
+ * // ...
95
+ * }
96
+ * ```
97
+ */
98
+ export declare function ContextLanguage(...args: Array<any>): void;
99
+ /**
100
+ * A decorator to be used on class properties or on service method arguments
101
+ * to inform that the decorated property or argument should be bound to the
102
+ * the preferred media type for the current request.
103
+ *
104
+ * For example:
105
+ *
106
+ * ```
107
+ * @ Path('context')
108
+ * class TestService {
109
+ * @ ContextAccept
110
+ * media: string
111
+ * // ...
112
+ * }
113
+ * ```
114
+ */
115
+ export declare function ContextAccept(...args: Array<any>): void;
116
+ /**
117
+ * Creates a mapping between a fragment of the requested path and
118
+ * a method argument.
119
+ *
120
+ * For example:
121
+ *
122
+ * ```
123
+ * @ Path('people')
124
+ * class PeopleService {
125
+ * @ GET
126
+ * @ Path(':id')
127
+ * getPerson(@ PathParam('id') id: string) {
128
+ * // ...
129
+ * }
130
+ * }
131
+ * ```
132
+ *
133
+ * Will create a service that listen for requests like:
134
+ *
135
+ * ```
136
+ * GET http://mydomain/people/123
137
+ * ```
138
+ *
139
+ * And pass 123 as the id argument on getPerson method's call.
140
+ */
141
+ export declare function PathParam(name: string): (...args: Array<any>) => void;
142
+ /**
143
+ * Creates a mapping between a file on a multipart request and a method
144
+ * argument.
145
+ *
146
+ * For example:
147
+ *
148
+ * ```
149
+ * @ Path('people')
150
+ * class PeopleService {
151
+ * @ POST
152
+ * @ Path('id')
153
+ * addAvatar(@ PathParam('id') id: string,
154
+ * @ FileParam('avatar') file: Express.Multer.File) {
155
+ * // ...
156
+ * }
157
+ * }
158
+ * ```
159
+ *
160
+ * Will create a service that listen for requests and bind the
161
+ * file with name 'avatar' on the requested form to the file
162
+ * argument on addAvatar method's call.
163
+ */
164
+ export declare function FileParam(name: string): (...args: Array<any>) => void;
165
+ /**
166
+ * Creates a mapping between a list of files on a multipart request and a method
167
+ * argument.
168
+ *
169
+ * For example:
170
+ *
171
+ * ```
172
+ * @ Path('people')
173
+ * class PeopleService {
174
+ * @ POST
175
+ * @ Path('id')
176
+ * addAvatar(@ PathParam('id') id: string,
177
+ * @ FilesParam('avatar[]') files: Array<Express.Multer.File>) {
178
+ * // ...
179
+ * }
180
+ * }
181
+ * ```
182
+ *
183
+ * Will create a service that listen for requests and bind the
184
+ * files with name 'avatar' on the request form to the file
185
+ * argument on addAvatar method's call.
186
+ */
187
+ export declare function FilesParam(name: string): (...args: Array<any>) => void;
188
+ /**
189
+ * Creates a mapping between a query parameter on request and a method
190
+ * argument.
191
+ *
192
+ * For example:
193
+ *
194
+ * ```
195
+ * @ Path('people')
196
+ * class PeopleService {
197
+ * @ GET
198
+ * getPeople(@ QueryParam('name') name: string) {
199
+ * // ...
200
+ * }
201
+ * }
202
+ * ```
203
+ *
204
+ * Will create a service that listen for requests like:
205
+ *
206
+ * ```
207
+ * GET http://mydomain/people?name=joe
208
+ * ```
209
+ *
210
+ * And pass 'joe' as the name argument on getPerson method's call.
211
+ */
212
+ export declare function QueryParam(name: string): (...args: Array<any>) => void;
213
+ /**
214
+ * Creates a mapping between a header on request and a method
215
+ * argument.
216
+ *
217
+ * For example:
218
+ *
219
+ * ```
220
+ * @ Path('people')
221
+ * class PeopleService {
222
+ * @ GET
223
+ * getPeople(@ HeaderParam('header') header: string) {
224
+ * // ...
225
+ * }
226
+ * }
227
+ * ```
228
+ *
229
+ * Will create a service that listen for requests and bind the
230
+ * header called 'header' to the header argument on getPerson method's call.
231
+ */
232
+ export declare function HeaderParam(name: string): (...args: Array<any>) => void;
233
+ /**
234
+ * Creates a mapping between a cookie on request and a method
235
+ * argument.
236
+ *
237
+ * For example:
238
+ *
239
+ * ```
240
+ * @ Path('people')
241
+ * class PeopleService {
242
+ * @ GET
243
+ * getPeople(@ CookieParam('cookie') cookie: string) {
244
+ * // ...
245
+ * }
246
+ * }
247
+ * ```
248
+ *
249
+ * Will create a service that listen for requests and bind the
250
+ * cookie called 'cookie' to the cookie argument on getPerson method's call.
251
+ */
252
+ export declare function CookieParam(name: string): (...args: Array<any>) => void;
253
+ /**
254
+ * Creates a mapping between a form parameter on request and a method
255
+ * argument.
256
+ *
257
+ * For example:
258
+ *
259
+ * ```
260
+ * @ Path('people')
261
+ * class PeopleService {
262
+ * @ GET
263
+ * getPeople(@ FormParam('name') name: string) {
264
+ * // ...
265
+ * }
266
+ * }
267
+ * ```
268
+ *
269
+ * Will create a service that listen for requests and bind the
270
+ * request paramenter called 'name' to the name argument on getPerson
271
+ * method's call.
272
+ */
273
+ export declare function FormParam(name: string): (...args: Array<any>) => void;
274
+ /**
275
+ * Creates a mapping between a parameter on request and a method
276
+ * argument.
277
+ *
278
+ * For example:
279
+ *
280
+ * ```
281
+ * @ Path('people')
282
+ * class PeopleService {
283
+ * @ GET
284
+ * getPeople(@ Param('name') name: string) {
285
+ * // ...
286
+ * }
287
+ * }
288
+ * ```
289
+ *
290
+ * Will create a service that listen for requests and bind the
291
+ * request paramenter called 'name' to the name argument on getPerson
292
+ * method's call. It will work to query parameters or form parameters
293
+ * received in the current request.
294
+ */
295
+ export declare function Param(name: string): (...args: Array<any>) => void;