sveltekit-sync
Version:
Local-first sync engine for SvelteKit
34 lines (33 loc) • 1.85 kB
TypeScript
export declare const OPERATOR_SYMBOL: unique symbol;
export type OperatorType = 'eq' | 'ne' | 'gt' | 'gte' | 'lt' | 'lte' | 'in' | 'notIn' | 'contains' | 'startsWith' | 'endsWith' | 'between' | 'isNull' | 'isNotNull';
export interface QueryOperator<T = any> {
[OPERATOR_SYMBOL]: true;
type: OperatorType;
value: T;
}
export declare function isOperator(value: any): value is QueryOperator;
export declare const eq: <T>(value: T) => QueryOperator<T>;
export declare const ne: <T>(value: T) => QueryOperator<T>;
export declare const gt: <T>(value: T) => QueryOperator<T>;
export declare const gte: <T>(value: T) => QueryOperator<T>;
export declare const lt: <T>(value: T) => QueryOperator<T>;
export declare const lte: <T>(value: T) => QueryOperator<T>;
export declare const inArray: <T>(values: T[]) => QueryOperator<T[]>;
export declare const notInArray: <T>(values: T[]) => QueryOperator<T[]>;
export declare const contains: (value: string) => QueryOperator<string>;
export declare const startsWith: (value: string) => QueryOperator<string>;
export declare const endsWith: (value: string) => QueryOperator<string>;
export declare const between: <T>(min: T, max: T) => QueryOperator<[T, T]>;
export declare const isNull: () => QueryOperator<null>;
export declare const isNotNull: () => QueryOperator<null>;
export type LogicalOperator<T> = {
[OPERATOR_SYMBOL]: true;
type: 'and' | 'or' | 'not';
conditions: WhereCondition<T>[];
};
export type WhereCondition<T> = ((item: T) => boolean) | Partial<{
[K in keyof T]: T[K] | QueryOperator<T[K]>;
}> | LogicalOperator<T>;
export declare function and<T>(...conditions: WhereCondition<T>[]): LogicalOperator<T>;
export declare function or<T>(...conditions: WhereCondition<T>[]): LogicalOperator<T>;
export declare function not<T>(condition: WhereCondition<T>): LogicalOperator<T>;