UNPKG

@decaf-ts/core

Version:

Core persistence module for the decaf framework

58 lines 2.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.OperatorsMap = void 0; const Condition_1 = require("./Condition.cjs"); /** * @description * Map of supported operators to their corresponding parser functions. * * @summary * The `OperatorsMap` defines a collection of operator names as keys * (such as `Equals`, `LessThan`, `Between`, etc.), each mapped to a * function that constructs a `Condition` object for that operator. * These functions translate query clauses into concrete condition * builders, enabling dynamic query construction from method names. * * @template T The type of the field values used in conditions. * * @param f {string} - The field name the condition applies to. * @param v1 {any} - The value to compare the field against or the lower bound value for range-based operators. * @param v2 {any} - The upper bound value for range-based operators. * * @return {Condition<any>} A condition object representing the operator applied to the field. * * @function OperatorsMap * * @mermaid * sequenceDiagram * participant Client as Caller * participant Map as OperatorsMap * participant Parser as OperatorParser * participant Cond as Condition * * Client->>Map: Request operator parser ("Between", field, v1, v2) * Map->>Parser: Call corresponding operator function * Parser->>Cond: Condition.attribute(field) * Cond-->>Parser: Condition instance * Parser->>Cond: Apply gte(v1) * Parser->>Cond: Apply and(lte(v2)) * Parser-->>Client: Return built Condition * * @memberOf module:query */ exports.OperatorsMap = { Equals: (f, v) => Condition_1.Condition.attribute(f).eq(v), Diff: (f, v) => Condition_1.Condition.attribute(f).dif(v), LessThan: (f, v) => Condition_1.Condition.attribute(f).lt(v), LessThanEqual: (f, v) => Condition_1.Condition.attribute(f).lte(v), GreaterThan: (f, v) => Condition_1.Condition.attribute(f).gt(v), GreaterThanEqual: (f, v) => Condition_1.Condition.attribute(f).gte(v), // Between deprecated due to GreaterThan/LessThanEqual // Between: (f, v1, v2) => // Condition.attribute(f as any) // .gte(v1) // .and(Condition.attribute(f as any).lte(v2)), In: (f, v) => Condition_1.Condition.attribute(f).in(v), Matches: (f, v) => Condition_1.Condition.attribute(f).regexp(v), }; //# sourceMappingURL=utils.js.map