sveltekit-sync
Version:
Local-first sync engine for SvelteKit
37 lines (36 loc) • 1.67 kB
JavaScript
// These create operator objects that can be used in object syntax queries
export const OPERATOR_SYMBOL = Symbol('query-operator');
function createOperator(type, value) {
return { [OPERATOR_SYMBOL]: true, type, value };
}
export function isOperator(value) {
return value !== null && typeof value === 'object' && OPERATOR_SYMBOL in value;
}
// Comparison operators
export const eq = (value) => createOperator('eq', value);
export const ne = (value) => createOperator('ne', value);
export const gt = (value) => createOperator('gt', value);
export const gte = (value) => createOperator('gte', value);
export const lt = (value) => createOperator('lt', value);
export const lte = (value) => createOperator('lte', value);
// Array operators
export const inArray = (values) => createOperator('in', values);
export const notInArray = (values) => createOperator('notIn', values);
// String operators
export const contains = (value) => createOperator('contains', value);
export const startsWith = (value) => createOperator('startsWith', value);
export const endsWith = (value) => createOperator('endsWith', value);
// Range operator
export const between = (min, max) => createOperator('between', [min, max]);
// Null operators
export const isNull = () => createOperator('isNull', null);
export const isNotNull = () => createOperator('isNotNull', null);
export function and(...conditions) {
return { [OPERATOR_SYMBOL]: true, type: 'and', conditions };
}
export function or(...conditions) {
return { [OPERATOR_SYMBOL]: true, type: 'or', conditions };
}
export function not(condition) {
return { [OPERATOR_SYMBOL]: true, type: 'not', conditions: [condition] };
}