rawsql-ts 0.11.1-beta → 0.11.2-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/dist/esm/index.js +7 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.min.js +45 -11
- package/dist/esm/index.min.js.map +4 -4
- package/dist/esm/src/index.js +7 -2
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/parsers/ValueParser.js +86 -4
- package/dist/esm/src/parsers/ValueParser.js.map +1 -1
- package/dist/esm/src/transformers/DynamicQueryBuilder.js.map +1 -1
- package/dist/esm/src/transformers/EnhancedJsonMapping.js +217 -0
- package/dist/esm/src/transformers/EnhancedJsonMapping.js.map +1 -0
- package/dist/esm/src/transformers/JsonMappingConverter.js +388 -0
- package/dist/esm/src/transformers/JsonMappingConverter.js.map +1 -0
- package/dist/esm/src/transformers/JsonMappingUnifier.js +36 -46
- package/dist/esm/src/transformers/JsonMappingUnifier.js.map +1 -1
- package/dist/esm/src/transformers/ModelDrivenJsonMapping.js +14 -2
- package/dist/esm/src/transformers/ModelDrivenJsonMapping.js.map +1 -1
- package/dist/esm/src/transformers/PostgresArrayEntityCteBuilder.js +132 -97
- package/dist/esm/src/transformers/PostgresArrayEntityCteBuilder.js.map +1 -1
- package/dist/esm/src/transformers/PostgresJsonQueryBuilder.js +21 -11
- package/dist/esm/src/transformers/PostgresJsonQueryBuilder.js.map +1 -1
- package/dist/esm/src/transformers/PostgresObjectEntityCteBuilder.js +71 -14
- package/dist/esm/src/transformers/PostgresObjectEntityCteBuilder.js.map +1 -1
- package/dist/esm/src/transformers/SqlParamInjector.js +189 -108
- package/dist/esm/src/transformers/SqlParamInjector.js.map +1 -1
- package/dist/esm/src/transformers/UpstreamSelectQueryFinder.js +43 -2
- package/dist/esm/src/transformers/UpstreamSelectQueryFinder.js.map +1 -1
- package/dist/esm/tsconfig.browser.tsbuildinfo +1 -1
- package/dist/esm/types/src/index.d.ts +7 -2
- package/dist/esm/types/src/parsers/ValueParser.d.ts +8 -0
- package/dist/esm/types/src/transformers/DynamicQueryBuilder.d.ts +6 -0
- package/dist/esm/types/src/transformers/EnhancedJsonMapping.d.ts +194 -0
- package/dist/esm/types/src/transformers/JsonMappingConverter.d.ts +200 -0
- package/dist/esm/types/src/transformers/JsonMappingUnifier.d.ts +5 -0
- package/dist/esm/types/src/transformers/PostgresArrayEntityCteBuilder.d.ts +39 -77
- package/dist/esm/types/src/transformers/PostgresJsonQueryBuilder.d.ts +3 -2
- package/dist/esm/types/src/transformers/PostgresObjectEntityCteBuilder.d.ts +31 -6
- package/dist/esm/types/src/transformers/SqlParamInjector.d.ts +48 -0
- package/dist/esm/types/src/transformers/UpstreamSelectQueryFinder.d.ts +8 -0
- package/dist/index.min.js +45 -11
- package/dist/index.min.js.map +4 -4
- package/dist/src/index.d.ts +7 -2
- package/dist/src/index.js +7 -3
- package/dist/src/index.js.map +1 -1
- package/dist/src/parsers/ValueParser.d.ts +8 -0
- package/dist/src/parsers/ValueParser.js +86 -4
- package/dist/src/parsers/ValueParser.js.map +1 -1
- package/dist/src/transformers/DynamicQueryBuilder.d.ts +6 -0
- package/dist/src/transformers/DynamicQueryBuilder.js.map +1 -1
- package/dist/src/transformers/EnhancedJsonMapping.d.ts +194 -0
- package/dist/src/transformers/EnhancedJsonMapping.js +223 -0
- package/dist/src/transformers/EnhancedJsonMapping.js.map +1 -0
- package/dist/src/transformers/JsonMappingConverter.d.ts +200 -0
- package/dist/src/transformers/JsonMappingConverter.js +392 -0
- package/dist/src/transformers/JsonMappingConverter.js.map +1 -0
- package/dist/src/transformers/JsonMappingUnifier.d.ts +5 -0
- package/dist/src/transformers/JsonMappingUnifier.js +36 -46
- package/dist/src/transformers/JsonMappingUnifier.js.map +1 -1
- package/dist/src/transformers/ModelDrivenJsonMapping.js +14 -2
- package/dist/src/transformers/ModelDrivenJsonMapping.js.map +1 -1
- package/dist/src/transformers/PostgresArrayEntityCteBuilder.d.ts +39 -77
- package/dist/src/transformers/PostgresArrayEntityCteBuilder.js +132 -97
- package/dist/src/transformers/PostgresArrayEntityCteBuilder.js.map +1 -1
- package/dist/src/transformers/PostgresJsonQueryBuilder.d.ts +3 -2
- package/dist/src/transformers/PostgresJsonQueryBuilder.js +21 -11
- package/dist/src/transformers/PostgresJsonQueryBuilder.js.map +1 -1
- package/dist/src/transformers/PostgresObjectEntityCteBuilder.d.ts +31 -6
- package/dist/src/transformers/PostgresObjectEntityCteBuilder.js +71 -14
- package/dist/src/transformers/PostgresObjectEntityCteBuilder.js.map +1 -1
- package/dist/src/transformers/SqlParamInjector.d.ts +48 -0
- package/dist/src/transformers/SqlParamInjector.js +189 -108
- package/dist/src/transformers/SqlParamInjector.js.map +1 -1
- package/dist/src/transformers/UpstreamSelectQueryFinder.d.ts +8 -0
- package/dist/src/transformers/UpstreamSelectQueryFinder.js +43 -2
- package/dist/src/transformers/UpstreamSelectQueryFinder.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified JSON mapping converter that handles all supported formats
|
|
3
|
+
* and provides a single interface for mapping transformations.
|
|
4
|
+
*/
|
|
5
|
+
import { convertModelDrivenMapping } from './ModelDrivenJsonMapping';
|
|
6
|
+
import { toLegacyMapping, extractTypeProtection } from './EnhancedJsonMapping';
|
|
7
|
+
/**
|
|
8
|
+
* Type guard to check if input is valid JSON mapping input
|
|
9
|
+
*/
|
|
10
|
+
function isValidMappingInput(input) {
|
|
11
|
+
return input !== null &&
|
|
12
|
+
input !== undefined &&
|
|
13
|
+
typeof input === 'object';
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Enhanced format conversion strategy.
|
|
17
|
+
*/
|
|
18
|
+
class EnhancedFormatStrategy {
|
|
19
|
+
detect(input) {
|
|
20
|
+
if (!isValidMappingInput(input)) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
const candidate = input;
|
|
24
|
+
if (!candidate ||
|
|
25
|
+
typeof candidate.rootName !== 'string' ||
|
|
26
|
+
!candidate.rootEntity ||
|
|
27
|
+
!Array.isArray(candidate.nestedEntities)) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
// Check if it has enhanced features
|
|
31
|
+
if (candidate.typeInfo || candidate.typeProtection || candidate.metadata) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
// Check if any column uses enhanced format (object with 'column' property)
|
|
35
|
+
const hasEnhancedColumns = (columns) => {
|
|
36
|
+
if (!columns || typeof columns !== 'object')
|
|
37
|
+
return false;
|
|
38
|
+
return Object.values(columns).some(col => typeof col === 'object' && col !== null && 'column' in col);
|
|
39
|
+
};
|
|
40
|
+
if (hasEnhancedColumns(candidate.rootEntity.columns)) {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
return candidate.nestedEntities.some((entity) => entity && typeof entity === 'object' &&
|
|
44
|
+
hasEnhancedColumns(entity.columns));
|
|
45
|
+
}
|
|
46
|
+
convert(input) {
|
|
47
|
+
var _a, _b;
|
|
48
|
+
return {
|
|
49
|
+
format: 'enhanced',
|
|
50
|
+
mapping: toLegacyMapping(input),
|
|
51
|
+
typeProtection: extractTypeProtection(input),
|
|
52
|
+
originalInput: input,
|
|
53
|
+
metadata: {
|
|
54
|
+
typeInfo: input.typeInfo,
|
|
55
|
+
version: (_a = input.metadata) === null || _a === void 0 ? void 0 : _a.version,
|
|
56
|
+
description: (_b = input.metadata) === null || _b === void 0 ? void 0 : _b.description
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Model-driven format conversion strategy.
|
|
63
|
+
*/
|
|
64
|
+
class ModelDrivenFormatStrategy {
|
|
65
|
+
detect(input) {
|
|
66
|
+
if (!isValidMappingInput(input)) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
const candidate = input;
|
|
70
|
+
return candidate &&
|
|
71
|
+
candidate.typeInfo &&
|
|
72
|
+
candidate.structure &&
|
|
73
|
+
typeof candidate.typeInfo.interface === 'string';
|
|
74
|
+
}
|
|
75
|
+
convert(input) {
|
|
76
|
+
// Use the existing convertModelDrivenMapping function to avoid code duplication
|
|
77
|
+
const converted = convertModelDrivenMapping(input);
|
|
78
|
+
return {
|
|
79
|
+
format: 'model-driven',
|
|
80
|
+
mapping: converted.jsonMapping,
|
|
81
|
+
typeProtection: converted.typeProtection,
|
|
82
|
+
originalInput: input,
|
|
83
|
+
metadata: {
|
|
84
|
+
typeInfo: input.typeInfo
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Legacy format conversion strategy.
|
|
91
|
+
*/
|
|
92
|
+
class LegacyFormatStrategy {
|
|
93
|
+
detect(input) {
|
|
94
|
+
if (!isValidMappingInput(input)) {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
const candidate = input;
|
|
98
|
+
if (!candidate ||
|
|
99
|
+
typeof candidate.rootName !== 'string' ||
|
|
100
|
+
!candidate.rootEntity ||
|
|
101
|
+
typeof candidate.rootEntity.columns !== 'object' ||
|
|
102
|
+
candidate.typeInfo || candidate.typeProtection || candidate.metadata) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
// Check if any column uses enhanced format (object with 'column' property)
|
|
106
|
+
const hasEnhancedColumns = (columns) => {
|
|
107
|
+
if (!columns || typeof columns !== 'object')
|
|
108
|
+
return false;
|
|
109
|
+
return Object.values(columns).some(col => typeof col === 'object' && col !== null && 'column' in col);
|
|
110
|
+
};
|
|
111
|
+
// If it has enhanced columns, it's not legacy format
|
|
112
|
+
if (hasEnhancedColumns(candidate.rootEntity.columns)) {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
if (candidate.nestedEntities && Array.isArray(candidate.nestedEntities)) {
|
|
116
|
+
const hasEnhancedNested = candidate.nestedEntities.some((entity) => entity && typeof entity === 'object' && hasEnhancedColumns(entity.columns));
|
|
117
|
+
if (hasEnhancedNested) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
convert(input) {
|
|
124
|
+
return {
|
|
125
|
+
format: 'legacy',
|
|
126
|
+
mapping: input,
|
|
127
|
+
typeProtection: { protectedStringFields: [] },
|
|
128
|
+
originalInput: input
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Unified JSON mapping converter that handles all supported formats using the Strategy pattern.
|
|
134
|
+
*
|
|
135
|
+
* This converter automatically detects the input format and applies the appropriate conversion
|
|
136
|
+
* strategy to transform any supported JSON mapping format into a standardized result.
|
|
137
|
+
*
|
|
138
|
+
* **Supported Formats:**
|
|
139
|
+
* - **Enhanced**: Rich format with metadata, type protection, and advanced column configurations
|
|
140
|
+
* - **Model-Driven**: TypeScript interface-based mapping with structured field definitions
|
|
141
|
+
* - **Legacy**: Simple format compatible with PostgresJsonQueryBuilder
|
|
142
|
+
*
|
|
143
|
+
* **Usage:**
|
|
144
|
+
* ```typescript
|
|
145
|
+
* const converter = new JsonMappingConverter();
|
|
146
|
+
* const result = converter.convert(someMapping);
|
|
147
|
+
* const legacyMapping = converter.toLegacyMapping(someMapping);
|
|
148
|
+
* ```
|
|
149
|
+
*
|
|
150
|
+
* @public
|
|
151
|
+
*/
|
|
152
|
+
export class JsonMappingConverter {
|
|
153
|
+
/**
|
|
154
|
+
* Creates a new JsonMappingConverter with all supported strategies.
|
|
155
|
+
*
|
|
156
|
+
* Strategies are checked in order of specificity:
|
|
157
|
+
* 1. Enhanced format (most feature-rich)
|
|
158
|
+
* 2. Model-driven format (TypeScript-based)
|
|
159
|
+
* 3. Legacy format (fallback)
|
|
160
|
+
*/
|
|
161
|
+
constructor() {
|
|
162
|
+
this.strategies = [
|
|
163
|
+
new EnhancedFormatStrategy(),
|
|
164
|
+
new ModelDrivenFormatStrategy(),
|
|
165
|
+
new LegacyFormatStrategy()
|
|
166
|
+
];
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Detects the format of the input mapping without performing conversion.
|
|
170
|
+
*
|
|
171
|
+
* This method uses the same strategy pattern as conversion but only returns
|
|
172
|
+
* the detected format type for inspection purposes.
|
|
173
|
+
*
|
|
174
|
+
* @param input - The JSON mapping to analyze
|
|
175
|
+
* @returns The detected mapping format type
|
|
176
|
+
*
|
|
177
|
+
* @throws {Error} When input format is not supported by any strategy
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```typescript
|
|
181
|
+
* const format = converter.detectFormat(myMapping);
|
|
182
|
+
* console.log(`Detected format: ${format}`); // "enhanced", "model-driven", or "legacy"
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
detectFormat(input) {
|
|
186
|
+
for (const strategy of this.strategies) {
|
|
187
|
+
if (strategy.detect(input)) {
|
|
188
|
+
const result = strategy.convert(input);
|
|
189
|
+
return result.format;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
throw new Error('Unsupported JSON mapping format');
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Converts any supported JSON mapping format to a comprehensive result with metadata.
|
|
196
|
+
*
|
|
197
|
+
* This is the primary conversion method that performs format detection and transformation
|
|
198
|
+
* in a single operation. The result includes the legacy mapping, type protection configuration,
|
|
199
|
+
* and metadata about the conversion process.
|
|
200
|
+
*
|
|
201
|
+
* @param input - The JSON mapping in any supported format (Enhanced, Model-Driven, or Legacy)
|
|
202
|
+
* @returns Complete conversion result with mapping, metadata, and type protection
|
|
203
|
+
*
|
|
204
|
+
* @throws {Error} When the input format is not recognized by any strategy
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```typescript
|
|
208
|
+
* const result = converter.convert(enhancedMapping);
|
|
209
|
+
* console.log(`Format: ${result.format}`);
|
|
210
|
+
* console.log(`Type protection: ${result.typeProtection.protectedStringFields.length} fields`);
|
|
211
|
+
*
|
|
212
|
+
* // Use the converted mapping
|
|
213
|
+
* const queryBuilder = new PostgresJsonQueryBuilder(result.mapping);
|
|
214
|
+
* ```
|
|
215
|
+
*
|
|
216
|
+
* @see {@link toLegacyMapping} For simple mapping extraction
|
|
217
|
+
* @see {@link getTypeProtection} For type protection only
|
|
218
|
+
*/
|
|
219
|
+
convert(input) {
|
|
220
|
+
for (const strategy of this.strategies) {
|
|
221
|
+
if (strategy.detect(input)) {
|
|
222
|
+
return strategy.convert(input);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
throw new Error('Unsupported JSON mapping format: Unable to detect a compatible strategy for the provided input');
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Extracts only the legacy JsonMapping for direct use with PostgresJsonQueryBuilder.
|
|
229
|
+
*
|
|
230
|
+
* This convenience method performs the full conversion but returns only the mapping portion,
|
|
231
|
+
* discarding metadata and type protection information. Use this when you only need
|
|
232
|
+
* the mapping for query building and don't require additional metadata.
|
|
233
|
+
*
|
|
234
|
+
* @param input - The JSON mapping in any supported format
|
|
235
|
+
* @returns Legacy-format JsonMapping ready for PostgresJsonQueryBuilder
|
|
236
|
+
*
|
|
237
|
+
* @throws {Error} When the input format is not supported
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* ```typescript
|
|
241
|
+
* const legacyMapping = converter.toLegacyMapping(modelDrivenMapping);
|
|
242
|
+
* const queryBuilder = new PostgresJsonQueryBuilder(legacyMapping);
|
|
243
|
+
* const query = queryBuilder.build(selectQuery);
|
|
244
|
+
* ```
|
|
245
|
+
*
|
|
246
|
+
* @see {@link convert} For full conversion with metadata
|
|
247
|
+
*/
|
|
248
|
+
toLegacyMapping(input) {
|
|
249
|
+
return this.convert(input).mapping;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Extracts type protection configuration for runtime type checking.
|
|
253
|
+
*
|
|
254
|
+
* Type protection helps identify fields that should be treated as strings
|
|
255
|
+
* to prevent injection attacks or type coercion issues. This is particularly
|
|
256
|
+
* useful when working with user input or external data sources.
|
|
257
|
+
*
|
|
258
|
+
* @param input - The JSON mapping in any supported format
|
|
259
|
+
* @returns Type protection configuration with protected field definitions
|
|
260
|
+
*
|
|
261
|
+
* @throws {Error} When the input format is not supported
|
|
262
|
+
*
|
|
263
|
+
* @example
|
|
264
|
+
* ```typescript
|
|
265
|
+
* const typeProtection = converter.getTypeProtection(enhancedMapping);
|
|
266
|
+
*
|
|
267
|
+
* // Apply type protection during data processing
|
|
268
|
+
* for (const field of typeProtection.protectedStringFields) {
|
|
269
|
+
* if (typeof data[field] !== 'string') {
|
|
270
|
+
* data[field] = String(data[field]);
|
|
271
|
+
* }
|
|
272
|
+
* }
|
|
273
|
+
* ```
|
|
274
|
+
*/
|
|
275
|
+
getTypeProtection(input) {
|
|
276
|
+
return this.convert(input).typeProtection;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Validates that the input mapping is well-formed and can be successfully converted.
|
|
280
|
+
*
|
|
281
|
+
* This method performs comprehensive validation without attempting conversion,
|
|
282
|
+
* returning an array of error messages for any issues found. An empty array
|
|
283
|
+
* indicates the mapping is valid and ready for conversion.
|
|
284
|
+
*
|
|
285
|
+
* **Validation Checks:**
|
|
286
|
+
* - Basic structure validation (object type, required fields)
|
|
287
|
+
* - Format-specific validation (Enhanced, Model-Driven, Legacy)
|
|
288
|
+
* - Column configuration validation
|
|
289
|
+
* - Type protection configuration validation
|
|
290
|
+
*
|
|
291
|
+
* @param input - The JSON mapping to validate
|
|
292
|
+
* @returns Array of validation error messages (empty if valid)
|
|
293
|
+
*
|
|
294
|
+
* @example
|
|
295
|
+
* ```typescript
|
|
296
|
+
* const errors = converter.validate(suspiciousMapping);
|
|
297
|
+
* if (errors.length > 0) {
|
|
298
|
+
* console.error('Validation failed:', errors);
|
|
299
|
+
* throw new Error(`Invalid mapping: ${errors.join(', ')}`);
|
|
300
|
+
* }
|
|
301
|
+
*
|
|
302
|
+
* // Safe to convert
|
|
303
|
+
* const result = converter.convert(suspiciousMapping);
|
|
304
|
+
* ```
|
|
305
|
+
*
|
|
306
|
+
* @see {@link convert} Performs conversion after implicit validation
|
|
307
|
+
*/
|
|
308
|
+
validate(input) {
|
|
309
|
+
const errors = [];
|
|
310
|
+
// Pre-validation checks
|
|
311
|
+
if (!input || typeof input !== 'object') {
|
|
312
|
+
errors.push('Input must be an object');
|
|
313
|
+
return errors;
|
|
314
|
+
}
|
|
315
|
+
// Check for rootName before attempting conversion
|
|
316
|
+
if (!('rootName' in input) || !input.rootName) {
|
|
317
|
+
errors.push('rootName is required');
|
|
318
|
+
}
|
|
319
|
+
try {
|
|
320
|
+
const result = this.convert(input);
|
|
321
|
+
// Basic validation
|
|
322
|
+
if (!result.mapping.rootName) {
|
|
323
|
+
errors.push('rootName is required');
|
|
324
|
+
}
|
|
325
|
+
if (!result.mapping.rootEntity) {
|
|
326
|
+
errors.push('rootEntity is required');
|
|
327
|
+
}
|
|
328
|
+
else {
|
|
329
|
+
if (!result.mapping.rootEntity.id) {
|
|
330
|
+
errors.push('rootEntity.id is required');
|
|
331
|
+
}
|
|
332
|
+
if (!result.mapping.rootEntity.columns) {
|
|
333
|
+
errors.push('rootEntity.columns is required');
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
// Validate nested entities
|
|
337
|
+
if (result.mapping.nestedEntities) {
|
|
338
|
+
for (const entity of result.mapping.nestedEntities) {
|
|
339
|
+
if (!entity.id) {
|
|
340
|
+
errors.push(`Nested entity missing id: ${entity.propertyName}`);
|
|
341
|
+
}
|
|
342
|
+
if (!entity.parentId) {
|
|
343
|
+
errors.push(`Nested entity missing parentId: ${entity.id}`);
|
|
344
|
+
}
|
|
345
|
+
if (!entity.propertyName) {
|
|
346
|
+
errors.push(`Nested entity missing propertyName: ${entity.id}`);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
catch (error) {
|
|
352
|
+
// Only add conversion error if we haven't already found specific errors
|
|
353
|
+
if (errors.length === 0) {
|
|
354
|
+
errors.push(`Conversion failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
return errors;
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Creates a new enhanced mapping from legacy mapping.
|
|
361
|
+
*/
|
|
362
|
+
upgradeToEnhanced(legacy, typeInfo) {
|
|
363
|
+
return {
|
|
364
|
+
rootName: legacy.rootName,
|
|
365
|
+
rootEntity: {
|
|
366
|
+
id: legacy.rootEntity.id,
|
|
367
|
+
name: legacy.rootEntity.name,
|
|
368
|
+
columns: legacy.rootEntity.columns
|
|
369
|
+
},
|
|
370
|
+
nestedEntities: legacy.nestedEntities.map(entity => ({
|
|
371
|
+
id: entity.id,
|
|
372
|
+
name: entity.name,
|
|
373
|
+
parentId: entity.parentId,
|
|
374
|
+
propertyName: entity.propertyName,
|
|
375
|
+
relationshipType: entity.relationshipType || 'object',
|
|
376
|
+
columns: entity.columns
|
|
377
|
+
})),
|
|
378
|
+
resultFormat: legacy.resultFormat,
|
|
379
|
+
emptyResult: legacy.emptyResult,
|
|
380
|
+
typeInfo,
|
|
381
|
+
metadata: {
|
|
382
|
+
version: '1.0',
|
|
383
|
+
description: 'Upgraded from legacy format'
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
//# sourceMappingURL=JsonMappingConverter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JsonMappingConverter.js","sourceRoot":"","sources":["../../../../src/transformers/JsonMappingConverter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAA0B,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AAC7F,OAAO,EAAgE,eAAe,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AA+C7I;;GAE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AAE,CAAC,CAAC;gBACjD,EAAE,EAAE,MAAM,CAAC,EAAE;gBACb,IAAI,EAAE,MAAM,CAAC,IAAI;gBACjB,QAAQ,EAAE,MAAM,CAAC,QAAQ;gBACzB,YAAY,EAAE,MAAM,CAAC,YAAY;gBACjC,gBAAgB,EAAE,MAAM,CAAC,gBAAgB,IAAI,QAAQ;gBACrD,OAAO,EAAE,MAAM,CAAC,OAAO;aAC1B,CAAC,CAAC;YACH,YAAY,EAAE,MAAM,CAAC,YAAY;YACjC,WAAW,EAAE,MAAM,CAAC,WAAW;YAC/B,QAAQ;YACR,QAAQ,EAAE;gBACN,OAAO,EAAE,KAAK;gBACd,WAAW,EAAE,6BAA6B;aAC7C;SACJ,CAAC;IACN,CAAC;CACJ"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Unified JSON Mapping processor that supports both legacy and model-driven formats.
|
|
3
3
|
*
|
|
4
|
+
* @deprecated Use JsonMappingConverter instead. This module is kept for backward compatibility.
|
|
4
5
|
* This module provides backward compatibility while encouraging migration to the model-driven format.
|
|
5
6
|
* It automatically detects the input format and normalizes to a consistent internal representation.
|
|
6
7
|
*/
|
|
7
|
-
import {
|
|
8
|
+
import { JsonMappingConverter } from './JsonMappingConverter';
|
|
8
9
|
/**
|
|
9
10
|
* Detects the format of a JSON mapping configuration.
|
|
10
11
|
*
|
|
@@ -95,6 +96,8 @@ function convertLegacyFormat(input) {
|
|
|
95
96
|
/**
|
|
96
97
|
* Main processor that unifies all JSON mapping formats into a consistent JsonMapping.
|
|
97
98
|
*
|
|
99
|
+
* @deprecated Use JsonMappingConverter.convert() instead.
|
|
100
|
+
*
|
|
98
101
|
* Features:
|
|
99
102
|
* - Automatic format detection
|
|
100
103
|
* - Backward compatibility with all existing formats
|
|
@@ -105,65 +108,52 @@ function convertLegacyFormat(input) {
|
|
|
105
108
|
* @returns Unified processing result with JsonMapping and metadata
|
|
106
109
|
*/
|
|
107
110
|
export function processJsonMapping(input) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
if (!input.typeInfo || !input.structure) {
|
|
116
|
-
throw new Error('Model-driven format requires typeInfo and structure fields');
|
|
117
|
-
}
|
|
118
|
-
// Convert model-driven to JsonMapping
|
|
119
|
-
const modelDrivenInput = {
|
|
120
|
-
typeInfo: input.typeInfo,
|
|
121
|
-
structure: input.structure
|
|
122
|
-
};
|
|
123
|
-
const converted = convertModelDrivenMapping(modelDrivenInput);
|
|
124
|
-
jsonMapping = converted.jsonMapping;
|
|
125
|
-
// Preserve metadata
|
|
126
|
-
metadata = {
|
|
127
|
-
typeInfo: input.typeInfo,
|
|
128
|
-
typeProtection: converted.typeProtection
|
|
129
|
-
};
|
|
130
|
-
break;
|
|
131
|
-
case 'unified':
|
|
132
|
-
// Validate unified input
|
|
133
|
-
if (!input.rootEntity) {
|
|
134
|
-
throw new Error('Unified format requires rootEntity field');
|
|
135
|
-
}
|
|
136
|
-
jsonMapping = convertUnifiedFormat(input);
|
|
137
|
-
break;
|
|
138
|
-
case 'legacy':
|
|
139
|
-
// Validate legacy input
|
|
140
|
-
if (!input.columns && !input.relationships) {
|
|
141
|
-
throw new Error('Legacy format requires at least columns or relationships field');
|
|
142
|
-
}
|
|
143
|
-
jsonMapping = convertLegacyFormat(input);
|
|
144
|
-
break;
|
|
145
|
-
default:
|
|
146
|
-
throw new Error(`Unsupported mapping format: ${format}`);
|
|
147
|
-
}
|
|
111
|
+
var _a;
|
|
112
|
+
// Runtime deprecation warning
|
|
113
|
+
console.warn('⚠️ DEPRECATED: processJsonMapping() is deprecated. Use JsonMappingConverter.convert() instead.');
|
|
114
|
+
console.warn('Migration guide: https://github.com/mk3008/rawsql-ts/blob/main/docs/migration-guide.md');
|
|
115
|
+
// Check for legacy format with columns and relationships
|
|
116
|
+
if ((input.columns || input.relationships) && !input.rootName && !input.rootEntity) {
|
|
117
|
+
const jsonMapping = convertLegacyFormat(input);
|
|
148
118
|
return {
|
|
149
|
-
format,
|
|
119
|
+
format: 'legacy',
|
|
150
120
|
jsonMapping,
|
|
151
121
|
originalInput: input,
|
|
152
|
-
metadata
|
|
122
|
+
metadata: {}
|
|
153
123
|
};
|
|
154
124
|
}
|
|
155
|
-
|
|
156
|
-
|
|
125
|
+
const converter = new JsonMappingConverter();
|
|
126
|
+
const result = converter.convert(input);
|
|
127
|
+
// Map converter formats to unifier formats for backward compatibility
|
|
128
|
+
let format = result.format;
|
|
129
|
+
// If it's detected as 'legacy' by converter but has rootName and rootEntity, it's 'unified' format
|
|
130
|
+
if (result.format === 'legacy' && input.rootName && input.rootEntity) {
|
|
131
|
+
format = 'unified';
|
|
157
132
|
}
|
|
133
|
+
return {
|
|
134
|
+
format,
|
|
135
|
+
jsonMapping: result.mapping,
|
|
136
|
+
originalInput: input,
|
|
137
|
+
metadata: {
|
|
138
|
+
typeInfo: (_a = result.metadata) === null || _a === void 0 ? void 0 : _a.typeInfo,
|
|
139
|
+
typeProtection: result.typeProtection
|
|
140
|
+
}
|
|
141
|
+
};
|
|
158
142
|
}
|
|
159
143
|
/**
|
|
160
144
|
* Convenience function for direct JsonMapping extraction.
|
|
161
145
|
*
|
|
146
|
+
* @deprecated Use JsonMappingConverter.toLegacyMapping() instead.
|
|
147
|
+
*
|
|
162
148
|
* @param input - Any supported JSON mapping format
|
|
163
149
|
* @returns JsonMapping ready for use with PostgresJsonQueryBuilder
|
|
164
150
|
*/
|
|
165
151
|
export function unifyJsonMapping(input) {
|
|
166
|
-
|
|
152
|
+
// Runtime deprecation warning
|
|
153
|
+
console.warn('⚠️ DEPRECATED: unifyJsonMapping() is deprecated. Use JsonMappingConverter.toLegacyMapping() instead.');
|
|
154
|
+
console.warn('Migration guide: https://github.com/mk3008/rawsql-ts/blob/main/docs/migration-guide.md');
|
|
155
|
+
const converter = new JsonMappingConverter();
|
|
156
|
+
return converter.toLegacyMapping(input);
|
|
167
157
|
}
|
|
168
158
|
/**
|
|
169
159
|
* Type guard to check if input uses model-driven format.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JsonMappingUnifier.js","sourceRoot":"","sources":["../../../../src/transformers/JsonMappingUnifier.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"JsonMappingUnifier.js","sourceRoot":"","sources":["../../../../src/transformers/JsonMappingUnifier.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,EAAE,oBAAoB,EAAoB,MAAM,wBAAwB,CAAC;AAyChF;;;;;GAKG;AACH,MAAM,UAAU,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;IACnB,OAAO,QAAQ,CAAC;AACpB,CAAC;AAED;;;;;GAKG;AACH,SAAS,oBAAoB,CAAC,KAA0B;IACpD,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;IAC1D,CAAC;IAED,MAAM,MAAM,GAAgB;QACxB,QAAQ,EAAE,KAAK,CAAC,QAAQ,IAAI,MAAM;QAClC,UAAU,EAAE;YACR,EAAE,EAAE,KAAK,CAAC,UAAU,CAAC,EAAE,IAAI,MAAM;YACjC,IAAI,EAAE,KAAK,CAAC,UAAU,CAAC,IAAI,IAAI,MAAM;YACrC,OAAO,EAAE,KAAK,CAAC,UAAU,CAAC,OAAO,IAAI,EAA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,CAAC;QAC3E,WAAW,CAAC,IAAI,CAAC,oEAAoE,CAAC,CAAC;QACvF,WAAW,CAAC,IAAI,CAAC,iEAAiE,CAAC,CAAC;QAEpF,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACvB,WAAW,CAAC,IAAI,CAAC,4DAA4D,CAAC,CAAC;QACnF,CAAC;QAED,IAAI,MAAM,KAAK,QAAQ,EAAE,CAAC;YACtB,WAAW,CAAC,IAAI,CAAC,sFAAsF,CAAC,CAAC;QAC7G,CAAC;IACL,CAAC;IAED,OAAO,WAAW,CAAC;AACvB,CAAC"}
|
|
@@ -9,8 +9,17 @@
|
|
|
9
9
|
export function convertModelDrivenMapping(modelMapping) {
|
|
10
10
|
const protectedStringFields = [];
|
|
11
11
|
let entityIdCounter = 0;
|
|
12
|
+
const propertyNameCounters = {};
|
|
12
13
|
// Generate unique entity IDs
|
|
13
14
|
const generateEntityId = () => `entity_${++entityIdCounter}`;
|
|
15
|
+
// Generate unique property names to avoid JSON key conflicts
|
|
16
|
+
const generateUniquePropertyName = (baseName) => {
|
|
17
|
+
if (!propertyNameCounters[baseName]) {
|
|
18
|
+
propertyNameCounters[baseName] = 0;
|
|
19
|
+
}
|
|
20
|
+
propertyNameCounters[baseName]++;
|
|
21
|
+
return propertyNameCounters[baseName] === 1 ? baseName : `${baseName}_${propertyNameCounters[baseName]}`;
|
|
22
|
+
};
|
|
14
23
|
// Helper function to process structure fields and extract entities
|
|
15
24
|
const processStructure = (structure, parentId = null) => {
|
|
16
25
|
const columns = {};
|
|
@@ -43,13 +52,16 @@ export function convertModelDrivenMapping(modelMapping) {
|
|
|
43
52
|
else if ('type' in config && (config.type === 'object' || config.type === 'array')) {
|
|
44
53
|
// Nested structure: object or array
|
|
45
54
|
const nestedStructure = config;
|
|
55
|
+
const uniquePropertyName = generateUniquePropertyName(fieldName);
|
|
56
|
+
// Generate globally unique entity ID to ensure unique JSON column names
|
|
46
57
|
const entityId = generateEntityId();
|
|
47
58
|
const processedNested = processStructure(nestedStructure.structure, entityId);
|
|
48
59
|
nestedEntities.push({
|
|
49
|
-
id: entityId,
|
|
60
|
+
id: entityId, // Use unique ID to avoid column conflicts
|
|
50
61
|
name: fieldName.charAt(0).toUpperCase() + fieldName.slice(1), // Capitalize first letter
|
|
51
62
|
parentId: parentId || 'root',
|
|
52
|
-
propertyName:
|
|
63
|
+
propertyName: uniquePropertyName,
|
|
64
|
+
originalPropertyName: fieldName, // Store original name for final mapping
|
|
53
65
|
relationshipType: nestedStructure.type,
|
|
54
66
|
columns: processedNested.columns
|
|
55
67
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModelDrivenJsonMapping.js","sourceRoot":"","sources":["../../../../src/transformers/ModelDrivenJsonMapping.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAuDH;;;GAGG;AACH,MAAM,UAAU,yBAAyB,CAAC,YAAoC;IAI1E,MAAM,qBAAqB,GAAa,EAAE,CAAC;IAC3C,IAAI,eAAe,GAAG,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"ModelDrivenJsonMapping.js","sourceRoot":"","sources":["../../../../src/transformers/ModelDrivenJsonMapping.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAuDH;;;GAGG;AACH,MAAM,UAAU,yBAAyB,CAAC,YAAoC;IAI1E,MAAM,qBAAqB,GAAa,EAAE,CAAC;IAC3C,IAAI,eAAe,GAAG,CAAC,CAAC;IACxB,MAAM,oBAAoB,GAA2B,EAAE,CAAC;IAExD,6BAA6B;IAC7B,MAAM,gBAAgB,GAAG,GAAG,EAAE,CAAC,UAAU,EAAE,eAAe,EAAE,CAAC;IAE7D,6DAA6D;IAC7D,MAAM,0BAA0B,GAAG,CAAC,QAAgB,EAAU,EAAE;QAC5D,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAAC,EAAE,CAAC;YAClC,oBAAoB,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QACvC,CAAC;QACD,oBAAoB,CAAC,QAAQ,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