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,KAAK,YACvB,IAAK,IAAI,EAAI,EAAG,EAAI,EAAM,OAAQ,IAAK,CAErC,MAGM,EAAmB,IAAI,OAAO,IAHxB,mBACD,eACC,SAEZ,GAAI,EAAM,GAAG,MAAM,GAAmB,CACpC,IAAI,EAAO,OAAO,GACd,EAAK,OAAO,GACZ,EAAQ,OAAO,GACnB,IAAK,EAAU,GACb,MAAM,IAAI,MAAM,oBAAoB,KAEtC,MAAM,EAAW,EAAU,IAEvB,EAAM,MAAM,YAAc,EAAM,MAAM,mBACxC,EAAQ,MAEV,YAAY,EAAO,EAAM,EAAS,GAAI,EAAS,QAAQ,GACzD,CACF,CACF,CACA,GAAa,MAAT,EACF,MAAM,IAAI,MAAM,sBAAsB,KAExC,OAAO,CACT,CAWA,IAAA,CAAM,EAAY,GAGhB,EAAY,GAAa,KAAK,UAC9B,IAAI,EAAQ,GACR,EAAc,EAAW,MAAM,WACnC,IAAK,IAAI,EAAI,EAAG,EAAI,EAAY,OAAQ,IAAK,CAC3C,IAAI,EAAM,EAAY,GAAG,MAAM,KAC/B,GAAmB,IAAf,EAAI,OAAc,CACpB,IAAI,EAAO,EAAI,GACX,EAAM,EAAI,GAAG,cACb,EAAI,MAAM,cACZ,EAAM,KAAK,CAAC,EAAM,EAAI,eAE1B,CACF,CAMA,GALI,EAAW,MAAM,YACF,MAAb,IACF,EAAQ,CAAC,EAAU,GAAG,YAGb,MAAT,EACF,MAAM,IAAI,MAAM,4BAElB,OAAO,CACT,EAIF,OAAO,QAAU,IAAI","file":"/npm/sequelize-querystring-utf8@0.10.2/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/sequelize-querystring-utf8@0.10.2/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","'use strict'\n\nconst utf8letters = require('./utf8letters.js')\n\nconst identity = (v) => v\nconst arrayHave = (v) => { return v.split(' ').map(v => { return isNaN(v) ? `{${v}}` : v }) }\n\n/** @function\n * @description helper function used to construct query objects\n * (replacing _.set() to avoid importing all of underscore)\n */\nconst deepPropSet = (obj, dotPath, key, val) => {\n  const props = dotPath.split('.')\n  let here = obj\n  props.forEach((prop, i) => {\n    here = (here[prop] = here[prop] || {})\n  })\n  here[key] = val\n}\n\n/** @class\n *\n * @description Used to parse query strings and produce sort / filter objects \n *  for sequelize querying\n */\nclass SequelizeQueryStringParser { \n  /** @constructor\n   *\n   * @param {Object} sequelize - the user's `require('sequelize')`\n   * @param {Object} opts  - extra options to determine behaviour\n   * @param {Boolean} opts.symbolic - whether to use symbolic Ops \n   *    or (deprecated) string Ops\n   */\n  constructor (sequelize, opts={}) {\n    this.sequelize = sequelize\n    this.symbolic = opts.symbolic || false\n    if (opts.symbolic && !sequelize) {\n      throw new Error('requested symbolic Ops but didn\\'t provide Sequelize instance in constructor of SequelizeQueryStringParser (how are we going to look up the symbols?)')\n    }\n  }\n\n  /** @method\n   *\n   * @description a helper method which allows the user to get a parser with \n   *    symbolic=true by doing: \n   *    `const sqs = require('sequelize-querystring').withSymbolicOps(sequelize)`\n   *\n   * @param {Object} sequelize - the user's `require('sequelize')`\n   * @param {Object} opts  - extra options to determine behaviour\n   * @param {Boolean} opts.symbolic - will be set to true regardless of passed value\n   * @returns an instance of `SequelizeQueryStringParser` with symbolic=true.\n   */\n  withSymbolicOps (sequelize, opts={}) {\n    return new SequelizeQueryStringParser(sequelize, \n      Object.assign(opts, {symbolic: true}))\n  }\n\n  /** @method\n   *\n   * @description returns a table keyed by operator strings that will appear in the\n   *  GET query string (eg. 'gt'), where the values are objects with properties\n   *  'op' and 'val', where `op` is the operator symbol or string (depending on \n   *  `this.symbolic`) and `val` is a function transforming the right-hand-side\n   *  string in the GET query expression into an object which can be inserted into\n   *  the sequelize query object.\n   *\n   * @returns {Object} - the map, with `op` for each operation being either a\n   *  symbol (eg. Sequelize.Op.lt) or string (eg. '$lt') depending on `this.symbolic`\n   */\n  operators() {\n    const identityOps = {\n      valFunc: identity,\n      ops: ['gt', 'gte', 'lt', 'lte', 'ne', 'eq', 'not', 'like', \n      'notLike', 'iLike', 'notILike']\n    }\n    const arrayHaveOps = {\n      valFunc: arrayHave,\n      ops: ['or', 'in', 'notIn', 'overlap', 'contains', 'contained', 'between', 'notBetween']\n    }\n    let resultMap = {}\n    for (var opSet of [identityOps, arrayHaveOps]) {\n      for (var op of opSet.ops) {\n        resultMap[op] = {\n          'op': (this.symbolic ? this.sequelize.Op[op] : `$${op}`), \n          'valFunc': opSet.valFunc\n        }\n      }\n    }\n    return resultMap\n  }\n\n  /** @method\n   * \n   * Converts a query string into a where clause object for building \n   *    a sequelize query\n   *\n   * @param {String} expression - query string expression \n   *    (eg \"geoId eq 111, properties.publicoId  eq 1231\")\n   * @returns {Object} the where clause for building the corresponding \n   *    Sequelize query\n   */\n  find (expression) {\n    let where = {}\n    if (expression.match(new RegExp(`(([\\\\w|.]+)\\\\s(\\\\w+)\\\\s([\\\\w|\\\\s|%|_|${utf8letters}]+),?)+`))) {\n      let parts = (expression).split(/,\\s/)\n      const operators = this.operators()\n      for (let i = 0; i < parts.length; i++) {\n        // build a regexp to match filter expressions\n        const lhs = '[\\\\w|.]+'\n        const op = '\\\\w+'\n        const rhs = `.+`\n        const expressionRegExp = new RegExp(`(${lhs})\\\\s+(${op})\\\\s+(${rhs})`)\n        if (parts[i].match(expressionRegExp)) {\n          let prop = RegExp.$1\n          let op = RegExp.$2\n          let value = RegExp.$3\n          if (!operators[op]) {\n            throw new Error(`Invalid operator ${op}`)\n          }\n          const operator = operators[op]\n          // if the value is null, dont use operator to force the \"is null\" or \"is not null\"\n          if (value.match(/^null$/i) || value.match(/^undefined$/i)) {\n            value = null\n          }\n          deepPropSet(where, prop, operator.op, operator.valFunc(value))\n        }\n      }\n    }\n    if (where == null) {\n      throw new Error(`Invalid expression ${expression}`)\n    }\n    return where\n  }\n\n  /** @method\n   *\n   * Converts a query string into an order by\n   *\n   * @param {String} expression - query string expression\n   *    (eg. \"geoId desc\")\n   * @returns {Array} the order clause for building the corresponding Sequelize \n   *    query\n   */\n  sort (expression, sequelize) {\n    // maintain backward-compatibility with v0.x.x, where users supply\n    // their own sequelize object as the second param of sort()\n    sequelize = sequelize || this.sequelize\n    let order = []\n    let expressions = expression.split(/\\s*,\\s*/)\n    for (var e = 0; e < expressions.length; e++) {\n      let exp = expressions[e].split(' ')\n      if (exp.length === 2) {\n        let prop = exp[0]\n        let ord = exp[1].toUpperCase()\n        if (ord.match(/ASC|DESC/i)) {\n          order.push([prop, ord.toUpperCase()])\n        }\n      }\n    }\n    if (expression.match(/RANDOM/i)) {\n      if (sequelize != null) {\n        order = [sequelize.fn('RANDOM')]\n      }\n    }\n    if (order == null) {\n      throw new Error('Invalid order expression')\n    }\n    return order\n  }\n\n}\n\nmodule.exports = new SequelizeQueryStringParser()\n"]}