{"version":3,"file":"pss-rewriter.cjs","names":[],"sources":["../../src/optimizer/pss-rewriter.ts"],"sourcesContent":["/**\n * Rewriter for pg_stat_statements queries.\n * Not all queries found in pg_stat_statements can be\n * directly sent back to the database without first being rewritten.\n */\nexport class PssRewriter {\n  rewrite(query: string): string {\n    return this.rewriteKeywordWithParameter(query);\n  }\n\n  private rewriteKeywordWithParameter(query: string): string {\n    return query.replace(/\\b(\\w+) (\\$\\d+)\\b/gi, (match) => {\n      const [keyword, parameter] = match.split(\" \");\n      const isProblematicKeyword = this.problematicKeywords.includes(\n        keyword.toLowerCase(),\n      );\n      if (!isProblematicKeyword) {\n        return match;\n      }\n      return `(${parameter}::${keyword.toLowerCase()})`;\n    });\n  }\n\n  private problematicKeywords = [\"interval\", \"timestamp\", \"geometry\"];\n}\n"],"mappings":";;;;;;;;AAKA,IAAa,cAAb,MAAyB;;+CAkBf,uBAAsB;GAAC;GAAY;GAAa;GAAW,CAAC;;CAjBpE,QAAQ,OAAuB;AAC7B,SAAO,KAAK,4BAA4B,MAAM;;CAGhD,4BAAoC,OAAuB;AACzD,SAAO,MAAM,QAAQ,wBAAwB,UAAU;GACrD,MAAM,CAAC,SAAS,aAAa,MAAM,MAAM,IAAI;AAI7C,OAAI,CAHyB,KAAK,oBAAoB,SACpD,QAAQ,aAAa,CAEE,CACvB,QAAO;AAET,UAAO,IAAI,UAAU,IAAI,QAAQ,aAAa,CAAC;IAC/C"}