@memberjunction/metadata-sync 2.54.0 → 2.56.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/README.md +92 -51
  2. package/dist/index.d.ts +21 -1
  3. package/dist/index.js +41 -3
  4. package/dist/index.js.map +1 -1
  5. package/dist/lib/file-backup-manager.js +2 -2
  6. package/dist/lib/file-backup-manager.js.map +1 -1
  7. package/dist/lib/sql-logger.d.ts +44 -0
  8. package/dist/lib/sql-logger.js +140 -0
  9. package/dist/lib/sql-logger.js.map +1 -0
  10. package/dist/lib/sync-engine.js +2 -2
  11. package/dist/lib/sync-engine.js.map +1 -1
  12. package/dist/lib/transaction-manager.d.ts +36 -0
  13. package/dist/lib/transaction-manager.js +117 -0
  14. package/dist/lib/transaction-manager.js.map +1 -0
  15. package/dist/services/FileResetService.d.ts +30 -0
  16. package/dist/services/FileResetService.js +182 -0
  17. package/dist/services/FileResetService.js.map +1 -0
  18. package/dist/services/InitService.d.ts +17 -0
  19. package/dist/services/InitService.js +118 -0
  20. package/dist/services/InitService.js.map +1 -0
  21. package/dist/services/PullService.d.ts +45 -0
  22. package/dist/services/PullService.js +564 -0
  23. package/dist/services/PullService.js.map +1 -0
  24. package/dist/services/PushService.d.ts +45 -0
  25. package/dist/services/PushService.js +394 -0
  26. package/dist/services/PushService.js.map +1 -0
  27. package/dist/services/StatusService.d.ts +32 -0
  28. package/dist/services/StatusService.js +138 -0
  29. package/dist/services/StatusService.js.map +1 -0
  30. package/dist/services/WatchService.d.ts +32 -0
  31. package/dist/services/WatchService.js +242 -0
  32. package/dist/services/WatchService.js.map +1 -0
  33. package/dist/services/index.d.ts +16 -0
  34. package/dist/services/index.js +28 -0
  35. package/dist/services/index.js.map +1 -0
  36. package/package.json +14 -45
  37. package/bin/debug.js +0 -7
  38. package/bin/run +0 -17
  39. package/bin/run.js +0 -6
  40. package/dist/commands/file-reset/index.d.ts +0 -15
  41. package/dist/commands/file-reset/index.js +0 -221
  42. package/dist/commands/file-reset/index.js.map +0 -1
  43. package/dist/commands/init/index.d.ts +0 -7
  44. package/dist/commands/init/index.js +0 -155
  45. package/dist/commands/init/index.js.map +0 -1
  46. package/dist/commands/pull/index.d.ts +0 -246
  47. package/dist/commands/pull/index.js +0 -1448
  48. package/dist/commands/pull/index.js.map +0 -1
  49. package/dist/commands/push/index.d.ts +0 -41
  50. package/dist/commands/push/index.js +0 -1131
  51. package/dist/commands/push/index.js.map +0 -1
  52. package/dist/commands/status/index.d.ts +0 -10
  53. package/dist/commands/status/index.js +0 -199
  54. package/dist/commands/status/index.js.map +0 -1
  55. package/dist/commands/validate/index.d.ts +0 -15
  56. package/dist/commands/validate/index.js +0 -149
  57. package/dist/commands/validate/index.js.map +0 -1
  58. package/dist/commands/watch/index.d.ts +0 -15
  59. package/dist/commands/watch/index.js +0 -300
  60. package/dist/commands/watch/index.js.map +0 -1
  61. package/dist/hooks/init.d.ts +0 -3
  62. package/dist/hooks/init.js +0 -59
  63. package/dist/hooks/init.js.map +0 -1
  64. package/oclif.manifest.json +0 -376
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PullService.js","sourceRoot":"","sources":["../../src/services/PullService.ts"],"names":[],"mappings":";;;;;;AAAA,wDAA0B;AAC1B,gDAAwB;AACxB,+CAA+E;AAE/E,sCAAkE;AAClE,0DAAsD;AA8BtD,MAAa,WAAW;IACd,UAAU,CAAa;IACvB,WAAW,CAAW;IAE9B,YAAY,UAAsB,EAAE,WAAqB;QACvD,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,OAAoB,EAAE,SAAyB;QACxD,IAAI,SAAiB,CAAC;QACtB,IAAI,YAAiB,CAAC;QAEtB,qDAAqD;QACrD,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;YACtB,IAAI,OAAO,CAAC,OAAO,EAAE,CAA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C,IAAI,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QACtC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,4BAA4B;QAC9B,CAAC;IACH,CAAC;CACF;AA/sBD,kCA+sBC","sourcesContent":["import fs from 'fs-extra';\nimport path from 'path';\nimport { RunView, Metadata, EntityInfo, UserInfo } from '@memberjunction/core';\nimport { SyncEngine, RecordData } from '../lib/sync-engine';\nimport { loadEntityConfig, RelatedEntityConfig } from '../config';\nimport { configManager } from '../lib/config-manager';\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 \n constructor(syncEngine: SyncEngine, contextUser: UserInfo) {\n this.syncEngine = syncEngine;\n this.contextUser = contextUser;\n }\n \n async pull(options: PullOptions, callbacks?: PullCallbacks): Promise<PullResult> {\n let targetDir: string;\n let entityConfig: any;\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 // Check if we need to wait for async property loading\n if (entityConfig.pull?.externalizeFields && result.Results.length > 0) {\n await this.handleAsyncPropertyLoading(options.entity, entityConfig, options.verbose, callbacks);\n }\n \n // Process records\n const pullResult = await this.processRecords(\n result.Results,\n options,\n targetDir,\n entityConfig,\n callbacks\n );\n \n return {\n ...pullResult,\n targetDir\n };\n }\n \n private async handleAsyncPropertyLoading(\n entityName: string,\n entityConfig: any,\n verbose?: boolean,\n callbacks?: PullCallbacks\n ): Promise<void> {\n const metadata = new Metadata();\n const entityInfo = metadata.EntityByName(entityName);\n \n if (!entityInfo) return;\n \n const externalizeConfig = entityConfig.pull.externalizeFields;\n let fieldsToExternalize: string[] = [];\n \n if (Array.isArray(externalizeConfig)) {\n if (externalizeConfig.length > 0 && typeof externalizeConfig[0] === 'string') {\n fieldsToExternalize = externalizeConfig as string[];\n } else {\n fieldsToExternalize = (externalizeConfig as Array<{field: string; pattern: string}>)\n .map(item => item.field);\n }\n } else {\n fieldsToExternalize = Object.keys(externalizeConfig);\n }\n \n // Get all field names from entity metadata\n const metadataFieldNames = entityInfo.Fields.map(f => f.Name);\n \n // Check if any externalized fields are NOT in metadata (likely computed properties)\n const computedFields = fieldsToExternalize.filter(f => !metadataFieldNames.includes(f));\n \n if (computedFields.length > 0) {\n if (verbose) {\n callbacks?.onProgress?.(`Waiting 5 seconds for async property loading in ${entityName} (${computedFields.join(', ')})...`);\n }\n await new Promise(resolve => setTimeout(resolve, 5000));\n if (verbose) {\n callbacks?.onSuccess?.('Async property loading wait complete');\n }\n }\n }\n \n private async processRecords(\n records: any[],\n options: PullOptions,\n targetDir: string,\n entityConfig: any,\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 \n for (const record of records) {\n try {\n // Build primary key\n const primaryKey: Record<string, any> = {};\n for (const pk of entityInfo.PrimaryKeys) {\n primaryKey[pk.Name] = record[pk.Name];\n }\n \n // Process record for multi-file\n const recordData = await this.processRecordData(\n record, \n primaryKey, \n targetDir, \n entityConfig, \n options.verbose, \n true\n );\n allRecords.push(recordData);\n processed++;\n \n if (options.verbose) {\n callbacks?.onProgress?.(`Processing records (${processed}/${records.length})`);\n }\n } catch (error) {\n callbacks?.onWarn?.(`Failed to process record: ${(error as any).message || error}`);\n }\n }\n \n // Write all records to single file\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 await fs.writeJson(filePath, allRecords, { spaces: 2 });\n callbacks?.onSuccess?.(`Pulled ${processed} records to ${path.basename(filePath)}`);\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 private async processIndividualRecords(\n records: any[],\n options: PullOptions,\n targetDir: string,\n entityConfig: any,\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: any; primaryKey: Record<string, any> }> = [];\n const existingRecordsToUpdate: Array<{ record: any; 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[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 \n // Process existing records updates\n for (const { record, primaryKey, filePath } of existingRecordsToUpdate) {\n try {\n callbacks?.onProgress?.(`Updating existing records (${updated + 1}/${existingRecordsToUpdate.length})`);\n \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.processRecordData(\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 // Write updated data\n if (Array.isArray(existingData)) {\n // Update the record in the array\n const index = existingData.findIndex(r => \n this.createPrimaryKeyLookup(r.primaryKey || {}) === this.createPrimaryKeyLookup(primaryKey)\n );\n if (index >= 0) {\n existingData[index] = mergedData;\n await fs.writeJson(filePath, existingData, { spaces: 2 });\n }\n } else {\n await fs.writeJson(filePath, mergedData, { spaces: 2 });\n }\n \n updated++;\n processed++;\n \n if (options.verbose) {\n callbacks?.onLog?.(`Updated: ${filePath}`);\n }\n } catch (error) {\n callbacks?.onWarn?.(`Failed to update record: ${(error as any).message || error}`);\n }\n }\n \n // Process new records\n if (newRecords.length > 0) {\n callbacks?.onProgress?.(`Creating new records (0/${newRecords.length})`);\n \n if (entityConfig.pull?.appendRecordsToExistingFile && entityConfig.pull?.newFileName) {\n // Append all new records to a single file\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 // Load existing file if it exists\n let existingData: RecordData[] = [];\n if (await fs.pathExists(filePath)) {\n const fileData = await fs.readJson(filePath);\n existingData = Array.isArray(fileData) ? fileData : [fileData];\n }\n \n // Process and append all new records\n for (const { record, primaryKey } of newRecords) {\n try {\n // For new records, pass isNewRecord = true (default)\n const recordData = await this.processRecordData(\n record, \n primaryKey, \n targetDir, \n entityConfig, \n options.verbose, \n true\n );\n existingData.push(recordData);\n created++;\n processed++;\n \n if (options.verbose) {\n callbacks?.onProgress?.(`Creating new records (${created}/${newRecords.length})`);\n }\n } catch (error) {\n callbacks?.onWarn?.(`Failed to process new record: ${(error as any).message || error}`);\n }\n }\n \n // Write the combined data\n await fs.writeJson(filePath, existingData, { spaces: 2 });\n \n if (options.verbose) {\n callbacks?.onLog?.(`Appended ${created} new records to: ${filePath}`);\n }\n } else {\n // Create individual files for each new record\n for (const { record, primaryKey } of newRecords) {\n try {\n await this.processRecord(record, primaryKey, targetDir, entityConfig, options.verbose);\n created++;\n processed++;\n \n if (options.verbose) {\n callbacks?.onProgress?.(`Creating new records (${created}/${newRecords.length})`);\n }\n } catch (error) {\n callbacks?.onWarn?.(`Failed to process new record: ${(error as any).message || error}`);\n }\n }\n }\n }\n \n return { processed, updated, created, skipped };\n }\n \n private async processRecord(\n record: any, \n primaryKey: Record<string, any>,\n targetDir: string, \n entityConfig: any,\n verbose?: boolean\n ): Promise<void> {\n const recordData = await this.processRecordData(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 // Write JSON file\n await fs.writeJson(filePath, recordData, { spaces: 2 });\n }\n \n private async processRecordData(\n record: any, \n primaryKey: Record<string, any>,\n targetDir: string, \n entityConfig: any,\n verbose?: boolean,\n isNewRecord: boolean = true,\n existingRecordData?: RecordData,\n currentDepth: number = 0,\n ancestryPath: Set<string> = new Set()\n ): Promise<RecordData> {\n // This is a simplified version - the full implementation would need to be extracted\n // from the pull command. For now, we'll delegate to a method that would be\n // implemented in the full service\n \n // Build record data\n const fields: Record<string, any> = {};\n const relatedEntities: Record<string, RecordData[]> = {};\n \n // Get the underlying data from the entity object\n let dataToProcess = record;\n if (typeof record.GetAll === 'function') {\n dataToProcess = record.GetAll();\n }\n \n // Process fields (simplified - full implementation needed)\n for (const [fieldName, fieldValue] of Object.entries(dataToProcess)) {\n // Skip primary key fields\n if (primaryKey[fieldName] !== undefined) {\n continue;\n }\n \n // Skip internal fields\n if (fieldName.startsWith('__mj_')) {\n continue;\n }\n \n // Skip excluded fields\n if (entityConfig.pull?.excludeFields?.includes(fieldName)) {\n continue;\n }\n \n fields[fieldName] = fieldValue;\n }\n \n // Calculate checksum\n const checksum = this.syncEngine.calculateChecksum(fields);\n \n // Build the final record data\n const recordData: RecordData = {\n fields,\n primaryKey,\n sync: {\n lastModified: new Date().toISOString(),\n checksum: checksum\n }\n };\n \n if (Object.keys(relatedEntities).length > 0) {\n recordData.relatedEntities = relatedEntities;\n }\n \n return 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: any): 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 \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 } catch (error) {\n // Log error but don't throw\n }\n }\n}"]}
@@ -0,0 +1,45 @@
1
+ import { UserInfo } from '@memberjunction/core';
2
+ import { SyncEngine } from '../lib/sync-engine';
3
+ export interface PushOptions {
4
+ dir?: string;
5
+ dryRun?: boolean;
6
+ verbose?: boolean;
7
+ noValidate?: boolean;
8
+ }
9
+ export interface PushCallbacks {
10
+ onProgress?: (message: string) => void;
11
+ onSuccess?: (message: string) => void;
12
+ onError?: (message: string) => void;
13
+ onWarn?: (message: string) => void;
14
+ onLog?: (message: string) => void;
15
+ onConfirm?: (message: string) => Promise<boolean>;
16
+ }
17
+ export interface PushResult {
18
+ created: number;
19
+ updated: number;
20
+ unchanged: number;
21
+ errors: number;
22
+ warnings: string[];
23
+ sqlLogPath?: string;
24
+ }
25
+ export interface EntityPushResult {
26
+ created: number;
27
+ updated: number;
28
+ unchanged: number;
29
+ errors: number;
30
+ }
31
+ export declare class PushService {
32
+ private syncEngine;
33
+ private contextUser;
34
+ private warnings;
35
+ private processedRecords;
36
+ private syncConfig;
37
+ constructor(syncEngine: SyncEngine, contextUser: UserInfo);
38
+ push(options: PushOptions, callbacks?: PushCallbacks): Promise<PushResult>;
39
+ private processEntityDirectory;
40
+ private processRecord;
41
+ private processRelatedEntities;
42
+ private isValidRecordData;
43
+ private getRecordKey;
44
+ private findEntityDirectories;
45
+ }
@@ -0,0 +1,394 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.PushService = void 0;
7
+ const fs_extra_1 = __importDefault(require("fs-extra"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const fast_glob_1 = __importDefault(require("fast-glob"));
10
+ const core_1 = require("@memberjunction/core");
11
+ const config_1 = require("../config");
12
+ const file_backup_manager_1 = require("../lib/file-backup-manager");
13
+ const config_manager_1 = require("../lib/config-manager");
14
+ const sql_logger_1 = require("../lib/sql-logger");
15
+ const transaction_manager_1 = require("../lib/transaction-manager");
16
+ class PushService {
17
+ syncEngine;
18
+ contextUser;
19
+ warnings = [];
20
+ processedRecords = new Map();
21
+ syncConfig;
22
+ constructor(syncEngine, contextUser) {
23
+ this.syncEngine = syncEngine;
24
+ this.contextUser = contextUser;
25
+ }
26
+ async push(options, callbacks) {
27
+ this.warnings = [];
28
+ this.processedRecords.clear();
29
+ const fileBackupManager = new file_backup_manager_1.FileBackupManager();
30
+ // Load sync config for SQL logging settings and autoCreateMissingRecords flag
31
+ this.syncConfig = await (0, config_1.loadSyncConfig)(config_manager_1.configManager.getOriginalCwd());
32
+ const sqlLogger = new sql_logger_1.SQLLogger(this.syncConfig);
33
+ const transactionManager = new transaction_manager_1.TransactionManager(sqlLogger);
34
+ try {
35
+ // Initialize SQL logger if enabled
36
+ if (sqlLogger.enabled && !options.dryRun) {
37
+ await sqlLogger.initialize();
38
+ if (options.verbose) {
39
+ callbacks?.onLog?.('šŸ“ SQL logging enabled');
40
+ }
41
+ }
42
+ // Find entity directories to process
43
+ const entityDirs = this.findEntityDirectories(config_manager_1.configManager.getOriginalCwd(), options.dir);
44
+ if (entityDirs.length === 0) {
45
+ throw new Error('No entity directories found');
46
+ }
47
+ if (options.verbose) {
48
+ callbacks?.onLog?.(`Found ${entityDirs.length} entity ${entityDirs.length === 1 ? 'directory' : 'directories'} to process`);
49
+ }
50
+ // Initialize file backup manager (unless in dry-run mode)
51
+ if (!options.dryRun) {
52
+ await fileBackupManager.initialize();
53
+ if (options.verbose) {
54
+ callbacks?.onLog?.('šŸ“ File backup manager initialized');
55
+ }
56
+ }
57
+ // Process each entity directory
58
+ let totalCreated = 0;
59
+ let totalUpdated = 0;
60
+ let totalUnchanged = 0;
61
+ let totalErrors = 0;
62
+ // Begin transaction if not in dry-run mode
63
+ if (!options.dryRun) {
64
+ await transactionManager.beginTransaction();
65
+ }
66
+ try {
67
+ for (const entityDir of entityDirs) {
68
+ const entityConfig = await (0, config_1.loadEntityConfig)(entityDir);
69
+ if (!entityConfig) {
70
+ const warning = `Skipping ${entityDir} - no valid entity configuration`;
71
+ this.warnings.push(warning);
72
+ callbacks?.onWarn?.(warning);
73
+ continue;
74
+ }
75
+ if (options.verbose) {
76
+ callbacks?.onLog?.(`\nProcessing ${entityConfig.entity} in ${entityDir}`);
77
+ }
78
+ const result = await this.processEntityDirectory(entityDir, entityConfig, options, fileBackupManager, callbacks, sqlLogger);
79
+ // Show per-directory summary
80
+ const dirName = path_1.default.relative(process.cwd(), entityDir) || '.';
81
+ const dirTotal = result.created + result.updated + result.unchanged;
82
+ if (dirTotal > 0 || result.errors > 0) {
83
+ callbacks?.onLog?.(`\nšŸ“ ${dirName}:`);
84
+ callbacks?.onLog?.(` Total processed: ${dirTotal} unique records`);
85
+ if (result.created > 0) {
86
+ callbacks?.onLog?.(` āœ“ Created: ${result.created}`);
87
+ }
88
+ if (result.updated > 0) {
89
+ callbacks?.onLog?.(` āœ“ Updated: ${result.updated}`);
90
+ }
91
+ if (result.unchanged > 0) {
92
+ callbacks?.onLog?.(` - Unchanged: ${result.unchanged}`);
93
+ }
94
+ if (result.errors > 0) {
95
+ callbacks?.onLog?.(` āœ— Errors: ${result.errors}`);
96
+ }
97
+ }
98
+ totalCreated += result.created;
99
+ totalUpdated += result.updated;
100
+ totalUnchanged += result.unchanged;
101
+ totalErrors += result.errors;
102
+ }
103
+ // Commit transaction if successful
104
+ if (!options.dryRun && totalErrors === 0) {
105
+ await transactionManager.commitTransaction();
106
+ }
107
+ }
108
+ catch (error) {
109
+ // Rollback transaction on error
110
+ if (!options.dryRun) {
111
+ await transactionManager.rollbackTransaction();
112
+ }
113
+ throw error;
114
+ }
115
+ // Commit file backups if successful and not in dry-run mode
116
+ if (!options.dryRun && totalErrors === 0) {
117
+ await fileBackupManager.cleanup();
118
+ if (options.verbose) {
119
+ callbacks?.onLog?.('āœ… File backups committed');
120
+ }
121
+ }
122
+ // Write SQL log if enabled
123
+ let sqlLogPath;
124
+ if (sqlLogger.enabled && !options.dryRun) {
125
+ sqlLogPath = await sqlLogger.writeLog();
126
+ if (sqlLogPath && options.verbose) {
127
+ callbacks?.onLog?.(`šŸ“ SQL log written to: ${sqlLogPath}`);
128
+ }
129
+ }
130
+ return {
131
+ created: totalCreated,
132
+ updated: totalUpdated,
133
+ unchanged: totalUnchanged,
134
+ errors: totalErrors,
135
+ warnings: this.warnings,
136
+ sqlLogPath
137
+ };
138
+ }
139
+ catch (error) {
140
+ // Rollback file backups on error
141
+ if (!options.dryRun) {
142
+ try {
143
+ await fileBackupManager.rollback();
144
+ callbacks?.onWarn?.('File backups rolled back due to error');
145
+ }
146
+ catch (rollbackError) {
147
+ callbacks?.onWarn?.(`Failed to rollback file backups: ${rollbackError}`);
148
+ }
149
+ }
150
+ throw error;
151
+ }
152
+ }
153
+ async processEntityDirectory(entityDir, entityConfig, options, fileBackupManager, callbacks, sqlLogger) {
154
+ let created = 0;
155
+ let updated = 0;
156
+ let unchanged = 0;
157
+ let errors = 0;
158
+ // Find all JSON files in the directory
159
+ const pattern = entityConfig.filePattern || '*.json';
160
+ const files = await (0, fast_glob_1.default)(pattern, {
161
+ cwd: entityDir,
162
+ absolute: true,
163
+ onlyFiles: true,
164
+ ignore: ['**/node_modules/**', '**/.mj-*.json']
165
+ });
166
+ if (options.verbose) {
167
+ callbacks?.onLog?.(`Found ${files.length} files to process`);
168
+ }
169
+ // Process each file
170
+ for (const filePath of files) {
171
+ try {
172
+ const fileData = await fs_extra_1.default.readJson(filePath);
173
+ const records = Array.isArray(fileData) ? fileData : [fileData];
174
+ for (let i = 0; i < records.length; i++) {
175
+ const recordData = records[i];
176
+ if (!this.isValidRecordData(recordData)) {
177
+ callbacks?.onWarn?.(`Invalid record format in ${filePath}${Array.isArray(fileData) ? ` at index ${i}` : ''}`);
178
+ errors++;
179
+ continue;
180
+ }
181
+ try {
182
+ const result = await this.processRecord(recordData, entityConfig, entityDir, options, callbacks);
183
+ if (result === 'created')
184
+ created++;
185
+ else if (result === 'updated')
186
+ updated++;
187
+ else if (result === 'unchanged')
188
+ unchanged++;
189
+ // Track processed record
190
+ const recordKey = this.getRecordKey(recordData, entityConfig.entity);
191
+ this.processedRecords.set(recordKey, {
192
+ filePath,
193
+ arrayIndex: Array.isArray(fileData) ? i : undefined,
194
+ lineNumber: i + 1 // Simple line number approximation
195
+ });
196
+ }
197
+ catch (recordError) {
198
+ const errorMsg = `Error processing record in ${filePath}${Array.isArray(fileData) ? ` at index ${i}` : ''}: ${recordError}`;
199
+ callbacks?.onError?.(errorMsg);
200
+ errors++;
201
+ }
202
+ }
203
+ }
204
+ catch (fileError) {
205
+ const errorMsg = `Error reading file ${filePath}: ${fileError}`;
206
+ callbacks?.onError?.(errorMsg);
207
+ errors++;
208
+ }
209
+ }
210
+ return { created, updated, unchanged, errors };
211
+ }
212
+ async processRecord(recordData, entityConfig, entityDir, options, callbacks) {
213
+ const metadata = new core_1.Metadata();
214
+ const entityInfo = metadata.EntityByName(entityConfig.entity);
215
+ if (!entityInfo) {
216
+ throw new Error(`Entity ${entityConfig.entity} not found in metadata`);
217
+ }
218
+ // Get or create entity instance
219
+ let entity = await metadata.GetEntityObject(entityConfig.entity, this.contextUser);
220
+ if (!entity) {
221
+ throw new Error(`Failed to create entity object for ${entityConfig.entity}`);
222
+ }
223
+ // Apply defaults from configuration
224
+ const defaults = { ...entityConfig.defaults };
225
+ // Build full record data
226
+ const fullData = {
227
+ ...defaults,
228
+ ...recordData.fields
229
+ };
230
+ // Process field values
231
+ const processedData = {};
232
+ for (const [fieldName, fieldValue] of Object.entries(fullData)) {
233
+ const processedValue = await this.syncEngine.processFieldValue(fieldValue, entityDir, null, // parentRecord
234
+ null // rootRecord
235
+ );
236
+ processedData[fieldName] = processedValue;
237
+ }
238
+ // Check if record exists
239
+ const primaryKey = recordData.primaryKey;
240
+ let exists = false;
241
+ let existingEntity = null;
242
+ if (primaryKey && Object.keys(primaryKey).length > 0) {
243
+ // Try to load existing record
244
+ const compositeKey = new core_1.CompositeKey();
245
+ compositeKey.LoadFromSimpleObject(primaryKey);
246
+ existingEntity = await metadata.GetEntityObject(entityConfig.entity, this.contextUser);
247
+ if (existingEntity) {
248
+ exists = await existingEntity.InnerLoad(compositeKey);
249
+ // Check autoCreateMissingRecords flag if record not found
250
+ if (!exists) {
251
+ const autoCreate = this.syncConfig?.push?.autoCreateMissingRecords ?? false;
252
+ const pkDisplay = Object.entries(primaryKey)
253
+ .map(([key, value]) => `${key}=${value}`)
254
+ .join(', ');
255
+ if (!autoCreate) {
256
+ const warning = `Record not found: ${entityConfig.entity} with primaryKey {${pkDisplay}}. To auto-create missing records, set push.autoCreateMissingRecords=true in .mj-sync.json`;
257
+ this.warnings.push(warning);
258
+ callbacks?.onWarn?.(warning);
259
+ return 'error';
260
+ }
261
+ else if (options.verbose) {
262
+ callbacks?.onLog?.(`Auto-creating missing ${entityConfig.entity} record with primaryKey {${pkDisplay}}`);
263
+ }
264
+ }
265
+ }
266
+ }
267
+ if (options.dryRun) {
268
+ if (exists) {
269
+ callbacks?.onLog?.(`[DRY RUN] Would update ${entityConfig.entity} record`);
270
+ return 'updated';
271
+ }
272
+ else {
273
+ callbacks?.onLog?.(`[DRY RUN] Would create ${entityConfig.entity} record`);
274
+ return 'created';
275
+ }
276
+ }
277
+ // Use existing entity if found, otherwise create new one
278
+ if (!exists) {
279
+ entity = existingEntity || entity;
280
+ entity.NewRecord();
281
+ // Set primary key values for new records if provided
282
+ if (primaryKey) {
283
+ for (const [pkField, pkValue] of Object.entries(primaryKey)) {
284
+ entity.Set(pkField, pkValue);
285
+ }
286
+ }
287
+ }
288
+ // Set field values
289
+ for (const [fieldName, fieldValue] of Object.entries(processedData)) {
290
+ entity.Set(fieldName, fieldValue);
291
+ }
292
+ // Handle related entities
293
+ if (recordData.relatedEntities) {
294
+ // Store related entities to process after parent save
295
+ entity.__pendingRelatedEntities = recordData.relatedEntities;
296
+ }
297
+ // Save the record
298
+ // TODO: Hook into BaseEntity SQL execution for SQL logging
299
+ // Currently SQL logging requires deeper integration with MJ core
300
+ const saveResult = await entity.Save();
301
+ if (!saveResult) {
302
+ throw new Error(`Failed to save ${entityConfig.entity} record: ${entity.LatestResult?.Message || 'Unknown error'}`);
303
+ }
304
+ // Process related entities after parent save
305
+ if (recordData.relatedEntities) {
306
+ await this.processRelatedEntities(entity, recordData.relatedEntities, entityDir, options, callbacks);
307
+ }
308
+ return exists ? 'updated' : 'created';
309
+ }
310
+ async processRelatedEntities(parentEntity, relatedEntities, entityDir, options, callbacks) {
311
+ // TODO: Complete implementation for processing related entities
312
+ // This is a simplified version - full implementation would:
313
+ // 1. Create entity objects for each related entity type
314
+ // 2. Apply field values with proper parent/root references
315
+ // 3. Save related entities with proper error handling
316
+ // 4. Support nested related entities recursively
317
+ for (const [key, records] of Object.entries(relatedEntities)) {
318
+ for (const relatedRecord of records) {
319
+ // Process @parent references
320
+ const processedFields = {};
321
+ for (const [fieldName, fieldValue] of Object.entries(relatedRecord.fields)) {
322
+ if (typeof fieldValue === 'string' && fieldValue.startsWith('@parent:')) {
323
+ const parentField = fieldValue.substring(8);
324
+ processedFields[fieldName] = parentEntity.Get(parentField);
325
+ }
326
+ else {
327
+ processedFields[fieldName] = await this.syncEngine.processFieldValue(fieldValue, entityDir, parentEntity, null);
328
+ }
329
+ }
330
+ // Save related entity (simplified - full implementation needed)
331
+ relatedRecord.fields = processedFields;
332
+ }
333
+ }
334
+ }
335
+ isValidRecordData(data) {
336
+ return data &&
337
+ typeof data === 'object' &&
338
+ 'fields' in data &&
339
+ typeof data.fields === 'object';
340
+ }
341
+ getRecordKey(recordData, entityName) {
342
+ if (recordData.primaryKey) {
343
+ const keys = Object.entries(recordData.primaryKey)
344
+ .sort(([a], [b]) => a.localeCompare(b))
345
+ .map(([k, v]) => `${k}:${v}`)
346
+ .join('|');
347
+ return `${entityName}|${keys}`;
348
+ }
349
+ // Generate a key from fields if no primary key
350
+ const fieldKeys = Object.keys(recordData.fields).sort().join(',');
351
+ return `${entityName}|fields:${fieldKeys}`;
352
+ }
353
+ findEntityDirectories(baseDir, specificDir) {
354
+ const dirs = [];
355
+ if (specificDir) {
356
+ // Process specific directory
357
+ const fullPath = path_1.default.resolve(baseDir, specificDir);
358
+ if (fs_extra_1.default.existsSync(fullPath) && fs_extra_1.default.statSync(fullPath).isDirectory()) {
359
+ dirs.push(fullPath);
360
+ }
361
+ }
362
+ else {
363
+ // Find all entity directories
364
+ const searchDirs = (dir) => {
365
+ const entries = fs_extra_1.default.readdirSync(dir, { withFileTypes: true });
366
+ for (const entry of entries) {
367
+ if (entry.isDirectory() && !entry.name.startsWith('.') && entry.name !== 'node_modules') {
368
+ const fullPath = path_1.default.join(dir, entry.name);
369
+ const configPath = path_1.default.join(fullPath, '.mj-sync.json');
370
+ if (fs_extra_1.default.existsSync(configPath)) {
371
+ try {
372
+ const config = fs_extra_1.default.readJsonSync(configPath);
373
+ if (config.entity) {
374
+ dirs.push(fullPath);
375
+ }
376
+ }
377
+ catch {
378
+ // Skip invalid config files
379
+ }
380
+ }
381
+ else {
382
+ // Recurse into subdirectories
383
+ searchDirs(fullPath);
384
+ }
385
+ }
386
+ }
387
+ };
388
+ searchDirs(baseDir);
389
+ }
390
+ return dirs;
391
+ }
392
+ }
393
+ exports.PushService = PushService;
394
+ //# sourceMappingURL=PushService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PushService.js","sourceRoot":"","sources":["../../src/services/PushService.ts"],"names":[],"mappings":";;;;;;AAAA,wDAA0B;AAC1B,gDAAwB;AACxB,0DAAiC;AACjC,+CAA+F;AAE/F,sCAA6D;AAC7D,oEAA+D;AAC/D,0DAAsD;AACtD,kDAA8C;AAC9C,oEAAgE;AAkChE,MAAa,WAAW;IACd,UAAU,CAAa;IACvB,WAAW,CAAW;IACtB,QAAQ,GAAa,EAAE,CAAC;IACxB,gBAAgB,GAAgF,IAAI,GAAG,EAAE,CAAC;IAC1G,UAAU,CAAM;IAExB,YAAY,UAAsB,EAAE,WAAqB;QACvD,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,OAAoB,EAAE,SAAyB;QACxD,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QACnB,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC;QAE9B,MAAM,iBAAiB,GAAG,IAAI,uCAAiB,EAAE,CAAC;QAElD,8EAA8E;QAC9E,IAAI,CAAC,UAAU,GAAG,MAAM,IAAA,uBAAc,EAAC,8BAAa,CAAC,cAAc,EAAE,CAAC,CAAC;QACvE,MAAM,SAAS,GAAG,IAAI,sBAAS,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACjD,MAAM,kBAAkB,GAAG,IAAI,wCAAkB,CAAC,SAAS,CAAC,CAAC;QAE7D,IAAI,CAAC;YACH,mCAAmC;YACnC,IAAI,SAAS,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;gBACzC,MAAM,SAAS,CAAC,UAAU,EAAE,CAAC;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AAC;YACtB,CAAC;QACH,CAAC;aAAM,CAAC;YACN,8BAA8B;YAC9B,MAAM,UAAU,GAAG,CAAC,GAAW,EAAE,EAAE;gBACjC,MAAM,OAAO,GAAG,kBAAE,CAAC,WAAW,CAAC,GAAG,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;gBAE7D,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;oBAC5B,IAAI,KAAK,CAAC,WAAW,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,cAAc,EAAE,CAAC;wBACxF,MAAM,QAAQ,GAAG,cAAI,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;wBAC5C,MAAM,UAAU,GAAG,cAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;wBAExD,IAAI,kBAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;4BAC9B,IAAI,CAAC;gCACH,MAAM,MAAM,GAAG,kBAAE,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;gCAC3C,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;oCAClB,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gCACtB,CAAC;4BACH,CAAC;4BAAC,MAAM,CAAC;gCACP,4BAA4B;4BAC9B,CAAC;wBACH,CAAC;6BAAM,CAAC;4BACN,8BAA8B;4BAC9B,UAAU,CAAC,QAAQ,CAAC,CAAC;wBACvB,CAAC;oBACH,CAAC;gBACH,CAAC;YACH,CAAC,CAAC;YAEF,UAAU,CAAC,OAAO,CAAC,CAAC;QACtB,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAtdD,kCAsdC","sourcesContent":["import fs from 'fs-extra';\nimport path from 'path';\nimport fastGlob from 'fast-glob';\nimport { BaseEntity, LogStatus, Metadata, UserInfo, CompositeKey } from '@memberjunction/core';\nimport { SyncEngine, RecordData } from '../lib/sync-engine';\nimport { loadEntityConfig, loadSyncConfig } from '../config';\nimport { FileBackupManager } from '../lib/file-backup-manager';\nimport { configManager } from '../lib/config-manager';\nimport { SQLLogger } from '../lib/sql-logger';\nimport { TransactionManager } from '../lib/transaction-manager';\n\nexport interface PushOptions {\n dir?: string;\n dryRun?: boolean;\n verbose?: boolean;\n noValidate?: boolean;\n}\n\nexport interface PushCallbacks {\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 onConfirm?: (message: string) => Promise<boolean>;\n}\n\nexport interface PushResult {\n created: number;\n updated: number;\n unchanged: number;\n errors: number;\n warnings: string[];\n sqlLogPath?: string;\n}\n\nexport interface EntityPushResult {\n created: number;\n updated: number;\n unchanged: number;\n errors: number;\n}\n\nexport class PushService {\n private syncEngine: SyncEngine;\n private contextUser: UserInfo;\n private warnings: string[] = [];\n private processedRecords: Map<string, { filePath: string; arrayIndex?: number; lineNumber?: number }> = new Map();\n private syncConfig: any;\n \n constructor(syncEngine: SyncEngine, contextUser: UserInfo) {\n this.syncEngine = syncEngine;\n this.contextUser = contextUser;\n }\n \n async push(options: PushOptions, callbacks?: PushCallbacks): Promise<PushResult> {\n this.warnings = [];\n this.processedRecords.clear();\n \n const fileBackupManager = new FileBackupManager();\n \n // Load sync config for SQL logging settings and autoCreateMissingRecords flag\n this.syncConfig = await loadSyncConfig(configManager.getOriginalCwd());\n const sqlLogger = new SQLLogger(this.syncConfig);\n const transactionManager = new TransactionManager(sqlLogger);\n \n try {\n // Initialize SQL logger if enabled\n if (sqlLogger.enabled && !options.dryRun) {\n await sqlLogger.initialize();\n if (options.verbose) {\n callbacks?.onLog?.('šŸ“ SQL logging enabled');\n }\n }\n \n // Find entity directories to process\n const entityDirs = this.findEntityDirectories(configManager.getOriginalCwd(), options.dir);\n \n if (entityDirs.length === 0) {\n throw new Error('No entity directories found');\n }\n \n if (options.verbose) {\n callbacks?.onLog?.(`Found ${entityDirs.length} entity ${entityDirs.length === 1 ? 'directory' : 'directories'} to process`);\n }\n \n // Initialize file backup manager (unless in dry-run mode)\n if (!options.dryRun) {\n await fileBackupManager.initialize();\n if (options.verbose) {\n callbacks?.onLog?.('šŸ“ File backup manager initialized');\n }\n }\n \n // Process each entity directory\n let totalCreated = 0;\n let totalUpdated = 0;\n let totalUnchanged = 0;\n let totalErrors = 0;\n \n // Begin transaction if not in dry-run mode\n if (!options.dryRun) {\n await transactionManager.beginTransaction();\n }\n \n try {\n for (const entityDir of entityDirs) {\n const entityConfig = await loadEntityConfig(entityDir);\n if (!entityConfig) {\n const warning = `Skipping ${entityDir} - no valid entity configuration`;\n this.warnings.push(warning);\n callbacks?.onWarn?.(warning);\n continue;\n }\n \n if (options.verbose) {\n callbacks?.onLog?.(`\\nProcessing ${entityConfig.entity} in ${entityDir}`);\n }\n \n const result = await this.processEntityDirectory(\n entityDir,\n entityConfig,\n options,\n fileBackupManager,\n callbacks,\n sqlLogger\n );\n \n // Show per-directory summary\n const dirName = path.relative(process.cwd(), entityDir) || '.';\n const dirTotal = result.created + result.updated + result.unchanged;\n if (dirTotal > 0 || result.errors > 0) {\n callbacks?.onLog?.(`\\nšŸ“ ${dirName}:`);\n callbacks?.onLog?.(` Total processed: ${dirTotal} unique records`);\n if (result.created > 0) {\n callbacks?.onLog?.(` āœ“ Created: ${result.created}`);\n }\n if (result.updated > 0) {\n callbacks?.onLog?.(` āœ“ Updated: ${result.updated}`);\n }\n if (result.unchanged > 0) {\n callbacks?.onLog?.(` - Unchanged: ${result.unchanged}`);\n }\n if (result.errors > 0) {\n callbacks?.onLog?.(` āœ— Errors: ${result.errors}`);\n }\n }\n \n totalCreated += result.created;\n totalUpdated += result.updated;\n totalUnchanged += result.unchanged;\n totalErrors += result.errors;\n }\n \n // Commit transaction if successful\n if (!options.dryRun && totalErrors === 0) {\n await transactionManager.commitTransaction();\n }\n } catch (error) {\n // Rollback transaction on error\n if (!options.dryRun) {\n await transactionManager.rollbackTransaction();\n }\n throw error;\n }\n \n // Commit file backups if successful and not in dry-run mode\n if (!options.dryRun && totalErrors === 0) {\n await fileBackupManager.cleanup();\n if (options.verbose) {\n callbacks?.onLog?.('āœ… File backups committed');\n }\n }\n \n // Write SQL log if enabled\n let sqlLogPath: string | undefined;\n if (sqlLogger.enabled && !options.dryRun) {\n sqlLogPath = await sqlLogger.writeLog();\n if (sqlLogPath && options.verbose) {\n callbacks?.onLog?.(`šŸ“ SQL log written to: ${sqlLogPath}`);\n }\n }\n \n return {\n created: totalCreated,\n updated: totalUpdated,\n unchanged: totalUnchanged,\n errors: totalErrors,\n warnings: this.warnings,\n sqlLogPath\n };\n \n } catch (error) {\n // Rollback file backups on error\n if (!options.dryRun) {\n try {\n await fileBackupManager.rollback();\n callbacks?.onWarn?.('File backups rolled back due to error');\n } catch (rollbackError) {\n callbacks?.onWarn?.(`Failed to rollback file backups: ${rollbackError}`);\n }\n }\n throw error;\n }\n }\n \n private async processEntityDirectory(\n entityDir: string,\n entityConfig: any,\n options: PushOptions,\n fileBackupManager: FileBackupManager,\n callbacks?: PushCallbacks,\n sqlLogger?: SQLLogger\n ): Promise<EntityPushResult> {\n let created = 0;\n let updated = 0;\n let unchanged = 0;\n let errors = 0;\n \n // Find all JSON files in the directory\n const pattern = entityConfig.filePattern || '*.json';\n const files = await fastGlob(pattern, {\n cwd: entityDir,\n absolute: true,\n onlyFiles: true,\n ignore: ['**/node_modules/**', '**/.mj-*.json']\n });\n \n if (options.verbose) {\n callbacks?.onLog?.(`Found ${files.length} files to process`);\n }\n \n // Process each file\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 (let i = 0; i < records.length; i++) {\n const recordData = records[i];\n \n if (!this.isValidRecordData(recordData)) {\n callbacks?.onWarn?.(`Invalid record format in ${filePath}${Array.isArray(fileData) ? ` at index ${i}` : ''}`);\n errors++;\n continue;\n }\n \n try {\n const result = await this.processRecord(\n recordData,\n entityConfig,\n entityDir,\n options,\n callbacks\n );\n \n if (result === 'created') created++;\n else if (result === 'updated') updated++;\n else if (result === 'unchanged') unchanged++;\n \n // Track processed record\n const recordKey = this.getRecordKey(recordData, entityConfig.entity);\n this.processedRecords.set(recordKey, {\n filePath,\n arrayIndex: Array.isArray(fileData) ? i : undefined,\n lineNumber: i + 1 // Simple line number approximation\n });\n \n } catch (recordError) {\n const errorMsg = `Error processing record in ${filePath}${Array.isArray(fileData) ? ` at index ${i}` : ''}: ${recordError}`;\n callbacks?.onError?.(errorMsg);\n errors++;\n }\n }\n } catch (fileError) {\n const errorMsg = `Error reading file ${filePath}: ${fileError}`;\n callbacks?.onError?.(errorMsg);\n errors++;\n }\n }\n \n return { created, updated, unchanged, errors };\n }\n \n private async processRecord(\n recordData: RecordData,\n entityConfig: any,\n entityDir: string,\n options: PushOptions,\n callbacks?: PushCallbacks\n ): Promise<'created' | 'updated' | 'unchanged' | 'error'> {\n const metadata = new Metadata();\n const entityInfo = metadata.EntityByName(entityConfig.entity);\n \n if (!entityInfo) {\n throw new Error(`Entity ${entityConfig.entity} not found in metadata`);\n }\n \n // Get or create entity instance\n let entity = await metadata.GetEntityObject(entityConfig.entity, this.contextUser);\n if (!entity) {\n throw new Error(`Failed to create entity object for ${entityConfig.entity}`);\n }\n \n // Apply defaults from configuration\n const defaults = { ...entityConfig.defaults };\n \n // Build full record data\n const fullData = {\n ...defaults,\n ...recordData.fields\n };\n \n // Process field values\n const processedData: Record<string, any> = {};\n for (const [fieldName, fieldValue] of Object.entries(fullData)) {\n const processedValue = await this.syncEngine.processFieldValue(\n fieldValue,\n entityDir,\n null, // parentRecord\n null // rootRecord\n );\n processedData[fieldName] = processedValue;\n }\n \n // Check if record exists\n const primaryKey = recordData.primaryKey;\n let exists = false;\n let existingEntity: BaseEntity | null = null;\n \n if (primaryKey && Object.keys(primaryKey).length > 0) {\n // Try to load existing record\n const compositeKey = new CompositeKey();\n compositeKey.LoadFromSimpleObject(primaryKey);\n existingEntity = await metadata.GetEntityObject(entityConfig.entity, this.contextUser);\n if (existingEntity) {\n exists = await existingEntity.InnerLoad(compositeKey);\n \n // Check autoCreateMissingRecords flag if record not found\n if (!exists) {\n const autoCreate = this.syncConfig?.push?.autoCreateMissingRecords ?? false;\n const pkDisplay = Object.entries(primaryKey)\n .map(([key, value]) => `${key}=${value}`)\n .join(', ');\n \n if (!autoCreate) {\n const warning = `Record not found: ${entityConfig.entity} with primaryKey {${pkDisplay}}. To auto-create missing records, set push.autoCreateMissingRecords=true in .mj-sync.json`;\n this.warnings.push(warning);\n callbacks?.onWarn?.(warning);\n return 'error';\n } else if (options.verbose) {\n callbacks?.onLog?.(`Auto-creating missing ${entityConfig.entity} record with primaryKey {${pkDisplay}}`);\n }\n }\n }\n }\n \n if (options.dryRun) {\n if (exists) {\n callbacks?.onLog?.(`[DRY RUN] Would update ${entityConfig.entity} record`);\n return 'updated';\n } else {\n callbacks?.onLog?.(`[DRY RUN] Would create ${entityConfig.entity} record`);\n return 'created';\n }\n }\n \n // Use existing entity if found, otherwise create new one\n if (!exists) {\n entity = existingEntity || entity;\n entity.NewRecord();\n \n // Set primary key values for new records if provided\n if (primaryKey) {\n for (const [pkField, pkValue] of Object.entries(primaryKey)) {\n entity.Set(pkField, pkValue);\n }\n }\n }\n \n // Set field values\n for (const [fieldName, fieldValue] of Object.entries(processedData)) {\n entity.Set(fieldName, fieldValue);\n }\n \n // Handle related entities\n if (recordData.relatedEntities) {\n // Store related entities to process after parent save\n (entity as any).__pendingRelatedEntities = recordData.relatedEntities;\n }\n \n // Save the record\n // TODO: Hook into BaseEntity SQL execution for SQL logging\n // Currently SQL logging requires deeper integration with MJ core\n const saveResult = await entity.Save();\n \n if (!saveResult) {\n throw new Error(`Failed to save ${entityConfig.entity} record: ${entity.LatestResult?.Message || 'Unknown error'}`);\n }\n \n // Process related entities after parent save\n if (recordData.relatedEntities) {\n await this.processRelatedEntities(\n entity,\n recordData.relatedEntities,\n entityDir,\n options,\n callbacks\n );\n }\n \n return exists ? 'updated' : 'created';\n }\n \n private async processRelatedEntities(\n parentEntity: BaseEntity,\n relatedEntities: Record<string, RecordData[]>,\n entityDir: string,\n options: PushOptions,\n callbacks?: PushCallbacks\n ): Promise<void> {\n // TODO: Complete implementation for processing related entities\n // This is a simplified version - full implementation would:\n // 1. Create entity objects for each related entity type\n // 2. Apply field values with proper parent/root references\n // 3. Save related entities with proper error handling\n // 4. Support nested related entities recursively\n for (const [key, records] of Object.entries(relatedEntities)) {\n for (const relatedRecord of records) {\n // Process @parent references\n const processedFields: Record<string, any> = {};\n for (const [fieldName, fieldValue] of Object.entries(relatedRecord.fields)) {\n if (typeof fieldValue === 'string' && fieldValue.startsWith('@parent:')) {\n const parentField = fieldValue.substring(8);\n processedFields[fieldName] = parentEntity.Get(parentField);\n } else {\n processedFields[fieldName] = await this.syncEngine.processFieldValue(\n fieldValue,\n entityDir,\n parentEntity,\n null\n );\n }\n }\n \n // Save related entity (simplified - full implementation needed)\n relatedRecord.fields = processedFields;\n }\n }\n }\n \n private isValidRecordData(data: any): data is RecordData {\n return data && \n typeof data === 'object' && \n 'fields' in data &&\n typeof data.fields === 'object';\n }\n \n private getRecordKey(recordData: RecordData, entityName: string): string {\n if (recordData.primaryKey) {\n const keys = Object.entries(recordData.primaryKey)\n .sort(([a], [b]) => a.localeCompare(b))\n .map(([k, v]) => `${k}:${v}`)\n .join('|');\n return `${entityName}|${keys}`;\n }\n \n // Generate a key from fields if no primary key\n const fieldKeys = Object.keys(recordData.fields).sort().join(',');\n return `${entityName}|fields:${fieldKeys}`;\n }\n \n private findEntityDirectories(baseDir: string, specificDir?: string): string[] {\n const dirs: string[] = [];\n \n if (specificDir) {\n // Process specific directory\n const fullPath = path.resolve(baseDir, specificDir);\n if (fs.existsSync(fullPath) && fs.statSync(fullPath).isDirectory()) {\n dirs.push(fullPath);\n }\n } else {\n // Find all entity directories\n const searchDirs = (dir: string) => {\n const entries = fs.readdirSync(dir, { withFileTypes: true });\n \n for (const entry of entries) {\n if (entry.isDirectory() && !entry.name.startsWith('.') && entry.name !== 'node_modules') {\n const fullPath = path.join(dir, entry.name);\n const configPath = path.join(fullPath, '.mj-sync.json');\n \n if (fs.existsSync(configPath)) {\n try {\n const config = fs.readJsonSync(configPath);\n if (config.entity) {\n dirs.push(fullPath);\n }\n } catch {\n // Skip invalid config files\n }\n } else {\n // Recurse into subdirectories\n searchDirs(fullPath);\n }\n }\n }\n };\n \n searchDirs(baseDir);\n }\n \n return dirs;\n }\n}"]}