Commit d1895b24 authored by Aurélien Vermylen's avatar Aurélien Vermylen

Make tests pass (except usual CryptStorage and stringify) and build.

parent 0e69426d
/*! jio v3.23.1 2017-11-03 */
/*! jio v3.23.1 2017-11-06 */
function parseStringToObject(a){var b=function(){var a,b,c=[],d=arguments;for(a=0;a<d.length;a+=1)for(b=0;b<d[a].length;b+=1)c.push(d[a][b]);return c},c=function(a,b,c){var d={type:"simple",key:a,value:b};return void 0!==c&&(d.operator=c),d},d=function(a){return"NOT"===a.operator?a.query_list[0]:{type:"complex",operator:"NOT",query_list:[a]}},e=function(a,c){var d,e=[];for(d=0;d<c.length;d+=1)c[d].operator===a?e=b(e,c[d].query_list):e.push(c[d]);return{type:"complex",operator:a,query_list:e}},f=function(a,b){var c;if("complex"===a.type){for(c=0;c<a.query_list.length;++c)f(a.query_list[c],b);return!0}return"simple"!==a.type||a.key?!1:(a.key=b,!0)},g=function(){function a(){this.yy={}}var b=function(a,b,c,d){for(c=c||{},d=a.length;d--;c[a[d]]=b);return c},g=[1,5],h=[1,7],i=[1,8],j=[1,10],k=[1,12],l=[1,6,7,15],m=[1,6,7,9,12,14,15,16,19,21],n=[1,6,7,9,11,12,14,15,16,19,21],o=[2,17],p={trace:function(){},yy:{},symbols_:{error:2,begin:3,search_text:4,end:5,EOF:6,NEWLINE:7,and_expression:8,OR:9,boolean_expression:10,AND:11,NOT:12,expression:13,LEFT_PARENTHESE:14,RIGHT_PARENTHESE:15,WORD:16,DEFINITION:17,value:18,OPERATOR:19,string:20,QUOTE:21,QUOTED_STRING:22,$accept:0,$end:1},terminals_:{2:"error",6:"EOF",7:"NEWLINE",9:"OR",11:"AND",12:"NOT",14:"LEFT_PARENTHESE",15:"RIGHT_PARENTHESE",16:"WORD",17:"DEFINITION",19:"OPERATOR",21:"QUOTE",22:"QUOTED_STRING"},productions_:[0,[3,2],[5,0],[5,1],[5,1],[4,1],[4,2],[4,3],[8,1],[8,3],[10,2],[10,1],[13,3],[13,3],[13,1],[18,2],[18,1],[20,1],[20,3]],performAction:function(a,b,g,h,i,j,k){var l=j.length-1;switch(i){case 1:return j[l-1];case 5:case 8:case 11:case 14:case 16:this.$=j[l];break;case 6:this.$=e("AND",[j[l-1],j[l]]);break;case 7:this.$=e("OR",[j[l-2],j[l]]);break;case 9:this.$=e("AND",[j[l-2],j[l]]);break;case 10:this.$=d(j[l]);break;case 12:this.$=j[l-1];break;case 13:f(j[l],j[l-2]),this.$=j[l];break;case 15:j[l].operator=j[l-1],this.$=j[l];break;case 17:this.$=c("",j[l]);break;case 18:this.$=c("",j[l-1])}},table:[{3:1,4:2,8:3,10:4,12:g,13:6,14:h,16:i,18:9,19:j,20:11,21:k},{1:[3]},{1:[2,2],5:13,6:[1,14],7:[1,15]},b(l,[2,5],{8:3,10:4,13:6,18:9,20:11,4:16,9:[1,17],12:g,14:h,16:i,19:j,21:k}),b(m,[2,8],{11:[1,18]}),{13:19,14:h,16:i,18:9,19:j,20:11,21:k},b(n,[2,11]),{4:20,8:3,10:4,12:g,13:6,14:h,16:i,18:9,19:j,20:11,21:k},b(n,o,{17:[1,21]}),b(n,[2,14]),{16:[1,23],20:22,21:k},b(n,[2,16]),{22:[1,24]},{1:[2,1]},{1:[2,3]},{1:[2,4]},b(l,[2,6]),{4:25,8:3,10:4,12:g,13:6,14:h,16:i,18:9,19:j,20:11,21:k},{8:26,10:4,12:g,13:6,14:h,16:i,18:9,19:j,20:11,21:k},b(n,[2,10]),{15:[1,27]},{13:28,14:h,16:i,18:9,19:j,20:11,21:k},b(n,[2,15]),b(n,o),{21:[1,29]},b(l,[2,7]),b(m,[2,9]),b(n,[2,12]),b(n,[2,13]),b(n,[2,18])],defaultActions:{13:[2,1],14:[2,3],15:[2,4]},parseError:function(a,b){function c(a,b){this.message=a,this.hash=b}if(!b.recoverable)throw c.prototype=new Error,new c(a,b);this.trace(a)},parse:function(a){var b=this,c=[0],d=[null],e=[],f=this.table,g="",h=0,i=0,j=0,k=2,l=1,m=e.slice.call(arguments,1),n=Object.create(this.lexer),o={yy:{}};for(var p in this.yy)Object.prototype.hasOwnProperty.call(this.yy,p)&&(o.yy[p]=this.yy[p]);n.setInput(a,o.yy),o.yy.lexer=n,o.yy.parser=this,"undefined"==typeof n.yylloc&&(n.yylloc={});var q=n.yylloc;e.push(q);var r=n.options&&n.options.ranges;"function"==typeof o.yy.parseError?this.parseError=o.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;for(var s,t,u,v,w,x,y,z,A,B=function(){var a;return a=n.lex()||l,"number"!=typeof a&&(a=b.symbols_[a]||a),a},C={};;){if(u=c[c.length-1],this.defaultActions[u]?v=this.defaultActions[u]:((null===s||"undefined"==typeof s)&&(s=B()),v=f[u]&&f[u][s]),"undefined"==typeof v||!v.length||!v[0]){var D="";A=[];for(x in f[u])this.terminals_[x]&&x>k&&A.push("'"+this.terminals_[x]+"'");D=n.showPosition?"Parse error on line "+(h+1)+":\n"+n.showPosition()+"\nExpecting "+A.join(", ")+", got '"+(this.terminals_[s]||s)+"'":"Parse error on line "+(h+1)+": Unexpected "+(s==l?"end of input":"'"+(this.terminals_[s]||s)+"'"),this.parseError(D,{text:n.match,token:this.terminals_[s]||s,line:n.yylineno,loc:q,expected:A})}if(v[0]instanceof Array&&v.length>1)throw new Error("Parse Error: multiple actions possible at state: "+u+", token: "+s);switch(v[0]){case 1:c.push(s),d.push(n.yytext),e.push(n.yylloc),c.push(v[1]),s=null,t?(s=t,t=null):(i=n.yyleng,g=n.yytext,h=n.yylineno,q=n.yylloc,j>0&&j--);break;case 2:if(y=this.productions_[v[1]][1],C.$=d[d.length-y],C._$={first_line:e[e.length-(y||1)].first_line,last_line:e[e.length-1].last_line,first_column:e[e.length-(y||1)].first_column,last_column:e[e.length-1].last_column},r&&(C._$.range=[e[e.length-(y||1)].range[0],e[e.length-1].range[1]]),w=this.performAction.apply(C,[g,i,h,o.yy,v[1],d,e].concat(m)),"undefined"!=typeof w)return w;y&&(c=c.slice(0,-1*y*2),d=d.slice(0,-1*y),e=e.slice(0,-1*y)),c.push(this.productions_[v[1]][0]),d.push(C.$),e.push(C._$),z=f[c[c.length-2]][c[c.length-1]],c.push(z);break;case 3:return!0}}return!0}},q=function(){var a={EOF:1,parseError:function(a,b){if(!this.yy.parser)throw new Error(a);this.yy.parser.parseError(a,b)},setInput:function(a,b){return this.yy=b||this.yy||{},this._input=a,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var a=this._input[0];this.yytext+=a,this.yyleng++,this.offset++,this.match+=a,this.matched+=a;var b=a.match(/(?:\r\n?|\n).*/g);return b?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),a},unput:function(a){var b=a.length,c=a.split(/(?:\r\n?|\n)/g);this._input=a+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-b),this.offset-=b;var d=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),c.length-1&&(this.yylineno-=c.length-1);var e=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:c?(c.length===d.length?this.yylloc.first_column:0)+d[d.length-c.length].length-c[0].length:this.yylloc.first_column-b},this.options.ranges&&(this.yylloc.range=[e[0],e[0]+this.yyleng-b]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){return this.options.backtrack_lexer?(this._backtrack=!0,this):this.parseError("Lexical error on line "+(this.yylineno+1)+". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},less:function(a){this.unput(this.match.slice(a))},pastInput:function(){var a=this.matched.substr(0,this.matched.length-this.match.length);return(a.length>20?"...":"")+a.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var a=this.match;return a.length<20&&(a+=this._input.substr(0,20-a.length)),(a.substr(0,20)+(a.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var a=this.pastInput(),b=new Array(a.length+1).join("-");return a+this.upcomingInput()+"\n"+b+"^"},test_match:function(a,b){var c,d,e;if(this.options.backtrack_lexer&&(e={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(e.yylloc.range=this.yylloc.range.slice(0))),d=a[0].match(/(?:\r\n?|\n).*/g),d&&(this.yylineno+=d.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:d?d[d.length-1].length-d[d.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+a[0].length},this.yytext+=a[0],this.match+=a[0],this.matches=a,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(a[0].length),this.matched+=a[0],c=this.performAction.call(this,this.yy,this,b,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),c)return c;if(this._backtrack){for(var f in e)this[f]=e[f];return!1}return!1},next:function(){if(this.done)return this.EOF;this._input||(this.done=!0);var a,b,c,d;this._more||(this.yytext="",this.match="");for(var e=this._currentRules(),f=0;f<e.length;f++)if(c=this._input.match(this.rules[e[f]]),c&&(!b||c[0].length>b[0].length)){if(b=c,d=f,this.options.backtrack_lexer){if(a=this.test_match(c,e[f]),a!==!1)return a;if(this._backtrack){b=!1;continue}return!1}if(!this.options.flex)break}return b?(a=this.test_match(b,e[d]),a!==!1?a:!1):""===this._input?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){var a=this.next();return a?a:this.lex()},begin:function(a){this.conditionStack.push(a)},popState:function(){var a=this.conditionStack.length-1;return a>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(a){return a=this.conditionStack.length-1-Math.abs(a||0),a>=0?this.conditionStack[a]:"INITIAL"},pushState:function(a){this.begin(a)},stateStackSize:function(){return this.conditionStack.length},options:{},performAction:function(a,b,c,d){switch(c){case 0:return this.begin("letsquote"),"QUOTE";case 1:return this.popState(),this.begin("endquote"),"QUOTED_STRING";case 2:return this.popState(),"QUOTE";case 3:break;case 4:return"LEFT_PARENTHESE";case 5:return"RIGHT_PARENTHESE";case 6:return"AND";case 7:return"OR";case 8:return"NOT";case 9:return"DEFINITION";case 10:return 19;case 11:return 16;case 12:return 6}},rules:[/^(?:")/,/^(?:(\\"|[^"])*)/,/^(?:")/,/^(?:[^\S]+)/,/^(?:\()/,/^(?:\))/,/^(?:AND\b)/,/^(?:OR\b)/,/^(?:NOT\b)/,/^(?::)/,/^(?:(!?=|<=?|>=?))/,/^(?:[^\s\n"():><!=]+)/,/^(?:$)/],conditions:{endquote:{rules:[2],inclusive:!1},letsquote:{rules:[1],inclusive:!1},INITIAL:{rules:[0,3,4,5,6,7,8,9,10,11,12],inclusive:!0}}};return a}();return p.lexer=q,a.prototype=p,p.Parser=a,new a}();return g.parse(a)}!function(a,b){"object"==typeof exports?module.exports=b():"function"==typeof define&&define.amd?define(b):a.IPv6=b(a)}(this,function(a){var b=a&&a.IPv6;return{best:function(a){a=a.toLowerCase().split(":");var b=a.length,c=8;""===a[0]&&""===a[1]&&""===a[2]?(a.shift(),a.shift()):""===a[0]&&""===a[1]?a.shift():""===a[b-1]&&""===a[b-2]&&a.pop(),b=a.length,-1!==a[b-1].indexOf(".")&&(c=7);var d;for(d=0;b>d&&""!==a[d];d++);if(c>d)for(a.splice(d,1,"0000");a.length<c;)a.splice(d,0,"0000");for(d=0;c>d;d++){for(var b=a[d].split(""),e=0;3>e&&("0"===b[0]&&1<b.length);e++)b.splice(0,1);a[d]=b.join("")}var b=-1,f=e=0,g=-1,h=!1;for(d=0;c>d;d++)h?"0"===a[d]?f+=1:(h=!1,f>e&&(b=g,e=f)):"0"==a[d]&&(h=!0,g=d,f=1);for(f>e&&(b=g,e=f),e>1&&a.splice(b,e,""),b=a.length,c="",""===a[0]&&(beststr=":"),d=0;b>d&&(c+=a[d],d!==b-1);d++)c+=":";return""===a[b-1]&&(c+=":"),c},noConflict:function(){return a.IPv6===this&&(a.IPv6=b),this}}}),function(a){function b(a){throw RangeError(B[a])}function c(a,b){for(var c=a.length;c--;)a[c]=b(a[c]);return a}function d(a,b){return c(a.split(A),b).join(".")}function e(a){for(var b,c,d=[],e=0,f=a.length;f>e;)b=a.charCodeAt(e++),b>=55296&&56319>=b&&f>e?(c=a.charCodeAt(e++),56320==(64512&c)?d.push(((1023&b)<<10)+(1023&c)+65536):(d.push(b),e--)):d.push(b);return d}function f(a){return c(a,function(a){var b="";return a>65535&&(a-=65536,b+=E(a>>>10&1023|55296),a=56320|1023&a),b+=E(a)}).join("")}function g(a,b){return a+22+75*(26>a)-((0!=b)<<5)}function h(a,b,c){var d=0;for(a=c?D(a/u):a>>1,a+=D(a/b);a>C*s>>1;d+=q)a=D(a/C);return D(d+(C+1)*a/(a+t))}function i(a){var c,d,e,g,i,j,k=[],l=a.length,m=0,n=w,o=v;for(d=a.lastIndexOf(x),0>d&&(d=0),e=0;d>e;++e)128<=a.charCodeAt(e)&&b("not-basic"),k.push(a.charCodeAt(e));for(d=d>0?d+1:0;l>d;){for(e=m,c=1,g=q;d>=l&&b("invalid-input"),i=a.charCodeAt(d++),i=10>i-48?i-22:26>i-65?i-65:26>i-97?i-97:q,(i>=q||i>D((p-m)/c))&&b("overflow"),m+=i*c,j=o>=g?r:g>=o+s?s:g-o,!(j>i);g+=q)i=q-j,c>D(p/i)&&b("overflow"),c*=i;c=k.length+1,o=h(m-e,c,0==e),D(m/c)>p-n&&b("overflow"),n+=D(m/c),m%=c,k.splice(m++,0,n)}return f(k)}function j(a){var c,d,f,i,j,k,l,m,n,o,t,u,y=[];for(a=e(a),o=a.length,c=w,d=0,j=v,k=0;o>k;++k)n=a[k],128>n&&y.push(E(n));for((f=i=y.length)&&y.push(x);o>f;){for(l=p,k=0;o>k;++k)n=a[k],n>=c&&l>n&&(l=n);for(t=f+1,l-c>D((p-d)/t)&&b("overflow"),d+=(l-c)*t,c=l,k=0;o>k;++k)if(n=a[k],c>n&&++d>p&&b("overflow"),n==c){for(m=d,l=q;n=j>=l?r:l>=j+s?s:l-j,!(n>m);l+=q)u=m-n,m=q-n,y.push(E(g(n+u%m,0))),m=D(u/m);y.push(E(g(m,0))),j=h(d,t,f==i),d=0,++f}++d,++c}return y.join("")}var k="object"==typeof exports&&exports,l="object"==typeof module&&module&&module.exports==k&&module,m="object"==typeof global&&global;(m.global===m||m.window===m)&&(a=m);var n,o,p=2147483647,q=36,r=1,s=26,t=38,u=700,v=72,w=128,x="-",y=/^xn--/,z=/[^ -~]/,A=/\x2E|\u3002|\uFF0E|\uFF61/g,B={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},C=q-r,D=Math.floor,E=String.fromCharCode;if(n={version:"1.2.3",ucs2:{decode:e,encode:f},decode:i,encode:j,toASCII:function(a){return d(a,function(a){return z.test(a)?"xn--"+j(a):a})},toUnicode:function(a){return d(a,function(a){return y.test(a)?i(a.slice(4).toLowerCase()):a})}},"function"==typeof define&&"object"==typeof define.amd&&define.amd)define(function(){return n});else if(k&&!k.nodeType)if(l)l.exports=n;else for(o in n)n.hasOwnProperty(o)&&(k[o]=n[o]);else a.punycode=n}(this),function(a,b){"object"==typeof exports?module.exports=b():"function"==typeof define&&define.amd?define(b):a.SecondLevelDomains=b(a)}(this,function(a){var b=a&&a.SecondLevelDomains,c=Object.prototype.hasOwnProperty,d={list:{ac:"com|gov|mil|net|org",ae:"ac|co|gov|mil|name|net|org|pro|sch",af:"com|edu|gov|net|org",al:"com|edu|gov|mil|net|org",ao:"co|ed|gv|it|og|pb",ar:"com|edu|gob|gov|int|mil|net|org|tur",at:"ac|co|gv|or",au:"asn|com|csiro|edu|gov|id|net|org",ba:"co|com|edu|gov|mil|net|org|rs|unbi|unmo|unsa|untz|unze",bb:"biz|co|com|edu|gov|info|net|org|store|tv",bh:"biz|cc|com|edu|gov|info|net|org",bn:"com|edu|gov|net|org",bo:"com|edu|gob|gov|int|mil|net|org|tv",br:"adm|adv|agr|am|arq|art|ato|b|bio|blog|bmd|cim|cng|cnt|com|coop|ecn|edu|eng|esp|etc|eti|far|flog|fm|fnd|fot|fst|g12|ggf|gov|imb|ind|inf|jor|jus|lel|mat|med|mil|mus|net|nom|not|ntr|odo|org|ppg|pro|psc|psi|qsl|rec|slg|srv|tmp|trd|tur|tv|vet|vlog|wiki|zlg",bs:"com|edu|gov|net|org",bz:"du|et|om|ov|rg",ca:"ab|bc|mb|nb|nf|nl|ns|nt|nu|on|pe|qc|sk|yk",ck:"biz|co|edu|gen|gov|info|net|org",cn:"ac|ah|bj|com|cq|edu|fj|gd|gov|gs|gx|gz|ha|hb|he|hi|hl|hn|jl|js|jx|ln|mil|net|nm|nx|org|qh|sc|sd|sh|sn|sx|tj|tw|xj|xz|yn|zj",co:"com|edu|gov|mil|net|nom|org",cr:"ac|c|co|ed|fi|go|or|sa",cy:"ac|biz|com|ekloges|gov|ltd|name|net|org|parliament|press|pro|tm","do":"art|com|edu|gob|gov|mil|net|org|sld|web",dz:"art|asso|com|edu|gov|net|org|pol",ec:"com|edu|fin|gov|info|med|mil|net|org|pro",eg:"com|edu|eun|gov|mil|name|net|org|sci",er:"com|edu|gov|ind|mil|net|org|rochest|w",es:"com|edu|gob|nom|org",et:"biz|com|edu|gov|info|name|net|org",fj:"ac|biz|com|info|mil|name|net|org|pro",fk:"ac|co|gov|net|nom|org",fr:"asso|com|f|gouv|nom|prd|presse|tm",gg:"co|net|org",gh:"com|edu|gov|mil|org",gn:"ac|com|gov|net|org",gr:"com|edu|gov|mil|net|org",gt:"com|edu|gob|ind|mil|net|org",gu:"com|edu|gov|net|org",hk:"com|edu|gov|idv|net|org",id:"ac|co|go|mil|net|or|sch|web",il:"ac|co|gov|idf|k12|muni|net|org","in":"ac|co|edu|ernet|firm|gen|gov|i|ind|mil|net|nic|org|res",iq:"com|edu|gov|i|mil|net|org",ir:"ac|co|dnssec|gov|i|id|net|org|sch",it:"edu|gov",je:"co|net|org",jo:"com|edu|gov|mil|name|net|org|sch",jp:"ac|ad|co|ed|go|gr|lg|ne|or",ke:"ac|co|go|info|me|mobi|ne|or|sc",kh:"com|edu|gov|mil|net|org|per",ki:"biz|com|de|edu|gov|info|mob|net|org|tel",km:"asso|com|coop|edu|gouv|k|medecin|mil|nom|notaires|pharmaciens|presse|tm|veterinaire",kn:"edu|gov|net|org",kr:"ac|busan|chungbuk|chungnam|co|daegu|daejeon|es|gangwon|go|gwangju|gyeongbuk|gyeonggi|gyeongnam|hs|incheon|jeju|jeonbuk|jeonnam|k|kg|mil|ms|ne|or|pe|re|sc|seoul|ulsan",kw:"com|edu|gov|net|org",ky:"com|edu|gov|net|org",kz:"com|edu|gov|mil|net|org",lb:"com|edu|gov|net|org",lk:"assn|com|edu|gov|grp|hotel|int|ltd|net|ngo|org|sch|soc|web",lr:"com|edu|gov|net|org",lv:"asn|com|conf|edu|gov|id|mil|net|org",ly:"com|edu|gov|id|med|net|org|plc|sch",ma:"ac|co|gov|m|net|org|press",mc:"asso|tm",me:"ac|co|edu|gov|its|net|org|priv",mg:"com|edu|gov|mil|nom|org|prd|tm",mk:"com|edu|gov|inf|name|net|org|pro",ml:"com|edu|gov|net|org|presse",mn:"edu|gov|org",mo:"com|edu|gov|net|org",mt:"com|edu|gov|net|org",mv:"aero|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro",mw:"ac|co|com|coop|edu|gov|int|museum|net|org",mx:"com|edu|gob|net|org",my:"com|edu|gov|mil|name|net|org|sch",nf:"arts|com|firm|info|net|other|per|rec|store|web",ng:"biz|com|edu|gov|mil|mobi|name|net|org|sch",ni:"ac|co|com|edu|gob|mil|net|nom|org",np:"com|edu|gov|mil|net|org",nr:"biz|com|edu|gov|info|net|org",om:"ac|biz|co|com|edu|gov|med|mil|museum|net|org|pro|sch",pe:"com|edu|gob|mil|net|nom|org|sld",ph:"com|edu|gov|i|mil|net|ngo|org",pk:"biz|com|edu|fam|gob|gok|gon|gop|gos|gov|net|org|web",pl:"art|bialystok|biz|com|edu|gda|gdansk|gorzow|gov|info|katowice|krakow|lodz|lublin|mil|net|ngo|olsztyn|org|poznan|pwr|radom|slupsk|szczecin|torun|warszawa|waw|wroc|wroclaw|zgora",pr:"ac|biz|com|edu|est|gov|info|isla|name|net|org|pro|prof",ps:"com|edu|gov|net|org|plo|sec",pw:"belau|co|ed|go|ne|or",ro:"arts|com|firm|info|nom|nt|org|rec|store|tm|www",rs:"ac|co|edu|gov|in|org",sb:"com|edu|gov|net|org",sc:"com|edu|gov|net|org",sh:"co|com|edu|gov|net|nom|org",sl:"com|edu|gov|net|org",st:"co|com|consulado|edu|embaixada|gov|mil|net|org|principe|saotome|store",sv:"com|edu|gob|org|red",sz:"ac|co|org",tr:"av|bbs|bel|biz|com|dr|edu|gen|gov|info|k12|name|net|org|pol|tel|tsk|tv|web",tt:"aero|biz|cat|co|com|coop|edu|gov|info|int|jobs|mil|mobi|museum|name|net|org|pro|tel|travel",tw:"club|com|ebiz|edu|game|gov|idv|mil|net|org",mu:"ac|co|com|gov|net|or|org",mz:"ac|co|edu|gov|org",na:"co|com",nz:"ac|co|cri|geek|gen|govt|health|iwi|maori|mil|net|org|parliament|school",pa:"abo|ac|com|edu|gob|ing|med|net|nom|org|sld",pt:"com|edu|gov|int|net|nome|org|publ",py:"com|edu|gov|mil|net|org",qa:"com|edu|gov|mil|net|org",re:"asso|com|nom",ru:"ac|adygeya|altai|amur|arkhangelsk|astrakhan|bashkiria|belgorod|bir|bryansk|buryatia|cbg|chel|chelyabinsk|chita|chukotka|chuvashia|com|dagestan|e-burg|edu|gov|grozny|int|irkutsk|ivanovo|izhevsk|jar|joshkar-ola|kalmykia|kaluga|kamchatka|karelia|kazan|kchr|kemerovo|khabarovsk|khakassia|khv|kirov|koenig|komi|kostroma|kranoyarsk|kuban|kurgan|kursk|lipetsk|magadan|mari|mari-el|marine|mil|mordovia|mosreg|msk|murmansk|nalchik|net|nnov|nov|novosibirsk|nsk|omsk|orenburg|org|oryol|penza|perm|pp|pskov|ptz|rnd|ryazan|sakhalin|samara|saratov|simbirsk|smolensk|spb|stavropol|stv|surgut|tambov|tatarstan|tom|tomsk|tsaritsyn|tsk|tula|tuva|tver|tyumen|udm|udmurtia|ulan-ude|vladikavkaz|vladimir|vladivostok|volgograd|vologda|voronezh|vrn|vyatka|yakutia|yamal|yekaterinburg|yuzhno-sakhalinsk",rw:"ac|co|com|edu|gouv|gov|int|mil|net",sa:"com|edu|gov|med|net|org|pub|sch",sd:"com|edu|gov|info|med|net|org|tv",se:"a|ac|b|bd|c|d|e|f|g|h|i|k|l|m|n|o|org|p|parti|pp|press|r|s|t|tm|u|w|x|y|z",sg:"com|edu|gov|idn|net|org|per",sn:"art|com|edu|gouv|org|perso|univ",sy:"com|edu|gov|mil|net|news|org",th:"ac|co|go|in|mi|net|or",tj:"ac|biz|co|com|edu|go|gov|info|int|mil|name|net|nic|org|test|web",tn:"agrinet|com|defense|edunet|ens|fin|gov|ind|info|intl|mincom|nat|net|org|perso|rnrt|rns|rnu|tourism",tz:"ac|co|go|ne|or",ua:"biz|cherkassy|chernigov|chernovtsy|ck|cn|co|com|crimea|cv|dn|dnepropetrovsk|donetsk|dp|edu|gov|if|in|ivano-frankivsk|kh|kharkov|kherson|khmelnitskiy|kiev|kirovograd|km|kr|ks|kv|lg|lugansk|lutsk|lviv|me|mk|net|nikolaev|od|odessa|org|pl|poltava|pp|rovno|rv|sebastopol|sumy|te|ternopil|uzhgorod|vinnica|vn|zaporizhzhe|zhitomir|zp|zt",ug:"ac|co|go|ne|or|org|sc",uk:"ac|bl|british-library|co|cym|gov|govt|icnet|jet|lea|ltd|me|mil|mod|national-library-scotland|nel|net|nhs|nic|nls|org|orgn|parliament|plc|police|sch|scot|soc",us:"dni|fed|isa|kids|nsn",uy:"com|edu|gub|mil|net|org",ve:"co|com|edu|gob|info|mil|net|org|web",vi:"co|com|k12|net|org",vn:"ac|biz|com|edu|gov|health|info|int|name|net|org|pro",ye:"co|com|gov|ltd|me|net|org|plc",yu:"ac|co|edu|gov|org",za:"ac|agric|alt|bourse|city|co|cybernet|db|edu|gov|grondar|iaccess|imt|inca|landesign|law|mil|net|ngo|nis|nom|olivetti|org|pix|school|tm|web",zm:"ac|co|com|edu|gov|net|org|sch"},has_expression:null,is_expression:null,has:function(a){return!!a.match(d.has_expression)},is:function(a){return!!a.match(d.is_expression)},get:function(a){return(a=a.match(d.has_expression))&&a[1]||null},noConflict:function(){return a.SecondLevelDomains===this&&(a.SecondLevelDomains=b),this},init:function(){var a,b="";for(a in d.list)c.call(d.list,a)&&(b+="|("+("("+d.list[a]+")."+a)+")");d.has_expression=RegExp("\\.("+b.substr(1)+")$","i"),d.is_expression=RegExp("^("+b.substr(1)+")$","i")}};return d.init(),d}),function(a,b){"object"==typeof exports?module.exports=b(require("./punycode"),require("./IPv6"),require("./SecondLevelDomains")):"function"==typeof define&&define.amd?define(["./punycode","./IPv6","./SecondLevelDomains"],b):a.URI=b(a.punycode,a.IPv6,a.SecondLevelDomains,a)}(this,function(a,b,c,d){function e(a,b){return this instanceof e?(void 0===a&&(a="undefined"!=typeof location?location.href+"":""),this.href(a),void 0!==b?this.absoluteTo(b):this):new e(a,b)}function f(a){return a.replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")}function g(a){return void 0===a?"Undefined":String(Object.prototype.toString.call(a)).slice(8,-1)}function h(a){return"Array"===g(a)}function i(a,b){var c,d;if(h(b)){for(c=0,d=b.length;d>c;c++)if(!i(a,b[c]))return!1;return!0}var e=g(b);for(c=0,d=a.length;d>c;c++)if("RegExp"===e){if("string"==typeof a[c]&&a[c].match(b))return!0}else if(a[c]===b)return!0;return!1}function j(a,b){if(!h(a)||!h(b)||a.length!==b.length)return!1;a.sort(),b.sort();for(var c=0,d=a.length;d>c;c++)if(a[c]!==b[c])return!1;return!0}function k(a){return escape(a)}function l(a){return encodeURIComponent(a).replace(/[!'()*]/g,k).replace(/\*/g,"%2A")}var m=d&&d.URI;e.version="1.12.0";var n=e.prototype,o=Object.prototype.hasOwnProperty;e._parts=function(){return{protocol:null,username:null,password:null,hostname:null,urn:null,port:null,path:null,query:null,fragment:null,duplicateQueryParameters:e.duplicateQueryParameters,escapeQuerySpace:e.escapeQuerySpace}},e.duplicateQueryParameters=!1,e.escapeQuerySpace=!0,e.protocol_expression=/^[a-z][a-z0-9.+-]*$/i,e.idn_expression=/[^a-z0-9\.-]/i,e.punycode_expression=/(xn--)/i,e.ip4_expression=/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/,e.ip6_expression=/^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$/,e.find_uri_expression=/\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?\u00ab\u00bb\u201c\u201d\u2018\u2019]))/gi,e.findUri={start:/\b(?:([a-z][a-z0-9.+-]*:\/\/)|www\.)/gi,end:/[\s\r\n]|$/,trim:/[`!()\[\]{};:'".,<>?\u00ab\u00bb\u201c\u201d\u201e\u2018\u2019]+$/},e.defaultPorts={http:"80",https:"443",ftp:"21",gopher:"70",ws:"80",wss:"443"},e.invalid_hostname_characters=/[^a-zA-Z0-9\.-]/,e.domAttributes={a:"href",blockquote:"cite",link:"href",base:"href",script:"src",form:"action",img:"src",area:"href",iframe:"src",embed:"src",source:"src",track:"src",input:"src"},e.getDomAttribute=function(a){if(a&&a.nodeName){var b=a.nodeName.toLowerCase();return"input"===b&&"image"!==a.type?void 0:e.domAttributes[b]}},e.encode=l,e.decode=decodeURIComponent,e.iso8859=function(){e.encode=escape,e.decode=unescape},e.unicode=function(){e.encode=l,e.decode=decodeURIComponent},e.characters={pathname:{encode:{expression:/%(24|26|2B|2C|3B|3D|3A|40)/gi,map:{"%24":"$","%26":"&","%2B":"+","%2C":",","%3B":";","%3D":"=","%3A":":","%40":"@"}},decode:{expression:/[\/\?#]/g,map:{"/":"%2F","?":"%3F","#":"%23"}}},reserved:{encode:{expression:/%(21|23|24|26|27|28|29|2A|2B|2C|2F|3A|3B|3D|3F|40|5B|5D)/gi,map:{"%3A":":","%2F":"/","%3F":"?","%23":"#","%5B":"[","%5D":"]","%40":"@","%21":"!","%24":"$","%26":"&","%27":"'","%28":"(","%29":")","%2A":"*","%2B":"+","%2C":",","%3B":";","%3D":"="}}}},e.encodeQuery=function(a,b){var c=e.encode(a+"");return b?c.replace(/%20/g,"+"):c},e.decodeQuery=function(a,b){a+="";try{return e.decode(b?a.replace(/\+/g,"%20"):a)}catch(c){return a}},e.recodePath=function(a){a=(a+"").split("/");for(var b=0,c=a.length;c>b;b++)a[b]=e.encodePathSegment(e.decode(a[b]));return a.join("/")},e.decodePath=function(a){a=(a+"").split("/");for(var b=0,c=a.length;c>b;b++)a[b]=e.decodePathSegment(a[b]);return a.join("/")};var p,q={encode:"encode",decode:"decode"},r=function(a,b){return function(c){return e[b](c+"").replace(e.characters[a][b].expression,function(c){return e.characters[a][b].map[c]})}};for(p in q)e[p+"PathSegment"]=r("pathname",q[p]);e.encodeReserved=r("reserved","encode"),e.parse=function(a,b){var c;return b||(b={}),c=a.indexOf("#"),c>-1&&(b.fragment=a.substring(c+1)||null,a=a.substring(0,c)),c=a.indexOf("?"),c>-1&&(b.query=a.substring(c+1)||null,a=a.substring(0,c)),"//"===a.substring(0,2)?(b.protocol=null,a=a.substring(2),a=e.parseAuthority(a,b)):(c=a.indexOf(":"),c>-1&&(b.protocol=a.substring(0,c)||null,b.protocol&&!b.protocol.match(e.protocol_expression)?b.protocol=void 0:"file"===b.protocol?a=a.substring(c+3):"//"===a.substring(c+1,c+3)?(a=a.substring(c+3),a=e.parseAuthority(a,b)):(a=a.substring(c+1),b.urn=!0))),b.path=a,b},e.parseHost=function(a,b){var c,d=a.indexOf("/");return-1===d&&(d=a.length),"["===a.charAt(0)?(c=a.indexOf("]"),b.hostname=a.substring(1,c)||null,b.port=a.substring(c+2,d)||null):a.indexOf(":")!==a.lastIndexOf(":")?(b.hostname=a.substring(0,d)||null,b.port=null):(c=a.substring(0,d).split(":"),b.hostname=c[0]||null,b.port=c[1]||null),b.hostname&&"/"!==a.substring(d).charAt(0)&&(d++,a="/"+a),a.substring(d)||"/"},e.parseAuthority=function(a,b){return a=e.parseUserinfo(a,b),e.parseHost(a,b)},e.parseUserinfo=function(a,b){var c=a.indexOf("/"),d=c>-1?a.lastIndexOf("@",c):a.indexOf("@");return d>-1&&(-1===c||c>d)?(c=a.substring(0,d).split(":"),b.username=c[0]?e.decode(c[0]):null,c.shift(),b.password=c[0]?e.decode(c.join(":")):null,a=a.substring(d+1)):(b.username=null,b.password=null),a},e.parseQuery=function(a,b){if(!a)return{};if(a=a.replace(/&+/g,"&").replace(/^\?*&*|&+$/g,""),!a)return{};for(var c,d,f={},g=a.split("&"),h=g.length,i=0;h>i;i++)c=g[i].split("="),d=e.decodeQuery(c.shift(),b),c=c.length?e.decodeQuery(c.join("="),b):null,f[d]?("string"==typeof f[d]&&(f[d]=[f[d]]),f[d].push(c)):f[d]=c;return f},e.build=function(a){var b="";return a.protocol&&(b+=a.protocol+":"),a.urn||!b&&!a.hostname||(b+="//"),b+=e.buildAuthority(a)||"","string"==typeof a.path&&("/"!==a.path.charAt(0)&&"string"==typeof a.hostname&&(b+="/"),b+=a.path),"string"==typeof a.query&&a.query&&(b+="?"+a.query),"string"==typeof a.fragment&&a.fragment&&(b+="#"+a.fragment),b},e.buildHost=function(a){var b="";return a.hostname?(e.ip6_expression.test(a.hostname)?b=a.port?b+("["+a.hostname+"]:"+a.port):b+a.hostname:(b+=a.hostname,a.port&&(b+=":"+a.port)),b):""},e.buildAuthority=function(a){return e.buildUserinfo(a)+e.buildHost(a)},e.buildUserinfo=function(a){var b="";return a.username&&(b+=e.encode(a.username),a.password&&(b+=":"+e.encode(a.password)),b+="@"),b},e.buildQuery=function(a,b,c){var d,f,g,i,j="";for(f in a)if(o.call(a,f)&&f)if(h(a[f]))for(d={},g=0,i=a[f].length;i>g;g++)void 0!==a[f][g]&&void 0===d[a[f][g]+""]&&(j+="&"+e.buildQueryParameter(f,a[f][g],c),!0!==b&&(d[a[f][g]+""]=!0));else void 0!==a[f]&&(j+="&"+e.buildQueryParameter(f,a[f],c));return j.substring(1)},e.buildQueryParameter=function(a,b,c){return e.encodeQuery(a,c)+(null!==b?"="+e.encodeQuery(b,c):"")},e.addQuery=function(a,b,c){if("object"==typeof b)for(var d in b)o.call(b,d)&&e.addQuery(a,d,b[d]);else{if("string"!=typeof b)throw new TypeError("URI.addQuery() accepts an object, string as the name parameter");void 0===a[b]?a[b]=c:("string"==typeof a[b]&&(a[b]=[a[b]]),h(c)||(c=[c]),a[b]=a[b].concat(c))}},e.removeQuery=function(a,b,c){var d;if(h(b))for(c=0,d=b.length;d>c;c++)a[b[c]]=void 0;else if("object"==typeof b)for(d in b)o.call(b,d)&&e.removeQuery(a,d,b[d]);else{if("string"!=typeof b)throw new TypeError("URI.addQuery() accepts an object, string as the first parameter");if(void 0!==c){if(a[b]===c)a[b]=void 0;else if(h(a[b])){d=a[b];var f,g,i={};if(h(c))for(f=0,g=c.length;g>f;f++)i[c[f]]=!0;else i[c]=!0;for(f=0,g=d.length;g>f;f++)void 0!==i[d[f]]&&(d.splice(f,1),g--,f--);a[b]=d}}else a[b]=void 0}},e.hasQuery=function(a,b,c,d){if("object"==typeof b){for(var f in b)if(o.call(b,f)&&!e.hasQuery(a,f,b[f]))return!1;return!0}if("string"!=typeof b)throw new TypeError("URI.hasQuery() accepts an object, string as the name parameter");switch(g(c)){case"Undefined":return b in a;case"Boolean":return a=Boolean(h(a[b])?a[b].length:a[b]),c===a;case"Function":return!!c(a[b],b,a);case"Array":return h(a[b])?(d?i:j)(a[b],c):!1;case"RegExp":return h(a[b])?d?i(a[b],c):!1:Boolean(a[b]&&a[b].match(c));case"Number":c=String(c);case"String":return h(a[b])?d?i(a[b],c):!1:a[b]===c;default:throw new TypeError("URI.hasQuery() accepts undefined, boolean, string, number, RegExp, Function as the value parameter")}},e.commonPath=function(a,b){var c,d=Math.min(a.length,b.length);for(c=0;d>c;c++)if(a.charAt(c)!==b.charAt(c)){c--;break}return 1>c?a.charAt(0)===b.charAt(0)&&"/"===a.charAt(0)?"/":"":(("/"!==a.charAt(c)||"/"!==b.charAt(c))&&(c=a.substring(0,c).lastIndexOf("/")),a.substring(0,c+1))},e.withinString=function(a,b,c){c||(c={});var d=c.start||e.findUri.start,f=c.end||e.findUri.end,g=c.trim||e.findUri.trim,h=/[a-z0-9-]=["']?$/i;for(d.lastIndex=0;;){var i=d.exec(a);if(!i)break;if(i=i.index,c.ignoreHtml){var j=a.slice(Math.max(i-3,0),i);if(j&&h.test(j))continue}var j=i+a.slice(i).search(f),k=a.slice(i,j).replace(g,"");c.ignore&&c.ignore.test(k)||(j=i+k.length,k=b(k,i,j,a),a=a.slice(0,i)+k+a.slice(j),d.lastIndex=i+k.length)}return d.lastIndex=0,a},e.ensureValidHostname=function(b){if(b.match(e.invalid_hostname_characters)){if(!a)throw new TypeError("Hostname '"+b+"' contains characters other than [A-Z0-9.-] and Punycode.js is not available");
if(a.toASCII(b).match(e.invalid_hostname_characters))throw new TypeError("Hostname '"+b+"' contains characters other than [A-Z0-9.-]")}},e.noConflict=function(a){return a?(a={URI:this.noConflict()},URITemplate&&"function"==typeof URITemplate.noConflict&&(a.URITemplate=URITemplate.noConflict()),b&&"function"==typeof b.noConflict&&(a.IPv6=b.noConflict()),SecondLevelDomains&&"function"==typeof SecondLevelDomains.noConflict&&(a.SecondLevelDomains=SecondLevelDomains.noConflict()),a):(d.URI===this&&(d.URI=m),this)},n.build=function(a){return!0===a?this._deferred_build=!0:(void 0===a||this._deferred_build)&&(this._string=e.build(this._parts),this._deferred_build=!1),this},n.clone=function(){return new e(this)},n.valueOf=n.toString=function(){return this.build(!1)._string},q={protocol:"protocol",username:"username",password:"password",hostname:"hostname",port:"port"},r=function(a){return function(b,c){return void 0===b?this._parts[a]||"":(this._parts[a]=b||null,this.build(!c),this)}};for(p in q)n[p]=r(q[p]);q={query:"?",fragment:"#"},r=function(a,b){return function(c,d){return void 0===c?this._parts[a]||"":(null!==c&&(c+="",c.charAt(0)===b&&(c=c.substring(1))),this._parts[a]=c,this.build(!d),this)}};for(p in q)n[p]=r(p,q[p]);q={search:["?","query"],hash:["#","fragment"]},r=function(a,b){return function(c,d){var e=this[a](c,d);return"string"==typeof e&&e.length?b+e:e}};for(p in q)n[p]=r(q[p][1],q[p][0]);n.pathname=function(a,b){if(void 0===a||!0===a){var c=this._parts.path||(this._parts.hostname?"/":"");return a?e.decodePath(c):c}return this._parts.path=a?e.recodePath(a):"/",this.build(!b),this},n.path=n.pathname,n.href=function(a,b){var c;if(void 0===a)return this.toString();this._string="",this._parts=e._parts();var d=a instanceof e,f="object"==typeof a&&(a.hostname||a.path||a.pathname);if(a.nodeName&&(f=e.getDomAttribute(a),a=a[f]||"",f=!1),!d&&f&&void 0!==a.pathname&&(a=a.toString()),"string"==typeof a)this._parts=e.parse(a,this._parts);else{if(!d&&!f)throw new TypeError("invalid input");for(c in d=d?a._parts:a)o.call(this._parts,c)&&(this._parts[c]=d[c])}return this.build(!b),this},n.is=function(a){var b=!1,d=!1,f=!1,g=!1,h=!1,i=!1,j=!1,k=!this._parts.urn;switch(this._parts.hostname&&(k=!1,d=e.ip4_expression.test(this._parts.hostname),f=e.ip6_expression.test(this._parts.hostname),b=d||f,h=(g=!b)&&c&&c.has(this._parts.hostname),i=g&&e.idn_expression.test(this._parts.hostname),j=g&&e.punycode_expression.test(this._parts.hostname)),a.toLowerCase()){case"relative":return k;case"absolute":return!k;case"domain":case"name":return g;case"sld":return h;case"ip":return b;case"ip4":case"ipv4":case"inet4":return d;case"ip6":case"ipv6":case"inet6":return f;case"idn":return i;case"url":return!this._parts.urn;case"urn":return!!this._parts.urn;case"punycode":return j}return null};var s=n.protocol,t=n.port,u=n.hostname;n.protocol=function(a,b){if(void 0!==a&&a&&(a=a.replace(/:(\/\/)?$/,""),!a.match(e.protocol_expression)))throw new TypeError("Protocol '"+a+"' contains characters other than [A-Z0-9.+-] or doesn't start with [A-Z]");return s.call(this,a,b)},n.scheme=n.protocol,n.port=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0!==a&&(0===a&&(a=null),a&&(a+="",":"===a.charAt(0)&&(a=a.substring(1)),a.match(/[^0-9]/))))throw new TypeError("Port '"+a+"' contains characters other than [0-9]");return t.call(this,a,b)},n.hostname=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0!==a){var c={};e.parseHost(a,c),a=c.hostname}return u.call(this,a,b)},n.host=function(a,b){return this._parts.urn?void 0===a?"":this:void 0===a?this._parts.hostname?e.buildHost(this._parts):"":(e.parseHost(a,this._parts),this.build(!b),this)},n.authority=function(a,b){return this._parts.urn?void 0===a?"":this:void 0===a?this._parts.hostname?e.buildAuthority(this._parts):"":(e.parseAuthority(a,this._parts),this.build(!b),this)},n.userinfo=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0===a){if(!this._parts.username)return"";var c=e.buildUserinfo(this._parts);return c.substring(0,c.length-1)}return"@"!==a[a.length-1]&&(a+="@"),e.parseUserinfo(a,this._parts),this.build(!b),this},n.resource=function(a,b){var c;return void 0===a?this.path()+this.search()+this.hash():(c=e.parse(a),this._parts.path=c.path,this._parts.query=c.query,this._parts.fragment=c.fragment,this.build(!b),this)},n.subdomain=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0===a){if(!this._parts.hostname||this.is("IP"))return"";var c=this._parts.hostname.length-this.domain().length-1;return this._parts.hostname.substring(0,c)||""}return c=this._parts.hostname.length-this.domain().length,c=this._parts.hostname.substring(0,c),c=RegExp("^"+f(c)),a&&"."!==a.charAt(a.length-1)&&(a+="."),a&&e.ensureValidHostname(a),this._parts.hostname=this._parts.hostname.replace(c,a),this.build(!b),this},n.domain=function(a,b){if(this._parts.urn)return void 0===a?"":this;if("boolean"==typeof a&&(b=a,a=void 0),void 0===a){if(!this._parts.hostname||this.is("IP"))return"";var c=this._parts.hostname.match(/\./g);return c&&2>c.length?this._parts.hostname:(c=this._parts.hostname.length-this.tld(b).length-1,c=this._parts.hostname.lastIndexOf(".",c-1)+1,this._parts.hostname.substring(c)||"")}if(!a)throw new TypeError("cannot set domain empty");return e.ensureValidHostname(a),!this._parts.hostname||this.is("IP")?this._parts.hostname=a:(c=RegExp(f(this.domain())+"$"),this._parts.hostname=this._parts.hostname.replace(c,a)),this.build(!b),this},n.tld=function(a,b){if(this._parts.urn)return void 0===a?"":this;if("boolean"==typeof a&&(b=a,a=void 0),void 0===a){if(!this._parts.hostname||this.is("IP"))return"";var d=this._parts.hostname.lastIndexOf("."),d=this._parts.hostname.substring(d+1);return!0!==b&&c&&c.list[d.toLowerCase()]?c.get(this._parts.hostname)||d:d}if(!a)throw new TypeError("cannot set TLD empty");if(a.match(/[^a-zA-Z0-9-]/)){if(!c||!c.is(a))throw new TypeError("TLD '"+a+"' contains characters other than [A-Z0-9]");d=RegExp(f(this.tld())+"$"),this._parts.hostname=this._parts.hostname.replace(d,a)}else{if(!this._parts.hostname||this.is("IP"))throw new ReferenceError("cannot set TLD on non-domain host");d=RegExp(f(this.tld())+"$"),this._parts.hostname=this._parts.hostname.replace(d,a)}return this.build(!b),this},n.directory=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0===a||!0===a){if(!this._parts.path&&!this._parts.hostname)return"";if("/"===this._parts.path)return"/";var c=this._parts.path.length-this.filename().length-1,c=this._parts.path.substring(0,c)||(this._parts.hostname?"/":"");return a?e.decodePath(c):c}return c=this._parts.path.length-this.filename().length,c=this._parts.path.substring(0,c),c=RegExp("^"+f(c)),this.is("relative")||(a||(a="/"),"/"!==a.charAt(0)&&(a="/"+a)),a&&"/"!==a.charAt(a.length-1)&&(a+="/"),a=e.recodePath(a),this._parts.path=this._parts.path.replace(c,a),this.build(!b),this},n.filename=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0===a||!0===a){if(!this._parts.path||"/"===this._parts.path)return"";var c=this._parts.path.lastIndexOf("/"),c=this._parts.path.substring(c+1);return a?e.decodePathSegment(c):c}c=!1,"/"===a.charAt(0)&&(a=a.substring(1)),a.match(/\.?\//)&&(c=!0);var d=RegExp(f(this.filename())+"$");return a=e.recodePath(a),this._parts.path=this._parts.path.replace(d,a),c?this.normalizePath(b):this.build(!b),this},n.suffix=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0===a||!0===a){if(!this._parts.path||"/"===this._parts.path)return"";var c=this.filename(),d=c.lastIndexOf(".");return-1===d?"":(c=c.substring(d+1),c=/^[a-z0-9%]+$/i.test(c)?c:"",a?e.decodePathSegment(c):c)}if("."===a.charAt(0)&&(a=a.substring(1)),c=this.suffix())d=a?RegExp(f(c)+"$"):RegExp(f("."+c)+"$");else{if(!a)return this;this._parts.path+="."+e.recodePath(a)}return d&&(a=e.recodePath(a),this._parts.path=this._parts.path.replace(d,a)),this.build(!b),this},n.segment=function(a,b,c){var d=this._parts.urn?":":"/",e=this.path(),f="/"===e.substring(0,1),e=e.split(d);if(void 0!==a&&"number"!=typeof a&&(c=b,b=a,a=void 0),void 0!==a&&"number"!=typeof a)throw Error("Bad segment '"+a+"', must be 0-based integer");if(f&&e.shift(),0>a&&(a=Math.max(e.length+a,0)),void 0===b)return void 0===a?e:e[a];if(null===a||void 0===e[a])if(h(b)){e=[],a=0;for(var g=b.length;g>a;a++)(b[a].length||e.length&&e[e.length-1].length)&&(e.length&&!e[e.length-1].length&&e.pop(),e.push(b[a]))}else(b||"string"==typeof b)&&(""===e[e.length-1]?e[e.length-1]=b:e.push(b));else b||"string"==typeof b&&b.length?e[a]=b:e.splice(a,1);return f&&e.unshift(""),this.path(e.join(d),c)},n.segmentCoded=function(a,b,c){var d,f;if("number"!=typeof a&&(c=b,b=a,a=void 0),void 0===b){if(a=this.segment(a,b,c),h(a))for(d=0,f=a.length;f>d;d++)a[d]=e.decode(a[d]);else a=void 0!==a?e.decode(a):void 0;return a}if(h(b))for(d=0,f=b.length;f>d;d++)b[d]=e.decode(b[d]);else b="string"==typeof b?e.encode(b):b;return this.segment(a,b,c)};var v=n.query;return n.query=function(a,b){if(!0===a)return e.parseQuery(this._parts.query,this._parts.escapeQuerySpace);if("function"==typeof a){var c=e.parseQuery(this._parts.query,this._parts.escapeQuerySpace),d=a.call(this,c);return this._parts.query=e.buildQuery(d||c,this._parts.duplicateQueryParameters,this._parts.escapeQuerySpace),this.build(!b),this}return void 0!==a&&"string"!=typeof a?(this._parts.query=e.buildQuery(a,this._parts.duplicateQueryParameters,this._parts.escapeQuerySpace),this.build(!b),this):v.call(this,a,b)},n.setQuery=function(a,b,c){var d=e.parseQuery(this._parts.query,this._parts.escapeQuerySpace);if("object"==typeof a)for(var f in a)o.call(a,f)&&(d[f]=a[f]);else{if("string"!=typeof a)throw new TypeError("URI.addQuery() accepts an object, string as the name parameter");d[a]=void 0!==b?b:null}return this._parts.query=e.buildQuery(d,this._parts.duplicateQueryParameters,this._parts.escapeQuerySpace),"string"!=typeof a&&(c=b),this.build(!c),this},n.addQuery=function(a,b,c){var d=e.parseQuery(this._parts.query,this._parts.escapeQuerySpace);return e.addQuery(d,a,void 0===b?null:b),this._parts.query=e.buildQuery(d,this._parts.duplicateQueryParameters,this._parts.escapeQuerySpace),"string"!=typeof a&&(c=b),this.build(!c),this},n.removeQuery=function(a,b,c){var d=e.parseQuery(this._parts.query,this._parts.escapeQuerySpace);return e.removeQuery(d,a,b),this._parts.query=e.buildQuery(d,this._parts.duplicateQueryParameters,this._parts.escapeQuerySpace),"string"!=typeof a&&(c=b),this.build(!c),this},n.hasQuery=function(a,b,c){var d=e.parseQuery(this._parts.query,this._parts.escapeQuerySpace);return e.hasQuery(d,a,b,c)},n.setSearch=n.setQuery,n.addSearch=n.addQuery,n.removeSearch=n.removeQuery,n.hasSearch=n.hasQuery,n.normalize=function(){return this._parts.urn?this.normalizeProtocol(!1).normalizeQuery(!1).normalizeFragment(!1).build():this.normalizeProtocol(!1).normalizeHostname(!1).normalizePort(!1).normalizePath(!1).normalizeQuery(!1).normalizeFragment(!1).build()},n.normalizeProtocol=function(a){return"string"==typeof this._parts.protocol&&(this._parts.protocol=this._parts.protocol.toLowerCase(),this.build(!a)),this},n.normalizeHostname=function(c){return this._parts.hostname&&(this.is("IDN")&&a?this._parts.hostname=a.toASCII(this._parts.hostname):this.is("IPv6")&&b&&(this._parts.hostname=b.best(this._parts.hostname)),this._parts.hostname=this._parts.hostname.toLowerCase(),this.build(!c)),this},n.normalizePort=function(a){return"string"==typeof this._parts.protocol&&this._parts.port===e.defaultPorts[this._parts.protocol]&&(this._parts.port=null,this.build(!a)),this},n.normalizePath=function(a){if(this._parts.urn||!this._parts.path||"/"===this._parts.path)return this;var b,c,d,f=this._parts.path,g="";for("/"!==f.charAt(0)&&(b=!0,f="/"+f),f=f.replace(/(\/(\.\/)+)|(\/\.$)/g,"/").replace(/\/{2,}/g,"/"),b&&(g=f.substring(1).match(/^(\.\.\/)+/)||"")&&(g=g[0]);c=f.indexOf("/.."),-1!==c;)0!==c?(d=f.substring(0,c).lastIndexOf("/"),-1===d&&(d=c),f=f.substring(0,d)+f.substring(c+3)):f=f.substring(3);return b&&this.is("relative")&&(f=g+f.substring(1)),f=e.recodePath(f),this._parts.path=f,this.build(!a),this},n.normalizePathname=n.normalizePath,n.normalizeQuery=function(a){return"string"==typeof this._parts.query&&(this._parts.query.length?this.query(e.parseQuery(this._parts.query,this._parts.escapeQuerySpace)):this._parts.query=null,this.build(!a)),this},n.normalizeFragment=function(a){return this._parts.fragment||(this._parts.fragment=null,this.build(!a)),this},n.normalizeSearch=n.normalizeQuery,n.normalizeHash=n.normalizeFragment,n.iso8859=function(){var a=e.encode,b=e.decode;return e.encode=escape,e.decode=decodeURIComponent,this.normalize(),e.encode=a,e.decode=b,this},n.unicode=function(){var a=e.encode,b=e.decode;return e.encode=l,e.decode=unescape,this.normalize(),e.encode=a,e.decode=b,this},n.readable=function(){var b=this.clone();b.username("").password("").normalize();var c="";if(b._parts.protocol&&(c+=b._parts.protocol+"://"),b._parts.hostname&&(b.is("punycode")&&a?(c+=a.toUnicode(b._parts.hostname),b._parts.port&&(c+=":"+b._parts.port)):c+=b.host()),b._parts.hostname&&b._parts.path&&"/"!==b._parts.path.charAt(0)&&(c+="/"),c+=b.path(!0),b._parts.query){for(var d="",f=0,g=b._parts.query.split("&"),h=g.length;h>f;f++){var i=(g[f]||"").split("="),d=d+("&"+e.decodeQuery(i[0],this._parts.escapeQuerySpace).replace(/&/g,"%26"));void 0!==i[1]&&(d+="="+e.decodeQuery(i[1],this._parts.escapeQuerySpace).replace(/&/g,"%26"))}c+="?"+d.substring(1)}return c+=e.decodeQuery(b.hash(),!0)},n.absoluteTo=function(a){var b,c,d=this.clone(),f=["protocol","username","password","hostname","port"];if(this._parts.urn)throw Error("URNs do not have any generally defined hierarchical components");if(a instanceof e||(a=new e(a)),d._parts.protocol||(d._parts.protocol=a._parts.protocol),this._parts.hostname)return d;for(b=0;c=f[b];b++)d._parts[c]=a._parts[c];return d._parts.path?".."===d._parts.path.substring(-2)&&(d._parts.path+="/"):(d._parts.path=a._parts.path,d._parts.query||(d._parts.query=a._parts.query)),"/"!==d.path().charAt(0)&&(a=a.directory(),d._parts.path=(a?a+"/":"")+d._parts.path,d.normalizePath()),d.build(),d},n.relativeTo=function(a){var b,c,d,f,g=this.clone().normalize();if(g._parts.urn)throw Error("URNs do not have any generally defined hierarchical components");if(a=new e(a).normalize(),b=g._parts,c=a._parts,d=g.path(),f=a.path(),"/"!==d.charAt(0))throw Error("URI is already relative");if("/"!==f.charAt(0))throw Error("Cannot calculate a URI relative to another relative URI");return b.protocol===c.protocol&&(b.protocol=null),b.username!==c.username||b.password!==c.password||null!==b.protocol||null!==b.username||null!==b.password||b.hostname!==c.hostname||b.port!==c.port?g.build():(b.hostname=null,b.port=null,d===f?(b.path="",g.build()):(a=e.commonPath(g.path(),a.path()))?(c=c.path.substring(a.length).replace(/[^\/]*$/,"").replace(/.*?\//g,"../"),b.path=c+b.path.substring(a.length),g.build()):g.build())},n.equals=function(a){var b=this.clone();a=new e(a);var c,d={},f={},g={};if(b.normalize(),a.normalize(),b.toString()===a.toString())return!0;if(d=b.query(),f=a.query(),b.query(""),a.query(""),b.toString()!==a.toString()||d.length!==f.length)return!1;d=e.parseQuery(d,this._parts.escapeQuerySpace),f=e.parseQuery(f,this._parts.escapeQuerySpace);for(c in d)if(o.call(d,c)){if(h(d[c])){if(!j(d[c],f[c]))return!1}else if(d[c]!==f[c])return!1;g[c]=!0}for(c in f)if(o.call(f,c)&&!g[c])return!1;return!0},n.duplicateQueryParameters=function(a){return this._parts.duplicateQueryParameters=!!a,this},n.escapeQuerySpace=function(a){return this._parts.escapeQuerySpace=!!a,this},e}),function(a,b){"object"==typeof exports?module.exports=b(require("./URI")):"function"==typeof define&&define.amd?define(["./URI"],b):b(a.URI)}(this,function(a){var b=a.prototype,c=b.fragment;a.fragmentPrefix="?";var d=a._parts;return a._parts=function(){var b=d();return b.fragmentPrefix=a.fragmentPrefix,b},b.fragmentPrefix=function(a){return this._parts.fragmentPrefix=a,this},b.fragment=function(b,d){var e=this._parts.fragmentPrefix,f=this._parts.fragment||"";return!0===b?f.substring(0,e.length)!==e?{}:a.parseQuery(f.substring(e.length)):void 0!==b&&"string"!=typeof b?(this._parts.fragment=e+a.buildQuery(b),this.build(!d),this):c.call(this,b,d)},b.addFragment=function(b,c,d){var e=this._parts.fragmentPrefix,f=a.parseQuery((this._parts.fragment||"").substring(e.length));return a.addQuery(f,b,c),this._parts.fragment=e+a.buildQuery(f),"string"!=typeof b&&(d=c),this.build(!d),this},b.removeFragment=function(b,c,d){var e=this._parts.fragmentPrefix,f=a.parseQuery((this._parts.fragment||"").substring(e.length));return a.removeQuery(f,b,c),this._parts.fragment=e+a.buildQuery(f),"string"!=typeof b&&(d=c),this.build(!d),this},b.addHash=b.addFragment,b.removeHash=b.removeFragment,{}}),function(a){"use strict";function b(a){var c;if(null===a||void 0===a)return!1;if(d.isArray(a))return a.length>0;if("string"==typeof a||"number"==typeof a||"boolean"==typeof a)return!0;for(c in a)if(a.hasOwnProperty(c)&&b(a[c]))return!0;return!1}var c=function(){function a(a){this.options=a}return a.prototype.toString=function(){return JSON&&JSON.stringify?JSON.stringify(this.options):this.options},a}(),d=function(){function a(a){return"[object Array]"===Object.prototype.toString.apply(a)}function b(a){return"[object String]"===Object.prototype.toString.apply(a)}function c(a){return"[object Number]"===Object.prototype.toString.apply(a)}function d(a){return"[object Boolean]"===Object.prototype.toString.apply(a)}function e(a,b){var c,d="",e=!0;for(c=0;c<a.length;c+=1)e?e=!1:d+=b,d+=a[c];return d}function f(a,b){for(var c=[],d=0;d<a.length;d+=1)c.push(b(a[d]));return c}function g(a,b){for(var c=[],d=0;d<a.length;d+=1)b(a[d])&&c.push(a[d]);return c}function h(a){if("object"!=typeof a||null===a)return a;Object.freeze(a);var b,c;for(c in a)a.hasOwnProperty(c)&&(b=a[c],"object"!=typeof b||b instanceof RegExp||i(b));return a}function i(a){return"function"==typeof Object.freeze?h(a):a}return{isArray:a,isString:b,isNumber:c,isBoolean:d,join:e,map:f,filter:g,deepFreeze:i}}(),e=function(){function a(a){return a>="a"&&"z">=a||a>="A"&&"Z">=a}function b(a){return a>="0"&&"9">=a}function c(a){return b(a)||a>="a"&&"f">=a||a>="A"&&"F">=a}return{isAlpha:a,isDigit:b,isHexDigit:c}}(),f=function(){function a(a){var b,c,d="",e=g.encode(a);for(c=0;c<e.length;c+=1)b=e.charCodeAt(c),d+="%"+(16>b?"0":"")+b.toString(16).toUpperCase();return d}function b(a,b){return"%"===a.charAt(b)&&e.isHexDigit(a.charAt(b+1))&&e.isHexDigit(a.charAt(b+2))}function c(a,b){return parseInt(a.substr(b,2),16)}function d(a){if(!b(a,0))return!1;var d=c(a,1),e=g.numBytes(d);if(0===e)return!1;for(var f=1;e>f;f+=1)if(!b(a,3*f)||!g.isValidFollowingCharCode(c(a,3*f+1)))return!1;return!0}function f(a,d){var e=a.charAt(d);if(!b(a,d))return e;var f=c(a,d+1),h=g.numBytes(f);if(0===h)return e;for(var i=1;h>i;i+=1)if(!b(a,d+3*i)||!g.isValidFollowingCharCode(c(a,d+3*i+1)))return e;return a.substr(d,3*h)}var g={encode:function(a){return unescape(encodeURIComponent(a))},numBytes:function(a){return 127>=a?1:a>=194&&223>=a?2:a>=224&&239>=a?3:a>=240&&244>=a?4:0},isValidFollowingCharCode:function(a){return a>=128&&191>=a}};return{encodeCharacter:a,isPctEncoded:d,pctCharAt:f}}(),g=function(){function a(a){return e.isAlpha(a)||e.isDigit(a)||"_"===a||f.isPctEncoded(a)}function b(a){return e.isAlpha(a)||e.isDigit(a)||"-"===a||"."===a||"_"===a||"~"===a}function c(a){return":"===a||"/"===a||"?"===a||"#"===a||"["===a||"]"===a||"@"===a||"!"===a||"$"===a||"&"===a||"("===a||")"===a||"*"===a||"+"===a||","===a||";"===a||"="===a||"'"===a}return{isVarchar:a,isUnreserved:b,isReserved:c}}(),h=function(){function a(a,b){var c,d="",e="";for(("number"==typeof a||"boolean"==typeof a)&&(a=a.toString()),c=0;c<a.length;c+=e.length)e=a.charAt(c),d+=g.isUnreserved(e)||b&&g.isReserved(e)?e:f.encodeCharacter(e);return d}function b(b){return a(b,!0)}function c(a,b){var c=f.pctCharAt(a,b);return c.length>1?c:g.isReserved(c)||g.isUnreserved(c)?c:f.encodeCharacter(c)}function d(a){var b,c="",d="";for(b=0;b<a.length;b+=d.length)d=f.pctCharAt(a,b),c+=d.length>1?d:g.isReserved(d)||g.isUnreserved(d)?d:f.encodeCharacter(d);return c}return{encode:a,encodePassReserved:b,encodeLiteral:d,encodeLiteralCharacter:c}}(),i=function(){function a(a){b[a]={symbol:a,separator:"?"===a?"&":""===a||"+"===a||"#"===a?",":a,named:";"===a||"&"===a||"?"===a,ifEmpty:"&"===a||"?"===a?"=":"",first:"+"===a?"":a,encode:"+"===a||"#"===a?h.encodePassReserved:h.encode,toString:function(){return this.symbol}}}var b={};return a(""),a("+"),a("#"),a("."),a("/"),a(";"),a("?"),a("&"),{valueOf:function(a){return b[a]?b[a]:"=,!@|".indexOf(a)>=0?null:b[""]}}}(),j=function(){function a(a){this.literal=h.encodeLiteral(a)}return a.prototype.expand=function(){return this.literal},a.prototype.toString=a.prototype.expand,a}(),k=function(){function a(a){function b(){var b=a.substring(n,j);if(0===b.length)throw new c({expressionText:a,message:"a varname must be specified",position:j});m={varname:b,exploded:!1,maxLength:null},n=null}function d(){if(o===j)throw new c({expressionText:a,message:"after a ':' you have to specify the length",position:j});m.maxLength=parseInt(a.substring(o,j),10),o=null}var h,j,k=[],m=null,n=null,o=null,p="";for(h=function(b){var d=i.valueOf(b);if(null===d)throw new c({expressionText:a,message:"illegal use of reserved operator",position:j,operator:b});return d}(a.charAt(0)),j=h.symbol.length,n=j;j<a.length;j+=p.length){if(p=f.pctCharAt(a,j),null!==n){if("."===p){if(n===j)throw new c({expressionText:a,message:"a varname MUST NOT start with a dot",position:j});continue}if(g.isVarchar(p))continue;b()}if(null!==o){if(j===o&&"0"===p)throw new c({expressionText:a,message:"A :prefix must not start with digit 0",position:j});if(e.isDigit(p)){if(j-o>=4)throw new c({expressionText:a,message:"A :prefix must have max 4 digits",position:j});continue}d()}if(":"!==p)if("*"!==p){if(","!==p)throw new c({expressionText:a,message:"illegal character",character:p,position:j});k.push(m),m=null,n=j+1}else{if(null===m)throw new c({expressionText:a,message:"exploded without varspec",position:j});if(m.exploded)throw new c({expressionText:a,message:"exploded twice",position:j});if(m.maxLength)throw new c({expressionText:a,message:"an explode (*) MUST NOT follow to a prefix",position:j});m.exploded=!0}else{if(null!==m.maxLength)throw new c({expressionText:a,message:"only one :maxLength is allowed per varspec",position:j});if(m.exploded)throw new c({expressionText:a,message:"an exploeded varspec MUST NOT be varspeced",position:j});o=j+1}}return null!==n&&b(),null!==o&&d(),k.push(m),new l(a,h,k)}function b(a){return a.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,"\\$&")}function d(d){var e,f,g,h=[],i=null,k="",l=!0,n=0;for(e=0;e<d.length;e+=1)if(f=d.charAt(e),null===n){if(null===i)throw new Error("reached unreachable code");if("{"===f)throw new c({templateText:d,message:"brace already opened",position:e});if("}"===f){if(i+1===e)throw new c({templateText:d,message:"empty braces",position:i});try{g=a(d.substring(i+1,e))}catch(o){if(o.prototype===c.prototype)throw new c({templateText:d,message:o.options.message,position:i+o.options.position,details:o.options});throw o}h.push(g),0===g.operator.symbol.length?k+="([^/]+)":l=!1,i=null,n=e+1}}else{if("}"===f)throw new c({templateText:d,message:"unopened brace closed",position:e});"{"===f&&(e>n&&(g=new j(d.substring(n,e)),h.push(g),k+=b(g.literal)),n=null,i=e)}if(null!==i)throw new c({templateText:d,message:"unclosed brace",position:i});return n<d.length&&(g=new j(d.substring(n)),h.push(g),k+=b(g.literal)),l===!1&&(k=void 0),new m(d,h,k)}return d}(),l=function(){function a(a){return JSON&&JSON.stringify?JSON.stringify(a):a}function c(a){if(!b(a))return!0;if(d.isString(a))return""===a;if(d.isNumber(a)||d.isBoolean(a))return!1;if(d.isArray(a))return 0===a.length;for(var c in a)if(a.hasOwnProperty(c))return!1;return!0}function e(a){var b,c=[];for(b in a)a.hasOwnProperty(b)&&c.push({name:b,value:a[b]});return c}function f(a,b,c){this.templateText=a,this.operator=b,this.varspecs=c}function g(a,b,c){var d="";if(c=c.toString(),b.named){if(d+=h.encodeLiteral(a.varname),""===c)return d+=b.ifEmpty;d+="="}return null!==a.maxLength&&(c=c.substr(0,a.maxLength)),d+=b.encode(c)}function i(a){return b(a.value)}function j(a,f,g){var j=[],k="";if(f.named){if(k+=h.encodeLiteral(a.varname),c(g))return k+=f.ifEmpty;k+="="}return d.isArray(g)?(j=g,j=d.filter(j,b),j=d.map(j,f.encode),k+=d.join(j,",")):(j=e(g),j=d.filter(j,i),j=d.map(j,function(a){return f.encode(a.name)+","+f.encode(a.value)}),k+=d.join(j,",")),k}function k(a,f,g){var j=d.isArray(g),k=[];return j?(k=g,k=d.filter(k,b),k=d.map(k,function(b){var d=h.encodeLiteral(a.varname);return d+=c(b)?f.ifEmpty:"="+f.encode(b)})):(k=e(g),k=d.filter(k,i),k=d.map(k,function(a){var b=h.encodeLiteral(a.name);return b+=c(a.value)?f.ifEmpty:"="+f.encode(a.value)})),d.join(k,f.separator)}function l(a,c){var f=[],g="";return d.isArray(c)?(f=c,f=d.filter(f,b),f=d.map(f,a.encode),g+=d.join(f,a.separator)):(f=e(c),f=d.filter(f,function(a){return b(a.value)}),f=d.map(f,function(b){return a.encode(b.name)+"="+a.encode(b.value)}),g+=d.join(f,a.separator)),g}return f.prototype.toString=function(){return this.templateText},f.prototype.expand=function(e){var f,h,i,m,n=[],o=!1,p=this.operator;for(f=0;f<this.varspecs.length;f+=1)if(h=this.varspecs[f],i=e[h.varname],null!==i&&void 0!==i)if(h.exploded&&(o=!0),m=d.isArray(i),"string"==typeof i||"number"==typeof i||"boolean"==typeof i)n.push(g(h,p,i));else{if(h.maxLength&&b(i))throw new Error("Prefix modifiers are not applicable to variables that have composite values. You tried to expand "+this+" with "+a(i));h.exploded?b(i)&&(p.named?n.push(k(h,p,i)):n.push(l(p,i))):(p.named||!c(i))&&n.push(j(h,p,i))}return 0===n.length?"":p.first+d.join(n,p.separator)},f}(),m=function(){function a(a,b,c){this.templateText=a,this.expressions=b,void 0!==c&&(this.regexp=new RegExp("^"+c+"$")),d.deepFreeze(this)}return a.prototype.toString=function(){return this.templateText},a.prototype.expand=function(a){var b,c="";for(b=0;b<this.expressions.length;b+=1)c+=this.expressions[b].expand(a);return c},a.prototype.extract=function(a){var b,c,d,e,f=1,g=!0,h={};if(void 0!==this.regexp&&this.regexp.test(a)){for(e=this.regexp.exec(a),b=0;b<this.expressions.length;b+=1)c=this.expressions[b],void 0===c.literal&&(void 0!==c.operator&&0===c.operator.symbol.length&&1===c.varspecs.length?(d=c.varspecs[0],d.exploded===!1&&null===d.maxLength&&-1===e[f].indexOf(",")?(h[d.varname]=decodeURIComponent(e[f]),f+=1):g=!1):g=!1);if(g)return h}return!1},a.parse=k,a.UriTemplateError=c,a}();a(m)}(function(a){"use strict";"undefined"!=typeof module?module.exports=a:"function"==typeof define?define([],function(){return a}):"undefined"!=typeof window?window.UriTemplate=a:global.UriTemplate=a});var LZString=function(){function a(a,b){if(!e[a]){e[a]={};for(var c=0;c<a.length;c++)e[a][a.charAt(c)]=c}return e[a][b]}var b=String.fromCharCode,c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",d="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$",e={},f={compressToBase64:function(a){if(null==a)return"";var b=f._compress(a,6,function(a){return c.charAt(a)});switch(b.length%4){default:case 0:return b;case 1:return b+"===";case 2:return b+"==";case 3:return b+"="}},decompressFromBase64:function(b){return null==b?"":""==b?null:f._decompress(b.length,32,function(d){return a(c,b.charAt(d))})},compressToUTF16:function(a){return null==a?"":f._compress(a,15,function(a){return b(a+32)})+" "},decompressFromUTF16:function(a){return null==a?"":""==a?null:f._decompress(a.length,16384,function(b){return a.charCodeAt(b)-32})},compressToUint8Array:function(a){for(var b=f.compress(a),c=new Uint8Array(2*b.length),d=0,e=b.length;e>d;d++){var g=b.charCodeAt(d);c[2*d]=g>>>8,c[2*d+1]=g%256}return c},decompressFromUint8Array:function(a){if(null===a||void 0===a)return f.decompress(a);for(var c=new Array(a.length/2),d=0,e=c.length;e>d;d++)c[d]=256*a[2*d]+a[2*d+1];var g=[];return c.forEach(function(a){g.push(b(a))}),f.decompress(g.join(""))},compressToEncodedURIComponent:function(a){return null==a?"":f._compress(a,6,function(a){return d.charAt(a)})},decompressFromEncodedURIComponent:function(b){return null==b?"":""==b?null:(b=b.replace(/ /g,"+"),f._decompress(b.length,32,function(c){return a(d,b.charAt(c))}))},compress:function(a){return f._compress(a,16,function(a){return b(a)})},_compress:function(a,b,c){if(null==a)return"";var d,e,f,g={},h={},i="",j="",k="",l=2,m=3,n=2,o=[],p=0,q=0;for(f=0;f<a.length;f+=1)if(i=a.charAt(f),Object.prototype.hasOwnProperty.call(g,i)||(g[i]=m++,h[i]=!0),j=k+i,Object.prototype.hasOwnProperty.call(g,j))k=j;else{if(Object.prototype.hasOwnProperty.call(h,k)){if(k.charCodeAt(0)<256){for(d=0;n>d;d++)p<<=1,q==b-1?(q=0,o.push(c(p)),p=0):q++;for(e=k.charCodeAt(0),d=0;8>d;d++)p=p<<1|1&e,q==b-1?(q=0,o.push(c(p)),p=0):q++,e>>=1}else{for(e=1,d=0;n>d;d++)p=p<<1|e,q==b-1?(q=0,o.push(c(p)),p=0):q++,e=0;for(e=k.charCodeAt(0),d=0;16>d;d++)p=p<<1|1&e,q==b-1?(q=0,o.push(c(p)),p=0):q++,e>>=1}l--,0==l&&(l=Math.pow(2,n),n++),delete h[k]}else for(e=g[k],d=0;n>d;d++)p=p<<1|1&e,q==b-1?(q=0,o.push(c(p)),p=0):q++,e>>=1;l--,0==l&&(l=Math.pow(2,n),n++),g[j]=m++,k=String(i)}if(""!==k){if(Object.prototype.hasOwnProperty.call(h,k)){if(k.charCodeAt(0)<256){for(d=0;n>d;d++)p<<=1,q==b-1?(q=0,o.push(c(p)),p=0):q++;for(e=k.charCodeAt(0),d=0;8>d;d++)p=p<<1|1&e,q==b-1?(q=0,o.push(c(p)),p=0):q++,e>>=1}else{for(e=1,d=0;n>d;d++)p=p<<1|e,q==b-1?(q=0,o.push(c(p)),p=0):q++,e=0;for(e=k.charCodeAt(0),d=0;16>d;d++)p=p<<1|1&e,q==b-1?(q=0,o.push(c(p)),p=0):q++,e>>=1}l--,0==l&&(l=Math.pow(2,n),n++),delete h[k]}else for(e=g[k],d=0;n>d;d++)p=p<<1|1&e,q==b-1?(q=0,o.push(c(p)),p=0):q++,e>>=1;l--,0==l&&(l=Math.pow(2,n),n++)}for(e=2,d=0;n>d;d++)p=p<<1|1&e,q==b-1?(q=0,o.push(c(p)),p=0):q++,e>>=1;for(;;){if(p<<=1,q==b-1){o.push(c(p));break}q++}return o.join("")},decompress:function(a){return null==a?"":""==a?null:f._decompress(a.length,32768,function(b){return a.charCodeAt(b)})},_decompress:function(a,c,d){var e,f,g,h,i,j,k,l,m=[],n=4,o=4,p=3,q="",r=[],s={val:d(0),position:c,index:1};for(f=0;3>f;f+=1)m[f]=f;for(h=0,j=Math.pow(2,2),k=1;k!=j;)i=s.val&s.position,s.position>>=1,0==s.position&&(s.position=c,s.val=d(s.index++)),h|=(i>0?1:0)*k,k<<=1;switch(e=h){case 0:for(h=0,j=Math.pow(2,8),k=1;k!=j;)i=s.val&s.position,s.position>>=1,0==s.position&&(s.position=c,s.val=d(s.index++)),h|=(i>0?1:0)*k,k<<=1;l=b(h);break;case 1:for(h=0,j=Math.pow(2,16),k=1;k!=j;)i=s.val&s.position,s.position>>=1,0==s.position&&(s.position=c,s.val=d(s.index++)),h|=(i>0?1:0)*k,k<<=1;l=b(h);break;case 2:return""}for(m[3]=l,g=l,r.push(l);;){if(s.index>a)return"";for(h=0,j=Math.pow(2,p),k=1;k!=j;)i=s.val&s.position,s.position>>=1,0==s.position&&(s.position=c,s.val=d(s.index++)),h|=(i>0?1:0)*k,k<<=1;switch(l=h){case 0:for(h=0,j=Math.pow(2,8),k=1;k!=j;)i=s.val&s.position,s.position>>=1,0==s.position&&(s.position=c,s.val=d(s.index++)),h|=(i>0?1:0)*k,k<<=1;m[o++]=b(h),l=o-1,n--;break;case 1:for(h=0,j=Math.pow(2,16),k=1;k!=j;)i=s.val&s.position,s.position>>=1,0==s.position&&(s.position=c,s.val=d(s.index++)),h|=(i>0?1:0)*k,k<<=1;m[o++]=b(h),l=o-1,n--;break;case 2:return r.join("")}if(0==n&&(n=Math.pow(2,p),p++),m[l])q=m[l];else{if(l!==o)return null;q=g+g.charAt(0)}r.push(q),m[o++]=g+q.charAt(0),n--,g=q,0==n&&(n=Math.pow(2,p),p++)}}};return f}();"function"==typeof define&&define.amd?define(function(){return LZString}):"undefined"!=typeof module&&null!=module&&(module.exports=LZString),function(a,b){"object"==typeof exports&&"undefined"!=typeof module?module.exports=b():"function"==typeof define&&define.amd?define(b):a.moment=b()}(this,function(){"use strict";function a(){return fd.apply(null,arguments)}function b(a){fd=a}function c(a){return a instanceof Array||"[object Array]"===Object.prototype.toString.call(a)}function d(a){return a instanceof Date||"[object Date]"===Object.prototype.toString.call(a);
}function e(a,b){var c,d=[];for(c=0;c<a.length;++c)d.push(b(a[c],c));return d}function f(a,b){return Object.prototype.hasOwnProperty.call(a,b)}function g(a,b){for(var c in b)f(b,c)&&(a[c]=b[c]);return f(b,"toString")&&(a.toString=b.toString),f(b,"valueOf")&&(a.valueOf=b.valueOf),a}function h(a,b,c,d){return Ja(a,b,c,d,!0).utc()}function i(){return{empty:!1,unusedTokens:[],unusedInput:[],overflow:-2,charsLeftOver:0,nullInput:!1,invalidMonth:null,invalidFormat:!1,userInvalidated:!1,iso:!1,parsedDateParts:[],meridiem:null}}function j(a){return null==a._pf&&(a._pf=i()),a._pf}function k(a){if(null==a._isValid){var b=j(a),c=gd.call(b.parsedDateParts,function(a){return null!=a});a._isValid=!isNaN(a._d.getTime())&&b.overflow<0&&!b.empty&&!b.invalidMonth&&!b.invalidWeekday&&!b.nullInput&&!b.invalidFormat&&!b.userInvalidated&&(!b.meridiem||b.meridiem&&c),a._strict&&(a._isValid=a._isValid&&0===b.charsLeftOver&&0===b.unusedTokens.length&&void 0===b.bigHour)}return a._isValid}function l(a){var b=h(NaN);return null!=a?g(j(b),a):j(b).userInvalidated=!0,b}function m(a){return void 0===a}function n(a,b){var c,d,e;if(m(b._isAMomentObject)||(a._isAMomentObject=b._isAMomentObject),m(b._i)||(a._i=b._i),m(b._f)||(a._f=b._f),m(b._l)||(a._l=b._l),m(b._strict)||(a._strict=b._strict),m(b._tzm)||(a._tzm=b._tzm),m(b._isUTC)||(a._isUTC=b._isUTC),m(b._offset)||(a._offset=b._offset),m(b._pf)||(a._pf=j(b)),m(b._locale)||(a._locale=b._locale),hd.length>0)for(c in hd)d=hd[c],e=b[d],m(e)||(a[d]=e);return a}function o(b){n(this,b),this._d=new Date(null!=b._d?b._d.getTime():NaN),id===!1&&(id=!0,a.updateOffset(this),id=!1)}function p(a){return a instanceof o||null!=a&&null!=a._isAMomentObject}function q(a){return 0>a?Math.ceil(a):Math.floor(a)}function r(a){var b=+a,c=0;return 0!==b&&isFinite(b)&&(c=q(b)),c}function s(a,b,c){var d,e=Math.min(a.length,b.length),f=Math.abs(a.length-b.length),g=0;for(d=0;e>d;d++)(c&&a[d]!==b[d]||!c&&r(a[d])!==r(b[d]))&&g++;return g+f}function t(b){a.suppressDeprecationWarnings===!1&&"undefined"!=typeof console&&console.warn&&console.warn("Deprecation warning: "+b)}function u(b,c){var d=!0;return g(function(){return null!=a.deprecationHandler&&a.deprecationHandler(null,b),d&&(t(b+"\nArguments: "+Array.prototype.slice.call(arguments).join(", ")+"\n"+(new Error).stack),d=!1),c.apply(this,arguments)},c)}function v(b,c){null!=a.deprecationHandler&&a.deprecationHandler(b,c),jd[b]||(t(c),jd[b]=!0)}function w(a){return a instanceof Function||"[object Function]"===Object.prototype.toString.call(a)}function x(a){return"[object Object]"===Object.prototype.toString.call(a)}function y(a){var b,c;for(c in a)b=a[c],w(b)?this[c]=b:this["_"+c]=b;this._config=a,this._ordinalParseLenient=new RegExp(this._ordinalParse.source+"|"+/\d{1,2}/.source)}function z(a,b){var c,d=g({},a);for(c in b)f(b,c)&&(x(a[c])&&x(b[c])?(d[c]={},g(d[c],a[c]),g(d[c],b[c])):null!=b[c]?d[c]=b[c]:delete d[c]);return d}function A(a){null!=a&&this.set(a)}function B(a){return a?a.toLowerCase().replace("_","-"):a}function C(a){for(var b,c,d,e,f=0;f<a.length;){for(e=B(a[f]).split("-"),b=e.length,c=B(a[f+1]),c=c?c.split("-"):null;b>0;){if(d=D(e.slice(0,b).join("-")))return d;if(c&&c.length>=b&&s(e,c,!0)>=b-1)break;b--}f++}return null}function D(a){var b=null;if(!nd[a]&&"undefined"!=typeof module&&module&&module.exports)try{b=ld._abbr,require("./locale/"+a),E(b)}catch(c){}return nd[a]}function E(a,b){var c;return a&&(c=m(b)?H(a):F(a,b),c&&(ld=c)),ld._abbr}function F(a,b){return null!==b?(b.abbr=a,null!=nd[a]?(v("defineLocaleOverride","use moment.updateLocale(localeName, config) to change an existing locale. moment.defineLocale(localeName, config) should only be used for creating a new locale"),b=z(nd[a]._config,b)):null!=b.parentLocale&&(null!=nd[b.parentLocale]?b=z(nd[b.parentLocale]._config,b):v("parentLocaleUndefined","specified parentLocale is not defined yet")),nd[a]=new A(b),E(a),nd[a]):(delete nd[a],null)}function G(a,b){if(null!=b){var c;null!=nd[a]&&(b=z(nd[a]._config,b)),c=new A(b),c.parentLocale=nd[a],nd[a]=c,E(a)}else null!=nd[a]&&(null!=nd[a].parentLocale?nd[a]=nd[a].parentLocale:null!=nd[a]&&delete nd[a]);return nd[a]}function H(a){var b;if(a&&a._locale&&a._locale._abbr&&(a=a._locale._abbr),!a)return ld;if(!c(a)){if(b=D(a))return b;a=[a]}return C(a)}function I(){return kd(nd)}function J(a,b){var c=a.toLowerCase();od[c]=od[c+"s"]=od[b]=a}function K(a){return"string"==typeof a?od[a]||od[a.toLowerCase()]:void 0}function L(a){var b,c,d={};for(c in a)f(a,c)&&(b=K(c),b&&(d[b]=a[c]));return d}function M(b,c){return function(d){return null!=d?(O(this,b,d),a.updateOffset(this,c),this):N(this,b)}}function N(a,b){return a.isValid()?a._d["get"+(a._isUTC?"UTC":"")+b]():NaN}function O(a,b,c){a.isValid()&&a._d["set"+(a._isUTC?"UTC":"")+b](c)}function P(a,b){var c;if("object"==typeof a)for(c in a)this.set(c,a[c]);else if(a=K(a),w(this[a]))return this[a](b);return this}function Q(a,b,c){var d=""+Math.abs(a),e=b-d.length,f=a>=0;return(f?c?"+":"":"-")+Math.pow(10,Math.max(0,e)).toString().substr(1)+d}function R(a,b,c,d){var e=d;"string"==typeof d&&(e=function(){return this[d]()}),a&&(sd[a]=e),b&&(sd[b[0]]=function(){return Q(e.apply(this,arguments),b[1],b[2])}),c&&(sd[c]=function(){return this.localeData().ordinal(e.apply(this,arguments),a)})}function S(a){return a.match(/\[[\s\S]/)?a.replace(/^\[|\]$/g,""):a.replace(/\\/g,"")}function T(a){var b,c,d=a.match(pd);for(b=0,c=d.length;c>b;b++)sd[d[b]]?d[b]=sd[d[b]]:d[b]=S(d[b]);return function(b){var e,f="";for(e=0;c>e;e++)f+=d[e]instanceof Function?d[e].call(b,a):d[e];return f}}function U(a,b){return a.isValid()?(b=V(b,a.localeData()),rd[b]=rd[b]||T(b),rd[b](a)):a.localeData().invalidDate()}function V(a,b){function c(a){return b.longDateFormat(a)||a}var d=5;for(qd.lastIndex=0;d>=0&&qd.test(a);)a=a.replace(qd,c),qd.lastIndex=0,d-=1;return a}function W(a,b,c){Kd[a]=w(b)?b:function(a,d){return a&&c?c:b}}function X(a,b){return f(Kd,a)?Kd[a](b._strict,b._locale):new RegExp(Y(a))}function Y(a){return Z(a.replace("\\","").replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g,function(a,b,c,d,e){return b||c||d||e}))}function Z(a){return a.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")}function $(a,b){var c,d=b;for("string"==typeof a&&(a=[a]),"number"==typeof b&&(d=function(a,c){c[b]=r(a)}),c=0;c<a.length;c++)Ld[a[c]]=d}function _(a,b){$(a,function(a,c,d,e){d._w=d._w||{},b(a,d._w,d,e)})}function aa(a,b,c){null!=b&&f(Ld,a)&&Ld[a](b,c._a,c,a)}function ba(a,b){return new Date(Date.UTC(a,b+1,0)).getUTCDate()}function ca(a,b){return c(this._months)?this._months[a.month()]:this._months[Vd.test(b)?"format":"standalone"][a.month()]}function da(a,b){return c(this._monthsShort)?this._monthsShort[a.month()]:this._monthsShort[Vd.test(b)?"format":"standalone"][a.month()]}function ea(a,b,c){var d,e,f,g=a.toLocaleLowerCase();if(!this._monthsParse)for(this._monthsParse=[],this._longMonthsParse=[],this._shortMonthsParse=[],d=0;12>d;++d)f=h([2e3,d]),this._shortMonthsParse[d]=this.monthsShort(f,"").toLocaleLowerCase(),this._longMonthsParse[d]=this.months(f,"").toLocaleLowerCase();return c?"MMM"===b?(e=md.call(this._shortMonthsParse,g),-1!==e?e:null):(e=md.call(this._longMonthsParse,g),-1!==e?e:null):"MMM"===b?(e=md.call(this._shortMonthsParse,g),-1!==e?e:(e=md.call(this._longMonthsParse,g),-1!==e?e:null)):(e=md.call(this._longMonthsParse,g),-1!==e?e:(e=md.call(this._shortMonthsParse,g),-1!==e?e:null))}function fa(a,b,c){var d,e,f;if(this._monthsParseExact)return ea.call(this,a,b,c);for(this._monthsParse||(this._monthsParse=[],this._longMonthsParse=[],this._shortMonthsParse=[]),d=0;12>d;d++){if(e=h([2e3,d]),c&&!this._longMonthsParse[d]&&(this._longMonthsParse[d]=new RegExp("^"+this.months(e,"").replace(".","")+"$","i"),this._shortMonthsParse[d]=new RegExp("^"+this.monthsShort(e,"").replace(".","")+"$","i")),c||this._monthsParse[d]||(f="^"+this.months(e,"")+"|^"+this.monthsShort(e,""),this._monthsParse[d]=new RegExp(f.replace(".",""),"i")),c&&"MMMM"===b&&this._longMonthsParse[d].test(a))return d;if(c&&"MMM"===b&&this._shortMonthsParse[d].test(a))return d;if(!c&&this._monthsParse[d].test(a))return d}}function ga(a,b){var c;if(!a.isValid())return a;if("string"==typeof b)if(/^\d+$/.test(b))b=r(b);else if(b=a.localeData().monthsParse(b),"number"!=typeof b)return a;return c=Math.min(a.date(),ba(a.year(),b)),a._d["set"+(a._isUTC?"UTC":"")+"Month"](b,c),a}function ha(b){return null!=b?(ga(this,b),a.updateOffset(this,!0),this):N(this,"Month")}function ia(){return ba(this.year(),this.month())}function ja(a){return this._monthsParseExact?(f(this,"_monthsRegex")||la.call(this),a?this._monthsShortStrictRegex:this._monthsShortRegex):this._monthsShortStrictRegex&&a?this._monthsShortStrictRegex:this._monthsShortRegex}function ka(a){return this._monthsParseExact?(f(this,"_monthsRegex")||la.call(this),a?this._monthsStrictRegex:this._monthsRegex):this._monthsStrictRegex&&a?this._monthsStrictRegex:this._monthsRegex}function la(){function a(a,b){return b.length-a.length}var b,c,d=[],e=[],f=[];for(b=0;12>b;b++)c=h([2e3,b]),d.push(this.monthsShort(c,"")),e.push(this.months(c,"")),f.push(this.months(c,"")),f.push(this.monthsShort(c,""));for(d.sort(a),e.sort(a),f.sort(a),b=0;12>b;b++)d[b]=Z(d[b]),e[b]=Z(e[b]),f[b]=Z(f[b]);this._monthsRegex=new RegExp("^("+f.join("|")+")","i"),this._monthsShortRegex=this._monthsRegex,this._monthsStrictRegex=new RegExp("^("+e.join("|")+")","i"),this._monthsShortStrictRegex=new RegExp("^("+d.join("|")+")","i")}function ma(a){var b,c=a._a;return c&&-2===j(a).overflow&&(b=c[Nd]<0||c[Nd]>11?Nd:c[Od]<1||c[Od]>ba(c[Md],c[Nd])?Od:c[Pd]<0||c[Pd]>24||24===c[Pd]&&(0!==c[Qd]||0!==c[Rd]||0!==c[Sd])?Pd:c[Qd]<0||c[Qd]>59?Qd:c[Rd]<0||c[Rd]>59?Rd:c[Sd]<0||c[Sd]>999?Sd:-1,j(a)._overflowDayOfYear&&(Md>b||b>Od)&&(b=Od),j(a)._overflowWeeks&&-1===b&&(b=Td),j(a)._overflowWeekday&&-1===b&&(b=Ud),j(a).overflow=b),a}function na(a){var b,c,d,e,f,g,h=a._i,i=$d.exec(h)||_d.exec(h);if(i){for(j(a).iso=!0,b=0,c=be.length;c>b;b++)if(be[b][1].exec(i[1])){e=be[b][0],d=be[b][2]!==!1;break}if(null==e)return void(a._isValid=!1);if(i[3]){for(b=0,c=ce.length;c>b;b++)if(ce[b][1].exec(i[3])){f=(i[2]||" ")+ce[b][0];break}if(null==f)return void(a._isValid=!1)}if(!d&&null!=f)return void(a._isValid=!1);if(i[4]){if(!ae.exec(i[4]))return void(a._isValid=!1);g="Z"}a._f=e+(f||"")+(g||""),Ca(a)}else a._isValid=!1}function oa(b){var c=de.exec(b._i);return null!==c?void(b._d=new Date(+c[1])):(na(b),void(b._isValid===!1&&(delete b._isValid,a.createFromInputFallback(b))))}function pa(a,b,c,d,e,f,g){var h=new Date(a,b,c,d,e,f,g);return 100>a&&a>=0&&isFinite(h.getFullYear())&&h.setFullYear(a),h}function qa(a){var b=new Date(Date.UTC.apply(null,arguments));return 100>a&&a>=0&&isFinite(b.getUTCFullYear())&&b.setUTCFullYear(a),b}function ra(a){return sa(a)?366:365}function sa(a){return a%4===0&&a%100!==0||a%400===0}function ta(){return sa(this.year())}function ua(a,b,c){var d=7+b-c,e=(7+qa(a,0,d).getUTCDay()-b)%7;return-e+d-1}function va(a,b,c,d,e){var f,g,h=(7+c-d)%7,i=ua(a,d,e),j=1+7*(b-1)+h+i;return 0>=j?(f=a-1,g=ra(f)+j):j>ra(a)?(f=a+1,g=j-ra(a)):(f=a,g=j),{year:f,dayOfYear:g}}function wa(a,b,c){var d,e,f=ua(a.year(),b,c),g=Math.floor((a.dayOfYear()-f-1)/7)+1;return 1>g?(e=a.year()-1,d=g+xa(e,b,c)):g>xa(a.year(),b,c)?(d=g-xa(a.year(),b,c),e=a.year()+1):(e=a.year(),d=g),{week:d,year:e}}function xa(a,b,c){var d=ua(a,b,c),e=ua(a+1,b,c);return(ra(a)-d+e)/7}function ya(a,b,c){return null!=a?a:null!=b?b:c}function za(b){var c=new Date(a.now());return b._useUTC?[c.getUTCFullYear(),c.getUTCMonth(),c.getUTCDate()]:[c.getFullYear(),c.getMonth(),c.getDate()]}function Aa(a){var b,c,d,e,f=[];if(!a._d){for(d=za(a),a._w&&null==a._a[Od]&&null==a._a[Nd]&&Ba(a),a._dayOfYear&&(e=ya(a._a[Md],d[Md]),a._dayOfYear>ra(e)&&(j(a)._overflowDayOfYear=!0),c=qa(e,0,a._dayOfYear),a._a[Nd]=c.getUTCMonth(),a._a[Od]=c.getUTCDate()),b=0;3>b&&null==a._a[b];++b)a._a[b]=f[b]=d[b];for(;7>b;b++)a._a[b]=f[b]=null==a._a[b]?2===b?1:0:a._a[b];24===a._a[Pd]&&0===a._a[Qd]&&0===a._a[Rd]&&0===a._a[Sd]&&(a._nextDay=!0,a._a[Pd]=0),a._d=(a._useUTC?qa:pa).apply(null,f),null!=a._tzm&&a._d.setUTCMinutes(a._d.getUTCMinutes()-a._tzm),a._nextDay&&(a._a[Pd]=24)}}function Ba(a){var b,c,d,e,f,g,h,i;b=a._w,null!=b.GG||null!=b.W||null!=b.E?(f=1,g=4,c=ya(b.GG,a._a[Md],wa(Ka(),1,4).year),d=ya(b.W,1),e=ya(b.E,1),(1>e||e>7)&&(i=!0)):(f=a._locale._week.dow,g=a._locale._week.doy,c=ya(b.gg,a._a[Md],wa(Ka(),f,g).year),d=ya(b.w,1),null!=b.d?(e=b.d,(0>e||e>6)&&(i=!0)):null!=b.e?(e=b.e+f,(b.e<0||b.e>6)&&(i=!0)):e=f),1>d||d>xa(c,f,g)?j(a)._overflowWeeks=!0:null!=i?j(a)._overflowWeekday=!0:(h=va(c,d,e,f,g),a._a[Md]=h.year,a._dayOfYear=h.dayOfYear)}function Ca(b){if(b._f===a.ISO_8601)return void na(b);b._a=[],j(b).empty=!0;var c,d,e,f,g,h=""+b._i,i=h.length,k=0;for(e=V(b._f,b._locale).match(pd)||[],c=0;c<e.length;c++)f=e[c],d=(h.match(X(f,b))||[])[0],d&&(g=h.substr(0,h.indexOf(d)),g.length>0&&j(b).unusedInput.push(g),h=h.slice(h.indexOf(d)+d.length),k+=d.length),sd[f]?(d?j(b).empty=!1:j(b).unusedTokens.push(f),aa(f,d,b)):b._strict&&!d&&j(b).unusedTokens.push(f);j(b).charsLeftOver=i-k,h.length>0&&j(b).unusedInput.push(h),j(b).bigHour===!0&&b._a[Pd]<=12&&b._a[Pd]>0&&(j(b).bigHour=void 0),j(b).parsedDateParts=b._a.slice(0),j(b).meridiem=b._meridiem,b._a[Pd]=Da(b._locale,b._a[Pd],b._meridiem),Aa(b),ma(b)}function Da(a,b,c){var d;return null==c?b:null!=a.meridiemHour?a.meridiemHour(b,c):null!=a.isPM?(d=a.isPM(c),d&&12>b&&(b+=12),d||12!==b||(b=0),b):b}function Ea(a){var b,c,d,e,f;if(0===a._f.length)return j(a).invalidFormat=!0,void(a._d=new Date(NaN));for(e=0;e<a._f.length;e++)f=0,b=n({},a),null!=a._useUTC&&(b._useUTC=a._useUTC),b._f=a._f[e],Ca(b),k(b)&&(f+=j(b).charsLeftOver,f+=10*j(b).unusedTokens.length,j(b).score=f,(null==d||d>f)&&(d=f,c=b));g(a,c||b)}function Fa(a){if(!a._d){var b=L(a._i);a._a=e([b.year,b.month,b.day||b.date,b.hour,b.minute,b.second,b.millisecond],function(a){return a&&parseInt(a,10)}),Aa(a)}}function Ga(a){var b=new o(ma(Ha(a)));return b._nextDay&&(b.add(1,"d"),b._nextDay=void 0),b}function Ha(a){var b=a._i,e=a._f;return a._locale=a._locale||H(a._l),null===b||void 0===e&&""===b?l({nullInput:!0}):("string"==typeof b&&(a._i=b=a._locale.preparse(b)),p(b)?new o(ma(b)):(c(e)?Ea(a):e?Ca(a):d(b)?a._d=b:Ia(a),k(a)||(a._d=null),a))}function Ia(b){var f=b._i;void 0===f?b._d=new Date(a.now()):d(f)?b._d=new Date(f.valueOf()):"string"==typeof f?oa(b):c(f)?(b._a=e(f.slice(0),function(a){return parseInt(a,10)}),Aa(b)):"object"==typeof f?Fa(b):"number"==typeof f?b._d=new Date(f):a.createFromInputFallback(b)}function Ja(a,b,c,d,e){var f={};return"boolean"==typeof c&&(d=c,c=void 0),f._isAMomentObject=!0,f._useUTC=f._isUTC=e,f._l=c,f._i=a,f._f=b,f._strict=d,Ga(f)}function Ka(a,b,c,d){return Ja(a,b,c,d,!1)}function La(a,b){var d,e;if(1===b.length&&c(b[0])&&(b=b[0]),!b.length)return Ka();for(d=b[0],e=1;e<b.length;++e)(!b[e].isValid()||b[e][a](d))&&(d=b[e]);return d}function Ma(){var a=[].slice.call(arguments,0);return La("isBefore",a)}function Na(){var a=[].slice.call(arguments,0);return La("isAfter",a)}function Oa(a){var b=L(a),c=b.year||0,d=b.quarter||0,e=b.month||0,f=b.week||0,g=b.day||0,h=b.hour||0,i=b.minute||0,j=b.second||0,k=b.millisecond||0;this._milliseconds=+k+1e3*j+6e4*i+1e3*h*60*60,this._days=+g+7*f,this._months=+e+3*d+12*c,this._data={},this._locale=H(),this._bubble()}function Pa(a){return a instanceof Oa}function Qa(a,b){R(a,0,0,function(){var a=this.utcOffset(),c="+";return 0>a&&(a=-a,c="-"),c+Q(~~(a/60),2)+b+Q(~~a%60,2)})}function Ra(a,b){var c=(b||"").match(a)||[],d=c[c.length-1]||[],e=(d+"").match(ie)||["-",0,0],f=+(60*e[1])+r(e[2]);return"+"===e[0]?f:-f}function Sa(b,c){var e,f;return c._isUTC?(e=c.clone(),f=(p(b)||d(b)?b.valueOf():Ka(b).valueOf())-e.valueOf(),e._d.setTime(e._d.valueOf()+f),a.updateOffset(e,!1),e):Ka(b).local()}function Ta(a){return 15*-Math.round(a._d.getTimezoneOffset()/15)}function Ua(b,c){var d,e=this._offset||0;return this.isValid()?null!=b?("string"==typeof b?b=Ra(Hd,b):Math.abs(b)<16&&(b=60*b),!this._isUTC&&c&&(d=Ta(this)),this._offset=b,this._isUTC=!0,null!=d&&this.add(d,"m"),e!==b&&(!c||this._changeInProgress?jb(this,db(b-e,"m"),1,!1):this._changeInProgress||(this._changeInProgress=!0,a.updateOffset(this,!0),this._changeInProgress=null)),this):this._isUTC?e:Ta(this):null!=b?this:NaN}function Va(a,b){return null!=a?("string"!=typeof a&&(a=-a),this.utcOffset(a,b),this):-this.utcOffset()}function Wa(a){return this.utcOffset(0,a)}function Xa(a){return this._isUTC&&(this.utcOffset(0,a),this._isUTC=!1,a&&this.subtract(Ta(this),"m")),this}function Ya(){return this._tzm?this.utcOffset(this._tzm):"string"==typeof this._i&&this.utcOffset(Ra(Gd,this._i)),this}function Za(a){return this.isValid()?(a=a?Ka(a).utcOffset():0,(this.utcOffset()-a)%60===0):!1}function $a(){return this.utcOffset()>this.clone().month(0).utcOffset()||this.utcOffset()>this.clone().month(5).utcOffset()}function _a(){if(!m(this._isDSTShifted))return this._isDSTShifted;var a={};if(n(a,this),a=Ha(a),a._a){var b=a._isUTC?h(a._a):Ka(a._a);this._isDSTShifted=this.isValid()&&s(a._a,b.toArray())>0}else this._isDSTShifted=!1;return this._isDSTShifted}function ab(){return this.isValid()?!this._isUTC:!1}function bb(){return this.isValid()?this._isUTC:!1}function cb(){return this.isValid()?this._isUTC&&0===this._offset:!1}function db(a,b){var c,d,e,g=a,h=null;return Pa(a)?g={ms:a._milliseconds,d:a._days,M:a._months}:"number"==typeof a?(g={},b?g[b]=a:g.milliseconds=a):(h=je.exec(a))?(c="-"===h[1]?-1:1,g={y:0,d:r(h[Od])*c,h:r(h[Pd])*c,m:r(h[Qd])*c,s:r(h[Rd])*c,ms:r(h[Sd])*c}):(h=ke.exec(a))?(c="-"===h[1]?-1:1,g={y:eb(h[2],c),M:eb(h[3],c),w:eb(h[4],c),d:eb(h[5],c),h:eb(h[6],c),m:eb(h[7],c),s:eb(h[8],c)}):null==g?g={}:"object"==typeof g&&("from"in g||"to"in g)&&(e=gb(Ka(g.from),Ka(g.to)),g={},g.ms=e.milliseconds,g.M=e.months),d=new Oa(g),Pa(a)&&f(a,"_locale")&&(d._locale=a._locale),d}function eb(a,b){var c=a&&parseFloat(a.replace(",","."));return(isNaN(c)?0:c)*b}function fb(a,b){var c={milliseconds:0,months:0};return c.months=b.month()-a.month()+12*(b.year()-a.year()),a.clone().add(c.months,"M").isAfter(b)&&--c.months,c.milliseconds=+b-+a.clone().add(c.months,"M"),c}function gb(a,b){var c;return a.isValid()&&b.isValid()?(b=Sa(b,a),a.isBefore(b)?c=fb(a,b):(c=fb(b,a),c.milliseconds=-c.milliseconds,c.months=-c.months),c):{milliseconds:0,months:0}}function hb(a){return 0>a?-1*Math.round(-1*a):Math.round(a)}function ib(a,b){return function(c,d){var e,f;return null===d||isNaN(+d)||(v(b,"moment()."+b+"(period, number) is deprecated. Please use moment()."+b+"(number, period)."),f=c,c=d,d=f),c="string"==typeof c?+c:c,e=db(c,d),jb(this,e,a),this}}function jb(b,c,d,e){var f=c._milliseconds,g=hb(c._days),h=hb(c._months);b.isValid()&&(e=null==e?!0:e,f&&b._d.setTime(b._d.valueOf()+f*d),g&&O(b,"Date",N(b,"Date")+g*d),h&&ga(b,N(b,"Month")+h*d),e&&a.updateOffset(b,g||h))}function kb(a,b){var c=a||Ka(),d=Sa(c,this).startOf("day"),e=this.diff(d,"days",!0),f=-6>e?"sameElse":-1>e?"lastWeek":0>e?"lastDay":1>e?"sameDay":2>e?"nextDay":7>e?"nextWeek":"sameElse",g=b&&(w(b[f])?b[f]():b[f]);return this.format(g||this.localeData().calendar(f,this,Ka(c)))}function lb(){return new o(this)}function mb(a,b){var c=p(a)?a:Ka(a);return this.isValid()&&c.isValid()?(b=K(m(b)?"millisecond":b),"millisecond"===b?this.valueOf()>c.valueOf():c.valueOf()<this.clone().startOf(b).valueOf()):!1}function nb(a,b){var c=p(a)?a:Ka(a);return this.isValid()&&c.isValid()?(b=K(m(b)?"millisecond":b),"millisecond"===b?this.valueOf()<c.valueOf():this.clone().endOf(b).valueOf()<c.valueOf()):!1}function ob(a,b,c,d){return d=d||"()",("("===d[0]?this.isAfter(a,c):!this.isBefore(a,c))&&(")"===d[1]?this.isBefore(b,c):!this.isAfter(b,c))}function pb(a,b){var c,d=p(a)?a:Ka(a);return this.isValid()&&d.isValid()?(b=K(b||"millisecond"),"millisecond"===b?this.valueOf()===d.valueOf():(c=d.valueOf(),this.clone().startOf(b).valueOf()<=c&&c<=this.clone().endOf(b).valueOf())):!1}function qb(a,b){return this.isSame(a,b)||this.isAfter(a,b)}function rb(a,b){return this.isSame(a,b)||this.isBefore(a,b)}function sb(a,b,c){var d,e,f,g;return this.isValid()?(d=Sa(a,this),d.isValid()?(e=6e4*(d.utcOffset()-this.utcOffset()),b=K(b),"year"===b||"month"===b||"quarter"===b?(g=tb(this,d),"quarter"===b?g/=3:"year"===b&&(g/=12)):(f=this-d,g="second"===b?f/1e3:"minute"===b?f/6e4:"hour"===b?f/36e5:"day"===b?(f-e)/864e5:"week"===b?(f-e)/6048e5:f),c?g:q(g)):NaN):NaN}function tb(a,b){var c,d,e=12*(b.year()-a.year())+(b.month()-a.month()),f=a.clone().add(e,"months");return 0>b-f?(c=a.clone().add(e-1,"months"),d=(b-f)/(f-c)):(c=a.clone().add(e+1,"months"),d=(b-f)/(c-f)),-(e+d)||0}function ub(){return this.clone().locale("en").format("ddd MMM DD YYYY HH:mm:ss [GMT]ZZ")}function vb(){var a=this.clone().utc();return 0<a.year()&&a.year()<=9999?w(Date.prototype.toISOString)?this.toDate().toISOString():U(a,"YYYY-MM-DD[T]HH:mm:ss.SSS[Z]"):U(a,"YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]")}function wb(b){b||(b=this.isUtc()?a.defaultFormatUtc:a.defaultFormat);var c=U(this,b);return this.localeData().postformat(c)}function xb(a,b){return this.isValid()&&(p(a)&&a.isValid()||Ka(a).isValid())?db({to:this,from:a}).locale(this.locale()).humanize(!b):this.localeData().invalidDate()}function yb(a){return this.from(Ka(),a)}function zb(a,b){return this.isValid()&&(p(a)&&a.isValid()||Ka(a).isValid())?db({from:this,to:a}).locale(this.locale()).humanize(!b):this.localeData().invalidDate()}function Ab(a){return this.to(Ka(),a)}function Bb(a){var b;return void 0===a?this._locale._abbr:(b=H(a),null!=b&&(this._locale=b),this)}function Cb(){return this._locale}function Db(a){switch(a=K(a)){case"year":this.month(0);case"quarter":case"month":this.date(1);case"week":case"isoWeek":case"day":case"date":this.hours(0);case"hour":this.minutes(0);case"minute":this.seconds(0);case"second":this.milliseconds(0)}return"week"===a&&this.weekday(0),"isoWeek"===a&&this.isoWeekday(1),"quarter"===a&&this.month(3*Math.floor(this.month()/3)),this}function Eb(a){return a=K(a),void 0===a||"millisecond"===a?this:("date"===a&&(a="day"),this.startOf(a).add(1,"isoWeek"===a?"week":a).subtract(1,"ms"))}function Fb(){return this._d.valueOf()-6e4*(this._offset||0)}function Gb(){return Math.floor(this.valueOf()/1e3)}function Hb(){return this._offset?new Date(this.valueOf()):this._d}function Ib(){var a=this;return[a.year(),a.month(),a.date(),a.hour(),a.minute(),a.second(),a.millisecond()]}function Jb(){var a=this;return{years:a.year(),months:a.month(),date:a.date(),hours:a.hours(),minutes:a.minutes(),seconds:a.seconds(),milliseconds:a.milliseconds()}}function Kb(){return this.isValid()?this.toISOString():null}function Lb(){return k(this)}function Mb(){return g({},j(this))}function Nb(){return j(this).overflow}function Ob(){return{input:this._i,format:this._f,locale:this._locale,isUTC:this._isUTC,strict:this._strict}}function Pb(a,b){R(0,[a,a.length],0,b)}function Qb(a){return Ub.call(this,a,this.week(),this.weekday(),this.localeData()._week.dow,this.localeData()._week.doy)}function Rb(a){return Ub.call(this,a,this.isoWeek(),this.isoWeekday(),1,4)}function Sb(){return xa(this.year(),1,4)}function Tb(){var a=this.localeData()._week;return xa(this.year(),a.dow,a.doy)}function Ub(a,b,c,d,e){var f;return null==a?wa(this,d,e).year:(f=xa(a,d,e),b>f&&(b=f),Vb.call(this,a,b,c,d,e))}function Vb(a,b,c,d,e){var f=va(a,b,c,d,e),g=qa(f.year,0,f.dayOfYear);return this.year(g.getUTCFullYear()),this.month(g.getUTCMonth()),this.date(g.getUTCDate()),this}function Wb(a){return null==a?Math.ceil((this.month()+1)/3):this.month(3*(a-1)+this.month()%3)}function Xb(a){return wa(a,this._week.dow,this._week.doy).week}function Yb(){return this._week.dow}function Zb(){return this._week.doy}function $b(a){var b=this.localeData().week(this);return null==a?b:this.add(7*(a-b),"d")}function _b(a){var b=wa(this,1,4).week;return null==a?b:this.add(7*(a-b),"d")}function ac(a,b){return"string"!=typeof a?a:isNaN(a)?(a=b.weekdaysParse(a),"number"==typeof a?a:null):parseInt(a,10)}function bc(a,b){return c(this._weekdays)?this._weekdays[a.day()]:this._weekdays[this._weekdays.isFormat.test(b)?"format":"standalone"][a.day()]}function cc(a){return this._weekdaysShort[a.day()]}function dc(a){return this._weekdaysMin[a.day()]}function ec(a,b,c){var d,e,f,g=a.toLocaleLowerCase();if(!this._weekdaysParse)for(this._weekdaysParse=[],this._shortWeekdaysParse=[],this._minWeekdaysParse=[],d=0;7>d;++d)f=h([2e3,1]).day(d),this._minWeekdaysParse[d]=this.weekdaysMin(f,"").toLocaleLowerCase(),this._shortWeekdaysParse[d]=this.weekdaysShort(f,"").toLocaleLowerCase(),this._weekdaysParse[d]=this.weekdays(f,"").toLocaleLowerCase();return c?"dddd"===b?(e=md.call(this._weekdaysParse,g),-1!==e?e:null):"ddd"===b?(e=md.call(this._shortWeekdaysParse,g),-1!==e?e:null):(e=md.call(this._minWeekdaysParse,g),-1!==e?e:null):"dddd"===b?(e=md.call(this._weekdaysParse,g),-1!==e?e:(e=md.call(this._shortWeekdaysParse,g),-1!==e?e:(e=md.call(this._minWeekdaysParse,g),-1!==e?e:null))):"ddd"===b?(e=md.call(this._shortWeekdaysParse,g),-1!==e?e:(e=md.call(this._weekdaysParse,g),-1!==e?e:(e=md.call(this._minWeekdaysParse,g),-1!==e?e:null))):(e=md.call(this._minWeekdaysParse,g),-1!==e?e:(e=md.call(this._weekdaysParse,g),-1!==e?e:(e=md.call(this._shortWeekdaysParse,g),-1!==e?e:null)))}function fc(a,b,c){var d,e,f;if(this._weekdaysParseExact)return ec.call(this,a,b,c);for(this._weekdaysParse||(this._weekdaysParse=[],this._minWeekdaysParse=[],this._shortWeekdaysParse=[],this._fullWeekdaysParse=[]),d=0;7>d;d++){if(e=h([2e3,1]).day(d),c&&!this._fullWeekdaysParse[d]&&(this._fullWeekdaysParse[d]=new RegExp("^"+this.weekdays(e,"").replace(".",".?")+"$","i"),this._shortWeekdaysParse[d]=new RegExp("^"+this.weekdaysShort(e,"").replace(".",".?")+"$","i"),this._minWeekdaysParse[d]=new RegExp("^"+this.weekdaysMin(e,"").replace(".",".?")+"$","i")),this._weekdaysParse[d]||(f="^"+this.weekdays(e,"")+"|^"+this.weekdaysShort(e,"")+"|^"+this.weekdaysMin(e,""),this._weekdaysParse[d]=new RegExp(f.replace(".",""),"i")),c&&"dddd"===b&&this._fullWeekdaysParse[d].test(a))return d;if(c&&"ddd"===b&&this._shortWeekdaysParse[d].test(a))return d;if(c&&"dd"===b&&this._minWeekdaysParse[d].test(a))return d;if(!c&&this._weekdaysParse[d].test(a))return d}}function gc(a){if(!this.isValid())return null!=a?this:NaN;var b=this._isUTC?this._d.getUTCDay():this._d.getDay();return null!=a?(a=ac(a,this.localeData()),this.add(a-b,"d")):b}function hc(a){if(!this.isValid())return null!=a?this:NaN;var b=(this.day()+7-this.localeData()._week.dow)%7;return null==a?b:this.add(a-b,"d")}function ic(a){return this.isValid()?null==a?this.day()||7:this.day(this.day()%7?a:a-7):null!=a?this:NaN}function jc(a){return this._weekdaysParseExact?(f(this,"_weekdaysRegex")||mc.call(this),a?this._weekdaysStrictRegex:this._weekdaysRegex):this._weekdaysStrictRegex&&a?this._weekdaysStrictRegex:this._weekdaysRegex}function kc(a){return this._weekdaysParseExact?(f(this,"_weekdaysRegex")||mc.call(this),a?this._weekdaysShortStrictRegex:this._weekdaysShortRegex):this._weekdaysShortStrictRegex&&a?this._weekdaysShortStrictRegex:this._weekdaysShortRegex}function lc(a){return this._weekdaysParseExact?(f(this,"_weekdaysRegex")||mc.call(this),a?this._weekdaysMinStrictRegex:this._weekdaysMinRegex):this._weekdaysMinStrictRegex&&a?this._weekdaysMinStrictRegex:this._weekdaysMinRegex}function mc(){function a(a,b){return b.length-a.length}var b,c,d,e,f,g=[],i=[],j=[],k=[];for(b=0;7>b;b++)c=h([2e3,1]).day(b),d=this.weekdaysMin(c,""),e=this.weekdaysShort(c,""),f=this.weekdays(c,""),g.push(d),i.push(e),j.push(f),k.push(d),k.push(e),k.push(f);for(g.sort(a),i.sort(a),j.sort(a),k.sort(a),b=0;7>b;b++)i[b]=Z(i[b]),j[b]=Z(j[b]),k[b]=Z(k[b]);this._weekdaysRegex=new RegExp("^("+k.join("|")+")","i"),this._weekdaysShortRegex=this._weekdaysRegex,this._weekdaysMinRegex=this._weekdaysRegex,this._weekdaysStrictRegex=new RegExp("^("+j.join("|")+")","i"),this._weekdaysShortStrictRegex=new RegExp("^("+i.join("|")+")","i"),this._weekdaysMinStrictRegex=new RegExp("^("+g.join("|")+")","i")}function nc(a){var b=Math.round((this.clone().startOf("day")-this.clone().startOf("year"))/864e5)+1;return null==a?b:this.add(a-b,"d")}function oc(){return this.hours()%12||12}function pc(){return this.hours()||24}function qc(a,b){R(a,0,0,function(){return this.localeData().meridiem(this.hours(),this.minutes(),b)})}function rc(a,b){return b._meridiemParse}function sc(a){return"p"===(a+"").toLowerCase().charAt(0)}function tc(a,b,c){return a>11?c?"pm":"PM":c?"am":"AM"}function uc(a,b){b[Sd]=r(1e3*("0."+a))}function vc(){return this._isUTC?"UTC":""}function wc(){return this._isUTC?"Coordinated Universal Time":""}function xc(a){return Ka(1e3*a)}function yc(){return Ka.apply(null,arguments).parseZone()}function zc(a,b,c){var d=this._calendar[a];return w(d)?d.call(b,c):d}function Ac(a){var b=this._longDateFormat[a],c=this._longDateFormat[a.toUpperCase()];return b||!c?b:(this._longDateFormat[a]=c.replace(/MMMM|MM|DD|dddd/g,function(a){return a.slice(1)}),this._longDateFormat[a])}function Bc(){return this._invalidDate}function Cc(a){return this._ordinal.replace("%d",a)}function Dc(a){return a}function Ec(a,b,c,d){var e=this._relativeTime[c];return w(e)?e(a,b,c,d):e.replace(/%d/i,a)}function Fc(a,b){var c=this._relativeTime[a>0?"future":"past"];return w(c)?c(b):c.replace(/%s/i,b)}function Gc(a,b,c,d){var e=H(),f=h().set(d,b);return e[c](f,a)}function Hc(a,b,c){if("number"==typeof a&&(b=a,a=void 0),a=a||"",null!=b)return Gc(a,b,c,"month");var d,e=[];for(d=0;12>d;d++)e[d]=Gc(a,d,c,"month");return e}function Ic(a,b,c,d){"boolean"==typeof a?("number"==typeof b&&(c=b,b=void 0),b=b||""):(b=a,c=b,a=!1,"number"==typeof b&&(c=b,b=void 0),b=b||"");var e=H(),f=a?e._week.dow:0;if(null!=c)return Gc(b,(c+f)%7,d,"day");var g,h=[];for(g=0;7>g;g++)h[g]=Gc(b,(g+f)%7,d,"day");return h}function Jc(a,b){return Hc(a,b,"months")}function Kc(a,b){return Hc(a,b,"monthsShort")}function Lc(a,b,c){return Ic(a,b,c,"weekdays")}function Mc(a,b,c){return Ic(a,b,c,"weekdaysShort")}function Nc(a,b,c){return Ic(a,b,c,"weekdaysMin")}function Oc(){var a=this._data;return this._milliseconds=Le(this._milliseconds),this._days=Le(this._days),this._months=Le(this._months),a.milliseconds=Le(a.milliseconds),a.seconds=Le(a.seconds),a.minutes=Le(a.minutes),a.hours=Le(a.hours),a.months=Le(a.months),a.years=Le(a.years),this}function Pc(a,b,c,d){var e=db(b,c);return a._milliseconds+=d*e._milliseconds,a._days+=d*e._days,a._months+=d*e._months,a._bubble()}function Qc(a,b){return Pc(this,a,b,1)}function Rc(a,b){return Pc(this,a,b,-1)}function Sc(a){return 0>a?Math.floor(a):Math.ceil(a)}function Tc(){var a,b,c,d,e,f=this._milliseconds,g=this._days,h=this._months,i=this._data;return f>=0&&g>=0&&h>=0||0>=f&&0>=g&&0>=h||(f+=864e5*Sc(Vc(h)+g),g=0,h=0),i.milliseconds=f%1e3,a=q(f/1e3),i.seconds=a%60,b=q(a/60),i.minutes=b%60,c=q(b/60),i.hours=c%24,g+=q(c/24),e=q(Uc(g)),h+=e,g-=Sc(Vc(e)),d=q(h/12),h%=12,i.days=g,i.months=h,i.years=d,this}function Uc(a){return 4800*a/146097}function Vc(a){return 146097*a/4800}function Wc(a){var b,c,d=this._milliseconds;if(a=K(a),"month"===a||"year"===a)return b=this._days+d/864e5,c=this._months+Uc(b),"month"===a?c:c/12;switch(b=this._days+Math.round(Vc(this._months)),a){case"week":return b/7+d/6048e5;case"day":return b+d/864e5;case"hour":return 24*b+d/36e5;case"minute":return 1440*b+d/6e4;case"second":return 86400*b+d/1e3;case"millisecond":return Math.floor(864e5*b)+d;default:throw new Error("Unknown unit "+a)}}function Xc(){return this._milliseconds+864e5*this._days+this._months%12*2592e6+31536e6*r(this._months/12)}function Yc(a){return function(){return this.as(a)}}function Zc(a){return a=K(a),this[a+"s"]()}function $c(a){return function(){return this._data[a]}}function _c(){return q(this.days()/7)}function ad(a,b,c,d,e){return e.relativeTime(b||1,!!c,a,d)}function bd(a,b,c){var d=db(a).abs(),e=_e(d.as("s")),f=_e(d.as("m")),g=_e(d.as("h")),h=_e(d.as("d")),i=_e(d.as("M")),j=_e(d.as("y")),k=e<af.s&&["s",e]||1>=f&&["m"]||f<af.m&&["mm",f]||1>=g&&["h"]||g<af.h&&["hh",g]||1>=h&&["d"]||h<af.d&&["dd",h]||1>=i&&["M"]||i<af.M&&["MM",i]||1>=j&&["y"]||["yy",j];
......
......@@ -21,20 +21,20 @@ global.HTMLCanvasElement = {};
;(function (env) {
"use strict";
const process = require("process");
var process = require("process");
env._html5_weakmap = new WeakMap();
function EventTarget() { env._html5_weakmap.set(this, Object.create(null)); }
EventTarget.prototype.addEventListener = function (type, listener) {
if (typeof listener !== "function") return;
const em = env._html5_weakmap.get(this);
var em = env._html5_weakmap.get(this);
type = "" + type;
if (em[type]) em[type].push(listener);
else em[type] = [listener];
};
EventTarget.prototype.removeEventListener = function (type, listener) {
if (typeof listener !== "function") return;
const em = env._html5_weakmap.get(this);
var em = env._html5_weakmap.get(this);
var i = 0, listeners = em[type];
type = "" + type;
if (listeners) for (; i < listeners.length; ++i) if (listeners[i] === listener) {
......@@ -44,7 +44,7 @@ global.HTMLCanvasElement = {};
}
};
EventTarget.prototype.dispatchEvent = function (event) {
const type = "" + event.type,
var type = "" + event.type,
em = env._html5_weakmap.get(this),
ontype = "on" + type;
var i = 0, listeners;
......@@ -59,7 +59,7 @@ global.HTMLCanvasElement = {};
function Blob(blobParts, options) {
// https://developer.mozilla.org/en-US/docs/Web/API/Blob
var i = 0; const priv = {}, buffers = [];
var i = 0; var priv = {}, buffers = [];
env._html5_weakmap.set(this, priv);
for (; i < blobParts.length; ++i) {
if (Buffer.isBuffer(blobParts[i])) {
......@@ -87,27 +87,27 @@ global.HTMLCanvasElement = {};
FileReader.prototype = Object.create(EventTarget.prototype);
Object.defineProperty(FileReader, "constructor", {value: FileReader});
FileReader.prototype.readAsText = function (blob) {
const priv = env._html5_weakmap.get(blob);
const text = priv.data.toString();
const event = Object.freeze({type: "load", target: this});
var priv = env._html5_weakmap.get(blob);
var text = priv.data.toString();
var event = Object.freeze({type: "load", target: this});
process.nextTick(() => {
this.result = text;
this.dispatchEvent(event);
});
};
FileReader.prototype.readAsArrayBuffer = function (blob) {
const priv = env._html5_weakmap.get(blob);
const arrayBuffer = new Uint8Array(priv.data).buffer;
const event = Object.freeze({type: "load", target: this});
var priv = env._html5_weakmap.get(blob);
var arrayBuffer = new Uint8Array(priv.data).buffer;
var event = Object.freeze({type: "load", target: this});
process.nextTick(() => {
this.result = arrayBuffer;
this.dispatchEvent(event);
});
};
FileReader.prototype.readAsDataURL = function (blob) {
const priv = env._html5_weakmap.get(blob);
const dataUrl = "data:" + blob.type + ";base64," + priv.data.toString("base64");
const event = Object.freeze({type: "load", target: this});
var priv = env._html5_weakmap.get(blob);
var dataUrl = "data:" + blob.type + ";base64," + priv.data.toString("base64");
var event = Object.freeze({type: "load", target: this});
process.nextTick(() => {
this.result = dataUrl;
this.dispatchEvent(event);
......@@ -267,7 +267,7 @@ case 5: case 8: case 11: case 14: case 16:
this.$ = $$[$0];
break;
case 6:
this.$ = mkComplexQuery('OR', [$$[$0-1], $$[$0]]);
this.$ = mkComplexQuery('AND', [$$[$0-1], $$[$0]]);
break;
case 7:
this.$ = mkComplexQuery('OR', [$$[$0-2], $$[$0]]);
......@@ -1234,8 +1234,8 @@ return new Parser;
return new RegExp("^" + stringEscapeRegexpCharacters(string) + "$");
}
return new RegExp("^" + stringEscapeRegexpCharacters(string)
.replace(regexp_percent, '.*')
.replace(regexp_underscore, '.') + "$");
.replace(regexp_percent, '[\\s\\S]*')
.replace(regexp_underscore, '.') + "$", "i");
}
/**
......@@ -1536,7 +1536,8 @@ return new Parser;
matchMethod = null,
operator = this.operator,
value = null,
key = this.key;
key = this.key,
k;
if (!(regexp_comparaison.test(operator))) {
// `operator` is not correct, we have to change it to "like" or "="
......@@ -1555,6 +1556,22 @@ return new Parser;
key = this._key_schema.key_set[key];
}
// match with all the fields if key is empty
if (key === '') {
matchMethod = this.like;
value = '%' + this.value + '%';
for (k in item) {
if (item.hasOwnProperty(k)) {
if (k !== '__id' && item[k]) {
if (matchMethod(item[k], value) === true) {
return true;
}
}
}
}
return false;
}
if (typeof key === 'object') {
checkKey(key);
object_value = item[key.read_from];
......@@ -2570,6 +2587,15 @@ return new Parser;
CONFLICT_KEEP_REMOTE = 2,
CONFLICT_CONTINUE = 3;
function SkipError(message) {
if ((message !== undefined) && (typeof message !== "string")) {
throw new TypeError('You must pass a string.');
}
this.message = message || "Skip some asynchronous code";
}
SkipError.prototype = new Error();
SkipError.prototype.constructor = SkipError;
/****************************************************
Use a local jIO to read/write/search documents
Synchronize in background those document with a remote jIO.
......@@ -2588,20 +2614,33 @@ return new Parser;
function ReplicateStorage(spec) {
this._query_options = spec.query || {};
if (spec.signature_hash_key !== undefined) {
this._query_options.select_list = [spec.signature_hash_key];
}
this._signature_hash_key = spec.signature_hash_key;
this._local_sub_storage = jIO.createJIO(spec.local_sub_storage);
this._remote_sub_storage = jIO.createJIO(spec.remote_sub_storage);
if (spec.hasOwnProperty('signature_sub_storage')) {
this._signature_sub_storage = jIO.createJIO(spec.signature_sub_storage);
this._custom_signature_sub_storage = true;
} else {
this._signature_hash = "_replicate_" + generateHash(
stringify(spec.local_sub_storage) +
stringify(spec.remote_sub_storage) +
stringify(this._query_options)
);
this._signature_sub_storage = jIO.createJIO({
type: "query",
sub_storage: {
type: "document",
document_id: this._signature_hash,
sub_storage: spec.signature_storage || spec.local_sub_storage
sub_storage: spec.local_sub_storage
}
});
this._custom_signature_sub_storage = false;
}
this._use_remote_post = spec.use_remote_post || false;
// Number of request we allow browser execution for attachments
......@@ -2744,15 +2783,8 @@ return new Parser;
arguments);
};
ReplicateStorage.prototype.repair = function () {
var context = this,
argument_list = arguments,
skip_document_dict = {};
// Do not sync the signature document
skip_document_dict[context._signature_hash] = null;
function dispatchQueue(function_used, argument_list, number_queue) {
function dispatchQueue(context, function_used, argument_list,
number_queue) {
var result_promise_list = [],
i;
......@@ -2760,10 +2792,12 @@ return new Parser;
queue
.push(function () {
if (argument_list.length > 0) {
var argument_array = argument_list.shift();
argument_array[0] = queue;
var argument_array = argument_list.shift(),
sub_queue = new RSVP.Queue();
argument_array[0] = sub_queue;
function_used.apply(context, argument_array);
pushAndExecute(queue);
return sub_queue;
}
});
}
......@@ -2777,7 +2811,27 @@ return new Parser;
return result_promise_list[0];
}
function propagateAttachmentDeletion(skip_attachment_dict,
function callAllDocsOnStorage(context, storage, cache, cache_key) {
return new RSVP.Queue()
.push(function () {
if (!cache.hasOwnProperty(cache_key)) {
return storage.allDocs(context._query_options)
.push(function (result) {
var i,
cache_entry = {};
for (i = 0; i < result.data.total_rows; i += 1) {
cache_entry[result.data.rows[i].id] = result.data.rows[i].value;
}
cache[cache_key] = cache_entry;
});
}
})
.push(function () {
return cache[cache_key];
});
}
function propagateAttachmentDeletion(context, skip_attachment_dict,
destination,
id, name) {
return destination.removeAttachment(id, name)
......@@ -2789,7 +2843,7 @@ return new Parser;
});
}
function propagateAttachmentModification(skip_attachment_dict,
function propagateAttachmentModification(context, skip_attachment_dict,
destination,
blob, hash, id, name) {
return destination.putAttachment(id, name, blob)
......@@ -2804,7 +2858,8 @@ return new Parser;
});
}
function checkAndPropagateAttachment(skip_attachment_dict,
function checkAndPropagateAttachment(context,
skip_attachment_dict,
status_hash, local_hash, blob,
source, destination, id, name,
conflict_force, conflict_revert,
......@@ -2834,7 +2889,7 @@ return new Parser;
// Deleted on both side, drop signature
return context._signature_sub_storage.removeAttachment(id, name)
.push(function () {
skip_attachment_dict[id] = null;
skip_attachment_dict[name] = null;
});
}
......@@ -2843,7 +2898,7 @@ return new Parser;
hash: local_hash
}))
.push(function () {
skip_document_dict[id] = null;
skip_attachment_dict[name] = null;
});
}
......@@ -2851,11 +2906,12 @@ return new Parser;
// Modified only locally. No conflict or force
if (local_hash === null) {
// Deleted locally
return propagateAttachmentDeletion(skip_attachment_dict,
return propagateAttachmentDeletion(context, skip_attachment_dict,
destination,
id, name);
}
return propagateAttachmentModification(skip_attachment_dict,
return propagateAttachmentModification(context,
skip_attachment_dict,
destination, blob,
local_hash, id, name);
}
......@@ -2869,10 +2925,11 @@ return new Parser;
// Automatically resolve conflict or force revert
if (remote_hash === null) {
// Deleted remotely
return propagateAttachmentDeletion(skip_attachment_dict,
return propagateAttachmentDeletion(context, skip_attachment_dict,
source, id, name);
}
return propagateAttachmentModification(
context,
skip_attachment_dict,
source,
remote_blob,
......@@ -2885,7 +2942,8 @@ return new Parser;
// Minimize conflict if it can be resolved
if (remote_hash === null) {
// Copy remote modification remotely
return propagateAttachmentModification(skip_attachment_dict,
return propagateAttachmentModification(context,
skip_attachment_dict,
destination, blob,
local_hash, id, name);
}
......@@ -2896,8 +2954,9 @@ return new Parser;
});
}
function checkAttachmentSignatureDifference(skip_attachment_dict,
queue, source,
function checkAttachmentSignatureDifference(queue, context,
skip_attachment_dict,
source,
destination, id, name,
conflict_force,
conflict_revert,
......@@ -2938,7 +2997,8 @@ return new Parser;
local_hash = generateHashFromArrayBuffer(array_buffer);
if (local_hash !== status_hash) {
return checkAndPropagateAttachment(skip_attachment_dict,
return checkAndPropagateAttachment(context,
skip_attachment_dict,
status_hash, local_hash, blob,
source, destination, id, name,
conflict_force, conflict_revert,
......@@ -2947,8 +3007,9 @@ return new Parser;
});
}
function checkAttachmentLocalDeletion(skip_attachment_dict,
queue, destination, id, name, source,
function checkAttachmentLocalDeletion(queue, context,
skip_attachment_dict,
destination, id, name, source,
conflict_force, conflict_revert,
conflict_ignore) {
var status_hash;
......@@ -2959,7 +3020,8 @@ return new Parser;
})
.push(function (result) {
status_hash = result.hash;
return checkAndPropagateAttachment(skip_attachment_dict,
return checkAndPropagateAttachment(context,
skip_attachment_dict,
status_hash, null, null,
source, destination, id, name,
conflict_force, conflict_revert,
......@@ -2967,22 +3029,13 @@ return new Parser;
});
}
function pushDocumentAttachment(skip_attachment_dict, id, source,
destination, options) {
var queue = new RSVP.Queue();
return queue
.push(function () {
return RSVP.all([
source.allAttachments(id)
.push(undefined, function (error) {
if ((error instanceof jIO.util.jIOError) &&
(error.status_code === 404)) {
return {};
}
throw error;
}),
context._signature_sub_storage.allAttachments(id)
function pushDocumentAttachment(context,
skip_attachment_dict, id, source,
destination, signature_allAttachments,
options) {
var local_dict = {},
signature_dict = {};
return source.allAttachments(id)
.push(undefined, function (error) {
if ((error instanceof jIO.util.jIOError) &&
(error.status_code === 404)) {
......@@ -2990,23 +3043,20 @@ return new Parser;
}
throw error;
})
]);
})
.push(function (result_list) {
var local_dict = {},
signature_dict = {},
is_modification,
.push(function (source_allAttachments) {
var is_modification,
is_creation,
key;
for (key in result_list[0]) {
if (result_list[0].hasOwnProperty(key)) {
key,
argument_list = [];
for (key in source_allAttachments) {
if (source_allAttachments.hasOwnProperty(key)) {
if (!skip_attachment_dict.hasOwnProperty(key)) {
local_dict[key] = null;
}
}
}
for (key in result_list[1]) {
if (result_list[1].hasOwnProperty(key)) {
for (key in signature_allAttachments) {
if (signature_allAttachments.hasOwnProperty(key)) {
if (!skip_attachment_dict.hasOwnProperty(key)) {
signature_dict[key] = null;
}
......@@ -3020,47 +3070,262 @@ return new Parser;
is_creation = !signature_dict.hasOwnProperty(key)
&& options.check_creation;
if (is_modification === true || is_creation === true) {
checkAttachmentSignatureDifference(skip_attachment_dict,
queue, source,
argument_list.push([undefined,
context,
skip_attachment_dict,
source,
destination, id, key,
options.conflict_force,
options.conflict_revert,
options.conflict_ignore,
is_creation,
is_modification);
is_modification]);
}
}
}
return dispatchQueue(
context,
checkAttachmentSignatureDifference,
argument_list,
context._parallel_operation_attachment_amount
);
})
.push(function () {
var key, argument_list = [];
if (options.check_deletion === true) {
for (key in signature_dict) {
if (signature_dict.hasOwnProperty(key)) {
if (!local_dict.hasOwnProperty(key)) {
checkAttachmentLocalDeletion(skip_attachment_dict,
queue, destination, id, key,
argument_list.push([undefined,
context,
skip_attachment_dict,
destination, id, key,
source,
options.conflict_force,
options.conflict_revert,
options.conflict_ignore);
options.conflict_ignore]);
}
}
}
return dispatchQueue(
context,
checkAttachmentLocalDeletion,
argument_list,
context._parallel_operation_attachment_amount
);
}
});
}
function propagateFastAttachmentDeletion(queue, id, name, storage) {
return queue
.push(function () {
return storage.removeAttachment(id, name);
});
}
function propagateFastAttachmentModification(queue, id, key, source,
destination, signature, hash) {
return queue
.push(function () {
return signature.getAttachment(id, key, {format: 'json'})
.push(undefined, function (error) {
if ((error instanceof jIO.util.jIOError) &&
(error.status_code === 404)) {
return {hash: null};
}
throw error;
})
.push(function (result) {
if (result.hash !== hash) {
return source.getAttachment(id, key)
.push(function (blob) {
return destination.putAttachment(id, key, blob);
})
.push(function () {
return signature.putAttachment(id, key, JSON.stringify({
hash: hash
}));
});
}
});
});
}
function repairFastDocumentAttachment(context, id,
signature_hash,
signature_attachment_hash,
signature_from_local) {
if (signature_hash === signature_attachment_hash) {
// No replication to do
return;
}
return new RSVP.Queue()
.push(function () {
return RSVP.all([
context._signature_sub_storage.allAttachments(id),
context._local_sub_storage.allAttachments(id),
context._remote_sub_storage.allAttachments(id)
]);
})
.push(function (result_list) {
var key,
source_attachment_dict,
destination_attachment_dict,
source,
destination,
push_argument_list = [],
delete_argument_list = [],
signature_attachment_dict = result_list[0],
local_attachment_dict = result_list[1],
remote_attachment_list = result_list[2],
check_local_modification =
context._check_local_attachment_modification,
check_local_creation = context._check_local_attachment_creation,
check_local_deletion = context._check_local_attachment_deletion,
check_remote_modification =
context._check_remote_attachment_modification,
check_remote_creation = context._check_remote_attachment_creation,
check_remote_deletion = context._check_remote_attachment_deletion;
if (signature_from_local) {
source_attachment_dict = local_attachment_dict;
destination_attachment_dict = remote_attachment_list;
source = context._local_sub_storage;
destination = context._remote_sub_storage;
} else {
source_attachment_dict = remote_attachment_list;
destination_attachment_dict = local_attachment_dict;
source = context._remote_sub_storage;
destination = context._local_sub_storage;
check_local_modification = check_remote_modification;
check_local_creation = check_remote_creation;
check_local_deletion = check_remote_deletion;
check_remote_creation = check_local_creation;
check_remote_deletion = check_local_deletion;
}
// Push all source attachments
for (key in source_attachment_dict) {
if (source_attachment_dict.hasOwnProperty(key)) {
if ((check_local_creation &&
!signature_attachment_dict.hasOwnProperty(key)) ||
(check_local_modification &&
signature_attachment_dict.hasOwnProperty(key))) {
push_argument_list.push([
undefined,
id,
key,
source,
destination,
context._signature_sub_storage,
signature_hash
]);
}
}
}
// Delete remaining signature + remote attachments
for (key in signature_attachment_dict) {
if (signature_attachment_dict.hasOwnProperty(key)) {
if (check_local_deletion &&
!source_attachment_dict.hasOwnProperty(key)) {
delete_argument_list.push([
undefined,
id,
key,
context._signature_sub_storage
]);
}
}
}
for (key in destination_attachment_dict) {
if (destination_attachment_dict.hasOwnProperty(key)) {
if (!source_attachment_dict.hasOwnProperty(key)) {
if ((check_local_deletion &&
signature_attachment_dict.hasOwnProperty(key)) ||
(check_remote_creation &&
!signature_attachment_dict.hasOwnProperty(key))) {
delete_argument_list.push([
undefined,
id,
key,
destination
]);
}
}
}
}
return RSVP.all([
dispatchQueue(
context,
propagateFastAttachmentModification,
push_argument_list,
context._parallel_operation_attachment_amount
),
dispatchQueue(
context,
propagateFastAttachmentDeletion,
delete_argument_list,
context._parallel_operation_attachment_amount
)
]);
})
.push(function () {
// Mark that all attachments have been synchronized
return context._signature_sub_storage.put(id, {
hash: signature_hash,
attachment_hash: signature_hash,
from_local: signature_from_local
});
});
}
function repairDocumentAttachment(context, id, signature_hash_key,
signature_hash,
signature_attachment_hash,
signature_from_local) {
if (signature_hash_key !== undefined) {
return repairFastDocumentAttachment(context, id,
signature_hash,
signature_attachment_hash,
signature_from_local);
}
function repairDocumentAttachment(id) {
var skip_attachment_dict = {};
return new RSVP.Queue()
.push(function () {
if (context._check_local_attachment_modification ||
context._check_local_attachment_creation ||
context._check_local_attachment_deletion ||
context._check_remote_attachment_modification ||
context._check_remote_attachment_creation ||
context._check_remote_attachment_deletion) {
return context._signature_sub_storage.allAttachments(id);
}
return {};
})
.push(undefined, function (error) {
if ((error instanceof jIO.util.jIOError) &&
(error.status_code === 404)) {
return {};
}
throw error;
})
.push(function (signature_allAttachments) {
if (context._check_local_attachment_modification ||
context._check_local_attachment_creation ||
context._check_local_attachment_deletion) {
return pushDocumentAttachment(
context,
skip_attachment_dict,
id,
context._local_sub_storage,
context._remote_sub_storage,
signature_allAttachments,
{
conflict_force: (context._conflict_handling ===
CONFLICT_KEEP_LOCAL),
......@@ -3073,18 +3338,24 @@ return new Parser;
check_creation: context._check_local_attachment_creation,
check_deletion: context._check_local_attachment_deletion
}
);
)
.push(function () {
return signature_allAttachments;
});
}
return signature_allAttachments;
})
.push(function () {
.push(function (signature_allAttachments) {
if (context._check_remote_attachment_modification ||
context._check_remote_attachment_creation ||
context._check_remote_attachment_deletion) {
return pushDocumentAttachment(
context,
skip_attachment_dict,
id,
context._remote_sub_storage,
context._local_sub_storage,
signature_allAttachments,
{
use_revert_post: context._use_remote_post,
conflict_force: (context._conflict_handling ===
......@@ -3103,16 +3374,39 @@ return new Parser;
});
}
function propagateModification(source, destination, doc, hash, id,
function propagateModification(context, source, destination, doc, hash, id,
skip_document_dict,
skip_deleted_document_dict,
options) {
var result,
var result = new RSVP.Queue(),
post_id,
to_skip = true;
to_skip = true,
from_local;
if (options === undefined) {
options = {};
}
from_local = options.from_local;
if (doc === null) {
result
.push(function () {
return source.get(id);
})
.push(function (source_doc) {
doc = source_doc;
}, function (error) {
if ((error instanceof jIO.util.jIOError) &&
(error.status_code === 404)) {
throw new SkipError(id);
}
throw error;
});
}
if (options.use_post) {
result = destination.post(doc)
result
.push(function () {
return destination.post(doc);
})
.push(function (new_id) {
to_skip = false;
post_id = new_id;
......@@ -3154,17 +3448,30 @@ return new Parser;
.push(function () {
to_skip = true;
return context._signature_sub_storage.put(post_id, {
"hash": hash
hash: hash,
from_local: from_local
});
})
.push(function () {
skip_document_dict[post_id] = null;
});
} else {
result = destination.put(id, doc)
result
.push(function () {
// Drop signature if the destination document was empty
// but a signature exists
if (options.create_new_document === true) {
delete skip_deleted_document_dict[id];
return context._signature_sub_storage.remove(id);
}
})
.push(function () {
return destination.put(id, doc);
})
.push(function () {
return context._signature_sub_storage.put(id, {
"hash": hash
hash: hash,
from_local: from_local
});
});
}
......@@ -3173,15 +3480,29 @@ return new Parser;
if (to_skip) {
skip_document_dict[id] = null;
}
})
.push(undefined, function (error) {
if (error instanceof SkipError) {
return;
}
throw error;
});
}
function propagateDeletion(destination, id) {
function propagateDeletion(context, destination, id, skip_document_dict,
skip_deleted_document_dict) {
// Do not delete a document if it has an attachment
// ie, replication should prevent losing user data
// Synchronize attachments before, to ensure
// all of them will be deleted too
return repairDocumentAttachment(id)
var result;
if (context._signature_hash_key !== undefined) {
result = destination.remove(id)
.push(function () {
return context._signature_sub_storage.remove(id);
});
} else {
result = repairDocumentAttachment(context, id)
.push(function () {
return destination.allAttachments(id);
})
......@@ -3198,17 +3519,37 @@ return new Parser;
return;
}
throw error;
})
});
}
return result
.push(function () {
skip_document_dict[id] = null;
// No need to sync attachment twice on this document
skip_deleted_document_dict[id] = null;
});
}
function checkAndPropagate(status_hash, local_hash, doc,
function checkAndPropagate(context, skip_document_dict,
skip_deleted_document_dict,
cache, destination_key,
status_hash, local_hash, doc,
source, destination, id,
conflict_force, conflict_revert,
conflict_ignore,
options) {
var from_local = options.from_local;
return new RSVP.Queue()
.push(function () {
if (options.signature_hash_key !== undefined) {
return callAllDocsOnStorage(context, destination,
cache, destination_key)
.push(function (result) {
if (result.hasOwnProperty(id)) {
return [null, result[id][options.signature_hash_key]];
}
return [null, null];
});
}
return destination.get(id)
.push(function (remote_doc) {
return [remote_doc, generateHash(stringify(remote_doc))];
......@@ -3218,11 +3559,12 @@ return new Parser;
return [null, null];
}
throw error;
});
})
.push(function (remote_list) {
var remote_doc = remote_list[0],
remote_hash = remote_list[1];
if (local_hash === remote_hash) {
// Same modifications on both side
if (local_hash === null) {
......@@ -3234,7 +3576,8 @@ return new Parser;
}
return context._signature_sub_storage.put(id, {
"hash": local_hash
hash: local_hash,
from_local: from_local
})
.push(function () {
skip_document_dict[id] = null;
......@@ -3245,12 +3588,20 @@ return new Parser;
// Modified only locally. No conflict or force
if (local_hash === null) {
// Deleted locally
return propagateDeletion(destination, id);
return propagateDeletion(context, destination, id,
skip_document_dict,
skip_deleted_document_dict);
}
return propagateModification(source, destination, doc,
local_hash, id,
return propagateModification(context, source, destination, doc,
local_hash, id, skip_document_dict,
skip_deleted_document_dict,
{use_post: ((options.use_post) &&
(remote_hash === null))});
(remote_hash === null)),
from_local: from_local,
create_new_document:
((remote_hash === null) &&
(status_hash !== null))
});
}
// Conflict cases
......@@ -3262,34 +3613,50 @@ return new Parser;
// Automatically resolve conflict or force revert
if (remote_hash === null) {
// Deleted remotely
return propagateDeletion(source, id);
return propagateDeletion(context, source, id, skip_document_dict,
skip_deleted_document_dict);
}
return propagateModification(
context,
destination,
source,
remote_doc,
remote_hash,
id,
skip_document_dict,
skip_deleted_document_dict,
{use_post: ((options.use_revert_post) &&
(local_hash === null))}
(local_hash === null)),
from_local: !from_local,
create_new_document: ((local_hash === null) &&
(status_hash !== null))}
);
}
// Minimize conflict if it can be resolved
if (remote_hash === null) {
// Copy remote modification remotely
return propagateModification(source, destination, doc,
local_hash, id,
{use_post: options.use_post});
}
return propagateModification(context, source, destination, doc,
local_hash, id, skip_document_dict,
skip_deleted_document_dict,
{use_post: options.use_post,
from_local: from_local,
create_new_document:
(status_hash !== null)});
}
doc = doc || local_hash;
remote_doc = remote_doc || remote_hash;
throw new jIO.util.jIOError("Conflict on '" + id + "': " +
stringify(doc || '') + " !== " +
stringify(remote_doc || ''),
stringify(doc) + " !== " +
stringify(remote_doc),
409);
});
}
function checkLocalDeletion(queue, destination, id, source,
function checkLocalDeletion(queue, context, skip_document_dict,
skip_deleted_document_dict,
cache, destination_key,
destination, id, source,
conflict_force, conflict_revert,
conflict_ignore, options) {
var status_hash;
......@@ -3299,7 +3666,10 @@ return new Parser;
})
.push(function (result) {
status_hash = result.hash;
return checkAndPropagate(status_hash, null, null,
return checkAndPropagate(context, skip_document_dict,
skip_deleted_document_dict,
cache, destination_key,
status_hash, null, null,
source, destination, id,
conflict_force, conflict_revert,
conflict_ignore,
......@@ -3307,37 +3677,33 @@ return new Parser;
});
}
function checkSignatureDifference(queue, source, destination, id,
function checkSignatureDifference(queue, context, skip_document_dict,
skip_deleted_document_dict,
cache, destination_key,
source, destination, id,
conflict_force, conflict_revert,
conflict_ignore,
is_creation, is_modification,
getMethod, options) {
local_hash, status_hash,
options) {
queue
.push(function () {
// Optimisation to save a get call to signature storage
if (is_creation === true) {
return RSVP.all([
getMethod(id),
{hash: null}
]);
}
if (is_modification === true) {
return RSVP.all([
getMethod(id),
context._signature_sub_storage.get(id)
]);
if (local_hash === null) {
// Hash was not provided by the allDocs query
return source.get(id);
}
throw new jIO.util.jIOError("Unexpected call of"
+ " checkSignatureDifference",
409);
return null;
})
.push(function (result_list) {
var doc = result_list[0],
local_hash = generateHash(stringify(doc)),
status_hash = result_list[1].hash;
.push(function (doc) {
if (local_hash === null) {
// Hash was not provided by the allDocs query
local_hash = generateHash(stringify(doc));
}
if (local_hash !== status_hash) {
return checkAndPropagate(status_hash, local_hash, doc,
return checkAndPropagate(context, skip_document_dict,
skip_deleted_document_dict,
cache, destination_key,
status_hash, local_hash, doc,
source, destination, id,
conflict_force, conflict_revert,
conflict_ignore,
......@@ -3346,47 +3712,11 @@ return new Parser;
});
}
function checkBulkSignatureDifference(queue, source, destination, id_list,
document_status_list, options,
conflict_force, conflict_revert,
conflict_ignore) {
queue
.push(function () {
return source.bulk(id_list);
})
.push(function (result_list) {
var i,
argument_list = [];
function getResult(j) {
return function (id) {
if (id !== id_list[j].parameter_list[0]) {
throw new Error("Does not access expected ID " + id);
}
return result_list[j];
};
}
for (i = 0; i < result_list.length; i += 1) {
argument_list[i] = [undefined, source, destination,
id_list[i].parameter_list[0],
conflict_force, conflict_revert,
conflict_ignore,
document_status_list[i].is_creation,
document_status_list[i].is_modification,
getResult(i), options];
}
return dispatchQueue(
checkSignatureDifference,
argument_list,
options.operation_amount
);
});
}
function pushStorage(source, destination, options) {
var queue = new RSVP.Queue(),
argument_list = [],
function pushStorage(context, skip_document_dict,
skip_deleted_document_dict,
cache, source_key, destination_key,
source, destination, signature_allDocs, options) {
var argument_list = [],
argument_list_deletion = [];
if (!options.hasOwnProperty("use_post")) {
options.use_post = false;
......@@ -3394,127 +3724,162 @@ return new Parser;
if (!options.hasOwnProperty("use_revert_post")) {
options.use_revert_post = false;
}
return queue
.push(function () {
return RSVP.all([
source.allDocs(context._query_options),
context._signature_sub_storage.allDocs()
]);
})
.push(function (result_list) {
return callAllDocsOnStorage(context, source, cache, source_key)
.push(function (source_allDocs) {
var i,
local_dict = {},
document_list = [],
document_status_list = [],
signature_dict = {},
is_modification,
is_creation,
key;
for (i = 0; i < result_list[0].data.total_rows; i += 1) {
status_hash,
local_hash,
key,
queue = new RSVP.Queue();
for (key in source_allDocs) {
if (source_allDocs.hasOwnProperty(key)) {
if (!skip_document_dict.hasOwnProperty(key)) {
local_dict[key] = source_allDocs[key];
}
}
}
/*
for (i = 0; i < source_allDocs.data.total_rows; i += 1) {
if (!skip_document_dict.hasOwnProperty(
result_list[0].data.rows[i].id
source_allDocs.data.rows[i].id
)) {
local_dict[result_list[0].data.rows[i].id] = i;
local_dict[source_allDocs.data.rows[i].id] =
source_allDocs.data.rows[i].value;
}
}
for (i = 0; i < result_list[1].data.total_rows; i += 1) {
*/
for (i = 0; i < signature_allDocs.data.total_rows; i += 1) {
if (!skip_document_dict.hasOwnProperty(
result_list[1].data.rows[i].id
signature_allDocs.data.rows[i].id
)) {
signature_dict[result_list[1].data.rows[i].id] = i;
signature_dict[signature_allDocs.data.rows[i].id] =
signature_allDocs.data.rows[i].value.hash;
}
}
i = 0;
for (key in local_dict) {
if (local_dict.hasOwnProperty(key)) {
is_modification = signature_dict.hasOwnProperty(key)
&& options.check_modification;
is_creation = !signature_dict.hasOwnProperty(key)
&& options.check_creation;
if (is_creation === true) {
status_hash = null;
} else if (is_modification === true) {
status_hash = signature_dict[key];
}
local_hash = null;
if (options.signature_hash_key !== undefined) {
local_hash = local_dict[key][options.signature_hash_key];
if (is_modification === true) {
// Bypass fetching all documents and calculating the sha
// Compare the select list values returned by allDocs calls
is_modification = false;
if (local_hash !== status_hash) {
is_modification = true;
}
}
}
if (is_modification === true || is_creation === true) {
if (options.use_bulk_get === true) {
document_list.push({
method: "get",
parameter_list: [key]
});
document_status_list.push({
is_creation: is_creation,
is_modification: is_modification
});
} else {
argument_list[i] = [undefined, source, destination,
argument_list.push([undefined, context, skip_document_dict,
skip_deleted_document_dict,
cache, destination_key,
source, destination,
key,
options.conflict_force,
options.conflict_revert,
options.conflict_ignore,
is_creation, is_modification,
source.get.bind(source),
options];
i += 1;
}
local_hash, status_hash,
options]);
}
}
}
queue
.push(function () {
return dispatchQueue(
context,
checkSignatureDifference,
argument_list,
options.operation_amount
);
});
if (options.check_deletion === true) {
i = 0;
for (key in signature_dict) {
if (signature_dict.hasOwnProperty(key)) {
if (!local_dict.hasOwnProperty(key)) {
argument_list_deletion[i] = [undefined,
if (options.check_deletion === true) {
argument_list_deletion.push([undefined,
context,
skip_document_dict,
skip_deleted_document_dict,
cache, destination_key,
destination, key,
source,
options.conflict_force,
options.conflict_revert,
options.conflict_ignore,
options];
i += 1;
options]);
} else {
skip_deleted_document_dict[key] = null;
}
}
}
}
if (argument_list_deletion.length !== 0) {
queue.push(function () {
return dispatchQueue(
context,
checkLocalDeletion,
argument_list_deletion,
options.operation_amount
);
});
}
if ((options.use_bulk_get === true) && (document_list.length !== 0)) {
checkBulkSignatureDifference(queue, source, destination,
document_list, document_status_list,
options,
options.conflict_force,
options.conflict_revert,
options.conflict_ignore);
}
return queue;
});
}
function repairDocument(queue, id) {
function repairDocument(queue, context, id, signature_hash_key,
signature_hash, signature_attachment_hash,
signature_from_local) {
queue.push(function () {
return repairDocumentAttachment(id);
return repairDocumentAttachment(context, id, signature_hash_key,
signature_hash,
signature_attachment_hash,
signature_from_local);
});
}
ReplicateStorage.prototype.repair = function () {
var context = this,
argument_list = arguments,
skip_document_dict = {},
skip_deleted_document_dict = {},
cache = {};
return new RSVP.Queue()
.push(function () {
// Ensure that the document storage is usable
return context._signature_sub_storage.__storage._sub_storage.get(
if (context._custom_signature_sub_storage === false) {
// Do not sync the signature document
skip_document_dict[context._signature_hash] = null;
return context._signature_sub_storage.__storage._sub_storage
.__storage._sub_storage.get(
context._signature_hash
);
}
})
.push(undefined, function (error) {
if ((error instanceof jIO.util.jIOError) &&
(error.status_code === 404)) {
return context._signature_sub_storage.__storage._sub_storage.put(
return context._signature_sub_storage.__storage._sub_storage
.__storage._sub_storage.put(
context._signature_hash,
{}
);
......@@ -3541,11 +3906,28 @@ return new Parser;
})
.push(function () {
if (context._check_local_modification ||
context._check_local_creation ||
context._check_local_deletion ||
context._check_remote_modification ||
context._check_remote_creation ||
context._check_remote_deletion) {
return context._signature_sub_storage.allDocs({
select_list: ['hash']
});
}
})
.push(function (signature_allDocs) {
if (context._check_local_modification ||
context._check_local_creation ||
context._check_local_deletion) {
return pushStorage(context._local_sub_storage,
return pushStorage(context, skip_document_dict,
skip_deleted_document_dict,
cache, 'local', 'remote',
context._local_sub_storage,
context._remote_sub_storage,
signature_allDocs,
{
use_post: context._use_remote_post,
conflict_force: (context._conflict_handling ===
......@@ -3557,28 +3939,26 @@ return new Parser;
check_modification: context._check_local_modification,
check_creation: context._check_local_creation,
check_deletion: context._check_local_deletion,
operation_amount: context._parallel_operation_amount
});
}
operation_amount: context._parallel_operation_amount,
signature_hash_key: context._signature_hash_key,
from_local: true
})
.push(function () {
// Autoactivate bulk if substorage implements it
// Keep it like this until the bulk API is stabilized
var use_bulk_get = false;
try {
use_bulk_get = context._remote_sub_storage.hasCapacity("bulk_get");
} catch (error) {
if (!((error instanceof jIO.util.jIOError) &&
(error.status_code === 501))) {
throw error;
}
return signature_allDocs;
});
}
return signature_allDocs;
})
.push(function (signature_allDocs) {
if (context._check_remote_modification ||
context._check_remote_creation ||
context._check_remote_deletion) {
return pushStorage(context._remote_sub_storage,
context._local_sub_storage, {
use_bulk_get: use_bulk_get,
return pushStorage(context, skip_document_dict,
skip_deleted_document_dict,
cache, 'remote', 'local',
context._remote_sub_storage,
context._local_sub_storage,
signature_allDocs, {
use_revert_post: context._use_remote_post,
conflict_force: (context._conflict_handling ===
CONFLICT_KEEP_REMOTE),
......@@ -3589,7 +3969,9 @@ return new Parser;
check_modification: context._check_remote_modification,
check_creation: context._check_remote_creation,
check_deletion: context._check_remote_deletion,
operation_amount: context._parallel_operation_amount
operation_amount: context._parallel_operation_amount,
signature_hash_key: context._signature_hash_key,
from_local: false
});
}
})
......@@ -3602,21 +3984,32 @@ return new Parser;
context._check_remote_attachment_deletion) {
// Attachments are synchronized if and only if their parent document
// has been also marked as synchronized.
return context._signature_sub_storage.allDocs()
return context._signature_sub_storage.allDocs({
select_list: ['hash', 'attachment_hash', 'from_local']
})
.push(function (result) {
var i,
argument_list = [],
local_argument_list = [],
row,
len = result.data.total_rows;
for (i = 0; i < len; i += 1) {
argument_list.push(
[undefined, result.data.rows[i].id]
row = result.data.rows[i];
// Do not synchronize attachment if one version of the document
// is deleted but not pushed to the other storage
if (!skip_deleted_document_dict.hasOwnProperty(row.id)) {
local_argument_list.push(
[undefined, context, row.id, context._signature_hash_key,
row.value.hash, row.value.attachment_hash,
row.value.from_local]
);
}
}
return dispatchQueue(
context,
repairDocument,
argument_list,
context._parallel_operation_attachment_amount
local_argument_list,
context._parallel_operation_amount
);
});
}
......@@ -3875,7 +4268,7 @@ return new Parser;
/*jslint nomen: true, unparam: true */
/*global jIO, UriTemplate, FormData, RSVP, URI, Blob,
SimpleQuery, ComplexQuery, btoa*/
SimpleQuery, ComplexQuery*/
(function (jIO, UriTemplate, FormData, RSVP, URI, Blob,
SimpleQuery, ComplexQuery) {
......@@ -3888,9 +4281,8 @@ return new Parser;
"type": "GET",
"url": storage._url,
"xhrFields": {
withCredentials: storage._thisCredentials
},
"headers": storage._headers
withCredentials: true
}
});
})
.push(function (event) {
......@@ -3915,9 +4307,8 @@ return new Parser;
view: options._view
}),
"xhrFields": {
withCredentials: storage._thisCredentials
},
"headers": storage._headers
withCredentials: true
}
});
})
.push(undefined, function (error) {
......@@ -3994,8 +4385,8 @@ return new Parser;
});
}
function extractPropertyFromForm(storage, id) {
return storage.getAttachment(id, "view")
function extractPropertyFromForm(context, id) {
return context.getAttachment(id, "view")
.push(function (blob) {
return jIO.util.readBlobAsText(blob);
})
......@@ -4015,17 +4406,20 @@ return new Parser;
}
this._url = spec.url;
this._default_view_reference = spec.default_view_reference;
this._headers = null;
this._thisCredentials = true;
if (spec.login !== undefined && spec.password !== undefined) {
this._headers = {"Authorization": "Basic "
+ btoa(spec.login + ":" + spec.password)};
this._thisCredentials = false;
}
}
function convertJSONToGet(json) {
return json.data;
var key,
result = json.data;
// Remove all ERP5 hateoas links / convert them into jIO ID
for (key in result) {
if (result.hasOwnProperty(key)) {
if (!result[key]) {
delete result[key];
}
}
}
return result;
}
ERP5Storage.prototype.get = function (id) {
......@@ -4035,59 +4429,8 @@ return new Parser;
});
};
ERP5Storage.prototype.bulk = function (request_list) {
var i,
storage = this,
bulk_list = [];
for (i = 0; i < request_list.length; i += 1) {
if (request_list[i].method !== "get") {
throw new Error("ERP5Storage: not supported " +
request_list[i].method + " in bulk");
}
bulk_list.push({
relative_url: request_list[i].parameter_list[0],
view: storage._default_view_reference
});
}
return getSiteDocument(storage)
.push(function (site_hal) {
var form_data = new FormData();
form_data.append("bulk_list", JSON.stringify(bulk_list));
return jIO.util.ajax({
"type": "POST",
"url": site_hal._actions.bulk.href,
"data": form_data,
// "headers": {
// "Content-Type": "application/json"
// },
"xhrFields": {
withCredentials: storage._thisCredentials
},
"headers": storage._headers
});
})
.push(function (response) {
var result_list = [],
hateoas = JSON.parse(response.target.responseText);
function pushResult(json) {
return extractPropertyFromFormJSON(json)
.push(function (json2) {
return convertJSONToGet(json2);
});
}
for (i = 0; i < hateoas.result_list.length; i += 1) {
result_list.push(pushResult(hateoas.result_list[i]));
}
return RSVP.all(result_list);
});
};
ERP5Storage.prototype.post = function (data) {
var storage = this,
var context = this,
new_id;
return getSiteDocument(this)
......@@ -4100,16 +4443,15 @@ return new Parser;
url: site_hal._actions.add.href,
data: form_data,
xhrFields: {
withCredentials: storage._thisCredentials
},
"headers": storage._headers
withCredentials: true
}
});
})
.push(function (evt) {
var location = evt.target.getResponseHeader("X-Location"),
uri = new URI(location);
new_id = uri.segment(2);
return storage.put(new_id, data);
return context.put(new_id, data);
})
.push(function () {
return new_id;
......@@ -4117,9 +4459,9 @@ return new Parser;
};
ERP5Storage.prototype.put = function (id, data) {
var storage = this;
var context = this;
return extractPropertyFromForm(storage, id)
return extractPropertyFromForm(context, id)
.push(function (result) {
var key,
json = result.form_data,
......@@ -4152,7 +4494,7 @@ return new Parser;
403
);
}
return storage.putAttachment(
return context.putAttachment(
id,
result.action_href,
new Blob([JSON.stringify(form_data)], {type: "application/json"})
......@@ -4161,10 +4503,10 @@ return new Parser;
};
ERP5Storage.prototype.allAttachments = function (id) {
var storage = this;
var context = this;
return getDocumentAndHateoas(this, id)
.push(function () {
if (storage._default_view_reference === undefined) {
if (context._default_view_reference === undefined) {
return {
links: {}
};
......@@ -4177,7 +4519,6 @@ return new Parser;
};
ERP5Storage.prototype.getAttachment = function (id, action, options) {
var storage = this;
if (options === undefined) {
options = {};
}
......@@ -4224,9 +4565,8 @@ return new Parser;
"dataType": "blob",
"url": action,
"xhrFields": {
withCredentials: storage._thisCredentials
},
"headers": storage._headers
withCredentials: true
}
};
if (options.start !== undefined || options.end !== undefined) {
start = options.start || 0;
......@@ -4246,11 +4586,7 @@ return new Parser;
}
range = "bytes=" + start + "-" + end;
}
if (storage._headers === undefined) {
request_options.headers = {Range: range};
} else {
request_options.headers.Range = range;
}
}
return jIO.util.ajax(request_options);
})
......@@ -4269,7 +4605,6 @@ return new Parser;
};
ERP5Storage.prototype.putAttachment = function (id, name, blob) {
var storage = this;
// Assert we use a callable on a document from the ERP5 site
if (name.indexOf(this._url) !== 0) {
throw new jIO.util.jIOError("Can not store outside ERP5: " +
......@@ -4309,10 +4644,10 @@ return new Parser;
"type": "POST",
"url": name,
"data": data,
"dataType": "blob",
"xhrFields": {
withCredentials: storage._thisCredentials
},
"headers": storage._headers
withCredentials: true
}
});
});
};
......@@ -4320,7 +4655,7 @@ return new Parser;
ERP5Storage.prototype.hasCapacity = function (name) {
return ((name === "list") || (name === "query") ||
(name === "select") || (name === "limit") ||
(name === "sort")) || (name === "bulk_get");
(name === "sort"));
};
function isSingleLocalRoles(parsed_query) {
......@@ -4361,7 +4696,6 @@ return new Parser;
// jIO.Query.objectToSearchText(options.query) :
// undefined);
// }
var storage = this;
return getSiteDocument(this)
.push(function (site_hal) {
var query = options.query,
......@@ -4430,9 +4764,8 @@ return new Parser;
local_roles: local_roles
}),
"xhrFields": {
withCredentials: storage._thisCredentials
},
"headers": storage._headers
withCredentials: true
}
});
})
.push(function (response) {
......@@ -4463,10 +4796,9 @@ return new Parser;
}(jIO, UriTemplate, FormData, RSVP, URI, Blob,
SimpleQuery, ComplexQuery));
;/*jslint nomen: true*/
/*global Blob, atob, btoa, RSVP*/
(function (jIO, Blob, atob, btoa, RSVP) {
/*global Blob, RSVP, unescape, escape*/
(function (jIO, Blob, RSVP, unescape, escape) {
"use strict";
/**
* The jIO DocumentStorage extension
*
......@@ -4482,7 +4814,13 @@ return new Parser;
var DOCUMENT_EXTENSION = ".json",
DOCUMENT_REGEXP = new RegExp("^jio_document/([\\w=]+)" +
DOCUMENT_EXTENSION + "$"),
ATTACHMENT_REGEXP = new RegExp("^jio_attachment/([\\w=]+)/([\\w=]+)$");
ATTACHMENT_REGEXP = new RegExp("^jio_attachment/([\\w=]+)/([\\w=]+)$"),
btoa = function (str) {
return window.btoa(unescape(encodeURIComponent(str)));
},
atob = function (str) {
return decodeURIComponent(escape(window.atob(str)));
};
function getSubAttachmentIdFromParam(id, name) {
if (name === undefined) {
......@@ -4689,7 +5027,7 @@ return new Parser;
jIO.addStorage('document', DocumentStorage);
}(jIO, Blob, atob, btoa, RSVP));
}(jIO, Blob, RSVP, unescape, escape));
;/*jslint nomen: true*/
/*global RSVP*/
(function (jIO, RSVP) {
......@@ -5015,9 +5353,9 @@ return new Parser;
}(jIO, sessionStorage, localStorage, RSVP));
;/*jslint indent:2, maxlen: 80, nomen: true */
/*global jIO, RSVP, UriTemplate, SimpleQuery, ComplexQuery, QueryFactory,
Query*/
Query, FormData*/
(function (jIO, RSVP, UriTemplate, SimpleQuery, ComplexQuery, QueryFactory,
Query) {
Query, FormData) {
"use strict";
function getSubIdEqualSubProperty(storage, value, key) {
......@@ -5025,6 +5363,15 @@ return new Parser;
if (storage._no_sub_query_id) {
throw new jIO.util.jIOError('no sub query id active', 404);
}
if (!value) {
throw new jIO.util.jIOError(
'can not find document with ' + key + ' : undefined',
404
);
}
if (storage._mapping_id_memory_dict[value]) {
return storage._mapping_id_memory_dict[value];
}
query = new SimpleQuery({
key: key,
value: value,
......@@ -5045,16 +5392,17 @@ return new Parser;
"limit": storage._query.limit
})
.push(function (data) {
if (data.data.rows.length === 0) {
if (data.data.total_rows === 0) {
throw new jIO.util.jIOError(
"Can not find id",
"Can not find document with (" + key + ", " + value + ")",
404
);
}
if (data.data.rows.length > 1) {
if (data.data.total_rows > 1) {
throw new TypeError("id must be unique field: " + key
+ ", result:" + data.data.rows.toString());
}
storage._mapping_id_memory_dict[value] = data.data.rows[0].id;
return data.data.rows[0].id;
});
}
......@@ -5078,9 +5426,6 @@ return new Parser;
doc.hasOwnProperty(storage._property_for_sub_id)) {
return doc[storage._property_for_sub_id];
}
if (doc.hasOwnProperty(args)) {
return doc[args];
}
}
return getSubIdEqualSubProperty(storage, id, storage._map_id[1]);
},
......@@ -5182,6 +5527,9 @@ return new Parser;
}
}
}
if (storage._map_id[0] === "equalSubProperty") {
storage._mapping_dict[storage._map_id[1]] = ["keep"];
}
if (storage._query.query !== undefined) {
query_list.push(QueryFactory.create(storage._query.query));
}
......@@ -5211,6 +5559,8 @@ return new Parser;
this._query.query = QueryFactory.create(this._query.query);
}
this._default_mapping = {};
this._mapping_id_memory_dict = {};
this._attachment_list = spec.attachment_list || [];
initializeQueryAndDefaultMapping(this);
}
......@@ -5320,12 +5670,20 @@ return new Parser;
return getSubStorageId(storage, argument_list[0])
.push(function (sub_id) {
argument_list[0] = sub_id;
var old_id = argument_list[1];
argument_list[1] = getAttachmentId(
storage,
sub_id,
argument_list[0],
argument_list[1],
method
);
if (storage._attachment_list.length > 0
&& storage._attachment_list.indexOf(old_id) < 0) {
if (method === "get") {
throw new jIO.util.jIOError("unhautorized attachment", 404);
}
return;
}
return storage._sub_storage[method + "Attachment"].apply(
storage._sub_storage,
argument_list
......@@ -5349,12 +5707,25 @@ return new Parser;
this,
doc
),
id = doc[this._property_for_sub_id];
id = doc[this._property_for_sub_id],
storage = this;
if (this._property_for_sub_id && id !== undefined) {
return this._sub_storage.put(id, sub_doc);
}
if (!this._id_mapped || doc[this._id_mapped] !== undefined) {
return this._sub_storage.post(sub_doc);
if (this._id_mapped && doc[this._id_mapped] !== undefined) {
return getSubStorageId(storage, id, doc)
.push(function (sub_id) {
return storage._sub_storage.put(sub_id, sub_doc);
})
.push(function () {
return doc[storage._id_mapped];
})
.push(undefined, function (error) {
if (error instanceof jIO.util.jIOError) {
return storage._sub_storage.post(sub_doc);
}
throw error;
});
}
throw new jIO.util.jIOError(
"post is not supported with id mapped",
......@@ -5391,17 +5762,42 @@ return new Parser;
});
};
MappingStorage.prototype.putAttachment = function (id, attachment_id) {
MappingStorage.prototype.getAttachment = function () {
return handleAttachment(this, arguments, "get");
};
MappingStorage.prototype.putAttachment = function (id, attachment_id, blob) {
var storage = this,
mapping_dict = storage._attachment_mapping_dict;
// THIS IS REALLY BAD, FIND AN OTHER WAY IN FUTURE
if (mapping_dict !== undefined
&& mapping_dict[attachment_id] !== undefined
&& mapping_dict[attachment_id].put !== undefined
&& mapping_dict[attachment_id].put.erp5_put_template !== undefined) {
return getSubStorageId(storage, id)
.push(function (sub_id) {
var url = UriTemplate.parse(
mapping_dict[attachment_id].put.erp5_put_template
).expand({id: sub_id}),
data = new FormData();
data.append("field_my_file", blob);
data.append("form_id", "File_view");
return jIO.util.ajax({
"type": "POST",
"url": url,
"data": data,
"xhrFields": {
withCredentials: true
}
});
});
}
return handleAttachment(this, arguments, "put", id)
.push(function () {
return attachment_id;
});
};
MappingStorage.prototype.getAttachment = function () {
return handleAttachment(this, arguments, "get");
};
MappingStorage.prototype.removeAttachment = function (id, attachment_id) {
return handleAttachment(this, arguments, "remove", id)
.push(function () {
......@@ -5419,7 +5815,8 @@ return new Parser;
.push(function (result) {
var attachment_id,
attachments = {},
mapping_dict = {};
mapping_dict = {},
i;
for (attachment_id in storage._attachment_mapping_dict) {
if (storage._attachment_mapping_dict.hasOwnProperty(attachment_id)) {
mapping_dict[getAttachmentId(storage, sub_id, attachment_id, "get")]
......@@ -5428,6 +5825,8 @@ return new Parser;
}
for (attachment_id in result) {
if (result.hasOwnProperty(attachment_id)) {
if (!(storage._attachment_list.length > 0
&& storage._attachment_list.indexOf(attachment_id) < 0)) {
if (mapping_dict.hasOwnProperty(attachment_id)) {
attachments[mapping_dict[attachment_id]] = {};
} else {
......@@ -5435,6 +5834,12 @@ return new Parser;
}
}
}
}
for (i = 0; i < storage._attachment_list.length; i += 1) {
if (!attachments.hasOwnProperty(storage._attachment_list[i])) {
attachments[storage._attachment_list[i]] = {};
}
}
return attachments;
});
};
......@@ -5498,7 +5903,7 @@ return new Parser;
return one_query;
}
key = mapToMainProperty(storage, one_query.key, {}, {});
if (key) {
if (key !== undefined) {
one_query.key = key;
return one_query;
}
......@@ -5589,4 +5994,5 @@ return new Parser;
};
jIO.addStorage('mapping', MappingStorage);
}(jIO, RSVP, UriTemplate, SimpleQuery, ComplexQuery, QueryFactory, Query));
\ No newline at end of file
}(jIO, RSVP, UriTemplate, SimpleQuery, ComplexQuery, QueryFactory, Query,
FormData));
\ No newline at end of file
......@@ -11,7 +11,7 @@
/*jslint nomen: true, unparam: true */
/*global jIO, UriTemplate, FormData, RSVP, URI, Blob,
SimpleQuery, ComplexQuery, btoa*/
SimpleQuery, ComplexQuery*/
(function (jIO, UriTemplate, FormData, RSVP, URI, Blob,
SimpleQuery, ComplexQuery) {
......@@ -24,9 +24,8 @@
"type": "GET",
"url": storage._url,
"xhrFields": {
withCredentials: storage._thisCredentials
},
"headers": storage._headers
withCredentials: true
}
});
})
.push(function (event) {
......@@ -51,9 +50,8 @@
view: options._view
}),
"xhrFields": {
withCredentials: storage._thisCredentials
},
"headers": storage._headers
withCredentials: true
}
});
})
.push(undefined, function (error) {
......@@ -130,8 +128,8 @@
});
}
function extractPropertyFromForm(storage, id) {
return storage.getAttachment(id, "view")
function extractPropertyFromForm(context, id) {
return context.getAttachment(id, "view")
.push(function (blob) {
return jIO.util.readBlobAsText(blob);
})
......@@ -151,17 +149,20 @@
}
this._url = spec.url;
this._default_view_reference = spec.default_view_reference;
this._headers = null;
this._thisCredentials = true;
if (spec.login !== undefined && spec.password !== undefined) {
this._headers = {"Authorization": "Basic "
+ btoa(spec.login + ":" + spec.password)};
this._thisCredentials = false;
}
}
function convertJSONToGet(json) {
return json.data;
var key,
result = json.data;
// Remove all ERP5 hateoas links / convert them into jIO ID
for (key in result) {
if (result.hasOwnProperty(key)) {
if (!result[key]) {
delete result[key];
}
}
}
return result;
}
ERP5Storage.prototype.get = function (id) {
......@@ -172,7 +173,7 @@
};
ERP5Storage.prototype.post = function (data) {
var storage = this,
var context = this,
new_id;
return getSiteDocument(this)
......@@ -185,16 +186,15 @@
url: site_hal._actions.add.href,
data: form_data,
xhrFields: {
withCredentials: storage._thisCredentials
},
"headers": storage._headers
withCredentials: true
}
});
})
.push(function (evt) {
var location = evt.target.getResponseHeader("X-Location"),
uri = new URI(location);
new_id = uri.segment(2);
return storage.put(new_id, data);
return context.put(new_id, data);
})
.push(function () {
return new_id;
......@@ -202,9 +202,9 @@
};
ERP5Storage.prototype.put = function (id, data) {
var storage = this;
var context = this;
return extractPropertyFromForm(storage, id)
return extractPropertyFromForm(context, id)
.push(function (result) {
var key,
json = result.form_data,
......@@ -237,7 +237,7 @@
403
);
}
return storage.putAttachment(
return context.putAttachment(
id,
result.action_href,
new Blob([JSON.stringify(form_data)], {type: "application/json"})
......@@ -246,10 +246,10 @@
};
ERP5Storage.prototype.allAttachments = function (id) {
var storage = this;
var context = this;
return getDocumentAndHateoas(this, id)
.push(function () {
if (storage._default_view_reference === undefined) {
if (context._default_view_reference === undefined) {
return {
links: {}
};
......@@ -262,7 +262,6 @@
};
ERP5Storage.prototype.getAttachment = function (id, action, options) {
var storage = this;
if (options === undefined) {
options = {};
}
......@@ -309,9 +308,8 @@
"dataType": "blob",
"url": action,
"xhrFields": {
withCredentials: storage._thisCredentials
},
"headers": storage._headers
withCredentials: true
}
};
if (options.start !== undefined || options.end !== undefined) {
start = options.start || 0;
......@@ -331,11 +329,7 @@
}
range = "bytes=" + start + "-" + end;
}
if (storage._headers === undefined) {
request_options.headers = {Range: range};
} else {
request_options.headers.Range = range;
}
}
return jIO.util.ajax(request_options);
})
......@@ -354,7 +348,6 @@
};
ERP5Storage.prototype.putAttachment = function (id, name, blob) {
var storage = this;
// Assert we use a callable on a document from the ERP5 site
if (name.indexOf(this._url) !== 0) {
throw new jIO.util.jIOError("Can not store outside ERP5: " +
......@@ -396,9 +389,8 @@
"data": data,
"dataType": "blob",
"xhrFields": {
withCredentials: storage._thisCredentials
},
"headers": storage._headers
withCredentials: true
}
});
});
};
......@@ -447,7 +439,6 @@
// jIO.Query.objectToSearchText(options.query) :
// undefined);
// }
var storage = this;
return getSiteDocument(this)
.push(function (site_hal) {
var query = options.query,
......@@ -516,9 +507,8 @@
local_roles: local_roles
}),
"xhrFields": {
withCredentials: storage._thisCredentials
},
"headers": storage._headers
withCredentials: true
}
});
})
.push(function (response) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment