@memberjunction/metadata-sync 2.47.0 → 2.49.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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/push/index.ts"],"names":[],"mappings":";;;;;AAAA,sCAA6C;AAC7C,wDAA0B;AAC1B,gDAAwB;AAExB,8DAA8B;AAC9B,0DAAiC;AACjC,yCAA8E;AAC9E,uDAA+D;AAC/D,6DAAoG;AAEpG,6DAA2D;AAE3D,MAAqB,IAAK,SAAQ,cAAO;IACvC,MAAM,CAAC,WAAW,GAAG,yCAAyC,CAAC;IAE/D,MAAM,CAAC,QAAQ,GAAG;QAChB,qCAAqC;QACrC,+CAA+C;QAC/C,wDAAwD;QACxD,0CAA0C;KAC3C,CAAC;IAEF,MAAM,CAAC,KAAK,GAAG;QACb,GAAG,EAAE,YAAK,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,mCAAmC,EAAE,CAAC;QACvE,SAAS,EAAE,YAAK,CAAC,OAAO,CAAC,EAAE,WAAW,EAAE,oDAAoD,EAAE,CAAC;QAC/F,EAAE,EAAE,YAAK,CAAC,OAAO,CAAC,EAAE,WAAW,EAAE,sCAAsC,EAAE,CAAC;QAC1E,OAAO,EAAE,YAAK,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,WAAW,EAAE,kCAAkC,EAAE,CAAC;KACvF,CAAC;IAEF,KAAK,CAAC,GAAG;QACP,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACzC,MAAM,OAAO,GAAG,IAAA,qBAAG,GAAE,CAAC;QAEtB,IAAI,CAAC;YACH,sBAAsB;YACtB,OAAO,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;YACvC,MAAM,QAAQ,GAAG,IAAA,qBAAY,GAAE,CAAC;YAChC,IAAI,CAAC,QAAQ,EA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E,CAAC;gCACxC,aAAa,CAAC,UAAU,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;4BAC1D,CAAC;wBACH,CAAC;wBAED,8BAA8B;wBAC9B,aAAa,CAAC,IAAI,GAAG;4BACnB,YAAY,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;4BACtC,QAAQ,EAAE,UAAU,CAAC,iBAAiB,CAAC,aAAa,CAAC,MAAM,CAAC;yBAC7D,CAAC;oBACJ,CAAC;oBAED,yCAAyC;oBACzC,IAAI,aAAa,CAAC,eAAe,EAAE,CAAC;wBAClC,MAAM,IAAI,CAAC,sBAAsB,CAC/B,aAAa,CAAC,eAAe,EAC7B,MAAM,EACN,UAAU,EACV,OAAO,EACP,UAAU,EACV,OAAO,EACP,WAAW,GAAG,CAAC,CAChB,CAAC;oBACJ,CAAC;gBACH,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,MAAM,IAAI,KAAK,CAAC,6BAA6B,UAAU,KAAK,KAAK,EAAE,CAAC,CAAC;gBACvE,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;;AAvbH,uBAwbC","sourcesContent":["import { Command, Flags } from '@oclif/core';\nimport fs from 'fs-extra';\nimport path from 'path';\nimport { confirm } from '@inquirer/prompts';\nimport ora from 'ora-classic';\nimport fastGlob from 'fast-glob';\nimport { loadMJConfig, loadSyncConfig, loadEntityConfig } from '../../config';\nimport { SyncEngine, RecordData } from '../../lib/sync-engine';\nimport { initializeProvider, findEntityDirectories, getSystemUser } from '../../lib/provider-utils';\nimport { BaseEntity } from '@memberjunction/core';\nimport { cleanupProvider } from '../../lib/provider-utils';\n\nexport default class Push extends Command {\n static description = 'Push local file changes to the database';\n \n static examples = [\n `<%= config.bin %> <%= command.id %>`,\n `<%= config.bin %> <%= command.id %> --dry-run`,\n `<%= config.bin %> <%= command.id %> --dir=\"ai-prompts\"`,\n `<%= config.bin %> <%= command.id %> --ci`,\n ];\n \n static flags = {\n dir: Flags.string({ description: 'Specific entity directory to push' }),\n 'dry-run': Flags.boolean({ description: 'Show what would be pushed without actually pushing' }),\n ci: Flags.boolean({ description: 'CI mode - no prompts, fail on issues' }),\n verbose: Flags.boolean({ char: 'v', description: 'Show detailed field-level output' }),\n };\n \n async run(): Promise<void> {\n const { flags } = await this.parse(Push);\n const spinner = ora();\n \n try {\n // Load configurations\n spinner.start('Loading configuration');\n const mjConfig = loadMJConfig();\n if (!mjConfig) {\n this.error('No mj.config.cjs found in current directory or parent directories');\n }\n \n const syncConfig = await loadSyncConfig(process.cwd());\n \n // Initialize data provider\n await initializeProvider(mjConfig);\n \n // Initialize sync engine\n const syncEngine = new SyncEngine(getSystemUser());\n await syncEngine.initialize();\n spinner.succeed('Configuration loaded');\n \n // Find entity directories to process\n const entityDirs = findEntityDirectories(process.cwd(), flags.dir);\n \n if (entityDirs.length === 0) {\n this.error('No entity directories found');\n }\n \n this.log(`Found ${entityDirs.length} entity ${entityDirs.length === 1 ? 'directory' : 'directories'} to process`);\n \n // Process each entity directory\n let totalCreated = 0;\n let totalUpdated = 0;\n let totalErrors = 0;\n \n for (const entityDir of entityDirs) {\n const entityConfig = await loadEntityConfig(entityDir);\n if (!entityConfig) {\n this.warn(`Skipping ${entityDir} - no valid entity configuration`);\n continue;\n }\n \n this.log(`\\nProcessing ${entityConfig.entity} in ${entityDir}`);\n \n const result = await this.processEntityDirectory(\n entityDir,\n entityConfig,\n syncEngine,\n flags,\n syncConfig\n );\n \n totalCreated += result.created;\n totalUpdated += result.updated;\n totalErrors += result.errors;\n }\n \n // Summary\n this.log('\\n=== Push Summary ===');\n this.log(`Created: ${totalCreated}`);\n this.log(`Updated: ${totalUpdated}`);\n this.log(`Errors: ${totalErrors}`);\n \n if (totalErrors > 0 && flags.ci) {\n this.error('Push failed with errors in CI mode');\n }\n \n } catch (error) {\n spinner.fail('Push failed');\n this.error(error as Error);\n } finally {\n // Clean up database connection\n await cleanupProvider();\n }\n }\n \n private async processEntityDirectory(\n entityDir: string,\n entityConfig: any,\n syncEngine: SyncEngine,\n flags: any,\n syncConfig: any\n ): Promise<{ created: number; updated: number; errors: number }> {\n const result = { created: 0, updated: 0, errors: 0 };\n \n // Find JSON files in the current directory only (not subdirectories)\n const pattern = entityConfig.filePattern || '*.json';\n const jsonFiles = await fastGlob(pattern, {\n cwd: entityDir,\n ignore: ['.mj-sync.json', '.mj-folder.json'],\n dot: true // Include dotfiles (files starting with .)\n });\n \n this.log(`Processing ${jsonFiles.length} records in ${path.relative(process.cwd(), entityDir) || '.'}`);\n \n // First, process all JSON files in this directory\n await this.processJsonFiles(jsonFiles, entityDir, entityConfig, syncEngine, flags, result);\n \n // Then, recursively process subdirectories\n const entries = await fs.readdir(entityDir, { withFileTypes: true });\n for (const entry of entries) {\n if (entry.isDirectory() && !entry.name.startsWith('.')) {\n const subDir = path.join(entityDir, entry.name);\n \n // Load subdirectory config and merge with parent config\n let subEntityConfig = { ...entityConfig };\n const subDirConfig = await loadEntityConfig(subDir);\n \n if (subDirConfig) {\n // Check if this is a new entity type (has different entity name)\n if (subDirConfig.entity && subDirConfig.entity !== entityConfig.entity) {\n // This is a different entity type, skip it (will be processed separately)\n continue;\n }\n \n // Merge defaults: parent defaults + subdirectory overrides\n subEntityConfig = {\n ...entityConfig,\n ...subDirConfig,\n defaults: {\n ...entityConfig.defaults,\n ...(subDirConfig.defaults || {})\n }\n };\n }\n \n // Process subdirectory with merged config\n const subResult = await this.processEntityDirectory(\n subDir,\n subEntityConfig,\n syncEngine,\n flags,\n syncConfig\n );\n \n result.created += subResult.created;\n result.updated += subResult.updated;\n result.errors += subResult.errors;\n }\n }\n \n return result;\n }\n \n private async processJsonFiles(\n jsonFiles: string[],\n entityDir: string,\n entityConfig: any,\n syncEngine: SyncEngine,\n flags: any,\n result: { created: number; updated: number; errors: number }\n ): Promise<void> {\n if (jsonFiles.length === 0) {\n return;\n }\n \n const spinner = ora();\n spinner.start('Processing records');\n \n let totalRecords = 0;\n \n for (const file of jsonFiles) {\n try {\n const filePath = path.join(entityDir, file);\n const fileContent = await fs.readJson(filePath);\n \n // Process templates in the loaded content\n const processedContent = await syncEngine.processTemplates(fileContent, entityDir);\n \n // Check if the file contains a single record or an array of records\n const isArray = Array.isArray(processedContent);\n const records: RecordData[] = isArray ? processedContent : [processedContent];\n totalRecords += records.length;\n \n // Build and process defaults (including lookups)\n const defaults = await syncEngine.buildDefaults(filePath, entityConfig);\n \n // Process each record in the file\n for (let i = 0; i < records.length; i++) {\n const recordData = records[i];\n \n // Process the record\n const isNew = await this.pushRecord(\n recordData,\n entityConfig.entity,\n path.dirname(filePath),\n file,\n defaults,\n syncEngine,\n flags['dry-run'],\n flags.verbose,\n isArray ? i : undefined\n );\n \n if (!flags['dry-run']) {\n if (isNew) {\n result.created++;\n } else {\n result.updated++;\n }\n }\n \n spinner.text = `Processing records (${result.created + result.updated + result.errors}/${totalRecords})`;\n }\n \n // Write back the entire file if it's an array\n if (isArray && !flags['dry-run']) {\n await fs.writeJson(filePath, records, { spaces: 2 });\n }\n \n } catch (error) {\n result.errors++;\n const errorMessage = error instanceof Error ? error.message : String(error);\n this.error(`Failed to process ${file}: ${errorMessage}`, { exit: false });\n }\n }\n \n spinner.succeed(`Processed ${totalRecords} records from ${jsonFiles.length} files`);\n }\n \n private async pushRecord(\n recordData: RecordData,\n entityName: string,\n baseDir: string,\n fileName: string,\n defaults: Record<string, any>,\n syncEngine: SyncEngine,\n dryRun: boolean,\n verbose: boolean = false,\n arrayIndex?: number\n ): Promise<boolean> {\n // Load or create entity\n let entity: BaseEntity | null = null;\n let isNew = false;\n \n if (recordData.primaryKey) {\n entity = await syncEngine.loadEntity(entityName, recordData.primaryKey);\n }\n \n if (!entity) {\n // New record\n entity = await syncEngine.createEntityObject(entityName);\n entity.NewRecord();\n isNew = true;\n }\n \n // Apply defaults first\n for (const [field, value] of Object.entries(defaults)) {\n if (field in entity) {\n (entity as any)[field] = value;\n }\n }\n \n // Apply record fields\n for (const [field, value] of Object.entries(recordData.fields)) {\n if (field in entity) {\n try {\n const processedValue = await syncEngine.processFieldValue(value, baseDir, null, null);\n if (verbose) {\n this.log(` Setting ${field}: ${JSON.stringify(value)} -> ${JSON.stringify(processedValue)}`);\n }\n (entity as any)[field] = processedValue;\n } catch (error) {\n throw new Error(`Failed to process field '${field}': ${error}`);\n }\n } else {\n this.warn(`Field '${field}' does not exist on entity '${entityName}'`);\n }\n }\n \n if (dryRun) {\n this.log(`Would ${isNew ? 'create' : 'update'} ${entityName} record`);\n return isNew;\n }\n \n // Save the record\n const saved = await entity.Save();\n if (!saved) {\n const errors = entity.LatestResult?.Errors?.join(', ') || 'Unknown error';\n throw new Error(`Failed to save record: ${errors}`);\n }\n \n // Process related entities after saving parent\n if (recordData.relatedEntities && !dryRun) {\n await this.processRelatedEntities(\n recordData.relatedEntities,\n entity,\n entity, // root is same as parent for top level\n baseDir,\n syncEngine,\n verbose\n );\n }\n \n // Update the local file with new primary key if created\n if (isNew) {\n const entityInfo = syncEngine.getEntityInfo(entityName);\n if (entityInfo) {\n const newPrimaryKey: Record<string, any> = {};\n for (const pk of entityInfo.PrimaryKeys) {\n newPrimaryKey[pk.Name] = entity.Get(pk.Name);\n }\n recordData.primaryKey = newPrimaryKey;\n }\n }\n \n // Always update sync metadata\n // This ensures related entities are persisted with their metadata\n recordData.sync = {\n lastModified: new Date().toISOString(),\n checksum: syncEngine.calculateChecksum(recordData.fields)\n };\n \n // Write back to file only if it's a single record (not part of an array)\n // Array records are written back in bulk after all records are processed\n if (arrayIndex === undefined) {\n const filePath = path.join(baseDir, fileName);\n await fs.writeJson(filePath, recordData, { spaces: 2 });\n }\n \n return isNew;\n }\n \n private async processRelatedEntities(\n relatedEntities: Record<string, RecordData[]>,\n parentEntity: BaseEntity,\n rootEntity: BaseEntity,\n baseDir: string,\n syncEngine: SyncEngine,\n verbose: boolean = false,\n indentLevel: number = 1\n ): Promise<void> {\n const indent = ' '.repeat(indentLevel);\n \n for (const [entityName, records] of Object.entries(relatedEntities)) {\n this.log(`${indent}↳ Processing ${records.length} related ${entityName} records`);\n \n for (const relatedRecord of records) {\n try {\n // Load or create entity\n let entity = null;\n let isNew = false;\n \n if (relatedRecord.primaryKey) {\n entity = await syncEngine.loadEntity(entityName, relatedRecord.primaryKey);\n }\n \n if (!entity) {\n entity = await syncEngine.createEntityObject(entityName);\n entity.NewRecord();\n isNew = true;\n }\n \n // Apply fields with parent/root context\n for (const [field, value] of Object.entries(relatedRecord.fields)) {\n if (field in entity) {\n try {\n const processedValue = await syncEngine.processFieldValue(\n value, \n baseDir, \n parentEntity, \n rootEntity\n );\n if (verbose) {\n this.log(`${indent} Setting ${field}: ${JSON.stringify(value)} -> ${JSON.stringify(processedValue)}`);\n }\n (entity as any)[field] = processedValue;\n } catch (error) {\n throw new Error(`Failed to process field '${field}' in ${entityName}: ${error}`);\n }\n } else {\n this.warn(`${indent} Field '${field}' does not exist on entity '${entityName}'`);\n }\n }\n \n // Save the related entity\n const saved = await entity.Save();\n if (!saved) {\n const errors = entity.LatestResult?.Errors?.join(', ') || 'Unknown error';\n throw new Error(`Failed to save related ${entityName}: ${errors}`);\n }\n \n if (verbose) {\n this.log(`${indent} ✓ ${isNew ? 'Created' : 'Updated'} ${entityName} record`);\n }\n \n // Update the related record with primary key and sync metadata\n const entityInfo = syncEngine.getEntityInfo(entityName);\n if (entityInfo) {\n // Update primary key if new\n if (isNew) {\n relatedRecord.primaryKey = {};\n for (const pk of entityInfo.PrimaryKeys) {\n relatedRecord.primaryKey[pk.Name] = entity.Get(pk.Name);\n }\n }\n \n // Always update sync metadata\n relatedRecord.sync = {\n lastModified: new Date().toISOString(),\n checksum: syncEngine.calculateChecksum(relatedRecord.fields)\n };\n }\n \n // Process nested related entities if any\n if (relatedRecord.relatedEntities) {\n await this.processRelatedEntities(\n relatedRecord.relatedEntities,\n entity,\n rootEntity,\n baseDir,\n syncEngine,\n verbose,\n indentLevel + 1\n );\n }\n } catch (error) {\n throw new Error(`Failed to process related ${entityName}: ${error}`);\n }\n }\n }\n }\n}"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/push/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sCAA6C;AAC7C,wDAA0B;AAC1B,gDAAwB;AAExB,8DAA8B;AAC9B,0DAAiC;AACjC,yCAA8E;AAE9E,6DAAoG;AAEpG,6DAA2D;AAC3D,6DAAyD;AACzD,mEAA6E;AAE7E,mDAAgD;AAEhD,MAAqB,IAAK,SAAQ,cAAO;IACvC,MAAM,CAAC,WAAW,GAAG,yCAAyC,CAAC;IAE/D,MAAM,CAAC,QAAQ,GAAG;QAChB,qCAAqC;QACrC,+CAA+C;QAC/C,wDAAwD;QACxD,0CAA0C;KAC3C,CAAC;IAEF,MAAM,CAAC,KAAK,GAAG;QACb,GAAG,EAAE,YAAK,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,mCAAmC,EAAE,CAAC;QACvE,SAAS,EAAE,YAAK,CAAC,OAAO,CAAC,EAAE,WAAW,EAAE,oDAAoD,EAAE,CAAC;QAC/F,EAAE,EAAE,YAAK,CAAC,OAAO,CAAC,EAAE,WAAW,EAAE,sCAAsC,EAAE,CAAC;QAC1E,OAAO,EAAE,YAAK,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,WAAW,EAAE,kCAAkC,EAAE,CAAC;KACvF,CAAC;IAEF,KAAK,CAAC,GAAG;QACP,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACzC,MAAM,OAAO,GAAG,IAAA,qBAAG,GAAE,CAAC;QACtB,IAAI,SAAS,GAA6B,IAAI,CAAC;QAE/C,IAAI,CAAC;YACH,sBAAsB;YACtB,OAAO,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;YACvC,MAAM,QAAQ,GAAG,IAAA,qBAAY,GAAE,CAAC;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BAAiB,CAAC,aAAa,CAAC,MAAM,CAAC;yBAC7D,CAAC;oBACJ,CAAC;oBAED,yCAAyC;oBACzC,IAAI,aAAa,CAAC,eAAe,EAAE,CAAC;wBAClC,MAAM,IAAI,CAAC,sBAAsB,CAC/B,aAAa,CAAC,eAAe,EAC7B,MAAM,EACN,UAAU,EACV,OAAO,EACP,UAAU,EACV,OAAO,EACP,WAAW,GAAG,CAAC,CAChB,CAAC;oBACJ,CAAC;gBACH,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,MAAM,IAAI,KAAK,CAAC,6BAA6B,UAAU,KAAK,KAAK,EAAE,CAAC,CAAC;gBACvE,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;;AA1lBH,uBA2lBC","sourcesContent":["import { Command, Flags } from '@oclif/core';\nimport fs from 'fs-extra';\nimport path from 'path';\nimport { confirm } from '@inquirer/prompts';\nimport ora from 'ora-classic';\nimport fastGlob from 'fast-glob';\nimport { loadMJConfig, loadSyncConfig, loadEntityConfig } from '../../config';\nimport { SyncEngine, RecordData } from '../../lib/sync-engine';\nimport { initializeProvider, findEntityDirectories, getSystemUser } from '../../lib/provider-utils';\nimport { BaseEntity } from '@memberjunction/core';\nimport { cleanupProvider } from '../../lib/provider-utils';\nimport { configManager } from '../../lib/config-manager';\nimport { getSyncEngine, resetSyncEngine } from '../../lib/singleton-manager';\nimport type { SqlLoggingSession } from '@memberjunction/sqlserver-dataprovider';\nimport { uuidv4 } from '@memberjunction/global';\n\nexport default class Push extends Command {\n static description = 'Push local file changes to the database';\n \n static examples = [\n `<%= config.bin %> <%= command.id %>`,\n `<%= config.bin %> <%= command.id %> --dry-run`,\n `<%= config.bin %> <%= command.id %> --dir=\"ai-prompts\"`,\n `<%= config.bin %> <%= command.id %> --ci`,\n ];\n \n static flags = {\n dir: Flags.string({ description: 'Specific entity directory to push' }),\n 'dry-run': Flags.boolean({ description: 'Show what would be pushed without actually pushing' }),\n ci: Flags.boolean({ description: 'CI mode - no prompts, fail on issues' }),\n verbose: Flags.boolean({ char: 'v', description: 'Show detailed field-level output' }),\n };\n \n async run(): Promise<void> {\n const { flags } = await this.parse(Push);\n const spinner = ora();\n let sqlLogger: SqlLoggingSession | null = null;\n \n try {\n // Load configurations\n spinner.start('Loading configuration');\n const mjConfig = loadMJConfig();\n if (!mjConfig) {\n this.error('No mj.config.cjs found in current directory or parent directories');\n }\n \n // Load sync config from target directory if --dir is specified, otherwise from current directory\n const syncConfigDir = flags.dir ? path.resolve(configManager.getOriginalCwd(), flags.dir) : configManager.getOriginalCwd();\n const syncConfig = await loadSyncConfig(syncConfigDir);\n \n // Stop spinner before provider initialization (which logs to console)\n spinner.stop();\n \n // Initialize data provider\n await initializeProvider(mjConfig);\n \n // Initialize sync engine using singleton pattern\n const syncEngine = await getSyncEngine(getSystemUser());\n \n // Show success after all initialization is complete\n spinner.succeed('Configuration and metadata loaded');\n \n // Initialize SQL logging AFTER provider setup is complete\n if (syncConfig?.sqlLogging?.enabled) {\n const outputDir = syncConfig.sqlLogging.outputDirectory || './sql_logging';\n const formatAsMigration = syncConfig.sqlLogging.formatAsMigration || false;\n \n // Ensure output directory exists\n const fullOutputDir = path.resolve(outputDir);\n await fs.ensureDir(fullOutputDir);\n \n // Generate filename with timestamp and directory name\n const now = new Date();\n const humanReadableTimestamp = now.toISOString()\n .replace('T', '_')\n .replace(/:/g, '-')\n .slice(0, -5); // Remove milliseconds and Z\n \n // Get directory name for filename\n const targetDir = flags.dir ? path.resolve(configManager.getOriginalCwd(), flags.dir) : configManager.getOriginalCwd();\n const dirName = path.basename(targetDir);\n \n const filename = formatAsMigration \n ? `V${now.toISOString().replace(/[:.T-]/g, '').slice(0, -5)}__MetadataSync_Push.sql`\n : `metadata-sync-push_${dirName}_${humanReadableTimestamp}.sql`;\n const logFilePath = path.join(fullOutputDir, filename);\n \n // Import and access the data provider from the provider utils\n const { getDataProvider } = await import('../../lib/provider-utils');\n const dataProvider = getDataProvider();\n \n if (dataProvider && typeof dataProvider.createSqlLogger === 'function') {\n sqlLogger = await dataProvider.createSqlLogger(logFilePath, {\n formatAsMigration,\n description: 'MetadataSync Push Operation',\n statementTypes: 'mutations', // Only log mutations (data changes)\n batchSeparator: 'GO', // Add GO statements for SQL Server batch processing\n prettyPrint: true // Enable pretty printing for readable output\n });\n \n this.log(`📝 SQL logging enabled: ${path.relative(process.cwd(), logFilePath)}`);\n } else {\n this.warn('SQL logging requested but data provider does not support createSqlLogger');\n }\n }\n \n // Find entity directories to process\n const entityDirs = findEntityDirectories(configManager.getOriginalCwd(), flags.dir, syncConfig?.directoryOrder);\n \n if (entityDirs.length === 0) {\n this.error('No entity directories found');\n }\n \n this.log(`Found ${entityDirs.length} entity ${entityDirs.length === 1 ? 'directory' : 'directories'} to process`);\n \n // Process each entity directory\n let totalCreated = 0;\n let totalUpdated = 0;\n let totalErrors = 0;\n \n for (const entityDir of entityDirs) {\n const entityConfig = await loadEntityConfig(entityDir);\n if (!entityConfig) {\n this.warn(`Skipping ${entityDir} - no valid entity configuration`);\n continue;\n }\n \n this.log(`\\nProcessing ${entityConfig.entity} in ${entityDir}`);\n \n const result = await this.processEntityDirectory(\n entityDir,\n entityConfig,\n syncEngine,\n flags,\n syncConfig\n );\n \n totalCreated += result.created;\n totalUpdated += result.updated;\n totalErrors += result.errors;\n }\n \n // Summary\n this.log('\\n=== Push Summary ===');\n this.log(`Created: ${totalCreated}`);\n this.log(`Updated: ${totalUpdated}`);\n this.log(`Errors: ${totalErrors}`);\n \n if (totalErrors > 0 && flags.ci) {\n this.error('Push failed with errors in CI mode');\n }\n \n } catch (error) {\n spinner.fail('Push failed');\n \n // Enhanced error logging for debugging\n this.log('\\n=== Push Error Details ===');\n this.log(`Error type: ${error?.constructor?.name || 'Unknown'}`);\n this.log(`Error message: ${error instanceof Error ? error.message : String(error)}`);\n \n if (error instanceof Error && error.stack) {\n this.log(`\\nStack trace:`);\n this.log(error.stack);\n }\n \n // Log context information\n this.log(`\\nContext:`);\n this.log(`- Working directory: ${configManager.getOriginalCwd()}`);\n this.log(`- Flags: ${JSON.stringify(flags, null, 2)}`);\n \n // Check if error is related to common issues\n const errorMessage = error instanceof Error ? error.message : String(error);\n if (errorMessage.includes('entity directories')) {\n this.log(`\\nHint: This appears to be an entity directory configuration issue.`);\n this.log(`Make sure each entity directory has a .mj-sync.json file.`);\n } else if (errorMessage.includes('database') || errorMessage.includes('connection')) {\n this.log(`\\nHint: This appears to be a database connectivity issue.`);\n this.log(`Check your mj.config.cjs configuration and database connectivity.`);\n } else if (errorMessage.includes('config') || errorMessage.includes('mj.config.cjs')) {\n this.log(`\\nHint: This appears to be a configuration file issue.`);\n this.log(`Make sure mj.config.cjs exists and is properly configured.`);\n }\n \n this.error(error as Error);\n } finally {\n // Dispose SQL logging session if active\n if (sqlLogger) {\n try {\n await sqlLogger.dispose();\n this.log('✅ SQL logging session closed');\n } catch (error) {\n this.warn(`Failed to close SQL logging session: ${error}`);\n }\n }\n \n // Reset sync engine singleton\n resetSyncEngine();\n // Clean up database connection\n await cleanupProvider();\n \n // Exit process to prevent background MJ tasks from throwing errors\n process.exit(0);\n }\n }\n \n private async processEntityDirectory(\n entityDir: string,\n entityConfig: any,\n syncEngine: SyncEngine,\n flags: any,\n syncConfig: any\n ): Promise<{ created: number; updated: number; errors: number }> {\n const result = { created: 0, updated: 0, errors: 0 };\n \n // Find files matching the configured pattern\n const pattern = entityConfig.filePattern || '*.json';\n const jsonFiles = await fastGlob(pattern, {\n cwd: entityDir,\n ignore: ['.mj-sync.json', '.mj-folder.json', '**/*.backup'],\n dot: true, // Include dotfiles (files starting with .)\n onlyFiles: true\n });\n \n this.log(`Processing ${jsonFiles.length} records in ${path.relative(process.cwd(), entityDir) || '.'}`);\n \n // First, process all JSON files in this directory\n await this.processJsonFiles(jsonFiles, entityDir, entityConfig, syncEngine, flags, result);\n \n // Then, recursively process subdirectories\n const entries = await fs.readdir(entityDir, { withFileTypes: true });\n for (const entry of entries) {\n if (entry.isDirectory() && !entry.name.startsWith('.')) {\n const subDir = path.join(entityDir, entry.name);\n \n // Load subdirectory config and merge with parent config\n let subEntityConfig = { ...entityConfig };\n const subDirConfig = await loadEntityConfig(subDir);\n \n if (subDirConfig) {\n // Check if this is a new entity type (has different entity name)\n if (subDirConfig.entity && subDirConfig.entity !== entityConfig.entity) {\n // This is a different entity type, skip it (will be processed separately)\n continue;\n }\n \n // Merge defaults: parent defaults + subdirectory overrides\n subEntityConfig = {\n ...entityConfig,\n ...subDirConfig,\n defaults: {\n ...entityConfig.defaults,\n ...(subDirConfig.defaults || {})\n }\n };\n }\n \n // Process subdirectory with merged config\n const subResult = await this.processEntityDirectory(\n subDir,\n subEntityConfig,\n syncEngine,\n flags,\n syncConfig\n );\n \n result.created += subResult.created;\n result.updated += subResult.updated;\n result.errors += subResult.errors;\n }\n }\n \n return result;\n }\n \n private async processJsonFiles(\n jsonFiles: string[],\n entityDir: string,\n entityConfig: any,\n syncEngine: SyncEngine,\n flags: any,\n result: { created: number; updated: number; errors: number }\n ): Promise<void> {\n if (jsonFiles.length === 0) {\n return;\n }\n \n const spinner = ora();\n spinner.start('Processing records');\n \n let totalRecords = 0;\n \n for (const file of jsonFiles) {\n try {\n const filePath = path.join(entityDir, file);\n const fileContent = await fs.readJson(filePath);\n \n // Process templates in the loaded content\n const processedContent = await syncEngine.processTemplates(fileContent, entityDir);\n \n // Check if the file contains a single record or an array of records\n const isArray = Array.isArray(processedContent);\n const records: RecordData[] = isArray ? processedContent : [processedContent];\n totalRecords += records.length;\n \n // Build and process defaults (including lookups)\n const defaults = await syncEngine.buildDefaults(filePath, entityConfig);\n \n // Process each record in the file\n for (let i = 0; i < records.length; i++) {\n const recordData = records[i];\n \n // Process the record\n const isNew = await this.pushRecord(\n recordData,\n entityConfig.entity,\n path.dirname(filePath),\n file,\n defaults,\n syncEngine,\n flags['dry-run'],\n flags.verbose,\n isArray ? i : undefined\n );\n \n if (!flags['dry-run']) {\n if (isNew) {\n result.created++;\n } else {\n result.updated++;\n }\n }\n \n spinner.text = `Processing records (${result.created + result.updated + result.errors}/${totalRecords})`;\n }\n \n // Write back the entire file if it's an array\n if (isArray && !flags['dry-run']) {\n await fs.writeJson(filePath, records, { spaces: 2 });\n }\n \n } catch (error) {\n result.errors++;\n const errorMessage = error instanceof Error ? error.message : String(error);\n this.error(`Failed to process ${file}: ${errorMessage}`, { exit: false });\n }\n }\n \n spinner.succeed(`Processed ${totalRecords} records from ${jsonFiles.length} files`);\n }\n \n private async pushRecord(\n recordData: RecordData,\n entityName: string,\n baseDir: string,\n fileName: string,\n defaults: Record<string, any>,\n syncEngine: SyncEngine,\n dryRun: boolean,\n verbose: boolean = false,\n arrayIndex?: number\n ): Promise<boolean> {\n // Load or create entity\n let entity: BaseEntity | null = null;\n let isNew = false;\n \n if (recordData.primaryKey) {\n entity = await syncEngine.loadEntity(entityName, recordData.primaryKey);\n }\n \n if (!entity) {\n // New record\n entity = await syncEngine.createEntityObject(entityName);\n entity.NewRecord();\n isNew = true;\n \n // Handle primary keys for new records\n const entityInfo = syncEngine.getEntityInfo(entityName);\n if (entityInfo) {\n for (const pk of entityInfo.PrimaryKeys) {\n if (!pk.AutoIncrement) {\n // Check if we have a value in primaryKey object\n if (recordData.primaryKey?.[pk.Name]) {\n // User specified a primary key for new record, set it on entity directly\n // Don't add to fields as it will be in primaryKey section\n (entity as any)[pk.Name] = recordData.primaryKey[pk.Name];\n if (verbose) {\n this.log(` Using specified primary key ${pk.Name}: ${recordData.primaryKey[pk.Name]}`);\n }\n } else if (pk.Type.toLowerCase() === 'uniqueidentifier' && !recordData.fields[pk.Name]) {\n // Generate UUID for this primary key and set it on entity directly\n const uuid = uuidv4();\n // Don't add to fields as it will be in primaryKey section after save\n if (verbose) {\n this.log(` Generated UUID for primary key ${pk.Name}: ${uuid}`);\n }\n // Set the generated UUID on the entity\n (entity as any)[pk.Name] = uuid;\n }\n }\n }\n }\n }\n \n // Apply defaults first\n for (const [field, value] of Object.entries(defaults)) {\n if (field in entity) {\n (entity as any)[field] = value;\n }\n }\n \n // Apply record fields\n for (const [field, value] of Object.entries(recordData.fields)) {\n if (field in entity) {\n try {\n const processedValue = await syncEngine.processFieldValue(value, baseDir, null, null);\n if (verbose) {\n this.log(` Setting ${field}: ${JSON.stringify(value)} -> ${JSON.stringify(processedValue)}`);\n }\n (entity as any)[field] = processedValue;\n } catch (error) {\n throw new Error(`Failed to process field '${field}': ${error}`);\n }\n } else {\n this.warn(`Field '${field}' does not exist on entity '${entityName}'`);\n }\n }\n \n if (dryRun) {\n this.log(`Would ${isNew ? 'create' : 'update'} ${entityName} record`);\n return isNew;\n }\n \n // Save the record\n const saved = await entity.Save();\n if (!saved) {\n const message = entity.LatestResult?.Message;\n if (message) {\n throw new Error(`Failed to save record: ${message}`);\n }\n \n const errors = entity.LatestResult?.Errors?.map(err => \n typeof err === 'string' ? err : (err?.message || JSON.stringify(err))\n )?.join(', ') || 'Unknown error';\n throw new Error(`Failed to save record: ${errors}`);\n }\n \n // Process related entities after saving parent\n if (recordData.relatedEntities && !dryRun) {\n await this.processRelatedEntities(\n recordData.relatedEntities,\n entity,\n entity, // root is same as parent for top level\n baseDir,\n syncEngine,\n verbose\n );\n }\n \n // Update the local file with new primary key if created\n if (isNew) {\n const entityInfo = syncEngine.getEntityInfo(entityName);\n if (entityInfo) {\n const newPrimaryKey: Record<string, any> = {};\n for (const pk of entityInfo.PrimaryKeys) {\n newPrimaryKey[pk.Name] = entity.Get(pk.Name);\n }\n recordData.primaryKey = newPrimaryKey;\n }\n }\n \n // Always update sync metadata\n // This ensures related entities are persisted with their metadata\n recordData.sync = {\n lastModified: new Date().toISOString(),\n checksum: syncEngine.calculateChecksum(recordData.fields)\n };\n \n // Write back to file only if it's a single record (not part of an array)\n // Array records are written back in bulk after all records are processed\n if (arrayIndex === undefined) {\n const filePath = path.join(baseDir, fileName);\n await fs.writeJson(filePath, recordData, { spaces: 2 });\n }\n \n return isNew;\n }\n \n private async processRelatedEntities(\n relatedEntities: Record<string, RecordData[]>,\n parentEntity: BaseEntity,\n rootEntity: BaseEntity,\n baseDir: string,\n syncEngine: SyncEngine,\n verbose: boolean = false,\n indentLevel: number = 1\n ): Promise<void> {\n const indent = ' '.repeat(indentLevel);\n \n for (const [entityName, records] of Object.entries(relatedEntities)) {\n this.log(`${indent}↳ Processing ${records.length} related ${entityName} records`);\n \n for (const relatedRecord of records) {\n try {\n // Load or create entity\n let entity = null;\n let isNew = false;\n \n if (relatedRecord.primaryKey) {\n entity = await syncEngine.loadEntity(entityName, relatedRecord.primaryKey);\n }\n \n if (!entity) {\n entity = await syncEngine.createEntityObject(entityName);\n entity.NewRecord();\n isNew = true;\n \n // Handle primary keys for new related entity records\n const entityInfo = syncEngine.getEntityInfo(entityName);\n if (entityInfo) {\n for (const pk of entityInfo.PrimaryKeys) {\n if (!pk.AutoIncrement) {\n // Check if we have a value in primaryKey object\n if (relatedRecord.primaryKey?.[pk.Name]) {\n // User specified a primary key for new record, set it on entity directly\n // Don't add to fields as it will be in primaryKey section\n (entity as any)[pk.Name] = relatedRecord.primaryKey[pk.Name];\n if (verbose) {\n this.log(`${indent} Using specified primary key ${pk.Name}: ${relatedRecord.primaryKey[pk.Name]}`);\n }\n } else if (pk.Type.toLowerCase() === 'uniqueidentifier' && !relatedRecord.fields[pk.Name]) {\n // Generate UUID for this primary key and set it on entity directly\n const uuid = uuidv4();\n // Don't add to fields as it will be in primaryKey section after save\n (entity as any)[pk.Name] = uuid;\n if (verbose) {\n this.log(`${indent} Generated UUID for primary key ${pk.Name}: ${uuid}`);\n }\n }\n }\n }\n }\n }\n \n // Apply fields with parent/root context\n for (const [field, value] of Object.entries(relatedRecord.fields)) {\n if (field in entity) {\n try {\n const processedValue = await syncEngine.processFieldValue(\n value, \n baseDir, \n parentEntity, \n rootEntity\n );\n if (verbose) {\n this.log(`${indent} Setting ${field}: ${JSON.stringify(value)} -> ${JSON.stringify(processedValue)}`);\n }\n (entity as any)[field] = processedValue;\n } catch (error) {\n throw new Error(`Failed to process field '${field}' in ${entityName}: ${error}`);\n }\n } else {\n this.warn(`${indent} Field '${field}' does not exist on entity '${entityName}'`);\n }\n }\n \n // Save the related entity\n const saved = await entity.Save();\n if (!saved) {\n const message = entity.LatestResult?.Message;\n if (message) {\n throw new Error(`Failed to save related ${entityName}: ${message}`);\n }\n \n const errors = entity.LatestResult?.Errors?.map(err => \n typeof err === 'string' ? err : (err?.message || JSON.stringify(err))\n )?.join(', ') || 'Unknown error';\n throw new Error(`Failed to save related ${entityName}: ${errors}`);\n }\n \n if (verbose) {\n this.log(`${indent} ✓ ${isNew ? 'Created' : 'Updated'} ${entityName} record`);\n }\n \n // Update the related record with primary key and sync metadata\n const entityInfo = syncEngine.getEntityInfo(entityName);\n if (entityInfo) {\n // Update primary key if new\n if (isNew) {\n relatedRecord.primaryKey = {};\n for (const pk of entityInfo.PrimaryKeys) {\n relatedRecord.primaryKey[pk.Name] = entity.Get(pk.Name);\n }\n }\n \n // Always update sync metadata\n relatedRecord.sync = {\n lastModified: new Date().toISOString(),\n checksum: syncEngine.calculateChecksum(relatedRecord.fields)\n };\n }\n \n // Process nested related entities if any\n if (relatedRecord.relatedEntities) {\n await this.processRelatedEntities(\n relatedRecord.relatedEntities,\n entity,\n rootEntity,\n baseDir,\n syncEngine,\n verbose,\n indentLevel + 1\n );\n }\n } catch (error) {\n throw new Error(`Failed to process related ${entityName}: ${error}`);\n }\n }\n }\n }\n}"]}
@@ -9,8 +9,9 @@ const path_1 = __importDefault(require("path"));
9
9
  const fast_glob_1 = __importDefault(require("fast-glob"));
10
10
  const ora_classic_1 = __importDefault(require("ora-classic"));
11
11
  const config_1 = require("../../config");
12
- const sync_engine_1 = require("../../lib/sync-engine");
13
12
  const provider_utils_1 = require("../../lib/provider-utils");
13
+ const singleton_manager_1 = require("../../lib/singleton-manager");
14
+ const provider_utils_2 = require("../../lib/provider-utils");
14
15
  class Status extends core_1.Command {
15
16
  static description = 'Show status of local files vs database';
16
17
  static examples = [
@@ -30,12 +31,14 @@ class Status extends core_1.Command {
30
31
  if (!mjConfig) {
31
32
  this.error('No mj.config.cjs found in current directory or parent directories');
32
33
  }
34
+ // Stop spinner before provider initialization (which logs to console)
35
+ spinner.stop();
33
36
  // Initialize data provider
34
37
  const provider = await (0, provider_utils_1.initializeProvider)(mjConfig);
35
- // Initialize sync engine
36
- const syncEngine = new sync_engine_1.SyncEngine((0, provider_utils_1.getSystemUser)());
37
- await syncEngine.initialize();
38
- spinner.succeed('Configuration loaded');
38
+ // Initialize sync engine using singleton pattern
39
+ const syncEngine = await (0, singleton_manager_1.getSyncEngine)((0, provider_utils_1.getSystemUser)());
40
+ // Show success after all initialization is complete
41
+ spinner.succeed('Configuration and metadata loaded');
39
42
  // Find entity directories to process
40
43
  const entityDirs = (0, provider_utils_1.findEntityDirectories)(process.cwd(), flags.dir);
41
44
  if (entityDirs.length === 0) {
@@ -76,16 +79,55 @@ class Status extends core_1.Command {
76
79
  }
77
80
  catch (error) {
78
81
  spinner.fail('Status check failed');
82
+ // Enhanced error logging for debugging
83
+ this.log('\n=== Status Check Error Details ===');
84
+ this.log(`Error type: ${error?.constructor?.name || 'Unknown'}`);
85
+ this.log(`Error message: ${error instanceof Error ? error.message : String(error)}`);
86
+ if (error instanceof Error && error.stack) {
87
+ this.log(`\nStack trace:`);
88
+ this.log(error.stack);
89
+ }
90
+ // Log context information
91
+ this.log(`\nContext:`);
92
+ this.log(`- Working directory: ${process.cwd()}`);
93
+ this.log(`- Specific directory: ${flags.dir || 'none (checking all directories)'}`);
94
+ this.log(`- Flags: ${JSON.stringify(flags, null, 2)}`);
95
+ // Check if error is related to common issues
96
+ const errorMessage = error instanceof Error ? error.message : String(error);
97
+ if (errorMessage.includes('No entity directories found')) {
98
+ this.log(`\nHint: This appears to be an entity directory configuration issue.`);
99
+ this.log(`Make sure directories have .mj-sync.json files or run "mj-sync init".`);
100
+ }
101
+ else if (errorMessage.includes('database') || errorMessage.includes('connection')) {
102
+ this.log(`\nHint: This appears to be a database connectivity issue.`);
103
+ this.log(`Check your mj.config.cjs configuration and database connectivity.`);
104
+ }
105
+ else if (errorMessage.includes('config') || errorMessage.includes('mj.config.cjs')) {
106
+ this.log(`\nHint: This appears to be a configuration file issue.`);
107
+ this.log(`Make sure mj.config.cjs exists and is properly configured.`);
108
+ }
109
+ else if (errorMessage.includes('metadata')) {
110
+ this.log(`\nHint: This appears to be a metadata loading issue.`);
111
+ this.log(`Check database connectivity and entity configurations.`);
112
+ }
79
113
  this.error(error);
80
114
  }
115
+ finally {
116
+ // Reset sync engine singleton
117
+ (0, singleton_manager_1.resetSyncEngine)();
118
+ // Clean up database connection
119
+ await (0, provider_utils_2.cleanupProvider)();
120
+ // Exit process to prevent background MJ tasks from throwing errors
121
+ process.exit(0);
122
+ }
81
123
  }
82
124
  async checkEntityDirectory(entityDir, entityConfig, syncEngine) {
83
125
  const result = { new: 0, modified: 0, deleted: 0, unchanged: 0 };
84
- // Find JSON files in the current directory only (not subdirectories)
126
+ // Find files matching the configured pattern
85
127
  const pattern = entityConfig.filePattern || '*.json';
86
128
  const jsonFiles = await (0, fast_glob_1.default)(pattern, {
87
129
  cwd: entityDir,
88
- ignore: ['.mj-sync.json', '.mj-folder.json'],
130
+ ignore: ['.mj-sync.json', '.mj-folder.json', '**/*.backup'],
89
131
  dot: true // Include dotfiles (files starting with .)
90
132
  });
91
133
  for (const file of jsonFiles) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/status/index.ts"],"names":[],"mappings":";;;;;AAAA,sCAA6C;AAC7C,wDAA0B;AAC1B,gDAAwB;AACxB,0DAAiC;AACjC,8DAA8B;AAC9B,yCAA8D;AAC9D,uDAA+D;AAC/D,6DAAoG;AAEpG,MAAqB,MAAO,SAAQ,cAAO;IACzC,MAAM,CAAC,WAAW,GAAG,wCAAwC,CAAC;IAE9D,MAAM,CAAC,QAAQ,GAAG;QAChB,qCAAqC;QACrC,wDAAwD;KACzD,CAAC;IAEF,MAAM,CAAC,KAAK,G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KAAK,YAAY,CAAC,MAAM,EAAE,CAAC;wBACvE,0EAA0E;wBAC1E,SAAS;oBACX,CAAC;oBAED,2DAA2D;oBAC3D,eAAe,GAAG;wBAChB,GAAG,YAAY;wBACf,GAAG,YAAY;wBACf,QAAQ,EAAE;4BACR,GAAG,YAAY,CAAC,QAAQ;4BACxB,GAAG,CAAC,YAAY,CAAC,QAAQ,IAAI,EAAE,CAAC;yBACjC;qBACF,CAAC;gBACJ,CAAC;gBAED,0CAA0C;gBAC1C,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,oBAAoB,CAC/C,MAAM,EACN,eAAe,EACf,UAAU,CACX,CAAC;gBAEF,MAAM,CAAC,GAAG,IAAI,SAAS,CAAC,GAAG,CAAC;gBAC5B,MAAM,CAAC,QAAQ,IAAI,SAAS,CAAC,QAAQ,CAAC;gBACtC,MAAM,CAAC,OAAO,IAAI,SAAS,CAAC,OAAO,CAAC;gBACpC,MAAM,CAAC,SAAS,IAAI,SAAS,CAAC,SAAS,CAAC;YAC1C,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;;AAhLH,yBAiLC","sourcesContent":["import { Command, Flags } from '@oclif/core';\nimport fs from 'fs-extra';\nimport path from 'path';\nimport fastGlob from 'fast-glob';\nimport ora from 'ora-classic';\nimport { loadMJConfig, loadEntityConfig } from '../../config';\nimport { SyncEngine, RecordData } from '../../lib/sync-engine';\nimport { initializeProvider, findEntityDirectories, getSystemUser } from '../../lib/provider-utils';\n\nexport default class Status extends Command {\n static description = 'Show status of local files vs database';\n \n static examples = [\n `<%= config.bin %> <%= command.id %>`,\n `<%= config.bin %> <%= command.id %> --dir=\"ai-prompts\"`,\n ];\n \n static flags = {\n dir: Flags.string({ description: 'Specific entity directory to check status' }),\n };\n \n async run(): Promise<void> {\n const { flags } = await this.parse(Status);\n const spinner = ora();\n \n try {\n // Load configurations\n spinner.start('Loading configuration');\n const mjConfig = loadMJConfig();\n if (!mjConfig) {\n this.error('No mj.config.cjs found in current directory or parent directories');\n }\n \n // Initialize data provider\n const provider = await initializeProvider(mjConfig);\n \n // Initialize sync engine\n const syncEngine = new SyncEngine(getSystemUser());\n await syncEngine.initialize();\n spinner.succeed('Configuration loaded');\n \n // Find entity directories to process\n const entityDirs = findEntityDirectories(process.cwd(), flags.dir);\n \n if (entityDirs.length === 0) {\n this.error('No entity directories found');\n }\n \n this.log(`Found ${entityDirs.length} entity ${entityDirs.length === 1 ? 'directory' : 'directories'} to check`);\n \n // Process each entity directory\n let totalNew = 0;\n let totalModified = 0;\n let totalDeleted = 0;\n let totalUnchanged = 0;\n \n for (const entityDir of entityDirs) {\n const entityConfig = await loadEntityConfig(entityDir);\n if (!entityConfig) {\n this.warn(`Skipping ${entityDir} - no valid entity configuration`);\n continue;\n }\n \n this.log(`\\nChecking ${entityConfig.entity} in ${entityDir}`);\n \n const result = await this.checkEntityDirectory(\n entityDir,\n entityConfig,\n syncEngine\n );\n \n totalNew += result.new;\n totalModified += result.modified;\n totalDeleted += result.deleted;\n totalUnchanged += result.unchanged;\n \n // Show directory summary\n if (result.new > 0 || result.modified > 0 || result.deleted > 0) {\n this.log(` New: ${result.new}, Modified: ${result.modified}, Deleted: ${result.deleted}, Unchanged: ${result.unchanged}`);\n } else {\n this.log(` All ${result.unchanged} records are up to date`);\n }\n }\n \n // Overall summary\n this.log('\\n=== Status Summary ===');\n this.log(`New (local only): ${totalNew}`);\n this.log(`Modified locally: ${totalModified}`);\n this.log(`Deleted locally: ${totalDeleted}`);\n this.log(`Unchanged: ${totalUnchanged}`);\n \n } catch (error) {\n spinner.fail('Status check failed');\n this.error(error as Error);\n }\n }\n \n private async checkEntityDirectory(\n entityDir: string,\n entityConfig: any,\n syncEngine: SyncEngine\n ): Promise<{ new: number; modified: number; deleted: number; unchanged: number }> {\n const result = { new: 0, modified: 0, deleted: 0, unchanged: 0 };\n \n // Find JSON files in the current directory only (not subdirectories)\n const pattern = entityConfig.filePattern || '*.json';\n const jsonFiles = await fastGlob(pattern, {\n cwd: entityDir,\n ignore: ['.mj-sync.json', '.mj-folder.json'],\n dot: true // Include dotfiles (files starting with .)\n });\n \n for (const file of jsonFiles) {\n try {\n const filePath = path.join(entityDir, file);\n const recordData: RecordData = await fs.readJson(filePath);\n \n if (recordData.primaryKey) {\n // Check if record exists in database\n const entity = await syncEngine.loadEntity(entityConfig.entity, recordData.primaryKey);\n \n if (!entity) {\n result.deleted++;\n } else {\n // Check if modified\n const currentChecksum = syncEngine.calculateChecksum(recordData.fields);\n if (recordData.sync?.checksum !== currentChecksum) {\n result.modified++;\n } else {\n result.unchanged++;\n }\n }\n } else {\n // New record\n result.new++;\n }\n \n } catch (error) {\n this.warn(`Failed to check ${file}: ${error}`);\n }\n }\n \n // Recursively process subdirectories\n const entries = await fs.readdir(entityDir, { withFileTypes: true });\n for (const entry of entries) {\n if (entry.isDirectory() && !entry.name.startsWith('.')) {\n const subDir = path.join(entityDir, entry.name);\n \n // Load subdirectory config and merge with parent config\n let subEntityConfig = { ...entityConfig };\n const subDirConfig = await loadEntityConfig(subDir);\n \n if (subDirConfig) {\n // Check if this is a new entity type (has different entity name)\n if (subDirConfig.entity && subDirConfig.entity !== entityConfig.entity) {\n // This is a different entity type, skip it (will be processed separately)\n continue;\n }\n \n // Merge defaults: parent defaults + subdirectory overrides\n subEntityConfig = {\n ...entityConfig,\n ...subDirConfig,\n defaults: {\n ...entityConfig.defaults,\n ...(subDirConfig.defaults || {})\n }\n };\n }\n \n // Process subdirectory with merged config\n const subResult = await this.checkEntityDirectory(\n subDir,\n subEntityConfig,\n syncEngine\n );\n \n result.new += subResult.new;\n result.modified += subResult.modified;\n result.deleted += subResult.deleted;\n result.unchanged += subResult.unchanged;\n }\n }\n \n return result;\n }\n}"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/status/index.ts"],"names":[],"mappings":";;;;;AAAA,sCAA6C;AAC7C,wDAA0B;AAC1B,gDAAwB;AACxB,0DAAiC;AACjC,8DAA8B;AAC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4BACxB,GAAG,CAAC,YAAY,CAAC,QAAQ,IAAI,EAAE,CAAC;yBACjC;qBACF,CAAC;gBACJ,CAAC;gBAED,0CAA0C;gBAC1C,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,oBAAoB,CAC/C,MAAM,EACN,eAAe,EACf,UAAU,CACX,CAAC;gBAEF,MAAM,CAAC,GAAG,IAAI,SAAS,CAAC,GAAG,CAAC;gBAC5B,MAAM,CAAC,QAAQ,IAAI,SAAS,CAAC,QAAQ,CAAC;gBACtC,MAAM,CAAC,OAAO,IAAI,SAAS,CAAC,OAAO,CAAC;gBACpC,MAAM,CAAC,SAAS,IAAI,SAAS,CAAC,SAAS,CAAC;YAC1C,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;;AA7NH,yBA8NC","sourcesContent":["import { Command, Flags } from '@oclif/core';\nimport fs from 'fs-extra';\nimport path from 'path';\nimport fastGlob from 'fast-glob';\nimport ora from 'ora-classic';\nimport { loadMJConfig, loadEntityConfig } from '../../config';\nimport { SyncEngine, RecordData } from '../../lib/sync-engine';\nimport { initializeProvider, findEntityDirectories, getSystemUser } from '../../lib/provider-utils';\nimport { getSyncEngine, resetSyncEngine } from '../../lib/singleton-manager';\nimport { cleanupProvider } from '../../lib/provider-utils';\n\nexport default class Status extends Command {\n static description = 'Show status of local files vs database';\n \n static examples = [\n `<%= config.bin %> <%= command.id %>`,\n `<%= config.bin %> <%= command.id %> --dir=\"ai-prompts\"`,\n ];\n \n static flags = {\n dir: Flags.string({ description: 'Specific entity directory to check status' }),\n };\n \n async run(): Promise<void> {\n const { flags } = await this.parse(Status);\n const spinner = ora();\n \n try {\n // Load configurations\n spinner.start('Loading configuration');\n const mjConfig = loadMJConfig();\n if (!mjConfig) {\n this.error('No mj.config.cjs found in current directory or parent directories');\n }\n \n // Stop spinner before provider initialization (which logs to console)\n spinner.stop();\n \n // Initialize data provider\n const provider = await initializeProvider(mjConfig);\n \n // Initialize sync engine using singleton pattern\n const syncEngine = await getSyncEngine(getSystemUser());\n \n // Show success after all initialization is complete\n spinner.succeed('Configuration and metadata loaded');\n \n // Find entity directories to process\n const entityDirs = findEntityDirectories(process.cwd(), flags.dir);\n \n if (entityDirs.length === 0) {\n this.error('No entity directories found');\n }\n \n this.log(`Found ${entityDirs.length} entity ${entityDirs.length === 1 ? 'directory' : 'directories'} to check`);\n \n // Process each entity directory\n let totalNew = 0;\n let totalModified = 0;\n let totalDeleted = 0;\n let totalUnchanged = 0;\n \n for (const entityDir of entityDirs) {\n const entityConfig = await loadEntityConfig(entityDir);\n if (!entityConfig) {\n this.warn(`Skipping ${entityDir} - no valid entity configuration`);\n continue;\n }\n \n this.log(`\\nChecking ${entityConfig.entity} in ${entityDir}`);\n \n const result = await this.checkEntityDirectory(\n entityDir,\n entityConfig,\n syncEngine\n );\n \n totalNew += result.new;\n totalModified += result.modified;\n totalDeleted += result.deleted;\n totalUnchanged += result.unchanged;\n \n // Show directory summary\n if (result.new > 0 || result.modified > 0 || result.deleted > 0) {\n this.log(` New: ${result.new}, Modified: ${result.modified}, Deleted: ${result.deleted}, Unchanged: ${result.unchanged}`);\n } else {\n this.log(` All ${result.unchanged} records are up to date`);\n }\n }\n \n // Overall summary\n this.log('\\n=== Status Summary ===');\n this.log(`New (local only): ${totalNew}`);\n this.log(`Modified locally: ${totalModified}`);\n this.log(`Deleted locally: ${totalDeleted}`);\n this.log(`Unchanged: ${totalUnchanged}`);\n \n } catch (error) {\n spinner.fail('Status check failed');\n \n // Enhanced error logging for debugging\n this.log('\\n=== Status Check Error Details ===');\n this.log(`Error type: ${error?.constructor?.name || 'Unknown'}`);\n this.log(`Error message: ${error instanceof Error ? error.message : String(error)}`);\n \n if (error instanceof Error && error.stack) {\n this.log(`\\nStack trace:`);\n this.log(error.stack);\n }\n \n // Log context information\n this.log(`\\nContext:`);\n this.log(`- Working directory: ${process.cwd()}`);\n this.log(`- Specific directory: ${flags.dir || 'none (checking all directories)'}`);\n this.log(`- Flags: ${JSON.stringify(flags, null, 2)}`);\n \n // Check if error is related to common issues\n const errorMessage = error instanceof Error ? error.message : String(error);\n if (errorMessage.includes('No entity directories found')) {\n this.log(`\\nHint: This appears to be an entity directory configuration issue.`);\n this.log(`Make sure directories have .mj-sync.json files or run \"mj-sync init\".`);\n } else if (errorMessage.includes('database') || errorMessage.includes('connection')) {\n this.log(`\\nHint: This appears to be a database connectivity issue.`);\n this.log(`Check your mj.config.cjs configuration and database connectivity.`);\n } else if (errorMessage.includes('config') || errorMessage.includes('mj.config.cjs')) {\n this.log(`\\nHint: This appears to be a configuration file issue.`);\n this.log(`Make sure mj.config.cjs exists and is properly configured.`);\n } else if (errorMessage.includes('metadata')) {\n this.log(`\\nHint: This appears to be a metadata loading issue.`);\n this.log(`Check database connectivity and entity configurations.`);\n }\n \n this.error(error as Error);\n } finally {\n // Reset sync engine singleton\n resetSyncEngine();\n // Clean up database connection\n await cleanupProvider();\n \n // Exit process to prevent background MJ tasks from throwing errors\n process.exit(0);\n }\n }\n \n private async checkEntityDirectory(\n entityDir: string,\n entityConfig: any,\n syncEngine: SyncEngine\n ): Promise<{ new: number; modified: number; deleted: number; unchanged: number }> {\n const result = { new: 0, modified: 0, deleted: 0, unchanged: 0 };\n \n // Find files matching the configured pattern\n const pattern = entityConfig.filePattern || '*.json';\n const jsonFiles = await fastGlob(pattern, {\n cwd: entityDir,\n ignore: ['.mj-sync.json', '.mj-folder.json', '**/*.backup'],\n dot: true // Include dotfiles (files starting with .)\n });\n \n for (const file of jsonFiles) {\n try {\n const filePath = path.join(entityDir, file);\n const recordData: RecordData = await fs.readJson(filePath);\n \n if (recordData.primaryKey) {\n // Check if record exists in database\n const entity = await syncEngine.loadEntity(entityConfig.entity, recordData.primaryKey);\n \n if (!entity) {\n result.deleted++;\n } else {\n // Check if modified\n const currentChecksum = syncEngine.calculateChecksum(recordData.fields);\n if (recordData.sync?.checksum !== currentChecksum) {\n result.modified++;\n } else {\n result.unchanged++;\n }\n }\n } else {\n // New record\n result.new++;\n }\n \n } catch (error) {\n this.warn(`Failed to check ${file}: ${error}`);\n }\n }\n \n // Recursively process subdirectories\n const entries = await fs.readdir(entityDir, { withFileTypes: true });\n for (const entry of entries) {\n if (entry.isDirectory() && !entry.name.startsWith('.')) {\n const subDir = path.join(entityDir, entry.name);\n \n // Load subdirectory config and merge with parent config\n let subEntityConfig = { ...entityConfig };\n const subDirConfig = await loadEntityConfig(subDir);\n \n if (subDirConfig) {\n // Check if this is a new entity type (has different entity name)\n if (subDirConfig.entity && subDirConfig.entity !== entityConfig.entity) {\n // This is a different entity type, skip it (will be processed separately)\n continue;\n }\n \n // Merge defaults: parent defaults + subdirectory overrides\n subEntityConfig = {\n ...entityConfig,\n ...subDirConfig,\n defaults: {\n ...entityConfig.defaults,\n ...(subDirConfig.defaults || {})\n }\n };\n }\n \n // Process subdirectory with merged config\n const subResult = await this.checkEntityDirectory(\n subDir,\n subEntityConfig,\n syncEngine\n );\n \n result.new += subResult.new;\n result.modified += subResult.modified;\n result.deleted += subResult.deleted;\n result.unchanged += subResult.unchanged;\n }\n }\n \n return result;\n }\n}"]}
@@ -9,8 +9,9 @@ const path_1 = __importDefault(require("path"));
9
9
  const chokidar_1 = __importDefault(require("chokidar"));
10
10
  const ora_classic_1 = __importDefault(require("ora-classic"));
11
11
  const config_1 = require("../../config");
12
- const sync_engine_1 = require("../../lib/sync-engine");
13
12
  const provider_utils_1 = require("../../lib/provider-utils");
13
+ const singleton_manager_1 = require("../../lib/singleton-manager");
14
+ const provider_utils_2 = require("../../lib/provider-utils");
14
15
  class Watch extends core_1.Command {
15
16
  static description = 'Watch for file changes and automatically push to database';
16
17
  static examples = [
@@ -34,12 +35,14 @@ class Watch extends core_1.Command {
34
35
  this.error('No mj.config.cjs found in current directory or parent directories');
35
36
  }
36
37
  this.syncConfig = await (0, config_1.loadSyncConfig)(process.cwd());
38
+ // Stop spinner before provider initialization (which logs to console)
39
+ spinner.stop();
37
40
  // Initialize data provider
38
41
  const provider = await (0, provider_utils_1.initializeProvider)(mjConfig);
39
- // Initialize sync engine
40
- this.syncEngine = new sync_engine_1.SyncEngine((0, provider_utils_1.getSystemUser)());
41
- await this.syncEngine.initialize();
42
- spinner.succeed('Configuration loaded');
42
+ // Initialize sync engine using singleton pattern
43
+ this.syncEngine = await (0, singleton_manager_1.getSyncEngine)((0, provider_utils_1.getSystemUser)());
44
+ // Show success after all initialization is complete
45
+ spinner.succeed('Configuration and metadata loaded');
43
46
  // Find entity directories to watch
44
47
  const entityDirs = (0, provider_utils_1.findEntityDirectories)(process.cwd(), flags.dir);
45
48
  if (entityDirs.length === 0) {
@@ -56,6 +59,7 @@ class Watch extends core_1.Command {
56
59
  }
57
60
  this.log(`Watching ${entityConfig.entity} in ${entityDir}`);
58
61
  // Watch for JSON files and external files
62
+ // All JSON files will be watched, but only dot-prefixed ones will be processed
59
63
  const patterns = [
60
64
  path_1.default.join(entityDir, entityConfig.filePattern || '**/*.json'),
61
65
  path_1.default.join(entityDir, '**/*.md'),
@@ -69,6 +73,7 @@ class Watch extends core_1.Command {
69
73
  '**/.git/**',
70
74
  '**/.mj-sync.json',
71
75
  '**/.mj-folder.json',
76
+ '**/*.backup',
72
77
  ...(this.syncConfig?.watch?.ignorePatterns || [])
73
78
  ];
74
79
  const watcher = chokidar_1.default.watch(patterns, {
@@ -86,14 +91,57 @@ class Watch extends core_1.Command {
86
91
  // Keep process alive
87
92
  process.stdin.resume();
88
93
  // Cleanup on exit
89
- process.on('SIGINT', () => {
94
+ process.on('SIGINT', async () => {
90
95
  this.log('\nStopping watchers...');
91
96
  watchers.forEach(w => w.close());
97
+ // Reset sync engine singleton
98
+ (0, singleton_manager_1.resetSyncEngine)();
99
+ // Clean up database connection
100
+ await (0, provider_utils_2.cleanupProvider)();
92
101
  process.exit(0);
93
102
  });
94
103
  }
95
104
  catch (error) {
96
105
  spinner.fail('Watch failed');
106
+ // Enhanced error logging for debugging
107
+ this.log('\n=== Watch Error Details ===');
108
+ this.log(`Error type: ${error?.constructor?.name || 'Unknown'}`);
109
+ this.log(`Error message: ${error instanceof Error ? error.message : String(error)}`);
110
+ if (error instanceof Error && error.stack) {
111
+ this.log(`\nStack trace:`);
112
+ this.log(error.stack);
113
+ }
114
+ // Log context information
115
+ this.log(`\nContext:`);
116
+ this.log(`- Working directory: ${process.cwd()}`);
117
+ this.log(`- Specific directory: ${flags.dir || 'none (watching all directories)'}`);
118
+ this.log(`- Flags: ${JSON.stringify(flags, null, 2)}`);
119
+ // Check if error is related to common issues
120
+ const errorMessage = error instanceof Error ? error.message : String(error);
121
+ if (errorMessage.includes('No entity directories found')) {
122
+ this.log(`\nHint: This appears to be an entity directory configuration issue.`);
123
+ this.log(`Make sure directories have .mj-sync.json files or run "mj-sync init".`);
124
+ }
125
+ else if (errorMessage.includes('database') || errorMessage.includes('connection')) {
126
+ this.log(`\nHint: This appears to be a database connectivity issue.`);
127
+ this.log(`Check your mj.config.cjs configuration and database connectivity.`);
128
+ }
129
+ else if (errorMessage.includes('config') || errorMessage.includes('mj.config.cjs')) {
130
+ this.log(`\nHint: This appears to be a configuration file issue.`);
131
+ this.log(`Make sure mj.config.cjs exists and is properly configured.`);
132
+ }
133
+ else if (errorMessage.includes('ENOENT') || errorMessage.includes('no such file')) {
134
+ this.log(`\nHint: File or directory access issue.`);
135
+ this.log(`Check that the directories exist and are accessible.`);
136
+ }
137
+ else if (errorMessage.includes('chokidar') || errorMessage.includes('watch')) {
138
+ this.log(`\nHint: File watching system issue.`);
139
+ this.log(`Check file system permissions and available file descriptors.`);
140
+ }
141
+ // Reset sync engine singleton
142
+ (0, singleton_manager_1.resetSyncEngine)();
143
+ // Clean up database connection
144
+ await (0, provider_utils_2.cleanupProvider)();
97
145
  this.error(error);
98
146
  }
99
147
  }
@@ -161,7 +209,11 @@ class Watch extends core_1.Command {
161
209
  // Save the record
162
210
  const saved = await entity.Save();
163
211
  if (!saved) {
164
- const errors = entity.LatestResult?.Errors?.join(', ') || 'Unknown error';
212
+ const message = entity.LatestResult?.Message;
213
+ if (message) {
214
+ throw new Error(`Failed to save record: ${message}`);
215
+ }
216
+ const errors = entity.LatestResult?.Errors?.map(err => typeof err === 'string' ? err : (err?.message || JSON.stringify(err)))?.join(', ') || 'Unknown error';
165
217
  throw new Error(`Failed to save record: ${errors}`);
166
218
  }
167
219
  this.log(`Successfully ${isNew ? 'created' : 'updated'} ${entityConfig.entity} record`);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/watch/index.ts"],"names":[],"mappings":";;;;;AAAA,sCAA6C;AAC7C,wDAA0B;AAC1B,gDAAwB;AACxB,wDAAgC;AAChC,8DAA8B;AAC9B,yCAA8E;AAC9E,uDAA+D;AAC/D,6DAAoG;AAGpG,MAAqB,KAAM,SAAQ,cAAO;IACxC,MAAM,CAAC,WAAW,GAAG,2DAA2D,CAAC;IAEjF,MAAM,CAAC,QAAQ,GAAG;QAChB,qCAAqC;QACrC,wDAAwD;KACzD,CAAC;IAEF,MAAM,CAAC,KAAK,GAAG;QACb,GAAG,EAAE,YAAK,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,oCAAoC,EAAE,CAAC;KACzE,CAAC;IAEM,UAAU,CAAc;IACxB,UAAU,CAAM;IAChB,cAAc,GAAgC,IAAI,GAAG,EAAE,CAAC;IAEhE,KAAK,CAAC,GAAG;QACP,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC1C,MAAM,OAAO,GAAG,IAAA,qBAAG,GAAE,CAAC;QAEtB,IAAI,CAAC;YACH,sBAAsB;YACtB,OAAO,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;YACvC,MAAM,QAAQ,GAAG,IAAA,qBAAY,GAAE,CAAC;YAChC,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACd,IAAI,CAAC,KAAK,CAAC,mEAAmE,CAAC,CAAC;YAClF,CAAC;YAED,IAAI,CAAC,UAAU,GAAG,MAAM,I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AY,CAAC,EAAE,CAAC;gBACtC,yDAAyD;gBACzD,MAAM,UAAU,GAAe,MAAM,kBAAE,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;gBAC/D,UAAU,CAAC,IAAI,GAAG;oBAChB,YAAY,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;oBACtC,QAAQ,EAAE,UAAU,CAAC,IAAI,EAAE,QAAQ,IAAI,EAAE;iBAC1C,CAAC;gBACF,MAAM,kBAAE,CAAC,SAAS,CAAC,YAAY,EAAE,UAAU,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC;gBAE5D,IAAI,CAAC,GAAG,CAAC,6BAA6B,YAAY,8BAA8B,CAAC,CAAC;YACpF,CAAC;QACH,CAAC;IACH,CAAC;;AAtPH,wBAuPC","sourcesContent":["import { Command, Flags } from '@oclif/core';\nimport fs from 'fs-extra';\nimport path from 'path';\nimport chokidar from 'chokidar';\nimport ora from 'ora-classic';\nimport { loadMJConfig, loadSyncConfig, loadEntityConfig } from '../../config';\nimport { SyncEngine, RecordData } from '../../lib/sync-engine';\nimport { initializeProvider, findEntityDirectories, getSystemUser } from '../../lib/provider-utils';\nimport { BaseEntity } from '@memberjunction/core';\n\nexport default class Watch extends Command {\n static description = 'Watch for file changes and automatically push to database';\n \n static examples = [\n `<%= config.bin %> <%= command.id %>`,\n `<%= config.bin %> <%= command.id %> --dir=\"ai-prompts\"`,\n ];\n \n static flags = {\n dir: Flags.string({ description: 'Specific entity directory to watch' }),\n };\n \n private syncEngine!: SyncEngine;\n private syncConfig: any;\n private debounceTimers: Map<string, NodeJS.Timeout> = new Map();\n \n async run(): Promise<void> {\n const { flags } = await this.parse(Watch);\n const spinner = ora();\n \n try {\n // Load configurations\n spinner.start('Loading configuration');\n const mjConfig = loadMJConfig();\n if (!mjConfig) {\n this.error('No mj.config.cjs found in current directory or parent directories');\n }\n \n this.syncConfig = await loadSyncConfig(process.cwd());\n \n // Initialize data provider\n const provider = await initializeProvider(mjConfig);\n \n // Initialize sync engine\n this.syncEngine = new SyncEngine(getSystemUser());\n await this.syncEngine.initialize();\n spinner.succeed('Configuration loaded');\n \n // Find entity directories to watch\n const entityDirs = findEntityDirectories(process.cwd(), flags.dir);\n \n if (entityDirs.length === 0) {\n this.error('No entity directories found');\n }\n \n this.log(`Watching ${entityDirs.length} entity ${entityDirs.length === 1 ? 'directory' : 'directories'} for changes`);\n \n // Set up watchers\n const watchers: chokidar.FSWatcher[] = [];\n \n for (const entityDir of entityDirs) {\n const entityConfig = await loadEntityConfig(entityDir);\n if (!entityConfig) {\n this.warn(`Skipping ${entityDir} - no valid entity configuration`);\n continue;\n }\n \n this.log(`Watching ${entityConfig.entity} in ${entityDir}`);\n \n // Watch for JSON files and external files\n const patterns = [\n path.join(entityDir, entityConfig.filePattern || '**/*.json'),\n path.join(entityDir, '**/*.md'),\n path.join(entityDir, '**/*.txt'),\n path.join(entityDir, '**/*.html'),\n path.join(entityDir, '**/*.liquid'),\n path.join(entityDir, '**/*.sql')\n ];\n \n const ignored = [\n '**/node_modules/**',\n '**/.git/**',\n '**/.mj-sync.json',\n '**/.mj-folder.json',\n ...(this.syncConfig?.watch?.ignorePatterns || [])\n ];\n \n const watcher = chokidar.watch(patterns, {\n ignored,\n persistent: true,\n ignoreInitial: true\n });\n \n watcher\n .on('add', (filePath) => this.handleFileChange(filePath, 'added', entityDir, entityConfig))\n .on('change', (filePath) => this.handleFileChange(filePath, 'changed', entityDir, entityConfig))\n .on('unlink', (filePath) => this.handleFileChange(filePath, 'deleted', entityDir, entityConfig));\n \n watchers.push(watcher);\n }\n \n this.log('\\nPress Ctrl+C to stop watching');\n \n // Keep process alive\n process.stdin.resume();\n \n // Cleanup on exit\n process.on('SIGINT', () => {\n this.log('\\nStopping watchers...');\n watchers.forEach(w => w.close());\n process.exit(0);\n });\n \n } catch (error) {\n spinner.fail('Watch failed');\n this.error(error as Error);\n }\n }\n \n private async handleFileChange(\n filePath: string,\n event: string,\n entityDir: string,\n entityConfig: any\n ): Promise<void> {\n // Clear existing debounce timer\n const existingTimer = this.debounceTimers.get(filePath);\n if (existingTimer) {\n clearTimeout(existingTimer);\n }\n \n // Set new debounce timer\n const debounceMs = this.syncConfig?.watch?.debounceMs || 1000;\n const timer = setTimeout(async () => {\n this.debounceTimers.delete(filePath);\n \n try {\n const relativePath = path.relative(entityDir, filePath);\n this.log(`\\nFile ${event}: ${relativePath}`);\n \n if (event === 'deleted') {\n // Handle deletion\n this.log('File deletion detected - manual database cleanup may be required');\n } else if (filePath.endsWith('.json')) {\n // Handle JSON file change\n await this.syncJsonFile(filePath, entityDir, entityConfig);\n } else {\n // Handle external file change\n await this.syncExternalFile(filePath, entityDir, entityConfig);\n }\n } catch (error) {\n this.warn(`Failed to sync ${filePath}: ${(error as any).message || error}`);\n }\n }, debounceMs);\n \n this.debounceTimers.set(filePath, timer);\n }\n \n private async syncJsonFile(\n filePath: string,\n entityDir: string,\n entityConfig: any\n ): Promise<void> {\n const recordData: RecordData = await fs.readJson(filePath);\n \n // Build defaults\n const defaults = await this.syncEngine.buildDefaults(filePath, entityConfig);\n \n // Load or create entity\n let entity: BaseEntity | null = null;\n let isNew = false;\n \n if (recordData.primaryKey) {\n entity = await this.syncEngine.loadEntity(entityConfig.entity, recordData.primaryKey);\n }\n \n if (!entity) {\n // New record\n entity = await this.syncEngine.createEntityObject(entityConfig.entity);\n entity.NewRecord();\n isNew = true;\n }\n \n // Apply defaults first\n for (const [field, value] of Object.entries(defaults)) {\n if (field in entity) {\n (entity as any)[field] = value;\n }\n }\n \n // Apply record fields\n for (const [field, value] of Object.entries(recordData.fields)) {\n if (field in entity) {\n const processedValue = await this.syncEngine.processFieldValue(value, path.dirname(filePath));\n (entity as any)[field] = processedValue;\n }\n }\n \n // Save the record\n const saved = await entity.Save();\n if (!saved) {\n const errors = entity.LatestResult?.Errors?.join(', ') || 'Unknown error';\n throw new Error(`Failed to save record: ${errors}`);\n }\n \n this.log(`Successfully ${isNew ? 'created' : 'updated'} ${entityConfig.entity} record`);\n \n // Update the local file with new primary key if created\n if (isNew) {\n const entityInfo = this.syncEngine.getEntityInfo(entityConfig.entity);\n if (entityInfo) {\n const newPrimaryKey: Record<string, any> = {};\n for (const pk of entityInfo.PrimaryKeys) {\n newPrimaryKey[pk.Name] = entity.Get(pk.Name);\n }\n recordData.primaryKey = newPrimaryKey;\n \n // Update sync metadata\n recordData.sync = {\n lastModified: new Date().toISOString(),\n checksum: this.syncEngine.calculateChecksum(recordData.fields)\n };\n \n // Write back to file\n await fs.writeJson(filePath, recordData, { spaces: 2 });\n }\n }\n }\n \n private async syncExternalFile(\n filePath: string,\n entityDir: string,\n entityConfig: any\n ): Promise<void> {\n // Find the corresponding JSON file\n const fileName = path.basename(filePath);\n const parts = fileName.split('.');\n \n if (parts.length >= 3) {\n // Format: uuid.fieldname.ext\n const jsonFileName = `${parts[0]}.json`;\n const fieldName = parts[1];\n const jsonFilePath = path.join(path.dirname(filePath), jsonFileName);\n \n if (await fs.pathExists(jsonFilePath)) {\n // Update the JSON file's sync metadata to trigger a sync\n const recordData: RecordData = await fs.readJson(jsonFilePath);\n recordData.sync = {\n lastModified: new Date().toISOString(),\n checksum: recordData.sync?.checksum || ''\n };\n await fs.writeJson(jsonFilePath, recordData, { spaces: 2 });\n \n this.log(`Updated sync metadata for ${jsonFileName} due to external file change`);\n }\n }\n }\n}"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/watch/index.ts"],"names":[],"mappings":";;;;;AAAA,sCAA6C;AAC7C,wDAA0B;AAC1B,gDAAwB;AACxB,wDAAgC;AAChC,8DAA8B;AAC9B,yCAA8E;AAE9E,6DAAoG;AAEpG,mEAA6E;AAC7E,6DAA2D;AAE3D,MAAqB,KAAM,SAAQ,cAAO;IACxC,MAAM,CAAC,WAAW,GAAG,2DAA2D,CAAC;IAEjF,MAAM,CAAC,QAAQ,GAAG;QAChB,qCAAqC;QACrC,wDAAwD;KACzD,CAAC;IAEF,MAAM,CAA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GAAG,CAAC,6BAA6B,YAAY,8BAA8B,CAAC,CAAC;YACpF,CAAC;QACH,CAAC;IACH,CAAC;;AA/SH,wBAgTC","sourcesContent":["import { Command, Flags } from '@oclif/core';\nimport fs from 'fs-extra';\nimport path from 'path';\nimport chokidar from 'chokidar';\nimport ora from 'ora-classic';\nimport { loadMJConfig, loadSyncConfig, loadEntityConfig } from '../../config';\nimport { SyncEngine, RecordData } from '../../lib/sync-engine';\nimport { initializeProvider, findEntityDirectories, getSystemUser } from '../../lib/provider-utils';\nimport { BaseEntity } from '@memberjunction/core';\nimport { getSyncEngine, resetSyncEngine } from '../../lib/singleton-manager';\nimport { cleanupProvider } from '../../lib/provider-utils';\n\nexport default class Watch extends Command {\n static description = 'Watch for file changes and automatically push to database';\n \n static examples = [\n `<%= config.bin %> <%= command.id %>`,\n `<%= config.bin %> <%= command.id %> --dir=\"ai-prompts\"`,\n ];\n \n static flags = {\n dir: Flags.string({ description: 'Specific entity directory to watch' }),\n };\n \n private syncEngine!: SyncEngine;\n private syncConfig: any;\n private debounceTimers: Map<string, NodeJS.Timeout> = new Map();\n \n async run(): Promise<void> {\n const { flags } = await this.parse(Watch);\n const spinner = ora();\n \n try {\n // Load configurations\n spinner.start('Loading configuration');\n const mjConfig = loadMJConfig();\n if (!mjConfig) {\n this.error('No mj.config.cjs found in current directory or parent directories');\n }\n \n this.syncConfig = await loadSyncConfig(process.cwd());\n \n // Stop spinner before provider initialization (which logs to console)\n spinner.stop();\n \n // Initialize data provider\n const provider = await initializeProvider(mjConfig);\n \n // Initialize sync engine using singleton pattern\n this.syncEngine = await getSyncEngine(getSystemUser());\n \n // Show success after all initialization is complete\n spinner.succeed('Configuration and metadata loaded');\n \n // Find entity directories to watch\n const entityDirs = findEntityDirectories(process.cwd(), flags.dir);\n \n if (entityDirs.length === 0) {\n this.error('No entity directories found');\n }\n \n this.log(`Watching ${entityDirs.length} entity ${entityDirs.length === 1 ? 'directory' : 'directories'} for changes`);\n \n // Set up watchers\n const watchers: chokidar.FSWatcher[] = [];\n \n for (const entityDir of entityDirs) {\n const entityConfig = await loadEntityConfig(entityDir);\n if (!entityConfig) {\n this.warn(`Skipping ${entityDir} - no valid entity configuration`);\n continue;\n }\n \n this.log(`Watching ${entityConfig.entity} in ${entityDir}`);\n \n // Watch for JSON files and external files\n // All JSON files will be watched, but only dot-prefixed ones will be processed\n const patterns = [\n path.join(entityDir, entityConfig.filePattern || '**/*.json'),\n path.join(entityDir, '**/*.md'),\n path.join(entityDir, '**/*.txt'),\n path.join(entityDir, '**/*.html'),\n path.join(entityDir, '**/*.liquid'),\n path.join(entityDir, '**/*.sql')\n ];\n \n const ignored = [\n '**/node_modules/**',\n '**/.git/**',\n '**/.mj-sync.json',\n '**/.mj-folder.json',\n '**/*.backup',\n ...(this.syncConfig?.watch?.ignorePatterns || [])\n ];\n \n const watcher = chokidar.watch(patterns, {\n ignored,\n persistent: true,\n ignoreInitial: true\n });\n \n watcher\n .on('add', (filePath) => this.handleFileChange(filePath, 'added', entityDir, entityConfig))\n .on('change', (filePath) => this.handleFileChange(filePath, 'changed', entityDir, entityConfig))\n .on('unlink', (filePath) => this.handleFileChange(filePath, 'deleted', entityDir, entityConfig));\n \n watchers.push(watcher);\n }\n \n this.log('\\nPress Ctrl+C to stop watching');\n \n // Keep process alive\n process.stdin.resume();\n \n // Cleanup on exit\n process.on('SIGINT', async () => {\n this.log('\\nStopping watchers...');\n watchers.forEach(w => w.close());\n // Reset sync engine singleton\n resetSyncEngine();\n // Clean up database connection\n await cleanupProvider();\n process.exit(0);\n });\n \n } catch (error) {\n spinner.fail('Watch failed');\n \n // Enhanced error logging for debugging\n this.log('\\n=== Watch Error Details ===');\n this.log(`Error type: ${error?.constructor?.name || 'Unknown'}`);\n this.log(`Error message: ${error instanceof Error ? error.message : String(error)}`);\n \n if (error instanceof Error && error.stack) {\n this.log(`\\nStack trace:`);\n this.log(error.stack);\n }\n \n // Log context information\n this.log(`\\nContext:`);\n this.log(`- Working directory: ${process.cwd()}`);\n this.log(`- Specific directory: ${flags.dir || 'none (watching all directories)'}`);\n this.log(`- Flags: ${JSON.stringify(flags, null, 2)}`);\n \n // Check if error is related to common issues\n const errorMessage = error instanceof Error ? error.message : String(error);\n if (errorMessage.includes('No entity directories found')) {\n this.log(`\\nHint: This appears to be an entity directory configuration issue.`);\n this.log(`Make sure directories have .mj-sync.json files or run \"mj-sync init\".`);\n } else if (errorMessage.includes('database') || errorMessage.includes('connection')) {\n this.log(`\\nHint: This appears to be a database connectivity issue.`);\n this.log(`Check your mj.config.cjs configuration and database connectivity.`);\n } else if (errorMessage.includes('config') || errorMessage.includes('mj.config.cjs')) {\n this.log(`\\nHint: This appears to be a configuration file issue.`);\n this.log(`Make sure mj.config.cjs exists and is properly configured.`);\n } else if (errorMessage.includes('ENOENT') || errorMessage.includes('no such file')) {\n this.log(`\\nHint: File or directory access issue.`);\n this.log(`Check that the directories exist and are accessible.`);\n } else if (errorMessage.includes('chokidar') || errorMessage.includes('watch')) {\n this.log(`\\nHint: File watching system issue.`);\n this.log(`Check file system permissions and available file descriptors.`);\n }\n \n // Reset sync engine singleton\n resetSyncEngine();\n // Clean up database connection\n await cleanupProvider();\n this.error(error as Error);\n }\n }\n \n private async handleFileChange(\n filePath: string,\n event: string,\n entityDir: string,\n entityConfig: any\n ): Promise<void> {\n // Clear existing debounce timer\n const existingTimer = this.debounceTimers.get(filePath);\n if (existingTimer) {\n clearTimeout(existingTimer);\n }\n \n // Set new debounce timer\n const debounceMs = this.syncConfig?.watch?.debounceMs || 1000;\n const timer = setTimeout(async () => {\n this.debounceTimers.delete(filePath);\n \n try {\n const relativePath = path.relative(entityDir, filePath);\n this.log(`\\nFile ${event}: ${relativePath}`);\n \n if (event === 'deleted') {\n // Handle deletion\n this.log('File deletion detected - manual database cleanup may be required');\n } else if (filePath.endsWith('.json')) {\n // Handle JSON file change\n await this.syncJsonFile(filePath, entityDir, entityConfig);\n } else {\n // Handle external file change\n await this.syncExternalFile(filePath, entityDir, entityConfig);\n }\n } catch (error) {\n this.warn(`Failed to sync ${filePath}: ${(error as any).message || error}`);\n }\n }, debounceMs);\n \n this.debounceTimers.set(filePath, timer);\n }\n \n private async syncJsonFile(\n filePath: string,\n entityDir: string,\n entityConfig: any\n ): Promise<void> {\n const recordData: RecordData = await fs.readJson(filePath);\n \n // Build defaults\n const defaults = await this.syncEngine.buildDefaults(filePath, entityConfig);\n \n // Load or create entity\n let entity: BaseEntity | null = null;\n let isNew = false;\n \n if (recordData.primaryKey) {\n entity = await this.syncEngine.loadEntity(entityConfig.entity, recordData.primaryKey);\n }\n \n if (!entity) {\n // New record\n entity = await this.syncEngine.createEntityObject(entityConfig.entity);\n entity.NewRecord();\n isNew = true;\n }\n \n // Apply defaults first\n for (const [field, value] of Object.entries(defaults)) {\n if (field in entity) {\n (entity as any)[field] = value;\n }\n }\n \n // Apply record fields\n for (const [field, value] of Object.entries(recordData.fields)) {\n if (field in entity) {\n const processedValue = await this.syncEngine.processFieldValue(value, path.dirname(filePath));\n (entity as any)[field] = processedValue;\n }\n }\n \n // Save the record\n const saved = await entity.Save();\n if (!saved) {\n const message = entity.LatestResult?.Message;\n if (message) {\n throw new Error(`Failed to save record: ${message}`);\n }\n \n const errors = entity.LatestResult?.Errors?.map(err => \n typeof err === 'string' ? err : (err?.message || JSON.stringify(err))\n )?.join(', ') || 'Unknown error';\n throw new Error(`Failed to save record: ${errors}`);\n }\n \n this.log(`Successfully ${isNew ? 'created' : 'updated'} ${entityConfig.entity} record`);\n \n // Update the local file with new primary key if created\n if (isNew) {\n const entityInfo = this.syncEngine.getEntityInfo(entityConfig.entity);\n if (entityInfo) {\n const newPrimaryKey: Record<string, any> = {};\n for (const pk of entityInfo.PrimaryKeys) {\n newPrimaryKey[pk.Name] = entity.Get(pk.Name);\n }\n recordData.primaryKey = newPrimaryKey;\n \n // Update sync metadata\n recordData.sync = {\n lastModified: new Date().toISOString(),\n checksum: this.syncEngine.calculateChecksum(recordData.fields)\n };\n \n // Write back to file\n await fs.writeJson(filePath, recordData, { spaces: 2 });\n }\n }\n }\n \n private async syncExternalFile(\n filePath: string,\n entityDir: string,\n entityConfig: any\n ): Promise<void> {\n // Find the corresponding JSON file\n const fileName = path.basename(filePath);\n const parts = fileName.split('.');\n \n if (parts.length >= 3) {\n // Format: uuid.fieldname.ext\n const jsonFileName = `${parts[0]}.json`;\n const fieldName = parts[1];\n const jsonFilePath = path.join(path.dirname(filePath), jsonFileName);\n \n if (await fs.pathExists(jsonFilePath)) {\n // Update the JSON file's sync metadata to trigger a sync\n const recordData: RecordData = await fs.readJson(jsonFilePath);\n recordData.sync = {\n lastModified: new Date().toISOString(),\n checksum: recordData.sync?.checksum || ''\n };\n await fs.writeJson(jsonFilePath, recordData, { spaces: 2 });\n \n this.log(`Updated sync metadata for ${jsonFileName} due to external file change`);\n }\n }\n }\n}"]}