/*! Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one or more contributor license agreements. * Licensed under the Elastic License 2.0; you may not use this file except in compliance with the Elastic License 2.0. */ (window.canvas_bundle_jsonpfunction=window.canvas_bundle_jsonpfunction||[]).push([[15],{234:function(t,e,r){"use strict";const n=/[\0\b\t\n\r\x1a"'\\]/g,i={"\0":"\\0","\b":"\\b","\t":"\\t","\n":"\\n","\r":"\\r","":"\\Z",'"':'\\"',"'":"\\'","\\":"\\\\"};t.exports=function(t,e){if(null==t)throw new Error("Need to pass a valid string");if(!(e=e||{}).backslashSupported)return"'"+t.replace(/'/g,"''")+"'";const r=n,o=i;for(var l,a=r.lastIndex=0,u="";l=r.exec(t);)u+=t.slice(a,l.index)+o[l[0]],a=r.lastIndex;return 0===a?"'"+t+"'":a1?e-1:0),i=1;i0&&void 0!==arguments[0]?arguments[0]:null,d={isSquelBuilder:function(t){return t&&!!t._toParamString}},p=function(t){return!d.isSquelBuilder(t)||!t.options.rawNesting};d.DefaultQueryBuilderOptions={autoQuoteTableNames:!1,autoQuoteFieldNames:!1,autoQuoteAliasNames:!0,useAsForTableAliasNames:!1,nameQuoteCharacter:"`",tableAliasQuoteCharacter:"`",fieldAliasQuoteCharacter:'"',valueHandlers:[],parameterCharacter:"?",numberedParameters:!1,numberedParametersPrefix:"$",numberedParametersStartAt:1,replaceSingleQuotes:!1,singleQuoteReplacement:"''",separator:" ",stringFormatter:null,rawNesting:!1},d.globalValueHandlers=[],d.registerValueHandler=function(t,e){v(d.globalValueHandlers,t,e)},d.Cloneable=function(){function t(){l(this,t)}return e(t,[{key:"clone",value:function(){return s(new this.constructor,h(s({},this)))}}]),t}(),d.BaseBuilder=function(t){function r(t){l(this,r);var e=i(this,(r.__proto__||Object.getPrototypeOf(r)).call(this)),n=JSON.parse(JSON.stringify(d.DefaultQueryBuilderOptions));return["stringFormatter"].forEach((function(t){n[t]=d.DefaultQueryBuilderOptions[t]})),e.options=s({},n,t),e}return o(r,t),e(r,[{key:"registerValueHandler",value:function(t,e){return v(this.options.valueHandlers,t,e),this}},{key:"_sanitizeExpression",value:function(t){if(!d.isSquelBuilder(t)&&"string"!=typeof t)throw new Error("expression must be a stringĀ or builder instance");return t}},{key:"_sanitizeName",value:function(t,e){if("string"!=typeof t)throw new Error(e+" must be a string");return t}},{key:"_sanitizeField",value:function(t){return d.isSquelBuilder(t)||(t=this._sanitizeName(t,"field name")),t}},{key:"_sanitizeBaseBuilder",value:function(t){if(d.isSquelBuilder(t))return t;throw new Error("must be a builder instance")}},{key:"_sanitizeTable",value:function(t){if("string"!=typeof t)try{t=this._sanitizeBaseBuilder(t)}catch(t){throw new Error("table name must be a string or a builder")}else t=this._sanitizeName(t,"table");return t}},{key:"_sanitizeTableAlias",value:function(t){return this._sanitizeName(t,"table alias")}},{key:"_sanitizeFieldAlias",value:function(t){return this._sanitizeName(t,"field alias")}},{key:"_sanitizeLimitOffset",value:function(t){if(0>(t=parseInt(t))||isNaN(t))throw new Error("limit/offset must be >= 0");return t}},{key:"_sanitizeValue",value:function(t){var e=void 0===t?"undefined":n(t);if(null===t);else if("string"===e||"number"===e||"boolean"===e);else if(d.isSquelBuilder(t));else if(!_(t,this.options.valueHandlers,d.globalValueHandlers))throw new Error("field value must be a string, number, boolean, null or one of the registered custom value types");return t}},{key:"_escapeValue",value:function(t){return t?this.options.replaceSingleQuotes?"'"+t.replace(/\'/g,this.options.singleQuoteReplacement)+"'":a(t):"''"}},{key:"_formatTableName",value:function(t){if(this.options.autoQuoteTableNames){var e=this.options.nameQuoteCharacter;t=""+e+t+e}return t}},{key:"_formatFieldAlias",value:function(t){if(this.options.autoQuoteAliasNames){var e=this.options.fieldAliasQuoteCharacter;t=""+e+t+e}return t}},{key:"_formatTableAlias",value:function(t){if(this.options.autoQuoteAliasNames){var e=this.options.tableAliasQuoteCharacter;t=""+e+t+e}return this.options.useAsForTableAliasNames?"AS "+t:t}},{key:"_formatFieldName",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(this.options.autoQuoteFieldNames){var r=this.options.nameQuoteCharacter;t=e.ignorePeriodsForFieldNameQuotes?""+r+t+r:t.split(".").map((function(t){return"*"===t?t:""+r+t+r})).join(".")}return t}},{key:"_formatCustomValue",value:function(t,e,r){var n=_(t,this.options.valueHandlers,d.globalValueHandlers);return n&&(t=n(t,e,r))&&t.rawNesting?{formatted:!0,rawNesting:!0,value:t.value}:{formatted:!!n,value:t}}},{key:"_formatValueForParamArray",value:function(t){var e=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return f(t)?t.map((function(t){return e._formatValueForParamArray(t,r)})):this._formatCustomValue(t,!0,r).value}},{key:"_formatValueForQueryString",value:function(t){var e=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=this._formatCustomValue(t,!1,r),o=i.rawNesting,l=i.formatted,a=i.value;if(l)return o?a:this._applyNestingFormatting(a,p(t));if(f(a))a=a.map((function(t){return e._formatValueForQueryString(t)})),a=this._applyNestingFormatting(a.join(", "),p(a));else{var u=void 0===a?"undefined":n(a);if(null===a)a="NULL";else if("boolean"===u)a=a?"TRUE":"FALSE";else if(d.isSquelBuilder(a))a=this._applyNestingFormatting(a.toString(),p(a));else if("number"!==u){if("string"===u&&this.options.stringFormatter)return this.options.stringFormatter(a,r);a=r.dontQuote?""+a:this._escapeValue(a)}}return a}},{key:"_applyNestingFormatting",value:function(t){if(t&&"string"==typeof t&&(!(arguments.length>1&&void 0!==arguments[1])||arguments[1])&&!this.options.rawNesting){var e="("===t.charAt(0)&&")"===t.charAt(t.length-1);if(e)for(var r=0,n=1;t.length-1>++r;){var i=t.charAt(r);if("("===i)n++;else if(")"===i&&1>--n){e=!1;break}}e||(t="("+t+")")}return t}},{key:"_buildString",value:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=r.nested,i=r.buildParameterized,o=r.formattingOptions;e=e||[],t=t||"";for(var l="",a=-1,u=[],s=this.options.parameterCharacter,c=0;t.length>c;)if(t.substr(c,s.length)===s){var h=e[++a];if(i)if(d.isSquelBuilder(h)){var v=h._toParamString({buildParameterized:i,nested:!0});l+=v.text,v.values.forEach((function(t){return u.push(t)}))}else f(h=this._formatValueForParamArray(h,o))?(l+="("+h.map((function(){return s})).join(", ")+")",h.forEach((function(t){return u.push(t)}))):(l+=s,u.push(h));else l+=this._formatValueForQueryString(h,o);c+=s.length}else l+=t.charAt(c),c++;return{text:this._applyNestingFormatting(l,!!n),values:u}}},{key:"_buildManyStrings",value:function(t,e){for(var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=[],i=[],o=0;t.length>o;++o){var l=t[o],a=e[o],u=this._buildString(l,a,{buildParameterized:r.buildParameterized,nested:!1}),s=u.text,c=u.values;n.push(s),c.forEach((function(t){return i.push(t)}))}return{text:(n=n.join(this.options.separator)).length?this._applyNestingFormatting(n,!!r.nested):"",values:i}}},{key:"_toParamString",value:function(t){throw new Error("Not yet implemented")}},{key:"toString",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return this._toParamString(t).text}},{key:"toParam",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return this._toParamString(s({},t,{buildParameterized:!0}))}}]),r}(d.Cloneable),d.Expression=function(t){function r(t){l(this,r);var e=i(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,t));return e._nodes=[],e}return o(r,t),e(r,[{key:"and",value:function(t){for(var e=arguments.length,r=Array(e>1?e-1:0),n=1;n1?e-1:0),n=1;n0&&void 0!==arguments[0]?arguments[0]:{},e=[],r=[],n=!0,i=!1,o=void 0;try{for(var l,a=this._nodes[Symbol.iterator]();!(n=(l=a.next()).done);n=!0){var u=l.value,s=u.type,c=u.expr,f=u.para,h=d.isSquelBuilder(c)?c._toParamString({buildParameterized:t.buildParameterized,nested:!0}):this._buildString(c,f,{buildParameterized:t.buildParameterized}),v=h.text,_=h.values;e.length&&e.push(s),e.push(v),_.forEach((function(t){return r.push(t)}))}}catch(t){i=!0,o=t}finally{try{!n&&a.return&&a.return()}finally{if(i)throw o}}return e=e.join(" "),{text:this._applyNestingFormatting(e,!!t.nested),values:r}}}]),r}(d.BaseBuilder),d.Case=function(t){function r(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};l(this,r);var n=i(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,e));return c(t)&&(e=t,t=null),t&&(n._fieldName=n._sanitizeField(t)),n.options=s({},d.DefaultQueryBuilderOptions,e),n._cases=[],n._elseValue=null,n}return o(r,t),e(r,[{key:"when",value:function(t){for(var e=arguments.length,r=Array(e>1?e-1:0),n=1;n0&&void 0!==arguments[0]?arguments[0]:{},e="",r=[],n=!0,i=!1,o=void 0;try{for(var l,a=this._cases[Symbol.iterator]();!(n=(l=a.next()).done);n=!0){var s=l.value,c=s.expression,f=s.values,h=s.result;e=u(e," ");var v=this._buildString(c,f,{buildParameterized:t.buildParameterized,nested:!0});e+="WHEN "+v.text+" THEN "+this._formatValueForQueryString(h),v.values.forEach((function(t){return r.push(t)}))}}catch(t){i=!0,o=t}finally{try{!n&&a.return&&a.return()}finally{if(i)throw o}}return e.length?(e+=" ELSE "+this._formatValueForQueryString(this._elseValue)+" END",this._fieldName&&(e=this._fieldName+" "+e),e="CASE "+e):e=this._formatValueForQueryString(this._elseValue),{text:e,values:r}}}]),r}(d.BaseBuilder),d.Block=function(t){function r(t){return l(this,r),i(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,t))}return o(r,t),e(r,[{key:"exposedMethods",value:function(){for(var t={},e=this;e;)Object.getOwnPropertyNames(e).forEach((function(r){"constructor"===r||"function"!=typeof e[r]||"_"===r.charAt(0)||d.Block.prototype[r]||(t[r]=e[r])})),e=Object.getPrototypeOf(e);return t}}]),r}(d.BaseBuilder),d.StringBlock=function(t){function r(t,e){l(this,r);var n=i(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,t));return n._str=e,n}return o(r,t),e(r,[{key:"_toParamString",value:function(){return{text:this._str,values:[]}}}]),r}(d.Block),d.FunctionBlock=function(t){function r(t){l(this,r);var e=i(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,t));return e._strings=[],e._values=[],e}return o(r,t),e(r,[{key:"function",value:function(t){this._strings.push(t);for(var e=arguments.length,r=Array(e>1?e-1:0),n=1;n0&&void 0!==arguments[0]?arguments[0]:{};return this._buildManyStrings(this._strings,this._values,t)}}]),r}(d.Block),d.registerValueHandler(d.FunctionBlock,(function(t){return arguments.length>1&&void 0!==arguments[1]&&arguments[1]?t.toParam():t.toString()})),d.AbstractTableBlock=function(t){function r(t,e){l(this,r);var n=i(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,t));return n._tables=[],n}return o(r,t),e(r,[{key:"_table",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;e=e?this._sanitizeTableAlias(e):e,t=this._sanitizeTable(t),this.options.singleTable&&(this._tables=[]),this._tables.push({table:t,alias:e})}},{key:"_hasTable",value:function(){return 00&&void 0!==arguments[0]?arguments[0]:{},e="",r=[];if(this._hasTable()){var n=!0,i=!1,o=void 0;try{for(var l,a=this._tables[Symbol.iterator]();!(n=(l=a.next()).done);n=!0){var s=l.value,c=s.table,f=s.alias;e=u(e,", ");var h=void 0;if(d.isSquelBuilder(c)){var v=c._toParamString({buildParameterized:t.buildParameterized,nested:!0}),_=v.text,p=v.values;h=_,p.forEach((function(t){return r.push(t)}))}else h=this._formatTableName(c);f&&(h+=" "+this._formatTableAlias(f)),e+=h}}catch(t){i=!0,o=t}finally{try{!n&&a.return&&a.return()}finally{if(i)throw o}}this.options.prefix&&(e=this.options.prefix+" "+e)}return{text:e,values:r}}}]),r}(d.Block),d.TargetTableBlock=function(t){function r(){return l(this,r),i(this,(r.__proto__||Object.getPrototypeOf(r)).apply(this,arguments))}return o(r,t),e(r,[{key:"target",value:function(t){this._table(t)}}]),r}(d.AbstractTableBlock),d.UpdateTableBlock=function(r){function n(){return l(this,n),i(this,(n.__proto__||Object.getPrototypeOf(n)).apply(this,arguments))}return o(n,r),e(n,[{key:"table",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;this._table(t,e)}},{key:"_toParamString",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(!this._hasTable())throw new Error("table() needs to be called");return t(n.prototype.__proto__||Object.getPrototypeOf(n.prototype),"_toParamString",this).call(this,e)}}]),n}(d.AbstractTableBlock),d.FromTableBlock=function(t){function r(t){return l(this,r),i(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,s({},t,{prefix:"FROM"})))}return o(r,t),e(r,[{key:"from",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;this._table(t,e)}}]),r}(d.AbstractTableBlock),d.IntoTableBlock=function(r){function n(t){return l(this,n),i(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,s({},t,{prefix:"INTO",singleTable:!0})))}return o(n,r),e(n,[{key:"into",value:function(t){this._table(t)}},{key:"_toParamString",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(!this._hasTable())throw new Error("into() needs to be called");return t(n.prototype.__proto__||Object.getPrototypeOf(n.prototype),"_toParamString",this).call(this,e)}}]),n}(d.AbstractTableBlock),d.GetFieldBlock=function(t){function r(t){l(this,r);var e=i(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,t));return e._fields=[],e}return o(r,t),e(r,[{key:"fields",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(f(t)){var r=!0,n=!1,i=void 0;try{for(var o,l=t[Symbol.iterator]();!(r=(o=l.next()).done);r=!0){var a=o.value;this.field(a,null,e)}}catch(t){n=!0,i=t}finally{try{!r&&l.return&&l.return()}finally{if(n)throw i}}}else for(var u in t){var s=t[u];this.field(u,s,e)}}},{key:"field",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(e=e?this._sanitizeFieldAlias(e):e,t=this._sanitizeField(t),this._fields.filter((function(r){return r.name===t&&r.alias===e})).length)return this;this._fields.push({name:t,alias:e,options:r})}},{key:"_toParamString",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=t.queryBuilder,r=t.buildParameterized,n="",i=[],o=!0,l=!1,a=void 0;try{for(var s,c=this._fields[Symbol.iterator]();!(o=(s=c.next()).done);o=!0){var f=s.value;n=u(n,", ");var h=f.name,v=f.alias,_=f.options;if("string"==typeof h)n+=this._formatFieldName(h,_);else{var p=h._toParamString({nested:!0,buildParameterized:r});n+=p.text,p.values.forEach((function(t){return i.push(t)}))}v&&(n+=" AS "+this._formatFieldAlias(v))}}catch(t){l=!0,a=t}finally{try{!o&&c.return&&c.return()}finally{if(l)throw a}}if(!n.length){var y=e&&e.getBlock(d.FromTableBlock);y&&y._hasTable()&&(n="*")}return{text:n,values:i}}}]),r}(d.Block),d.AbstractSetFieldBlock=function(t){function r(t){l(this,r);var e=i(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,t));return e._reset(),e}return o(r,t),e(r,[{key:"_reset",value:function(){this._fields=[],this._values=[[]],this._valueOptions=[[]]}},{key:"_set",value:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(this._values.length>1)throw new Error("Cannot set multiple rows of fields this way.");void 0!==e&&(e=this._sanitizeValue(e)),t=this._sanitizeField(t);var n=this._fields.indexOf(t);-1===n&&(this._fields.push(t),n=this._fields.length-1),this._values[0][n]=e,this._valueOptions[0][n]=r}},{key:"_setFields",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if("object"!==(void 0===t?"undefined":n(t)))throw new Error("Expected an object but got "+(void 0===t?"undefined":n(t)));for(var r in t)this._set(r,t[r],e)}},{key:"_setFieldsRows",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!f(t))throw new Error("Expected an array of objects but got "+(void 0===t?"undefined":n(t)));this._reset();for(var r=0;t.length>r;++r){var i=t[r];for(var o in i){var l=i[o];o=this._sanitizeField(o),l=this._sanitizeValue(l);var a=this._fields.indexOf(o);if(00&&void 0!==arguments[0]?arguments[0]:{}).buildParameterized;if(0>=this._fields.length)throw new Error("set() needs to be called");for(var e="",r=[],n=0;ni.indexOf("=")&&(i=i+" = "+this.options.parameterCharacter);var l=this._buildString(i,[o],{buildParameterized:t,formattingOptions:this._valueOptions[0][n]});e+=l.text,l.values.forEach((function(t){return r.push(t)}))}return{text:"SET "+e,values:r}}}]),r}(d.AbstractSetFieldBlock),d.InsertFieldValueBlock=function(t){function r(){return l(this,r),i(this,(r.__proto__||Object.getPrototypeOf(r)).apply(this,arguments))}return o(r,t),e(r,[{key:"set",value:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};this._set(t,e,r)}},{key:"setFields",value:function(t,e){this._setFields(t,e)}},{key:"setFieldsRows",value:function(t,e){this._setFieldsRows(t,e)}},{key:"_toParamString",value:function(){for(var t=this,e=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).buildParameterized,r=this._fields.map((function(e){return t._formatFieldName(e)})).join(", "),n=[],i=[],o=0;o0&&void 0!==arguments[0]?arguments[0]:{},e="",r=[];if(this._fields.length&&this._query){var n=this._query._toParamString({buildParameterized:t.buildParameterized,nested:!0}),i=n.text,o=n.values;e="("+this._fields.join(", ")+") "+this._applyNestingFormatting(i),r=o}return{text:e,values:r}}}]),r}(d.Block),d.DistinctBlock=function(t){function r(){return l(this,r),i(this,(r.__proto__||Object.getPrototypeOf(r)).apply(this,arguments))}return o(r,t),e(r,[{key:"distinct",value:function(){this._useDistinct=!0}},{key:"_toParamString",value:function(){return{text:this._useDistinct?"DISTINCT":"",values:[]}}}]),r}(d.Block),d.GroupByBlock=function(t){function r(t){l(this,r);var e=i(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,t));return e._groups=[],e}return o(r,t),e(r,[{key:"group",value:function(t){this._groups.push(this._sanitizeField(t))}},{key:"_toParamString",value:function(){return{text:this._groups.length?"GROUP BY "+this._groups.join(", "):"",values:[]}}}]),r}(d.Block),d.AbstractVerbSingleValueBlock=function(t){function r(t){l(this,r);var e=i(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,t));return e._value=null,e}return o(r,t),e(r,[{key:"_setValue",value:function(t){this._value=null!==t?this._sanitizeLimitOffset(t):t}},{key:"_toParamString",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=null!==this._value?this.options.verb+" "+this.options.parameterCharacter:"",r=null!==this._value?[this._value]:[];return this._buildString(e,r,t)}}]),r}(d.Block),d.OffsetBlock=function(t){function r(t){return l(this,r),i(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,s({},t,{verb:"OFFSET"})))}return o(r,t),e(r,[{key:"offset",value:function(t){this._setValue(t)}}]),r}(d.AbstractVerbSingleValueBlock),d.LimitBlock=function(t){function r(t){return l(this,r),i(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,s({},t,{verb:"LIMIT"})))}return o(r,t),e(r,[{key:"limit",value:function(t){this._setValue(t)}}]),r}(d.AbstractVerbSingleValueBlock),d.AbstractConditionBlock=function(t){function r(t){l(this,r);var e=i(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,t));return e._conditions=[],e}return o(r,t),e(r,[{key:"_condition",value:function(t){t=this._sanitizeExpression(t);for(var e=arguments.length,r=Array(e>1?e-1:0),n=1;n0&&void 0!==arguments[0]?arguments[0]:{},e=[],r=[],n=!0,i=!1,o=void 0;try{for(var l,a=this._conditions[Symbol.iterator]();!(n=(l=a.next()).done);n=!0){var u=l.value,s=u.expr,c=u.values,f=d.isSquelBuilder(s)?s._toParamString({buildParameterized:t.buildParameterized}):this._buildString(s,c,{buildParameterized:t.buildParameterized});f.text.length&&e.push(f.text),f.values.forEach((function(t){return r.push(t)}))}}catch(t){i=!0,o=t}finally{try{!n&&a.return&&a.return()}finally{if(i)throw o}}return e.length&&(e=e.join(") AND (")),{text:e.length?this.options.verb+" ("+e+")":"",values:r}}}]),r}(d.Block),d.WhereBlock=function(t){function r(t){return l(this,r),i(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,s({},t,{verb:"WHERE"})))}return o(r,t),e(r,[{key:"where",value:function(t){for(var e=arguments.length,r=Array(e>1?e-1:0),n=1;n1?e-1:0),n=1;n2?r-2:0),i=2;i0&&void 0!==arguments[0]?arguments[0]:{},e="",r=[],n=!0,i=!1,o=void 0;try{for(var l,a=this._orders[Symbol.iterator]();!(n=(l=a.next()).done);n=!0){var s=l.value,c=s.field,h=s.dir,v=s.values;e=u(e,", ");var _=this._buildString(c,v,{buildParameterized:t.buildParameterized});e+=_.text,f(_.values)&&_.values.forEach((function(t){return r.push(t)})),null!==h&&(e+=" "+h)}}catch(t){i=!0,o=t}finally{try{!n&&a.return&&a.return()}finally{if(i)throw o}}return{text:e.length?"ORDER BY "+e:"",values:r}}}]),r}(d.Block),d.JoinBlock=function(t){function r(t){l(this,r);var e=i(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,t));return e._joins=[],e}return o(r,t),e(r,[{key:"join",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"INNER";t=this._sanitizeTable(t,!0),e=e?this._sanitizeTableAlias(e):e,r=r?this._sanitizeExpression(r):r,this._joins.push({type:n,table:t,alias:e,condition:r})}},{key:"left_join",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;this.join(t,e,r,"LEFT")}},{key:"right_join",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;this.join(t,e,r,"RIGHT")}},{key:"outer_join",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;this.join(t,e,r,"OUTER")}},{key:"left_outer_join",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;this.join(t,e,r,"LEFT OUTER")}},{key:"full_join",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;this.join(t,e,r,"FULL")}},{key:"cross_join",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;this.join(t,e,r,"CROSS")}},{key:"_toParamString",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e="",r=[],n=!0,i=!1,o=void 0;try{for(var l,a=this._joins[Symbol.iterator]();!(n=(l=a.next()).done);n=!0){var s=l.value,c=s.type,f=s.table,h=s.alias,v=s.condition;e=u(e,this.options.separator);var _=void 0;if(d.isSquelBuilder(f)){var p=f._toParamString({buildParameterized:t.buildParameterized,nested:!0});p.values.forEach((function(t){return r.push(t)})),_=p.text}else _=this._formatTableName(f);if(e+=c+" JOIN "+_,h&&(e+=" "+this._formatTableAlias(h)),v){e+=" ON ";var y=void 0;y=d.isSquelBuilder(v)?v._toParamString({buildParameterized:t.buildParameterized}):this._buildString(v,[],{buildParameterized:t.buildParameterized}),e+=this._applyNestingFormatting(y.text),y.values.forEach((function(t){return r.push(t)}))}}}catch(t){i=!0,o=t}finally{try{!n&&a.return&&a.return()}finally{if(i)throw o}}return{text:e,values:r}}}]),r}(d.Block),d.UnionBlock=function(t){function r(t){l(this,r);var e=i(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,t));return e._unions=[],e}return o(r,t),e(r,[{key:"union",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"UNION";t=this._sanitizeTable(t),this._unions.push({type:e,table:t})}},{key:"union_all",value:function(t){this.union(t,"UNION ALL")}},{key:"_toParamString",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e="",r=[],n=!0,i=!1,o=void 0;try{for(var l,a=this._unions[Symbol.iterator]();!(n=(l=a.next()).done);n=!0){var s=l.value,c=s.type,f=s.table;e=u(e,this.options.separator);var h=void 0;if(f instanceof d.BaseBuilder){var v=f._toParamString({buildParameterized:t.buildParameterized,nested:!0});h=v.text,v.values.forEach((function(t){return r.push(t)}))}else e=this._formatTableName(f);e+=c+" "+h}}catch(t){i=!0,o=t}finally{try{!n&&a.return&&a.return()}finally{if(i)throw o}}return{text:e,values:r}}}]),r}(d.Block),d.QueryBuilder=function(r){function n(t,e){l(this,n);var r=i(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,t));r.blocks=e||[];var o=!0,a=!1,u=void 0;try{for(var s,c=r.blocks[Symbol.iterator]();!(o=(s=c.next()).done);o=!0){var f=s.value,h=f.exposedMethods();for(var v in h){var _=h[v];if(void 0!==r[v])throw new Error("Builder already has a builder method called: "+v);!function(t,e,n){r[e]=function(){for(var e=arguments.length,i=Array(e),o=0;o0&&void 0!==arguments[0]?arguments[0]:{};e=s({},this.options,e);var r=this.blocks.map((function(r){return r._toParamString({buildParameterized:e.buildParameterized,queryBuilder:t})})),n=r.map((function(t){return t.text})),i=r.map((function(t){return t.values})),o=n.filter((function(t){return 01&&void 0!==arguments[1]?arguments[1]:null;return l(this,e),r=r||[new d.StringBlock(t,"SELECT"),new d.FunctionBlock(t),new d.DistinctBlock(t),new d.GetFieldBlock(t),new d.FromTableBlock(t),new d.JoinBlock(t),new d.WhereBlock(t),new d.GroupByBlock(t),new d.HavingBlock(t),new d.OrderByBlock(t),new d.LimitBlock(t),new d.OffsetBlock(t),new d.UnionBlock(t)],i(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,r))}return o(e,t),e}(d.QueryBuilder),d.Update=function(t){function e(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return l(this,e),r=r||[new d.StringBlock(t,"UPDATE"),new d.UpdateTableBlock(t),new d.SetFieldBlock(t),new d.WhereBlock(t),new d.OrderByBlock(t),new d.LimitBlock(t)],i(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,r))}return o(e,t),e}(d.QueryBuilder),d.Delete=function(t){function e(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return l(this,e),r=r||[new d.StringBlock(t,"DELETE"),new d.TargetTableBlock(t),new d.FromTableBlock(s({},t,{singleTable:!0})),new d.JoinBlock(t),new d.WhereBlock(t),new d.OrderByBlock(t),new d.LimitBlock(t)],i(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,r))}return o(e,t),e}(d.QueryBuilder),d.Insert=function(t){function e(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return l(this,e),r=r||[new d.StringBlock(t,"INSERT"),new d.IntoTableBlock(t),new d.InsertFieldValueBlock(t),new d.InsertFieldsFromQueryBlock(t)],i(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,r))}return o(e,t),e}(d.QueryBuilder);var y={VERSION:"5.12.5",flavour:r,expr:function(t){return new d.Expression(t)},case:function(t,e){return new d.Case(t,e)},select:function(t,e){return new d.Select(t,e)},update:function(t,e){return new d.Update(t,e)},insert:function(t,e){return new d.Insert(t,e)},delete:function(t,e){return new d.Delete(t,e)},str:function(){var t=new d.FunctionBlock;return t.function.apply(t,arguments),t},rstr:function(){var t=new d.FunctionBlock({rawNesting:!0});return t.function.apply(t,arguments),t},registerValueHandler:d.registerValueHandler};return y.remove=y.delete,y.cls=d,y}var y=p();return y.flavours={},y.useFlavour=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(!t)return y;if(y.flavours[t]instanceof Function){var e=p(t);return y.flavours[t].call(null,e),e.flavours=y.flavours,e.useFlavour=y.useFlavour,e}throw new Error("Flavour not available: "+t)},y.flavours.mssql=function(r){var n=r.cls;n.DefaultQueryBuilderOptions.replaceSingleQuotes=!0,n.DefaultQueryBuilderOptions.autoQuoteAliasNames=!1,n.DefaultQueryBuilderOptions.numberedParametersPrefix="@",r.registerValueHandler(Date,(function(t){return"'"+t.getUTCFullYear()+"-"+(t.getUTCMonth()+1)+"-"+t.getUTCDate()+" "+t.getUTCHours()+":"+t.getUTCMinutes()+":"+t.getUTCSeconds()+"'"})),n.MssqlLimitOffsetTopBlock=function(t){function r(t){l(this,r);var a=i(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,t));a._limits=null,a._offsets=null;var u=function(t){t=this._sanitizeLimitOffset(t),this._parent._limits=t};return a.ParentBlock=function(t){function e(t){l(this,e);var r=i(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t.options));return r._parent=t,r}return o(e,t),e}(n.Block),a.LimitBlock=function(t){function r(t){l(this,r);var e=i(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,t));return e.limit=u,e}return o(r,t),e(r,[{key:"_toParamString",value:function(){var t="";return this._parent._limits&&this._parent._offsets&&(t="FETCH NEXT "+this._parent._limits+" ROWS ONLY"),{text:t,values:[]}}}]),r}(a.ParentBlock),a.TopBlock=function(t){function r(t){l(this,r);var e=i(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,t));return e.top=u,e}return o(r,t),e(r,[{key:"_toParamString",value:function(){var t="";return this._parent._limits&&!this._parent._offsets&&(t="TOP ("+this._parent._limits+")"),{text:t,values:[]}}}]),r}(a.ParentBlock),a.OffsetBlock=function(t){function r(){return l(this,r),i(this,(r.__proto__||Object.getPrototypeOf(r)).apply(this,arguments))}return o(r,t),e(r,[{key:"offset",value:function(t){this._parent._offsets=this._sanitizeLimitOffset(t)}},{key:"_toParamString",value:function(){var t="";return this._parent._offsets&&(t="OFFSET "+this._parent._offsets+" ROWS"),{text:t,values:[]}}}]),r}(a.ParentBlock),a}return o(r,t),e(r,[{key:"LIMIT",value:function(){return new this.LimitBlock(this)}},{key:"TOP",value:function(){return new this.TopBlock(this)}},{key:"OFFSET",value:function(){return new this.OffsetBlock(this)}}]),r}(n.Block),n.MssqlUpdateTopBlock=function(t){function r(t){l(this,r);var e=i(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,t));return e._limits=null,e.limit=e.top=function(t){e._limits=e._sanitizeLimitOffset(t)},e}return o(r,t),e(r,[{key:"_toParamString",value:function(){return{text:this._limits?"TOP ("+this._limits+")":"",values:[]}}}]),r}(n.Block),n.MssqlInsertFieldValueBlock=function(r){function n(t){l(this,n);var e=i(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,t));return e._outputs=[],e}return o(n,r),e(n,[{key:"output",value:function(t){var e=this;"string"==typeof t?this._outputs.push("INSERTED."+this._sanitizeField(t)):t.forEach((function(t){e._outputs.push("INSERTED."+e._sanitizeField(t))}))}},{key:"_toParamString",value:function(e){var r=t(n.prototype.__proto__||Object.getPrototypeOf(n.prototype),"_toParamString",this).call(this,e);if(r.text.length&&01&&void 0!==arguments[1]?arguments[1]:null;t=this._sanitizeField(t),e=e?this._sanitizeFieldAlias(e):e,this._outputs.push({name:this.options.forDelete?"DELETED."+t:"INSERTED."+t,alias:e})}},{key:"_toParamString",value:function(t){var e="";if(this._outputs.length){var r=!0,n=!1,i=void 0;try{for(var o,l=this._outputs[Symbol.iterator]();!(r=(o=l.next()).done);r=!0){var a=o.value;e=u(e,", "),e+=a.name,a.alias&&(e+=" AS "+this._formatFieldAlias(a.alias))}}catch(t){n=!0,i=t}finally{try{!r&&l.return&&l.return()}finally{if(n)throw i}}e="OUTPUT "+e}return{text:e,values:[]}}}]),r}(n.Block),n.Select=function(t){function e(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;l(this,e);var o=new n.MssqlLimitOffsetTopBlock(t);return r=r||[new n.StringBlock(t,"SELECT"),new n.DistinctBlock(t),o.TOP(),new n.GetFieldBlock(t),new n.FromTableBlock(t),new n.JoinBlock(t),new n.WhereBlock(t),new n.GroupByBlock(t),new n.OrderByBlock(t),o.OFFSET(),o.LIMIT(),new n.UnionBlock(t)],i(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,r))}return o(e,t),e}(n.QueryBuilder),n.Update=function(t){function e(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return l(this,e),r=r||[new n.StringBlock(t,"UPDATE"),new n.MssqlUpdateTopBlock(t),new n.UpdateTableBlock(t),new n.SetFieldBlock(t),new n.MssqlUpdateDeleteOutputBlock(t),new n.WhereBlock(t)],i(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,r))}return o(e,t),e}(n.QueryBuilder),n.Delete=function(t){function e(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return l(this,e),r=r||[new n.StringBlock(t,"DELETE"),new n.TargetTableBlock(t),new n.FromTableBlock(s({},t,{singleTable:!0})),new n.JoinBlock(t),new n.MssqlUpdateDeleteOutputBlock(s({},t,{forDelete:!0})),new n.WhereBlock(t),new n.OrderByBlock(t),new n.LimitBlock(t)],i(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,r))}return o(e,t),e}(n.QueryBuilder),n.Insert=function(t){function e(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return l(this,e),r=r||[new n.StringBlock(t,"INSERT"),new n.IntoTableBlock(t),new n.MssqlInsertFieldValueBlock(t),new n.InsertFieldsFromQueryBlock(t)],i(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,r))}return o(e,t),e}(n.QueryBuilder)},y.flavours.mysql=function(t){var n=r(234),a=t.cls;a.DefaultQueryBuilderOptions.stringFormatter=function(t,e){return e.dontQuote?t:n(t,{backslashSupported:!0})},a.MysqlIgnoreBlock=function(t){function r(){return l(this,r),i(this,(r.__proto__||Object.getPrototypeOf(r)).apply(this,arguments))}return o(r,t),e(r,[{key:"ignore",value:function(){this._str="IGNORE"}},{key:"_toParamString",value:function(){return{text:this._str||"",values:[]}}}]),r}(a.AbstractSetFieldBlock),a.MysqlOnDuplicateKeyUpdateBlock=function(t){function r(){return l(this,r),i(this,(r.__proto__||Object.getPrototypeOf(r)).apply(this,arguments))}return o(r,t),e(r,[{key:"onDupUpdate",value:function(t,e,r){this._set(t,e,r)}},{key:"_toParamString",value:function(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e="",r=[],n=0;n1&&void 0!==arguments[1]?arguments[1]:null;return l(this,e),r=r||[new a.StringBlock(t,"INSERT"),new a.MysqlIgnoreBlock(t),new a.IntoTableBlock(t),new a.InsertFieldValueBlock(t),new a.InsertFieldsFromQueryBlock(t),new a.MysqlOnDuplicateKeyUpdateBlock(t)],i(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,r))}return o(e,t),e}(a.QueryBuilder),a.Replace=function(t){function e(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return l(this,e),r=r||[new a.StringBlock(t,"REPLACE"),new a.IntoTableBlock(t),new a.InsertFieldValueBlock(t),new a.InsertFieldsFromQueryBlock(t)],i(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,r))}return o(e,t),e}(a.QueryBuilder),t.replace=function(t,e){return new a.Replace(t,e)}},y.flavours.postgres=function(t){var r=t.cls;r.DefaultQueryBuilderOptions.numberedParameters=!0,r.DefaultQueryBuilderOptions.numberedParametersStartAt=1,r.DefaultQueryBuilderOptions.autoQuoteAliasNames=!1,r.DefaultQueryBuilderOptions.useAsForTableAliasNames=!0,r.PostgresOnConflictKeyUpdateBlock=function(t){function r(){return l(this,r),i(this,(r.__proto__||Object.getPrototypeOf(r)).apply(this,arguments))}return o(r,t),e(r,[{key:"onConflict",value:function(t,e){var r=this;this._onConflict=!0,t&&(f(t)||(t=[t]),this._dupFields=t.map(this._sanitizeField.bind(this)),e&&Object.keys(e).forEach((function(t){r._set(t,e[t])})))}},{key:"_toParamString",value:function(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e="",r=[],n=0;n1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(e=e?this._sanitizeFieldAlias(e):e,t=this._sanitizeField(t),this._fields.filter((function(r){return r.name===t&&r.alias===e})).length)return this;this._fields.push({name:t,alias:e,options:r})}},{key:"_toParamString",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=(t.queryBuilder,t.buildParameterized),r="",n=[],i=!0,o=!1,l=void 0;try{for(var a,s=this._fields[Symbol.iterator]();!(i=(a=s.next()).done);i=!0){var c=a.value;r=u(r,", ");var f=c.name,h=c.alias,v=c.options;if("string"==typeof f)r+=this._formatFieldName(f,v);else{var _=f._toParamString({nested:!0,buildParameterized:e});r+=_.text,_.values.forEach((function(t){return n.push(t)}))}h&&(r+=" AS "+this._formatFieldAlias(h))}}catch(t){o=!0,l=t}finally{try{!i&&s.return&&s.return()}finally{if(o)throw l}}return{text:r.length>0?"RETURNING "+r:"",values:n}}}]),r}(r.Block),r.WithBlock=function(t){function r(t){l(this,r);var e=i(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,t));return e._tables=[],e}return o(r,t),e(r,[{key:"with",value:function(t,e){this._tables.push({alias:t,table:e})}},{key:"_toParamString",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=[],r=[],n=!0,i=!1,o=void 0;try{for(var l,a=this._tables[Symbol.iterator]();!(n=(l=a.next()).done);n=!0){var u=l.value,s=u.alias,c=u.table._toParamString({buildParameterized:t.buildParameterized,nested:!0});e.push(s+" AS "+c.text),c.values.forEach((function(t){return r.push(t)}))}}catch(t){i=!0,o=t}finally{try{!n&&a.return&&a.return()}finally{if(i)throw o}}return{text:e.length?"WITH "+e.join(", "):"",values:r}}}]),r}(r.Block),r.DistinctOnBlock=function(t){function r(t){l(this,r);var e=i(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,t));return e._distinctFields=[],e}return o(r,t),e(r,[{key:"distinct",value:function(){var t=this;this._useDistinct=!0;for(var e=arguments.length,r=Array(e),n=0;n1&&void 0!==arguments[1]?arguments[1]:null;return l(this,e),n=n||[new r.WithBlock(t),new r.StringBlock(t,"SELECT"),new r.FunctionBlock(t),new r.DistinctOnBlock(t),new r.GetFieldBlock(t),new r.FromTableBlock(t),new r.JoinBlock(t),new r.WhereBlock(t),new r.GroupByBlock(t),new r.HavingBlock(t),new r.OrderByBlock(t),new r.LimitBlock(t),new r.OffsetBlock(t),new r.UnionBlock(t)],i(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,n))}return o(e,t),e}(r.QueryBuilder),r.Insert=function(t){function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return l(this,e),n=n||[new r.WithBlock(t),new r.StringBlock(t,"INSERT"),new r.IntoTableBlock(t),new r.InsertFieldValueBlock(t),new r.InsertFieldsFromQueryBlock(t),new r.PostgresOnConflictKeyUpdateBlock(t),new r.ReturningBlock(t)],i(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,n))}return o(e,t),e}(r.QueryBuilder),r.Update=function(t){function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return l(this,e),n=n||[new r.WithBlock(t),new r.StringBlock(t,"UPDATE"),new r.UpdateTableBlock(t),new r.SetFieldBlock(t),new r.FromTableBlock(t),new r.WhereBlock(t),new r.OrderByBlock(t),new r.LimitBlock(t),new r.ReturningBlock(t)],i(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,n))}return o(e,t),e}(r.QueryBuilder),r.Delete=function(t){function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return l(this,e),n=n||[new r.WithBlock(t),new r.StringBlock(t,"DELETE"),new r.TargetTableBlock(t),new r.FromTableBlock(s({},t,{singleTable:!0})),new r.JoinBlock(t),new r.WhereBlock(t),new r.OrderByBlock(t),new r.LimitBlock(t),new r.ReturningBlock(t)],i(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,n))}return o(e,t),e}(r.QueryBuilder)},y},void 0===(i=n.apply(e,[]))||(t.exports=i)}}]);