@openobserve/node-sql-parser
Version:
simple node sql parser
1 lines • 2.67 MB
JavaScript
!function(r,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e=t();for(var n in e)("object"==typeof exports?exports:r)[n]=e[n]}}(this,(function(){return function(r){var t={};function e(n){if(t[n])return t[n].exports;var s=t[n]={i:n,l:!1,exports:{}};return r[n].call(s.exports,s,s.exports,e),s.l=!0,s.exports}return e.m=r,e.c=t,e.d=function(r,t,n){e.o(r,t)||Object.defineProperty(r,t,{enumerable:!0,get:n})},e.r=function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})},e.t=function(r,t){if(1&t&&(r=e(r)),8&t)return r;if(4&t&&"object"==typeof r&&r&&r.__esModule)return r;var n=Object.create(null);if(e.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:r}),2&t&&"string"!=typeof r)for(var s in r)e.d(n,s,function(t){return r[t]}.bind(null,s));return n},e.n=function(r){var t=r&&r.__esModule?function(){return r.default}:function(){return r};return e.d(t,"a",t),t},e.o=function(r,t){return Object.prototype.hasOwnProperty.call(r,t)},e.p="",e(e.s=41)}([function(r,t,e){"use strict";e.r(t),e.d(t,"arrayStructTypeToSQL",(function(){return R})),e.d(t,"autoIncrementToSQL",(function(){return _})),e.d(t,"columnOrderListToSQL",(function(){return g})),e.d(t,"commonKeywordArgsToSQL",(function(){return S})),e.d(t,"commonOptionConnector",(function(){return i})),e.d(t,"connector",(function(){return l})),e.d(t,"commonTypeValue",(function(){return E})),e.d(t,"commentToSQL",(function(){return I})),e.d(t,"createBinaryExpr",(function(){return f})),e.d(t,"createValueExpr",(function(){return c})),e.d(t,"dataTypeToSQL",(function(){return T})),e.d(t,"DEFAULT_OPT",(function(){return o})),e.d(t,"escape",(function(){return b})),e.d(t,"literalToSQL",(function(){return h})),e.d(t,"columnIdentifierToSql",(function(){return C})),e.d(t,"getParserOpt",(function(){return v})),e.d(t,"identifierToSql",(function(){return d})),e.d(t,"onPartitionsToSQL",(function(){return m})),e.d(t,"replaceParams",(function(){return A})),e.d(t,"returningToSQL",(function(){return O})),e.d(t,"hasVal",(function(){return y})),e.d(t,"setParserOpt",(function(){return p})),e.d(t,"toUpper",(function(){return w})),e.d(t,"topToSQL",(function(){return L})),e.d(t,"triggerEventToSQL",(function(){return N}));var n=e(2),s=e(15);function u(r){return(u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r})(r)}var o={database:"mysql",type:"table",trimQuery:!0,parseOptions:{includeLocations:!1}},a=o;function i(r,t,e){if(e)return r?"".concat(r.toUpperCase()," ").concat(t(e)):t(e)}function l(r,t){if(t)return"".concat(r.toUpperCase()," ").concat(t)}function c(r){var t=u(r);if(Array.isArray(r))return{type:"expr_list",value:r.map(c)};if(null===r)return{type:"null",value:null};switch(t){case"boolean":return{type:"bool",value:r};case"string":return{type:"string",value:r};case"number":return{type:"number",value:r};default:throw new Error('Cannot convert value "'.concat(t,'" to SQL'))}}function f(r,t,e){var n={operator:r,type:"binary_expr"};return n.left=t.type?t:c(t),"BETWEEN"===r||"NOT BETWEEN"===r?(n.right={type:"expr_list",value:[c(e[0]),c(e[1])]},n):(n.right=e.type?e:c(e),n)}function b(r){return r}function v(){return a}function p(r){a=r}function L(r){if(r){var t=r.value,e=r.percent,n=r.parentheses?"(".concat(t,")"):t,s="TOP ".concat(n);return e?"".concat(s," ").concat(e.toUpperCase()):s}}function C(r){var t=v().database;if(r)switch(t&&t.toLowerCase()){case"db2":case"postgresql":case"redshift":case"snowflake":case"noql":case"trino":case"sqlite":return'"'.concat(r,'"');case"transactsql":return"[".concat(r,"]");case"mysql":case"mariadb":case"bigquery":default:return"`".concat(r,"`")}}function d(r,t){var e=v().database;if(!0===t)return"'".concat(r,"'");if(r){if("*"===r)return r;switch(e&&e.toLowerCase()){case"mysql":case"mariadb":return"`".concat(r,"`");case"postgresql":case"redshift":case"snowflake":case"trino":case"noql":case"sqlite":return'"'.concat(r,'"');case"transactsql":return"[".concat(r,"]");case"bigquery":case"db2":return r;default:return"`".concat(r,"`")}}}function w(r){if(r)return r.toUpperCase()}function y(r){return r}function h(r){if(r){var t=r.prefix,e=r.type,n=r.parentheses,o=r.suffix,a=r.value,i="object"===u(r)?a:r;switch(e){case"backticks_quote_string":i="`".concat(a,"`");break;case"string":i="'".concat(a,"'");break;case"regex_string":i='r"'.concat(a,'"');break;case"hex_string":i="X'".concat(a,"'");break;case"full_hex_string":i="0x".concat(a);break;case"natural_string":i="N'".concat(a,"'");break;case"bit_string":i="b'".concat(a,"'");break;case"double_quote_string":i='"'.concat(a,'"');break;case"single_quote_string":i="'".concat(a,"'");break;case"boolean":case"bool":i=a?"TRUE":"FALSE";break;case"null":i="NULL";break;case"star":i="*";break;case"param":i="".concat(t||":").concat(a),t=null;break;case"origin":i=a.toUpperCase();break;case"date":case"datetime":case"time":case"timestamp":i="".concat(e.toUpperCase()," '").concat(a,"'");break;case"var_string":i="N'".concat(a,"'")}var l=[];return t&&l.push(w(t)),l.push(i),o&&("string"==typeof o&&l.push(o),"object"===u(o)&&(o.collate?l.push(Object(s.a)(o.collate)):l.push(h(o)))),i=l.join(" "),n?"(".concat(i,")"):i}}function E(r){if(!r)return[];var t=r.type,e=r.symbol,n=r.value;return[t.toUpperCase(),e,"string"==typeof n?n.toUpperCase():h(n)].filter(y)}function A(r,t){return function r(t,e){return Object.keys(t).filter((function(r){var e=t[r];return Array.isArray(e)||"object"===u(e)&&null!==e})).forEach((function(n){var s=t[n];if("object"!==u(s)||"param"!==s.type)return r(s,e);if(void 0===e[s.value])throw new Error("no value for parameter :".concat(s.value," found"));return t[n]=c(e[s.value]),null})),t}(JSON.parse(JSON.stringify(r)),t)}function m(r){var t=r.type,e=r.partitions;return[w(t),"(".concat(e.map((function(r){if("range"!==r.type)return h(r);var t=r.start,e=r.end,n=r.symbol;return"".concat(h(t)," ").concat(w(n)," ").concat(h(e))})).join(", "),")")].join(" ")}function T(r){var t=r.dataType,e=r.length,n=r.parentheses,s=r.scale,u=r.suffix,o="";return null!=e&&(o=s?"".concat(e,", ").concat(s):e),n&&(o="(".concat(o,")")),u&&u.length&&(o+=" ".concat(u.join(" "))),"".concat(t).concat(o)}function R(r){if(r){var t=r.dataType,e=r.definition,n=r.anglebracket,s=w(t);if("ARRAY"!==s&&"STRUCT"!==s)return s;var u=e&&e.map((function(r){return[r.field_name,R(r.field_type)].filter(y).join(" ")})).join(", ");return n?"".concat(s,"<").concat(u,">"):"".concat(s," ").concat(u)}}function I(r){if(r){var t=[],e=r.keyword,n=r.symbol,s=r.value;return t.push(e.toUpperCase()),n&&t.push(n),t.push(h(s)),t.join(" ")}}function N(r){return r.map((function(r){var t=r.keyword,e=r.args,s=[w(t)];if(e){var u=e.keyword,o=e.columns;s.push(w(u),o.map(n.e).join(", "))}return s.join(" ")})).join(" OR ")}function O(r){return r?["RETURNING",r.columns.map(n.g).filter(y).join(", ")].join(" "):""}function S(r){return r?[w(r.keyword),w(r.args)]:[]}function _(r){if(r){if("string"==typeof r){var t=v().database;switch(t&&t.toLowerCase()){case"sqlite":return"AUTOINCREMENT";default:return"AUTO_INCREMENT"}}var e=r.keyword,n=r.seed,s=r.increment,u=r.parentheses,o=w(e);return u&&(o+="(".concat(h(n),", ").concat(h(s),")")),o}}function g(r){if(r)return r.map(n.d).filter(y).join(", ")}},function(r,t,e){"use strict";e.d(t,"a",(function(){return m})),e.d(t,"b",(function(){return T})),e.d(t,"d",(function(){return A})),e.d(t,"c",(function(){return R}));var n=e(0),s=e(10),u=e(13);var o=e(23),a=e(21);var i=e(15),l=e(2),c=e(7),f=e(22);var b=e(8),v=e(24);function p(r){return(p="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r})(r)}function L(r){var t=r.expr_list,e=r.type;switch(Object(n.toUpper)(e)){case"STRUCT":return"(".concat(Object(l.h)(t),")");case"ARRAY":return function(r){var t=r.array_path,e=r.brackets,s=r.expr_list,u=r.parentheses;if(!s)return"[".concat(Object(l.h)(t),"]");var o=Array.isArray(s)?s.map((function(r){return"(".concat(Object(l.h)(r),")")})).filter(n.hasVal).join(", "):m(s);return e?"[".concat(o,"]"):u?"(".concat(o,")"):o}(r);default:return""}}function C(r){var t=r.definition,e=r.keyword,s=[Object(n.toUpper)(e)];return t&&"object"===p(t)&&(s.length=0,s.push(Object(n.arrayStructTypeToSQL)(t))),s.push(L(r)),s.filter(n.hasVal).join("")}var d=e(3),w=e(6),y=e(19);function h(r){return(h="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r})(r)}var E={alter:s.b,aggr_func:function(r){var t=r.args,e=r.filter,s=r.over,o=r.within_group_orderby,a=m(t.expr);a=Array.isArray(a)?a.join(", "):a;var i=r.name,l=Object(u.a)(s);t.distinct&&(a=["DISTINCT",a].join(" ")),t.separator&&t.separator.delimiter&&(a=[a,Object(n.literalToSQL)(t.separator.delimiter)].join("".concat(t.separator.symbol," "))),t.orderby&&(a=[a,R(t.orderby,"order by")].join(" ")),t.separator&&t.separator.value&&(a=[a,Object(n.toUpper)(t.separator.keyword),Object(n.literalToSQL)(t.separator.value)].filter(n.hasVal).join(" "));var c=o?"WITHIN GROUP (".concat(R(o,"order by"),")"):"",f=e?"FILTER (WHERE ".concat(m(e.where),")"):"";return["".concat(i,"(").concat(a,")"),c,l,f].filter(n.hasVal).join(" ")},any_value:c.a,window_func:y.c,array:C,assign:o.a,binary_expr:a.a,case:function(r){var t=["CASE"],e=r.args,n=r.expr,s=r.parentheses;n&&t.push(m(n));for(var u=0,o=e.length;u<o;++u)t.push(e[u].type.toUpperCase()),e[u].cond&&(t.push(m(e[u].cond)),t.push("THEN")),t.push(m(e[u].result));return t.push("END"),s?"(".concat(t.join(" "),")"):t.join(" ")},cast:c.c,collate:i.a,column_ref:l.e,column_definition:l.c,datatype:n.dataTypeToSQL,extract:c.d,flatten:c.e,fulltext_search:l.i,function:c.f,lambda:c.h,insert:w.b,interval:f.a,json:function(r){var t=r.keyword,e=r.expr_list;return[Object(n.toUpper)(t),e.map((function(r){return m(r)})).join(", ")].join(" ")},json_object_arg:c.g,json_visitor:function(r){return[r.symbol,m(r.expr)].join("")},show:v.a,struct:C,tablefunc:c.i,tables:d.c,unnest:d.d,window:y.b};function A(r){var t=r.prefix,e=void 0===t?"@":t,s=r.name,u=r.members,o=r.quoted,a=r.suffix,i=[],l=u&&u.length>0?"".concat(s,".").concat(u.join(".")):s,c="".concat(e||"").concat(l);return a&&(c+=a),i.push(c),[o,i.join(" "),o].filter(n.hasVal).join("")}function m(r){if(r){var t=r;if(r.ast){var e=t.ast;Reflect.deleteProperty(t,e);for(var s=0,u=Object.keys(e);s<u.length;s++){var o=u[s];t[o]=e[o]}}var a=t.type;return"expr"===a?m(t.expr):E[a]?E[a](t):Object(n.literalToSQL)(t)}}function T(r){return r?(Array.isArray(r)||(r=[r]),r.map(m)):[]}function R(r,t){if(!Array.isArray(r))return"";var e=[],s=Object(n.toUpper)(t);switch(s){case"ORDER BY":e=r.map((function(r){return[m(r.expr),r.type||"ASC",Object(n.toUpper)(r.nulls)].filter(n.hasVal).join(" ")}));break;case"PARTITION BY":default:e=r.map((function(r){return m(r.expr)}))}return Object(n.connector)(s,e.join(", "))}E.var=A,E.expr_list=function(r){var t=T(r.value);return r.parentheses?"(".concat(t.join(", "),")"):t},E.select=function(r){var t="object"===h(r._next)?Object(w.b)(r):Object(b.a)(r);return r.parentheses?"(".concat(t,")"):t},E.unary_expr=function(r){var t=r.operator,e=r.parentheses,n=r.expr,s="-"===t||"+"===t||"~"===t||"!"===t?"":" ",u="".concat(t).concat(s).concat(m(n));return e?"(".concat(u,")"):u},E.map_object=function(r){var t=r.keyword,e=r.expr.map((function(r){return[Object(n.literalToSQL)(r.key),Object(n.literalToSQL)(r.value)].join(", ")})).join(", ");return[Object(n.toUpper)(t),"[".concat(e,"]")].join("")}},function(r,t,e){"use strict";e.d(t,"a",(function(){return b})),e.d(t,"c",(function(){return w})),e.d(t,"e",(function(){return v})),e.d(t,"g",(function(){return E})),e.d(t,"h",(function(){return A})),e.d(t,"b",(function(){return p})),e.d(t,"d",(function(){return d})),e.d(t,"f",(function(){return L})),e.d(t,"i",(function(){return h}));var n=e(18),s=e(1),u=e(7),o=e(3),a=e(0);function i(r){return(i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r})(r)}function l(r){return function(r){if(Array.isArray(r))return f(r)}(r)||function(r){if("undefined"!=typeof Symbol&&null!=r[Symbol.iterator]||null!=r["@@iterator"])return Array.from(r)}(r)||c(r)||function(){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 c(r,t){if(r){if("string"==typeof r)return f(r,t);var e={}.toString.call(r).slice(8,-1);return"Object"===e&&r.constructor&&(e=r.constructor.name),"Map"===e||"Set"===e?Array.from(r):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?f(r,t):void 0}}function f(r,t){(null==t||t>r.length)&&(t=r.length);for(var e=0,n=Array(t);e<t;e++)n[e]=r[e];return n}function b(r){if(!r||0===r.length)return"";var t,e=[],n=function(r,t){var e="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(!e){if(Array.isArray(r)||(e=c(r))||t&&r&&"number"==typeof r.length){e&&(r=e);var n=0,s=function(){};return{s:s,n:function(){return n>=r.length?{done:!0}:{done:!1,value:r[n++]}},e:function(r){throw r},f:s}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var u,o=!0,a=!1;return{s:function(){e=e.call(r)},n:function(){var r=e.next();return o=r.done,r},e:function(r){a=!0,u=r},f:function(){try{o||null==e.return||e.return()}finally{if(a)throw u}}}}(r);try{for(n.s();!(t=n.n()).done;){var s=t.value,u=s.brackets?"[".concat(Object(a.literalToSQL)(s.index),"]"):"".concat(s.notation).concat(Object(a.literalToSQL)(s.index));s.property&&(u="".concat(u,".").concat(Object(a.literalToSQL)(s.property))),e.push(u)}}catch(r){n.e(r)}finally{n.f()}return e.join("")}function v(r){var t=r.array_index,e=r.as,n=r.column,u=r.db,o=r.isDual,i=r.notations,c=void 0===i?[]:i,f=r.schema,v=r.table,p=r.parentheses,L=r.suffix,C=r.order_by,d=r.subFields,w=void 0===d?[]:d,y="*"===n?"*":function(r,t){if("string"==typeof r)return Object(a.identifierToSql)(r,t);var e=r.expr,n=r.offset,u=r.suffix,o=n&&n.map((function(r){return["[",r.name,"".concat(r.name?"(":""),Object(a.literalToSQL)(r.value),"".concat(r.name?")":""),"]"].filter(a.hasVal).join("")})).join("");return[Object(s.a)(e),o,u].filter(a.hasVal).join("")}(n,o),h=[u,f,v].filter(a.hasVal).map((function(r){return"".concat("string"==typeof r?Object(a.identifierToSql)(r):Object(s.a)(r))})),E=h[0];if(E){for(var A=1;A<h.length;++A)E="".concat(E).concat(c[A]||".").concat(h[A]);y="".concat(E).concat(c[A]||".").concat(y)}var m=[y=["".concat(y).concat(b(t))].concat(l(w)).join("."),Object(a.commonOptionConnector)("AS",s.a,e)];m.push("string"==typeof L?Object(a.toUpper)(L):Object(s.a)(L)),m.push(Object(a.toUpper)(C));var T=m.filter(a.hasVal).join(" ");return p?"(".concat(T,")"):T}function p(r){if(r){var t=r.dataType,e=r.length,n=r.suffix,o=r.scale,a=r.expr,i=t;if(null!=e&&(i+="(".concat([e,o].filter((function(r){return null!=r})).join(", "),")")),n&&n.length&&(i+=" ".concat(n.join(" "))),a&&(i+=Object(s.a)(a)),r.array){var l=Object(u.b)(r);i+=[/^\[.*\]$/.test(l)?"":" ",l].join("")}return i}}function L(r){var t=[];if(!r)return t;var e=r.definition,n=r.keyword,u=r.match,i=r.table,l=r.on_action;return t.push(Object(a.toUpper)(n)),t.push(Object(o.c)(i)),t.push(e&&"(".concat(e.map((function(r){return Object(s.a)(r)})).join(", "),")")),t.push(Object(a.toUpper)(u)),l.map((function(r){return t.push(Object(a.toUpper)(r.type),Object(s.a)(r.value))})),t.filter(a.hasVal)}function C(r){var t=[],e=r.nullable,u=r.character_set,o=r.check,i=r.comment,c=r.constraint,f=r.collate,b=r.storage,v=r.using,p=r.default_val,C=r.generated,d=r.auto_increment,w=r.unique,y=r.primary_key,h=r.column_format,E=r.reference_definition;if(t.push(Object(a.toUpper)(e&&e.action),Object(a.toUpper)(e&&e.value)),p){var A=p.type,m=p.value;t.push(A.toUpperCase(),Object(s.a)(m))}var T=Object(a.getParserOpt)().database;return c&&t.push(Object(a.toUpper)(c.keyword),Object(a.literalToSQL)(c.constraint)),t.push(Object(n.a)(o)),t.push(function(r){if(r)return[Object(a.toUpper)(r.value),"(".concat(Object(s.a)(r.expr),")"),Object(a.toUpper)(r.storage_type)].filter(a.hasVal).join(" ")}(C)),t.push(Object(a.autoIncrementToSQL)(d),Object(a.toUpper)(y),Object(a.toUpper)(w),Object(a.commentToSQL)(i)),t.push.apply(t,l(Object(a.commonTypeValue)(u))),"sqlite"!==T&&t.push(Object(s.a)(f)),t.push.apply(t,l(Object(a.commonTypeValue)(h))),t.push.apply(t,l(Object(a.commonTypeValue)(b))),t.push.apply(t,l(L(E))),t.push(Object(a.commonOptionConnector)("USING",s.a,v)),t.filter(a.hasVal).join(" ")}function d(r){var t=r.column,e=r.collate,n=r.nulls,u=r.opclass,o=r.order_by,i="string"==typeof t?{type:"column_ref",table:r.table,column:t}:r;return i.collate=null,[Object(s.a)(i),Object(s.a)(e),u,Object(a.toUpper)(o),Object(a.toUpper)(n)].filter(a.hasVal).join(" ")}function w(r){var t=[],e=v(r.column),n=p(r.definition);return t.push(e),t.push(n),t.push(C(r)),t.filter(a.hasVal).join(" ")}function y(r){return r?"object"===i(r)?["AS",Object(s.a)(r)].join(" "):["AS",/^(`?)[a-z_][0-9a-z_]*(`?)$/i.test(r)?Object(a.identifierToSql)(r):Object(a.columnIdentifierToSql)(r)].join(" "):""}function h(r){var t=r.against,e=r.as,n=r.columns,u=r.match,o=r.mode;return[[Object(a.toUpper)(u),"(".concat(n.map((function(r){return v(r)})).join(", "),")")].join(" "),[Object(a.toUpper)(t),["(",Object(s.a)(r.expr),o&&" ".concat(Object(a.literalToSQL)(o)),")"].filter(a.hasVal).join("")].join(" "),y(e)].filter(a.hasVal).join(" ")}function E(r,t){var e=r.expr,n=r.type;if("cast"===n)return Object(u.c)(r);t&&(e.isDual=t);var o=Object(s.a)(e),i=r.expr_list;if(i){var l=[o],c=i.map((function(r){return E(r,t)})).join(", ");return l.push([Object(a.toUpper)(n),n&&"(",c,n&&")"].filter(a.hasVal).join("")),l.filter(a.hasVal).join(" ")}return e.parentheses&&Reflect.has(e,"array_index")&&"cast"!==e.type&&(o="(".concat(o,")")),e.array_index&&"column_ref"!==e.type&&(o="".concat(o).concat(b(e.array_index))),[o,y(r.as)].filter(a.hasVal).join(" ")}function A(r,t){if(!r||"*"===r)return r;var e=function(r){var t=Array.isArray(r)&&r[0];return!(!t||"dual"!==t.type)}(t);return r.map((function(r){return E(r,e)})).join(", ")}},function(r,t,e){"use strict";e.d(t,"c",(function(){return p})),e.d(t,"a",(function(){return L})),e.d(t,"b",(function(){return v})),e.d(t,"d",(function(){return l}));var n=e(21),s=e(2),u=e(1),o=e(20),a=e(22),i=e(0);function l(r){var t=r.type,e=r.as,n=r.expr,s=r.with_offset;return["".concat(Object(i.toUpper)(t),"(").concat(n&&Object(u.a)(n)||"",")"),Object(i.commonOptionConnector)("AS","string"==typeof e?i.identifierToSql:u.a,e),Object(i.commonOptionConnector)(Object(i.toUpper)(s&&s.keyword),i.identifierToSql,s&&s.as)].filter(i.hasVal).join(" ")}function c(r){if(r)switch(r.type){case"pivot":case"unpivot":return function(r){var t=r.as,e=r.column,o=r.expr,a=r.in_expr,l=r.type,c=[Object(u.a)(o),"FOR",Object(s.e)(e),Object(n.a)(a)],f=["".concat(Object(i.toUpper)(l),"(").concat(c.join(" "),")")];return t&&f.push("AS",Object(i.identifierToSql)(t)),f.join(" ")}(r);default:return""}}function f(r){if(r){var t=r.keyword,e=r.expr,n=r.index,s=r.index_columns,o=r.parentheses,a=r.prefix,l=[];switch(t.toLowerCase()){case"forceseek":l.push(Object(i.toUpper)(t),"(".concat(Object(i.identifierToSql)(n)),"(".concat(s.map(u.a).filter(i.hasVal).join(", "),"))"));break;case"spatial_window_max_cells":l.push(Object(i.toUpper)(t),"=",Object(u.a)(e));break;case"index":l.push(Object(i.toUpper)(a),Object(i.toUpper)(t),o?"(".concat(e.map(i.identifierToSql).join(", "),")"):"= ".concat(Object(i.identifierToSql)(e)));break;default:l.push(Object(u.a)(e))}return l.filter(i.hasVal).join(" ")}}function b(r){var t=[];switch(r.keyword){case"as":t.push("AS","OF",Object(u.a)(r.of));break;case"from_to":t.push("FROM",Object(u.a)(r.from),"TO",Object(u.a)(r.to));break;case"between_and":t.push("BETWEEN",Object(u.a)(r.between),"AND",Object(u.a)(r.and));break;case"contained":t.push("CONTAINED","IN",Object(u.a)(r.in))}return t.filter(i.hasVal).join(" ")}function v(r){if("UNNEST"===Object(i.toUpper)(r.type))return l(r);var t,e,n,v,p=r.table,L=r.db,C=r.as,d=r.expr,w=r.operator,y=r.prefix,h=r.schema,E=r.server,A=r.suffix,m=r.tablesample,T=r.temporal_table,R=r.table_hint,I=Object(i.identifierToSql)(E),N=Object(i.identifierToSql)(L),O=Object(i.identifierToSql)(h),S=p&&Object(i.identifierToSql)(p);if(d)switch(d.type){case"values":var _=d.parentheses,g=d.values,x=d.prefix,U=[_&&"(","",_&&")"],k=Object(o.b)(g);x&&(k=k.split("(").slice(1).map((function(r){return"".concat(Object(i.toUpper)(x),"(").concat(r)})).join("")),U[1]="VALUES ".concat(k),S=U.filter(i.hasVal).join("");break;case"tumble":S=function(r){if(!r)return"";var t=r.data,e=r.timecol,n=r.size;return["TABLE(TUMBLE(TABLE",[Object(i.identifierToSql)(t.db),Object(i.identifierToSql)(t.table)].filter(i.hasVal).join("."),"DESCRIPTOR(".concat(Object(s.e)(e),")"),"".concat(Object(a.a)(n),"))")].filter(i.hasVal).join(" ")}(d);break;case"generator":e=(t=d).keyword,n=t.type,v=t.generators.map((function(r){return Object(i.commonTypeValue)(r).join(" ")})).join(", "),S="".concat(Object(i.toUpper)(e),"(").concat(Object(i.toUpper)(n),"(").concat(v,"))");break;default:S=Object(u.a)(d)}var M=[[I,N,O,S=[Object(i.toUpper)(y),S,Object(i.toUpper)(A)].filter(i.hasVal).join(" ")].filter(i.hasVal).join(".")];if(m){var D=["TABLESAMPLE",Object(u.a)(m.expr),Object(i.literalToSQL)(m.repeatable)].filter(i.hasVal).join(" ");M.push(D)}M.push(function(r){if(r){var t=r.keyword,e=r.expr;return[Object(i.toUpper)(t),b(e)].filter(i.hasVal).join(" ")}}(T),Object(i.commonOptionConnector)("AS",i.identifierToSql,C),c(w)),R&&M.push(Object(i.toUpper)(R.keyword),"(".concat(R.expr.map(f).filter(i.hasVal).join(", "),")"));var j=M.filter(i.hasVal).join(" ");return r.parentheses?"(".concat(j,")"):j}function p(r){if(!r)return"";if(!Array.isArray(r)){var t=r.expr,e=r.parentheses,n=p(t);return e?"(".concat(n,")"):n}var s=r[0],o=[];if("dual"===s.type)return"DUAL";o.push(v(s));for(var a=1;a<r.length;++a){var l=r[a],c=l.on,f=l.using,b=l.join,L=[];L.push(b?" ".concat(Object(i.toUpper)(b)):","),L.push(v(l)),L.push(Object(i.commonOptionConnector)("ON",u.a,c)),f&&L.push("USING (".concat(f.map(i.identifierToSql).join(", "),")")),o.push(L.filter(i.hasVal).join(" "))}return o.filter(i.hasVal).join("")}function L(r){var t=r.keyword,e=r.symbol,n=r.value,s=[t.toUpperCase()];e&&s.push(e);var o=Object(i.literalToSQL)(n);switch(t){case"partition by":case"default collate":o=Object(u.a)(n);break;case"options":o="(".concat(n.map((function(r){return[r.keyword,r.symbol,Object(u.a)(r.value)].join(" ")})).join(", "),")");break;case"cluster by":o=n.map(u.a).join(", ")}return s.push(o),s.join(" ")}},function(r,t,e){"use strict";e.d(t,"a",(function(){return p})),e.d(t,"b",(function(){return L})),e.d(t,"c",(function(){return T})),e.d(t,"d",(function(){return R})),e.d(t,"e",(function(){return C})),e.d(t,"f",(function(){return d})),e.d(t,"g",(function(){return w})),e.d(t,"h",(function(){return O})),e.d(t,"i",(function(){return N})),e.d(t,"j",(function(){return I})),e.d(t,"l",(function(){return y})),e.d(t,"m",(function(){return h})),e.d(t,"o",(function(){return E})),e.d(t,"n",(function(){return A})),e.d(t,"k",(function(){return m}));var n=e(2),s=e(16),u=e(0),o=e(1),a=e(3),i=e(17),l=e(6);function c(r,t){var e="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(!e){if(Array.isArray(r)||(e=b(r))||t&&r&&"number"==typeof r.length){e&&(r=e);var n=0,s=function(){};return{s:s,n:function(){return n>=r.length?{done:!0}:{done:!1,value:r[n++]}},e:function(r){throw r},f:s}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var u,o=!0,a=!1;return{s:function(){e=e.call(r)},n:function(){var r=e.next();return o=r.done,r},e:function(r){a=!0,u=r},f:function(){try{o||null==e.return||e.return()}finally{if(a)throw u}}}}function f(r){return function(r){if(Array.isArray(r))return v(r)}(r)||function(r){if("undefined"!=typeof Symbol&&null!=r[Symbol.iterator]||null!=r["@@iterator"])return Array.from(r)}(r)||b(r)||function(){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 b(r,t){if(r){if("string"==typeof r)return v(r,t);var e={}.toString.call(r).slice(8,-1);return"Object"===e&&r.constructor&&(e=r.constructor.name),"Map"===e||"Set"===e?Array.from(r):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?v(r,t):void 0}}function v(r,t){(null==t||t>r.length)&&(t=r.length);for(var e=0,n=Array(t);e<t;e++)n[e]=r[e];return n}function p(r){var t=Object(o.a)(r.expr);return"".concat("CALL"," ").concat(t)}function L(r){var t=r.type,e=r.keyword,s=r.name,i=r.prefix,l=r.suffix,c=[Object(u.toUpper)(t),Object(u.toUpper)(e),Object(u.toUpper)(i)];switch(e){case"table":c.push(Object(a.c)(s));break;case"trigger":c.push([s[0].schema?"".concat(Object(u.identifierToSql)(s[0].schema),"."):"",Object(u.identifierToSql)(s[0].trigger)].filter(u.hasVal).join(""));break;case"database":case"schema":case"procedure":c.push(Object(u.identifierToSql)(s));break;case"view":c.push(Object(a.c)(s),r.options&&r.options.map(o.a).filter(u.hasVal).join(" "));break;case"index":c.push.apply(c,[Object(n.e)(s)].concat(f(r.table?["ON",Object(a.b)(r.table)]:[]),[r.options&&r.options.map(o.a).filter(u.hasVal).join(" ")]))}return l&&c.push(l.map(o.a).filter(u.hasVal).join(" ")),c.filter(u.hasVal).join(" ")}function C(r){var t=r.type,e=r.table,n=Object(u.toUpper)(t);return"".concat(n," ").concat(Object(u.identifierToSql)(e))}function d(r){var t=r.type,e=r.name,n=r.args,s=[Object(u.toUpper)(t)],a=[e];return n&&a.push("(".concat(Object(o.a)(n).join(", "),")")),s.push(a.join("")),s.filter(u.hasVal).join(" ")}function w(r){var t=r.type,e=r.label,n=r.target,s=r.query,o=r.stmts;return[e,Object(u.toUpper)(t),n,"IN",Object(l.a)([s]),"LOOP",Object(l.a)(o),"END LOOP",e].filter(u.hasVal).join(" ")}function y(r){var t=r.type,e=r.level,n=r.raise,s=r.using,a=[Object(u.toUpper)(t),Object(u.toUpper)(e)];return n&&a.push([Object(u.literalToSQL)(n.keyword),"format"===n.type&&n.expr.length>0&&","].filter(u.hasVal).join(""),n.expr.map((function(r){return Object(o.a)(r)})).join(", ")),s&&a.push(Object(u.toUpper)(s.type),Object(u.toUpper)(s.option),s.symbol,s.expr.map((function(r){return Object(o.a)(r)})).join(", ")),a.filter(u.hasVal).join(" ")}function h(r){var t=r.type,e=r.table,n=[],s="".concat(t&&t.toUpperCase()," TABLE");if(e){var u,o=c(e);try{for(o.s();!(u=o.n()).done;){var i=u.value.map(a.b);n.push(i.join(" TO "))}}catch(r){o.e(r)}finally{o.f()}}return"".concat(s," ").concat(n.join(", "))}function E(r){var t=r.type,e=r.db,n=Object(u.toUpper)(t),s=Object(u.identifierToSql)(e);return"".concat(n," ").concat(s)}function A(r){var t=r.type,e=r.expr,n=r.keyword,s=Object(u.toUpper)(t),a=e.map(o.a).join(", ");return[s,Object(u.toUpper)(n),a].filter(u.hasVal).join(" ")}function m(r){var t=r.type,e=r.keyword,n=r.tables,s=[t.toUpperCase(),Object(u.toUpper)(e)];if("UNLOCK"===t.toUpperCase())return s.join(" ");var o,i=[],l=c(n);try{var b=function(){var r=o.value,t=r.table,e=r.lock_type,n=[Object(a.b)(t)];if(e){n.push(["prefix","type","suffix"].map((function(r){return Object(u.toUpper)(e[r])})).filter(u.hasVal).join(" "))}i.push(n.join(" "))};for(l.s();!(o=l.n()).done;)b()}catch(r){l.e(r)}finally{l.f()}return s.push.apply(s,[i.join(", ")].concat(f(function(r){var t=r.lock_mode,e=r.nowait,n=[];if(t){var s=t.mode;n.push(s.toUpperCase())}return e&&n.push(e.toUpperCase()),n}(r)))),s.filter(u.hasVal).join(" ")}function T(r){var t=r.type,e=r.keyword,n=r.expr;return[Object(u.toUpper)(t),Object(u.toUpper)(e),Object(o.a)(n)].filter(u.hasVal).join(" ")}function R(r){var t=r.type,e=r.declare,a=r.symbol,i=[Object(u.toUpper)(t)],l=e.map((function(r){var t=r.at,e=r.name,a=r.as,i=r.constant,l=r.datatype,c=r.not_null,f=r.prefix,b=r.definition,v=r.keyword,p=[[t,e].filter(u.hasVal).join(""),Object(u.toUpper)(a),Object(u.toUpper)(i)];switch(v){case"variable":p.push(Object(n.b)(l),Object(o.a)(r.collate),Object(u.toUpper)(c)),b&&p.push(Object(u.toUpper)(b.keyword),Object(o.a)(b.value));break;case"cursor":p.push(Object(u.toUpper)(f));break;case"table":p.push(Object(u.toUpper)(f),"(".concat(b.map(s.a).join(", "),")"))}return p.filter(u.hasVal).join(" ")})).join("".concat(a," "));return i.push(l),i.join(" ")}function I(r){var t=r.boolean_expr,e=r.else_expr,n=r.elseif_expr,s=r.if_expr,a=r.prefix,l=r.go,c=r.semicolons,f=r.suffix,b=r.type,v=[Object(u.toUpper)(b),Object(o.a)(t),Object(u.literalToSQL)(a),"".concat(Object(i.a)(s.ast||s)).concat(c[0]),Object(u.toUpper)(l)];return n&&v.push(n.map((function(r){return[Object(u.toUpper)(r.type),Object(o.a)(r.boolean_expr),"THEN",Object(i.a)(r.then.ast||r.then),r.semicolon].filter(u.hasVal).join(" ")})).join(" ")),e&&v.push("ELSE","".concat(Object(i.a)(e.ast||e)).concat(c[1])),v.push(Object(u.literalToSQL)(f)),v.filter(u.hasVal).join(" ")}function N(r){var t=r.name,e=r.host,n=[Object(u.literalToSQL)(t)];return e&&n.push("@",Object(u.literalToSQL)(e)),n.join("")}function O(r){var t=r.type,e=r.grant_option_for,s=r.keyword,a=r.objects,i=r.on,l=r.to_from,c=r.user_or_roles,f=r.with,b=[Object(u.toUpper)(t),Object(u.literalToSQL)(e)],v=a.map((function(r){var t=r.priv,e=r.columns,s=[Object(o.a)(t)];return e&&s.push("(".concat(e.map(n.e).join(", "),")")),s.join(" ")})).join(", ");if(b.push(v),i)switch(b.push("ON"),s){case"priv":b.push(Object(u.literalToSQL)(i.object_type),i.priv_level.map((function(r){return[Object(u.identifierToSql)(r.prefix),Object(u.identifierToSql)(r.name)].filter(u.hasVal).join(".")})).join(", "));break;case"proxy":b.push(N(i))}return b.push(Object(u.toUpper)(l),c.map(N).join(", ")),b.push(Object(u.literalToSQL)(f)),b.filter(u.hasVal).join(" ")}},function(r,t,e){(function(r){var n,s=function(r){"use strict";var t=1e7,e=9007199254740992,n=f(e),u="function"==typeof BigInt;function o(r,t,e,n){return void 0===r?o[0]:void 0!==t&&(10!=+t||e)?G(r,t,e,n):V(r)}function a(r,t){this.value=r,this.sign=t,this.isSmall=!1}function i(r){this.value=r,this.sign=r<0,this.isSmall=!0}function l(r){this.value=r}function c(r){return-e<r&&r<e}function f(r){return r<1e7?[r]:r<1e14?[r%1e7,Math.floor(r/1e7)]:[r%1e7,Math.floor(r/1e7)%1e7,Math.floor(r/1e14)]}function b(r){v(r);var e=r.length;if(e<4&&O(r,n)<0)switch(e){case 0:return 0;case 1:return r[0];case 2:return r[0]+r[1]*t;default:return r[0]+(r[1]+r[2]*t)*t}return r}function v(r){for(var t=r.length;0===r[--t];);r.length=t+1}function p(r){for(var t=new Array(r),e=-1;++e<r;)t[e]=0;return t}function L(r){return r>0?Math.floor(r):Math.ceil(r)}function C(r,e){var n,s,u=r.length,o=e.length,a=new Array(u),i=0,l=t;for(s=0;s<o;s++)i=(n=r[s]+e[s]+i)>=l?1:0,a[s]=n-i*l;for(;s<u;)i=(n=r[s]+i)===l?1:0,a[s++]=n-i*l;return i>0&&a.push(i),a}function d(r,t){return r.length>=t.length?C(r,t):C(t,r)}function w(r,e){var n,s,u=r.length,o=new Array(u),a=t;for(s=0;s<u;s++)n=r[s]-a+e,e=Math.floor(n/a),o[s]=n-e*a,e+=1;for(;e>0;)o[s++]=e%a,e=Math.floor(e/a);return o}function y(r,t){var e,n,s=r.length,u=t.length,o=new Array(s),a=0;for(e=0;e<u;e++)(n=r[e]-a-t[e])<0?(n+=1e7,a=1):a=0,o[e]=n;for(e=u;e<s;e++){if(!((n=r[e]-a)<0)){o[e++]=n;break}n+=1e7,o[e]=n}for(;e<s;e++)o[e]=r[e];return v(o),o}function h(r,t,e){var n,s,u=r.length,o=new Array(u),l=-t;for(n=0;n<u;n++)s=r[n]+l,l=Math.floor(s/1e7),s%=1e7,o[n]=s<0?s+1e7:s;return"number"==typeof(o=b(o))?(e&&(o=-o),new i(o)):new a(o,e)}function E(r,t){var e,n,s,u,o=r.length,a=t.length,i=p(o+a);for(s=0;s<o;++s){u=r[s];for(var l=0;l<a;++l)e=u*t[l]+i[s+l],n=Math.floor(e/1e7),i[s+l]=e-1e7*n,i[s+l+1]+=n}return v(i),i}function A(r,e){var n,s,u=r.length,o=new Array(u),a=t,i=0;for(s=0;s<u;s++)n=r[s]*e+i,i=Math.floor(n/a),o[s]=n-i*a;for(;i>0;)o[s++]=i%a,i=Math.floor(i/a);return o}function m(r,t){for(var e=[];t-- >0;)e.push(0);return e.concat(r)}function T(r,e,n){return new a(r<t?A(e,r):E(e,f(r)),n)}function R(r){var t,e,n,s,u=r.length,o=p(u+u);for(n=0;n<u;n++){e=0-(s=r[n])*s;for(var a=n;a<u;a++)t=s*r[a]*2+o[n+a]+e,e=Math.floor(t/1e7),o[n+a]=t-1e7*e;o[n+u]=e}return v(o),o}function I(r,t){var e,n,s,u,o=r.length,a=p(o);for(s=0,e=o-1;e>=0;--e)s=(u=1e7*s+r[e])-(n=L(u/t))*t,a[e]=0|n;return[a,0|s]}function N(r,e){var n,s=V(e);if(u)return[new l(r.value/s.value),new l(r.value%s.value)];var c,C=r.value,d=s.value;if(0===d)throw new Error("Cannot divide by zero");if(r.isSmall)return s.isSmall?[new i(L(C/d)),new i(C%d)]:[o[0],r];if(s.isSmall){if(1===d)return[r,o[0]];if(-1==d)return[r.negate(),o[0]];var w=Math.abs(d);if(w<t){c=b((n=I(C,w))[0]);var h=n[1];return r.sign&&(h=-h),"number"==typeof c?(r.sign!==s.sign&&(c=-c),[new i(c),new i(h)]):[new a(c,r.sign!==s.sign),new i(h)]}d=f(w)}var E=O(C,d);if(-1===E)return[o[0],r];if(0===E)return[o[r.sign===s.sign?1:-1],o[0]];c=(n=C.length+d.length<=200?function(r,e){var n,s,u,o,a,i,l,c=r.length,f=e.length,v=t,L=p(e.length),C=e[f-1],d=Math.ceil(v/(2*C)),w=A(r,d),y=A(e,d);for(w.length<=c&&w.push(0),y.push(0),C=y[f-1],s=c-f;s>=0;s--){for(n=v-1,w[s+f]!==C&&(n=Math.floor((w[s+f]*v+w[s+f-1])/C)),u=0,o=0,i=y.length,a=0;a<i;a++)u+=n*y[a],l=Math.floor(u/v),o+=w[s+a]-(u-l*v),u=l,o<0?(w[s+a]=o+v,o=-1):(w[s+a]=o,o=0);for(;0!==o;){for(n-=1,u=0,a=0;a<i;a++)(u+=w[s+a]-v+y[a])<0?(w[s+a]=u+v,u=0):(w[s+a]=u,u=1);o+=u}L[s]=n}return w=I(w,d)[0],[b(L),b(w)]}(C,d):function(r,t){for(var e,n,s,u,o,a=r.length,i=t.length,l=[],c=[];a;)if(c.unshift(r[--a]),v(c),O(c,t)<0)l.push(0);else{s=1e7*c[(n=c.length)-1]+c[n-2],u=1e7*t[i-1]+t[i-2],n>i&&(s=1e7*(s+1)),e=Math.ceil(s/u);do{if(O(o=A(t,e),c)<=0)break;e--}while(e);l.push(e),c=y(c,o)}return l.reverse(),[b(l),b(c)]}(C,d))[0];var m=r.sign!==s.sign,T=n[1],R=r.sign;return"number"==typeof c?(m&&(c=-c),c=new i(c)):c=new a(c,m),"number"==typeof T?(R&&(T=-T),T=new i(T)):T=new a(T,R),[c,T]}function O(r,t){if(r.length!==t.length)return r.length>t.length?1:-1;for(var e=r.length-1;e>=0;e--)if(r[e]!==t[e])return r[e]>t[e]?1:-1;return 0}function S(r){var t=r.abs();return!t.isUnit()&&(!!(t.equals(2)||t.equals(3)||t.equals(5))||!(t.isEven()||t.isDivisibleBy(3)||t.isDivisibleBy(5))&&(!!t.lesser(49)||void 0))}function _(r,t){for(var e,n,u,o=r.prev(),a=o,i=0;a.isEven();)a=a.divide(2),i++;r:for(n=0;n<t.length;n++)if(!r.lesser(t[n])&&!(u=s(t[n]).modPow(a,r)).isUnit()&&!u.equals(o)){for(e=i-1;0!=e;e--){if((u=u.square().mod(r)).isUnit())return!1;if(u.equals(o))continue r}return!1}return!0}a.prototype=Object.create(o.prototype),i.prototype=Object.create(o.prototype),l.prototype=Object.create(o.prototype),a.prototype.add=function(r){var t=V(r);if(this.sign!==t.sign)return this.subtract(t.negate());var e=this.value,n=t.value;return t.isSmall?new a(w(e,Math.abs(n)),this.sign):new a(d(e,n),this.sign)},a.prototype.plus=a.prototype.add,i.prototype.add=function(r){var t=V(r),e=this.value;if(e<0!==t.sign)return this.subtract(t.negate());var n=t.value;if(t.isSmall){if(c(e+n))return new i(e+n);n=f(Math.abs(n))}return new a(w(n,Math.abs(e)),e<0)},i.prototype.plus=i.prototype.add,l.prototype.add=function(r){return new l(this.value+V(r).value)},l.prototype.plus=l.prototype.add,a.prototype.subtract=function(r){var t=V(r);if(this.sign!==t.sign)return this.add(t.negate());var e=this.value,n=t.value;return t.isSmall?h(e,Math.abs(n),this.sign):function(r,t,e){var n;return O(r,t)>=0?n=y(r,t):(n=y(t,r),e=!e),"number"==typeof(n=b(n))?(e&&(n=-n),new i(n)):new a(n,e)}(e,n,this.sign)},a.prototype.minus=a.prototype.subtract,i.prototype.subtract=function(r){var t=V(r),e=this.value;if(e<0!==t.sign)return this.add(t.negate());var n=t.value;return t.isSmall?new i(e-n):h(n,Math.abs(e),e>=0)},i.prototype.minus=i.prototype.subtract,l.prototype.subtract=function(r){return new l(this.value-V(r).value)},l.prototype.minus=l.prototype.subtract,a.prototype.negate=function(){return new a(this.value,!this.sign)},i.prototype.negate=function(){var r=this.sign,t=new i(-this.value);return t.sign=!r,t},l.prototype.negate=function(){return new l(-this.value)},a.prototype.abs=function(){return new a(this.value,!1)},i.prototype.abs=function(){return new i(Math.abs(this.value))},l.prototype.abs=function(){return new l(this.value>=0?this.value:-this.value)},a.prototype.multiply=function(r){var e,n,s,u=V(r),i=this.value,l=u.value,c=this.sign!==u.sign;if(u.isSmall){if(0===l)return o[0];if(1===l)return this;if(-1===l)return this.negate();if((e=Math.abs(l))<t)return new a(A(i,e),c);l=f(e)}return n=i.length,s=l.length,new a(-.012*n-.012*s+15e-6*n*s>0?function r(t,e){var n=Math.max(t.length,e.length);if(n<=30)return E(t,e);n=Math.ceil(n/2);var s=t.slice(n),u=t.slice(0,n),o=e.slice(n),a=e.slice(0,n),i=r(u,a),l=r(s,o),c=r(d(u,s),d(a,o)),f=d(d(i,m(y(y(c,i),l),n)),m(l,2*n));return v(f),f}(i,l):E(i,l),c)},a.prototype.times=a.prototype.multiply,i.prototype._multiplyBySmall=function(r){return c(r.value*this.value)?new i(r.value*this.value):T(Math.abs(r.value),f(Math.abs(this.value)),this.sign!==r.sign)},a.prototype._multiplyBySmall=function(r){return 0===r.value?o[0]:1===r.value?this:-1===r.value?this.negate():T(Math.abs(r.value),this.value,this.sign!==r.sign)},i.prototype.multiply=function(r){return V(r)._multiplyBySmall(this)},i.prototype.times=i.prototype.multiply,l.prototype.multiply=function(r){return new l(this.value*V(r).value)},l.prototype.times=l.prototype.multiply,a.prototype.square=function(){return new a(R(this.value),!1)},i.prototype.square=function(){var r=this.value*this.value;return c(r)?new i(r):new a(R(f(Math.abs(this.value))),!1)},l.prototype.square=function(r){return new l(this.value*this.value)},a.prototype.divmod=function(r){var t=N(this,r);return{quotient:t[0],remainder:t[1]}},l.prototype.divmod=i.prototype.divmod=a.prototype.divmod,a.prototype.divide=function(r){return N(this,r)[0]},l.prototype.over=l.prototype.divide=function(r){return new l(this.value/V(r).value)},i.prototype.over=i.prototype.divide=a.prototype.over=a.prototype.divide,a.prototype.mod=function(r){return N(this,r)[1]},l.prototype.mod=l.prototype.remainder=function(r){return new l(this.value%V(r).value)},i.prototype.remainder=i.prototype.mod=a.prototype.remainder=a.prototype.mod,a.prototype.pow=function(r){var t,e,n,s=V(r),u=this.value,a=s.value;if(0===a)return o[1];if(0===u)return o[0];if(1===u)return o[1];if(-1===u)return s.isEven()?o[1]:o[-1];if(s.sign)return o[0];if(!s.isSmall)throw new Error("The exponent "+s.toString()+" is too large.");if(this.isSmall&&c(t=Math.pow(u,a)))return new i(L(t));for(e=this,n=o[1];!0&a&&(n=n.times(e),--a),0!==a;)a/=2,e=e.square();return n},i.prototype.pow=a.prototype.pow,l.prototype.pow=function(r){var t=V(r),e=this.value,n=t.value,s=BigInt(0),u=BigInt(1),a=BigInt(2);if(n===s)return o[1];if(e===s)return o[0];if(e===u)return o[1];if(e===BigInt(-1))return t.isEven()?o[1]:o[-1];if(t.isNegative())return new l(s);for(var i=this,c=o[1];(n&u)===u&&(c=c.times(i),--n),n!==s;)n/=a,i=i.square();return c},a.prototype.modPow=function(r,t){if(r=V(r),(t=V(t)).isZero())throw new Error("Cannot take modPow with modulus 0");var e=o[1],n=this.mod(t);for(r.isNegative()&&(r=r.multiply(o[-1]),n=n.modInv(t));r.isPositive();){if(n.isZero())return o[0];r.isOdd()&&(e=e.multiply(n).mod(t)),r=r.divide(2),n=n.square().mod(t)}return e},l.prototype.modPow=i.prototype.modPow=a.prototype.modPow,a.prototype.compareAbs=function(r){var t=V(r),e=this.value,n=t.value;return t.isSmall?1:O(e,n)},i.prototype.compareAbs=function(r){var t=V(r),e=Math.abs(this.value),n=t.value;return t.isSmall?e===(n=Math.abs(n))?0:e>n?1:-1:-1},l.prototype.compareAbs=function(r){var t=this.value,e=V(r).value;return(t=t>=0?t:-t)===(e=e>=0?e:-e)?0:t>e?1:-1},a.prototype.compare=function(r){if(r===1/0)return-1;if(r===-1/0)return 1;var t=V(r),e=this.value,n=t.value;return this.sign!==t.sign?t.sign?1:-1:t.isSmall?this.sign?-1:1:O(e,n)*(this.sign?-1:1)},a.prototype.compareTo=a.prototype.compare,i.prototype.compare=function(r){if(r===1/0)return-1;if(r===-1/0)return 1;var t=V(r),e=this.value,n=t.value;return t.isSmall?e==n?0:e>n?1:-1:e<0!==t.sign?e<0?-1:1:e<0?1:-1},i.prototype.compareTo=i.prototype.compare,l.prototype.compare=function(r){if(r===1/0)return-1;if(r===-1/0)return 1;var t=this.value,e=V(r).value;return t===e?0:t>e?1:-1},l.prototype.compareTo=l.prototype.compare,a.prototype.equals=function(r){return 0===this.compare(r)},l.prototype.eq=l.prototype.equals=i.prototype.eq=i.prototype.equals=a.prototype.eq=a.prototype.equals,a.prototype.notEquals=function(r){return 0!==this.compare(r)},l.prototype.neq=l.prototype.notEquals=i.prototype.neq=i.prototype.notEquals=a.prototype.neq=a.prototype.notEquals,a.prototype.greater=function(r){return this.compare(r)>0},l.prototype.gt=l.prototype.greater=i.prototype.gt=i.prototype.greater=a.prototype.gt=a.prototype.greater,a.prototype.lesser=function(r){return this.compare(r)<0},l.prototype.lt=l.prototype.lesser=i.prototype.lt=i.prototype.lesser=a.prototype.lt=a.prototype.lesser,a.prototype.greaterOrEquals=function(r){return this.compare(r)>=0},l.prototype.geq=l.prototype.greaterOrEquals=i.prototype.geq=i.prototype.greaterOrEquals=a.prototype.geq=a.prototype.greaterOrEquals,a.prototype.lesserOrEquals=function(r){return this.compare(r)<=0},l.prototype.leq=l.prototype.lesserOrEquals=i.prototype.leq=i.prototype.lesserOrEquals=a.prototype.leq=a.prototype.lesserOrEquals,a.prototype.isEven=function(){return 0==(1&this.value[0])},i.prototype.isEven=function(){return 0==(1&this.value)},l.prototype.isEven=function(){return(this.value&BigInt(1))===BigInt(0)},a.prototype.isOdd=function(){return 1==(1&this.value[0])},i.prototype.isOdd=function(){return 1==(1&this.value)},l.prototype.isOdd=function(){return(this.value&BigInt(1))===BigInt(1)},a.prototype.isPositive=function(){return!this.sign},i.prototype.isPositive=function(){return this.value>0},l.prototype.isPositive=i.prototype.isPositive,a.prototype.isNegative=function(){return this.sign},i.prototype.isNegative=function(){return this.value<0},l.prototype.isNegative=i.prototype.isNegative,a.prototype.isUnit=function(){return!1},i.prototype.isUnit=function(){return 1===Math.abs(this.value)},l.prototype.isUnit=function(){return this.abs().value===BigInt(1)},a.prototype.isZero=function(){return!1},i.prototype.isZero=function(){return 0===this.value},l.prototype.isZero=function(){return this.value===BigInt(0)},a.prototype.isDivisibleBy=function(r){var t=V(r);return!t.isZero()&&(!!t.isUnit()||(0===t.compareAbs(2)?this.isEven():this.mod(t).isZero()))},l.prototype.isDivisibleBy=i.prototype.isDivisibleBy=a.prototype.isDivisibleBy,a.prototype.isPrime=function(r){var t=S(this);if(void 0!==t)return t;var e=this.abs(),n=e.bitLength();if(n<=64)return _(e,[2,3,5,7,11,13,17,19,23,29,31,37]);for(var u=Math.log(2)*n.toJSNumber(),o=Math.ceil(!0===r?2*Math.pow(u,2):u),a=[],i=0;i<o;i++)a.push(s(i+2));return _(e,a)},l.prototype.isPrime=i.prototype.isPrime=a.prototype.isPrime,a.prototype.isProbablePrime=function(r,t){var e=S(this);if(void 0!==e)return e;for(var n=this.abs(),u=void 0===r?5:r,o=[],a=0;a<u;a++)o.push(s.randBetween(2,n.minus(2),t));return _(n,o)},l.prototype.isProbablePrime=i.prototype.isProbablePrime=a.prototype.isProbablePrime,a.prototype.modInv=function(r){for(var t,e,n,u=s.zero,o=s.one,a=V(r),i=this.abs();!i.isZero();)t=a.divide(i),e=u,n=a,u=o,a=i,o=e.subtract(t.multiply(o)),i=n.subtract(t.multiply(i));if(!a.isUnit())throw new Error(this.toString()+" and "+r.toString()+" are not co-prime");return-1===u.compare(0)&&(u=u.add(r)),this.isNegative()?u.negate():u},l.prototype.modInv=i.prototype.modInv=a.prototype.modInv,a.prototype.next=function(){var r=this.value;return this.sign?h(r,1,this.sign):new a(w(r,1),this.sign)},i.prototype.next=function(){var r=this.value;return r+1<e?new i(r+1):new a(n,!1)},l.prototype.next=function(){return new l(this.value+BigInt(1))},a.prototype.prev=function(){var r=this.value;return this.sign?new a(w(r,1),!0):h(r,1,this.sign)},i.prototype.prev=function(){var r=this.value;return r-1>-e?new i(r-1):new a(n,!0)},l.prototype.prev=function(){return new l(this.value-BigInt(1))};for(var g=[1];2*g[g.length-1]<=t;)g.push(2*g[g.length-1]);var x=g.length,U=g[x-1];function k(r){return Math.abs(r)<=t}function M(r,t,e){t=V(t);for(var n=r.isNegative(),u=t.isNegative(),o=n?r.not():r,a=u?t.not():t,i=0,l=0,c=null,f=null,b=[];!o.isZero()||!a.isZero();)i=(c=N(o,U))[1].toJSNumber(),n&&(i=U-1-i),l=(f=N(a,U))[1].toJSNumber(),u&&(l=U-1-l),o=c[0],a=f[0],b.push(e(i,l));for(var v=0!==e(n?1:0,u?1:0)?s(-1):s(0),p=b.length-1;p>=0;p-=1)v=v.multiply(U).add(s(b[p]));return v}a.prototype.shiftLeft=function(r){var t=V(r).toJSNumber();if(!k(t))throw new Error(String(t)+" is too large for shifting.");if(t<0)return this.shiftRight(-t);var e=this;if(e.isZero())return e;for(;t>=x;)e=e.multiply(U),t-=x-1;return e.multiply(g[t])},l.prototype.shiftLeft=i.prototype.shiftLeft=a.prototype.shiftLeft,a.prototype.shiftRight=function(r){var t,e=V(r).toJSNumber();if(!k(e))throw new Error(String(e)+" is too large for shifting.");if(e<0)return this.shiftLeft(-e);for(var n=this;e>=x;){if(n.isZero()||n.isNegative()&&n.isUnit())return n;n=(t=N(n,U))[1].isNegative()?t[0].prev():t[0],e-=x-1}return(t=N(n,g[e]))[1].isNegative()?t[0].prev():t[0]},l.prototype.shiftRight=i.prototype.shiftRight=a.prototype.shiftRight,a.prototype.not=function(){return this.negate().prev()},l.prototype.not=i.prototype.not=a.prototype.not,a.prototype.and=function(r){return M(this,r,(function(r,t){return r&t}))},l.prototype.and=i.prototype.and=a.prototype.and,a.prototype.or=function(r){return M(this,r,(function(r,t){return r|t}))},l.prototype.or=i.prototype.or=a.prototype.or,a.prototype.xor=function(r){return M(this,r,(function(r,t){return r^t}))},l.prototype.xor=i.prototype.xor=a.prototype.xor;function D(r){var e=r.value,n="number"==typeof e?e|1<<30:"bigint"==typeof e?e|BigInt(1<<30):e[0]+e[1]*t|1073758208;return n&-n}function j(r,t){return r=V(r),t=V(t),r.greater(t)?r:t}function $(r,t){return r=V(r),t=V(t),r.lesser(t)?r:t}function P(r,t){if(r=V(r).abs(),t=V(t).abs(),r.equals(t))return r;if(r.isZero())return t;if(t.isZero())return r;for(var e,n,s=o[1];r.isEven()&&t.isEven();)e=$(D(r),D(t)),r=r.divide(e),t=t.divide(e),s=s.multiply(e);for(;r.isEven();)r=r.divide(D(r));do{for(;t.isEven();)t=t.divide(D(t));r.greater(t)&&(n=t,t=r,r=n),t=t.subtract(r)}while(!t.isZero());return s.isUnit()?r:r.multiply(s)}a.prototype.bitLength=function(){var r=this;return r.compareTo(s(0))<0&&(r=r.negate().subtract(s(1))),0===r.compareTo(s(0))?s(0):s(function r(t,e){if(e.compareTo(t)<=0){var n=r(t,e.square(e)),u=n.p,o=n.e,a=u.multiply(e);return a.compareTo(t)<=0?{p:a,e:2*o+1}:{p:u,e:2*o}}return{p:s(1),e:0}}(r,s(2)).e).add(s(1))},l.prototype.bitLength=i.prototype.bitLength=a.prototype.bitLength;var G=function(r,t,e,n){e=e||"0123456789abcdefghijklmnopqrstuvwxyz",r=String(r),n||(r=r.toLowerCase(),e=e.toLowerCase());var s,u=r.length,o=Math.abs(t),a={};for(s=0;s<e.length;s++)a[e[s]]=s;for(s=0;s<u;s++){if("-"!==(c=r[s])&&(c in a&&a[c]>=o)){if("1"===c&&1===o)continue;throw new Error(c+" is not a valid digit in base "+t+".")}}t=V(t);var i=[],l="-"===r[0];for(s=l?1:0;s<r.length;s++){var c;if((c=r[s])in a)i.push(V(a[c]));else{if("<"!==c)throw new Error(c+" is not a valid character");var f=s;do{s++}while(">"!==r[s]&&s<r.length);i.push(V(r.slice(f+1,s)))}}return F(i,t,l)};function F(r,t,e){var n,s=o[0],u=o[1];for(n=r.length-1;n>=0;n--)s=s.add(r[n].times(u)),u=u.times(t);return e?s.negate():s}function H(r,t){if((t=s(t)).isZero()){if(r.isZero())return{value:[0],isNegative:!1};throw new Error("Cannot convert nonzero numbers to base 0.")}if(t.equals(-1)){if(r.isZero())return{value:[0],isNegative:!1};if(r.isNegative())return{value:[].concat.apply([],Array.apply(null,Array(-r.toJSNumber())).map(Array.prototype.valueOf,[1,0])),isNegative:!1};var e=Array.apply(null,Array(r.toJSNumber()-1)).map(Array.prototype.valueOf,[0,1]);return e.unshift([1]),{value:[].concat.apply([],e),isNegative:!1}}var n=!1;if(r.isNegative()&&t.isPositive()&&(n=!0,r=r.abs()),t.isUnit())return r.isZero()?{value:[0],isNegative:!1}:{value:Array.apply(null,Array(r.toJSNumber())).map(Number.prototype.valueOf,1),isNegative:n};for(var u,o=[],a=r;a.isNegative()||a.compareAbs(t)>=0;){u=a.divmod(t),a=u.quotient;var i=u.remainder;i.isNegative()&&(i=t.minus(i).abs(),a=a.next()),o.push(i.toJSNumber())}return o.push(a.toJSNumber()),{value:o.reverse(),isNegative:n}}function Y(r,t,e){var n=H(r,t);return(n.isNegative?"-":"")+n.value.map((function(r){return function(r,t){return r<(t=t||"0123456789abcdefghijklmnopqrstuvwxyz").length?t[r]:"<"+r+">"}(r,e)})).join("")}function B(r){if(c(+r)){var t=+r;if(t===L(t))return u?new l(BigInt(t)):new i(t);throw new Error("Invalid integer: "+r)}var e="-"===r[0];e&&(r=r.slice(1));var n=r.split(/e/i);if(n.length>2)throw new Error("Invalid integer: "+n.join("e"));if(2===n.length){var s=n[1];if("+"===s[0]&&(s=s.slice(1)),(s=+s)!==L(s)||!c(s))throw new Error("Invalid integer: "+s+" is not a valid exponent.");var o=n[0],f=o.indexOf(".");if(f>=0&&(s-=o.length-f-1,o=o.slice(0,f)+o.slice(f+1)),s<0)throw new Error("Cannot include negative exponent part for integers");r=o+=new Array(s+1).join("0")}if(!/^([0-9][0-9]*)$/.test(r))throw new Error("Invalid integer: "+r);if(u)return new l(BigInt(e?"-"+r:r));for(var b=[],p=r.length,C=p-7;p>0;)b.push(+r.slice(C,p)),(C-=7)<0&&(C=0),p-=7;return v(b),new a(b,e)}function V(r){return"number"==typeof r?function(r){if(u)return new l(BigInt(r));if(c(r)){if(r!==L(r))throw new Error(r+" is not an integer.");return new i(r)}return B(r.toString())}(r):"string"==typeof r?B(r):"bigint"==typeof r?new l(