UNPKG

alinea

Version:
49 lines (47 loc) 1.37 kB
import "../../chunks/chunk-NZLE2WMY.js"; // src/core/db/EntryDB.ts import { sourceChanges } from "./CommitRequest.js"; import { EntryTransaction } from "./EntryTransaction.js"; import { LocalDB } from "./LocalDB.js"; var EntryDB = class extends LocalDB { connect; constructor(config, source, connect) { super(config, source); this.connect = connect; } async mutate(mutations) { const from = await this.source.getTree(); const tx = new EntryTransaction(this.config, this.index, this.source, from); tx.apply(mutations); const request = await tx.toRequest(); const contentChanges = sourceChanges(request); const sha = this.indexChanges(contentChanges); return { sha: await sha, remote: sha.then(async () => { try { const remote = await this.connect(); await remote.mutate(mutations); await this.applyChanges(contentChanges); } finally { await this.syncWithRemote(); } return this.sha; }) }; } async write(request) { throw new Error("This must be implemented on the server"); } async prepareUpload(file) { const remote = await this.connect(); return remote.prepareUpload(file); } async syncWithRemote() { const remote = await this.connect(); return this.syncWith(remote); } }; export { EntryDB };