rawsql-ts 0.20.0 → 0.21.1

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 (89) 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 +3 -39
  6. package/dist/esm/index.min.js.map +3 -3
  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/PruneOptionalConditionBranches.d.ts +19 -0
  11. package/dist/esm/transformers/PruneOptionalConditionBranches.js +220 -0
  12. package/dist/esm/transformers/PruneOptionalConditionBranches.js.map +1 -1
  13. package/dist/esm/transformers/SSSQLFilterBuilder.js +2 -1
  14. package/dist/esm/transformers/SSSQLFilterBuilder.js.map +1 -1
  15. package/dist/esm/utils/SchemaManager.d.ts +3 -19
  16. package/dist/esm/utils/SchemaManager.js +2 -62
  17. package/dist/esm/utils/SchemaManager.js.map +1 -1
  18. package/dist/index.js +2 -18
  19. package/dist/index.js.map +1 -1
  20. package/dist/index.min.js +3 -39
  21. package/dist/index.min.js.map +3 -3
  22. package/dist/src/index.d.ts +1 -11
  23. package/dist/src/transformers/DynamicQueryBuilder.d.ts +4 -27
  24. package/dist/src/transformers/PruneOptionalConditionBranches.d.ts +19 -0
  25. package/dist/src/utils/SchemaManager.d.ts +3 -19
  26. package/dist/transformers/DynamicQueryBuilder.js +10 -27
  27. package/dist/transformers/DynamicQueryBuilder.js.map +1 -1
  28. package/dist/transformers/PruneOptionalConditionBranches.js +222 -1
  29. package/dist/transformers/PruneOptionalConditionBranches.js.map +1 -1
  30. package/dist/transformers/SSSQLFilterBuilder.js +2 -1
  31. package/dist/transformers/SSSQLFilterBuilder.js.map +1 -1
  32. package/dist/tsconfig.browser.tsbuildinfo +1 -1
  33. package/dist/utils/SchemaManager.js +2 -63
  34. package/dist/utils/SchemaManager.js.map +1 -1
  35. package/package.json +10 -2
  36. package/dist/esm/transformers/EnhancedJsonMapping.d.ts +0 -194
  37. package/dist/esm/transformers/EnhancedJsonMapping.js +0 -217
  38. package/dist/esm/transformers/EnhancedJsonMapping.js.map +0 -1
  39. package/dist/esm/transformers/JsonMappingConverter.d.ts +0 -200
  40. package/dist/esm/transformers/JsonMappingConverter.js +0 -388
  41. package/dist/esm/transformers/JsonMappingConverter.js.map +0 -1
  42. package/dist/esm/transformers/JsonMappingUnifier.d.ts +0 -100
  43. package/dist/esm/transformers/JsonMappingUnifier.js +0 -207
  44. package/dist/esm/transformers/JsonMappingUnifier.js.map +0 -1
  45. package/dist/esm/transformers/ModelDrivenJsonMapping.d.ts +0 -62
  46. package/dist/esm/transformers/ModelDrivenJsonMapping.js +0 -115
  47. package/dist/esm/transformers/ModelDrivenJsonMapping.js.map +0 -1
  48. package/dist/esm/transformers/PostgresArrayEntityCteBuilder.d.ts +0 -138
  49. package/dist/esm/transformers/PostgresArrayEntityCteBuilder.js +0 -454
  50. package/dist/esm/transformers/PostgresArrayEntityCteBuilder.js.map +0 -1
  51. package/dist/esm/transformers/PostgresJsonQueryBuilder.d.ts +0 -88
  52. package/dist/esm/transformers/PostgresJsonQueryBuilder.js +0 -241
  53. package/dist/esm/transformers/PostgresJsonQueryBuilder.js.map +0 -1
  54. package/dist/esm/transformers/PostgresObjectEntityCteBuilder.d.ts +0 -165
  55. package/dist/esm/transformers/PostgresObjectEntityCteBuilder.js +0 -343
  56. package/dist/esm/transformers/PostgresObjectEntityCteBuilder.js.map +0 -1
  57. package/dist/esm/transformers/TypeTransformationPostProcessor.d.ts +0 -108
  58. package/dist/esm/transformers/TypeTransformationPostProcessor.js +0 -354
  59. package/dist/esm/transformers/TypeTransformationPostProcessor.js.map +0 -1
  60. package/dist/esm/utils/JsonSchemaValidator.d.ts +0 -81
  61. package/dist/esm/utils/JsonSchemaValidator.js +0 -211
  62. package/dist/esm/utils/JsonSchemaValidator.js.map +0 -1
  63. package/dist/src/transformers/EnhancedJsonMapping.d.ts +0 -194
  64. package/dist/src/transformers/JsonMappingConverter.d.ts +0 -200
  65. package/dist/src/transformers/JsonMappingUnifier.d.ts +0 -100
  66. package/dist/src/transformers/ModelDrivenJsonMapping.d.ts +0 -62
  67. package/dist/src/transformers/PostgresArrayEntityCteBuilder.d.ts +0 -138
  68. package/dist/src/transformers/PostgresJsonQueryBuilder.d.ts +0 -88
  69. package/dist/src/transformers/PostgresObjectEntityCteBuilder.d.ts +0 -165
  70. package/dist/src/transformers/TypeTransformationPostProcessor.d.ts +0 -108
  71. package/dist/src/utils/JsonSchemaValidator.d.ts +0 -81
  72. package/dist/transformers/EnhancedJsonMapping.js +0 -223
  73. package/dist/transformers/EnhancedJsonMapping.js.map +0 -1
  74. package/dist/transformers/JsonMappingConverter.js +0 -392
  75. package/dist/transformers/JsonMappingConverter.js.map +0 -1
  76. package/dist/transformers/JsonMappingUnifier.js +0 -216
  77. package/dist/transformers/JsonMappingUnifier.js.map +0 -1
  78. package/dist/transformers/ModelDrivenJsonMapping.js +0 -122
  79. package/dist/transformers/ModelDrivenJsonMapping.js.map +0 -1
  80. package/dist/transformers/PostgresArrayEntityCteBuilder.js +0 -458
  81. package/dist/transformers/PostgresArrayEntityCteBuilder.js.map +0 -1
  82. package/dist/transformers/PostgresJsonQueryBuilder.js +0 -245
  83. package/dist/transformers/PostgresJsonQueryBuilder.js.map +0 -1
  84. package/dist/transformers/PostgresObjectEntityCteBuilder.js +0 -347
  85. package/dist/transformers/PostgresObjectEntityCteBuilder.js.map +0 -1
  86. package/dist/transformers/TypeTransformationPostProcessor.js +0 -363
  87. package/dist/transformers/TypeTransformationPostProcessor.js.map +0 -1
  88. package/dist/utils/JsonSchemaValidator.js +0 -215
  89. package/dist/utils/JsonSchemaValidator.js.map +0 -1
@@ -1,207 +0,0 @@
1
- /**
2
- * Unified JSON Mapping processor that supports both legacy and model-driven formats.
3
- *
4
- * @deprecated Use JsonMappingConverter instead. This module is kept for backward compatibility.
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
- import { JsonMappingConverter } from './JsonMappingConverter';
9
- /**
10
- * Detects the format of a JSON mapping configuration.
11
- *
12
- * @param input - The mapping configuration to analyze
13
- * @returns The detected format type
14
- */
15
- export function detectMappingFormat(input) {
16
- // Model-driven format: has typeInfo and structure
17
- if (input.typeInfo && input.structure) {
18
- return 'model-driven';
19
- }
20
- // Unified format: has rootName and rootEntity
21
- if (input.rootName && input.rootEntity) {
22
- return 'unified';
23
- }
24
- // Legacy format: direct JsonMapping structure
25
- if (input.columns || input.relationships) {
26
- return 'legacy';
27
- }
28
- // Default fallback
29
- return 'legacy';
30
- }
31
- /**
32
- * Converts legacy unified format to JsonMapping.
33
- *
34
- * @param input - Unified format mapping configuration
35
- * @returns Converted JsonMapping
36
- */
37
- function convertUnifiedFormat(input) {
38
- if (!input.rootEntity) {
39
- throw new Error('Unified format requires rootEntity');
40
- }
41
- const result = {
42
- rootName: input.rootName || 'root',
43
- rootEntity: {
44
- id: input.rootEntity.id || 'root',
45
- name: input.rootEntity.name || 'Root',
46
- columns: input.rootEntity.columns || {}
47
- },
48
- nestedEntities: []
49
- };
50
- // Convert nestedEntities
51
- if (input.nestedEntities && Array.isArray(input.nestedEntities)) {
52
- result.nestedEntities = input.nestedEntities.map(entity => ({
53
- id: entity.id || entity.propertyName || 'nested',
54
- name: entity.name || entity.propertyName || 'Nested',
55
- parentId: entity.parentId || result.rootEntity.id,
56
- propertyName: entity.propertyName || 'nested',
57
- relationshipType: entity.relationshipType || 'object',
58
- columns: entity.columns || {}
59
- }));
60
- }
61
- return result;
62
- }
63
- /**
64
- * Converts legacy format directly to JsonMapping.
65
- *
66
- * @param input - Legacy format mapping configuration
67
- * @returns JsonMapping
68
- */
69
- function convertLegacyFormat(input) {
70
- const result = {
71
- rootName: input.rootName || 'root',
72
- rootEntity: {
73
- id: 'root',
74
- name: input.rootName || 'Root',
75
- columns: input.columns || {}
76
- },
77
- nestedEntities: []
78
- };
79
- // Convert relationships to nestedEntities
80
- if (input.relationships && typeof input.relationships === 'object') {
81
- for (const [propertyName, relationship] of Object.entries(input.relationships)) {
82
- // Type assertion for legacy relationship format
83
- const rel = relationship;
84
- result.nestedEntities.push({
85
- id: propertyName,
86
- name: propertyName.charAt(0).toUpperCase() + propertyName.slice(1),
87
- parentId: 'root',
88
- propertyName,
89
- relationshipType: rel.type === 'hasMany' ? 'array' : 'object',
90
- columns: rel.columns || {}
91
- });
92
- }
93
- }
94
- return result;
95
- }
96
- /**
97
- * Main processor that unifies all JSON mapping formats into a consistent JsonMapping.
98
- *
99
- * @deprecated Use JsonMappingConverter.convert() instead.
100
- *
101
- * Features:
102
- * - Automatic format detection
103
- * - Backward compatibility with all existing formats
104
- * - Metadata preservation for advanced features
105
- * - Zero external dependencies
106
- *
107
- * @param input - Any supported JSON mapping format
108
- * @returns Unified processing result with JsonMapping and metadata
109
- */
110
- export function processJsonMapping(input) {
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);
118
- return {
119
- format: 'legacy',
120
- jsonMapping,
121
- originalInput: input,
122
- metadata: {}
123
- };
124
- }
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';
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
- };
142
- }
143
- /**
144
- * Convenience function for direct JsonMapping extraction.
145
- *
146
- * @deprecated Use JsonMappingConverter.toLegacyMapping() instead.
147
- *
148
- * @param input - Any supported JSON mapping format
149
- * @returns JsonMapping ready for use with PostgresJsonQueryBuilder
150
- */
151
- export function unifyJsonMapping(input) {
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);
157
- }
158
- /**
159
- * Type guard to check if input uses model-driven format.
160
- *
161
- * @param input - Mapping input to check
162
- * @returns True if input is model-driven format
163
- */
164
- export function isModelDrivenFormat(input) {
165
- return detectMappingFormat(input) === 'model-driven';
166
- }
167
- /**
168
- * Type guard to check if input uses unified format.
169
- *
170
- * @param input - Mapping input to check
171
- * @returns True if input is unified format
172
- */
173
- export function isUnifiedFormat(input) {
174
- return detectMappingFormat(input) === 'unified';
175
- }
176
- /**
177
- * Type guard to check if input uses legacy format.
178
- *
179
- * @param input - Mapping input to check
180
- * @returns True if input is legacy format
181
- */
182
- export function isLegacyFormat(input) {
183
- return detectMappingFormat(input) === 'legacy';
184
- }
185
- /**
186
- * Migration helper that suggests upgrading to model-driven format.
187
- *
188
- * @param input - Current mapping configuration
189
- * @returns Suggestions for migration (if applicable)
190
- */
191
- export function suggestModelDrivenMigration(input) {
192
- const format = detectMappingFormat(input);
193
- const suggestions = [];
194
- if (format !== 'model-driven') {
195
- suggestions.push('Consider migrating to model-driven JSON mapping format');
196
- suggestions.push('Benefits: Better type safety, IDE support, and future-proof design');
197
- suggestions.push('See: Model-Driven JSON Mapping Guide for migration instructions');
198
- if (format === 'unified') {
199
- suggestions.push('Your current unified format can be automatically converted');
200
- }
201
- if (format === 'legacy') {
202
- suggestions.push('Legacy format support will be maintained but new features target model-driven format');
203
- }
204
- }
205
- return suggestions;
206
- }
207
- //# sourceMappingURL=JsonMappingUnifier.js.map
@@ -1 +0,0 @@
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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AAwD,CAAC,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"}
@@ -1,62 +0,0 @@
1
- /**
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[];
@@ -1,115 +0,0 @@
1
- /**
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
- /**
6
- * Convert a model-driven JSON mapping to the traditional JsonMapping format.
7
- * This enables backward compatibility with existing PostgresJsonQueryBuilder.
8
- */
9
- export function convertModelDrivenMapping(modelMapping) {
10
- const protectedStringFields = [];
11
- let entityIdCounter = 0;
12
- const propertyNameCounters = {};
13
- // Generate unique entity IDs
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
- };
23
- // Helper function to process structure fields and extract entities
24
- const processStructure = (structure, parentId = null) => {
25
- const columns = {};
26
- const nestedEntities = [];
27
- for (const [fieldName, config] of Object.entries(structure)) {
28
- if (typeof config === 'string') {
29
- // Simple field mapping: "fieldName": "column_name"
30
- columns[fieldName] = config;
31
- }
32
- else if ('column' in config && typeof config.column === 'string' && !('type' in config && (config.type === 'object' || config.type === 'array'))) {
33
- // Enhanced field mapping: "fieldName": { "column": "column_name", "type": "string" }
34
- const fieldConfig = config;
35
- if (typeof fieldConfig === 'object' && 'column' in fieldConfig) {
36
- columns[fieldName] = fieldConfig.column;
37
- if (fieldConfig.type === 'string') {
38
- protectedStringFields.push(fieldConfig.column);
39
- }
40
- }
41
- }
42
- else if ('from' in config && typeof config.from === 'string' && !('type' in config && (config.type === 'object' || config.type === 'array'))) {
43
- // Legacy field mapping: "fieldName": { "from": "column_name", "type": "string" }
44
- const fieldConfig = config;
45
- if (typeof fieldConfig === 'object' && 'from' in fieldConfig) {
46
- columns[fieldName] = fieldConfig.from;
47
- if (fieldConfig.type === 'string') {
48
- protectedStringFields.push(fieldConfig.from);
49
- }
50
- }
51
- }
52
- else if ('type' in config && (config.type === 'object' || config.type === 'array')) {
53
- // Nested structure: object or array
54
- const nestedStructure = config;
55
- const uniquePropertyName = generateUniquePropertyName(fieldName);
56
- // Generate globally unique entity ID to ensure unique JSON column names
57
- const entityId = generateEntityId();
58
- const processedNested = processStructure(nestedStructure.structure, entityId);
59
- nestedEntities.push({
60
- id: entityId, // Use unique ID to avoid column conflicts
61
- name: fieldName.charAt(0).toUpperCase() + fieldName.slice(1), // Capitalize first letter
62
- parentId: parentId || 'root',
63
- propertyName: uniquePropertyName,
64
- originalPropertyName: fieldName, // Store original name for final mapping
65
- relationshipType: nestedStructure.type,
66
- columns: processedNested.columns
67
- });
68
- // Add nested entities from deeper levels
69
- nestedEntities.push(...processedNested.nestedEntities.map(entity => (Object.assign(Object.assign({}, entity), { parentId: entity.parentId === 'root' ? entityId : entity.parentId }))));
70
- }
71
- }
72
- return { columns, nestedEntities };
73
- };
74
- // Process the root structure
75
- const processed = processStructure(modelMapping.structure); // Build the traditional JsonMapping
76
- const jsonMapping = {
77
- rootName: 'root', // Default root name
78
- rootEntity: {
79
- id: 'root',
80
- name: 'Root',
81
- columns: processed.columns
82
- },
83
- nestedEntities: processed.nestedEntities
84
- };
85
- // Add typeInfo for backward compatibility
86
- jsonMapping.typeInfo = modelMapping.typeInfo;
87
- return {
88
- jsonMapping,
89
- typeProtection: { protectedStringFields }
90
- };
91
- }
92
- /**
93
- * Validate that a model-driven mapping structure is well-formed.
94
- */
95
- export function validateModelDrivenMapping(mapping) {
96
- const errors = [];
97
- // Validate typeInfo
98
- if (!mapping.typeInfo) {
99
- errors.push('typeInfo is required');
100
- }
101
- else {
102
- if (!mapping.typeInfo.interface) {
103
- errors.push('typeInfo.interface is required');
104
- }
105
- if (!mapping.typeInfo.importPath) {
106
- errors.push('typeInfo.importPath is required');
107
- }
108
- }
109
- // Validate structure
110
- if (!mapping.structure || typeof mapping.structure !== 'object') {
111
- errors.push('structure is required and must be an object');
112
- }
113
- return errors;
114
- }
115
- //# sourceMappingURL=ModelDrivenJsonMapping.js.map
@@ -1 +0,0 @@
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,CAAC,EAAE,CAAC;QACjC,OAAO,oBAAoB,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,QAAQ,IAAI,oBAAoB,CAAC,QAAQ,CAAC,EAAE,CAAC;IAC7G,CAAC,CAAC;IACF,mEAAmE;IACnE,MAAM,gBAAgB,GAAG,CACrB,SAA0B,EAC1B,WAA0B,IAAI,EAIhC,EAAE;QACA,MAAM,OAAO,GAA2B,EAAE,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AO,MAAM,CAAC;AAClB,CAAC"}
@@ -1,138 +0,0 @@
1
- import { CommonTable } from '../models/Clause';
2
- import { JsonMapping } from './PostgresJsonQueryBuilder';
3
- import { ProcessableEntity, JsonColumnMapping } from './PostgresObjectEntityCteBuilder';
4
- /**
5
- * Builds CTEs for array entities using depth-first processing and row compression.
6
- *
7
- * Core concepts:
8
- * - Column Compression: OBJECT relationships (user_id, user_name → user_json)
9
- * - Row Compression: ARRAY relationships (multiple rows → JSON array via GROUP BY)
10
- * - Depth-First: Process deepest arrays first for dependency ordering
11
- * - GROUP BY Exclusion: Exclude array-internal columns to prevent over-grouping
12
- */
13
- export declare class PostgresArrayEntityCteBuilder {
14
- private static readonly CTE_ARRAY_PREFIX;
15
- private static readonly JSON_FUNCTIONS;
16
- /**
17
- * Builds CTEs for all array entities using depth-first processing.
18
- * Collects arrays by depth, processes deepest first, chains CTEs.
19
- *
20
- * @param ctesSoFar Array of CTEs built so far
21
- * @param aliasOfCteToBuildUpon Alias of the CTE to build upon
22
- * @param allEntities Map of all entities in the mapping
23
- * @param mapping The JSON mapping configuration
24
- * @param columnMappings Optional mappings from object entity IDs to generated JSON column names
25
- * @returns Object containing updated CTEs and last CTE alias
26
- */
27
- buildArrayEntityCtes(ctesSoFar: CommonTable[], aliasOfCteToBuildUpon: string, allEntities: Map<string, ProcessableEntity>, mapping: JsonMapping, columnMappings?: JsonColumnMapping[]): {
28
- updatedCtes: CommonTable[];
29
- lastCteAlias: string;
30
- };
31
- /**
32
- * Collects array entities and calculates depth for dependency ordering.
33
- * Depth = distance from root. Deeper arrays processed first.
34
- *
35
- * @param mapping The JSON mapping configuration
36
- * @param allEntities Map of all entities in the mapping
37
- * @returns Array of array entity information with depths, sorted deepest first
38
- */
39
- private collectAndSortArrayEntities;
40
- /**
41
- * Groups array entities by depth level for batch processing.
42
- *
43
- * @param arrayInfos Array of array entity information with depths
44
- * @returns Map of depth level to entities at that depth
45
- */
46
- private groupEntitiesByDepth;
47
- /**
48
- * Builds CTE for specific depth level using row compression.
49
- * Uses GROUP BY to aggregate multiple rows into JSON arrays.
50
- * Excludes array-internal columns from GROUP BY to prevent over-grouping.
51
- *
52
- * @param infos Array entities at this depth level
53
- * @param currentCteAlias Alias of the CTE to build upon
54
- * @param currentCtes All CTEs built so far
55
- * @param depth Current depth level being processed
56
- * @param mapping JSON mapping configuration
57
- * @param columnMappings Optional mappings from object entity IDs to generated JSON column names
58
- * @returns The new CTE and its alias
59
- */
60
- private buildDepthCte;
61
- /**
62
- * Creates jsonb_agg function for array entity.
63
- * Handles entity columns and nested child relationships.
64
- * Uses originalPropertyName to avoid sequential numbering.
65
- *
66
- * @param entity The array entity being processed
67
- * @param nestedEntities All nested entities from the mapping
68
- * @param allEntities Map of all entities (not used in current implementation)
69
- * @param columnMappings Mappings from object entity IDs to generated JSON column names
70
- * @returns Object containing the JSON aggregation function
71
- */
72
- private buildAggregationDetailsForArrayEntity;
73
- /**
74
- * Collects array entity columns by depth for GROUP BY exclusion strategy.
75
- *
76
- * @param mapping The JSON mapping configuration containing all entities
77
- * @param currentDepth The current aggregation depth being processed
78
- * @returns A map where keys are depth levels and values are sets of column names
79
- */
80
- private collectArrayEntityColumnsByDepth;
81
- /**
82
- * Calculates entity depth by traversing up to root.
83
- *
84
- * @param entity The entity to calculate depth for
85
- * @param mapping The JSON mapping containing all entities
86
- * @returns The depth level (0 for root level, 1 for first level, etc.)
87
- */
88
- private calculateEntityDepth;
89
- /**
90
- * Adds entity columns to depth set.
91
- *
92
- * @param entity The entity whose columns should be added
93
- * @param depth The depth level to add columns to
94
- * @param arrayEntitiesByDepth The map to update
95
- */
96
- private addEntityColumnsToDepthSet;
97
- /**
98
- * Recursively collects columns from descendant entities.
99
- *
100
- * @param parentEntityId The ID of the parent entity
101
- * @param targetDepth The depth level to assign collected columns to
102
- * @param mapping The JSON mapping containing all entities
103
- * @param arrayEntitiesByDepth The map to update with collected columns
104
- */
105
- private collectDescendantColumns;
106
- /**
107
- * Implements GROUP BY exclusion strategy for array aggregation.
108
- * Excludes current array columns and array-internal object JSON columns.
109
- *
110
- * @param prevSelects SELECT variables from the previous CTE
111
- * @param arrayColumns Columns that are being aggregated (should be excluded from GROUP BY)
112
- * @param arrayEntitiesByDepth Map of depth levels to their column sets
113
- * @param currentDepth The current aggregation depth being processed
114
- * @param selectItems Output array for SELECT items
115
- * @param groupByItems Output array for GROUP BY items
116
- * @param arrayInternalObjectColumns JSON columns from objects within arrays being processed
117
- */
118
- private processSelectVariablesForGroupBy;
119
- /**
120
- * Determines if column should be included in GROUP BY clause.
121
- * Applies depth-based filtering and special handling for JSON columns.
122
- *
123
- * @param columnName The name of the column to evaluate
124
- * @param arrayEntitiesByDepth Map of depth levels to their column sets
125
- * @param currentDepth The current aggregation depth
126
- * @returns True if the column should be included in GROUP BY, false otherwise
127
- */
128
- private shouldIncludeColumnInGroupBy;
129
- /**
130
- * Applies heuristics for entity JSON column inclusion in GROUP BY.
131
- * Uses entity numbering patterns to identify deeply nested entities.
132
- *
133
- * @param columnName The JSON column name (expected format: entity_N_json)
134
- * @param currentDepth The current aggregation depth
135
- * @returns True if the JSON column should be included, false otherwise
136
- */
137
- private shouldIncludeJsonColumn;
138
- }