@solid-nestjs/common 0.2.6 → 0.2.9

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 (253) hide show
  1. package/dist/adapters/index.d.ts +7 -0
  2. package/dist/adapters/index.d.ts.map +1 -0
  3. package/dist/adapters/index.js +23 -0
  4. package/dist/adapters/index.js.map +1 -0
  5. package/dist/adapters/validation.adapter.d.ts +20 -0
  6. package/dist/adapters/validation.adapter.d.ts.map +1 -0
  7. package/dist/adapters/validation.adapter.js +309 -0
  8. package/dist/adapters/validation.adapter.js.map +1 -0
  9. package/dist/decorator-registry/decorator-registry.d.ts +54 -0
  10. package/dist/decorator-registry/decorator-registry.d.ts.map +1 -0
  11. package/dist/decorator-registry/decorator-registry.js +161 -0
  12. package/dist/decorator-registry/decorator-registry.js.map +1 -0
  13. package/dist/decorator-registry/index.d.ts +2 -0
  14. package/dist/decorator-registry/index.d.ts.map +1 -0
  15. package/dist/decorator-registry/index.js +18 -0
  16. package/dist/decorator-registry/index.js.map +1 -0
  17. package/dist/decorators/index.d.ts +6 -0
  18. package/dist/decorators/index.d.ts.map +1 -1
  19. package/dist/decorators/index.js +6 -0
  20. package/dist/decorators/index.js.map +1 -1
  21. package/dist/decorators/solid-entity.decorator.d.ts +6 -0
  22. package/dist/decorators/solid-entity.decorator.d.ts.map +1 -0
  23. package/dist/decorators/solid-entity.decorator.js +23 -0
  24. package/dist/decorators/solid-entity.decorator.js.map +1 -0
  25. package/dist/decorators/solid-field.decorator.d.ts +7 -0
  26. package/dist/decorators/solid-field.decorator.d.ts.map +1 -0
  27. package/dist/decorators/solid-field.decorator.js +51 -0
  28. package/dist/decorators/solid-field.decorator.js.map +1 -0
  29. package/dist/decorators/solid-id.decorator.d.ts +9 -0
  30. package/dist/decorators/solid-id.decorator.d.ts.map +1 -0
  31. package/dist/decorators/solid-id.decorator.js +27 -0
  32. package/dist/decorators/solid-id.decorator.js.map +1 -0
  33. package/dist/decorators/solid-input.decorator.d.ts +6 -0
  34. package/dist/decorators/solid-input.decorator.d.ts.map +1 -0
  35. package/dist/decorators/solid-input.decorator.js +35 -0
  36. package/dist/decorators/solid-input.decorator.js.map +1 -0
  37. package/dist/decorators/solid-relation.decorator.d.ts +19 -0
  38. package/dist/decorators/solid-relation.decorator.d.ts.map +1 -0
  39. package/dist/decorators/solid-relation.decorator.js +66 -0
  40. package/dist/decorators/solid-relation.decorator.js.map +1 -0
  41. package/dist/decorators/solid-timestamp.decorator.d.ts +13 -0
  42. package/dist/decorators/solid-timestamp.decorator.d.ts.map +1 -0
  43. package/dist/decorators/solid-timestamp.decorator.js +49 -0
  44. package/dist/decorators/solid-timestamp.decorator.js.map +1 -0
  45. package/dist/enums/aggregate-function.enum.d.ts +42 -0
  46. package/dist/enums/aggregate-function.enum.d.ts.map +1 -0
  47. package/dist/enums/aggregate-function.enum.js +46 -0
  48. package/dist/enums/aggregate-function.enum.js.map +1 -0
  49. package/dist/enums/index.d.ts +1 -0
  50. package/dist/enums/index.d.ts.map +1 -1
  51. package/dist/enums/index.js +1 -0
  52. package/dist/enums/index.js.map +1 -1
  53. package/dist/helpers/args-helpers/class-generator.helper.d.ts +143 -0
  54. package/dist/helpers/args-helpers/class-generator.helper.d.ts.map +1 -0
  55. package/dist/helpers/args-helpers/class-generator.helper.js +221 -0
  56. package/dist/helpers/args-helpers/class-generator.helper.js.map +1 -0
  57. package/dist/helpers/args-helpers/create-groupby-request.helper.d.ts +83 -0
  58. package/dist/helpers/args-helpers/create-groupby-request.helper.d.ts.map +1 -0
  59. package/dist/helpers/args-helpers/create-groupby-request.helper.js +119 -0
  60. package/dist/helpers/args-helpers/create-groupby-request.helper.js.map +1 -0
  61. package/dist/helpers/args-helpers/decorator-builder.helper.d.ts +160 -0
  62. package/dist/helpers/args-helpers/decorator-builder.helper.d.ts.map +1 -0
  63. package/dist/helpers/args-helpers/decorator-builder.helper.js +161 -0
  64. package/dist/helpers/args-helpers/decorator-builder.helper.js.map +1 -0
  65. package/dist/helpers/args-helpers/field-config.helper.d.ts +98 -0
  66. package/dist/helpers/args-helpers/field-config.helper.d.ts.map +1 -0
  67. package/dist/helpers/args-helpers/field-config.helper.js +143 -0
  68. package/dist/helpers/args-helpers/field-config.helper.js.map +1 -0
  69. package/dist/helpers/args-helpers/groupby-args-from.helper.d.ts +87 -0
  70. package/dist/helpers/args-helpers/groupby-args-from.helper.d.ts.map +1 -0
  71. package/dist/helpers/args-helpers/groupby-args-from.helper.js +185 -0
  72. package/dist/helpers/args-helpers/groupby-args-from.helper.js.map +1 -0
  73. package/dist/helpers/args-helpers/index.d.ts +15 -0
  74. package/dist/helpers/args-helpers/index.d.ts.map +1 -0
  75. package/dist/helpers/args-helpers/index.js +58 -0
  76. package/dist/helpers/args-helpers/index.js.map +1 -0
  77. package/dist/helpers/args-helpers/type-inference.helper.d.ts +191 -0
  78. package/dist/helpers/args-helpers/type-inference.helper.d.ts.map +1 -0
  79. package/dist/helpers/args-helpers/type-inference.helper.js +330 -0
  80. package/dist/helpers/args-helpers/type-inference.helper.js.map +1 -0
  81. package/dist/helpers/class-generation/dynamic-class.helper.d.ts +101 -0
  82. package/dist/helpers/class-generation/dynamic-class.helper.d.ts.map +1 -0
  83. package/dist/helpers/class-generation/dynamic-class.helper.js +180 -0
  84. package/dist/helpers/class-generation/dynamic-class.helper.js.map +1 -0
  85. package/dist/helpers/class-generation/index.d.ts +9 -0
  86. package/dist/helpers/class-generation/index.d.ts.map +1 -0
  87. package/dist/helpers/class-generation/index.js +18 -0
  88. package/dist/helpers/class-generation/index.js.map +1 -0
  89. package/dist/helpers/decorators/decorator-utils.helper.d.ts +75 -0
  90. package/dist/helpers/decorators/decorator-utils.helper.d.ts.map +1 -0
  91. package/dist/helpers/decorators/decorator-utils.helper.js +92 -0
  92. package/dist/helpers/decorators/decorator-utils.helper.js.map +1 -0
  93. package/dist/helpers/decorators/index.d.ts +9 -0
  94. package/dist/helpers/decorators/index.d.ts.map +1 -0
  95. package/dist/helpers/decorators/index.js +16 -0
  96. package/dist/helpers/decorators/index.js.map +1 -0
  97. package/dist/helpers/dto-generator-base.helper.d.ts +19 -0
  98. package/dist/helpers/dto-generator-base.helper.d.ts.map +1 -0
  99. package/dist/helpers/dto-generator-base.helper.js +72 -0
  100. package/dist/helpers/dto-generator-base.helper.js.map +1 -0
  101. package/dist/helpers/index.d.ts +9 -0
  102. package/dist/helpers/index.d.ts.map +1 -1
  103. package/dist/helpers/index.js +9 -0
  104. package/dist/helpers/index.js.map +1 -1
  105. package/dist/helpers/metadata-extractor.helper.d.ts +26 -0
  106. package/dist/helpers/metadata-extractor.helper.d.ts.map +1 -0
  107. package/dist/helpers/metadata-extractor.helper.js +67 -0
  108. package/dist/helpers/metadata-extractor.helper.js.map +1 -0
  109. package/dist/helpers/package-detector.helper.d.ts +33 -0
  110. package/dist/helpers/package-detector.helper.d.ts.map +1 -0
  111. package/dist/helpers/package-detector.helper.js +82 -0
  112. package/dist/helpers/package-detector.helper.js.map +1 -0
  113. package/dist/helpers/property-filter.helper.d.ts +15 -0
  114. package/dist/helpers/property-filter.helper.d.ts.map +1 -0
  115. package/dist/helpers/property-filter.helper.js +44 -0
  116. package/dist/helpers/property-filter.helper.js.map +1 -0
  117. package/dist/helpers/type-inference.helper.d.ts +76 -0
  118. package/dist/helpers/type-inference.helper.d.ts.map +1 -0
  119. package/dist/helpers/type-inference.helper.js +205 -0
  120. package/dist/helpers/type-inference.helper.js.map +1 -0
  121. package/dist/helpers/validation-inference.helper.d.ts +18 -0
  122. package/dist/helpers/validation-inference.helper.d.ts.map +1 -0
  123. package/dist/helpers/validation-inference.helper.js +100 -0
  124. package/dist/helpers/validation-inference.helper.js.map +1 -0
  125. package/dist/index.d.ts +4 -0
  126. package/dist/index.d.ts.map +1 -1
  127. package/dist/index.js +4 -0
  128. package/dist/index.js.map +1 -1
  129. package/dist/interfaces/adapters/decorator-adapter.interface.d.ts +8 -0
  130. package/dist/interfaces/adapters/decorator-adapter.interface.d.ts.map +1 -0
  131. package/dist/interfaces/adapters/decorator-adapter.interface.js +3 -0
  132. package/dist/interfaces/adapters/decorator-adapter.interface.js.map +1 -0
  133. package/dist/interfaces/decorators/solid-field-options.interface.d.ts +55 -0
  134. package/dist/interfaces/decorators/solid-field-options.interface.d.ts.map +1 -0
  135. package/dist/interfaces/decorators/solid-field-options.interface.js +3 -0
  136. package/dist/interfaces/decorators/solid-field-options.interface.js.map +1 -0
  137. package/dist/interfaces/index.d.ts +5 -0
  138. package/dist/interfaces/index.d.ts.map +1 -1
  139. package/dist/interfaces/index.js +5 -0
  140. package/dist/interfaces/index.js.map +1 -1
  141. package/dist/interfaces/inputs/filters.interfaces.d.ts +36 -0
  142. package/dist/interfaces/inputs/filters.interfaces.d.ts.map +1 -0
  143. package/dist/interfaces/inputs/filters.interfaces.js +3 -0
  144. package/dist/interfaces/inputs/filters.interfaces.js.map +1 -0
  145. package/dist/interfaces/inputs/find-args.interface.d.ts +8 -0
  146. package/dist/interfaces/inputs/find-args.interface.d.ts.map +1 -0
  147. package/dist/interfaces/inputs/find-args.interface.js +3 -0
  148. package/dist/interfaces/inputs/find-args.interface.js.map +1 -0
  149. package/dist/interfaces/inputs/group-by-args.interface.d.ts +33 -0
  150. package/dist/interfaces/inputs/group-by-args.interface.d.ts.map +1 -0
  151. package/dist/interfaces/inputs/group-by-args.interface.js +3 -0
  152. package/dist/interfaces/inputs/group-by-args.interface.js.map +1 -0
  153. package/dist/interfaces/inputs/group-by-request.interface.d.ts +63 -0
  154. package/dist/interfaces/inputs/group-by-request.interface.d.ts.map +1 -0
  155. package/dist/interfaces/inputs/group-by-request.interface.js +3 -0
  156. package/dist/interfaces/inputs/group-by-request.interface.js.map +1 -0
  157. package/dist/interfaces/inputs/index.d.ts +6 -0
  158. package/dist/interfaces/inputs/index.d.ts.map +1 -0
  159. package/dist/interfaces/inputs/index.js +22 -0
  160. package/dist/interfaces/inputs/index.js.map +1 -0
  161. package/dist/interfaces/inputs/pagination-request.interface.d.ts +7 -0
  162. package/dist/interfaces/inputs/pagination-request.interface.d.ts.map +1 -0
  163. package/dist/interfaces/inputs/pagination-request.interface.js +3 -0
  164. package/dist/interfaces/inputs/pagination-request.interface.js.map +1 -0
  165. package/dist/interfaces/metadata/field-metadata.interface.d.ts +29 -0
  166. package/dist/interfaces/metadata/field-metadata.interface.d.ts.map +1 -0
  167. package/dist/interfaces/metadata/field-metadata.interface.js +3 -0
  168. package/dist/interfaces/metadata/field-metadata.interface.js.map +1 -0
  169. package/dist/interfaces/misc/group-by-args.interface.d.ts +33 -0
  170. package/dist/interfaces/misc/group-by-args.interface.d.ts.map +1 -0
  171. package/dist/interfaces/misc/group-by-args.interface.js +3 -0
  172. package/dist/interfaces/misc/group-by-args.interface.js.map +1 -0
  173. package/dist/interfaces/misc/group-by-request.interface.d.ts +63 -0
  174. package/dist/interfaces/misc/group-by-request.interface.d.ts.map +1 -0
  175. package/dist/interfaces/misc/group-by-request.interface.js +3 -0
  176. package/dist/interfaces/misc/group-by-request.interface.js.map +1 -0
  177. package/dist/interfaces/misc/group-by-response.interface.d.ts +59 -0
  178. package/dist/interfaces/misc/group-by-response.interface.d.ts.map +1 -0
  179. package/dist/interfaces/misc/group-by-response.interface.js +3 -0
  180. package/dist/interfaces/misc/group-by-response.interface.js.map +1 -0
  181. package/dist/interfaces/misc/group-by.interface.d.ts +145 -0
  182. package/dist/interfaces/misc/group-by.interface.d.ts.map +1 -0
  183. package/dist/interfaces/misc/group-by.interface.js +3 -0
  184. package/dist/interfaces/misc/group-by.interface.js.map +1 -0
  185. package/dist/interfaces/misc/index.d.ts +0 -4
  186. package/dist/interfaces/misc/index.d.ts.map +1 -1
  187. package/dist/interfaces/misc/index.js +0 -4
  188. package/dist/interfaces/misc/index.js.map +1 -1
  189. package/dist/interfaces/outputs/group-by-response.interface.d.ts +59 -0
  190. package/dist/interfaces/outputs/group-by-response.interface.d.ts.map +1 -0
  191. package/dist/interfaces/outputs/group-by-response.interface.js +3 -0
  192. package/dist/interfaces/outputs/group-by-response.interface.js.map +1 -0
  193. package/dist/interfaces/outputs/index.d.ts +3 -0
  194. package/dist/interfaces/outputs/index.d.ts.map +1 -0
  195. package/dist/interfaces/outputs/index.js +19 -0
  196. package/dist/interfaces/outputs/index.js.map +1 -0
  197. package/dist/interfaces/outputs/pagination-result.interface.d.ts +10 -0
  198. package/dist/interfaces/outputs/pagination-result.interface.d.ts.map +1 -0
  199. package/dist/interfaces/outputs/pagination-result.interface.js +3 -0
  200. package/dist/interfaces/outputs/pagination-result.interface.js.map +1 -0
  201. package/dist/interfaces/services/crud-service.interface.d.ts +2 -1
  202. package/dist/interfaces/services/crud-service.interface.d.ts.map +1 -1
  203. package/dist/interfaces/services/crud-service.interface.js.map +1 -1
  204. package/dist/interfaces/services/data-service.interface.d.ts +3 -1
  205. package/dist/interfaces/services/data-service.interface.d.ts.map +1 -1
  206. package/dist/interfaces/structures/common-services.index.d.ts +1 -0
  207. package/dist/interfaces/structures/common-services.index.d.ts.map +1 -0
  208. package/dist/interfaces/structures/common-services.index.js +2 -0
  209. package/dist/interfaces/structures/common-services.index.js.map +1 -0
  210. package/dist/interfaces/structures/crud-service-structure.interface.d.ts +2 -1
  211. package/dist/interfaces/structures/crud-service-structure.interface.d.ts.map +1 -1
  212. package/dist/interfaces/structures/data-service-structure.interface.d.ts +2 -1
  213. package/dist/interfaces/structures/data-service-structure.interface.d.ts.map +1 -1
  214. package/dist/interfaces/structures/entity-provider-structure.interface.d.ts +2 -1
  215. package/dist/interfaces/structures/entity-provider-structure.interface.d.ts.map +1 -1
  216. package/dist/interfaces/structures/entity-provider-structure.interface.js.map +1 -1
  217. package/dist/interfaces/structures/service-plugins.interface.d.ts +2 -1
  218. package/dist/interfaces/structures/service-plugins.interface.d.ts.map +1 -1
  219. package/dist/metadata/index.d.ts +2 -0
  220. package/dist/metadata/index.d.ts.map +1 -0
  221. package/dist/metadata/index.js +18 -0
  222. package/dist/metadata/index.js.map +1 -0
  223. package/dist/metadata/metadata-storage.d.ts +54 -0
  224. package/dist/metadata/metadata-storage.d.ts.map +1 -0
  225. package/dist/metadata/metadata-storage.js +106 -0
  226. package/dist/metadata/metadata-storage.js.map +1 -0
  227. package/dist/registry/index.d.ts +2 -0
  228. package/dist/registry/index.d.ts.map +1 -0
  229. package/dist/registry/index.js +18 -0
  230. package/dist/registry/index.js.map +1 -0
  231. package/dist/registry/relation-adapter-registry.d.ts +11 -0
  232. package/dist/registry/relation-adapter-registry.d.ts.map +1 -0
  233. package/dist/registry/relation-adapter-registry.js +30 -0
  234. package/dist/registry/relation-adapter-registry.js.map +1 -0
  235. package/dist/types/dto-generation.types.d.ts +46 -0
  236. package/dist/types/dto-generation.types.d.ts.map +1 -0
  237. package/dist/types/dto-generation.types.js +6 -0
  238. package/dist/types/dto-generation.types.js.map +1 -0
  239. package/dist/types/find-args.type.d.ts +9 -7
  240. package/dist/types/find-args.type.d.ts.map +1 -1
  241. package/dist/types/group-by.type.d.ts +41 -0
  242. package/dist/types/group-by.type.d.ts.map +1 -0
  243. package/dist/types/group-by.type.js +3 -0
  244. package/dist/types/group-by.type.js.map +1 -0
  245. package/dist/types/index.d.ts +2 -0
  246. package/dist/types/index.d.ts.map +1 -1
  247. package/dist/types/index.js +2 -0
  248. package/dist/types/index.js.map +1 -1
  249. package/package.json +2 -2
  250. package/dist/utils/object.utils.d.ts +0 -8
  251. package/dist/utils/object.utils.d.ts.map +0 -1
  252. package/dist/utils/object.utils.js +0 -11
  253. package/dist/utils/object.utils.js.map +0 -1
@@ -0,0 +1,330 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FilterTypeRegistry = void 0;
4
+ exports.inferPlainType = inferPlainType;
5
+ exports.inferFilterType = inferFilterType;
6
+ exports.isRelationType = isRelationType;
7
+ exports.setDefaultFilterTypes = setDefaultFilterTypes;
8
+ exports.isSupportedPrimitiveType = isSupportedPrimitiveType;
9
+ exports.getReflectedPropertyType = getReflectedPropertyType;
10
+ exports.isEnum = isEnum;
11
+ exports.getEnumInfo = getEnumInfo;
12
+ exports.shouldTreatAsEnum = shouldTreatAsEnum;
13
+ require("reflect-metadata");
14
+ /**
15
+ * Infers the appropriate plain type (String, Number, Date) for an entity property.
16
+ * Used when isPlain: true is specified in the field configuration.
17
+ *
18
+ * @template T - The entity type
19
+ * @param entity - The entity class constructor
20
+ * @param propertyName - The name of the property to infer type for
21
+ * @returns The plain type class constructor (String, Number, Date, Boolean)
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * class Product {
26
+ * name: string; // Will infer String
27
+ * price: number; // Will infer Number
28
+ * createdAt: Date; // Will infer Date
29
+ * isActive: boolean; // Will infer Boolean
30
+ * }
31
+ *
32
+ * const nameType = inferPlainType(Product, 'name'); // String
33
+ * const priceType = inferPlainType(Product, 'price'); // Number
34
+ * ```
35
+ */
36
+ function inferPlainType(entity, propertyName) {
37
+ // Use reflection to get property type from TypeScript metadata
38
+ const type = Reflect.getMetadata('design:type', entity.prototype, propertyName);
39
+ if (!type) {
40
+ console.warn(`Could not infer type for property ${propertyName} on ${entity.name}. Using String as fallback.`);
41
+ return String;
42
+ }
43
+ // Map native TypeScript types to plain types
44
+ if (type === String) {
45
+ return String;
46
+ }
47
+ if (type === Number) {
48
+ return Number;
49
+ }
50
+ if (type === Date) {
51
+ return Date;
52
+ }
53
+ if (type === Boolean) {
54
+ return Boolean;
55
+ }
56
+ // For enums, treat as String
57
+ if (isEnum(type)) {
58
+ return String;
59
+ }
60
+ // For unknown types, fallback to String
61
+ console.warn(`Unknown type ${type.name} for property ${propertyName}. Using String as fallback.`);
62
+ return String;
63
+ }
64
+ /**
65
+ * Infers the appropriate filter type for an entity property based on its TypeScript type.
66
+ * Uses reflection to determine the property type and maps it to the corresponding filter type.
67
+ *
68
+ * @template T - The entity type
69
+ * @param entity - The entity class constructor
70
+ * @param propertyName - The name of the property to infer type for
71
+ * @param config - Optional field configuration that may override the inferred type
72
+ * @returns The filter type class constructor
73
+ *
74
+ * @example
75
+ * ```typescript
76
+ * class Product {
77
+ * name: string; // Will infer StringFilter
78
+ * price: number; // Will infer NumberFilter
79
+ * createdAt: Date; // Will infer DateFilter
80
+ * isActive: boolean; // Will return Boolean
81
+ * }
82
+ *
83
+ * const nameFilterType = inferFilterType(Product, 'name'); // StringFilter
84
+ * const priceFilterType = inferFilterType(Product, 'price'); // NumberFilter
85
+ * ```
86
+ */
87
+ function inferFilterType(entity, propertyName, config) {
88
+ // If explicit type is provided in config, use it
89
+ if (typeof config === 'function') {
90
+ // Check if it's a relation type and return it directly
91
+ if (isRelationType(config)) {
92
+ return config;
93
+ }
94
+ return config;
95
+ }
96
+ if (typeof config === 'object' && config?.type) {
97
+ // Check if it's a relation type and return it directly
98
+ if (isRelationType(config.type)) {
99
+ return config.type;
100
+ }
101
+ return config.type;
102
+ }
103
+ // If explicitly marked as relation, return the type as-is without inference
104
+ if (typeof config === 'object' && config?.isRelation) {
105
+ return config.type || FilterTypeRegistry.getStringFilter();
106
+ }
107
+ // Check for explicit enum configuration
108
+ if (typeof config === 'object' && config?.enum) {
109
+ // For explicit enum configuration, use StringFilter as default
110
+ return FilterTypeRegistry.getStringFilter();
111
+ }
112
+ // Use reflection to get property type from TypeScript metadata
113
+ const type = Reflect.getMetadata('design:type', entity.prototype, propertyName);
114
+ if (!type) {
115
+ console.warn(`Could not infer type for property ${propertyName} on ${entity.name}. Using StringFilter as fallback.`);
116
+ return FilterTypeRegistry.getStringFilter();
117
+ }
118
+ // Map native TypeScript types to filter types
119
+ if (type === String) {
120
+ return FilterTypeRegistry.getStringFilter();
121
+ }
122
+ if (type === Number) {
123
+ return FilterTypeRegistry.getNumberFilter();
124
+ }
125
+ if (type === Date) {
126
+ return FilterTypeRegistry.getDateFilter();
127
+ }
128
+ if (type === Boolean) {
129
+ return Boolean; // Direct boolean, no filter wrapper needed
130
+ }
131
+ // Check if the type is an enum and treat it as StringFilter
132
+ if (isEnum(type)) {
133
+ return FilterTypeRegistry.getStringFilter();
134
+ }
135
+ // For complex types or unknown types, fallback to StringFilter
136
+ console.warn(`Unknown type ${type.name} for property ${propertyName}. Using StringFilter as fallback.`);
137
+ return FilterTypeRegistry.getStringFilter();
138
+ }
139
+ /**
140
+ * Checks if a given type appears to be a relation type (Where/OrderBy/GroupBy class)
141
+ * by examining the class name patterns commonly used in the framework
142
+ *
143
+ * @param type - The type to check
144
+ * @returns True if it appears to be a relation type
145
+ */
146
+ function isRelationType(type) {
147
+ if (!type || !type.name) {
148
+ return false;
149
+ }
150
+ const className = type.name;
151
+ // Check for common relation type patterns
152
+ return (className.includes('Where') ||
153
+ className.includes('OrderBy') ||
154
+ className.includes('GroupBy') ||
155
+ className.includes('FindArgs') ||
156
+ // Add other patterns as needed
157
+ className.endsWith('Fields'));
158
+ }
159
+ /**
160
+ * Registry for filter types that can be set by each package
161
+ */
162
+ class FilterTypeRegistry {
163
+ /**
164
+ * Registers filter types for the current package context
165
+ *
166
+ * @param types - Object containing the filter type constructors
167
+ */
168
+ static register(types) {
169
+ this.stringFilter = types.StringFilter;
170
+ this.numberFilter = types.NumberFilter;
171
+ this.dateFilter = types.DateFilter;
172
+ }
173
+ /**
174
+ * Gets the registered StringFilter type
175
+ *
176
+ * @returns The StringFilter type constructor
177
+ * @throws Error if not registered
178
+ */
179
+ static getStringFilter() {
180
+ if (!this.stringFilter) {
181
+ throw new Error('StringFilter type not registered. Call FilterTypeRegistry.register() in your package initialization.');
182
+ }
183
+ return this.stringFilter;
184
+ }
185
+ /**
186
+ * Gets the registered NumberFilter type
187
+ *
188
+ * @returns The NumberFilter type constructor
189
+ * @throws Error if not registered
190
+ */
191
+ static getNumberFilter() {
192
+ if (!this.numberFilter) {
193
+ throw new Error('NumberFilter type not registered. Call FilterTypeRegistry.register() in your package initialization.');
194
+ }
195
+ return this.numberFilter;
196
+ }
197
+ /**
198
+ * Gets the registered DateFilter type
199
+ *
200
+ * @returns The DateFilter type constructor
201
+ * @throws Error if not registered
202
+ */
203
+ static getDateFilter() {
204
+ if (!this.dateFilter) {
205
+ throw new Error('DateFilter type not registered. Call FilterTypeRegistry.register() in your package initialization.');
206
+ }
207
+ return this.dateFilter;
208
+ }
209
+ /**
210
+ * Checks if filter types are registered
211
+ *
212
+ * @returns True if all filter types are registered
213
+ */
214
+ static isRegistered() {
215
+ return !!(this.stringFilter && this.numberFilter && this.dateFilter);
216
+ }
217
+ /**
218
+ * Clears all registered filter types (mainly for testing)
219
+ */
220
+ static clear() {
221
+ this.stringFilter = undefined;
222
+ this.numberFilter = undefined;
223
+ this.dateFilter = undefined;
224
+ }
225
+ }
226
+ exports.FilterTypeRegistry = FilterTypeRegistry;
227
+ /**
228
+ * Sets the default filter types for the type inference system.
229
+ * This should be called by each package (rest-api, graphql, rest-graphql)
230
+ * during initialization to provide the appropriate filter types.
231
+ *
232
+ * @param filterTypes - Object containing the filter type constructors
233
+ * @deprecated Use FilterTypeRegistry.register() instead
234
+ */
235
+ function setDefaultFilterTypes(filterTypes) {
236
+ FilterTypeRegistry.register(filterTypes);
237
+ }
238
+ /**
239
+ * Checks if a given type is a primitive type that can be auto-inferred
240
+ *
241
+ * @param type - The type to check
242
+ * @returns True if the type is a supported primitive
243
+ */
244
+ function isSupportedPrimitiveType(type) {
245
+ return type === String || type === Number || type === Date || type === Boolean;
246
+ }
247
+ /**
248
+ * Gets the property type using reflection
249
+ *
250
+ * @param entity - The entity class
251
+ * @param propertyName - The property name
252
+ * @returns The reflected type or undefined if not found
253
+ */
254
+ function getReflectedPropertyType(entity, propertyName) {
255
+ return Reflect.getMetadata('design:type', entity.prototype, propertyName);
256
+ }
257
+ /**
258
+ * Checks if a given type appears to be an enum
259
+ *
260
+ * @param type - The type to check
261
+ * @returns True if the type appears to be an enum
262
+ */
263
+ function isEnum(type) {
264
+ if (!type || typeof type !== 'object') {
265
+ return false;
266
+ }
267
+ const values = Object.values(type);
268
+ const keys = Object.keys(type);
269
+ // Should have at least one key-value pair
270
+ if (keys.length === 0) {
271
+ return false;
272
+ }
273
+ // Enums typically have string or number values
274
+ const hasValidValues = values.every(v => typeof v === 'string' || typeof v === 'number');
275
+ if (!hasValidValues) {
276
+ return false;
277
+ }
278
+ // For numeric enums, TypeScript generates reverse mapping
279
+ // Check if this looks like a TypeScript enum structure
280
+ const numericValues = values.filter(v => typeof v === 'number');
281
+ if (numericValues.length > 0) {
282
+ // Should have reverse mappings for numeric enums
283
+ const hasReverseMappings = numericValues.every(numVal => keys.some(key => type[numVal] === key));
284
+ return hasReverseMappings;
285
+ }
286
+ // For string enums, check that all values are strings and keys match a pattern
287
+ // Also verify this isn't just a plain object by checking key structure
288
+ const stringValues = values.filter(v => typeof v === 'string');
289
+ if (stringValues.length === values.length && stringValues.length > 0) {
290
+ // Additional check: enum keys are typically uppercase or camelCase constants
291
+ // This helps distinguish from regular objects like { key: 'value' }
292
+ return keys.some(key => key === key.toUpperCase() || // CONSTANT_CASE
293
+ /^[A-Z][A-Z_0-9]*$/.test(key) // SCREAMING_SNAKE_CASE
294
+ );
295
+ }
296
+ return false;
297
+ }
298
+ /**
299
+ * Extracts enum information for use in decorators
300
+ *
301
+ * @param enumObject - The enum object
302
+ * @returns Information about the enum
303
+ */
304
+ function getEnumInfo(enumObject) {
305
+ const values = Object.values(enumObject);
306
+ const keys = Object.keys(enumObject);
307
+ return {
308
+ values,
309
+ example: values[0],
310
+ description: `One of: ${values.join(', ')}`
311
+ };
312
+ }
313
+ /**
314
+ * Determines if a field should be treated as an enum field
315
+ *
316
+ * @param entity - The entity class
317
+ * @param propertyName - The property name
318
+ * @param config - Field configuration
319
+ * @returns True if it should be treated as enum
320
+ */
321
+ function shouldTreatAsEnum(entity, propertyName, config) {
322
+ // Explicit enum configuration
323
+ if (typeof config === 'object' && config?.enum) {
324
+ return true;
325
+ }
326
+ // Auto-detection (could be enabled/disabled via settings)
327
+ const type = Reflect.getMetadata('design:type', entity.prototype, propertyName);
328
+ return isEnum(type);
329
+ }
330
+ //# sourceMappingURL=type-inference.helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-inference.helper.js","sourceRoot":"","sources":["../../../src/helpers/args-helpers/type-inference.helper.ts"],"names":[],"mappings":";;;AA0DA,wCAkCC;AAyBD,0CA8DC;AASD,wCAgBC;AA2FD,sDAMC;AAUD,4DAEC;AASD,4DAEC;AAQD,wBA8CC;AAQD,kCAaC;AAUD,8CAaC;AAraD,4BAA0B;AAmC1B;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,SAAgB,cAAc,CAC5B,MAAiB,EACjB,YAAoB;IAEpB,+DAA+D;IAC/D,MAAM,IAAI,GAAG,OAAO,CAAC,WAAW,CAAC,aAAa,EAAE,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;IAEhF,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO,CAAC,IAAI,CAAC,qCAAqC,YAAY,OAAO,MAAM,CAAC,IAAI,6BAA6B,CAAC,CAAC;QAC/G,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,6CAA6C;IAC7C,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;QACpB,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;QACpB,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QAClB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;QACrB,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,6BAA6B;IAC7B,IAAI,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;QACjB,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,wCAAwC;IACxC,OAAO,CAAC,IAAI,CAAC,gBAAgB,IAAI,CAAC,IAAI,iBAAiB,YAAY,6BAA6B,CAAC,CAAC;IAClG,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,SAAgB,eAAe,CAC7B,MAAiB,EACjB,YAAoB,EACpB,MA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C"}
@@ -0,0 +1,101 @@
1
+ import { Type } from '@nestjs/common';
2
+ import 'reflect-metadata';
3
+ /**
4
+ * Options for generating a dynamic class
5
+ */
6
+ export interface ClassGeneratorOptions {
7
+ className: string;
8
+ baseClass?: Type<any>;
9
+ interfaces?: Type<any>[];
10
+ metadata?: Record<string, any>;
11
+ isAbstract?: boolean;
12
+ description?: string;
13
+ }
14
+ /**
15
+ * Options for adding a property to a class
16
+ */
17
+ export interface PropertyOptions {
18
+ type: Type<any>;
19
+ isOptional?: boolean;
20
+ isArray?: boolean;
21
+ description?: string;
22
+ example?: any;
23
+ deprecated?: boolean;
24
+ }
25
+ /**
26
+ * Generates a base class with the specified options.
27
+ * This is the foundation for creating dynamic DTO classes.
28
+ *
29
+ * @param options - Configuration for the class generation
30
+ * @returns A dynamically created class constructor
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * const MyClass = generateBaseClass({
35
+ * className: 'ProductWhereFields',
36
+ * metadata: { version: '1.0' }
37
+ * });
38
+ *
39
+ * const instance = new MyClass();
40
+ * console.log(instance.constructor.name); // 'ProductWhereFields'
41
+ * ```
42
+ */
43
+ export declare function generateBaseClass(options: ClassGeneratorOptions): Type<any>;
44
+ /**
45
+ * Adds a property to a class prototype with proper descriptors.
46
+ * This function is used to dynamically add fields to generated DTO classes.
47
+ *
48
+ * @param targetClass - The class to add the property to
49
+ * @param propertyName - Name of the property to add
50
+ * @param options - Configuration for the property
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * const MyClass = generateBaseClass({ className: 'TestClass' });
55
+ *
56
+ * addPropertyToClass(MyClass, 'name', {
57
+ * type: String,
58
+ * isOptional: true,
59
+ * description: 'The name field'
60
+ * });
61
+ *
62
+ * const instance = new MyClass();
63
+ * instance.name = 'test'; // Property is now available
64
+ * ```
65
+ */
66
+ export declare function addPropertyToClass(targetClass: Type<any>, propertyName: string, options: PropertyOptions): void;
67
+ /**
68
+ * Gets metadata for a property from a class.
69
+ *
70
+ * @param targetClass - The class to get metadata from
71
+ * @param propertyName - The property name
72
+ * @param metadataKey - The metadata key to retrieve
73
+ * @returns The metadata value or undefined
74
+ */
75
+ export declare function getPropertyMetadata(targetClass: Type<any>, propertyName: string, metadataKey: string): any;
76
+ /**
77
+ * Sets metadata for a property on a class.
78
+ *
79
+ * @param targetClass - The class to set metadata on
80
+ * @param propertyName - The property name
81
+ * @param metadataKey - The metadata key
82
+ * @param metadataValue - The metadata value
83
+ */
84
+ export declare function setPropertyMetadata(targetClass: Type<any>, propertyName: string, metadataKey: string, metadataValue: any): void;
85
+ /**
86
+ * Gets all property names that have been defined on a class.
87
+ *
88
+ * @param targetClass - The class to inspect
89
+ * @returns Array of property names
90
+ */
91
+ export declare function getDefinedProperties(targetClass: Type<any>): string[];
92
+ /**
93
+ * Clones a class constructor, creating a new class with the same properties.
94
+ * This is useful for creating variations of existing classes.
95
+ *
96
+ * @param sourceClass - The class to clone
97
+ * @param newClassName - Name for the new class
98
+ * @returns A new class constructor
99
+ */
100
+ export declare function cloneClass(sourceClass: Type<any>, newClassName: string): Type<any>;
101
+ //# sourceMappingURL=dynamic-class.helper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dynamic-class.helper.d.ts","sourceRoot":"","sources":["../../../src/helpers/class-generation/dynamic-class.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,kBAAkB,CAAC;AAE1B;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IACtB,UAAU,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC/B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IAChB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,qBAAqB,GAAG,IAAI,CAAC,GAAG,CAAC,CA4B3E;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,kBAAkB,CAChC,WAAW,EAAE,IAAI,CAAC,GAAG,CAAC,EACtB,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,eAAe,GACvB,IAAI,CA6CN;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,WAAW,EAAE,IAAI,CAAC,GAAG,CAAC,EACtB,YAAY,EAAE,MAAM,EACpB,WAAW,EAAE,MAAM,GAClB,GAAG,CAEL;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,WAAW,EAAE,IAAI,CAAC,GAAG,CAAC,EACtB,YAAY,EAAE,MAAM,EACpB,WAAW,EAAE,MAAM,EACnB,aAAa,EAAE,GAAG,GACjB,IAAI,CAEN;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,EAAE,CAmBrE;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,WAAW,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAWlF"}
@@ -0,0 +1,180 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateBaseClass = generateBaseClass;
4
+ exports.addPropertyToClass = addPropertyToClass;
5
+ exports.getPropertyMetadata = getPropertyMetadata;
6
+ exports.setPropertyMetadata = setPropertyMetadata;
7
+ exports.getDefinedProperties = getDefinedProperties;
8
+ exports.cloneClass = cloneClass;
9
+ require("reflect-metadata");
10
+ /**
11
+ * Generates a base class with the specified options.
12
+ * This is the foundation for creating dynamic DTO classes.
13
+ *
14
+ * @param options - Configuration for the class generation
15
+ * @returns A dynamically created class constructor
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const MyClass = generateBaseClass({
20
+ * className: 'ProductWhereFields',
21
+ * metadata: { version: '1.0' }
22
+ * });
23
+ *
24
+ * const instance = new MyClass();
25
+ * console.log(instance.constructor.name); // 'ProductWhereFields'
26
+ * ```
27
+ */
28
+ function generateBaseClass(options) {
29
+ const { className, baseClass, metadata } = options;
30
+ // Create the dynamic class
31
+ let DynamicClass;
32
+ if (baseClass) {
33
+ // Extend from base class if provided
34
+ DynamicClass = class extends baseClass {
35
+ };
36
+ }
37
+ else {
38
+ // Create standalone class
39
+ DynamicClass = class {
40
+ };
41
+ }
42
+ // Set the class name
43
+ Object.defineProperty(DynamicClass, 'name', {
44
+ value: className,
45
+ configurable: true
46
+ });
47
+ // Apply custom metadata if provided
48
+ if (metadata) {
49
+ for (const [key, value] of Object.entries(metadata)) {
50
+ Reflect.defineMetadata(key, value, DynamicClass);
51
+ }
52
+ }
53
+ return DynamicClass;
54
+ }
55
+ /**
56
+ * Adds a property to a class prototype with proper descriptors.
57
+ * This function is used to dynamically add fields to generated DTO classes.
58
+ *
59
+ * @param targetClass - The class to add the property to
60
+ * @param propertyName - Name of the property to add
61
+ * @param options - Configuration for the property
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * const MyClass = generateBaseClass({ className: 'TestClass' });
66
+ *
67
+ * addPropertyToClass(MyClass, 'name', {
68
+ * type: String,
69
+ * isOptional: true,
70
+ * description: 'The name field'
71
+ * });
72
+ *
73
+ * const instance = new MyClass();
74
+ * instance.name = 'test'; // Property is now available
75
+ * ```
76
+ */
77
+ function addPropertyToClass(targetClass, propertyName, options) {
78
+ const { type, isOptional = true } = options;
79
+ // Define property with getter/setter that creates enumerable instance property on first access
80
+ Object.defineProperty(targetClass.prototype, propertyName, {
81
+ get() {
82
+ // If the property doesn't exist on the instance, return undefined
83
+ if (!this.hasOwnProperty(propertyName)) {
84
+ return undefined;
85
+ }
86
+ // Return the descriptor's value
87
+ const descriptor = Object.getOwnPropertyDescriptor(this, propertyName);
88
+ return descriptor?.value;
89
+ },
90
+ set(value) {
91
+ // Define the property directly on the instance (not prototype) as enumerable
92
+ // This makes it serializable with JSON.stringify
93
+ Object.defineProperty(this, propertyName, {
94
+ value: value,
95
+ writable: true,
96
+ enumerable: true,
97
+ configurable: true
98
+ });
99
+ },
100
+ enumerable: true,
101
+ configurable: true
102
+ });
103
+ // Set design-time type metadata for reflection
104
+ Reflect.defineMetadata('design:type', type, targetClass.prototype, propertyName);
105
+ // Set parameter types metadata (for constructor injection if needed)
106
+ const existingParamTypes = Reflect.getMetadata('design:paramtypes', targetClass) || [];
107
+ Reflect.defineMetadata('design:paramtypes', existingParamTypes, targetClass);
108
+ // Store additional property metadata
109
+ const propertyMetadata = {
110
+ type,
111
+ isOptional,
112
+ description: options.description,
113
+ example: options.example,
114
+ deprecated: options.deprecated
115
+ };
116
+ Reflect.defineMetadata(`property:${propertyName}`, propertyMetadata, targetClass.prototype);
117
+ }
118
+ /**
119
+ * Gets metadata for a property from a class.
120
+ *
121
+ * @param targetClass - The class to get metadata from
122
+ * @param propertyName - The property name
123
+ * @param metadataKey - The metadata key to retrieve
124
+ * @returns The metadata value or undefined
125
+ */
126
+ function getPropertyMetadata(targetClass, propertyName, metadataKey) {
127
+ return Reflect.getMetadata(metadataKey, targetClass.prototype, propertyName);
128
+ }
129
+ /**
130
+ * Sets metadata for a property on a class.
131
+ *
132
+ * @param targetClass - The class to set metadata on
133
+ * @param propertyName - The property name
134
+ * @param metadataKey - The metadata key
135
+ * @param metadataValue - The metadata value
136
+ */
137
+ function setPropertyMetadata(targetClass, propertyName, metadataKey, metadataValue) {
138
+ Reflect.defineMetadata(metadataKey, metadataValue, targetClass.prototype, propertyName);
139
+ }
140
+ /**
141
+ * Gets all property names that have been defined on a class.
142
+ *
143
+ * @param targetClass - The class to inspect
144
+ * @returns Array of property names
145
+ */
146
+ function getDefinedProperties(targetClass) {
147
+ const properties = [];
148
+ const prototype = targetClass.prototype;
149
+ // Get own property names
150
+ const ownProps = Object.getOwnPropertyNames(prototype);
151
+ properties.push(...ownProps.filter(prop => prop !== 'constructor'));
152
+ // Walk up the prototype chain to get inherited properties
153
+ let currentProto = Object.getPrototypeOf(prototype);
154
+ while (currentProto && currentProto !== Object.prototype) {
155
+ const protoProps = Object.getOwnPropertyNames(currentProto);
156
+ properties.push(...protoProps.filter(prop => prop !== 'constructor' && !properties.includes(prop)));
157
+ currentProto = Object.getPrototypeOf(currentProto);
158
+ }
159
+ return properties;
160
+ }
161
+ /**
162
+ * Clones a class constructor, creating a new class with the same properties.
163
+ * This is useful for creating variations of existing classes.
164
+ *
165
+ * @param sourceClass - The class to clone
166
+ * @param newClassName - Name for the new class
167
+ * @returns A new class constructor
168
+ */
169
+ function cloneClass(sourceClass, newClassName) {
170
+ // Create new class extending the source
171
+ const ClonedClass = class extends sourceClass {
172
+ };
173
+ // Set the new name
174
+ Object.defineProperty(ClonedClass, 'name', {
175
+ value: newClassName,
176
+ configurable: true
177
+ });
178
+ return ClonedClass;
179
+ }
180
+ //# sourceMappingURL=dynamic-class.helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dynamic-class.helper.js","sourceRoot":"","sources":["../../../src/helpers/class-generation/dynamic-class.helper.ts"],"names":[],"mappings":";;AA6CA,8CA4BC;AAwBD,gDAiDC;AAUD,kDAMC;AAUD,kDAOC;AAQD,oDAmBC;AAUD,gCAWC;AAlOD,4BAA0B;AA0B1B;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAgB,iBAAiB,CAAC,OAA8B;IAC9D,MAAM,E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+ * This module provides utilities for dynamically creating and manipulating classes.
5
+ * These utilities can be used by any feature that needs to generate DTO classes
6
+ * or manipulate class structures at runtime.
7
+ */
8
+ export { generateBaseClass, addPropertyToClass, getPropertyMetadata, setPropertyMetadata, getDefinedProperties, cloneClass, type ClassGeneratorOptions, type PropertyOptions } from './dynamic-class.helper';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/helpers/class-generation/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,UAAU,EACV,KAAK,qBAAqB,EAC1B,KAAK,eAAe,EACrB,MAAM,wBAAwB,CAAC"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ /**
3
+ * Class Generation Utilities
4
+ *
5
+ * This module provides utilities for dynamically creating and manipulating classes.
6
+ * These utilities can be used by any feature that needs to generate DTO classes
7
+ * or manipulate class structures at runtime.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.cloneClass = exports.getDefinedProperties = exports.setPropertyMetadata = exports.getPropertyMetadata = exports.addPropertyToClass = exports.generateBaseClass = void 0;
11
+ var dynamic_class_helper_1 = require("./dynamic-class.helper");
12
+ Object.defineProperty(exports, "generateBaseClass", { enumerable: true, get: function () { return dynamic_class_helper_1.generateBaseClass; } });
13
+ Object.defineProperty(exports, "addPropertyToClass", { enumerable: true, get: function () { return dynamic_class_helper_1.addPropertyToClass; } });
14
+ Object.defineProperty(exports, "getPropertyMetadata", { enumerable: true, get: function () { return dynamic_class_helper_1.getPropertyMetadata; } });
15
+ Object.defineProperty(exports, "setPropertyMetadata", { enumerable: true, get: function () { return dynamic_class_helper_1.setPropertyMetadata; } });
16
+ Object.defineProperty(exports, "getDefinedProperties", { enumerable: true, get: function () { return dynamic_class_helper_1.getDefinedProperties; } });
17
+ Object.defineProperty(exports, "cloneClass", { enumerable: true, get: function () { return dynamic_class_helper_1.cloneClass; } });
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/helpers/class-generation/index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,+DASgC;AAR9B,yHAAA,iBAAiB,OAAA;AACjB,0HAAA,kBAAkB,OAAA;AAClB,2HAAA,mBAAmB,OAAA;AACnB,2HAAA,mBAAmB,OAAA;AACnB,4HAAA,oBAAoB,OAAA;AACpB,kHAAA,UAAU,OAAA"}