Skip to content

Commit

Permalink
ADD postCleanup hook
Browse files Browse the repository at this point in the history
  • Loading branch information
pubkey committed Aug 19, 2024
1 parent 1689571 commit 2ecda43
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# RxDB Changelog

<!-- CHANGELOG NEWEST -->
- ADD `postCleanup` hook.

<!-- ADD new changes here! -->

Expand Down
3 changes: 3 additions & 0 deletions src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/attachments/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';



Expand Down
6 changes: 6 additions & 0 deletions src/plugins/cleanup/cleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -93,6 +94,11 @@ export async function cleanupRxCollection(
});
isDone = await RXSTORAGE_CLEANUP_QUEUE;
}

await runAsyncPluginHooks('postCleanup', {
collectionName: rxCollection.name,
databaseName: rxDatabase.name
});
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/types/rx-plugin.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ export interface RxPlugin {
}>;
preMigrateDocument?: RxPluginHooks<any>;
postMigrateDocument?: RxPluginHooks<any>;
postCleanup?: RxPluginHooks<{
databaseName: string;
collectionName: string;
}>;
preReplicationMasterWrite?: RxPluginHooks<{
rows: RxReplicationWriteToMasterRow<any>[];
collection: RxCollection;
Expand Down

0 comments on commit 2ecda43

Please sign in to comment.