@memberjunction/metadata-sync 2.111.1 ā 2.112.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.
- package/README.md +50 -50
- package/dist/lib/EntityPropertyExtractor.d.ts +1 -1
- package/dist/lib/EntityPropertyExtractor.js +18 -4
- package/dist/lib/EntityPropertyExtractor.js.map +1 -1
- package/dist/lib/FieldExternalizer.d.ts +1 -1
- package/dist/lib/FieldExternalizer.js +2 -2
- package/dist/lib/FieldExternalizer.js.map +1 -1
- package/dist/lib/RecordProcessor.d.ts +1 -1
- package/dist/lib/RecordProcessor.js +9 -10
- package/dist/lib/RecordProcessor.js.map +1 -1
- package/dist/lib/RelatedEntityHandler.d.ts +1 -1
- package/dist/lib/RelatedEntityHandler.js +5 -5
- package/dist/lib/RelatedEntityHandler.js.map +1 -1
- package/dist/lib/provider-utils.d.ts +1 -1
- package/dist/lib/provider-utils.js +16 -19
- package/dist/lib/provider-utils.js.map +1 -1
- package/dist/lib/record-dependency-analyzer.js +21 -27
- package/dist/lib/record-dependency-analyzer.js.map +1 -1
- package/dist/lib/singleton-manager.d.ts +1 -1
- package/dist/lib/singleton-manager.js.map +1 -1
- package/dist/lib/sync-engine.d.ts +1 -1
- package/dist/lib/sync-engine.js +22 -18
- package/dist/lib/sync-engine.js.map +1 -1
- package/dist/services/PullService.d.ts +1 -1
- package/dist/services/PullService.js +22 -18
- package/dist/services/PullService.js.map +1 -1
- package/dist/services/PushService.d.ts +1 -1
- package/dist/services/PushService.js +15 -21
- package/dist/services/PushService.js.map +1 -1
- package/dist/services/ValidationService.js +5 -5
- package/dist/services/ValidationService.js.map +1 -1
- package/dist/services/WatchService.d.ts +1 -1
- package/dist/services/WatchService.js +13 -14
- package/dist/services/WatchService.js.map +1 -1
- package/package.json +6 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PullService.js","sourceRoot":"","sources":["../../src/services/PullService.ts"],"names":[],"mappings":";;;;;;AAA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AC;QAE9D,iCAAiC;QACjC,MAAM,kBAAE,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QAC9B,yCAAyC;QACzC,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAEtC,MAAM,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QACjE,oEAAoE;QACpE,MAAM,cAAc,GAAG,QAAQ,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,SAAS,SAAS,CAAC,CAAC;QAC3E,MAAM,UAAU,GAAG,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;QAExD,IAAI,CAAC;YACH,MAAM,kBAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;YACpC,4CAA4C;YAC5C,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC3C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,4BAA4B;QAC9B,CAAC;IACH,CAAC;CACF;AAjzBD,kCAizBC","sourcesContent":["import fs from 'fs-extra';\nimport path from 'path';\nimport { RunView, EntityInfo, UserInfo, BaseEntity } from '@memberjunction/core';\nimport { SyncEngine, RecordData } from '../lib/sync-engine';\nimport { loadEntityConfig, EntityConfig } from '../config';\nimport { configManager } from '../lib/config-manager';\nimport { FileWriteBatch } from '../lib/file-write-batch';\nimport { JsonWriteHelper } from '../lib/json-write-helper';\nimport { RecordProcessor } from '../lib/RecordProcessor';\n\nexport interface PullOptions {\n entity: string;\n filter?: string;\n dryRun?: boolean;\n multiFile?: string;\n verbose?: boolean;\n noValidate?: boolean;\n targetDir?: string;\n updateExistingRecords?: boolean;\n createNewFileIfNotFound?: boolean;\n}\n\nexport interface PullCallbacks {\n onProgress?: (message: string) => void;\n onSuccess?: (message: string) => void;\n onError?: (message: string) => void;\n onWarn?: (message: string) => void;\n onLog?: (message: string) => void;\n}\n\nexport interface PullResult {\n processed: number;\n created: number;\n updated: number;\n skipped: number;\n targetDir: string;\n}\n\nexport class PullService {\n private syncEngine: SyncEngine;\n private contextUser: UserInfo;\n private createdBackupFiles: string[] = [];\n private createdBackupDirs: Set<string> = new Set();\n private fileWriteBatch: FileWriteBatch;\n private recordProcessor: RecordProcessor;\n \n constructor(syncEngine: SyncEngine, contextUser: UserInfo) {\n this.syncEngine = syncEngine;\n this.contextUser = contextUser;\n this.fileWriteBatch = new FileWriteBatch();\n this.recordProcessor = new RecordProcessor(syncEngine, contextUser);\n }\n \n async pull(options: PullOptions, callbacks?: PullCallbacks): Promise<PullResult> {\n // Clear any previous batch operations\n this.fileWriteBatch.clear();\n this.createdBackupFiles = [];\n this.createdBackupDirs.clear();\n \n let targetDir: string;\n let entityConfig: EntityConfig | null;\n \n // Check if we should use a specific target directory\n if (options.targetDir) {\n if (options.verbose) {\n callbacks?.onLog?.(`Using specified target directory: ${options.targetDir}`);\n }\n process.chdir(options.targetDir);\n targetDir = process.cwd();\n \n // Load entity config from the current directory\n entityConfig = await loadEntityConfig(targetDir);\n if (!entityConfig) {\n throw new Error(`No .mj-sync.json found in ${targetDir}`);\n }\n if (entityConfig.entity !== options.entity) {\n throw new Error(`Directory ${targetDir} is configured for entity \"${entityConfig.entity}\", not \"${options.entity}\"`);\n }\n } else {\n // Original behavior - find entity directory\n const entityDirs = await this.findEntityDirectories(options.entity);\n \n if (entityDirs.length === 0) {\n throw new Error(`No directory found for entity \"${options.entity}\". Run \"mj sync init\" first.`);\n }\n \n if (entityDirs.length === 1) {\n targetDir = entityDirs[0];\n } else {\n // Multiple directories found - in service mode, we'll use the first one\n // The CLI can handle prompting for selection\n throw new Error(`Multiple directories found for entity \"${options.entity}\". Please specify target directory.`);\n }\n \n entityConfig = await loadEntityConfig(targetDir);\n if (!entityConfig) {\n throw new Error(`Invalid entity configuration in ${targetDir}`);\n }\n }\n \n // Show configuration notice only if relevant and in verbose mode\n if (options.verbose && entityConfig?.pull?.appendRecordsToExistingFile && entityConfig?.pull?.newFileName) {\n const targetFile = path.join(targetDir, entityConfig.pull.newFileName.endsWith('.json') \n ? entityConfig.pull.newFileName \n : `${entityConfig.pull.newFileName}.json`);\n \n if (await fs.pathExists(targetFile)) {\n callbacks?.onLog?.(`\\nš Configuration: New records will be appended to existing file '${path.basename(targetFile)}'`);\n }\n }\n \n // Pull records\n callbacks?.onProgress?.(`Pulling ${options.entity} records`);\n const rv = new RunView();\n \n let filter = '';\n if (options.filter) {\n filter = options.filter;\n } else if (entityConfig?.pull?.filter) {\n filter = entityConfig.pull.filter;\n }\n \n const result = await rv.RunView({\n EntityName: options.entity,\n ExtraFilter: filter,\n ResultType: 'entity_object'\n }, this.contextUser);\n \n if (!result.Success) {\n throw new Error(`Failed to pull records: ${result.ErrorMessage}`);\n }\n \n callbacks?.onSuccess?.(`Found ${result.Results.length} records`);\n \n if (options.dryRun) {\n callbacks?.onLog?.(`\\nDry run mode - would pull ${result.Results.length} records to ${targetDir}`);\n return {\n processed: 0,\n created: 0,\n updated: 0,\n skipped: 0,\n targetDir\n };\n }\n \n // Process records with error handling and rollback\n let pullResult: Omit<PullResult, 'targetDir'>;\n \n try {\n pullResult = await this.processRecords(\n result.Results,\n options,\n targetDir,\n entityConfig,\n callbacks\n );\n \n // Write all batched file changes at once\n if (!options.dryRun) {\n const filesWritten = await this.fileWriteBatch.flush();\n if (options.verbose && filesWritten > 0) {\n callbacks?.onSuccess?.(`Wrote ${filesWritten} files with consistent property ordering`);\n }\n }\n \n // Operation succeeded - clean up backup files\n if (!options.dryRun) {\n await this.cleanupBackupFiles();\n }\n \n } catch (error) {\n callbacks?.onError?.(`Pull operation failed: ${(error as any).message || error}`);\n \n // Attempt to rollback file changes if not in dry run mode\n if (!options.dryRun) {\n try {\n await this.rollbackFileChanges(callbacks);\n callbacks?.onWarn?.('File changes have been rolled back due to operation failure');\n } catch (rollbackError) {\n callbacks?.onError?.(`Rollback failed: ${(rollbackError as any).message || rollbackError}`);\n }\n }\n \n throw error;\n }\n \n return {\n ...pullResult,\n targetDir\n };\n }\n \n private async processRecords(\n records: BaseEntity[],\n options: PullOptions,\n targetDir: string,\n entityConfig: EntityConfig,\n callbacks?: PullCallbacks\n ): Promise<Omit<PullResult, 'targetDir'>> {\n const entityInfo = this.syncEngine.getEntityInfo(options.entity);\n if (!entityInfo) {\n throw new Error(`Entity information not found for: ${options.entity}`);\n }\n \n callbacks?.onProgress?.('Processing records');\n let processed = 0;\n let updated = 0;\n let created = 0;\n let skipped = 0;\n \n // If multi-file flag is set, collect all records\n if (options.multiFile) {\n const allRecords: RecordData[] = [];\n const errors: string[] = [];\n \n // Process records in parallel for multi-file mode\n const recordPromises = records.map(async (record, index) => {\n try {\n // Build primary key\n const primaryKey: Record<string, any> = {};\n for (const pk of entityInfo.PrimaryKeys) {\n primaryKey[pk.Name] = (record as any)[pk.Name];\n }\n \n // Process record for multi-file\n const recordData = await this.recordProcessor.processRecord(\n record, \n primaryKey, \n targetDir, \n entityConfig, \n options.verbose, \n true\n );\n \n return { success: true, recordData, index };\n } catch (error) {\n const errorMessage = `Failed to process record ${index + 1}: ${(error as any).message || error}`;\n errors.push(errorMessage);\n callbacks?.onWarn?.(errorMessage);\n return { success: false, recordData: null, index };\n }\n });\n \n const recordResults = await Promise.all(recordPromises);\n \n // Collect successful records\n for (const result of recordResults) {\n if (result.success && result.recordData) {\n allRecords.push(result.recordData);\n processed++;\n }\n }\n \n if (options.verbose) {\n callbacks?.onProgress?.(`Processed ${processed}/${records.length} records in parallel`);\n }\n \n // Queue all records to single file for batched write\n if (allRecords.length > 0) {\n const fileName = options.multiFile.endsWith('.json') ? options.multiFile : `${options.multiFile}.json`;\n const filePath = path.join(targetDir, fileName);\n this.fileWriteBatch.queueWrite(filePath, allRecords);\n callbacks?.onSuccess?.(`Queued ${processed} records for ${path.basename(filePath)}`);\n }\n \n // If there were errors during parallel processing, throw them\n if (errors.length > 0) {\n throw new Error(`Multi-file processing completed with ${errors.length} errors:\\n${errors.join('\\n')}`);\n }\n } else {\n // Smart update logic for single-file-per-record\n const result = await this.processIndividualRecords(\n records,\n options,\n targetDir,\n entityConfig,\n entityInfo,\n callbacks\n );\n \n processed = result.processed;\n updated = result.updated;\n created = result.created;\n skipped = result.skipped;\n \n // Final status\n const statusParts = [`Processed ${processed} records`];\n if (updated > 0) statusParts.push(`updated ${updated}`);\n if (created > 0) statusParts.push(`created ${created}`);\n if (skipped > 0) statusParts.push(`skipped ${skipped}`);\n \n callbacks?.onSuccess?.(statusParts.join(', '));\n }\n \n return { processed, created, updated, skipped };\n }\n \n /**\n * Clean up backup files created during the pull operation\n * Should be called after successful pull operations to remove persistent backup files\n */\n async cleanupBackupFiles(): Promise<void> {\n if (this.createdBackupFiles.length === 0 && this.createdBackupDirs.size === 0) {\n return;\n }\n \n const errors: string[] = [];\n \n // Remove backup files\n for (const backupPath of this.createdBackupFiles) {\n try {\n if (await fs.pathExists(backupPath)) {\n await fs.remove(backupPath);\n }\n } catch (error) {\n errors.push(`Failed to remove backup file ${backupPath}: ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n \n // Remove empty backup directories\n for (const backupDir of this.createdBackupDirs) {\n try {\n await this.removeEmptyBackupDirectory(backupDir);\n } catch (error) {\n errors.push(`Failed to remove backup directory ${backupDir}: ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n \n // Clear the tracking arrays\n this.createdBackupFiles = [];\n this.createdBackupDirs.clear();\n \n if (errors.length > 0) {\n throw new Error(`Backup cleanup completed with errors:\\n${errors.join('\\n')}`);\n }\n }\n\n /**\n * Remove a backup directory if it's empty\n */\n private async removeEmptyBackupDirectory(backupDir: string): Promise<void> {\n try {\n // Check if directory exists\n if (!(await fs.pathExists(backupDir))) {\n return;\n }\n \n // Only remove if it's actually a .backups directory for safety\n if (!backupDir.endsWith('.backups')) {\n return;\n }\n \n // Check if directory is empty\n const files = await fs.readdir(backupDir);\n if (files.length === 0) {\n await fs.remove(backupDir);\n }\n } catch (error) {\n // Log error but don't throw - cleanup should be non-critical\n // The error will be caught by the caller and included in the error list\n throw error;\n }\n }\n \n /**\n * Get the list of backup files created during the current pull operation\n */\n getCreatedBackupFiles(): string[] {\n return [...this.createdBackupFiles];\n }\n \n /**\n * Rollback file changes by restoring from backup files\n * Called when pull operation fails after files have been modified\n */\n private async rollbackFileChanges(callbacks?: PullCallbacks): Promise<void> {\n if (this.createdBackupFiles.length === 0) {\n callbacks?.onLog?.('No backup files found - no rollback needed');\n return;\n }\n \n callbacks?.onProgress?.(`Rolling back ${this.createdBackupFiles.length} file changes...`);\n \n const errors: string[] = [];\n let restoredCount = 0;\n \n for (const backupPath of this.createdBackupFiles) {\n try {\n // Extract original file path from backup path\n const backupDir = path.dirname(backupPath);\n const backupFileName = path.basename(backupPath);\n \n // Remove timestamp and .backup extension to get original filename\n const originalFileName = backupFileName.replace(/\\.\\d{4}-\\d{2}-\\d{2}T\\d{2}-\\d{2}-\\d{2}-\\d{3}Z\\.backup$/, '.json');\n const originalFilePath = path.join(path.dirname(backupDir), originalFileName);\n \n if (await fs.pathExists(backupPath)) {\n await fs.copy(backupPath, originalFilePath);\n restoredCount++;\n }\n } catch (error) {\n errors.push(`Failed to restore ${backupPath}: ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n \n if (errors.length > 0) {\n throw new Error(`Rollback completed with ${errors.length} errors (${restoredCount} files restored):\\n${errors.join('\\n')}`);\n }\n \n callbacks?.onSuccess?.(`Successfully rolled back ${restoredCount} file changes`);\n }\n \n private async processIndividualRecords(\n records: BaseEntity[],\n options: PullOptions,\n targetDir: string,\n entityConfig: EntityConfig,\n entityInfo: EntityInfo,\n callbacks?: PullCallbacks\n ): Promise<{ processed: number; updated: number; created: number; skipped: number }> {\n let processed = 0;\n let updated = 0;\n let created = 0;\n let skipped = 0;\n \n // Find existing files\n const filePattern = entityConfig.pull?.filePattern || entityConfig.filePattern || '*.json';\n const existingFiles = await this.findExistingFiles(targetDir, filePattern);\n \n if (options.verbose) {\n callbacks?.onLog?.(`Found ${existingFiles.length} existing files matching pattern '${filePattern}'`);\n existingFiles.forEach(f => callbacks?.onLog?.(` - ${path.basename(f)}`));\n }\n \n // Load existing records and build lookup map\n const existingRecordsMap = await this.loadExistingRecords(existingFiles, entityInfo);\n \n if (options.verbose) {\n callbacks?.onLog?.(`Loaded ${existingRecordsMap.size} existing records from files`);\n }\n \n // Separate records into new and existing\n const newRecords: Array<{ record: BaseEntity; primaryKey: Record<string, any> }> = [];\n const existingRecordsToUpdate: Array<{ record: BaseEntity; primaryKey: Record<string, any>; filePath: string }> = [];\n \n for (const record of records) {\n // Build primary key\n const primaryKey: Record<string, any> = {};\n for (const pk of entityInfo.PrimaryKeys) {\n primaryKey[pk.Name] = (record as any)[pk.Name];\n }\n \n // Create lookup key\n const lookupKey = this.createPrimaryKeyLookup(primaryKey);\n const existingFileInfo = existingRecordsMap.get(lookupKey);\n \n if (existingFileInfo) {\n // Record exists locally\n if (entityConfig.pull?.updateExistingRecords !== false) {\n existingRecordsToUpdate.push({ record, primaryKey, filePath: existingFileInfo.filePath });\n } else {\n skipped++;\n if (options.verbose) {\n callbacks?.onLog?.(`Skipping existing record: ${lookupKey}`);\n }\n }\n } else {\n // Record doesn't exist locally\n if (entityConfig.pull?.createNewFileIfNotFound !== false) {\n newRecords.push({ record, primaryKey });\n } else {\n skipped++;\n if (options.verbose) {\n callbacks?.onLog?.(`Skipping new record (createNewFileIfNotFound=false): ${lookupKey}`);\n }\n }\n }\n }\n \n // Track which files have been backed up to avoid duplicates\n const backedUpFiles = new Set<string>();\n const errors: string[] = [];\n \n // Process existing records updates in parallel\n if (existingRecordsToUpdate.length > 0) {\n callbacks?.onProgress?.(`Updating existing records (parallel processing)`);\n \n const updatePromises = existingRecordsToUpdate.map(async ({ record, primaryKey, filePath }, index) => {\n try {\n // Create backup if configured (only once per file)\n if (entityConfig.pull?.backupBeforeUpdate && !backedUpFiles.has(filePath)) {\n await this.createBackup(filePath, entityConfig.pull?.backupDirectory);\n backedUpFiles.add(filePath);\n }\n \n // Load existing file data\n const existingData = await fs.readJson(filePath);\n \n // Find the specific existing record that matches this primary key\n let existingRecordData: RecordData;\n if (Array.isArray(existingData)) {\n // Find the matching record in the array\n const matchingRecord = existingData.find(r => \n this.createPrimaryKeyLookup(r.primaryKey || {}) === this.createPrimaryKeyLookup(primaryKey)\n );\n existingRecordData = matchingRecord || existingData[0]; // Fallback to first if not found\n } else {\n existingRecordData = existingData;\n }\n \n // Process the new record data (isNewRecord = false for updates)\n const newRecordData = await this.recordProcessor.processRecord(\n record, \n primaryKey, \n targetDir, \n entityConfig, \n options.verbose, \n false, \n existingRecordData\n );\n \n // Apply merge strategy\n const mergedData = await this.mergeRecords(\n existingRecordData,\n newRecordData,\n entityConfig.pull?.mergeStrategy || 'merge',\n entityConfig.pull?.preserveFields || []\n );\n \n // Queue updated data for batched write\n if (Array.isArray(existingData)) {\n // Queue array update - batch will handle merging\n const primaryKeyLookup = this.createPrimaryKeyLookup(primaryKey);\n this.fileWriteBatch.queueArrayUpdate(filePath, mergedData, primaryKeyLookup);\n } else {\n // Queue single record update\n this.fileWriteBatch.queueSingleUpdate(filePath, mergedData);\n }\n \n if (options.verbose) {\n callbacks?.onLog?.(`Updated: ${filePath}`);\n }\n \n return { success: true, index };\n } catch (error) {\n const errorMessage = `Failed to update record ${index + 1}: ${(error as any).message || error}`;\n errors.push(errorMessage);\n callbacks?.onWarn?.(errorMessage);\n return { success: false, index };\n }\n });\n \n const updateResults = await Promise.all(updatePromises);\n updated = updateResults.filter(r => r.success).length;\n processed += updated;\n \n if (options.verbose) {\n callbacks?.onSuccess?.(`Completed ${updated}/${existingRecordsToUpdate.length} record updates`);\n }\n }\n \n // Process new records in parallel\n if (newRecords.length > 0) {\n callbacks?.onProgress?.(`Creating new records (parallel processing)`);\n \n if (entityConfig.pull?.appendRecordsToExistingFile && entityConfig.pull?.newFileName) {\n // Append all new records to a single file using parallel processing\n const fileName = entityConfig.pull.newFileName.endsWith('.json') \n ? entityConfig.pull.newFileName \n : `${entityConfig.pull.newFileName}.json`;\n const filePath = path.join(targetDir, fileName);\n \n // Process all new records in parallel\n const newRecordPromises = newRecords.map(async ({ record, primaryKey }, index) => {\n try {\n // For new records, pass isNewRecord = true (default)\n const recordData = await this.recordProcessor.processRecord(\n record, \n primaryKey, \n targetDir, \n entityConfig, \n options.verbose, \n true\n );\n \n // Use queueArrayUpdate to append the new record without overwriting existing updates\n // For new records, we can use a special lookup key since they don't exist yet\n const newRecordLookup = this.createPrimaryKeyLookup(primaryKey);\n this.fileWriteBatch.queueArrayUpdate(filePath, recordData, newRecordLookup);\n \n return { success: true, index };\n } catch (error) {\n const errorMessage = `Failed to process new record ${index + 1}: ${(error as any).message || error}`;\n errors.push(errorMessage);\n callbacks?.onWarn?.(errorMessage);\n return { success: false, index };\n }\n });\n \n const newRecordResults = await Promise.all(newRecordPromises);\n created = newRecordResults.filter(r => r.success).length;\n processed += created;\n \n if (options.verbose) {\n callbacks?.onLog?.(`Queued ${created} new records for: ${filePath}`);\n }\n } else {\n // Create individual files for each new record in parallel\n const individualRecordPromises = newRecords.map(async ({ record, primaryKey }, index) => {\n try {\n await this.processRecord(record, primaryKey, targetDir, entityConfig, options.verbose);\n return { success: true, index };\n } catch (error) {\n const errorMessage = `Failed to process new record ${index + 1}: ${(error as any).message || error}`;\n errors.push(errorMessage);\n callbacks?.onWarn?.(errorMessage);\n return { success: false, index };\n }\n });\n \n const individualResults = await Promise.all(individualRecordPromises);\n created = individualResults.filter(r => r.success).length;\n processed += created;\n \n if (options.verbose) {\n callbacks?.onSuccess?.(`Created ${created}/${newRecords.length} individual record files`);\n }\n }\n }\n \n // If there were errors during parallel processing, throw them\n if (errors.length > 0) {\n throw new Error(`Parallel processing completed with ${errors.length} errors:\\n${errors.join('\\n')}`);\n }\n \n return { processed, updated, created, skipped };\n }\n \n private async processRecord(\n record: BaseEntity, \n primaryKey: Record<string, any>,\n targetDir: string, \n entityConfig: EntityConfig,\n verbose?: boolean\n ): Promise<void> {\n const recordData = await this.recordProcessor.processRecord(\n record, \n primaryKey, \n targetDir, \n entityConfig, \n verbose, \n true\n );\n \n // Determine file path\n const fileName = this.buildFileName(primaryKey, entityConfig);\n const filePath = path.join(targetDir, fileName);\n \n // Queue JSON file for batched write with controlled property order\n this.fileWriteBatch.queueWrite(filePath, recordData);\n }\n\n \n\n\n\n private async findEntityDirectories(entityName: string): Promise<string[]> {\n const dirs: string[] = [];\n \n // Search for directories with matching entity config\n const searchDirs = async (dir: string) => {\n const entries = await fs.readdir(dir, { withFileTypes: true });\n \n for (const entry of entries) {\n if (entry.isDirectory()) {\n const fullPath = path.join(dir, entry.name);\n const config = await loadEntityConfig(fullPath);\n \n if (config && config.entity === entityName) {\n dirs.push(fullPath);\n } else {\n // Recurse\n await searchDirs(fullPath);\n }\n }\n }\n };\n \n await searchDirs(configManager.getOriginalCwd());\n return dirs;\n }\n \n private buildFileName(primaryKey: Record<string, any>, _entityConfig: EntityConfig): string {\n // Use primary key values to build filename\n const keys = Object.values(primaryKey);\n \n if (keys.length === 1 && typeof keys[0] === 'string') {\n // Single string key - use as base if it's a guid\n const key = keys[0];\n if (key.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i)) {\n // It's a GUID, use first 8 chars, prefixed with dot, lowercase\n return `.${key.substring(0, 8).toLowerCase()}.json`;\n }\n // Use the whole key if not too long, prefixed with dot\n if (key.length <= 50) {\n return `.${key.replace(/[^a-zA-Z0-9\\-_]/g, '').toLowerCase()}.json`;\n }\n }\n \n // Multiple keys or numeric - create composite name, prefixed with dot\n return '.' + keys.map(k => String(k).replace(/[^a-zA-Z0-9\\-_]/g, '').toLowerCase()).join('-') + '.json';\n }\n \n private async findExistingFiles(dir: string, pattern: string): Promise<string[]> {\n const files: string[] = [];\n \n try {\n const entries = await fs.readdir(dir, { withFileTypes: true });\n \n for (const entry of entries) {\n if (entry.isFile()) {\n const fileName = entry.name;\n \n // Simple pattern matching\n if (pattern === '*.json' && fileName.endsWith('.json')) {\n files.push(path.join(dir, fileName));\n } else if (pattern === '.*.json' && fileName.startsWith('.') && fileName.endsWith('.json')) {\n files.push(path.join(dir, fileName));\n } else if (pattern === fileName) {\n files.push(path.join(dir, fileName));\n }\n }\n }\n } catch (error) {\n // Directory might not exist yet\n if ((error as any).code !== 'ENOENT') {\n throw error;\n }\n }\n \n return files;\n }\n \n private async loadExistingRecords(\n files: string[], \n _entityInfo: EntityInfo\n ): Promise<Map<string, { filePath: string; recordData: RecordData }>> {\n const recordsMap = new Map<string, { filePath: string; recordData: RecordData }>();\n \n for (const filePath of files) {\n try {\n const fileData = await fs.readJson(filePath);\n const records = Array.isArray(fileData) ? fileData : [fileData];\n \n for (const record of records) {\n if (record.primaryKey) {\n const lookupKey = this.createPrimaryKeyLookup(record.primaryKey);\n recordsMap.set(lookupKey, { filePath, recordData: record });\n }\n }\n } catch (error) {\n // Skip files that can't be parsed\n }\n }\n \n return recordsMap;\n }\n \n private createPrimaryKeyLookup(primaryKey: Record<string, any>): string {\n const keys = Object.keys(primaryKey).sort();\n return keys.map(k => `${k}:${primaryKey[k]}`).join('|');\n }\n \n private async mergeRecords(\n existing: RecordData,\n newData: RecordData,\n strategy: 'overwrite' | 'merge' | 'skip',\n preserveFields: string[]\n ): Promise<RecordData> {\n if (strategy === 'skip') {\n return existing;\n }\n \n if (strategy === 'overwrite') {\n const result: RecordData = {\n fields: { ...newData.fields },\n primaryKey: newData.primaryKey,\n sync: newData.sync\n };\n \n // Restore preserved fields from existing\n if (preserveFields.length > 0 && existing.fields) {\n for (const field of preserveFields) {\n if (field in existing.fields) {\n result.fields[field] = existing.fields[field];\n }\n }\n }\n \n if (newData.relatedEntities) {\n result.relatedEntities = newData.relatedEntities;\n }\n \n return result;\n }\n \n // Default 'merge' strategy\n const result: RecordData = {\n fields: { ...existing.fields, ...newData.fields },\n primaryKey: newData.primaryKey || existing.primaryKey,\n sync: newData.sync\n };\n \n // Restore preserved fields\n if (preserveFields.length > 0 && existing.fields) {\n for (const field of preserveFields) {\n if (field in existing.fields) {\n result.fields[field] = existing.fields[field];\n }\n }\n }\n \n if (existing.relatedEntities || newData.relatedEntities) {\n result.relatedEntities = {\n ...existing.relatedEntities,\n ...newData.relatedEntities\n };\n }\n \n return result;\n }\n \n private async createBackup(filePath: string, backupDirName?: string): Promise<void> {\n const dir = path.dirname(filePath);\n const fileName = path.basename(filePath);\n const backupDir = path.join(dir, backupDirName || '.backups');\n \n // Ensure backup directory exists\n await fs.ensureDir(backupDir);\n // Track the backup directory for cleanup\n this.createdBackupDirs.add(backupDir);\n \n const timestamp = new Date().toISOString().replace(/[:.]/g, '-');\n // Remove .json extension, add timestamp, then add .backup extension\n const backupFileName = fileName.replace(/\\.json$/, `.${timestamp}.backup`);\n const backupPath = path.join(backupDir, backupFileName);\n \n try {\n await fs.copy(filePath, backupPath);\n // Track the created backup file for cleanup\n this.createdBackupFiles.push(backupPath);\n } catch (error) {\n // Log error but don't throw\n }\n }\n}"]}
|
|
1
|
+
{"version":3,"file":"PullService.js","sourceRoot":"","sources":["../../src/services/PullService.ts"],"names":[],"mappings":";;;;;;AAAA,wDAA0B;AAC1B,gDAAwB;AACxB,mDAAmF;AAEnF,sCAA2D;AAC3D,0DAAsD;AACtD,8DAAyD;AAEzD,4DAAyD;AA8BzD,MAAa,WAAW;IACd,UAAU,CAAa;IACvB,WAAW,CAAW;IACtB,kBAAkB,GAAa,EAAE,CAAC;IAClC,iBAAiB,GAAgB,IAAI,GAAG,EAAE,CAAC;IAC3C,cAAc,CAAiB;IAC/B,eAAe,CAAkB;IAEzC,YAAY,UAAsB,EAAE,WAAqB;QACvD,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,cAAc,GAAG,IAAI,iCAAc,EAAE,CAAC;QAC3C,IAAI,CAAC,eAAe,GAAG,IAAI,iCA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SAAS,EAAE,cAAc,CAAC,CAAC;QAExD,IAAI,CAAC;YACH,MAAM,kBAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;YACpC,4CAA4C;YAC5C,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC3C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,4BAA4B;QAC9B,CAAC;IACH,CAAC;CACF;AAxxBD,kCAwxBC","sourcesContent":["import fs from 'fs-extra';\nimport path from 'path';\nimport { RunView, EntityInfo, UserInfo, BaseEntity } from '@memberjunction/global';\nimport { SyncEngine, RecordData } from '../lib/sync-engine';\nimport { loadEntityConfig, EntityConfig } from '../config';\nimport { configManager } from '../lib/config-manager';\nimport { FileWriteBatch } from '../lib/file-write-batch';\nimport { JsonWriteHelper } from '../lib/json-write-helper';\nimport { RecordProcessor } from '../lib/RecordProcessor';\n\nexport interface PullOptions {\n entity: string;\n filter?: string;\n dryRun?: boolean;\n multiFile?: string;\n verbose?: boolean;\n noValidate?: boolean;\n targetDir?: string;\n updateExistingRecords?: boolean;\n createNewFileIfNotFound?: boolean;\n}\n\nexport interface PullCallbacks {\n onProgress?: (message: string) => void;\n onSuccess?: (message: string) => void;\n onError?: (message: string) => void;\n onWarn?: (message: string) => void;\n onLog?: (message: string) => void;\n}\n\nexport interface PullResult {\n processed: number;\n created: number;\n updated: number;\n skipped: number;\n targetDir: string;\n}\n\nexport class PullService {\n private syncEngine: SyncEngine;\n private contextUser: UserInfo;\n private createdBackupFiles: string[] = [];\n private createdBackupDirs: Set<string> = new Set();\n private fileWriteBatch: FileWriteBatch;\n private recordProcessor: RecordProcessor;\n\n constructor(syncEngine: SyncEngine, contextUser: UserInfo) {\n this.syncEngine = syncEngine;\n this.contextUser = contextUser;\n this.fileWriteBatch = new FileWriteBatch();\n this.recordProcessor = new RecordProcessor(syncEngine, contextUser);\n }\n\n async pull(options: PullOptions, callbacks?: PullCallbacks): Promise<PullResult> {\n // Clear any previous batch operations\n this.fileWriteBatch.clear();\n this.createdBackupFiles = [];\n this.createdBackupDirs.clear();\n\n let targetDir: string;\n let entityConfig: EntityConfig | null;\n\n // Check if we should use a specific target directory\n if (options.targetDir) {\n if (options.verbose) {\n callbacks?.onLog?.(`Using specified target directory: ${options.targetDir}`);\n }\n process.chdir(options.targetDir);\n targetDir = process.cwd();\n\n // Load entity config from the current directory\n entityConfig = await loadEntityConfig(targetDir);\n if (!entityConfig) {\n throw new Error(`No .mj-sync.json found in ${targetDir}`);\n }\n if (entityConfig.entity !== options.entity) {\n throw new Error(`Directory ${targetDir} is configured for entity \"${entityConfig.entity}\", not \"${options.entity}\"`);\n }\n } else {\n // Original behavior - find entity directory\n const entityDirs = await this.findEntityDirectories(options.entity);\n\n if (entityDirs.length === 0) {\n throw new Error(`No directory found for entity \"${options.entity}\". Run \"mj sync init\" first.`);\n }\n\n if (entityDirs.length === 1) {\n targetDir = entityDirs[0];\n } else {\n // Multiple directories found - in service mode, we'll use the first one\n // The CLI can handle prompting for selection\n throw new Error(`Multiple directories found for entity \"${options.entity}\". Please specify target directory.`);\n }\n\n entityConfig = await loadEntityConfig(targetDir);\n if (!entityConfig) {\n throw new Error(`Invalid entity configuration in ${targetDir}`);\n }\n }\n\n // Show configuration notice only if relevant and in verbose mode\n if (options.verbose && entityConfig?.pull?.appendRecordsToExistingFile && entityConfig?.pull?.newFileName) {\n const targetFile = path.join(\n targetDir,\n entityConfig.pull.newFileName.endsWith('.json') ? entityConfig.pull.newFileName : `${entityConfig.pull.newFileName}.json`\n );\n\n if (await fs.pathExists(targetFile)) {\n callbacks?.onLog?.(`\\nš Configuration: New records will be appended to existing file '${path.basename(targetFile)}'`);\n }\n }\n\n // Pull records\n callbacks?.onProgress?.(`Pulling ${options.entity} records`);\n const rv = new RunView();\n\n let filter = '';\n if (options.filter) {\n filter = options.filter;\n } else if (entityConfig?.pull?.filter) {\n filter = entityConfig.pull.filter;\n }\n\n const result = await rv.RunView(\n {\n EntityName: options.entity,\n ExtraFilter: filter,\n ResultType: 'entity_object',\n },\n this.contextUser\n );\n\n if (!result.Success) {\n throw new Error(`Failed to pull records: ${result.ErrorMessage}`);\n }\n\n callbacks?.onSuccess?.(`Found ${result.Results.length} records`);\n\n if (options.dryRun) {\n callbacks?.onLog?.(`\\nDry run mode - would pull ${result.Results.length} records to ${targetDir}`);\n return {\n processed: 0,\n created: 0,\n updated: 0,\n skipped: 0,\n targetDir,\n };\n }\n\n // Process records with error handling and rollback\n let pullResult: Omit<PullResult, 'targetDir'>;\n\n try {\n pullResult = await this.processRecords(result.Results, options, targetDir, entityConfig, callbacks);\n\n // Write all batched file changes at once\n if (!options.dryRun) {\n const filesWritten = await this.fileWriteBatch.flush();\n if (options.verbose && filesWritten > 0) {\n callbacks?.onSuccess?.(`Wrote ${filesWritten} files with consistent property ordering`);\n }\n }\n\n // Operation succeeded - clean up backup files\n if (!options.dryRun) {\n await this.cleanupBackupFiles();\n }\n } catch (error) {\n callbacks?.onError?.(`Pull operation failed: ${(error as any).message || error}`);\n\n // Attempt to rollback file changes if not in dry run mode\n if (!options.dryRun) {\n try {\n await this.rollbackFileChanges(callbacks);\n callbacks?.onWarn?.('File changes have been rolled back due to operation failure');\n } catch (rollbackError) {\n callbacks?.onError?.(`Rollback failed: ${(rollbackError as any).message || rollbackError}`);\n }\n }\n\n throw error;\n }\n\n return {\n ...pullResult,\n targetDir,\n };\n }\n\n private async processRecords(\n records: BaseEntity[],\n options: PullOptions,\n targetDir: string,\n entityConfig: EntityConfig,\n callbacks?: PullCallbacks\n ): Promise<Omit<PullResult, 'targetDir'>> {\n const entityInfo = this.syncEngine.getEntityInfo(options.entity);\n if (!entityInfo) {\n throw new Error(`Entity information not found for: ${options.entity}`);\n }\n\n callbacks?.onProgress?.('Processing records');\n let processed = 0;\n let updated = 0;\n let created = 0;\n let skipped = 0;\n\n // If multi-file flag is set, collect all records\n if (options.multiFile) {\n const allRecords: RecordData[] = [];\n const errors: string[] = [];\n\n // Process records in parallel for multi-file mode\n const recordPromises = records.map(async (record, index) => {\n try {\n // Build primary key\n const primaryKey: Record<string, any> = {};\n for (const pk of entityInfo.PrimaryKeys) {\n primaryKey[pk.Name] = (record as any)[pk.Name];\n }\n\n // Process record for multi-file\n const recordData = await this.recordProcessor.processRecord(record, primaryKey, targetDir, entityConfig, options.verbose, true);\n\n return { success: true, recordData, index };\n } catch (error) {\n const errorMessage = `Failed to process record ${index + 1}: ${(error as any).message || error}`;\n errors.push(errorMessage);\n callbacks?.onWarn?.(errorMessage);\n return { success: false, recordData: null, index };\n }\n });\n\n const recordResults = await Promise.all(recordPromises);\n\n // Collect successful records\n for (const result of recordResults) {\n if (result.success && result.recordData) {\n allRecords.push(result.recordData);\n processed++;\n }\n }\n\n if (options.verbose) {\n callbacks?.onProgress?.(`Processed ${processed}/${records.length} records in parallel`);\n }\n\n // Queue all records to single file for batched write\n if (allRecords.length > 0) {\n const fileName = options.multiFile.endsWith('.json') ? options.multiFile : `${options.multiFile}.json`;\n const filePath = path.join(targetDir, fileName);\n this.fileWriteBatch.queueWrite(filePath, allRecords);\n callbacks?.onSuccess?.(`Queued ${processed} records for ${path.basename(filePath)}`);\n }\n\n // If there were errors during parallel processing, throw them\n if (errors.length > 0) {\n throw new Error(`Multi-file processing completed with ${errors.length} errors:\\n${errors.join('\\n')}`);\n }\n } else {\n // Smart update logic for single-file-per-record\n const result = await this.processIndividualRecords(records, options, targetDir, entityConfig, entityInfo, callbacks);\n\n processed = result.processed;\n updated = result.updated;\n created = result.created;\n skipped = result.skipped;\n\n // Final status\n const statusParts = [`Processed ${processed} records`];\n if (updated > 0) statusParts.push(`updated ${updated}`);\n if (created > 0) statusParts.push(`created ${created}`);\n if (skipped > 0) statusParts.push(`skipped ${skipped}`);\n\n callbacks?.onSuccess?.(statusParts.join(', '));\n }\n\n return { processed, created, updated, skipped };\n }\n\n /**\n * Clean up backup files created during the pull operation\n * Should be called after successful pull operations to remove persistent backup files\n */\n async cleanupBackupFiles(): Promise<void> {\n if (this.createdBackupFiles.length === 0 && this.createdBackupDirs.size === 0) {\n return;\n }\n\n const errors: string[] = [];\n\n // Remove backup files\n for (const backupPath of this.createdBackupFiles) {\n try {\n if (await fs.pathExists(backupPath)) {\n await fs.remove(backupPath);\n }\n } catch (error) {\n errors.push(`Failed to remove backup file ${backupPath}: ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n\n // Remove empty backup directories\n for (const backupDir of this.createdBackupDirs) {\n try {\n await this.removeEmptyBackupDirectory(backupDir);\n } catch (error) {\n errors.push(`Failed to remove backup directory ${backupDir}: ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n\n // Clear the tracking arrays\n this.createdBackupFiles = [];\n this.createdBackupDirs.clear();\n\n if (errors.length > 0) {\n throw new Error(`Backup cleanup completed with errors:\\n${errors.join('\\n')}`);\n }\n }\n\n /**\n * Remove a backup directory if it's empty\n */\n private async removeEmptyBackupDirectory(backupDir: string): Promise<void> {\n try {\n // Check if directory exists\n if (!(await fs.pathExists(backupDir))) {\n return;\n }\n\n // Only remove if it's actually a .backups directory for safety\n if (!backupDir.endsWith('.backups')) {\n return;\n }\n\n // Check if directory is empty\n const files = await fs.readdir(backupDir);\n if (files.length === 0) {\n await fs.remove(backupDir);\n }\n } catch (error) {\n // Log error but don't throw - cleanup should be non-critical\n // The error will be caught by the caller and included in the error list\n throw error;\n }\n }\n\n /**\n * Get the list of backup files created during the current pull operation\n */\n getCreatedBackupFiles(): string[] {\n return [...this.createdBackupFiles];\n }\n\n /**\n * Rollback file changes by restoring from backup files\n * Called when pull operation fails after files have been modified\n */\n private async rollbackFileChanges(callbacks?: PullCallbacks): Promise<void> {\n if (this.createdBackupFiles.length === 0) {\n callbacks?.onLog?.('No backup files found - no rollback needed');\n return;\n }\n\n callbacks?.onProgress?.(`Rolling back ${this.createdBackupFiles.length} file changes...`);\n\n const errors: string[] = [];\n let restoredCount = 0;\n\n for (const backupPath of this.createdBackupFiles) {\n try {\n // Extract original file path from backup path\n const backupDir = path.dirname(backupPath);\n const backupFileName = path.basename(backupPath);\n\n // Remove timestamp and .backup extension to get original filename\n const originalFileName = backupFileName.replace(/\\.\\d{4}-\\d{2}-\\d{2}T\\d{2}-\\d{2}-\\d{2}-\\d{3}Z\\.backup$/, '.json');\n const originalFilePath = path.join(path.dirname(backupDir), originalFileName);\n\n if (await fs.pathExists(backupPath)) {\n await fs.copy(backupPath, originalFilePath);\n restoredCount++;\n }\n } catch (error) {\n errors.push(`Failed to restore ${backupPath}: ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n\n if (errors.length > 0) {\n throw new Error(`Rollback completed with ${errors.length} errors (${restoredCount} files restored):\\n${errors.join('\\n')}`);\n }\n\n callbacks?.onSuccess?.(`Successfully rolled back ${restoredCount} file changes`);\n }\n\n private async processIndividualRecords(\n records: BaseEntity[],\n options: PullOptions,\n targetDir: string,\n entityConfig: EntityConfig,\n entityInfo: EntityInfo,\n callbacks?: PullCallbacks\n ): Promise<{ processed: number; updated: number; created: number; skipped: number }> {\n let processed = 0;\n let updated = 0;\n let created = 0;\n let skipped = 0;\n\n // Find existing files\n const filePattern = entityConfig.pull?.filePattern || entityConfig.filePattern || '*.json';\n const existingFiles = await this.findExistingFiles(targetDir, filePattern);\n\n if (options.verbose) {\n callbacks?.onLog?.(`Found ${existingFiles.length} existing files matching pattern '${filePattern}'`);\n existingFiles.forEach((f) => callbacks?.onLog?.(` - ${path.basename(f)}`));\n }\n\n // Load existing records and build lookup map\n const existingRecordsMap = await this.loadExistingRecords(existingFiles, entityInfo);\n\n if (options.verbose) {\n callbacks?.onLog?.(`Loaded ${existingRecordsMap.size} existing records from files`);\n }\n\n // Separate records into new and existing\n const newRecords: Array<{ record: BaseEntity; primaryKey: Record<string, any> }> = [];\n const existingRecordsToUpdate: Array<{ record: BaseEntity; primaryKey: Record<string, any>; filePath: string }> = [];\n\n for (const record of records) {\n // Build primary key\n const primaryKey: Record<string, any> = {};\n for (const pk of entityInfo.PrimaryKeys) {\n primaryKey[pk.Name] = (record as any)[pk.Name];\n }\n\n // Create lookup key\n const lookupKey = this.createPrimaryKeyLookup(primaryKey);\n const existingFileInfo = existingRecordsMap.get(lookupKey);\n\n if (existingFileInfo) {\n // Record exists locally\n if (entityConfig.pull?.updateExistingRecords !== false) {\n existingRecordsToUpdate.push({ record, primaryKey, filePath: existingFileInfo.filePath });\n } else {\n skipped++;\n if (options.verbose) {\n callbacks?.onLog?.(`Skipping existing record: ${lookupKey}`);\n }\n }\n } else {\n // Record doesn't exist locally\n if (entityConfig.pull?.createNewFileIfNotFound !== false) {\n newRecords.push({ record, primaryKey });\n } else {\n skipped++;\n if (options.verbose) {\n callbacks?.onLog?.(`Skipping new record (createNewFileIfNotFound=false): ${lookupKey}`);\n }\n }\n }\n }\n\n // Track which files have been backed up to avoid duplicates\n const backedUpFiles = new Set<string>();\n const errors: string[] = [];\n\n // Process existing records updates in parallel\n if (existingRecordsToUpdate.length > 0) {\n callbacks?.onProgress?.(`Updating existing records (parallel processing)`);\n\n const updatePromises = existingRecordsToUpdate.map(async ({ record, primaryKey, filePath }, index) => {\n try {\n // Create backup if configured (only once per file)\n if (entityConfig.pull?.backupBeforeUpdate && !backedUpFiles.has(filePath)) {\n await this.createBackup(filePath, entityConfig.pull?.backupDirectory);\n backedUpFiles.add(filePath);\n }\n\n // Load existing file data\n const existingData = await fs.readJson(filePath);\n\n // Find the specific existing record that matches this primary key\n let existingRecordData: RecordData;\n if (Array.isArray(existingData)) {\n // Find the matching record in the array\n const matchingRecord = existingData.find(\n (r) => this.createPrimaryKeyLookup(r.primaryKey || {}) === this.createPrimaryKeyLookup(primaryKey)\n );\n existingRecordData = matchingRecord || existingData[0]; // Fallback to first if not found\n } else {\n existingRecordData = existingData;\n }\n\n // Process the new record data (isNewRecord = false for updates)\n const newRecordData = await this.recordProcessor.processRecord(\n record,\n primaryKey,\n targetDir,\n entityConfig,\n options.verbose,\n false,\n existingRecordData\n );\n\n // Apply merge strategy\n const mergedData = await this.mergeRecords(\n existingRecordData,\n newRecordData,\n entityConfig.pull?.mergeStrategy || 'merge',\n entityConfig.pull?.preserveFields || []\n );\n\n // Queue updated data for batched write\n if (Array.isArray(existingData)) {\n // Queue array update - batch will handle merging\n const primaryKeyLookup = this.createPrimaryKeyLookup(primaryKey);\n this.fileWriteBatch.queueArrayUpdate(filePath, mergedData, primaryKeyLookup);\n } else {\n // Queue single record update\n this.fileWriteBatch.queueSingleUpdate(filePath, mergedData);\n }\n\n if (options.verbose) {\n callbacks?.onLog?.(`Updated: ${filePath}`);\n }\n\n return { success: true, index };\n } catch (error) {\n const errorMessage = `Failed to update record ${index + 1}: ${(error as any).message || error}`;\n errors.push(errorMessage);\n callbacks?.onWarn?.(errorMessage);\n return { success: false, index };\n }\n });\n\n const updateResults = await Promise.all(updatePromises);\n updated = updateResults.filter((r) => r.success).length;\n processed += updated;\n\n if (options.verbose) {\n callbacks?.onSuccess?.(`Completed ${updated}/${existingRecordsToUpdate.length} record updates`);\n }\n }\n\n // Process new records in parallel\n if (newRecords.length > 0) {\n callbacks?.onProgress?.(`Creating new records (parallel processing)`);\n\n if (entityConfig.pull?.appendRecordsToExistingFile && entityConfig.pull?.newFileName) {\n // Append all new records to a single file using parallel processing\n const fileName = entityConfig.pull.newFileName.endsWith('.json')\n ? entityConfig.pull.newFileName\n : `${entityConfig.pull.newFileName}.json`;\n const filePath = path.join(targetDir, fileName);\n\n // Process all new records in parallel\n const newRecordPromises = newRecords.map(async ({ record, primaryKey }, index) => {\n try {\n // For new records, pass isNewRecord = true (default)\n const recordData = await this.recordProcessor.processRecord(record, primaryKey, targetDir, entityConfig, options.verbose, true);\n\n // Use queueArrayUpdate to append the new record without overwriting existing updates\n // For new records, we can use a special lookup key since they don't exist yet\n const newRecordLookup = this.createPrimaryKeyLookup(primaryKey);\n this.fileWriteBatch.queueArrayUpdate(filePath, recordData, newRecordLookup);\n\n return { success: true, index };\n } catch (error) {\n const errorMessage = `Failed to process new record ${index + 1}: ${(error as any).message || error}`;\n errors.push(errorMessage);\n callbacks?.onWarn?.(errorMessage);\n return { success: false, index };\n }\n });\n\n const newRecordResults = await Promise.all(newRecordPromises);\n created = newRecordResults.filter((r) => r.success).length;\n processed += created;\n\n if (options.verbose) {\n callbacks?.onLog?.(`Queued ${created} new records for: ${filePath}`);\n }\n } else {\n // Create individual files for each new record in parallel\n const individualRecordPromises = newRecords.map(async ({ record, primaryKey }, index) => {\n try {\n await this.processRecord(record, primaryKey, targetDir, entityConfig, options.verbose);\n return { success: true, index };\n } catch (error) {\n const errorMessage = `Failed to process new record ${index + 1}: ${(error as any).message || error}`;\n errors.push(errorMessage);\n callbacks?.onWarn?.(errorMessage);\n return { success: false, index };\n }\n });\n\n const individualResults = await Promise.all(individualRecordPromises);\n created = individualResults.filter((r) => r.success).length;\n processed += created;\n\n if (options.verbose) {\n callbacks?.onSuccess?.(`Created ${created}/${newRecords.length} individual record files`);\n }\n }\n }\n\n // If there were errors during parallel processing, throw them\n if (errors.length > 0) {\n throw new Error(`Parallel processing completed with ${errors.length} errors:\\n${errors.join('\\n')}`);\n }\n\n return { processed, updated, created, skipped };\n }\n\n private async processRecord(\n record: BaseEntity,\n primaryKey: Record<string, any>,\n targetDir: string,\n entityConfig: EntityConfig,\n verbose?: boolean\n ): Promise<void> {\n const recordData = await this.recordProcessor.processRecord(record, primaryKey, targetDir, entityConfig, verbose, true);\n\n // Determine file path\n const fileName = this.buildFileName(primaryKey, entityConfig);\n const filePath = path.join(targetDir, fileName);\n\n // Queue JSON file for batched write with controlled property order\n this.fileWriteBatch.queueWrite(filePath, recordData);\n }\n\n private async findEntityDirectories(entityName: string): Promise<string[]> {\n const dirs: string[] = [];\n\n // Search for directories with matching entity config\n const searchDirs = async (dir: string) => {\n const entries = await fs.readdir(dir, { withFileTypes: true });\n\n for (const entry of entries) {\n if (entry.isDirectory()) {\n const fullPath = path.join(dir, entry.name);\n const config = await loadEntityConfig(fullPath);\n\n if (config && config.entity === entityName) {\n dirs.push(fullPath);\n } else {\n // Recurse\n await searchDirs(fullPath);\n }\n }\n }\n };\n\n await searchDirs(configManager.getOriginalCwd());\n return dirs;\n }\n\n private buildFileName(primaryKey: Record<string, any>, _entityConfig: EntityConfig): string {\n // Use primary key values to build filename\n const keys = Object.values(primaryKey);\n\n if (keys.length === 1 && typeof keys[0] === 'string') {\n // Single string key - use as base if it's a guid\n const key = keys[0];\n if (key.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i)) {\n // It's a GUID, use first 8 chars, prefixed with dot, lowercase\n return `.${key.substring(0, 8).toLowerCase()}.json`;\n }\n // Use the whole key if not too long, prefixed with dot\n if (key.length <= 50) {\n return `.${key.replace(/[^a-zA-Z0-9\\-_]/g, '').toLowerCase()}.json`;\n }\n }\n\n // Multiple keys or numeric - create composite name, prefixed with dot\n return (\n '.' +\n keys\n .map((k) =>\n String(k)\n .replace(/[^a-zA-Z0-9\\-_]/g, '')\n .toLowerCase()\n )\n .join('-') +\n '.json'\n );\n }\n\n private async findExistingFiles(dir: string, pattern: string): Promise<string[]> {\n const files: string[] = [];\n\n try {\n const entries = await fs.readdir(dir, { withFileTypes: true });\n\n for (const entry of entries) {\n if (entry.isFile()) {\n const fileName = entry.name;\n\n // Simple pattern matching\n if (pattern === '*.json' && fileName.endsWith('.json')) {\n files.push(path.join(dir, fileName));\n } else if (pattern === '.*.json' && fileName.startsWith('.') && fileName.endsWith('.json')) {\n files.push(path.join(dir, fileName));\n } else if (pattern === fileName) {\n files.push(path.join(dir, fileName));\n }\n }\n }\n } catch (error) {\n // Directory might not exist yet\n if ((error as any).code !== 'ENOENT') {\n throw error;\n }\n }\n\n return files;\n }\n\n private async loadExistingRecords(\n files: string[],\n _entityInfo: EntityInfo\n ): Promise<Map<string, { filePath: string; recordData: RecordData }>> {\n const recordsMap = new Map<string, { filePath: string; recordData: RecordData }>();\n\n for (const filePath of files) {\n try {\n const fileData = await fs.readJson(filePath);\n const records = Array.isArray(fileData) ? fileData : [fileData];\n\n for (const record of records) {\n if (record.primaryKey) {\n const lookupKey = this.createPrimaryKeyLookup(record.primaryKey);\n recordsMap.set(lookupKey, { filePath, recordData: record });\n }\n }\n } catch (error) {\n // Skip files that can't be parsed\n }\n }\n\n return recordsMap;\n }\n\n private createPrimaryKeyLookup(primaryKey: Record<string, any>): string {\n const keys = Object.keys(primaryKey).sort();\n return keys.map((k) => `${k}:${primaryKey[k]}`).join('|');\n }\n\n private async mergeRecords(\n existing: RecordData,\n newData: RecordData,\n strategy: 'overwrite' | 'merge' | 'skip',\n preserveFields: string[]\n ): Promise<RecordData> {\n if (strategy === 'skip') {\n return existing;\n }\n\n if (strategy === 'overwrite') {\n const result: RecordData = {\n fields: { ...newData.fields },\n primaryKey: newData.primaryKey,\n sync: newData.sync,\n };\n\n // Restore preserved fields from existing\n if (preserveFields.length > 0 && existing.fields) {\n for (const field of preserveFields) {\n if (field in existing.fields) {\n result.fields[field] = existing.fields[field];\n }\n }\n }\n\n if (newData.relatedEntities) {\n result.relatedEntities = newData.relatedEntities;\n }\n\n return result;\n }\n\n // Default 'merge' strategy\n const result: RecordData = {\n fields: { ...existing.fields, ...newData.fields },\n primaryKey: newData.primaryKey || existing.primaryKey,\n sync: newData.sync,\n };\n\n // Restore preserved fields\n if (preserveFields.length > 0 && existing.fields) {\n for (const field of preserveFields) {\n if (field in existing.fields) {\n result.fields[field] = existing.fields[field];\n }\n }\n }\n\n if (existing.relatedEntities || newData.relatedEntities) {\n result.relatedEntities = {\n ...existing.relatedEntities,\n ...newData.relatedEntities,\n };\n }\n\n return result;\n }\n\n private async createBackup(filePath: string, backupDirName?: string): Promise<void> {\n const dir = path.dirname(filePath);\n const fileName = path.basename(filePath);\n const backupDir = path.join(dir, backupDirName || '.backups');\n\n // Ensure backup directory exists\n await fs.ensureDir(backupDir);\n // Track the backup directory for cleanup\n this.createdBackupDirs.add(backupDir);\n\n const timestamp = new Date().toISOString().replace(/[:.]/g, '-');\n // Remove .json extension, add timestamp, then add .backup extension\n const backupFileName = fileName.replace(/\\.json$/, `.${timestamp}.backup`);\n const backupPath = path.join(backupDir, backupFileName);\n\n try {\n await fs.copy(filePath, backupPath);\n // Track the created backup file for cleanup\n this.createdBackupFiles.push(backupPath);\n } catch (error) {\n // Log error but don't throw\n }\n }\n}\n"]}
|
|
@@ -7,7 +7,7 @@ exports.PushService = void 0;
|
|
|
7
7
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
10
|
-
const
|
|
10
|
+
const global_1 = require("@memberjunction/global");
|
|
11
11
|
const config_1 = require("../config");
|
|
12
12
|
const file_backup_manager_1 = require("../lib/file-backup-manager");
|
|
13
13
|
const config_manager_1 = require("../lib/config-manager");
|
|
@@ -58,7 +58,7 @@ class PushService {
|
|
|
58
58
|
try {
|
|
59
59
|
// Initialize SQL logger if enabled and not dry-run
|
|
60
60
|
if (sqlLogger.enabled && !options.dryRun) {
|
|
61
|
-
const provider =
|
|
61
|
+
const provider = global_1.Metadata.Provider;
|
|
62
62
|
if (options.verbose) {
|
|
63
63
|
callbacks?.onLog?.(`SQL logging enabled: ${sqlLogger.enabled}`);
|
|
64
64
|
callbacks?.onLog?.(`Provider type: ${provider?.constructor?.name || 'Unknown'}`);
|
|
@@ -67,9 +67,7 @@ class PushService {
|
|
|
67
67
|
if (provider && typeof provider.CreateSqlLogger === 'function') {
|
|
68
68
|
// Generate filename with timestamp
|
|
69
69
|
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
70
|
-
const filename = this.syncConfig.sqlLogging?.formatAsMigration
|
|
71
|
-
? `MetadataSync_Push_${timestamp}.sql`
|
|
72
|
-
: `push_${timestamp}.sql`;
|
|
70
|
+
const filename = this.syncConfig.sqlLogging?.formatAsMigration ? `MetadataSync_Push_${timestamp}.sql` : `push_${timestamp}.sql`;
|
|
73
71
|
// Use .sql-log-push directory in the config directory (where sync was initiated)
|
|
74
72
|
const outputDir = path_1.default.join(configDir, this.syncConfig?.sqlLogging?.outputDirectory || './sql-log-push');
|
|
75
73
|
const filepath = path_1.default.join(outputDir, filename);
|
|
@@ -79,7 +77,7 @@ class PushService {
|
|
|
79
77
|
sqlLoggingSession = await provider.CreateSqlLogger(filepath, {
|
|
80
78
|
formatAsMigration: this.syncConfig.sqlLogging?.formatAsMigration || false,
|
|
81
79
|
description: 'MetadataSync push operation',
|
|
82
|
-
statementTypes:
|
|
80
|
+
statementTypes: 'mutations',
|
|
83
81
|
prettyPrint: true,
|
|
84
82
|
filterPatterns: this.syncConfig.sqlLogging?.filterPatterns,
|
|
85
83
|
filterType: this.syncConfig.sqlLogging?.filterType,
|
|
@@ -218,7 +216,7 @@ class PushService {
|
|
|
218
216
|
skipped: totalSkipped,
|
|
219
217
|
errors: totalErrors,
|
|
220
218
|
warnings: this.warnings,
|
|
221
|
-
sqlLogPath
|
|
219
|
+
sqlLogPath,
|
|
222
220
|
};
|
|
223
221
|
}
|
|
224
222
|
catch (error) {
|
|
@@ -258,7 +256,7 @@ class PushService {
|
|
|
258
256
|
absolute: true,
|
|
259
257
|
onlyFiles: true,
|
|
260
258
|
dot: true,
|
|
261
|
-
ignore: ['**/node_modules/**', '**/.mj-*.json']
|
|
259
|
+
ignore: ['**/node_modules/**', '**/.mj-*.json'],
|
|
262
260
|
});
|
|
263
261
|
if (options.verbose) {
|
|
264
262
|
callbacks?.onLog?.(`Found ${files.length} files to process`);
|
|
@@ -409,7 +407,7 @@ class PushService {
|
|
|
409
407
|
return { created, updated, unchanged, deleted, skipped, errors };
|
|
410
408
|
}
|
|
411
409
|
async processFlattenedRecord(flattenedRecord, entityDir, options, batchContext, callbacks, entityConfig) {
|
|
412
|
-
const metadata = new
|
|
410
|
+
const metadata = new global_1.Metadata();
|
|
413
411
|
const { record, entityName, parentContext, id: recordId } = flattenedRecord;
|
|
414
412
|
// Check if this record has a deleteRecord directive
|
|
415
413
|
if (record.deleteRecord && record.deleteRecord.delete === true) {
|
|
@@ -645,9 +643,7 @@ class PushService {
|
|
|
645
643
|
for (const field of entity.Fields) {
|
|
646
644
|
const value = entity.Get(field.Name);
|
|
647
645
|
if (value !== null && value !== undefined) {
|
|
648
|
-
const displayValue = typeof value === 'string' && value.length > 100
|
|
649
|
-
? value.substring(0, 100) + '...'
|
|
650
|
-
: value;
|
|
646
|
+
const displayValue = typeof value === 'string' && value.length > 100 ? value.substring(0, 100) + '...' : value;
|
|
651
647
|
logError(` ${field.Name}: ${displayValue}`);
|
|
652
648
|
}
|
|
653
649
|
}
|
|
@@ -672,7 +668,7 @@ class PushService {
|
|
|
672
668
|
if (entity.LatestResult.Errors && entity.LatestResult.Errors.length > 0) {
|
|
673
669
|
logError(` Errors:`);
|
|
674
670
|
entity.LatestResult.Errors.forEach((err, idx) => {
|
|
675
|
-
const errorMsg = typeof err === 'string' ? err :
|
|
671
|
+
const errorMsg = typeof err === 'string' ? err : err?.message || JSON.stringify(err);
|
|
676
672
|
logError(` ${idx + 1}. ${errorMsg}`);
|
|
677
673
|
});
|
|
678
674
|
}
|
|
@@ -686,9 +682,7 @@ class PushService {
|
|
|
686
682
|
for (const field of entity.Fields) {
|
|
687
683
|
const value = entity.Get(field.Name);
|
|
688
684
|
if (value !== null && value !== undefined) {
|
|
689
|
-
const displayValue = typeof value === 'string' && value.length > 100
|
|
690
|
-
? value.substring(0, 100) + '...'
|
|
691
|
-
: value;
|
|
685
|
+
const displayValue = typeof value === 'string' && value.length > 100 ? value.substring(0, 100) + '...' : value;
|
|
692
686
|
logError(` ${field.Name}: ${displayValue}`);
|
|
693
687
|
}
|
|
694
688
|
}
|
|
@@ -711,7 +705,7 @@ class PushService {
|
|
|
711
705
|
}
|
|
712
706
|
// Get the actual error details from the entity
|
|
713
707
|
const errorMessage = entity.LatestResult?.Message || 'Unknown error';
|
|
714
|
-
const errorDetails = entity.LatestResult?.Errors?.map(err => typeof err === 'string' ? err :
|
|
708
|
+
const errorDetails = entity.LatestResult?.Errors?.map((err) => (typeof err === 'string' ? err : err?.message || JSON.stringify(err)))?.join(', ') || '';
|
|
715
709
|
// Log detailed error information
|
|
716
710
|
callbacks?.onError?.(`\nā FATAL ERROR: Failed to save ${entityName} record`);
|
|
717
711
|
callbacks?.onError?.(` Entity: ${entityName}`);
|
|
@@ -756,7 +750,7 @@ class PushService {
|
|
|
756
750
|
if (isNew || isDirty) {
|
|
757
751
|
record.sync = {
|
|
758
752
|
lastModified: new Date().toISOString(),
|
|
759
|
-
checksum: await this.syncEngine.calculateChecksumWithFileContent(originalFields, entityDir)
|
|
753
|
+
checksum: await this.syncEngine.calculateChecksumWithFileContent(originalFields, entityDir),
|
|
760
754
|
};
|
|
761
755
|
if (options.verbose) {
|
|
762
756
|
callbacks?.onLog?.(` ā Updated sync metadata (record was ${isNew ? 'new' : 'changed'})`);
|
|
@@ -768,8 +762,8 @@ class PushService {
|
|
|
768
762
|
// Restore original field values to preserve @ references
|
|
769
763
|
record.fields = originalFields;
|
|
770
764
|
return {
|
|
771
|
-
status: isNew ? 'created' :
|
|
772
|
-
isDuplicate: false
|
|
765
|
+
status: isNew ? 'created' : isDirty ? 'updated' : 'unchanged',
|
|
766
|
+
isDuplicate: false,
|
|
773
767
|
};
|
|
774
768
|
}
|
|
775
769
|
formatFieldValue(value) {
|
|
@@ -846,7 +840,7 @@ class PushService {
|
|
|
846
840
|
if (!deleteResult) {
|
|
847
841
|
// Check the LatestResult for error details
|
|
848
842
|
const errorMessage = existingEntity.LatestResult?.Message || 'Unknown error';
|
|
849
|
-
const errorDetails = existingEntity.LatestResult?.Errors?.map(err => typeof err === 'string' ? err :
|
|
843
|
+
const errorDetails = existingEntity.LatestResult?.Errors?.map((err) => (typeof err === 'string' ? err : err?.message || JSON.stringify(err)))?.join(', ') || '';
|
|
850
844
|
callbacks?.onError?.(`\nā Failed to delete ${entityName} record`);
|
|
851
845
|
callbacks?.onError?.(` Primary Key: {${primaryKeyDisplay.join(', ')}}`);
|
|
852
846
|
callbacks?.onError?.(` Error: ${errorMessage}`);
|