From c172413377a2e653d503737fc0b82784c3aa22d2 Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Mon, 21 Feb 2022 23:40:27 +0000 Subject: [PATCH] fix: support waiting for sent/real event from PendingBranchEvent --- src/PendingBranchEntry.ts | 42 +++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/src/PendingBranchEntry.ts b/src/PendingBranchEntry.ts index 7e440b9..147571b 100644 --- a/src/PendingBranchEntry.ts +++ b/src/PendingBranchEntry.ts @@ -89,29 +89,55 @@ export class PendingBranchEntry extends AutoBindingEmitter implements IFileEntry return this.date; } + private async waitForRealEntry() { + this.trace('waitForRealEntry'); + await this.sentPromise; + return this.files.getDescendantById(this.id); + } + async delete() { this.trace('delete', this.path.join('/')); - throw new Error('Unable to delete pending branch'); + const real = await this.waitForRealEntry(); + if (!real) { + throw new Error('Unable to delete pending branch'); + } + return real.delete(); } async rename(name: string) { this.trace('rename', `${this.path.join('/')} to ${name}`); - throw new Error('Unable to rename pending branch'); + const real = await this.waitForRealEntry(); + if (!real) { + throw new Error('Unable to rename pending branch'); + } + return real.rename(name); } async copyAsVersion(fileTo: IFileEntry): Promise { this.trace('copyAsVersion', `${this.path.join('/')} to ${fileTo.path.join('/')}`); - throw new Error('Unable to copy pending branch'); + const real = await this.waitForRealEntry(); + if (!real) { + throw new Error('Unable to copy pending branch'); + } + return (real as IFileEntry).copyAsVersion(fileTo); } async copyTo(resolvedParent: IFolderEntry, fileName: string): Promise { this.trace('copyTo', `${this.path.join('/')} to ${resolvedParent.path.join('/')}/${fileName}`); - throw new Error('Unable to copy pending branch'); + const real = await this.waitForRealEntry(); + if (!real) { + throw new Error('Unable to copy pending branch'); + } + return this.copyTo(resolvedParent, fileName); } async moveTo(resolvedParent: IFolderEntry, fileName: string): Promise { this.trace('moveTo', `${this.path.join('/')} to ${resolvedParent.path.join('/')}/${fileName}`); - throw new Error('Unable to move pending branch'); + const real = await this.waitForRealEntry(); + if (!real) { + throw new Error('Unable to move pending branch'); + } + return this.moveTo(resolvedParent, fileName); } private async createNewVersion( @@ -209,6 +235,10 @@ export class PendingBranchEntry extends AutoBindingEmitter implements IFileEntry locked = false; async setLocked(locked: boolean): Promise { - throw new Error('Unable to lock pending branch'); + const real = await this.waitForRealEntry(); + if (!real) { + throw new Error('Unable to lock pending branch'); + } + return (real as IFileEntry).setLocked(locked); } }