collectype / factory/queries/queryKey / queryKeyFactory
queryKeyFactory<
T,C>(ctx,oper): <K>(field,target) =>C
Defined in: factory/queries/queryKey.ts:39
Creates a predicate filter for query key checks using PredicType.query.key.
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.
QueryKeyOper
The query key operation to perform.
Returns a function that takes a query field on T, checks a key, and filters the context.
<K>(field, target) => C
// Example: query key filter with URL
import { BaseFunctions, queryKeyFactory } from 'collectype';
type Post = { id: number; query: URL };
class PostFunctions extends BaseFunctions<Post> {
queryContainsKey = queryKeyFactory<Post, this>(this, 'contains_key');
}
const posts: Post[] = [
{ id: 1, query: new URL('https://example.com/?tag=ts&tag=ai') },
{ id: 2, query: new URL('https://example.com/?q=docs') }
];
const fn = new PostFunctions(posts);
const filtered = fn.queryContainsKey('query', 'q');
// filtered contains items whose query has the key 'q'
URL and URLSearchParams.PredicType.query.key.