UNPKG

@enonic/js-utils

Version:
184 lines (183 loc) 5.8 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/aggregation/index.ts var aggregation_exports = {}; __export(aggregation_exports, { stats: function() { return stats; }, statsParams: function() { return statsParams; }, terms: function() { return terms; }, termsParams: function() { return termsParams; } }); module.exports = __toCommonJS(aggregation_exports); // storage/query/aggregation/stats.ts function statsParams(field) { var stats2 = { field: field }; return stats2; } function stats(field) { var statsAggregation = { stats: statsParams(field) }; return statsAggregation; } // value/isFunction.ts function isFunction(value) { return Object.prototype.toString.call(value).slice(8, -1) === "Function"; } // 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/isInt.ts function isInt(value) { return typeof value === "number" && isFinite(value) && // TODO Is isFinite() available in Enonic XP? Math.floor(value) === value; } // value/isInteger.ts var isInteger = "isInteger" in Number && isFunction(Number.isInteger) ? Number.isInteger : isInt; // value/isObject.ts var isObject = function(value) { return Object.prototype.toString.call(value).slice(8, -1) === "Object"; }; // value/isSet.ts function isSet(value) { if (typeof value === "boolean") { return true; } return value !== null && typeof value !== "undefined"; } // storage/query/aggregation/terms.ts function termsParams(field, order, size, minDocCount) { var terms2 = { field: field }; if (order) { terms2.order = order; } if (size) { terms2.size = size; } if (minDocCount) { terms2.minDocCount = minDocCount; } return terms2; } function terms(field) { for(var _len = arguments.length, optionalArgs = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){ optionalArgs[_key - 1] = arguments[_key]; } var order; var size; var minDocCount; var aggregations; for(var i = 0; i < optionalArgs.length; i++){ var optinalArg = optionalArgs[i]; if (isString(optinalArg)) { if (order) { throw new Error("terms: You can only provide one optional order parameter!"); } order = optinalArg; } else if (isNumber(optinalArg)) { if (isSet(minDocCount)) { throw new Error("terms: You can only provide one or two optional number parameters!"); } if (isSet(size)) { minDocCount = optinalArg; } else { size = optinalArg; } } else if (isObject(optinalArg)) { if (aggregations) { throw new Error("terms: You can only provide one optional aggregations parameter!"); } aggregations = optinalArg; } else { throw new Error("terms: Unknown optional parameter type!"); } } var termsAggregation = { terms: termsParams(field, order, size, minDocCount) }; if (aggregations) { termsAggregation.aggregations = aggregations; } return termsAggregation; }