UNPKG

@enonic/js-utils

Version:
228 lines (227 loc) 10.2 kB
"use strict"; function _instanceof(left, right) { if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) { return !!right[Symbol.hasInstance](left); } else { return left instanceof right; } } function _type_of(obj) { "@swc/helpers - typeof"; return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; } var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = function(target, all) { for(var name in all)__defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = function(to, from, except, desc) { if (from && (typeof from === "undefined" ? "undefined" : _type_of(from)) === "object" || typeof from === "function") { var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; try { var _loop = function() { var key = _step.value; if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: function() { return from[key]; }, enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); }; for(var _iterator = __getOwnPropNames(from)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop(); } catch (err) { _didIteratorError = true; _iteratorError = err; } finally{ try { if (!_iteratorNormalCompletion && _iterator.return != null) { _iterator.return(); } } finally{ if (_didIteratorError) { throw _iteratorError; } } } } return to; }; var __toCommonJS = function(mod) { return __copyProps(__defProp({}, "__esModule", { value: true }), mod); }; // storage/query/dsl/isQueryDsl.ts var isQueryDsl_exports = {}; __export(isQueryDsl_exports, { default: function() { return isQueryDsl; }, isBooleanDslExpression: function() { return isBooleanDslExpression; } }); module.exports = __toCommonJS(isQueryDsl_exports); // value/isBasicObject.ts var isBasicObject = function(value) { return (typeof value === "undefined" ? "undefined" : _type_of(value)) === "object"; }; // value/isNumber.ts function isNumber(value) { return typeof value === "number" && isFinite(value); } // value/isStringLiteral.ts var isStringLiteral = function(value) { return typeof value === "string"; }; // value/isStringObject.ts var isStringObject = function(value) { return _instanceof(value, String); }; // value/isString.ts var isString = function(value) { return isStringLiteral(value) || isStringObject(value); }; // value/isSymbol.ts var isSymbol = function(value) { return (typeof value === "undefined" ? "undefined" : _type_of(value)) === "symbol"; }; // value/isPropertyKey.ts var isPropertyKey = function(value) { return isString(value) || isNumber(value) || isSymbol(value); }; // value/toStr.ts function toStr(value, replacer) { var space = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 4; return JSON.stringify(value, replacer, space); } // object/hasOwnProperty.ts function hasOwnProperty(obj, propKey) { if (!isBasicObject(obj)) { throw new Error("First parameter to hasOwnProperty must be a basic Object! ".concat(toStr(obj))); } if (!isPropertyKey(propKey)) { throw new Error("Second parameter to hasOwnProperty must be a PropertyKey (string|number|symbol)! ".concat(toStr(propKey))); } return obj.hasOwnProperty(propKey); } // array/forceArray.ts function forceArray(data) { return Array.isArray(data) ? data : [ data ]; } // value/isObject.ts var isObject = function(value) { return Object.prototype.toString.call(value).slice(8, -1) === "Object"; }; // storage/query/dsl/isDslQueryType.ts var DSL_EXPRESSION_VALUE_TYPE_DATE_TIME = "dateTime"; var DSL_EXPRESSION_VALUE_TYPE_TIME = "time"; function isDslQueryType(value) { return isString(value) && (value === DSL_EXPRESSION_VALUE_TYPE_DATE_TIME || value === DSL_EXPRESSION_VALUE_TYPE_TIME); } // storage/query/dsl/isInDslExpression.ts function isInDslExpression(value) { return isObject(value) && hasOwnProperty(value, "field") && hasOwnProperty(value, "values") && isString(value.field) && Array.isArray(value.values) && (hasOwnProperty(value, "type") ? isDslQueryType(value.type) : true) && (hasOwnProperty(value, "boost") ? isNumber(value.boost) : true); } // storage/query/dsl/isExistsDslExpression.ts function isExistsDslExpression(value) { return isObject(value) && hasOwnProperty(value, "field") && isString(value.field) && (hasOwnProperty(value, "boost") ? isNumber(value.boost) : true); } // array/includes.ts function sameValueZero(x, y) { return x === y || typeof x === "number" && typeof y === "number" && isNaN(x) && isNaN(y); } function includes(array, searchElement) { var fromIndex = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 0; if (array == null) { throw new TypeError('"array" is null or not defined'); } var o = Object(array); var len = o.length >>> 0; if (len === 0) { return false; } var n = fromIndex | 0; var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0); while(k < len){ if (sameValueZero(o[k], searchElement)) { return true; } k++; } return false; } // storage/query/constants.ts var QUERY_OPERATOR_AND = "AND"; var QUERY_OPERATOR_OR = "OR"; var QUERY_OPERATORS = [ QUERY_OPERATOR_AND, QUERY_OPERATOR_OR ]; // storage/query/dsl/isDslOperator.ts function isDslOperator(value) { return isString(value) && includes(QUERY_OPERATORS, value); } // storage/query/dsl/isFulltextDslExpression.ts function isFulltextDslExpression(value) { return isObject(value) && hasOwnProperty(value, "fields") && hasOwnProperty(value, "query") && Array.isArray(value.fields) && value.fields.every(isString) && isString(value.query) && (hasOwnProperty(value, "operator") ? isDslOperator(value.operator) : true) && (hasOwnProperty(value, "boost") ? isNumber(value.boost) : true); } // storage/query/dsl/isLikeDslExpression.ts function isLikeDslExpression(value) { return isObject(value) && hasOwnProperty(value, "field") && hasOwnProperty(value, "value") && isString(value.field) && isString(value.value) && (hasOwnProperty(value, "type") ? isDslQueryType(value.type) : true) && (hasOwnProperty(value, "boost") ? isNumber(value.boost) : true); } // storage/query/dsl/isMatchAllDslExpression.ts function isMatchAllDslExpression(value) { return isObject(value) && (hasOwnProperty(value, "boost") ? isNumber(value.boost) : true); } // storage/query/dsl/isNgramDslExpression.ts function isNgramDslExpression(value) { return isFulltextDslExpression(value); } // storage/query/dsl/isPathMatchDslExpression.ts function isPathMatchDslExpression(value) { return isObject(value) && hasOwnProperty(value, "field") && hasOwnProperty(value, "path") && isString(value.field) && isString(value.path) && (hasOwnProperty(value, "minimumMatch") ? isNumber(value.minimumMatch) : true) && (hasOwnProperty(value, "boost") ? isNumber(value.boost) : true); } // storage/query/dsl/isRangeDslExpression.ts function isRangeDslExpression(value) { return isObject(value) && hasOwnProperty(value, "field") && isString(value.field) && [ "lt", "lte", "gt", "gte" ].some(function(key) { return hasOwnProperty(value, key); }) && (hasOwnProperty(value, "boost") ? isNumber(value.boost) : true); } // storage/query/dsl/isStemmedDslExpression.ts function isStemmedDslExpression(value) { return isObject(value) && hasOwnProperty(value, "fields") && hasOwnProperty(value, "language") && hasOwnProperty(value, "query") && Array.isArray(value.fields) && value.fields.every(isString) && isString(value.language) && isString(value.query) && (hasOwnProperty(value, "operator") ? isDslOperator(value.operator) : true) && (hasOwnProperty(value, "boost") ? isNumber(value.boost) : true); } // storage/query/dsl/isTermDslExpression.ts function isTermDslExpression(value) { return isObject(value) && hasOwnProperty(value, "field") && hasOwnProperty(value, "value") && isString(value.field) && (hasOwnProperty(value, "type") ? isDslQueryType(value.type) : true) && (hasOwnProperty(value, "boost") ? isNumber(value.boost) : true); } // storage/query/dsl/isQueryDsl.ts var COMPOUND_PROPERTIES = [ "must", "mustNot", "should", "filter" ]; function isBooleanDslExpression(value) { return isObject(value) && COMPOUND_PROPERTIES.every(function(prop) { return hasOwnProperty(value, prop) ? forceArray(value[prop]).every(function(item) { return isQueryDsl(item); }) : true; }) && (hasOwnProperty(value, "boost") ? isNumber(value.boost) : true); } function isQueryDsl(value) { return isObject(value) && (hasOwnProperty(value, "boolean") && isBooleanDslExpression(value.boolean) || hasOwnProperty(value, "exists") && isExistsDslExpression(value.exists) || hasOwnProperty(value, "fulltext") && isFulltextDslExpression(value.fulltext) || hasOwnProperty(value, "in") && isInDslExpression(value.in) || hasOwnProperty(value, "like") && isLikeDslExpression(value.like) || hasOwnProperty(value, "matchAll") && isMatchAllDslExpression(value.matchAll) || hasOwnProperty(value, "ngram") && isNgramDslExpression(value.ngram) || hasOwnProperty(value, "pathMatch") && isPathMatchDslExpression(value.pathMatch) || hasOwnProperty(value, "range") && isRangeDslExpression(value.range) || hasOwnProperty(value, "stemmed") && isStemmedDslExpression(value.stemmed) || hasOwnProperty(value, "term") && isTermDslExpression(value.term)); }