@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,178 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NotImplementedError = exports.InternalServerError = exports.UnprocessableEntityError = exports.UnsupportedMediaTypeError = exports.GoneError = exports.ConflictError = exports.NotAcceptableError = exports.MethodNotAllowedError = exports.NotFoundError = exports.ForbiddenError = exports.UnauthorizedError = exports.BadRequestError = exports.HttpError = void 0;
4
+ /**
5
+ * The Base class for all HTTP errors
6
+ */
7
+ class HttpError extends Error {
8
+ constructor(name, message) {
9
+ super(message);
10
+ this.message = message;
11
+ this.name = name;
12
+ }
13
+ }
14
+ exports.HttpError = HttpError;
15
+ /**
16
+ * Represents a BAD REQUEST error. The request could not be understood by the
17
+ * server due to malformed syntax. The client SHOULD NOT repeat the request
18
+ * without modifications.
19
+ */
20
+ class BadRequestError extends HttpError {
21
+ constructor(message) {
22
+ super('BadRequestError', message || 'Bad Request');
23
+ Object.setPrototypeOf(this, BadRequestError.prototype);
24
+ this.statusCode = 400;
25
+ }
26
+ }
27
+ exports.BadRequestError = BadRequestError;
28
+ /**
29
+ * Represents an UNAUTHORIZED error. The request requires user authentication. The response
30
+ * MUST include a WWW-Authenticate header field containing a challenge applicable to the
31
+ * requested resource.
32
+ */
33
+ class UnauthorizedError extends HttpError {
34
+ constructor(message) {
35
+ super('UnauthorizedError', message || 'Unauthorized');
36
+ Object.setPrototypeOf(this, UnauthorizedError.prototype);
37
+ this.statusCode = 401;
38
+ }
39
+ }
40
+ exports.UnauthorizedError = UnauthorizedError;
41
+ /**
42
+ * Represents a FORBIDDEN error. The server understood the request, but is refusing to
43
+ * fulfill it. Authorization will not help and the request SHOULD NOT be repeated.
44
+ */
45
+ class ForbiddenError extends HttpError {
46
+ constructor(message) {
47
+ super('ForbiddenError', message || 'Forbidden');
48
+ Object.setPrototypeOf(this, ForbiddenError.prototype);
49
+ this.statusCode = 403;
50
+ }
51
+ }
52
+ exports.ForbiddenError = ForbiddenError;
53
+ /**
54
+ * Represents a NOT FOUND error. The server has not found anything matching
55
+ * the Request-URI. No indication is given of whether the condition is temporary
56
+ * or permanent. The 410 (GoneError) status code SHOULD be used if the server knows,
57
+ * through some internally configurable mechanism, that an old resource is permanently
58
+ * unavailable and has no forwarding address.
59
+ *
60
+ * This error is commonly used when
61
+ * the server does not wish to reveal exactly why the request has been refused,
62
+ * or when no other response is applicable.
63
+ */
64
+ class NotFoundError extends HttpError {
65
+ constructor(message) {
66
+ super('NotFoundError', message || 'Not Found');
67
+ Object.setPrototypeOf(this, NotFoundError.prototype);
68
+ this.statusCode = 404;
69
+ }
70
+ }
71
+ exports.NotFoundError = NotFoundError;
72
+ /**
73
+ * Represents a METHOD NOT ALLOWED error. The method specified in the Request-Line is not allowed for
74
+ * the resource identified by the Request-URI. The response MUST include an Allow header
75
+ * containing a list of valid methods for the requested resource.
76
+ */
77
+ class MethodNotAllowedError extends HttpError {
78
+ constructor(message) {
79
+ super('MethodNotAllowedError', message || 'Method Not Allowed');
80
+ Object.setPrototypeOf(this, MethodNotAllowedError.prototype);
81
+ this.statusCode = 405;
82
+ }
83
+ }
84
+ exports.MethodNotAllowedError = MethodNotAllowedError;
85
+ /**
86
+ * Represents a NOT ACCEPTABLE error. The resource identified by the request is only capable of
87
+ * generating response entities which have content characteristics not acceptable according
88
+ * to the accept headers sent in the request.
89
+ */
90
+ class NotAcceptableError extends HttpError {
91
+ constructor(message) {
92
+ super('NotAcceptableError', message || 'Not Acceptable');
93
+ Object.setPrototypeOf(this, NotAcceptableError.prototype);
94
+ this.statusCode = 406;
95
+ }
96
+ }
97
+ exports.NotAcceptableError = NotAcceptableError;
98
+ /**
99
+ * Represents a CONFLICT error. The request could not be completed due to a
100
+ * conflict with the current state of the resource.
101
+ */
102
+ class ConflictError extends HttpError {
103
+ constructor(message) {
104
+ super('ConflictError', message || 'Conflict');
105
+ Object.setPrototypeOf(this, ConflictError.prototype);
106
+ this.statusCode = 409;
107
+ }
108
+ }
109
+ exports.ConflictError = ConflictError;
110
+ /**
111
+ * Represents a GONE error. The requested resource is no longer available at the server
112
+ * and no forwarding address is known. This condition is expected to be considered
113
+ * permanent. Clients with link editing capabilities SHOULD delete references to
114
+ * the Request-URI after user approval. If the server does not know, or has
115
+ * no facility to determine, whether or not the condition is permanent, the
116
+ * error 404 (NotFoundError) SHOULD be used instead. This response is
117
+ * cacheable unless indicated otherwise.
118
+ */
119
+ class GoneError extends HttpError {
120
+ constructor(message) {
121
+ super('GoneError', message || 'Gone');
122
+ Object.setPrototypeOf(this, GoneError.prototype);
123
+ this.statusCode = 410;
124
+ }
125
+ }
126
+ exports.GoneError = GoneError;
127
+ /**
128
+ * Represents an UNSUPPORTED MEDIA TYPE error. The server is refusing to service the request
129
+ * because the entity of the request is in a format not supported by the requested resource
130
+ * for the requested method.
131
+ */
132
+ class UnsupportedMediaTypeError extends HttpError {
133
+ constructor(message) {
134
+ super('UnsupportedMediaTypeError', message || 'Unsupported Media Type');
135
+ Object.setPrototypeOf(this, UnsupportedMediaTypeError.prototype);
136
+ this.statusCode = 415;
137
+ }
138
+ }
139
+ exports.UnsupportedMediaTypeError = UnsupportedMediaTypeError;
140
+ /**
141
+ * Represents a UNPROCESSABLE ENTITY error. The server understands the content type of the request entity
142
+ * (hence a 415 Unsupported Media Type status code is inappropriate), and the syntax of the request entity is correct
143
+ * (thus a 400 Bad Request status code is inappropriate) but was unable to process the contained instructions.
144
+ */
145
+ class UnprocessableEntityError extends HttpError {
146
+ constructor(message) {
147
+ super('UnprocessableEntityError', message || 'Unprocessable Entity');
148
+ Object.setPrototypeOf(this, UnprocessableEntityError.prototype);
149
+ this.statusCode = 422;
150
+ }
151
+ }
152
+ exports.UnprocessableEntityError = UnprocessableEntityError;
153
+ /**
154
+ * Represents an INTERNAL SERVER error. The server encountered an unexpected condition
155
+ * which prevented it from fulfilling the request.
156
+ */
157
+ class InternalServerError extends HttpError {
158
+ constructor(message) {
159
+ super('InternalServerError', message || 'Internal Server Error');
160
+ Object.setPrototypeOf(this, InternalServerError.prototype);
161
+ this.statusCode = 500;
162
+ }
163
+ }
164
+ exports.InternalServerError = InternalServerError;
165
+ /**
166
+ * Represents a NOT IMPLEMENTED error. The server does not support the functionality required
167
+ * to fulfill the request. This is the appropriate response when the server does not recognize
168
+ * the request method and is not capable of supporting it for any resource.
169
+ */
170
+ class NotImplementedError extends HttpError {
171
+ constructor(message) {
172
+ super('NotImplementedError', message || 'Not Implemented');
173
+ Object.setPrototypeOf(this, NotImplementedError.prototype);
174
+ this.statusCode = 501;
175
+ }
176
+ }
177
+ exports.NotImplementedError = NotImplementedError;
178
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/server/model/errors.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;AAEb;;GAEG;AACH,MAAsB,SAAU,SAAQ,KAAK;IAGzC,YACI,IAAY,EACL,OAAe;QAEtB,KAAK,CAAC,OAAO,CAAC,CAAC;QAFR,YAAO,GAAP,OAAO,CAAQ;QAGtB,IAAI,CAAC,IAAI,GAAG,IAAI,CAA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UAAU,GAAG,GAAG,CAAC;IAC1B,CAAC;CACJ;AAND,8DAMC;AAED;;;;GAIG;AACH,MAAa,wBAAyB,SAAQ,SAAS;IACnD,YAAY,OAAgB;QACxB,KAAK,CAAC,0BAA0B,EAAE,OAAO,IAAI,sBAAsB,CAAC,CAAC;QACrE,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,wBAAwB,CAAC,SAAS,CAAC,CAAC;QAChE,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC;IAC1B,CAAC;CACJ;AAND,4DAMC;AAED;;;GAGG;AACH,MAAa,mBAAoB,SAAQ,SAAS;IAC9C,YAAY,OAAgB;QACxB,KAAK,CAAC,qBAAqB,EAAE,OAAO,IAAI,uBAAuB,CAAC,CAAC;QACjE,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,mBAAmB,CAAC,SAAS,CAAC,CAAC;QAC3D,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC;IAC1B,CAAC;CACJ;AAND,kDAMC;AAED;;;;GAIG;AACH,MAAa,mBAAoB,SAAQ,SAAS;IAC9C,YAAY,OAAgB;QACxB,KAAK,CAAC,qBAAqB,EAAE,OAAO,IAAI,iBAAiB,CAAC,CAAC;QAC3D,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,mBAAmB,CAAC,SAAS,CAAC,CAAC;QAC3D,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC;IAC1B,CAAC;CACJ;AAND,kDAMC"}
@@ -0,0 +1,91 @@
1
+ import { HttpMethod, ParserType, ServiceProcessor } from './server-types';
2
+ export interface ServiceProperty {
3
+ type: ParamType;
4
+ name: string;
5
+ propertyType: any;
6
+ }
7
+ /**
8
+ * Metadata for REST service classes
9
+ */
10
+ export declare class ServiceClass {
11
+ [key: string]: any;
12
+ targetClass: any;
13
+ path: string;
14
+ authenticator: Record<string, Array<string>>;
15
+ preProcessors: Array<ServiceProcessor>;
16
+ postProcessors: Array<ServiceProcessor>;
17
+ methods: Map<string, ServiceMethod>;
18
+ bodyParserOptions: any;
19
+ bodyParserType: ParserType;
20
+ languages: Array<string>;
21
+ accepts: Array<string>;
22
+ properties: Map<string, ServiceProperty>;
23
+ isAbstract: boolean;
24
+ ignoreNextMiddlewares: boolean;
25
+ constructor(targetClass: any);
26
+ addProperty(key: string, property: ServiceProperty): void;
27
+ hasProperties(): boolean;
28
+ }
29
+ /**
30
+ * Metadata for REST service methods
31
+ */
32
+ export declare class ServiceMethod {
33
+ [key: string]: any;
34
+ name: string;
35
+ path: string;
36
+ authenticator: Record<string, Array<string>>;
37
+ resolvedPath: string;
38
+ httpMethod: HttpMethod;
39
+ parameters: Array<MethodParam>;
40
+ mustParseCookies: boolean;
41
+ files: Array<FileParam>;
42
+ mustParseBody: boolean;
43
+ bodyParserOptions: any;
44
+ bodyParserType: ParserType;
45
+ mustParseForms: boolean;
46
+ acceptMultiTypedParam: boolean;
47
+ languages: Array<string>;
48
+ accepts: Array<string>;
49
+ resolvedLanguages: Array<string>;
50
+ resolvedAccepts: Array<string>;
51
+ preProcessors: Array<ServiceProcessor>;
52
+ postProcessors: Array<ServiceProcessor>;
53
+ ignoreNextMiddlewares: boolean;
54
+ }
55
+ /**
56
+ * Metadata for File parameters on REST methods
57
+ */
58
+ export declare class FileParam {
59
+ name: string;
60
+ singleFile: boolean;
61
+ constructor(name: string, singleFile: boolean);
62
+ }
63
+ /**
64
+ * Metadata for REST service method parameters
65
+ */
66
+ export declare class MethodParam {
67
+ name: string;
68
+ type: Function;
69
+ paramType: ParamType;
70
+ constructor(name: string, type: Function, paramType: ParamType);
71
+ }
72
+ /**
73
+ * Enumeration of accepted parameter types
74
+ */
75
+ export declare enum ParamType {
76
+ path = "path",
77
+ query = "query",
78
+ header = "header",
79
+ cookie = "cookie",
80
+ form = "form",
81
+ body = "body",
82
+ param = "param",
83
+ file = "file",
84
+ files = "files",
85
+ context = "context",
86
+ context_request = "context_request",
87
+ context_response = "context_response",
88
+ context_next = "context_next",
89
+ context_accept = "context_accept",
90
+ context_accept_language = "context_accept_language"
91
+ }
@@ -0,0 +1,80 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ParamType = exports.MethodParam = exports.FileParam = exports.ServiceMethod = exports.ServiceClass = void 0;
4
+ /**
5
+ * Metadata for REST service classes
6
+ */
7
+ class ServiceClass {
8
+ constructor(targetClass) {
9
+ this.isAbstract = false;
10
+ this.ignoreNextMiddlewares = false;
11
+ this.targetClass = targetClass;
12
+ this.methods = new Map();
13
+ this.properties = new Map();
14
+ }
15
+ addProperty(key, property) {
16
+ this.properties.set(key, property);
17
+ }
18
+ hasProperties() {
19
+ return this.properties && this.properties.size > 0;
20
+ }
21
+ }
22
+ exports.ServiceClass = ServiceClass;
23
+ /**
24
+ * Metadata for REST service methods
25
+ */
26
+ class ServiceMethod {
27
+ constructor() {
28
+ this.parameters = new Array();
29
+ this.mustParseCookies = false;
30
+ this.files = new Array();
31
+ this.mustParseBody = false;
32
+ this.mustParseForms = false;
33
+ this.acceptMultiTypedParam = false;
34
+ this.ignoreNextMiddlewares = false;
35
+ }
36
+ }
37
+ exports.ServiceMethod = ServiceMethod;
38
+ /**
39
+ * Metadata for File parameters on REST methods
40
+ */
41
+ class FileParam {
42
+ constructor(name, singleFile) {
43
+ this.name = name;
44
+ this.singleFile = singleFile;
45
+ }
46
+ }
47
+ exports.FileParam = FileParam;
48
+ /**
49
+ * Metadata for REST service method parameters
50
+ */
51
+ class MethodParam {
52
+ constructor(name, type, paramType) {
53
+ this.name = name;
54
+ this.type = type;
55
+ this.paramType = paramType;
56
+ }
57
+ }
58
+ exports.MethodParam = MethodParam;
59
+ /**
60
+ * Enumeration of accepted parameter types
61
+ */
62
+ var ParamType;
63
+ (function (ParamType) {
64
+ ParamType["path"] = "path";
65
+ ParamType["query"] = "query";
66
+ ParamType["header"] = "header";
67
+ ParamType["cookie"] = "cookie";
68
+ ParamType["form"] = "form";
69
+ ParamType["body"] = "body";
70
+ ParamType["param"] = "param";
71
+ ParamType["file"] = "file";
72
+ ParamType["files"] = "files";
73
+ ParamType["context"] = "context";
74
+ ParamType["context_request"] = "context_request";
75
+ ParamType["context_response"] = "context_response";
76
+ ParamType["context_next"] = "context_next";
77
+ ParamType["context_accept"] = "context_accept";
78
+ ParamType["context_accept_language"] = "context_accept_language";
79
+ })(ParamType || (exports.ParamType = ParamType = {}));
80
+ //# sourceMappingURL=metadata.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metadata.js","sourceRoot":"","sources":["../../../src/server/model/metadata.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;AAUb;;GAEG;AACH,MAAa,YAAY;IAgBrB,YAAY,WAAgB;QAFrB,eAAU,GAAY,KAAK,CAAC;QAC5B,0BAAqB,GAAY,KAAK,CAAC;QAE1C,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,EAAyB,CAAC;QAChD,IAAI,CAAC,UAAU,GAAG,IAAI,GAAG,EAA2B,CAAC;IACzD,CAAC;IAEM,WAAW,CAAC,GAAW,EAAE,QAAyB;QACrD,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IACvC,CAAC;IAEM,aAAa;QAChB,OAAO,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,GAAG,CAAC,CAAC;IACvD,CAAC;CACJ;AA7BD,oCA6BC;AAED;;GAEG;AACH,MAAa,aAAa;IAA1B;QAQW,eAAU,GAAuB,IAAI,KAAK,EAAe,CAAC;QAC1D,qBAAgB,GAAY,KAAK,CAAC;QAClC,UAAK,GAAqB,IAAI,KAAK,EAAa,CAAC;QACjD,kBAAa,GAAY,KAAK,CAAC;QAG/B,mBAAc,GAAY,KAAK,CAAC;QAChC,0BAAqB,GAAY,KAAK,CAAC;QAOvC,0BAAqB,GAAY,KAAK,CAAC;IAClD,CAAC;CAAA;AAvBD,sCAuBC;AAED;;GAEG;AACH,MAAa,SAAS;IAGlB,YAAY,IAAY,EAAE,UAAmB;QACzC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IACjC,CAAC;CACJ;AAPD,8BAOC;AAED;;GAEG;AACH,MAAa,WAAW;IAIpB,YAAY,IAAY,EAAE,IAAc,EAAE,SAAoB;QAC1D,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC/B,CAAC;CACJ;AATD,kCASC;AAED;;GAEG;AACH,IAAY,SAgBX;AAhBD,WAAY,SAAS;IACjB,0BAAa,CAAA;IACb,4BAAe,CAAA;IACf,8BAAiB,CAAA;IACjB,8BAAiB,CAAA;IACjB,0BAAa,CAAA;IACb,0BAAa,CAAA;IACb,4BAAe,CAAA;IACf,0BAAa,CAAA;IACb,4BAAe,CAAA;IACf,gCAAmB,CAAA;IACnB,gDAAmC,CAAA;IACnC,kDAAqC,CAAA;IACrC,0CAA6B,CAAA;IAC7B,8CAAiC,CAAA;IACjC,gEAAmD,CAAA;AACvD,CAAC,EAhBW,SAAS,yBAAT,SAAS,QAgBpB"}
@@ -0,0 +1,86 @@
1
+ import { ReferencedResource } from './server-types';
2
+ /**
3
+ * Inform that a new resource was created. Server will
4
+ * add a Location header and set status to 201
5
+ */
6
+ export declare class NewResource<T> extends ReferencedResource<T> {
7
+ /**
8
+ * Constructor. Receives the location of the new resource created.
9
+ * @param location To be added to the Location header on response
10
+ * @param body To be added to the response body
11
+ */
12
+ constructor(location: string, body?: T);
13
+ }
14
+ /**
15
+ * Inform that the request was accepted but is not completed.
16
+ * A Location header should inform the location where the user
17
+ * can monitor his request processing status.
18
+ */
19
+ export declare class RequestAccepted<T> extends ReferencedResource<T> {
20
+ /**
21
+ * Constructor. Receives the location where information about the
22
+ * request processing can be found.
23
+ * @param location To be added to the Location header on response
24
+ * @param body To be added to the response body
25
+ */
26
+ constructor(location: string, body?: T);
27
+ }
28
+ /**
29
+ * Inform that the resource has permanently
30
+ * moved to a new location, and that future references should use a
31
+ * new URI with their requests.
32
+ */
33
+ export declare class MovedPermanently<T> extends ReferencedResource<T> {
34
+ /**
35
+ * Constructor. Receives the location where the resource can be found.
36
+ * @param location To be added to the Location header on response
37
+ * @param body To be added to the response body
38
+ */
39
+ constructor(location: string, body?: T);
40
+ }
41
+ /**
42
+ * Inform that the resource has temporarily
43
+ * moved to another location, but that future references should
44
+ * still use the original URI to access the resource.
45
+ */
46
+ export declare class MovedTemporarily<T> extends ReferencedResource<T> {
47
+ /**
48
+ * Constructor. Receives the location where the resource can be found.
49
+ * @param location To be added to the Location header on response
50
+ * @param body To be added to the response body
51
+ */
52
+ constructor(location: string, body?: T);
53
+ }
54
+ /**
55
+ * Used to download a resource.
56
+ */
57
+ export declare class DownloadResource {
58
+ filePath: string;
59
+ fileName: string;
60
+ /**
61
+ * Constructor.
62
+ * @param filePath The file path to download.
63
+ * @param fileName The file name
64
+ */
65
+ constructor(filePath: string, fileName: string);
66
+ }
67
+ /**
68
+ * Used to download binary data as a file.
69
+ */
70
+ export declare class DownloadBinaryData {
71
+ content: Buffer;
72
+ mimeType: string;
73
+ fileName?: string;
74
+ /**
75
+ * Constructor. Receives the location of the resource.
76
+ * @param content The binary data to be downloaded as a file.
77
+ * @param mimeType The mime-type to be passed on Content-Type header.
78
+ * @param fileName The file name
79
+ */
80
+ constructor(content: Buffer, mimeType: string, fileName?: string);
81
+ }
82
+ /**
83
+ * If returned by a service, no response will be sent to client. Use it
84
+ * if you want to send the response by yourself.
85
+ */
86
+ export declare const NoResponse: {};
@@ -0,0 +1,110 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NoResponse = exports.DownloadBinaryData = exports.DownloadResource = exports.MovedTemporarily = exports.MovedPermanently = exports.RequestAccepted = exports.NewResource = void 0;
4
+ const server_types_1 = require("./server-types");
5
+ /**
6
+ * Inform that a new resource was created. Server will
7
+ * add a Location header and set status to 201
8
+ */
9
+ class NewResource extends server_types_1.ReferencedResource {
10
+ /**
11
+ * Constructor. Receives the location of the new resource created.
12
+ * @param location To be added to the Location header on response
13
+ * @param body To be added to the response body
14
+ */
15
+ constructor(location, body) {
16
+ super(location, 201);
17
+ this.body = body;
18
+ }
19
+ }
20
+ exports.NewResource = NewResource;
21
+ /**
22
+ * Inform that the request was accepted but is not completed.
23
+ * A Location header should inform the location where the user
24
+ * can monitor his request processing status.
25
+ */
26
+ class RequestAccepted extends server_types_1.ReferencedResource {
27
+ /**
28
+ * Constructor. Receives the location where information about the
29
+ * request processing can be found.
30
+ * @param location To be added to the Location header on response
31
+ * @param body To be added to the response body
32
+ */
33
+ constructor(location, body) {
34
+ super(location, 202);
35
+ this.body = body;
36
+ }
37
+ }
38
+ exports.RequestAccepted = RequestAccepted;
39
+ /**
40
+ * Inform that the resource has permanently
41
+ * moved to a new location, and that future references should use a
42
+ * new URI with their requests.
43
+ */
44
+ class MovedPermanently extends server_types_1.ReferencedResource {
45
+ /**
46
+ * Constructor. Receives the location where the resource can be found.
47
+ * @param location To be added to the Location header on response
48
+ * @param body To be added to the response body
49
+ */
50
+ constructor(location, body) {
51
+ super(location, 301);
52
+ this.body = body;
53
+ }
54
+ }
55
+ exports.MovedPermanently = MovedPermanently;
56
+ /**
57
+ * Inform that the resource has temporarily
58
+ * moved to another location, but that future references should
59
+ * still use the original URI to access the resource.
60
+ */
61
+ class MovedTemporarily extends server_types_1.ReferencedResource {
62
+ /**
63
+ * Constructor. Receives the location where the resource can be found.
64
+ * @param location To be added to the Location header on response
65
+ * @param body To be added to the response body
66
+ */
67
+ constructor(location, body) {
68
+ super(location, 302);
69
+ this.body = body;
70
+ }
71
+ }
72
+ exports.MovedTemporarily = MovedTemporarily;
73
+ /**
74
+ * Used to download a resource.
75
+ */
76
+ class DownloadResource {
77
+ /**
78
+ * Constructor.
79
+ * @param filePath The file path to download.
80
+ * @param fileName The file name
81
+ */
82
+ constructor(filePath, fileName) {
83
+ this.filePath = filePath;
84
+ this.fileName = fileName;
85
+ }
86
+ }
87
+ exports.DownloadResource = DownloadResource;
88
+ /**
89
+ * Used to download binary data as a file.
90
+ */
91
+ class DownloadBinaryData {
92
+ /**
93
+ * Constructor. Receives the location of the resource.
94
+ * @param content The binary data to be downloaded as a file.
95
+ * @param mimeType The mime-type to be passed on Content-Type header.
96
+ * @param fileName The file name
97
+ */
98
+ constructor(content, mimeType, fileName) {
99
+ this.content = content;
100
+ this.mimeType = mimeType;
101
+ this.fileName = fileName;
102
+ }
103
+ }
104
+ exports.DownloadBinaryData = DownloadBinaryData;
105
+ /**
106
+ * If returned by a service, no response will be sent to client. Use it
107
+ * if you want to send the response by yourself.
108
+ */
109
+ exports.NoResponse = {};
110
+ //# sourceMappingURL=return-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"return-types.js","sourceRoot":"","sources":["../../../src/server/model/return-types.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;AAEb,iDAAoD;AAEpD;;;GAGG;AACH,MAAa,WAAe,SAAQ,iCAAqB;IACrD;;;;OAIG;IACH,YAAY,QAAgB,EAAE,IAAQ;QAClC,KAAK,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;CACJ;AAVD,kCAUC;AAED;;;;GAIG;AACH,MAAa,eAAmB,SAAQ,iCAAqB;IACzD;;;;;OAKG;IACH,YAAY,QAAgB,EAAE,IAAQ;QAClC,KAAK,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;CACJ;AAXD,0CAWC;AAED;;;;GAIG;AACH,MAAa,gBAAoB,SAAQ,iCAAqB;IAC1D;;;;OAIG;IACH,YAAY,QAAgB,EAAE,IAAQ;QAClC,KAAK,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;CACJ;AAVD,4CAUC;AAED;;;;GAIG;AACH,MAAa,gBAAoB,SAAQ,iCAAqB;IAC1D;;;;OAIG;IACH,YAAY,QAAgB,EAAE,IAAQ;QAClC,KAAK,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;CACJ;AAVD,4CAUC;AAED;;GAEG;AACH,MAAa,gBAAgB;IACzB;;;;OAIG;IACH,YACW,QAAgB,EAChB,QAAgB;QADhB,aAAQ,GAAR,QAAQ,CAAQ;QAChB,aAAQ,GAAR,QAAQ,CAAQ;IACxB,CAAC;CACP;AAVD,4CAUC;AAED;;GAEG;AACH,MAAa,kBAAkB;IAC3B;;;;;OAKG;IACH,YACW,OAAe,EACf,QAAgB,EAChB,QAAiB;QAFjB,YAAO,GAAP,OAAO,CAAQ;QACf,aAAQ,GAAR,QAAQ,CAAQ;QAChB,aAAQ,GAAR,QAAQ,CAAS;IACzB,CAAC;CACP;AAZD,gDAYC;AAED;;;GAGG;AACU,QAAA,UAAU,GAAG,EAAE,CAAC"}
@@ -0,0 +1,118 @@
1
+ import * as express from 'express';
2
+ /**
3
+ * Limits for file uploads
4
+ */
5
+ export interface FileLimits {
6
+ /** Max field name size (Default: 100 bytes) */
7
+ fieldNameSize?: number;
8
+ /** Max field value size (Default: 1MB) */
9
+ fieldSize?: number;
10
+ /** Max number of non- file fields (Default: Infinity) */
11
+ fields?: number;
12
+ /** For multipart forms, the max file size (in bytes)(Default: Infinity) */
13
+ fileSize?: number;
14
+ /** For multipart forms, the max number of file fields (Default: Infinity) */
15
+ files?: number;
16
+ /** For multipart forms, the max number of parts (fields + files)(Default: Infinity) */
17
+ parts?: number;
18
+ /** For multipart forms, the max number of header key=> value pairs to parse Default: 2000(same as node's http). */
19
+ headerPairs?: number;
20
+ }
21
+ /**
22
+ * The supported HTTP methods.
23
+ */
24
+ export declare enum HttpMethod {
25
+ GET = "GET",
26
+ POST = "POST",
27
+ PUT = "PUT",
28
+ DELETE = "DELETE",
29
+ HEAD = "HEAD",
30
+ OPTIONS = "OPTIONS",
31
+ PATCH = "PATCH"
32
+ }
33
+ /**
34
+ * Represents the current context of the request being handled.
35
+ */
36
+ export declare class ServiceContext {
37
+ /**
38
+ * The resolved language to be used in the current request handling.
39
+ */
40
+ language: string;
41
+ /**
42
+ * The preferred media type to be used in the current request handling.
43
+ */
44
+ accept: string;
45
+ /**
46
+ * The request object.
47
+ */
48
+ request: express.Request;
49
+ /**
50
+ * The response object
51
+ */
52
+ response: express.Response;
53
+ /**
54
+ * The next function. It can be used to delegate to the next middleware
55
+ * registered the processing of the current request.
56
+ */
57
+ next: express.NextFunction;
58
+ }
59
+ /**
60
+ * Used to create a reference to a resource.
61
+ */
62
+ export declare abstract class ReferencedResource<T> {
63
+ location: string;
64
+ statusCode: number;
65
+ /**
66
+ * the body to be sent
67
+ */
68
+ body: T;
69
+ /**
70
+ * Constructor. Receives the location of the resource.
71
+ * @param location To be added to the Location header on response
72
+ * @param statusCode the response status code to be sent
73
+ */
74
+ constructor(location: string, statusCode: number);
75
+ }
76
+ /**
77
+ * The factory used to instantiate the object services
78
+ */
79
+ export interface ServiceFactory {
80
+ /**
81
+ * Create a new service object. Called before each request handling.
82
+ */
83
+ create: (serviceClass: Function, context: ServiceContext) => any;
84
+ /**
85
+ * Return the type used to handle requests to the target service.
86
+ * By default, returns the serviceClass received, but you can use this
87
+ * to implement IoC integrations, once some frameworks like typescript-ioc or
88
+ * Inversify can override constructors for injectable types.
89
+ */
90
+ getTargetClass: (serviceClass: Function) => FunctionConstructor;
91
+ }
92
+ /**
93
+ * An optional authenticator for rest services
94
+ */
95
+ export interface ServiceAuthenticator {
96
+ /**
97
+ * Get the user list of roles.
98
+ */
99
+ getRoles: (req: express.Request, res: express.Response) => Array<string>;
100
+ /**
101
+ * Initialize the authenticator
102
+ */
103
+ initialize(router: express.Router): void;
104
+ /**
105
+ * Retrieve the middleware used to authenticate users.
106
+ */
107
+ getMiddleware(): express.RequestHandler;
108
+ }
109
+ export type ServiceProcessor = (req: express.Request, res?: express.Response) => void | Promise<void>;
110
+ export type ParameterConverter = (paramValue: any) => any;
111
+ /**
112
+ * The types of parsers to parse the message body
113
+ */
114
+ export declare enum ParserType {
115
+ json = "json",
116
+ text = "text",
117
+ raw = "raw"
118
+ }