@sepo27/servicio 0.0.0-stage → 0.2.3
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/CHANGELOG.md +37 -0
- package/README.md +38 -2
- package/dist/spec/index.d.ts +1 -0
- package/dist/spec/index.js +1 -0
- package/dist/spec/mocks/expressRequestMock.d.ts +2 -0
- package/dist/spec/mocks/expressRequestMock.js +2 -0
- package/dist/spec/mocks/expressResponseMock.d.ts +8 -0
- package/dist/spec/mocks/expressResponseMock.js +5 -0
- package/dist/spec/mocks/index.d.ts +2 -0
- package/dist/spec/mocks/index.js +2 -0
- package/dist/src/Servicio.d.ts +8 -0
- package/dist/src/Servicio.js +50 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.js +3 -0
- package/dist/src/lib/common/isType.d.ts +2 -0
- package/dist/src/lib/common/isType.js +2 -0
- package/dist/src/lib/common/string.d.ts +1 -0
- package/dist/src/lib/common/string.js +1 -0
- package/dist/src/lib/common/types.d.ts +4 -0
- package/dist/src/lib/common/types.js +1 -0
- package/dist/src/lib/express/types.d.ts +28 -0
- package/dist/src/lib/express/types.js +38 -0
- package/dist/src/lib/http-meta/HttpMethod.d.ts +29 -0
- package/dist/src/lib/http-meta/HttpMethod.js +33 -0
- package/dist/src/lib/http-meta/index.d.ts +5 -0
- package/dist/src/lib/http-meta/index.js +4 -0
- package/dist/src/lib/http-meta/response/HttpResponse.d.ts +7 -0
- package/dist/src/lib/http-meta/response/HttpResponse.js +1 -0
- package/dist/src/lib/http-meta/response/SuccessResponse.d.ts +11 -0
- package/dist/src/lib/http-meta/response/SuccessResponse.js +29 -0
- package/dist/src/lib/http-meta/response/errors/HttpError.d.ts +15 -0
- package/dist/src/lib/http-meta/response/errors/HttpError.js +20 -0
- package/dist/src/lib/http-meta/response/errors/errors.d.ts +122 -0
- package/dist/src/lib/http-meta/response/errors/errors.js +243 -0
- package/dist/src/lib/http-meta/response/errors/index.d.ts +2 -0
- package/dist/src/lib/http-meta/response/errors/index.js +2 -0
- package/dist/src/lib/http-meta/response/httpStatus.d.ts +83 -0
- package/dist/src/lib/http-meta/response/httpStatus.js +94 -0
- package/dist/src/lib/http-meta/response/types.d.ts +3 -0
- package/dist/src/lib/http-meta/response/types.js +1 -0
- package/dist/src/main/Route.d.ts +9 -0
- package/dist/src/main/Route.js +21 -0
- package/dist/src/main/Route.spec.d.ts +1 -0
- package/dist/src/main/Route.spec.js +26 -0
- package/dist/src/main/ServicioApp.d.ts +10 -0
- package/dist/src/main/ServicioApp.js +39 -0
- package/dist/src/main/ServicioApp.spec.d.ts +1 -0
- package/dist/src/main/ServicioApp.spec.js +85 -0
- package/dist/src/main/index.d.ts +1 -0
- package/dist/src/main/index.js +2 -0
- package/dist/src/main/servicio.d.ts +2 -0
- package/dist/src/main/servicio.js +41 -0
- package/dist/src/main/servicio.spec.d.ts +1 -0
- package/dist/src/main/servicio.spec.js +71 -0
- package/dist/src/main/types.d.ts +13 -0
- package/dist/src/main/types.js +1 -0
- package/package.json +54 -3
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { HttpError } from './HttpError.js';
|
|
2
|
+
import { HttpStatus } from '../httpStatus.js';
|
|
3
|
+
export class BadRequestError extends HttpError {
|
|
4
|
+
constructor(opts = {}) {
|
|
5
|
+
super(HttpStatus.BAD_REQUEST, opts);
|
|
6
|
+
Object.setPrototypeOf(this, BadRequestError.prototype);
|
|
7
|
+
// this.name = BadRequestError.name; // TODO: not needed (name derived via prototype) ?
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export class UnauthorizedError extends HttpError {
|
|
11
|
+
constructor(opts = {}) {
|
|
12
|
+
super(HttpStatus.UNAUTHORIZED, opts);
|
|
13
|
+
Object.setPrototypeOf(this, UnauthorizedError.prototype);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export class PaymentRequiredError extends HttpError {
|
|
17
|
+
constructor(opts = {}) {
|
|
18
|
+
super(HttpStatus.PAYMENT_REQUIRED, opts);
|
|
19
|
+
Object.setPrototypeOf(this, PaymentRequiredError.prototype);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export class ForbiddenError extends HttpError {
|
|
23
|
+
constructor(opts = {}) {
|
|
24
|
+
super(HttpStatus.FORBIDDEN, opts);
|
|
25
|
+
Object.setPrototypeOf(this, ForbiddenError.prototype);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export class NotFoundError extends HttpError {
|
|
29
|
+
constructor(opts = {}) {
|
|
30
|
+
super(HttpStatus.NOT_FOUND, opts);
|
|
31
|
+
Object.setPrototypeOf(this, NotFoundError.prototype);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export class MethodNotAllowedError extends HttpError {
|
|
35
|
+
constructor(opts = {}) {
|
|
36
|
+
super(HttpStatus.METHOD_NOT_ALLOWED, opts);
|
|
37
|
+
Object.setPrototypeOf(this, MethodNotAllowedError.prototype);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export class NotAcceptableError extends HttpError {
|
|
41
|
+
constructor(opts = {}) {
|
|
42
|
+
super(HttpStatus.NOT_ACCEPTABLE, opts);
|
|
43
|
+
Object.setPrototypeOf(this, NotAcceptableError.prototype);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export class ProxyAuthenticationRequiredError extends HttpError {
|
|
47
|
+
constructor(opts = {}) {
|
|
48
|
+
super(HttpStatus.PROXY_AUTHENTICATION_REQUIRED, opts);
|
|
49
|
+
Object.setPrototypeOf(this, ProxyAuthenticationRequiredError.prototype);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export class RequestTimeoutError extends HttpError {
|
|
53
|
+
constructor(opts = {}) {
|
|
54
|
+
super(HttpStatus.REQUEST_TIMEOUT, opts);
|
|
55
|
+
Object.setPrototypeOf(this, RequestTimeoutError.prototype);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export class ConflictError extends HttpError {
|
|
59
|
+
constructor(opts = {}) {
|
|
60
|
+
super(HttpStatus.CONFLICT, opts);
|
|
61
|
+
Object.setPrototypeOf(this, ConflictError.prototype);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export class GoneError extends HttpError {
|
|
65
|
+
constructor(opts = {}) {
|
|
66
|
+
super(HttpStatus.GONE, opts);
|
|
67
|
+
Object.setPrototypeOf(this, GoneError.prototype);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
export class LengthRequiredError extends HttpError {
|
|
71
|
+
constructor(opts = {}) {
|
|
72
|
+
super(HttpStatus.LENGTH_REQUIRED, opts);
|
|
73
|
+
Object.setPrototypeOf(this, LengthRequiredError.prototype);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
export class PreconditionFailedError extends HttpError {
|
|
77
|
+
constructor(opts = {}) {
|
|
78
|
+
super(HttpStatus.PRECONDITION_FAILED, opts);
|
|
79
|
+
Object.setPrototypeOf(this, PreconditionFailedError.prototype);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
export class ContentTooLargeError extends HttpError {
|
|
83
|
+
constructor(opts = {}) {
|
|
84
|
+
super(HttpStatus.CONTENT_TOO_LARGE, opts);
|
|
85
|
+
Object.setPrototypeOf(this, ContentTooLargeError.prototype);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
export class UriTooLongError extends HttpError {
|
|
89
|
+
constructor(opts = {}) {
|
|
90
|
+
super(HttpStatus.URI_TOO_LONG, opts);
|
|
91
|
+
Object.setPrototypeOf(this, UriTooLongError.prototype);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
export class UnsupportedMediaTypeError extends HttpError {
|
|
95
|
+
constructor(opts = {}) {
|
|
96
|
+
super(HttpStatus.UNSUPPORTED_MEDIA_TYPE, opts);
|
|
97
|
+
Object.setPrototypeOf(this, UnsupportedMediaTypeError.prototype);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
export class RangeNotSatisfiableError extends HttpError {
|
|
101
|
+
constructor(opts = {}) {
|
|
102
|
+
super(HttpStatus.RANGE_NOT_SATISFIABLE, opts);
|
|
103
|
+
Object.setPrototypeOf(this, RangeNotSatisfiableError.prototype);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
export class ExpectationFailedError extends HttpError {
|
|
107
|
+
constructor(opts = {}) {
|
|
108
|
+
super(HttpStatus.EXPECTATION_FAILED, opts);
|
|
109
|
+
Object.setPrototypeOf(this, ExpectationFailedError.prototype);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
export class ImATeapotError extends HttpError {
|
|
113
|
+
constructor(opts = {}) {
|
|
114
|
+
super(HttpStatus.IM_A_TEAPOT, opts);
|
|
115
|
+
Object.setPrototypeOf(this, ImATeapotError.prototype);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
export class MisdirectedRequestError extends HttpError {
|
|
119
|
+
constructor(opts = {}) {
|
|
120
|
+
super(HttpStatus.MISDIRECTED_REQUEST, opts);
|
|
121
|
+
Object.setPrototypeOf(this, MisdirectedRequestError.prototype);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
export class UnprocessableContentError extends HttpError {
|
|
125
|
+
constructor(opts = {}) {
|
|
126
|
+
super(HttpStatus.UNPROCESSABLE_CONTENT, opts);
|
|
127
|
+
Object.setPrototypeOf(this, UnprocessableContentError.prototype);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
export class LockedError extends HttpError {
|
|
131
|
+
constructor(opts = {}) {
|
|
132
|
+
super(HttpStatus.LOCKED, opts);
|
|
133
|
+
Object.setPrototypeOf(this, LockedError.prototype);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
export class FailedDependencyError extends HttpError {
|
|
137
|
+
constructor(opts = {}) {
|
|
138
|
+
super(HttpStatus.FAILED_DEPENDENCY, opts);
|
|
139
|
+
Object.setPrototypeOf(this, FailedDependencyError.prototype);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
export class TooEarlyError extends HttpError {
|
|
143
|
+
constructor(opts = {}) {
|
|
144
|
+
super(HttpStatus.TOO_EARLY, opts);
|
|
145
|
+
Object.setPrototypeOf(this, TooEarlyError.prototype);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
export class UpgradeRequiredError extends HttpError {
|
|
149
|
+
constructor(opts = {}) {
|
|
150
|
+
super(HttpStatus.UPGRADE_REQUIRED, opts);
|
|
151
|
+
Object.setPrototypeOf(this, UpgradeRequiredError.prototype);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
export class PreconditionRequiredError extends HttpError {
|
|
155
|
+
constructor(opts = {}) {
|
|
156
|
+
super(HttpStatus.PRECONDITION_REQUIRED, opts);
|
|
157
|
+
Object.setPrototypeOf(this, PreconditionRequiredError.prototype);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
export class TooManyRequestsError extends HttpError {
|
|
161
|
+
constructor(opts = {}) {
|
|
162
|
+
super(HttpStatus.TOO_MANY_REQUESTS, opts);
|
|
163
|
+
Object.setPrototypeOf(this, TooManyRequestsError.prototype);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
export class RequestHeaderFieldsTooLargeError extends HttpError {
|
|
167
|
+
constructor(opts = {}) {
|
|
168
|
+
super(HttpStatus.REQUEST_HEADER_FIELDS_TOO_LARGE, opts);
|
|
169
|
+
Object.setPrototypeOf(this, RequestHeaderFieldsTooLargeError.prototype);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
export class UnavailableForLegalReasonsError extends HttpError {
|
|
173
|
+
constructor(opts = {}) {
|
|
174
|
+
super(HttpStatus.UNAVAILABLE_FOR_LEGAL_REASONS, opts);
|
|
175
|
+
Object.setPrototypeOf(this, UnavailableForLegalReasonsError.prototype);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
export class InternalServerError extends HttpError {
|
|
179
|
+
constructor(opts = {}) {
|
|
180
|
+
super(HttpStatus.INTERNAL_SERVER_ERROR, opts);
|
|
181
|
+
Object.setPrototypeOf(this, InternalServerError.prototype);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
export class NotImplementedError extends HttpError {
|
|
185
|
+
constructor(opts = {}) {
|
|
186
|
+
super(HttpStatus.NOT_IMPLEMENTED, opts);
|
|
187
|
+
Object.setPrototypeOf(this, NotImplementedError.prototype);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
export class BadGatewayError extends HttpError {
|
|
191
|
+
constructor(opts = {}) {
|
|
192
|
+
super(HttpStatus.BAD_GATEWAY, opts);
|
|
193
|
+
Object.setPrototypeOf(this, BadGatewayError.prototype);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
export class ServiceUnavailableError extends HttpError {
|
|
197
|
+
constructor(opts = {}) {
|
|
198
|
+
super(HttpStatus.SERVICE_UNAVAILABLE, opts);
|
|
199
|
+
Object.setPrototypeOf(this, ServiceUnavailableError.prototype);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
export class GatewayTimeoutError extends HttpError {
|
|
203
|
+
constructor(opts = {}) {
|
|
204
|
+
super(HttpStatus.GATEWAY_TIMEOUT, opts);
|
|
205
|
+
Object.setPrototypeOf(this, GatewayTimeoutError.prototype);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
export class HttpVersionNotSupportedError extends HttpError {
|
|
209
|
+
constructor(opts = {}) {
|
|
210
|
+
super(HttpStatus.HTTP_VERSION_NOT_SUPPORTED, opts);
|
|
211
|
+
Object.setPrototypeOf(this, HttpVersionNotSupportedError.prototype);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
export class VariantAlsoNegotiatesError extends HttpError {
|
|
215
|
+
constructor(opts = {}) {
|
|
216
|
+
super(HttpStatus.VARIANT_ALSO_NEGOTIATES, opts);
|
|
217
|
+
Object.setPrototypeOf(this, VariantAlsoNegotiatesError.prototype);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
export class InsufficientStorageError extends HttpError {
|
|
221
|
+
constructor(opts = {}) {
|
|
222
|
+
super(HttpStatus.INSUFFICIENT_STORAGE, opts);
|
|
223
|
+
Object.setPrototypeOf(this, InsufficientStorageError.prototype);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
export class LoopDetectedError extends HttpError {
|
|
227
|
+
constructor(opts = {}) {
|
|
228
|
+
super(HttpStatus.LOOP_DETECTED, opts);
|
|
229
|
+
Object.setPrototypeOf(this, LoopDetectedError.prototype);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
export class NotExtendedError extends HttpError {
|
|
233
|
+
constructor(opts = {}) {
|
|
234
|
+
super(HttpStatus.NOT_EXTENDED, opts);
|
|
235
|
+
Object.setPrototypeOf(this, NotExtendedError.prototype);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
export class NetworkAuthenticationRequiredError extends HttpError {
|
|
239
|
+
constructor(opts = {}) {
|
|
240
|
+
super(HttpStatus.NETWORK_AUTHENTICATION_REQUIRED, opts);
|
|
241
|
+
Object.setPrototypeOf(this, NetworkAuthenticationRequiredError.prototype);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP Status Codes enum.
|
|
3
|
+
* Based on MDN Web Docs and IANA HTTP Status Code Registry.
|
|
4
|
+
* Covers all registered status codes from RFC 9110 and related RFCs.
|
|
5
|
+
*
|
|
6
|
+
* (Generated by Junie)
|
|
7
|
+
*/
|
|
8
|
+
export declare enum HttpStatus {
|
|
9
|
+
CONTINUE = 100,
|
|
10
|
+
SWITCHING_PROTOCOLS = 101,
|
|
11
|
+
PROCESSING = 102,
|
|
12
|
+
EARLY_HINTS = 103,
|
|
13
|
+
OK = 200,
|
|
14
|
+
CREATED = 201,
|
|
15
|
+
ACCEPTED = 202,
|
|
16
|
+
NON_AUTHORITATIVE_INFORMATION = 203,
|
|
17
|
+
NO_CONTENT = 204,
|
|
18
|
+
RESET_CONTENT = 205,
|
|
19
|
+
PARTIAL_CONTENT = 206,
|
|
20
|
+
MULTI_STATUS = 207,
|
|
21
|
+
ALREADY_REPORTED = 208,
|
|
22
|
+
IM_USED = 226,
|
|
23
|
+
MULTIPLE_CHOICES = 300,
|
|
24
|
+
MOVED_PERMANENTLY = 301,
|
|
25
|
+
FOUND = 302,
|
|
26
|
+
SEE_OTHER = 303,
|
|
27
|
+
NOT_MODIFIED = 304,
|
|
28
|
+
USE_PROXY = 305,
|
|
29
|
+
TEMPORARY_REDIRECT = 307,
|
|
30
|
+
PERMANENT_REDIRECT = 308,
|
|
31
|
+
BAD_REQUEST = 400,
|
|
32
|
+
UNAUTHORIZED = 401,
|
|
33
|
+
PAYMENT_REQUIRED = 402,
|
|
34
|
+
FORBIDDEN = 403,
|
|
35
|
+
NOT_FOUND = 404,
|
|
36
|
+
METHOD_NOT_ALLOWED = 405,
|
|
37
|
+
NOT_ACCEPTABLE = 406,
|
|
38
|
+
PROXY_AUTHENTICATION_REQUIRED = 407,
|
|
39
|
+
REQUEST_TIMEOUT = 408,
|
|
40
|
+
CONFLICT = 409,
|
|
41
|
+
GONE = 410,
|
|
42
|
+
LENGTH_REQUIRED = 411,
|
|
43
|
+
PRECONDITION_FAILED = 412,
|
|
44
|
+
CONTENT_TOO_LARGE = 413,
|
|
45
|
+
URI_TOO_LONG = 414,
|
|
46
|
+
UNSUPPORTED_MEDIA_TYPE = 415,
|
|
47
|
+
RANGE_NOT_SATISFIABLE = 416,
|
|
48
|
+
EXPECTATION_FAILED = 417,
|
|
49
|
+
IM_A_TEAPOT = 418,
|
|
50
|
+
MISDIRECTED_REQUEST = 421,
|
|
51
|
+
UNPROCESSABLE_CONTENT = 422,
|
|
52
|
+
LOCKED = 423,
|
|
53
|
+
FAILED_DEPENDENCY = 424,
|
|
54
|
+
TOO_EARLY = 425,
|
|
55
|
+
UPGRADE_REQUIRED = 426,
|
|
56
|
+
PRECONDITION_REQUIRED = 428,
|
|
57
|
+
TOO_MANY_REQUESTS = 429,
|
|
58
|
+
REQUEST_HEADER_FIELDS_TOO_LARGE = 431,
|
|
59
|
+
UNAVAILABLE_FOR_LEGAL_REASONS = 451,
|
|
60
|
+
INTERNAL_SERVER_ERROR = 500,
|
|
61
|
+
NOT_IMPLEMENTED = 501,
|
|
62
|
+
BAD_GATEWAY = 502,
|
|
63
|
+
SERVICE_UNAVAILABLE = 503,
|
|
64
|
+
GATEWAY_TIMEOUT = 504,
|
|
65
|
+
HTTP_VERSION_NOT_SUPPORTED = 505,
|
|
66
|
+
VARIANT_ALSO_NEGOTIATES = 506,
|
|
67
|
+
INSUFFICIENT_STORAGE = 507,
|
|
68
|
+
LOOP_DETECTED = 508,
|
|
69
|
+
NOT_EXTENDED = 510,
|
|
70
|
+
NETWORK_AUTHENTICATION_REQUIRED = 511
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Derived type containing only error status codes (>= 400).
|
|
74
|
+
* Includes client errors (4xx) and server errors (5xx).
|
|
75
|
+
*
|
|
76
|
+
* (Generated by Junie)
|
|
77
|
+
*/
|
|
78
|
+
export type HttpErrorStatus = HttpStatus.BAD_REQUEST | HttpStatus.UNAUTHORIZED | HttpStatus.PAYMENT_REQUIRED | HttpStatus.FORBIDDEN | HttpStatus.NOT_FOUND | HttpStatus.METHOD_NOT_ALLOWED | HttpStatus.NOT_ACCEPTABLE | HttpStatus.PROXY_AUTHENTICATION_REQUIRED | HttpStatus.REQUEST_TIMEOUT | HttpStatus.CONFLICT | HttpStatus.GONE | HttpStatus.LENGTH_REQUIRED | HttpStatus.PRECONDITION_FAILED | HttpStatus.CONTENT_TOO_LARGE | HttpStatus.URI_TOO_LONG | HttpStatus.UNSUPPORTED_MEDIA_TYPE | HttpStatus.RANGE_NOT_SATISFIABLE | HttpStatus.EXPECTATION_FAILED | HttpStatus.IM_A_TEAPOT | HttpStatus.MISDIRECTED_REQUEST | HttpStatus.UNPROCESSABLE_CONTENT | HttpStatus.LOCKED | HttpStatus.FAILED_DEPENDENCY | HttpStatus.TOO_EARLY | HttpStatus.UPGRADE_REQUIRED | HttpStatus.PRECONDITION_REQUIRED | HttpStatus.TOO_MANY_REQUESTS | HttpStatus.REQUEST_HEADER_FIELDS_TOO_LARGE | HttpStatus.UNAVAILABLE_FOR_LEGAL_REASONS | HttpStatus.INTERNAL_SERVER_ERROR | HttpStatus.NOT_IMPLEMENTED | HttpStatus.BAD_GATEWAY | HttpStatus.SERVICE_UNAVAILABLE | HttpStatus.GATEWAY_TIMEOUT | HttpStatus.HTTP_VERSION_NOT_SUPPORTED | HttpStatus.VARIANT_ALSO_NEGOTIATES | HttpStatus.INSUFFICIENT_STORAGE | HttpStatus.LOOP_DETECTED | HttpStatus.NOT_EXTENDED | HttpStatus.NETWORK_AUTHENTICATION_REQUIRED;
|
|
79
|
+
/**
|
|
80
|
+
* Deduce status text from the code.
|
|
81
|
+
* @param statusCode
|
|
82
|
+
*/
|
|
83
|
+
export declare const httpStatusText: (statusCode: HttpStatus) => string;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { toCamelCase } from '../../common/string.js';
|
|
2
|
+
/**
|
|
3
|
+
* HTTP Status Codes enum.
|
|
4
|
+
* Based on MDN Web Docs and IANA HTTP Status Code Registry.
|
|
5
|
+
* Covers all registered status codes from RFC 9110 and related RFCs.
|
|
6
|
+
*
|
|
7
|
+
* (Generated by Junie)
|
|
8
|
+
*/
|
|
9
|
+
export var HttpStatus;
|
|
10
|
+
(function (HttpStatus) {
|
|
11
|
+
// Informational responses (100–199)
|
|
12
|
+
HttpStatus[HttpStatus["CONTINUE"] = 100] = "CONTINUE";
|
|
13
|
+
HttpStatus[HttpStatus["SWITCHING_PROTOCOLS"] = 101] = "SWITCHING_PROTOCOLS";
|
|
14
|
+
HttpStatus[HttpStatus["PROCESSING"] = 102] = "PROCESSING";
|
|
15
|
+
HttpStatus[HttpStatus["EARLY_HINTS"] = 103] = "EARLY_HINTS";
|
|
16
|
+
// Successful responses (200–299)
|
|
17
|
+
HttpStatus[HttpStatus["OK"] = 200] = "OK";
|
|
18
|
+
HttpStatus[HttpStatus["CREATED"] = 201] = "CREATED";
|
|
19
|
+
HttpStatus[HttpStatus["ACCEPTED"] = 202] = "ACCEPTED";
|
|
20
|
+
HttpStatus[HttpStatus["NON_AUTHORITATIVE_INFORMATION"] = 203] = "NON_AUTHORITATIVE_INFORMATION";
|
|
21
|
+
HttpStatus[HttpStatus["NO_CONTENT"] = 204] = "NO_CONTENT";
|
|
22
|
+
HttpStatus[HttpStatus["RESET_CONTENT"] = 205] = "RESET_CONTENT";
|
|
23
|
+
HttpStatus[HttpStatus["PARTIAL_CONTENT"] = 206] = "PARTIAL_CONTENT";
|
|
24
|
+
HttpStatus[HttpStatus["MULTI_STATUS"] = 207] = "MULTI_STATUS";
|
|
25
|
+
HttpStatus[HttpStatus["ALREADY_REPORTED"] = 208] = "ALREADY_REPORTED";
|
|
26
|
+
HttpStatus[HttpStatus["IM_USED"] = 226] = "IM_USED";
|
|
27
|
+
// Redirection messages (300–399)
|
|
28
|
+
HttpStatus[HttpStatus["MULTIPLE_CHOICES"] = 300] = "MULTIPLE_CHOICES";
|
|
29
|
+
HttpStatus[HttpStatus["MOVED_PERMANENTLY"] = 301] = "MOVED_PERMANENTLY";
|
|
30
|
+
HttpStatus[HttpStatus["FOUND"] = 302] = "FOUND";
|
|
31
|
+
HttpStatus[HttpStatus["SEE_OTHER"] = 303] = "SEE_OTHER";
|
|
32
|
+
HttpStatus[HttpStatus["NOT_MODIFIED"] = 304] = "NOT_MODIFIED";
|
|
33
|
+
HttpStatus[HttpStatus["USE_PROXY"] = 305] = "USE_PROXY";
|
|
34
|
+
HttpStatus[HttpStatus["TEMPORARY_REDIRECT"] = 307] = "TEMPORARY_REDIRECT";
|
|
35
|
+
HttpStatus[HttpStatus["PERMANENT_REDIRECT"] = 308] = "PERMANENT_REDIRECT";
|
|
36
|
+
// Client error responses (400–499)
|
|
37
|
+
HttpStatus[HttpStatus["BAD_REQUEST"] = 400] = "BAD_REQUEST";
|
|
38
|
+
HttpStatus[HttpStatus["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
|
|
39
|
+
HttpStatus[HttpStatus["PAYMENT_REQUIRED"] = 402] = "PAYMENT_REQUIRED";
|
|
40
|
+
HttpStatus[HttpStatus["FORBIDDEN"] = 403] = "FORBIDDEN";
|
|
41
|
+
HttpStatus[HttpStatus["NOT_FOUND"] = 404] = "NOT_FOUND";
|
|
42
|
+
HttpStatus[HttpStatus["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED";
|
|
43
|
+
HttpStatus[HttpStatus["NOT_ACCEPTABLE"] = 406] = "NOT_ACCEPTABLE";
|
|
44
|
+
HttpStatus[HttpStatus["PROXY_AUTHENTICATION_REQUIRED"] = 407] = "PROXY_AUTHENTICATION_REQUIRED";
|
|
45
|
+
HttpStatus[HttpStatus["REQUEST_TIMEOUT"] = 408] = "REQUEST_TIMEOUT";
|
|
46
|
+
HttpStatus[HttpStatus["CONFLICT"] = 409] = "CONFLICT";
|
|
47
|
+
HttpStatus[HttpStatus["GONE"] = 410] = "GONE";
|
|
48
|
+
HttpStatus[HttpStatus["LENGTH_REQUIRED"] = 411] = "LENGTH_REQUIRED";
|
|
49
|
+
HttpStatus[HttpStatus["PRECONDITION_FAILED"] = 412] = "PRECONDITION_FAILED";
|
|
50
|
+
HttpStatus[HttpStatus["CONTENT_TOO_LARGE"] = 413] = "CONTENT_TOO_LARGE";
|
|
51
|
+
HttpStatus[HttpStatus["URI_TOO_LONG"] = 414] = "URI_TOO_LONG";
|
|
52
|
+
HttpStatus[HttpStatus["UNSUPPORTED_MEDIA_TYPE"] = 415] = "UNSUPPORTED_MEDIA_TYPE";
|
|
53
|
+
HttpStatus[HttpStatus["RANGE_NOT_SATISFIABLE"] = 416] = "RANGE_NOT_SATISFIABLE";
|
|
54
|
+
HttpStatus[HttpStatus["EXPECTATION_FAILED"] = 417] = "EXPECTATION_FAILED";
|
|
55
|
+
HttpStatus[HttpStatus["IM_A_TEAPOT"] = 418] = "IM_A_TEAPOT";
|
|
56
|
+
HttpStatus[HttpStatus["MISDIRECTED_REQUEST"] = 421] = "MISDIRECTED_REQUEST";
|
|
57
|
+
HttpStatus[HttpStatus["UNPROCESSABLE_CONTENT"] = 422] = "UNPROCESSABLE_CONTENT";
|
|
58
|
+
HttpStatus[HttpStatus["LOCKED"] = 423] = "LOCKED";
|
|
59
|
+
HttpStatus[HttpStatus["FAILED_DEPENDENCY"] = 424] = "FAILED_DEPENDENCY";
|
|
60
|
+
HttpStatus[HttpStatus["TOO_EARLY"] = 425] = "TOO_EARLY";
|
|
61
|
+
HttpStatus[HttpStatus["UPGRADE_REQUIRED"] = 426] = "UPGRADE_REQUIRED";
|
|
62
|
+
HttpStatus[HttpStatus["PRECONDITION_REQUIRED"] = 428] = "PRECONDITION_REQUIRED";
|
|
63
|
+
HttpStatus[HttpStatus["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
|
|
64
|
+
HttpStatus[HttpStatus["REQUEST_HEADER_FIELDS_TOO_LARGE"] = 431] = "REQUEST_HEADER_FIELDS_TOO_LARGE";
|
|
65
|
+
HttpStatus[HttpStatus["UNAVAILABLE_FOR_LEGAL_REASONS"] = 451] = "UNAVAILABLE_FOR_LEGAL_REASONS";
|
|
66
|
+
// Server error responses (500–599)
|
|
67
|
+
HttpStatus[HttpStatus["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
|
|
68
|
+
HttpStatus[HttpStatus["NOT_IMPLEMENTED"] = 501] = "NOT_IMPLEMENTED";
|
|
69
|
+
HttpStatus[HttpStatus["BAD_GATEWAY"] = 502] = "BAD_GATEWAY";
|
|
70
|
+
HttpStatus[HttpStatus["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
|
|
71
|
+
HttpStatus[HttpStatus["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT";
|
|
72
|
+
HttpStatus[HttpStatus["HTTP_VERSION_NOT_SUPPORTED"] = 505] = "HTTP_VERSION_NOT_SUPPORTED";
|
|
73
|
+
HttpStatus[HttpStatus["VARIANT_ALSO_NEGOTIATES"] = 506] = "VARIANT_ALSO_NEGOTIATES";
|
|
74
|
+
HttpStatus[HttpStatus["INSUFFICIENT_STORAGE"] = 507] = "INSUFFICIENT_STORAGE";
|
|
75
|
+
HttpStatus[HttpStatus["LOOP_DETECTED"] = 508] = "LOOP_DETECTED";
|
|
76
|
+
HttpStatus[HttpStatus["NOT_EXTENDED"] = 510] = "NOT_EXTENDED";
|
|
77
|
+
HttpStatus[HttpStatus["NETWORK_AUTHENTICATION_REQUIRED"] = 511] = "NETWORK_AUTHENTICATION_REQUIRED";
|
|
78
|
+
})(HttpStatus || (HttpStatus = {}));
|
|
79
|
+
/**
|
|
80
|
+
* Deduce status text from the code.
|
|
81
|
+
* @param statusCode
|
|
82
|
+
*/
|
|
83
|
+
export const httpStatusText = (statusCode) => {
|
|
84
|
+
if (!HttpStatus[statusCode]) {
|
|
85
|
+
throw new Error(`Unknown http status code: ${statusCode}`);
|
|
86
|
+
}
|
|
87
|
+
if (statusCode === HttpStatus.OK) {
|
|
88
|
+
return HttpStatus[HttpStatus.OK];
|
|
89
|
+
}
|
|
90
|
+
return HttpStatus[statusCode]
|
|
91
|
+
.split('_')
|
|
92
|
+
.map(toCamelCase)
|
|
93
|
+
.join(' ');
|
|
94
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { RouteEndpoint, RouteEndpointStruct, RouteHandler } from './types.js';
|
|
2
|
+
export declare class Route {
|
|
3
|
+
constructor(endpoint: RouteEndpoint, handler: RouteHandler);
|
|
4
|
+
/*** Public ***/
|
|
5
|
+
readonly endpoint: RouteEndpointStruct;
|
|
6
|
+
readonly handler: RouteHandler;
|
|
7
|
+
/*** Private ***/
|
|
8
|
+
private parseEndpoint;
|
|
9
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { isObj } from '../lib/common/isType.js';
|
|
2
|
+
import { HttpMethod } from '../lib/http-meta/index.js';
|
|
3
|
+
const httpMethodsList = Object.values(HttpMethod).join('|'), stringEndpointPattern = new RegExp(`^(${httpMethodsList})\\s(/.*)$`);
|
|
4
|
+
export class Route {
|
|
5
|
+
constructor(endpoint, handler) {
|
|
6
|
+
this.endpoint = this.parseEndpoint(endpoint);
|
|
7
|
+
this.handler = handler;
|
|
8
|
+
}
|
|
9
|
+
/*** Private ***/
|
|
10
|
+
parseEndpoint(endpoint) {
|
|
11
|
+
if (isObj(endpoint)) {
|
|
12
|
+
return endpoint;
|
|
13
|
+
}
|
|
14
|
+
const match = endpoint.match(stringEndpointPattern);
|
|
15
|
+
if (match) {
|
|
16
|
+
const [, method, path] = match;
|
|
17
|
+
return { method: method, path };
|
|
18
|
+
}
|
|
19
|
+
throw new Error(`Invalid route endpoint: ${endpoint}`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { HttpMethod, SuccessResponse } from '../lib/http-meta/index.js';
|
|
2
|
+
import { Route } from './Route.js';
|
|
3
|
+
import { afterEach } from 'node:test';
|
|
4
|
+
describe('Route', () => {
|
|
5
|
+
let defaultHandler;
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
defaultHandler = () => Promise.resolve(new SuccessResponse());
|
|
8
|
+
});
|
|
9
|
+
afterEach(() => {
|
|
10
|
+
jest.resetAllMocks();
|
|
11
|
+
});
|
|
12
|
+
it('constructs with struct endpoint', () => {
|
|
13
|
+
const endpoint = { method: HttpMethod.POST, path: '/foo' }, handler = () => Promise.resolve(new SuccessResponse()), route = new Route(endpoint, handler);
|
|
14
|
+
expect(route.endpoint).toBe(endpoint);
|
|
15
|
+
expect(route.handler).toBe(handler);
|
|
16
|
+
});
|
|
17
|
+
it('constructs with string endpoint (method + path format)', () => {
|
|
18
|
+
const endpoint = 'PUT /bar/:id', expectedEndpoint = { method: HttpMethod.PUT, path: '/bar/:id' }, handler = () => Promise.resolve(new SuccessResponse()), route = new Route(endpoint, handler);
|
|
19
|
+
expect(route.endpoint).toEqual(expectedEndpoint);
|
|
20
|
+
});
|
|
21
|
+
it('errors out when incorrect endpoint string', () => {
|
|
22
|
+
['get /foo', 'POST bar', 'baz', ''].forEach(edp => {
|
|
23
|
+
expect(() => new Route(edp, defaultHandler)).toThrow(new Error(`Invalid route endpoint: ${edp}`));
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import { Route } from './Route.js';
|
|
3
|
+
export declare class ServicioApp {
|
|
4
|
+
private readonly _express;
|
|
5
|
+
constructor(_express: express.Express);
|
|
6
|
+
/*** Public ***/
|
|
7
|
+
addRoute(route: Route): this;
|
|
8
|
+
/*** Private ***/
|
|
9
|
+
private wrapRouteHandler;
|
|
10
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
export class ServicioApp {
|
|
11
|
+
constructor(_express) {
|
|
12
|
+
this._express = _express;
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
_express.use((_, res, next, err) => {
|
|
15
|
+
console.log('=== err', err);
|
|
16
|
+
return next();
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
/*** Public ***/
|
|
20
|
+
addRoute(route) {
|
|
21
|
+
const expressMethod = route.endpoint.method.toLowerCase();
|
|
22
|
+
// @ts-ignore: TODO ?
|
|
23
|
+
this._express[expressMethod](route.endpoint.path, this.wrapRouteHandler(route.handler));
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
/*** Private ***/
|
|
27
|
+
wrapRouteHandler(handler) {
|
|
28
|
+
return (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
const handlerRes = yield handler(req), sendArgs = [];
|
|
30
|
+
if (handlerRes.headers) {
|
|
31
|
+
res.set(handlerRes.headers);
|
|
32
|
+
}
|
|
33
|
+
if (handlerRes.body) {
|
|
34
|
+
sendArgs.push(handlerRes.body);
|
|
35
|
+
}
|
|
36
|
+
res.status(handlerRes.status).send(...sendArgs);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import express from 'express';
|
|
11
|
+
import { HttpMethod, HttpStatus, SuccessResponse } from '../lib/http-meta/index.js';
|
|
12
|
+
import { Route } from './Route.js';
|
|
13
|
+
import { ServicioApp } from './ServicioApp.js';
|
|
14
|
+
import { expressRequestMock, expressResponseMock } from '../../spec/index.js';
|
|
15
|
+
describe('ServicioApp', () => {
|
|
16
|
+
let expressApp, app, expressMethodMockMap;
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
expressApp = express();
|
|
19
|
+
app = new ServicioApp(expressApp);
|
|
20
|
+
expressMethodMockMap = Object.values(HttpMethod).reduce((acc, method) => Object.assign(acc, {
|
|
21
|
+
[method]: jest.spyOn(expressApp, method.toLowerCase()),
|
|
22
|
+
}), {});
|
|
23
|
+
});
|
|
24
|
+
afterEach(() => {
|
|
25
|
+
});
|
|
26
|
+
it('addRoute() adds route to express app for all methods', () => {
|
|
27
|
+
const paths = ['/foo', '/bar/:bar', '/abc'], endpoints = Object.values(HttpMethod).map(method => {
|
|
28
|
+
const pathIdx = Math.floor(Math.random() * paths.length), endpointPath = paths[pathIdx];
|
|
29
|
+
return { method, path: endpointPath };
|
|
30
|
+
});
|
|
31
|
+
const wrapRouteHandlerMock = mockWrapRouteHandler();
|
|
32
|
+
endpoints.forEach(endpoint => {
|
|
33
|
+
const route = new Route(endpoint, () => Promise.resolve(new SuccessResponse()));
|
|
34
|
+
const expressMethodMock = expressMethodMockMap[endpoint.method];
|
|
35
|
+
app.addRoute(route);
|
|
36
|
+
expect(expressMethodMock).toHaveBeenCalledWith(route.endpoint.path, wrapRouteHandlerMock);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
it('addRoute() wraps route handler to send http status', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
|
+
const response = new SuccessResponse(HttpStatus.ACCEPTED), route = new Route('GET /foo', () => Promise.resolve(response));
|
|
41
|
+
const resMock = yield runRouteHandlerWrapper(route);
|
|
42
|
+
expect(resMock.status).toHaveBeenCalledWith(response.status);
|
|
43
|
+
expect(resMock.send).toHaveBeenCalled();
|
|
44
|
+
}));
|
|
45
|
+
it('addRoute() wraps route handler to send http body', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
+
const responseBody = { foo: 'bar' }, response = new SuccessResponse({ status: HttpStatus.OK, body: responseBody }), route = new Route('GET /foo', () => Promise.resolve(response));
|
|
47
|
+
const resMock = yield runRouteHandlerWrapper(route);
|
|
48
|
+
expect(resMock.status).toHaveBeenCalledWith(response.status);
|
|
49
|
+
expect(resMock.status).toHaveBeenCalledBefore(resMock.send);
|
|
50
|
+
expect(resMock.send).toHaveBeenCalledWith(responseBody);
|
|
51
|
+
}));
|
|
52
|
+
it('addRoute() wraps route handler to send http headers', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
53
|
+
const responseHeaders = { 'x-header': 'abc' }, response = new SuccessResponse({ status: HttpStatus.OK, headers: responseHeaders }), route = new Route('GET /foo', () => Promise.resolve(response));
|
|
54
|
+
const resMock = yield runRouteHandlerWrapper(route);
|
|
55
|
+
expect(resMock.status).toHaveBeenCalledWith(response.status);
|
|
56
|
+
expect(resMock.set).toHaveBeenCalledWith(responseHeaders);
|
|
57
|
+
expect(resMock.set).toHaveBeenCalledBefore(resMock.send);
|
|
58
|
+
expect(resMock.send).toHaveBeenCalled();
|
|
59
|
+
}));
|
|
60
|
+
it('addRoute() wraps route handler to send http status, body and headers', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
61
|
+
const responseHeaders = { 'x-header': 'abc' }, responseBody = { ok: true }, response = new SuccessResponse({ status: HttpStatus.OK, headers: responseHeaders, body: responseBody }), route = new Route('GET /foo', () => Promise.resolve(response));
|
|
62
|
+
const resMock = yield runRouteHandlerWrapper(route);
|
|
63
|
+
expect(resMock.status).toHaveBeenCalledWith(response.status);
|
|
64
|
+
expect(resMock.set).toHaveBeenCalledWith(responseHeaders);
|
|
65
|
+
expect(resMock.send).toHaveBeenCalledWith(responseBody);
|
|
66
|
+
}));
|
|
67
|
+
/*** Private ***/
|
|
68
|
+
function mockWrapRouteHandler() {
|
|
69
|
+
const mock = jest.fn();
|
|
70
|
+
// @ts-ignore: Mocking private member
|
|
71
|
+
jest.spyOn(app, 'wrapRouteHandler').mockReturnValue(mock);
|
|
72
|
+
return mock;
|
|
73
|
+
}
|
|
74
|
+
function runRouteHandlerWrapper(route) {
|
|
75
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
const expressMethodMock = jest.spyOn(expressApp, route.endpoint.method.toLowerCase());
|
|
77
|
+
app.addRoute(route);
|
|
78
|
+
const routeHandlerWrapper = expressMethodMock.mock.calls[0][1];
|
|
79
|
+
const resMock = expressResponseMock();
|
|
80
|
+
// @ts-ignore
|
|
81
|
+
yield routeHandlerWrapper(expressRequestMock(), resMock);
|
|
82
|
+
return resMock;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|