collectype / factory/sets/setRelation / setRelationFactory
setRelationFactory<
T,C>(ctx,oper): <K>(field,target) =>C
Defined in: factory/sets/setRelation.ts:40
Creates a predicate filter for set relations using PredicType.set.relation.
T
The item type in the collection.
C extends Wherable<T, C>
The Wherable context type (must extend Wherable<T, C>).
C
The context (usually a collection) supporting the where method.
SetRelationOper
The set relation operation to perform (see PredicType.set.relation).
Returns a function that takes a field (of type Set on T) and a target set, and applies the set relation predicate to filter the context.
<
K>(field,target):C
K extends string | number | symbol
K
Set<unknown>
C
// Example: Composing a set relation filter as a property, homogeneous model
import { BaseFunctions } from 'collectype';
import { setRelationFactory } from 'collectype';
type Person = { name: string; tags: Set<string> };
class PersonFunctions extends BaseFunctions<Person> {
setIsSubset = setRelationFactory<Person, this>(this, 'isSubset');
}
// Usage:
const people: Person[] = [
{ name: 'Alice', tags: new Set(['a', 'b']) },
{ name: 'Bob', tags: new Set(['a']) },
{ name: 'Eve', tags: new Set(['b']) }
];
const fn = new PersonFunctions(people);
const filtered = fn.setIsSubset('tags', new Set(['a', 'b', 'c']));
// filtered contains the items where 'tags' is a subset of Set(['a', 'b', 'c'])
PredicType.set.relation for set relation checks on set fields.