UNPKG

rawsql-ts

Version:

[beta]High-performance SQL parser and AST analyzer written in TypeScript. Provides fast parsing and advanced transformation capabilities.

60 lines 2.29 kB
"use strict"; /** * Enhanced JSON mapping structure that integrates column mapping and type protection configuration. * This unified approach eliminates the need for separate .types.json files. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.convertUnifiedMapping = convertUnifiedMapping; /** * Convert a unified JSON mapping to separate JsonMapping and TypeProtectionConfig. * This enables backward compatibility with existing code while supporting the new unified structure. */ function convertUnifiedMapping(unified) { const protectedStringFields = []; // Helper function to process columns and extract string protection settings const processColumns = (columns) => { const result = {}; for (const [key, config] of Object.entries(columns)) { if (typeof config === 'string') { result[key] = config; } else { result[key] = config.column; if (config.type === 'string') { protectedStringFields.push(config.column); } } } return result; }; // Convert the unified mapping to traditional JsonMapping const jsonMapping = { rootName: unified.rootName, rootEntity: { id: unified.rootEntity.id, name: unified.rootEntity.name, columns: processColumns(unified.rootEntity.columns) }, nestedEntities: [] // Initialize as empty array }; // Add typeInfo if it exists if (unified.typeInfo) { // Note: JsonMapping doesn't have typeInfo in core, but we preserve it for backward compatibility jsonMapping.typeInfo = unified.typeInfo; } // Process nested entities if they exist if (unified.nestedEntities) { jsonMapping.nestedEntities = unified.nestedEntities.map(entity => ({ id: entity.id, name: entity.name, parentId: entity.parentId, propertyName: entity.propertyName, relationshipType: entity.relationshipType, columns: processColumns(entity.columns) })); } return { jsonMapping, typeProtection: { protectedStringFields } }; } //# sourceMappingURL=UnifiedJsonMapping.js.map