rawsql-ts 0.11.0-beta → 0.11.2-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -3
- package/dist/esm/index.js +8 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.min.js +47 -13
- package/dist/esm/index.min.js.map +4 -4
- package/dist/esm/src/index.js +8 -1
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/parsers/ValueParser.js +86 -4
- package/dist/esm/src/parsers/ValueParser.js.map +1 -1
- package/dist/esm/src/tokenReaders/OperatorTokenReader.js +4 -0
- package/dist/esm/src/tokenReaders/OperatorTokenReader.js.map +1 -1
- package/dist/esm/src/transformers/CTEDependencyTracer.js +249 -0
- package/dist/esm/src/transformers/CTEDependencyTracer.js.map +1 -0
- package/dist/esm/src/transformers/DynamicQueryBuilder.js.map +1 -1
- package/dist/esm/src/transformers/EnhancedJsonMapping.js +217 -0
- package/dist/esm/src/transformers/EnhancedJsonMapping.js.map +1 -0
- package/dist/esm/src/transformers/JsonMappingConverter.js +388 -0
- package/dist/esm/src/transformers/JsonMappingConverter.js.map +1 -0
- package/dist/esm/src/transformers/JsonMappingUnifier.js +207 -0
- package/dist/esm/src/transformers/JsonMappingUnifier.js.map +1 -0
- package/dist/esm/src/transformers/ModelDrivenJsonMapping.js +115 -0
- package/dist/esm/src/transformers/ModelDrivenJsonMapping.js.map +1 -0
- package/dist/esm/src/transformers/PostgresArrayEntityCteBuilder.js +293 -70
- package/dist/esm/src/transformers/PostgresArrayEntityCteBuilder.js.map +1 -1
- package/dist/esm/src/transformers/PostgresJsonQueryBuilder.js +26 -15
- package/dist/esm/src/transformers/PostgresJsonQueryBuilder.js.map +1 -1
- package/dist/esm/src/transformers/PostgresObjectEntityCteBuilder.js +75 -15
- package/dist/esm/src/transformers/PostgresObjectEntityCteBuilder.js.map +1 -1
- package/dist/esm/src/transformers/SelectableColumnCollector.js +17 -5
- package/dist/esm/src/transformers/SelectableColumnCollector.js.map +1 -1
- package/dist/esm/src/transformers/SqlParamInjector.js +189 -108
- package/dist/esm/src/transformers/SqlParamInjector.js.map +1 -1
- package/dist/esm/src/transformers/UnifiedJsonMapping.js +2 -4
- package/dist/esm/src/transformers/UnifiedJsonMapping.js.map +1 -1
- package/dist/esm/src/transformers/UpstreamSelectQueryFinder.js +51 -3
- package/dist/esm/src/transformers/UpstreamSelectQueryFinder.js.map +1 -1
- package/dist/esm/src/utils/OperatorPrecedence.js +3 -1
- package/dist/esm/src/utils/OperatorPrecedence.js.map +1 -1
- package/dist/esm/src/utils/SchemaManager.js +0 -1
- package/dist/esm/src/utils/SchemaManager.js.map +1 -1
- package/dist/esm/tsconfig.browser.tsbuildinfo +1 -1
- package/dist/esm/types/src/index.d.ts +8 -1
- package/dist/esm/types/src/parsers/ValueParser.d.ts +8 -0
- package/dist/esm/types/src/transformers/CTEDependencyTracer.d.ts +58 -0
- package/dist/esm/types/src/transformers/DynamicQueryBuilder.d.ts +6 -0
- package/dist/esm/types/src/transformers/EnhancedJsonMapping.d.ts +194 -0
- package/dist/esm/types/src/transformers/JsonMappingConverter.d.ts +200 -0
- package/dist/esm/types/src/transformers/JsonMappingUnifier.d.ts +100 -0
- package/dist/esm/types/src/transformers/ModelDrivenJsonMapping.d.ts +62 -0
- package/dist/esm/types/src/transformers/PostgresArrayEntityCteBuilder.d.ts +93 -52
- package/dist/esm/types/src/transformers/PostgresJsonQueryBuilder.d.ts +3 -3
- package/dist/esm/types/src/transformers/PostgresObjectEntityCteBuilder.d.ts +31 -6
- package/dist/esm/types/src/transformers/SelectableColumnCollector.d.ts +14 -3
- package/dist/esm/types/src/transformers/SqlParamInjector.d.ts +48 -0
- package/dist/esm/types/src/transformers/UnifiedJsonMapping.d.ts +0 -1
- package/dist/esm/types/src/transformers/UpstreamSelectQueryFinder.d.ts +13 -1
- package/dist/index.min.js +47 -13
- package/dist/index.min.js.map +4 -4
- package/dist/src/index.d.ts +8 -1
- package/dist/src/index.js +15 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/parsers/ValueParser.d.ts +8 -0
- package/dist/src/parsers/ValueParser.js +86 -4
- package/dist/src/parsers/ValueParser.js.map +1 -1
- package/dist/src/tokenReaders/OperatorTokenReader.js +4 -0
- package/dist/src/tokenReaders/OperatorTokenReader.js.map +1 -1
- package/dist/src/transformers/CTEDependencyTracer.d.ts +58 -0
- package/dist/src/transformers/CTEDependencyTracer.js +253 -0
- package/dist/src/transformers/CTEDependencyTracer.js.map +1 -0
- package/dist/src/transformers/DynamicQueryBuilder.d.ts +6 -0
- package/dist/src/transformers/DynamicQueryBuilder.js.map +1 -1
- package/dist/src/transformers/EnhancedJsonMapping.d.ts +194 -0
- package/dist/src/transformers/EnhancedJsonMapping.js +223 -0
- package/dist/src/transformers/EnhancedJsonMapping.js.map +1 -0
- package/dist/src/transformers/JsonMappingConverter.d.ts +200 -0
- package/dist/src/transformers/JsonMappingConverter.js +392 -0
- package/dist/src/transformers/JsonMappingConverter.js.map +1 -0
- package/dist/src/transformers/JsonMappingUnifier.d.ts +100 -0
- package/dist/src/transformers/JsonMappingUnifier.js +216 -0
- package/dist/src/transformers/JsonMappingUnifier.js.map +1 -0
- package/dist/src/transformers/ModelDrivenJsonMapping.d.ts +62 -0
- package/dist/src/transformers/ModelDrivenJsonMapping.js +122 -0
- package/dist/src/transformers/ModelDrivenJsonMapping.js.map +1 -0
- package/dist/src/transformers/PostgresArrayEntityCteBuilder.d.ts +93 -52
- package/dist/src/transformers/PostgresArrayEntityCteBuilder.js +293 -70
- package/dist/src/transformers/PostgresArrayEntityCteBuilder.js.map +1 -1
- package/dist/src/transformers/PostgresJsonQueryBuilder.d.ts +3 -3
- package/dist/src/transformers/PostgresJsonQueryBuilder.js +26 -15
- package/dist/src/transformers/PostgresJsonQueryBuilder.js.map +1 -1
- package/dist/src/transformers/PostgresObjectEntityCteBuilder.d.ts +31 -6
- package/dist/src/transformers/PostgresObjectEntityCteBuilder.js +75 -15
- package/dist/src/transformers/PostgresObjectEntityCteBuilder.js.map +1 -1
- package/dist/src/transformers/SelectableColumnCollector.d.ts +14 -3
- package/dist/src/transformers/SelectableColumnCollector.js +17 -5
- package/dist/src/transformers/SelectableColumnCollector.js.map +1 -1
- package/dist/src/transformers/SqlParamInjector.d.ts +48 -0
- package/dist/src/transformers/SqlParamInjector.js +189 -108
- package/dist/src/transformers/SqlParamInjector.js.map +1 -1
- package/dist/src/transformers/UnifiedJsonMapping.d.ts +0 -1
- package/dist/src/transformers/UnifiedJsonMapping.js +2 -4
- package/dist/src/transformers/UnifiedJsonMapping.js.map +1 -1
- package/dist/src/transformers/UpstreamSelectQueryFinder.d.ts +13 -1
- package/dist/src/transformers/UpstreamSelectQueryFinder.js +51 -3
- package/dist/src/transformers/UpstreamSelectQueryFinder.js.map +1 -1
- package/dist/src/utils/OperatorPrecedence.js +3 -1
- package/dist/src/utils/OperatorPrecedence.js.map +1 -1
- package/dist/src/utils/SchemaManager.js +0 -1
- package/dist/src/utils/SchemaManager.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,194 @@
|
|
|
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;
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Enhanced JSON mapping structure that extends the base JsonMapping interface
|
|
4
|
+
* with additional metadata and type safety features.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.convertColumnsToLegacy = convertColumnsToLegacy;
|
|
8
|
+
exports.convertToLegacyJsonMapping = convertToLegacyJsonMapping;
|
|
9
|
+
exports.toLegacyMapping = toLegacyMapping;
|
|
10
|
+
exports.extractTypeProtection = extractTypeProtection;
|
|
11
|
+
/**
|
|
12
|
+
* Converts enhanced column configurations to simple string mappings for legacy compatibility.
|
|
13
|
+
*
|
|
14
|
+
* This function transforms complex column configurations (with type info, nullable flags, etc.)
|
|
15
|
+
* into simple string mappings that can be used with PostgresJsonQueryBuilder.
|
|
16
|
+
*
|
|
17
|
+
* **Supported Input Formats:**
|
|
18
|
+
* - Simple strings: `"user_name"` → `"user_name"`
|
|
19
|
+
* - Column config: `{ column: "u.name", type: "string" }` → `"u.name"`
|
|
20
|
+
* - From config: `{ from: "user_name", nullable: true }` → `"user_name"`
|
|
21
|
+
*
|
|
22
|
+
* @param columns - Record of field names to column configurations
|
|
23
|
+
* @returns Record of field names to column source strings
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* const enhanced = {
|
|
28
|
+
* id: { column: "u.user_id", type: "number" },
|
|
29
|
+
* name: { from: "user_name", type: "string" },
|
|
30
|
+
* email: "email_address"
|
|
31
|
+
* };
|
|
32
|
+
*
|
|
33
|
+
* const legacy = convertColumnsToLegacy(enhanced);
|
|
34
|
+
* // Result: { id: "u.user_id", name: "user_name", email: "email_address" }
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
function convertColumnsToLegacy(columns) {
|
|
38
|
+
const result = {};
|
|
39
|
+
for (const [key, config] of Object.entries(columns)) {
|
|
40
|
+
if (typeof config === 'string') {
|
|
41
|
+
result[key] = config;
|
|
42
|
+
}
|
|
43
|
+
else if (config && typeof config === 'object') {
|
|
44
|
+
if ('column' in config) {
|
|
45
|
+
result[key] = config.column;
|
|
46
|
+
}
|
|
47
|
+
else if ('from' in config) {
|
|
48
|
+
result[key] = config.from;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
result[key] = key; // fallback
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
result[key] = key; // fallback
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Converts any unified JSON mapping format to legacy JsonMapping format.
|
|
62
|
+
*
|
|
63
|
+
* This universal converter handles Enhanced, Unified, and Legacy formats, providing
|
|
64
|
+
* a single interface for converting complex mapping configurations to the simple
|
|
65
|
+
* format expected by PostgresJsonQueryBuilder.
|
|
66
|
+
*
|
|
67
|
+
* **Supported Input Formats:**
|
|
68
|
+
* - **Enhanced**: With metadata, type protection, and advanced column configs
|
|
69
|
+
* - **Unified**: Standard format with rootName and rootEntity
|
|
70
|
+
* - **Legacy**: Already compatible format (returned as-is)
|
|
71
|
+
*
|
|
72
|
+
* **Features:**
|
|
73
|
+
* - Automatic format detection
|
|
74
|
+
* - Column configuration simplification
|
|
75
|
+
* - Nested entity handling
|
|
76
|
+
* - Type protection extraction
|
|
77
|
+
*
|
|
78
|
+
* @param input - JSON mapping in any supported format
|
|
79
|
+
* @returns Legacy JsonMapping compatible with PostgresJsonQueryBuilder
|
|
80
|
+
*
|
|
81
|
+
* @throws {Error} When input is null, undefined, or malformed
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* // Enhanced format input
|
|
86
|
+
* const enhanced = {
|
|
87
|
+
* rootName: "User",
|
|
88
|
+
* rootEntity: {
|
|
89
|
+
* columns: {
|
|
90
|
+
* id: { column: "u.user_id", type: "number" },
|
|
91
|
+
* name: { column: "u.user_name", type: "string" }
|
|
92
|
+
* }
|
|
93
|
+
* },
|
|
94
|
+
* metadata: { version: "2.0" }
|
|
95
|
+
* };
|
|
96
|
+
*
|
|
97
|
+
* const legacy = convertToLegacyJsonMapping(enhanced);
|
|
98
|
+
* // Result: Compatible with PostgresJsonQueryBuilder
|
|
99
|
+
* ```
|
|
100
|
+
*
|
|
101
|
+
* @see {@link convertColumnsToLegacy} For column-specific conversion
|
|
102
|
+
* @see {@link extractTypeProtection} For type safety features
|
|
103
|
+
*/
|
|
104
|
+
function convertToLegacyJsonMapping(input) {
|
|
105
|
+
if (!input) {
|
|
106
|
+
throw new Error('Input mapping is required');
|
|
107
|
+
}
|
|
108
|
+
// If it's already in legacy format, return as-is
|
|
109
|
+
if (input.rootName && input.rootEntity &&
|
|
110
|
+
typeof input.rootEntity.columns === 'object' &&
|
|
111
|
+
!input.typeInfo && !input.typeProtection && !input.metadata) {
|
|
112
|
+
// Check if columns are already in string format
|
|
113
|
+
const allColumnsAreStrings = Object.values(input.rootEntity.columns).every(col => typeof col === 'string');
|
|
114
|
+
if (allColumnsAreStrings) {
|
|
115
|
+
return input;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
// Enhanced format conversion
|
|
119
|
+
if (input.rootName && input.rootEntity) {
|
|
120
|
+
return {
|
|
121
|
+
rootName: input.rootName,
|
|
122
|
+
rootEntity: {
|
|
123
|
+
id: input.rootEntity.id || 'root',
|
|
124
|
+
name: input.rootEntity.name || input.rootName,
|
|
125
|
+
columns: convertColumnsToLegacy(input.rootEntity.columns || {})
|
|
126
|
+
},
|
|
127
|
+
nestedEntities: (input.nestedEntities || []).map((entity) => ({
|
|
128
|
+
id: entity.id,
|
|
129
|
+
name: entity.name,
|
|
130
|
+
parentId: entity.parentId,
|
|
131
|
+
propertyName: entity.propertyName,
|
|
132
|
+
relationshipType: entity.relationshipType,
|
|
133
|
+
columns: convertColumnsToLegacy(entity.columns || {})
|
|
134
|
+
})),
|
|
135
|
+
resultFormat: input.resultFormat,
|
|
136
|
+
emptyResult: input.emptyResult
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
throw new Error('Unsupported mapping format');
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Converts enhanced mapping to legacy format for backward compatibility.
|
|
143
|
+
*/
|
|
144
|
+
function toLegacyMapping(enhanced) {
|
|
145
|
+
return {
|
|
146
|
+
rootName: enhanced.rootName,
|
|
147
|
+
rootEntity: {
|
|
148
|
+
id: enhanced.rootEntity.id,
|
|
149
|
+
name: enhanced.rootEntity.name,
|
|
150
|
+
columns: convertColumnsToLegacy(enhanced.rootEntity.columns)
|
|
151
|
+
},
|
|
152
|
+
nestedEntities: enhanced.nestedEntities.map(entity => ({
|
|
153
|
+
id: entity.id,
|
|
154
|
+
name: entity.name,
|
|
155
|
+
parentId: entity.parentId,
|
|
156
|
+
propertyName: entity.propertyName,
|
|
157
|
+
relationshipType: entity.relationshipType,
|
|
158
|
+
columns: convertColumnsToLegacy(entity.columns)
|
|
159
|
+
})),
|
|
160
|
+
resultFormat: enhanced.resultFormat,
|
|
161
|
+
emptyResult: enhanced.emptyResult
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Extracts type protection configuration from enhanced mapping.
|
|
166
|
+
*/
|
|
167
|
+
function extractTypeProtection(enhanced) {
|
|
168
|
+
const protectedStringFields = [];
|
|
169
|
+
const dateFields = [];
|
|
170
|
+
const numberFields = [];
|
|
171
|
+
// Use existing type protection if available
|
|
172
|
+
if (enhanced.typeProtection) {
|
|
173
|
+
return {
|
|
174
|
+
protectedStringFields: enhanced.typeProtection.protectedStringFields || [],
|
|
175
|
+
dateFields: enhanced.typeProtection.dateFields,
|
|
176
|
+
numberFields: enhanced.typeProtection.numberFields,
|
|
177
|
+
customTransforms: enhanced.typeProtection.customTransforms
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
// Process root entity
|
|
181
|
+
for (const [key, config] of Object.entries(enhanced.rootEntity.columns)) {
|
|
182
|
+
if (typeof config === 'object' && config.type) {
|
|
183
|
+
const columnName = config.column;
|
|
184
|
+
switch (config.type) {
|
|
185
|
+
case 'string':
|
|
186
|
+
protectedStringFields.push(columnName);
|
|
187
|
+
break;
|
|
188
|
+
case 'date':
|
|
189
|
+
dateFields.push(columnName);
|
|
190
|
+
break;
|
|
191
|
+
case 'number':
|
|
192
|
+
numberFields.push(columnName);
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
// Process nested entities
|
|
198
|
+
for (const entity of enhanced.nestedEntities) {
|
|
199
|
+
for (const [key, config] of Object.entries(entity.columns)) {
|
|
200
|
+
if (typeof config === 'object' && config.type) {
|
|
201
|
+
const columnName = config.column;
|
|
202
|
+
switch (config.type) {
|
|
203
|
+
case 'string':
|
|
204
|
+
protectedStringFields.push(columnName);
|
|
205
|
+
break;
|
|
206
|
+
case 'date':
|
|
207
|
+
dateFields.push(columnName);
|
|
208
|
+
break;
|
|
209
|
+
case 'number':
|
|
210
|
+
numberFields.push(columnName);
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return {
|
|
217
|
+
protectedStringFields,
|
|
218
|
+
dateFields: dateFields.length > 0 ? dateFields : undefined,
|
|
219
|
+
numberFields: numberFields.length > 0 ? numberFields : undefined,
|
|
220
|
+
customTransforms: undefined
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
//# sourceMappingURL=EnhancedJsonMapping.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EnhancedJsonMapping.js","sourceRoot":"","sources":["../../../src/transformers/EnhancedJsonMapping.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AA8IH,wDAkBC;AA8CD,gEA2CC;AAKD,0CAoBC;AAKD,sDA2DC;AA9ND;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,SAAgB,sBAAsB,CAAC,OAA4B;IAC/D,MAAM,MAAM,GAA2B,EAAE,CAAC;IAC1C,KAAK,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAClD,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;YAC7B,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC;QACzB,CAAC;aAAM,IAAI,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;YAC9C,IAAI,QAAQ,IAAI,MAAM,EAAE,CAAC;gBACrB,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,C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AC,UAAU,CAAC,CAAC;oBAC9B,MAAM;YACd,CAAC;QACL,CAAC;IACL,CAAC;IAED,0BAA0B;IAC1B,KAAK,MAAM,MAAM,IAAI,QAAQ,CAAC,cAAc,EAAE,CAAC;QAC3C,KAAK,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;YACzD,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;gBAC5C,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC;gBACjC,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;oBAClB,KAAK,QAAQ;wBACT,qBAAqB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;wBACvC,MAAM;oBACV,KAAK,MAAM;wBACP,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;wBAC5B,MAAM;oBACV,KAAK,QAAQ;wBACT,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;wBAC9B,MAAM;gBACd,CAAC;YACL,CAAC;QACL,CAAC;IACL,CAAC;IAED,OAAO;QACH,qBAAqB;QACrB,UAAU,EAAE,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS;QAC1D,YAAY,EAAE,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS;QAChE,gBAAgB,EAAE,SAAS;KAC9B,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,200 @@
|
|
|
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
|
+
}
|