Creates a new SyncEngine instance
The user context for database operations
Build cascading defaults for a file path and process field values
Walks up the directory tree from the file location, collecting defaults from entity config and folder configs, with deeper folders overriding parent values. All default values are processed for special references.
Path to the file being processed
Entity configuration containing base defaults
Processed defaults with all references resolved
Calculate SHA256 checksum for data
Generates a deterministic hash of the provided data by converting it to formatted JSON and calculating a SHA256 digest. Used for change detection in sync operations.
Any data structure to calculate checksum for
Hexadecimal string representation of the SHA256 hash
Calculate checksum including resolved file content
Enhanced checksum calculation that resolves
Fields object that may contain
Directory for resolving relative file paths
Promise resolving to checksum string
Create a new entity object instance
Uses the MemberJunction metadata system to properly instantiate an entity object. This ensures correct class registration and respects any custom entity subclasses.
Name of the entity to create
Promise resolving to the new BaseEntity instance
Get entity metadata information by name
Retrieves the EntityInfo object containing schema metadata for the specified entity. Returns null if the entity is not found in the metadata cache.
Name of the entity to look up
EntityInfo object with schema details or null if not found
Returns the metadata provider this engine is using.
mj sync runs as a single-purpose CLI process with one configured
provider per run, so this proxies to the global default (the only
provider the process will ever see). Surfacing it through SyncEngine
keeps callers from reaching for Metadata.Provider directly and makes
it obvious which provider the sync is bound to.
Initializes the sync engine by refreshing metadata cache
Promise that resolves when initialization is complete
Load an entity record by primary key
Retrieves an existing entity record from the database using its primary key values. Supports both single and composite primary keys. Returns null if the record is not found.
Name of the entity to load
Object containing primary key field names and values
Promise resolving to the loaded entity or null if not found
Process special references in field values and handle complex objects
Automatically handles:
Handles the following reference types for string values:
@parent:fieldName - References a field from the parent record@root:fieldName - References a field from the root record@file:path - Reads content from an external file@url:address - Fetches content from a URL@lookup:Entity.Field=Value - Looks up an entity ID by field value@env:VARIABLE - Reads an environment variableThe field value to process
Base directory for resolving relative file paths
OptionalparentRecord: BatchContextStub | BaseEntity<unknown>Optional parent entity for
OptionalrootRecord: BatchContextStub | BaseEntity<unknown>Optional root entity for
Current recursion depth (for preventing infinite loops)
OptionalbatchContext: BatchContextOptional batch context for in-memory entity resolution
OptionalresolutionCollector: SyncResolutionCollectorOptional collector for tracking
OptionalfieldName: stringOptional field name for tracking resolutions
The processed value with all references resolved
// File reference
const content = await processFieldValue('@file:template.md', '/path/to/dir');
// Lookup with auto-create
const userId = await processFieldValue('@lookup:Users.Email=john@example.com?create', '/path');
// Complex object - automatically stringified
const jsonStr = await processFieldValue({items: [{id: 1}, {id: 2}]}, '/path');
// Returns: '{\n "items": [\n {\n "id": 1\n },\n {\n "id": 2\n }\n ]\n}'
// With resolution collector for tracking
const collector: SyncResolutionCollector = { notes: [], fieldPrefix: 'fields' };
const result = await processFieldValue('@lookup:Users.Email=admin@example.com', '/path', null, null, 0, undefined, collector, 'UserID');
// collector.notes will contain the resolution info
OptionalbatchContext: BatchContextOptionaloriginalValue: string
Core engine for synchronizing MemberJunction metadata between database and files
SyncEngine
Example