UNPKG

@react-awesome-query-builder/core

Version:
1,244 lines (1,237 loc) 76.2 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = exports.ConfigMixins = void 0; var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")); var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _default2 = require("./default"); var _ctx = _interopRequireDefault(require("./ctx")); function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; } function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } } function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } //---------------------------- conjunctions var conjunctions = { AND: { label: "And", mongoConj: "$and", jsonLogicConj: "and", sqlConj: "AND", spelConj: "and", spelConjs: ["and", "&&"], reversedConj: "OR", formatConj: function formatConj(children, conj, not, isForDisplay) { var ret = children.size > 1 ? children.join(" " + (isForDisplay ? "AND" : "&&") + " ") : children.first(); if (children.size > 1 || not) { ret = this.utils.wrapWithBrackets(ret); } if (not) { ret = "NOT " + ret; } return ret; }, sqlFormatConj: function sqlFormatConj(children, conj, not) { var ret = children.size > 1 ? children.join(" " + "AND" + " ") : children.first(); if (children.size > 1 || not) { ret = this.utils.wrapWithBrackets(ret); } if (not) { ret = "NOT " + ret; } return ret; }, spelFormatConj: function spelFormatConj(children, conj, not, omitBrackets) { if (not) omitBrackets = false; var ret = children.size > 1 ? children.join(" " + "&&" + " ") : children.first(); if ((children.size > 1 || not) && !omitBrackets) { ret = this.utils.wrapWithBrackets(ret); } if (not) { ret = "!" + ret; } return ret; } }, OR: { label: "Or", mongoConj: "$or", jsonLogicConj: "or", sqlConj: "OR", spelConj: "or", spelConjs: ["or", "||"], reversedConj: "AND", formatConj: function formatConj(children, conj, not, isForDisplay) { return children.size > 1 ? (not ? "NOT " : "") + "(" + children.join(" " + (isForDisplay ? "OR" : "||") + " ") + ")" : (not ? "NOT (" : "") + children.first() + (not ? ")" : ""); }, sqlFormatConj: function sqlFormatConj(children, conj, not) { var ret = children.size > 1 ? children.join(" " + "OR" + " ") : children.first(); if (children.size > 1 || not) { ret = this.utils.wrapWithBrackets(ret); } if (not) { ret = "NOT " + ret; } return ret; }, spelFormatConj: function spelFormatConj(children, conj, not, omitBrackets) { if (not) omitBrackets = false; return children.size > 1 ? (not ? "!" : "") + (omitBrackets ? "" : "(") + children.join(" " + "||" + " ") + (omitBrackets ? "" : ")") : (not ? "!(" : "") + children.first() + (not ? ")" : ""); } } }; //---------------------------- operators var operators = { equal: { label: "==", labelForFormat: "==", sqlOp: "=", spelOp: "==", spelOps: ["==", "eq"], reversedOp: "not_equal", formatOp: function formatOp(field, op, value, valueSrcs, valueTypes, opDef, operatorOptions, isForDisplay, fieldDef) { var opStr = isForDisplay ? "=" : opDef.label; if (valueTypes == "boolean" && isForDisplay) return value == "No" ? "NOT ".concat(field) : "".concat(field);else return "".concat(field, " ").concat(opStr, " ").concat(value); }, mongoFormatOp: function mongoFormatOp() { var _this$utils; for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return (_this$utils = this.utils).mongoFormatOp1.apply(_this$utils, ["$eq", function (v) { return v; }, false].concat(args)); }, jsonLogic2: "==", jsonLogicOps: ["==", "datetime==", "date=="], jsonLogic: function jsonLogic(field, op, val, _opDef, _opOpts, _fieldDef, expectedType, settings) { if (settings !== null && settings !== void 0 && settings.fixJsonLogicDateCompareOp && ["date", "datetime"].includes(expectedType)) { return (0, _defineProperty2["default"])({}, "".concat(expectedType, "=="), [field, val]); } return { "==": [field, val] }; }, elasticSearchQueryType: "term" }, not_equal: { isNotOp: true, label: "!=", labelForFormat: "!=", sqlOp: "<>", sqlOps: ["<>", "!="], spelOp: "!=", spelOps: ["!=", "ne"], reversedOp: "equal", formatOp: function formatOp(field, op, value, valueSrcs, valueTypes, opDef, operatorOptions, isForDisplay, fieldDef) { if (valueTypes == "boolean" && isForDisplay) return value == "No" ? "".concat(field) : "NOT ".concat(field);else return "".concat(field, " ").concat(opDef.label, " ").concat(value); }, mongoFormatOp: function mongoFormatOp() { var _this$utils2; for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { args[_key2] = arguments[_key2]; } return (_this$utils2 = this.utils).mongoFormatOp1.apply(_this$utils2, ["$ne", function (v) { return v; }, false].concat(args)); }, jsonLogic2: "!=", jsonLogicOps: ["!=", "datetime!=", "date!="], jsonLogic: function jsonLogic(field, op, val, _opDef, _opOpts, _fieldDef, expectedType, settings) { if (settings !== null && settings !== void 0 && settings.fixJsonLogicDateCompareOp && ["date", "datetime"].includes(expectedType)) { return (0, _defineProperty2["default"])({}, "".concat(expectedType, "!="), [field, val]); } return { "!=": [field, val] }; } }, less: { label: "<", labelForFormat: "<", sqlOp: "<", spelOp: "<", spelOps: ["<", "lt"], reversedOp: "greater_or_equal", mongoFormatOp: function mongoFormatOp() { var _this$utils3; for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { args[_key3] = arguments[_key3]; } return (_this$utils3 = this.utils).mongoFormatOp1.apply(_this$utils3, ["$lt", function (v) { return v; }, false].concat(args)); }, jsonLogic: "<", elasticSearchQueryType: "range" }, less_or_equal: { label: "<=", labelForFormat: "<=", sqlOp: "<=", spelOp: "<=", spelOps: ["<=", "le"], reversedOp: "greater", mongoFormatOp: function mongoFormatOp() { var _this$utils4; for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) { args[_key4] = arguments[_key4]; } return (_this$utils4 = this.utils).mongoFormatOp1.apply(_this$utils4, ["$lte", function (v) { return v; }, false].concat(args)); }, jsonLogic: "<=", elasticSearchQueryType: "range" }, greater: { label: ">", labelForFormat: ">", sqlOp: ">", spelOp: ">", spelOps: [">", "gt"], reversedOp: "less_or_equal", mongoFormatOp: function mongoFormatOp() { var _this$utils5; for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) { args[_key5] = arguments[_key5]; } return (_this$utils5 = this.utils).mongoFormatOp1.apply(_this$utils5, ["$gt", function (v) { return v; }, false].concat(args)); }, jsonLogic: ">", elasticSearchQueryType: "range" }, greater_or_equal: { label: ">=", labelForFormat: ">=", sqlOp: ">=", spelOp: ">=", spelOps: [">=", "ge"], reversedOp: "less", mongoFormatOp: function mongoFormatOp() { var _this$utils6; for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) { args[_key6] = arguments[_key6]; } return (_this$utils6 = this.utils).mongoFormatOp1.apply(_this$utils6, ["$gte", function (v) { return v; }, false].concat(args)); }, jsonLogic: ">=", elasticSearchQueryType: "range" }, like: { label: "Contains", labelForFormat: "Contains", reversedOp: "not_like", sqlOp: "LIKE", // tip: this function covers import of 3 operators sqlImport: function sqlImport(sqlObj, _, sqlDialect) { if ((sqlObj === null || sqlObj === void 0 ? void 0 : sqlObj.operator) == "LIKE" || (sqlObj === null || sqlObj === void 0 ? void 0 : sqlObj.operator) == "NOT LIKE") { var _right$valueType; var not = (sqlObj === null || sqlObj === void 0 ? void 0 : sqlObj.operator) == "NOT LIKE"; var _ref3 = sqlObj.children || [], _ref4 = (0, _slicedToArray2["default"])(_ref3, 2), _left = _ref4[0], right = _ref4[1]; if (right !== null && right !== void 0 && (_right$valueType = right.valueType) !== null && _right$valueType !== void 0 && _right$valueType.endsWith("_quote_string")) { if (right !== null && right !== void 0 && right.value.startsWith("%") && right !== null && right !== void 0 && right.value.endsWith("%")) { right.value = this.utils.SqlString.unescapeLike(right.value.substring(1, right.value.length - 1), sqlDialect); sqlObj.operator = not ? "not_like" : "like"; return sqlObj; } else if (right !== null && right !== void 0 && right.value.startsWith("%")) { right.value = this.utils.SqlString.unescapeLike(right.value.substring(1), sqlDialect); sqlObj.operator = "ends_with"; return sqlObj; } else if (right !== null && right !== void 0 && right.value.endsWith("%")) { right.value = this.utils.SqlString.unescapeLike(right.value.substring(0, right.value.length - 1), sqlDialect); sqlObj.operator = "starts_with"; return sqlObj; } } } }, spelOp: "${0}.contains(${1})", valueTypes: ["text"], mongoFormatOp: function mongoFormatOp() { var _this$utils7, _this = this; for (var _len7 = arguments.length, args = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) { args[_key7] = arguments[_key7]; } return (_this$utils7 = this.utils).mongoFormatOp1.apply(_this$utils7, ["$regex", function (v) { return typeof v == "string" ? _this.utils.escapeRegExp(v) : undefined; }, false].concat(args)); }, jsonLogic: function jsonLogic(field, op, val) { return { "in": [val, field] }; }, jsonLogic2: "#in", valueSources: ["value"], elasticSearchQueryType: "regexp" }, not_like: { isNotOp: true, label: "Not contains", reversedOp: "like", labelForFormat: "Not Contains", sqlOp: "NOT LIKE", mongoFormatOp: function mongoFormatOp() { var _this$utils8, _this2 = this; for (var _len8 = arguments.length, args = new Array(_len8), _key8 = 0; _key8 < _len8; _key8++) { args[_key8] = arguments[_key8]; } return (_this$utils8 = this.utils).mongoFormatOp1.apply(_this$utils8, ["$regex", function (v) { return typeof v == "string" ? _this2.utils.escapeRegExp(v) : undefined; }, true].concat(args)); }, jsonLogic: function jsonLogic(field, op, val) { return { "!": { "in": [val, field] } }; }, jsonLogic2: "#!in", _jsonLogicIsExclamationOp: true, valueSources: ["value"] }, starts_with: { label: "Starts with", labelForFormat: "Starts with", sqlOp: "LIKE", spelOp: "${0}.startsWith(${1})", mongoFormatOp: function mongoFormatOp() { var _this$utils9, _this3 = this; for (var _len9 = arguments.length, args = new Array(_len9), _key9 = 0; _key9 < _len9; _key9++) { args[_key9] = arguments[_key9]; } return (_this$utils9 = this.utils).mongoFormatOp1.apply(_this$utils9, ["$regex", function (v) { return typeof v == "string" ? "^" + _this3.utils.escapeRegExp(v) : undefined; }, false].concat(args)); }, jsonLogic: undefined, // not supported valueSources: ["value"] }, ends_with: { label: "Ends with", labelForFormat: "Ends with", sqlOp: "LIKE", spelOp: "${0}.endsWith(${1})", mongoFormatOp: function mongoFormatOp() { var _this$utils10, _this4 = this; for (var _len10 = arguments.length, args = new Array(_len10), _key10 = 0; _key10 < _len10; _key10++) { args[_key10] = arguments[_key10]; } return (_this$utils10 = this.utils).mongoFormatOp1.apply(_this$utils10, ["$regex", function (v) { return typeof v == "string" ? _this4.utils.escapeRegExp(v) + "$" : undefined; }, false].concat(args)); }, jsonLogic: undefined, // not supported valueSources: ["value"] }, between: { label: "Between", labelForFormat: "BETWEEN", sqlOp: "BETWEEN", cardinality: 2, formatOp: function formatOp(field, op, values, valueSrcs, valueTypes, opDef, operatorOptions, isForDisplay) { var valFrom = values.first(); var valTo = values.get(1); if (isForDisplay) return "".concat(field, " BETWEEN ").concat(valFrom, " AND ").concat(valTo);else return "".concat(field, " >= ").concat(valFrom, " && ").concat(field, " <= ").concat(valTo); }, // tip: this op can be imported from SpEL manually without using config spelFormatOp: function spelFormatOp(field, op, values, valueSrc, valueTypes, opDef, operatorOptions, fieldDef) { var valFrom = values[0]; var valTo = values[1]; return "(".concat(field, " >= ").concat(valFrom, " && ").concat(field, " <= ").concat(valTo, ")"); }, mongoFormatOp: function mongoFormatOp() { var _this$utils11; for (var _len11 = arguments.length, args = new Array(_len11), _key11 = 0; _key11 < _len11; _key11++) { args[_key11] = arguments[_key11]; } return (_this$utils11 = this.utils).mongoFormatOp2.apply(_this$utils11, [["$gte", "$lte"], false].concat(args)); }, valueLabels: ["Value from", "Value to"], textSeparators: [null, "and"], reversedOp: "not_between", jsonLogic: "<=", validateValues: function validateValues(values) { if (values[0] != undefined && values[1] != undefined) { return values[0] <= values[1]; } return null; }, elasticSearchQueryType: function elasticSearchQueryType(type) { return type === "time" ? "filter" : "range"; } }, not_between: { isNotOp: true, label: "Not between", labelForFormat: "NOT BETWEEN", sqlOp: "NOT BETWEEN", cardinality: 2, formatOp: function formatOp(field, op, values, valueSrcs, valueTypes, opDef, operatorOptions, isForDisplay) { var valFrom = values.first(); var valTo = values.get(1); if (isForDisplay) return "".concat(field, " NOT BETWEEN ").concat(valFrom, " AND ").concat(valTo);else return "(".concat(field, " < ").concat(valFrom, " || ").concat(field, " > ").concat(valTo, ")"); }, spelFormatOp: function spelFormatOp(field, op, values, valueSrc, valueTypes, opDef, operatorOptions, fieldDef) { var valFrom = values[0]; var valTo = values[1]; return "(".concat(field, " < ").concat(valFrom, " || ").concat(field, " > ").concat(valTo, ")"); }, mongoFormatOp: function mongoFormatOp() { var _this$utils12; for (var _len12 = arguments.length, args = new Array(_len12), _key12 = 0; _key12 < _len12; _key12++) { args[_key12] = arguments[_key12]; } return (_this$utils12 = this.utils).mongoFormatOp2.apply(_this$utils12, [["$gte", "$lte"], true].concat(args)); }, valueLabels: ["Value from", "Value to"], textSeparators: [null, "and"], reversedOp: "between", jsonLogic: function jsonLogic(field, op, val) { return { "!": { "<=": [Array.isArray(val) ? val[0] : val, field, Array.isArray(val) ? val[1] : val] } }; }, jsonLogic2: "!<=", _jsonLogicIsExclamationOp: true, validateValues: function validateValues(values) { if (values[0] != undefined && values[1] != undefined) { return values[0] <= values[1]; } return null; } }, is_empty: { label: "Is empty", labelForFormat: "IS EMPTY", cardinality: 0, reversedOp: "is_not_empty", formatOp: function formatOp(field, op, value, valueSrc, valueType, opDef, operatorOptions, isForDisplay) { return isForDisplay ? "".concat(field, " IS EMPTY") : "!".concat(field); }, sqlFormatOp: function sqlFormatOp(field, op, values, valueSrc, valueType, opDef, operatorOptions, fieldDef) { var empty = this.utils.sqlEmptyValue(fieldDef); return "COALESCE(".concat(field, ", ").concat(empty, ") = ").concat(empty); }, // tip: this function covers import of 2 operators sqlImport: function sqlImport(sqlObj, _, sqlDialect) { if ((sqlObj === null || sqlObj === void 0 ? void 0 : sqlObj.operator) === "=" || (sqlObj === null || sqlObj === void 0 ? void 0 : sqlObj.operator) === "<>") { var _left$children; var _ref5 = sqlObj.children || [], _ref6 = (0, _slicedToArray2["default"])(_ref5, 2), left = _ref6[0], right = _ref6[1]; if ((right === null || right === void 0 ? void 0 : right.value) === "" && (left === null || left === void 0 ? void 0 : left.func) === "COALESCE" && (left === null || left === void 0 || (_left$children = left.children) === null || _left$children === void 0 || (_left$children = _left$children[1]) === null || _left$children === void 0 ? void 0 : _left$children.value) === "") { sqlObj.operator = (sqlObj === null || sqlObj === void 0 ? void 0 : sqlObj.operator) === "=" ? "is_empty" : "is_not_empty"; sqlObj.children = [left.children[0]]; return sqlObj; } } }, // tip: this op can be imported from SpEL manually without using config spelFormatOp: function spelFormatOp(field, op, values, valueSrc, valueTypes, opDef, operatorOptions, fieldDef) { //tip: is empty or null return "".concat(field, " <= ''"); }, mongoFormatOp: function mongoFormatOp() { var _this$utils13, _this5 = this; for (var _len13 = arguments.length, args = new Array(_len13), _key13 = 0; _key13 < _len13; _key13++) { args[_key13] = arguments[_key13]; } return (_this$utils13 = this.utils).mongoFormatOp1.apply(_this$utils13, ["$in", function (v, fieldDef) { return [_this5.utils.mongoEmptyValue(fieldDef), null]; }, false].concat(args)); }, jsonLogic: "!" }, is_not_empty: { isNotOp: true, label: "Is not empty", labelForFormat: "IS NOT EMPTY", cardinality: 0, reversedOp: "is_empty", formatOp: function formatOp(field, op, value, valueSrc, valueType, opDef, operatorOptions, isForDisplay) { return isForDisplay ? "".concat(field, " IS NOT EMPTY") : "!!".concat(field); }, sqlFormatOp: function sqlFormatOp(field, op, values, valueSrc, valueType, opDef, operatorOptions, fieldDef) { var empty = this.utils.sqlEmptyValue(fieldDef); return "COALESCE(".concat(field, ", ").concat(empty, ") <> ").concat(empty); }, spelFormatOp: function spelFormatOp(field, op, values, valueSrc, valueTypes, opDef, operatorOptions, fieldDef) { //tip: is not empty and not null return "".concat(field, " > ''"); }, mongoFormatOp: function mongoFormatOp() { var _this$utils14, _this6 = this; for (var _len14 = arguments.length, args = new Array(_len14), _key14 = 0; _key14 < _len14; _key14++) { args[_key14] = arguments[_key14]; } return (_this$utils14 = this.utils).mongoFormatOp1.apply(_this$utils14, ["$nin", function (v, fieldDef) { return [_this6.utils.mongoEmptyValue(fieldDef), null]; }, false].concat(args)); }, jsonLogic: "!!", elasticSearchQueryType: "exists" }, is_null: { label: "Is null", labelForFormat: "IS NULL", sqlOp: "IS NULL", // tip: this function covers import of 2 operators sqlImport: function sqlImport(sqlObj, _, sqlDialect) { if ((sqlObj === null || sqlObj === void 0 ? void 0 : sqlObj.operator) === "IS" || (sqlObj === null || sqlObj === void 0 ? void 0 : sqlObj.operator) === "IS NOT") { var _ref7 = sqlObj.children || [], _ref8 = (0, _slicedToArray2["default"])(_ref7, 2), left = _ref8[0], right = _ref8[1]; if ((right === null || right === void 0 ? void 0 : right.valueType) == "null") { sqlObj.operator = (sqlObj === null || sqlObj === void 0 ? void 0 : sqlObj.operator) === "IS" ? "is_null" : "is_not_null"; sqlObj.value = left; return sqlObj; } } }, cardinality: 0, reversedOp: "is_not_null", formatOp: function formatOp(field, op, value, valueSrc, valueType, opDef, operatorOptions, isForDisplay) { return isForDisplay ? "".concat(field, " IS NULL") : "!".concat(field); }, // tip: this op can be imported from SpEL manually without using config spelFormatOp: function spelFormatOp(field, op, values, valueSrc, valueTypes, opDef, operatorOptions, fieldDef) { return "".concat(field, " == null"); }, // check if value is null OR not exists mongoFormatOp: function mongoFormatOp() { var _this$utils15; for (var _len15 = arguments.length, args = new Array(_len15), _key15 = 0; _key15 < _len15; _key15++) { args[_key15] = arguments[_key15]; } return (_this$utils15 = this.utils).mongoFormatOp1.apply(_this$utils15, ["$eq", function (v) { return null; }, false].concat(args)); }, jsonLogic: "==" }, is_not_null: { label: "Is not null", labelForFormat: "IS NOT NULL", sqlOp: "IS NOT NULL", cardinality: 0, reversedOp: "is_null", formatOp: function formatOp(field, op, value, valueSrc, valueType, opDef, operatorOptions, isForDisplay) { return isForDisplay ? "".concat(field, " IS NOT NULL") : "!!".concat(field); }, spelFormatOp: function spelFormatOp(field, op, values, valueSrc, valueTypes, opDef, operatorOptions, fieldDef) { return "".concat(field, " != null"); }, // check if value exists and is not null mongoFormatOp: function mongoFormatOp() { var _this$utils16; for (var _len16 = arguments.length, args = new Array(_len16), _key16 = 0; _key16 < _len16; _key16++) { args[_key16] = arguments[_key16]; } return (_this$utils16 = this.utils).mongoFormatOp1.apply(_this$utils16, ["$ne", function (v) { return null; }, false].concat(args)); }, jsonLogic: "!=", elasticSearchQueryType: "exists" }, select_equals: { label: "==", labelForFormat: "==", sqlOp: "=", // enum/set formatOp: function formatOp(field, op, value, valueSrc, valueType, opDef, operatorOptions, isForDisplay) { var opStr = isForDisplay ? "=" : "=="; return "".concat(field, " ").concat(opStr, " ").concat(value); }, spelOp: "==", spelOps: ["==", "eq"], mongoFormatOp: function mongoFormatOp() { var _this$utils17; for (var _len17 = arguments.length, args = new Array(_len17), _key17 = 0; _key17 < _len17; _key17++) { args[_key17] = arguments[_key17]; } return (_this$utils17 = this.utils).mongoFormatOp1.apply(_this$utils17, ["$eq", function (v) { return v; }, false].concat(args)); }, reversedOp: "select_not_equals", jsonLogic: "==", elasticSearchQueryType: "term" }, select_not_equals: { isNotOp: true, label: "!=", labelForFormat: "!=", sqlOp: "<>", // enum/set sqlOps: ["<>", "!="], formatOp: function formatOp(field, op, value, valueSrc, valueType, opDef, operatorOptions, isForDisplay) { return "".concat(field, " != ").concat(value); }, spelOp: "!=", spelOps: ["!=", "ne"], mongoFormatOp: function mongoFormatOp() { var _this$utils18; for (var _len18 = arguments.length, args = new Array(_len18), _key18 = 0; _key18 < _len18; _key18++) { args[_key18] = arguments[_key18]; } return (_this$utils18 = this.utils).mongoFormatOp1.apply(_this$utils18, ["$ne", function (v) { return v; }, false].concat(args)); }, reversedOp: "select_equals", jsonLogic: "!=" }, select_any_in: { label: "Any in", labelForFormat: "IN", sqlOp: "IN", formatOp: function formatOp(field, op, values, valueSrc, valueType, opDef, operatorOptions, isForDisplay) { if (valueSrc == "value") return "".concat(field, " IN (").concat(values.join(", "), ")");else return "".concat(field, " IN (").concat(values, ")"); }, sqlFormatOp: function sqlFormatOp(field, op, values, valueSrc, valueType, opDef, operatorOptions, fieldDef) { if (valueSrc == "value") { return "".concat(field, " IN (").concat(values.join(", "), ")"); } else return undefined; // not supported }, valueTypes: ["multiselect"], spelOp: "${1}.contains(${0})", mongoFormatOp: function mongoFormatOp() { var _this$utils19; for (var _len19 = arguments.length, args = new Array(_len19), _key19 = 0; _key19 < _len19; _key19++) { args[_key19] = arguments[_key19]; } return (_this$utils19 = this.utils).mongoFormatOp1.apply(_this$utils19, ["$in", function (v) { return v; }, false].concat(args)); }, reversedOp: "select_not_any_in", jsonLogic: "in", elasticSearchQueryType: "term" }, select_not_any_in: { isNotOp: true, label: "Not in", labelForFormat: "NOT IN", sqlOp: "NOT IN", formatOp: function formatOp(field, op, values, valueSrc, valueType, opDef, operatorOptions, isForDisplay) { if (valueSrc == "value") return "".concat(field, " NOT IN (").concat(values.join(", "), ")");else return "".concat(field, " NOT IN (").concat(values, ")"); }, sqlFormatOp: function sqlFormatOp(field, op, values, valueSrc, valueType, opDef, operatorOptions, fieldDef) { if (valueSrc == "value") { return "".concat(field, " NOT IN (").concat(values.join(", "), ")"); } else return undefined; // not supported }, mongoFormatOp: function mongoFormatOp() { var _this$utils20; for (var _len20 = arguments.length, args = new Array(_len20), _key20 = 0; _key20 < _len20; _key20++) { args[_key20] = arguments[_key20]; } return (_this$utils20 = this.utils).mongoFormatOp1.apply(_this$utils20, ["$nin", function (v) { return v; }, false].concat(args)); }, reversedOp: "select_any_in", jsonLogic: function jsonLogic(field, op, val) { return { "!": { "in": [field, val] } }; }, jsonLogic2: "!in", _jsonLogicIsExclamationOp: true }, // it's not "contains all", but "contains any" operator multiselect_contains: { label: "Contains", labelForFormat: "CONTAINS", valueTypes: ["multiselect"], formatOp: function formatOp(field, op, values, valueSrc, valueType, opDef, operatorOptions, isForDisplay) { if (valueSrc == "value") return "".concat(field, " CONTAINS [").concat(values.join(", "), "]");else return "".concat(field, " CONTAINS ").concat(values); }, reversedOp: "multiselect_not_contains", jsonLogic2: "some-in", jsonLogic: function jsonLogic(field, op, vals) { return { "some": [field, { "in": [{ "var": "" }, vals] }] }; }, //spelOp: "${0}.containsAll(${1})", spelOp: "T(CollectionUtils).containsAny(${0}, ${1})", spelImportFuncs: [ // just for backward compatibility (issue #1007) { obj: { type: "property", val: "CollectionUtils" }, methodName: "containsAny", args: [{ "var": "0" }, { "var": "1" }] }], elasticSearchQueryType: "term", mongoFormatOp: function mongoFormatOp() { var _this$utils21; for (var _len21 = arguments.length, args = new Array(_len21), _key21 = 0; _key21 < _len21; _key21++) { args[_key21] = arguments[_key21]; } return (_this$utils21 = this.utils).mongoFormatOp1.apply(_this$utils21, ["$in", function (v) { return v; }, false].concat(args)); } }, multiselect_not_contains: { isNotOp: true, label: "Not contains", labelForFormat: "NOT CONTAINS", valueTypes: ["multiselect"], formatOp: function formatOp(field, op, values, valueSrc, valueType, opDef, operatorOptions, isForDisplay) { if (valueSrc == "value") return "".concat(field, " NOT CONTAINS [").concat(values.join(", "), "]");else return "".concat(field, " NOT CONTAINS ").concat(values); }, reversedOp: "multiselect_contains", jsonLogic2: "!some-in", jsonLogic: function jsonLogic(field, op, vals) { return { "!": { "some": [field, { "in": [{ "var": "" }, vals] }] } }; }, _jsonLogicIsExclamationOp: true }, multiselect_equals: { label: "Equals", labelForFormat: "==", sqlOp: "=", valueTypes: ["multiselect"], formatOp: function formatOp(field, op, values, valueSrc, valueType, opDef, operatorOptions, isForDisplay) { var opStr = isForDisplay ? "=" : "=="; if (valueSrc == "value") return "".concat(field, " ").concat(opStr, " [").concat(values.join(", "), "]");else return "".concat(field, " ").concat(opStr, " ").concat(values); }, sqlFormatOp: function sqlFormatOp(field, op, values, valueSrc, valueType, opDef, operatorOptions, fieldDef) { var _this7 = this; if (valueSrc == "value") // set return "".concat(field, " = '").concat(values.map(function (v) { return _this7.utils.SqlString.trim(v); }).join(","), "'");else return undefined; //not supported }, spelOp: "${0}.equals(${1})", mongoFormatOp: function mongoFormatOp() { var _this$utils22; for (var _len22 = arguments.length, args = new Array(_len22), _key22 = 0; _key22 < _len22; _key22++) { args[_key22] = arguments[_key22]; } return (_this$utils22 = this.utils).mongoFormatOp1.apply(_this$utils22, ["$eq", function (v) { return v; }, false].concat(args)); }, reversedOp: "multiselect_not_equals", jsonLogic2: "all-in", jsonLogic: function jsonLogic(field, op, vals) { return { // it's not "equals", but "includes" operator - just for example "all": [field, { "in": [{ "var": "" }, vals] }] }; }, elasticSearchQueryType: "term" }, multiselect_not_equals: { isNotOp: true, label: "Not equals", labelForFormat: "!=", sqlOp: "<>", sqlOps: ["<>", "!="], valueTypes: ["multiselect"], formatOp: function formatOp(field, op, values, valueSrc, valueType, opDef, operatorOptions, isForDisplay) { if (valueSrc == "value") return "".concat(field, " != [").concat(values.join(", "), "]");else return "".concat(field, " != ").concat(values); }, sqlFormatOp: function sqlFormatOp(field, op, values, valueSrc, valueType, opDef, operatorOptions, fieldDef) { var _this8 = this; if (valueSrc == "value") // set return "".concat(field, " != '").concat(values.map(function (v) { return _this8.utils.SqlString.trim(v); }).join(","), "'");else return undefined; //not supported }, mongoFormatOp: function mongoFormatOp() { var _this$utils23; for (var _len23 = arguments.length, args = new Array(_len23), _key23 = 0; _key23 < _len23; _key23++) { args[_key23] = arguments[_key23]; } return (_this$utils23 = this.utils).mongoFormatOp1.apply(_this$utils23, ["$ne", function (v) { return v; }, false].concat(args)); }, reversedOp: "multiselect_equals", jsonLogic2: "!all-in", jsonLogic: function jsonLogic(field, op, vals) { return { // it's not "equals", but "includes" operator - just for example "!": { "all": [field, { "in": [{ "var": "" }, vals] }] } }; }, _jsonLogicIsExclamationOp: true }, proximity: { label: "Proximity search", cardinality: 2, valueLabels: [{ label: "Word 1", placeholder: "Enter first word" }, { label: "Word 2", placeholder: "Enter second word" }], textSeparators: [ //'Word 1', //'Word 2' ], formatOp: function formatOp(field, op, values, valueSrc, valueType, opDef, operatorOptions, isForDisplay) { var val1 = values.first(); var val2 = values.get(1); var prox = operatorOptions === null || operatorOptions === void 0 ? void 0 : operatorOptions.get("proximity"); return "".concat(field, " ").concat(val1, " NEAR/").concat(prox, " ").concat(val2); }, sqlFormatOp: function sqlFormatOp(field, op, values, valueSrc, valueType, opDef, operatorOptions, fieldDef) { // https://learn.microsoft.com/en-us/sql/relational-databases/search/search-for-words-close-to-another-word-with-near?view=sql-server-ver16#example-1 var val1 = values.first(); var val2 = values.get(1); var aVal1 = this.utils.SqlString.trim(val1); var aVal2 = this.utils.SqlString.trim(val2); var prox = operatorOptions === null || operatorOptions === void 0 ? void 0 : operatorOptions.get("proximity"); return "CONTAINS(".concat(field, ", 'NEAR((").concat(aVal1, ", ").concat(aVal2, "), ").concat(prox, ")')"); }, sqlImport: function sqlImport(sqlObj, _, sqlDialect) { if ((sqlObj === null || sqlObj === void 0 ? void 0 : sqlObj.func) === "CONTAINS") { var _right$value; var _ref9 = sqlObj.children || [], _ref10 = (0, _slicedToArray2["default"])(_ref9, 2), left = _ref10[0], right = _ref10[1]; if (right !== null && right !== void 0 && (_right$value = right.value) !== null && _right$value !== void 0 && _right$value.includes("NEAR(")) { var m = right.value.match(/NEAR\(\((\w+), (\w+)\), (\d+)\)/); if (m) { delete sqlObj.func; sqlObj.operator = "proximity"; sqlObj.children = [left, { value: m[1] }, { value: m[2] }]; sqlObj.operatorOptions = { proximity: parseInt(m[3]) }; return sqlObj; } } } }, mongoFormatOp: undefined, // not supported jsonLogic: undefined, // not supported options: { optionLabel: "Near", // label on top of "near" selectbox (for config.settings.showLabels==true) optionTextBefore: "Near", // label before "near" selectbox (for config.settings.showLabels==false) optionPlaceholder: "Select words between", // placeholder for "near" selectbox minProximity: 2, maxProximity: 10, defaults: { proximity: 2 } } }, some: { label: "Some", labelForFormat: "SOME", cardinality: 0, jsonLogic: "some", spelFormatOp: function spelFormatOp(filteredSize) { return "".concat(filteredSize, " > 0"); }, mongoFormatOp: function mongoFormatOp() { var _this$utils24; for (var _len24 = arguments.length, args = new Array(_len24), _key24 = 0; _key24 < _len24; _key24++) { args[_key24] = arguments[_key24]; } return (_this$utils24 = this.utils).mongoFormatOp1.apply(_this$utils24, ["$gt", function (v) { return 0; }, false].concat(args)); } // reversedOp: undefined, }, all: { label: "All", labelForFormat: "ALL", cardinality: 0, jsonLogic: "all", spelFormatOp: function spelFormatOp(filteredSize, op, fullSize) { return "".concat(filteredSize, " == ").concat(fullSize); }, mongoFormatOp: function mongoFormatOp() { var _this$utils25; for (var _len25 = arguments.length, args = new Array(_len25), _key25 = 0; _key25 < _len25; _key25++) { args[_key25] = arguments[_key25]; } return (_this$utils25 = this.utils).mongoFormatOp1.apply(_this$utils25, ["$eq", function (v) { return v; }, false].concat(args)); } // reversedOp: "none", }, none: { label: "None", labelForFormat: "NONE", cardinality: 0, jsonLogic: "none", spelFormatOp: function spelFormatOp(filteredSize) { return "".concat(filteredSize, " == 0"); }, mongoFormatOp: function mongoFormatOp() { var _this$utils26; for (var _len26 = arguments.length, args = new Array(_len26), _key26 = 0; _key26 < _len26; _key26++) { args[_key26] = arguments[_key26]; } return (_this$utils26 = this.utils).mongoFormatOp1.apply(_this$utils26, ["$eq", function (v) { return 0; }, false].concat(args)); } // reversedOp: "all", } }; //---------------------------- widgets var widgets = { text: { type: "text", jsType: "string", valueSrc: "value", valueLabel: "String", valuePlaceholder: "Enter string", formatValue: function formatValue(val, fieldDef, wgtDef, isForDisplay) { return isForDisplay ? this.utils.stringifyForDisplay(val) : JSON.stringify(val); }, spelFormatValue: function spelFormatValue(val, fieldDef, wgtDef, op, opDef) { return this.utils.spelEscape(val); }, sqlFormatValue: function sqlFormatValue(val, fieldDef, wgtDef, op, opDef, _, sqlDialect) { if (opDef.sqlOp == "LIKE" || opDef.sqlOp == "NOT LIKE") { return this.utils.SqlString.escapeLike(val, op != "starts_with", op != "ends_with", sqlDialect); } else { return this.utils.SqlString.escape(val); } }, toJS: function toJS(val, fieldSettings) { return val; }, mongoFormatValue: function mongoFormatValue(val, fieldDef, wgtDef) { return val; } }, textarea: { type: "text", jsType: "string", valueSrc: "value", valueLabel: "Text", valuePlaceholder: "Enter text", formatValue: function formatValue(val, fieldDef, wgtDef, isForDisplay) { return isForDisplay ? this.utils.stringifyForDisplay(val) : JSON.stringify(val); }, sqlFormatValue: function sqlFormatValue(val, fieldDef, wgtDef, op, opDef, _, sqlDialect) { if (opDef.sqlOp == "LIKE" || opDef.sqlOp == "NOT LIKE") { return this.utils.SqlString.escapeLike(val, op != "starts_with", op != "ends_with", sqlDialect); } else { return this.utils.SqlString.escape(val); } }, spelFormatValue: function spelFormatValue(val) { return this.utils.spelEscape(val); }, toJS: function toJS(val, fieldSettings) { return val; }, mongoFormatValue: function mongoFormatValue(val, fieldDef, wgtDef) { return val; }, fullWidth: true }, number: { type: "number", jsType: "number", valueSrc: "value", valueLabel: "Number", valuePlaceholder: "Enter number", valueLabels: [{ label: "Number from", placeholder: "Enter number from" }, { label: "Number to", placeholder: "Enter number to" }], formatValue: function formatValue(val, fieldDef, wgtDef, isForDisplay) { return isForDisplay ? this.utils.stringifyForDisplay(val) : JSON.stringify(val); }, sqlFormatValue: function sqlFormatValue(val, fieldDef, wgtDef, op, opDef, _, sqlDialect) { return this.utils.SqlString.escape(val); }, spelFormatValue: function spelFormatValue(val, fieldDef, wgtDef) { var isFloat = wgtDef.step && !Number.isInteger(wgtDef.step); return this.utils.spelEscape(val, isFloat); }, toJS: function toJS(val, fieldSettings) { return val; }, mongoFormatValue: function mongoFormatValue(val, fieldDef, wgtDef) { return val; } }, price: { type: "number", jsType: "number", valueSrc: "value", valueLabel: "Price", valueLabels: [{ label: "Price from", placeholder: "Enter price from" }, { label: "Price to", placeholder: "Enter price to" }], formatValue: function formatValue(val, fieldDef, wgtDef, isForDisplay) { return isForDisplay ? this.utils.stringifyForDisplay(val) : JSON.stringify(val); }, sqlFormatValue: function sqlFormatValue(val, fieldDef, wgtDef, op, opDef) { return this.utils.SqlString.escape(val); }, spelFormatValue: function spelFormatValue(val, fieldDef, wgtDef) { var isFloat = wgtDef.step && !Number.isInteger(wgtDef.step); return this.utils.spelEscape(val, isFloat); }, toJS: function toJS(val, fieldSettings) { return val; }, mongoFormatValue: function mongoFormatValue(val, fieldDef, wgtDef) { return val; } }, slider: { type: "number", jsType: "number", valueSrc: "value", valueLabel: "Number", valuePlaceholder: "Enter number or move slider", formatValue: function formatValue(val, fieldDef, wgtDef, isForDisplay) { return isForDisplay ? this.utils.stringifyForDisplay(val) : JSON.stringify(val); }, sqlFormatValue: function sqlFormatValue(val, fieldDef, wgtDef, op, opDef, _, sqlDialect) { return this.utils.SqlString.escape(val); }, spelFormatValue: function spelFormatValue(val) { return this.utils.spelEscape(val); }, toJS: function toJS(val, fieldSettings) { return val; }, mongoFormatValue: function mongoFormatValue(val, fieldDef, wgtDef) { return val; } }, select: { type: "select", jsType: "string", valueSrc: "value", valueLabel: "Value", valuePlaceholder: "Select value", formatValue: function formatValue(val, fieldDef, wgtDef, isForDisplay) { var valLabel = this.utils.getTitleInListValues(fieldDef.fieldSettings.listValues || fieldDef.asyncListValues, val); return isForDisplay ? this.utils.stringifyForDisplay(valLabel) : JSON.stringify(val); }, sqlFormatValue: function sqlFormatValue(val, fieldDef, wgtDef, op, opDef, _, sqlDialect) { return this.utils.SqlString.escape(val); }, spelFormatValue: function spelFormatValue(val) { return this.utils.spelEscape(val); }, toJS: function toJS(val, fieldSettings) { return val; }, mongoFormatValue: function mongoFormatValue(val, fieldDef, wgtDef) { return val; } }, multiselect: { type: "multiselect", jsType: "array", valueSrc: "value", valueLabel: "Values", valuePlaceholder: "Select values", formatValue: function formatValue(vals, fieldDef, wgtDef, isForDisplay) { var _this9 = this; var valsLabels = vals.map(function (v) { return _this9.utils.getTitleInListValues(fieldDef.fieldSettings.listValues || fieldDef.asyncListValues, v); }); return isForDisplay ? valsLabels.map(this.utils.stringifyForDisplay) : vals.map(JSON.stringify); }, sqlFormatValue: function sqlFormatValue(vals, fieldDef, wgtDef, op, opDef, _, sqlDialect) { var _this10 = this; return vals.map(function (v) { return _this10.utils.SqlString.escape(v); }); }, spelFormatValue: function spelFormatValue(vals, fieldDef, wgtDef, op, opDef) { var isCallable = opDef && opDef.spelOp && opDef.spelOp.startsWith("${1}"); var res = this.utils.spelEscape(vals); // inline list if (isCallable) { // `{1,2}.contains(1)` NOT works // `{1,2}.?[true].contains(1)` works res = this.utils.spelFixList(res); } return res; }, toJS: function toJS(val, fieldSettings) { return val; }, mongoFormatValue: function mongoFormatValue(val, fieldDef, wgtDef) { return val; } }, date: { type: "date", jsType: "string", valueSrc: "value", dateFormat: "DD.MM.YYYY", valueFormat: "YYYY-MM-DD", valueLabel: "Date", valuePlaceholder: "Enter date", valueLabels: [{ label: "Date from", placeholder: "Enter date from" }, { label: "Date to", placeholder: "Enter date to" }], formatValue: function formatValue(val, fieldDef, wgtDef, isForDisplay) { var dateVal = this.utils.moment(val, wgtDef.valueFormat); return isForDisplay ? dateVal.format(wgtDef.dateFormat) : JSON.stringify(val); }, sqlFormatValue: function sqlFormatValue(val, fieldDef, wgtDef, op, opDef, _, sqlDialect) { var dateVal = this.utils.moment(val, wgtDef.valueFormat); return this.utils.SqlString.escape(dateVal.format("YYYY-MM-DD")); }, spelFormatValue: function spelFormatValue(val, fieldDef, wgtDef, op, opDef) { var dateVal = this.utils.moment(val, wgtDef.valueFormat); var v = dateVal.format("YYYY-MM-DD"); var fmt = "yyyy-MM-dd"; //return `new java.text.SimpleDateFormat('${fmt}').parse('${v}')`; return "T(java.time.LocalDate).parse('".concat(v, "', T(java.time.format.DateTimeFormatter).ofPattern('").concat(fmt, "'))"); }, spelImportFuncs: [ //"new java.text.SimpleDateFormat(${fmt}).parse(${v})", { obj: { cls: ["java", "time", "LocalDate"] }, methodName: "parse", args: [{ "var": "v" }, { obj: { cls: ["java", "time", "format", "DateTimeFormatter"] }, methodName: "ofPattern", args: [{ "var": "fmt" }] }] }], spelImportValue: function spelImportValue(val, wgtDef, args) { var _args$fmt, _args$fmt$includes, _args$fmt2, _args$fmt2$toLowerCas; if (!wgtDef) return [undefined, "No widget def to get value format"]; if (args !== null && args !== void 0 && (_args$fmt = args.fmt) !== null && _args$fmt !== void 0 && (_args$fmt = _args$fmt.value) !== null && _args$fmt !== void 0 && (_args$fmt$includes = _args$fmt.includes) !== null && _args$fmt$includes !== void 0 && _args$fmt$includes.call(_args$fmt, " ") || (_args$fmt2 = args.fmt) !== null && _args$fmt2 !== void 0 && (_args$fmt2 = _args$fmt2.value) !== null && _args$fmt2 !== void 0 && (_args$fmt2$toLowerCas = _args$fmt2.toLowerCase) !== null && _args$fmt2$toLowerCas !== void 0 && _args$fmt2$toLowerCas.call(_args$fmt2).includes("hh:mm")) return [undefined, "Invalid date format ".concat(JSON.stringify(args.fmt))]; var dateVal = this.utils.moment(val.value, this.utils.moment.ISO_8601); if (dateVal.isValid()) { return [dateVal.format(wgtDef === null || wgtDef === void 0 ? void 0 : wgtDef.valueFormat), []]; } else { return [undefined, "Invalid date"]; } }, jsonLogic: function jsonLogic(val, fieldDef, wgtDef) { // tip: we use UTC to return same result as new Date(val) // new Date("2000-01-01") is now the same as new Date("2000-01-01 00:00:00") (first one in UTC) return this.utils.moment.utc(val, wgtDef.valueFormat).toDate(); }, toJS: function toJS(val, fieldSettings) { var dateVal = this.utils.moment(val, fieldSettings.valueFormat); return dateVal.isValid() ? dateVal.toDate() : undefined; }, mongoFormatValue: function mongoFormatValue(val, fieldDef, wgtDef) { var dateVal = this.utils.moment(val, wgtDef.valueFormat); if (dateVal.isValid()) { return { "$dateFromString": { "dateString": dateVal.format("YYYY-MM-DD"), "format": "%Y-%m-%d" } }; } return undefined; } }, time: { type: "time", jsType: "string", valueSrc: "value", timeFormat: "HH:mm", valueFormat: "HH:mm:ss", use12Hours: false, valueLabel: "Time", valuePlaceholder: "Enter time",