Skip to main content

Function: createClassFilter()

function createClassFilter(options): (doc) => boolean;

Defined in: packages/client/src/core/sync/class-filter.ts:125

Builds a class-level replication filter.

PouchDB filter functions use include-semantics: true replicates the document. The returned function is pure and carries a configuration-derived identity so that changing which classes replicate also changes the replication checkpoint - see withFilterIdentity.

Documents that carry no ~class and no ~domain pass through untouched. That matters for deletions: a tombstone is { _id, _rev, _deleted } with no class on it, and dropping those would mean a deletion never reaches the peer.

Parameters

ParameterTypeDescription
optionsClassFilterOptionsWhich classes to replicate.

Returns

A predicate suitable for replicate's filter option.

(doc): boolean;

Parameters

ParameterType
docMaybeClassedDoc

Returns

boolean

Example

const filter = createClassFilter({ include: ["Task"] });
filter({ _id: "Task-1", "~class": "Task" }); // true
filter({ _id: "Draft-1", "~class": "Draft" }); // false
filter({ _id: "Task", "~class": "class" }); // true - the data model
filter({ _id: "r1", "~domain": "TaskDraft",
sourceClass: "Task", targetClass: "Draft" }); // false - dangling end