@arkyn/server 3.0.1-beta.12 → 3.0.1-beta.121
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +368 -65
- package/dist/bundle.js +1518 -0
- package/dist/bundle.umd.cjs +5 -0
- package/dist/{api/arkynLogRequest.d.ts → http/api/_logRequest.d.ts} +22 -19
- package/dist/{api/arkynLogRequest.d.ts.map → http/api/_logRequest.d.ts.map} +1 -1
- package/dist/http/api/_logRequest.js +88 -0
- package/dist/http/api/_makeRequest.d.ts +61 -0
- package/dist/http/api/_makeRequest.d.ts.map +1 -0
- package/dist/{api/makeRequest.js → http/api/_makeRequest.js} +33 -20
- package/dist/http/api/deleteRequest.d.ts +17 -0
- package/dist/http/api/deleteRequest.d.ts.map +1 -0
- package/dist/http/api/deleteRequest.js +18 -0
- package/dist/http/api/getRequest.d.ts +16 -0
- package/dist/http/api/getRequest.d.ts.map +1 -0
- package/dist/http/api/getRequest.js +17 -0
- package/dist/http/api/patchRequest.d.ts +17 -0
- package/dist/http/api/patchRequest.d.ts.map +1 -0
- package/dist/http/api/patchRequest.js +18 -0
- package/dist/http/api/postRequest.d.ts +17 -0
- package/dist/http/api/postRequest.d.ts.map +1 -0
- package/dist/http/api/postRequest.js +18 -0
- package/dist/http/api/putRequest.d.ts +17 -0
- package/dist/http/api/putRequest.d.ts.map +1 -0
- package/dist/http/api/putRequest.js +18 -0
- package/dist/http/badResponses/_badResponse.d.ts +22 -0
- package/dist/http/badResponses/_badResponse.d.ts.map +1 -0
- package/dist/http/badResponses/_badResponse.js +51 -0
- package/dist/http/badResponses/badGateway.d.ts +6 -9
- package/dist/http/badResponses/badGateway.d.ts.map +1 -1
- package/dist/http/badResponses/badGateway.js +12 -14
- package/dist/http/badResponses/badRequest.d.ts +6 -9
- package/dist/http/badResponses/badRequest.d.ts.map +1 -1
- package/dist/http/badResponses/badRequest.js +12 -14
- package/dist/http/badResponses/conflict.d.ts +6 -9
- package/dist/http/badResponses/conflict.d.ts.map +1 -1
- package/dist/http/badResponses/conflict.js +12 -14
- package/dist/http/badResponses/forbidden.d.ts +6 -9
- package/dist/http/badResponses/forbidden.d.ts.map +1 -1
- package/dist/http/badResponses/forbidden.js +12 -14
- package/dist/http/badResponses/notFound.d.ts +6 -9
- package/dist/http/badResponses/notFound.d.ts.map +1 -1
- package/dist/http/badResponses/notFound.js +12 -14
- package/dist/http/badResponses/notImplemented.d.ts +6 -9
- package/dist/http/badResponses/notImplemented.d.ts.map +1 -1
- package/dist/http/badResponses/notImplemented.js +12 -14
- package/dist/http/badResponses/serverError.d.ts +6 -9
- package/dist/http/badResponses/serverError.d.ts.map +1 -1
- package/dist/http/badResponses/serverError.js +12 -14
- package/dist/http/badResponses/unauthorized.d.ts +4 -7
- package/dist/http/badResponses/unauthorized.d.ts.map +1 -1
- package/dist/http/badResponses/unauthorized.js +10 -12
- package/dist/http/badResponses/unprocessableEntity.d.ts +15 -19
- package/dist/http/badResponses/unprocessableEntity.d.ts.map +1 -1
- package/dist/http/badResponses/unprocessableEntity.js +18 -21
- package/dist/http/successResponses/_successResponse.d.ts +33 -0
- package/dist/http/successResponses/_successResponse.d.ts.map +1 -0
- package/dist/http/successResponses/_successResponse.js +66 -0
- package/dist/http/successResponses/created.d.ts +9 -19
- package/dist/http/successResponses/created.d.ts.map +1 -1
- package/dist/http/successResponses/created.js +16 -25
- package/dist/http/successResponses/found.d.ts +10 -23
- package/dist/http/successResponses/found.d.ts.map +1 -1
- package/dist/http/successResponses/found.js +17 -29
- package/dist/http/successResponses/noContent.d.ts +6 -13
- package/dist/http/successResponses/noContent.d.ts.map +1 -1
- package/dist/http/successResponses/noContent.js +12 -17
- package/dist/http/successResponses/success.d.ts +9 -19
- package/dist/http/successResponses/success.d.ts.map +1 -1
- package/dist/http/successResponses/success.js +16 -25
- package/dist/http/successResponses/updated.d.ts +9 -19
- package/dist/http/successResponses/updated.d.ts.map +1 -1
- package/dist/http/successResponses/updated.js +16 -25
- package/dist/index.d.ts +19 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -13
- package/dist/services/apiService.d.ts +63 -0
- package/dist/services/apiService.d.ts.map +1 -0
- package/dist/services/apiService.js +158 -0
- package/dist/services/debugService.d.ts +69 -0
- package/dist/services/debugService.d.ts.map +1 -0
- package/dist/services/debugService.js +114 -0
- package/dist/services/logMapperService.d.ts +86 -0
- package/dist/services/logMapperService.d.ts.map +1 -0
- package/dist/services/logMapperService.js +68 -0
- package/dist/services/logService.d.ts +38 -0
- package/dist/services/logService.d.ts.map +1 -0
- package/dist/services/logService.js +40 -0
- package/dist/{services → utilities}/decodeRequestBody.d.ts +3 -4
- package/dist/utilities/decodeRequestBody.d.ts.map +1 -0
- package/dist/{services → utilities}/decodeRequestBody.js +5 -5
- package/dist/{services/decodeErrorMessageFromRequest.d.ts → utilities/decodeRequestErrorMessage.d.ts} +6 -6
- package/dist/utilities/decodeRequestErrorMessage.d.ts.map +1 -0
- package/dist/{services/decodeErrorMessageFromRequest.js → utilities/decodeRequestErrorMessage.js} +5 -5
- package/dist/utilities/errorHandler.d.ts +50 -0
- package/dist/utilities/errorHandler.d.ts.map +1 -0
- package/dist/{services → utilities}/errorHandler.js +34 -28
- package/dist/utilities/flushDebugLogs.d.ts +46 -0
- package/dist/utilities/flushDebugLogs.d.ts.map +1 -0
- package/dist/utilities/flushDebugLogs.js +59 -0
- package/dist/utilities/formAsyncParse.d.ts +59 -0
- package/dist/utilities/formAsyncParse.d.ts.map +1 -0
- package/dist/utilities/formAsyncParse.js +58 -0
- package/dist/{services → utilities}/formParse.d.ts +6 -6
- package/dist/utilities/formParse.d.ts.map +1 -0
- package/dist/{services → utilities}/formParse.js +10 -8
- package/dist/{services → utilities}/getScopedParams.d.ts +3 -4
- package/dist/utilities/getScopedParams.d.ts.map +1 -0
- package/dist/{services → utilities}/getScopedParams.js +4 -4
- package/dist/utilities/schemaValidator.d.ts +146 -0
- package/dist/utilities/schemaValidator.d.ts.map +1 -0
- package/dist/utilities/schemaValidator.js +191 -0
- package/dist/validations/validateCep.d.ts +19 -0
- package/dist/validations/validateCep.d.ts.map +1 -0
- package/dist/validations/validateCep.js +27 -0
- package/dist/validations/validateCnpj.d.ts +21 -0
- package/dist/validations/validateCnpj.d.ts.map +1 -0
- package/dist/validations/validateCnpj.js +59 -0
- package/dist/validations/validateCpf.d.ts +23 -0
- package/dist/validations/validateCpf.d.ts.map +1 -0
- package/dist/validations/validateCpf.js +61 -0
- package/dist/validations/validateDate.d.ts +27 -0
- package/dist/validations/validateDate.d.ts.map +1 -0
- package/dist/validations/validateDate.js +55 -0
- package/dist/validations/validateEmail.d.ts +21 -0
- package/dist/validations/validateEmail.d.ts.map +1 -0
- package/dist/validations/validateEmail.js +111 -0
- package/dist/validations/validatePassword.d.ts +20 -0
- package/dist/validations/validatePassword.d.ts.map +1 -0
- package/dist/validations/validatePassword.js +34 -0
- package/dist/validations/validatePhone.d.ts +28 -0
- package/dist/validations/validatePhone.d.ts.map +1 -0
- package/dist/validations/validatePhone.js +44 -0
- package/dist/validations/validateRg.d.ts +21 -0
- package/dist/validations/validateRg.d.ts.map +1 -0
- package/dist/validations/validateRg.js +31 -0
- package/package.json +34 -18
- package/dist/api/arkynLogRequest.js +0 -82
- package/dist/api/deleteRequest.d.ts +0 -13
- package/dist/api/deleteRequest.d.ts.map +0 -1
- package/dist/api/deleteRequest.js +0 -14
- package/dist/api/getRequest.d.ts +0 -12
- package/dist/api/getRequest.d.ts.map +0 -1
- package/dist/api/getRequest.js +0 -13
- package/dist/api/makeRequest.d.ts +0 -38
- package/dist/api/makeRequest.d.ts.map +0 -1
- package/dist/api/patchRequest.d.ts +0 -13
- package/dist/api/patchRequest.d.ts.map +0 -1
- package/dist/api/patchRequest.js +0 -14
- package/dist/api/postRequest.d.ts +0 -13
- package/dist/api/postRequest.d.ts.map +0 -1
- package/dist/api/postRequest.js +0 -14
- package/dist/api/putRequest.d.ts +0 -13
- package/dist/api/putRequest.d.ts.map +0 -1
- package/dist/api/putRequest.js +0 -14
- package/dist/config/apiInstance.d.ts +0 -80
- package/dist/config/apiInstance.d.ts.map +0 -1
- package/dist/config/apiInstance.js +0 -111
- package/dist/config/arkynLogInstance.d.ts +0 -44
- package/dist/config/arkynLogInstance.d.ts.map +0 -1
- package/dist/config/arkynLogInstance.js +0 -49
- package/dist/mapper/arkynLogRequestMapper.d.ts +0 -30
- package/dist/mapper/arkynLogRequestMapper.d.ts.map +0 -1
- package/dist/mapper/arkynLogRequestMapper.js +0 -44
- package/dist/services/decodeErrorMessageFromRequest.d.ts.map +0 -1
- package/dist/services/decodeRequestBody.d.ts.map +0 -1
- package/dist/services/errorHandler.d.ts +0 -44
- package/dist/services/errorHandler.d.ts.map +0 -1
- package/dist/services/formParse.d.ts.map +0 -1
- package/dist/services/getCaller.d.ts +0 -17
- package/dist/services/getCaller.d.ts.map +0 -1
- package/dist/services/getCaller.js +0 -65
- package/dist/services/getScopedParams.d.ts.map +0 -1
- package/dist/services/httpDebug.d.ts +0 -35
- package/dist/services/httpDebug.d.ts.map +0 -1
- package/dist/services/httpDebug.js +0 -52
- package/dist/services/measureRouteExecution.d.ts +0 -3
- package/dist/services/measureRouteExecution.d.ts.map +0 -1
- package/dist/services/measureRouteExecution.js +0 -24
- package/dist/services/schemaValidator.d.ts +0 -13
- package/dist/services/schemaValidator.d.ts.map +0 -1
- package/dist/services/schemaValidator.js +0 -51
- package/dist/types/ApiResponseDTO.d.ts +0 -17
- package/dist/types/ApiResponseDTO.d.ts.map +0 -1
- package/dist/types/ApiResponseDTO.js +0 -1
- package/src/api/arkynLogRequest.ts +0 -118
- package/src/api/deleteRequest.ts +0 -22
- package/src/api/getRequest.ts +0 -20
- package/src/api/makeRequest.ts +0 -118
- package/src/api/patchRequest.ts +0 -22
- package/src/api/postRequest.ts +0 -22
- package/src/api/putRequest.ts +0 -22
- package/src/config/apiInstance.ts +0 -148
- package/src/config/arkynLogInstance.ts +0 -70
- package/src/http/badResponses/badGateway.ts +0 -63
- package/src/http/badResponses/badRequest.ts +0 -63
- package/src/http/badResponses/conflict.ts +0 -63
- package/src/http/badResponses/forbidden.ts +0 -63
- package/src/http/badResponses/notFound.ts +0 -63
- package/src/http/badResponses/notImplemented.ts +0 -63
- package/src/http/badResponses/serverError.ts +0 -63
- package/src/http/badResponses/unauthorized.ts +0 -63
- package/src/http/badResponses/unprocessableEntity.ts +0 -79
- package/src/http/successResponses/created.ts +0 -64
- package/src/http/successResponses/found.ts +0 -67
- package/src/http/successResponses/noContent.ts +0 -42
- package/src/http/successResponses/success.ts +0 -64
- package/src/http/successResponses/updated.ts +0 -64
- package/src/index.ts +0 -31
- package/src/mapper/arkynLogRequestMapper.ts +0 -73
- package/src/services/decodeErrorMessageFromRequest.ts +0 -36
- package/src/services/decodeRequestBody.ts +0 -43
- package/src/services/errorHandler.ts +0 -99
- package/src/services/formParse.ts +0 -83
- package/src/services/getCaller.ts +0 -82
- package/src/services/getScopedParams.ts +0 -43
- package/src/services/httpDebug.ts +0 -61
- package/src/services/measureRouteExecution.ts +0 -31
- package/src/services/schemaValidator.ts +0 -66
- package/src/types/ApiResponseDTO.ts +0 -19
- package/tsconfig.json +0 -21
- package/vitest.config.ts +0 -5
|
@@ -1,31 +1,29 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BadResponse } from "./_badResponse";
|
|
2
2
|
/**
|
|
3
3
|
* Represents an HTTP error response with a status code of 501 (Not Implemented).
|
|
4
4
|
* This class is used to standardize the structure of a "Not Implemented" error response,
|
|
5
5
|
* including the response body, headers, status, and status text.
|
|
6
6
|
*/
|
|
7
|
-
class NotImplemented {
|
|
8
|
-
body;
|
|
9
|
-
cause;
|
|
10
|
-
status = 501;
|
|
11
|
-
statusText;
|
|
7
|
+
class NotImplemented extends BadResponse {
|
|
12
8
|
/**
|
|
13
9
|
* Creates an instance of the `NotImplemented` class.
|
|
14
10
|
*
|
|
15
|
-
* @param message - A descriptive message explaining why the functionality is not implemented.
|
|
16
|
-
* @param cause - Optional additional information about the cause of the error.
|
|
11
|
+
* @param {string} message - A descriptive message explaining why the functionality is not implemented.
|
|
12
|
+
* @param {any} cause - Optional additional information about the cause of the error.
|
|
17
13
|
*/
|
|
18
14
|
constructor(message, cause) {
|
|
19
|
-
|
|
15
|
+
super();
|
|
16
|
+
this.name = "NotImplemented";
|
|
17
|
+
this.status = 501;
|
|
20
18
|
this.statusText = message;
|
|
21
19
|
this.cause = cause ? JSON.stringify(cause) : undefined;
|
|
22
|
-
|
|
20
|
+
this.onDebug();
|
|
23
21
|
}
|
|
24
22
|
/**
|
|
25
23
|
* Converts the `NotImplemented` instance into a `Response` object with a JSON body.
|
|
26
24
|
* This method ensures the response has the appropriate headers, status, and status text.
|
|
27
25
|
*
|
|
28
|
-
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
26
|
+
* @returns {Response} A `Response` object with the serialized JSON body and response metadata.
|
|
29
27
|
*/
|
|
30
28
|
toResponse() {
|
|
31
29
|
const responseInit = {
|
|
@@ -33,20 +31,20 @@ class NotImplemented {
|
|
|
33
31
|
status: this.status,
|
|
34
32
|
statusText: this.statusText,
|
|
35
33
|
};
|
|
36
|
-
return new Response(JSON.stringify(this.
|
|
34
|
+
return new Response(JSON.stringify(this.makeBody()), responseInit);
|
|
37
35
|
}
|
|
38
36
|
/**
|
|
39
37
|
* Converts the `NotImplemented` instance into a `Response` object using the `Response.json` method.
|
|
40
38
|
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
41
39
|
*
|
|
42
|
-
* @returns A `Response` object with the JSON body and response metadata.
|
|
40
|
+
* @returns {Response["json"]} A `Response` object with the JSON body and response metadata.
|
|
43
41
|
*/
|
|
44
42
|
toJson() {
|
|
45
43
|
const responseInit = {
|
|
46
44
|
status: this.status,
|
|
47
45
|
statusText: this.statusText,
|
|
48
46
|
};
|
|
49
|
-
return Response.json(this.
|
|
47
|
+
return Response.json(this.makeBody(), responseInit);
|
|
50
48
|
}
|
|
51
49
|
}
|
|
52
50
|
export { NotImplemented };
|
|
@@ -1,32 +1,29 @@
|
|
|
1
|
+
import { BadResponse } from "./_badResponse";
|
|
1
2
|
/**
|
|
2
3
|
* Represents an HTTP error response with a status code of 500 (Internal Server Error).
|
|
3
4
|
* This class is used to standardize the structure of a "Server Error" response,
|
|
4
5
|
* including the response body, headers, status, and status text.
|
|
5
6
|
*/
|
|
6
|
-
declare class ServerError {
|
|
7
|
-
body: any;
|
|
8
|
-
cause?: any;
|
|
9
|
-
status: number;
|
|
10
|
-
statusText: string;
|
|
7
|
+
declare class ServerError extends BadResponse {
|
|
11
8
|
/**
|
|
12
9
|
* Creates an instance of the `ServerError` class.
|
|
13
10
|
*
|
|
14
|
-
* @param message - A descriptive message explaining the cause of the server error.
|
|
15
|
-
* @param cause - Optional additional information about the cause of the error.
|
|
11
|
+
* @param {string} message - A descriptive message explaining the cause of the server error.
|
|
12
|
+
* @param {any} cause - Optional additional information about the cause of the error.
|
|
16
13
|
*/
|
|
17
14
|
constructor(message: string, cause?: any);
|
|
18
15
|
/**
|
|
19
16
|
* Converts the `ServerError` instance into a `Response` object with a JSON body.
|
|
20
17
|
* This method ensures the response has the appropriate headers, status, and status text.
|
|
21
18
|
*
|
|
22
|
-
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
19
|
+
* @returns {Response} A `Response` object with the serialized JSON body and response metadata.
|
|
23
20
|
*/
|
|
24
21
|
toResponse(): Response;
|
|
25
22
|
/**
|
|
26
23
|
* Converts the `ServerError` instance into a `Response` object using the `Response.json` method.
|
|
27
24
|
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
28
25
|
*
|
|
29
|
-
* @returns A `Response` object with the JSON body and response metadata.
|
|
26
|
+
* @returns {Response["json"]} A `Response` object with the JSON body and response metadata.
|
|
30
27
|
*/
|
|
31
28
|
toJson(): Response;
|
|
32
29
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serverError.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/serverError.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"serverError.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/serverError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;GAIG;AAEH,cAAM,WAAY,SAAQ,WAAW;IACnC;;;;;OAKG;gBAES,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;IAWxC;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CAQnB;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -1,31 +1,29 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BadResponse } from "./_badResponse";
|
|
2
2
|
/**
|
|
3
3
|
* Represents an HTTP error response with a status code of 500 (Internal Server Error).
|
|
4
4
|
* This class is used to standardize the structure of a "Server Error" response,
|
|
5
5
|
* including the response body, headers, status, and status text.
|
|
6
6
|
*/
|
|
7
|
-
class ServerError {
|
|
8
|
-
body;
|
|
9
|
-
cause;
|
|
10
|
-
status = 500;
|
|
11
|
-
statusText;
|
|
7
|
+
class ServerError extends BadResponse {
|
|
12
8
|
/**
|
|
13
9
|
* Creates an instance of the `ServerError` class.
|
|
14
10
|
*
|
|
15
|
-
* @param message - A descriptive message explaining the cause of the server error.
|
|
16
|
-
* @param cause - Optional additional information about the cause of the error.
|
|
11
|
+
* @param {string} message - A descriptive message explaining the cause of the server error.
|
|
12
|
+
* @param {any} cause - Optional additional information about the cause of the error.
|
|
17
13
|
*/
|
|
18
14
|
constructor(message, cause) {
|
|
19
|
-
|
|
15
|
+
super();
|
|
16
|
+
this.name = "ServerError";
|
|
17
|
+
this.status = 500;
|
|
20
18
|
this.statusText = message;
|
|
21
19
|
this.cause = cause ? JSON.stringify(cause) : undefined;
|
|
22
|
-
|
|
20
|
+
this.onDebug();
|
|
23
21
|
}
|
|
24
22
|
/**
|
|
25
23
|
* Converts the `ServerError` instance into a `Response` object with a JSON body.
|
|
26
24
|
* This method ensures the response has the appropriate headers, status, and status text.
|
|
27
25
|
*
|
|
28
|
-
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
26
|
+
* @returns {Response} A `Response` object with the serialized JSON body and response metadata.
|
|
29
27
|
*/
|
|
30
28
|
toResponse() {
|
|
31
29
|
const responseInit = {
|
|
@@ -33,20 +31,20 @@ class ServerError {
|
|
|
33
31
|
status: this.status,
|
|
34
32
|
statusText: this.statusText,
|
|
35
33
|
};
|
|
36
|
-
return new Response(JSON.stringify(this.
|
|
34
|
+
return new Response(JSON.stringify(this.makeBody()), responseInit);
|
|
37
35
|
}
|
|
38
36
|
/**
|
|
39
37
|
* Converts the `ServerError` instance into a `Response` object using the `Response.json` method.
|
|
40
38
|
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
41
39
|
*
|
|
42
|
-
* @returns A `Response` object with the JSON body and response metadata.
|
|
40
|
+
* @returns {Response["json"]} A `Response` object with the JSON body and response metadata.
|
|
43
41
|
*/
|
|
44
42
|
toJson() {
|
|
45
43
|
const responseInit = {
|
|
46
44
|
status: this.status,
|
|
47
45
|
statusText: this.statusText,
|
|
48
46
|
};
|
|
49
|
-
return Response.json(this.
|
|
47
|
+
return Response.json(this.makeBody(), responseInit);
|
|
50
48
|
}
|
|
51
49
|
}
|
|
52
50
|
export { ServerError };
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
+
import { BadResponse } from "./_badResponse";
|
|
1
2
|
/**
|
|
2
3
|
* Represents an HTTP error response with a status code of 401 (Unauthorized).
|
|
3
4
|
* This class is used to standardize the structure of an "Unauthorized" error response,
|
|
4
5
|
* including the response body, headers, status, and status text.
|
|
5
6
|
*/
|
|
6
|
-
declare class Unauthorized {
|
|
7
|
-
body: any;
|
|
8
|
-
cause?: any;
|
|
9
|
-
status: number;
|
|
10
|
-
statusText: string;
|
|
7
|
+
declare class Unauthorized extends BadResponse {
|
|
11
8
|
/**
|
|
12
9
|
* Creates an instance of the `Unauthorized` class.
|
|
13
10
|
*
|
|
@@ -19,14 +16,14 @@ declare class Unauthorized {
|
|
|
19
16
|
* Converts the `Unauthorized` instance into a `Response` object with a JSON body.
|
|
20
17
|
* This method ensures the response has the appropriate headers, status, and status text.
|
|
21
18
|
*
|
|
22
|
-
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
19
|
+
* @returns {Response} A `Response` object with the serialized JSON body and response metadata.
|
|
23
20
|
*/
|
|
24
21
|
toResponse(): Response;
|
|
25
22
|
/**
|
|
26
23
|
* Converts the `Unauthorized` instance into a `Response` object using the `Response.json` method.
|
|
27
24
|
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
28
25
|
*
|
|
29
|
-
* @returns A `Response` object with the JSON body and response metadata.
|
|
26
|
+
* @returns {Response["json"]} A `Response` object with the JSON body and response metadata.
|
|
30
27
|
*/
|
|
31
28
|
toJson(): Response;
|
|
32
29
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unauthorized.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/unauthorized.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"unauthorized.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/unauthorized.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;GAIG;AAEH,cAAM,YAAa,SAAQ,WAAW;IACpC;;;;;OAKG;gBAES,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;IAWxC;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CAQnB;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BadResponse } from "./_badResponse";
|
|
2
2
|
/**
|
|
3
3
|
* Represents an HTTP error response with a status code of 401 (Unauthorized).
|
|
4
4
|
* This class is used to standardize the structure of an "Unauthorized" error response,
|
|
5
5
|
* including the response body, headers, status, and status text.
|
|
6
6
|
*/
|
|
7
|
-
class Unauthorized {
|
|
8
|
-
body;
|
|
9
|
-
cause;
|
|
10
|
-
status = 401;
|
|
11
|
-
statusText;
|
|
7
|
+
class Unauthorized extends BadResponse {
|
|
12
8
|
/**
|
|
13
9
|
* Creates an instance of the `Unauthorized` class.
|
|
14
10
|
*
|
|
@@ -16,16 +12,18 @@ class Unauthorized {
|
|
|
16
12
|
* @param cause - Optional additional information about the cause of the error.
|
|
17
13
|
*/
|
|
18
14
|
constructor(message, cause) {
|
|
19
|
-
|
|
15
|
+
super();
|
|
16
|
+
this.name = "Unauthorized";
|
|
17
|
+
this.status = 401;
|
|
20
18
|
this.statusText = message;
|
|
21
19
|
this.cause = cause ? JSON.stringify(cause) : undefined;
|
|
22
|
-
|
|
20
|
+
this.onDebug();
|
|
23
21
|
}
|
|
24
22
|
/**
|
|
25
23
|
* Converts the `Unauthorized` instance into a `Response` object with a JSON body.
|
|
26
24
|
* This method ensures the response has the appropriate headers, status, and status text.
|
|
27
25
|
*
|
|
28
|
-
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
26
|
+
* @returns {Response} A `Response` object with the serialized JSON body and response metadata.
|
|
29
27
|
*/
|
|
30
28
|
toResponse() {
|
|
31
29
|
const responseInit = {
|
|
@@ -33,20 +31,20 @@ class Unauthorized {
|
|
|
33
31
|
status: this.status,
|
|
34
32
|
statusText: this.statusText,
|
|
35
33
|
};
|
|
36
|
-
return new Response(JSON.stringify(this.
|
|
34
|
+
return new Response(JSON.stringify(this.makeBody()), responseInit);
|
|
37
35
|
}
|
|
38
36
|
/**
|
|
39
37
|
* Converts the `Unauthorized` instance into a `Response` object using the `Response.json` method.
|
|
40
38
|
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
41
39
|
*
|
|
42
|
-
* @returns A `Response` object with the JSON body and response metadata.
|
|
40
|
+
* @returns {Response["json"]} A `Response` object with the JSON body and response metadata.
|
|
43
41
|
*/
|
|
44
42
|
toJson() {
|
|
45
43
|
const responseInit = {
|
|
46
44
|
status: this.status,
|
|
47
45
|
statusText: this.statusText,
|
|
48
46
|
};
|
|
49
|
-
return Response.json(this.
|
|
47
|
+
return Response.json(this.makeBody(), responseInit);
|
|
50
48
|
}
|
|
51
49
|
}
|
|
52
50
|
export { Unauthorized };
|
|
@@ -1,41 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
data?: any;
|
|
3
|
-
fieldErrors?: Record<string, string>;
|
|
4
|
-
fields?: Record<string, string>;
|
|
5
|
-
message?: string;
|
|
6
|
-
};
|
|
1
|
+
import { BadResponse } from "./_badResponse";
|
|
7
2
|
/**
|
|
8
3
|
* Represents an HTTP error response with a status code of 422 (Unprocessable Entity).
|
|
9
4
|
* This class is used to standardize the structure of an "Unprocessable Entity" error response,
|
|
10
5
|
* including the response body, headers, status, and status text.
|
|
11
6
|
*/
|
|
12
|
-
declare class UnprocessableEntity {
|
|
13
|
-
body: any;
|
|
14
|
-
status: number;
|
|
15
|
-
statusText: string;
|
|
7
|
+
declare class UnprocessableEntity extends BadResponse {
|
|
16
8
|
/**
|
|
17
9
|
* Creates an instance of the `UnprocessableEntity` class.
|
|
18
10
|
*
|
|
19
|
-
* @param props - An object containing details about the error, such as:
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* @param enableDebug - A boolean indicating whether to enable debug logging for this error.
|
|
11
|
+
* @param {object} props - An object containing details about the error, such as:
|
|
12
|
+
* @param {any} [props.data] - `data`: Additional data related to the error.
|
|
13
|
+
* @param {Record<string, string>} [props.fieldErrors] - `fieldErrors`: A record of field-specific error messages.
|
|
14
|
+
* @param {Record<string, string>} [props.fields] - `fields`: A record of field values that caused the error.
|
|
15
|
+
* @param {string} [props.message] - `message`: A descriptive message explaining the error.
|
|
25
16
|
*/
|
|
26
|
-
constructor(props:
|
|
17
|
+
constructor(props: {
|
|
18
|
+
data?: any;
|
|
19
|
+
fieldErrors?: Record<string, string>;
|
|
20
|
+
fields?: Record<string, string>;
|
|
21
|
+
message?: string;
|
|
22
|
+
});
|
|
27
23
|
/**
|
|
28
24
|
* Converts the `UnprocessableEntity` instance into a `Response` object with a JSON body.
|
|
29
25
|
* This method ensures the response has the appropriate headers, status, and status text.
|
|
30
26
|
*
|
|
31
|
-
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
27
|
+
* @returns {Response} A `Response` object with the serialized JSON body and response metadata.
|
|
32
28
|
*/
|
|
33
29
|
toResponse(): Response;
|
|
34
30
|
/**
|
|
35
31
|
* Converts the `UnprocessableEntity` instance into a `Response` object using the `Response.json` method.
|
|
36
32
|
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
37
33
|
*
|
|
38
|
-
* @returns A `Response` object with the JSON body and response metadata.
|
|
34
|
+
* @returns {Response["json"]} A `Response` object with the JSON body and response metadata.
|
|
39
35
|
*/
|
|
40
36
|
toJson(): Response;
|
|
41
37
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unprocessableEntity.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/unprocessableEntity.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"unprocessableEntity.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/unprocessableEntity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;GAIG;AAEH,cAAM,mBAAoB,SAAQ,WAAW;IAC3C;;;;;;;;OAQG;gBAES,KAAK,EAAE;QACjB,IAAI,CAAC,EAAE,GAAG,CAAC;QACX,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACrC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAChC,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB;IAeD;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CAQnB;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
|
|
@@ -1,39 +1,36 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BadResponse } from "./_badResponse";
|
|
2
2
|
/**
|
|
3
3
|
* Represents an HTTP error response with a status code of 422 (Unprocessable Entity).
|
|
4
4
|
* This class is used to standardize the structure of an "Unprocessable Entity" error response,
|
|
5
5
|
* including the response body, headers, status, and status text.
|
|
6
6
|
*/
|
|
7
|
-
class UnprocessableEntity {
|
|
8
|
-
body;
|
|
9
|
-
status = 422;
|
|
10
|
-
statusText;
|
|
7
|
+
class UnprocessableEntity extends BadResponse {
|
|
11
8
|
/**
|
|
12
9
|
* Creates an instance of the `UnprocessableEntity` class.
|
|
13
10
|
*
|
|
14
|
-
* @param props - An object containing details about the error, such as:
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* @param enableDebug - A boolean indicating whether to enable debug logging for this error.
|
|
11
|
+
* @param {object} props - An object containing details about the error, such as:
|
|
12
|
+
* @param {any} [props.data] - `data`: Additional data related to the error.
|
|
13
|
+
* @param {Record<string, string>} [props.fieldErrors] - `fieldErrors`: A record of field-specific error messages.
|
|
14
|
+
* @param {Record<string, string>} [props.fields] - `fields`: A record of field values that caused the error.
|
|
15
|
+
* @param {string} [props.message] - `message`: A descriptive message explaining the error.
|
|
20
16
|
*/
|
|
21
|
-
constructor(props
|
|
22
|
-
|
|
23
|
-
this.
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
constructor(props) {
|
|
18
|
+
super();
|
|
19
|
+
this.name = "UnprocessableEntity";
|
|
20
|
+
this.status = 422;
|
|
21
|
+
this.statusText = props.message || "Unprocessable entity";
|
|
22
|
+
this.cause = {
|
|
26
23
|
data: props.data,
|
|
27
24
|
fieldErrors: props.fieldErrors,
|
|
28
25
|
fields: props.fields,
|
|
29
26
|
};
|
|
30
|
-
|
|
27
|
+
this.onDebug();
|
|
31
28
|
}
|
|
32
29
|
/**
|
|
33
30
|
* Converts the `UnprocessableEntity` instance into a `Response` object with a JSON body.
|
|
34
31
|
* This method ensures the response has the appropriate headers, status, and status text.
|
|
35
32
|
*
|
|
36
|
-
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
33
|
+
* @returns {Response} A `Response` object with the serialized JSON body and response metadata.
|
|
37
34
|
*/
|
|
38
35
|
toResponse() {
|
|
39
36
|
const responseInit = {
|
|
@@ -41,20 +38,20 @@ class UnprocessableEntity {
|
|
|
41
38
|
status: this.status,
|
|
42
39
|
statusText: this.statusText,
|
|
43
40
|
};
|
|
44
|
-
return new Response(JSON.stringify(this.
|
|
41
|
+
return new Response(JSON.stringify(this.makeBody()), responseInit);
|
|
45
42
|
}
|
|
46
43
|
/**
|
|
47
44
|
* Converts the `UnprocessableEntity` instance into a `Response` object using the `Response.json` method.
|
|
48
45
|
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
49
46
|
*
|
|
50
|
-
* @returns A `Response` object with the JSON body and response metadata.
|
|
47
|
+
* @returns {Response["json"]} A `Response` object with the JSON body and response metadata.
|
|
51
48
|
*/
|
|
52
49
|
toJson() {
|
|
53
50
|
const responseInit = {
|
|
54
51
|
status: this.status,
|
|
55
52
|
statusText: this.statusText,
|
|
56
53
|
};
|
|
57
|
-
return Response.json(this.
|
|
54
|
+
return Response.json(this.makeBody(), responseInit);
|
|
58
55
|
}
|
|
59
56
|
}
|
|
60
57
|
export { UnprocessableEntity };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base class for handling successful HTTP responses with debugging capabilities.
|
|
3
|
+
* Provides logging functionality to track response and their context.
|
|
4
|
+
*/
|
|
5
|
+
declare class SuccessResponse {
|
|
6
|
+
private _body;
|
|
7
|
+
private _name;
|
|
8
|
+
private _status;
|
|
9
|
+
private _statusText;
|
|
10
|
+
get body(): any;
|
|
11
|
+
set body(value: any);
|
|
12
|
+
get name(): string;
|
|
13
|
+
set name(value: string);
|
|
14
|
+
get status(): number;
|
|
15
|
+
set status(value: number);
|
|
16
|
+
get statusText(): string;
|
|
17
|
+
set statusText(value: string);
|
|
18
|
+
/**
|
|
19
|
+
* Logs debug information for success responses including caller context and response details.
|
|
20
|
+
*
|
|
21
|
+
* @param {any} body - The response body or success data to be logged
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const SuccessResponse = new SuccessResponse();
|
|
26
|
+
* SuccessResponse.onDebug({ data: "Operation completed successfully" });
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
onDebug(body?: any): void;
|
|
30
|
+
makeBody(): any;
|
|
31
|
+
}
|
|
32
|
+
export { SuccessResponse };
|
|
33
|
+
//# sourceMappingURL=_successResponse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_successResponse.d.ts","sourceRoot":"","sources":["../../../src/http/successResponses/_successResponse.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,cAAM,eAAe;IACnB,OAAO,CAAC,KAAK,CAAa;IAC1B,OAAO,CAAC,KAAK,CAA6B;IAC1C,OAAO,CAAC,OAAO,CAAe;IAC9B,OAAO,CAAC,WAAW,CAAgB;IAEnC,IAAI,IAAI,IAAI,GAAG,CAEd;IAED,IAAI,IAAI,CAAC,KAAK,EAAE,GAAG,EAElB;IAED,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,IAAI,CAAC,KAAK,EAAE,MAAM,EAErB;IAED,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,IAAI,MAAM,CAAC,KAAK,EAAE,MAAM,EAEvB;IAED,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED,IAAI,UAAU,CAAC,KAAK,EAAE,MAAM,EAE3B;IAED;;;;;;;;;;OAUG;IACH,OAAO,CAAC,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI;IAazB,QAAQ,IAAI,GAAG;CAOhB;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { DebugService } from "../../services/debugService";
|
|
2
|
+
import { flushDebugLogs } from "../../utilities/flushDebugLogs";
|
|
3
|
+
/**
|
|
4
|
+
* Base class for handling successful HTTP responses with debugging capabilities.
|
|
5
|
+
* Provides logging functionality to track response and their context.
|
|
6
|
+
*/
|
|
7
|
+
class SuccessResponse {
|
|
8
|
+
_body = null;
|
|
9
|
+
_name = "SuccessResponse";
|
|
10
|
+
_status = 200;
|
|
11
|
+
_statusText = "OK";
|
|
12
|
+
get body() {
|
|
13
|
+
return this._body;
|
|
14
|
+
}
|
|
15
|
+
set body(value) {
|
|
16
|
+
this._body = value ?? null;
|
|
17
|
+
}
|
|
18
|
+
get name() {
|
|
19
|
+
return this._name;
|
|
20
|
+
}
|
|
21
|
+
set name(value) {
|
|
22
|
+
this._name = value;
|
|
23
|
+
}
|
|
24
|
+
get status() {
|
|
25
|
+
return this._status;
|
|
26
|
+
}
|
|
27
|
+
set status(value) {
|
|
28
|
+
this._status = value;
|
|
29
|
+
}
|
|
30
|
+
get statusText() {
|
|
31
|
+
return this._statusText;
|
|
32
|
+
}
|
|
33
|
+
set statusText(value) {
|
|
34
|
+
this._statusText = value;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Logs debug information for success responses including caller context and response details.
|
|
38
|
+
*
|
|
39
|
+
* @param {any} body - The response body or success data to be logged
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* const SuccessResponse = new SuccessResponse();
|
|
44
|
+
* SuccessResponse.onDebug({ data: "Operation completed successfully" });
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
onDebug(body) {
|
|
48
|
+
const debugs = [];
|
|
49
|
+
const { callerInfo, functionName } = DebugService.getCaller();
|
|
50
|
+
debugs.push(`Caller Function: ${functionName}`);
|
|
51
|
+
debugs.push(`Caller Location: ${callerInfo}`);
|
|
52
|
+
if (this.statusText)
|
|
53
|
+
debugs.push(`Message: ${this.statusText}`);
|
|
54
|
+
if (body)
|
|
55
|
+
debugs.push(`Body: ${JSON.stringify(body)}`);
|
|
56
|
+
flushDebugLogs({ scheme: "red", name: this.name, debugs });
|
|
57
|
+
}
|
|
58
|
+
makeBody() {
|
|
59
|
+
return {
|
|
60
|
+
name: this.name,
|
|
61
|
+
message: this.statusText,
|
|
62
|
+
body: this.body,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
export { SuccessResponse };
|
|
@@ -1,34 +1,24 @@
|
|
|
1
|
+
import { SuccessResponse } from "./_successResponse";
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
-
* This class is used to standardize the structure of a "Created" response,
|
|
4
|
-
* including the response body, headers, status, and status text.
|
|
5
|
-
*
|
|
6
|
-
* @template T - The type of the response body.
|
|
3
|
+
* Class representing a successful HTTP 201 Created response.
|
|
7
4
|
*/
|
|
8
|
-
declare class Created
|
|
9
|
-
body: T;
|
|
10
|
-
headers: ResponseInit["headers"];
|
|
11
|
-
status: number;
|
|
12
|
-
statusText: string;
|
|
5
|
+
declare class Created extends SuccessResponse {
|
|
13
6
|
/**
|
|
14
7
|
* Creates an instance of the `Created` class.
|
|
15
8
|
*
|
|
16
|
-
* @param
|
|
17
|
-
* @param
|
|
9
|
+
* @param {string} message - A message describing the creation status.
|
|
10
|
+
* @param {any} body - The response body to be included in the HTTP response.
|
|
18
11
|
*/
|
|
19
|
-
constructor(
|
|
12
|
+
constructor(message: string, body?: any);
|
|
20
13
|
/**
|
|
21
|
-
* Converts the `Created` instance into a `Response` object
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
14
|
+
* Converts the `Created` instance into a `Response` object.
|
|
15
|
+
* @returns {Response} A `Response` object with the body and response metadata.
|
|
25
16
|
*/
|
|
26
17
|
toResponse(): Response;
|
|
27
18
|
/**
|
|
28
19
|
* Converts the `Created` instance into a `Response` object using the `Response.json` method.
|
|
29
20
|
* This method is an alternative to `toResponse` for generating JSON responses.
|
|
30
|
-
*
|
|
31
|
-
* @returns A `Response` object with the JSON body and response metadata.
|
|
21
|
+
* @returns {Response["json"]} A `Response` object with the JSON body and response metadata.
|
|
32
22
|
*/
|
|
33
23
|
toJson(): Response;
|
|
34
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"created.d.ts","sourceRoot":"","sources":["../../../src/http/successResponses/created.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"created.d.ts","sourceRoot":"","sources":["../../../src/http/successResponses/created.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD;;GAEG;AAEH,cAAM,OAAQ,SAAQ,eAAe;IACnC;;;;;OAKG;gBAES,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG;IAWvC;;;OAGG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;OAIG;IAEH,MAAM,IAAI,QAAQ;CAQnB;AAED,OAAO,EAAE,OAAO,EAAE,CAAC"}
|
|
@@ -1,36 +1,29 @@
|
|
|
1
|
+
import { SuccessResponse } from "./_successResponse";
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
-
* This class is used to standardize the structure of a "Created" response,
|
|
4
|
-
* including the response body, headers, status, and status text.
|
|
5
|
-
*
|
|
6
|
-
* @template T - The type of the response body.
|
|
3
|
+
* Class representing a successful HTTP 201 Created response.
|
|
7
4
|
*/
|
|
8
|
-
class Created {
|
|
9
|
-
body;
|
|
10
|
-
headers;
|
|
11
|
-
status;
|
|
12
|
-
statusText;
|
|
5
|
+
class Created extends SuccessResponse {
|
|
13
6
|
/**
|
|
14
7
|
* Creates an instance of the `Created` class.
|
|
15
8
|
*
|
|
16
|
-
* @param
|
|
17
|
-
* @param
|
|
9
|
+
* @param {string} message - A message describing the creation status.
|
|
10
|
+
* @param {any} body - The response body to be included in the HTTP response.
|
|
18
11
|
*/
|
|
19
|
-
constructor(
|
|
20
|
-
|
|
21
|
-
this.
|
|
22
|
-
this.status =
|
|
23
|
-
this.statusText =
|
|
12
|
+
constructor(message, body) {
|
|
13
|
+
super();
|
|
14
|
+
this.name = "Created";
|
|
15
|
+
this.status = 201;
|
|
16
|
+
this.statusText = message;
|
|
17
|
+
this.body = body || undefined;
|
|
18
|
+
this.onDebug();
|
|
24
19
|
}
|
|
25
20
|
/**
|
|
26
|
-
* Converts the `Created` instance into a `Response` object
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
21
|
+
* Converts the `Created` instance into a `Response` object.
|
|
22
|
+
* @returns {Response} A `Response` object with the body and response metadata.
|
|
30
23
|
*/
|
|
31
24
|
toResponse() {
|
|
32
25
|
const responseInit = {
|
|
33
|
-
headers: { "Content-Type": "application/json"
|
|
26
|
+
headers: { "Content-Type": "application/json" },
|
|
34
27
|
status: this.status,
|
|
35
28
|
statusText: this.statusText,
|
|
36
29
|
};
|
|
@@ -39,12 +32,10 @@ class Created {
|
|
|
39
32
|
/**
|
|
40
33
|
* Converts the `Created` instance into a `Response` object using the `Response.json` method.
|
|
41
34
|
* This method is an alternative to `toResponse` for generating JSON responses.
|
|
42
|
-
*
|
|
43
|
-
* @returns A `Response` object with the JSON body and response metadata.
|
|
35
|
+
* @returns {Response["json"]} A `Response` object with the JSON body and response metadata.
|
|
44
36
|
*/
|
|
45
37
|
toJson() {
|
|
46
38
|
const responseInit = {
|
|
47
|
-
headers: this.headers,
|
|
48
39
|
status: this.status,
|
|
49
40
|
statusText: this.statusText,
|
|
50
41
|
};
|