rawsql-ts 0.20.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 (83) 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/SSSQLFilterBuilder.js +2 -1
  11. package/dist/esm/transformers/SSSQLFilterBuilder.js.map +1 -1
  12. package/dist/esm/utils/SchemaManager.d.ts +3 -19
  13. package/dist/esm/utils/SchemaManager.js +2 -62
  14. package/dist/esm/utils/SchemaManager.js.map +1 -1
  15. package/dist/index.js +2 -18
  16. package/dist/index.js.map +1 -1
  17. package/dist/index.min.js +3 -39
  18. package/dist/index.min.js.map +3 -3
  19. package/dist/src/index.d.ts +1 -11
  20. package/dist/src/transformers/DynamicQueryBuilder.d.ts +4 -27
  21. package/dist/src/utils/SchemaManager.d.ts +3 -19
  22. package/dist/transformers/DynamicQueryBuilder.js +10 -27
  23. package/dist/transformers/DynamicQueryBuilder.js.map +1 -1
  24. package/dist/transformers/SSSQLFilterBuilder.js +2 -1
  25. package/dist/transformers/SSSQLFilterBuilder.js.map +1 -1
  26. package/dist/tsconfig.browser.tsbuildinfo +1 -1
  27. package/dist/utils/SchemaManager.js +2 -63
  28. package/dist/utils/SchemaManager.js.map +1 -1
  29. package/package.json +10 -2
  30. package/dist/esm/transformers/EnhancedJsonMapping.d.ts +0 -194
  31. package/dist/esm/transformers/EnhancedJsonMapping.js +0 -217
  32. package/dist/esm/transformers/EnhancedJsonMapping.js.map +0 -1
  33. package/dist/esm/transformers/JsonMappingConverter.d.ts +0 -200
  34. package/dist/esm/transformers/JsonMappingConverter.js +0 -388
  35. package/dist/esm/transformers/JsonMappingConverter.js.map +0 -1
  36. package/dist/esm/transformers/JsonMappingUnifier.d.ts +0 -100
  37. package/dist/esm/transformers/JsonMappingUnifier.js +0 -207
  38. package/dist/esm/transformers/JsonMappingUnifier.js.map +0 -1
  39. package/dist/esm/transformers/ModelDrivenJsonMapping.d.ts +0 -62
  40. package/dist/esm/transformers/ModelDrivenJsonMapping.js +0 -115
  41. package/dist/esm/transformers/ModelDrivenJsonMapping.js.map +0 -1
  42. package/dist/esm/transformers/PostgresArrayEntityCteBuilder.d.ts +0 -138
  43. package/dist/esm/transformers/PostgresArrayEntityCteBuilder.js +0 -454
  44. package/dist/esm/transformers/PostgresArrayEntityCteBuilder.js.map +0 -1
  45. package/dist/esm/transformers/PostgresJsonQueryBuilder.d.ts +0 -88
  46. package/dist/esm/transformers/PostgresJsonQueryBuilder.js +0 -241
  47. package/dist/esm/transformers/PostgresJsonQueryBuilder.js.map +0 -1
  48. package/dist/esm/transformers/PostgresObjectEntityCteBuilder.d.ts +0 -165
  49. package/dist/esm/transformers/PostgresObjectEntityCteBuilder.js +0 -343
  50. package/dist/esm/transformers/PostgresObjectEntityCteBuilder.js.map +0 -1
  51. package/dist/esm/transformers/TypeTransformationPostProcessor.d.ts +0 -108
  52. package/dist/esm/transformers/TypeTransformationPostProcessor.js +0 -354
  53. package/dist/esm/transformers/TypeTransformationPostProcessor.js.map +0 -1
  54. package/dist/esm/utils/JsonSchemaValidator.d.ts +0 -81
  55. package/dist/esm/utils/JsonSchemaValidator.js +0 -211
  56. package/dist/esm/utils/JsonSchemaValidator.js.map +0 -1
  57. package/dist/src/transformers/EnhancedJsonMapping.d.ts +0 -194
  58. package/dist/src/transformers/JsonMappingConverter.d.ts +0 -200
  59. package/dist/src/transformers/JsonMappingUnifier.d.ts +0 -100
  60. package/dist/src/transformers/ModelDrivenJsonMapping.d.ts +0 -62
  61. package/dist/src/transformers/PostgresArrayEntityCteBuilder.d.ts +0 -138
  62. package/dist/src/transformers/PostgresJsonQueryBuilder.d.ts +0 -88
  63. package/dist/src/transformers/PostgresObjectEntityCteBuilder.d.ts +0 -165
  64. package/dist/src/transformers/TypeTransformationPostProcessor.d.ts +0 -108
  65. package/dist/src/utils/JsonSchemaValidator.d.ts +0 -81
  66. package/dist/transformers/EnhancedJsonMapping.js +0 -223
  67. package/dist/transformers/EnhancedJsonMapping.js.map +0 -1
  68. package/dist/transformers/JsonMappingConverter.js +0 -392
  69. package/dist/transformers/JsonMappingConverter.js.map +0 -1
  70. package/dist/transformers/JsonMappingUnifier.js +0 -216
  71. package/dist/transformers/JsonMappingUnifier.js.map +0 -1
  72. package/dist/transformers/ModelDrivenJsonMapping.js +0 -122
  73. package/dist/transformers/ModelDrivenJsonMapping.js.map +0 -1
  74. package/dist/transformers/PostgresArrayEntityCteBuilder.js +0 -458
  75. package/dist/transformers/PostgresArrayEntityCteBuilder.js.map +0 -1
  76. package/dist/transformers/PostgresJsonQueryBuilder.js +0 -245
  77. package/dist/transformers/PostgresJsonQueryBuilder.js.map +0 -1
  78. package/dist/transformers/PostgresObjectEntityCteBuilder.js +0 -347
  79. package/dist/transformers/PostgresObjectEntityCteBuilder.js.map +0 -1
  80. package/dist/transformers/TypeTransformationPostProcessor.js +0 -363
  81. package/dist/transformers/TypeTransformationPostProcessor.js.map +0 -1
  82. package/dist/utils/JsonSchemaValidator.js +0 -215
  83. package/dist/utils/JsonSchemaValidator.js.map +0 -1
@@ -1,194 +0,0 @@
1
- /**
2
- * Enhanced JSON mapping structure that extends the base JsonMapping interface
3
- * with additional metadata and type safety features.
4
- */
5
- /**
6
- * Supported column types for enhanced mapping.
7
- */
8
- export type ColumnType = 'string' | 'number' | 'boolean' | 'date' | 'auto';
9
- /**
10
- * Enhanced column configuration that supports both simple and complex mappings.
11
- */
12
- export interface ColumnConfig {
13
- /** Source column name */
14
- column: string;
15
- /** Type enforcement for this column */
16
- type?: ColumnType;
17
- /** Whether this field is nullable */
18
- nullable?: boolean;
19
- /** Custom transformation function */
20
- transform?: string;
21
- }
22
- /**
23
- * Column mapping can be either a simple string or enhanced configuration.
24
- */
25
- export type ColumnMapping = string | ColumnConfig;
26
- /**
27
- * Enhanced entity definition with additional metadata.
28
- */
29
- export interface EnhancedEntity {
30
- id: string;
31
- name: string;
32
- columns: Record<string, ColumnMapping>;
33
- /** Entity description for documentation */
34
- description?: string;
35
- }
36
- /**
37
- * Enhanced nested entity with relationship metadata.
38
- */
39
- export interface EnhancedNestedEntity extends EnhancedEntity {
40
- parentId: string;
41
- propertyName: string;
42
- relationshipType: 'object' | 'array';
43
- /** Join condition for complex relationships */
44
- joinCondition?: string;
45
- }
46
- /**
47
- * Type protection configuration.
48
- */
49
- export interface TypeProtectionConfig {
50
- /** Columns that should be treated as strings */
51
- protectedStringFields: string[];
52
- /** Columns that should be parsed as dates */
53
- dateFields?: string[];
54
- /** Columns that should be parsed as numbers */
55
- numberFields?: string[];
56
- /** Custom type transformations */
57
- customTransforms?: Record<string, string>;
58
- }
59
- /**
60
- * Enhanced JSON mapping with type safety and metadata support.
61
- */
62
- export interface EnhancedJsonMapping {
63
- /** Root entity name */
64
- rootName: string;
65
- /** Root entity definition */
66
- rootEntity: EnhancedEntity;
67
- /** Nested entities */
68
- nestedEntities: EnhancedNestedEntity[];
69
- /** Result format */
70
- resultFormat?: 'array' | 'single';
71
- /** Empty result fallback */
72
- emptyResult?: string;
73
- /** Type information */
74
- typeInfo?: {
75
- interface: string;
76
- importPath: string;
77
- generics?: string[];
78
- };
79
- /** Type protection configuration */
80
- typeProtection?: TypeProtectionConfig;
81
- /** Mapping metadata */
82
- metadata?: {
83
- version: string;
84
- description?: string;
85
- author?: string;
86
- createdAt?: string;
87
- updatedAt?: string;
88
- };
89
- }
90
- /**
91
- * Legacy JSON mapping interface (from PostgresJsonQueryBuilder).
92
- */
93
- export interface LegacyJsonMapping {
94
- rootName: string;
95
- rootEntity: {
96
- id: string;
97
- name: string;
98
- columns: {
99
- [jsonKey: string]: string;
100
- };
101
- };
102
- nestedEntities: Array<{
103
- id: string;
104
- name: string;
105
- parentId: string;
106
- propertyName: string;
107
- relationshipType?: "object" | "array";
108
- columns: {
109
- [jsonKey: string]: string;
110
- };
111
- }>;
112
- resultFormat?: "array" | "single";
113
- emptyResult?: string;
114
- }
115
- /**
116
- * Converts enhanced column configurations to simple string mappings for legacy compatibility.
117
- *
118
- * This function transforms complex column configurations (with type info, nullable flags, etc.)
119
- * into simple string mappings that can be used with PostgresJsonQueryBuilder.
120
- *
121
- * **Supported Input Formats:**
122
- * - Simple strings: `"user_name"` → `"user_name"`
123
- * - Column config: `{ column: "u.name", type: "string" }` → `"u.name"`
124
- * - From config: `{ from: "user_name", nullable: true }` → `"user_name"`
125
- *
126
- * @param columns - Record of field names to column configurations
127
- * @returns Record of field names to column source strings
128
- *
129
- * @example
130
- * ```typescript
131
- * const enhanced = {
132
- * id: { column: "u.user_id", type: "number" },
133
- * name: { from: "user_name", type: "string" },
134
- * email: "email_address"
135
- * };
136
- *
137
- * const legacy = convertColumnsToLegacy(enhanced);
138
- * // Result: { id: "u.user_id", name: "user_name", email: "email_address" }
139
- * ```
140
- */
141
- export declare function convertColumnsToLegacy(columns: Record<string, any>): Record<string, string>;
142
- /**
143
- * Converts any unified JSON mapping format to legacy JsonMapping format.
144
- *
145
- * This universal converter handles Enhanced, Unified, and Legacy formats, providing
146
- * a single interface for converting complex mapping configurations to the simple
147
- * format expected by PostgresJsonQueryBuilder.
148
- *
149
- * **Supported Input Formats:**
150
- * - **Enhanced**: With metadata, type protection, and advanced column configs
151
- * - **Unified**: Standard format with rootName and rootEntity
152
- * - **Legacy**: Already compatible format (returned as-is)
153
- *
154
- * **Features:**
155
- * - Automatic format detection
156
- * - Column configuration simplification
157
- * - Nested entity handling
158
- * - Type protection extraction
159
- *
160
- * @param input - JSON mapping in any supported format
161
- * @returns Legacy JsonMapping compatible with PostgresJsonQueryBuilder
162
- *
163
- * @throws {Error} When input is null, undefined, or malformed
164
- *
165
- * @example
166
- * ```typescript
167
- * // Enhanced format input
168
- * const enhanced = {
169
- * rootName: "User",
170
- * rootEntity: {
171
- * columns: {
172
- * id: { column: "u.user_id", type: "number" },
173
- * name: { column: "u.user_name", type: "string" }
174
- * }
175
- * },
176
- * metadata: { version: "2.0" }
177
- * };
178
- *
179
- * const legacy = convertToLegacyJsonMapping(enhanced);
180
- * // Result: Compatible with PostgresJsonQueryBuilder
181
- * ```
182
- *
183
- * @see {@link convertColumnsToLegacy} For column-specific conversion
184
- * @see {@link extractTypeProtection} For type safety features
185
- */
186
- export declare function convertToLegacyJsonMapping(input: any): LegacyJsonMapping;
187
- /**
188
- * Converts enhanced mapping to legacy format for backward compatibility.
189
- */
190
- export declare function toLegacyMapping(enhanced: EnhancedJsonMapping): LegacyJsonMapping;
191
- /**
192
- * Extracts type protection configuration from enhanced mapping.
193
- */
194
- export declare function extractTypeProtection(enhanced: EnhancedJsonMapping): TypeProtectionConfig;
@@ -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,100 +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 { JsonMapping } from './PostgresJsonQueryBuilder';
9
- import { ModelDrivenJsonMapping } from './ModelDrivenJsonMapping';
10
- /**
11
- * Unified mapping format that can handle both legacy and model-driven inputs.
12
- */
13
- export interface UnifiedMappingInput {
14
- typeInfo?: {
15
- interface: string;
16
- importPath: string;
17
- };
18
- structure?: any;
19
- protectedStringFields?: string[];
20
- rootName?: string;
21
- rootEntity?: any;
22
- nestedEntities?: any[];
23
- columns?: any;
24
- relationships?: any;
25
- }
26
- /**
27
- * Result of mapping format detection and conversion.
28
- */
29
- export interface MappingProcessResult {
30
- format: 'model-driven' | 'unified' | 'legacy';
31
- jsonMapping: JsonMapping;
32
- originalInput: UnifiedMappingInput;
33
- metadata?: {
34
- typeInfo?: {
35
- interface: string;
36
- importPath: string;
37
- };
38
- protectedStringFields?: string[];
39
- typeProtection?: any;
40
- };
41
- }
42
- /**
43
- * Detects the format of a JSON mapping configuration.
44
- *
45
- * @param input - The mapping configuration to analyze
46
- * @returns The detected format type
47
- */
48
- export declare function detectMappingFormat(input: UnifiedMappingInput): 'model-driven' | 'unified' | 'legacy';
49
- /**
50
- * Main processor that unifies all JSON mapping formats into a consistent JsonMapping.
51
- *
52
- * @deprecated Use JsonMappingConverter.convert() instead.
53
- *
54
- * Features:
55
- * - Automatic format detection
56
- * - Backward compatibility with all existing formats
57
- * - Metadata preservation for advanced features
58
- * - Zero external dependencies
59
- *
60
- * @param input - Any supported JSON mapping format
61
- * @returns Unified processing result with JsonMapping and metadata
62
- */
63
- export declare function processJsonMapping(input: UnifiedMappingInput): MappingProcessResult;
64
- /**
65
- * Convenience function for direct JsonMapping extraction.
66
- *
67
- * @deprecated Use JsonMappingConverter.toLegacyMapping() instead.
68
- *
69
- * @param input - Any supported JSON mapping format
70
- * @returns JsonMapping ready for use with PostgresJsonQueryBuilder
71
- */
72
- export declare function unifyJsonMapping(input: UnifiedMappingInput): JsonMapping;
73
- /**
74
- * Type guard to check if input uses model-driven format.
75
- *
76
- * @param input - Mapping input to check
77
- * @returns True if input is model-driven format
78
- */
79
- export declare function isModelDrivenFormat(input: UnifiedMappingInput): input is ModelDrivenJsonMapping;
80
- /**
81
- * Type guard to check if input uses unified format.
82
- *
83
- * @param input - Mapping input to check
84
- * @returns True if input is unified format
85
- */
86
- export declare function isUnifiedFormat(input: UnifiedMappingInput): boolean;
87
- /**
88
- * Type guard to check if input uses legacy format.
89
- *
90
- * @param input - Mapping input to check
91
- * @returns True if input is legacy format
92
- */
93
- export declare function isLegacyFormat(input: UnifiedMappingInput): boolean;
94
- /**
95
- * Migration helper that suggests upgrading to model-driven format.
96
- *
97
- * @param input - Current mapping configuration
98
- * @returns Suggestions for migration (if applicable)
99
- */
100
- export declare function suggestModelDrivenMigration(input: UnifiedMappingInput): string[];
@@ -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,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
- }