Change DB move API
This commit is contained in:
parent
a5bcaec9fe
commit
f6ee0b727b
1 changed files with 23 additions and 22 deletions
|
|
@ -88,28 +88,6 @@ export class Database {
|
||||||
await this.save();
|
await this.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async moveDocument({
|
|
||||||
documentId,
|
|
||||||
oldRelativePath,
|
|
||||||
relativePath,
|
|
||||||
parentVersionId,
|
|
||||||
hash
|
|
||||||
}: {
|
|
||||||
documentId: DocumentId;
|
|
||||||
oldRelativePath: RelativePath;
|
|
||||||
relativePath: RelativePath;
|
|
||||||
parentVersionId: VaultUpdateId;
|
|
||||||
hash: string;
|
|
||||||
}): Promise<void> {
|
|
||||||
this.documents.delete(oldRelativePath);
|
|
||||||
this.documents.set(relativePath, {
|
|
||||||
documentId,
|
|
||||||
parentVersionId,
|
|
||||||
hash
|
|
||||||
});
|
|
||||||
await this.save();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async removeDocument(relativePath: RelativePath): Promise<void> {
|
public async removeDocument(relativePath: RelativePath): Promise<void> {
|
||||||
this.documents.delete(relativePath);
|
this.documents.delete(relativePath);
|
||||||
await this.save();
|
await this.save();
|
||||||
|
|
@ -121,6 +99,29 @@ export class Database {
|
||||||
return this.documents.get(relativePath);
|
return this.documents.get(relativePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async updatePath(
|
||||||
|
oldRelativePath: RelativePath,
|
||||||
|
newRelativePath: RelativePath
|
||||||
|
): Promise<void> {
|
||||||
|
const document = this.documents.get(oldRelativePath);
|
||||||
|
if (!document) {
|
||||||
|
throw new Error(
|
||||||
|
`Cannot update physical path for document that does not exist: ${oldRelativePath}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.documents.has(newRelativePath)) {
|
||||||
|
throw new Error(
|
||||||
|
`Cannot update physical path to path that is already in use: ${newRelativePath}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.documents.delete(oldRelativePath);
|
||||||
|
this.documents.set(newRelativePath, document);
|
||||||
|
|
||||||
|
await this.save();
|
||||||
|
}
|
||||||
|
|
||||||
private async save(): Promise<void> {
|
private async save(): Promise<void> {
|
||||||
await this.saveData({
|
await this.saveData({
|
||||||
documents: Object.fromEntries(this.documents.entries()),
|
documents: Object.fromEntries(this.documents.entries()),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue