@arkyn/server 3.0.1-beta.117 → 3.0.1-beta.119

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 (178) hide show
  1. package/dist/bundle.js +721 -734
  2. package/dist/bundle.umd.cjs +5 -10
  3. package/dist/{api/arkynLogRequest.d.ts → http/api/_logRequest.d.ts} +22 -19
  4. package/dist/{api/arkynLogRequest.d.ts.map → http/api/_logRequest.d.ts.map} +1 -1
  5. package/dist/{api/arkynLogRequest.js → http/api/_logRequest.js} +30 -30
  6. package/dist/http/api/_makeRequest.d.ts +61 -0
  7. package/dist/http/api/_makeRequest.d.ts.map +1 -0
  8. package/dist/{api/makeRequest.js → http/api/_makeRequest.js} +29 -20
  9. package/dist/http/api/deleteRequest.d.ts +17 -0
  10. package/dist/http/api/deleteRequest.d.ts.map +1 -0
  11. package/dist/http/api/deleteRequest.js +18 -0
  12. package/dist/http/api/getRequest.d.ts +16 -0
  13. package/dist/http/api/getRequest.d.ts.map +1 -0
  14. package/dist/http/api/getRequest.js +17 -0
  15. package/dist/http/api/patchRequest.d.ts +17 -0
  16. package/dist/http/api/patchRequest.d.ts.map +1 -0
  17. package/dist/http/api/patchRequest.js +18 -0
  18. package/dist/http/api/postRequest.d.ts +17 -0
  19. package/dist/http/api/postRequest.d.ts.map +1 -0
  20. package/dist/http/api/postRequest.js +18 -0
  21. package/dist/http/api/putRequest.d.ts +17 -0
  22. package/dist/http/api/putRequest.d.ts.map +1 -0
  23. package/dist/http/api/putRequest.js +18 -0
  24. package/dist/http/badResponses/_badResponse.d.ts +18 -7
  25. package/dist/http/badResponses/_badResponse.d.ts.map +1 -1
  26. package/dist/http/badResponses/_badResponse.js +44 -13
  27. package/dist/http/badResponses/badGateway.d.ts +4 -8
  28. package/dist/http/badResponses/badGateway.d.ts.map +1 -1
  29. package/dist/http/badResponses/badGateway.js +9 -17
  30. package/dist/http/badResponses/badRequest.d.ts +4 -8
  31. package/dist/http/badResponses/badRequest.d.ts.map +1 -1
  32. package/dist/http/badResponses/badRequest.js +9 -17
  33. package/dist/http/badResponses/conflict.d.ts +4 -8
  34. package/dist/http/badResponses/conflict.d.ts.map +1 -1
  35. package/dist/http/badResponses/conflict.js +9 -17
  36. package/dist/http/badResponses/forbidden.d.ts +4 -8
  37. package/dist/http/badResponses/forbidden.d.ts.map +1 -1
  38. package/dist/http/badResponses/forbidden.js +9 -17
  39. package/dist/http/badResponses/notFound.d.ts +4 -8
  40. package/dist/http/badResponses/notFound.d.ts.map +1 -1
  41. package/dist/http/badResponses/notFound.js +9 -17
  42. package/dist/http/badResponses/notImplemented.d.ts +4 -8
  43. package/dist/http/badResponses/notImplemented.d.ts.map +1 -1
  44. package/dist/http/badResponses/notImplemented.js +9 -17
  45. package/dist/http/badResponses/serverError.d.ts +4 -8
  46. package/dist/http/badResponses/serverError.d.ts.map +1 -1
  47. package/dist/http/badResponses/serverError.js +9 -17
  48. package/dist/http/badResponses/unauthorized.d.ts +2 -6
  49. package/dist/http/badResponses/unauthorized.d.ts.map +1 -1
  50. package/dist/http/badResponses/unauthorized.js +7 -15
  51. package/dist/http/badResponses/unprocessableEntity.d.ts +13 -18
  52. package/dist/http/badResponses/unprocessableEntity.d.ts.map +1 -1
  53. package/dist/http/badResponses/unprocessableEntity.js +14 -22
  54. package/dist/http/successResponses/_successResponse.d.ts +18 -7
  55. package/dist/http/successResponses/_successResponse.d.ts.map +1 -1
  56. package/dist/http/successResponses/_successResponse.js +50 -21
  57. package/dist/http/successResponses/created.d.ts +8 -22
  58. package/dist/http/successResponses/created.d.ts.map +1 -1
  59. package/dist/http/successResponses/created.js +13 -25
  60. package/dist/http/successResponses/found.d.ts +9 -26
  61. package/dist/http/successResponses/found.d.ts.map +1 -1
  62. package/dist/http/successResponses/found.js +14 -29
  63. package/dist/http/successResponses/noContent.d.ts +4 -12
  64. package/dist/http/successResponses/noContent.d.ts.map +1 -1
  65. package/dist/http/successResponses/noContent.js +9 -17
  66. package/dist/http/successResponses/success.d.ts +8 -22
  67. package/dist/http/successResponses/success.d.ts.map +1 -1
  68. package/dist/http/successResponses/success.js +13 -25
  69. package/dist/http/successResponses/updated.d.ts +8 -22
  70. package/dist/http/successResponses/updated.d.ts.map +1 -1
  71. package/dist/http/successResponses/updated.js +13 -25
  72. package/dist/index.d.ts +9 -10
  73. package/dist/index.d.ts.map +1 -1
  74. package/dist/index.js +11 -12
  75. package/dist/services/apiService.d.ts +7 -28
  76. package/dist/services/apiService.d.ts.map +1 -1
  77. package/dist/services/apiService.js +36 -42
  78. package/dist/services/debugService.d.ts +16 -1
  79. package/dist/services/debugService.d.ts.map +1 -1
  80. package/dist/services/debugService.js +58 -1
  81. package/dist/services/logMapperService.d.ts +86 -0
  82. package/dist/services/logMapperService.d.ts.map +1 -0
  83. package/dist/services/logMapperService.js +68 -0
  84. package/dist/services/logService.d.ts +38 -0
  85. package/dist/services/logService.d.ts.map +1 -0
  86. package/dist/services/logService.js +40 -0
  87. package/dist/{services → utilities}/decodeRequestBody.d.ts +3 -4
  88. package/dist/utilities/decodeRequestBody.d.ts.map +1 -0
  89. package/dist/{services → utilities}/decodeRequestBody.js +5 -5
  90. package/dist/{services/decodeErrorMessageFromRequest.d.ts → utilities/decodeRequestErrorMessage.d.ts} +6 -6
  91. package/dist/utilities/decodeRequestErrorMessage.d.ts.map +1 -0
  92. package/dist/{services/decodeErrorMessageFromRequest.js → utilities/decodeRequestErrorMessage.js} +5 -5
  93. package/dist/utilities/errorHandler.d.ts +50 -0
  94. package/dist/utilities/errorHandler.d.ts.map +1 -0
  95. package/dist/{services → utilities}/errorHandler.js +34 -28
  96. package/dist/utilities/flushDebugLogs.d.ts +46 -0
  97. package/dist/utilities/flushDebugLogs.d.ts.map +1 -0
  98. package/dist/utilities/flushDebugLogs.js +59 -0
  99. package/dist/{services → utilities}/formAsyncParse.d.ts +3 -3
  100. package/dist/utilities/formAsyncParse.d.ts.map +1 -0
  101. package/dist/{services → utilities}/formAsyncParse.js +3 -3
  102. package/dist/{services → utilities}/formParse.d.ts +3 -3
  103. package/dist/utilities/formParse.d.ts.map +1 -0
  104. package/dist/{services → utilities}/formParse.js +3 -3
  105. package/dist/{services → utilities}/getScopedParams.d.ts +3 -4
  106. package/dist/utilities/getScopedParams.d.ts.map +1 -0
  107. package/dist/{services → utilities}/getScopedParams.js +4 -4
  108. package/dist/{services → utilities}/schemaValidator.d.ts +3 -15
  109. package/dist/utilities/schemaValidator.d.ts.map +1 -0
  110. package/dist/{services → utilities}/schemaValidator.js +3 -19
  111. package/dist/validations/validateCep.d.ts +7 -12
  112. package/dist/validations/validateCep.d.ts.map +1 -1
  113. package/dist/validations/validateCep.js +9 -15
  114. package/dist/validations/validateCnpj.d.ts +4 -5
  115. package/dist/validations/validateCnpj.d.ts.map +1 -1
  116. package/dist/validations/validateCnpj.js +12 -5
  117. package/dist/validations/validateCpf.d.ts +3 -4
  118. package/dist/validations/validateCpf.d.ts.map +1 -1
  119. package/dist/validations/validateCpf.js +11 -4
  120. package/dist/validations/validateDate.d.ts +16 -23
  121. package/dist/validations/validateDate.d.ts.map +1 -1
  122. package/dist/validations/validateDate.js +38 -56
  123. package/dist/validations/validateEmail.d.ts +3 -4
  124. package/dist/validations/validateEmail.d.ts.map +1 -1
  125. package/dist/validations/validateEmail.js +23 -35
  126. package/dist/validations/validatePassword.d.ts +3 -4
  127. package/dist/validations/validatePassword.d.ts.map +1 -1
  128. package/dist/validations/validatePassword.js +5 -5
  129. package/dist/validations/validatePhone.d.ts +3 -4
  130. package/dist/validations/validatePhone.d.ts.map +1 -1
  131. package/dist/validations/validatePhone.js +4 -4
  132. package/dist/validations/validateRg.d.ts +3 -4
  133. package/dist/validations/validateRg.d.ts.map +1 -1
  134. package/dist/validations/validateRg.js +4 -4
  135. package/package.json +1 -1
  136. package/dist/api/deleteRequest.d.ts +0 -13
  137. package/dist/api/deleteRequest.d.ts.map +0 -1
  138. package/dist/api/deleteRequest.js +0 -14
  139. package/dist/api/getRequest.d.ts +0 -12
  140. package/dist/api/getRequest.d.ts.map +0 -1
  141. package/dist/api/getRequest.js +0 -13
  142. package/dist/api/makeRequest.d.ts +0 -38
  143. package/dist/api/makeRequest.d.ts.map +0 -1
  144. package/dist/api/patchRequest.d.ts +0 -13
  145. package/dist/api/patchRequest.d.ts.map +0 -1
  146. package/dist/api/patchRequest.js +0 -14
  147. package/dist/api/postRequest.d.ts +0 -13
  148. package/dist/api/postRequest.d.ts.map +0 -1
  149. package/dist/api/postRequest.js +0 -14
  150. package/dist/api/putRequest.d.ts +0 -13
  151. package/dist/api/putRequest.d.ts.map +0 -1
  152. package/dist/api/putRequest.js +0 -14
  153. package/dist/mapper/arkynLogRequestMapper.d.ts +0 -30
  154. package/dist/mapper/arkynLogRequestMapper.d.ts.map +0 -1
  155. package/dist/mapper/arkynLogRequestMapper.js +0 -44
  156. package/dist/services/arkynLogService.d.ts +0 -44
  157. package/dist/services/arkynLogService.d.ts.map +0 -1
  158. package/dist/services/arkynLogService.js +0 -46
  159. package/dist/services/decodeErrorMessageFromRequest.d.ts.map +0 -1
  160. package/dist/services/decodeRequestBody.d.ts.map +0 -1
  161. package/dist/services/errorHandler.d.ts +0 -44
  162. package/dist/services/errorHandler.d.ts.map +0 -1
  163. package/dist/services/flushDebugLogs.d.ts +0 -8
  164. package/dist/services/flushDebugLogs.d.ts.map +0 -1
  165. package/dist/services/flushDebugLogs.js +0 -20
  166. package/dist/services/formAsyncParse.d.ts.map +0 -1
  167. package/dist/services/formParse.d.ts.map +0 -1
  168. package/dist/services/getCaller.d.ts +0 -17
  169. package/dist/services/getCaller.d.ts.map +0 -1
  170. package/dist/services/getCaller.js +0 -60
  171. package/dist/services/getScopedParams.d.ts.map +0 -1
  172. package/dist/services/measureRouteExecution.d.ts +0 -3
  173. package/dist/services/measureRouteExecution.d.ts.map +0 -1
  174. package/dist/services/measureRouteExecution.js +0 -24
  175. package/dist/services/schemaValidator.d.ts.map +0 -1
  176. package/dist/types/ApiResponseDTO.d.ts +0 -17
  177. package/dist/types/ApiResponseDTO.d.ts.map +0 -1
  178. package/dist/types/ApiResponseDTO.js +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decodeRequestBody.d.ts","sourceRoot":"","sources":["../../src/utilities/decodeRequestBody.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AAEH,iBAAe,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CAsB/D;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
@@ -7,14 +7,14 @@ import { BadRequest } from "../http/badResponses/badRequest";
7
7
  * 2. If JSON parsing fails, attempts to parse the body as URL-encoded form data.
8
8
  * 3. If both parsing attempts fail, logs the errors and returns an empty object.
9
9
  *
10
- * @param req - The incoming request object containing the body to decode.
11
- * @returns A promise that resolves to the decoded data as a JavaScript object.
10
+ * @param {Request} request - The incoming request object containing the body to decode.
11
+ * @returns {Promise<any>} A promise that resolves to the decoded data as a JavaScript object.
12
12
  *
13
13
  * @throws Logs errors to the console if the request body cannot be read or parsed.
14
14
  */
15
- const decodeRequestBody = async (req) => {
15
+ async function decodeRequestBody(request) {
16
16
  let data;
17
- const arrayBuffer = await req.arrayBuffer();
17
+ const arrayBuffer = await request.arrayBuffer();
18
18
  const text = new TextDecoder().decode(arrayBuffer);
19
19
  try {
20
20
  data = JSON.parse(text);
@@ -34,5 +34,5 @@ const decodeRequestBody = async (req) => {
34
34
  }
35
35
  }
36
36
  return data;
37
- };
37
+ }
38
38
  export { decodeRequestBody };
@@ -5,13 +5,13 @@
5
5
  * `data` or `response` objects by checking various properties in a specific order.
6
6
  * If no valid error message is found, it returns a default message: "Missing error message".
7
7
  *
8
- * @param data - The data object that may contain error information. It can have properties
8
+ * @param {any} data - The data object that may contain error information. It can have properties
9
9
  * such as `message`, `error`, or `error.message` that are checked for a string value.
10
- * @param response - The response object that may contain a `statusText` property
10
+ * @param {Response} response - The response object that may contain a `statusText` property
11
11
  * representing the HTTP status text.
12
- * @returns A string representing the decoded error message, or a default message
12
+ * @returns {string} A string representing the decoded error message, or a default message
13
13
  * if no error message is found.
14
14
  */
15
- declare function decodeErrorMessageFromRequest(data: any, response: Response): string;
16
- export { decodeErrorMessageFromRequest };
17
- //# sourceMappingURL=decodeErrorMessageFromRequest.d.ts.map
15
+ declare function decodeRequestErrorMessage(data: any, response: Response): string;
16
+ export { decodeRequestErrorMessage };
17
+ //# sourceMappingURL=decodeRequestErrorMessage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decodeRequestErrorMessage.d.ts","sourceRoot":"","sources":["../../src/utilities/decodeRequestErrorMessage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,iBAAS,yBAAyB,CAAC,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAkBxE;AAED,OAAO,EAAE,yBAAyB,EAAE,CAAC"}
@@ -5,14 +5,14 @@
5
5
  * `data` or `response` objects by checking various properties in a specific order.
6
6
  * If no valid error message is found, it returns a default message: "Missing error message".
7
7
  *
8
- * @param data - The data object that may contain error information. It can have properties
8
+ * @param {any} data - The data object that may contain error information. It can have properties
9
9
  * such as `message`, `error`, or `error.message` that are checked for a string value.
10
- * @param response - The response object that may contain a `statusText` property
10
+ * @param {Response} response - The response object that may contain a `statusText` property
11
11
  * representing the HTTP status text.
12
- * @returns A string representing the decoded error message, or a default message
12
+ * @returns {string} A string representing the decoded error message, or a default message
13
13
  * if no error message is found.
14
14
  */
15
- function decodeErrorMessageFromRequest(data, response) {
15
+ function decodeRequestErrorMessage(data, response) {
16
16
  if (data?.message && typeof data?.message === "string") {
17
17
  return data?.message;
18
18
  }
@@ -27,4 +27,4 @@ function decodeErrorMessageFromRequest(data, response) {
27
27
  }
28
28
  return "Missing error message";
29
29
  }
30
- export { decodeErrorMessageFromRequest };
30
+ export { decodeRequestErrorMessage };
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Handles errors and success responses, converting them into standard HTTP Response objects.
3
+ *
4
+ * This function acts as a centralized error and response handler that processes various
5
+ * response types (both success and error responses) and converts them into HTTP Response
6
+ * objects. If the error is not recognized, it defaults to returning a ServerError response.
7
+ *
8
+ * @param {any} error - The error or response object to be handled. Can be:
9
+ * - A native Response object
10
+ * - A success response instance (Found, Created, Updated, Success, NoContent)
11
+ * - An error response instance (BadGateway, BadRequest, Conflict, Forbidden, NotFound, NotImplemented, ServerError, Unauthorized, UnprocessableEntity)
12
+ * - Any other error object (will be wrapped in ServerError)
13
+ *
14
+ * @returns {Response} A standard HTTP Response object with appropriate status code, headers, and body
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * // Handling a success response
19
+ * try {
20
+ * const result = await someOperation();
21
+ * throw new Success("Operation successful", result);
22
+ * } catch (error) {
23
+ * return errorHandler(error);
24
+ * }
25
+ * ```
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * // Handling an error response
30
+ * try {
31
+ * const user = await findUser(id);
32
+ * if (!user) throw new NotFound("User not found");
33
+ * } catch (error) {
34
+ * return errorHandler(error);
35
+ * }
36
+ * ```
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * // Handling unexpected errors
41
+ * try {
42
+ * await riskyOperation();
43
+ * } catch (error) {
44
+ * return errorHandler(error); // Returns ServerError response
45
+ * }
46
+ * ```
47
+ */
48
+ declare function errorHandler(error: any): Response;
49
+ export { errorHandler };
50
+ //# sourceMappingURL=errorHandler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errorHandler.d.ts","sourceRoot":"","sources":["../../src/utilities/errorHandler.ts"],"names":[],"mappings":"AAgBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,iBAAS,YAAY,CAAC,KAAK,EAAE,GAAG,GAAG,QAAQ,CAsC1C;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
@@ -13,45 +13,51 @@ import { NoContent } from "../http/successResponses/noContent";
13
13
  import { Success } from "../http/successResponses/success";
14
14
  import { Updated } from "../http/successResponses/updated";
15
15
  /**
16
- * Handles errors and converts them into appropriate HTTP responses.
16
+ * Handles errors and success responses, converting them into standard HTTP Response objects.
17
17
  *
18
- * This function takes an error object and determines its type to return
19
- * the corresponding HTTP response. It supports both success and error
20
- * response types, converting them into a standardized format using the
21
- * `toResponse` method when applicable.
18
+ * This function acts as a centralized error and response handler that processes various
19
+ * response types (both success and error responses) and converts them into HTTP Response
20
+ * objects. If the error is not recognized, it defaults to returning a ServerError response.
22
21
  *
23
- * @param error - The error object to handle. It can be an instance of various
24
- * HTTP response classes or a generic error.
22
+ * @param {any} error - The error or response object to be handled. Can be:
23
+ * - A native Response object
24
+ * - A success response instance (Found, Created, Updated, Success, NoContent)
25
+ * - An error response instance (BadGateway, BadRequest, Conflict, Forbidden, NotFound, NotImplemented, ServerError, Unauthorized, UnprocessableEntity)
26
+ * - Any other error object (will be wrapped in ServerError)
25
27
  *
26
- * @returns The corresponding HTTP response object if the error matches a known
27
- * type, or `undefined` if no match is found.
28
+ * @returns {Response} A standard HTTP Response object with appropriate status code, headers, and body
28
29
  *
29
- * ### Supported Success Responses:
30
- * - `Found`
31
- * - `Created`
32
- * - `Updated`
33
- * - `Success`
34
- * - `NoContent`
35
- *
36
- * ### Supported Error Responses:
37
- * - `BadGateway`
38
- * - `BadRequest`
39
- * - `Conflict`
40
- * - `Forbidden`
41
- * - `NotFound`
42
- * - `NotImplemented`
43
- * - `ServerError`
44
- * - `Unauthorized`
45
- * - `UnprocessableEntity`
30
+ * @example
31
+ * ```typescript
32
+ * // Handling a success response
33
+ * try {
34
+ * const result = await someOperation();
35
+ * throw new Success("Operation successful", result);
36
+ * } catch (error) {
37
+ * return errorHandler(error);
38
+ * }
39
+ * ```
46
40
  *
47
- * ### Example Usage:
41
+ * @example
48
42
  * ```typescript
43
+ * // Handling an error response
49
44
  * try {
50
- * // Some operation that might throw an error
45
+ * const user = await findUser(id);
46
+ * if (!user) throw new NotFound("User not found");
51
47
  * } catch (error) {
52
48
  * return errorHandler(error);
53
49
  * }
54
50
  * ```
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * // Handling unexpected errors
55
+ * try {
56
+ * await riskyOperation();
57
+ * } catch (error) {
58
+ * return errorHandler(error); // Returns ServerError response
59
+ * }
60
+ * ```
55
61
  */
56
62
  function errorHandler(error) {
57
63
  switch (true) {
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Flushes debug logs to the console with colored output in development mode.
3
+ *
4
+ * This function only outputs logs when running in development mode or when
5
+ * the DEBUG_MODE environment variable is set to "true".
6
+ * Each log entry is prefixed with a colored name tag based on the specified color scheme.
7
+ *
8
+ * @param {object} props - Configuration object for debug logging.
9
+ * @param {string} props.name - The name/label to display before each log entry (e.g., "API", "Database").
10
+ * @param {"yellow" | "cyan" | "red" | "green"} props.scheme - The color scheme for the name tag:
11
+ * - "yellow": Warning-level logs
12
+ * - "cyan": Info-level logs
13
+ * - "red": Error-level logs
14
+ * - "green": Success-level logs
15
+ * @param {string[]} props.debugs - Array of debug messages to be logged.
16
+ *
17
+ * @returns {void}
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * // Log API request information
22
+ * flushDebugLogs({
23
+ * name: "API",
24
+ * scheme: "cyan",
25
+ * debugs: ["POST /api/users", "Status: 201", "Response time: 45ms"]
26
+ * });
27
+ * // Output:
28
+ * // [API] POST /api/users
29
+ * // [API] Status: 201
30
+ * // [API] Response time: 45ms
31
+ *
32
+ * // Log error messages
33
+ * flushDebugLogs({
34
+ * name: "ERROR",
35
+ * scheme: "red",
36
+ * debugs: ["Database connection failed", "Retrying in 5s..."]
37
+ * });
38
+ * ```
39
+ */
40
+ declare function flushDebugLogs(props: {
41
+ scheme: "yellow" | "cyan" | "red" | "green";
42
+ name: string;
43
+ debugs: string[];
44
+ }): void;
45
+ export { flushDebugLogs };
46
+ //# sourceMappingURL=flushDebugLogs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flushDebugLogs.d.ts","sourceRoot":"","sources":["../../src/utilities/flushDebugLogs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH,iBAAS,cAAc,CAAC,KAAK,EAAE;IAC7B,MAAM,EAAE,QAAQ,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,CAAC;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,GAAG,IAAI,CAwBP;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Flushes debug logs to the console with colored output in development mode.
3
+ *
4
+ * This function only outputs logs when running in development mode or when
5
+ * the DEBUG_MODE environment variable is set to "true".
6
+ * Each log entry is prefixed with a colored name tag based on the specified color scheme.
7
+ *
8
+ * @param {object} props - Configuration object for debug logging.
9
+ * @param {string} props.name - The name/label to display before each log entry (e.g., "API", "Database").
10
+ * @param {"yellow" | "cyan" | "red" | "green"} props.scheme - The color scheme for the name tag:
11
+ * - "yellow": Warning-level logs
12
+ * - "cyan": Info-level logs
13
+ * - "red": Error-level logs
14
+ * - "green": Success-level logs
15
+ * @param {string[]} props.debugs - Array of debug messages to be logged.
16
+ *
17
+ * @returns {void}
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * // Log API request information
22
+ * flushDebugLogs({
23
+ * name: "API",
24
+ * scheme: "cyan",
25
+ * debugs: ["POST /api/users", "Status: 201", "Response time: 45ms"]
26
+ * });
27
+ * // Output:
28
+ * // [API] POST /api/users
29
+ * // [API] Status: 201
30
+ * // [API] Response time: 45ms
31
+ *
32
+ * // Log error messages
33
+ * flushDebugLogs({
34
+ * name: "ERROR",
35
+ * scheme: "red",
36
+ * debugs: ["Database connection failed", "Retrying in 5s..."]
37
+ * });
38
+ * ```
39
+ */
40
+ function flushDebugLogs(props) {
41
+ const isDebugMode = process.env.NODE_ENV === "development" ||
42
+ process.env?.DEBUG_MODE === "true";
43
+ if (isDebugMode) {
44
+ const reset = "\x1b[0m";
45
+ const colors = {
46
+ yellow: "\x1b[33m",
47
+ cyan: "\x1b[36m",
48
+ red: "\x1b[31m",
49
+ green: "\x1b[32m",
50
+ };
51
+ const debugName = `${colors[props.scheme]}[${props.name}]${reset}`;
52
+ let consoleData = `\n`;
53
+ props.debugs.forEach((debug) => {
54
+ consoleData += `${debugName} ${debug.trim()}\n`;
55
+ });
56
+ console.log(consoleData);
57
+ }
58
+ }
59
+ export { flushDebugLogs };
@@ -21,9 +21,9 @@ type FormParseReturnType<T extends FormParseProps> = SuccessResponse<T> | ErrorR
21
21
  *
22
22
  * @template T - A type that extends `FormParseProps`.
23
23
  *
24
- * @param {T} param0 - An array containing the form data and the Zod schema.
25
- * @param {T[0]} param0[0] - The form data to be validated.
26
- * @param {T[1]} param0[1] - The Zod schema used for validation.
24
+ * @param {T} props - An array containing the form data and the Zod schema.
25
+ * @param {T[0]} formData[0] - The form data to be validated.
26
+ * @param {T[1]} schema[1] - The Zod schema used for validation.
27
27
  *
28
28
  * @returns {Promise<FormParseReturnType<T>>} A promise that resolves to an object containing the validation result.
29
29
  * - If validation fails, it includes:
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formAsyncParse.d.ts","sourceRoot":"","sources":["../../src/utilities/formAsyncParse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAEnC,KAAK,eAAe,CAAC,CAAC,SAAS,cAAc,IAAI;IAC/C,OAAO,EAAE,IAAI,CAAC;IACd,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;CACjD,CAAC;AAEF,KAAK,aAAa,GAAG;IACnB,OAAO,EAAE,KAAK,CAAC;IACf,MAAM,EAAE;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IAChC,WAAW,EAAE;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;CACtC,CAAC;AAEF,KAAK,cAAc,GAAG,CAAC,QAAQ,EAAE;IAAE,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AAExE,KAAK,mBAAmB,CAAC,CAAC,SAAS,cAAc,IAC7C,eAAe,CAAC,CAAC,CAAC,GAClB,aAAa,CAAC;AAElB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,iBAAe,cAAc,CAAC,CAAC,SAAS,cAAc,EAAE,CACtD,QAAQ,EACR,MAAM,EACP,EAAE,CAAC,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAqBrC;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
@@ -3,9 +3,9 @@
3
3
  *
4
4
  * @template T - A type that extends `FormParseProps`.
5
5
  *
6
- * @param {T} param0 - An array containing the form data and the Zod schema.
7
- * @param {T[0]} param0[0] - The form data to be validated.
8
- * @param {T[1]} param0[1] - The Zod schema used for validation.
6
+ * @param {T} props - An array containing the form data and the Zod schema.
7
+ * @param {T[0]} formData[0] - The form data to be validated.
8
+ * @param {T[1]} schema[1] - The Zod schema used for validation.
9
9
  *
10
10
  * @returns {Promise<FormParseReturnType<T>>} A promise that resolves to an object containing the validation result.
11
11
  * - If validation fails, it includes:
@@ -21,9 +21,9 @@ type FormParseReturnType<T extends FormParseProps> = SuccessResponse<T> | ErrorR
21
21
  *
22
22
  * @template T - A type that extends `FormParseProps`.
23
23
  *
24
- * @param {T} param0 - An array containing the form data and the Zod schema.
25
- * @param {T[0]} param0[0] - The form data to be validated.
26
- * @param {T[1]} param0[1] - The Zod schema used for validation.
24
+ * @param {T} props - An array containing the form data and the Zod schema.
25
+ * @param {T[0]} formData[0] - The form data to be validated.
26
+ * @param {T[1]} schema[1] - The Zod schema used for validation.
27
27
  *
28
28
  * @returns {FormParseReturnType<T>} An object containing the validation result.
29
29
  * - If validation fails, it includes:
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formParse.d.ts","sourceRoot":"","sources":["../../src/utilities/formParse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAEnC,KAAK,eAAe,CAAC,CAAC,SAAS,cAAc,IAAI;IAC/C,OAAO,EAAE,IAAI,CAAC;IACd,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;CACjD,CAAC;AAEF,KAAK,aAAa,GAAG;IACnB,OAAO,EAAE,KAAK,CAAC;IACf,MAAM,EAAE;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IAChC,WAAW,EAAE;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;CACtC,CAAC;AAEF,KAAK,cAAc,GAAG,CAAC,QAAQ,EAAE;IAAE,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AAExE,KAAK,mBAAmB,CAAC,CAAC,SAAS,cAAc,IAC7C,eAAe,CAAC,CAAC,CAAC,GAClB,aAAa,CAAC;AAElB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,iBAAS,SAAS,CAAC,CAAC,SAAS,cAAc,EAAE,CAC3C,QAAQ,EACR,MAAM,EACP,EAAE,CAAC,GAAG,mBAAmB,CAAC,CAAC,CAAC,CAqB5B;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
@@ -3,9 +3,9 @@
3
3
  *
4
4
  * @template T - A type that extends `FormParseProps`.
5
5
  *
6
- * @param {T} param0 - An array containing the form data and the Zod schema.
7
- * @param {T[0]} param0[0] - The form data to be validated.
8
- * @param {T[1]} param0[1] - The Zod schema used for validation.
6
+ * @param {T} props - An array containing the form data and the Zod schema.
7
+ * @param {T[0]} formData[0] - The form data to be validated.
8
+ * @param {T[1]} schema[1] - The Zod schema used for validation.
9
9
  *
10
10
  * @returns {FormParseReturnType<T>} An object containing the validation result.
11
11
  * - If validation fails, it includes:
@@ -1,9 +1,8 @@
1
- type GetScopedParamsFunction = (request: Request, scope?: string) => URLSearchParams;
2
1
  /**
3
2
  * Extracts and returns scoped query parameters from a request URL.
4
3
  *
5
- * @param request - The incoming request object containing the URL.
6
- * @param scope - An optional string representing the scope prefix for filtering query parameters.
4
+ * @param {Request} request - The incoming request object containing the URL.
5
+ * @param {string} scope - An optional string representing the scope prefix for filtering query parameters.
7
6
  * If no scope is provided, all query parameters are returned.
8
7
  *
9
8
  * @returns A `URLSearchParams` object containing the scoped query parameters.
@@ -23,6 +22,6 @@ type GetScopedParamsFunction = (request: Request, scope?: string) => URLSearchPa
23
22
  * const params = getScopedParams(request, "scope");
24
23
  * console.log(params.toString()); // Output: "key1=value1&key2=value2"
25
24
  */
26
- declare const getScopedParams: GetScopedParamsFunction;
25
+ declare function getScopedParams(request: Request, scope?: string): URLSearchParams;
27
26
  export { getScopedParams };
28
27
  //# sourceMappingURL=getScopedParams.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getScopedParams.d.ts","sourceRoot":"","sources":["../../src/utilities/getScopedParams.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,iBAAS,eAAe,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,GAAE,MAAW,mBAW5D;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * Extracts and returns scoped query parameters from a request URL.
3
3
  *
4
- * @param request - The incoming request object containing the URL.
5
- * @param scope - An optional string representing the scope prefix for filtering query parameters.
4
+ * @param {Request} request - The incoming request object containing the URL.
5
+ * @param {string} scope - An optional string representing the scope prefix for filtering query parameters.
6
6
  * If no scope is provided, all query parameters are returned.
7
7
  *
8
8
  * @returns A `URLSearchParams` object containing the scoped query parameters.
@@ -22,7 +22,7 @@
22
22
  * const params = getScopedParams(request, "scope");
23
23
  * console.log(params.toString()); // Output: "key1=value1&key2=value2"
24
24
  */
25
- const getScopedParams = (request, scope = "") => {
25
+ function getScopedParams(request, scope = "") {
26
26
  const url = new URL(request.url);
27
27
  if (scope === "")
28
28
  return url.searchParams;
@@ -30,5 +30,5 @@ const getScopedParams = (request, scope = "") => {
30
30
  .filter(([key]) => key.startsWith(`${scope}:`))
31
31
  .map(([key, value]) => [key.replace(`${scope}:`, ""), value]);
32
32
  return new URLSearchParams(scopedSearchParams);
33
- };
33
+ }
34
34
  export { getScopedParams };
@@ -2,8 +2,6 @@ import { ZodType, z } from "zod";
2
2
  /**
3
3
  * A schema validator class that provides multiple validation methods for Zod schemas.
4
4
  *
5
- * @template T - A type that extends ZodType.
6
- *
7
5
  * @example
8
6
  * ```typescript
9
7
  * import { z } from "zod";
@@ -36,11 +34,8 @@ import { ZodType, z } from "zod";
36
34
  */
37
35
  declare class SchemaValidator<T extends ZodType> {
38
36
  readonly schema: T;
39
- functionName: string;
40
- callerInfo: string;
41
37
  /**
42
38
  * Creates a new SchemaValidator instance.
43
- *
44
39
  * @param {T} schema - The Zod schema to use for validation.
45
40
  */
46
41
  constructor(schema: T);
@@ -63,7 +58,6 @@ declare class SchemaValidator<T extends ZodType> {
63
58
  * Safely validates data and returns the complete parse result without throwing errors.
64
59
  *
65
60
  * @param {any} data - The data to validate.
66
- *
67
61
  * @returns {z.ZodSafeParseResult<z.infer<T>>} The Zod safe parse result containing success status and data or error.
68
62
  *
69
63
  * @example
@@ -83,10 +77,8 @@ declare class SchemaValidator<T extends ZodType> {
83
77
  * Validates data and returns the parsed result, throwing a ServerError on validation failure.
84
78
  *
85
79
  * @param {any} data - The data to validate.
86
- *
87
- * @returns {z.infer<T>} The validated and parsed data.
88
- *
89
80
  * @throws {ServerError} When validation fails, with a formatted error message.
81
+ * @returns {z.infer<T>} The validated and parsed data.
90
82
  *
91
83
  * @example
92
84
  * ```typescript
@@ -107,10 +99,8 @@ declare class SchemaValidator<T extends ZodType> {
107
99
  *
108
100
  * @param {any} data - The form data to validate.
109
101
  * @param {string} [message] - Optional custom error message.
110
- *
111
- * @returns {z.infer<T>} The validated and parsed form data.
112
- *
113
102
  * @throws {UnprocessableEntity} When validation fails, with structured field errors for form handling.
103
+ * @returns {z.infer<T>} The validated and parsed form data.
114
104
  *
115
105
  * @example
116
106
  * ```typescript
@@ -133,10 +123,8 @@ declare class SchemaValidator<T extends ZodType> {
133
123
  *
134
124
  * @param {any} data - The form data to validate.
135
125
  * @param {string} [message] - Optional custom error message.
136
- *
137
- * @returns {Promise<z.infer<T>>} A promise that resolves to the validated and parsed form data.
138
- *
139
126
  * @throws {UnprocessableEntity} When validation fails, with structured field errors for form handling.
127
+ * @returns {Promise<z.infer<T>>} A promise that resolves to the validated and parsed form data.
140
128
  *
141
129
  * @example
142
130
  * ```typescript
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemaValidator.d.ts","sourceRoot":"","sources":["../../src/utilities/schemaValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAgBjC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,cAAM,eAAe,CAAC,CAAC,SAAS,OAAO;IAKzB,QAAQ,CAAC,MAAM,EAAE,CAAC;IAJ9B;;;OAGG;gBACkB,MAAM,EAAE,CAAC;IAE9B;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAC,IAAI,EAAE,GAAG,GAAG,OAAO;IAI3B;;;;;;;;;;;;;;;;;OAiBG;IACH,YAAY,CAAC,IAAI,EAAE,GAAG,GAAG,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAIzD;;;;;;;;;;;;;;;;;;OAkBG;IACH,QAAQ,CAAC,IAAI,EAAE,GAAG,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;IAQ/B;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,YAAY,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;IAiBrD;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACG,iBAAiB,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;CAgB1E;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
@@ -3,7 +3,6 @@ import { ServerError } from "../http/badResponses/serverError";
3
3
  import { UnprocessableEntity } from "../http/badResponses/unprocessableEntity";
4
4
  import { formAsyncParse } from "./formAsyncParse";
5
5
  import { formParse } from "./formParse";
6
- import { getCaller } from "./getCaller";
7
6
  function formatErrorMessage(error) {
8
7
  const title = "Error validating:";
9
8
  const lines = error.issues.map(({ path, message }) => `-> ${path.join(".")}: ${message}`);
@@ -12,8 +11,6 @@ function formatErrorMessage(error) {
12
11
  /**
13
12
  * A schema validator class that provides multiple validation methods for Zod schemas.
14
13
  *
15
- * @template T - A type that extends ZodType.
16
- *
17
14
  * @example
18
15
  * ```typescript
19
16
  * import { z } from "zod";
@@ -46,18 +43,12 @@ function formatErrorMessage(error) {
46
43
  */
47
44
  class SchemaValidator {
48
45
  schema;
49
- functionName;
50
- callerInfo;
51
46
  /**
52
47
  * Creates a new SchemaValidator instance.
53
- *
54
48
  * @param {T} schema - The Zod schema to use for validation.
55
49
  */
56
50
  constructor(schema) {
57
51
  this.schema = schema;
58
- const { callerInfo, functionName } = getCaller();
59
- this.callerInfo = callerInfo;
60
- this.functionName = functionName;
61
52
  }
62
53
  /**
63
54
  * Checks if the provided data is valid according to the schema without throwing errors.
@@ -80,7 +71,6 @@ class SchemaValidator {
80
71
  * Safely validates data and returns the complete parse result without throwing errors.
81
72
  *
82
73
  * @param {any} data - The data to validate.
83
- *
84
74
  * @returns {z.ZodSafeParseResult<z.infer<T>>} The Zod safe parse result containing success status and data or error.
85
75
  *
86
76
  * @example
@@ -102,10 +92,8 @@ class SchemaValidator {
102
92
  * Validates data and returns the parsed result, throwing a ServerError on validation failure.
103
93
  *
104
94
  * @param {any} data - The data to validate.
105
- *
106
- * @returns {z.infer<T>} The validated and parsed data.
107
- *
108
95
  * @throws {ServerError} When validation fails, with a formatted error message.
96
+ * @returns {z.infer<T>} The validated and parsed data.
109
97
  *
110
98
  * @example
111
99
  * ```typescript
@@ -133,10 +121,8 @@ class SchemaValidator {
133
121
  *
134
122
  * @param {any} data - The form data to validate.
135
123
  * @param {string} [message] - Optional custom error message.
136
- *
137
- * @returns {z.infer<T>} The validated and parsed form data.
138
- *
139
124
  * @throws {UnprocessableEntity} When validation fails, with structured field errors for form handling.
125
+ * @returns {z.infer<T>} The validated and parsed form data.
140
126
  *
141
127
  * @example
142
128
  * ```typescript
@@ -171,10 +157,8 @@ class SchemaValidator {
171
157
  *
172
158
  * @param {any} data - The form data to validate.
173
159
  * @param {string} [message] - Optional custom error message.
174
- *
175
- * @returns {Promise<z.infer<T>>} A promise that resolves to the validated and parsed form data.
176
- *
177
160
  * @throws {UnprocessableEntity} When validation fails, with structured field errors for form handling.
161
+ * @returns {Promise<z.infer<T>>} A promise that resolves to the validated and parsed form data.
178
162
  *
179
163
  * @example
180
164
  * ```typescript
@@ -1,24 +1,19 @@
1
- type ValidateCepFunction = (rawCep: string) => boolean;
2
1
  /**
3
- * Removes all non-digit characters from the CEP.
4
- * @param cep - Raw CEP string.
5
- * @returns Only numeric characters.
6
- */
7
- /**
8
- * Validates a Brazilian CEP (Código de Endereçamento Postal).
2
+ * Validates a Brazilian CEP (postal code).
9
3
  *
10
- * A valid CEP has 8 numeric digits.
4
+ * A valid CEP must contain exactly 8 numeric digits,
5
+ * optionally formatted as "12345-678".
11
6
  *
12
- * @param rawCep - CEP string, may include formatting (e.g., "12345-678").
13
- * @returns `true` if the CEP is valid, otherwise `false`.
7
+ * @param {string} rawCep - CEP value, with or without formatting.
8
+ * @returns {boolean} `true` if the CEP is valid, otherwise `false`.
14
9
  *
15
10
  * @example
16
- * ```ts
11
+ * ```typescript
17
12
  * validateCep("12345-678"); // true
18
13
  * validateCep("12345678"); // true
19
14
  * validateCep("ABCDE-123"); // false
20
15
  * ```
21
16
  */
22
- declare const validateCep: ValidateCepFunction;
17
+ declare function validateCep(rawCep: string): boolean;
23
18
  export { validateCep };
24
19
  //# sourceMappingURL=validateCep.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"validateCep.d.ts","sourceRoot":"","sources":["../../src/validations/validateCep.ts"],"names":[],"mappings":"AAEA,KAAK,mBAAmB,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC;AAEvD;;;;GAIG;AAEH;;;;;;;;;;;;;;GAcG;AAEH,QAAA,MAAM,WAAW,EAAE,mBAYlB,CAAC;AAEF,OAAO,EAAE,WAAW,EAAE,CAAC"}
1
+ {"version":3,"file":"validateCep.d.ts","sourceRoot":"","sources":["../../src/validations/validateCep.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;GAeG;AAEH,iBAAS,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAU5C;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}