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,354 +0,0 @@
1
- /**
2
- * Post-processor for transforming database values to appropriate TypeScript types
3
- * after JSON serialization from PostgreSQL
4
- */
5
- /**
6
- * Applies type transformations to JSON results from PostgreSQL
7
- */
8
- export class TypeTransformationPostProcessor {
9
- constructor(config = {}) {
10
- this.config = Object.assign({ enableValueBasedDetection: true, strictDateDetection: false }, config);
11
- }
12
- /**
13
- * Transform a single result object
14
- * @param result The result object from PostgreSQL JSON query
15
- * @returns Transformed result with proper TypeScript types
16
- */
17
- transformResult(result) {
18
- if (result === null || result === undefined) {
19
- return result;
20
- }
21
- if (Array.isArray(result)) {
22
- return result.map(item => this.transformSingleObject(item));
23
- }
24
- return this.transformSingleObject(result);
25
- }
26
- /**
27
- * Transform a single object recursively
28
- */
29
- transformSingleObject(obj) {
30
- var _a;
31
- if (obj === null || obj === undefined || typeof obj !== 'object') {
32
- return obj;
33
- }
34
- if (Array.isArray(obj)) {
35
- return obj.map(item => this.transformSingleObject(item));
36
- }
37
- const transformed = {};
38
- for (const [key, value] of Object.entries(obj)) {
39
- if (value === null || value === undefined) {
40
- transformed[key] = value;
41
- continue;
42
- } // Check for column-specific transformation first (takes precedence)
43
- const columnTransform = (_a = this.config.columnTransformations) === null || _a === void 0 ? void 0 : _a[key];
44
- if (columnTransform) {
45
- transformed[key] = this.applyTransformation(value, columnTransform);
46
- continue;
47
- }
48
- // Only apply value-based detection if enabled and no column mapping exists
49
- if (this.config.enableValueBasedDetection) {
50
- const detectedTransform = this.detectValueBasedTransformation(value);
51
- if (detectedTransform) {
52
- transformed[key] = this.applyTransformation(value, detectedTransform);
53
- continue;
54
- }
55
- }
56
- // Apply global transformations based on SQL type (if available)
57
- const globalTransform = this.config.globalTransformations &&
58
- this.getGlobalTransformationForValue(value);
59
- if (globalTransform) {
60
- transformed[key] = this.applyTransformation(value, globalTransform);
61
- continue;
62
- }
63
- // Recursively transform nested objects
64
- if (typeof value === 'object' && !Array.isArray(value)) {
65
- transformed[key] = this.transformSingleObject(value);
66
- continue;
67
- }
68
- if (Array.isArray(value)) {
69
- transformed[key] = value.map(item => typeof item === 'object' ? this.transformSingleObject(item) : item);
70
- continue;
71
- }
72
- // No transformation needed
73
- transformed[key] = value;
74
- }
75
- return transformed;
76
- }
77
- /**
78
- * Detect value type and create appropriate transformation based on value characteristics
79
- * This is the core value-based detection logic
80
- */
81
- detectValueBasedTransformation(value) {
82
- // Date string detection
83
- if (typeof value === 'string' && this.isDateString(value)) {
84
- return {
85
- sourceType: 'TIMESTAMP',
86
- targetType: 'Date',
87
- handleNull: true,
88
- validator: (v) => typeof v === 'string' && !isNaN(Date.parse(v))
89
- };
90
- }
91
- // BigInt detection (number > MAX_SAFE_INTEGER)
92
- if (typeof value === 'number' && !Number.isSafeInteger(value)) {
93
- return {
94
- sourceType: 'BIGINT',
95
- targetType: 'bigint',
96
- handleNull: true,
97
- validator: (v) => {
98
- try {
99
- if (typeof v === 'string' || typeof v === 'number' || typeof v === 'bigint' || typeof v === 'boolean') {
100
- BigInt(v);
101
- return true;
102
- }
103
- return false;
104
- }
105
- catch (_a) {
106
- return false;
107
- }
108
- }
109
- };
110
- }
111
- // Large string number detection (potential BIGINT)
112
- if (typeof value === 'string' && /^\d{16,}$/.test(value)) {
113
- return {
114
- sourceType: 'BIGINT',
115
- targetType: 'bigint',
116
- handleNull: true,
117
- validator: (v) => {
118
- try {
119
- if (typeof v === 'string' || typeof v === 'number' || typeof v === 'bigint' || typeof v === 'boolean') {
120
- BigInt(v);
121
- return true;
122
- }
123
- return false;
124
- }
125
- catch (_a) {
126
- return false;
127
- }
128
- }
129
- };
130
- }
131
- return null;
132
- }
133
- /**
134
- * Get global transformation for a specific value (if any match)
135
- * This is separate from value-based detection and relies on configured global rules
136
- */
137
- getGlobalTransformationForValue(value) {
138
- if (!this.config.globalTransformations) {
139
- return null;
140
- }
141
- // This could be extended to match values against configured global rules
142
- // For now, it's a placeholder for future SQL-type-based global transformations
143
- return null;
144
- }
145
- /**
146
- * @deprecated Use detectValueBasedTransformation instead
147
- * Detect value type and get appropriate global transformation
148
- */
149
- detectAndGetGlobalTransformation(value) {
150
- return this.detectValueBasedTransformation(value);
151
- }
152
- /**
153
- * Check if string is a valid date string
154
- * Supports both strict (ISO 8601 with T separator) and loose detection
155
- */
156
- isDateString(value) {
157
- if (this.config.strictDateDetection) {
158
- // Strict: Only ISO 8601 with T separator (safer for user input)
159
- const strictIsoPattern = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?(?:Z|[+-]\d{2}:\d{2})?$/;
160
- if (!strictIsoPattern.test(value)) {
161
- return false;
162
- }
163
- }
164
- else {
165
- // Loose: ISO 8601 date pattern (includes date-only strings)
166
- const isoDatePattern = /^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2}(?:\.\d{3})?(?:Z|[+-]\d{2}:\d{2})?)?$/;
167
- if (!isoDatePattern.test(value)) {
168
- return false;
169
- }
170
- }
171
- const date = new Date(value);
172
- return !isNaN(date.getTime());
173
- }
174
- /**
175
- * Apply a specific transformation to a value
176
- */
177
- applyTransformation(value, transformation) {
178
- var _a;
179
- // Handle null values
180
- if (value === null || value === undefined) {
181
- return transformation.handleNull !== false ? value : null;
182
- }
183
- // Validate value if validator is provided
184
- if (transformation.validator && !transformation.validator(value)) {
185
- console.warn(`TypeTransformationPostProcessor: Value validation failed for ${value}`);
186
- return value;
187
- }
188
- try {
189
- switch (transformation.targetType) {
190
- case 'Date':
191
- return new Date(value);
192
- case 'bigint':
193
- // Handle both string and number inputs for BIGINT
194
- // For scientific notation numbers, convert to integer first
195
- if (typeof value === 'number') {
196
- // Convert scientific notation to integer string
197
- const integerValue = Math.trunc(value);
198
- return BigInt(integerValue.toString());
199
- }
200
- return BigInt(value);
201
- case 'string':
202
- return value.toString();
203
- case 'number':
204
- return typeof value === 'string' ? parseFloat(value) : Number(value);
205
- case 'object':
206
- return typeof value === 'string' ? JSON.parse(value) : value;
207
- case 'custom':
208
- if (transformation.customTransformer &&
209
- ((_a = this.config.customTransformers) === null || _a === void 0 ? void 0 : _a[transformation.customTransformer])) {
210
- return this.config.customTransformers[transformation.customTransformer](value);
211
- }
212
- break;
213
- default:
214
- return value;
215
- }
216
- }
217
- catch (error) {
218
- console.warn(`TypeTransformationPostProcessor: Transformation failed for ${value}:`, error);
219
- return value;
220
- }
221
- return value;
222
- }
223
- /**
224
- * Create a default configuration for common PostgreSQL types
225
- * Enables value-based detection with loose date detection by default
226
- */
227
- static createDefaultConfig() {
228
- return {
229
- enableValueBasedDetection: true,
230
- strictDateDetection: false,
231
- globalTransformations: {
232
- 'DATE': {
233
- sourceType: 'DATE',
234
- targetType: 'Date',
235
- handleNull: true,
236
- validator: (value) => typeof value === 'string' && !isNaN(Date.parse(value))
237
- },
238
- 'TIMESTAMP': {
239
- sourceType: 'TIMESTAMP',
240
- targetType: 'Date',
241
- handleNull: true,
242
- validator: (value) => typeof value === 'string' && !isNaN(Date.parse(value))
243
- },
244
- 'BIGINT': {
245
- sourceType: 'BIGINT',
246
- targetType: 'bigint',
247
- handleNull: true,
248
- validator: (value) => {
249
- try {
250
- if (typeof value === 'string' || typeof value === 'number' || typeof value === 'bigint' || typeof value === 'boolean') {
251
- BigInt(value);
252
- return true;
253
- }
254
- return false;
255
- }
256
- catch (_a) {
257
- return false;
258
- }
259
- }
260
- }
261
- }
262
- };
263
- }
264
- /**
265
- * Create a safe configuration for handling user input
266
- * Disables value-based detection and uses strict date detection
267
- */
268
- static createSafeConfig(columnMappings) {
269
- return {
270
- enableValueBasedDetection: false,
271
- strictDateDetection: true,
272
- columnTransformations: columnMappings || {},
273
- globalTransformations: {
274
- 'DATE': {
275
- sourceType: 'DATE',
276
- targetType: 'Date',
277
- handleNull: true,
278
- validator: (value) => typeof value === 'string' && !isNaN(Date.parse(value))
279
- },
280
- 'TIMESTAMP': {
281
- sourceType: 'TIMESTAMP',
282
- targetType: 'Date',
283
- handleNull: true,
284
- validator: (value) => typeof value === 'string' && !isNaN(Date.parse(value))
285
- },
286
- 'BIGINT': {
287
- sourceType: 'BIGINT',
288
- targetType: 'bigint',
289
- handleNull: true,
290
- validator: (value) => {
291
- try {
292
- if (typeof value === 'string' || typeof value === 'number' || typeof value === 'bigint' || typeof value === 'boolean') {
293
- BigInt(value);
294
- return true;
295
- }
296
- return false;
297
- }
298
- catch (_a) {
299
- return false;
300
- }
301
- }
302
- }
303
- }
304
- };
305
- }
306
- }
307
- /**
308
- * Convenience function to create and apply transformations
309
- */
310
- export function transformDatabaseResult(result, config) {
311
- const processor = new TypeTransformationPostProcessor(config || TypeTransformationPostProcessor.createDefaultConfig());
312
- return processor.transformResult(result);
313
- }
314
- /**
315
- * Type-safe transformation helpers
316
- */
317
- export const TypeTransformers = {
318
- /**
319
- * Transform date string to Date object
320
- */
321
- toDate: (value) => {
322
- if (value === null || value === undefined)
323
- return null;
324
- const date = new Date(value);
325
- return isNaN(date.getTime()) ? null : date;
326
- },
327
- /**
328
- * Transform numeric string to BigInt
329
- */
330
- toBigInt: (value) => {
331
- if (value === null || value === undefined)
332
- return null;
333
- try {
334
- return BigInt(value);
335
- }
336
- catch (_a) {
337
- return null;
338
- }
339
- },
340
- /**
341
- * Transform JSON string to object
342
- */
343
- toObject: (value) => {
344
- if (value === null || value === undefined)
345
- return null;
346
- try {
347
- return JSON.parse(value);
348
- }
349
- catch (_a) {
350
- return null;
351
- }
352
- }
353
- };
354
- //# sourceMappingURL=TypeTransformationPostProcessor.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"TypeTransformationPostProcessor.js","sourceRoot":"","sources":["../../../src/transformers/TypeTransformationPostProcessor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAkCH;;GAEG;AACH,MAAM,OAAO,+BAA+B;IACE,YAAY,SAAmC,EAAE;QACvF,IAAI,CAAC,MAAM,mBACP,yBAAyB,EAAE,IAAI,EAC/B,mBAAmB,EAAE,KAAK,IACvB,MAAM,CACZ,CAAC;IACN,CAAC;IAED;;;;OAIG;IACI,eAAe,CAAc,MAAe;QAC/C,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YAC1C,OAAO,MAAW,CAAC;QACvB,CAAC;QAED,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YACxB,OAAO,MAAM,CAAC,GAAG,CAAC,IAAI,CA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,KAAK,CAAC,KAAK,CAAM,CAAC;QAClC,CAAC;QAAC,WAAM,CAAC;YACL,OAAO,IAAI,CAAC;QAChB,CAAC;IACL,CAAC;CACJ,CAAC"}
@@ -1,81 +0,0 @@
1
- import { JsonMapping } from '../transformers/PostgresJsonQueryBuilder';
2
- /**
3
- * Represents the structure extracted from JsonMapping analysis
4
- */
5
- export type ExtractedStructure = 'primitive' | {
6
- [key: string]: ExtractedStructure;
7
- } | ExtractedStructure[];
8
- /**
9
- * Represents the expected type structure for validation
10
- */
11
- export type ExpectedTypeStructure = 'primitive' | {
12
- [key: string]: ExpectedTypeStructure;
13
- } | ExpectedTypeStructure[];
14
- /**
15
- * Result of JsonMapping validation
16
- */
17
- export interface ValidationResult {
18
- isValid: boolean;
19
- errors: string[];
20
- missingProperties: string[];
21
- extraProperties: string[];
22
- }
23
- export declare class JsonSchemaValidator {
24
- /**
25
- * Validates JsonMapping structure against an expected type structure.
26
- * Checks if the JsonMapping covers all required properties and relationships.
27
- *
28
- * @param jsonMapping The JsonMapping configuration to validate
29
- * @param expectedStructure The expected type structure to validate against
30
- * @returns ValidationResult containing validation status and detailed errors
31
- */
32
- static validate(jsonMapping: JsonMapping, expectedStructure: ExpectedTypeStructure): ValidationResult;
33
- /**
34
- * Validates JsonMapping structure and throws an error if validation fails.
35
- * Convenience method for strict validation scenarios.
36
- *
37
- * @param jsonMapping The JsonMapping configuration to validate
38
- * @param expectedStructure The expected type structure to validate against
39
- * @throws Error if validation fails with detailed error messages
40
- */
41
- static validateStrict(jsonMapping: JsonMapping, expectedStructure: ExpectedTypeStructure): void;
42
- /**
43
- * Extracts structure information from JsonMapping configuration.
44
- * Analyzes rootEntity and nestedEntities to build complete structure map.
45
- *
46
- * @param jsonMapping The JsonMapping to analyze
47
- * @returns ExtractedStructure representing the mapping structure
48
- */
49
- private static extractStructureFromJsonMapping; /**
50
- * Extracts structure from a nested entity, including its children.
51
- */
52
- private static extractNestedEntityStructure; /**
53
- * Compares extracted structure with expected structure with proper type guards.
54
- */
55
- private static compareStructures;
56
- /**
57
- * Validates JsonMapping structure against a sample object that implements the expected type.
58
- * This method extracts structure from the sample object and compares it with JsonMapping.
59
- *
60
- * @param jsonMapping The JsonMapping configuration to validate
61
- * @param sampleObject A sample object that implements the expected interface/type
62
- * @returns ValidationResult containing validation status and detailed errors
63
- */
64
- static validateAgainstSample<T>(jsonMapping: JsonMapping, sampleObject: T): ValidationResult;
65
- /**
66
- * Validates JsonMapping structure against a sample object and throws an error if validation fails.
67
- * Convenience method for strict validation scenarios with sample objects.
68
- *
69
- * @param jsonMapping The JsonMapping configuration to validate
70
- * @param sampleObject A sample object that implements the expected interface/type
71
- * @throws Error if validation fails with detailed error messages
72
- */
73
- static validateAgainstSampleStrict<T>(jsonMapping: JsonMapping, sampleObject: T): void; /**
74
- * Extracts structure information from a sample object.
75
- * Recursively analyzes the object properties to build a structure map.
76
- *
77
- * @param sampleObject The sample object to analyze
78
- * @returns ExpectedTypeStructure representing the object structure
79
- */
80
- private static extractStructureFromSample;
81
- }
@@ -1,211 +0,0 @@
1
- export class JsonSchemaValidator {
2
- /**
3
- * Validates JsonMapping structure against an expected type structure.
4
- * Checks if the JsonMapping covers all required properties and relationships.
5
- *
6
- * @param jsonMapping The JsonMapping configuration to validate
7
- * @param expectedStructure The expected type structure to validate against
8
- * @returns ValidationResult containing validation status and detailed errors
9
- */
10
- static validate(jsonMapping, expectedStructure) {
11
- const extractedStructure = this.extractStructureFromJsonMapping(jsonMapping);
12
- return this.compareStructures(extractedStructure, expectedStructure);
13
- }
14
- /**
15
- * Validates JsonMapping structure and throws an error if validation fails.
16
- * Convenience method for strict validation scenarios.
17
- *
18
- * @param jsonMapping The JsonMapping configuration to validate
19
- * @param expectedStructure The expected type structure to validate against
20
- * @throws Error if validation fails with detailed error messages
21
- */
22
- static validateStrict(jsonMapping, expectedStructure) {
23
- const result = this.validate(jsonMapping, expectedStructure);
24
- if (!result.isValid) {
25
- const errorMessage = [
26
- 'JsonMapping validation failed:',
27
- ...result.errors
28
- ].join('\n');
29
- throw new Error(errorMessage);
30
- }
31
- }
32
- /**
33
- * Extracts structure information from JsonMapping configuration.
34
- * Analyzes rootEntity and nestedEntities to build complete structure map.
35
- *
36
- * @param jsonMapping The JsonMapping to analyze
37
- * @returns ExtractedStructure representing the mapping structure
38
- */
39
- static extractStructureFromJsonMapping(jsonMapping) {
40
- const structure = {};
41
- // Extract root entity properties
42
- if (jsonMapping.rootEntity && jsonMapping.rootEntity.columns) {
43
- Object.keys(jsonMapping.rootEntity.columns).forEach(propertyName => {
44
- structure[propertyName] = 'primitive';
45
- });
46
- }
47
- // Extract nested entities
48
- if (jsonMapping.nestedEntities) {
49
- // Process direct children of root entity first
50
- jsonMapping.nestedEntities
51
- .filter((entity) => entity.parentId === jsonMapping.rootEntity.id)
52
- .forEach((entity) => {
53
- if (entity.propertyName && entity.columns) {
54
- if (entity.relationshipType === 'object') {
55
- // Single object relationship
56
- structure[entity.propertyName] = this.extractNestedEntityStructure(entity, jsonMapping);
57
- }
58
- else if (entity.relationshipType === 'array') {
59
- // Array relationship
60
- structure[entity.propertyName] = [this.extractNestedEntityStructure(entity, jsonMapping)];
61
- }
62
- }
63
- });
64
- }
65
- return structure;
66
- } /**
67
- * Extracts structure from a nested entity, including its children.
68
- */
69
- static extractNestedEntityStructure(entity, jsonMapping) {
70
- const entityStructure = {};
71
- // Add entity's own columns
72
- if (entity.columns) {
73
- Object.keys(entity.columns).forEach(propName => {
74
- entityStructure[propName] = 'primitive';
75
- });
76
- }
77
- // Add nested children of this entity
78
- if (jsonMapping.nestedEntities) {
79
- jsonMapping.nestedEntities
80
- .filter((childEntity) => childEntity.parentId === entity.id)
81
- .forEach((childEntity) => {
82
- if (childEntity.propertyName && childEntity.columns) {
83
- if (childEntity.relationshipType === 'object') {
84
- entityStructure[childEntity.propertyName] = this.extractNestedEntityStructure(childEntity, jsonMapping);
85
- }
86
- else if (childEntity.relationshipType === 'array') {
87
- entityStructure[childEntity.propertyName] = [this.extractNestedEntityStructure(childEntity, jsonMapping)];
88
- }
89
- }
90
- });
91
- }
92
- return entityStructure;
93
- } /**
94
- * Compares extracted structure with expected structure with proper type guards.
95
- */
96
- static compareStructures(extracted, expected, path = '') {
97
- const errors = [];
98
- const missingProperties = [];
99
- const extraProperties = [];
100
- // Handle primitive comparison
101
- if (extracted === 'primitive' && expected === 'primitive') {
102
- return { isValid: true, errors: [], missingProperties: [], extraProperties: [] };
103
- }
104
- // Handle array types
105
- if (Array.isArray(expected) && Array.isArray(extracted)) {
106
- if (expected.length > 0 && extracted.length > 0) {
107
- const nestedResult = this.compareStructures(extracted[0], expected[0], `${path}[]`);
108
- errors.push(...nestedResult.errors);
109
- missingProperties.push(...nestedResult.missingProperties);
110
- extraProperties.push(...nestedResult.extraProperties);
111
- }
112
- return { isValid: errors.length === 0, errors, missingProperties, extraProperties };
113
- } // Both should be objects for property comparison
114
- if (typeof extracted !== 'object' || typeof expected !== 'object' ||
115
- Array.isArray(extracted) || Array.isArray(expected) ||
116
- extracted === null || expected === null) {
117
- return { isValid: true, errors: [], missingProperties: [], extraProperties: [] };
118
- }
119
- // Now we know both are object types, safe to access properties
120
- const extractedObj = extracted;
121
- const expectedObj = expected;
122
- // Check for missing properties in extracted structure
123
- Object.keys(expectedObj).forEach(key => {
124
- const currentPath = path ? `${path}.${key}` : key;
125
- if (!(key in extractedObj)) {
126
- missingProperties.push(currentPath);
127
- errors.push(`Missing property: ${currentPath}`);
128
- return;
129
- }
130
- const extractedValue = extractedObj[key];
131
- const expectedValue = expectedObj[key];
132
- // Recursively compare nested structures
133
- const nestedResult = this.compareStructures(extractedValue, expectedValue, currentPath);
134
- errors.push(...nestedResult.errors);
135
- missingProperties.push(...nestedResult.missingProperties);
136
- extraProperties.push(...nestedResult.extraProperties);
137
- });
138
- // Check for extra properties in extracted structure
139
- Object.keys(extractedObj).forEach(key => {
140
- const currentPath = path ? `${path}.${key}` : key;
141
- if (!(key in expectedObj)) {
142
- extraProperties.push(currentPath);
143
- // Note: Extra properties are not considered errors in this implementation
144
- // as JsonMapping might include additional metadata
145
- }
146
- });
147
- return {
148
- isValid: errors.length === 0,
149
- errors,
150
- missingProperties,
151
- extraProperties
152
- };
153
- }
154
- /**
155
- * Validates JsonMapping structure against a sample object that implements the expected type.
156
- * This method extracts structure from the sample object and compares it with JsonMapping.
157
- *
158
- * @param jsonMapping The JsonMapping configuration to validate
159
- * @param sampleObject A sample object that implements the expected interface/type
160
- * @returns ValidationResult containing validation status and detailed errors
161
- */
162
- static validateAgainstSample(jsonMapping, sampleObject) {
163
- const expectedStructure = this.extractStructureFromSample(sampleObject);
164
- return this.validate(jsonMapping, expectedStructure);
165
- }
166
- /**
167
- * Validates JsonMapping structure against a sample object and throws an error if validation fails.
168
- * Convenience method for strict validation scenarios with sample objects.
169
- *
170
- * @param jsonMapping The JsonMapping configuration to validate
171
- * @param sampleObject A sample object that implements the expected interface/type
172
- * @throws Error if validation fails with detailed error messages
173
- */
174
- static validateAgainstSampleStrict(jsonMapping, sampleObject) {
175
- const result = this.validateAgainstSample(jsonMapping, sampleObject);
176
- if (!result.isValid) {
177
- const errorMessage = [
178
- 'JsonMapping validation against sample object failed:',
179
- ...result.errors
180
- ].join('\n');
181
- throw new Error(errorMessage);
182
- }
183
- } /**
184
- * Extracts structure information from a sample object.
185
- * Recursively analyzes the object properties to build a structure map.
186
- *
187
- * @param sampleObject The sample object to analyze
188
- * @returns ExpectedTypeStructure representing the object structure
189
- */
190
- static extractStructureFromSample(sampleObject) {
191
- if (sampleObject === null || sampleObject === undefined) {
192
- return 'primitive';
193
- }
194
- if (Array.isArray(sampleObject)) {
195
- if (sampleObject.length === 0) {
196
- return [];
197
- }
198
- return [this.extractStructureFromSample(sampleObject[0])];
199
- }
200
- if (typeof sampleObject === 'object') {
201
- const structure = {};
202
- Object.keys(sampleObject).forEach(key => {
203
- structure[key] = this.extractStructureFromSample(sampleObject[key]);
204
- });
205
- return structure;
206
- }
207
- // Primitive types (string, number, boolean, etc.)
208
- return 'primitive';
209
- }
210
- }
211
- //# sourceMappingURL=JsonSchemaValidator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"JsonSchemaValidator.js","sourceRoot":"","sources":["../../../src/utils/JsonSchemaValidator.ts"],"names":[],"mappings":"AAiCA,MAAM,OAAO,mBAAmB;IAC5B;;;;;;;OAOG;IACI,MAAM,CAAC,QAAQ,CAClB,WAAwB,EACxB,iBAAwC;QAExC,MAAM,kBAAkB,GAAG,IAAI,CAAC,+BAA+B,CAAC,WAAW,CAAC,CAAC;QAC7E,OAAO,IAAI,CAAC,iBAAiB,CAAC,kBAAkB,EAAE,iBAAiB,CAAC,CAAC;IACzE,CAAC;IAED;;;;;;;OAOG;IACI,MAAM,CAAC,cAAc,CACxB,WAAwB,EACxB,iBAAwC;QAExC,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,iBAAiB,CAAC,CAAC;QAC7D,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YAClB,MAAM,YAAY,GAAG;gBACjB,gCAAgC;gBAChC,GAAG,MAAM,CAAC,MAAM;aACnB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;QAClC,CAAC;IACL,CAAC;IAED;;;;;;OAMG;IACK,MAAM,CAAC,+BAA+B,CAAC,WAAwB;QACnE,MAAM,SAAS,GAAuB,EAAE,CAAC;QAEzC,iCAAiC;QACjC,IAAI,WAAW,CAAC,UAAU,IAAI,WAAW,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;YAC3D,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE;gBAC/D,SAAS,CAAC,YAAY,CAAC,GAAG,WAAW,CAAC;YAC1C,CAAC,CAAC,CAAC;QACP,CAAC;QACD,0BAA0B;QAC1B,IAAI,WAAW,CAAC,cAAc,EA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