'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var smob = require('smob');
var minimatch = require('minimatch');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var minimatch__default = /*#__PURE__*/_interopDefaultLegacy(minimatch);

function ownKeys(object, enumerableOnly) {
  var keys = Object.keys(object);
  if (Object.getOwnPropertySymbols) {
    var symbols = Object.getOwnPropertySymbols(object);
    enumerableOnly && (symbols = symbols.filter(function (sym) {
      return Object.getOwnPropertyDescriptor(object, sym).enumerable;
    })), keys.push.apply(keys, symbols);
  }
  return keys;
}
function _objectSpread2(target) {
  for (var i = 1; i < arguments.length; i++) {
    var source = null != arguments[i] ? arguments[i] : {};
    i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
      _defineProperty(target, key, source[key]);
    }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
      Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
    });
  }
  return target;
}
function _typeof(obj) {
  "@babel/helpers - typeof";

  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
    return typeof obj;
  } : function (obj) {
    return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  }, _typeof(obj);
}
function _defineProperty(obj, key, value) {
  key = _toPropertyKey(key);
  if (key in obj) {
    Object.defineProperty(obj, key, {
      value: value,
      enumerable: true,
      configurable: true,
      writable: true
    });
  } else {
    obj[key] = value;
  }
  return obj;
}
function _toConsumableArray(arr) {
  return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
}
function _arrayWithoutHoles(arr) {
  if (Array.isArray(arr)) return _arrayLikeToArray(arr);
}
function _iterableToArray(iter) {
  if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _unsupportedIterableToArray(o, minLen) {
  if (!o) return;
  if (typeof o === "string") return _arrayLikeToArray(o, minLen);
  var n = Object.prototype.toString.call(o).slice(8, -1);
  if (n === "Object" && o.constructor) n = o.constructor.name;
  if (n === "Map" || n === "Set") return Array.from(o);
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
function _arrayLikeToArray(arr, len) {
  if (len == null || len > arr.length) len = arr.length;
  for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
  return arr2;
}
function _nonIterableSpread() {
  throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _toPrimitive(input, hint) {
  if (typeof input !== "object" || input === null) return input;
  var prim = input[Symbol.toPrimitive];
  if (prim !== undefined) {
    var res = prim.call(input, hint || "default");
    if (typeof res !== "object") return res;
    throw new TypeError("@@toPrimitive must return a primitive value.");
  }
  return (hint === "string" ? String : Number)(input);
}
function _toPropertyKey(arg) {
  var key = _toPrimitive(arg, "string");
  return typeof key === "symbol" ? key : String(key);
}

/*
 * Copyright (c) 2021-2022.
 * Author Peter Placzek (tada5hi)
 * For the full copyright and license information,
 * view the LICENSE file that was distributed with this source code.
 */

// -----------------------------------------------------------

exports.Parameter = void 0;

// -----------------------------------------------------------
(function (Parameter) {
  Parameter["FILTERS"] = "filters";
  Parameter["FIELDS"] = "fields";
  Parameter["PAGINATION"] = "pagination";
  Parameter["RELATIONS"] = "relations";
  Parameter["SORT"] = "sort";
})(exports.Parameter || (exports.Parameter = {}));
exports.URLParameter = void 0;

// -----------------------------------------------------------
(function (URLParameter) {
  URLParameter["FILTERS"] = "filter";
  URLParameter["FIELDS"] = "fields";
  URLParameter["PAGINATION"] = "page";
  URLParameter["RELATIONS"] = "include";
  URLParameter["SORT"] = "sort";
})(exports.URLParameter || (exports.URLParameter = {}));
var DEFAULT_ID = '__DEFAULT__';

function buildKeyPath(key, prefix) {
  if (typeof prefix === 'string') {
    return "".concat(prefix, ".").concat(key);
  }
  return key;
}
function flattenToKeyPathArray(input, options, prefix) {
  options = options || {};
  var output = [];
  if (options.transformer) {
    var result = options.transformer(input, output, prefix);
    if (typeof result !== 'undefined' && !!result) {
      return output;
    }
  }
  if (Array.isArray(input)) {
    for (var i = 0; i < input.length; i++) {
      if (options.transformer) {
        var _result = options.transformer(input[i], output, prefix);
        if (typeof _result !== 'undefined' && !!_result) {
          return output;
        }
      }
      if (Array.isArray(input[i])) {
        for (var j = 0; j < input[i].length; j++) {
          var key = buildKeyPath(input[i][j], prefix);
          output.push(key);
        }
        continue;
      }
      if (typeof input[i] === 'string') {
        output.push(buildKeyPath(input[i], prefix));
        continue;
      }
      if (_typeof(input[i]) === 'object') {
        var keys = Object.keys(input[i]);
        for (var _j = 0; _j < keys.length; _j++) {
          var value = buildKeyPath(keys[_j], prefix);
          var data = flattenToKeyPathArray(input[i][keys[_j]], options, value);
          if (data.length === 0) {
            output.push(value);
          } else {
            output.push.apply(output, _toConsumableArray(data));
          }
        }
      }
    }
    return output;
  }
  if (_typeof(input) === 'object' && input !== null) {
    var _keys = Object.keys(input);
    for (var _i = 0; _i < _keys.length; _i++) {
      var _value = buildKeyPath(_keys[_i], prefix);
      var _data = flattenToKeyPathArray(input[_keys[_i]], options, _value);
      if (_data.length === 0) {
        output.push(_value);
      } else {
        output.push.apply(output, _toConsumableArray(_data));
      }
    }
    return output;
  }
  if (typeof input === 'string') {
    var _value2 = buildKeyPath(input, prefix);
    output.push(_value2);
    return output;
  }
  return output;
}
function groupArrayByKeyPath(input) {
  var pathItems = {};
  for (var i = 0; i < input.length; i++) {
    var parts = input[i].split('.');
    var key = void 0;
    var name = void 0;
    if (parts.length === 1) {
      key = DEFAULT_ID;
      name = input[i];
    } else {
      name = parts.pop();
      key = parts.join('.');
    }
    if (!Object.prototype.hasOwnProperty.call(pathItems, key)) {
      pathItems[key] = [];
    }
    pathItems[key].push(name);
  }
  return pathItems;
}

/*
 * Copyright (c) 2021-2022.
 * Author Peter Placzek (tada5hi)
 * For the full copyright and license information,
 * view the LICENSE file that was distributed with this source code.
 */

function hasOwnProperty(obj, prop) {
  return Object.prototype.hasOwnProperty.call(obj, prop);
}
function flattenNestedObject(data, options, prefixParts) {
  options = options || {};
  prefixParts = prefixParts || [];
  var output = {};
  if (options.transformer) {
    var result = options.transformer(data, output, prefixParts.join('.'));
    if (typeof result !== 'undefined' && !!result) {
      return output;
    }
  }
  var keys = Object.keys(data);
  for (var i = 0; i < keys.length; i++) {
    var _key = keys[i];
    if (options.transformer) {
      var _result = options.transformer(data[_key], output, [].concat(_toConsumableArray(prefixParts), [_key]).join('.'));
      if (typeof _result !== 'undefined' && !!_result) {
        continue;
      }
    }
    if (_typeof(data[_key]) === 'object' && data[_key]) {
      output = _objectSpread2(_objectSpread2({}, output), flattenNestedObject(data[_key], options, [].concat(_toConsumableArray(prefixParts), [_key])));
      continue;
    }
    var destinationKey = [].concat(_toConsumableArray(prefixParts), [_key]).join('.');
    if (typeof data[_key] === 'boolean' || typeof data[_key] === 'string' || typeof data[_key] === 'number' || typeof data[_key] === 'undefined' || data[_key] === null || Array.isArray(data[_key])) {
      output[destinationKey] = data[_key];
    }
  }
  return output;
}

function applyMapping(name, map, onlyKey) {
  if (typeof map === 'undefined') {
    return name;
  }
  var parts = name.split('.');
  var output = [];
  var run = true;
  while (run) {
    var value = parts.shift();
    if (typeof value === 'undefined') {
      run = false;
      break;
    }
    if (hasOwnProperty(map, value)) {
      output.push(map[value]);
    } else {
      var found = false;
      var rest = [];
      var copy = _toConsumableArray(parts);
      while (copy.length > 0) {
        var key = [value].concat(_toConsumableArray(copy)).join('.');
        if (hasOwnProperty(map, key)) {
          output.push(map[key]);
          found = true;
          break;
        } else {
          var last = copy.pop();
          if (last) {
            rest.unshift(last);
          }
        }
      }
      if (found) {
        parts = rest;
      } else {
        output.push(value);
      }
    }
  }
  if (onlyKey) {
    return output.pop();
  }
  return output.join('.');
}

/*
 * Copyright (c) 2022.
 * Author Peter Placzek (tada5hi)
 * For the full copyright and license information,
 * view the LICENSE file that was distributed with this source code.
 */

function getFieldDetails(field) {
  var parts = field.split('.');
  return {
    name: parts.pop(),
    path: parts.length > 0 ? parts.join('.') : undefined
  };
}

/*
 * Copyright (c) 2021-2022.
 * Author Peter Placzek (tada5hi)
 * For the full copyright and license information,
 * view the LICENSE file that was distributed with this source code.
 */
function isFieldNonRelational(field) {
  var details = typeof field === 'string' ? getFieldDetails(field) : field;
  return typeof details.path === 'undefined';
}
function isFieldPathAllowedByRelations(field, includes) {
  if (typeof includes === 'undefined') {
    return true;
  }
  var details = typeof field === 'string' ? getFieldDetails(field) : field;
  if (typeof details.path === 'undefined') {
    return true;
  }
  return includes.some(function (include) {
    return include.key === details.path;
  });
}
function buildFieldWithPath(field, path) {
  var details = typeof field === 'string' ? getFieldDetails(field) : field;
  return details.path || path ? "".concat(details.path || path, ".").concat(details.name) : details.name;
}

/*
 * Copyright (c) 2021-2022.
 * Author Peter Placzek (tada5hi)
 * For the full copyright and license information,
 * view the LICENSE file that was distributed with this source code.
 */

function buildURLQueryString(data) {
  var withQuestionMark = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
  if (typeof data === 'undefined' || data === null) return '';

  // If the data is already a string, return it as-is
  if (typeof data === 'string') return data;

  // Create a query array to hold the key/value pairs
  var query = [];

  // Loop through the data object
  var keys = Object.keys(data);
  for (var i = 0; i < keys.length; i++) {
    if (Object.prototype.hasOwnProperty.call(data, keys[i])) {
      var value = data[keys[i]];
      if (value && _typeof(value) === 'object' && value.constructor === Array) {
        value = value.join(',');
      }
      if (value && _typeof(value) === 'object' && value.constructor === Object) {
        var valueKeys = Object.keys(value);
        for (var j = 0; j < valueKeys.length; j++) {
          var v = value[valueKeys[j]];
          if (v && _typeof(v) === 'object' && v.constructor === Array) {
            v = v.join(',');
          }
          query.push("".concat(encodeURIComponent("".concat(keys[i], "[").concat(valueKeys[j], "]")), "=").concat(encodeURIComponent(v)));
        }
        continue;
      }

      // Encode each key and value, concatenate them into a string, and push them to the array
      query.push("".concat(encodeURIComponent(keys[i]), "=").concat(encodeURIComponent(value)));
    }
  }

  // Join each item in the array with a `&` and return the resulting string
  return (withQuestionMark ? '?' : '') + query.join('&');
}

/*
 * Copyright (c) 2021-2022.
 * Author Peter Placzek (tada5hi)
 * For the full copyright and license information,
 * view the LICENSE file that was distributed with this source code.
 */
function buildQueryFields(input) {
  if (typeof input === 'undefined') {
    return [];
  }
  var data = groupArrayByKeyPath(flattenToKeyPathArray(input));
  var keys = Object.keys(data);
  if (keys.length === 1) {
    return data[keys[0]];
  }
  return data;
}
function mergeQueryFields(target, source) {
  if (Array.isArray(target)) {
    target = groupArrayByKeyPath(target);
  }
  if (Array.isArray(source)) {
    source = groupArrayByKeyPath(source);
  }
  var merge = smob.createMerger({
    array: true,
    arrayDistinct: true
  });
  var data = merge({}, target, source);
  var keys = Object.keys(data);
  if (keys.length === 1) {
    return data[keys[0]];
  }
  return data;
}

/*
 * Copyright (c) 2022.
 * Author Peter Placzek (tada5hi)
 * For the full copyright and license information,
 * view the LICENSE file that was distributed with this source code.
 */

exports.FieldOperator = void 0;
(function (FieldOperator) {
  FieldOperator["INCLUDE"] = "+";
  FieldOperator["EXCLUDE"] = "-";
})(exports.FieldOperator || (exports.FieldOperator = {}));

/*
 * Copyright (c) 2022-2022.
 * Author Peter Placzek (tada5hi)
 * For the full copyright and license information,
 * view the LICENSE file that was distributed with this source code.
 */
function flattenParseAllowedOption(input) {
  return flattenToKeyPathArray(input);
}
function isPathCoveredByParseAllowedOption(input, path) {
  var paths = Array.isArray(path) ? path : [path];
  var items = flattenToKeyPathArray(input);
  for (var i = 0; i < items.length; i++) {
    if (paths.indexOf(items[i]) !== -1) {
      return true;
    }
  }
  return false;
}

/*
 * Copyright (c) 2022.
 * Author Peter Placzek (tada5hi)
 * For the full copyright and license information,
 * view the LICENSE file that was distributed with this source code.
 */
function buildFieldDomainRecords(data) {
  if (typeof data === 'undefined') {
    return {};
  }
  var domainFields = {};
  if (Array.isArray(data)) {
    domainFields[DEFAULT_ID] = data;
  } else {
    domainFields = data;
  }
  return domainFields;
}

/*
 * Copyright (c) 2022.
 * Author Peter Placzek (tada5hi)
 * For the full copyright and license information,
 * view the LICENSE file that was distributed with this source code.
 */
function removeFieldInputOperator(field) {
  return field.substring(0, 1) === exports.FieldOperator.INCLUDE || field.substring(0, 1) === exports.FieldOperator.EXCLUDE ? field.substring(1) : field;
}
function transformFieldsInput(fields) {
  var output = {
    "default": [],
    included: [],
    excluded: []
  };
  for (var i = 0; i < fields.length; i++) {
    var operator = void 0;
    if (fields[i].substring(0, 1) === exports.FieldOperator.INCLUDE) {
      operator = exports.FieldOperator.INCLUDE;
    } else if (fields[i].substring(0, 1) === exports.FieldOperator.EXCLUDE) {
      operator = exports.FieldOperator.EXCLUDE;
    }
    if (operator) {
      fields[i] = fields[i].substring(1);
      switch (operator) {
        case exports.FieldOperator.INCLUDE:
          {
            output.included.push(fields[i]);
            break;
          }
        case exports.FieldOperator.EXCLUDE:
          {
            output.excluded.push(fields[i]);
            break;
          }
      }
    } else {
      output["default"].push(fields[i]);
    }
  }
  return output;
}
function parseFieldsInput(data) {
  var valuePrototype = Object.prototype.toString.call(data);
  if (valuePrototype !== '[object Array]' && valuePrototype !== '[object String]') {
    return [];
  }
  var fieldsArr = [];

  /* istanbul ignore next */
  if (valuePrototype === '[object String]') {
    fieldsArr = data.split(',');
  }

  /* istanbul ignore next */
  if (valuePrototype === '[object Array]') {
    fieldsArr = data.filter(function (val) {
      return typeof val === 'string';
    });
  }
  return fieldsArr;
}

/*
 * Copyright (c) 2022.
 * Author Peter Placzek (tada5hi)
 * For the full copyright and license information,
 * view the LICENSE file that was distributed with this source code.
 */

function isValidFieldName(input) {
  return /^[A-Z_a-z][0-9A-Z_a-z]*$/g.test(input);
}

// --------------------------------------------------

function buildReverseRecord(record) {
  var keys = Object.keys(record);
  var output = {};
  for (var i = 0; i < keys.length; i++) {
    output[record[keys[i]]] = keys[i];
  }
  return output;
}
function parseQueryFields(data, options) {
  var _options, _options2, _options2$mapping;
  (_options = options) !== null && _options !== void 0 ? _options : options = {};
  var defaultDomainFields = groupArrayByKeyPath(flattenParseAllowedOption(options["default"]));
  var allowedDomainFields = groupArrayByKeyPath(flattenParseAllowedOption(options.allowed));
  var domainFields = smob.merge({}, defaultDomainFields, allowedDomainFields);
  var keys = Object.keys(domainFields);

  // If it is an empty array nothing is allowed
  if ((typeof options["default"] !== 'undefined' || typeof options.allowed !== 'undefined') && keys.length === 0) {
    return [];
  }
  var prototype = Object.prototype.toString.call(data);
  if (prototype !== '[object Object]' && prototype !== '[object Array]' && prototype !== '[object String]') {
    data = _defineProperty({}, DEFAULT_ID, []);
  }
  if (prototype === '[object String]') {
    data = _defineProperty({}, DEFAULT_ID, data);
  }
  if (prototype === '[object Array]') {
    data = _defineProperty({}, DEFAULT_ID, data);
  }
  (_options2$mapping = (_options2 = options).mapping) !== null && _options2$mapping !== void 0 ? _options2$mapping : _options2.mapping = {};
  var reverseMapping = buildReverseRecord(options.mapping);
  if (keys.length === 0) {
    keys = Object.keys(data);
  }
  var output = [];
  var _loop = function _loop(i) {
    var path = keys[i];
    if (!isFieldPathAllowedByRelations({
      path: path
    }, options.relations) && path !== DEFAULT_ID) {
      return "continue";
    }
    var fields = [];
    if (hasOwnProperty(data, path)) {
      fields = parseFieldsInput(data[path]);
    } else if (hasOwnProperty(reverseMapping, path)) {
      if (hasOwnProperty(data, reverseMapping[path])) {
        fields = parseFieldsInput(data[reverseMapping[path]]);
      }
    }
    var transformed = {
      "default": [],
      included: [],
      excluded: []
    };
    if (fields.length > 0) {
      for (var j = 0; j < fields.length; j++) {
        fields[j] = applyMapping(buildFieldWithPath({
          name: fields[j],
          path: path
        }), options.mapping, true);
      }
      if (hasOwnProperty(domainFields, path)) {
        fields = fields.filter(function (field) {
          return domainFields[path].indexOf(removeFieldInputOperator(field)) !== -1;
        });
      } else {
        fields = fields.filter(function (field) {
          return isValidFieldName(removeFieldInputOperator(field));
        });
      }
      transformed = transformFieldsInput(fields);
    }
    if (transformed["default"].length === 0 && hasOwnProperty(defaultDomainFields, path)) {
      transformed["default"] = defaultDomainFields[path];
    }
    if (transformed.included.length === 0 && transformed["default"].length === 0 && hasOwnProperty(allowedDomainFields, path)) {
      transformed["default"] = allowedDomainFields[path];
    }
    transformed["default"] = Array.from(new Set([].concat(_toConsumableArray(transformed["default"]), _toConsumableArray(transformed.included))));
    for (var _j = 0; _j < transformed.excluded.length; _j++) {
      var index = transformed["default"].indexOf(transformed.excluded[_j]);
      if (index !== -1) {
        transformed["default"].splice(index, 1);
      }
    }
    if (transformed["default"].length > 0) {
      for (var _j2 = 0; _j2 < transformed["default"].length; _j2++) {
        var destPath = void 0;
        if (path !== DEFAULT_ID) {
          destPath = path;
        } else if (options.defaultPath) {
          destPath = options.defaultPath;
        }
        output.push(_objectSpread2({
          key: transformed["default"][_j2]
        }, destPath ? {
          path: destPath
        } : {}));
      }
    }
  };
  for (var i = 0; i < keys.length; i++) {
    var _ret = _loop(i);
    if (_ret === "continue") continue;
  }
  return output;
}

/*
 * Copyright (c) 2022-2022.
 * Author Peter Placzek (tada5hi)
 * For the full copyright and license information,
 * view the LICENSE file that was distributed with this source code.
 */

exports.FilterComparisonOperator = void 0;
(function (FilterComparisonOperator) {
  FilterComparisonOperator["EQUAL"] = "$eq";
  FilterComparisonOperator["NOT_EQUAL"] = "$ne";
  FilterComparisonOperator["LIKE"] = "$l";
  FilterComparisonOperator["NOT_LIKE"] = "$nl";
  FilterComparisonOperator["LESS_THAN_EQUAL"] = "$lte";
  FilterComparisonOperator["LESS_THAN"] = "$lt";
  FilterComparisonOperator["GREATER_THAN_EQUAL"] = "$gte";
  FilterComparisonOperator["GREATER_THAN"] = "$gt";
  FilterComparisonOperator["IN"] = "$in";
  FilterComparisonOperator["NOT_IN"] = "$nin";
})(exports.FilterComparisonOperator || (exports.FilterComparisonOperator = {}));
exports.FilterInputOperatorValue = void 0;
(function (FilterInputOperatorValue) {
  FilterInputOperatorValue["NEGATION"] = "!";
  FilterInputOperatorValue["LIKE"] = "~";
  FilterInputOperatorValue["LESS_THAN_EQUAL"] = "<=";
  FilterInputOperatorValue["LESS_THAN"] = "<";
  FilterInputOperatorValue["MORE_THAN_EQUAL"] = ">=";
  FilterInputOperatorValue["MORE_THAN"] = ">";
  FilterInputOperatorValue["IN"] = ",";
})(exports.FilterInputOperatorValue || (exports.FilterInputOperatorValue = {}));

/*
 * Copyright (c) 2021-2022.
 * Author Peter Placzek (tada5hi)
 * For the full copyright and license information,
 * view the LICENSE file that was distributed with this source code.
 */
function buildQueryFilters(data) {
  if (typeof data === 'undefined') {
    return {};
  }
  return flattenNestedObject(data, {
    transformer: function transformer(input, output, key) {
      if (typeof input === 'undefined') {
        output[key] = null;
        return true;
      }
      if (Array.isArray(input)) {
        // preserve null values
        var _data = [];
        for (var i = 0; i < input.length; i++) {
          if (input[i] === null) {
            input[i] = 'null';
          }
          if (typeof input[i] === 'number') {
            input[i] = "".concat(input[i]);
          }
          if (typeof input[i] === 'string') {
            _data.push(input[i]);
          }
        }
        output[key] = _data.join(',');
        return true;
      }
      return undefined;
    }
  });
}
function mergeQueryFilters(target, source) {
  return smob.merge({}, target || {}, source || {});
}

/*
 * Copyright (c) 2022.
 * Author Peter Placzek (tada5hi)
 * For the full copyright and license information,
 * view the LICENSE file that was distributed with this source code.
 */

function transformFilterValue(input) {
  if (typeof input === 'string') {
    input = input.trim();
    var lower = input.toLowerCase();
    if (lower === 'true') {
      return true;
    }
    if (lower === 'false') {
      return false;
    }
    if (lower === 'null') {
      return null;
    }
    if (input.length === 0) {
      return input;
    }
    var num = Number(input);
    if (!Number.isNaN(num)) {
      return num;
    }
    var parts = input.split(',');
    if (parts.length > 1) {
      return transformFilterValue(parts);
    }
  }
  if (Array.isArray(input)) {
    for (var i = 0; i < input.length; i++) {
      input[i] = transformFilterValue(input[i]);
    }
    return input.filter(function (n) {
      return n === 0 || n === null || !!n;
    });
  }
  if (typeof input === 'undefined' || input === null) {
    return null;
  }
  return input;
}

/*
 * Copyright (c) 2022-2022.
 * Author Peter Placzek (tada5hi)
 * For the full copyright and license information,
 * view the LICENSE file that was distributed with this source code.
 */
function matchOperator(key, value, position) {
  if (typeof value === 'string') {
    switch (position) {
      case 'start':
        {
          if (value.substring(0, key.length) === key) {
            return value.substring(key.length);
          }
          break;
        }
      case 'end':
        {
          if (value.substring(0 - key.length) === key) {
            return value.substring(0, value.length - key.length - 1);
          }
          break;
        }
    }
    return undefined;
  }
  if (Array.isArray(value)) {
    var match = false;
    for (var i = 0; i < value.length; i++) {
      var output = matchOperator(key, value[i], position);
      if (typeof output !== 'undefined') {
        match = true;
        value[i] = output;
      }
    }
    if (match) {
      return value;
    }
  }
  return undefined;
}
function parseFilterValue(input) {
  if (typeof input === 'string' && input.includes(exports.FilterInputOperatorValue.IN)) {
    input = input.split(exports.FilterInputOperatorValue.IN);
  }
  var negation = false;
  var value = matchOperator(exports.FilterInputOperatorValue.NEGATION, input, 'start');
  if (typeof value !== 'undefined') {
    negation = true;
    input = value;
  }
  if (Array.isArray(input)) {
    return {
      value: input,
      operator: negation ? exports.FilterComparisonOperator.NOT_IN : exports.FilterComparisonOperator.IN
    };
  }
  value = matchOperator(exports.FilterInputOperatorValue.LIKE, input, 'start');
  if (typeof value !== 'undefined') {
    return {
      value: value,
      operator: negation ? exports.FilterComparisonOperator.NOT_LIKE : exports.FilterComparisonOperator.LIKE
    };
  }
  value = matchOperator(exports.FilterInputOperatorValue.LESS_THAN_EQUAL, input, 'start');
  if (typeof value !== 'undefined') {
    return {
      value: value,
      operator: exports.FilterComparisonOperator.LESS_THAN_EQUAL
    };
  }
  value = matchOperator(exports.FilterInputOperatorValue.LESS_THAN, input, 'start');
  if (typeof value !== 'undefined') {
    return {
      value: value,
      operator: exports.FilterComparisonOperator.LESS_THAN
    };
  }
  value = matchOperator(exports.FilterInputOperatorValue.MORE_THAN_EQUAL, input, 'start');
  if (typeof value !== 'undefined') {
    return {
      value: value,
      operator: exports.FilterComparisonOperator.GREATER_THAN_EQUAL
    };
  }
  value = matchOperator(exports.FilterInputOperatorValue.MORE_THAN, input, 'start');
  if (typeof value !== 'undefined') {
    return {
      value: value,
      operator: exports.FilterComparisonOperator.GREATER_THAN
    };
  }
  return {
    value: input,
    operator: negation ? exports.FilterComparisonOperator.NOT_EQUAL : exports.FilterComparisonOperator.EQUAL
  };
}

// --------------------------------------------------

function transformFiltersParseOutputElement(element) {
  if (hasOwnProperty(element, 'path') && (typeof element.path === 'undefined' || element.path === null)) {
    delete element.path;
  }
  if (element.operator) {
    return element;
  }
  if (typeof element.value === 'string') {
    element = _objectSpread2(_objectSpread2({}, element), parseFilterValue(element.value));
  } else {
    element.operator = exports.FilterComparisonOperator.EQUAL;
  }
  element.value = transformFilterValue(element.value);
  return element;
}
function buildDefaultFiltersParseOutput(options, input) {
  var inputKeys = Object.keys(input || {});
  if (!options.defaultByElement && inputKeys.length > 0) {
    return Object.values(input);
  }
  if (options["default"]) {
    var flatten = flattenNestedObject(options["default"]);
    var keys = Object.keys(flatten);
    var output = [];
    for (var i = 0; i < keys.length; i++) {
      var fieldDetails = getFieldDetails(keys[i]);
      if (options.defaultByElement && inputKeys.length > 0) {
        var fieldWithAlias = buildFieldWithPath(fieldDetails);
        if (hasOwnProperty(input, fieldWithAlias)) {
          continue;
        }
      }
      if (options.defaultByElement || inputKeys.length === 0) {
        var path = void 0;
        if (fieldDetails.path) {
          path = fieldDetails.path;
        } else if (options.defaultPath) {
          path = options.defaultPath;
        }
        output.push(transformFiltersParseOutputElement(_objectSpread2(_objectSpread2({}, path ? {
          path: path
        } : {}), {}, {
          key: fieldDetails.name,
          value: flatten[keys[i]]
        })));
      }
    }
    return input ? [].concat(_toConsumableArray(Object.values(input)), output) : output;
  }
  return input ? Object.values(input) : [];
}
function parseQueryFilters(data, options) {
  var _options;
  options = (_options = options) !== null && _options !== void 0 ? _options : {};
  options.mapping = options.mapping || {};
  options.relations = options.relations || [];

  // If it is an empty array nothing is allowed
  if (typeof options.allowed !== 'undefined') {
    options.allowed = flattenParseAllowedOption(options.allowed);
    if (options.allowed.length === 0) {
      return buildDefaultFiltersParseOutput(options);
    }
  }

  /* istanbul ignore next */
  if (_typeof(data) !== 'object' || data === null) {
    return buildDefaultFiltersParseOutput(options);
  }
  var _Object$keys = Object.keys(data),
    length = _Object$keys.length;
  if (length === 0) {
    return buildDefaultFiltersParseOutput(options);
  }
  if ((typeof options.allowed === 'undefined' || options.allowed.length === 0) && options["default"]) {
    var flatten = flattenNestedObject(options["default"]);
    options.allowed = Object.keys(flatten);
  }
  var items = {};

  // transform to appreciate data format & validate input
  var keys = Object.keys(data);
  for (var i = 0; i < keys.length; i++) {
    /* istanbul ignore next */
    if (!hasOwnProperty(data, keys[i])) {
      // eslint-disable-next-line no-continue
      continue;
    }
    var value = data[keys[i]];
    if (typeof value !== 'string' && typeof value !== 'number' && typeof value !== 'boolean' && typeof value !== 'undefined' && value !== null && !Array.isArray(value)) {
      continue;
    }
    keys[i] = applyMapping(keys[i], options.mapping);
    var fieldDetails = getFieldDetails(keys[i]);
    if (typeof options.allowed === 'undefined' && !isValidFieldName(fieldDetails.name)) {
      continue;
    }
    if (!isFieldPathAllowedByRelations(fieldDetails, options.relations) && !isFieldNonRelational(fieldDetails)) {
      continue;
    }
    var fullKey = buildFieldWithPath(fieldDetails);
    if (options.allowed && !isPathCoveredByParseAllowedOption(options.allowed, [keys[i], fullKey])) {
      continue;
    }
    var filter = transformFiltersParseOutputElement({
      key: fieldDetails.name,
      value: value
    });
    if (options.validate) {
      if (Array.isArray(filter.value)) {
        var output = [];
        for (var j = 0; j < filter.value.length; j++) {
          if (options.validate(filter.key, filter.value[j])) {
            output.push(filter.value[j]);
          }
        }
        filter.value = output;
        if (filter.value.length === 0) {
          continue;
        }
      } else if (!options.validate(filter.key, filter.value)) {
        continue;
      }
    }
    if (typeof filter.value === 'string' && filter.value.length === 0) {
      continue;
    }
    if (Array.isArray(filter.value) && filter.value.length === 0) {
      continue;
    }
    if (fieldDetails.path || options.defaultPath) {
      filter.path = fieldDetails.path || options.defaultPath;
    }
    items[fullKey] = filter;
  }
  return buildDefaultFiltersParseOutput(options, items);
}

/*
 * Copyright (c) 2022.
 * Author Peter Placzek (tada5hi)
 * For the full copyright and license information,
 * view the LICENSE file that was distributed with this source code.
 */
function mergeQueryPagination(target, source) {
  return smob.merge({}, target || {}, source || {});
}

/*
 * Copyright (c) 2022.
 * Author Peter Placzek (tada5hi)
 * For the full copyright and license information,
 * view the LICENSE file that was distributed with this source code.
 */

// --------------------------------------------------

function finalizePagination(data, options) {
  if (typeof options.maxLimit !== 'undefined') {
    if (typeof data.limit === 'undefined' || data.limit > options.maxLimit) {
      data.limit = options.maxLimit;
    }
  }
  if (typeof data.limit !== 'undefined' && typeof data.offset === 'undefined') {
    data.offset = 0;
  }
  return data;
}

/**
 * Transform pagination data to an appreciate data format.
 *
 * @param data
 * @param options
 */
function parseQueryPagination(data, options) {
  var _options;
  (_options = options) !== null && _options !== void 0 ? _options : options = {};
  var pagination = {};
  var prototype = Object.prototype.toString.call(data);
  if (prototype !== '[object Object]') {
    return finalizePagination(pagination, options);
  }
  var _ref = data,
    limit = _ref.limit,
    offset = _ref.offset;
  if (typeof limit !== 'undefined') {
    limit = parseInt(limit, 10);
    if (!Number.isNaN(limit) && limit > 0) {
      pagination.limit = limit;
    }
  }
  if (typeof offset !== 'undefined') {
    offset = parseInt(offset, 10);
    if (!Number.isNaN(offset) && offset >= 0) {
      pagination.offset = offset;
    }
  }
  return finalizePagination(pagination, options);
}

/*
 * Copyright (c) 2022.
 * Author Peter Placzek (tada5hi)
 * For the full copyright and license information,
 * view the LICENSE file that was distributed with this source code.
 */
function buildQueryRelations(input) {
  if (typeof input === 'undefined') {
    return input;
  }
  return flattenToKeyPathArray(input);
}
function mergeQueryRelations(target, source) {
  return smob.mergeArrays(target || [], source || [], true);
}

/*
 * Copyright (c) 2022.
 * Author Peter Placzek (tada5hi)
 * For the full copyright and license information,
 * view the LICENSE file that was distributed with this source code.
 */

function includeParents(data) {
  for (var i = 0; i < data.length; i++) {
    var parts = data[i].split('.');
    while (parts.length > 0) {
      parts.pop();
      if (parts.length > 0) {
        var value = parts.join('.');
        if (data.indexOf(value) === -1) {
          data.unshift(value);
        }
      }
    }
  }
  return data;
}

/*
 * Copyright (c) 2022.
 * Author Peter Placzek (tada5hi)
 * For the full copyright and license information,
 * view the LICENSE file that was distributed with this source code.
 */

function isValidRelationPath(input) {
  return /^[\x2D0-9A-Z_a-z]+(\.*[\x2D0-9A-Z_a-z])*$/g.test(input);
}

// --------------------------------------------------

function parseQueryRelations(data, options) {
  var _options, _options2, _options2$includePare;
  (_options = options) !== null && _options !== void 0 ? _options : options = {};

  // If it is an empty array nothing is allowed
  if (Array.isArray(options.allowed) && options.allowed.length === 0) {
    return [];
  }
  options.mapping = options.mapping || {};
  options.pathMapping = options.pathMapping || {};
  (_options2$includePare = (_options2 = options).includeParents) !== null && _options2$includePare !== void 0 ? _options2$includePare : _options2.includeParents = true;
  var items = [];
  var prototype = Object.prototype.toString.call(data);
  if (prototype !== '[object Array]' && prototype !== '[object String]') {
    return [];
  }
  if (prototype === '[object String]') {
    items = data.split(',');
  }
  if (prototype === '[object Array]') {
    items = data.filter(function (el) {
      return typeof el === 'string';
    });
  }
  if (items.length === 0) {
    return [];
  }
  var mappingKeys = Object.keys(options.mapping);
  if (mappingKeys.length > 0) {
    for (var i = 0; i < items.length; i++) {
      items[i] = applyMapping(items[i], options.mapping);
    }
  }
  if (options.allowed) {
    items = items.filter(function (item) {
      return isPathCoveredByParseAllowedOption(options.allowed, item);
    });
  } else {
    items = items.filter(function (item) {
      return isValidRelationPath(item);
    });
  }
  if (options.includeParents) {
    if (Array.isArray(options.includeParents)) {
      var _items;
      var parentIncludes = items.filter(function (item) {
        return item.includes('.') && options.includeParents.filter(function (parent) {
          return minimatch__default["default"](item, parent);
        }).length > 0;
      });
      (_items = items).unshift.apply(_items, _toConsumableArray(includeParents(parentIncludes)));
    } else {
      items = includeParents(items);
    }
  }
  items = Array.from(new Set(items));
  return items.map(function (key) {
    var parts = key.split('.');
    var value;
    if (options.pathMapping && hasOwnProperty(options.pathMapping, key)) {
      value = options.pathMapping[key];
    } else {
      value = parts.pop();
    }
    return {
      key: key,
      value: value
    };
  });
}

/*
 * Copyright (c) 2021-2022.
 * Author Peter Placzek (tada5hi)
 * For the full copyright and license information,
 * view the LICENSE file that was distributed with this source code.
 */

exports.SortDirection = void 0;

// -----------------------------------------------------------
// Build
// -----------------------------------------------------------
(function (SortDirection) {
  SortDirection["ASC"] = "ASC";
  SortDirection["DESC"] = "DESC";
})(exports.SortDirection || (exports.SortDirection = {}));

/*
 * Copyright (c) 2022.
 * Author Peter Placzek (tada5hi)
 * For the full copyright and license information,
 * view the LICENSE file that was distributed with this source code.
 */
function buildQuerySort(data) {
  if (typeof data === 'undefined') {
    return [];
  }
  if (typeof data === 'string') {
    return [data];
  }
  return flattenToKeyPathArray(data, {
    transformer: function transformer(input, output, path) {
      if (typeof input === 'string' && path && (input === exports.SortDirection.ASC || input === exports.SortDirection.DESC)) {
        if (input === exports.SortDirection.DESC) {
          output.push("-".concat(path));
        } else {
          output.push(path);
        }
        return true;
      }
      return undefined;
    }
  });
}
function mergeQuerySort(target, source) {
  return smob.mergeArrays(target || [], source || [], true);
}

/*
 * Copyright (c) 2022.
 * Author Peter Placzek (tada5hi)
 * For the full copyright and license information,
 * view the LICENSE file that was distributed with this source code.
 */
function parseSortValue(value) {
  var direction = exports.SortDirection.ASC;
  if (value.substring(0, 1) === '-') {
    direction = exports.SortDirection.DESC;
    value = value.substring(1);
  }
  return {
    direction: direction,
    value: value
  };
}

// --------------------------------------------------

function isMultiDimensionalArray(arr) {
  if (!Array.isArray(arr)) {
    return false;
  }
  return arr.length > 0 && Array.isArray(arr[0]);
}
function buildDefaultSortParseOutput(options) {
  if (options["default"]) {
    var output = [];
    var flatten = flattenNestedObject(options["default"]);
    var keys = Object.keys(flatten);
    for (var i = 0; i < keys.length; i++) {
      var fieldDetails = getFieldDetails(keys[i]);
      var path = void 0;
      if (fieldDetails.path) {
        path = fieldDetails.path;
      } else if (options.defaultPath) {
        path = options.defaultPath;
      }
      output.push(_objectSpread2(_objectSpread2({
        key: fieldDetails.name
      }, path ? {
        path: path
      } : {}), {}, {
        value: flatten[keys[i]]
      }));
    }
    return output;
  }
  return [];
}

/**
 * Transform sort data to appreciate data format.
 * @param data
 * @param options
 */
function parseQuerySort(data, options) {
  var _options;
  options = (_options = options) !== null && _options !== void 0 ? _options : {};

  // If it is an empty array nothing is allowed
  if (typeof options.allowed !== 'undefined') {
    var allowed = flattenParseAllowedOption(options.allowed);
    if (allowed.length === 0) {
      return buildDefaultSortParseOutput(options);
    }
  }
  options.mapping = options.mapping || {};
  var prototype = Object.prototype.toString.call(data);

  /* istanbul ignore next */
  if (prototype !== '[object String]' && prototype !== '[object Array]' && prototype !== '[object Object]') {
    return buildDefaultSortParseOutput(options);
  }
  if (typeof options.allowed === 'undefined' && options["default"]) {
    var flatten = flattenNestedObject(options["default"]);
    options.allowed = Object.keys(flatten);
  }
  var parts = [];
  if (typeof data === 'string') {
    parts = data.split(',');
  }
  if (Array.isArray(data)) {
    parts = data.filter(function (item) {
      return typeof item === 'string';
    });
  }
  if (_typeof(data) === 'object' && data !== null) {
    var keys = Object.keys(data);
    for (var i = 0; i < keys.length; i++) {
      /* istanbul ignore next */
      if (!hasOwnProperty(data, keys[i]) || typeof keys[i] !== 'string' || typeof data[keys[i]] !== 'string') continue;
      var fieldPrefix = data[keys[i]].toLowerCase() === 'desc' ? '-' : '';
      parts.push(fieldPrefix + keys[i]);
    }
  }
  var items = {};
  var matched = false;
  for (var _i = 0; _i < parts.length; _i++) {
    var _parseSortValue = parseSortValue(parts[_i]),
      value = _parseSortValue.value,
      direction = _parseSortValue.direction;
    parts[_i] = value;
    var key = applyMapping(parts[_i], options.mapping);
    var fieldDetails = getFieldDetails(key);
    if (typeof options.allowed === 'undefined' && !isValidFieldName(fieldDetails.name)) {
      continue;
    }
    if (!isFieldPathAllowedByRelations(fieldDetails, options.relations) && !isFieldNonRelational(fieldDetails)) {
      continue;
    }
    var keyWithAlias = buildFieldWithPath(fieldDetails);
    if (typeof options.allowed !== 'undefined' && !isMultiDimensionalArray(options.allowed) && !isPathCoveredByParseAllowedOption(options.allowed, [key, keyWithAlias])) {
      continue;
    }
    matched = true;
    var path = void 0;
    if (fieldDetails.path) {
      path = fieldDetails.path;
    } else if (options.defaultPath) {
      path = options.defaultPath;
    }
    items[keyWithAlias] = _objectSpread2(_objectSpread2({
      key: fieldDetails.name
    }, path ? {
      path: path
    } : {}), {}, {
      value: direction
    });
  }
  if (!matched) {
    return buildDefaultSortParseOutput(options);
  }
  if (isMultiDimensionalArray(options.allowed)) {
    // eslint-disable-next-line no-labels,no-restricted-syntax
    outerLoop: for (var _i2 = 0; _i2 < options.allowed.length; _i2++) {
      var temp = [];
      var keyPaths = flattenParseAllowedOption(options.allowed[_i2]);
      for (var j = 0; j < keyPaths.length; j++) {
        var _keyWithAlias = keyPaths[j];
        var _key = void 0;
        var _parts = _keyWithAlias.split('.');
        if (_parts.length > 1) {
          _key = _parts.pop();
        } else {
          _key = _keyWithAlias;
          _keyWithAlias = buildKeyPath(_key, options.defaultPath);
        }
        if (hasOwnProperty(items, _key) || hasOwnProperty(items, _keyWithAlias)) {
          var item = hasOwnProperty(items, _key) ? items[_key] : items[_keyWithAlias];
          temp.push(item);
        } else {
          // eslint-disable-next-line no-labels
          continue outerLoop;
        }
      }
      return temp;
    }

    // if we get no match, the sort data is invalid.
    return [];
  }
  return Object.values(items);
}

/*
 * Copyright (c) 2021-2022.
 * Author Peter Placzek (tada5hi)
 * For the full copyright and license information,
 * view the LICENSE file that was distributed with this source code.
 */
function buildQuery(input) {
  if (typeof input === 'undefined' || input === null) {
    return '';
  }
  var query = {};
  if (typeof input[exports.Parameter.FIELDS] !== 'undefined' || typeof input[exports.URLParameter.FIELDS] !== 'undefined') {
    query[exports.URLParameter.FIELDS] = mergeQueryFields(buildQueryFields(input[exports.Parameter.FIELDS]), buildQueryFields(input[exports.URLParameter.FIELDS]));
  }
  if (typeof input[exports.Parameter.FILTERS] !== 'undefined' || typeof input[exports.URLParameter.FILTERS] !== 'undefined') {
    query[exports.URLParameter.FILTERS] = mergeQueryFilters(buildQueryFilters(input[exports.Parameter.FILTERS]), buildQueryFilters(input[exports.URLParameter.FILTERS]));
  }
  if (typeof input[exports.Parameter.PAGINATION] !== 'undefined' || typeof input[exports.URLParameter.PAGINATION] !== 'undefined') {
    query[exports.URLParameter.PAGINATION] = mergeQueryPagination(input[exports.Parameter.PAGINATION], input[exports.URLParameter.PAGINATION]);
  }
  if (typeof input[exports.Parameter.RELATIONS] !== 'undefined' || typeof input[exports.URLParameter.RELATIONS] !== 'undefined') {
    query[exports.URLParameter.RELATIONS] = mergeQueryRelations(buildQueryRelations(input[exports.Parameter.RELATIONS]), buildQueryRelations(input[exports.URLParameter.RELATIONS]));
  }
  if (typeof input[exports.Parameter.SORT] !== 'undefined' || typeof input[exports.URLParameter.SORT] !== 'undefined') {
    query[exports.URLParameter.SORT] = mergeQuerySort(buildQuerySort(input[exports.Parameter.SORT]), buildQuerySort(input[exports.URLParameter.SORT]));
  }
  return buildURLQueryString(query);
}

function parseQueryParameter(key, data, options, relations) {
  switch (key) {
    case exports.Parameter.FIELDS:
    case exports.URLParameter.FIELDS:
      return parseQueryFields(data, _objectSpread2(_objectSpread2({}, invalidToEmptyObject(options)), relations ? {
        relations: relations
      } : {}));
    case exports.Parameter.FILTERS:
    case exports.URLParameter.FILTERS:
      return parseQueryFilters(data, _objectSpread2(_objectSpread2({}, invalidToEmptyObject(options)), relations ? {
        relations: relations
      } : {}));
    case exports.Parameter.PAGINATION:
    case exports.URLParameter.PAGINATION:
      return parseQueryPagination(data, _objectSpread2({}, invalidToEmptyObject(options)));
    case exports.Parameter.RELATIONS:
    case exports.URLParameter.RELATIONS:
      return parseQueryRelations(data, _objectSpread2({}, invalidToEmptyObject(options)));
    default:
      return parseQuerySort(data, _objectSpread2(_objectSpread2({}, invalidToEmptyObject(options)), relations ? {
        relations: relations
      } : {}));
  }
}
function invalidToEmptyObject(value) {
  return typeof value === 'boolean' || typeof value === 'undefined' ? {} : value;
}

/*
 * Copyright (c) 2022.
 * Author Peter Placzek (tada5hi)
 * For the full copyright and license information,
 * view the LICENSE file that was distributed with this source code.
 */

function buildQueryParameterOptions(input) {
  if (typeof input === 'boolean') {
    return {};
  }
  return input;
}
function isQueryParameterEnabled(input) {
  if (typeof input === 'boolean') {
    return input;
  }
  return true;
}

/*
 * Copyright (c) 2021-2022.
 * Author Peter Placzek (tada5hi)
 * For the full copyright and license information,
 * view the LICENSE file that was distributed with this source code.
 */
function parseQuery(input, options) {
  var _options;
  (_options = options) !== null && _options !== void 0 ? _options : options = {};
  var mergeWithGlobalOptions = function mergeWithGlobalOptions(data) {
    if (typeof data !== 'undefined') {
      if (options.defaultPath) {
        data.defaultPath = options.defaultPath;
      }
    }
    return data;
  };
  var output = {};
  if (options.defaultPath) {
    output.defaultPath = options.defaultPath;
  }
  var relations;
  var keys = [
  // relations must be first parameter
  exports.Parameter.RELATIONS, exports.Parameter.FIELDS, exports.Parameter.FILTERS, exports.Parameter.PAGINATION, exports.Parameter.SORT];
  for (var i = 0; i < keys.length; i++) {
    var _key = keys[i];
    switch (_key) {
      case exports.Parameter.RELATIONS:
        {
          var _input$Parameter$RELA;
          var value = (_input$Parameter$RELA = input[exports.Parameter.RELATIONS]) !== null && _input$Parameter$RELA !== void 0 ? _input$Parameter$RELA : input[exports.URLParameter.RELATIONS];
          if (value && isQueryParameterEnabled(options[exports.Parameter.RELATIONS])) {
            relations = parseQueryParameter(_key, value, buildQueryParameterOptions(options[exports.Parameter.RELATIONS]));
            output[exports.Parameter.RELATIONS] = relations;
          }
          break;
        }
      case exports.Parameter.FIELDS:
        {
          var _input$Parameter$FIEL;
          var _value = (_input$Parameter$FIEL = input[exports.Parameter.FIELDS]) !== null && _input$Parameter$FIEL !== void 0 ? _input$Parameter$FIEL : input[exports.URLParameter.FIELDS];
          if (_value && isQueryParameterEnabled(options[exports.Parameter.FIELDS])) {
            output[exports.Parameter.FIELDS] = parseQueryParameter(_key, _value, mergeWithGlobalOptions(buildQueryParameterOptions(options[exports.Parameter.FIELDS])), relations);
          }
          break;
        }
      case exports.Parameter.FILTERS:
        {
          var _input$Parameter$FILT;
          var _value2 = (_input$Parameter$FILT = input[exports.Parameter.FILTERS]) !== null && _input$Parameter$FILT !== void 0 ? _input$Parameter$FILT : input[exports.URLParameter.FILTERS];
          if (_value2 && isQueryParameterEnabled(options[exports.Parameter.FILTERS])) {
            output[exports.Parameter.FILTERS] = parseQueryParameter(_key, _value2, mergeWithGlobalOptions(buildQueryParameterOptions(options[exports.Parameter.FILTERS])), relations);
          }
          break;
        }
      case exports.Parameter.PAGINATION:
        {
          var _input$Parameter$PAGI;
          var _value3 = (_input$Parameter$PAGI = input[exports.Parameter.PAGINATION]) !== null && _input$Parameter$PAGI !== void 0 ? _input$Parameter$PAGI : input[exports.URLParameter.PAGINATION];
          if (_value3 && isQueryParameterEnabled(options[exports.Parameter.PAGINATION])) {
            output[exports.Parameter.PAGINATION] = parseQueryParameter(_key, _value3, buildQueryParameterOptions(options[exports.Parameter.PAGINATION]), relations);
          }
          break;
        }
      case exports.Parameter.SORT:
        {
          var _input$Parameter$SORT;
          var _value4 = (_input$Parameter$SORT = input[exports.Parameter.SORT]) !== null && _input$Parameter$SORT !== void 0 ? _input$Parameter$SORT : input[exports.URLParameter.SORT];
          if (_value4 && isQueryParameterEnabled(options[exports.Parameter.SORT])) {
            output[exports.Parameter.SORT] = parseQueryParameter(_key, _value4, mergeWithGlobalOptions(buildQueryParameterOptions(options[exports.Parameter.SORT])), relations);
          }
          break;
        }
    }
  }
  return output;
}

exports.DEFAULT_ID = DEFAULT_ID;
exports.buildFieldDomainRecords = buildFieldDomainRecords;
exports.buildQuery = buildQuery;
exports.buildQueryFields = buildQueryFields;
exports.buildQueryFilters = buildQueryFilters;
exports.buildQueryParameterOptions = buildQueryParameterOptions;
exports.buildQueryRelations = buildQueryRelations;
exports.buildQuerySort = buildQuerySort;
exports.flattenParseAllowedOption = flattenParseAllowedOption;
exports.isPathCoveredByParseAllowedOption = isPathCoveredByParseAllowedOption;
exports.isQueryParameterEnabled = isQueryParameterEnabled;
exports.isValidFieldName = isValidFieldName;
exports.mergeQueryFields = mergeQueryFields;
exports.mergeQueryFilters = mergeQueryFilters;
exports.mergeQueryPagination = mergeQueryPagination;
exports.mergeQueryRelations = mergeQueryRelations;
exports.mergeQuerySort = mergeQuerySort;
exports.parseFieldsInput = parseFieldsInput;
exports.parseFilterValue = parseFilterValue;
exports.parseQuery = parseQuery;
exports.parseQueryFields = parseQueryFields;
exports.parseQueryFilters = parseQueryFilters;
exports.parseQueryPagination = parseQueryPagination;
exports.parseQueryParameter = parseQueryParameter;
exports.parseQueryRelations = parseQueryRelations;
exports.parseQuerySort = parseQuerySort;
exports.removeFieldInputOperator = removeFieldInputOperator;
exports.transformFieldsInput = transformFieldsInput;
exports.transformFilterValue = transformFilterValue;
