From d6b654cf6e5959ccf33ada391eb77acec1daea65 Mon Sep 17 00:00:00 2001 From: Steven Vandevelde Date: Thu, 21 Dec 2023 17:52:15 +0100 Subject: [PATCH] feat: add modifications to publish event --- packages/nest/src/class.ts | 22 ++++++++++++++-------- packages/nest/src/events.ts | 5 ++++- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/packages/nest/src/class.ts b/packages/nest/src/class.ts index 0d450de..283bbba 100644 --- a/packages/nest/src/class.ts +++ b/packages/nest/src/class.ts @@ -64,7 +64,10 @@ export interface FileSystemOptions { /** @group 🪺 :: START HERE */ export class FileSystem { readonly #blockstore: Blockstore - readonly #debouncedDataRootUpdate: (...dataRoots: CID[]) => Promise + readonly #debouncedDataRootUpdate: ( + ...args: Array<{ dataRoot: CID; modifications: Modification[] }> + ) => Promise + readonly #eventEmitter: Emittery readonly #onCommit: CommitVerifier readonly #rng: Rng.Rng @@ -86,10 +89,13 @@ export class FileSystem { this.#rootTree = rootTree this.#debouncedDataRootUpdate = debounce( - async (...dataRoots: CID[]): Promise => { - const dataRoot = dataRoots.at(-1) + async ( + ...args: Array<{ dataRoot: CID; modifications: Modification[] }> + ): Promise => { + const modifications = args.flatMap((a) => a.modifications) + const dataRoot = args.at(-1)?.dataRoot if (dataRoot !== undefined) { - await this.#eventEmitter.emit('publish', { dataRoot }) + await this.#eventEmitter.emit('publish', { dataRoot, modifications }) } }, settleTimeBeforePublish @@ -664,13 +670,13 @@ export class FileSystem { mutationOptions.skipPublish === false || mutationOptions.skipPublish === undefined ) { - await this.#publish(dataRoot) + await this.#publish(dataRoot, modifications) } // Fin return { - modifications, dataRoot, + modifications, } } @@ -796,8 +802,8 @@ export class FileSystem { // ㊙️ ▒▒ PUBLISHING - async #publish(dataRoot: CID): Promise { + async #publish(dataRoot: CID, modifications: Modification[]): Promise { // eslint-disable-next-line @typescript-eslint/no-floating-promises - this.#debouncedDataRootUpdate(dataRoot) + this.#debouncedDataRootUpdate({ dataRoot, modifications }) } } diff --git a/packages/nest/src/events.ts b/packages/nest/src/events.ts index ebe1f03..fa6d683 100644 --- a/packages/nest/src/events.ts +++ b/packages/nest/src/events.ts @@ -9,7 +9,10 @@ export type Events = { dataRoot: CID modifications: Modification[] } - publish: { dataRoot: CID } + publish: { + dataRoot: CID + modifications: Modification[] + } } export type Listener<