From 2ecda432177350e134434efad89608e0b98eef52 Mon Sep 17 00:00:00 2001 From: pubkey <8926560+pubkey@users.noreply.github.com> Date: Mon, 19 Aug 2024 16:31:28 +0200 Subject: [PATCH] ADD postCleanup hook --- CHANGELOG.md | 1 + src/hooks.ts | 3 +++ src/plugins/attachments/index.ts | 5 ++++- src/plugins/cleanup/cleanup.ts | 6 ++++++ src/types/rx-plugin.d.ts | 4 ++++ 5 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 50fe68cae2b..2c19f152a84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ # RxDB Changelog +- ADD `postCleanup` hook. diff --git a/src/hooks.ts b/src/hooks.ts index 27c9360658b..497c4d5a0d8 100644 --- a/src/hooks.ts +++ b/src/hooks.ts @@ -83,6 +83,9 @@ export const HOOKS: { [k: string]: any[]; } = { */ postRemoveRxDatabase: [], + + postCleanup: [], + /** * runs before the replication writes the rows to master * but before the rows have been modified diff --git a/src/plugins/attachments/index.ts b/src/plugins/attachments/index.ts index db76e71e774..34543468d52 100644 --- a/src/plugins/attachments/index.ts +++ b/src/plugins/attachments/index.ts @@ -19,7 +19,10 @@ import type { RxAttachmentCreator, RxAttachmentWriteData } from '../../types/index.ts'; -import { assignMethodsToAttachment, ensureSchemaSupportsAttachments } from './attachments-utils.ts'; +import { + assignMethodsToAttachment, + ensureSchemaSupportsAttachments +} from './attachments-utils.ts'; diff --git a/src/plugins/cleanup/cleanup.ts b/src/plugins/cleanup/cleanup.ts index 47c60ec187d..df21a92d1c6 100644 --- a/src/plugins/cleanup/cleanup.ts +++ b/src/plugins/cleanup/cleanup.ts @@ -2,6 +2,7 @@ import type { RxCleanupPolicy, RxCollection } from '../../types/index.d.ts'; import { PROMISE_RESOLVE_TRUE } from '../../plugins/utils/index.ts'; import { REPLICATION_STATE_BY_COLLECTION } from '../replication/index.ts'; import { DEFAULT_CLEANUP_POLICY } from './cleanup-helper.ts'; +import { runAsyncPluginHooks } from 'rxdb-old'; /** * Even on multiple databases, @@ -93,6 +94,11 @@ export async function cleanupRxCollection( }); isDone = await RXSTORAGE_CLEANUP_QUEUE; } + + await runAsyncPluginHooks('postCleanup', { + collectionName: rxCollection.name, + databaseName: rxDatabase.name + }); } /** diff --git a/src/types/rx-plugin.d.ts b/src/types/rx-plugin.d.ts index d6c3fcce5ae..36213a0f976 100644 --- a/src/types/rx-plugin.d.ts +++ b/src/types/rx-plugin.d.ts @@ -144,6 +144,10 @@ export interface RxPlugin { }>; preMigrateDocument?: RxPluginHooks; postMigrateDocument?: RxPluginHooks; + postCleanup?: RxPluginHooks<{ + databaseName: string; + collectionName: string; + }>; preReplicationMasterWrite?: RxPluginHooks<{ rows: RxReplicationWriteToMasterRow[]; collection: RxCollection;