UNPKG

@thisisagile/easy

Version:

Straightforward library for building domain-driven microservice architectures

53 lines (51 loc) 1.33 kB
import { convert } from "./chunk-MJAB7NZV.mjs"; import { json } from "./chunk-A7KUHZ3A.mjs"; import { isDefined } from "./chunk-AAND4MKF.mjs"; // src/data/Condition.ts var Condition = class { constructor(key, operator, value) { this.key = key; this.operator = operator; this.value = value; } and = (...others) => new LogicalCondition("and", [this, ...others]); or = (...others) => new LogicalCondition("or", [this, ...others]); toJSON() { return { [this.key]: { [`$${this.operator}`]: json.parse(this.value) } }; } }; var LogicalCondition = class { constructor(operator, conditions) { this.operator = operator; this.conditions = conditions; } toJSON() { return { [`$${this.operator}`]: this.conditions.map((c) => c.toJSON()) }; } }; var SortCondition = class extends Condition { constructor(key, value) { super(key, "", value); this.key = key; this.value = value; } toJSON() { return { [this.key]: this.value }; } }; var toCondition = (field, operator, value, conv = convert.default) => new Condition(field, operator, conv.from(value)); var isSortCondition = (s) => isDefined(s) && s instanceof SortCondition; export { Condition, LogicalCondition, SortCondition, toCondition, isSortCondition }; //# sourceMappingURL=chunk-CR2ZP2PA.mjs.map