rawsql-ts 0.11.1-beta → 0.11.3-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 +735 -682
- package/dist/esm/index.js +8 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.min.js +46 -12
- package/dist/esm/index.min.js.map +4 -4
- package/dist/esm/src/index.js +8 -2
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/models/BinarySelectQuery.js +9 -0
- package/dist/esm/src/models/BinarySelectQuery.js.map +1 -1
- package/dist/esm/src/models/CTEError.js +31 -0
- package/dist/esm/src/models/CTEError.js.map +1 -0
- package/dist/esm/src/models/SelectQuery.js +1 -0
- package/dist/esm/src/models/SelectQuery.js.map +1 -1
- package/dist/esm/src/models/SimpleSelectQuery.js +229 -0
- package/dist/esm/src/models/SimpleSelectQuery.js.map +1 -1
- package/dist/esm/src/models/ValuesQuery.js +1 -1
- package/dist/esm/src/models/ValuesQuery.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/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 +36 -46
- package/dist/esm/src/transformers/JsonMappingUnifier.js.map +1 -1
- package/dist/esm/src/transformers/ModelDrivenJsonMapping.js +14 -2
- package/dist/esm/src/transformers/ModelDrivenJsonMapping.js.map +1 -1
- package/dist/esm/src/transformers/PostgresArrayEntityCteBuilder.js +132 -97
- package/dist/esm/src/transformers/PostgresArrayEntityCteBuilder.js.map +1 -1
- package/dist/esm/src/transformers/PostgresJsonQueryBuilder.js +21 -11
- package/dist/esm/src/transformers/PostgresJsonQueryBuilder.js.map +1 -1
- package/dist/esm/src/transformers/PostgresObjectEntityCteBuilder.js +71 -14
- package/dist/esm/src/transformers/PostgresObjectEntityCteBuilder.js.map +1 -1
- package/dist/esm/src/transformers/QueryBuilder.js +2 -0
- package/dist/esm/src/transformers/QueryBuilder.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/UpstreamSelectQueryFinder.js +43 -2
- package/dist/esm/src/transformers/UpstreamSelectQueryFinder.js.map +1 -1
- package/dist/esm/tsconfig.browser.tsbuildinfo +1 -1
- package/dist/esm/types/src/index.d.ts +8 -2
- package/dist/esm/types/src/models/BinarySelectQuery.d.ts +7 -0
- package/dist/esm/types/src/models/CTEError.d.ts +21 -0
- package/dist/esm/types/src/models/SelectQuery.d.ts +12 -0
- package/dist/esm/types/src/models/SimpleSelectQuery.d.ts +166 -2
- package/dist/esm/types/src/models/ValuesQuery.d.ts +1 -1
- package/dist/esm/types/src/parsers/ValueParser.d.ts +8 -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 +5 -0
- package/dist/esm/types/src/transformers/PostgresArrayEntityCteBuilder.d.ts +39 -77
- package/dist/esm/types/src/transformers/PostgresJsonQueryBuilder.d.ts +3 -2
- package/dist/esm/types/src/transformers/PostgresObjectEntityCteBuilder.d.ts +31 -6
- package/dist/esm/types/src/transformers/SqlParamInjector.d.ts +48 -0
- package/dist/esm/types/src/transformers/UpstreamSelectQueryFinder.d.ts +8 -0
- package/dist/index.min.js +46 -12
- package/dist/index.min.js.map +4 -4
- package/dist/src/index.d.ts +8 -2
- package/dist/src/index.js +8 -3
- package/dist/src/index.js.map +1 -1
- package/dist/src/models/BinarySelectQuery.d.ts +7 -0
- package/dist/src/models/BinarySelectQuery.js +9 -0
- package/dist/src/models/BinarySelectQuery.js.map +1 -1
- package/dist/src/models/CTEError.d.ts +21 -0
- package/dist/src/models/CTEError.js +37 -0
- package/dist/src/models/CTEError.js.map +1 -0
- package/dist/src/models/SelectQuery.d.ts +12 -0
- package/dist/src/models/SelectQuery.js +5 -1
- package/dist/src/models/SelectQuery.js.map +1 -1
- package/dist/src/models/SimpleSelectQuery.d.ts +166 -2
- package/dist/src/models/SimpleSelectQuery.js +229 -0
- package/dist/src/models/SimpleSelectQuery.js.map +1 -1
- package/dist/src/models/ValuesQuery.d.ts +1 -1
- package/dist/src/models/ValuesQuery.js +1 -1
- package/dist/src/models/ValuesQuery.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/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 +5 -0
- package/dist/src/transformers/JsonMappingUnifier.js +36 -46
- package/dist/src/transformers/JsonMappingUnifier.js.map +1 -1
- package/dist/src/transformers/ModelDrivenJsonMapping.js +14 -2
- package/dist/src/transformers/ModelDrivenJsonMapping.js.map +1 -1
- package/dist/src/transformers/PostgresArrayEntityCteBuilder.d.ts +39 -77
- package/dist/src/transformers/PostgresArrayEntityCteBuilder.js +132 -97
- package/dist/src/transformers/PostgresArrayEntityCteBuilder.js.map +1 -1
- package/dist/src/transformers/PostgresJsonQueryBuilder.d.ts +3 -2
- package/dist/src/transformers/PostgresJsonQueryBuilder.js +21 -11
- package/dist/src/transformers/PostgresJsonQueryBuilder.js.map +1 -1
- package/dist/src/transformers/PostgresObjectEntityCteBuilder.d.ts +31 -6
- package/dist/src/transformers/PostgresObjectEntityCteBuilder.js +71 -14
- package/dist/src/transformers/PostgresObjectEntityCteBuilder.js.map +1 -1
- package/dist/src/transformers/QueryBuilder.js +2 -0
- package/dist/src/transformers/QueryBuilder.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/UpstreamSelectQueryFinder.d.ts +8 -0
- package/dist/src/transformers/UpstreamSelectQueryFinder.js +43 -2
- package/dist/src/transformers/UpstreamSelectQueryFinder.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enhanced JSON mapping structure that extends the base JsonMapping interface
|
|
3
|
+
* with additional metadata and type safety features.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Converts enhanced column configurations to simple string mappings for legacy compatibility.
|
|
7
|
+
*
|
|
8
|
+
* This function transforms complex column configurations (with type info, nullable flags, etc.)
|
|
9
|
+
* into simple string mappings that can be used with PostgresJsonQueryBuilder.
|
|
10
|
+
*
|
|
11
|
+
* **Supported Input Formats:**
|
|
12
|
+
* - Simple strings: `"user_name"` → `"user_name"`
|
|
13
|
+
* - Column config: `{ column: "u.name", type: "string" }` → `"u.name"`
|
|
14
|
+
* - From config: `{ from: "user_name", nullable: true }` → `"user_name"`
|
|
15
|
+
*
|
|
16
|
+
* @param columns - Record of field names to column configurations
|
|
17
|
+
* @returns Record of field names to column source strings
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const enhanced = {
|
|
22
|
+
* id: { column: "u.user_id", type: "number" },
|
|
23
|
+
* name: { from: "user_name", type: "string" },
|
|
24
|
+
* email: "email_address"
|
|
25
|
+
* };
|
|
26
|
+
*
|
|
27
|
+
* const legacy = convertColumnsToLegacy(enhanced);
|
|
28
|
+
* // Result: { id: "u.user_id", name: "user_name", email: "email_address" }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export function convertColumnsToLegacy(columns) {
|
|
32
|
+
const result = {};
|
|
33
|
+
for (const [key, config] of Object.entries(columns)) {
|
|
34
|
+
if (typeof config === 'string') {
|
|
35
|
+
result[key] = config;
|
|
36
|
+
}
|
|
37
|
+
else if (config && typeof config === 'object') {
|
|
38
|
+
if ('column' in config) {
|
|
39
|
+
result[key] = config.column;
|
|
40
|
+
}
|
|
41
|
+
else if ('from' in config) {
|
|
42
|
+
result[key] = config.from;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
result[key] = key; // fallback
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
result[key] = key; // fallback
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Converts any unified JSON mapping format to legacy JsonMapping format.
|
|
56
|
+
*
|
|
57
|
+
* This universal converter handles Enhanced, Unified, and Legacy formats, providing
|
|
58
|
+
* a single interface for converting complex mapping configurations to the simple
|
|
59
|
+
* format expected by PostgresJsonQueryBuilder.
|
|
60
|
+
*
|
|
61
|
+
* **Supported Input Formats:**
|
|
62
|
+
* - **Enhanced**: With metadata, type protection, and advanced column configs
|
|
63
|
+
* - **Unified**: Standard format with rootName and rootEntity
|
|
64
|
+
* - **Legacy**: Already compatible format (returned as-is)
|
|
65
|
+
*
|
|
66
|
+
* **Features:**
|
|
67
|
+
* - Automatic format detection
|
|
68
|
+
* - Column configuration simplification
|
|
69
|
+
* - Nested entity handling
|
|
70
|
+
* - Type protection extraction
|
|
71
|
+
*
|
|
72
|
+
* @param input - JSON mapping in any supported format
|
|
73
|
+
* @returns Legacy JsonMapping compatible with PostgresJsonQueryBuilder
|
|
74
|
+
*
|
|
75
|
+
* @throws {Error} When input is null, undefined, or malformed
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* // Enhanced format input
|
|
80
|
+
* const enhanced = {
|
|
81
|
+
* rootName: "User",
|
|
82
|
+
* rootEntity: {
|
|
83
|
+
* columns: {
|
|
84
|
+
* id: { column: "u.user_id", type: "number" },
|
|
85
|
+
* name: { column: "u.user_name", type: "string" }
|
|
86
|
+
* }
|
|
87
|
+
* },
|
|
88
|
+
* metadata: { version: "2.0" }
|
|
89
|
+
* };
|
|
90
|
+
*
|
|
91
|
+
* const legacy = convertToLegacyJsonMapping(enhanced);
|
|
92
|
+
* // Result: Compatible with PostgresJsonQueryBuilder
|
|
93
|
+
* ```
|
|
94
|
+
*
|
|
95
|
+
* @see {@link convertColumnsToLegacy} For column-specific conversion
|
|
96
|
+
* @see {@link extractTypeProtection} For type safety features
|
|
97
|
+
*/
|
|
98
|
+
export function convertToLegacyJsonMapping(input) {
|
|
99
|
+
if (!input) {
|
|
100
|
+
throw new Error('Input mapping is required');
|
|
101
|
+
}
|
|
102
|
+
// If it's already in legacy format, return as-is
|
|
103
|
+
if (input.rootName && input.rootEntity &&
|
|
104
|
+
typeof input.rootEntity.columns === 'object' &&
|
|
105
|
+
!input.typeInfo && !input.typeProtection && !input.metadata) {
|
|
106
|
+
// Check if columns are already in string format
|
|
107
|
+
const allColumnsAreStrings = Object.values(input.rootEntity.columns).every(col => typeof col === 'string');
|
|
108
|
+
if (allColumnsAreStrings) {
|
|
109
|
+
return input;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
// Enhanced format conversion
|
|
113
|
+
if (input.rootName && input.rootEntity) {
|
|
114
|
+
return {
|
|
115
|
+
rootName: input.rootName,
|
|
116
|
+
rootEntity: {
|
|
117
|
+
id: input.rootEntity.id || 'root',
|
|
118
|
+
name: input.rootEntity.name || input.rootName,
|
|
119
|
+
columns: convertColumnsToLegacy(input.rootEntity.columns || {})
|
|
120
|
+
},
|
|
121
|
+
nestedEntities: (input.nestedEntities || []).map((entity) => ({
|
|
122
|
+
id: entity.id,
|
|
123
|
+
name: entity.name,
|
|
124
|
+
parentId: entity.parentId,
|
|
125
|
+
propertyName: entity.propertyName,
|
|
126
|
+
relationshipType: entity.relationshipType,
|
|
127
|
+
columns: convertColumnsToLegacy(entity.columns || {})
|
|
128
|
+
})),
|
|
129
|
+
resultFormat: input.resultFormat,
|
|
130
|
+
emptyResult: input.emptyResult
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
throw new Error('Unsupported mapping format');
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Converts enhanced mapping to legacy format for backward compatibility.
|
|
137
|
+
*/
|
|
138
|
+
export function toLegacyMapping(enhanced) {
|
|
139
|
+
return {
|
|
140
|
+
rootName: enhanced.rootName,
|
|
141
|
+
rootEntity: {
|
|
142
|
+
id: enhanced.rootEntity.id,
|
|
143
|
+
name: enhanced.rootEntity.name,
|
|
144
|
+
columns: convertColumnsToLegacy(enhanced.rootEntity.columns)
|
|
145
|
+
},
|
|
146
|
+
nestedEntities: enhanced.nestedEntities.map(entity => ({
|
|
147
|
+
id: entity.id,
|
|
148
|
+
name: entity.name,
|
|
149
|
+
parentId: entity.parentId,
|
|
150
|
+
propertyName: entity.propertyName,
|
|
151
|
+
relationshipType: entity.relationshipType,
|
|
152
|
+
columns: convertColumnsToLegacy(entity.columns)
|
|
153
|
+
})),
|
|
154
|
+
resultFormat: enhanced.resultFormat,
|
|
155
|
+
emptyResult: enhanced.emptyResult
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Extracts type protection configuration from enhanced mapping.
|
|
160
|
+
*/
|
|
161
|
+
export function extractTypeProtection(enhanced) {
|
|
162
|
+
const protectedStringFields = [];
|
|
163
|
+
const dateFields = [];
|
|
164
|
+
const numberFields = [];
|
|
165
|
+
// Use existing type protection if available
|
|
166
|
+
if (enhanced.typeProtection) {
|
|
167
|
+
return {
|
|
168
|
+
protectedStringFields: enhanced.typeProtection.protectedStringFields || [],
|
|
169
|
+
dateFields: enhanced.typeProtection.dateFields,
|
|
170
|
+
numberFields: enhanced.typeProtection.numberFields,
|
|
171
|
+
customTransforms: enhanced.typeProtection.customTransforms
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
// Process root entity
|
|
175
|
+
for (const [key, config] of Object.entries(enhanced.rootEntity.columns)) {
|
|
176
|
+
if (typeof config === 'object' && config.type) {
|
|
177
|
+
const columnName = config.column;
|
|
178
|
+
switch (config.type) {
|
|
179
|
+
case 'string':
|
|
180
|
+
protectedStringFields.push(columnName);
|
|
181
|
+
break;
|
|
182
|
+
case 'date':
|
|
183
|
+
dateFields.push(columnName);
|
|
184
|
+
break;
|
|
185
|
+
case 'number':
|
|
186
|
+
numberFields.push(columnName);
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
// Process nested entities
|
|
192
|
+
for (const entity of enhanced.nestedEntities) {
|
|
193
|
+
for (const [key, config] of Object.entries(entity.columns)) {
|
|
194
|
+
if (typeof config === 'object' && config.type) {
|
|
195
|
+
const columnName = config.column;
|
|
196
|
+
switch (config.type) {
|
|
197
|
+
case 'string':
|
|
198
|
+
protectedStringFields.push(columnName);
|
|
199
|
+
break;
|
|
200
|
+
case 'date':
|
|
201
|
+
dateFields.push(columnName);
|
|
202
|
+
break;
|
|
203
|
+
case 'number':
|
|
204
|
+
numberFields.push(columnName);
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return {
|
|
211
|
+
protectedStringFields,
|
|
212
|
+
dateFields: dateFields.length > 0 ? dateFields : undefined,
|
|
213
|
+
numberFields: numberFields.length > 0 ? numberFields : undefined,
|
|
214
|
+
customTransforms: undefined
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
//# sourceMappingURL=EnhancedJsonMapping.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EnhancedJsonMapping.js","sourceRoot":"","sources":["../../../../src/transformers/EnhancedJsonMapping.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAoHH;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,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,CAAC;YAChC,CAAC;iBAAM,IAAI,MAAM,IAAI,MAAM,EAAE,CAAC;gBAC1B,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC;YAC9B,CAAC;iBAAM,CAAC;gBACJ,MAAM,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,WAAW;YAClC,CAAC;QACL,CAAC;aAAM,CAAC;YACJ,MAAM,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,WAAW;QAClC,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,MAAM,UAAU,0BAA0B,CAAC,KAAU;IACjD,IAAI,CAAC,KA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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,388 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified JSON mapping converter that handles all supported formats
|
|
3
|
+
* and provides a single interface for mapping transformations.
|
|
4
|
+
*/
|
|
5
|
+
import { convertModelDrivenMapping } from './ModelDrivenJsonMapping';
|
|
6
|
+
import { toLegacyMapping, extractTypeProtection } from './EnhancedJsonMapping';
|
|
7
|
+
/**
|
|
8
|
+
* Type guard to check if input is valid JSON mapping input
|
|
9
|
+
*/
|
|
10
|
+
function isValidMappingInput(input) {
|
|
11
|
+
return input !== null &&
|
|
12
|
+
input !== undefined &&
|
|
13
|
+
typeof input === 'object';
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Enhanced format conversion strategy.
|
|
17
|
+
*/
|
|
18
|
+
class EnhancedFormatStrategy {
|
|
19
|
+
detect(input) {
|
|
20
|
+
if (!isValidMappingInput(input)) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
const candidate = input;
|
|
24
|
+
if (!candidate ||
|
|
25
|
+
typeof candidate.rootName !== 'string' ||
|
|
26
|
+
!candidate.rootEntity ||
|
|
27
|
+
!Array.isArray(candidate.nestedEntities)) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
// Check if it has enhanced features
|
|
31
|
+
if (candidate.typeInfo || candidate.typeProtection || candidate.metadata) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
// Check if any column uses enhanced format (object with 'column' property)
|
|
35
|
+
const hasEnhancedColumns = (columns) => {
|
|
36
|
+
if (!columns || typeof columns !== 'object')
|
|
37
|
+
return false;
|
|
38
|
+
return Object.values(columns).some(col => typeof col === 'object' && col !== null && 'column' in col);
|
|
39
|
+
};
|
|
40
|
+
if (hasEnhancedColumns(candidate.rootEntity.columns)) {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
return candidate.nestedEntities.some((entity) => entity && typeof entity === 'object' &&
|
|
44
|
+
hasEnhancedColumns(entity.columns));
|
|
45
|
+
}
|
|
46
|
+
convert(input) {
|
|
47
|
+
var _a, _b;
|
|
48
|
+
return {
|
|
49
|
+
format: 'enhanced',
|
|
50
|
+
mapping: toLegacyMapping(input),
|
|
51
|
+
typeProtection: extractTypeProtection(input),
|
|
52
|
+
originalInput: input,
|
|
53
|
+
metadata: {
|
|
54
|
+
typeInfo: input.typeInfo,
|
|
55
|
+
version: (_a = input.metadata) === null || _a === void 0 ? void 0 : _a.version,
|
|
56
|
+
description: (_b = input.metadata) === null || _b === void 0 ? void 0 : _b.description
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Model-driven format conversion strategy.
|
|
63
|
+
*/
|
|
64
|
+
class ModelDrivenFormatStrategy {
|
|
65
|
+
detect(input) {
|
|
66
|
+
if (!isValidMappingInput(input)) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
const candidate = input;
|
|
70
|
+
return candidate &&
|
|
71
|
+
candidate.typeInfo &&
|
|
72
|
+
candidate.structure &&
|
|
73
|
+
typeof candidate.typeInfo.interface === 'string';
|
|
74
|
+
}
|
|
75
|
+
convert(input) {
|
|
76
|
+
// Use the existing convertModelDrivenMapping function to avoid code duplication
|
|
77
|
+
const converted = convertModelDrivenMapping(input);
|
|
78
|
+
return {
|
|
79
|
+
format: 'model-driven',
|
|
80
|
+
mapping: converted.jsonMapping,
|
|
81
|
+
typeProtection: converted.typeProtection,
|
|
82
|
+
originalInput: input,
|
|
83
|
+
metadata: {
|
|
84
|
+
typeInfo: input.typeInfo
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Legacy format conversion strategy.
|
|
91
|
+
*/
|
|
92
|
+
class LegacyFormatStrategy {
|
|
93
|
+
detect(input) {
|
|
94
|
+
if (!isValidMappingInput(input)) {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
const candidate = input;
|
|
98
|
+
if (!candidate ||
|
|
99
|
+
typeof candidate.rootName !== 'string' ||
|
|
100
|
+
!candidate.rootEntity ||
|
|
101
|
+
typeof candidate.rootEntity.columns !== 'object' ||
|
|
102
|
+
candidate.typeInfo || candidate.typeProtection || candidate.metadata) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
// Check if any column uses enhanced format (object with 'column' property)
|
|
106
|
+
const hasEnhancedColumns = (columns) => {
|
|
107
|
+
if (!columns || typeof columns !== 'object')
|
|
108
|
+
return false;
|
|
109
|
+
return Object.values(columns).some(col => typeof col === 'object' && col !== null && 'column' in col);
|
|
110
|
+
};
|
|
111
|
+
// If it has enhanced columns, it's not legacy format
|
|
112
|
+
if (hasEnhancedColumns(candidate.rootEntity.columns)) {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
if (candidate.nestedEntities && Array.isArray(candidate.nestedEntities)) {
|
|
116
|
+
const hasEnhancedNested = candidate.nestedEntities.some((entity) => entity && typeof entity === 'object' && hasEnhancedColumns(entity.columns));
|
|
117
|
+
if (hasEnhancedNested) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
convert(input) {
|
|
124
|
+
return {
|
|
125
|
+
format: 'legacy',
|
|
126
|
+
mapping: input,
|
|
127
|
+
typeProtection: { protectedStringFields: [] },
|
|
128
|
+
originalInput: input
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Unified JSON mapping converter that handles all supported formats using the Strategy pattern.
|
|
134
|
+
*
|
|
135
|
+
* This converter automatically detects the input format and applies the appropriate conversion
|
|
136
|
+
* strategy to transform any supported JSON mapping format into a standardized result.
|
|
137
|
+
*
|
|
138
|
+
* **Supported Formats:**
|
|
139
|
+
* - **Enhanced**: Rich format with metadata, type protection, and advanced column configurations
|
|
140
|
+
* - **Model-Driven**: TypeScript interface-based mapping with structured field definitions
|
|
141
|
+
* - **Legacy**: Simple format compatible with PostgresJsonQueryBuilder
|
|
142
|
+
*
|
|
143
|
+
* **Usage:**
|
|
144
|
+
* ```typescript
|
|
145
|
+
* const converter = new JsonMappingConverter();
|
|
146
|
+
* const result = converter.convert(someMapping);
|
|
147
|
+
* const legacyMapping = converter.toLegacyMapping(someMapping);
|
|
148
|
+
* ```
|
|
149
|
+
*
|
|
150
|
+
* @public
|
|
151
|
+
*/
|
|
152
|
+
export class JsonMappingConverter {
|
|
153
|
+
/**
|
|
154
|
+
* Creates a new JsonMappingConverter with all supported strategies.
|
|
155
|
+
*
|
|
156
|
+
* Strategies are checked in order of specificity:
|
|
157
|
+
* 1. Enhanced format (most feature-rich)
|
|
158
|
+
* 2. Model-driven format (TypeScript-based)
|
|
159
|
+
* 3. Legacy format (fallback)
|
|
160
|
+
*/
|
|
161
|
+
constructor() {
|
|
162
|
+
this.strategies = [
|
|
163
|
+
new EnhancedFormatStrategy(),
|
|
164
|
+
new ModelDrivenFormatStrategy(),
|
|
165
|
+
new LegacyFormatStrategy()
|
|
166
|
+
];
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Detects the format of the input mapping without performing conversion.
|
|
170
|
+
*
|
|
171
|
+
* This method uses the same strategy pattern as conversion but only returns
|
|
172
|
+
* the detected format type for inspection purposes.
|
|
173
|
+
*
|
|
174
|
+
* @param input - The JSON mapping to analyze
|
|
175
|
+
* @returns The detected mapping format type
|
|
176
|
+
*
|
|
177
|
+
* @throws {Error} When input format is not supported by any strategy
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```typescript
|
|
181
|
+
* const format = converter.detectFormat(myMapping);
|
|
182
|
+
* console.log(`Detected format: ${format}`); // "enhanced", "model-driven", or "legacy"
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
detectFormat(input) {
|
|
186
|
+
for (const strategy of this.strategies) {
|
|
187
|
+
if (strategy.detect(input)) {
|
|
188
|
+
const result = strategy.convert(input);
|
|
189
|
+
return result.format;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
throw new Error('Unsupported JSON mapping format');
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Converts any supported JSON mapping format to a comprehensive result with metadata.
|
|
196
|
+
*
|
|
197
|
+
* This is the primary conversion method that performs format detection and transformation
|
|
198
|
+
* in a single operation. The result includes the legacy mapping, type protection configuration,
|
|
199
|
+
* and metadata about the conversion process.
|
|
200
|
+
*
|
|
201
|
+
* @param input - The JSON mapping in any supported format (Enhanced, Model-Driven, or Legacy)
|
|
202
|
+
* @returns Complete conversion result with mapping, metadata, and type protection
|
|
203
|
+
*
|
|
204
|
+
* @throws {Error} When the input format is not recognized by any strategy
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```typescript
|
|
208
|
+
* const result = converter.convert(enhancedMapping);
|
|
209
|
+
* console.log(`Format: ${result.format}`);
|
|
210
|
+
* console.log(`Type protection: ${result.typeProtection.protectedStringFields.length} fields`);
|
|
211
|
+
*
|
|
212
|
+
* // Use the converted mapping
|
|
213
|
+
* const queryBuilder = new PostgresJsonQueryBuilder(result.mapping);
|
|
214
|
+
* ```
|
|
215
|
+
*
|
|
216
|
+
* @see {@link toLegacyMapping} For simple mapping extraction
|
|
217
|
+
* @see {@link getTypeProtection} For type protection only
|
|
218
|
+
*/
|
|
219
|
+
convert(input) {
|
|
220
|
+
for (const strategy of this.strategies) {
|
|
221
|
+
if (strategy.detect(input)) {
|
|
222
|
+
return strategy.convert(input);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
throw new Error('Unsupported JSON mapping format: Unable to detect a compatible strategy for the provided input');
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Extracts only the legacy JsonMapping for direct use with PostgresJsonQueryBuilder.
|
|
229
|
+
*
|
|
230
|
+
* This convenience method performs the full conversion but returns only the mapping portion,
|
|
231
|
+
* discarding metadata and type protection information. Use this when you only need
|
|
232
|
+
* the mapping for query building and don't require additional metadata.
|
|
233
|
+
*
|
|
234
|
+
* @param input - The JSON mapping in any supported format
|
|
235
|
+
* @returns Legacy-format JsonMapping ready for PostgresJsonQueryBuilder
|
|
236
|
+
*
|
|
237
|
+
* @throws {Error} When the input format is not supported
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* ```typescript
|
|
241
|
+
* const legacyMapping = converter.toLegacyMapping(modelDrivenMapping);
|
|
242
|
+
* const queryBuilder = new PostgresJsonQueryBuilder(legacyMapping);
|
|
243
|
+
* const query = queryBuilder.build(selectQuery);
|
|
244
|
+
* ```
|
|
245
|
+
*
|
|
246
|
+
* @see {@link convert} For full conversion with metadata
|
|
247
|
+
*/
|
|
248
|
+
toLegacyMapping(input) {
|
|
249
|
+
return this.convert(input).mapping;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Extracts type protection configuration for runtime type checking.
|
|
253
|
+
*
|
|
254
|
+
* Type protection helps identify fields that should be treated as strings
|
|
255
|
+
* to prevent injection attacks or type coercion issues. This is particularly
|
|
256
|
+
* useful when working with user input or external data sources.
|
|
257
|
+
*
|
|
258
|
+
* @param input - The JSON mapping in any supported format
|
|
259
|
+
* @returns Type protection configuration with protected field definitions
|
|
260
|
+
*
|
|
261
|
+
* @throws {Error} When the input format is not supported
|
|
262
|
+
*
|
|
263
|
+
* @example
|
|
264
|
+
* ```typescript
|
|
265
|
+
* const typeProtection = converter.getTypeProtection(enhancedMapping);
|
|
266
|
+
*
|
|
267
|
+
* // Apply type protection during data processing
|
|
268
|
+
* for (const field of typeProtection.protectedStringFields) {
|
|
269
|
+
* if (typeof data[field] !== 'string') {
|
|
270
|
+
* data[field] = String(data[field]);
|
|
271
|
+
* }
|
|
272
|
+
* }
|
|
273
|
+
* ```
|
|
274
|
+
*/
|
|
275
|
+
getTypeProtection(input) {
|
|
276
|
+
return this.convert(input).typeProtection;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Validates that the input mapping is well-formed and can be successfully converted.
|
|
280
|
+
*
|
|
281
|
+
* This method performs comprehensive validation without attempting conversion,
|
|
282
|
+
* returning an array of error messages for any issues found. An empty array
|
|
283
|
+
* indicates the mapping is valid and ready for conversion.
|
|
284
|
+
*
|
|
285
|
+
* **Validation Checks:**
|
|
286
|
+
* - Basic structure validation (object type, required fields)
|
|
287
|
+
* - Format-specific validation (Enhanced, Model-Driven, Legacy)
|
|
288
|
+
* - Column configuration validation
|
|
289
|
+
* - Type protection configuration validation
|
|
290
|
+
*
|
|
291
|
+
* @param input - The JSON mapping to validate
|
|
292
|
+
* @returns Array of validation error messages (empty if valid)
|
|
293
|
+
*
|
|
294
|
+
* @example
|
|
295
|
+
* ```typescript
|
|
296
|
+
* const errors = converter.validate(suspiciousMapping);
|
|
297
|
+
* if (errors.length > 0) {
|
|
298
|
+
* console.error('Validation failed:', errors);
|
|
299
|
+
* throw new Error(`Invalid mapping: ${errors.join(', ')}`);
|
|
300
|
+
* }
|
|
301
|
+
*
|
|
302
|
+
* // Safe to convert
|
|
303
|
+
* const result = converter.convert(suspiciousMapping);
|
|
304
|
+
* ```
|
|
305
|
+
*
|
|
306
|
+
* @see {@link convert} Performs conversion after implicit validation
|
|
307
|
+
*/
|
|
308
|
+
validate(input) {
|
|
309
|
+
const errors = [];
|
|
310
|
+
// Pre-validation checks
|
|
311
|
+
if (!input || typeof input !== 'object') {
|
|
312
|
+
errors.push('Input must be an object');
|
|
313
|
+
return errors;
|
|
314
|
+
}
|
|
315
|
+
// Check for rootName before attempting conversion
|
|
316
|
+
if (!('rootName' in input) || !input.rootName) {
|
|
317
|
+
errors.push('rootName is required');
|
|
318
|
+
}
|
|
319
|
+
try {
|
|
320
|
+
const result = this.convert(input);
|
|
321
|
+
// Basic validation
|
|
322
|
+
if (!result.mapping.rootName) {
|
|
323
|
+
errors.push('rootName is required');
|
|
324
|
+
}
|
|
325
|
+
if (!result.mapping.rootEntity) {
|
|
326
|
+
errors.push('rootEntity is required');
|
|
327
|
+
}
|
|
328
|
+
else {
|
|
329
|
+
if (!result.mapping.rootEntity.id) {
|
|
330
|
+
errors.push('rootEntity.id is required');
|
|
331
|
+
}
|
|
332
|
+
if (!result.mapping.rootEntity.columns) {
|
|
333
|
+
errors.push('rootEntity.columns is required');
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
// Validate nested entities
|
|
337
|
+
if (result.mapping.nestedEntities) {
|
|
338
|
+
for (const entity of result.mapping.nestedEntities) {
|
|
339
|
+
if (!entity.id) {
|
|
340
|
+
errors.push(`Nested entity missing id: ${entity.propertyName}`);
|
|
341
|
+
}
|
|
342
|
+
if (!entity.parentId) {
|
|
343
|
+
errors.push(`Nested entity missing parentId: ${entity.id}`);
|
|
344
|
+
}
|
|
345
|
+
if (!entity.propertyName) {
|
|
346
|
+
errors.push(`Nested entity missing propertyName: ${entity.id}`);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
catch (error) {
|
|
352
|
+
// Only add conversion error if we haven't already found specific errors
|
|
353
|
+
if (errors.length === 0) {
|
|
354
|
+
errors.push(`Conversion failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
return errors;
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Creates a new enhanced mapping from legacy mapping.
|
|
361
|
+
*/
|
|
362
|
+
upgradeToEnhanced(legacy, typeInfo) {
|
|
363
|
+
return {
|
|
364
|
+
rootName: legacy.rootName,
|
|
365
|
+
rootEntity: {
|
|
366
|
+
id: legacy.rootEntity.id,
|
|
367
|
+
name: legacy.rootEntity.name,
|
|
368
|
+
columns: legacy.rootEntity.columns
|
|
369
|
+
},
|
|
370
|
+
nestedEntities: legacy.nestedEntities.map(entity => ({
|
|
371
|
+
id: entity.id,
|
|
372
|
+
name: entity.name,
|
|
373
|
+
parentId: entity.parentId,
|
|
374
|
+
propertyName: entity.propertyName,
|
|
375
|
+
relationshipType: entity.relationshipType || 'object',
|
|
376
|
+
columns: entity.columns
|
|
377
|
+
})),
|
|
378
|
+
resultFormat: legacy.resultFormat,
|
|
379
|
+
emptyResult: legacy.emptyResult,
|
|
380
|
+
typeInfo,
|
|
381
|
+
metadata: {
|
|
382
|
+
version: '1.0',
|
|
383
|
+
description: 'Upgraded from legacy format'
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
//# sourceMappingURL=JsonMappingConverter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JsonMappingConverter.js","sourceRoot":"","sources":["../../../../src/transformers/JsonMappingConverter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAA0B,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AAC7F,OAAO,EAAgE,eAAe,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AA+C7I;;GAEG;AACH,SAAS,mBAAmB,CAAC,KAAc;IACvC,OAAO,KAAK,KAAK,IAAI;QACd,KAAK,KAAK,SAAS;QACnB,OAAO,KAAK,KAAK,Q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