Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | /**
* Sync Factory
*
* Factory for creating sync service instances based on publisher configuration type.
* Routes to the appropriate sync implementation (folder, github, sysgit).
*/
import { FolderSync } from './folder/folder-sync.js';
import { GithubSync } from './github/github-sync.js';
import { SysgitSync } from './sysgit/sysgit-sync.js';
import { GitSync } from './git/git-sync.js';
/**
* SyncFactory creates sync service instances based on publisher configuration
*/
export class SyncFactory {
dependencies;
/**
* Set dependencies for sync services
* This should be called once during app initialization
*/
setDependencies(dependencies) {
this.dependencies = dependencies;
}
/**
* Get a sync service instance for the given publisher configuration
*
* @param publisherConfig - The publisher configuration (folder, github, or sysgit)
* @param siteKey - The site key
* @param workspaceKey - The workspace key
* @param progressCallback - Optional callback for streaming progress (overrides default)
* @returns A sync service instance
* @throws Error if the sync type is not implemented or dependencies not set
*/
getPublisher(publisherConfig, siteKey, workspaceKey, progressCallback) {
if (!this.dependencies) {
throw new Error('SyncFactory dependencies not set. Call setDependencies() first.');
}
// Create dependencies with optional progress callback override and workspaceKey
const deps = {
...this.dependencies,
workspaceKey,
progressCallback: progressCallback ?? this.dependencies.progressCallback,
};
const type = publisherConfig.type;
switch (type) {
case 'folder':
return new FolderSync(publisherConfig, siteKey, deps);
case 'github':
return new GithubSync(publisherConfig, siteKey, deps);
case 'sysgit':
return new SysgitSync(publisherConfig, siteKey, deps);
case 'git':
return new GitSync(publisherConfig, siteKey, deps);
default:
throw new Error(`Unknown sync type: ${type}`);
}
}
}
|