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,200 +0,0 @@
1
- /**
2
- * Unified JSON mapping converter that handles all supported formats
3
- * and provides a single interface for mapping transformations.
4
- */
5
- import { JsonMapping } from './PostgresJsonQueryBuilder';
6
- import { ModelDrivenJsonMapping } from './ModelDrivenJsonMapping';
7
- import { EnhancedJsonMapping, LegacyJsonMapping, TypeProtectionConfig } from './EnhancedJsonMapping';
8
- /**
9
- * Input format types that the converter can handle.
10
- */
11
- export type JsonMappingInput = EnhancedJsonMapping | ModelDrivenJsonMapping | LegacyJsonMapping;
12
- /**
13
- * Format detection result.
14
- */
15
- export type MappingFormat = 'enhanced' | 'model-driven' | 'legacy';
16
- /**
17
- * Conversion result with metadata.
18
- */
19
- export interface ConversionResult {
20
- /** Detected input format */
21
- format: MappingFormat;
22
- /** Converted legacy mapping for PostgresJsonQueryBuilder */
23
- mapping: JsonMapping;
24
- /** Type protection configuration */
25
- typeProtection: TypeProtectionConfig;
26
- /** Original input for reference */
27
- originalInput: JsonMappingInput;
28
- /** Additional metadata */
29
- metadata?: {
30
- typeInfo?: {
31
- interface: string;
32
- importPath: string;
33
- generics?: string[];
34
- };
35
- version?: string;
36
- description?: string;
37
- };
38
- }
39
- /**
40
- * Unified JSON mapping converter that handles all supported formats using the Strategy pattern.
41
- *
42
- * This converter automatically detects the input format and applies the appropriate conversion
43
- * strategy to transform any supported JSON mapping format into a standardized result.
44
- *
45
- * **Supported Formats:**
46
- * - **Enhanced**: Rich format with metadata, type protection, and advanced column configurations
47
- * - **Model-Driven**: TypeScript interface-based mapping with structured field definitions
48
- * - **Legacy**: Simple format compatible with PostgresJsonQueryBuilder
49
- *
50
- * **Usage:**
51
- * ```typescript
52
- * const converter = new JsonMappingConverter();
53
- * const result = converter.convert(someMapping);
54
- * const legacyMapping = converter.toLegacyMapping(someMapping);
55
- * ```
56
- *
57
- * @public
58
- */
59
- export declare class JsonMappingConverter {
60
- /** Ordered list of conversion strategies, checked in priority order */
61
- private strategies;
62
- /**
63
- * Creates a new JsonMappingConverter with all supported strategies.
64
- *
65
- * Strategies are checked in order of specificity:
66
- * 1. Enhanced format (most feature-rich)
67
- * 2. Model-driven format (TypeScript-based)
68
- * 3. Legacy format (fallback)
69
- */
70
- constructor();
71
- /**
72
- * Detects the format of the input mapping without performing conversion.
73
- *
74
- * This method uses the same strategy pattern as conversion but only returns
75
- * the detected format type for inspection purposes.
76
- *
77
- * @param input - The JSON mapping to analyze
78
- * @returns The detected mapping format type
79
- *
80
- * @throws {Error} When input format is not supported by any strategy
81
- *
82
- * @example
83
- * ```typescript
84
- * const format = converter.detectFormat(myMapping);
85
- * console.log(`Detected format: ${format}`); // "enhanced", "model-driven", or "legacy"
86
- * ```
87
- */
88
- detectFormat(input: JsonMappingInput): MappingFormat;
89
- /**
90
- * Converts any supported JSON mapping format to a comprehensive result with metadata.
91
- *
92
- * This is the primary conversion method that performs format detection and transformation
93
- * in a single operation. The result includes the legacy mapping, type protection configuration,
94
- * and metadata about the conversion process.
95
- *
96
- * @param input - The JSON mapping in any supported format (Enhanced, Model-Driven, or Legacy)
97
- * @returns Complete conversion result with mapping, metadata, and type protection
98
- *
99
- * @throws {Error} When the input format is not recognized by any strategy
100
- *
101
- * @example
102
- * ```typescript
103
- * const result = converter.convert(enhancedMapping);
104
- * console.log(`Format: ${result.format}`);
105
- * console.log(`Type protection: ${result.typeProtection.protectedStringFields.length} fields`);
106
- *
107
- * // Use the converted mapping
108
- * const queryBuilder = new PostgresJsonQueryBuilder(result.mapping);
109
- * ```
110
- *
111
- * @see {@link toLegacyMapping} For simple mapping extraction
112
- * @see {@link getTypeProtection} For type protection only
113
- */
114
- convert(input: JsonMappingInput): ConversionResult;
115
- /**
116
- * Extracts only the legacy JsonMapping for direct use with PostgresJsonQueryBuilder.
117
- *
118
- * This convenience method performs the full conversion but returns only the mapping portion,
119
- * discarding metadata and type protection information. Use this when you only need
120
- * the mapping for query building and don't require additional metadata.
121
- *
122
- * @param input - The JSON mapping in any supported format
123
- * @returns Legacy-format JsonMapping ready for PostgresJsonQueryBuilder
124
- *
125
- * @throws {Error} When the input format is not supported
126
- *
127
- * @example
128
- * ```typescript
129
- * const legacyMapping = converter.toLegacyMapping(modelDrivenMapping);
130
- * const queryBuilder = new PostgresJsonQueryBuilder(legacyMapping);
131
- * const query = queryBuilder.build(selectQuery);
132
- * ```
133
- *
134
- * @see {@link convert} For full conversion with metadata
135
- */
136
- toLegacyMapping(input: JsonMappingInput): JsonMapping;
137
- /**
138
- * Extracts type protection configuration for runtime type checking.
139
- *
140
- * Type protection helps identify fields that should be treated as strings
141
- * to prevent injection attacks or type coercion issues. This is particularly
142
- * useful when working with user input or external data sources.
143
- *
144
- * @param input - The JSON mapping in any supported format
145
- * @returns Type protection configuration with protected field definitions
146
- *
147
- * @throws {Error} When the input format is not supported
148
- *
149
- * @example
150
- * ```typescript
151
- * const typeProtection = converter.getTypeProtection(enhancedMapping);
152
- *
153
- * // Apply type protection during data processing
154
- * for (const field of typeProtection.protectedStringFields) {
155
- * if (typeof data[field] !== 'string') {
156
- * data[field] = String(data[field]);
157
- * }
158
- * }
159
- * ```
160
- */
161
- getTypeProtection(input: JsonMappingInput): TypeProtectionConfig;
162
- /**
163
- * Validates that the input mapping is well-formed and can be successfully converted.
164
- *
165
- * This method performs comprehensive validation without attempting conversion,
166
- * returning an array of error messages for any issues found. An empty array
167
- * indicates the mapping is valid and ready for conversion.
168
- *
169
- * **Validation Checks:**
170
- * - Basic structure validation (object type, required fields)
171
- * - Format-specific validation (Enhanced, Model-Driven, Legacy)
172
- * - Column configuration validation
173
- * - Type protection configuration validation
174
- *
175
- * @param input - The JSON mapping to validate
176
- * @returns Array of validation error messages (empty if valid)
177
- *
178
- * @example
179
- * ```typescript
180
- * const errors = converter.validate(suspiciousMapping);
181
- * if (errors.length > 0) {
182
- * console.error('Validation failed:', errors);
183
- * throw new Error(`Invalid mapping: ${errors.join(', ')}`);
184
- * }
185
- *
186
- * // Safe to convert
187
- * const result = converter.convert(suspiciousMapping);
188
- * ```
189
- *
190
- * @see {@link convert} Performs conversion after implicit validation
191
- */
192
- validate(input: JsonMappingInput): string[];
193
- /**
194
- * Creates a new enhanced mapping from legacy mapping.
195
- */
196
- upgradeToEnhanced(legacy: LegacyJsonMapping, typeInfo?: {
197
- interface: string;
198
- importPath: string;
199
- }): EnhancedJsonMapping;
200
- }
@@ -1,388 +0,0 @@
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
@@ -1 +0,0 @@
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;;GAEG;AACH,SAAS,mBAAmB,CAAC,KAAc;IACvC,OAAO,KAAK,KAAK,IAAI;QACd,KAAK,KAAK,SAAS;QACnB,OAAO,KAAK,KAAK,QAAQ,CAAC;AACrC,CAAC;AAED;;GAEG;AACH,MAAM,sBAAsB;IACxB,MAAM,CAAC,KAAc;QACjB,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,EAAE,CAAC;YAC9B,OAAO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