rawsql-ts 0.11.0-beta → 0.11.1-beta
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.
- package/README.md +1 -3
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.min.js +13 -13
- package/dist/esm/index.min.js.map +4 -4
- package/dist/esm/src/index.js +2 -0
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/tokenReaders/OperatorTokenReader.js +4 -0
- package/dist/esm/src/tokenReaders/OperatorTokenReader.js.map +1 -1
- package/dist/esm/src/transformers/CTEDependencyTracer.js +249 -0
- package/dist/esm/src/transformers/CTEDependencyTracer.js.map +1 -0
- package/dist/esm/src/transformers/JsonMappingUnifier.js +217 -0
- package/dist/esm/src/transformers/JsonMappingUnifier.js.map +1 -0
- package/dist/esm/src/transformers/ModelDrivenJsonMapping.js +103 -0
- package/dist/esm/src/transformers/ModelDrivenJsonMapping.js.map +1 -0
- package/dist/esm/src/transformers/PostgresArrayEntityCteBuilder.js +204 -16
- package/dist/esm/src/transformers/PostgresArrayEntityCteBuilder.js.map +1 -1
- package/dist/esm/src/transformers/PostgresJsonQueryBuilder.js +10 -9
- package/dist/esm/src/transformers/PostgresJsonQueryBuilder.js.map +1 -1
- package/dist/esm/src/transformers/PostgresObjectEntityCteBuilder.js +8 -5
- package/dist/esm/src/transformers/PostgresObjectEntityCteBuilder.js.map +1 -1
- package/dist/esm/src/transformers/SelectableColumnCollector.js +17 -5
- package/dist/esm/src/transformers/SelectableColumnCollector.js.map +1 -1
- package/dist/esm/src/transformers/UnifiedJsonMapping.js +2 -4
- package/dist/esm/src/transformers/UnifiedJsonMapping.js.map +1 -1
- package/dist/esm/src/transformers/UpstreamSelectQueryFinder.js +8 -1
- package/dist/esm/src/transformers/UpstreamSelectQueryFinder.js.map +1 -1
- package/dist/esm/src/utils/OperatorPrecedence.js +3 -1
- package/dist/esm/src/utils/OperatorPrecedence.js.map +1 -1
- package/dist/esm/src/utils/SchemaManager.js +0 -1
- package/dist/esm/src/utils/SchemaManager.js.map +1 -1
- package/dist/esm/tsconfig.browser.tsbuildinfo +1 -1
- package/dist/esm/types/src/index.d.ts +2 -0
- package/dist/esm/types/src/transformers/CTEDependencyTracer.d.ts +58 -0
- package/dist/esm/types/src/transformers/JsonMappingUnifier.d.ts +95 -0
- package/dist/esm/types/src/transformers/ModelDrivenJsonMapping.d.ts +62 -0
- package/dist/esm/types/src/transformers/PostgresArrayEntityCteBuilder.d.ts +80 -1
- package/dist/esm/types/src/transformers/PostgresJsonQueryBuilder.d.ts +0 -1
- package/dist/esm/types/src/transformers/SelectableColumnCollector.d.ts +14 -3
- package/dist/esm/types/src/transformers/UnifiedJsonMapping.d.ts +0 -1
- package/dist/esm/types/src/transformers/UpstreamSelectQueryFinder.d.ts +5 -1
- package/dist/index.min.js +13 -13
- package/dist/index.min.js.map +4 -4
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +10 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/tokenReaders/OperatorTokenReader.js +4 -0
- package/dist/src/tokenReaders/OperatorTokenReader.js.map +1 -1
- package/dist/src/transformers/CTEDependencyTracer.d.ts +58 -0
- package/dist/src/transformers/CTEDependencyTracer.js +253 -0
- package/dist/src/transformers/CTEDependencyTracer.js.map +1 -0
- package/dist/src/transformers/JsonMappingUnifier.d.ts +95 -0
- package/dist/src/transformers/JsonMappingUnifier.js +226 -0
- package/dist/src/transformers/JsonMappingUnifier.js.map +1 -0
- package/dist/src/transformers/ModelDrivenJsonMapping.d.ts +62 -0
- package/dist/src/transformers/ModelDrivenJsonMapping.js +110 -0
- package/dist/src/transformers/ModelDrivenJsonMapping.js.map +1 -0
- package/dist/src/transformers/PostgresArrayEntityCteBuilder.d.ts +80 -1
- package/dist/src/transformers/PostgresArrayEntityCteBuilder.js +204 -16
- package/dist/src/transformers/PostgresArrayEntityCteBuilder.js.map +1 -1
- package/dist/src/transformers/PostgresJsonQueryBuilder.d.ts +0 -1
- package/dist/src/transformers/PostgresJsonQueryBuilder.js +10 -9
- package/dist/src/transformers/PostgresJsonQueryBuilder.js.map +1 -1
- package/dist/src/transformers/PostgresObjectEntityCteBuilder.js +8 -5
- package/dist/src/transformers/PostgresObjectEntityCteBuilder.js.map +1 -1
- package/dist/src/transformers/SelectableColumnCollector.d.ts +14 -3
- package/dist/src/transformers/SelectableColumnCollector.js +17 -5
- package/dist/src/transformers/SelectableColumnCollector.js.map +1 -1
- package/dist/src/transformers/UnifiedJsonMapping.d.ts +0 -1
- package/dist/src/transformers/UnifiedJsonMapping.js +2 -4
- package/dist/src/transformers/UnifiedJsonMapping.js.map +1 -1
- package/dist/src/transformers/UpstreamSelectQueryFinder.d.ts +5 -1
- package/dist/src/transformers/UpstreamSelectQueryFinder.js +8 -1
- package/dist/src/transformers/UpstreamSelectQueryFinder.js.map +1 -1
- package/dist/src/utils/OperatorPrecedence.js +3 -1
- package/dist/src/utils/OperatorPrecedence.js.map +1 -1
- package/dist/src/utils/SchemaManager.js +0 -1
- package/dist/src/utils/SchemaManager.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Unified JSON Mapping processor that supports both legacy and model-driven formats.
|
|
4
|
+
*
|
|
5
|
+
* This module provides backward compatibility while encouraging migration to the model-driven format.
|
|
6
|
+
* It automatically detects the input format and normalizes to a consistent internal representation.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.detectMappingFormat = detectMappingFormat;
|
|
10
|
+
exports.processJsonMapping = processJsonMapping;
|
|
11
|
+
exports.unifyJsonMapping = unifyJsonMapping;
|
|
12
|
+
exports.isModelDrivenFormat = isModelDrivenFormat;
|
|
13
|
+
exports.isUnifiedFormat = isUnifiedFormat;
|
|
14
|
+
exports.isLegacyFormat = isLegacyFormat;
|
|
15
|
+
exports.suggestModelDrivenMigration = suggestModelDrivenMigration;
|
|
16
|
+
const ModelDrivenJsonMapping_1 = require("./ModelDrivenJsonMapping");
|
|
17
|
+
/**
|
|
18
|
+
* Detects the format of a JSON mapping configuration.
|
|
19
|
+
*
|
|
20
|
+
* @param input - The mapping configuration to analyze
|
|
21
|
+
* @returns The detected format type
|
|
22
|
+
*/
|
|
23
|
+
function detectMappingFormat(input) {
|
|
24
|
+
// Model-driven format: has typeInfo and structure
|
|
25
|
+
if (input.typeInfo && input.structure) {
|
|
26
|
+
return 'model-driven';
|
|
27
|
+
}
|
|
28
|
+
// Unified format: has rootName and rootEntity
|
|
29
|
+
if (input.rootName && input.rootEntity) {
|
|
30
|
+
return 'unified';
|
|
31
|
+
}
|
|
32
|
+
// Legacy format: direct JsonMapping structure
|
|
33
|
+
if (input.columns || input.relationships) {
|
|
34
|
+
return 'legacy';
|
|
35
|
+
}
|
|
36
|
+
// Default fallback
|
|
37
|
+
return 'legacy';
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Converts legacy unified format to JsonMapping.
|
|
41
|
+
*
|
|
42
|
+
* @param input - Unified format mapping configuration
|
|
43
|
+
* @returns Converted JsonMapping
|
|
44
|
+
*/
|
|
45
|
+
function convertUnifiedFormat(input) {
|
|
46
|
+
if (!input.rootEntity) {
|
|
47
|
+
throw new Error('Unified format requires rootEntity');
|
|
48
|
+
}
|
|
49
|
+
const result = {
|
|
50
|
+
rootName: input.rootName || 'root',
|
|
51
|
+
rootEntity: {
|
|
52
|
+
id: input.rootEntity.id || 'root',
|
|
53
|
+
name: input.rootEntity.name || 'Root',
|
|
54
|
+
columns: input.rootEntity.columns || {}
|
|
55
|
+
},
|
|
56
|
+
nestedEntities: []
|
|
57
|
+
};
|
|
58
|
+
// Convert nestedEntities
|
|
59
|
+
if (input.nestedEntities && Array.isArray(input.nestedEntities)) {
|
|
60
|
+
result.nestedEntities = input.nestedEntities.map(entity => ({
|
|
61
|
+
id: entity.id || entity.propertyName || 'nested',
|
|
62
|
+
name: entity.name || entity.propertyName || 'Nested',
|
|
63
|
+
parentId: entity.parentId || result.rootEntity.id,
|
|
64
|
+
propertyName: entity.propertyName || 'nested',
|
|
65
|
+
relationshipType: entity.relationshipType || 'object',
|
|
66
|
+
columns: entity.columns || {}
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Converts legacy format directly to JsonMapping.
|
|
73
|
+
*
|
|
74
|
+
* @param input - Legacy format mapping configuration
|
|
75
|
+
* @returns JsonMapping
|
|
76
|
+
*/
|
|
77
|
+
function convertLegacyFormat(input) {
|
|
78
|
+
const result = {
|
|
79
|
+
rootName: input.rootName || 'root',
|
|
80
|
+
rootEntity: {
|
|
81
|
+
id: 'root',
|
|
82
|
+
name: input.rootName || 'Root',
|
|
83
|
+
columns: input.columns || {}
|
|
84
|
+
},
|
|
85
|
+
nestedEntities: []
|
|
86
|
+
};
|
|
87
|
+
// Convert relationships to nestedEntities
|
|
88
|
+
if (input.relationships && typeof input.relationships === 'object') {
|
|
89
|
+
for (const [propertyName, relationship] of Object.entries(input.relationships)) {
|
|
90
|
+
// Type assertion for legacy relationship format
|
|
91
|
+
const rel = relationship;
|
|
92
|
+
result.nestedEntities.push({
|
|
93
|
+
id: propertyName,
|
|
94
|
+
name: propertyName.charAt(0).toUpperCase() + propertyName.slice(1),
|
|
95
|
+
parentId: 'root',
|
|
96
|
+
propertyName,
|
|
97
|
+
relationshipType: rel.type === 'hasMany' ? 'array' : 'object',
|
|
98
|
+
columns: rel.columns || {}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return result;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Main processor that unifies all JSON mapping formats into a consistent JsonMapping.
|
|
106
|
+
*
|
|
107
|
+
* Features:
|
|
108
|
+
* - Automatic format detection
|
|
109
|
+
* - Backward compatibility with all existing formats
|
|
110
|
+
* - Metadata preservation for advanced features
|
|
111
|
+
* - Zero external dependencies
|
|
112
|
+
*
|
|
113
|
+
* @param input - Any supported JSON mapping format
|
|
114
|
+
* @returns Unified processing result with JsonMapping and metadata
|
|
115
|
+
*/
|
|
116
|
+
function processJsonMapping(input) {
|
|
117
|
+
const format = detectMappingFormat(input);
|
|
118
|
+
let jsonMapping;
|
|
119
|
+
let metadata = {};
|
|
120
|
+
try {
|
|
121
|
+
switch (format) {
|
|
122
|
+
case 'model-driven':
|
|
123
|
+
// Validate model-driven input
|
|
124
|
+
if (!input.typeInfo || !input.structure) {
|
|
125
|
+
throw new Error('Model-driven format requires typeInfo and structure fields');
|
|
126
|
+
}
|
|
127
|
+
// Convert model-driven to JsonMapping
|
|
128
|
+
const modelDrivenInput = {
|
|
129
|
+
typeInfo: input.typeInfo,
|
|
130
|
+
structure: input.structure
|
|
131
|
+
};
|
|
132
|
+
const converted = (0, ModelDrivenJsonMapping_1.convertModelDrivenMapping)(modelDrivenInput);
|
|
133
|
+
jsonMapping = converted.jsonMapping;
|
|
134
|
+
// Preserve metadata
|
|
135
|
+
metadata = {
|
|
136
|
+
typeInfo: input.typeInfo,
|
|
137
|
+
typeProtection: converted.typeProtection
|
|
138
|
+
};
|
|
139
|
+
break;
|
|
140
|
+
case 'unified':
|
|
141
|
+
// Validate unified input
|
|
142
|
+
if (!input.rootEntity) {
|
|
143
|
+
throw new Error('Unified format requires rootEntity field');
|
|
144
|
+
}
|
|
145
|
+
jsonMapping = convertUnifiedFormat(input);
|
|
146
|
+
break;
|
|
147
|
+
case 'legacy':
|
|
148
|
+
// Validate legacy input
|
|
149
|
+
if (!input.columns && !input.relationships) {
|
|
150
|
+
throw new Error('Legacy format requires at least columns or relationships field');
|
|
151
|
+
}
|
|
152
|
+
jsonMapping = convertLegacyFormat(input);
|
|
153
|
+
break;
|
|
154
|
+
default:
|
|
155
|
+
throw new Error(`Unsupported mapping format: ${format}`);
|
|
156
|
+
}
|
|
157
|
+
return {
|
|
158
|
+
format,
|
|
159
|
+
jsonMapping,
|
|
160
|
+
originalInput: input,
|
|
161
|
+
metadata
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
throw new Error(`Failed to process JSON mapping (format: ${format}): ${error instanceof Error ? error.message : String(error)}`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Convenience function for direct JsonMapping extraction.
|
|
170
|
+
*
|
|
171
|
+
* @param input - Any supported JSON mapping format
|
|
172
|
+
* @returns JsonMapping ready for use with PostgresJsonQueryBuilder
|
|
173
|
+
*/
|
|
174
|
+
function unifyJsonMapping(input) {
|
|
175
|
+
return processJsonMapping(input).jsonMapping;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Type guard to check if input uses model-driven format.
|
|
179
|
+
*
|
|
180
|
+
* @param input - Mapping input to check
|
|
181
|
+
* @returns True if input is model-driven format
|
|
182
|
+
*/
|
|
183
|
+
function isModelDrivenFormat(input) {
|
|
184
|
+
return detectMappingFormat(input) === 'model-driven';
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Type guard to check if input uses unified format.
|
|
188
|
+
*
|
|
189
|
+
* @param input - Mapping input to check
|
|
190
|
+
* @returns True if input is unified format
|
|
191
|
+
*/
|
|
192
|
+
function isUnifiedFormat(input) {
|
|
193
|
+
return detectMappingFormat(input) === 'unified';
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Type guard to check if input uses legacy format.
|
|
197
|
+
*
|
|
198
|
+
* @param input - Mapping input to check
|
|
199
|
+
* @returns True if input is legacy format
|
|
200
|
+
*/
|
|
201
|
+
function isLegacyFormat(input) {
|
|
202
|
+
return detectMappingFormat(input) === 'legacy';
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Migration helper that suggests upgrading to model-driven format.
|
|
206
|
+
*
|
|
207
|
+
* @param input - Current mapping configuration
|
|
208
|
+
* @returns Suggestions for migration (if applicable)
|
|
209
|
+
*/
|
|
210
|
+
function suggestModelDrivenMigration(input) {
|
|
211
|
+
const format = detectMappingFormat(input);
|
|
212
|
+
const suggestions = [];
|
|
213
|
+
if (format !== 'model-driven') {
|
|
214
|
+
suggestions.push('Consider migrating to model-driven JSON mapping format');
|
|
215
|
+
suggestions.push('Benefits: Better type safety, IDE support, and future-proof design');
|
|
216
|
+
suggestions.push('See: Model-Driven JSON Mapping Guide for migration instructions');
|
|
217
|
+
if (format === 'unified') {
|
|
218
|
+
suggestions.push('Your current unified format can be automatically converted');
|
|
219
|
+
}
|
|
220
|
+
if (format === 'legacy') {
|
|
221
|
+
suggestions.push('Legacy format support will be maintained but new features target model-driven format');
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return suggestions;
|
|
225
|
+
}
|
|
226
|
+
//# sourceMappingURL=JsonMappingUnifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JsonMappingUnifier.js","sourceRoot":"","sources":["../../../src/transformers/JsonMappingUnifier.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAkDH,kDAkBC;AAqFD,gDA4DC;AAQD,4CAEC;AAQD,kDAEC;AAQD,0CAEC;AAQD,wCAEC;AAQD,kEAmBC;AArRD,qEAA6F;AAyC7F;;;;;GAKG;AACH,SAAgB,mBAAmB,CAAC,KAA0B;IAC1D,kDAAkD;IAClD,IAAI,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,SAAS,EAAE,CAAC;QACpC,OAAO,cAAc,CAAC;IAC1B,CAAC;IAED,8CAA8C;IAC9C,IAAI,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,UAAU,EAAE,CAAC;QACrC,OAAO,SAAS,CAAC;IACrB,CAAC;IAED,8CAA8C;IAC9C,IAAI,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,aAAa,EAAE,CAAC;QACvC,OAAO,QAAQ,CAAC;IACpB,CAAC;IAED,mBAAmB;IAC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
|
2
|
+
* Model-driven JSON mapping structure that mirrors TypeScript model definitions.
|
|
3
|
+
* This approach provides intuitive, hierarchical mapping that closely resembles the target data structure.
|
|
4
|
+
*/
|
|
5
|
+
import { JsonMapping } from './PostgresJsonQueryBuilder';
|
|
6
|
+
/**
|
|
7
|
+
* Supported field types for database column mapping.
|
|
8
|
+
*/
|
|
9
|
+
export type FieldType = 'string' | 'number' | 'boolean' | 'object' | 'array' | 'auto';
|
|
10
|
+
/**
|
|
11
|
+
* Field mapping configuration that can be either a simple column name or enhanced mapping with type control.
|
|
12
|
+
*/
|
|
13
|
+
export type FieldMapping = string | {
|
|
14
|
+
column: string;
|
|
15
|
+
type?: FieldType;
|
|
16
|
+
} | {
|
|
17
|
+
from: string;
|
|
18
|
+
type?: FieldType;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Nested object or array structure definition.
|
|
22
|
+
*/
|
|
23
|
+
export interface NestedStructure {
|
|
24
|
+
type: 'object' | 'array';
|
|
25
|
+
from: string;
|
|
26
|
+
structure: StructureFields;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Structure fields can contain either field mappings or nested structures.
|
|
30
|
+
*/
|
|
31
|
+
export type StructureFields = {
|
|
32
|
+
[key: string]: FieldMapping | NestedStructure;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Model-driven JSON mapping that mirrors TypeScript interface structure.
|
|
36
|
+
* This design makes it easy to understand the relationship between models and database columns.
|
|
37
|
+
*/
|
|
38
|
+
export interface ModelDrivenJsonMapping {
|
|
39
|
+
typeInfo: {
|
|
40
|
+
interface: string;
|
|
41
|
+
importPath: string;
|
|
42
|
+
};
|
|
43
|
+
structure: StructureFields;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Type protection configuration extracted from the model-driven mapping.
|
|
47
|
+
*/
|
|
48
|
+
export interface TypeProtectionConfig {
|
|
49
|
+
protectedStringFields: string[];
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Convert a model-driven JSON mapping to the traditional JsonMapping format.
|
|
53
|
+
* This enables backward compatibility with existing PostgresJsonQueryBuilder.
|
|
54
|
+
*/
|
|
55
|
+
export declare function convertModelDrivenMapping(modelMapping: ModelDrivenJsonMapping): {
|
|
56
|
+
jsonMapping: JsonMapping;
|
|
57
|
+
typeProtection: TypeProtectionConfig;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Validate that a model-driven mapping structure is well-formed.
|
|
61
|
+
*/
|
|
62
|
+
export declare function validateModelDrivenMapping(mapping: ModelDrivenJsonMapping): string[];
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Model-driven JSON mapping structure that mirrors TypeScript model definitions.
|
|
4
|
+
* This approach provides intuitive, hierarchical mapping that closely resembles the target data structure.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.convertModelDrivenMapping = convertModelDrivenMapping;
|
|
8
|
+
exports.validateModelDrivenMapping = validateModelDrivenMapping;
|
|
9
|
+
/**
|
|
10
|
+
* Convert a model-driven JSON mapping to the traditional JsonMapping format.
|
|
11
|
+
* This enables backward compatibility with existing PostgresJsonQueryBuilder.
|
|
12
|
+
*/
|
|
13
|
+
function convertModelDrivenMapping(modelMapping) {
|
|
14
|
+
const protectedStringFields = [];
|
|
15
|
+
let entityIdCounter = 0;
|
|
16
|
+
// Generate unique entity IDs
|
|
17
|
+
const generateEntityId = () => `entity_${++entityIdCounter}`;
|
|
18
|
+
// Helper function to process structure fields and extract entities
|
|
19
|
+
const processStructure = (structure, parentId = null) => {
|
|
20
|
+
const columns = {};
|
|
21
|
+
const nestedEntities = [];
|
|
22
|
+
for (const [fieldName, config] of Object.entries(structure)) {
|
|
23
|
+
if (typeof config === 'string') {
|
|
24
|
+
// Simple field mapping: "fieldName": "column_name"
|
|
25
|
+
columns[fieldName] = config;
|
|
26
|
+
}
|
|
27
|
+
else if ('column' in config && typeof config.column === 'string' && !('type' in config && (config.type === 'object' || config.type === 'array'))) {
|
|
28
|
+
// Enhanced field mapping: "fieldName": { "column": "column_name", "type": "string" }
|
|
29
|
+
const fieldConfig = config;
|
|
30
|
+
if (typeof fieldConfig === 'object' && 'column' in fieldConfig) {
|
|
31
|
+
columns[fieldName] = fieldConfig.column;
|
|
32
|
+
if (fieldConfig.type === 'string') {
|
|
33
|
+
protectedStringFields.push(fieldConfig.column);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else if ('from' in config && typeof config.from === 'string' && !('type' in config && (config.type === 'object' || config.type === 'array'))) {
|
|
38
|
+
// Legacy field mapping: "fieldName": { "from": "column_name", "type": "string" }
|
|
39
|
+
const fieldConfig = config;
|
|
40
|
+
if (typeof fieldConfig === 'object' && 'from' in fieldConfig) {
|
|
41
|
+
columns[fieldName] = fieldConfig.from;
|
|
42
|
+
if (fieldConfig.type === 'string') {
|
|
43
|
+
protectedStringFields.push(fieldConfig.from);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else if ('type' in config && (config.type === 'object' || config.type === 'array')) {
|
|
48
|
+
// Nested structure: object or array
|
|
49
|
+
const nestedStructure = config;
|
|
50
|
+
const entityId = generateEntityId();
|
|
51
|
+
const processedNested = processStructure(nestedStructure.structure, entityId);
|
|
52
|
+
nestedEntities.push({
|
|
53
|
+
id: entityId,
|
|
54
|
+
name: fieldName.charAt(0).toUpperCase() + fieldName.slice(1), // Capitalize first letter
|
|
55
|
+
parentId: parentId || 'root',
|
|
56
|
+
propertyName: fieldName,
|
|
57
|
+
relationshipType: nestedStructure.type,
|
|
58
|
+
columns: processedNested.columns
|
|
59
|
+
});
|
|
60
|
+
// Add nested entities from deeper levels
|
|
61
|
+
nestedEntities.push(...processedNested.nestedEntities.map(entity => ({
|
|
62
|
+
...entity,
|
|
63
|
+
parentId: entity.parentId === 'root' ? entityId : entity.parentId
|
|
64
|
+
})));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return { columns, nestedEntities };
|
|
68
|
+
};
|
|
69
|
+
// Process the root structure
|
|
70
|
+
const processed = processStructure(modelMapping.structure); // Build the traditional JsonMapping
|
|
71
|
+
const jsonMapping = {
|
|
72
|
+
rootName: 'root', // Default root name
|
|
73
|
+
rootEntity: {
|
|
74
|
+
id: 'root',
|
|
75
|
+
name: 'Root',
|
|
76
|
+
columns: processed.columns
|
|
77
|
+
},
|
|
78
|
+
nestedEntities: processed.nestedEntities
|
|
79
|
+
};
|
|
80
|
+
// Add typeInfo for backward compatibility
|
|
81
|
+
jsonMapping.typeInfo = modelMapping.typeInfo;
|
|
82
|
+
return {
|
|
83
|
+
jsonMapping,
|
|
84
|
+
typeProtection: { protectedStringFields }
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Validate that a model-driven mapping structure is well-formed.
|
|
89
|
+
*/
|
|
90
|
+
function validateModelDrivenMapping(mapping) {
|
|
91
|
+
const errors = [];
|
|
92
|
+
// Validate typeInfo
|
|
93
|
+
if (!mapping.typeInfo) {
|
|
94
|
+
errors.push('typeInfo is required');
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
if (!mapping.typeInfo.interface) {
|
|
98
|
+
errors.push('typeInfo.interface is required');
|
|
99
|
+
}
|
|
100
|
+
if (!mapping.typeInfo.importPath) {
|
|
101
|
+
errors.push('typeInfo.importPath is required');
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
// Validate structure
|
|
105
|
+
if (!mapping.structure || typeof mapping.structure !== 'object') {
|
|
106
|
+
errors.push('structure is required and must be an object');
|
|
107
|
+
}
|
|
108
|
+
return errors;
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=ModelDrivenJsonMapping.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ModelDrivenJsonMapping.js","sourceRoot":"","sources":["../../../src/transformers/Model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O,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;YAC/B,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;QACnD,CAAC;IACL,CAAC;IAED,qBAAqB;IACrB,IAAI,CAAC,OAAO,CAAC,SAAS,IAAI,OAAO,OAAO,CAAC,SAAS,KAAK,QAAQ,EAAE,CAAC;QAC9D,MAAM,CAAC,IAAI,CAAC,6CAA6C,CAAC,CAAC;IAC/D,CAAC;IAED,OAAO,MAAM,CAAC;AAClB,CAAC"}
|
|
@@ -90,8 +90,87 @@ export declare class PostgresArrayEntityCteBuilder {
|
|
|
90
90
|
* @param entity The array entity being processed
|
|
91
91
|
* @param nestedEntities All nested entities from the mapping
|
|
92
92
|
* @param allEntities Map of all entities (not used in current implementation)
|
|
93
|
-
* @param useJsonb Whether to use JSONB functions
|
|
94
93
|
* @returns Object containing the JSON aggregation function
|
|
95
94
|
*/
|
|
96
95
|
private buildAggregationDetailsForArrayEntity;
|
|
96
|
+
/**
|
|
97
|
+
* Collects array entity columns organized by depth for the GROUP BY exclusion strategy.
|
|
98
|
+
*
|
|
99
|
+
* This method creates a mapping from depth levels to sets of column names that belong to
|
|
100
|
+
* array entities at each depth. This is used to determine which columns should be excluded
|
|
101
|
+
* from GROUP BY clauses when performing array aggregation at specific depths.
|
|
102
|
+
*
|
|
103
|
+
* @param mapping The JSON mapping configuration containing all entities
|
|
104
|
+
* @param currentDepth The current aggregation depth being processed
|
|
105
|
+
* @returns A map where keys are depth levels and values are sets of column names
|
|
106
|
+
*/
|
|
107
|
+
private collectArrayEntityColumnsByDepth;
|
|
108
|
+
/**
|
|
109
|
+
* Calculates the depth of an entity in the hierarchy by traversing up to the root.
|
|
110
|
+
*
|
|
111
|
+
* @param entity The entity to calculate depth for
|
|
112
|
+
* @param mapping The JSON mapping containing all entities
|
|
113
|
+
* @returns The depth level (0 for root level, 1 for first level, etc.)
|
|
114
|
+
*/
|
|
115
|
+
private calculateEntityDepth;
|
|
116
|
+
/**
|
|
117
|
+
* Adds all columns from an entity to the specified depth set.
|
|
118
|
+
*
|
|
119
|
+
* @param entity The entity whose columns should be added
|
|
120
|
+
* @param depth The depth level to add columns to
|
|
121
|
+
* @param arrayEntitiesByDepth The map to update
|
|
122
|
+
*/
|
|
123
|
+
private addEntityColumnsToDepthSet;
|
|
124
|
+
/**
|
|
125
|
+
* Recursively collects columns from all descendant entities under a parent entity.
|
|
126
|
+
*
|
|
127
|
+
* This method ensures that all nested entities (at any depth) under an array entity
|
|
128
|
+
* have their columns properly categorized by the array entity's depth level.
|
|
129
|
+
*
|
|
130
|
+
* @param parentEntityId The ID of the parent entity
|
|
131
|
+
* @param targetDepth The depth level to assign collected columns to
|
|
132
|
+
* @param mapping The JSON mapping containing all entities
|
|
133
|
+
* @param arrayEntitiesByDepth The map to update with collected columns
|
|
134
|
+
*/
|
|
135
|
+
private collectDescendantColumns;
|
|
136
|
+
/**
|
|
137
|
+
* Processes SELECT variables to determine which should be included in GROUP BY clauses.
|
|
138
|
+
*
|
|
139
|
+
* This method implements the core logic for deciding which columns from previous CTEs
|
|
140
|
+
* should be included in the GROUP BY clause when performing array aggregation. It handles
|
|
141
|
+
* special cases for JSON columns and applies depth-based filtering to prevent over-grouping.
|
|
142
|
+
*
|
|
143
|
+
* @param prevSelects SELECT variables from the previous CTE
|
|
144
|
+
* @param arrayColumns Columns that are being aggregated (should be excluded from GROUP BY)
|
|
145
|
+
* @param arrayEntitiesByDepth Map of depth levels to their column sets
|
|
146
|
+
* @param currentDepth The current aggregation depth being processed
|
|
147
|
+
* @param selectItems Output array for SELECT items
|
|
148
|
+
* @param groupByItems Output array for GROUP BY items
|
|
149
|
+
*/
|
|
150
|
+
private processSelectVariablesForGroupBy;
|
|
151
|
+
/**
|
|
152
|
+
* Determines whether a column should be included in the GROUP BY clause.
|
|
153
|
+
*
|
|
154
|
+
* This method applies depth-based filtering and special handling for JSON columns
|
|
155
|
+
* to prevent over-grouping during array aggregation. It implements heuristics for
|
|
156
|
+
* excluding columns that belong to nested entities within array contexts.
|
|
157
|
+
*
|
|
158
|
+
* @param columnName The name of the column to evaluate
|
|
159
|
+
* @param arrayEntitiesByDepth Map of depth levels to their column sets
|
|
160
|
+
* @param currentDepth The current aggregation depth
|
|
161
|
+
* @returns True if the column should be included in GROUP BY, false otherwise
|
|
162
|
+
*/
|
|
163
|
+
private shouldIncludeColumnInGroupBy;
|
|
164
|
+
/**
|
|
165
|
+
* Applies heuristics to determine if an entity JSON column should be included in GROUP BY.
|
|
166
|
+
*
|
|
167
|
+
* This method uses entity numbering patterns to identify deeply nested entities
|
|
168
|
+
* that should be excluded from GROUP BY when processing array aggregations.
|
|
169
|
+
* This is a simplified heuristic approach that works for current use cases.
|
|
170
|
+
*
|
|
171
|
+
* @param columnName The JSON column name (expected format: entity_N_json)
|
|
172
|
+
* @param currentDepth The current aggregation depth
|
|
173
|
+
* @returns True if the JSON column should be included, false otherwise
|
|
174
|
+
*/
|
|
175
|
+
private shouldIncludeJsonColumn;
|
|
97
176
|
}
|