@arkyn/server 3.0.1-beta.20 → 3.0.1-beta.201

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 (244) hide show
  1. package/README.md +425 -69
  2. package/dist/{api/arkynLogRequest.d.ts → http/api/_logRequest.d.ts} +22 -19
  3. package/dist/{api/arkynLogRequest.d.ts.map → http/api/_logRequest.d.ts.map} +1 -1
  4. package/dist/http/api/_makeRequest.d.ts +61 -0
  5. package/dist/http/api/_makeRequest.d.ts.map +1 -0
  6. package/dist/http/api/deleteRequest.d.ts +17 -0
  7. package/dist/http/api/deleteRequest.d.ts.map +1 -0
  8. package/dist/http/api/getRequest.d.ts +16 -0
  9. package/dist/http/api/getRequest.d.ts.map +1 -0
  10. package/dist/http/api/patchRequest.d.ts +17 -0
  11. package/dist/http/api/patchRequest.d.ts.map +1 -0
  12. package/dist/http/api/postRequest.d.ts +17 -0
  13. package/dist/http/api/postRequest.d.ts.map +1 -0
  14. package/dist/http/api/putRequest.d.ts +17 -0
  15. package/dist/http/api/putRequest.d.ts.map +1 -0
  16. package/dist/http/badResponses/_badResponse.d.ts +25 -0
  17. package/dist/http/badResponses/_badResponse.d.ts.map +1 -0
  18. package/dist/http/badResponses/badGateway.d.ts +14 -24
  19. package/dist/http/badResponses/badGateway.d.ts.map +1 -1
  20. package/dist/http/badResponses/badRequest.d.ts +12 -24
  21. package/dist/http/badResponses/badRequest.d.ts.map +1 -1
  22. package/dist/http/badResponses/conflict.d.ts +12 -24
  23. package/dist/http/badResponses/conflict.d.ts.map +1 -1
  24. package/dist/http/badResponses/forbidden.d.ts +12 -24
  25. package/dist/http/badResponses/forbidden.d.ts.map +1 -1
  26. package/dist/http/badResponses/notFound.d.ts +12 -24
  27. package/dist/http/badResponses/notFound.d.ts.map +1 -1
  28. package/dist/http/badResponses/notImplemented.d.ts +12 -24
  29. package/dist/http/badResponses/notImplemented.d.ts.map +1 -1
  30. package/dist/http/badResponses/serverError.d.ts +12 -24
  31. package/dist/http/badResponses/serverError.d.ts.map +1 -1
  32. package/dist/http/badResponses/unauthorized.d.ts +12 -24
  33. package/dist/http/badResponses/unauthorized.d.ts.map +1 -1
  34. package/dist/http/badResponses/unprocessableEntity.d.ts +25 -34
  35. package/dist/http/badResponses/unprocessableEntity.d.ts.map +1 -1
  36. package/dist/http/successResponses/_successResponse.d.ts +36 -0
  37. package/dist/http/successResponses/_successResponse.d.ts.map +1 -0
  38. package/dist/http/successResponses/created.d.ts +12 -26
  39. package/dist/http/successResponses/created.d.ts.map +1 -1
  40. package/dist/http/successResponses/found.d.ts +12 -29
  41. package/dist/http/successResponses/found.d.ts.map +1 -1
  42. package/dist/http/successResponses/noContent.d.ts +12 -17
  43. package/dist/http/successResponses/noContent.d.ts.map +1 -1
  44. package/dist/http/successResponses/success.d.ts +12 -26
  45. package/dist/http/successResponses/success.d.ts.map +1 -1
  46. package/dist/http/successResponses/updated.d.ts +13 -26
  47. package/dist/http/successResponses/updated.d.ts.map +1 -1
  48. package/dist/index.d.ts +19 -10
  49. package/dist/index.d.ts.map +1 -1
  50. package/dist/index.js +1067 -28
  51. package/dist/modules/http/api/_logRequest.js +56 -0
  52. package/dist/modules/http/api/_makeRequest.js +70 -0
  53. package/dist/modules/http/api/deleteRequest.js +13 -0
  54. package/dist/modules/http/api/getRequest.js +12 -0
  55. package/dist/modules/http/api/patchRequest.js +13 -0
  56. package/dist/modules/http/api/postRequest.js +13 -0
  57. package/dist/modules/http/api/putRequest.js +13 -0
  58. package/dist/modules/http/badResponses/_badResponse.js +63 -0
  59. package/dist/modules/http/badResponses/badGateway.js +24 -0
  60. package/dist/modules/http/badResponses/badRequest.js +24 -0
  61. package/dist/modules/http/badResponses/conflict.js +24 -0
  62. package/dist/modules/http/badResponses/forbidden.js +24 -0
  63. package/dist/modules/http/badResponses/notFound.js +24 -0
  64. package/dist/modules/http/badResponses/notImplemented.js +24 -0
  65. package/dist/modules/http/badResponses/serverError.js +24 -0
  66. package/dist/modules/http/badResponses/unauthorized.js +24 -0
  67. package/dist/modules/http/badResponses/unprocessableEntity.js +28 -0
  68. package/dist/modules/http/successResponses/_successResponse.js +62 -0
  69. package/dist/modules/http/successResponses/created.js +24 -0
  70. package/dist/modules/http/successResponses/found.js +24 -0
  71. package/dist/modules/http/successResponses/noContent.js +17 -0
  72. package/dist/modules/http/successResponses/success.js +24 -0
  73. package/dist/modules/http/successResponses/updated.js +24 -0
  74. package/dist/modules/index.js +34 -0
  75. package/dist/modules/services/apiService.js +109 -0
  76. package/dist/modules/services/debugService.js +36 -0
  77. package/dist/modules/services/logMapperService.js +31 -0
  78. package/dist/modules/services/logService.js +21 -0
  79. package/dist/modules/utilities/decodeRequestBody.js +20 -0
  80. package/dist/modules/utilities/decodeRequestErrorMessage.js +6 -0
  81. package/dist/modules/utilities/errorHandler.js +39 -0
  82. package/dist/modules/utilities/flushDebugLogs.js +16 -0
  83. package/dist/modules/utilities/formAsyncParse.js +14 -0
  84. package/dist/modules/utilities/formParse.js +14 -0
  85. package/dist/modules/utilities/getScopedParams.js +9 -0
  86. package/dist/modules/utilities/schemaValidator.js +55 -0
  87. package/dist/modules/validations/validateCep.js +9 -0
  88. package/dist/modules/validations/validateCnpj.js +54 -0
  89. package/dist/modules/validations/validateCpf.js +27 -0
  90. package/dist/modules/validations/validateDate.js +26 -0
  91. package/dist/modules/validations/validateEmail.js +54 -0
  92. package/dist/modules/validations/validatePassword.js +12 -0
  93. package/dist/modules/validations/validatePhone.js +10 -0
  94. package/dist/modules/validations/validateRg.js +8 -0
  95. package/dist/services/apiService.d.ts +83 -0
  96. package/dist/services/apiService.d.ts.map +1 -0
  97. package/dist/services/debugService.d.ts +37 -0
  98. package/dist/services/debugService.d.ts.map +1 -0
  99. package/dist/services/logMapperService.d.ts +86 -0
  100. package/dist/services/logMapperService.d.ts.map +1 -0
  101. package/dist/services/logService.d.ts +33 -0
  102. package/dist/services/logService.d.ts.map +1 -0
  103. package/dist/utilities/decodeRequestBody.d.ts +18 -0
  104. package/dist/utilities/decodeRequestBody.d.ts.map +1 -0
  105. package/dist/utilities/decodeRequestErrorMessage.d.ts +19 -0
  106. package/dist/utilities/decodeRequestErrorMessage.d.ts.map +1 -0
  107. package/dist/utilities/errorHandler.d.ts +25 -0
  108. package/dist/utilities/errorHandler.d.ts.map +1 -0
  109. package/dist/utilities/flushDebugLogs.d.ts +24 -0
  110. package/dist/utilities/flushDebugLogs.d.ts.map +1 -0
  111. package/dist/utilities/formAsyncParse.d.ts +38 -0
  112. package/dist/utilities/formAsyncParse.d.ts.map +1 -0
  113. package/dist/utilities/formParse.d.ts +38 -0
  114. package/dist/utilities/formParse.d.ts.map +1 -0
  115. package/dist/utilities/getScopedParams.d.ts +19 -0
  116. package/dist/utilities/getScopedParams.d.ts.map +1 -0
  117. package/dist/utilities/schemaValidator.d.ts +75 -0
  118. package/dist/utilities/schemaValidator.d.ts.map +1 -0
  119. package/dist/validations/validateCep.d.ts +19 -0
  120. package/dist/validations/validateCep.d.ts.map +1 -0
  121. package/dist/validations/validateCnpj.d.ts +21 -0
  122. package/dist/validations/validateCnpj.d.ts.map +1 -0
  123. package/dist/validations/validateCpf.d.ts +16 -0
  124. package/dist/validations/validateCpf.d.ts.map +1 -0
  125. package/dist/validations/validateDate.d.ts +23 -0
  126. package/dist/validations/validateDate.d.ts.map +1 -0
  127. package/dist/validations/validateEmail.d.ts +21 -0
  128. package/dist/validations/validateEmail.d.ts.map +1 -0
  129. package/dist/validations/validatePassword.d.ts +20 -0
  130. package/dist/validations/validatePassword.d.ts.map +1 -0
  131. package/dist/validations/validatePhone.d.ts +16 -0
  132. package/dist/validations/validatePhone.d.ts.map +1 -0
  133. package/dist/validations/validateRg.d.ts +21 -0
  134. package/dist/validations/validateRg.d.ts.map +1 -0
  135. package/package.json +222 -15
  136. package/dist/api/arkynLogRequest.js +0 -82
  137. package/dist/api/deleteRequest.d.ts +0 -13
  138. package/dist/api/deleteRequest.d.ts.map +0 -1
  139. package/dist/api/deleteRequest.js +0 -14
  140. package/dist/api/getRequest.d.ts +0 -12
  141. package/dist/api/getRequest.d.ts.map +0 -1
  142. package/dist/api/getRequest.js +0 -13
  143. package/dist/api/makeRequest.d.ts +0 -38
  144. package/dist/api/makeRequest.d.ts.map +0 -1
  145. package/dist/api/makeRequest.js +0 -103
  146. package/dist/api/patchRequest.d.ts +0 -13
  147. package/dist/api/patchRequest.d.ts.map +0 -1
  148. package/dist/api/patchRequest.js +0 -14
  149. package/dist/api/postRequest.d.ts +0 -13
  150. package/dist/api/postRequest.d.ts.map +0 -1
  151. package/dist/api/postRequest.js +0 -14
  152. package/dist/api/putRequest.d.ts +0 -13
  153. package/dist/api/putRequest.d.ts.map +0 -1
  154. package/dist/api/putRequest.js +0 -14
  155. package/dist/config/apiInstance.d.ts +0 -80
  156. package/dist/config/apiInstance.d.ts.map +0 -1
  157. package/dist/config/apiInstance.js +0 -111
  158. package/dist/config/arkynLogInstance.d.ts +0 -44
  159. package/dist/config/arkynLogInstance.d.ts.map +0 -1
  160. package/dist/config/arkynLogInstance.js +0 -49
  161. package/dist/http/badResponses/badGateway.js +0 -52
  162. package/dist/http/badResponses/badRequest.js +0 -52
  163. package/dist/http/badResponses/conflict.js +0 -52
  164. package/dist/http/badResponses/forbidden.js +0 -52
  165. package/dist/http/badResponses/notFound.js +0 -52
  166. package/dist/http/badResponses/notImplemented.js +0 -52
  167. package/dist/http/badResponses/serverError.js +0 -52
  168. package/dist/http/badResponses/unauthorized.js +0 -52
  169. package/dist/http/badResponses/unprocessableEntity.js +0 -60
  170. package/dist/http/successResponses/created.js +0 -54
  171. package/dist/http/successResponses/found.js +0 -57
  172. package/dist/http/successResponses/noContent.js +0 -35
  173. package/dist/http/successResponses/success.js +0 -54
  174. package/dist/http/successResponses/updated.js +0 -54
  175. package/dist/mapper/arkynLogRequestMapper.d.ts +0 -30
  176. package/dist/mapper/arkynLogRequestMapper.d.ts.map +0 -1
  177. package/dist/mapper/arkynLogRequestMapper.js +0 -44
  178. package/dist/services/decodeErrorMessageFromRequest.d.ts +0 -17
  179. package/dist/services/decodeErrorMessageFromRequest.d.ts.map +0 -1
  180. package/dist/services/decodeErrorMessageFromRequest.js +0 -30
  181. package/dist/services/decodeRequestBody.d.ts +0 -17
  182. package/dist/services/decodeRequestBody.d.ts.map +0 -1
  183. package/dist/services/decodeRequestBody.js +0 -38
  184. package/dist/services/errorHandler.d.ts +0 -44
  185. package/dist/services/errorHandler.d.ts.map +0 -1
  186. package/dist/services/errorHandler.js +0 -93
  187. package/dist/services/formParse.d.ts +0 -59
  188. package/dist/services/formParse.d.ts.map +0 -1
  189. package/dist/services/formParse.js +0 -59
  190. package/dist/services/getCaller.d.ts +0 -17
  191. package/dist/services/getCaller.d.ts.map +0 -1
  192. package/dist/services/getCaller.js +0 -65
  193. package/dist/services/getScopedParams.d.ts +0 -28
  194. package/dist/services/getScopedParams.d.ts.map +0 -1
  195. package/dist/services/getScopedParams.js +0 -34
  196. package/dist/services/httpDebug.d.ts +0 -35
  197. package/dist/services/httpDebug.d.ts.map +0 -1
  198. package/dist/services/httpDebug.js +0 -52
  199. package/dist/services/measureRouteExecution.d.ts +0 -3
  200. package/dist/services/measureRouteExecution.d.ts.map +0 -1
  201. package/dist/services/measureRouteExecution.js +0 -24
  202. package/dist/services/schemaValidator.d.ts +0 -13
  203. package/dist/services/schemaValidator.d.ts.map +0 -1
  204. package/dist/services/schemaValidator.js +0 -51
  205. package/dist/types/ApiResponseDTO.d.ts +0 -17
  206. package/dist/types/ApiResponseDTO.d.ts.map +0 -1
  207. package/dist/types/ApiResponseDTO.js +0 -1
  208. package/src/api/arkynLogRequest.ts +0 -118
  209. package/src/api/deleteRequest.ts +0 -22
  210. package/src/api/getRequest.ts +0 -20
  211. package/src/api/makeRequest.ts +0 -118
  212. package/src/api/patchRequest.ts +0 -22
  213. package/src/api/postRequest.ts +0 -22
  214. package/src/api/putRequest.ts +0 -22
  215. package/src/config/apiInstance.ts +0 -148
  216. package/src/config/arkynLogInstance.ts +0 -70
  217. package/src/http/badResponses/badGateway.ts +0 -63
  218. package/src/http/badResponses/badRequest.ts +0 -63
  219. package/src/http/badResponses/conflict.ts +0 -63
  220. package/src/http/badResponses/forbidden.ts +0 -63
  221. package/src/http/badResponses/notFound.ts +0 -63
  222. package/src/http/badResponses/notImplemented.ts +0 -63
  223. package/src/http/badResponses/serverError.ts +0 -63
  224. package/src/http/badResponses/unauthorized.ts +0 -63
  225. package/src/http/badResponses/unprocessableEntity.ts +0 -79
  226. package/src/http/successResponses/created.ts +0 -64
  227. package/src/http/successResponses/found.ts +0 -67
  228. package/src/http/successResponses/noContent.ts +0 -42
  229. package/src/http/successResponses/success.ts +0 -64
  230. package/src/http/successResponses/updated.ts +0 -64
  231. package/src/index.ts +0 -31
  232. package/src/mapper/arkynLogRequestMapper.ts +0 -73
  233. package/src/services/decodeErrorMessageFromRequest.ts +0 -36
  234. package/src/services/decodeRequestBody.ts +0 -43
  235. package/src/services/errorHandler.ts +0 -99
  236. package/src/services/formParse.ts +0 -86
  237. package/src/services/getCaller.ts +0 -82
  238. package/src/services/getScopedParams.ts +0 -43
  239. package/src/services/httpDebug.ts +0 -61
  240. package/src/services/measureRouteExecution.ts +0 -31
  241. package/src/services/schemaValidator.ts +0 -66
  242. package/src/types/ApiResponseDTO.ts +0 -19
  243. package/tsconfig.json +0 -21
  244. package/vitest.config.ts +0 -5
@@ -1,44 +0,0 @@
1
- /**
2
- * Handles errors and converts them into appropriate HTTP responses.
3
- *
4
- * This function takes an error object and determines its type to return
5
- * the corresponding HTTP response. It supports both success and error
6
- * response types, converting them into a standardized format using the
7
- * `toResponse` method when applicable.
8
- *
9
- * @param error - The error object to handle. It can be an instance of various
10
- * HTTP response classes or a generic error.
11
- *
12
- * @returns The corresponding HTTP response object if the error matches a known
13
- * type, or `undefined` if no match is found.
14
- *
15
- * ### Supported Success Responses:
16
- * - `Found`
17
- * - `Created`
18
- * - `Updated`
19
- * - `Success`
20
- * - `NoContent`
21
- *
22
- * ### Supported Error Responses:
23
- * - `BadGateway`
24
- * - `BadRequest`
25
- * - `Conflict`
26
- * - `Forbidden`
27
- * - `NotFound`
28
- * - `NotImplemented`
29
- * - `ServerError`
30
- * - `Unauthorized`
31
- * - `UnprocessableEntity`
32
- *
33
- * ### Example Usage:
34
- * ```typescript
35
- * try {
36
- * // Some operation that might throw an error
37
- * } catch (error) {
38
- * return errorHandler(error);
39
- * }
40
- * ```
41
- */
42
- declare function errorHandler(error: any): Response;
43
- export { errorHandler };
44
- //# sourceMappingURL=errorHandler.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errorHandler.d.ts","sourceRoot":"","sources":["../../src/services/errorHandler.ts"],"names":[],"mappings":"AAgBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,iBAAS,YAAY,CAAC,KAAK,EAAE,GAAG,GAAG,QAAQ,CAsC1C;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
@@ -1,93 +0,0 @@
1
- import { BadGateway } from "../http/badResponses/badGateway";
2
- import { BadRequest } from "../http/badResponses/badRequest";
3
- import { Conflict } from "../http/badResponses/conflict";
4
- import { Forbidden } from "../http/badResponses/forbidden";
5
- import { NotFound } from "../http/badResponses/notFound";
6
- import { NotImplemented } from "../http/badResponses/notImplemented";
7
- import { ServerError } from "../http/badResponses/serverError";
8
- import { Unauthorized } from "../http/badResponses/unauthorized";
9
- import { UnprocessableEntity } from "../http/badResponses/unprocessableEntity";
10
- import { Created } from "../http/successResponses/created";
11
- import { Found } from "../http/successResponses/found";
12
- import { NoContent } from "../http/successResponses/noContent";
13
- import { Success } from "../http/successResponses/success";
14
- import { Updated } from "../http/successResponses/updated";
15
- /**
16
- * Handles errors and converts them into appropriate HTTP responses.
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.
22
- *
23
- * @param error - The error object to handle. It can be an instance of various
24
- * HTTP response classes or a generic error.
25
- *
26
- * @returns The corresponding HTTP response object if the error matches a known
27
- * type, or `undefined` if no match is found.
28
- *
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`
46
- *
47
- * ### Example Usage:
48
- * ```typescript
49
- * try {
50
- * // Some operation that might throw an error
51
- * } catch (error) {
52
- * return errorHandler(error);
53
- * }
54
- * ```
55
- */
56
- function errorHandler(error) {
57
- switch (true) {
58
- case error instanceof Response:
59
- return error;
60
- case error instanceof Found:
61
- return error.toResponse();
62
- case error instanceof Created:
63
- return error.toResponse();
64
- case error instanceof Updated:
65
- return error.toResponse();
66
- case error instanceof Success:
67
- return error.toResponse();
68
- case error instanceof NoContent:
69
- return error.toResponse();
70
- }
71
- switch (true) {
72
- case error instanceof BadGateway:
73
- return error.toResponse();
74
- case error instanceof BadRequest:
75
- return error.toResponse();
76
- case error instanceof Conflict:
77
- return error.toResponse();
78
- case error instanceof Forbidden:
79
- return error.toResponse();
80
- case error instanceof NotFound:
81
- return error.toResponse();
82
- case error instanceof NotImplemented:
83
- return error.toResponse();
84
- case error instanceof ServerError:
85
- return error.toResponse();
86
- case error instanceof Unauthorized:
87
- return error.toResponse();
88
- case error instanceof UnprocessableEntity:
89
- return error.toResponse();
90
- }
91
- return new ServerError("Server error", error).toResponse();
92
- }
93
- export { errorHandler };
@@ -1,59 +0,0 @@
1
- import type { ZodType } from "zod";
2
- type SuccessResponse<T extends FormParseProps> = {
3
- success: true;
4
- data: T[1] extends ZodType<infer U> ? U : never;
5
- };
6
- type ErrorResponse = {
7
- success: false;
8
- fields: {
9
- [x: string]: string;
10
- };
11
- fieldErrors: {
12
- [x: string]: string;
13
- };
14
- };
15
- type FormParseProps = [formData: {
16
- [k: string]: any;
17
- }, schema: ZodType];
18
- type FormParseReturnType<T extends FormParseProps> = SuccessResponse<T> | ErrorResponse;
19
- /**
20
- * Parses form data using a Zod schema and returns the result.
21
- *
22
- * @template T - A type that extends `FormParseProps`.
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.
27
- *
28
- * @returns {FormParseReturnType<T>} An object containing the validation result.
29
- * - If validation fails, it includes:
30
- * - `success`: A boolean indicating the validation status (false).
31
- * - `fieldErrors`: An object mapping field names to their respective error messages.
32
- * - `fields`: The original form data.
33
- * - If validation succeeds, it includes:
34
- * - `success`: A boolean indicating the validation status (true).
35
- * - `data`: The parsed and validated data.
36
- *
37
- * @example
38
- * ```typescript
39
- * import { z } from "zod";
40
- *
41
- * const schema = z.object({
42
- * name: z.string().min(1, "Name is required"),
43
- * age: z.number().min(18, "Must be at least 18"),
44
- * });
45
- *
46
- * const formData = { name: "", age: 17 };
47
- *
48
- * const result = formParse([formData, schema]);
49
- *
50
- * if (!result.success) {
51
- * console.log(result.fieldErrors); // { name: "Name is required", age: "Must be at least 18" }
52
- * } else {
53
- * console.log(result.data); // Parsed data
54
- * }
55
- * ```
56
- */
57
- declare function formParse<T extends FormParseProps>([formData, schema,]: T): FormParseReturnType<T>;
58
- export { formParse };
59
- //# sourceMappingURL=formParse.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"formParse.d.ts","sourceRoot":"","sources":["../../src/services/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,CAsB5B;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
@@ -1,59 +0,0 @@
1
- /**
2
- * Parses form data using a Zod schema and returns the result.
3
- *
4
- * @template T - A type that extends `FormParseProps`.
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.
9
- *
10
- * @returns {FormParseReturnType<T>} An object containing the validation result.
11
- * - If validation fails, it includes:
12
- * - `success`: A boolean indicating the validation status (false).
13
- * - `fieldErrors`: An object mapping field names to their respective error messages.
14
- * - `fields`: The original form data.
15
- * - If validation succeeds, it includes:
16
- * - `success`: A boolean indicating the validation status (true).
17
- * - `data`: The parsed and validated data.
18
- *
19
- * @example
20
- * ```typescript
21
- * import { z } from "zod";
22
- *
23
- * const schema = z.object({
24
- * name: z.string().min(1, "Name is required"),
25
- * age: z.number().min(18, "Must be at least 18"),
26
- * });
27
- *
28
- * const formData = { name: "", age: 17 };
29
- *
30
- * const result = formParse([formData, schema]);
31
- *
32
- * if (!result.success) {
33
- * console.log(result.fieldErrors); // { name: "Name is required", age: "Must be at least 18" }
34
- * } else {
35
- * console.log(result.data); // Parsed data
36
- * }
37
- * ```
38
- */
39
- function formParse([formData, schema,]) {
40
- const zodResponse = schema.safeParse(formData);
41
- if (zodResponse.success === false) {
42
- const errorsObject = Object.fromEntries(zodResponse.error.issues.map((item) => {
43
- console.log(item);
44
- return [item.path.join("."), item.message];
45
- }));
46
- return {
47
- success: zodResponse.success,
48
- fieldErrors: errorsObject,
49
- fields: formData,
50
- };
51
- }
52
- else {
53
- return {
54
- success: zodResponse.success,
55
- data: zodResponse.data,
56
- };
57
- }
58
- }
59
- export { formParse };
@@ -1,17 +0,0 @@
1
- /**
2
- * Retrieves information about the caller of the current function.
3
- *
4
- * This function analyzes the stack trace to determine the file path and function name
5
- * of the caller. It excludes stack trace entries related to the `@arkyn/server` package
6
- * and attempts to resolve the file path relative to the project root directory.
7
- *
8
- * @returns An object containing:
9
- * - `functionName`: The name of the function that called the current function, or "Unknown function" if it cannot be determined.
10
- * - `callerInfo`: The file path of the caller relative to the project root, or "Unknown caller" if it cannot be determined.
11
- */
12
- declare function getCaller(): {
13
- functionName: string;
14
- callerInfo: string;
15
- };
16
- export { getCaller };
17
- //# sourceMappingURL=getCaller.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getCaller.d.ts","sourceRoot":"","sources":["../../src/services/getCaller.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,iBAAS,SAAS;;;EAkEjB;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
@@ -1,65 +0,0 @@
1
- import path from "path";
2
- /**
3
- * Retrieves information about the caller of the current function.
4
- *
5
- * This function analyzes the stack trace to determine the file path and function name
6
- * of the caller. It excludes stack trace entries related to the `@arkyn/server` package
7
- * and attempts to resolve the file path relative to the project root directory.
8
- *
9
- * @returns An object containing:
10
- * - `functionName`: The name of the function that called the current function, or "Unknown function" if it cannot be determined.
11
- * - `callerInfo`: The file path of the caller relative to the project root, or "Unknown caller" if it cannot be determined.
12
- */
13
- function getCaller() {
14
- const projectRoot = process.cwd();
15
- const err = new Error();
16
- const stack = err.stack || "";
17
- const stackLines = stack.split("\n").map((line) => line.trim());
18
- // The first line is the error message
19
- // The second line is this function (getCaller)
20
- // The third line should be the direct caller
21
- // We start from 2 because indexes are zero-based
22
- let callerIndex = 2;
23
- // Ignore internal or infrastructure lines if necessary
24
- while (callerIndex < stackLines.length &&
25
- (stackLines[callerIndex].includes("node:internal") ||
26
- stackLines[callerIndex].includes("/node_modules/"))) {
27
- callerIndex++;
28
- }
29
- const callerLine = stackLines[callerIndex] || "";
30
- let functionName = "Unknown function";
31
- let callerInfo = "Unknown caller";
32
- // Default for named functions: "at functionName (file:line:column)"
33
- const namedFunctionMatch = callerLine.match(/at\s+([^(\s]+)\s+\(([^)]+)\)/);
34
- if (namedFunctionMatch) {
35
- functionName = namedFunctionMatch[1];
36
- callerInfo = namedFunctionMatch[2];
37
- }
38
- // Default for anonymous functions or methods: "at file:line:column"
39
- else {
40
- const anonymousFunctionMatch = callerLine.match(/at\s+(.+)/);
41
- if (anonymousFunctionMatch) {
42
- callerInfo = anonymousFunctionMatch[1];
43
- // Tenta extrair nome da função de padrões como Object.method ou Class.method
44
- const objectMethodMatch = callerInfo.match(/at\s+([^(\s]+)\s+/);
45
- if (objectMethodMatch && objectMethodMatch[1] !== "new") {
46
- functionName = objectMethodMatch[1];
47
- }
48
- }
49
- }
50
- // Handles file paths
51
- if (callerInfo.includes("(")) {
52
- callerInfo = callerInfo.substring(callerInfo.indexOf("(") + 1, callerInfo.lastIndexOf(")"));
53
- }
54
- // Remove the line:column part of the file path
55
- callerInfo = callerInfo.split(":").slice(0, -2).join(":");
56
- // Make the path relative to the project
57
- try {
58
- callerInfo = path.relative(projectRoot, callerInfo);
59
- }
60
- catch (e) {
61
- // If it fails to relativize, use the original path
62
- }
63
- return { functionName, callerInfo };
64
- }
65
- export { getCaller };
@@ -1,28 +0,0 @@
1
- type GetScopedParamsFunction = (request: Request, scope?: string) => URLSearchParams;
2
- /**
3
- * Extracts and returns scoped query parameters from a request URL.
4
- *
5
- * @param request - The incoming request object containing the URL.
6
- * @param scope - An optional string representing the scope prefix for filtering query parameters.
7
- * If no scope is provided, all query parameters are returned.
8
- *
9
- * @returns A `URLSearchParams` object containing the scoped query parameters.
10
- * If a scope is provided, only parameters with keys starting with the scope
11
- * (e.g., `scope:key`) are included, and the scope prefix is removed from the keys.
12
- * If no scope is provided, all query parameters are returned as-is.
13
- *
14
- * @example
15
- * // Example 1: No scope provided
16
- * const request = { url: "https://example.com?key1=value1&key2=value2" };
17
- * const params = getScopedParams(request);
18
- * console.log(params.toString()); // Output: "key1=value1&key2=value2"
19
- *
20
- * @example
21
- * // Example 2: Scope provided
22
- * const request = { url: "https://example.com?scope:key1=value1&scope:key2=value2&key3=value3" };
23
- * const params = getScopedParams(request, "scope");
24
- * console.log(params.toString()); // Output: "key1=value1&key2=value2"
25
- */
26
- declare const getScopedParams: GetScopedParamsFunction;
27
- export { getScopedParams };
28
- //# sourceMappingURL=getScopedParams.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getScopedParams.d.ts","sourceRoot":"","sources":["../../src/services/getScopedParams.ts"],"names":[],"mappings":"AAAA,KAAK,uBAAuB,GAAG,CAC7B,OAAO,EAAE,OAAO,EAChB,KAAK,CAAC,EAAE,MAAM,KACX,eAAe,CAAC;AACrB;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,QAAA,MAAM,eAAe,EAAE,uBAWtB,CAAC;AAEF,OAAO,EAAE,eAAe,EAAE,CAAC"}
@@ -1,34 +0,0 @@
1
- /**
2
- * Extracts and returns scoped query parameters from a request URL.
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.
6
- * If no scope is provided, all query parameters are returned.
7
- *
8
- * @returns A `URLSearchParams` object containing the scoped query parameters.
9
- * If a scope is provided, only parameters with keys starting with the scope
10
- * (e.g., `scope:key`) are included, and the scope prefix is removed from the keys.
11
- * If no scope is provided, all query parameters are returned as-is.
12
- *
13
- * @example
14
- * // Example 1: No scope provided
15
- * const request = { url: "https://example.com?key1=value1&key2=value2" };
16
- * const params = getScopedParams(request);
17
- * console.log(params.toString()); // Output: "key1=value1&key2=value2"
18
- *
19
- * @example
20
- * // Example 2: Scope provided
21
- * const request = { url: "https://example.com?scope:key1=value1&scope:key2=value2&key3=value3" };
22
- * const params = getScopedParams(request, "scope");
23
- * console.log(params.toString()); // Output: "key1=value1&key2=value2"
24
- */
25
- const getScopedParams = (request, scope = "") => {
26
- const url = new URL(request.url);
27
- if (scope === "")
28
- return url.searchParams;
29
- const scopedSearchParams = Array.from(url.searchParams.entries())
30
- .filter(([key]) => key.startsWith(`${scope}:`))
31
- .map(([key, value]) => [key.replace(`${scope}:`, ""), value]);
32
- return new URLSearchParams(scopedSearchParams);
33
- };
34
- export { getScopedParams };
@@ -1,35 +0,0 @@
1
- /**
2
- * Logs debug information to the console when in development mode or when the
3
- * `SHOW_ERRORS_IN_CONSOLE` environment variable is set to "true".
4
- *
5
- * This function provides detailed information about the caller function,
6
- * its location, and the provided body and cause, if any.
7
- *
8
- * @param name - A string representing the name or context of the debug log.
9
- * @param body - The main content or data to be logged.
10
- * @param cause - (Optional) Additional information or error cause to be logged.
11
- *
12
- * @remarks
13
- * The debug logs are only displayed when the application is running in
14
- * development mode (`NODE_ENV === "development"`) or when the
15
- * `SHOW_ERRORS_IN_CONSOLE` environment variable is explicitly set to "true".
16
- *
17
- * The logs include:
18
- * - The name of the debug context.
19
- * - The caller function name and its location.
20
- * - The provided body content.
21
- * - The optional cause, if provided.
22
- *
23
- * @example
24
- * ```typescript
25
- * httpDebug("FetchUserData", { userId: 123 });
26
- * ```
27
- *
28
- * @example
29
- * ```typescript
30
- * httpDebug("FetchUserDataError", { userId: 123 }, new Error("User not found"));
31
- * ```
32
- */
33
- declare function httpDebug(name: string, body: any, cause?: any): void;
34
- export { httpDebug };
35
- //# sourceMappingURL=httpDebug.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"httpDebug.d.ts","sourceRoot":"","sources":["../../src/services/httpDebug.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,iBAAS,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,GAAG,QAuBtD;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
@@ -1,52 +0,0 @@
1
- import { getCaller } from "../services/getCaller";
2
- /**
3
- * Logs debug information to the console when in development mode or when the
4
- * `SHOW_ERRORS_IN_CONSOLE` environment variable is set to "true".
5
- *
6
- * This function provides detailed information about the caller function,
7
- * its location, and the provided body and cause, if any.
8
- *
9
- * @param name - A string representing the name or context of the debug log.
10
- * @param body - The main content or data to be logged.
11
- * @param cause - (Optional) Additional information or error cause to be logged.
12
- *
13
- * @remarks
14
- * The debug logs are only displayed when the application is running in
15
- * development mode (`NODE_ENV === "development"`) or when the
16
- * `SHOW_ERRORS_IN_CONSOLE` environment variable is explicitly set to "true".
17
- *
18
- * The logs include:
19
- * - The name of the debug context.
20
- * - The caller function name and its location.
21
- * - The provided body content.
22
- * - The optional cause, if provided.
23
- *
24
- * @example
25
- * ```typescript
26
- * httpDebug("FetchUserData", { userId: 123 });
27
- * ```
28
- *
29
- * @example
30
- * ```typescript
31
- * httpDebug("FetchUserDataError", { userId: 123 }, new Error("User not found"));
32
- * ```
33
- */
34
- function httpDebug(name, body, cause) {
35
- const isDebugMode = process.env.NODE_ENV === "development" ||
36
- process.env?.SHOW_ERRORS_IN_CONSOLE === "true";
37
- if (isDebugMode) {
38
- const reset = "\x1b[0m";
39
- const cyan = "\x1b[36m";
40
- const debugName = `${cyan}[ARKYN-DEBUG]${reset}`;
41
- const { callerInfo, functionName } = getCaller();
42
- let consoleData = `${debugName} ${name} initialized\n`;
43
- consoleData += `${debugName} Caller Function: ${functionName}\n`;
44
- consoleData += `${debugName} Caller Location: ${callerInfo}\n`;
45
- consoleData += `${debugName} Body: ${JSON.stringify(body, null, 2)}\n`;
46
- if (cause) {
47
- consoleData += `${debugName} Cause: ${JSON.stringify(cause, null, 2)}\n`;
48
- }
49
- console.log(consoleData);
50
- }
51
- }
52
- export { httpDebug };
@@ -1,3 +0,0 @@
1
- declare function measureRouteExecution<T = unknown>(handler: (props: any) => Promise<T>): (props: any) => Promise<T>;
2
- export { measureRouteExecution };
3
- //# sourceMappingURL=measureRouteExecution.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"measureRouteExecution.d.ts","sourceRoot":"","sources":["../../src/services/measureRouteExecution.ts"],"names":[],"mappings":"AAAA,iBAAS,qBAAqB,CAAC,CAAC,GAAG,OAAO,EACxC,OAAO,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,OAAO,CAAC,CAAC,CAAC,IAEG,OAAO,GAAG,KAAG,OAAO,CAAC,CAAC,CAAC,CAyB9D;AAED,OAAO,EAAE,qBAAqB,EAAE,CAAC"}
@@ -1,24 +0,0 @@
1
- function measureRouteExecution(handler) {
2
- return async function measuredHandler(props) {
3
- const startTime = performance.now();
4
- try {
5
- const result = await handler(props);
6
- const url = new URL(props.request.url);
7
- const endTime = performance.now();
8
- const duration = (endTime - startTime).toFixed(2);
9
- console.log({
10
- domain: url.hostname,
11
- pathname: url.pathname,
12
- method: props.request.method,
13
- duration,
14
- });
15
- return result;
16
- }
17
- catch (error) {
18
- const endTime = performance.now();
19
- console.error("");
20
- throw error;
21
- }
22
- };
23
- }
24
- export { measureRouteExecution };
@@ -1,13 +0,0 @@
1
- import { ZodType, z } from "zod";
2
- declare class SchemaValidator<T extends ZodType> {
3
- readonly schema: T;
4
- functionName: string;
5
- callerInfo: string;
6
- constructor(schema: T);
7
- isValid(data: any): boolean;
8
- safeValidate(data: any): z.ZodSafeParseResult<z.infer<T>>;
9
- validate(data: any): z.infer<T>;
10
- formValidate(data: any, message?: string): z.infer<T>;
11
- }
12
- export { SchemaValidator };
13
- //# sourceMappingURL=schemaValidator.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"schemaValidator.d.ts","sourceRoot":"","sources":["../../src/services/schemaValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAiBjC,cAAM,eAAe,CAAC,CAAC,SAAS,OAAO;IAIzB,QAAQ,CAAC,MAAM,EAAE,CAAC;IAH9B,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;gBAEE,MAAM,EAAE,CAAC;IAM9B,OAAO,CAAC,IAAI,EAAE,GAAG,GAAG,OAAO;IAI3B,YAAY,CAAC,IAAI,EAAE,GAAG,GAAG,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAIzD,QAAQ,CAAC,IAAI,EAAE,GAAG,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;IAQ/B,YAAY,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;CAoBtD;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
@@ -1,51 +0,0 @@
1
- import { ZodType, z } from "zod";
2
- import { ServerError } from "../http/badResponses/serverError";
3
- import { UnprocessableEntity } from "../http/badResponses/unprocessableEntity";
4
- import { formParse } from "./formParse";
5
- import { getCaller } from "./getCaller";
6
- import { httpDebug } from "./httpDebug";
7
- function formatErrorMessage(error) {
8
- const title = "Error validating:";
9
- const lines = error.issues.map(({ path, message }) => `-> ${path.join(".")}: ${message}`);
10
- return [title, ...lines].join("\n");
11
- }
12
- class SchemaValidator {
13
- schema;
14
- functionName;
15
- callerInfo;
16
- constructor(schema) {
17
- this.schema = schema;
18
- const { callerInfo, functionName } = getCaller();
19
- this.callerInfo = callerInfo;
20
- this.functionName = functionName;
21
- }
22
- isValid(data) {
23
- return this.schema.safeParse(data).success;
24
- }
25
- safeValidate(data) {
26
- return this.schema.safeParse(data);
27
- }
28
- validate(data) {
29
- try {
30
- return this.schema.parse(data);
31
- }
32
- catch (error) {
33
- throw new ServerError(formatErrorMessage(error));
34
- }
35
- }
36
- formValidate(data, message) {
37
- const formParsed = formParse([data, this.schema]);
38
- if (!formParsed.success) {
39
- httpDebug("UnprocessableEntity", formParsed);
40
- const firstErrorKey = Object.keys(formParsed.fieldErrors)[0];
41
- throw new UnprocessableEntity({
42
- fields: formParsed.fields,
43
- fieldErrors: formParsed.fieldErrors,
44
- data: { scrollTo: firstErrorKey },
45
- message,
46
- }, false);
47
- }
48
- return formParsed.data;
49
- }
50
- }
51
- export { SchemaValidator };
@@ -1,17 +0,0 @@
1
- type ApiSuccessResponse<T = any> = {
2
- success: true;
3
- status: number;
4
- message: string;
5
- response: T;
6
- cause: null;
7
- };
8
- type ApiFailedResponse = {
9
- success: false;
10
- status: number;
11
- message: string;
12
- response: any;
13
- cause: string | Error | null;
14
- };
15
- type ApiResponseDTO<T = any> = ApiSuccessResponse<T> | ApiFailedResponse;
16
- export type { ApiResponseDTO };
17
- //# sourceMappingURL=ApiResponseDTO.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ApiResponseDTO.d.ts","sourceRoot":"","sources":["../../src/types/ApiResponseDTO.ts"],"names":[],"mappings":"AAAA,KAAK,kBAAkB,CAAC,CAAC,GAAG,GAAG,IAAI;IACjC,OAAO,EAAE,IAAI,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,CAAC,CAAC;IACZ,KAAK,EAAE,IAAI,CAAC;CACb,CAAC;AAEF,KAAK,iBAAiB,GAAG;IACvB,OAAO,EAAE,KAAK,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,GAAG,CAAC;IACd,KAAK,EAAE,MAAM,GAAG,KAAK,GAAG,IAAI,CAAC;CAC9B,CAAC;AAEF,KAAK,cAAc,CAAC,CAAC,GAAG,GAAG,IAAI,kBAAkB,CAAC,CAAC,CAAC,GAAG,iBAAiB,CAAC;AAEzE,YAAY,EAAE,cAAc,EAAE,CAAC"}
@@ -1 +0,0 @@
1
- export {};