rawsql-ts 0.19.0 → 0.21.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 (85) hide show
  1. package/README.md +12 -13
  2. package/dist/esm/index.d.ts +1 -11
  3. package/dist/esm/index.js +1 -11
  4. package/dist/esm/index.js.map +1 -1
  5. package/dist/esm/index.min.js +5 -41
  6. package/dist/esm/index.min.js.map +4 -4
  7. package/dist/esm/transformers/DynamicQueryBuilder.d.ts +4 -27
  8. package/dist/esm/transformers/DynamicQueryBuilder.js +10 -27
  9. package/dist/esm/transformers/DynamicQueryBuilder.js.map +1 -1
  10. package/dist/esm/transformers/SSSQLFilterBuilder.d.ts +48 -1
  11. package/dist/esm/transformers/SSSQLFilterBuilder.js +578 -31
  12. package/dist/esm/transformers/SSSQLFilterBuilder.js.map +1 -1
  13. package/dist/esm/utils/SchemaManager.d.ts +3 -19
  14. package/dist/esm/utils/SchemaManager.js +2 -62
  15. package/dist/esm/utils/SchemaManager.js.map +1 -1
  16. package/dist/index.js +2 -18
  17. package/dist/index.js.map +1 -1
  18. package/dist/index.min.js +5 -41
  19. package/dist/index.min.js.map +4 -4
  20. package/dist/src/index.d.ts +1 -11
  21. package/dist/src/transformers/DynamicQueryBuilder.d.ts +4 -27
  22. package/dist/src/transformers/SSSQLFilterBuilder.d.ts +48 -1
  23. package/dist/src/utils/SchemaManager.d.ts +3 -19
  24. package/dist/transformers/DynamicQueryBuilder.js +10 -27
  25. package/dist/transformers/DynamicQueryBuilder.js.map +1 -1
  26. package/dist/transformers/SSSQLFilterBuilder.js +576 -29
  27. package/dist/transformers/SSSQLFilterBuilder.js.map +1 -1
  28. package/dist/tsconfig.browser.tsbuildinfo +1 -1
  29. package/dist/utils/SchemaManager.js +2 -63
  30. package/dist/utils/SchemaManager.js.map +1 -1
  31. package/package.json +10 -2
  32. package/dist/esm/transformers/EnhancedJsonMapping.d.ts +0 -194
  33. package/dist/esm/transformers/EnhancedJsonMapping.js +0 -217
  34. package/dist/esm/transformers/EnhancedJsonMapping.js.map +0 -1
  35. package/dist/esm/transformers/JsonMappingConverter.d.ts +0 -200
  36. package/dist/esm/transformers/JsonMappingConverter.js +0 -388
  37. package/dist/esm/transformers/JsonMappingConverter.js.map +0 -1
  38. package/dist/esm/transformers/JsonMappingUnifier.d.ts +0 -100
  39. package/dist/esm/transformers/JsonMappingUnifier.js +0 -207
  40. package/dist/esm/transformers/JsonMappingUnifier.js.map +0 -1
  41. package/dist/esm/transformers/ModelDrivenJsonMapping.d.ts +0 -62
  42. package/dist/esm/transformers/ModelDrivenJsonMapping.js +0 -115
  43. package/dist/esm/transformers/ModelDrivenJsonMapping.js.map +0 -1
  44. package/dist/esm/transformers/PostgresArrayEntityCteBuilder.d.ts +0 -138
  45. package/dist/esm/transformers/PostgresArrayEntityCteBuilder.js +0 -454
  46. package/dist/esm/transformers/PostgresArrayEntityCteBuilder.js.map +0 -1
  47. package/dist/esm/transformers/PostgresJsonQueryBuilder.d.ts +0 -88
  48. package/dist/esm/transformers/PostgresJsonQueryBuilder.js +0 -241
  49. package/dist/esm/transformers/PostgresJsonQueryBuilder.js.map +0 -1
  50. package/dist/esm/transformers/PostgresObjectEntityCteBuilder.d.ts +0 -165
  51. package/dist/esm/transformers/PostgresObjectEntityCteBuilder.js +0 -343
  52. package/dist/esm/transformers/PostgresObjectEntityCteBuilder.js.map +0 -1
  53. package/dist/esm/transformers/TypeTransformationPostProcessor.d.ts +0 -108
  54. package/dist/esm/transformers/TypeTransformationPostProcessor.js +0 -354
  55. package/dist/esm/transformers/TypeTransformationPostProcessor.js.map +0 -1
  56. package/dist/esm/utils/JsonSchemaValidator.d.ts +0 -81
  57. package/dist/esm/utils/JsonSchemaValidator.js +0 -211
  58. package/dist/esm/utils/JsonSchemaValidator.js.map +0 -1
  59. package/dist/src/transformers/EnhancedJsonMapping.d.ts +0 -194
  60. package/dist/src/transformers/JsonMappingConverter.d.ts +0 -200
  61. package/dist/src/transformers/JsonMappingUnifier.d.ts +0 -100
  62. package/dist/src/transformers/ModelDrivenJsonMapping.d.ts +0 -62
  63. package/dist/src/transformers/PostgresArrayEntityCteBuilder.d.ts +0 -138
  64. package/dist/src/transformers/PostgresJsonQueryBuilder.d.ts +0 -88
  65. package/dist/src/transformers/PostgresObjectEntityCteBuilder.d.ts +0 -165
  66. package/dist/src/transformers/TypeTransformationPostProcessor.d.ts +0 -108
  67. package/dist/src/utils/JsonSchemaValidator.d.ts +0 -81
  68. package/dist/transformers/EnhancedJsonMapping.js +0 -223
  69. package/dist/transformers/EnhancedJsonMapping.js.map +0 -1
  70. package/dist/transformers/JsonMappingConverter.js +0 -392
  71. package/dist/transformers/JsonMappingConverter.js.map +0 -1
  72. package/dist/transformers/JsonMappingUnifier.js +0 -216
  73. package/dist/transformers/JsonMappingUnifier.js.map +0 -1
  74. package/dist/transformers/ModelDrivenJsonMapping.js +0 -122
  75. package/dist/transformers/ModelDrivenJsonMapping.js.map +0 -1
  76. package/dist/transformers/PostgresArrayEntityCteBuilder.js +0 -458
  77. package/dist/transformers/PostgresArrayEntityCteBuilder.js.map +0 -1
  78. package/dist/transformers/PostgresJsonQueryBuilder.js +0 -245
  79. package/dist/transformers/PostgresJsonQueryBuilder.js.map +0 -1
  80. package/dist/transformers/PostgresObjectEntityCteBuilder.js +0 -347
  81. package/dist/transformers/PostgresObjectEntityCteBuilder.js.map +0 -1
  82. package/dist/transformers/TypeTransformationPostProcessor.js +0 -363
  83. package/dist/transformers/TypeTransformationPostProcessor.js.map +0 -1
  84. package/dist/utils/JsonSchemaValidator.js +0 -215
  85. package/dist/utils/JsonSchemaValidator.js.map +0 -1
@@ -1,343 +0,0 @@
1
- import { CommonTable, SourceAliasExpression, SelectItem, SelectClause, FromClause, SourceExpression, TableSource } from '../models/Clause';
2
- import { SimpleSelectQuery } from '../models/SimpleSelectQuery';
3
- import { IdentifierString, ColumnReference, FunctionCall, ValueList, LiteralValue, BinaryExpression, CaseExpression, SwitchCaseArgument, CaseKeyValuePair, RawString } from '../models/ValueComponent';
4
- /**
5
- * PostgreSQL-specific builder for creating CTEs for object entities (object relationships).
6
- * This class handles the creation of CTEs that build JSON/JSONB objects for object entities,
7
- * processing them from the deepest level up to ensure proper dependency ordering.
8
- *
9
- * Features:
10
- * - Depth-based CTE naming (cte_object_depth_N)
11
- * - NULL handling for entity columns
12
- * - JSONB/JSON object construction
13
- * - Hierarchical processing of nested objects
14
- *
15
- * Why depth calculation is critical:
16
- * 1. Object entities can be nested at multiple levels. We must process the deepest
17
- * (most distant) objects first to ensure their JSON representations are available
18
- * when building their parent entities.
19
- * 2. Object entity processing is essentially a column compression operation. Entities
20
- * at the same depth level can be processed simultaneously since they don't depend
21
- * on each other.
22
- *
23
- * Example hierarchy:
24
- * Order (root, depth 0)
25
- * └─ Customer (depth 1)
26
- * └─ Address (depth 2)
27
- * └─ Shipping (depth 1)
28
- * └─ Carrier (depth 2)
29
- *
30
- * Processing order: depth 2 → depth 1 → depth 0
31
- */
32
- export class PostgresObjectEntityCteBuilder {
33
- constructor() {
34
- // Simple counter for unique JSON column names
35
- this.jsonColumnCounter = 0;
36
- // Map entity ID to generated JSON column name
37
- this.entityToJsonColumnMap = new Map();
38
- // Column mappings for external use
39
- this.columnMappings = [];
40
- }
41
- /**
42
- * Build CTEs for all object entities in the correct dependency order
43
- * @param initialCte The starting CTE containing all raw data
44
- * @param allEntities Map of all entities in the mapping
45
- * @param mapping The JSON mapping configuration
46
- * @returns Array of CTEs and the alias of the last CTE created
47
- */
48
- buildObjectEntityCtes(initialCte, allEntities, mapping) {
49
- // Reset counter and mapping for each query
50
- this.jsonColumnCounter = 0;
51
- this.entityToJsonColumnMap.clear();
52
- this.columnMappings = [];
53
- const ctes = [initialCte];
54
- let previousCteAlias = initialCte.aliasExpression.table.name; // Collect and sort object entities by depth
55
- const objectEntityInfos = this.collectAndSortObjectEntities(mapping, allEntities);
56
- // Group entities by depth
57
- const entitiesByDepth = this.groupEntitiesByDepth(objectEntityInfos);
58
- // Process each depth level, starting from the deepest
59
- const depths = Array.from(entitiesByDepth.keys()).sort((a, b) => b - a);
60
- for (const depth of depths) {
61
- const entitiesAtDepth = entitiesByDepth.get(depth);
62
- const cteAlias = `${PostgresObjectEntityCteBuilder.CTE_OBJECT_PREFIX}${depth}`;
63
- // Build CTE for all entities at this depth
64
- const cte = this.buildDepthCte(entitiesAtDepth, previousCteAlias, cteAlias, mapping, allEntities);
65
- ctes.push(cte);
66
- previousCteAlias = cteAlias;
67
- }
68
- return {
69
- ctes,
70
- lastCteAlias: previousCteAlias,
71
- columnMappings: this.columnMappings
72
- };
73
- }
74
- /**
75
- * Generate unique JSON column name with entity name and counter
76
- */
77
- generateUniqueJsonColumnName(entityName, entityId, depth) {
78
- this.jsonColumnCounter++;
79
- const columnName = `${entityName.toLowerCase()}_json_${this.jsonColumnCounter}`;
80
- // Record mapping information for external use
81
- this.columnMappings.push({
82
- entityId,
83
- entityName,
84
- generatedColumnName: columnName,
85
- depth
86
- });
87
- return columnName;
88
- } /**
89
- * Collect all object entities and calculate their depth from root.
90
- *
91
- * Depth calculation is crucial because:
92
- * - It determines the processing order (deepest first)
93
- * - It ensures dependencies are resolved before an entity is processed
94
- * - It allows parallel processing of entities at the same depth level
95
- *
96
- * @param mapping The JSON mapping configuration
97
- * @param allEntities Map of all entities in the mapping
98
- * @returns Array of object entity information with calculated depths
99
- */
100
- collectAndSortObjectEntities(mapping, allEntities) {
101
- const objectInfos = [];
102
- // Helper function to calculate actual object nesting depth for a given OBJECT entity
103
- const calculateActualObjectNestingDepth = (entityIdOfObject) => {
104
- const initialEntity = allEntities.get(entityIdOfObject);
105
- if (!initialEntity) {
106
- throw new Error(`Entity ${entityIdOfObject} not found for depth calculation.`);
107
- }
108
- // If the object itself is root, its depth is 0. (This function should ideally be called for nested entities, not the root itself as a "parent CTE" subject)
109
- if (initialEntity.isRoot)
110
- return 0;
111
- // If the object is not root and has no parentId, it's considered a top-level object, depth 1.
112
- if (!initialEntity.parentId) {
113
- return 1;
114
- }
115
- let currentParentIdInHierarchy = initialEntity.parentId;
116
- let calculatedObjectDepth = 0;
117
- const visitedInPath = new Set();
118
- visitedInPath.add(entityIdOfObject); // Add the starting object itself to detect cycles
119
- while (currentParentIdInHierarchy) {
120
- if (visitedInPath.has(currentParentIdInHierarchy)) {
121
- throw new Error(`Circular dependency detected: ${currentParentIdInHierarchy} already visited in path for ${entityIdOfObject}`);
122
- }
123
- visitedInPath.add(currentParentIdInHierarchy);
124
- const parentEntityData = allEntities.get(currentParentIdInHierarchy);
125
- if (!parentEntityData) {
126
- throw new Error(`Parent entity ${currentParentIdInHierarchy} not found during depth calculation for ${entityIdOfObject}`);
127
- }
128
- let parentIsConsideredAnObjectForNesting = false;
129
- if (parentEntityData.isRoot) {
130
- parentIsConsideredAnObjectForNesting = true; // Root counts as an object ancestor
131
- }
132
- else {
133
- // For non-root parents, find their definition in nestedEntities to check their type
134
- const parentDefinition = mapping.nestedEntities.find(ne => ne.id === currentParentIdInHierarchy);
135
- if (parentDefinition) {
136
- if (parentDefinition.relationshipType === "object") {
137
- parentIsConsideredAnObjectForNesting = true;
138
- }
139
- // If parentDefinition.relationshipType === "array", it's not an object ancestor for depth counting
140
- }
141
- else {
142
- // This implies currentParentIdInHierarchy refers to an entity not defined as root or in nestedEntities
143
- // This should ideally not happen with a consistent mapping.
144
- throw new Error(`Parent entity ${currentParentIdInHierarchy} (ancestor of ${entityIdOfObject}) has no definition in mapping.nestedEntities and is not root.`);
145
- }
146
- }
147
- if (parentIsConsideredAnObjectForNesting) {
148
- calculatedObjectDepth++;
149
- }
150
- if (parentEntityData.isRoot) {
151
- break; // Stop when the root is processed as the highest object ancestor
152
- }
153
- currentParentIdInHierarchy = parentEntityData.parentId; // Move to the next ancestor
154
- }
155
- return calculatedObjectDepth;
156
- };
157
- mapping.nestedEntities.forEach(nestedEntity => {
158
- if (nestedEntity.relationshipType === "object") {
159
- const entity = allEntities.get(nestedEntity.id);
160
- // Ensure we don't process the root entity itself as a "parent" CTE,
161
- // and that the entity actually exists.
162
- if (entity && !entity.isRoot) {
163
- objectInfos.push({
164
- entity,
165
- depth: calculateActualObjectNestingDepth(nestedEntity.id)
166
- });
167
- }
168
- }
169
- });
170
- // The existing grouping and sorting by depth (b - a for descending) should still work correctly
171
- // as it processes deepest levels first, regardless of the absolute depth numbers.
172
- return objectInfos;
173
- }
174
- /**
175
- * Group entities by their depth level.
176
- *
177
- * Grouping by depth allows us to:
178
- * - Process all entities at the same level in a single CTE
179
- * - Optimize query performance by reducing the number of CTEs
180
- * - Maintain clear dependency ordering
181
- *
182
- * @param parentInfos Array of parent entity information with depths
183
- * @returns Map of depth level to entities at that depth
184
- */ groupEntitiesByDepth(objectInfos) {
185
- const entitiesByDepth = new Map();
186
- objectInfos.forEach(info => {
187
- const depth = info.depth;
188
- if (!entitiesByDepth.has(depth)) {
189
- entitiesByDepth.set(depth, []);
190
- }
191
- entitiesByDepth.get(depth).push(info);
192
- });
193
- return entitiesByDepth;
194
- }
195
- /**
196
- * Build a CTE that processes all entities at a specific depth level
197
- */
198
- buildDepthCte(entitiesAtDepth, previousCteAlias, cteAlias, mapping, allEntities) {
199
- // Build SELECT items: * and JSON objects for all entities at this depth
200
- const selectItems = [
201
- // Select all columns from previous CTE
202
- new SelectItem(new ColumnReference(null, new IdentifierString(PostgresObjectEntityCteBuilder.WILDCARD_COLUMN)))
203
- ];
204
- // Process each entity at this depth
205
- for (const { entity } of entitiesAtDepth) {
206
- const jsonColumn = this.buildEntityJsonColumn(entity, mapping, allEntities);
207
- selectItems.push(jsonColumn);
208
- }
209
- // Create CTE that selects from previous CTE
210
- const cteSelect = new SimpleSelectQuery({
211
- selectClause: new SelectClause(selectItems),
212
- fromClause: new FromClause(new SourceExpression(new TableSource(null, new IdentifierString(previousCteAlias)), null), null)
213
- });
214
- return new CommonTable(cteSelect, new SourceAliasExpression(cteAlias, null), null);
215
- }
216
- /**
217
- * Build JSON column for a single entity with NULL handling
218
- */
219
- buildEntityJsonColumn(entity, mapping, allEntities) {
220
- // Build JSON object arguments and NULL checks
221
- const { jsonObjectArgs, nullChecks } = this.prepareEntityColumns(entity);
222
- // Add child object relationships
223
- this.addChildObjectRelationships(entity, jsonObjectArgs, mapping, allEntities);
224
- // Create JSON object
225
- const jsonObject = this.createJsonObject(jsonObjectArgs);
226
- // Build NULL condition and CASE expression
227
- const nullCondition = this.buildNullCondition(nullChecks);
228
- const caseExpr = this.createCaseExpression(nullCondition, jsonObject);
229
- // Add JSON object as named column with unique name to avoid conflicts
230
- // Calculate depth for this entity (approximate - for mapping purposes)
231
- const depth = this.calculateApproximateDepth(entity, mapping);
232
- const jsonColumnName = this.generateUniqueJsonColumnName(entity.name, entity.id, depth);
233
- // Store mapping for child entity references
234
- this.entityToJsonColumnMap.set(entity.id, jsonColumnName);
235
- return new SelectItem(caseExpr, jsonColumnName);
236
- }
237
- /**
238
- * Calculate approximate depth for an entity (for mapping purposes)
239
- */
240
- calculateApproximateDepth(entity, mapping) {
241
- if (entity.isRoot)
242
- return 0;
243
- if (!entity.parentId)
244
- return 1;
245
- // Simple depth calculation
246
- let depth = 1;
247
- let currentParentId = entity.parentId;
248
- while (currentParentId && currentParentId !== mapping.rootEntity.id) {
249
- const parentEntity = mapping.nestedEntities.find(e => e.id === currentParentId);
250
- if (!parentEntity)
251
- break;
252
- depth++;
253
- currentParentId = parentEntity.parentId;
254
- }
255
- return depth;
256
- }
257
- /**
258
- * Prepare entity columns and NULL checks.
259
- *
260
- * This method extracts column data and creates NULL checks for each column.
261
- * The NULL checking is essential for handling outer joins correctly.
262
- *
263
- * In outer join scenarios, when there's no matching row in the joined table,
264
- * all columns from that table will be NULL. Instead of creating an empty object
265
- * with all NULL properties (e.g., {id: null, name: null, email: null}),
266
- * we want to represent the absence of the entity as NULL itself.
267
- *
268
- * This ensures cleaner JSON output where missing relationships are represented
269
- * as NULL rather than objects with all NULL fields.
270
- *
271
- * @param entity The entity whose columns are being processed
272
- * @returns Object containing arrays of JSON object arguments and NULL check conditions
273
- */
274
- prepareEntityColumns(entity) {
275
- const jsonObjectArgs = [];
276
- const nullChecks = [];
277
- Object.entries(entity.columns).forEach(([jsonKey, sqlColumn]) => {
278
- jsonObjectArgs.push(new LiteralValue(jsonKey, undefined, true));
279
- jsonObjectArgs.push(new ColumnReference(null, new IdentifierString(sqlColumn)));
280
- // Collect NULL checks for each column
281
- nullChecks.push(new BinaryExpression(new ColumnReference(null, new IdentifierString(sqlColumn)), "is", new LiteralValue(null)));
282
- });
283
- return { jsonObjectArgs, nullChecks };
284
- }
285
- /**
286
- * Add child object relationships to JSON object arguments.
287
- *
288
- * This method processes nested object-type entities that are direct children of the current entity.
289
- * For each child entity, it adds the property name and corresponding JSON column reference
290
- * to the arguments array that will be used to build the parent's JSON object.
291
- *
292
- * The child JSON columns are expected to already exist in the data source (created by deeper
293
- * level CTEs), as we process from the deepest level up to the root.
294
- *
295
- * Note: In this context, "child" refers to entities that have an object relationship (0..1)
296
- * with their parent. From a data perspective, these are typically entities referenced via
297
- * foreign keys, representing "parent" entities in traditional database terminology.
298
- *
299
- * @param entity The current entity being processed
300
- * @param jsonObjectArgs Array to which JSON object arguments will be added
301
- * @param mapping The JSON mapping configuration
302
- * @param allEntities Map of all entities in the mapping
303
- */
304
- addChildObjectRelationships(entity, jsonObjectArgs, mapping, allEntities) {
305
- const childEntities = mapping.nestedEntities.filter(ne => ne.parentId === entity.id && ne.relationshipType === "object");
306
- childEntities.forEach(childEntity => {
307
- const child = allEntities.get(childEntity.id);
308
- if (child) {
309
- jsonObjectArgs.push(new LiteralValue(childEntity.propertyName, undefined, true));
310
- // Use mapped JSON column name to avoid conflicts
311
- const jsonColumnName = this.entityToJsonColumnMap.get(child.id);
312
- if (!jsonColumnName) {
313
- throw new Error(`JSON column name not found for child entity: ${child.id}`);
314
- }
315
- jsonObjectArgs.push(new ColumnReference(null, new IdentifierString(jsonColumnName)));
316
- }
317
- });
318
- }
319
- /**
320
- * Create JSON object function call
321
- */
322
- createJsonObject(args) {
323
- const jsonBuildFunction = "jsonb_build_object";
324
- // Always use JSONB
325
- return new FunctionCall(null, new RawString(jsonBuildFunction), new ValueList(args), null);
326
- }
327
- /**
328
- * Build NULL condition from NULL checks
329
- */
330
- buildNullCondition(nullChecks) {
331
- return nullChecks.reduce((acc, check) => acc ? new BinaryExpression(acc, "and", check) : check);
332
- }
333
- /**
334
- * Create CASE expression with NULL handling
335
- */
336
- createCaseExpression(nullCondition, jsonObject) {
337
- return new CaseExpression(null, new SwitchCaseArgument([new CaseKeyValuePair(nullCondition, new LiteralValue(null))], jsonObject // ELSE return the JSON object
338
- ));
339
- }
340
- }
341
- PostgresObjectEntityCteBuilder.CTE_OBJECT_PREFIX = 'cte_object_depth_';
342
- PostgresObjectEntityCteBuilder.WILDCARD_COLUMN = '*';
343
- //# sourceMappingURL=PostgresObjectEntityCteBuilder.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PostgresObjectEntityCteBuilder.js","sourceRoot":"","sources":["../../../src/transformers/PostgresObjectEntityCteBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC3I,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAkB,eAAe,EAAE,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,gBAAgB,EAAE,cAAc,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AA4CvN;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,OAAO,8BAA8B;IAA3C;QAII,8CAA8C;QACtC,sBAAiB,GAAG,CAAC,CAAC;QAC9B,8CAA8C;QACtC,0BAAqB,GAAG,IAAI,GAAG,EAAkB,CAAC;QAC1D,mCAAmC;QAC3B,mBAAc,GAAwB,EAA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AChE,IAAI,CAAC,cAAc,EAAE,CAAC;oBAClB,MAAM,IAAI,KAAK,CAAC,gDAAgD,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;gBAChF,CAAC;gBACD,cAAc,CAAC,IAAI,CAAC,IAAI,eAAe,CAAC,IAAI,EAAE,IAAI,gBAAgB,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;YACzF,CAAC;QACL,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;OAEG;IACK,gBAAgB,CAAC,IAAsB;QAC3C,MAAM,iBAAiB,GAAG,oBAAoB,CAAC;QAC/C,mBAAmB;QACnB,OAAO,IAAI,YAAY,CACnB,IAAI,EACJ,IAAI,SAAS,CAAC,iBAAiB,CAAC,EAChC,IAAI,SAAS,CAAC,IAAI,CAAC,EACnB,IAAI,CACP,CAAC;IACN,CAAC;IAED;;OAEG;IACK,kBAAkB,CAAC,UAA4B;QACnD,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CACpC,GAAG,CAAC,CAAC,CAAC,IAAI,gBAAgB,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CACxD,CAAC;IACN,CAAC;IAED;;OAEG;IACK,oBAAoB,CAAC,aAA6B,EAAE,UAA0B;QAClF,OAAO,IAAI,cAAc,CACrB,IAAI,EACJ,IAAI,kBAAkB,CAClB,CAAC,IAAI,gBAAgB,CAAC,aAAa,EAAE,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,EAC7D,UAAU,CAAE,8BAA8B;SAC7C,CACJ,CAAC;IACN,CAAC;;AAvZuB,gDAAiB,GAAG,mBAAmB,AAAtB,CAAuB;AACxC,8CAAe,GAAG,GAAG,AAAN,CAAO"}
@@ -1,108 +0,0 @@
1
- /**
2
- * Post-processor for transforming database values to appropriate TypeScript types
3
- * after JSON serialization from PostgreSQL
4
- */
5
- export interface TypeTransformationConfig {
6
- /** Column transformations mapping - takes precedence over value-based detection */
7
- columnTransformations?: {
8
- [columnName: string]: TypeTransformation;
9
- };
10
- /** Global transformation rules by SQL data type */
11
- globalTransformations?: {
12
- [sqlType: string]: TypeTransformation;
13
- };
14
- /** Custom transformation functions */
15
- customTransformers?: {
16
- [transformerName: string]: (value: unknown) => unknown;
17
- };
18
- /** Enable value-based type detection when column mapping is not provided (default: true) */
19
- enableValueBasedDetection?: boolean;
20
- /** Strict date detection - only convert ISO 8601 with 'T' separator (default: false) */
21
- strictDateDetection?: boolean;
22
- }
23
- export interface TypeTransformation {
24
- /** Source SQL data type */
25
- sourceType: 'DATE' | 'TIMESTAMP' | 'BIGINT' | 'NUMERIC' | 'JSONB' | 'custom';
26
- /** Target TypeScript type representation */
27
- targetType: 'Date' | 'bigint' | 'string' | 'number' | 'object' | 'custom';
28
- /** Custom transformer function name (for custom type) */
29
- customTransformer?: string;
30
- /** Whether to handle null values (default: true) */
31
- handleNull?: boolean;
32
- /** Validation function for the value */
33
- validator?: (value: unknown) => boolean;
34
- }
35
- /**
36
- * Applies type transformations to JSON results from PostgreSQL
37
- */
38
- export declare class TypeTransformationPostProcessor {
39
- private config;
40
- constructor(config?: TypeTransformationConfig);
41
- /**
42
- * Transform a single result object
43
- * @param result The result object from PostgreSQL JSON query
44
- * @returns Transformed result with proper TypeScript types
45
- */
46
- transformResult<T = unknown>(result: unknown): T;
47
- /**
48
- * Transform a single object recursively
49
- */
50
- private transformSingleObject;
51
- /**
52
- * Detect value type and create appropriate transformation based on value characteristics
53
- * This is the core value-based detection logic
54
- */
55
- private detectValueBasedTransformation;
56
- /**
57
- * Get global transformation for a specific value (if any match)
58
- * This is separate from value-based detection and relies on configured global rules
59
- */
60
- private getGlobalTransformationForValue;
61
- /**
62
- * @deprecated Use detectValueBasedTransformation instead
63
- * Detect value type and get appropriate global transformation
64
- */
65
- private detectAndGetGlobalTransformation;
66
- /**
67
- * Check if string is a valid date string
68
- * Supports both strict (ISO 8601 with T separator) and loose detection
69
- */
70
- private isDateString;
71
- /**
72
- * Apply a specific transformation to a value
73
- */
74
- private applyTransformation;
75
- /**
76
- * Create a default configuration for common PostgreSQL types
77
- * Enables value-based detection with loose date detection by default
78
- */
79
- static createDefaultConfig(): TypeTransformationConfig;
80
- /**
81
- * Create a safe configuration for handling user input
82
- * Disables value-based detection and uses strict date detection
83
- */
84
- static createSafeConfig(columnMappings?: {
85
- [columnName: string]: TypeTransformation;
86
- }): TypeTransformationConfig;
87
- }
88
- /**
89
- * Convenience function to create and apply transformations
90
- */
91
- export declare function transformDatabaseResult<T = unknown>(result: unknown, config?: TypeTransformationConfig): T;
92
- /**
93
- * Type-safe transformation helpers
94
- */
95
- export declare const TypeTransformers: {
96
- /**
97
- * Transform date string to Date object
98
- */
99
- toDate: (value: string | null) => Date | null;
100
- /**
101
- * Transform numeric string to BigInt
102
- */
103
- toBigInt: (value: string | number | null) => bigint | null;
104
- /**
105
- * Transform JSON string to object
106
- */
107
- toObject: <T = unknown>(value: string | null) => T | null;
108
- };