Phase 2: Analyze dependencies across all collected records globally.
This method should be called AFTER all files have been processed with flattenFileRecords().
It resolves @lookup, @parent,
All flattened records from all metadata files
Analysis result with sorted records, circular dependencies, etc.
Main entry point: analyzes all records in a file and returns them in dependency order.
The records from a metadata file
The root entity name for these records
Analysis result with sorted records
Build reverse dependency map from forward dependencies Maps: record ID -> list of records that depend on it
This is essential for deletion ordering - we need to know what depends on a record before we can safely delete it.
Find all transitive dependents of a set of records This is useful for finding all records that must be deleted when deleting a parent
Set of record IDs to find dependents for
Reverse dependency map
Set of all record IDs that depend on the input records (transitively)
Phase 1: Flatten records from a single file without analyzing dependencies.
This method flattens records including nested relatedEntities and assigns unique IDs, but does NOT analyze dependencies. Use this when collecting records from multiple files before running global dependency analysis.
After collecting records from all files, call analyzeAllDependencies() to resolve
cross-file dependencies.
The records from a metadata file
The root entity name for these records
Flattened records (dependencies not yet resolved)
Resets the analyzer state. Call this before starting a new batch of files.
Perform reverse topological sort for deletion order Returns records grouped by dependency level, with leaf nodes (highest dependency level) first
For deletions, we want to delete in reverse order of creation:
This is simply the reverse of the forward topological sort used for creates.
Analyzes and sorts records based on their dependencies