@forklaunch/core 0.2.36 → 0.3.0

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 (222) hide show
  1. package/lib/{src/database/mikro/models/entities/base.entity.d.ts → base.entity-DNfmMOgd.d.mts} +3 -2
  2. package/lib/base.entity-DNfmMOgd.d.ts +27 -0
  3. package/lib/{src/cache/redisTtlCache.d.ts → cache/index.d.mts} +67 -4
  4. package/lib/cache/index.d.ts +130 -0
  5. package/lib/cache/index.js +133 -0
  6. package/lib/cache/index.mjs +105 -0
  7. package/lib/controllers/index.d.mts +5 -0
  8. package/lib/controllers/index.d.ts +5 -0
  9. package/lib/controllers/index.js +18 -0
  10. package/lib/controllers/index.mjs +0 -0
  11. package/lib/database/index.d.mts +37 -0
  12. package/lib/{src/database/mikro/models/entities/mongo.base.entity.d.ts → database/index.d.ts} +5 -2
  13. package/lib/database/index.js +78 -0
  14. package/lib/database/index.mjs +53 -0
  15. package/lib/dtoMapper/index.d.mts +215 -0
  16. package/lib/dtoMapper/index.d.ts +215 -0
  17. package/lib/dtoMapper/index.js +230 -0
  18. package/lib/dtoMapper/index.mjs +202 -0
  19. package/lib/http/index.d.mts +910 -0
  20. package/lib/http/index.d.ts +910 -0
  21. package/lib/http/index.js +2181 -0
  22. package/lib/http/index.mjs +2122 -0
  23. package/lib/services/index.d.mts +64 -0
  24. package/lib/services/index.d.ts +64 -0
  25. package/lib/services/index.js +159 -0
  26. package/lib/services/index.mjs +131 -0
  27. package/package.json +39 -26
  28. package/lib/src/cache/index.d.ts +0 -5
  29. package/lib/src/cache/index.d.ts.map +0 -1
  30. package/lib/src/cache/index.js +0 -4
  31. package/lib/src/cache/interfaces/ttlCache.interface.d.ts +0 -48
  32. package/lib/src/cache/interfaces/ttlCache.interface.d.ts.map +0 -1
  33. package/lib/src/cache/interfaces/ttlCache.interface.js +0 -1
  34. package/lib/src/cache/redisTtlCache.d.ts.map +0 -1
  35. package/lib/src/cache/redisTtlCache.js +0 -98
  36. package/lib/src/cache/types/ttlCacheRecord.types.d.ts +0 -14
  37. package/lib/src/cache/types/ttlCacheRecord.types.d.ts.map +0 -1
  38. package/lib/src/cache/types/ttlCacheRecord.types.js +0 -1
  39. package/lib/src/cache/utils/cacheKey.d.ts +0 -2
  40. package/lib/src/cache/utils/cacheKey.d.ts.map +0 -1
  41. package/lib/src/cache/utils/cacheKey.js +0 -3
  42. package/lib/src/controllers/index.d.ts +0 -2
  43. package/lib/src/controllers/index.d.ts.map +0 -1
  44. package/lib/src/controllers/index.js +0 -1
  45. package/lib/src/controllers/interfaces/controller.interface.d.ts +0 -4
  46. package/lib/src/controllers/interfaces/controller.interface.d.ts.map +0 -1
  47. package/lib/src/controllers/interfaces/controller.interface.js +0 -1
  48. package/lib/src/database/index.d.ts +0 -3
  49. package/lib/src/database/index.d.ts.map +0 -1
  50. package/lib/src/database/index.js +0 -2
  51. package/lib/src/database/mikro/models/entities/base.entity.d.ts.map +0 -1
  52. package/lib/src/database/mikro/models/entities/base.entity.js +0 -42
  53. package/lib/src/database/mikro/models/entities/mongo.base.entity.d.ts.map +0 -1
  54. package/lib/src/database/mikro/models/entities/mongo.base.entity.js +0 -51
  55. package/lib/src/dtoMapper/index.d.ts +0 -3
  56. package/lib/src/dtoMapper/index.d.ts.map +0 -1
  57. package/lib/src/dtoMapper/index.js +0 -2
  58. package/lib/src/dtoMapper/interfaces/dtoMapper.interface.d.ts +0 -18
  59. package/lib/src/dtoMapper/interfaces/dtoMapper.interface.d.ts.map +0 -1
  60. package/lib/src/dtoMapper/interfaces/dtoMapper.interface.js +0 -1
  61. package/lib/src/dtoMapper/models/baseDtoMapper.model.d.ts +0 -72
  62. package/lib/src/dtoMapper/models/baseDtoMapper.model.d.ts.map +0 -1
  63. package/lib/src/dtoMapper/models/baseDtoMapper.model.js +0 -76
  64. package/lib/src/dtoMapper/models/requestDtoMapper.model.d.ts +0 -68
  65. package/lib/src/dtoMapper/models/requestDtoMapper.model.d.ts.map +0 -1
  66. package/lib/src/dtoMapper/models/requestDtoMapper.model.js +0 -71
  67. package/lib/src/dtoMapper/models/responseDtoMapper.model.d.ts +0 -67
  68. package/lib/src/dtoMapper/models/responseDtoMapper.model.d.ts.map +0 -1
  69. package/lib/src/dtoMapper/models/responseDtoMapper.model.js +0 -68
  70. package/lib/src/dtoMapper/types/dtoMapper.types.d.ts +0 -9
  71. package/lib/src/dtoMapper/types/dtoMapper.types.d.ts.map +0 -1
  72. package/lib/src/dtoMapper/types/dtoMapper.types.js +0 -1
  73. package/lib/src/http/application/expressLikeApplication.d.ts +0 -21
  74. package/lib/src/http/application/expressLikeApplication.d.ts.map +0 -1
  75. package/lib/src/http/application/expressLikeApplication.js +0 -21
  76. package/lib/src/http/guards/isConstrainedForklaunchRouter.d.ts +0 -4
  77. package/lib/src/http/guards/isConstrainedForklaunchRouter.d.ts.map +0 -1
  78. package/lib/src/http/guards/isConstrainedForklaunchRouter.js +0 -5
  79. package/lib/src/http/guards/isExpressLikeSchemaHandler.d.ts +0 -5
  80. package/lib/src/http/guards/isExpressLikeSchemaHandler.d.ts.map +0 -1
  81. package/lib/src/http/guards/isExpressLikeSchemaHandler.js +0 -6
  82. package/lib/src/http/guards/isForklaunchExpressLikeRouter.d.ts +0 -5
  83. package/lib/src/http/guards/isForklaunchExpressLikeRouter.d.ts.map +0 -1
  84. package/lib/src/http/guards/isForklaunchExpressLikeRouter.js +0 -6
  85. package/lib/src/http/guards/isForklaunchRouter.d.ts +0 -4
  86. package/lib/src/http/guards/isForklaunchRouter.d.ts.map +0 -1
  87. package/lib/src/http/guards/isForklaunchRouter.js +0 -7
  88. package/lib/src/http/guards/isHttpContractDetails.d.ts +0 -7
  89. package/lib/src/http/guards/isHttpContractDetails.d.ts.map +0 -1
  90. package/lib/src/http/guards/isHttpContractDetails.js +0 -9
  91. package/lib/src/http/guards/isPathParamContractDetails.d.ts +0 -4
  92. package/lib/src/http/guards/isPathParamContractDetails.d.ts.map +0 -1
  93. package/lib/src/http/guards/isPathParamContractDetails.js +0 -10
  94. package/lib/src/http/guards/isResponseShape.d.ts +0 -3
  95. package/lib/src/http/guards/isResponseShape.d.ts.map +0 -1
  96. package/lib/src/http/guards/isResponseShape.js +0 -7
  97. package/lib/src/http/guards/isTypedHandler.d.ts +0 -5
  98. package/lib/src/http/guards/isTypedHandler.d.ts.map +0 -1
  99. package/lib/src/http/guards/isTypedHandler.js +0 -6
  100. package/lib/src/http/handlers/delete.d.ts +0 -9
  101. package/lib/src/http/handlers/delete.d.ts.map +0 -1
  102. package/lib/src/http/handlers/delete.js +0 -4
  103. package/lib/src/http/handlers/get.d.ts +0 -9
  104. package/lib/src/http/handlers/get.d.ts.map +0 -1
  105. package/lib/src/http/handlers/get.js +0 -4
  106. package/lib/src/http/handlers/head.d.ts +0 -9
  107. package/lib/src/http/handlers/head.d.ts.map +0 -1
  108. package/lib/src/http/handlers/head.js +0 -4
  109. package/lib/src/http/handlers/middleware.d.ts +0 -9
  110. package/lib/src/http/handlers/middleware.d.ts.map +0 -1
  111. package/lib/src/http/handlers/middleware.js +0 -4
  112. package/lib/src/http/handlers/options.d.ts +0 -9
  113. package/lib/src/http/handlers/options.d.ts.map +0 -1
  114. package/lib/src/http/handlers/options.js +0 -4
  115. package/lib/src/http/handlers/patch.d.ts +0 -9
  116. package/lib/src/http/handlers/patch.d.ts.map +0 -1
  117. package/lib/src/http/handlers/patch.js +0 -4
  118. package/lib/src/http/handlers/post.d.ts +0 -9
  119. package/lib/src/http/handlers/post.d.ts.map +0 -1
  120. package/lib/src/http/handlers/post.js +0 -4
  121. package/lib/src/http/handlers/put.d.ts +0 -9
  122. package/lib/src/http/handlers/put.d.ts.map +0 -1
  123. package/lib/src/http/handlers/put.js +0 -4
  124. package/lib/src/http/handlers/trace.d.ts +0 -9
  125. package/lib/src/http/handlers/trace.d.ts.map +0 -1
  126. package/lib/src/http/handlers/trace.js +0 -4
  127. package/lib/src/http/handlers/typedAuthHandler.d.ts +0 -5
  128. package/lib/src/http/handlers/typedAuthHandler.d.ts.map +0 -1
  129. package/lib/src/http/handlers/typedAuthHandler.js +0 -3
  130. package/lib/src/http/handlers/typedHandler.d.ts +0 -21
  131. package/lib/src/http/handlers/typedHandler.d.ts.map +0 -1
  132. package/lib/src/http/handlers/typedHandler.js +0 -30
  133. package/lib/src/http/index.d.ts +0 -23
  134. package/lib/src/http/index.d.ts.map +0 -1
  135. package/lib/src/http/index.js +0 -22
  136. package/lib/src/http/interfaces/expressLikeRouter.interface.d.ts +0 -24
  137. package/lib/src/http/interfaces/expressLikeRouter.interface.d.ts.map +0 -1
  138. package/lib/src/http/interfaces/expressLikeRouter.interface.js +0 -1
  139. package/lib/src/http/middleware/request/auth.middleware.d.ts +0 -16
  140. package/lib/src/http/middleware/request/auth.middleware.d.ts.map +0 -1
  141. package/lib/src/http/middleware/request/auth.middleware.js +0 -143
  142. package/lib/src/http/middleware/request/cors.middleware.d.ts +0 -13
  143. package/lib/src/http/middleware/request/cors.middleware.d.ts.map +0 -1
  144. package/lib/src/http/middleware/request/cors.middleware.js +0 -15
  145. package/lib/src/http/middleware/request/createContext.middleware.d.ts +0 -15
  146. package/lib/src/http/middleware/request/createContext.middleware.d.ts.map +0 -1
  147. package/lib/src/http/middleware/request/createContext.middleware.js +0 -26
  148. package/lib/src/http/middleware/request/enrichDetails.middleware.d.ts +0 -15
  149. package/lib/src/http/middleware/request/enrichDetails.middleware.d.ts.map +0 -1
  150. package/lib/src/http/middleware/request/enrichDetails.middleware.js +0 -19
  151. package/lib/src/http/middleware/request/parse.middleware.d.ts +0 -17
  152. package/lib/src/http/middleware/request/parse.middleware.d.ts.map +0 -1
  153. package/lib/src/http/middleware/request/parse.middleware.js +0 -43
  154. package/lib/src/http/middleware/response/parse.middleware.d.ts +0 -31
  155. package/lib/src/http/middleware/response/parse.middleware.d.ts.map +0 -1
  156. package/lib/src/http/middleware/response/parse.middleware.js +0 -52
  157. package/lib/src/http/openApiV3Generator/openApiV3Generator.d.ts +0 -14
  158. package/lib/src/http/openApiV3Generator/openApiV3Generator.d.ts.map +0 -1
  159. package/lib/src/http/openApiV3Generator/openApiV3Generator.js +0 -169
  160. package/lib/src/http/router/expressLikeRouter.d.ts +0 -138
  161. package/lib/src/http/router/expressLikeRouter.d.ts.map +0 -1
  162. package/lib/src/http/router/expressLikeRouter.js +0 -483
  163. package/lib/src/http/types/apiDefinition.types.d.ts +0 -260
  164. package/lib/src/http/types/apiDefinition.types.d.ts.map +0 -1
  165. package/lib/src/http/types/apiDefinition.types.js +0 -1
  166. package/lib/src/http/types/contractDetails.types.d.ts +0 -211
  167. package/lib/src/http/types/contractDetails.types.d.ts.map +0 -1
  168. package/lib/src/http/types/contractDetails.types.js +0 -1
  169. package/lib/src/http/types/expressLikeRouter.types.d.ts +0 -51
  170. package/lib/src/http/types/expressLikeRouter.types.d.ts.map +0 -1
  171. package/lib/src/http/types/expressLikeRouter.types.js +0 -1
  172. package/lib/src/http/types/router.types.d.ts +0 -32
  173. package/lib/src/http/types/router.types.d.ts.map +0 -1
  174. package/lib/src/http/types/router.types.js +0 -1
  175. package/lib/src/http/types/typedHandler.types.d.ts +0 -10
  176. package/lib/src/http/types/typedHandler.types.d.ts.map +0 -1
  177. package/lib/src/http/types/typedHandler.types.js +0 -1
  178. package/lib/src/http/utils/enrichExpressLikeSend.d.ts +0 -32
  179. package/lib/src/http/utils/enrichExpressLikeSend.d.ts.map +0 -1
  180. package/lib/src/http/utils/enrichExpressLikeSend.js +0 -50
  181. package/lib/src/http/utils/httpStatusCodes.d.ts +0 -75
  182. package/lib/src/http/utils/httpStatusCodes.d.ts.map +0 -1
  183. package/lib/src/http/utils/httpStatusCodes.js +0 -1039
  184. package/lib/src/services/configInjector.d.ts +0 -21
  185. package/lib/src/services/configInjector.d.ts.map +0 -1
  186. package/lib/src/services/configInjector.js +0 -90
  187. package/lib/src/services/index.d.ts +0 -5
  188. package/lib/src/services/index.d.ts.map +0 -1
  189. package/lib/src/services/index.js +0 -4
  190. package/lib/src/services/interfaces/baseService.d.ts +0 -15
  191. package/lib/src/services/interfaces/baseService.d.ts.map +0 -1
  192. package/lib/src/services/interfaces/baseService.js +0 -1
  193. package/lib/src/services/types/configInjector.types.d.ts +0 -25
  194. package/lib/src/services/types/configInjector.types.d.ts.map +0 -1
  195. package/lib/src/services/types/configInjector.types.js +0 -6
  196. package/lib/src/services/types/entityManager.types.d.ts +0 -4
  197. package/lib/src/services/types/entityManager.types.d.ts.map +0 -1
  198. package/lib/src/services/types/entityManager.types.js +0 -1
  199. package/lib/tests/configInjector.test.d.ts +0 -2
  200. package/lib/tests/configInjector.test.d.ts.map +0 -1
  201. package/lib/tests/configInjector.test.js +0 -105
  202. package/lib/tests/dtoMapper.test.d.ts +0 -2
  203. package/lib/tests/dtoMapper.test.d.ts.map +0 -1
  204. package/lib/tests/dtoMapper.test.js +0 -170
  205. package/lib/tests/expressLikeRouterInstantiation.test.d.ts +0 -2
  206. package/lib/tests/expressLikeRouterInstantiation.test.d.ts.map +0 -1
  207. package/lib/tests/expressLikeRouterInstantiation.test.js +0 -118
  208. package/lib/tests/http.middleware.test.d.ts +0 -2
  209. package/lib/tests/http.middleware.test.d.ts.map +0 -1
  210. package/lib/tests/http.middleware.test.js +0 -102
  211. package/lib/tests/openApiV3Generator.test.d.ts +0 -2
  212. package/lib/tests/openApiV3Generator.test.d.ts.map +0 -1
  213. package/lib/tests/openApiV3Generator.test.js +0 -66
  214. package/lib/tests/redisTtlCache.test.d.ts +0 -2
  215. package/lib/tests/redisTtlCache.test.d.ts.map +0 -1
  216. package/lib/tests/redisTtlCache.test.js +0 -49
  217. package/lib/tests/typedHandler.test.d.ts +0 -2
  218. package/lib/tests/typedHandler.test.d.ts.map +0 -1
  219. package/lib/tests/typedHandler.test.js +0 -3
  220. package/lib/vitest.config.d.ts +0 -3
  221. package/lib/vitest.config.d.ts.map +0 -1
  222. package/lib/vitest.config.js +0 -7
@@ -0,0 +1,230 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/dtoMapper/index.ts
21
+ var dtoMapper_exports = {};
22
+ __export(dtoMapper_exports, {
23
+ RequestDtoMapper: () => RequestDtoMapper,
24
+ ResponseDtoMapper: () => ResponseDtoMapper
25
+ });
26
+ module.exports = __toCommonJS(dtoMapper_exports);
27
+
28
+ // src/dtoMapper/models/baseDtoMapper.model.ts
29
+ function construct(self, schemaValidator) {
30
+ return new self(schemaValidator || {});
31
+ }
32
+ var BaseDtoMapper = class {
33
+ /**
34
+ * The schema validator exact type.
35
+ * @type {SV}
36
+ * @protected
37
+ */
38
+ _SV;
39
+ /**
40
+ * The schema validator as a general type.
41
+ * @type {SchemaValidator}
42
+ * @protected
43
+ */
44
+ schemaValidator;
45
+ /**
46
+ * The Data Transfer Object (DTO).
47
+ * @type {Schema<this['schema'], SV>}
48
+ */
49
+ _dto = {};
50
+ /**
51
+ * Creates an instance of BaseDtoMapper.
52
+ *
53
+ * @param {SV} schemaValidator - The schema provider.
54
+ */
55
+ constructor(schemaValidator) {
56
+ this.schemaValidator = schemaValidator;
57
+ }
58
+ /**
59
+ * Validates and sets the Data Transfer Object (DTO).
60
+ *
61
+ * @param {this['_dto']} dto - The Data Transfer Object (DTO).
62
+ * @throws {Error} - Throws an error if the DTO is invalid.
63
+ */
64
+ set dto(_dto) {
65
+ const parsedSchema = this.schemaValidator.parse(
66
+ this.schemaValidator.schemify(this.schema),
67
+ _dto
68
+ );
69
+ if (!parsedSchema.ok) {
70
+ throw new Error(`Invalid DTO: ${parsedSchema.error}`);
71
+ }
72
+ this._dto = _dto;
73
+ }
74
+ /**
75
+ * Validates and gets the Data Transfer Object (DTO).
76
+ *
77
+ * @returns {this['_dto']} - The Data Transfer Object (DTO).
78
+ */
79
+ get dto() {
80
+ return this._dto;
81
+ }
82
+ /**
83
+ * Gets the schema of a T.
84
+ *
85
+ * @template T - A type that extends BaseDtoMapper.
86
+ * @template SV - A type that extends AnySchemaValidator.
87
+ * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
88
+ * @returns {T['schema']} - The schema of the T.
89
+ */
90
+ static schema() {
91
+ return construct(this).schema;
92
+ }
93
+ };
94
+
95
+ // src/dtoMapper/models/requestDtoMapper.model.ts
96
+ var RequestDtoMapper = class extends BaseDtoMapper {
97
+ /**
98
+ * The entity type.
99
+ * @type {Entity}
100
+ * @protected
101
+ */
102
+ _Entity;
103
+ /**
104
+ * Populates the DTO with data from a JSON object.
105
+ *
106
+ * @param {this['_dto']} json - The JSON object.
107
+ * @returns {this} - The instance of the RequestDtoMapper.
108
+ */
109
+ fromDto(json) {
110
+ const parsedSchema = this.schemaValidator.parse(
111
+ this.schemaValidator.schemify(this.schema),
112
+ json
113
+ );
114
+ if (!parsedSchema.ok) {
115
+ throw new Error(`Invalid DTO: ${parsedSchema.error}`);
116
+ }
117
+ this.dto = json;
118
+ return this;
119
+ }
120
+ /**
121
+ * Deserializes a JSON object to an entity.
122
+ *
123
+ * @param {this['_dto']} json - The JSON object.
124
+ * @param {...unknown[]} additionalArgs - Additional arguments.
125
+ * @returns {Entity} - The entity.
126
+ */
127
+ deserializeDtoToEntity(json, ...additionalArgs) {
128
+ return this.fromDto(json).toEntity(...additionalArgs);
129
+ }
130
+ /**
131
+ * Creates an instance of a RequestDtoMapper from a JSON object.
132
+ *
133
+ * @template T - A type that extends RequestDtoMapper.
134
+ * @template SV - A type that extends AnySchemaValidator.
135
+ * @template JsonType - The type of the JSON object.
136
+ * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
137
+ * @param {SV} schemaValidator - The schema provider.
138
+ * @param {JsonType} json - The JSON object.
139
+ * @returns {T} - An instance of the T.
140
+ */
141
+ static fromDto(schemaValidator, json) {
142
+ return construct(this, schemaValidator).fromDto(json);
143
+ }
144
+ /**
145
+ * Deserializes a JSON object to an entity.
146
+ *
147
+ * @template T - A type that extends RequestDtoMapper.
148
+ * @template SV - A type that extends AnySchemaValidator.
149
+ * @template JsonType - The type of the JSON object.
150
+ * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
151
+ * @param {SV} schemaValidator - The schema provider.
152
+ * @param {JsonType} json - The JSON object.
153
+ * @param {...unknown[]} additionalArgs - Additional arguments.
154
+ * @returns {T['_Entity']} - The entity.
155
+ */
156
+ static deserializeDtoToEntity(schemaValidator, json, ...additionalArgs) {
157
+ return construct(this, schemaValidator).fromDto(json).toEntity(...additionalArgs);
158
+ }
159
+ };
160
+
161
+ // src/dtoMapper/models/responseDtoMapper.model.ts
162
+ var ResponseDtoMapper = class extends BaseDtoMapper {
163
+ /**
164
+ * The entity type.
165
+ * @type {Entity}
166
+ * @protected
167
+ */
168
+ _Entity;
169
+ /**
170
+ * Converts the underlying DTO to a JSON object.
171
+ *
172
+ * @returns {this['_dto']} - The JSON object.
173
+ * @throws {Error} - Throws an error if the DTO is invalid.
174
+ */
175
+ toDto() {
176
+ const parsedSchema = this.schemaValidator.parse(
177
+ this.schemaValidator.schemify(this.schema),
178
+ this.dto
179
+ );
180
+ if (!parsedSchema.ok) {
181
+ throw new Error(`Invalid DTO: ${parsedSchema.error}`);
182
+ }
183
+ return this.dto;
184
+ }
185
+ /**
186
+ * Serializes an entity to a JSON object.
187
+ *
188
+ * @param {Entity} entity - The entity to serialize.
189
+ * @returns {this['_dto']} - The JSON object.
190
+ * @throws {Error} - Throws an error if the DTO is invalid.
191
+ */
192
+ serializeEntityToDto(...[entity, ...additionalArgs]) {
193
+ return this.fromEntity(entity, ...additionalArgs).toDto();
194
+ }
195
+ /**
196
+ * Populates entity mapper with DTO from an entity.
197
+ *
198
+ * @template T - A type that extends ResponseDtoMapper.
199
+ * @template SV - A type that extends AnySchemaValidator.
200
+ * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
201
+ * @param {SV} schemaValidator - The schema provider.
202
+ * @param {T['_Entity']} entity - The entity to convert.
203
+ * @returns {T} - An instance of the T.
204
+ */
205
+ static fromEntity(schemaValidator, ...[entity, ...additionalArgs]) {
206
+ return construct(this, schemaValidator).fromEntity(
207
+ entity,
208
+ ...additionalArgs
209
+ );
210
+ }
211
+ /**
212
+ * Serializes an entity to a JSON object.
213
+ *
214
+ * @template T - A type that extends ResponseDtoMapper.
215
+ * @template SV - A type that extends AnySchemaValidator.
216
+ * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
217
+ * @param {SV} schemaValidator - The schema provider.
218
+ * @param {T['_Entity']} entity - The entity to serialize.
219
+ * @returns {T['_dto']} - The JSON object.
220
+ * @throws {Error} - Throws an error if the DTO is invalid.
221
+ */
222
+ static serializeEntityToDto(schemaValidator, ...[entity, ...additionalArgs]) {
223
+ return construct(this, schemaValidator).fromEntity(entity, ...additionalArgs).toDto();
224
+ }
225
+ };
226
+ // Annotate the CommonJS export names for ESM import in node:
227
+ 0 && (module.exports = {
228
+ RequestDtoMapper,
229
+ ResponseDtoMapper
230
+ });
@@ -0,0 +1,202 @@
1
+ // src/dtoMapper/models/baseDtoMapper.model.ts
2
+ function construct(self, schemaValidator) {
3
+ return new self(schemaValidator || {});
4
+ }
5
+ var BaseDtoMapper = class {
6
+ /**
7
+ * The schema validator exact type.
8
+ * @type {SV}
9
+ * @protected
10
+ */
11
+ _SV;
12
+ /**
13
+ * The schema validator as a general type.
14
+ * @type {SchemaValidator}
15
+ * @protected
16
+ */
17
+ schemaValidator;
18
+ /**
19
+ * The Data Transfer Object (DTO).
20
+ * @type {Schema<this['schema'], SV>}
21
+ */
22
+ _dto = {};
23
+ /**
24
+ * Creates an instance of BaseDtoMapper.
25
+ *
26
+ * @param {SV} schemaValidator - The schema provider.
27
+ */
28
+ constructor(schemaValidator) {
29
+ this.schemaValidator = schemaValidator;
30
+ }
31
+ /**
32
+ * Validates and sets the Data Transfer Object (DTO).
33
+ *
34
+ * @param {this['_dto']} dto - The Data Transfer Object (DTO).
35
+ * @throws {Error} - Throws an error if the DTO is invalid.
36
+ */
37
+ set dto(_dto) {
38
+ const parsedSchema = this.schemaValidator.parse(
39
+ this.schemaValidator.schemify(this.schema),
40
+ _dto
41
+ );
42
+ if (!parsedSchema.ok) {
43
+ throw new Error(`Invalid DTO: ${parsedSchema.error}`);
44
+ }
45
+ this._dto = _dto;
46
+ }
47
+ /**
48
+ * Validates and gets the Data Transfer Object (DTO).
49
+ *
50
+ * @returns {this['_dto']} - The Data Transfer Object (DTO).
51
+ */
52
+ get dto() {
53
+ return this._dto;
54
+ }
55
+ /**
56
+ * Gets the schema of a T.
57
+ *
58
+ * @template T - A type that extends BaseDtoMapper.
59
+ * @template SV - A type that extends AnySchemaValidator.
60
+ * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
61
+ * @returns {T['schema']} - The schema of the T.
62
+ */
63
+ static schema() {
64
+ return construct(this).schema;
65
+ }
66
+ };
67
+
68
+ // src/dtoMapper/models/requestDtoMapper.model.ts
69
+ var RequestDtoMapper = class extends BaseDtoMapper {
70
+ /**
71
+ * The entity type.
72
+ * @type {Entity}
73
+ * @protected
74
+ */
75
+ _Entity;
76
+ /**
77
+ * Populates the DTO with data from a JSON object.
78
+ *
79
+ * @param {this['_dto']} json - The JSON object.
80
+ * @returns {this} - The instance of the RequestDtoMapper.
81
+ */
82
+ fromDto(json) {
83
+ const parsedSchema = this.schemaValidator.parse(
84
+ this.schemaValidator.schemify(this.schema),
85
+ json
86
+ );
87
+ if (!parsedSchema.ok) {
88
+ throw new Error(`Invalid DTO: ${parsedSchema.error}`);
89
+ }
90
+ this.dto = json;
91
+ return this;
92
+ }
93
+ /**
94
+ * Deserializes a JSON object to an entity.
95
+ *
96
+ * @param {this['_dto']} json - The JSON object.
97
+ * @param {...unknown[]} additionalArgs - Additional arguments.
98
+ * @returns {Entity} - The entity.
99
+ */
100
+ deserializeDtoToEntity(json, ...additionalArgs) {
101
+ return this.fromDto(json).toEntity(...additionalArgs);
102
+ }
103
+ /**
104
+ * Creates an instance of a RequestDtoMapper from a JSON object.
105
+ *
106
+ * @template T - A type that extends RequestDtoMapper.
107
+ * @template SV - A type that extends AnySchemaValidator.
108
+ * @template JsonType - The type of the JSON object.
109
+ * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
110
+ * @param {SV} schemaValidator - The schema provider.
111
+ * @param {JsonType} json - The JSON object.
112
+ * @returns {T} - An instance of the T.
113
+ */
114
+ static fromDto(schemaValidator, json) {
115
+ return construct(this, schemaValidator).fromDto(json);
116
+ }
117
+ /**
118
+ * Deserializes a JSON object to an entity.
119
+ *
120
+ * @template T - A type that extends RequestDtoMapper.
121
+ * @template SV - A type that extends AnySchemaValidator.
122
+ * @template JsonType - The type of the JSON object.
123
+ * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
124
+ * @param {SV} schemaValidator - The schema provider.
125
+ * @param {JsonType} json - The JSON object.
126
+ * @param {...unknown[]} additionalArgs - Additional arguments.
127
+ * @returns {T['_Entity']} - The entity.
128
+ */
129
+ static deserializeDtoToEntity(schemaValidator, json, ...additionalArgs) {
130
+ return construct(this, schemaValidator).fromDto(json).toEntity(...additionalArgs);
131
+ }
132
+ };
133
+
134
+ // src/dtoMapper/models/responseDtoMapper.model.ts
135
+ var ResponseDtoMapper = class extends BaseDtoMapper {
136
+ /**
137
+ * The entity type.
138
+ * @type {Entity}
139
+ * @protected
140
+ */
141
+ _Entity;
142
+ /**
143
+ * Converts the underlying DTO to a JSON object.
144
+ *
145
+ * @returns {this['_dto']} - The JSON object.
146
+ * @throws {Error} - Throws an error if the DTO is invalid.
147
+ */
148
+ toDto() {
149
+ const parsedSchema = this.schemaValidator.parse(
150
+ this.schemaValidator.schemify(this.schema),
151
+ this.dto
152
+ );
153
+ if (!parsedSchema.ok) {
154
+ throw new Error(`Invalid DTO: ${parsedSchema.error}`);
155
+ }
156
+ return this.dto;
157
+ }
158
+ /**
159
+ * Serializes an entity to a JSON object.
160
+ *
161
+ * @param {Entity} entity - The entity to serialize.
162
+ * @returns {this['_dto']} - The JSON object.
163
+ * @throws {Error} - Throws an error if the DTO is invalid.
164
+ */
165
+ serializeEntityToDto(...[entity, ...additionalArgs]) {
166
+ return this.fromEntity(entity, ...additionalArgs).toDto();
167
+ }
168
+ /**
169
+ * Populates entity mapper with DTO from an entity.
170
+ *
171
+ * @template T - A type that extends ResponseDtoMapper.
172
+ * @template SV - A type that extends AnySchemaValidator.
173
+ * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
174
+ * @param {SV} schemaValidator - The schema provider.
175
+ * @param {T['_Entity']} entity - The entity to convert.
176
+ * @returns {T} - An instance of the T.
177
+ */
178
+ static fromEntity(schemaValidator, ...[entity, ...additionalArgs]) {
179
+ return construct(this, schemaValidator).fromEntity(
180
+ entity,
181
+ ...additionalArgs
182
+ );
183
+ }
184
+ /**
185
+ * Serializes an entity to a JSON object.
186
+ *
187
+ * @template T - A type that extends ResponseDtoMapper.
188
+ * @template SV - A type that extends AnySchemaValidator.
189
+ * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
190
+ * @param {SV} schemaValidator - The schema provider.
191
+ * @param {T['_Entity']} entity - The entity to serialize.
192
+ * @returns {T['_dto']} - The JSON object.
193
+ * @throws {Error} - Throws an error if the DTO is invalid.
194
+ */
195
+ static serializeEntityToDto(schemaValidator, ...[entity, ...additionalArgs]) {
196
+ return construct(this, schemaValidator).fromEntity(entity, ...additionalArgs).toDto();
197
+ }
198
+ };
199
+ export {
200
+ RequestDtoMapper,
201
+ ResponseDtoMapper
202
+ };