rxdb
Version:
A local-first realtime NoSQL Database for JavaScript applications - https://rxdb.info/
67 lines (66 loc) • 2.42 kB
TypeScript
import type { RxCollection } from '../../types/index.d.ts';
import type { RxReplicationState } from '../replication/index.ts';
export type ReplicationBaseTestSuiteConfig = {
/**
* Start a live replication for a collection.
* Must target a shared server endpoint so that multiple
* collections can replicate to the same backend.
*/
startReplication(collection: RxCollection<any>): RxReplicationState<any, any>;
/**
* Run a one-shot (non-live) sync and wait for completion.
* Must target the same server endpoint as startReplication.
*/
syncOnce(collection: RxCollection<any>): Promise<void>;
/**
* Get all documents from the server,
* including soft-deleted ones when the backend uses soft deletes.
*/
getAllServerDocs(): Promise<any[]>;
/**
* Remove all documents from the server.
*/
cleanUpServer(): Promise<void>;
/**
* Whether the server uses soft deletes
* (marks docs as deleted instead of removing them).
*/
softDeletes: boolean;
/**
* Check if a server document is marked as deleted.
* Required when softDeletes is true.
*/
isDeleted?(serverDoc: any): boolean;
/**
* Get the client primary key (passportId) from a server document.
* Different backends store the primary key in different fields.
*/
getPrimaryOfServerDoc(serverDoc: any): string;
/**
* Additional wait time for eventually consistent backends (ms).
*/
waitTime?: number;
};
/**
* Runs the base test suite for a replication plugin.
* Call this inside a describe() block in your replication test file.
*
* The config callbacks should target a shared server endpoint.
* Each test calls cleanUpServer() at the start to ensure a clean state.
*
* @example
* ```ts
* describe('replication-nats.test.ts', () => {
* runReplicationBaseTestSuite({
* startReplication: (collection) => syncNats(collection, natsName),
* syncOnce: (collection) => syncOnceNats(collection, natsName),
* getAllServerDocs: () => getAllDocsOfServer(natsName),
* cleanUpServer: async () => { ... },
* softDeletes: true,
* isDeleted: (doc) => doc._deleted,
* getPrimaryOfServerDoc: (doc) => doc.passportId,
* });
* });
* ```
*/
export declare function runReplicationBaseTestSuite(config: ReplicationBaseTestSuiteConfig): void;