operators.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. "use strict";
  2. var __defProp = Object.defineProperty;
  3. var __getOwnPropSymbols = Object.getOwnPropertySymbols;
  4. var __hasOwnProp = Object.prototype.hasOwnProperty;
  5. var __propIsEnum = Object.prototype.propertyIsEnumerable;
  6. var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  7. var __spreadValues = (a, b) => {
  8. for (var prop in b || (b = {}))
  9. if (__hasOwnProp.call(b, prop))
  10. __defNormalProp(a, prop, b[prop]);
  11. if (__getOwnPropSymbols)
  12. for (var prop of __getOwnPropSymbols(b)) {
  13. if (__propIsEnum.call(b, prop))
  14. __defNormalProp(a, prop, b[prop]);
  15. }
  16. return a;
  17. };
  18. const _ = require("lodash");
  19. const Op = require("../../../operators");
  20. const Utils = require("../../../utils");
  21. const OperatorHelpers = {
  22. OperatorMap: {
  23. [Op.eq]: "=",
  24. [Op.ne]: "!=",
  25. [Op.gte]: ">=",
  26. [Op.gt]: ">",
  27. [Op.lte]: "<=",
  28. [Op.lt]: "<",
  29. [Op.not]: "IS NOT",
  30. [Op.is]: "IS",
  31. [Op.in]: "IN",
  32. [Op.notIn]: "NOT IN",
  33. [Op.like]: "LIKE",
  34. [Op.notLike]: "NOT LIKE",
  35. [Op.iLike]: "ILIKE",
  36. [Op.notILike]: "NOT ILIKE",
  37. [Op.startsWith]: "LIKE",
  38. [Op.endsWith]: "LIKE",
  39. [Op.substring]: "LIKE",
  40. [Op.regexp]: "~",
  41. [Op.notRegexp]: "!~",
  42. [Op.iRegexp]: "~*",
  43. [Op.notIRegexp]: "!~*",
  44. [Op.between]: "BETWEEN",
  45. [Op.notBetween]: "NOT BETWEEN",
  46. [Op.overlap]: "&&",
  47. [Op.contains]: "@>",
  48. [Op.contained]: "<@",
  49. [Op.adjacent]: "-|-",
  50. [Op.strictLeft]: "<<",
  51. [Op.strictRight]: ">>",
  52. [Op.noExtendRight]: "&<",
  53. [Op.noExtendLeft]: "&>",
  54. [Op.any]: "ANY",
  55. [Op.all]: "ALL",
  56. [Op.and]: " AND ",
  57. [Op.or]: " OR ",
  58. [Op.col]: "COL",
  59. [Op.placeholder]: "$$PLACEHOLDER$$",
  60. [Op.match]: "@@"
  61. },
  62. OperatorsAliasMap: {},
  63. setOperatorsAliases(aliases) {
  64. if (!aliases || _.isEmpty(aliases)) {
  65. this.OperatorsAliasMap = false;
  66. } else {
  67. this.OperatorsAliasMap = __spreadValues({}, aliases);
  68. }
  69. },
  70. _replaceAliases(orig) {
  71. const obj = {};
  72. if (!this.OperatorsAliasMap) {
  73. return orig;
  74. }
  75. Utils.getOperators(orig).forEach((op) => {
  76. const item = orig[op];
  77. if (_.isPlainObject(item)) {
  78. obj[op] = this._replaceAliases(item);
  79. } else {
  80. obj[op] = item;
  81. }
  82. });
  83. _.forOwn(orig, (item, prop) => {
  84. prop = this.OperatorsAliasMap[prop] || prop;
  85. if (_.isPlainObject(item)) {
  86. item = this._replaceAliases(item);
  87. }
  88. obj[prop] = item;
  89. });
  90. return obj;
  91. }
  92. };
  93. module.exports = OperatorHelpers;
  94. //# sourceMappingURL=operators.js.map