@graffiti-garden/implementation-local 0.2.3 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.browser.js +1 -1
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/session-manager.browser.js +1 -1
- package/dist/session-manager.cjs.js +1 -1
- package/dist/session-manager.js +1 -1
- package/dist/src/session-manager.d.ts.map +1 -1
- package/dist/src/utilities.d.ts +2 -2
- package/dist/src/utilities.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/session-manager.ts +1 -0
- package/src/utilities.ts +2 -2
package/dist/index.browser.js
CHANGED
|
@@ -4,7 +4,7 @@ class e{objectToUri(e){return this.locationToUri(e)}}class t extends Error{const
|
|
|
4
4
|
|| ${c} === "boolean" || ${s} === null`).assign(l,n._`[${s}]`)}}o.else(),f(e),o.endIf(),o.if(n._`${l} !== undefined`,(()=>{o.assign(s,l),function({gen:e,parentData:t,parentDataProperty:r},o){e.if(n._`${t} !== undefined`,(()=>e.assign(n._`${t}[${r}]`,o)))}(e,l)}))}(e,r,l):f(e)}))}return d};const a=new Set(["string","number","integer","boolean","null"]);function c(e,t,r,o=s.Correct){const i=o===s.Correct?n.operators.EQ:n.operators.NEQ;let a;switch(e){case"null":return n._`${t} ${i} null`;case"array":a=n._`Array.isArray(${t})`;break;case"object":a=n._`${t} && typeof ${t} == "object" && !Array.isArray(${t})`;break;case"integer":a=c(n._`!(${t} % 1) && !isNaN(${t})`);break;case"number":a=c();break;default:return n._`typeof ${t} ${i} ${e}`}return o===s.Correct?a:(0,n.not)(a);function c(e=n.nil){return(0,n.and)(n._`typeof ${t} == "number"`,e,r?n._`isFinite(${t})`:n.nil)}}function u(e,t,r,s){if(1===e.length)return c(e[0],t,r,s);let i;const a=(0,o.toHash)(e);if(a.array&&a.object){const e=n._`typeof ${t} != "object"`;i=a.null?e:n._`!${t} || ${e}`,delete a.null,delete a.array,delete a.object}else i=n.nil;a.number&&delete a.integer;for(const e in a)i=(0,n.and)(i,c(e,t,r,s));return i}N.checkDataType=c,N.checkDataTypes=u;const l={message:({schema:e})=>`must be ${e}`,params:({schema:e,schemaValue:t})=>"string"==typeof e?n._`{type: ${e}}`:n._`{type: ${t}}`};function f(e){const t=function(e){const{gen:t,data:r,schema:n}=e,s=(0,o.schemaRefOrVal)(e,n,"type");return{gen:t,keyword:"type",data:r,schema:n.type,schemaCode:s,schemaValue:s,parentSchema:n,params:{},it:e}}(e);(0,r.reportError)(t,l)}return N.reportTypeError=f,N}var U,B={};var z,K,F={},J={};function G(){if(z)return J;z=1,Object.defineProperty(J,"__esModule",{value:!0}),J.validateUnion=J.validateArray=J.usePattern=J.callValidateCode=J.schemaProperties=J.allSchemaProperties=J.noPropertyInData=J.propertyInData=J.isOwnProperty=J.hasPropFunc=J.reportMissingProp=J.checkMissingProp=J.checkReportMissingProp=void 0;const e=$(),t=P(),r=A(),n=P();function o(t){return t.scopeValue("func",{ref:Object.prototype.hasOwnProperty,code:e._`Object.prototype.hasOwnProperty`})}function s(t,r,n){return e._`${o(t)}.call(${r}, ${n})`}function i(t,r,n,o){const i=e._`${r}${(0,e.getProperty)(n)} === undefined`;return o?(0,e.or)(i,(0,e.not)(s(t,r,n))):i}function a(e){return e?Object.keys(e).filter((e=>"__proto__"!==e)):[]}J.checkReportMissingProp=function(t,r){const{gen:n,data:o,it:s}=t;n.if(i(n,o,r,s.opts.ownProperties),(()=>{t.setParams({missingProperty:e._`${r}`},!0),t.error()}))},J.checkMissingProp=function({gen:t,data:r,it:{opts:n}},o,s){return(0,e.or)(...o.map((o=>(0,e.and)(i(t,r,o,n.ownProperties),e._`${s} = ${o}`))))},J.reportMissingProp=function(e,t){e.setParams({missingProperty:t},!0),e.error()},J.hasPropFunc=o,J.isOwnProperty=s,J.propertyInData=function(t,r,n,o){const i=e._`${r}${(0,e.getProperty)(n)} !== undefined`;return o?e._`${i} && ${s(t,r,n)}`:i},J.noPropertyInData=i,J.allSchemaProperties=a,J.schemaProperties=function(e,r){return a(r).filter((n=>!(0,t.alwaysValidSchema)(e,r[n])))},J.callValidateCode=function({schemaCode:t,data:n,it:{gen:o,topSchemaRef:s,schemaPath:i,errorPath:a},it:c},u,l,f){const d=f?e._`${t}, ${n}, ${s}${i}`:n,h=[[r.default.instancePath,(0,e.strConcat)(r.default.instancePath,a)],[r.default.parentData,c.parentData],[r.default.parentDataProperty,c.parentDataProperty],[r.default.rootData,r.default.rootData]];c.opts.dynamicRef&&h.push([r.default.dynamicAnchors,r.default.dynamicAnchors]);const p=e._`${d}, ${o.object(...h)}`;return l!==e.nil?e._`${u}.call(${l}, ${p})`:e._`${u}(${p})`};const c=e._`new RegExp`;return J.usePattern=function({gen:t,it:{opts:r}},o){const s=r.unicodeRegExp?"u":"",{regExp:i}=r.code,a=i(o,s);return t.scopeValue("pattern",{key:a.toString(),ref:a,code:e._`${"new RegExp"===i.code?c:(0,n.useFunc)(t,i)}(${o}, ${s})`})},J.validateArray=function(r){const{gen:n,data:o,keyword:s,it:i}=r,a=n.name("valid");if(i.allErrors){const e=n.let("valid",!0);return c((()=>n.assign(e,!1))),e}return n.var(a,!0),c((()=>n.break())),a;function c(i){const c=n.const("len",e._`${o}.length`);n.forRange("i",0,c,(o=>{r.subschema({keyword:s,dataProp:o,dataPropType:t.Type.Num},a),n.if((0,e.not)(a),i)}))}},J.validateUnion=function(r){const{gen:n,schema:o,keyword:s,it:i}=r;if(!Array.isArray(o))throw new Error("ajv implementation error");if(o.some((e=>(0,t.alwaysValidSchema)(i,e)))&&!i.opts.unevaluated)return;const a=n.let("valid",!1),c=n.name("_valid");n.block((()=>o.forEach(((t,o)=>{const i=r.subschema({keyword:s,schemaProp:o,compositeRule:!0},c);n.assign(a,e._`${a} || ${c}`);r.mergeValidEvaluated(i,c)||n.if((0,e.not)(a))})))),r.result(a,(()=>r.reset()),(()=>r.error(!0)))},J}function H(){if(K)return F;K=1,Object.defineProperty(F,"__esModule",{value:!0}),F.validateKeywordUsage=F.validSchemaType=F.funcKeywordCode=F.macroKeywordCode=void 0;const e=$(),t=A(),r=G(),n=C();function o(t){const{gen:r,data:n,it:o}=t;r.if(o.parentData,(()=>r.assign(n,e._`${o.parentData}[${o.parentDataProperty}]`)))}function s(t,r,n){if(void 0===n)throw new Error(`keyword "${r}" failed to compile`);return t.scopeValue("keyword","function"==typeof n?{ref:n}:{ref:n,code:(0,e.stringify)(n)})}return F.macroKeywordCode=function(t,r){const{gen:n,keyword:o,schema:i,parentSchema:a,it:c}=t,u=r.macro.call(c.self,i,a,c),l=s(n,o,u);!1!==c.opts.validateSchema&&c.self.validateSchema(u,!0);const f=n.name("valid");t.subschema({schema:u,schemaPath:e.nil,errSchemaPath:`${c.errSchemaPath}/${o}`,topSchemaRef:l,compositeRule:!0},f),t.pass(f,(()=>t.error(!0)))},F.funcKeywordCode=function(i,a){var c;const{gen:u,keyword:l,schema:f,parentSchema:d,$data:h,it:p}=i;!function({schemaEnv:e},t){if(t.async&&!e.$async)throw new Error("async keyword in sync schema")}(p,a);const m=!h&&a.compile?a.compile.call(p.self,f,d,p):a.validate,v=s(u,l,m),y=u.let("valid");function g(n=(a.async?e._`await `:e.nil)){const o=p.opts.passContext?t.default.this:t.default.self,s=!("compile"in a&&!h||!1===a.schema);u.assign(y,e._`${n}${(0,r.callValidateCode)(i,v,o,s)}`,a.modifying)}function _(t){var r;u.if((0,e.not)(null!==(r=a.valid)&&void 0!==r?r:y),t)}i.block$data(y,(function(){if(!1===a.errors)g(),a.modifying&&o(i),_((()=>i.error()));else{const r=a.async?function(){const t=u.let("ruleErrs",null);return u.try((()=>g(e._`await `)),(r=>u.assign(y,!1).if(e._`${r} instanceof ${p.ValidationError}`,(()=>u.assign(t,e._`${r}.errors`)),(()=>u.throw(r))))),t}():function(){const t=e._`${v}.errors`;return u.assign(t,null),g(e.nil),t}();a.modifying&&o(i),_((()=>function(r,o){const{gen:s}=r;s.if(e._`Array.isArray(${o})`,(()=>{s.assign(t.default.vErrors,e._`${t.default.vErrors} === null ? ${o} : ${t.default.vErrors}.concat(${o})`).assign(t.default.errors,e._`${t.default.vErrors}.length`),(0,n.extendErrors)(r)}),(()=>r.error()))}(i,r)))}})),i.ok(null!==(c=a.valid)&&void 0!==c?c:y)},F.validSchemaType=function(e,t,r=!1){return!t.length||t.some((t=>"array"===t?Array.isArray(e):"object"===t?e&&"object"==typeof e&&!Array.isArray(e):typeof e==t||r&&void 0===e))},F.validateKeywordUsage=function({schema:e,opts:t,self:r,errSchemaPath:n},o,s){if(Array.isArray(o.keyword)?!o.keyword.includes(s):o.keyword!==s)throw new Error("ajv implementation error");const i=o.dependencies;if(null==i?void 0:i.some((t=>!Object.prototype.hasOwnProperty.call(e,t))))throw new Error(`parent schema must have dependencies of ${s}: ${i.join(",")}`);if(o.validateSchema){if(!o.validateSchema(e[s])){const e=`keyword "${s}" value is invalid at path "${n}": `+r.errorsText(o.validateSchema.errors);if("log"!==t.validateSchema)throw new Error(e);r.logger.error(e)}}},F}var W,Q={};var Y,X,Z={};function ee(){return X||(X=1,Y=function e(t,r){if(t===r)return!0;if(t&&r&&"object"==typeof t&&"object"==typeof r){if(t.constructor!==r.constructor)return!1;var n,o,s;if(Array.isArray(t)){if((n=t.length)!=r.length)return!1;for(o=n;0!=o--;)if(!e(t[o],r[o]))return!1;return!0}if(t.constructor===RegExp)return t.source===r.source&&t.flags===r.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===r.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===r.toString();if((n=(s=Object.keys(t)).length)!==Object.keys(r).length)return!1;for(o=n;0!=o--;)if(!Object.prototype.hasOwnProperty.call(r,s[o]))return!1;for(o=n;0!=o--;){var i=s[o];if(!e(t[i],r[i]))return!1}return!0}return t!=t&&r!=r}),Y}var te,re,ne,oe={exports:{}};function se(){if(te)return oe.exports;te=1;var e=oe.exports=function(e,r,n){"function"==typeof r&&(n=r,r={}),t(r,"function"==typeof(n=r.cb||n)?n:n.pre||function(){},n.post||function(){},e,"",e)};function t(r,n,o,s,i,a,c,u,l,f){if(s&&"object"==typeof s&&!Array.isArray(s)){for(var d in n(s,i,a,c,u,l,f),s){var h=s[d];if(Array.isArray(h)){if(d in e.arrayKeywords)for(var p=0;p<h.length;p++)t(r,n,o,h[p],i+"/"+d+"/"+p,a,i,d,s,p)}else if(d in e.propsKeywords){if(h&&"object"==typeof h)for(var m in h)t(r,n,o,h[m],i+"/"+d+"/"+m.replace(/~/g,"~0").replace(/\//g,"~1"),a,i,d,s,m)}else(d in e.keywords||r.allKeys&&!(d in e.skipKeywords))&&t(r,n,o,h,i+"/"+d,a,i,d,s)}o(s,i,a,c,u,l,f)}}return e.keywords={additionalItems:!0,items:!0,contains:!0,additionalProperties:!0,propertyNames:!0,not:!0,if:!0,then:!0,else:!0},e.arrayKeywords={items:!0,allOf:!0,anyOf:!0,oneOf:!0},e.propsKeywords={$defs:!0,definitions:!0,properties:!0,patternProperties:!0,dependencies:!0},e.skipKeywords={default:!0,enum:!0,const:!0,required:!0,maximum:!0,minimum:!0,exclusiveMaximum:!0,exclusiveMinimum:!0,multipleOf:!0,maxLength:!0,minLength:!0,pattern:!0,format:!0,maxItems:!0,minItems:!0,uniqueItems:!0,maxProperties:!0,minProperties:!0},oe.exports}function ie(){if(re)return Z;re=1,Object.defineProperty(Z,"__esModule",{value:!0}),Z.getSchemaRefs=Z.resolveUrl=Z.normalizeId=Z._getFullPath=Z.getFullPath=Z.inlineRef=void 0;const e=P(),t=ee(),r=se(),n=new Set(["type","format","pattern","maxLength","minLength","maxProperties","minProperties","maxItems","minItems","maximum","minimum","uniqueItems","multipleOf","required","enum","const"]);Z.inlineRef=function(e,t=!0){return"boolean"==typeof e||(!0===t?!s(e):!!t&&i(e)<=t)};const o=new Set(["$ref","$recursiveRef","$recursiveAnchor","$dynamicRef","$dynamicAnchor"]);function s(e){for(const t in e){if(o.has(t))return!0;const r=e[t];if(Array.isArray(r)&&r.some(s))return!0;if("object"==typeof r&&s(r))return!0}return!1}function i(t){let r=0;for(const o in t){if("$ref"===o)return 1/0;if(r++,!n.has(o)&&("object"==typeof t[o]&&(0,e.eachItem)(t[o],(e=>r+=i(e))),r===1/0))return 1/0}return r}function a(e,t="",r){!1!==r&&(t=l(t));const n=e.parse(t);return c(e,n)}function c(e,t){return e.serialize(t).split("#")[0]+"#"}Z.getFullPath=a,Z._getFullPath=c;const u=/#\/?$/;function l(e){return e?e.replace(u,""):""}Z.normalizeId=l,Z.resolveUrl=function(e,t,r){return r=l(r),e.resolve(t,r)};const f=/^[a-z_][-a-z0-9._]*$/i;return Z.getSchemaRefs=function(e,n){if("boolean"==typeof e)return{};const{schemaId:o,uriResolver:s}=this.opts,i=l(e[o]||n),c={"":i},u=a(s,i,!1),d={},h=new Set;return r(e,{allKeys:!0},((e,t,r,n)=>{if(void 0===n)return;const s=u+t;let i=c[n];function a(t){const r=this.opts.uriResolver.resolve;if(t=l(i?r(i,t):t),h.has(t))throw m(t);h.add(t);let n=this.refs[t];return"string"==typeof n&&(n=this.refs[n]),"object"==typeof n?p(e,n.schema,t):t!==l(s)&&("#"===t[0]?(p(e,d[t],t),d[t]=e):this.refs[t]=s),t}function v(e){if("string"==typeof e){if(!f.test(e))throw new Error(`invalid anchor "${e}"`);a.call(this,`#${e}`)}}"string"==typeof e[o]&&(i=a.call(this,e[o])),v.call(this,e.$anchor),v.call(this,e.$dynamicAnchor),c[t]=i})),d;function p(e,r,n){if(void 0!==r&&!t(e,r))throw m(n)}function m(e){return new Error(`reference "${e}" resolves to more than one schema`)}},Z}function ae(){if(ne)return d;ne=1,Object.defineProperty(d,"__esModule",{value:!0}),d.getData=d.KeywordCxt=d.validateFunctionCode=void 0;const e=function(){if(O)return h;O=1,Object.defineProperty(h,"__esModule",{value:!0}),h.boolOrEmptySchema=h.topBoolOrEmptySchema=void 0;const e=C(),t=$(),r=A(),n={message:"boolean schema is false"};function o(t,r){const{gen:o,data:s}=t,i={gen:o,keyword:"false schema",data:s,schema:!1,schemaCode:!1,schemaValue:!1,params:{},it:t};(0,e.reportError)(i,n,void 0,r)}return h.topBoolOrEmptySchema=function(e){const{gen:n,schema:s,validateName:i}=e;!1===s?o(e,!1):"object"==typeof s&&!0===s.$async?n.return(r.default.data):(n.assign(t._`${i}.errors`,null),n.return(!0))},h.boolOrEmptySchema=function(e,t){const{gen:r,schema:n}=e;!1===n?(r.var(t,!1),o(e)):r.var(t,!0)},h}(),t=V(),r=M(),n=V(),o=function(){if(U)return B;U=1,Object.defineProperty(B,"__esModule",{value:!0}),B.assignDefaults=void 0;const e=$(),t=P();function r(r,n,o){const{gen:s,compositeRule:i,data:a,opts:c}=r;if(void 0===o)return;const u=e._`${a}${(0,e.getProperty)(n)}`;if(i)return void(0,t.checkStrictMode)(r,`default is ignored for: ${u}`);let l=e._`${u} === undefined`;"empty"===c.useDefaults&&(l=e._`${l} || ${u} === null || ${u} === ""`),s.if(l,e._`${u} = ${(0,e.stringify)(o)}`)}return B.assignDefaults=function(e,t){const{properties:n,items:o}=e.schema;if("object"===t&&n)for(const t in n)r(e,t,n[t].default);else"array"===t&&Array.isArray(o)&&o.forEach(((t,n)=>r(e,n,t.default)))},B}(),s=H(),i=function(){if(W)return Q;W=1,Object.defineProperty(Q,"__esModule",{value:!0}),Q.extendSubschemaMode=Q.extendSubschemaData=Q.getSubschema=void 0;const e=$(),t=P();return Q.getSubschema=function(r,{keyword:n,schemaProp:o,schema:s,schemaPath:i,errSchemaPath:a,topSchemaRef:c}){if(void 0!==n&&void 0!==s)throw new Error('both "keyword" and "schema" passed, only one allowed');if(void 0!==n){const s=r.schema[n];return void 0===o?{schema:s,schemaPath:e._`${r.schemaPath}${(0,e.getProperty)(n)}`,errSchemaPath:`${r.errSchemaPath}/${n}`}:{schema:s[o],schemaPath:e._`${r.schemaPath}${(0,e.getProperty)(n)}${(0,e.getProperty)(o)}`,errSchemaPath:`${r.errSchemaPath}/${n}/${(0,t.escapeFragment)(o)}`}}if(void 0!==s){if(void 0===i||void 0===a||void 0===c)throw new Error('"schemaPath", "errSchemaPath" and "topSchemaRef" are required with "schema"');return{schema:s,schemaPath:i,topSchemaRef:c,errSchemaPath:a}}throw new Error('either "keyword" or "schema" must be passed')},Q.extendSubschemaData=function(r,n,{dataProp:o,dataPropType:s,data:i,dataTypes:a,propertyName:c}){if(void 0!==i&&void 0!==o)throw new Error('both "data" and "dataProp" passed, only one allowed');const{gen:u}=n;if(void 0!==o){const{errorPath:i,dataPathArr:a,opts:c}=n;l(u.let("data",e._`${n.data}${(0,e.getProperty)(o)}`,!0)),r.errorPath=e.str`${i}${(0,t.getErrorPath)(o,s,c.jsPropertySyntax)}`,r.parentDataProperty=e._`${o}`,r.dataPathArr=[...a,r.parentDataProperty]}function l(e){r.data=e,r.dataLevel=n.dataLevel+1,r.dataTypes=[],n.definedProperties=new Set,r.parentData=n.data,r.dataNames=[...n.dataNames,e]}void 0!==i&&(l(i instanceof e.Name?i:u.let("data",i,!0)),void 0!==c&&(r.propertyName=c)),a&&(r.dataTypes=a)},Q.extendSubschemaMode=function(e,{jtdDiscriminator:t,jtdMetadata:r,compositeRule:n,createErrors:o,allErrors:s}){void 0!==n&&(e.compositeRule=n),void 0!==o&&(e.createErrors=o),void 0!==s&&(e.allErrors=s),e.jtdDiscriminator=t,e.jtdMetadata=r},Q}(),a=$(),c=A(),u=ie(),l=P(),f=C();function p({gen:e,validateName:t,schema:r,schemaEnv:n,opts:o},s){o.code.es5?e.func(t,a._`${c.default.data}, ${c.default.valCxt}`,n.$async,(()=>{e.code(a._`"use strict"; ${m(r,o)}`),function(e,t){e.if(c.default.valCxt,(()=>{e.var(c.default.instancePath,a._`${c.default.valCxt}.${c.default.instancePath}`),e.var(c.default.parentData,a._`${c.default.valCxt}.${c.default.parentData}`),e.var(c.default.parentDataProperty,a._`${c.default.valCxt}.${c.default.parentDataProperty}`),e.var(c.default.rootData,a._`${c.default.valCxt}.${c.default.rootData}`),t.dynamicRef&&e.var(c.default.dynamicAnchors,a._`${c.default.valCxt}.${c.default.dynamicAnchors}`)}),(()=>{e.var(c.default.instancePath,a._`""`),e.var(c.default.parentData,a._`undefined`),e.var(c.default.parentDataProperty,a._`undefined`),e.var(c.default.rootData,c.default.data),t.dynamicRef&&e.var(c.default.dynamicAnchors,a._`{}`)}))}(e,o),e.code(s)})):e.func(t,a._`${c.default.data}, ${function(e){return a._`{${c.default.instancePath}="", ${c.default.parentData}, ${c.default.parentDataProperty}, ${c.default.rootData}=${c.default.data}${e.dynamicRef?a._`, ${c.default.dynamicAnchors}={}`:a.nil}}={}`}(o)}`,n.$async,(()=>e.code(m(r,o)).code(s)))}function m(e,t){const r="object"==typeof e&&e[t.schemaId];return r&&(t.code.source||t.code.process)?a._`/*# sourceURL=${r} */`:a.nil}function v(t,r){g(t)&&(_(t),y(t))?function(e,t){const{schema:r,gen:n,opts:o}=e;o.$comment&&r.$comment&&b(e);(function(e){const t=e.schema[e.opts.schemaId];t&&(e.baseId=(0,u.resolveUrl)(e.opts.uriResolver,e.baseId,t))})(e),function(e){if(e.schema.$async&&!e.schemaEnv.$async)throw new Error("async schema in sync schema")}(e);const s=n.const("_errs",c.default.errors);w(e,s),n.var(t,a._`${s} === ${c.default.errors}`)}(t,r):(0,e.boolOrEmptySchema)(t,r)}function y({schema:e,self:t}){if("boolean"==typeof e)return!e;for(const r in e)if(t.RULES.all[r])return!0;return!1}function g(e){return"boolean"!=typeof e.schema}function _(e){(0,l.checkUnknownRules)(e),function(e){const{schema:t,errSchemaPath:r,opts:n,self:o}=e;t.$ref&&n.ignoreKeywordsWithRef&&(0,l.schemaHasRulesButRef)(t,o.RULES)&&o.logger.warn(`$ref: keywords ignored in schema at path "${r}"`)}(e)}function w(e,r){if(e.opts.jtd)return k(e,[],!1,r);const n=(0,t.getSchemaTypes)(e.schema);k(e,n,!(0,t.coerceAndCheckDataType)(e,n),r)}function b({gen:e,schemaEnv:t,schema:r,errSchemaPath:n,opts:o}){const s=r.$comment;if(!0===o.$comment)e.code(a._`${c.default.self}.logger.log(${s})`);else if("function"==typeof o.$comment){const r=a.str`${n}/$comment`,o=e.scopeValue("root",{ref:t.root});e.code(a._`${c.default.self}.opts.$comment(${s}, ${r}, ${o}.schema)`)}}function k(e,t,o,s){const{gen:i,schema:u,data:f,allErrors:d,opts:h,self:p}=e,{RULES:m}=p;function v(l){(0,r.shouldUseGroup)(u,l)&&(l.type?(i.if((0,n.checkDataType)(l.type,f,h.strictNumbers)),E(e,l),1===t.length&&t[0]===l.type&&o&&(i.else(),(0,n.reportTypeError)(e)),i.endIf()):E(e,l),d||i.if(a._`${c.default.errors} === ${s||0}`))}!u.$ref||!h.ignoreKeywordsWithRef&&(0,l.schemaHasRulesButRef)(u,m)?(h.jtd||function(e,t){if(e.schemaEnv.meta||!e.opts.strictTypes)return;(function(e,t){if(!t.length)return;if(!e.dataTypes.length)return void(e.dataTypes=t);t.forEach((t=>{j(e.dataTypes,t)||x(e,`type "${t}" not allowed by context "${e.dataTypes.join(",")}"`)})),function(e,t){const r=[];for(const n of e.dataTypes)j(t,n)?r.push(n):t.includes("integer")&&"number"===n&&r.push("integer");e.dataTypes=r}(e,t)})(e,t),e.opts.allowUnionTypes||function(e,t){t.length>1&&(2!==t.length||!t.includes("null"))&&x(e,"use allowUnionTypes to allow union type keyword")}(e,t);!function(e,t){const n=e.self.RULES.all;for(const o in n){const s=n[o];if("object"==typeof s&&(0,r.shouldUseRule)(e.schema,s)){const{type:r}=s.definition;r.length&&!r.some((e=>S(t,e)))&&x(e,`missing type "${r.join(",")}" for keyword "${o}"`)}}}(e,e.dataTypes)}(e,t),i.block((()=>{for(const e of m.rules)v(e);v(m.post)}))):i.block((()=>N(e,"$ref",m.all.$ref.definition)))}function E(e,t){const{gen:n,schema:s,opts:{useDefaults:i}}=e;i&&(0,o.assignDefaults)(e,t.type),n.block((()=>{for(const n of t.rules)(0,r.shouldUseRule)(s,n)&&N(e,n.keyword,n.definition,t.type)}))}function S(e,t){return e.includes(t)||"number"===t&&e.includes("integer")}function j(e,t){return e.includes(t)||"integer"===t&&e.includes("number")}function x(e,t){t+=` at "${e.schemaEnv.baseId+e.errSchemaPath}" (strictTypes)`,(0,l.checkStrictMode)(e,t,e.opts.strictTypes)}d.validateFunctionCode=function(t){g(t)&&(_(t),y(t))?function(e){const{schema:t,opts:r,gen:n}=e;p(e,(()=>{r.$comment&&t.$comment&&b(e),function(e){const{schema:t,opts:r}=e;void 0!==t.default&&r.useDefaults&&r.strictSchema&&(0,l.checkStrictMode)(e,"default is ignored in the schema root")}(e),n.let(c.default.vErrors,null),n.let(c.default.errors,0),r.unevaluated&&function(e){const{gen:t,validateName:r}=e;e.evaluated=t.const("evaluated",a._`${r}.evaluated`),t.if(a._`${e.evaluated}.dynamicProps`,(()=>t.assign(a._`${e.evaluated}.props`,a._`undefined`))),t.if(a._`${e.evaluated}.dynamicItems`,(()=>t.assign(a._`${e.evaluated}.items`,a._`undefined`)))}(e),w(e),function(e){const{gen:t,schemaEnv:r,validateName:n,ValidationError:o,opts:s}=e;r.$async?t.if(a._`${c.default.errors} === 0`,(()=>t.return(c.default.data)),(()=>t.throw(a._`new ${o}(${c.default.vErrors})`))):(t.assign(a._`${n}.errors`,c.default.vErrors),s.unevaluated&&function({gen:e,evaluated:t,props:r,items:n}){r instanceof a.Name&&e.assign(a._`${t}.props`,r);n instanceof a.Name&&e.assign(a._`${t}.items`,n)}(e),t.return(a._`${c.default.errors} === 0`))}(e)}))}(t):p(t,(()=>(0,e.topBoolOrEmptySchema)(t)))};class I{constructor(e,t,r){if((0,s.validateKeywordUsage)(e,t,r),this.gen=e.gen,this.allErrors=e.allErrors,this.keyword=r,this.data=e.data,this.schema=e.schema[r],this.$data=t.$data&&e.opts.$data&&this.schema&&this.schema.$data,this.schemaValue=(0,l.schemaRefOrVal)(e,this.schema,r,this.$data),this.schemaType=t.schemaType,this.parentSchema=e.schema,this.params={},this.it=e,this.def=t,this.$data)this.schemaCode=e.gen.const("vSchema",q(this.$data,e));else if(this.schemaCode=this.schemaValue,!(0,s.validSchemaType)(this.schema,t.schemaType,t.allowUndefined))throw new Error(`${r} value must be ${JSON.stringify(t.schemaType)}`);("code"in t?t.trackErrors:!1!==t.errors)&&(this.errsCount=e.gen.const("_errs",c.default.errors))}result(e,t,r){this.failResult((0,a.not)(e),t,r)}failResult(e,t,r){this.gen.if(e),r?r():this.error(),t?(this.gen.else(),t(),this.allErrors&&this.gen.endIf()):this.allErrors?this.gen.endIf():this.gen.else()}pass(e,t){this.failResult((0,a.not)(e),void 0,t)}fail(e){if(void 0===e)return this.error(),void(this.allErrors||this.gen.if(!1));this.gen.if(e),this.error(),this.allErrors?this.gen.endIf():this.gen.else()}fail$data(e){if(!this.$data)return this.fail(e);const{schemaCode:t}=this;this.fail(a._`${t} !== undefined && (${(0,a.or)(this.invalid$data(),e)})`)}error(e,t,r){if(t)return this.setParams(t),this._error(e,r),void this.setParams({});this._error(e,r)}_error(e,t){(e?f.reportExtraError:f.reportError)(this,this.def.error,t)}$dataError(){(0,f.reportError)(this,this.def.$dataError||f.keyword$DataError)}reset(){if(void 0===this.errsCount)throw new Error('add "trackErrors" to keyword definition');(0,f.resetErrorsCount)(this.gen,this.errsCount)}ok(e){this.allErrors||this.gen.if(e)}setParams(e,t){t?Object.assign(this.params,e):this.params=e}block$data(e,t,r=a.nil){this.gen.block((()=>{this.check$data(e,r),t()}))}check$data(e=a.nil,t=a.nil){if(!this.$data)return;const{gen:r,schemaCode:n,schemaType:o,def:s}=this;r.if((0,a.or)(a._`${n} === undefined`,t)),e!==a.nil&&r.assign(e,!0),(o.length||s.validateSchema)&&(r.elseIf(this.invalid$data()),this.$dataError(),e!==a.nil&&r.assign(e,!1)),r.else()}invalid$data(){const{gen:e,schemaCode:t,schemaType:r,def:o,it:s}=this;return(0,a.or)(function(){if(r.length){if(!(t instanceof a.Name))throw new Error("ajv implementation error");const e=Array.isArray(r)?r:[r];return a._`${(0,n.checkDataTypes)(e,t,s.opts.strictNumbers,n.DataType.Wrong)}`}return a.nil}(),function(){if(o.validateSchema){const r=e.scopeValue("validate$data",{ref:o.validateSchema});return a._`!${r}(${t})`}return a.nil}())}subschema(e,t){const r=(0,i.getSubschema)(this.it,e);(0,i.extendSubschemaData)(r,this.it,e),(0,i.extendSubschemaMode)(r,e);const n={...this.it,...r,items:void 0,props:void 0};return v(n,t),n}mergeEvaluated(e,t){const{it:r,gen:n}=this;r.opts.unevaluated&&(!0!==r.props&&void 0!==e.props&&(r.props=l.mergeEvaluated.props(n,e.props,r.props,t)),!0!==r.items&&void 0!==e.items&&(r.items=l.mergeEvaluated.items(n,e.items,r.items,t)))}mergeValidEvaluated(e,t){const{it:r,gen:n}=this;if(r.opts.unevaluated&&(!0!==r.props||!0!==r.items))return n.if(t,(()=>this.mergeEvaluated(e,a.Name))),!0}}function N(e,t,r,n){const o=new I(e,r,t);"code"in r?r.code(o,n):o.$data&&r.validate?(0,s.funcKeywordCode)(o,r):"macro"in r?(0,s.macroKeywordCode)(o,r):(r.compile||r.validate)&&(0,s.funcKeywordCode)(o,r)}d.KeywordCxt=I;const T=/^\/(?:[^~]|~0|~1)*$/,R=/^([0-9]+)(#|\/(?:[^~]|~0|~1)*)?$/;function q(e,{dataLevel:t,dataNames:r,dataPathArr:n}){let o,s;if(""===e)return c.default.rootData;if("/"===e[0]){if(!T.test(e))throw new Error(`Invalid JSON-pointer: ${e}`);o=e,s=c.default.rootData}else{const i=R.exec(e);if(!i)throw new Error(`Invalid JSON-pointer: ${e}`);const a=+i[1];if(o=i[2],"#"===o){if(a>=t)throw new Error(f("property/index",a));return n[t-a]}if(a>t)throw new Error(f("data",a));if(s=r[t-a],!o)return s}let i=s;const u=o.split("/");for(const e of u)e&&(s=a._`${s}${(0,a.getProperty)((0,l.unescapeJsonPointer)(e))}`,i=a._`${i} && ${s}`);return i;function f(e,r){return`Cannot access ${e} ${r} levels up, current level is ${t}`}}return d.getData=q,d}var ce,ue={};function le(){if(ce)return ue;ce=1,Object.defineProperty(ue,"__esModule",{value:!0});class e extends Error{constructor(e){super("validation failed"),this.errors=e,this.ajv=this.validation=!0}}return ue.default=e,ue}var fe,de={};function he(){if(fe)return de;fe=1,Object.defineProperty(de,"__esModule",{value:!0});const e=ie();class t extends Error{constructor(t,r,n,o){super(o||`can't resolve reference ${n} from id ${r}`),this.missingRef=(0,e.resolveUrl)(t,r,n),this.missingSchema=(0,e.normalizeId)((0,e.getFullPath)(t,this.missingRef))}}return de.default=t,de}var pe,me={};function ve(){if(pe)return me;pe=1,Object.defineProperty(me,"__esModule",{value:!0}),me.resolveSchema=me.getCompilingSchema=me.resolveRef=me.compileSchema=me.SchemaEnv=void 0;const e=$(),t=le(),r=A(),n=ie(),o=P(),s=ae();class i{constructor(e){var t;let r;this.refs={},this.dynamicAnchors={},"object"==typeof e.schema&&(r=e.schema),this.schema=e.schema,this.schemaId=e.schemaId,this.root=e.root||this,this.baseId=null!==(t=e.baseId)&&void 0!==t?t:(0,n.normalizeId)(null==r?void 0:r[e.schemaId||"$id"]),this.schemaPath=e.schemaPath,this.localRefs=e.localRefs,this.meta=e.meta,this.$async=null==r?void 0:r.$async,this.refs={}}}function a(o){const i=u.call(this,o);if(i)return i;const a=(0,n.getFullPath)(this.opts.uriResolver,o.root.baseId),{es5:c,lines:l}=this.opts.code,{ownProperties:f}=this.opts,d=new e.CodeGen(this.scope,{es5:c,lines:l,ownProperties:f});let h;o.$async&&(h=d.scopeValue("Error",{ref:t.default,code:e._`require("ajv/dist/runtime/validation_error").default`}));const p=d.scopeName("validate");o.validateName=p;const m={gen:d,allErrors:this.opts.allErrors,data:r.default.data,parentData:r.default.parentData,parentDataProperty:r.default.parentDataProperty,dataNames:[r.default.data],dataPathArr:[e.nil],dataLevel:0,dataTypes:[],definedProperties:new Set,topSchemaRef:d.scopeValue("schema",!0===this.opts.code.source?{ref:o.schema,code:(0,e.stringify)(o.schema)}:{ref:o.schema}),validateName:p,ValidationError:h,schema:o.schema,schemaEnv:o,rootId:a,baseId:o.baseId||a,schemaPath:e.nil,errSchemaPath:o.schemaPath||(this.opts.jtd?"":"#"),errorPath:e._`""`,opts:this.opts,self:this};let v;try{this._compilations.add(o),(0,s.validateFunctionCode)(m),d.optimize(this.opts.code.optimize);const t=d.toString();v=`${d.scopeRefs(r.default.scope)}return ${t}`,this.opts.code.process&&(v=this.opts.code.process(v,o));const n=new Function(`${r.default.self}`,`${r.default.scope}`,v)(this,this.scope.get());if(this.scope.value(p,{ref:n}),n.errors=null,n.schema=o.schema,n.schemaEnv=o,o.$async&&(n.$async=!0),!0===this.opts.code.source&&(n.source={validateName:p,validateCode:t,scopeValues:d._values}),this.opts.unevaluated){const{props:t,items:r}=m;n.evaluated={props:t instanceof e.Name?void 0:t,items:r instanceof e.Name?void 0:r,dynamicProps:t instanceof e.Name,dynamicItems:r instanceof e.Name},n.source&&(n.source.evaluated=(0,e.stringify)(n.evaluated))}return o.validate=n,o}catch(e){throw delete o.validate,delete o.validateName,v&&this.logger.error("Error compiling schema, function code:",v),e}finally{this._compilations.delete(o)}}function c(e){return(0,n.inlineRef)(e.schema,this.opts.inlineRefs)?e.schema:e.validate?e:a.call(this,e)}function u(e){for(const n of this._compilations)if(r=e,(t=n).schema===r.schema&&t.root===r.root&&t.baseId===r.baseId)return n;var t,r}function l(e,t){let r;for(;"string"==typeof(r=this.refs[t]);)t=r;return r||this.schemas[t]||f.call(this,e,t)}function f(e,t){const r=this.opts.uriResolver.parse(t),o=(0,n._getFullPath)(this.opts.uriResolver,r);let s=(0,n.getFullPath)(this.opts.uriResolver,e.baseId,void 0);if(Object.keys(e.schema).length>0&&o===s)return h.call(this,r,e);const c=(0,n.normalizeId)(o),u=this.refs[c]||this.schemas[c];if("string"==typeof u){const t=f.call(this,e,u);if("object"!=typeof(null==t?void 0:t.schema))return;return h.call(this,r,t)}if("object"==typeof(null==u?void 0:u.schema)){if(u.validate||a.call(this,u),c===(0,n.normalizeId)(t)){const{schema:t}=u,{schemaId:r}=this.opts,o=t[r];return o&&(s=(0,n.resolveUrl)(this.opts.uriResolver,s,o)),new i({schema:t,schemaId:r,root:e,baseId:s})}return h.call(this,r,u)}}me.SchemaEnv=i,me.compileSchema=a,me.resolveRef=function(e,t,r){var o;r=(0,n.resolveUrl)(this.opts.uriResolver,t,r);const s=e.refs[r];if(s)return s;let a=l.call(this,e,r);if(void 0===a){const n=null===(o=e.localRefs)||void 0===o?void 0:o[r],{schemaId:s}=this.opts;n&&(a=new i({schema:n,schemaId:s,root:e,baseId:t}))}return void 0!==a?e.refs[r]=c.call(this,a):void 0},me.getCompilingSchema=u,me.resolveSchema=f;const d=new Set(["properties","patternProperties","enum","dependencies","definitions"]);function h(e,{baseId:t,schema:r,root:s}){var a;if("/"!==(null===(a=e.fragment)||void 0===a?void 0:a[0]))return;for(const s of e.fragment.slice(1).split("/")){if("boolean"==typeof r)return;const e=r[(0,o.unescapeFragment)(s)];if(void 0===e)return;const i="object"==typeof(r=e)&&r[this.opts.schemaId];!d.has(s)&&i&&(t=(0,n.resolveUrl)(this.opts.uriResolver,t,i))}let c;if("boolean"!=typeof r&&r.$ref&&!(0,o.schemaHasRulesButRef)(r,this.RULES)){const e=(0,n.resolveUrl)(this.opts.uriResolver,t,r.$ref);c=f.call(this,s,e)}const{schemaId:u}=this.opts;return c=c||new i({schema:r,schemaId:u,root:s,baseId:t}),c.schema!==c.root.schema?c:void 0}return me}var ye,ge,_e,we,be,$e,ke,Ee,Pe,Se={$id:"https://raw.githubusercontent.com/ajv-validator/ajv/master/lib/refs/data.json#",description:"Meta-schema for $data reference (JSON AnySchema extension proposal)",type:"object",required:["$data"],properties:{$data:{type:"string",anyOf:[{format:"relative-json-pointer"},{format:"json-pointer"}]}},additionalProperties:!1},je={},Oe={exports:{}};function xe(){if(we)return _e;we=1;const{HEX:e}=ge?ye:(ge=1,ye={HEX:{0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,a:10,A:10,b:11,B:11,c:12,C:12,d:13,D:13,e:14,E:14,f:15,F:15}}),t=/^(?:(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)$/u;function r(e){if(i(e,".")<3)return{host:e,isIPV4:!1};const r=e.match(t)||[],[n]=r;return n?{host:s(n,"."),isIPV4:!0}:{host:e,isIPV4:!1}}function n(t,r=!1){let n="",o=!0;for(const r of t){if(void 0===e[r])return;"0"!==r&&!0===o&&(o=!1),o||(n+=r)}return r&&0===n.length&&(n="0"),n}function o(e){if(i(e,":")<2)return{host:e,isIPV6:!1};const t=function(e){let t=0;const r={error:!1,address:"",zone:""},o=[],s=[];let i=!1,a=!1,c=!1;function u(){if(s.length){if(!1===i){const e=n(s);if(void 0===e)return r.error=!0,!1;o.push(e)}s.length=0}return!0}for(let n=0;n<e.length;n++){const l=e[n];if("["!==l&&"]"!==l)if(":"!==l)if("%"===l){if(!u())break;i=!0}else s.push(l);else{if(!0===a&&(c=!0),!u())break;if(t++,o.push(":"),t>7){r.error=!0;break}n-1>=0&&":"===e[n-1]&&(a=!0)}}return s.length&&(i?r.zone=s.join(""):c?o.push(s.join("")):o.push(n(s))),r.address=o.join(""),r}(e);if(t.error)return{host:e,isIPV6:!1};{let e=t.address,r=t.address;return t.zone&&(e+="%"+t.zone,r+="%25"+t.zone),{host:e,escapedHost:r,isIPV6:!0}}}function s(e,t){let r="",n=!0;const o=e.length;for(let s=0;s<o;s++){const i=e[s];"0"===i&&n?(s+1<=o&&e[s+1]===t||s+1===o)&&(r+=i,n=!1):(n=i===t,r+=i)}return r}function i(e,t){let r=0;for(let n=0;n<e.length;n++)e[n]===t&&r++;return r}const a=/^\.\.?\//u,c=/^\/\.(?:\/|$)/u,u=/^\/\.\.(?:\/|$)/u,l=/^\/?(?:.|\n)*?(?=\/|$)/u;return _e={recomposeAuthority:function(e){const t=[];if(void 0!==e.userinfo&&(t.push(e.userinfo),t.push("@")),void 0!==e.host){let n=unescape(e.host);const s=r(n);if(s.isIPV4)n=s.host;else{const t=o(s.host);n=!0===t.isIPV6?`[${t.escapedHost}]`:e.host}t.push(n)}return"number"!=typeof e.port&&"string"!=typeof e.port||(t.push(":"),t.push(String(e.port))),t.length?t.join(""):void 0},normalizeComponentEncoding:function(e,t){const r=!0!==t?escape:unescape;return void 0!==e.scheme&&(e.scheme=r(e.scheme)),void 0!==e.userinfo&&(e.userinfo=r(e.userinfo)),void 0!==e.host&&(e.host=r(e.host)),void 0!==e.path&&(e.path=r(e.path)),void 0!==e.query&&(e.query=r(e.query)),void 0!==e.fragment&&(e.fragment=r(e.fragment)),e},removeDotSegments:function(e){const t=[];for(;e.length;)if(e.match(a))e=e.replace(a,"");else if(e.match(c))e=e.replace(c,"/");else if(e.match(u))e=e.replace(u,"/"),t.pop();else if("."===e||".."===e)e="";else{const r=e.match(l);if(!r)throw new Error("Unexpected dot segment condition");{const n=r[0];e=e.slice(n.length),t.push(n)}}return t.join("")},normalizeIPv4:r,normalizeIPv6:o,stringArrayToHexStripped:n},_e}function Ae(){if(ke)return Oe.exports;ke=1;const{normalizeIPv6:e,normalizeIPv4:t,removeDotSegments:r,recomposeAuthority:n,normalizeComponentEncoding:o}=xe(),s=function(){if($e)return be;$e=1;const e=/^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/iu,t=/([\da-z][\d\-a-z]{0,31}):((?:[\w!$'()*+,\-.:;=@]|%[\da-f]{2})+)/iu;function r(e){return"boolean"==typeof e.secure?e.secure:"wss"===String(e.scheme).toLowerCase()}function n(e){return e.host||(e.error=e.error||"HTTP URIs must have a host."),e}function o(e){const t="https"===String(e.scheme).toLowerCase();return e.port!==(t?443:80)&&""!==e.port||(e.port=void 0),e.path||(e.path="/"),e}const s={scheme:"http",domainHost:!0,parse:n,serialize:o},i={scheme:"ws",domainHost:!0,parse:function(e){return e.secure=r(e),e.resourceName=(e.path||"/")+(e.query?"?"+e.query:""),e.path=void 0,e.query=void 0,e},serialize:function(e){if(e.port!==(r(e)?443:80)&&""!==e.port||(e.port=void 0),"boolean"==typeof e.secure&&(e.scheme=e.secure?"wss":"ws",e.secure=void 0),e.resourceName){const[t,r]=e.resourceName.split("?");e.path=t&&"/"!==t?t:void 0,e.query=r,e.resourceName=void 0}return e.fragment=void 0,e}},a={http:s,https:{scheme:"https",domainHost:s.domainHost,parse:n,serialize:o},ws:i,wss:{scheme:"wss",domainHost:i.domainHost,parse:i.parse,serialize:i.serialize},urn:{scheme:"urn",parse:function(e,r){if(!e.path)return e.error="URN can not be parsed",e;const n=e.path.match(t);if(n){const t=r.scheme||e.scheme||"urn";e.nid=n[1].toLowerCase(),e.nss=n[2];const o=`${t}:${r.nid||e.nid}`,s=a[o];e.path=void 0,s&&(e=s.parse(e,r))}else e.error=e.error||"URN can not be parsed.";return e},serialize:function(e,t){const r=t.scheme||e.scheme||"urn",n=e.nid.toLowerCase(),o=`${r}:${t.nid||n}`,s=a[o];s&&(e=s.serialize(e,t));const i=e,c=e.nss;return i.path=`${n||t.nid}:${c}`,t.skipEscape=!0,i},skipNormalize:!0},"urn:uuid":{scheme:"urn:uuid",parse:function(t,r){const n=t;return n.uuid=n.nss,n.nss=void 0,r.tolerant||n.uuid&&e.test(n.uuid)||(n.error=n.error||"UUID is not valid."),n},serialize:function(e){const t=e;return t.nss=(e.uuid||"").toLowerCase(),t},skipNormalize:!0}};return be=a}();function i(e,t,n,o){const s={};return o||(e=l(a(e,n),n),t=l(a(t,n),n)),!(n=n||{}).tolerant&&t.scheme?(s.scheme=t.scheme,s.userinfo=t.userinfo,s.host=t.host,s.port=t.port,s.path=r(t.path||""),s.query=t.query):(void 0!==t.userinfo||void 0!==t.host||void 0!==t.port?(s.userinfo=t.userinfo,s.host=t.host,s.port=t.port,s.path=r(t.path||""),s.query=t.query):(t.path?("/"===t.path.charAt(0)?s.path=r(t.path):(void 0===e.userinfo&&void 0===e.host&&void 0===e.port||e.path?e.path?s.path=e.path.slice(0,e.path.lastIndexOf("/")+1)+t.path:s.path=t.path:s.path="/"+t.path,s.path=r(s.path)),s.query=t.query):(s.path=e.path,void 0!==t.query?s.query=t.query:s.query=e.query),s.userinfo=e.userinfo,s.host=e.host,s.port=e.port),s.scheme=e.scheme),s.fragment=t.fragment,s}function a(e,t){const o={host:e.host,scheme:e.scheme,userinfo:e.userinfo,port:e.port,path:e.path,query:e.query,nid:e.nid,nss:e.nss,uuid:e.uuid,fragment:e.fragment,reference:e.reference,resourceName:e.resourceName,secure:e.secure,error:""},i=Object.assign({},t),a=[],c=s[(i.scheme||o.scheme||"").toLowerCase()];c&&c.serialize&&c.serialize(o,i),void 0!==o.path&&(i.skipEscape?o.path=unescape(o.path):(o.path=escape(o.path),void 0!==o.scheme&&(o.path=o.path.split("%3A").join(":")))),"suffix"!==i.reference&&o.scheme&&a.push(o.scheme,":");const u=n(o);if(void 0!==u&&("suffix"!==i.reference&&a.push("//"),a.push(u),o.path&&"/"!==o.path.charAt(0)&&a.push("/")),void 0!==o.path){let e=o.path;i.absolutePath||c&&c.absolutePath||(e=r(e)),void 0===u&&(e=e.replace(/^\/\//u,"/%2F")),a.push(e)}return void 0!==o.query&&a.push("?",o.query),void 0!==o.fragment&&a.push("#",o.fragment),a.join("")}const c=Array.from({length:127},((e,t)=>/[^!"$&'()*+,\-.;=_`a-z{}~]/u.test(String.fromCharCode(t))));const u=/^(?:([^#/:?]+):)?(?:\/\/((?:([^#/?@]*)@)?(\[[^#/?\]]+\]|[^#/:?]*)(?::(\d*))?))?([^#?]*)(?:\?([^#]*))?(?:#((?:.|[\n\r])*))?/u;function l(r,n){const o=Object.assign({},n),i={scheme:void 0,userinfo:void 0,host:"",port:void 0,path:"",query:void 0,fragment:void 0},a=-1!==r.indexOf("%");let l=!1;"suffix"===o.reference&&(r=(o.scheme?o.scheme+":":"")+"//"+r);const f=r.match(u);if(f){if(i.scheme=f[1],i.userinfo=f[3],i.host=f[4],i.port=parseInt(f[5],10),i.path=f[6]||"",i.query=f[7],i.fragment=f[8],isNaN(i.port)&&(i.port=f[5]),i.host){const r=t(i.host);if(!1===r.isIPV4){const t=e(r.host);i.host=t.host.toLowerCase(),l=t.isIPV6}else i.host=r.host,l=!0}void 0!==i.scheme||void 0!==i.userinfo||void 0!==i.host||void 0!==i.port||void 0!==i.query||i.path?void 0===i.scheme?i.reference="relative":void 0===i.fragment?i.reference="absolute":i.reference="uri":i.reference="same-document",o.reference&&"suffix"!==o.reference&&o.reference!==i.reference&&(i.error=i.error||"URI is not a "+o.reference+" reference.");const r=s[(o.scheme||i.scheme||"").toLowerCase()];if(!(o.unicodeSupport||r&&r.unicodeSupport)&&i.host&&(o.domainHost||r&&r.domainHost)&&!1===l&&function(e){let t=0;for(let r=0,n=e.length;r<n;++r)if(t=e.charCodeAt(r),t>126||c[t])return!0;return!1}(i.host))try{i.host=URL.domainToASCII(i.host.toLowerCase())}catch(e){i.error=i.error||"Host's domain name can not be converted to ASCII: "+e}(!r||r&&!r.skipNormalize)&&(a&&void 0!==i.scheme&&(i.scheme=unescape(i.scheme)),a&&void 0!==i.host&&(i.host=unescape(i.host)),i.path&&(i.path=escape(unescape(i.path))),i.fragment&&(i.fragment=encodeURI(decodeURIComponent(i.fragment)))),r&&r.parse&&r.parse(i,o)}else i.error=i.error||"URI can not be parsed.";return i}const f={SCHEMES:s,normalize:function(e,t){return"string"==typeof e?e=a(l(e,t),t):"object"==typeof e&&(e=l(a(e,t),t)),e},resolve:function(e,t,r){const n=Object.assign({scheme:"null"},r);return a(i(l(e,n),l(t,n),n,!0),{...n,skipEscape:!0})},resolveComponents:i,equal:function(e,t,r){return"string"==typeof e?(e=unescape(e),e=a(o(l(e,r),!0),{...r,skipEscape:!0})):"object"==typeof e&&(e=a(o(e,!0),{...r,skipEscape:!0})),"string"==typeof t?(t=unescape(t),t=a(o(l(t,r),!0),{...r,skipEscape:!0})):"object"==typeof t&&(t=a(o(t,!0),{...r,skipEscape:!0})),e.toLowerCase()===t.toLowerCase()},serialize:a,parse:l};return Oe.exports=f,Oe.exports.default=f,Oe.exports.fastUri=f,Oe.exports}function Ce(){return Pe||(Pe=1,function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.CodeGen=e.Name=e.nil=e.stringify=e.str=e._=e.KeywordCxt=void 0;var t=ae();Object.defineProperty(e,"KeywordCxt",{enumerable:!0,get:function(){return t.KeywordCxt}});var r=$();Object.defineProperty(e,"_",{enumerable:!0,get:function(){return r._}}),Object.defineProperty(e,"str",{enumerable:!0,get:function(){return r.str}}),Object.defineProperty(e,"stringify",{enumerable:!0,get:function(){return r.stringify}}),Object.defineProperty(e,"nil",{enumerable:!0,get:function(){return r.nil}}),Object.defineProperty(e,"Name",{enumerable:!0,get:function(){return r.Name}}),Object.defineProperty(e,"CodeGen",{enumerable:!0,get:function(){return r.CodeGen}});const n=le(),o=he(),s=R(),i=ve(),a=$(),c=ie(),u=V(),l=P(),f=Se,d=function(){if(Ee)return je;Ee=1,Object.defineProperty(je,"__esModule",{value:!0});const e=Ae();return e.code='require("ajv/dist/runtime/uri").default',je.default=e,je}(),h=(e,t)=>new RegExp(e,t);h.code="new RegExp";const p=["removeAdditional","useDefaults","coerceTypes"],m=new Set(["validate","serialize","parse","wrapper","root","schema","keyword","pattern","formats","validate$data","func","obj","Error"]),v={errorDataPath:"",format:"`validateFormats: false` can be used instead.",nullable:'"nullable" keyword is supported by default.',jsonPointers:"Deprecated jsPropertySyntax can be used instead.",extendRefs:"Deprecated ignoreKeywordsWithRef can be used instead.",missingRefs:"Pass empty schema with $id that should be ignored to ajv.addSchema.",processCode:"Use option `code: {process: (code, schemaEnv: object) => string}`",sourceCode:"Use option `code: {source: true}`",strictDefaults:"It is default now, see option `strict`.",strictKeywords:"It is default now, see option `strict`.",uniqueItems:'"uniqueItems" keyword is always validated.',unknownFormats:"Disable strict mode or pass `true` to `ajv.addFormat` (or `formats` option).",cache:"Map is used as cache, schema object as key.",serialize:"Map is used as cache, schema object as key.",ajvErrors:"It is default now."},y={ignoreKeywordsWithRef:"",jsPropertySyntax:"",unicode:'"minLength"/"maxLength" account for unicode characters by default.'};function g(e){var t,r,n,o,s,i,a,c,u,l,f,p,m,v,y,g,_,w,b,$,k,E,P,S,j;const O=e.strict,x=null===(t=e.code)||void 0===t?void 0:t.optimize,A=!0===x||void 0===x?1:x||0,C=null!==(n=null===(r=e.code)||void 0===r?void 0:r.regExp)&&void 0!==n?n:h,I=null!==(o=e.uriResolver)&&void 0!==o?o:d.default;return{strictSchema:null===(i=null!==(s=e.strictSchema)&&void 0!==s?s:O)||void 0===i||i,strictNumbers:null===(c=null!==(a=e.strictNumbers)&&void 0!==a?a:O)||void 0===c||c,strictTypes:null!==(l=null!==(u=e.strictTypes)&&void 0!==u?u:O)&&void 0!==l?l:"log",strictTuples:null!==(p=null!==(f=e.strictTuples)&&void 0!==f?f:O)&&void 0!==p?p:"log",strictRequired:null!==(v=null!==(m=e.strictRequired)&&void 0!==m?m:O)&&void 0!==v&&v,code:e.code?{...e.code,optimize:A,regExp:C}:{optimize:A,regExp:C},loopRequired:null!==(y=e.loopRequired)&&void 0!==y?y:200,loopEnum:null!==(g=e.loopEnum)&&void 0!==g?g:200,meta:null===(_=e.meta)||void 0===_||_,messages:null===(w=e.messages)||void 0===w||w,inlineRefs:null===(b=e.inlineRefs)||void 0===b||b,schemaId:null!==($=e.schemaId)&&void 0!==$?$:"$id",addUsedSchema:null===(k=e.addUsedSchema)||void 0===k||k,validateSchema:null===(E=e.validateSchema)||void 0===E||E,validateFormats:null===(P=e.validateFormats)||void 0===P||P,unicodeRegExp:null===(S=e.unicodeRegExp)||void 0===S||S,int32range:null===(j=e.int32range)||void 0===j||j,uriResolver:I}}class _{constructor(e={}){this.schemas={},this.refs={},this.formats={},this._compilations=new Set,this._loading={},this._cache=new Map,e=this.opts={...e,...g(e)};const{es5:t,lines:r}=this.opts.code;this.scope=new a.ValueScope({scope:{},prefixes:m,es5:t,lines:r}),this.logger=function(e){if(!1===e)return O;if(void 0===e)return console;if(e.log&&e.warn&&e.error)return e;throw new Error("logger must implement log, warn and error methods")}(e.logger);const n=e.validateFormats;e.validateFormats=!1,this.RULES=(0,s.getRules)(),w.call(this,v,e,"NOT SUPPORTED"),w.call(this,y,e,"DEPRECATED","warn"),this._metaOpts=j.call(this),e.formats&&E.call(this),this._addVocabularies(),this._addDefaultMetaSchema(),e.keywords&&S.call(this,e.keywords),"object"==typeof e.meta&&this.addMetaSchema(e.meta),k.call(this),e.validateFormats=n}_addVocabularies(){this.addKeyword("$async")}_addDefaultMetaSchema(){const{$data:e,meta:t,schemaId:r}=this.opts;let n=f;"id"===r&&(n={...f},n.id=n.$id,delete n.$id),t&&e&&this.addMetaSchema(n,n[r],!1)}defaultMeta(){const{meta:e,schemaId:t}=this.opts;return this.opts.defaultMeta="object"==typeof e?e[t]||e:void 0}validate(e,t){let r;if("string"==typeof e){if(r=this.getSchema(e),!r)throw new Error(`no schema with key or ref "${e}"`)}else r=this.compile(e);const n=r(t);return"$async"in r||(this.errors=r.errors),n}compile(e,t){const r=this._addSchema(e,t);return r.validate||this._compileSchemaEnv(r)}compileAsync(e,t){if("function"!=typeof this.opts.loadSchema)throw new Error("options.loadSchema should be a function");const{loadSchema:r}=this.opts;return n.call(this,e,t);async function n(e,t){await s.call(this,e.$schema);const r=this._addSchema(e,t);return r.validate||i.call(this,r)}async function s(e){e&&!this.getSchema(e)&&await n.call(this,{$ref:e},!0)}async function i(e){try{return this._compileSchemaEnv(e)}catch(t){if(!(t instanceof o.default))throw t;return a.call(this,t),await c.call(this,t.missingSchema),i.call(this,e)}}function a({missingSchema:e,missingRef:t}){if(this.refs[e])throw new Error(`AnySchema ${e} is loaded but ${t} cannot be resolved`)}async function c(e){const r=await u.call(this,e);this.refs[e]||await s.call(this,r.$schema),this.refs[e]||this.addSchema(r,e,t)}async function u(e){const t=this._loading[e];if(t)return t;try{return await(this._loading[e]=r(e))}finally{delete this._loading[e]}}}addSchema(e,t,r,n=this.opts.validateSchema){if(Array.isArray(e)){for(const t of e)this.addSchema(t,void 0,r,n);return this}let o;if("object"==typeof e){const{schemaId:t}=this.opts;if(o=e[t],void 0!==o&&"string"!=typeof o)throw new Error(`schema ${t} must be string`)}return t=(0,c.normalizeId)(t||o),this._checkUnique(t),this.schemas[t]=this._addSchema(e,r,t,n,!0),this}addMetaSchema(e,t,r=this.opts.validateSchema){return this.addSchema(e,t,!0,r),this}validateSchema(e,t){if("boolean"==typeof e)return!0;let r;if(r=e.$schema,void 0!==r&&"string"!=typeof r)throw new Error("$schema must be a string");if(r=r||this.opts.defaultMeta||this.defaultMeta(),!r)return this.logger.warn("meta-schema not available"),this.errors=null,!0;const n=this.validate(r,e);if(!n&&t){const e="schema is invalid: "+this.errorsText();if("log"!==this.opts.validateSchema)throw new Error(e);this.logger.error(e)}return n}getSchema(e){let t;for(;"string"==typeof(t=b.call(this,e));)e=t;if(void 0===t){const{schemaId:r}=this.opts,n=new i.SchemaEnv({schema:{},schemaId:r});if(t=i.resolveSchema.call(this,n,e),!t)return;this.refs[e]=t}return t.validate||this._compileSchemaEnv(t)}removeSchema(e){if(e instanceof RegExp)return this._removeAllSchemas(this.schemas,e),this._removeAllSchemas(this.refs,e),this;switch(typeof e){case"undefined":return this._removeAllSchemas(this.schemas),this._removeAllSchemas(this.refs),this._cache.clear(),this;case"string":{const t=b.call(this,e);return"object"==typeof t&&this._cache.delete(t.schema),delete this.schemas[e],delete this.refs[e],this}case"object":{const t=e;this._cache.delete(t);let r=e[this.opts.schemaId];return r&&(r=(0,c.normalizeId)(r),delete this.schemas[r],delete this.refs[r]),this}default:throw new Error("ajv.removeSchema: invalid parameter")}}addVocabulary(e){for(const t of e)this.addKeyword(t);return this}addKeyword(e,t){let r;if("string"==typeof e)r=e,"object"==typeof t&&(this.logger.warn("these parameters are deprecated, see docs for addKeyword"),t.keyword=r);else{if("object"!=typeof e||void 0!==t)throw new Error("invalid addKeywords parameters");if(r=(t=e).keyword,Array.isArray(r)&&!r.length)throw new Error("addKeywords: keyword must be string or non-empty array")}if(A.call(this,r,t),!t)return(0,l.eachItem)(r,(e=>C.call(this,e))),this;N.call(this,t);const n={...t,type:(0,u.getJSONTypes)(t.type),schemaType:(0,u.getJSONTypes)(t.schemaType)};return(0,l.eachItem)(r,0===n.type.length?e=>C.call(this,e,n):e=>n.type.forEach((t=>C.call(this,e,n,t)))),this}getKeyword(e){const t=this.RULES.all[e];return"object"==typeof t?t.definition:!!t}removeKeyword(e){const{RULES:t}=this;delete t.keywords[e],delete t.all[e];for(const r of t.rules){const t=r.rules.findIndex((t=>t.keyword===e));t>=0&&r.rules.splice(t,1)}return this}addFormat(e,t){return"string"==typeof t&&(t=new RegExp(t)),this.formats[e]=t,this}errorsText(e=this.errors,{separator:t=", ",dataVar:r="data"}={}){return e&&0!==e.length?e.map((e=>`${r}${e.instancePath} ${e.message}`)).reduce(((e,r)=>e+t+r)):"No errors"}$dataMetaSchema(e,t){const r=this.RULES.all;e=JSON.parse(JSON.stringify(e));for(const n of t){const t=n.split("/").slice(1);let o=e;for(const e of t)o=o[e];for(const e in r){const t=r[e];if("object"!=typeof t)continue;const{$data:n}=t.definition,s=o[e];n&&s&&(o[e]=q(s))}}return e}_removeAllSchemas(e,t){for(const r in e){const n=e[r];t&&!t.test(r)||("string"==typeof n?delete e[r]:n&&!n.meta&&(this._cache.delete(n.schema),delete e[r]))}}_addSchema(e,t,r,n=this.opts.validateSchema,o=this.opts.addUsedSchema){let s;const{schemaId:a}=this.opts;if("object"==typeof e)s=e[a];else{if(this.opts.jtd)throw new Error("schema must be object");if("boolean"!=typeof e)throw new Error("schema must be object or boolean")}let u=this._cache.get(e);if(void 0!==u)return u;r=(0,c.normalizeId)(s||r);const l=c.getSchemaRefs.call(this,e,r);return u=new i.SchemaEnv({schema:e,schemaId:a,meta:t,baseId:r,localRefs:l}),this._cache.set(u.schema,u),o&&!r.startsWith("#")&&(r&&this._checkUnique(r),this.refs[r]=u),n&&this.validateSchema(e,!0),u}_checkUnique(e){if(this.schemas[e]||this.refs[e])throw new Error(`schema with key or id "${e}" already exists`)}_compileSchemaEnv(e){if(e.meta?this._compileMetaSchema(e):i.compileSchema.call(this,e),!e.validate)throw new Error("ajv implementation error");return e.validate}_compileMetaSchema(e){const t=this.opts;this.opts=this._metaOpts;try{i.compileSchema.call(this,e)}finally{this.opts=t}}}function w(e,t,r,n="error"){for(const o in e){const s=o;s in t&&this.logger[n](`${r}: option ${o}. ${e[s]}`)}}function b(e){return e=(0,c.normalizeId)(e),this.schemas[e]||this.refs[e]}function k(){const e=this.opts.schemas;if(e)if(Array.isArray(e))this.addSchema(e);else for(const t in e)this.addSchema(e[t],t)}function E(){for(const e in this.opts.formats){const t=this.opts.formats[e];t&&this.addFormat(e,t)}}function S(e){if(Array.isArray(e))this.addVocabulary(e);else{this.logger.warn("keywords option as map is deprecated, pass array");for(const t in e){const r=e[t];r.keyword||(r.keyword=t),this.addKeyword(r)}}}function j(){const e={...this.opts};for(const t of p)delete e[t];return e}_.ValidationError=n.default,_.MissingRefError=o.default,e.default=_;const O={log(){},warn(){},error(){}};const x=/^[a-z_$][a-z0-9_$:-]*$/i;function A(e,t){const{RULES:r}=this;if((0,l.eachItem)(e,(e=>{if(r.keywords[e])throw new Error(`Keyword ${e} is already defined`);if(!x.test(e))throw new Error(`Keyword ${e} has invalid name`)})),t&&t.$data&&!("code"in t)&&!("validate"in t))throw new Error('$data keyword must have "code" or "validate" function')}function C(e,t,r){var n;const o=null==t?void 0:t.post;if(r&&o)throw new Error('keyword with "post" flag cannot have "type"');const{RULES:s}=this;let i=o?s.post:s.rules.find((({type:e})=>e===r));if(i||(i={type:r,rules:[]},s.rules.push(i)),s.keywords[e]=!0,!t)return;const a={keyword:e,definition:{...t,type:(0,u.getJSONTypes)(t.type),schemaType:(0,u.getJSONTypes)(t.schemaType)}};t.before?I.call(this,i,a,t.before):i.rules.push(a),s.all[e]=a,null===(n=t.implements)||void 0===n||n.forEach((e=>this.addKeyword(e)))}function I(e,t,r){const n=e.rules.findIndex((e=>e.keyword===r));n>=0?e.rules.splice(n,0,t):(e.rules.push(t),this.logger.warn(`rule ${r} is not defined`))}function N(e){let{metaSchema:t}=e;void 0!==t&&(e.$data&&this.opts.$data&&(t=q(t)),e.validateSchema=this.compile(t,!0))}const T={$ref:"https://raw.githubusercontent.com/ajv-validator/ajv/master/lib/refs/data.json#"};function q(e){return{anyOf:[e,T]}}}(f)),f}var Ie,Ne,Te={},Re={},qe={};function De(){if(Ne)return Re;Ne=1,Object.defineProperty(Re,"__esModule",{value:!0});const e=function(){if(Ie)return qe;Ie=1,Object.defineProperty(qe,"__esModule",{value:!0}),qe.callRef=qe.getValidate=void 0;const e=he(),t=G(),r=$(),n=A(),o=ve(),s=P(),i={keyword:"$ref",schemaType:"string",code(t){const{gen:n,schema:s,it:i}=t,{baseId:u,schemaEnv:l,validateName:f,opts:d,self:h}=i,{root:p}=l;if(("#"===s||"#/"===s)&&u===p.baseId)return function(){if(l===p)return c(t,f,l,l.$async);const e=n.scopeValue("root",{ref:p});return c(t,r._`${e}.validate`,p,p.$async)}();const m=o.resolveRef.call(h,p,u,s);if(void 0===m)throw new e.default(i.opts.uriResolver,u,s);return m instanceof o.SchemaEnv?function(e){const r=a(t,e);c(t,r,e,e.$async)}(m):function(e){const o=n.scopeValue("schema",!0===d.code.source?{ref:e,code:(0,r.stringify)(e)}:{ref:e}),i=n.name("valid"),a=t.subschema({schema:e,dataTypes:[],schemaPath:r.nil,topSchemaRef:o,errSchemaPath:s},i);t.mergeEvaluated(a),t.ok(i)}(m)}};function a(e,t){const{gen:n}=e;return t.validate?n.scopeValue("validate",{ref:t.validate}):r._`${n.scopeValue("wrapper",{ref:t})}.validate`}function c(e,o,i,a){const{gen:c,it:u}=e,{allErrors:l,schemaEnv:f,opts:d}=u,h=d.passContext?n.default.this:r.nil;function p(e){const t=r._`${e}.errors`;c.assign(n.default.vErrors,r._`${n.default.vErrors} === null ? ${t} : ${n.default.vErrors}.concat(${t})`),c.assign(n.default.errors,r._`${n.default.vErrors}.length`)}function m(e){var t;if(!u.opts.unevaluated)return;const n=null===(t=null==i?void 0:i.validate)||void 0===t?void 0:t.evaluated;if(!0!==u.props)if(n&&!n.dynamicProps)void 0!==n.props&&(u.props=s.mergeEvaluated.props(c,n.props,u.props));else{const t=c.var("props",r._`${e}.evaluated.props`);u.props=s.mergeEvaluated.props(c,t,u.props,r.Name)}if(!0!==u.items)if(n&&!n.dynamicItems)void 0!==n.items&&(u.items=s.mergeEvaluated.items(c,n.items,u.items));else{const t=c.var("items",r._`${e}.evaluated.items`);u.items=s.mergeEvaluated.items(c,t,u.items,r.Name)}}a?function(){if(!f.$async)throw new Error("async schema referenced by sync schema");const n=c.let("valid");c.try((()=>{c.code(r._`await ${(0,t.callValidateCode)(e,o,h)}`),m(o),l||c.assign(n,!0)}),(e=>{c.if(r._`!(${e} instanceof ${u.ValidationError})`,(()=>c.throw(e))),p(e),l||c.assign(n,!1)})),e.ok(n)}():e.result((0,t.callValidateCode)(e,o,h),(()=>m(o)),(()=>p(o)))}return qe.getValidate=a,qe.callRef=c,qe.default=i,qe}(),t=["$schema","id","$defs",{keyword:"$comment"},"definitions",e.default];return Re.default=t,Re}var Le,Me={},Ve={};var Ue,Be={};var ze,Ke={};var Fe,Je,Ge={},He={};function We(){if(Je)return Ge;Je=1,Object.defineProperty(Ge,"__esModule",{value:!0});const e=$(),t=P(),r=function(){if(Fe)return He;function e(e){const t=e.length;let r,n=0,o=0;for(;o<t;)n++,r=e.charCodeAt(o++),r>=55296&&r<=56319&&o<t&&(r=e.charCodeAt(o),56320==(64512&r)&&o++);return n}return Fe=1,Object.defineProperty(He,"__esModule",{value:!0}),He.default=e,e.code='require("ajv/dist/runtime/ucs2length").default',He}(),n={message({keyword:t,schemaCode:r}){const n="maxLength"===t?"more":"fewer";return e.str`must NOT have ${n} than ${r} characters`},params:({schemaCode:t})=>e._`{limit: ${t}}`},o={keyword:["maxLength","minLength"],type:"string",schemaType:"number",$data:!0,error:n,code(n){const{keyword:o,data:s,schemaCode:i,it:a}=n,c="maxLength"===o?e.operators.GT:e.operators.LT,u=!1===a.opts.unicode?e._`${s}.length`:e._`${(0,t.useFunc)(n.gen,r.default)}(${s})`;n.fail$data(e._`${u} ${c} ${i}`)}};return Ge.default=o,Ge}var Qe,Ye={};var Xe,Ze={};var et,tt={};function rt(){if(et)return tt;et=1,Object.defineProperty(tt,"__esModule",{value:!0});const e=G(),t=$(),r=P(),n={keyword:"required",type:"object",schemaType:"array",$data:!0,error:{message:({params:{missingProperty:e}})=>t.str`must have required property '${e}'`,params:({params:{missingProperty:e}})=>t._`{missingProperty: ${e}}`},code(n){const{gen:o,schema:s,schemaCode:i,data:a,$data:c,it:u}=n,{opts:l}=u;if(!c&&0===s.length)return;const f=s.length>=l.loopRequired;if(u.allErrors?function(){if(f||c)n.block$data(t.nil,d);else for(const t of s)(0,e.checkReportMissingProp)(n,t)}():function(){const r=o.let("missing");if(f||c){const s=o.let("valid",!0);n.block$data(s,(()=>function(r,s){n.setParams({missingProperty:r}),o.forOf(r,i,(()=>{o.assign(s,(0,e.propertyInData)(o,a,r,l.ownProperties)),o.if((0,t.not)(s),(()=>{n.error(),o.break()}))}),t.nil)}(r,s))),n.ok(s)}else o.if((0,e.checkMissingProp)(n,s,r)),(0,e.reportMissingProp)(n,r),o.else()}(),l.strictRequired){const e=n.parentSchema.properties,{definedProperties:t}=n.it;for(const n of s)if(void 0===(null==e?void 0:e[n])&&!t.has(n)){const e=`required property "${n}" is not defined at "${u.schemaEnv.baseId+u.errSchemaPath}" (strictRequired)`;(0,r.checkStrictMode)(u,e,u.opts.strictRequired)}}function d(){o.forOf("prop",i,(t=>{n.setParams({missingProperty:t}),o.if((0,e.noPropertyInData)(o,a,t,l.ownProperties),(()=>n.error()))}))}}};return tt.default=n,tt}var nt,ot={};var st,it,at={},ct={};function ut(){if(st)return ct;st=1,Object.defineProperty(ct,"__esModule",{value:!0});const e=ee();return e.code='require("ajv/dist/runtime/equal").default',ct.default=e,ct}function lt(){if(it)return at;it=1,Object.defineProperty(at,"__esModule",{value:!0});const e=V(),t=$(),r=P(),n=ut(),o={message:({params:{i:e,j:r}})=>t.str`must NOT have duplicate items (items ## ${r} and ${e} are identical)`,params:({params:{i:e,j:r}})=>t._`{i: ${e}, j: ${r}}`},s={keyword:"uniqueItems",type:"array",schemaType:"boolean",$data:!0,error:o,code(o){const{gen:s,data:i,$data:a,schema:c,parentSchema:u,schemaCode:l,it:f}=o;if(!a&&!c)return;const d=s.let("valid"),h=u.items?(0,e.getSchemaTypes)(u.items):[];function p(r,n){const a=s.name("item"),c=(0,e.checkDataTypes)(h,a,f.opts.strictNumbers,e.DataType.Wrong),u=s.const("indices",t._`{}`);s.for(t._`;${r}--;`,(()=>{s.let(a,t._`${i}[${r}]`),s.if(c,t._`continue`),h.length>1&&s.if(t._`typeof ${a} == "string"`,t._`${a} += "_"`),s.if(t._`typeof ${u}[${a}] == "number"`,(()=>{s.assign(n,t._`${u}[${a}]`),o.error(),s.assign(d,!1).break()})).code(t._`${u}[${a}] = ${r}`)}))}function m(e,a){const c=(0,r.useFunc)(s,n.default),u=s.name("outer");s.label(u).for(t._`;${e}--;`,(()=>s.for(t._`${a} = ${e}; ${a}--;`,(()=>s.if(t._`${c}(${i}[${e}], ${i}[${a}])`,(()=>{o.error(),s.assign(d,!1).break(u)}))))))}o.block$data(d,(function(){const e=s.let("i",t._`${i}.length`),r=s.let("j");o.setParams({i:e,j:r}),s.assign(d,!0),s.if(t._`${e} > 1`,(()=>(h.length>0&&!h.some((e=>"object"===e||"array"===e))?p:m)(e,r)))}),t._`${l} === false`),o.ok(d)}};return at.default=s,at}var ft,dt={};var ht,pt,mt={};function vt(){if(ht)return mt;ht=1,Object.defineProperty(mt,"__esModule",{value:!0});const e=$(),t=P(),r=ut(),n={keyword:"enum",schemaType:"array",$data:!0,error:{message:"must be equal to one of the allowed values",params:({schemaCode:t})=>e._`{allowedValues: ${t}}`},code(n){const{gen:o,data:s,$data:i,schema:a,schemaCode:c,it:u}=n;if(!i&&0===a.length)throw new Error("enum must have non-empty array");const l=a.length>=u.opts.loopEnum;let f;const d=()=>null!=f?f:f=(0,t.useFunc)(o,r.default);let h;if(l||i)h=o.let("valid"),n.block$data(h,(function(){o.assign(h,!1),o.forOf("v",c,(t=>o.if(e._`${d()}(${s}, ${t})`,(()=>o.assign(h,!0).break()))))}));else{if(!Array.isArray(a))throw new Error("ajv implementation error");const t=o.const("vSchema",c);h=(0,e.or)(...a.map(((r,n)=>function(t,r){const n=a[r];return"object"==typeof n&&null!==n?e._`${d()}(${s}, ${t}[${r}])`:e._`${s} === ${n}`}(t,n))))}n.pass(h)}};return mt.default=n,mt}function yt(){if(pt)return Me;pt=1,Object.defineProperty(Me,"__esModule",{value:!0});const e=function(){if(Le)return Ve;Le=1,Object.defineProperty(Ve,"__esModule",{value:!0});const e=Ce(),t=$().operators,r={maximum:{exclusive:"exclusiveMaximum",ops:[{okStr:"<=",ok:t.LTE,fail:t.GT},{okStr:"<",ok:t.LT,fail:t.GTE}]},minimum:{exclusive:"exclusiveMinimum",ops:[{okStr:">=",ok:t.GTE,fail:t.LT},{okStr:">",ok:t.GT,fail:t.LTE}]}},n={message:t=>e.str`must be ${s(t).okStr} ${t.schemaCode}`,params:t=>e._`{comparison: ${s(t).okStr}, limit: ${t.schemaCode}}`},o={keyword:Object.keys(r),type:"number",schemaType:"number",$data:!0,error:n,code(t){const{data:r,schemaCode:n}=t;t.fail$data(e._`${r} ${s(t).fail} ${n} || isNaN(${r})`)}};function s(e){var t;const n=e.keyword,o=(null===(t=e.parentSchema)||void 0===t?void 0:t[r[n].exclusive])?1:0;return r[n].ops[o]}return Ve.default=o,Ve}(),t=function(){if(Ue)return Be;Ue=1,Object.defineProperty(Be,"__esModule",{value:!0});const e={exclusiveMaximum:"maximum",exclusiveMinimum:"minimum"},t={keyword:Object.keys(e),type:"number",schemaType:"boolean",code({keyword:t,parentSchema:r}){const n=e[t];if(void 0===r[n])throw new Error(`${t} can only be used with ${n}`)}};return Be.default=t,Be}(),r=function(){if(ze)return Ke;ze=1,Object.defineProperty(Ke,"__esModule",{value:!0});const e=$(),t={keyword:"multipleOf",type:"number",schemaType:"number",$data:!0,error:{message:({schemaCode:t})=>e.str`must be multiple of ${t}`,params:({schemaCode:t})=>e._`{multipleOf: ${t}}`},code(t){const{gen:r,data:n,schemaCode:o,it:s}=t,i=s.opts.multipleOfPrecision,a=r.let("res"),c=i?e._`Math.abs(Math.round(${a}) - ${a}) > 1e-${i}`:e._`${a} !== parseInt(${a})`;t.fail$data(e._`(${o} === 0 || (${a} = ${n}/${o}, ${c}))`)}};return Ke.default=t,Ke}(),n=We(),o=function(){if(Qe)return Ye;Qe=1,Object.defineProperty(Ye,"__esModule",{value:!0});const e=G(),t=$(),r={keyword:"pattern",type:"string",schemaType:"string",$data:!0,error:{message:({schemaCode:e})=>t.str`must match pattern "${e}"`,params:({schemaCode:e})=>t._`{pattern: ${e}}`},code(r){const{data:n,$data:o,schema:s,schemaCode:i,it:a}=r,c=a.opts.unicodeRegExp?"u":"",u=o?t._`(new RegExp(${i}, ${c}))`:(0,e.usePattern)(r,s);r.fail$data(t._`!${u}.test(${n})`)}};return Ye.default=r,Ye}(),s=function(){if(Xe)return Ze;Xe=1,Object.defineProperty(Ze,"__esModule",{value:!0});const e=$(),t={message({keyword:t,schemaCode:r}){const n="maxProperties"===t?"more":"fewer";return e.str`must NOT have ${n} than ${r} properties`},params:({schemaCode:t})=>e._`{limit: ${t}}`},r={keyword:["maxProperties","minProperties"],type:"object",schemaType:"number",$data:!0,error:t,code(t){const{keyword:r,data:n,schemaCode:o}=t,s="maxProperties"===r?e.operators.GT:e.operators.LT;t.fail$data(e._`Object.keys(${n}).length ${s} ${o}`)}};return Ze.default=r,Ze}(),i=rt(),a=function(){if(nt)return ot;nt=1,Object.defineProperty(ot,"__esModule",{value:!0});const e=$(),t={message({keyword:t,schemaCode:r}){const n="maxItems"===t?"more":"fewer";return e.str`must NOT have ${n} than ${r} items`},params:({schemaCode:t})=>e._`{limit: ${t}}`},r={keyword:["maxItems","minItems"],type:"array",schemaType:"number",$data:!0,error:t,code(t){const{keyword:r,data:n,schemaCode:o}=t,s="maxItems"===r?e.operators.GT:e.operators.LT;t.fail$data(e._`${n}.length ${s} ${o}`)}};return ot.default=r,ot}(),c=lt(),u=function(){if(ft)return dt;ft=1,Object.defineProperty(dt,"__esModule",{value:!0});const e=$(),t=P(),r=ut(),n={keyword:"const",$data:!0,error:{message:"must be equal to constant",params:({schemaCode:t})=>e._`{allowedValue: ${t}}`},code(n){const{gen:o,data:s,$data:i,schemaCode:a,schema:c}=n;i||c&&"object"==typeof c?n.fail$data(e._`!${(0,t.useFunc)(o,r.default)}(${s}, ${a})`):n.fail(e._`${c} !== ${s}`)}};return dt.default=n,dt}(),l=vt(),f=[e.default,t.default,r.default,n.default,o.default,s.default,i.default,a.default,c.default,{keyword:"type",schemaType:["string","array"]},{keyword:"nullable",schemaType:"boolean"},u.default,l.default];return Me.default=f,Me}var gt,_t={},wt={};function bt(){if(gt)return wt;gt=1,Object.defineProperty(wt,"__esModule",{value:!0}),wt.validateAdditionalItems=void 0;const e=$(),t=P(),r={keyword:"additionalItems",type:"array",schemaType:["boolean","object"],before:"uniqueItems",error:{message:({params:{len:t}})=>e.str`must NOT have more than ${t} items`,params:({params:{len:t}})=>e._`{limit: ${t}}`},code(e){const{parentSchema:r,it:o}=e,{items:s}=r;Array.isArray(s)?n(e,s):(0,t.checkStrictMode)(o,'"additionalItems" is ignored when "items" is not an array of schemas')}};function n(r,n){const{gen:o,schema:s,data:i,keyword:a,it:c}=r;c.items=!0;const u=o.const("len",e._`${i}.length`);if(!1===s)r.setParams({len:n.length}),r.pass(e._`${u} <= ${n.length}`);else if("object"==typeof s&&!(0,t.alwaysValidSchema)(c,s)){const s=o.var("valid",e._`${u} <= ${n.length}`);o.if((0,e.not)(s),(()=>function(s){o.forRange("i",n.length,u,(n=>{r.subschema({keyword:a,dataProp:n,dataPropType:t.Type.Num},s),c.allErrors||o.if((0,e.not)(s),(()=>o.break()))}))}(s))),r.ok(s)}}return wt.validateAdditionalItems=n,wt.default=r,wt}var $t,kt,Et={},Pt={};function St(){if($t)return Pt;$t=1,Object.defineProperty(Pt,"__esModule",{value:!0}),Pt.validateTuple=void 0;const e=$(),t=P(),r=G(),n={keyword:"items",type:"array",schemaType:["object","array","boolean"],before:"uniqueItems",code(e){const{schema:n,it:s}=e;if(Array.isArray(n))return o(e,"additionalItems",n);s.items=!0,(0,t.alwaysValidSchema)(s,n)||e.ok((0,r.validateArray)(e))}};function o(r,n,o=r.schema){const{gen:s,parentSchema:i,data:a,keyword:c,it:u}=r;!function(e){const{opts:r,errSchemaPath:s}=u,i=o.length,a=i===e.minItems&&(i===e.maxItems||!1===e[n]);if(r.strictTuples&&!a){const e=`"${c}" is ${i}-tuple, but minItems or maxItems/${n} are not specified or different at path "${s}"`;(0,t.checkStrictMode)(u,e,r.strictTuples)}}(i),u.opts.unevaluated&&o.length&&!0!==u.items&&(u.items=t.mergeEvaluated.items(s,o.length,u.items));const l=s.name("valid"),f=s.const("len",e._`${a}.length`);o.forEach(((n,o)=>{(0,t.alwaysValidSchema)(u,n)||(s.if(e._`${f} > ${o}`,(()=>r.subschema({keyword:c,schemaProp:o,dataProp:o},l))),r.ok(l))}))}return Pt.validateTuple=o,Pt.default=n,Pt}var jt,Ot={};var xt,At={};function Ct(){if(xt)return At;xt=1,Object.defineProperty(At,"__esModule",{value:!0});const e=$(),t=P(),r={keyword:"contains",type:"array",schemaType:["object","boolean"],before:"uniqueItems",trackErrors:!0,error:{message:({params:{min:t,max:r}})=>void 0===r?e.str`must contain at least ${t} valid item(s)`:e.str`must contain at least ${t} and no more than ${r} valid item(s)`,params:({params:{min:t,max:r}})=>void 0===r?e._`{minContains: ${t}}`:e._`{minContains: ${t}, maxContains: ${r}}`},code(r){const{gen:n,schema:o,parentSchema:s,data:i,it:a}=r;let c,u;const{minContains:l,maxContains:f}=s;a.opts.next?(c=void 0===l?1:l,u=f):c=1;const d=n.const("len",e._`${i}.length`);if(r.setParams({min:c,max:u}),void 0===u&&0===c)return void(0,t.checkStrictMode)(a,'"minContains" == 0 without "maxContains": "contains" keyword ignored');if(void 0!==u&&c>u)return(0,t.checkStrictMode)(a,'"minContains" > "maxContains" is always invalid'),void r.fail();if((0,t.alwaysValidSchema)(a,o)){let t=e._`${d} >= ${c}`;return void 0!==u&&(t=e._`${t} && ${d} <= ${u}`),void r.pass(t)}a.items=!0;const h=n.name("valid");function p(){const t=n.name("_valid"),r=n.let("count",0);m(t,(()=>n.if(t,(()=>function(t){n.code(e._`${t}++`),void 0===u?n.if(e._`${t} >= ${c}`,(()=>n.assign(h,!0).break())):(n.if(e._`${t} > ${u}`,(()=>n.assign(h,!1).break())),1===c?n.assign(h,!0):n.if(e._`${t} >= ${c}`,(()=>n.assign(h,!0))))}(r)))))}function m(e,o){n.forRange("i",0,d,(n=>{r.subschema({keyword:"contains",dataProp:n,dataPropType:t.Type.Num,compositeRule:!0},e),o()}))}void 0===u&&1===c?m(h,(()=>n.if(h,(()=>n.break())))):0===c?(n.let(h,!0),void 0!==u&&n.if(e._`${i}.length > 0`,p)):(n.let(h,!1),p()),r.result(h,(()=>r.reset()))}};return At.default=r,At}var It,Nt={};function Tt(){return It||(It=1,function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.validateSchemaDeps=e.validatePropertyDeps=e.error=void 0;const t=$(),r=P(),n=G();e.error={message:({params:{property:e,depsCount:r,deps:n}})=>{const o=1===r?"property":"properties";return t.str`must have ${o} ${n} when property ${e} is present`},params:({params:{property:e,depsCount:r,deps:n,missingProperty:o}})=>t._`{property: ${e},
|
|
5
5
|
missingProperty: ${o},
|
|
6
6
|
depsCount: ${r},
|
|
7
|
-
deps: ${n}}`};const o={keyword:"dependencies",type:"object",schemaType:"object",error:e.error,code(e){const[t,r]=function({schema:e}){const t={},r={};for(const n in e){if("__proto__"===n)continue;(Array.isArray(e[n])?t:r)[n]=e[n]}return[t,r]}(e);s(e,t),i(e,r)}};function s(e,r=e.schema){const{gen:o,data:s,it:i}=e;if(0===Object.keys(r).length)return;const a=o.let("missing");for(const c in r){const u=r[c];if(0===u.length)continue;const l=(0,n.propertyInData)(o,s,c,i.opts.ownProperties);e.setParams({property:c,depsCount:u.length,deps:u.join(", ")}),i.allErrors?o.if(l,(()=>{for(const t of u)(0,n.checkReportMissingProp)(e,t)})):(o.if(t._`${l} && (${(0,n.checkMissingProp)(e,u,a)})`),(0,n.reportMissingProp)(e,a),o.else())}}function i(e,t=e.schema){const{gen:o,data:s,keyword:i,it:a}=e,c=o.name("valid");for(const u in t)(0,r.alwaysValidSchema)(a,t[u])||(o.if((0,n.propertyInData)(o,s,u,a.opts.ownProperties),(()=>{const t=e.subschema({keyword:i,schemaProp:u},c);e.mergeValidEvaluated(t,c)}),(()=>o.var(c,!0))),e.ok(c))}e.validatePropertyDeps=s,e.validateSchemaDeps=i,e.default=o}(Nt)),Nt}var Rt,qt={};var Dt,Lt={};function Mt(){if(Dt)return Lt;Dt=1,Object.defineProperty(Lt,"__esModule",{value:!0});const e=G(),t=$(),r=A(),n=P(),o={keyword:"additionalProperties",type:["object"],schemaType:["boolean","object"],allowUndefined:!0,trackErrors:!0,error:{message:"must NOT have additional properties",params:({params:e})=>t._`{additionalProperty: ${e.additionalProperty}}`},code(o){const{gen:s,schema:i,parentSchema:a,data:c,errsCount:u,it:l}=o;if(!u)throw new Error("ajv implementation error");const{allErrors:f,opts:d}=l;if(l.props=!0,"all"!==d.removeAdditional&&(0,n.alwaysValidSchema)(l,i))return;const h=(0,e.allSchemaProperties)(a.properties),p=(0,e.allSchemaProperties)(a.patternProperties);function m(e){s.code(t._`delete ${c}[${e}]`)}function v(e){if("all"===d.removeAdditional||d.removeAdditional&&!1===i)m(e);else{if(!1===i)return o.setParams({additionalProperty:e}),o.error(),void(f||s.break());if("object"==typeof i&&!(0,n.alwaysValidSchema)(l,i)){const r=s.name("valid");"failing"===d.removeAdditional?(y(e,r,!1),s.if((0,t.not)(r),(()=>{o.reset(),m(e)}))):(y(e,r),f||s.if((0,t.not)(r),(()=>s.break())))}}}function y(e,t,r){const s={keyword:"additionalProperties",dataProp:e,dataPropType:n.Type.Str};!1===r&&Object.assign(s,{compositeRule:!0,createErrors:!1,allErrors:!1}),o.subschema(s,t)}s.forIn("key",c,(r=>{h.length||p.length?s.if(function(r){let i;if(h.length>8){const t=(0,n.schemaRefOrVal)(l,a.properties,"properties");i=(0,e.isOwnProperty)(s,t,r)}else i=h.length?(0,t.or)(...h.map((e=>t._`${r} === ${e}`))):t.nil;return p.length&&(i=(0,t.or)(i,...p.map((n=>t._`${(0,e.usePattern)(o,n)}.test(${r})`)))),(0,t.not)(i)}(r),(()=>v(r))):v(r)})),o.ok(t._`${u} === ${r.default.errors}`)}};return Lt.default=o,Lt}var Vt,Ut={};var Bt,zt={};var Kt,Ft={};var Jt,Gt={};var Ht,Wt={};var Qt,Yt={};var Xt,Zt={};var er,tr,rr={};function nr(){if(tr)return _t;tr=1,Object.defineProperty(_t,"__esModule",{value:!0});const e=bt(),t=function(){if(kt)return Et;kt=1,Object.defineProperty(Et,"__esModule",{value:!0});const e=St(),t={keyword:"prefixItems",type:"array",schemaType:["array"],before:"uniqueItems",code:t=>(0,e.validateTuple)(t,"items")};return Et.default=t,Et}(),r=St(),n=function(){if(jt)return Ot;jt=1,Object.defineProperty(Ot,"__esModule",{value:!0});const e=$(),t=P(),r=G(),n=bt(),o={keyword:"items",type:"array",schemaType:["object","boolean"],before:"uniqueItems",error:{message:({params:{len:t}})=>e.str`must NOT have more than ${t} items`,params:({params:{len:t}})=>e._`{limit: ${t}}`},code(e){const{schema:o,parentSchema:s,it:i}=e,{prefixItems:a}=s;i.items=!0,(0,t.alwaysValidSchema)(i,o)||(a?(0,n.validateAdditionalItems)(e,a):e.ok((0,r.validateArray)(e)))}};return Ot.default=o,Ot}(),o=Ct(),s=Tt(),i=function(){if(Rt)return qt;Rt=1,Object.defineProperty(qt,"__esModule",{value:!0});const e=$(),t=P(),r={keyword:"propertyNames",type:"object",schemaType:["object","boolean"],error:{message:"property name must be valid",params:({params:t})=>e._`{propertyName: ${t.propertyName}}`},code(r){const{gen:n,schema:o,data:s,it:i}=r;if((0,t.alwaysValidSchema)(i,o))return;const a=n.name("valid");n.forIn("key",s,(t=>{r.setParams({propertyName:t}),r.subschema({keyword:"propertyNames",data:t,dataTypes:["string"],propertyName:t,compositeRule:!0},a),n.if((0,e.not)(a),(()=>{r.error(!0),i.allErrors||n.break()}))})),r.ok(a)}};return qt.default=r,qt}(),a=Mt(),c=function(){if(Vt)return Ut;Vt=1,Object.defineProperty(Ut,"__esModule",{value:!0});const e=ae(),t=G(),r=P(),n=Mt(),o={keyword:"properties",type:"object",schemaType:"object",code(o){const{gen:s,schema:i,parentSchema:a,data:c,it:u}=o;"all"===u.opts.removeAdditional&&void 0===a.additionalProperties&&n.default.code(new e.KeywordCxt(u,n.default,"additionalProperties"));const l=(0,t.allSchemaProperties)(i);for(const e of l)u.definedProperties.add(e);u.opts.unevaluated&&l.length&&!0!==u.props&&(u.props=r.mergeEvaluated.props(s,(0,r.toHash)(l),u.props));const f=l.filter((e=>!(0,r.alwaysValidSchema)(u,i[e])));if(0===f.length)return;const d=s.name("valid");for(const e of f)h(e)?p(e):(s.if((0,t.propertyInData)(s,c,e,u.opts.ownProperties)),p(e),u.allErrors||s.else().var(d,!0),s.endIf()),o.it.definedProperties.add(e),o.ok(d);function h(e){return u.opts.useDefaults&&!u.compositeRule&&void 0!==i[e].default}function p(e){o.subschema({keyword:"properties",schemaProp:e,dataProp:e},d)}}};return Ut.default=o,Ut}(),u=function(){if(Bt)return zt;Bt=1,Object.defineProperty(zt,"__esModule",{value:!0});const e=G(),t=$(),r=P(),n=P(),o={keyword:"patternProperties",type:"object",schemaType:"object",code(o){const{gen:s,schema:i,data:a,parentSchema:c,it:u}=o,{opts:l}=u,f=(0,e.allSchemaProperties)(i),d=f.filter((e=>(0,r.alwaysValidSchema)(u,i[e])));if(0===f.length||d.length===f.length&&(!u.opts.unevaluated||!0===u.props))return;const h=l.strictSchema&&!l.allowMatchingProperties&&c.properties,p=s.name("valid");!0===u.props||u.props instanceof t.Name||(u.props=(0,n.evaluatedPropsToName)(s,u.props));const{props:m}=u;function v(e){for(const t in h)new RegExp(e).test(t)&&(0,r.checkStrictMode)(u,`property ${t} matches pattern ${e} (use allowMatchingProperties)`)}function y(r){s.forIn("key",a,(i=>{s.if(t._`${(0,e.usePattern)(o,r)}.test(${i})`,(()=>{const e=d.includes(r);e||o.subschema({keyword:"patternProperties",schemaProp:r,dataProp:i,dataPropType:n.Type.Str},p),u.opts.unevaluated&&!0!==m?s.assign(t._`${m}[${i}]`,!0):e||u.allErrors||s.if((0,t.not)(p),(()=>s.break()))}))}))}!function(){for(const e of f)h&&v(e),u.allErrors?y(e):(s.var(p,!0),y(e),s.if(p))}()}};return zt.default=o,zt}(),l=function(){if(Kt)return Ft;Kt=1,Object.defineProperty(Ft,"__esModule",{value:!0});const e=P(),t={keyword:"not",schemaType:["object","boolean"],trackErrors:!0,code(t){const{gen:r,schema:n,it:o}=t;if((0,e.alwaysValidSchema)(o,n))return void t.fail();const s=r.name("valid");t.subschema({keyword:"not",compositeRule:!0,createErrors:!1,allErrors:!1},s),t.failResult(s,(()=>t.reset()),(()=>t.error()))},error:{message:"must NOT be valid"}};return Ft.default=t,Ft}(),f=function(){if(Jt)return Gt;Jt=1,Object.defineProperty(Gt,"__esModule",{value:!0});const e={keyword:"anyOf",schemaType:"array",trackErrors:!0,code:G().validateUnion,error:{message:"must match a schema in anyOf"}};return Gt.default=e,Gt}(),d=function(){if(Ht)return Wt;Ht=1,Object.defineProperty(Wt,"__esModule",{value:!0});const e=$(),t=P(),r={keyword:"oneOf",schemaType:"array",trackErrors:!0,error:{message:"must match exactly one schema in oneOf",params:({params:t})=>e._`{passingSchemas: ${t.passing}}`},code(r){const{gen:n,schema:o,parentSchema:s,it:i}=r;if(!Array.isArray(o))throw new Error("ajv implementation error");if(i.opts.discriminator&&s.discriminator)return;const a=o,c=n.let("valid",!1),u=n.let("passing",null),l=n.name("_valid");r.setParams({passing:u}),n.block((function(){a.forEach(((o,s)=>{let a;(0,t.alwaysValidSchema)(i,o)?n.var(l,!0):a=r.subschema({keyword:"oneOf",schemaProp:s,compositeRule:!0},l),s>0&&n.if(e._`${l} && ${c}`).assign(c,!1).assign(u,e._`[${u}, ${s}]`).else(),n.if(l,(()=>{n.assign(c,!0),n.assign(u,s),a&&r.mergeEvaluated(a,e.Name)}))}))})),r.result(c,(()=>r.reset()),(()=>r.error(!0)))}};return Wt.default=r,Wt}(),h=function(){if(Qt)return Yt;Qt=1,Object.defineProperty(Yt,"__esModule",{value:!0});const e=P(),t={keyword:"allOf",schemaType:"array",code(t){const{gen:r,schema:n,it:o}=t;if(!Array.isArray(n))throw new Error("ajv implementation error");const s=r.name("valid");n.forEach(((r,n)=>{if((0,e.alwaysValidSchema)(o,r))return;const i=t.subschema({keyword:"allOf",schemaProp:n},s);t.ok(s),t.mergeEvaluated(i)}))}};return Yt.default=t,Yt}(),p=function(){if(Xt)return Zt;Xt=1,Object.defineProperty(Zt,"__esModule",{value:!0});const e=$(),t=P(),r={keyword:"if",schemaType:["object","boolean"],trackErrors:!0,error:{message:({params:t})=>e.str`must match "${t.ifClause}" schema`,params:({params:t})=>e._`{failingKeyword: ${t.ifClause}}`},code(r){const{gen:o,parentSchema:s,it:i}=r;void 0===s.then&&void 0===s.else&&(0,t.checkStrictMode)(i,'"if" without "then" and "else" is ignored');const a=n(i,"then"),c=n(i,"else");if(!a&&!c)return;const u=o.let("valid",!0),l=o.name("_valid");if(function(){const e=r.subschema({keyword:"if",compositeRule:!0,createErrors:!1,allErrors:!1},l);r.mergeEvaluated(e)}(),r.reset(),a&&c){const e=o.let("ifClause");r.setParams({ifClause:e}),o.if(l,f("then",e),f("else",e))}else a?o.if(l,f("then")):o.if((0,e.not)(l),f("else"));function f(t,n){return()=>{const s=r.subschema({keyword:t},l);o.assign(u,l),r.mergeValidEvaluated(s,u),n?o.assign(n,e._`${t}`):r.setParams({ifClause:t})}}r.pass(u,(()=>r.error(!0)))}};function n(e,r){const n=e.schema[r];return void 0!==n&&!(0,t.alwaysValidSchema)(e,n)}return Zt.default=r,Zt}(),m=function(){if(er)return rr;er=1,Object.defineProperty(rr,"__esModule",{value:!0});const e=P(),t={keyword:["then","else"],schemaType:["object","boolean"],code({keyword:t,parentSchema:r,it:n}){void 0===r.if&&(0,e.checkStrictMode)(n,`"${t}" without "if" is ignored`)}};return rr.default=t,rr}();return _t.default=function(v=!1){const y=[l.default,f.default,d.default,h.default,p.default,m.default,i.default,a.default,s.default,c.default,u.default];return v?y.push(t.default,n.default):y.push(e.default,r.default),y.push(o.default),y},_t}var or,sr,ir,ar={},cr={};function ur(){if(or)return cr;or=1,Object.defineProperty(cr,"__esModule",{value:!0});const e=$(),t={keyword:"format",type:["number","string"],schemaType:"string",$data:!0,error:{message:({schemaCode:t})=>e.str`must match format "${t}"`,params:({schemaCode:t})=>e._`{format: ${t}}`},code(t,r){const{gen:n,data:o,$data:s,schema:i,schemaCode:a,it:c}=t,{opts:u,errSchemaPath:l,schemaEnv:f,self:d}=c;u.validateFormats&&(s?function(){const s=n.scopeValue("formats",{ref:d.formats,code:u.code.formats}),i=n.const("fDef",e._`${s}[${a}]`),c=n.let("fType"),l=n.let("format");n.if(e._`typeof ${i} == "object" && !(${i} instanceof RegExp)`,(()=>n.assign(c,e._`${i}.type || "string"`).assign(l,e._`${i}.validate`)),(()=>n.assign(c,e._`"string"`).assign(l,i))),t.fail$data((0,e.or)(!1===u.strictSchema?e.nil:e._`${a} && !${l}`,function(){const t=f.$async?e._`(${i}.async ? await ${l}(${o}) : ${l}(${o}))`:e._`${l}(${o})`,n=e._`(typeof ${l} == "function" ? ${t} : ${l}.test(${o}))`;return e._`${l} && ${l} !== true && ${c} === ${r} && !${n}`}()))}():function(){const s=d.formats[i];if(!s)return void function(){if(!1===u.strictSchema)return void d.logger.warn(e());throw new Error(e());function e(){return`unknown format "${i}" ignored in schema at path "${l}"`}}();if(!0===s)return;const[a,c,h]=function(t){const r=t instanceof RegExp?(0,e.regexpCode)(t):u.code.formats?e._`${u.code.formats}${(0,e.getProperty)(i)}`:void 0,o=n.scopeValue("formats",{key:i,ref:t,code:r});if("object"==typeof t&&!(t instanceof RegExp))return[t.type||"string",t.validate,e._`${o}.validate`];return["string",t,o]}(s);a===r&&t.pass(function(){if("object"==typeof s&&!(s instanceof RegExp)&&s.async){if(!f.$async)throw new Error("async format in sync schema");return e._`await ${h}(${o})`}return"function"==typeof c?e._`${h}(${o})`:e._`${h}.test(${o})`}())}())}};return cr.default=t,cr}function lr(){if(ir)return Te;ir=1,Object.defineProperty(Te,"__esModule",{value:!0});const e=De(),t=yt(),r=nr(),n=function(){if(sr)return ar;sr=1,Object.defineProperty(ar,"__esModule",{value:!0});const e=[ur().default];return ar.default=e,ar}(),o=[e.default,t.default,r.default(),n.default,["title","description","default"]];return Te.default=o,Te}var fr,dr,hr={},pr={};function mr(){if(dr)return hr;dr=1,Object.defineProperty(hr,"__esModule",{value:!0});const e=$(),t=(fr||(fr=1,Object.defineProperty(pr,"__esModule",{value:!0}),pr.DiscrError=void 0,function(e){e.Tag="tag",e.Mapping="mapping"}(r||(pr.DiscrError=r={}))),pr);var r;const n=ve(),o=he(),s=P(),i={keyword:"discriminator",type:"object",schemaType:"object",error:{message:({params:{discrError:e,tagName:r}})=>e===t.DiscrError.Tag?`tag "${r}" must be string`:`value of tag "${r}" must be in oneOf`,params:({params:{discrError:t,tag:r,tagName:n}})=>e._`{error: ${t}, tag: ${n}, tagValue: ${r}}`},code(r){const{gen:i,data:a,schema:c,parentSchema:u,it:l}=r,{oneOf:f}=u;if(!l.opts.discriminator)throw new Error("discriminator: requires discriminator option");const d=c.propertyName;if("string"!=typeof d)throw new Error("discriminator: requires propertyName");if(c.mapping)throw new Error("discriminator: mapping is not supported");if(!f)throw new Error("discriminator: requires oneOf keyword");const h=i.let("valid",!1),p=i.const("tag",e._`${a}${(0,e.getProperty)(d)}`);function m(t){const n=i.name("valid"),o=r.subschema({keyword:"oneOf",schemaProp:t},n);return r.mergeEvaluated(o,e.Name),n}i.if(e._`typeof ${p} == "string"`,(()=>function(){const a=function(){var e;const t={},r=a(u);let i=!0;for(let t=0;t<f.length;t++){let u=f[t];if((null==u?void 0:u.$ref)&&!(0,s.schemaHasRulesButRef)(u,l.self.RULES)){const e=u.$ref;if(u=n.resolveRef.call(l.self,l.schemaEnv.root,l.baseId,e),u instanceof n.SchemaEnv&&(u=u.schema),void 0===u)throw new o.default(l.opts.uriResolver,l.baseId,e)}const h=null===(e=null==u?void 0:u.properties)||void 0===e?void 0:e[d];if("object"!=typeof h)throw new Error(`discriminator: oneOf subschemas (or referenced schemas) must have "properties/${d}"`);i=i&&(r||a(u)),c(h,t)}if(!i)throw new Error(`discriminator: "${d}" must be required`);return t;function a({required:e}){return Array.isArray(e)&&e.includes(d)}function c(e,t){if(e.const)h(e.const,t);else{if(!e.enum)throw new Error(`discriminator: "properties/${d}" must have "const" or "enum"`);for(const r of e.enum)h(r,t)}}function h(e,r){if("string"!=typeof e||e in t)throw new Error(`discriminator: "${d}" values must be unique strings`);t[e]=r}}();i.if(!1);for(const t in a)i.elseIf(e._`${p} === ${t}`),i.assign(h,m(a[t]));i.else(),r.error(!1,{discrError:t.DiscrError.Mapping,tag:p,tagName:d}),i.endIf()}()),(()=>r.error(!1,{discrError:t.DiscrError.Tag,tag:p,tagName:d}))),r.ok(h)}};return hr.default=i,hr}var vr,yr={id:"http://json-schema.org/draft-04/schema#",$schema:"http://json-schema.org/draft-04/schema#",description:"Core schema meta-schema",definitions:{schemaArray:{type:"array",minItems:1,items:{$ref:"#"}},positiveInteger:{type:"integer",minimum:0},positiveIntegerDefault0:{allOf:[{$ref:"#/definitions/positiveInteger"},{default:0}]},simpleTypes:{enum:["array","boolean","integer","null","number","object","string"]},stringArray:{type:"array",items:{type:"string"},minItems:1,uniqueItems:!0}},type:"object",properties:{id:{type:"string",format:"uri"},$schema:{type:"string",format:"uri"},title:{type:"string"},description:{type:"string"},default:{},multipleOf:{type:"number",minimum:0,exclusiveMinimum:!0},maximum:{type:"number"},exclusiveMaximum:{type:"boolean",default:!1},minimum:{type:"number"},exclusiveMinimum:{type:"boolean",default:!1},maxLength:{$ref:"#/definitions/positiveInteger"},minLength:{$ref:"#/definitions/positiveIntegerDefault0"},pattern:{type:"string",format:"regex"},additionalItems:{anyOf:[{type:"boolean"},{$ref:"#"}],default:{}},items:{anyOf:[{$ref:"#"},{$ref:"#/definitions/schemaArray"}],default:{}},maxItems:{$ref:"#/definitions/positiveInteger"},minItems:{$ref:"#/definitions/positiveIntegerDefault0"},uniqueItems:{type:"boolean",default:!1},maxProperties:{$ref:"#/definitions/positiveInteger"},minProperties:{$ref:"#/definitions/positiveIntegerDefault0"},required:{$ref:"#/definitions/stringArray"},additionalProperties:{anyOf:[{type:"boolean"},{$ref:"#"}],default:{}},definitions:{type:"object",additionalProperties:{$ref:"#"},default:{}},properties:{type:"object",additionalProperties:{$ref:"#"},default:{}},patternProperties:{type:"object",additionalProperties:{$ref:"#"},default:{}},dependencies:{type:"object",additionalProperties:{anyOf:[{$ref:"#"},{$ref:"#/definitions/stringArray"}]}},enum:{type:"array",minItems:1,uniqueItems:!0},type:{anyOf:[{$ref:"#/definitions/simpleTypes"},{type:"array",items:{$ref:"#/definitions/simpleTypes"},minItems:1,uniqueItems:!0}]},allOf:{$ref:"#/definitions/schemaArray"},anyOf:{$ref:"#/definitions/schemaArray"},oneOf:{$ref:"#/definitions/schemaArray"},not:{$ref:"#"}},dependencies:{exclusiveMaximum:["maximum"],exclusiveMinimum:["minimum"]},default:{}};var gr=(vr||(vr=1,function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.CodeGen=t.Name=t.nil=t.stringify=t.str=t._=t.KeywordCxt=void 0;const r=Ce(),n=lr(),o=mr(),s=yr,i=["/properties"],a="http://json-schema.org/draft-04/schema";class c extends r.default{constructor(e={}){super({...e,schemaId:"id"})}_addVocabularies(){super._addVocabularies(),n.default.forEach((e=>this.addVocabulary(e))),this.opts.discriminator&&this.addKeyword(o.default)}_addDefaultMetaSchema(){if(super._addDefaultMetaSchema(),!this.opts.meta)return;const e=this.opts.$data?this.$dataMetaSchema(s,i):s;this.addMetaSchema(e,a,!1),this.refs["http://json-schema.org/schema"]=a}defaultMeta(){return this.opts.defaultMeta=super.defaultMeta()||(this.getSchema(a)?a:void 0)}}e.exports=t=c,Object.defineProperty(t,"__esModule",{value:!0}),t.default=c;var u=Ce();Object.defineProperty(t,"KeywordCxt",{enumerable:!0,get:function(){return u.KeywordCxt}});var l=Ce();Object.defineProperty(t,"_",{enumerable:!0,get:function(){return l._}}),Object.defineProperty(t,"str",{enumerable:!0,get:function(){return l.str}}),Object.defineProperty(t,"stringify",{enumerable:!0,get:function(){return l.stringify}}),Object.defineProperty(t,"nil",{enumerable:!0,get:function(){return l.nil}}),Object.defineProperty(t,"Name",{enumerable:!0,get:function(){return l.Name}}),Object.defineProperty(t,"CodeGen",{enumerable:!0,get:function(){return l.CodeGen}})}(l,l.exports)),l.exports),_r=c(gr);class wr{sessionEvents=new EventTarget;constructor(){(async()=>{await Promise.resolve();for(const e of this.getLoggedInActors()){const t=new CustomEvent("login",{detail:{session:{actor:e}}});this.sessionEvents.dispatchEvent(t)}const e=new CustomEvent("initialized");this.sessionEvents.dispatchEvent(e)})()}loggedInActors=[];getLoggedInActors(){if("undefined"!=typeof window){const e=window.localStorage.getItem("graffiti-actor");return e?e.split(",").map(decodeURIComponent):[]}return this.loggedInActors}setLoggedInActors(e){"undefined"!=typeof window?window.localStorage.setItem("graffiti-actor",e.map(encodeURIComponent).join(",")):this.loggedInActors=e}login=async e=>{let t,r=e?.actor;if(!r&&"undefined"!=typeof window){const e=window.prompt("This is an insecure implementation of the Graffiti API for *demo purposes only*. Do not store any sensitive information here. \n\n Simply choose a username to log in.");e&&(r=e)}if(r){const e=this.getLoggedInActors();e.includes(r)||this.setLoggedInActors([...e,r]),t={session:{actor:r}}}else t={error:new Error("No actor ID provided to login")};const n=new CustomEvent("login",{detail:t});this.sessionEvents.dispatchEvent(n)};logout=async e=>{const t=this.getLoggedInActors(),r=t.includes(e.actor);r&&this.setLoggedInActors(t.filter((t=>t!==e.actor)));const n=r?{actor:e.actor}:{actor:e.actor,error:new Error("Not logged in with that actor")},o=new CustomEvent("logout",{detail:n});this.sessionEvents.dispatchEvent(o)}}var br="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function $r(){throw new Error("setTimeout has not been defined")}function kr(){throw new Error("clearTimeout has not been defined")}var Er=$r,Pr=kr;function Sr(e){if(Er===setTimeout)return setTimeout(e,0);if((Er===$r||!Er)&&setTimeout)return Er=setTimeout,setTimeout(e,0);try{return Er(e,0)}catch(t){try{return Er.call(null,e,0)}catch(t){return Er.call(this,e,0)}}}"function"==typeof br.setTimeout&&(Er=setTimeout),"function"==typeof br.clearTimeout&&(Pr=clearTimeout);var jr,Or=[],xr=!1,Ar=-1;function Cr(){xr&&jr&&(xr=!1,jr.length?Or=jr.concat(Or):Ar=-1,Or.length&&Ir())}function Ir(){if(!xr){var e=Sr(Cr);xr=!0;for(var t=Or.length;t;){for(jr=Or,Or=[];++Ar<t;)jr&&jr[Ar].run();Ar=-1,t=Or.length}jr=null,xr=!1,function(e){if(Pr===clearTimeout)return clearTimeout(e);if((Pr===kr||!Pr)&&clearTimeout)return Pr=clearTimeout,clearTimeout(e);try{return Pr(e)}catch(t){try{return Pr.call(null,e)}catch(t){return Pr.call(this,e)}}}(e)}}function Nr(e,t){this.fun=e,this.array=t}Nr.prototype.run=function(){this.fun.apply(null,this.array)};function Tr(){}var Rr=Tr,qr=Tr,Dr=Tr,Lr=Tr,Mr=Tr,Vr=Tr,Ur=Tr;var Br=br.performance||{},zr=Br.now||Br.mozNow||Br.msNow||Br.oNow||Br.webkitNow||function(){return(new Date).getTime()};var Kr=new Date;var Fr,Jr={nextTick:function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)t[r-1]=arguments[r];Or.push(new Nr(e,t)),1!==Or.length||xr||Sr(Ir)},title:"browser",browser:!0,env:{},argv:[],version:"",versions:{},on:Rr,addListener:qr,once:Dr,off:Lr,removeListener:Mr,removeAllListeners:Vr,emit:Ur,binding:function(e){throw new Error("process.binding is not supported")},cwd:function(){return"/"},chdir:function(e){throw new Error("process.chdir is not supported")},umask:function(){return 0},hrtime:function(e){var t=.001*zr.call(Br),r=Math.floor(t),n=Math.floor(t%1*1e9);return e&&(r-=e[0],(n-=e[1])<0&&(r--,n+=1e9)),[r,n]},platform:"browser",release:{},config:{},uptime:function(){return(new Date-Kr)/1e3}},Gr={exports:{}};var Hr,Wr=(Fr||(Fr=1,Gr.exports=function(e){var t=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];function r(e,t){var r=e[0],n=e[1],o=e[2],s=e[3];n=((n+=((o=((o+=((s=((s+=((r=((r+=(n&o|~n&s)+t[0]-680876936|0)<<7|r>>>25)+n|0)&n|~r&o)+t[1]-389564586|0)<<12|s>>>20)+r|0)&r|~s&n)+t[2]+606105819|0)<<17|o>>>15)+s|0)&s|~o&r)+t[3]-1044525330|0)<<22|n>>>10)+o|0,n=((n+=((o=((o+=((s=((s+=((r=((r+=(n&o|~n&s)+t[4]-176418897|0)<<7|r>>>25)+n|0)&n|~r&o)+t[5]+1200080426|0)<<12|s>>>20)+r|0)&r|~s&n)+t[6]-1473231341|0)<<17|o>>>15)+s|0)&s|~o&r)+t[7]-45705983|0)<<22|n>>>10)+o|0,n=((n+=((o=((o+=((s=((s+=((r=((r+=(n&o|~n&s)+t[8]+1770035416|0)<<7|r>>>25)+n|0)&n|~r&o)+t[9]-1958414417|0)<<12|s>>>20)+r|0)&r|~s&n)+t[10]-42063|0)<<17|o>>>15)+s|0)&s|~o&r)+t[11]-1990404162|0)<<22|n>>>10)+o|0,n=((n+=((o=((o+=((s=((s+=((r=((r+=(n&o|~n&s)+t[12]+1804603682|0)<<7|r>>>25)+n|0)&n|~r&o)+t[13]-40341101|0)<<12|s>>>20)+r|0)&r|~s&n)+t[14]-1502002290|0)<<17|o>>>15)+s|0)&s|~o&r)+t[15]+1236535329|0)<<22|n>>>10)+o|0,n=((n+=((o=((o+=((s=((s+=((r=((r+=(n&s|o&~s)+t[1]-165796510|0)<<5|r>>>27)+n|0)&o|n&~o)+t[6]-1069501632|0)<<9|s>>>23)+r|0)&n|r&~n)+t[11]+643717713|0)<<14|o>>>18)+s|0)&r|s&~r)+t[0]-373897302|0)<<20|n>>>12)+o|0,n=((n+=((o=((o+=((s=((s+=((r=((r+=(n&s|o&~s)+t[5]-701558691|0)<<5|r>>>27)+n|0)&o|n&~o)+t[10]+38016083|0)<<9|s>>>23)+r|0)&n|r&~n)+t[15]-660478335|0)<<14|o>>>18)+s|0)&r|s&~r)+t[4]-405537848|0)<<20|n>>>12)+o|0,n=((n+=((o=((o+=((s=((s+=((r=((r+=(n&s|o&~s)+t[9]+568446438|0)<<5|r>>>27)+n|0)&o|n&~o)+t[14]-1019803690|0)<<9|s>>>23)+r|0)&n|r&~n)+t[3]-187363961|0)<<14|o>>>18)+s|0)&r|s&~r)+t[8]+1163531501|0)<<20|n>>>12)+o|0,n=((n+=((o=((o+=((s=((s+=((r=((r+=(n&s|o&~s)+t[13]-1444681467|0)<<5|r>>>27)+n|0)&o|n&~o)+t[2]-51403784|0)<<9|s>>>23)+r|0)&n|r&~n)+t[7]+1735328473|0)<<14|o>>>18)+s|0)&r|s&~r)+t[12]-1926607734|0)<<20|n>>>12)+o|0,n=((n+=((o=((o+=((s=((s+=((r=((r+=(n^o^s)+t[5]-378558|0)<<4|r>>>28)+n|0)^n^o)+t[8]-2022574463|0)<<11|s>>>21)+r|0)^r^n)+t[11]+1839030562|0)<<16|o>>>16)+s|0)^s^r)+t[14]-35309556|0)<<23|n>>>9)+o|0,n=((n+=((o=((o+=((s=((s+=((r=((r+=(n^o^s)+t[1]-1530992060|0)<<4|r>>>28)+n|0)^n^o)+t[4]+1272893353|0)<<11|s>>>21)+r|0)^r^n)+t[7]-155497632|0)<<16|o>>>16)+s|0)^s^r)+t[10]-1094730640|0)<<23|n>>>9)+o|0,n=((n+=((o=((o+=((s=((s+=((r=((r+=(n^o^s)+t[13]+681279174|0)<<4|r>>>28)+n|0)^n^o)+t[0]-358537222|0)<<11|s>>>21)+r|0)^r^n)+t[3]-722521979|0)<<16|o>>>16)+s|0)^s^r)+t[6]+76029189|0)<<23|n>>>9)+o|0,n=((n+=((o=((o+=((s=((s+=((r=((r+=(n^o^s)+t[9]-640364487|0)<<4|r>>>28)+n|0)^n^o)+t[12]-421815835|0)<<11|s>>>21)+r|0)^r^n)+t[15]+530742520|0)<<16|o>>>16)+s|0)^s^r)+t[2]-995338651|0)<<23|n>>>9)+o|0,n=((n+=((s=((s+=(n^((r=((r+=(o^(n|~s))+t[0]-198630844|0)<<6|r>>>26)+n|0)|~o))+t[7]+1126891415|0)<<10|s>>>22)+r|0)^((o=((o+=(r^(s|~n))+t[14]-1416354905|0)<<15|o>>>17)+s|0)|~r))+t[5]-57434055|0)<<21|n>>>11)+o|0,n=((n+=((s=((s+=(n^((r=((r+=(o^(n|~s))+t[12]+1700485571|0)<<6|r>>>26)+n|0)|~o))+t[3]-1894986606|0)<<10|s>>>22)+r|0)^((o=((o+=(r^(s|~n))+t[10]-1051523|0)<<15|o>>>17)+s|0)|~r))+t[1]-2054922799|0)<<21|n>>>11)+o|0,n=((n+=((s=((s+=(n^((r=((r+=(o^(n|~s))+t[8]+1873313359|0)<<6|r>>>26)+n|0)|~o))+t[15]-30611744|0)<<10|s>>>22)+r|0)^((o=((o+=(r^(s|~n))+t[6]-1560198380|0)<<15|o>>>17)+s|0)|~r))+t[13]+1309151649|0)<<21|n>>>11)+o|0,n=((n+=((s=((s+=(n^((r=((r+=(o^(n|~s))+t[4]-145523070|0)<<6|r>>>26)+n|0)|~o))+t[11]-1120210379|0)<<10|s>>>22)+r|0)^((o=((o+=(r^(s|~n))+t[2]+718787259|0)<<15|o>>>17)+s|0)|~r))+t[9]-343485551|0)<<21|n>>>11)+o|0,e[0]=r+e[0]|0,e[1]=n+e[1]|0,e[2]=o+e[2]|0,e[3]=s+e[3]|0}function n(e){var t,r=[];for(t=0;t<64;t+=4)r[t>>2]=e.charCodeAt(t)+(e.charCodeAt(t+1)<<8)+(e.charCodeAt(t+2)<<16)+(e.charCodeAt(t+3)<<24);return r}function o(e){var t,r=[];for(t=0;t<64;t+=4)r[t>>2]=e[t]+(e[t+1]<<8)+(e[t+2]<<16)+(e[t+3]<<24);return r}function s(e){var t,o,s,i,a,c,u=e.length,l=[1732584193,-271733879,-1732584194,271733878];for(t=64;t<=u;t+=64)r(l,n(e.substring(t-64,t)));for(o=(e=e.substring(t-64)).length,s=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],t=0;t<o;t+=1)s[t>>2]|=e.charCodeAt(t)<<(t%4<<3);if(s[t>>2]|=128<<(t%4<<3),t>55)for(r(l,s),t=0;t<16;t+=1)s[t]=0;return i=(i=8*u).toString(16).match(/(.*?)(.{0,8})$/),a=parseInt(i[2],16),c=parseInt(i[1],16)||0,s[14]=a,s[15]=c,r(l,s),l}function i(e){var t,n,s,i,a,c,u=e.length,l=[1732584193,-271733879,-1732584194,271733878];for(t=64;t<=u;t+=64)r(l,o(e.subarray(t-64,t)));for(n=(e=t-64<u?e.subarray(t-64):new Uint8Array(0)).length,s=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],t=0;t<n;t+=1)s[t>>2]|=e[t]<<(t%4<<3);if(s[t>>2]|=128<<(t%4<<3),t>55)for(r(l,s),t=0;t<16;t+=1)s[t]=0;return i=(i=8*u).toString(16).match(/(.*?)(.{0,8})$/),a=parseInt(i[2],16),c=parseInt(i[1],16)||0,s[14]=a,s[15]=c,r(l,s),l}function a(e){var r,n="";for(r=0;r<4;r+=1)n+=t[e>>8*r+4&15]+t[e>>8*r&15];return n}function c(e){var t;for(t=0;t<e.length;t+=1)e[t]=a(e[t]);return e.join("")}function u(e){return/[\u0080-\uFFFF]/.test(e)&&(e=unescape(encodeURIComponent(e))),e}function l(e,t){var r,n=e.length,o=new ArrayBuffer(n),s=new Uint8Array(o);for(r=0;r<n;r+=1)s[r]=e.charCodeAt(r);return t?s:o}function f(e){return String.fromCharCode.apply(null,new Uint8Array(e))}function d(e,t,r){var n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e)),n.set(new Uint8Array(t),e.byteLength),n}function h(e){var t,r=[],n=e.length;for(t=0;t<n-1;t+=2)r.push(parseInt(e.substr(t,2),16));return String.fromCharCode.apply(String,r)}function p(){this.reset()}return c(s("hello")),"undefined"==typeof ArrayBuffer||ArrayBuffer.prototype.slice||function(){function t(e,t){return(e=0|e||0)<0?Math.max(e+t,0):Math.min(e,t)}ArrayBuffer.prototype.slice=function(r,n){var o,s,i,a,c=this.byteLength,u=t(r,c),l=c;return n!==e&&(l=t(n,c)),u>l?new ArrayBuffer(0):(o=l-u,s=new ArrayBuffer(o),i=new Uint8Array(s),a=new Uint8Array(this,u,o),i.set(a),s)}}(),p.prototype.append=function(e){return this.appendBinary(u(e)),this},p.prototype.appendBinary=function(e){this._buff+=e,this._length+=e.length;var t,o=this._buff.length;for(t=64;t<=o;t+=64)r(this._hash,n(this._buff.substring(t-64,t)));return this._buff=this._buff.substring(t-64),this},p.prototype.end=function(e){var t,r,n=this._buff,o=n.length,s=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(t=0;t<o;t+=1)s[t>>2]|=n.charCodeAt(t)<<(t%4<<3);return this._finish(s,o),r=c(this._hash),e&&(r=h(r)),this.reset(),r},p.prototype.reset=function(){return this._buff="",this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},p.prototype.getState=function(){return{buff:this._buff,length:this._length,hash:this._hash.slice()}},p.prototype.setState=function(e){return this._buff=e.buff,this._length=e.length,this._hash=e.hash,this},p.prototype.destroy=function(){delete this._hash,delete this._buff,delete this._length},p.prototype._finish=function(e,t){var n,o,s,i=t;if(e[i>>2]|=128<<(i%4<<3),i>55)for(r(this._hash,e),i=0;i<16;i+=1)e[i]=0;n=(n=8*this._length).toString(16).match(/(.*?)(.{0,8})$/),o=parseInt(n[2],16),s=parseInt(n[1],16)||0,e[14]=o,e[15]=s,r(this._hash,e)},p.hash=function(e,t){return p.hashBinary(u(e),t)},p.hashBinary=function(e,t){var r=c(s(e));return t?h(r):r},p.ArrayBuffer=function(){this.reset()},p.ArrayBuffer.prototype.append=function(e){var t,n=d(this._buff.buffer,e),s=n.length;for(this._length+=e.byteLength,t=64;t<=s;t+=64)r(this._hash,o(n.subarray(t-64,t)));return this._buff=t-64<s?new Uint8Array(n.buffer.slice(t-64)):new Uint8Array(0),this},p.ArrayBuffer.prototype.end=function(e){var t,r,n=this._buff,o=n.length,s=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(t=0;t<o;t+=1)s[t>>2]|=n[t]<<(t%4<<3);return this._finish(s,o),r=c(this._hash),e&&(r=h(r)),this.reset(),r},p.ArrayBuffer.prototype.reset=function(){return this._buff=new Uint8Array(0),this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},p.ArrayBuffer.prototype.getState=function(){var e=p.prototype.getState.call(this);return e.buff=f(e.buff),e},p.ArrayBuffer.prototype.setState=function(e){return e.buff=l(e.buff,!0),p.prototype.setState.call(this,e)},p.ArrayBuffer.prototype.destroy=p.prototype.destroy,p.ArrayBuffer.prototype._finish=p.prototype._finish,p.ArrayBuffer.hash=function(e,t){var r=c(i(new Uint8Array(e)));return t?h(r):r},p}()),Gr.exports),Qr=c(Wr),Yr=new Uint8Array(16);function Xr(){if(!Hr&&!(Hr="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Hr(Yr)}var Zr=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;for(var en=[],tn=0;tn<256;++tn)en.push((tn+256).toString(16).substr(1));function rn(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=(en[e[t+0]]+en[e[t+1]]+en[e[t+2]]+en[e[t+3]]+"-"+en[e[t+4]]+en[e[t+5]]+"-"+en[e[t+6]]+en[e[t+7]]+"-"+en[e[t+8]]+en[e[t+9]]+"-"+en[e[t+10]]+en[e[t+11]]+en[e[t+12]]+en[e[t+13]]+en[e[t+14]]+en[e[t+15]]).toLowerCase();if(!function(e){return"string"==typeof e&&Zr.test(e)}(r))throw TypeError("Stringified UUID is invalid");return r}function nn(e,t,r){var n=(e=e||{}).random||(e.rng||Xr)();if(n[6]=15&n[6]|64,n[8]=63&n[8]|128,t){r=r||0;for(var o=0;o<16;++o)t[r+o]=n[o];return t}return rn(n)}var on,sn={};var an=function(){if(on)return sn;function e(e,t,r){var n=r[r.length-1];e===n.element&&(r.pop(),n=r[r.length-1]);var o=n.element,s=n.index;if(Array.isArray(o))o.push(e);else if(s===t.length-2){o[t.pop()]=e}else t.push(e)}return on=1,sn.stringify=function(e){var t=[];t.push({obj:e});for(var r,n,o,s,i,a,c,u,l,f,d="";r=t.pop();)if(n=r.obj,d+=r.prefix||"",o=r.val||"")d+=o;else if("object"!=typeof n)d+=void 0===n?null:JSON.stringify(n);else if(null===n)d+="null";else if(Array.isArray(n)){for(t.push({val:"]"}),s=n.length-1;s>=0;s--)i=0===s?"":",",t.push({obj:n[s],prefix:i});t.push({val:"["})}else{for(c in a=[],n)n.hasOwnProperty(c)&&a.push(c);for(t.push({val:"}"}),s=a.length-1;s>=0;s--)l=n[u=a[s]],f=s>0?",":"",f+=JSON.stringify(u)+":",t.push({obj:l,prefix:f});t.push({val:"{"})}return d},sn.parse=function(t){for(var r,n,o,s,i,a,c,u,l,f=[],d=[],h=0;;)if("}"!==(r=t[h++])&&"]"!==r&&void 0!==r)switch(r){case" ":case"\t":case"\n":case":":case",":break;case"n":h+=3,e(null,f,d);break;case"t":h+=3,e(!0,f,d);break;case"f":h+=4,e(!1,f,d);break;case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":case"-":for(n="",h--;;){if(o=t[h++],!/[\d\.\-e\+]/.test(o)){h--;break}n+=o}e(parseFloat(n),f,d);break;case'"':for(s="",i=void 0,a=0;'"'!==(c=t[h++])||"\\"===i&&a%2==1;)s+=c,"\\"===(i=c)?a++:a=0;e(JSON.parse('"'+s+'"'),f,d);break;case"[":u={element:[],index:f.length},f.push(u.element),d.push(u);break;case"{":l={element:{},index:f.length},f.push(l.element),d.push(l);break;default:throw new Error("unexpectedly reached end of input: "+r)}else{if(1===f.length)return f.pop();e(f.pop(),f,d)}},sn}(),cn=c(an);function un(){}function ln(){ln.init.call(this)}function fn(e){return void 0===e._maxListeners?ln.defaultMaxListeners:e._maxListeners}function dn(e,t,r,n){var o,s,i;if("function"!=typeof r)throw new TypeError('"listener" argument must be a function');if((s=e._events)?(s.newListener&&(e.emit("newListener",t,r.listener?r.listener:r),s=e._events),i=s[t]):(s=e._events=new un,e._eventsCount=0),i){if("function"==typeof i?i=s[t]=n?[r,i]:[i,r]:n?i.unshift(r):i.push(r),!i.warned&&(o=fn(e))&&o>0&&i.length>o){i.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+i.length+" "+t+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=i.length,function(e){"function"==typeof console.warn?console.warn(e):console.log(e)}(a)}}else i=s[t]=r,++e._eventsCount;return e}function hn(e,t,r){var n=!1;function o(){e.removeListener(t,o),n||(n=!0,r.apply(e,arguments))}return o.listener=r,o}function pn(e){var t=this._events;if(t){var r=t[e];if("function"==typeof r)return 1;if(r)return r.length}return 0}function mn(e,t){for(var r=new Array(t);t--;)r[t]=e[t];return r}un.prototype=Object.create(null),ln.EventEmitter=ln,ln.usingDomains=!1,ln.prototype.domain=void 0,ln.prototype._events=void 0,ln.prototype._maxListeners=void 0,ln.defaultMaxListeners=10,ln.init=function(){this.domain=null,ln.usingDomains&&undefined.active,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new un,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},ln.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||isNaN(e))throw new TypeError('"n" argument must be a positive number');return this._maxListeners=e,this},ln.prototype.getMaxListeners=function(){return fn(this)},ln.prototype.emit=function(e){var t,r,n,o,s,i,a,c="error"===e;if(i=this._events)c=c&&null==i.error;else if(!c)return!1;if(a=this.domain,c){if(t=arguments[1],!a){if(t instanceof Error)throw t;var u=new Error('Uncaught, unspecified "error" event. ('+t+")");throw u.context=t,u}return t||(t=new Error('Uncaught, unspecified "error" event')),t.domainEmitter=this,t.domain=a,t.domainThrown=!1,a.emit("error",t),!1}if(!(r=i[e]))return!1;var l="function"==typeof r;switch(n=arguments.length){case 1:!function(e,t,r){if(t)e.call(r);else for(var n=e.length,o=mn(e,n),s=0;s<n;++s)o[s].call(r)}(r,l,this);break;case 2:!function(e,t,r,n){if(t)e.call(r,n);else for(var o=e.length,s=mn(e,o),i=0;i<o;++i)s[i].call(r,n)}(r,l,this,arguments[1]);break;case 3:!function(e,t,r,n,o){if(t)e.call(r,n,o);else for(var s=e.length,i=mn(e,s),a=0;a<s;++a)i[a].call(r,n,o)}(r,l,this,arguments[1],arguments[2]);break;case 4:!function(e,t,r,n,o,s){if(t)e.call(r,n,o,s);else for(var i=e.length,a=mn(e,i),c=0;c<i;++c)a[c].call(r,n,o,s)}(r,l,this,arguments[1],arguments[2],arguments[3]);break;default:for(o=new Array(n-1),s=1;s<n;s++)o[s-1]=arguments[s];!function(e,t,r,n){if(t)e.apply(r,n);else for(var o=e.length,s=mn(e,o),i=0;i<o;++i)s[i].apply(r,n)}(r,l,this,o)}return!0},ln.prototype.addListener=function(e,t){return dn(this,e,t,!1)},ln.prototype.on=ln.prototype.addListener,ln.prototype.prependListener=function(e,t){return dn(this,e,t,!0)},ln.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,hn(this,e,t)),this},ln.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,hn(this,e,t)),this},ln.prototype.removeListener=function(e,t){var r,n,o,s,i;if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');if(!(n=this._events))return this;if(!(r=n[e]))return this;if(r===t||r.listener&&r.listener===t)0==--this._eventsCount?this._events=new un:(delete n[e],n.removeListener&&this.emit("removeListener",e,r.listener||t));else if("function"!=typeof r){for(o=-1,s=r.length;s-- >0;)if(r[s]===t||r[s].listener&&r[s].listener===t){i=r[s].listener,o=s;break}if(o<0)return this;if(1===r.length){if(r[0]=void 0,0==--this._eventsCount)return this._events=new un,this;delete n[e]}else!function(e,t){for(var r=t,n=r+1,o=e.length;n<o;r+=1,n+=1)e[r]=e[n];e.pop()}(r,o);n.removeListener&&this.emit("removeListener",e,i||t)}return this},ln.prototype.removeAllListeners=function(e){var t,r;if(!(r=this._events))return this;if(!r.removeListener)return 0===arguments.length?(this._events=new un,this._eventsCount=0):r[e]&&(0==--this._eventsCount?this._events=new un:delete r[e]),this;if(0===arguments.length){for(var n,o=Object.keys(r),s=0;s<o.length;++s)"removeListener"!==(n=o[s])&&this.removeAllListeners(n);return this.removeAllListeners("removeListener"),this._events=new un,this._eventsCount=0,this}if("function"==typeof(t=r[e]))this.removeListener(e,t);else if(t)do{this.removeListener(e,t[t.length-1])}while(t[0]);return this},ln.prototype.listeners=function(e){var t,r,n=this._events;return r=n&&(t=n[e])?"function"==typeof t?[t.listener||t]:function(e){for(var t=new Array(e.length),r=0;r<t.length;++r)t[r]=e[r].listener||e[r];return t}(t):[],r},ln.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):pn.call(e,t)},ln.prototype.listenerCount=pn,ln.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};var vn=Function.prototype.toString,yn=vn.call(Object);function gn(e){var t,r,n;if(!e||"object"!=typeof e)return e;if(Array.isArray(e)){for(t=[],r=0,n=e.length;r<n;r++)t[r]=gn(e[r]);return t}if(e instanceof Date&&isFinite(e))return e.toISOString();if(function(e){return"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer||"undefined"!=typeof Blob&&e instanceof Blob}(e))return function(e){return e instanceof ArrayBuffer?e.slice(0):e.slice(0,e.size,e.type)}(e);if(!function(e){var t=Object.getPrototypeOf(e);if(null===t)return!0;var r=t.constructor;return"function"==typeof r&&r instanceof r&&vn.call(r)==yn}(e))return e;for(r in t={},e)if(Object.prototype.hasOwnProperty.call(e,r)){var o=gn(e[r]);void 0!==o&&(t[r]=o)}return t}function _n(e){var t=!1;return function(...r){if(t)throw new Error("once called more than once");t=!0,e.apply(this,r)}}function wn(e){return function(...t){t=gn(t);var r=this,n="function"==typeof t[t.length-1]&&t.pop(),o=new Promise((function(n,o){var s;try{var i=_n((function(e,t){e?o(e):n(t)}));t.push(i),(s=e.apply(r,t))&&"function"==typeof s.then&&n(s)}catch(e){o(e)}}));return n&&o.then((function(e){n(null,e)}),n),o}}function bn(e,t){return wn((function(...r){if(this._closed)return Promise.reject(new Error("database is closed"));if(this._destroyed)return Promise.reject(new Error("database is destroyed"));var n=this;return function(e,t,r){if(e.constructor.listeners("debug").length){for(var n=["api",e.name,t],o=0;o<r.length-1;o++)n.push(r[o]);e.constructor.emit("debug",n);var s=r[r.length-1];r[r.length-1]=function(r,n){var o=["api",e.name,t];o=o.concat(r?["error",r]:["success",n]),e.constructor.emit("debug",o),s(r,n)}}}(n,e,r),this.taskqueue.isReady?t.apply(this,r):new Promise((function(t,o){n.taskqueue.addTask((function(s){s?o(s):t(n[e].apply(n,r))}))}))}))}function $n(e,t){for(var r={},n=0,o=t.length;n<o;n++){var s=t[n];s in e&&(r[s]=e[s])}return r}var kn;function En(e){return e}function Pn(e){return[{ok:e}]}function Sn(e,t,r){var n=t.docs,o=new Map;n.forEach((function(e){o.has(e.id)?o.get(e.id).push(e):o.set(e.id,[e])}));var s=o.size,i=0,a=new Array(s);function c(){var e;++i===s&&(e=[],a.forEach((function(t){t.docs.forEach((function(r){e.push({id:t.id,docs:[r]})}))})),r(null,{results:e}))}var u=[];o.forEach((function(e,t){u.push(t)}));var l=0;function f(){if(!(l>=u.length)){var r=Math.min(l+6,u.length),n=u.slice(l,r);!function(r,n){r.forEach((function(r,s){var i=n+s,u=o.get(r),l=$n(u[0],["atts_since","attachments"]);l.open_revs=u.map((function(e){return e.rev})),l.open_revs=l.open_revs.filter(En);var d=En;0===l.open_revs.length&&(delete l.open_revs,d=Pn),["revs","attachments","binary","ajax","latest"].forEach((function(e){e in t&&(l[e]=t[e])})),e.get(r,l,(function(e,t){var n;n=e?[{error:e}]:d(t),function(e,t,r){a[e]={id:t,docs:r},c()}(i,r,n),f()}))}))}(n,l),l+=n.length}}f()}try{localStorage.setItem("_pouch_check_localstorage",1),kn=!!localStorage.getItem("_pouch_check_localstorage")}catch(r){kn=!1}function jn(){return kn}const On="function"==typeof queueMicrotask?queueMicrotask:function(e){Promise.resolve().then(e)};function xn(e){if("undefined"!=typeof console&&"function"==typeof console[e]){var t=Array.prototype.slice.call(arguments,1);console[e].apply(console,t)}}function An(e){var t=0;return e||(t=2e3),function(e,t){var r=6e5;return e=parseInt(e,10)||0,(t=parseInt(t,10))!=t||t<=e?t=(e||1)<<1:t+=1,t>r&&(e=3e5,t=r),~~((t-e)*Math.random()+e)}(e,t)}function Cn(e,t){xn("info","The above "+e+" is totally normal. "+t)}class In extends Error{constructor(e,t,r){super(),this.status=e,this.name=t,this.message=r,this.error=!0}toString(){return JSON.stringify({status:this.status,name:this.name,message:this.message,reason:this.reason})}}new In(401,"unauthorized","Name or password is incorrect.");var Nn=new In(400,"bad_request","Missing JSON list of 'docs'"),Tn=new In(404,"not_found","missing"),Rn=new In(409,"conflict","Document update conflict"),qn=new In(400,"bad_request","_id field must contain a string"),Dn=new In(412,"missing_id","_id is required for puts"),Ln=new In(400,"bad_request","Only reserved document ids may start with underscore.");new In(412,"precondition_failed","Database not open");var Mn=new In(500,"unknown_error","Database encountered an unknown error"),Vn=new In(500,"badarg","Some query argument is invalid");new In(400,"invalid_request","Request was invalid");var Un=new In(400,"query_parse_error","Some query parameter is invalid"),Bn=new In(500,"doc_validation","Bad special document member"),zn=new In(400,"bad_request","Something wrong with the request"),Kn=new In(400,"bad_request","Document must be a JSON object");new In(404,"not_found","Database not found");var Fn=new In(500,"indexed_db_went_bad","unknown");new In(500,"web_sql_went_bad","unknown"),new In(500,"levelDB_went_went_bad","unknown"),new In(403,"forbidden","Forbidden by design doc validate_doc_update function");var Jn=new In(400,"bad_request","Invalid rev format");new In(412,"file_exists","The database could not be created, the file already exists.");var Gn=new In(412,"missing_stub","A pre-existing attachment stub wasn't found");function Hn(e,t){function r(t){for(var r=Object.getOwnPropertyNames(e),n=0,o=r.length;n<o;n++)"function"!=typeof e[r[n]]&&(this[r[n]]=e[r[n]]);void 0===this.stack&&(this.stack=(new Error).stack),void 0!==t&&(this.reason=t)}return r.prototype=In.prototype,new r(t)}function Wn(e){if("object"!=typeof e){var t=e;(e=Mn).data=t}return"error"in e&&"conflict"===e.error&&(e.name="conflict",e.status=409),"name"in e||(e.name=e.error||"unknown"),"status"in e||(e.status=500),"message"in e||(e.message=e.message||e.reason),"stack"in e||(e.stack=(new Error).stack),e}function Qn(e){var t={},r=e.filter&&"function"==typeof e.filter;return t.query=e.query_params,function(n){n.doc||(n.doc={});var o=r&&function(e,t,r){try{return!e(t,r)}catch(e){var n="Filter function threw: "+e.toString();return Hn(zn,n)}}(e.filter,n.doc,t);if("object"==typeof o)return o;if(o)return!1;if(e.include_docs){if(!e.attachments)for(var s in n.doc._attachments)Object.prototype.hasOwnProperty.call(n.doc._attachments,s)&&(n.doc._attachments[s].stub=!0)}else delete n.doc;return!0}}function Yn(e){var t;if(e?"string"!=typeof e?t=Hn(qn):/^_/.test(e)&&!/^_(design|local)/.test(e)&&(t=Hn(Ln)):t=Hn(Dn),t)throw t}function Xn(e){return"boolean"==typeof e._remote?e._remote:"function"==typeof e.type&&(xn("warn","db.type() is deprecated and will be removed in a future version of PouchDB"),"http"===e.type())}function Zn(e){if(!e)return null;var t=e.split("/");return 2===t.length?t:1===t.length?[e,e]:null}function eo(e){var t=Zn(e);return t?t.join("/"):null}new In(413,"invalid_url","Provided URL is invalid");var to=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],ro="queryKey",no=/(?:^|&)([^&=]*)=?([^&]*)/g,oo=/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/;function so(e){for(var t=oo.exec(e),r={},n=14;n--;){var o=to[n],s=t[n]||"",i=-1!==["user","password"].indexOf(o);r[o]=i?decodeURIComponent(s):s}return r[ro]={},r[to[12]].replace(no,(function(e,t,n){t&&(r[ro][t]=n)})),r}function io(e,t){var r=[],n=[];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(r.push(o),n.push(t[o]));return r.push(e),Function.apply(null,r).apply(null,n)}function ao(e,t,r){return e.get(t).catch((function(e){if(404!==e.status)throw e;return{}})).then((function(n){var o=n._rev,s=r(n);return s?(s._id=t,s._rev=o,function(e,t,r){return e.put(t).then((function(e){return{updated:!0,rev:e.rev}}),(function(n){if(409!==n.status)throw n;return ao(e,t._id,r)}))}(e,s,r)):{updated:!1,rev:o}}))}var co=function(e){return atob(e)},uo=function(e){return btoa(e)};function lo(e,t){e=e||[],t=t||{};try{return new Blob(e,t)}catch(o){if("TypeError"!==o.name)throw o;for(var r=new("undefined"!=typeof BlobBuilder?BlobBuilder:"undefined"!=typeof MSBlobBuilder?MSBlobBuilder:"undefined"!=typeof MozBlobBuilder?MozBlobBuilder:WebKitBlobBuilder),n=0;n<e.length;n+=1)r.append(e[n]);return r.getBlob(t.type)}}function fo(e){for(var t=e.length,r=new ArrayBuffer(t),n=new Uint8Array(r),o=0;o<t;o++)n[o]=e.charCodeAt(o);return r}function ho(e,t){return lo([fo(e)],{type:t})}function po(e,t){return ho(co(e),t)}function mo(e,t){var r=new FileReader,n="function"==typeof r.readAsBinaryString;r.onloadend=function(e){var r=e.target.result||"";if(n)return t(r);t(function(e){for(var t="",r=new Uint8Array(e),n=r.byteLength,o=0;o<n;o++)t+=String.fromCharCode(r[o]);return t}(r))},n?r.readAsBinaryString(e):r.readAsArrayBuffer(e)}function vo(e,t){mo(e,(function(e){t(e)}))}function yo(e,t){vo(e,(function(e){t(uo(e))}))}var go=self.setImmediate||self.setTimeout;function _o(e,t,r,n,o){(r>0||n<t.size)&&(t=t.slice(r,n)),function(e,t){var r=new FileReader;r.onloadend=function(e){var r=e.target.result||new ArrayBuffer(0);t(r)},r.readAsArrayBuffer(e)}(t,(function(t){e.append(t),o()}))}function wo(e,t,r,n,o){(r>0||n<t.length)&&(t=t.substring(r,n)),e.appendBinary(t),o()}function bo(e,t){var r="string"==typeof e,n=r?e.length:e.size,o=Math.min(32768,n),s=Math.ceil(n/o),i=0,a=r?new Qr:new Qr.ArrayBuffer,c=r?wo:_o;function u(){go(f)}function l(){var e=function(e){return uo(e)}(a.end(!0));t(e),a.destroy()}function f(){var t=i*o,r=t+o;i++,c(a,e,t,r,i<s?u:l)}f()}function $o(e){return Qr.hash(e)}function ko(e,t){if(!t)return nn().replace(/-/g,"").toLowerCase();var r=Object.assign({},e);return delete r._rev_tree,$o(JSON.stringify(r))}var Eo=nn;function Po(e){for(var t,r,n,o,s=e.rev_tree.slice();o=s.pop();){var i=o.ids,a=i[2],c=o.pos;if(a.length)for(var u=0,l=a.length;u<l;u++)s.push({pos:c+1,ids:a[u]});else{var f=!!i[1].deleted,d=i[0];t&&!(n!==f?n:r!==c?r<c:t<d)||(t=d,r=c,n=f)}}return r+"-"+t}function So(e,t){for(var r,n=e.slice();r=n.pop();)for(var o=r.pos,s=r.ids,i=s[2],a=t(0===i.length,o,s[0],r.ctx,s[1]),c=0,u=i.length;c<u;c++)n.push({pos:o+1,ids:i[c],ctx:a})}function jo(e,t){return e.pos-t.pos}function Oo(e){var t=[];So(e,(function(e,r,n,o,s){e&&t.push({rev:r+"-"+n,pos:r,opts:s})})),t.sort(jo).reverse();for(var r=0,n=t.length;r<n;r++)delete t[r].pos;return t}function xo(e){for(var t=Po(e),r=Oo(e.rev_tree),n=[],o=0,s=r.length;o<s;o++){var i=r[o];i.rev===t||i.opts.deleted||n.push(i.rev)}return n}function Ao(e){for(var t,r=[],n=e.slice();t=n.pop();){var o=t.pos,s=t.ids,i=s[0],a=s[1],c=s[2],u=0===c.length,l=t.history?t.history.slice():[];l.push({id:i,opts:a}),u&&r.push({pos:o+1-l.length,ids:l});for(var f=0,d=c.length;f<d;f++)n.push({pos:o+1,ids:c[f],history:l})}return r.reverse()}function Co(e,t){return e.pos-t.pos}function Io(e,t,r){var n=function(e,t,r){for(var n,o=0,s=e.length;o<s;)r(e[n=o+s>>>1],t)<0?o=n+1:s=n;return o}(e,t,r);e.splice(n,0,t)}function No(e,t){for(var r,n,o=t,s=e.length;o<s;o++){var i=e[o],a=[i.id,i.opts,[]];n?(n[2].push(a),n=a):r=n=a}return r}function To(e,t){return e[0]<t[0]?-1:1}function Ro(e,t){for(var r=[{tree1:e,tree2:t}],n=!1;r.length>0;){var o=r.pop(),s=o.tree1,i=o.tree2;(s[1].status||i[1].status)&&(s[1].status="available"===s[1].status||"available"===i[1].status?"available":"missing");for(var a=0;a<i[2].length;a++)if(s[2][0]){for(var c=!1,u=0;u<s[2].length;u++)s[2][u][0]===i[2][a][0]&&(r.push({tree1:s[2][u],tree2:i[2][a]}),c=!0);c||(n="new_branch",Io(s[2],i[2][a],To))}else n="new_leaf",s[2][0]=i[2][a]}return{conflicts:n,tree:e}}function qo(e,t,r){var n,o=[],s=!1,i=!1;if(!e.length)return{tree:[t],conflicts:"new_leaf"};for(var a=0,c=e.length;a<c;a++){var u=e[a];if(u.pos===t.pos&&u.ids[0]===t.ids[0])n=Ro(u.ids,t.ids),o.push({pos:u.pos,ids:n.tree}),s=s||n.conflicts,i=!0;else if(!0!==r){var l=u.pos<t.pos?u:t,f=u.pos<t.pos?t:u,d=f.pos-l.pos,h=[],p=[];for(p.push({ids:l.ids,diff:d,parent:null,parentIdx:null});p.length>0;){var m=p.pop();if(0!==m.diff)for(var v=m.ids[2],y=0,g=v.length;y<g;y++)p.push({ids:v[y],diff:m.diff-1,parent:m.ids,parentIdx:y});else m.ids[0]===f.ids[0]&&h.push(m)}var _=h[0];_?(n=Ro(_.ids,f.ids),_.parent[2][_.parentIdx]=n.tree,o.push({pos:l.pos,ids:l.ids}),s=s||n.conflicts,i=!0):o.push(u)}else o.push(u)}return i||o.push(t),o.sort(Co),{tree:o,conflicts:s||"internal_node"}}function Do(e,t,r){var n=qo(e,t),o=function(e,t){for(var r,n,o=Ao(e),s=0,i=o.length;s<i;s++){var a,c=o[s],u=c.ids;if(u.length>t){r||(r={});var l=u.length-t;a={pos:c.pos+l,ids:No(u,l)};for(var f=0;f<l;f++){var d=c.pos+f+"-"+u[f].id;r[d]=!0}}else a={pos:c.pos,ids:No(u,0)};n=n?qo(n,a,!0).tree:[a]}return r&&So(n,(function(e,t,n){delete r[t+"-"+n]})),{tree:n,revs:r?Object.keys(r):[]}}(n.tree,r);return{tree:o.tree,stemmedRevs:o.revs,conflicts:n.conflicts}}function Lo(e){return e.ids}function Mo(e,t){t||(t=Po(e));for(var r,n=t.substring(t.indexOf("-")+1),o=e.rev_tree.map(Lo);r=o.pop();){if(r[0]===n)return!!r[1].deleted;o=o.concat(r[2])}}function Vo(e){return"string"==typeof e&&e.startsWith("_local/")}function Uo(e,t,r){var n=[{rev:e._rev}];"all_docs"===r.style&&(n=Oo(t.rev_tree).map((function(e){return{rev:e.rev}})));var o={id:t.id,changes:n,doc:e};return Mo(t,e._rev)&&(o.deleted=!0),r.conflicts&&(o.doc._conflicts=xo(t),o.doc._conflicts.length||delete o.doc._conflicts),o}class Bo extends ln{constructor(e,t,r){super(),this.db=e;var n=(t=t?gn(t):{}).complete=_n(((t,r)=>{t?function(e,t){return"listenerCount"in e?e.listenerCount(t):ln.listenerCount(e,t)}(this,"error")>0&&this.emit("error",t):this.emit("complete",r),this.removeAllListeners(),e.removeListener("destroyed",o)}));r&&(this.on("complete",(function(e){r(null,e)})),this.on("error",r));const o=()=>{this.cancel()};e.once("destroyed",o),t.onChange=(e,t,r)=>{this.isCancelled||function(e,t,r,n){try{e.emit("change",t,r,n)}catch(e){xn("error",'Error in .on("change", function):',e)}}(this,e,t,r)};var s=new Promise((function(e,r){t.complete=function(t,n){t?r(t):e(n)}}));this.once("cancel",(function(){e.removeListener("destroyed",o),t.complete(null,{status:"cancelled"})})),this.then=s.then.bind(s),this.catch=s.catch.bind(s),this.then((function(e){n(null,e)}),n),e.taskqueue.isReady?this.validateChanges(t):e.taskqueue.addTask((e=>{e?t.complete(e):this.isCancelled?this.emit("cancel"):this.validateChanges(t)}))}cancel(){this.isCancelled=!0,this.db.taskqueue.isReady&&this.emit("cancel")}validateChanges(e){var t=e.complete;es._changesFilterPlugin?es._changesFilterPlugin.validate(e,(r=>{if(r)return t(r);this.doChanges(e)})):this.doChanges(e)}doChanges(e){var t=e.complete;if("live"in(e=gn(e))&&!("continuous"in e)&&(e.continuous=e.live),e.processChange=Uo,"latest"===e.since&&(e.since="now"),e.since||(e.since=0),"now"!==e.since){if(es._changesFilterPlugin){if(es._changesFilterPlugin.normalize(e),es._changesFilterPlugin.shouldFilter(this,e))return es._changesFilterPlugin.filter(this,e)}else["doc_ids","filter","selector","view"].forEach((function(t){t in e&&xn("warn",'The "'+t+'" option was passed in to changes/replicate, but pouchdb-changes-filter plugin is not installed, so it was ignored. Please install the plugin to enable filtering.')}));"descending"in e||(e.descending=!1),e.limit=0===e.limit?1:e.limit,e.complete=t;var r=this.db._changes(e);if(r&&"function"==typeof r.cancel){const e=this.cancel;this.cancel=(...t)=>{r.cancel(),e.apply(this,t)}}}else this.db.info().then((r=>{this.isCancelled?t(null,{status:"cancelled"}):(e.since=r.update_seq,this.doChanges(e))}),t)}}function zo(e,t){return function(r,n){r||n[0]&&n[0].error?((r=r||n[0]).docId=t,e(r)):e(null,n.length?n[0]:n)}}function Ko(e,t){if(e._id===t._id){return(e._revisions?e._revisions.start:0)-(t._revisions?t._revisions.start:0)}return e._id<t._id?-1:1}function Fo(e){var t=e._compactionQueue[0],r=t.opts,n=t.callback;e.get("_local/compaction").catch((function(){return!1})).then((function(t){t&&t.last_seq&&(r.last_seq=t.last_seq),e._compact(r,(function(t,r){t?n(t):n(null,r),On((function(){e._compactionQueue.shift(),e._compactionQueue.length&&Fo(e)}))}))}))}function Jo(e,t,r){return e.get("_local/purges").then((function(e){const n=e.purgeSeq+1;return e.purges.push({docId:t,rev:r,purgeSeq:n}),e.purges.length>self.purged_infos_limit&&e.purges.splice(0,e.purges.length-self.purged_infos_limit),e.purgeSeq=n,e})).catch((function(e){if(404!==e.status)throw e;return{_id:"_local/purges",purges:[{docId:t,rev:r,purgeSeq:0}],purgeSeq:0}})).then((function(t){return e.put(t)}))}function Go(e){return null===e||"object"!=typeof e||Array.isArray(e)}const Ho=/^\d+-[^-]*$/;function Wo(e){return"string"==typeof e&&Ho.test(e)}class Qo extends ln{_setup(){this.post=bn("post",(function(e,t,r){if("function"==typeof t&&(r=t,t={}),Go(e))return r(Hn(Kn));this.bulkDocs({docs:[e]},t,zo(r,e._id))})).bind(this),this.put=bn("put",(function(e,t,r){if("function"==typeof t&&(r=t,t={}),Go(e))return r(Hn(Kn));if(Yn(e._id),"_rev"in e&&!Wo(e._rev))return r(Hn(Jn));if(Vo(e._id)&&"function"==typeof this._putLocal)return e._deleted?this._removeLocal(e,r):this._putLocal(e,r);const n=r=>{"function"==typeof this._put&&!1!==t.new_edits?this._put(e,t,r):this.bulkDocs({docs:[e]},t,zo(r,e._id))};var o,s,i,a;t.force&&e._rev?(o=e._rev.split("-"),s=o[1],i=parseInt(o[0],10)+1,a=ko(),e._revisions={start:i,ids:[a,s]},e._rev=i+"-"+a,t.new_edits=!1,n((function(t){var n=t?null:{ok:!0,id:e._id,rev:e._rev};r(t,n)}))):n(r)})).bind(this),this.putAttachment=bn("putAttachment",(function(e,t,r,n,o){var s=this;function i(e){var r="_rev"in e?parseInt(e._rev,10):0;return e._attachments=e._attachments||{},e._attachments[t]={content_type:o,data:n,revpos:++r},s.put(e)}return"function"==typeof o&&(o=n,n=r,r=null),void 0===o&&(o=n,n=r,r=null),o||xn("warn","Attachment",t,"on document",e,"is missing content_type"),s.get(e).then((function(e){if(e._rev!==r)throw Hn(Rn);return i(e)}),(function(t){if(t.reason===Tn.message)return i({_id:e});throw t}))})).bind(this),this.removeAttachment=bn("removeAttachment",(function(e,t,r,n){this.get(e,((e,o)=>{if(e)n(e);else if(o._rev===r){if(!o._attachments)return n();delete o._attachments[t],0===Object.keys(o._attachments).length&&delete o._attachments,this.put(o,n)}else n(Hn(Rn))}))})).bind(this),this.remove=bn("remove",(function(e,t,r,n){var o;"string"==typeof t?(o={_id:e,_rev:t},"function"==typeof r&&(n=r,r={})):(o=e,"function"==typeof t?(n=t,r={}):(n=r,r=t)),(r=r||{}).was_delete=!0;var s={_id:o._id,_rev:o._rev||r.rev,_deleted:!0};if(Vo(s._id)&&"function"==typeof this._removeLocal)return this._removeLocal(o,n);this.bulkDocs({docs:[s]},r,zo(n,s._id))})).bind(this),this.revsDiff=bn("revsDiff",(function(e,t,r){"function"==typeof t&&(r=t,t={});var n=Object.keys(e);if(!n.length)return r(null,{});var o=0,s=new Map;function i(e,t){s.has(e)||s.set(e,{missing:[]}),s.get(e).missing.push(t)}n.forEach((function(t){this._getRevisionTree(t,(function(a,c){if(a&&404===a.status&&"missing"===a.message)s.set(t,{missing:e[t]});else{if(a)return r(a);!function(t,r){var n=e[t].slice(0);So(r,(function(e,r,o,s,a){var c=r+"-"+o,u=n.indexOf(c);-1!==u&&(n.splice(u,1),"available"!==a.status&&i(t,c))})),n.forEach((function(e){i(t,e)}))}(t,c)}if(++o===n.length){var u={};return s.forEach((function(e,t){u[t]=e})),r(null,u)}}))}),this)})).bind(this),this.bulkGet=bn("bulkGet",(function(e,t){Sn(this,e,t)})).bind(this),this.compactDocument=bn("compactDocument",(function(e,t,r){this._getRevisionTree(e,((n,o)=>{if(n)return r(n);var s=function(e){var t={},r=[];return So(e,(function(e,n,o,s){var i=n+"-"+o;return e&&(t[i]=0),void 0!==s&&r.push({from:s,to:i}),i})),r.reverse(),r.forEach((function(e){void 0===t[e.from]?t[e.from]=1+t[e.to]:t[e.from]=Math.min(t[e.from],1+t[e.to])})),t}(o),i=[],a=[];Object.keys(s).forEach((function(e){s[e]>t&&i.push(e)})),So(o,(function(e,t,r,n,o){var s=t+"-"+r;"available"===o.status&&-1!==i.indexOf(s)&&a.push(s)})),this._doCompaction(e,a,r)}))})).bind(this),this.compact=bn("compact",(function(e,t){"function"==typeof e&&(t=e,e={}),e=e||{},this._compactionQueue=this._compactionQueue||[],this._compactionQueue.push({opts:e,callback:t}),1===this._compactionQueue.length&&Fo(this)})).bind(this),this.get=bn("get",(function(e,t,r){if("function"==typeof t&&(r=t,t={}),t=t||{},"string"!=typeof e)return r(Hn(qn));if(Vo(e)&&"function"==typeof this._getLocal)return this._getLocal(e,r);var n=[];const o=()=>{var o=[],s=n.length;if(!s)return r(null,o);n.forEach((n=>{this.get(e,{rev:n,revs:t.revs,latest:t.latest,attachments:t.attachments,binary:t.binary},(function(e,t){if(e)o.push({missing:n});else{for(var i,a=0,c=o.length;a<c;a++)if(o[a].ok&&o[a].ok._rev===t._rev){i=!0;break}i||o.push({ok:t})}--s||r(null,o)}))}))};if(!t.open_revs)return this._get(e,t,((n,o)=>{if(n)return n.docId=e,r(n);var s=o.doc,i=o.metadata,a=o.ctx;if(t.conflicts){var c=xo(i);c.length&&(s._conflicts=c)}if(Mo(i,s._rev)&&(s._deleted=!0),t.revs||t.revs_info){for(var u=s._rev.split("-"),l=parseInt(u[0],10),f=u[1],d=Ao(i.rev_tree),h=null,p=0;p<d.length;p++){var m=d[p];const e=m.ids.findIndex((e=>e.id===f));(e===l-1||!h&&-1!==e)&&(h=m)}if(!h)return(n=new Error("invalid rev tree")).docId=e,r(n);const o=s._rev.split("-")[1],a=h.ids.findIndex((e=>e.id===o))+1;var v=h.ids.length-a;if(h.ids.splice(a,v),h.ids.reverse(),t.revs&&(s._revisions={start:h.pos+h.ids.length-1,ids:h.ids.map((function(e){return e.id}))}),t.revs_info){var y=h.pos+h.ids.length;s._revs_info=h.ids.map((function(e){return{rev:--y+"-"+e.id,status:e.opts.status}}))}}if(t.attachments&&s._attachments){var g=s._attachments,_=Object.keys(g).length;if(0===_)return r(null,s);Object.keys(g).forEach((e=>{this._getAttachment(s._id,e,g[e],{binary:t.binary,metadata:i,ctx:a},(function(t,n){var o=s._attachments[e];o.data=n,delete o.stub,delete o.length,--_||r(null,s)}))}))}else{if(s._attachments)for(var w in s._attachments)Object.prototype.hasOwnProperty.call(s._attachments,w)&&(s._attachments[w].stub=!0);r(null,s)}}));if("all"===t.open_revs)this._getRevisionTree(e,(function(e,t){if(e)return r(e);n=Oo(t).map((function(e){return e.rev})),o()}));else{if(!Array.isArray(t.open_revs))return r(Hn(Mn,"function_clause"));n=t.open_revs;for(var s=0;s<n.length;s++){if(!Wo(n[s]))return r(Hn(Jn))}o()}})).bind(this),this.getAttachment=bn("getAttachment",(function(e,t,r,n){r instanceof Function&&(n=r,r={}),this._get(e,r,((o,s)=>o?n(o):s.doc._attachments&&s.doc._attachments[t]?(r.ctx=s.ctx,r.binary=!0,r.metadata=s.metadata,void this._getAttachment(e,t,s.doc._attachments[t],r,n)):n(Hn(Tn))))})).bind(this),this.allDocs=bn("allDocs",(function(e,t){if("function"==typeof e&&(t=e,e={}),e.skip=void 0!==e.skip?e.skip:0,e.start_key&&(e.startkey=e.start_key),e.end_key&&(e.endkey=e.end_key),"keys"in e){if(!Array.isArray(e.keys))return t(new TypeError("options.keys must be an array"));var r=["startkey","endkey","key"].filter((function(t){return t in e}))[0];if(r)return void t(Hn(Un,"Query parameter `"+r+"` is not compatible with multi-get"));if(!Xn(this)&&(function(e){var t="limit"in e?e.keys.slice(e.skip,e.limit+e.skip):e.skip>0?e.keys.slice(e.skip):e.keys;e.keys=t,e.skip=0,delete e.limit,e.descending&&(t.reverse(),e.descending=!1)}(e),0===e.keys.length))return this._allDocs({limit:0},t)}return this._allDocs(e,t)})).bind(this),this.close=bn("close",(function(e){return this._closed=!0,this.emit("closed"),this._close(e)})).bind(this),this.info=bn("info",(function(e){this._info(((t,r)=>{if(t)return e(t);r.db_name=r.db_name||this.name,r.auto_compaction=!(!this.auto_compaction||Xn(this)),r.adapter=this.adapter,e(null,r)}))})).bind(this),this.id=bn("id",(function(e){return this._id(e)})).bind(this),this.bulkDocs=bn("bulkDocs",(function(e,t,r){if("function"==typeof t&&(r=t,t={}),t=t||{},Array.isArray(e)&&(e={docs:e}),!e||!e.docs||!Array.isArray(e.docs))return r(Hn(Nn));for(var n=0;n<e.docs.length;++n){const t=e.docs[n];if(Go(t))return r(Hn(Kn));if("_rev"in t&&!Wo(t._rev))return r(Hn(Jn))}var o;if(e.docs.forEach((function(e){e._attachments&&Object.keys(e._attachments).forEach((function(t){o=o||function(e){return"_"===e.charAt(0)&&e+" is not a valid attachment name, attachment names cannot start with '_'"}(t),e._attachments[t].content_type||xn("warn","Attachment",t,"on document",e._id,"is missing content_type")}))})),o)return r(Hn(zn,o));"new_edits"in t||(t.new_edits=!("new_edits"in e)||e.new_edits);var s=this;t.new_edits||Xn(s)||e.docs.sort(Ko),function(e){for(var t=0;t<e.length;t++){var r=e[t];if(r._deleted)delete r._attachments;else if(r._attachments)for(var n=Object.keys(r._attachments),o=0;o<n.length;o++){var s=n[o];r._attachments[s]=$n(r._attachments[s],["data","digest","content_type","length","revpos","stub"])}}}(e.docs);var i=e.docs.map((function(e){return e._id}));this._bulkDocs(e,t,(function(e,n){if(e)return r(e);if(t.new_edits||(n=n.filter((function(e){return e.error}))),!Xn(s))for(var o=0,a=n.length;o<a;o++)n[o].id=n[o].id||i[o];r(null,n)}))})).bind(this),this.registerDependentDatabase=bn("registerDependentDatabase",(function(e,t){var r=gn(this.__opts);this.__opts.view_adapter&&(r.adapter=this.__opts.view_adapter);var n=new this.constructor(e,r);ao(this,"_local/_pouch_dependentDbs",(function(t){return t.dependentDbs=t.dependentDbs||{},!t.dependentDbs[e]&&(t.dependentDbs[e]=!0,t)})).then((function(){t(null,{db:n})})).catch(t)})).bind(this),this.destroy=bn("destroy",(function(e,t){"function"==typeof e&&(t=e,e={});var r=!("use_prefix"in this)||this.use_prefix;const n=()=>{this._destroy(e,((e,r)=>{if(e)return t(e);this._destroyed=!0,this.emit("destroyed"),t(null,r||{ok:!0})}))};if(Xn(this))return n();this.get("_local/_pouch_dependentDbs",((e,o)=>{if(e)return 404!==e.status?t(e):n();var s=o.dependentDbs,i=this.constructor,a=Object.keys(s).map((e=>{var t=r?e.replace(new RegExp("^"+i.prefix),""):e;return new i(t,this.__opts).destroy()}));Promise.all(a).then(n,t)}))})).bind(this)}_compact(e,t){var r,n={return_docs:!1,last_seq:e.last_seq||0,since:e.last_seq||0},o=[],s=0;const i=e=>{this.activeTasks.update(r,{completed_items:++s}),o.push(this.compactDocument(e.id,0))},a=e=>{this.activeTasks.remove(r,e),t(e)},c=e=>{var n=e.last_seq;Promise.all(o).then((()=>ao(this,"_local/compaction",(e=>(!e.last_seq||e.last_seq<n)&&(e.last_seq=n,e))))).then((()=>{this.activeTasks.remove(r),t(null,{ok:!0})})).catch(a)};this.info().then((e=>{r=this.activeTasks.add({name:"database_compaction",total_items:e.update_seq-n.last_seq}),this.changes(n).on("change",i).on("complete",c).on("error",a)}))}changes(e,t){return"function"==typeof e&&(t=e,e={}),(e=e||{}).return_docs="return_docs"in e?e.return_docs:!e.live,new Bo(this,e,t)}type(){return"function"==typeof this._type?this._type():this.adapter}}Qo.prototype.purge=bn("_purge",(function(e,t,r){if(void 0===this._purge)return r(Hn(Mn,"Purge is not implemented in the "+this.adapter+" adapter."));var n=this;n._getRevisionTree(e,((o,s)=>{if(o)return r(o);if(!s)return r(Hn(Tn));let i;try{i=function(e,t){let r=[];const n=e.slice();let o;for(;o=n.pop();){const{pos:e,ids:s}=o,i=`${e}-${s[0]}`,a=s[2];if(r.push(i),i===t){if(0!==a.length)throw new Error("The requested revision is not a leaf");return r.reverse()}(0===a.length||a.length>1)&&(r=[]);for(let t=0,r=a.length;t<r;t++)n.push({pos:e+1,ids:a[t]})}if(0===r.length)throw new Error("The requested revision does not exist");return r.reverse()}(s,t)}catch(o){return r(o.message||o)}n._purge(e,i,((o,s)=>{if(o)return r(o);Jo(n,e,t).then((function(){return r(null,s)}))}))}))}));class Yo{constructor(){this.isReady=!1,this.failed=!1,this.queue=[]}execute(){var e;if(this.failed)for(;e=this.queue.shift();)e(this.failed);else for(;e=this.queue.shift();)e()}fail(e){this.failed=e,this.execute()}ready(e){this.isReady=!0,this.db=e,this.execute()}addTask(e){this.queue.push(e),this.failed&&this.execute()}}function Xo(e,t){let r=function(...e){if(!(this instanceof r))return new r(...e);t.apply(this,e)};var n,o;return o=e,(n=r).prototype=Object.create(o.prototype,{constructor:{value:n}}),r}class Zo extends Qo{constructor(e,t){super(),this._setup(e,t)}_setup(e,t){if(super._setup(),t=t||{},e&&"object"==typeof e&&(e=(t=e).name,delete t.name),void 0===t.deterministic_revs&&(t.deterministic_revs=!0),this.__opts=t=gn(t),this.auto_compaction=t.auto_compaction,this.purged_infos_limit=t.purged_infos_limit||1e3,this.prefix=es.prefix,"string"!=typeof e)throw new Error("Missing/invalid DB name");var r=function(e,t){var r=e.match(/([a-z-]*):\/\/(.*)/);if(r)return{name:/https?/.test(r[1])?r[1]+"://"+r[2]:r[2],adapter:r[1]};var n=es.adapters,o=es.preferredAdapters,s=es.prefix,i=t.adapter;if(!i)for(var a=0;a<o.length&&"idb"===(i=o[a])&&"websql"in n&&jn()&&localStorage["_pouch__websqldb_"+s+e];++a)xn("log",'PouchDB is downgrading "'+e+'" to WebSQL to avoid data loss, because it was already opened with WebSQL.');var c=n[i];return{name:c&&"use_prefix"in c&&!c.use_prefix?e:s+e,adapter:i}}((t.prefix||"")+e,t);if(t.name=r.name,t.adapter=t.adapter||r.adapter,this.name=e,this._adapter=t.adapter,es.emit("debug",["adapter","Picked adapter: ",t.adapter]),!es.adapters[t.adapter]||!es.adapters[t.adapter].valid())throw new Error("Invalid Adapter: "+t.adapter);if(t.view_adapter&&(!es.adapters[t.view_adapter]||!es.adapters[t.view_adapter].valid()))throw new Error("Invalid View Adapter: "+t.view_adapter);this.taskqueue=new Yo,this.adapter=t.adapter,es.adapters[t.adapter].call(this,t,(e=>{if(e)return this.taskqueue.fail(e);!function(e){function t(t){e.removeListener("closed",r),t||e.constructor.emit("destroyed",e.name)}function r(){e.removeListener("destroyed",t),e.constructor.emit("unref",e)}e.once("destroyed",t),e.once("closed",r),e.constructor.emit("ref",e)}(this),this.emit("created",this),es.emit("created",this.name),this.taskqueue.ready(this)}))}}const es=Xo(Zo,(function(e,t){Zo.prototype._setup.call(this,e,t)}));var ts=fetch,rs=Headers;es.adapters={},es.preferredAdapters=[],es.prefix="_pouch_";var ns=new ln;!function(e){Object.keys(ln.prototype).forEach((function(t){"function"==typeof ln.prototype[t]&&(e[t]=ns[t].bind(ns))}));var t=e._destructionListeners=new Map;e.on("ref",(function(e){t.has(e.name)||t.set(e.name,[]),t.get(e.name).push(e)})),e.on("unref",(function(e){if(t.has(e.name)){var r=t.get(e.name),n=r.indexOf(e);n<0||(r.splice(n,1),r.length>1?t.set(e.name,r):t.delete(e.name))}})),e.on("destroyed",(function(e){if(t.has(e)){var r=t.get(e);t.delete(e),r.forEach((function(e){e.emit("destroyed",!0)}))}}))}(es),es.adapter=function(e,t,r){t.valid()&&(es.adapters[e]=t,r&&es.preferredAdapters.push(e))},es.plugin=function(e){if("function"==typeof e)e(es);else{if("object"!=typeof e||0===Object.keys(e).length)throw new Error('Invalid plugin: got "'+e+'", expected an object or a function');Object.keys(e).forEach((function(t){es.prototype[t]=e[t]}))}return this.__defaults&&(es.__defaults=Object.assign({},this.__defaults)),es},es.defaults=function(e){let t=Xo(es,(function(e,r){r=r||{},e&&"object"==typeof e&&(e=(r=e).name,delete r.name),r=Object.assign({},t.__defaults,r),es.call(this,e,r)}));return t.preferredAdapters=es.preferredAdapters.slice(),Object.keys(es).forEach((function(e){e in t||(t[e]=es[e])})),t.__defaults=Object.assign({},this.__defaults,e),t},es.fetch=function(e,t){return ts(e,t)},es.prototype.activeTasks=es.activeTasks=new class{constructor(){this.tasks={}}list(){return Object.values(this.tasks)}add(e){const t=nn();return this.tasks[t]={id:t,name:e.name,total_items:e.total_items,created_at:(new Date).toJSON()},t}get(e){return this.tasks[e]}remove(e,t){return delete this.tasks[e],this.tasks}update(e,t){const r=this.tasks[e];if(void 0!==r){const n={id:r.id,name:r.name,created_at:r.created_at,total_items:t.total_items||r.total_items,completed_items:t.completed_items||r.completed_items,updated_at:(new Date).toJSON()};this.tasks[e]=n}return this.tasks}};function os(e,t){for(var r=e,n=0,o=t.length;n<o;n++){if(!(r=r[t[n]]))break}return r}function ss(e){for(var t=[],r="",n=0,o=e.length;n<o;n++){var s=e[n];n>0&&"\\"===e[n-1]&&("$"===s||"."===s)?r=r.substring(0,r.length-1)+s:"."===s?(t.push(r),r=""):r+=s}return t.push(r),t}var is=["$or","$nor","$not"];function as(e){return is.indexOf(e)>-1}function cs(e){return Object.keys(e)[0]}function us(e){var t={},r={$or:!0,$nor:!0};return e.forEach((function(e){Object.keys(e).forEach((function(n){var o=e[n];if("object"!=typeof o&&(o={$eq:o}),as(n))if(o instanceof Array){if(r[n])return r[n]=!1,void(t[n]=o);var s=[];t[n].forEach((function(e){Object.keys(o).forEach((function(t){var r=o[t],n=Math.max(Object.keys(e).length,Object.keys(r).length),i=us([e,r]);Object.keys(i).length<=n||s.push(i)}))})),t[n]=s}else t[n]=us([o]);else{var i=t[n]=t[n]||{};Object.keys(o).forEach((function(e){var t=o[e];return"$gt"===e||"$gte"===e?function(e,t,r){if(void 0!==r.$eq)return;void 0!==r.$gte?"$gte"===e?t>r.$gte&&(r.$gte=t):t>=r.$gte&&(delete r.$gte,r.$gt=t):void 0!==r.$gt?"$gte"===e?t>r.$gt&&(delete r.$gt,r.$gte=t):t>r.$gt&&(r.$gt=t):r[e]=t}(e,t,i):"$lt"===e||"$lte"===e?function(e,t,r){if(void 0!==r.$eq)return;void 0!==r.$lte?"$lte"===e?t<r.$lte&&(r.$lte=t):t<=r.$lte&&(delete r.$lte,r.$lt=t):void 0!==r.$lt?"$lte"===e?t<r.$lt&&(delete r.$lt,r.$lte=t):t<r.$lt&&(r.$lt=t):r[e]=t}(e,t,i):"$ne"===e?function(e,t){"$ne"in t?t.$ne.push(e):t.$ne=[e]}(t,i):"$eq"===e?function(e,t){delete t.$gt,delete t.$gte,delete t.$lt,delete t.$lte,delete t.$ne,t.$eq=e}(t,i):"$regex"===e?function(e,t){"$regex"in t?t.$regex.push(e):t.$regex=[e]}(t,i):void(i[e]=t)}))}}))})),t}function ls(e){for(var t in e){if(Array.isArray(e))for(var r in e)e[r].$and&&(e[r]=us(e[r].$and));var n=e[t];"object"==typeof n&&ls(n)}return e}function fs(e,t){for(var r in e){"$and"===r&&(t=!0);var n=e[r];"object"==typeof n&&(t=fs(n,t))}return t}function ds(e){var t=gn(e);fs(t,!1)&&"$and"in(t=ls(t))&&(t=us(t.$and)),["$or","$nor"].forEach((function(e){e in t&&t[e].forEach((function(e){for(var t=Object.keys(e),r=0;r<t.length;r++){var n=t[r],o=e[n];"object"==typeof o&&null!==o||(e[n]={$eq:o})}}))})),"$not"in t&&(t.$not=us([t.$not]));for(var r=Object.keys(t),n=0;n<r.length;n++){var o=r[n],s=t[o];"object"==typeof s&&null!==s||(s={$eq:s}),t[o]=s}return hs(t),t}function hs(e){Object.keys(e).forEach((function(t){var r=e[t];Array.isArray(r)?r.forEach((function(e){e&&"object"==typeof e&&hs(e)})):"$ne"===t?e.$ne=[r]:"$regex"===t?e.$regex=[r]:r&&"object"==typeof r&&hs(r)}))}var ps=-324;function ms(e,t){if(e===t)return 0;e=vs(e),t=vs(t);var r=bs(e),n=bs(t);if(r-n!=0)return r-n;switch(typeof e){case"number":return e-t;case"boolean":return e<t?-1:1;case"string":return function(e,t){return e===t?0:e>t?1:-1}(e,t)}return Array.isArray(e)?function(e,t){for(var r=Math.min(e.length,t.length),n=0;n<r;n++){var o=ms(e[n],t[n]);if(0!==o)return o}return e.length===t.length?0:e.length>t.length?1:-1}(e,t):function(e,t){for(var r=Object.keys(e),n=Object.keys(t),o=Math.min(r.length,n.length),s=0;s<o;s++){var i=ms(r[s],n[s]);if(0!==i)return i;if(0!==(i=ms(e[r[s]],t[n[s]])))return i}return r.length===n.length?0:r.length>n.length?1:-1}(e,t)}function vs(e){switch(typeof e){case"undefined":return null;case"number":return e===1/0||e===-1/0||isNaN(e)?null:e;case"object":var t=e;if(Array.isArray(e)){var r=e.length;e=new Array(r);for(var n=0;n<r;n++)e[n]=vs(t[n])}else{if(e instanceof Date)return e.toJSON();if(null!==e)for(var o in e={},t)if(Object.prototype.hasOwnProperty.call(t,o)){var s=t[o];void 0!==s&&(e[o]=vs(s))}}}return e}function ys(e){if(null!==e)switch(typeof e){case"boolean":return e?1:0;case"number":return function(e){if(0===e)return"1";var t=e.toExponential().split(/e\+?/),r=parseInt(t[1],10),n=e<0,o=n?"0":"2",s=(i=((n?-r:r)-ps).toString(),a="0",c=3,function(e,t,r){for(var n="",o=r-e.length;n.length<o;)n+=t;return n}(i,a,c)+i);var i,a,c;o+=""+s;var u=Math.abs(parseFloat(t[0]));n&&(u=10-u);var l=u.toFixed(20);return l=l.replace(/\.?0+$/,""),o+=""+l,o}(e);case"string":return e.replace(/\u0002/g,"").replace(/\u0001/g,"").replace(/\u0000/g,"");case"object":var t=Array.isArray(e),r=t?e:Object.keys(e),n=-1,o=r.length,s="";if(t)for(;++n<o;)s+=gs(r[n]);else for(;++n<o;){var i=r[n];s+=gs(i)+gs(e[i])}return s}return""}function gs(e){return bs(e=vs(e))+""+ys(e)+"\0"}function _s(e,t){var r,n=t;if("1"===e[t])r=0,t++;else{var o="0"===e[t];t++;var s="",i=e.substring(t,t+3),a=parseInt(i,10)+ps;for(o&&(a=-a),t+=3;;){var c=e[t];if("\0"===c)break;s+=c,t++}r=1===(s=s.split(".")).length?parseInt(s,10):parseFloat(s[0]+"."+s[1]),o&&(r-=10),0!==a&&(r=parseFloat(r+"e"+a))}return{num:r,length:t-n}}function ws(e,t){var r=e.pop();if(t.length){var n=t[t.length-1];r===n.element&&(t.pop(),n=t[t.length-1]);var o=n.element,s=n.index;if(Array.isArray(o))o.push(r);else if(s===e.length-2){o[e.pop()]=r}else e.push(r)}}function bs(e){var t=["boolean","number","string","object"].indexOf(typeof e);return~t?null===e?1:Array.isArray(e)?5:t<3?t+2:t+3:Array.isArray(e)?5:void 0}function $s(e,t,r){if(e=e.filter((function(e){return ks(e.doc,t.selector,r)})),t.sort){var n=function(e){function t(t){return e.map((function(e){var r=ss(cs(e));return os(t,r)}))}return function(e,r){var n,o,s=ms(t(e.doc),t(r.doc));return 0!==s?s:(n=e.doc._id)<(o=r.doc._id)?-1:n>o?1:0}}(t.sort);e=e.sort(n),"string"!=typeof t.sort[0]&&"desc"===(o=t.sort[0])[cs(o)]&&(e=e.reverse())}var o;if("limit"in t||"skip"in t){var s=t.skip||0,i=("limit"in t?t.limit:e.length)+s;e=e.slice(s,i)}return e}function ks(e,t,r){return r.every((function(r){var n=t[r],o=ss(r),s=os(e,o);return as(r)?function(e,t,r){if("$or"===e)return t.some((function(e){return ks(r,e,Object.keys(e))}));if("$not"===e)return!ks(r,t,Object.keys(t));return!t.find((function(e){return ks(r,e,Object.keys(e))}))}(r,n,e):Es(n,e,o,s)}))}function Es(e,t,r,n){return!e||("object"==typeof e?Object.keys(e).every((function(o){var s=e[o];if(0===o.indexOf("$"))return Ps(o,t,s,r,n);var i=ss(o);if(void 0===n&&"object"!=typeof s&&i.length>0)return!1;var a=os(n,i);return"object"==typeof s?Es(s,t,r,a):Ps("$eq",t,s,i,a)})):e===n)}function Ps(e,t,r,n,o){if(!xs[e])throw new Error('unknown operator "'+e+'" - should be one of $eq, $lte, $lt, $gt, $gte, $exists, $ne, $in, $nin, $size, $mod, $regex, $elemMatch, $type, $allMatch or $all');return xs[e](t,r,n,o)}function Ss(e){return null!=e}function js(e){return void 0!==e}function Os(e,t){return t.some((function(t){return e instanceof Array?e.some((function(e){return 0===ms(t,e)})):0===ms(t,e)}))}var xs={$elemMatch:function(e,t,r,n){return!!Array.isArray(n)&&(0!==n.length&&("object"==typeof n[0]&&null!==n[0]?n.some((function(e){return ks(e,t,Object.keys(t))})):n.some((function(n){return Es(t,e,r,n)}))))},$allMatch:function(e,t,r,n){return!!Array.isArray(n)&&(0!==n.length&&("object"==typeof n[0]&&null!==n[0]?n.every((function(e){return ks(e,t,Object.keys(t))})):n.every((function(n){return Es(t,e,r,n)}))))},$eq:function(e,t,r,n){return js(n)&&0===ms(n,t)},$gte:function(e,t,r,n){return js(n)&&ms(n,t)>=0},$gt:function(e,t,r,n){return js(n)&&ms(n,t)>0},$lte:function(e,t,r,n){return js(n)&&ms(n,t)<=0},$lt:function(e,t,r,n){return js(n)&&ms(n,t)<0},$exists:function(e,t,r,n){return t?js(n):!js(n)},$mod:function(e,t,r,n){return Ss(n)&&function(e,t){return"number"==typeof e&&parseInt(e,10)===e&&e%t[0]===t[1]}(n,t)},$ne:function(e,t,r,n){return t.every((function(e){return 0!==ms(n,e)}))},$in:function(e,t,r,n){return Ss(n)&&Os(n,t)},$nin:function(e,t,r,n){return Ss(n)&&!Os(n,t)},$size:function(e,t,r,n){return Ss(n)&&Array.isArray(n)&&function(e,t){return e.length===t}(n,t)},$all:function(e,t,r,n){return Array.isArray(n)&&function(e,t){return t.every((function(t){return e.some((function(e){return 0===ms(t,e)}))}))}(n,t)},$regex:function(e,t,r,n){return Ss(n)&&"string"==typeof n&&t.every((function(e){return function(e,t){return new RegExp(t).test(e)}(n,e)}))},$type:function(e,t,r,n){return function(e,t){switch(t){case"null":return null===e;case"boolean":return"boolean"==typeof e;case"number":return"number"==typeof e;case"string":return"string"==typeof e;case"array":return e instanceof Array;case"object":return"[object Object]"==={}.toString.call(e)}}(n,t)}};function As(e,t){if(e.selector&&e.filter&&"_selector"!==e.filter){var r="string"==typeof e.filter?e.filter:"function";return t(new Error('selector invalid for filter "'+r+'"'))}t()}function Cs(e){e.view&&!e.filter&&(e.filter="_view"),e.selector&&!e.filter&&(e.filter="_selector"),e.filter&&"string"==typeof e.filter&&("_view"===e.filter?e.view=eo(e.view):e.filter=eo(e.filter))}function Is(e,t){return t.filter&&"string"==typeof t.filter&&!t.doc_ids&&!Xn(e.db)}function Ns(e,t){var r=t.complete;if("_view"===t.filter){if(!t.view||"string"!=typeof t.view){var n=Hn(zn,"`view` filter parameter not found or invalid.");return r(n)}var o=Zn(t.view);e.db.get("_design/"+o[0],(function(n,s){if(e.isCancelled)return r(null,{status:"cancelled"});if(n)return r(Wn(n));var i=s&&s.views&&s.views[o[1]]&&s.views[o[1]].map;if(!i)return r(Hn(Tn,s.views?"missing json key: "+o[1]:"missing json key: views"));t.filter=io(["return function(doc) {",' "use strict";'," var emitted = false;"," var emit = function (a, b) {"," emitted = true;"," };"," var view = "+i+";"," view(doc);"," if (emitted) {"," return true;"," }","};"].join("\n"),{}),e.doChanges(t)}))}else if(t.selector)t.filter=function(e){return function(e,t){if("object"!=typeof t)throw new Error("Selector error: expected a JSON object");var r=$s([{doc:e}],{selector:t=ds(t)},Object.keys(t));return r&&1===r.length}(e,t.selector)},e.doChanges(t);else{var s=Zn(t.filter);e.db.get("_design/"+s[0],(function(n,o){if(e.isCancelled)return r(null,{status:"cancelled"});if(n)return r(Wn(n));var i=o&&o.filters&&o.filters[s[1]];if(!i)return r(Hn(Tn,o&&o.filters?"missing json key: "+s[1]:"missing json key: filters"));t.filter=io('"use strict";\nreturn '+i+";",{}),e.doChanges(t)}))}}function Ts(e){return e.reduce((function(e,t){return e[t]=!0,e}),{})}es.plugin((function(e){e._changesFilterPlugin={validate:As,normalize:Cs,shouldFilter:Is,filter:Ns}})),es.version="9.0.0";var Rs=Ts(["_id","_rev","_access","_attachments","_deleted","_revisions","_revs_info","_conflicts","_deleted_conflicts","_local_seq","_rev_tree","_replication_id","_replication_state","_replication_state_time","_replication_state_reason","_replication_stats","_removed"]),qs=Ts(["_access","_attachments","_replication_id","_replication_state","_replication_state_time","_replication_state_reason","_replication_stats"]);function Ds(e){if(!/^\d+-/.test(e))return Hn(Jn);var t=e.indexOf("-"),r=e.substring(0,t),n=e.substring(t+1);return{prefix:parseInt(r,10),id:n}}function Ls(e,t,r){var n,o,s;r||(r={deterministic_revs:!0});var i={status:"available"};if(e._deleted&&(i.deleted=!0),t)if(e._id||(e._id=Eo()),o=ko(e,r.deterministic_revs),e._rev){if((s=Ds(e._rev)).error)return s;e._rev_tree=[{pos:s.prefix,ids:[s.id,{status:"missing"},[[o,i,[]]]]}],n=s.prefix+1}else e._rev_tree=[{pos:1,ids:[o,i,[]]}],n=1;else if(e._revisions&&(e._rev_tree=function(e,t){for(var r=e.start-e.ids.length+1,n=e.ids,o=[n[0],t,[]],s=1,i=n.length;s<i;s++)o=[n[s],{status:"missing"},[o]];return[{pos:r,ids:o}]}(e._revisions,i),n=e._revisions.start,o=e._revisions.ids[0]),!e._rev_tree){if((s=Ds(e._rev)).error)return s;n=s.prefix,o=s.id,e._rev_tree=[{pos:n,ids:[o,i,[]]}]}Yn(e._id),e._rev=n+"-"+o;var a={metadata:{},data:{}};for(var c in e)if(Object.prototype.hasOwnProperty.call(e,c)){var u="_"===c[0];if(u&&!Rs[c]){var l=Hn(Bn,c);throw l.message=Bn.message+": "+c,l}u&&!qs[c]?a.metadata[c.slice(1)]=e[c]:a.data[c]=e[c]}return a}function Ms(e,t,r){var n=function(e){try{return co(e)}catch(e){return{error:Hn(Vn,"Attachment is not a valid base64 string")}}}(e.data);if(n.error)return r(n.error);e.length=n.length,e.data="blob"===t?ho(n,e.content_type):"base64"===t?uo(n):n,bo(n,(function(t){e.digest="md5-"+t,r()}))}function Vs(e,t,r){if(e.stub)return r();"string"==typeof e.data?Ms(e,t,r):function(e,t,r){bo(e.data,(function(n){e.digest="md5-"+n,e.length=e.data.size||e.data.length||0,"binary"===t?vo(e.data,(function(t){e.data=t,r()})):"base64"===t?yo(e.data,(function(t){e.data=t,r()})):r()}))}(e,t,r)}function Us(e,t,r,n,o,s,i,a){if(function(e,t){for(var r,n=e.slice(),o=t.split("-"),s=parseInt(o[0],10),i=o[1];r=n.pop();){if(r.pos===s&&r.ids[0]===i)return!0;for(var a=r.ids[2],c=0,u=a.length;c<u;c++)n.push({pos:r.pos+1,ids:a[c]})}return!1}(t.rev_tree,r.metadata.rev)&&!a)return n[o]=r,s();var c=t.winningRev||Po(t),u="deleted"in t?t.deleted:Mo(t,c),l="deleted"in r.metadata?r.metadata.deleted:Mo(r.metadata),f=/^1-/.test(r.metadata.rev);if(u&&!l&&a&&f){var d=r.data;d._rev=c,d._id=r.metadata.id,r=Ls(d,a)}var h=Do(t.rev_tree,r.metadata.rev_tree[0],e);if(a&&(u&&l&&"new_leaf"!==h.conflicts||!u&&"new_leaf"!==h.conflicts||u&&!l&&"new_branch"===h.conflicts)){var p=Hn(Rn);return n[o]=p,s()}var m=r.metadata.rev;r.metadata.rev_tree=h.tree,r.stemmedRevs=h.stemmedRevs||[],t.rev_map&&(r.metadata.rev_map=t.rev_map);var v=Po(r.metadata),y=Mo(r.metadata,v),g=u===y?0:u<y?-1:1;i(r,v,y,m===v?y:Mo(r.metadata,m),!0,g,o,s)}function Bs(e,t,r,n,o,s,i,a,c){e=e||1e3;var u=a.new_edits,l=new Map,f=0,d=t.length;function h(){++f===d&&c&&c()}t.forEach((function(e,t){if(e._id&&Vo(e._id)){var n=e._deleted?"_removeLocal":"_putLocal";r[n](e,{ctx:o},(function(e,r){s[t]=e||r,h()}))}else{var i=e.metadata.id;l.has(i)?(d--,l.get(i).push([e,t])):l.set(i,[[e,t]])}})),l.forEach((function(t,r){var o=0;function c(){++o<t.length?l():h()}function l(){var l=t[o],f=l[0],d=l[1];if(n.has(r))Us(e,n.get(r),f,s,d,c,i,u);else{var h=Do([],f.metadata.rev_tree[0],e);f.metadata.rev_tree=h.tree,f.stemmedRevs=h.stemmedRevs||[],function(e,t,r){var n=Po(e.metadata),o=Mo(e.metadata,n);if("was_delete"in a&&o)return s[t]=Hn(Tn,"deleted"),r();if(u&&function(e){return"missing"===e.metadata.rev_tree[0].ids[1].status}(e)){var c=Hn(Rn);return s[t]=c,r()}i(e,n,o,o,!1,o?0:1,t,r)}(f,d,c)}}l()}))}var zs="document-store",Ks="by-sequence",Fs="attach-store",Js="attach-seq-store",Gs="meta-store",Hs="local-store",Ws="detect-blob-support";function Qs(e){try{return JSON.stringify(e)}catch(t){return cn.stringify(e)}}function Ys(e){return function(t){var r="unknown_error";t.target&&t.target.error&&(r=t.target.error.name||t.target.error.message),e(Hn(Fn,r,t.type))}}function Xs(e,t,r){return{data:Qs(e),winningRev:t,deletedOrLocal:r?"1":"0",seq:e.seq,id:e.id}}function Zs(e){if(!e)return null;var t=function(e){try{return JSON.parse(e)}catch(t){return cn.parse(e)}}(e.data);return t.winningRev=e.winningRev,t.deleted="1"===e.deletedOrLocal,t.seq=e.seq,t}function ei(e){if(!e)return e;var t=e._doc_id_rev.lastIndexOf(":");return e._id=e._doc_id_rev.substring(0,t-1),e._rev=e._doc_id_rev.substring(t+1),delete e._doc_id_rev,e}function ti(e,t,r,n){r?n(e?"string"!=typeof e?e:po(e,t):lo([""],{type:t})):e?"string"!=typeof e?mo(e,(function(e){n(uo(e))})):n(e):n("")}function ri(e,t,r,n){var o=Object.keys(e._attachments||{});if(!o.length)return n&&n();var s=0;function i(){++s===o.length&&n&&n()}o.forEach((function(n){t.attachments&&t.include_docs?function(e,t){var n=e._attachments[t],o=n.digest;r.objectStore(Fs).get(o).onsuccess=function(e){n.body=e.target.result.body,i()}}(e,n):(e._attachments[n].stub=!0,i())}))}function ni(e,t){return Promise.all(e.map((function(e){if(e.doc&&e.doc._attachments){var r=Object.keys(e.doc._attachments);return Promise.all(r.map((function(r){var n=e.doc._attachments[r];if("body"in n){var o=n.body,s=n.content_type;return new Promise((function(i){ti(o,s,t,(function(t){e.doc._attachments[r]=Object.assign($n(n,["digest","content_type"]),{data:t}),i()}))}))}})))}})))}function oi(e,t,r){var n=[],o=r.objectStore(Ks),s=r.objectStore(Fs),i=r.objectStore(Js),a=e.length;function c(){--a||function(){if(!n.length)return;n.forEach((function(e){i.index("digestSeq").count(IDBKeyRange.bound(e+"::",e+"::",!1,!1)).onsuccess=function(t){t.target.result||s.delete(e)}}))}()}e.forEach((function(e){var r=o.index("_doc_id_rev"),s=t+"::"+e;r.getKey(s).onsuccess=function(e){var t=e.target.result;if("number"!=typeof t)return c();o.delete(t),i.index("seq").openCursor(IDBKeyRange.only(t)).onsuccess=function(e){var t=e.target.result;if(t){var r=t.value.digestSeq.split("::")[0];n.push(r),i.delete(t.primaryKey),t.continue()}else c()}}}))}function si(e,t,r){try{return{txn:e.transaction(t,r)}}catch(e){return{error:e}}}var ii=new class extends ln{constructor(){super(),this._listeners={},jn()&&addEventListener("storage",(e=>{this.emit(e.key)}))}addListener(e,t,r,n){if(!this._listeners[t]){var o=!1,s=this;this._listeners[t]=i,this.on(e,i)}function i(){if(s._listeners[t])if(o)o="waiting";else{o=!0;var e=$n(n,["style","include_docs","attachments","conflicts","filter","doc_ids","view","since","query_params","binary","return_docs"]);r.changes(e).on("change",(function(e){e.seq>n.since&&!n.cancelled&&(n.since=e.seq,n.onChange(e))})).on("complete",(function(){"waiting"===o&&On(i),o=!1})).on("error",(function(){o=!1}))}}}removeListener(e,t){t in this._listeners&&(super.removeListener(e,this._listeners[t]),delete this._listeners[t])}notifyLocalWindows(e){jn()&&(localStorage[e]="a"===localStorage[e]?"b":"a")}notify(e){this.emit(e),this.notifyLocalWindows(e)}};function ai(e,t,r,n,o,s){for(var i,a,c,u,l,f,d,h,p=t.docs,m=0,v=p.length;m<v;m++){var y=p[m];y._id&&Vo(y._id)||(y=p[m]=Ls(y,r.new_edits,e)).error&&!d&&(d=y)}if(d)return s(d);var g=!1,_=0,w=new Array(p.length),b=new Map,$=!1,k=n._meta.blobSupport?"blob":"base64";function E(){g=!0,P()}function P(){h&&g&&(h.docCount+=_,f.put(h))}function S(){$||(ii.notify(n._meta.name),s(null,w))}function j(e,t,r,n,o,s,i,a){e.metadata.winningRev=t,e.metadata.deleted=r;var c=e.data;if(c._id=e.metadata.id,c._rev=e.metadata.rev,n&&(c._deleted=!0),c._attachments&&Object.keys(c._attachments).length)return function(e,t,r,n,o,s){var i=e.data,a=0,c=Object.keys(i._attachments);function l(){a===c.length&&O(e,t,r,n,o,s)}function f(){a++,l()}c.forEach((function(r){var n=e.data._attachments[r];if(n.stub)a++,l();else{var o=n.data;delete n.data,n.revpos=parseInt(t,10),function(e,t,r){var n=u.count(e);n.onsuccess=function(n){if(n.target.result)return r();var o={digest:e,body:t};u.put(o).onsuccess=r}}(n.digest,o,f)}}))}(e,t,r,o,i,a);_+=s,P(),O(e,t,r,o,i,a)}function O(e,t,r,o,s,u){var f=e.data,d=e.metadata;function h(s){var c=e.stemmedRevs||[];o&&n.auto_compaction&&(c=c.concat(function(e){var t=[];return So(e.rev_tree,(function(e,r,n,o,s){"available"!==s.status||e||(t.push(r+"-"+n),s.status="missing")})),t}(e.metadata))),c&&c.length&&oi(c,e.metadata.id,i),d.seq=s.target.result;var u=Xs(d,t,r);a.put(u).onsuccess=p}function p(){w[s]={ok:!0,id:d.id,rev:d.rev},b.set(e.metadata.id,e.metadata),function(e,t,r){var n=0,o=Object.keys(e.data._attachments||{});if(!o.length)return r();function s(){++n===o.length&&r()}function i(r){var n=e.data._attachments[r].digest,o=l.put({seq:t,digestSeq:n+"::"+t});o.onsuccess=s,o.onerror=function(e){e.preventDefault(),e.stopPropagation(),s()}}for(var a=0;a<o.length;a++)i(o[a])}(e,d.seq,u)}f._doc_id_rev=d.id+"::"+d.rev,delete f._id,delete f._rev;var m=c.put(f);m.onsuccess=h,m.onerror=function(e){e.preventDefault(),e.stopPropagation(),c.index("_doc_id_rev").getKey(f._doc_id_rev).onsuccess=function(e){c.put(f,e.target.result).onsuccess=h}}}!function(e,t,r){if(!e.length)return r();var n,o=0;function s(){o++,e.length===o&&(n?r(n):r())}e.forEach((function(e){var r=e.data&&e.data._attachments?Object.keys(e.data._attachments):[],o=0;if(!r.length)return s();function i(e){n=e,++o===r.length&&s()}for(var a in e.data._attachments)Object.prototype.hasOwnProperty.call(e.data._attachments,a)&&Vs(e.data._attachments[a],t,i)}))}(p,k,(function(t){if(t)return s(t);!function(){var t=si(o,[zs,Ks,Fs,Hs,Js,Gs],"readwrite");if(t.error)return s(t.error);(i=t.txn).onabort=Ys(s),i.ontimeout=Ys(s),i.oncomplete=S,a=i.objectStore(zs),c=i.objectStore(Ks),u=i.objectStore(Fs),l=i.objectStore(Js),(f=i.objectStore(Gs)).get(Gs).onsuccess=function(e){h=e.target.result,P()},function(e){var t=[];if(p.forEach((function(e){e.data&&e.data._attachments&&Object.keys(e.data._attachments).forEach((function(r){var n=e.data._attachments[r];n.stub&&t.push(n.digest)}))})),!t.length)return e();var r,n=0;function o(){++n===t.length&&e(r)}t.forEach((function(e){!function(e,t){var r=u.get(e);r.onsuccess=function(r){if(r.target.result)t();else{var n=Hn(Gn,"unknown stub attachment with digest "+e);n.status=412,t(n)}}}(e,(function(e){e&&!r&&(r=e),o()}))}))}((function(t){if(t)return $=!0,s(t);!function(){if(!p.length)return;var t=0;function o(){++t===p.length&&Bs(e.revs_limit,p,n,b,i,w,j,r,E)}function s(e){var t=Zs(e.target.result);t&&b.set(t.id,t),o()}for(var c=0,u=p.length;c<u;c++){var l=p[c];if(l._id&&Vo(l._id))o();else a.get(l.metadata.id).onsuccess=s}}()}))}()}))}function ci(e,t,r,n,o){var s,i,a;function c(e){i=e.target.result,s&&o(s,i,a)}function u(e){s=e.target.result,i&&o(s,i,a)}function l(e){var t=e.target.result;if(!t)return o();o([t.key],[t.value],t)}-1===n&&(n=1e3),"function"==typeof e.getAll&&"function"==typeof e.getAllKeys&&n>1&&!r?(a={continue:function(){if(!s.length)return o();var r,a=s[s.length-1];if(t&&t.upper)try{r=IDBKeyRange.bound(a,t.upper,!0,t.upperOpen)}catch(e){if("DataError"===e.name&&0===e.code)return o()}else r=IDBKeyRange.lowerBound(a,!0);t=r,s=null,i=null,e.getAll(t,n).onsuccess=c,e.getAllKeys(t,n).onsuccess=u}},e.getAll(t,n).onsuccess=c,e.getAllKeys(t,n).onsuccess=u):r?e.openCursor(t,"prev").onsuccess=l:e.openCursor(t).onsuccess=l}function ui(e,t,r){var n,o,s="startkey"in e&&e.startkey,i="endkey"in e&&e.endkey,a="key"in e&&e.key,c="keys"in e&&e.keys,u=e.skip||0,l="number"==typeof e.limit?e.limit:-1,f=!1!==e.inclusive_end;if(!c&&(n=function(e,t,r,n,o){try{if(e&&t)return o?IDBKeyRange.bound(t,e,!r,!1):IDBKeyRange.bound(e,t,!1,!r);if(e)return o?IDBKeyRange.upperBound(e):IDBKeyRange.lowerBound(e);if(t)return o?IDBKeyRange.lowerBound(t,!r):IDBKeyRange.upperBound(t,!r);if(n)return IDBKeyRange.only(n)}catch(e){return{error:e}}return null}(s,i,f,a,e.descending),(o=n&&n.error)&&("DataError"!==o.name||0!==o.code)))return r(Hn(Fn,o.name,o.message));var d=[zs,Ks,Gs];e.attachments&&d.push(Fs);var h=si(t,d,"readonly");if(h.error)return r(h.error);var p=h.txn;p.oncomplete=function(){e.attachments?ni(b,e.binary).then(P):P()},p.onabort=Ys(r);var m,v,y=p.objectStore(zs),g=p.objectStore(Ks),_=p.objectStore(Gs),w=g.index("_doc_id_rev"),b=[];function $(t,r){var n={id:r.id,key:r.id,value:{rev:t}};r.deleted?c&&(b.push(n),n.value.deleted=!0,n.doc=null):u--<=0&&(b.push(n),e.include_docs&&function(t,r,n){var o=t.id+"::"+n;w.get(o).onsuccess=function(n){if(r.doc=ei(n.target.result)||{},e.conflicts){var o=xo(t);o.length&&(r.doc._conflicts=o)}ri(r.doc,e,p)}}(r,n,t))}function k(e){for(var t=0,r=e.length;t<r&&b.length!==l;t++){var n=e[t];if(n.error&&c)b.push(n);else{var o=Zs(n);$(o.winningRev,o)}}}function E(e,t,r){r&&(k(t),b.length<l&&r.continue())}function P(){var t={total_rows:m,offset:e.skip,rows:b};e.update_seq&&void 0!==v&&(t.update_seq=v),r(null,t)}return _.get(Gs).onsuccess=function(e){m=e.target.result.docCount},e.update_seq&&(g.openKeyCursor(null,"prev").onsuccess=e=>{var t=e.target.result;t&&t.key&&(v=t.key)}),o||0===l?void 0:c?function(e,t,r){var n=new Array(e.length),o=0;e.forEach((function(s,i){t.get(s).onsuccess=function(t){t.target.result?n[i]=t.target.result:n[i]={key:s,error:"not_found"},++o===e.length&&r(e,n,{})}}))}(c,y,E):-1===l?function(e,t,r){if("function"!=typeof e.getAll){var n=[];e.openCursor(t).onsuccess=function(e){var t=e.target.result;t?(n.push(t.value),t.continue()):r({target:{result:n}})}}else e.getAll(t).onsuccess=r}(y,n,(function(t){var r=t.target.result;e.descending&&(r=r.reverse()),k(r)})):void ci(y,n,e.descending,l+u,E)}var li=!1,fi=[];function di(){!li&&fi.length&&(li=!0,fi.shift()())}function hi(e,t,r,n){if((e=gn(e)).continuous){var o=r+":"+Eo();return ii.addListener(r,o,t,e),ii.notify(r),{cancel:function(){ii.removeListener(r,o)}}}var s=e.doc_ids&&new Set(e.doc_ids);e.since=e.since||0;var i=e.since,a="limit"in e?e.limit:-1;0===a&&(a=1);var c,u,l,f,d=[],h=0,p=Qn(e),m=new Map;function v(e,t,r,n){if(r.seq!==t)return n();if(r.winningRev===e._rev)return n(r,e);var o=e._id+"::"+r.winningRev;f.get(o).onsuccess=function(e){n(r,ei(e.target.result))}}function y(){e.complete(null,{results:d,last_seq:i})}var g=[zs,Ks];e.attachments&&g.push(Fs);var _=si(n,g,"readonly");if(_.error)return e.complete(_.error);(c=_.txn).onabort=Ys(e.complete),c.oncomplete=function(){!e.continuous&&e.attachments?ni(d).then(y):y()},u=c.objectStore(Ks),l=c.objectStore(zs),f=u.index("_doc_id_rev"),ci(u,e.since&&!e.descending?IDBKeyRange.lowerBound(e.since,!0):null,e.descending,a,(function(t,r,n){if(n&&t.length){var o=new Array(t.length),u=new Array(t.length),f=0;r.forEach((function(r,i){!function(e,t,r){if(s&&!s.has(e._id))return r();var n=m.get(e._id);if(n)return v(e,t,n,r);l.get(e._id).onsuccess=function(o){n=Zs(o.target.result),m.set(e._id,n),v(e,t,n,r)}}(ei(r),t[i],(function(r,s){u[i]=r,o[i]=s,++f===t.length&&function(){for(var t=[],r=0,s=o.length;r<s&&h!==a;r++){var i=o[r];if(i){var c=u[r];t.push(y(c,i))}}Promise.all(t).then((function(t){for(var r=0,n=t.length;r<n;r++)t[r]&&e.onChange(t[r])})).catch(e.complete),h!==a&&n.continue()}()}))}))}function y(t,r){var n=e.processChange(r,t,e);i=n.seq=t.seq;var o=p(n);return"object"==typeof o?Promise.reject(o):o?(h++,e.return_docs&&d.push(n),e.attachments&&e.include_docs?new Promise((function(t){ri(r,e,c,(function(){ni([n],e.binary).then((function(){t(n)}))}))})):Promise.resolve(n)):Promise.resolve()}}))}var pi,mi=new Map,vi=new Map;function yi(e,t){var r=this;!function(e,t,r){fi.push((function(){e((function(e,n){!function(e,t,r,n){try{e(t,r)}catch(t){n.emit("error",t)}}(t,e,n,r),li=!1,On((function(){di()}))}))})),di()}((function(t){!function(e,t,r){var n=t.name,o=null,s=null;function i(e){return function(t,r){t&&t instanceof Error&&!t.reason&&s&&(t.reason=s),e(t,r)}}function a(e){var t=e.createObjectStore(zs,{keyPath:"id"});e.createObjectStore(Ks,{autoIncrement:!0}).createIndex("_doc_id_rev","_doc_id_rev",{unique:!0}),e.createObjectStore(Fs,{keyPath:"digest"}),e.createObjectStore(Gs,{keyPath:"id",autoIncrement:!1}),e.createObjectStore(Ws),t.createIndex("deletedOrLocal","deletedOrLocal",{unique:!1}),e.createObjectStore(Hs,{keyPath:"_id"});var r=e.createObjectStore(Js,{autoIncrement:!0});r.createIndex("seq","seq"),r.createIndex("digestSeq","digestSeq",{unique:!0})}function c(e,t){var r=e.objectStore(zs);r.createIndex("deletedOrLocal","deletedOrLocal",{unique:!1}),r.openCursor().onsuccess=function(e){var n=e.target.result;if(n){var o=n.value,s=Mo(o);o.deletedOrLocal=s?"1":"0",r.put(o),n.continue()}else t()}}function u(e){e.createObjectStore(Hs,{keyPath:"_id"}).createIndex("_doc_id_rev","_doc_id_rev",{unique:!0})}function l(e,t){var r=e.objectStore(Hs),n=e.objectStore(zs),o=e.objectStore(Ks);n.openCursor().onsuccess=function(e){var s=e.target.result;if(s){var i=s.value,a=i.id,c=Vo(a),u=Po(i);if(c){var l=a+"::"+u,f=a+"::",d=a+"::~",h=o.index("_doc_id_rev"),p=IDBKeyRange.bound(f,d,!1,!1),m=h.openCursor(p);m.onsuccess=function(e){if(m=e.target.result){var t=m.value;t._doc_id_rev===l&&r.put(t),o.delete(m.primaryKey),m.continue()}else n.delete(s.primaryKey),s.continue()}}else s.continue()}else t&&t()}}function f(e){var t=e.createObjectStore(Js,{autoIncrement:!0});t.createIndex("seq","seq"),t.createIndex("digestSeq","digestSeq",{unique:!0})}function d(e,t){var r=e.objectStore(Ks),n=e.objectStore(Fs),o=e.objectStore(Js);n.count().onsuccess=function(e){if(!e.target.result)return t();r.openCursor().onsuccess=function(e){var r=e.target.result;if(!r)return t();for(var n=r.value,s=r.primaryKey,i=Object.keys(n._attachments||{}),a={},c=0;c<i.length;c++){a[n._attachments[i[c]].digest]=!0}var u=Object.keys(a);for(c=0;c<u.length;c++){var l=u[c];o.put({seq:s,digestSeq:l+"::"+s})}r.continue()}}}function h(e){function t(e){return e.data?Zs(e):(e.deleted="1"===e.deletedOrLocal,e)}var r=e.objectStore(Ks),n=e.objectStore(zs);n.openCursor().onsuccess=function(e){var o=e.target.result;if(o){var s=t(o.value);if(s.winningRev=s.winningRev||Po(s),s.seq)return a();i()}function i(){var e=s.id+"::",t=s.id+"::",n=r.index("_doc_id_rev").openCursor(IDBKeyRange.bound(e,t)),o=0;n.onsuccess=function(e){var t=e.target.result;if(!t)return s.seq=o,a();var r=t.primaryKey;r>o&&(o=r),t.continue()}}function a(){var e=Xs(s,s.winningRev,s.deleted);n.put(e).onsuccess=function(){o.continue()}}}}e._meta=null,e._remote=!1,e.type=function(){return"idb"},e._id=wn((function(t){t(null,e._meta.instanceId)})),e._bulkDocs=function(r,n,s){ai(t,r,n,e,o,i(s))},e._get=function(e,t,r){var n,s,i,a=t.ctx;if(!a){var c=si(o,[zs,Ks,Fs],"readonly");if(c.error)return r(c.error);a=c.txn}function u(){r(i,{doc:n,metadata:s,ctx:a})}a.objectStore(zs).get(e).onsuccess=function(e){if(!(s=Zs(e.target.result)))return i=Hn(Tn,"missing"),u();var r;if(t.rev)r=t.latest?function(e,t){for(var r,n=t.rev_tree.slice();r=n.pop();){var o=r.pos,s=r.ids,i=s[0],a=s[1],c=s[2],u=0===c.length,l=r.history?r.history.slice():[];if(l.push({id:i,pos:o,opts:a}),u)for(var f=0,d=l.length;f<d;f++){var h=l[f];if(h.pos+"-"+h.id===e)return o+"-"+i}for(var p=0,m=c.length;p<m;p++)n.push({pos:o+1,ids:c[p],history:l})}throw new Error("Unable to resolve latest revision for id "+t.id+", rev "+e)}(t.rev,s):t.rev;else if(r=s.winningRev,Mo(s))return i=Hn(Tn,"deleted"),u();var o=a.objectStore(Ks),c=s.id+"::"+r;o.index("_doc_id_rev").get(c).onsuccess=function(e){if((n=e.target.result)&&(n=ei(n)),!n)return i=Hn(Tn,"missing"),u();u()}}},e._getAttachment=function(e,t,r,n,s){var i;if(n.ctx)i=n.ctx;else{var a=si(o,[zs,Ks,Fs],"readonly");if(a.error)return s(a.error);i=a.txn}var c=r.digest,u=r.content_type;i.objectStore(Fs).get(c).onsuccess=function(e){ti(e.target.result.body,u,n.binary,(function(e){s(null,e)}))}},e._info=function(t){var r,n,s=si(o,[Gs,Ks],"readonly");if(s.error)return t(s.error);var i=s.txn;i.objectStore(Gs).get(Gs).onsuccess=function(e){n=e.target.result.docCount},i.objectStore(Ks).openKeyCursor(null,"prev").onsuccess=function(e){var t=e.target.result;r=t?t.key:0},i.oncomplete=function(){t(null,{doc_count:n,update_seq:r,idb_attachment_format:e._meta.blobSupport?"binary":"base64"})}},e._allDocs=function(e,t){ui(e,o,i(t))},e._changes=function(t){return hi(t,e,n,o)},e._close=function(e){o.close(),mi.delete(n),e()},e._getRevisionTree=function(e,t){var r=si(o,[zs],"readonly");if(r.error)return t(r.error);r.txn.objectStore(zs).get(e).onsuccess=function(e){var r=Zs(e.target.result);r?t(null,r.rev_tree):t(Hn(Tn))}},e._doCompaction=function(e,t,r){var n=si(o,[zs,Ks,Fs,Js],"readwrite");if(n.error)return r(n.error);var s=n.txn;s.objectStore(zs).get(e).onsuccess=function(r){var n=Zs(r.target.result);So(n.rev_tree,(function(e,r,n,o,s){var i=r+"-"+n;-1!==t.indexOf(i)&&(s.status="missing")})),oi(t,e,s);var o=n.winningRev,i=n.deleted;s.objectStore(zs).put(Xs(n,o,i))},s.onabort=Ys(r),s.oncomplete=function(){r()}},e._getLocal=function(e,t){var r=si(o,[Hs],"readonly");if(r.error)return t(r.error);var n=r.txn.objectStore(Hs).get(e);n.onerror=Ys(t),n.onsuccess=function(e){var r=e.target.result;r?(delete r._doc_id_rev,t(null,r)):t(Hn(Tn))}},e._putLocal=function(e,t,r){"function"==typeof t&&(r=t,t={}),delete e._revisions;var n=e._rev,s=e._id;e._rev=n?"0-"+(parseInt(n.split("-")[1],10)+1):"0-1";var i,a=t.ctx;if(!a){var c=si(o,[Hs],"readwrite");if(c.error)return r(c.error);(a=c.txn).onerror=Ys(r),a.oncomplete=function(){i&&r(null,i)}}var u,l=a.objectStore(Hs);n?(u=l.get(s)).onsuccess=function(o){var s=o.target.result;s&&s._rev===n?l.put(e).onsuccess=function(){i={ok:!0,id:e._id,rev:e._rev},t.ctx&&r(null,i)}:r(Hn(Rn))}:((u=l.add(e)).onerror=function(e){r(Hn(Rn)),e.preventDefault(),e.stopPropagation()},u.onsuccess=function(){i={ok:!0,id:e._id,rev:e._rev},t.ctx&&r(null,i)})},e._removeLocal=function(e,t,r){"function"==typeof t&&(r=t,t={});var n,s=t.ctx;if(!s){var i=si(o,[Hs],"readwrite");if(i.error)return r(i.error);(s=i.txn).oncomplete=function(){n&&r(null,n)}}var a=e._id,c=s.objectStore(Hs),u=c.get(a);u.onerror=Ys(r),u.onsuccess=function(o){var s=o.target.result;s&&s._rev===e._rev?(c.delete(a),n={ok:!0,id:a,rev:"0-0"},t.ctx&&r(null,n)):r(Hn(Tn))}},e._destroy=function(e,t){ii.removeAllListeners(n);var r=vi.get(n);r&&r.result&&(r.result.close(),mi.delete(n));var o=indexedDB.deleteDatabase(n);o.onsuccess=function(){vi.delete(n),jn()&&n in localStorage&&delete localStorage[n],t(null,{ok:!0})},o.onerror=Ys(t)};var p=mi.get(n);if(p)return o=p.idb,e._meta=p.global,On((function(){r(null,e)}));var m=indexedDB.open(n,5);vi.set(n,m),m.onupgradeneeded=function(e){var t=e.target.result;if(e.oldVersion<1)return a(t);var r=e.currentTarget.transaction;e.oldVersion<3&&u(t),e.oldVersion<4&&f(t);var n=[c,l,d,h],o=e.oldVersion;function s(){var e=n[o-1];o++,e&&e(r,s)}s()},m.onsuccess=function(t){(o=t.target.result).onversionchange=function(){o.close(),mi.delete(n)},o.onabort=function(e){xn("error","Database has a global failure",e.target.error),s=e.target.error,o.close(),mi.delete(n)};var i,a,c,u,l=o.transaction([Gs,Ws,zs],"readwrite"),f=!1;function d(){void 0!==c&&f&&(e._meta={name:n,instanceId:u,blobSupport:c},mi.set(n,{idb:o,global:e._meta}),r(null,e))}function h(){if(void 0!==a&&void 0!==i){var e=n+"_id";e in i?u=i[e]:i[e]=u=Eo(),i.docCount=a,l.objectStore(Gs).put(i)}}l.objectStore(Gs).get(Gs).onsuccess=function(e){i=e.target.result||{id:Gs},h()},function(e,t){e.objectStore(zs).index("deletedOrLocal").count(IDBKeyRange.only("0")).onsuccess=function(e){t(e.target.result)}}(l,(function(e){a=e,h()})),pi||(pi=function(e,t,r){return new Promise((function(n){var o=lo([""]);let s;{const n=r;s=e.objectStore(t).put(o,n)}s.onsuccess=function(){var e=navigator.userAgent.match(/Chrome\/(\d+)/),t=navigator.userAgent.match(/Edge\//);n(t||!e||parseInt(e[1],10)>=43)},s.onerror=e.onabort=function(e){e.preventDefault(),e.stopPropagation(),n(!1)}})).catch((function(){return!1}))}(l,Ws,"key")),pi.then((function(e){c=e,d()})),l.oncomplete=function(){f=!0,d()},l.onabort=Ys(r)},m.onerror=function(e){var t=e.target.error&&e.target.error.message;t?-1!==t.indexOf("stored database is a higher version")&&(t=new Error('This DB was created with the newer "indexeddb" adapter, but you are trying to open it with the older "idb" adapter')):t="Failed to open indexedDB, are you in private browsing mode?",xn("error",t),r(Hn(Fn,t))}}(r,e,t)}),t,r.constructor)}yi.valid=function(){try{return"undefined"!=typeof indexedDB&&"undefined"!=typeof IDBKeyRange}catch(e){return!1}};const gi=5e3,_i={};function wi(e){const t=e.doc||e.ok,r=t&&t._attachments;r&&Object.keys(r).forEach((function(e){const t=r[e];t.data=po(t.data,t.content_type)}))}function bi(e){return/^_design/.test(e)?"_design/"+encodeURIComponent(e.slice(8)):e.startsWith("_local/")?"_local/"+encodeURIComponent(e.slice(7)):encodeURIComponent(e)}function $i(e){return e._attachments&&Object.keys(e._attachments)?Promise.all(Object.keys(e._attachments).map((function(t){const r=e._attachments[t];if(r.data&&"string"!=typeof r.data)return new Promise((function(e){yo(r.data,e)})).then((function(e){r.data=e}))}))):Promise.resolve()}function ki(e,t){if(function(e){if(!e.prefix)return!1;const t=so(e.prefix).protocol;return"http"===t||"https"===t}(t)){const r=t.name.substr(t.prefix.length);e=t.prefix.replace(/\/?$/,"/")+encodeURIComponent(r)}const r=so(e);(r.user||r.password)&&(r.auth={username:r.user,password:r.password});const n=r.path.replace(/(^\/|\/$)/g,"").split("/");return r.db=n.pop(),-1===r.db.indexOf("%")&&(r.db=encodeURIComponent(r.db)),r.path=n.join("/"),r}function Ei(e,t){return Pi(e,e.db+"/"+t)}function Pi(e,t){const r=e.path?"/":"";return e.protocol+"://"+e.host+(e.port?":"+e.port:"")+"/"+e.path+r+t}function Si(e){const t=Object.keys(e);return 0===t.length?"":"?"+t.map((t=>t+"="+encodeURIComponent(e[t]))).join("&")}function ji(e,t){const r=this,n=ki(e.name,e),o=Ei(n,"");e=gn(e);const s=async function(t,r){if((r=r||{}).headers=r.headers||new rs,r.credentials="include",e.auth||n.auth){const t=e.auth||n.auth,o=t.username+":"+t.password,s=uo(unescape(encodeURIComponent(o)));r.headers.set("Authorization","Basic "+s)}const o=e.headers||{};Object.keys(o).forEach((function(e){r.headers.append(e,o[e])})),function(e){const t="undefined"!=typeof navigator&&navigator.userAgent?navigator.userAgent.toLowerCase():"",r=-1!==t.indexOf("msie"),n=-1!==t.indexOf("trident"),o=-1!==t.indexOf("edge"),s=!("method"in e)||"GET"===e.method;return(r||n||o)&&s}(r)&&(t+=(-1===t.indexOf("?")?"?":"&")+"_nonce="+Date.now());const s=e.fetch||ts;return await s(t,r)};function i(e,t){return bn(e,(function(...e){u().then((function(){return t.apply(this,e)})).catch((function(t){e.pop()(t)}))})).bind(r)}async function a(e,t){const r={};(t=t||{}).headers=t.headers||new rs,t.headers.get("Content-Type")||t.headers.set("Content-Type","application/json"),t.headers.get("Accept")||t.headers.set("Accept","application/json");const n=await s(e,t);r.ok=n.ok,r.status=n.status;const o=await n.json();if(r.data=o,!r.ok){r.data.status=r.status;throw Wn(r.data)}return Array.isArray(r.data)&&(r.data=r.data.map((function(e){return e.error||e.missing?Wn(e):e}))),r}let c;async function u(){return e.skip_setup?Promise.resolve():c||(c=a(o).catch((function(e){return e&&e.status&&404===e.status?(Cn(404,"PouchDB is just detecting if the remote exists."),a(o,{method:"PUT"})):Promise.reject(e)})).catch((function(e){return!(!e||!e.status||412!==e.status)||Promise.reject(e)})),c.catch((function(){c=null})),c)}function l(e){return e.split("/").map(encodeURIComponent).join("/")}On((function(){t(null,r)})),r._remote=!0,r.type=function(){return"http"},r.id=i("id",(async function(e){let t;try{const e=await s(Pi(n,""));t=await e.json()}catch(e){t={}}e(null,t&&t.uuid?t.uuid+n.db:Ei(n,""))})),r.compact=i("compact",(async function(e,t){"function"==typeof e&&(t=e,e={}),e=gn(e),await a(Ei(n,"_compact"),{method:"POST"}),function n(){r.info((function(r,o){o&&!o.compact_running?t(null,{ok:!0}):setTimeout(n,e.interval||200)}))}()})),r.bulkGet=bn("bulkGet",(function(e,t){const r=this;async function o(t){const r={};e.revs&&(r.revs=!0),e.attachments&&(r.attachments=!0),e.latest&&(r.latest=!0);try{const o=await a(Ei(n,"_bulk_get"+Si(r)),{method:"POST",body:JSON.stringify({docs:e.docs})});e.attachments&&e.binary&&o.data.results.forEach((function(e){e.docs.forEach(wi)})),t(null,o.data)}catch(e){t(e)}}function s(){const n=Math.ceil(e.docs.length/50);let o=0;const s=new Array(n);function i(e){return function(r,i){s[e]=i.results,++o===n&&t(null,{results:s.flat()})}}for(let t=0;t<n;t++){const n=$n(e,["revs","attachments","binary","latest"]);n.docs=e.docs.slice(50*t,Math.min(e.docs.length,50*(t+1))),Sn(r,n,i(t))}}const i=Pi(n,""),c=_i[i];"boolean"!=typeof c?o((function(e,r){e?(_i[i]=!1,Cn(e.status,"PouchDB is just detecting if the remote supports the _bulk_get API."),s()):(_i[i]=!0,t(null,r))})):c?o(t):s()})),r._info=async function(e){try{await u();const t=await s(Ei(n,"")),r=await t.json();r.host=Ei(n,""),e(null,r)}catch(t){e(t)}},r.fetch=async function(e,t){await u();const r="/"===e.substring(0,1)?Pi(n,e.substring(1)):Ei(n,e);return s(r,t)},r.get=i("get",(async function(e,t,r){"function"==typeof t&&(r=t,t={});const o={};function i(e){const r=e._attachments,o=r&&Object.keys(r);if(!r||!o.length)return;const i=o.map((function(o){return function(){return async function(o){const i=r[o],a=bi(e._id)+"/"+l(o)+"?rev="+e._rev,c=await s(Ei(n,a));let u,f;if(u="buffer"in c?await c.buffer():await c.blob(),t.binary){const e=Object.getOwnPropertyDescriptor(u.__proto__,"type");e&&!e.set||(u.type=i.content_type),f=u}else f=await new Promise((function(e){yo(u,e)}));delete i.stub,delete i.length,i.data=f}(o)}}));return function(e,t){return new Promise((function(r,n){var o,s=0,i=0,a=0,c=e.length;function u(){++a===c?o?n(o):r():d()}function l(){s--,u()}function f(e){s--,o=o||e,u()}function d(){for(;s<t&&i<c;)s++,e[i++]().then(l,f)}d()}))}(i,5)}(t=gn(t)).revs&&(o.revs=!0),t.revs_info&&(o.revs_info=!0),t.latest&&(o.latest=!0),t.open_revs&&("all"!==t.open_revs&&(t.open_revs=JSON.stringify(t.open_revs)),o.open_revs=t.open_revs),t.rev&&(o.rev=t.rev),t.conflicts&&(o.conflicts=t.conflicts),t.update_seq&&(o.update_seq=t.update_seq),e=bi(e);const c=Ei(n,e+Si(o));try{const e=await a(c);t.attachments&&await(u=e.data,Array.isArray(u)?Promise.all(u.map((function(e){if(e.ok)return i(e.ok)}))):i(u)),r(null,e.data)}catch(t){t.docId=e,r(t)}var u})),r.remove=i("remove",(async function(e,t,r,o){let s;"string"==typeof t?(s={_id:e,_rev:t},"function"==typeof r&&(o=r,r={})):(s=e,"function"==typeof t?(o=t,r={}):(o=r,r=t));const i=s._rev||r.rev,c=Ei(n,bi(s._id))+"?rev="+i;try{o(null,(await a(c,{method:"DELETE"})).data)}catch(e){o(e)}})),r.getAttachment=i("getAttachment",(async function(e,t,r,o){"function"==typeof r&&(o=r,r={});const i=r.rev?"?rev="+r.rev:"",a=Ei(n,bi(e))+"/"+l(t)+i;let c;try{const e=await s(a,{method:"GET"});if(!e.ok)throw e;let t;c=e.headers.get("content-type"),(Jr.browser||"function"!=typeof e.buffer)&&(t=await e.blob()),o(null,t)}catch(e){o(e)}})),r.removeAttachment=i("removeAttachment",(async function(e,t,r,o){const s=Ei(n,bi(e)+"/"+l(t))+"?rev="+r;try{o(null,(await a(s,{method:"DELETE"})).data)}catch(e){o(e)}})),r.putAttachment=i("putAttachment",(async function(e,t,r,o,s,i){"function"==typeof s&&(i=s,s=o,o=r,r=null);const c=bi(e)+"/"+l(t);let u=Ei(n,c);if(r&&(u+="?rev="+r),"string"==typeof o){let e;try{e=co(o)}catch(e){return i(Hn(Vn,"Attachment is not a valid base64 string"))}o=e?ho(e,s):""}try{i(null,(await a(u,{headers:new rs({"Content-Type":s}),method:"PUT",body:o})).data)}catch(e){i(e)}})),r._bulkDocs=async function(e,t,r){e.new_edits=t.new_edits;try{await u(),await Promise.all(e.docs.map($i));r(null,(await a(Ei(n,"_bulk_docs"),{method:"POST",body:JSON.stringify(e)})).data)}catch(e){r(e)}},r._put=async function(e,t,r){try{await u(),await $i(e);r(null,(await a(Ei(n,bi(e._id)),{method:"PUT",body:JSON.stringify(e)})).data)}catch(t){t.docId=e&&e._id,r(t)}},r.allDocs=i("allDocs",(async function(e,t){"function"==typeof e&&(t=e,e={});const r={};let o,s="GET";(e=gn(e)).conflicts&&(r.conflicts=!0),e.update_seq&&(r.update_seq=!0),e.descending&&(r.descending=!0),e.include_docs&&(r.include_docs=!0),e.attachments&&(r.attachments=!0),e.key&&(r.key=JSON.stringify(e.key)),e.start_key&&(e.startkey=e.start_key),e.startkey&&(r.startkey=JSON.stringify(e.startkey)),e.end_key&&(e.endkey=e.end_key),e.endkey&&(r.endkey=JSON.stringify(e.endkey)),void 0!==e.inclusive_end&&(r.inclusive_end=!!e.inclusive_end),void 0!==e.limit&&(r.limit=e.limit),void 0!==e.skip&&(r.skip=e.skip);const i=Si(r);void 0!==e.keys&&(s="POST",o={keys:e.keys});try{const r=await a(Ei(n,"_all_docs"+i),{method:s,body:JSON.stringify(o)});e.include_docs&&e.attachments&&e.binary&&r.data.rows.forEach(wi),t(null,r.data)}catch(e){t(e)}})),r._changes=function(e){const t="batch_size"in e?e.batch_size:25;(e=gn(e)).continuous&&!("heartbeat"in e)&&(e.heartbeat=1e4);let r="timeout"in e?e.timeout:3e4;"timeout"in e&&e.timeout&&r-e.timeout<gi&&(r=e.timeout+gi),"heartbeat"in e&&e.heartbeat&&r-e.heartbeat<gi&&(r=e.heartbeat+gi);const o={};"timeout"in e&&e.timeout&&(o.timeout=e.timeout);const s=void 0!==e.limit&&e.limit;let i=s;if(e.style&&(o.style=e.style),(e.include_docs||e.filter&&"function"==typeof e.filter)&&(o.include_docs=!0),e.attachments&&(o.attachments=!0),e.continuous&&(o.feed="longpoll"),e.seq_interval&&(o.seq_interval=e.seq_interval),e.conflicts&&(o.conflicts=!0),e.descending&&(o.descending=!0),e.update_seq&&(o.update_seq=!0),"heartbeat"in e&&e.heartbeat&&(o.heartbeat=e.heartbeat),e.filter&&"string"==typeof e.filter&&(o.filter=e.filter),e.view&&"string"==typeof e.view&&(o.filter="_view",o.view=e.view),e.query_params&&"object"==typeof e.query_params)for(const t in e.query_params)Object.prototype.hasOwnProperty.call(e.query_params,t)&&(o[t]=e.query_params[t]);let c,l="GET";e.doc_ids?(o.filter="_doc_ids",l="POST",c={doc_ids:e.doc_ids}):e.selector&&(o.filter="_selector",l="POST",c={selector:e.selector});const f=new AbortController;let d;const h=async function(r,h){if(e.aborted)return;o.since=r,"object"==typeof o.since&&(o.since=JSON.stringify(o.since)),e.descending?s&&(o.limit=i):o.limit=!s||i>t?t:i;const p=Ei(n,"_changes"+Si(o)),m={signal:f.signal,method:l,body:JSON.stringify(c)};if(d=r,!e.aborted)try{await u();h(null,(await a(p,m)).data)}catch(e){h(e)}},p={results:[]},m=function(r,n){if(e.aborted)return;let o=0;if(n&&n.results){o=n.results.length,p.last_seq=n.last_seq;let t=null,r=null;"number"==typeof n.pending&&(t=n.pending),"string"!=typeof p.last_seq&&"number"!=typeof p.last_seq||(r=p.last_seq),e.query_params,n.results=n.results.filter((function(n){i--;const o=Qn(e)(n);return o&&(e.include_docs&&e.attachments&&e.binary&&wi(n),e.return_docs&&p.results.push(n),e.onChange(n,t,r)),o}))}else if(r)return e.aborted=!0,void e.complete(r);n&&n.last_seq&&(d=n.last_seq);const a=s&&i<=0||n&&o<t||e.descending;(!e.continuous||s&&i<=0)&&a?e.complete(null,p):On((function(){h(d,m)}))};return h(e.since||0,m),{cancel:function(){e.aborted=!0,f.abort()}}},r.revsDiff=i("revsDiff",(async function(e,t,r){"function"==typeof t&&(r=t,t={});try{r(null,(await a(Ei(n,"_revs_diff"),{method:"POST",body:JSON.stringify(e)})).data)}catch(e){r(e)}})),r._close=function(e){e()},r._destroy=async function(e,t){try{t(null,await a(Ei(n,""),{method:"DELETE"}))}catch(e){404===e.status?t(null,{ok:!0}):t(e)}}}ji.valid=function(){return!0};class Oi extends Error{constructor(e){super(),this.status=400,this.name="query_parse_error",this.message=e,this.error=!0;try{Error.captureStackTrace(this,Oi)}catch(e){}}}class xi extends Error{constructor(e){super(),this.status=404,this.name="not_found",this.message=e,this.error=!0;try{Error.captureStackTrace(this,xi)}catch(e){}}}class Ai extends Error{constructor(e){super(),this.status=500,this.name="invalid_value",this.message=e,this.error=!0;try{Error.captureStackTrace(this,Ai)}catch(e){}}}function Ci(e,t){return t&&e.then((function(e){On((function(){t(null,e)}))}),(function(e){On((function(){t(e)}))})),e}function Ii(e,t){return function(){var r=arguments,n=this;return e.add((function(){return t.apply(n,r)}))}}function Ni(e){var t=new Set(e),r=new Array(t.size),n=-1;return t.forEach((function(e){r[++n]=e})),r}function Ti(e){var t=new Array(e.size),r=-1;return e.forEach((function(e,n){t[++r]=n})),t}function Ri(e){return new Ai("builtin "+e+" function requires map values to be numbers or number arrays")}function qi(e){for(var t=0,r=0,n=e.length;r<n;r++){var o=e[r];if("number"!=typeof o){if(!Array.isArray(o))throw Ri("_sum");t="number"==typeof t?[t]:t;for(var s=0,i=o.length;s<i;s++){var a=o[s];if("number"!=typeof a)throw Ri("_sum");void 0===t[s]?t.push(a):t[s]+=a}}else"number"==typeof t?t+=o:t[0]+=o}return t}var Di=xn.bind(null,"log"),Li=Array.isArray,Mi=JSON.parse;function Vi(e,t){return io("return ("+e.replace(/;\s*$/,"")+");",{emit:t,sum:qi,log:Di,isArray:Li,toJSON:Mi})}class Ui{constructor(){this.promise=Promise.resolve()}add(e){return this.promise=this.promise.catch((()=>{})).then((()=>e())),this.promise}finish(){return this.promise}}function Bi(e){if(!e)return"undefined";switch(typeof e){case"function":case"string":return e.toString();default:return JSON.stringify(e)}}async function zi(e,t,r,n,o,s){const i=function(e,t){return Bi(e)+Bi(t)+"undefined"}(r,n);let a;if(!o&&(a=e._cachedViews=e._cachedViews||{},a[i]))return a[i];const c=e.info().then((async function(c){const u=c.db_name+"-mrview-"+(o?"temp":$o(i));await ao(e,"_local/"+s,(function(e){e.views=e.views||{};let r=t;-1===r.indexOf("/")&&(r=t+"/"+t);const n=e.views[r]=e.views[r]||{};if(!n[u])return n[u]=!0,e}));const l=(await e.registerDependentDatabase(u)).db;l.auto_compaction=!0;const f={name:u,db:l,sourceDB:e,adapter:e.adapter,mapFun:r,reduceFun:n};let d;try{d=await f.db.get("_local/lastSeq")}catch(e){if(404!==e.status)throw e}return f.seq=d?d.seq:0,a&&f.db.once("destroyed",(function(){delete a[i]})),f}));return a&&(a[i]=c),c}const Ki={},Fi=new Ui;function Ji(e){return-1===e.indexOf("/")?[e,e]:e.split("/")}function Gi(e,t,r){try{e.emit("error",t)}catch(e){xn("error","The user's map/reduce function threw an uncaught error.\nYou can debug this error by doing:\nmyDatabase.on('error', function (err) { debugger; });\nPlease double-check your map/reduce function."),xn("error",t,r)}}var Hi=function(e,t){return qi(t)},Wi=function(e,t){return t.length},Qi=function(e,t){return{sum:qi(t),min:Math.min.apply(null,t),max:Math.max.apply(null,t),count:t.length,sumsqr:function(e){for(var t=0,r=0,n=e.length;r<n;r++){var o=e[r];t+=o*o}return t}(t)}};var Yi=function(e,t,r,n){function o(e,t,r){try{t(r)}catch(n){Gi(e,n,{fun:t,doc:r})}}function s(e,t,r,n,o){try{return{output:t(r,n,o)}}catch(s){return Gi(e,s,{fun:t,keys:r,values:n,rereduce:o}),{error:s}}}function i(e,t){const r=ms(e.key,t.key);return 0!==r?r:ms(e.value,t.value)}function a(e,t,r){return r=r||0,"number"==typeof t?e.slice(r,t+r):r>0?e.slice(r):e}function c(e){const t=e.value;return t&&"object"==typeof t&&t._id||e.id}function u(e){return function(t){return e.include_docs&&e.attachments&&e.binary&&function(e){for(const t of e.rows){const e=t.doc&&t.doc._attachments;if(e)for(const t of Object.keys(e)){const r=e[t];e[t].data=po(r.data,r.content_type)}}}(t),t}}function l(e,t,r,n){let o=t[e];void 0!==o&&(n&&(o=encodeURIComponent(JSON.stringify(o))),r.push(e+"="+o))}function f(e){if(void 0!==e){const t=Number(e);return isNaN(t)||t!==parseInt(e,10)?e:t}}function d(e){if(e){if("number"!=typeof e)return new Oi(`Invalid value for integer: "${e}"`);if(e<0)return new Oi(`Invalid value for positive integer: "${e}"`)}}function h(e,t){const r=e.descending?"endkey":"startkey",n=e.descending?"startkey":"endkey";if(void 0!==e[r]&&void 0!==e[n]&&ms(e[r],e[n])>0)throw new Oi("No rows can match your key range, reverse your start_key and end_key or set {descending : true}");if(t.reduce&&!1!==e.reduce){if(e.include_docs)throw new Oi("{include_docs:true} is invalid for reduce");if(e.keys&&e.keys.length>1&&!e.group&&!e.group_level)throw new Oi("Multi-key fetches for reduce views must use {group: true}")}for(const t of["group_level","limit","skip"]){const r=d(e[t]);if(r)throw r}}function p(e){return function(t){if(404===t.status)return e;throw t}}function m(e,t,r){var n="_local/lastSeq";return e.db.get(n).catch(p({_id:n,seq:0})).then((function(n){var o=Ti(t);return Promise.all(o.map((function(r){return async function(e,t,r){const n="_local/doc_"+e,o={_id:n,keys:[]},s=r.get(e),i=s[0],a=s[1],c=await(function(e){return 1===e.length&&/^1-/.test(e[0].rev)}(a)?Promise.resolve(o):t.db.get(n).catch(p(o))),u=await function(e){return e.keys.length?t.db.allDocs({keys:e.keys,include_docs:!0}):Promise.resolve({rows:[]})}(c);return function(e,t){const r=[],n=new Set;for(const e of t.rows){const t=e.doc;if(t&&(r.push(t),n.add(t._id),t._deleted=!i.has(t._id),!t._deleted)){const e=i.get(t._id);"value"in e&&(t.value=e.value)}}const o=Ti(i);for(const e of o)if(!n.has(e)){const t={_id:e},n=i.get(e);"value"in n&&(t.value=n.value),r.push(t)}return e.keys=Ni(o.concat(e.keys)),r.push(e),r}(c,u)}(r,e,t)}))).then((function(t){var o=t.flat();return n.seq=r,o.push(n),e.db.bulkDocs({docs:o})})).then((()=>function(e){return e.sourceDB.get("_local/purges").then((function(t){const r=t.purgeSeq;return e.db.get("_local/purgeSeq").then((function(e){return e._rev})).catch(p(void 0)).then((function(t){return e.db.put({_id:"_local/purgeSeq",_rev:t,purgeSeq:r})}))})).catch((function(e){if(404!==e.status)throw e}))}(e)))}))}function v(e){const t="string"==typeof e?e:e.name;let r=Ki[t];return r||(r=Ki[t]=new Ui),r}async function y(e,r){return Ii(v(e),(function(){return async function(e,r){let n,s,a;function c(e,t){const r={id:s._id,key:vs(e)};null!=t&&(r.value=vs(t)),n.push(r)}const u=t(e.mapFun,c);let l=e.seq||0;function f(){return e.sourceDB.info().then((function(t){a=e.sourceDB.activeTasks.add({name:"view_indexing",total_items:t.update_seq-l})}))}function d(t,r){return function(){return m(e,t,r)}}let h=0;const v={view:e.name,indexed_docs:h};e.sourceDB.emit("indexing",v);const y=new Ui;async function g(){return w(await e.sourceDB.changes({return_docs:!0,conflicts:!0,include_docs:!0,style:"all_docs",since:l,limit:r.changes_batch_size}),await _())}function _(){return e.db.get("_local/purgeSeq").then((function(e){return e.purgeSeq})).catch(p(-1)).then((function(t){return e.sourceDB.get("_local/purges").then((function(r){const n=r.purges.filter((function(e,r){return r>t})).map((e=>e.docId)),o=n.filter((function(e,t){return n.indexOf(e)===t}));return Promise.all(o.map((function(t){return e.sourceDB.get(t).then((function(e){return{docId:t,doc:e}})).catch(p({docId:t}))})))})).catch(p([]))}))}function w(t,n){const o=t.results;if(!o.length&&!n.length)return;for(const e of n){if(o.findIndex((function(t){return t.id===e.docId}))<0){const t={_id:e.docId,doc:{_id:e.docId,_deleted:1},changes:[]};e.doc&&(t.doc=e.doc,t.changes.push({rev:e.doc._rev})),o.push(t)}}const s=b(o);y.add(d(s,l)),h+=o.length;const i={view:e.name,last_seq:t.last_seq,results_count:o.length,indexed_docs:h};return e.sourceDB.emit("indexing",i),e.sourceDB.activeTasks.update(a,{completed_items:h}),o.length<r.changes_batch_size?void 0:g()}function b(t){const r=new Map;for(const a of t){if("_"!==a.doc._id[0]){n=[],s=a.doc,s._deleted||o(e.sourceDB,u,s),n.sort(i);const t=$(n);r.set(a.doc._id,[t,a.changes])}l=a.seq}return r}function $(e){const t=new Map;let r;for(let n=0,o=e.length;n<o;n++){const o=e[n],s=[o.key,o.id];n>0&&0===ms(o.key,r)&&s.push(n),t.set(gs(s),o),r=o.key}return t}try{await f(),await g(),await y.finish(),e.seq=l,e.sourceDB.activeTasks.remove(a)}catch(t){e.sourceDB.activeTasks.remove(a,t)}}(e,r)}))()}function g(e,t){return Ii(v(e),(function(){return async function(e,t){let n;const o=e.reduceFun&&!1!==t.reduce,i=t.skip||0;void 0===t.keys||t.keys.length||(t.limit=0,delete t.keys);async function u(t){t.include_docs=!0;const r=await e.db.allDocs(t);return n=r.total_rows,r.rows.map((function(e){if("value"in e.doc&&"object"==typeof e.doc.value&&null!==e.doc.value){const t=Object.keys(e.doc.value).sort(),r=["id","key","value"];if(!(t<r||t>r))return e.doc.value}const t=function(e){for(var t=[],r=[],n=0;;){var o=e[n++];if("\0"!==o)switch(o){case"1":t.push(null);break;case"2":t.push("1"===e[n]),n++;break;case"3":var s=_s(e,n);t.push(s.num),n+=s.length;break;case"4":for(var i="";;){var a=e[n];if("\0"===a)break;i+=a,n++}i=i.replace(/\u0001\u0001/g,"\0").replace(/\u0001\u0002/g,"").replace(/\u0002\u0002/g,""),t.push(i);break;case"5":var c={element:[],index:t.length};t.push(c.element),r.push(c);break;case"6":var u={element:{},index:t.length};t.push(u.element),r.push(u);break;default:throw new Error("bad collationIndex or unexpectedly reached end of input: "+o)}else{if(1===t.length)return t.pop();ws(t,r)}}}(e.doc._id);return{key:t[0],id:t[1],value:"value"in e.doc?e.doc.value:null}}))}async function l(u){let l;if(l=o?function(e,t,n){0===n.group_level&&delete n.group_level;const o=n.group||n.group_level,i=r(e.reduceFun),c=[],u=isNaN(n.group_level)?Number.POSITIVE_INFINITY:n.group_level;for(const e of t){const t=c[c.length-1];let r=o?e.key:null;o&&Array.isArray(r)&&(r=r.slice(0,u)),t&&0===ms(t.groupKey,r)?(t.keys.push([e.key,e.id]),t.values.push(e.value)):c.push({keys:[[e.key,e.id]],values:[e.value],groupKey:r})}t=[];for(const r of c){const n=s(e.sourceDB,i,r.keys,r.values,!1);if(n.error&&n.error instanceof Ai)throw n.error;t.push({value:n.error?null:n.output,key:r.groupKey})}return{rows:a(t,n.limit,n.skip)}}(e,u,t):void 0===t.keys?{total_rows:n,offset:i,rows:u}:{total_rows:n,offset:i,rows:a(u,t.limit,t.skip)},t.update_seq&&(l.update_seq=e.seq),t.include_docs){const r=Ni(u.map(c)),n=await e.sourceDB.allDocs({keys:r,include_docs:!0,conflicts:t.conflicts,attachments:t.attachments,binary:t.binary}),o=new Map;for(const e of n.rows)o.set(e.id,e.doc);for(const e of u){const t=c(e),r=o.get(t);r&&(e.doc=r)}}return l}if(void 0!==t.keys){const e=t.keys.map((function(e){const r={startkey:gs([e]),endkey:gs([e,{}])};return t.update_seq&&(r.update_seq=!0),u(r)}));return l((await Promise.all(e)).flat())}{const e={descending:t.descending};let r,n;if(t.update_seq&&(e.update_seq=!0),"start_key"in t&&(r=t.start_key),"startkey"in t&&(r=t.startkey),"end_key"in t&&(n=t.end_key),"endkey"in t&&(n=t.endkey),void 0!==r&&(e.startkey=t.descending?gs([r,{}]):gs([r])),void 0!==n){let r=!1!==t.inclusive_end;t.descending&&(r=!r),e.endkey=gs(r?[n,{}]:[n])}if(void 0!==t.key){const r=gs([t.key]),n=gs([t.key,{}]);e.descending?(e.endkey=r,e.startkey=n):(e.startkey=r,e.endkey=n)}o||("number"==typeof t.limit&&(e.limit=t.limit),e.skip=i);return l(await u(e))}}(e,t)}))()}async function _(t,r,o){if("function"==typeof t._query)return function(e,t,r){return new Promise((function(n,o){e._query(t,r,(function(e,t){if(e)return o(e);n(t)}))}))}(t,r,o);if(Xn(t))return async function(e,t,r){let n,o,s=[],i="GET";if(l("reduce",r,s),l("include_docs",r,s),l("attachments",r,s),l("limit",r,s),l("descending",r,s),l("group",r,s),l("group_level",r,s),l("skip",r,s),l("stale",r,s),l("conflicts",r,s),l("startkey",r,s,!0),l("start_key",r,s,!0),l("endkey",r,s,!0),l("end_key",r,s,!0),l("inclusive_end",r,s),l("key",r,s,!0),l("update_seq",r,s),s=s.join("&"),s=""===s?"":"?"+s,void 0!==r.keys){const e=2e3,o=`keys=${encodeURIComponent(JSON.stringify(r.keys))}`;o.length+s.length+1<=e?s+=("?"===s[0]?"&":"?")+o:(i="POST","string"==typeof t?n={keys:r.keys}:t.keys=r.keys)}if("string"==typeof t){const a=Ji(t),c=await e.fetch("_design/"+a[0]+"/_view/"+a[1]+s,{headers:new rs({"Content-Type":"application/json"}),method:i,body:JSON.stringify(n)});o=c.ok;const l=await c.json();if(!o)throw l.status=c.status,Wn(l);for(const e of l.rows)if(e.value&&e.value.error&&"builtin_reduce_error"===e.value.error)throw new Error(e.reason);return new Promise((function(e){e(l)})).then(u(r))}n=n||{};for(const e of Object.keys(t))Array.isArray(t[e])?n[e]=t[e]:n[e]=t[e].toString();const a=await e.fetch("_temp_view"+s,{headers:new rs({"Content-Type":"application/json"}),method:"POST",body:JSON.stringify(n)});o=a.ok;const c=await a.json();if(!o)throw c.status=a.status,Wn(c);return new Promise((function(e){e(c)})).then(u(r))}(t,r,o);const s={changes_batch_size:t.__opts.view_update_changes_batch_size||50};if("string"!=typeof r)return h(o,r),Fi.add((async function(){const n=await zi(t,"temp_view/temp_view",r.map,r.reduce,!0,e);return i=y(n,s).then((function(){return g(n,o)})),a=function(){return n.db.destroy()},i.then((function(e){return a().then((function(){return e}))}),(function(e){return a().then((function(){throw e}))}));var i,a})),Fi.finish();{const i=r,a=Ji(i),c=a[0],u=a[1],l=await t.get("_design/"+c);if(!(r=l.views&&l.views[u]))throw new xi(`ddoc ${l._id} has no view named ${u}`);n(l,u),h(o,r);const f=await zi(t,i,r.map,r.reduce,!1,e);return"ok"===o.stale||"update_after"===o.stale?("update_after"===o.stale&&On((function(){y(f,s)})),g(f,o)):(await y(f,s),g(f,o))}}const w=(b=function(){const t=this;return"function"==typeof t._viewCleanup?function(e){return new Promise((function(t,r){e._viewCleanup((function(e,n){if(e)return r(e);t(n)}))}))}(t):Xn(t)?async function(e){return(await e.fetch("_view_cleanup",{headers:new rs({"Content-Type":"application/json"}),method:"POST"})).json()}(t):async function(t){try{const r=await t.get("_local/"+e),n=new Map;for(const e of Object.keys(r.views)){const t=Ji(e),r="_design/"+t[0],o=t[1];let s=n.get(r);s||(s=new Set,n.set(r,s)),s.add(o)}const o={keys:Ti(n),include_docs:!0},s=await t.allDocs(o),i={};for(const e of s.rows){const t=e.key.substring(8);for(const o of n.get(e.key)){let n=t+"/"+o;r.views[n]||(n=o);const s=Object.keys(r.views[n]),a=e.doc&&e.doc.views&&e.doc.views[o];for(const e of s)i[e]=i[e]||a}}const a=Object.keys(i).filter((function(e){return!i[e]})).map((function(e){return Ii(v(e),(function(){return new t.constructor(e,t.__opts).destroy()}))()}));return Promise.all(a).then((function(){return{ok:!0}}))}catch(e){if(404===e.status)return{ok:!0};throw e}}(t)},function(...e){var t=e.pop(),r=b.apply(this,e);return"function"==typeof t&&Ci(r,t),r});var b;return{query:function(e,t,r){const n=this;"function"==typeof t&&(r=t,t={}),t=t?function(e){return e.group_level=f(e.group_level),e.limit=f(e.limit),e.skip=f(e.skip),e}(t):{},"function"==typeof e&&(e={map:e});const o=Promise.resolve().then((function(){return _(n,e,t)}));return Ci(o,r),o},viewCleanup:w}}("mrviews",(function(e,t){if("function"==typeof e&&2===e.length){var r=e;return function(e){return r(e,t)}}return Vi(e.toString(),t)}),(function(e){var t=e.toString(),r=function(e){if(/^_sum/.test(e))return Hi;if(/^_count/.test(e))return Wi;if(/^_stats/.test(e))return Qi;if(/^_/.test(e))throw new Error(e+" is not a supported reduce function.")}(t);return r||Vi(t)}),(function(e,t){var r=e.views&&e.views[t];if("string"!=typeof r.map)throw new xi("ddoc "+e._id+" has no string view named "+t+", instead found object of type: "+typeof r.map)}));var Xi={query:function(e,t,r){return Yi.query.call(this,e,t,r)},viewCleanup:function(e){return Yi.viewCleanup.call(this,e)}};function Zi(e,t){var r=Object.keys(t._attachments);return Promise.all(r.map((function(r){return e.getAttachment(t._id,r,{rev:t._rev})})))}function ea(e,t,r,n){r=gn(r);var o=[],s=!0;return Promise.resolve().then((function(){var i=function(e){var t=[];return Object.keys(e).forEach((function(r){e[r].missing.forEach((function(e){t.push({id:r,rev:e})}))})),{docs:t,revs:!0,latest:!0}}(r);if(i.docs.length)return e.bulkGet(i).then((function(r){if(n.cancelled)throw new Error("cancelled");return Promise.all(r.results.map((function(r){return Promise.all(r.docs.map((function(r){var n=r.ok;return r.error&&(s=!1),n&&n._attachments?function(e,t,r){var n=Xn(t)&&!Xn(e),o=Object.keys(r._attachments);return n?e.get(r._id).then((function(n){return Promise.all(o.map((function(o){return function(e,t,r){return!e._attachments||!e._attachments[r]||e._attachments[r].digest!==t._attachments[r].digest}(n,r,o)?t.getAttachment(r._id,o):e.getAttachment(n._id,o)})))})).catch((function(e){if(404!==e.status)throw e;return Zi(t,r)})):Zi(t,r)}(t,e,n).then((e=>{var t=Object.keys(n._attachments);return e.forEach((function(e,r){var o=n._attachments[t[r]];delete o.stub,delete o.length,o.data=e})),n})):n})))}))).then((function(e){o=o.concat(e.flat().filter(Boolean))}))}))})).then((function(){return{ok:s,docs:o}}))}var ta="pouchdb";function ra(e,t,r,n,o){return e.get(t).catch((function(r){if(404===r.status)return"http"!==e.adapter&&"https"!==e.adapter||Cn(404,"PouchDB is just checking if a remote checkpoint exists."),{session_id:n,_id:t,history:[],replicator:ta,version:1};throw r})).then((function(s){if(!o.cancelled&&s.last_seq!==r)return s.history=(s.history||[]).filter((function(e){return e.session_id!==n})),s.history.unshift({last_seq:r,session_id:n}),s.history=s.history.slice(0,5),s.version=1,s.replicator=ta,s.session_id=n,s.last_seq=r,e.put(s).catch((function(s){if(409===s.status)return ra(e,t,r,n,o);throw s}))}))}class na{constructor(e,t,r,n,o={writeSourceCheckpoint:!0,writeTargetCheckpoint:!0}){this.src=e,this.target=t,this.id=r,this.returnValue=n,this.opts=o,void 0===o.writeSourceCheckpoint&&(o.writeSourceCheckpoint=!0),void 0===o.writeTargetCheckpoint&&(o.writeTargetCheckpoint=!0)}writeCheckpoint(e,t){var r=this;return this.updateTarget(e,t).then((function(){return r.updateSource(e,t)}))}updateTarget(e,t){return this.opts.writeTargetCheckpoint?ra(this.target,this.id,e,t,this.returnValue):Promise.resolve(!0)}updateSource(e,t){if(this.opts.writeSourceCheckpoint){var r=this;return ra(this.src,this.id,e,t,this.returnValue).catch((function(e){if(aa(e))return r.opts.writeSourceCheckpoint=!1,!0;throw e}))}return Promise.resolve(!0)}getCheckpoint(){var e=this;return e.opts.writeSourceCheckpoint||e.opts.writeTargetCheckpoint?e.opts&&e.opts.writeSourceCheckpoint&&!e.opts.writeTargetCheckpoint?e.src.get(e.id).then((function(e){return e.last_seq||0})).catch((function(e){if(404!==e.status)throw e;return 0})):e.target.get(e.id).then((function(t){return e.opts&&e.opts.writeTargetCheckpoint&&!e.opts.writeSourceCheckpoint?t.last_seq||0:e.src.get(e.id).then((function(e){return t.version!==e.version?0:(r=t.version?t.version.toString():"undefined")in oa?oa[r](t,e):0;var r}),(function(r){if(404===r.status&&t.last_seq)return e.src.put({_id:e.id,last_seq:0}).then((function(){return 0}),(function(r){return aa(r)?(e.opts.writeSourceCheckpoint=!1,t.last_seq):0}));throw r}))})).catch((function(e){if(404!==e.status)throw e;return 0})):Promise.resolve(0)}}var oa={undefined:function(e,t){return 0===ms(e.last_seq,t.last_seq)?t.last_seq:0},1:function(e,t){return function(e,t){if(e.session_id===t.session_id)return{last_seq:e.last_seq,history:e.history};return sa(e.history,t.history)}(t,e).last_seq}};function sa(e,t){var r=e[0],n=e.slice(1),o=t[0],s=t.slice(1);return r&&0!==t.length?ia(r.session_id,t)?{last_seq:r.last_seq,history:e}:ia(o.session_id,n)?{last_seq:o.last_seq,history:s}:sa(n,s):{last_seq:0,history:[]}}function ia(e,t){var r=t[0],n=t.slice(1);return!(!e||0===t.length)&&(e===r.session_id||ia(e,n))}function aa(e){return"number"==typeof e.status&&4===Math.floor(e.status/100)}function ca(e,t,r,n,o){return this instanceof na?ca:new na(e,t,r,n,o)}function ua(e,t,r){var n=r.doc_ids?r.doc_ids.sort(ms):"",o=r.filter?r.filter.toString():"",s="",i="",a="";return r.selector&&(a=JSON.stringify(r.selector)),r.filter&&r.query_params&&(s=JSON.stringify(function(e){return Object.keys(e).sort(ms).reduce((function(t,r){return t[r]=e[r],t}),{})}(r.query_params))),r.filter&&"_view"===r.filter&&(i=r.view.toString()),Promise.all([e.id(),t.id()]).then((function(e){var t=e[0]+e[1]+o+i+s+n+a;return new Promise((function(e){bo(t,e)}))})).then((function(e){return"_local/"+(e=e.replace(/\//g,".").replace(/\+/g,"_"))}))}function la(e,t,r,n,o){var s,i,a,c,u=[],l={seq:0,changes:[],docs:[]},f=!1,d=!1,h=!1,p=0,m=0,v=r.continuous||r.live||!1,y=r.batch_size||100,g=r.batches_limit||10,_=r.style||"all_docs",w=!1,b=r.doc_ids,$=r.selector,k=[],E=Eo();o=o||{ok:!0,start_time:(new Date).toISOString(),docs_read:0,docs_written:0,doc_write_failures:0,errors:[]};var P={};function S(){return a?Promise.resolve():ua(e,t,r).then((function(o){i=o;var s={};s=!1===r.checkpoint?{writeSourceCheckpoint:!1,writeTargetCheckpoint:!1}:"source"===r.checkpoint?{writeSourceCheckpoint:!0,writeTargetCheckpoint:!1}:"target"===r.checkpoint?{writeSourceCheckpoint:!1,writeTargetCheckpoint:!0}:{writeSourceCheckpoint:!0,writeTargetCheckpoint:!0},a=new ca(e,t,i,n,s)}))}function j(){if(k=[],0!==s.docs.length){var e=s.docs,i={timeout:r.timeout};return t.bulkDocs({docs:e,new_edits:!1},i).then((function(t){if(n.cancelled)throw N(),new Error("cancelled");var r=Object.create(null);t.forEach((function(e){e.error&&(r[e.id]=e)}));var s=Object.keys(r).length;o.doc_write_failures+=s,o.docs_written+=e.length-s,e.forEach((function(e){var t=r[e._id];if(t){o.errors.push(t);var s=(t.name||"").toLowerCase();if("unauthorized"!==s&&"forbidden"!==s)throw t;n.emit("denied",gn(t))}else k.push(e)}))}),(function(t){throw o.doc_write_failures+=e.length,t}))}}function O(){if(s.error)throw new Error("There was a problem getting docs.");o.last_seq=m=s.seq;var t=gn(o);return k.length&&(t.docs=k,"number"==typeof s.pending&&(t.pending=s.pending,delete s.pending),n.emit("change",t)),f=!0,e.info().then((function(t){var r=e.activeTasks.get(c);if(s&&r){var n=r.completed_items||0,o=parseInt(t.update_seq,10)-parseInt(p,10);e.activeTasks.update(c,{completed_items:n+s.changes.length,total_items:o})}})),a.writeCheckpoint(s.seq,E).then((function(){if(n.emit("checkpoint",{checkpoint:s.seq}),f=!1,n.cancelled)throw N(),new Error("cancelled");s=void 0,D()})).catch((function(e){throw V(e),e}))}function x(){return ea(e,t,s.diffs,n).then((function(e){s.error=!e.ok,e.docs.forEach((function(e){delete s.diffs[e._id],o.docs_read++,s.docs.push(e)}))}))}function A(){var e;n.cancelled||s||(0!==u.length?(s=u.shift(),n.emit("checkpoint",{start_next_batch:s.seq}),(e={},s.changes.forEach((function(t){n.emit("checkpoint",{revs_diff:t}),"_user/"!==t.id&&(e[t.id]=t.changes.map((function(e){return e.rev})))})),t.revsDiff(e).then((function(e){if(n.cancelled)throw N(),new Error("cancelled");s.diffs=e}))).then(x).then(j).then(O).then(A).catch((function(e){I("batch processing terminated with error",e)}))):C(!0))}function C(e){0!==l.changes.length?(e||d||l.changes.length>=y)&&(u.push(l),l={seq:0,changes:[],docs:[]},"pending"!==n.state&&"stopped"!==n.state||(n.state="active",n.emit("active")),A()):0!==u.length||s||((v&&P.live||d)&&(n.state="pending",n.emit("paused")),d&&N())}function I(e,t){h||(t.message||(t.message=e),o.ok=!1,o.status="aborting",u=[],l={seq:0,changes:[],docs:[]},N(t))}function N(s){if(!(h||n.cancelled&&(o.status="cancelled",f)))if(o.status=o.status||"complete",o.end_time=(new Date).toISOString(),o.last_seq=m,h=!0,e.activeTasks.remove(c,s),s){(s=Hn(s)).result=o;var i=(s.name||"").toLowerCase();"unauthorized"===i||"forbidden"===i?(n.emit("error",s),n.removeAllListeners()):function(e,t,r,n){if(!1===e.retry)return t.emit("error",r),void t.removeAllListeners();if("function"!=typeof e.back_off_function&&(e.back_off_function=An),t.emit("requestError",r),"active"===t.state||"pending"===t.state){t.emit("paused",r),t.state="stopped";var o=function(){e.current_back_off=0};t.once("paused",(function(){t.removeListener("active",o)})),t.once("active",o)}e.current_back_off=e.current_back_off||0,e.current_back_off=e.back_off_function(e.current_back_off),setTimeout(n,e.current_back_off)}(r,n,s,(function(){la(e,t,r,n)}))}else n.emit("complete",o),n.removeAllListeners()}function T(t,o,s){if(n.cancelled)return N();if("number"==typeof o&&(l.pending=o),Qn(r)(t))l.seq=t.seq||s,l.changes.push(t),n.emit("checkpoint",{pending_batch:l.seq}),On((function(){C(0===u.length&&P.live)}));else{var i=e.activeTasks.get(c);if(i){var a=i.completed_items||0;e.activeTasks.update(c,{completed_items:++a})}}}function R(e){if(w=!1,n.cancelled)return N();if(e.results.length>0)P.since=e.results[e.results.length-1].seq,D(),C(!0);else{var t=function(){v?(P.live=!0,D()):d=!0,C(!0)};s||0!==e.results.length?t():(f=!0,a.writeCheckpoint(e.last_seq,E).then((function(){if(f=!1,o.last_seq=m=e.last_seq,n.cancelled)throw N(),new Error("cancelled");t()})).catch(V))}}function q(e){if(w=!1,n.cancelled)return N();I("changes rejected",e)}function D(){if(!w&&!d&&u.length<g){w=!0,n._changes&&(n.removeListener("cancel",n._abortChanges),n._changes.cancel()),n.once("cancel",o);var t=e.changes(P).on("change",T);t.then(s,s),t.then(R).catch(q),r.retry&&(n._changes=t,n._abortChanges=o)}function o(){t.cancel()}function s(){n.removeListener("cancel",o)}}function L(t){return e.info().then((function(n){var o=void 0===r.since?parseInt(n.update_seq,10)-parseInt(t,10):parseInt(n.update_seq,10);return c=e.activeTasks.add({name:`${v?"continuous ":""}replication from ${n.db_name}`,total_items:o}),t}))}function M(){S().then((function(){if(!n.cancelled)return a.getCheckpoint().then(L).then((function(e){p=e,P={since:m=e,limit:y,batch_size:y,style:_,doc_ids:b,selector:$,return_docs:!0},r.filter&&("string"!=typeof r.filter?P.include_docs=!0:P.filter=r.filter),"heartbeat"in r&&(P.heartbeat=r.heartbeat),"timeout"in r&&(P.timeout=r.timeout),r.query_params&&(P.query_params=r.query_params),r.view&&(P.view=r.view),D()}));N()})).catch((function(e){I("getCheckpoint rejected with ",e)}))}function V(e){f=!1,I("writeCheckpoint completed with error",e)}n.ready(e,t),n.cancelled?N():(n._addedListeners||(n.once("cancel",N),"function"==typeof r.complete&&(n.once("error",r.complete),n.once("complete",(function(e){r.complete(null,e)}))),n._addedListeners=!0),void 0===r.since?M():S().then((function(){return f=!0,a.writeCheckpoint(r.since,E)})).then((function(){f=!1,n.cancelled?N():(m=r.since,M())})).catch(V))}class fa extends ln{constructor(){super(),this.cancelled=!1,this.state="pending";const e=new Promise(((e,t)=>{this.once("complete",e),this.once("error",t)}));this.then=function(t,r){return e.then(t,r)},this.catch=function(t){return e.catch(t)},this.catch((function(){}))}cancel(){this.cancelled=!0,this.state="cancelled",this.emit("cancel")}ready(e,t){if(this._readyCalled)return;this._readyCalled=!0;const r=()=>{this.cancel()};function n(){e.removeListener("destroyed",r),t.removeListener("destroyed",r)}e.once("destroyed",r),t.once("destroyed",r),this.once("complete",n),this.once("error",n)}}function da(e,t){var r=t.PouchConstructor;return"string"==typeof e?new r(e,t):e}function ha(e,t,r,n){if("function"==typeof r&&(n=r,r={}),void 0===r&&(r={}),r.doc_ids&&!Array.isArray(r.doc_ids))throw Hn(zn,"`doc_ids` filter parameter is not a list.");r.complete=n,(r=gn(r)).continuous=r.continuous||r.live,r.retry="retry"in r&&r.retry,r.PouchConstructor=r.PouchConstructor||this;var o=new fa(r);return la(da(e,r),da(t,r),r,o),o}function pa(e,t,r,n){return"function"==typeof r&&(n=r,r={}),void 0===r&&(r={}),(r=gn(r)).PouchConstructor=r.PouchConstructor||this,e=da(e,r),t=da(t,r),new ma(e,t,r,n)}class ma extends ln{constructor(e,t,r,n){super(),this.canceled=!1;const o=r.push?Object.assign({},r,r.push):r,s=r.pull?Object.assign({},r,r.pull):r;this.push=ha(e,t,o),this.pull=ha(t,e,s),this.pushPaused=!0,this.pullPaused=!0;const i=e=>{this.emit("change",{direction:"pull",change:e})},a=e=>{this.emit("change",{direction:"push",change:e})},c=e=>{this.emit("denied",{direction:"push",doc:e})},u=e=>{this.emit("denied",{direction:"pull",doc:e})},l=()=>{this.pushPaused=!0,this.pullPaused&&this.emit("paused")},f=()=>{this.pullPaused=!0,this.pushPaused&&this.emit("paused")},d=()=>{this.pushPaused=!1,this.pullPaused&&this.emit("active",{direction:"push"})},h=()=>{this.pullPaused=!1,this.pushPaused&&this.emit("active",{direction:"pull"})};let p={};const m=e=>(t,r)=>{("change"===t&&(r===i||r===a)||"denied"===t&&(r===u||r===c)||"paused"===t&&(r===f||r===l)||"active"===t&&(r===h||r===d))&&(t in p||(p[t]={}),p[t][e]=!0,2===Object.keys(p[t]).length&&this.removeAllListeners(t))};function v(e,t,r){-1==e.listeners(t).indexOf(r)&&e.on(t,r)}r.live&&(this.push.on("complete",this.pull.cancel.bind(this.pull)),this.pull.on("complete",this.push.cancel.bind(this.push))),this.on("newListener",(function(e){"change"===e?(v(this.pull,"change",i),v(this.push,"change",a)):"denied"===e?(v(this.pull,"denied",u),v(this.push,"denied",c)):"active"===e?(v(this.pull,"active",h),v(this.push,"active",d)):"paused"===e&&(v(this.pull,"paused",f),v(this.push,"paused",l))})),this.on("removeListener",(function(e){"change"===e?(this.pull.removeListener("change",i),this.push.removeListener("change",a)):"denied"===e?(this.pull.removeListener("denied",u),this.push.removeListener("denied",c)):"active"===e?(this.pull.removeListener("active",h),this.push.removeListener("active",d)):"paused"===e&&(this.pull.removeListener("paused",f),this.push.removeListener("paused",l))})),this.pull.on("removeListener",m("pull")),this.push.on("removeListener",m("push"));const y=Promise.all([this.push,this.pull]).then((e=>{const t={push:e[0],pull:e[1]};return this.emit("complete",t),n&&n(null,t),this.removeAllListeners(),t}),(e=>{if(this.cancel(),n?n(e):this.emit("error",e),this.removeAllListeners(),n)throw e}));this.then=function(e,t){return y.then(e,t)},this.catch=function(e){return y.catch(e)}}cancel(){this.canceled||(this.canceled=!0,this.push.cancel(),this.pull.cancel())}}es.plugin((function(e){e.adapter("idb",yi,!0)})).plugin((function(e){e.adapter("http",ji,!1),e.adapter("https",ji,!1)})).plugin(Xi).plugin((function(e){e.replicate=ha,e.sync=pa,Object.defineProperty(e.prototype,"replicate",{get:function(){var e=this;return void 0===this.replicateMethods&&(this.replicateMethods={from:function(t,r,n){return e.constructor.replicate(t,e,r,n)},to:function(t,r,n){return e.constructor.replicate(e,t,r,n)}}),this.replicateMethods}}),e.prototype.sync=function(e,t,r){return this.constructor.sync(this,e,t,r)}}));const va=e=>`${e.source}/${encodeURIComponent(e.actor)}/${encodeURIComponent(e.name)}`,ya=e=>{const t=e.split("/"),r=t.pop(),n=t.pop();if(!r||!n||!t.length)throw new a;return{name:decodeURIComponent(r),actor:decodeURIComponent(n),source:t.join("/")}};function ga(e=16){const t=new Uint8Array(e);crypto.getRandomValues(t);return btoa(String.fromCodePoint(...t)).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=+$/,"")}function _a(e){return"string"==typeof e?{location:ya(e),uri:e}:{location:{name:e.name,actor:e.actor,source:e.source},uri:va(e)}}function wa(e,t,r,n){const o=r[t];if(o&&o.length)try{n[t]=e(n[t],o,!0,!1).newDocument}catch(e){throw"object"==typeof e&&e&&"name"in e&&"string"==typeof e.name&&"message"in e&&"string"==typeof e.message?"TEST_OPERATION_FAILED"===e.name?new s(e.message):new i(e.name+": "+e.message):e}}function ba(e,t){try{return e.compile(t)}catch(e){throw new n(e instanceof Error?e.message:void 0)}}function $a(e,t,r){e.actor!==r?.actor&&(e.allowed=e.allowed&&r?[r.actor]:void 0,e.channels=e.channels.filter((e=>t.includes(e))))}function ka(e,t){return void 0===e.allowed||!!t?.actor&&(e.actor===t.actor||e.allowed.includes(t.actor))}
|
|
7
|
+
deps: ${n}}`};const o={keyword:"dependencies",type:"object",schemaType:"object",error:e.error,code(e){const[t,r]=function({schema:e}){const t={},r={};for(const n in e){if("__proto__"===n)continue;(Array.isArray(e[n])?t:r)[n]=e[n]}return[t,r]}(e);s(e,t),i(e,r)}};function s(e,r=e.schema){const{gen:o,data:s,it:i}=e;if(0===Object.keys(r).length)return;const a=o.let("missing");for(const c in r){const u=r[c];if(0===u.length)continue;const l=(0,n.propertyInData)(o,s,c,i.opts.ownProperties);e.setParams({property:c,depsCount:u.length,deps:u.join(", ")}),i.allErrors?o.if(l,(()=>{for(const t of u)(0,n.checkReportMissingProp)(e,t)})):(o.if(t._`${l} && (${(0,n.checkMissingProp)(e,u,a)})`),(0,n.reportMissingProp)(e,a),o.else())}}function i(e,t=e.schema){const{gen:o,data:s,keyword:i,it:a}=e,c=o.name("valid");for(const u in t)(0,r.alwaysValidSchema)(a,t[u])||(o.if((0,n.propertyInData)(o,s,u,a.opts.ownProperties),(()=>{const t=e.subschema({keyword:i,schemaProp:u},c);e.mergeValidEvaluated(t,c)}),(()=>o.var(c,!0))),e.ok(c))}e.validatePropertyDeps=s,e.validateSchemaDeps=i,e.default=o}(Nt)),Nt}var Rt,qt={};var Dt,Lt={};function Mt(){if(Dt)return Lt;Dt=1,Object.defineProperty(Lt,"__esModule",{value:!0});const e=G(),t=$(),r=A(),n=P(),o={keyword:"additionalProperties",type:["object"],schemaType:["boolean","object"],allowUndefined:!0,trackErrors:!0,error:{message:"must NOT have additional properties",params:({params:e})=>t._`{additionalProperty: ${e.additionalProperty}}`},code(o){const{gen:s,schema:i,parentSchema:a,data:c,errsCount:u,it:l}=o;if(!u)throw new Error("ajv implementation error");const{allErrors:f,opts:d}=l;if(l.props=!0,"all"!==d.removeAdditional&&(0,n.alwaysValidSchema)(l,i))return;const h=(0,e.allSchemaProperties)(a.properties),p=(0,e.allSchemaProperties)(a.patternProperties);function m(e){s.code(t._`delete ${c}[${e}]`)}function v(e){if("all"===d.removeAdditional||d.removeAdditional&&!1===i)m(e);else{if(!1===i)return o.setParams({additionalProperty:e}),o.error(),void(f||s.break());if("object"==typeof i&&!(0,n.alwaysValidSchema)(l,i)){const r=s.name("valid");"failing"===d.removeAdditional?(y(e,r,!1),s.if((0,t.not)(r),(()=>{o.reset(),m(e)}))):(y(e,r),f||s.if((0,t.not)(r),(()=>s.break())))}}}function y(e,t,r){const s={keyword:"additionalProperties",dataProp:e,dataPropType:n.Type.Str};!1===r&&Object.assign(s,{compositeRule:!0,createErrors:!1,allErrors:!1}),o.subschema(s,t)}s.forIn("key",c,(r=>{h.length||p.length?s.if(function(r){let i;if(h.length>8){const t=(0,n.schemaRefOrVal)(l,a.properties,"properties");i=(0,e.isOwnProperty)(s,t,r)}else i=h.length?(0,t.or)(...h.map((e=>t._`${r} === ${e}`))):t.nil;return p.length&&(i=(0,t.or)(i,...p.map((n=>t._`${(0,e.usePattern)(o,n)}.test(${r})`)))),(0,t.not)(i)}(r),(()=>v(r))):v(r)})),o.ok(t._`${u} === ${r.default.errors}`)}};return Lt.default=o,Lt}var Vt,Ut={};var Bt,zt={};var Kt,Ft={};var Jt,Gt={};var Ht,Wt={};var Qt,Yt={};var Xt,Zt={};var er,tr,rr={};function nr(){if(tr)return _t;tr=1,Object.defineProperty(_t,"__esModule",{value:!0});const e=bt(),t=function(){if(kt)return Et;kt=1,Object.defineProperty(Et,"__esModule",{value:!0});const e=St(),t={keyword:"prefixItems",type:"array",schemaType:["array"],before:"uniqueItems",code:t=>(0,e.validateTuple)(t,"items")};return Et.default=t,Et}(),r=St(),n=function(){if(jt)return Ot;jt=1,Object.defineProperty(Ot,"__esModule",{value:!0});const e=$(),t=P(),r=G(),n=bt(),o={keyword:"items",type:"array",schemaType:["object","boolean"],before:"uniqueItems",error:{message:({params:{len:t}})=>e.str`must NOT have more than ${t} items`,params:({params:{len:t}})=>e._`{limit: ${t}}`},code(e){const{schema:o,parentSchema:s,it:i}=e,{prefixItems:a}=s;i.items=!0,(0,t.alwaysValidSchema)(i,o)||(a?(0,n.validateAdditionalItems)(e,a):e.ok((0,r.validateArray)(e)))}};return Ot.default=o,Ot}(),o=Ct(),s=Tt(),i=function(){if(Rt)return qt;Rt=1,Object.defineProperty(qt,"__esModule",{value:!0});const e=$(),t=P(),r={keyword:"propertyNames",type:"object",schemaType:["object","boolean"],error:{message:"property name must be valid",params:({params:t})=>e._`{propertyName: ${t.propertyName}}`},code(r){const{gen:n,schema:o,data:s,it:i}=r;if((0,t.alwaysValidSchema)(i,o))return;const a=n.name("valid");n.forIn("key",s,(t=>{r.setParams({propertyName:t}),r.subschema({keyword:"propertyNames",data:t,dataTypes:["string"],propertyName:t,compositeRule:!0},a),n.if((0,e.not)(a),(()=>{r.error(!0),i.allErrors||n.break()}))})),r.ok(a)}};return qt.default=r,qt}(),a=Mt(),c=function(){if(Vt)return Ut;Vt=1,Object.defineProperty(Ut,"__esModule",{value:!0});const e=ae(),t=G(),r=P(),n=Mt(),o={keyword:"properties",type:"object",schemaType:"object",code(o){const{gen:s,schema:i,parentSchema:a,data:c,it:u}=o;"all"===u.opts.removeAdditional&&void 0===a.additionalProperties&&n.default.code(new e.KeywordCxt(u,n.default,"additionalProperties"));const l=(0,t.allSchemaProperties)(i);for(const e of l)u.definedProperties.add(e);u.opts.unevaluated&&l.length&&!0!==u.props&&(u.props=r.mergeEvaluated.props(s,(0,r.toHash)(l),u.props));const f=l.filter((e=>!(0,r.alwaysValidSchema)(u,i[e])));if(0===f.length)return;const d=s.name("valid");for(const e of f)h(e)?p(e):(s.if((0,t.propertyInData)(s,c,e,u.opts.ownProperties)),p(e),u.allErrors||s.else().var(d,!0),s.endIf()),o.it.definedProperties.add(e),o.ok(d);function h(e){return u.opts.useDefaults&&!u.compositeRule&&void 0!==i[e].default}function p(e){o.subschema({keyword:"properties",schemaProp:e,dataProp:e},d)}}};return Ut.default=o,Ut}(),u=function(){if(Bt)return zt;Bt=1,Object.defineProperty(zt,"__esModule",{value:!0});const e=G(),t=$(),r=P(),n=P(),o={keyword:"patternProperties",type:"object",schemaType:"object",code(o){const{gen:s,schema:i,data:a,parentSchema:c,it:u}=o,{opts:l}=u,f=(0,e.allSchemaProperties)(i),d=f.filter((e=>(0,r.alwaysValidSchema)(u,i[e])));if(0===f.length||d.length===f.length&&(!u.opts.unevaluated||!0===u.props))return;const h=l.strictSchema&&!l.allowMatchingProperties&&c.properties,p=s.name("valid");!0===u.props||u.props instanceof t.Name||(u.props=(0,n.evaluatedPropsToName)(s,u.props));const{props:m}=u;function v(e){for(const t in h)new RegExp(e).test(t)&&(0,r.checkStrictMode)(u,`property ${t} matches pattern ${e} (use allowMatchingProperties)`)}function y(r){s.forIn("key",a,(i=>{s.if(t._`${(0,e.usePattern)(o,r)}.test(${i})`,(()=>{const e=d.includes(r);e||o.subschema({keyword:"patternProperties",schemaProp:r,dataProp:i,dataPropType:n.Type.Str},p),u.opts.unevaluated&&!0!==m?s.assign(t._`${m}[${i}]`,!0):e||u.allErrors||s.if((0,t.not)(p),(()=>s.break()))}))}))}!function(){for(const e of f)h&&v(e),u.allErrors?y(e):(s.var(p,!0),y(e),s.if(p))}()}};return zt.default=o,zt}(),l=function(){if(Kt)return Ft;Kt=1,Object.defineProperty(Ft,"__esModule",{value:!0});const e=P(),t={keyword:"not",schemaType:["object","boolean"],trackErrors:!0,code(t){const{gen:r,schema:n,it:o}=t;if((0,e.alwaysValidSchema)(o,n))return void t.fail();const s=r.name("valid");t.subschema({keyword:"not",compositeRule:!0,createErrors:!1,allErrors:!1},s),t.failResult(s,(()=>t.reset()),(()=>t.error()))},error:{message:"must NOT be valid"}};return Ft.default=t,Ft}(),f=function(){if(Jt)return Gt;Jt=1,Object.defineProperty(Gt,"__esModule",{value:!0});const e={keyword:"anyOf",schemaType:"array",trackErrors:!0,code:G().validateUnion,error:{message:"must match a schema in anyOf"}};return Gt.default=e,Gt}(),d=function(){if(Ht)return Wt;Ht=1,Object.defineProperty(Wt,"__esModule",{value:!0});const e=$(),t=P(),r={keyword:"oneOf",schemaType:"array",trackErrors:!0,error:{message:"must match exactly one schema in oneOf",params:({params:t})=>e._`{passingSchemas: ${t.passing}}`},code(r){const{gen:n,schema:o,parentSchema:s,it:i}=r;if(!Array.isArray(o))throw new Error("ajv implementation error");if(i.opts.discriminator&&s.discriminator)return;const a=o,c=n.let("valid",!1),u=n.let("passing",null),l=n.name("_valid");r.setParams({passing:u}),n.block((function(){a.forEach(((o,s)=>{let a;(0,t.alwaysValidSchema)(i,o)?n.var(l,!0):a=r.subschema({keyword:"oneOf",schemaProp:s,compositeRule:!0},l),s>0&&n.if(e._`${l} && ${c}`).assign(c,!1).assign(u,e._`[${u}, ${s}]`).else(),n.if(l,(()=>{n.assign(c,!0),n.assign(u,s),a&&r.mergeEvaluated(a,e.Name)}))}))})),r.result(c,(()=>r.reset()),(()=>r.error(!0)))}};return Wt.default=r,Wt}(),h=function(){if(Qt)return Yt;Qt=1,Object.defineProperty(Yt,"__esModule",{value:!0});const e=P(),t={keyword:"allOf",schemaType:"array",code(t){const{gen:r,schema:n,it:o}=t;if(!Array.isArray(n))throw new Error("ajv implementation error");const s=r.name("valid");n.forEach(((r,n)=>{if((0,e.alwaysValidSchema)(o,r))return;const i=t.subschema({keyword:"allOf",schemaProp:n},s);t.ok(s),t.mergeEvaluated(i)}))}};return Yt.default=t,Yt}(),p=function(){if(Xt)return Zt;Xt=1,Object.defineProperty(Zt,"__esModule",{value:!0});const e=$(),t=P(),r={keyword:"if",schemaType:["object","boolean"],trackErrors:!0,error:{message:({params:t})=>e.str`must match "${t.ifClause}" schema`,params:({params:t})=>e._`{failingKeyword: ${t.ifClause}}`},code(r){const{gen:o,parentSchema:s,it:i}=r;void 0===s.then&&void 0===s.else&&(0,t.checkStrictMode)(i,'"if" without "then" and "else" is ignored');const a=n(i,"then"),c=n(i,"else");if(!a&&!c)return;const u=o.let("valid",!0),l=o.name("_valid");if(function(){const e=r.subschema({keyword:"if",compositeRule:!0,createErrors:!1,allErrors:!1},l);r.mergeEvaluated(e)}(),r.reset(),a&&c){const e=o.let("ifClause");r.setParams({ifClause:e}),o.if(l,f("then",e),f("else",e))}else a?o.if(l,f("then")):o.if((0,e.not)(l),f("else"));function f(t,n){return()=>{const s=r.subschema({keyword:t},l);o.assign(u,l),r.mergeValidEvaluated(s,u),n?o.assign(n,e._`${t}`):r.setParams({ifClause:t})}}r.pass(u,(()=>r.error(!0)))}};function n(e,r){const n=e.schema[r];return void 0!==n&&!(0,t.alwaysValidSchema)(e,n)}return Zt.default=r,Zt}(),m=function(){if(er)return rr;er=1,Object.defineProperty(rr,"__esModule",{value:!0});const e=P(),t={keyword:["then","else"],schemaType:["object","boolean"],code({keyword:t,parentSchema:r,it:n}){void 0===r.if&&(0,e.checkStrictMode)(n,`"${t}" without "if" is ignored`)}};return rr.default=t,rr}();return _t.default=function(v=!1){const y=[l.default,f.default,d.default,h.default,p.default,m.default,i.default,a.default,s.default,c.default,u.default];return v?y.push(t.default,n.default):y.push(e.default,r.default),y.push(o.default),y},_t}var or,sr,ir,ar={},cr={};function ur(){if(or)return cr;or=1,Object.defineProperty(cr,"__esModule",{value:!0});const e=$(),t={keyword:"format",type:["number","string"],schemaType:"string",$data:!0,error:{message:({schemaCode:t})=>e.str`must match format "${t}"`,params:({schemaCode:t})=>e._`{format: ${t}}`},code(t,r){const{gen:n,data:o,$data:s,schema:i,schemaCode:a,it:c}=t,{opts:u,errSchemaPath:l,schemaEnv:f,self:d}=c;u.validateFormats&&(s?function(){const s=n.scopeValue("formats",{ref:d.formats,code:u.code.formats}),i=n.const("fDef",e._`${s}[${a}]`),c=n.let("fType"),l=n.let("format");n.if(e._`typeof ${i} == "object" && !(${i} instanceof RegExp)`,(()=>n.assign(c,e._`${i}.type || "string"`).assign(l,e._`${i}.validate`)),(()=>n.assign(c,e._`"string"`).assign(l,i))),t.fail$data((0,e.or)(!1===u.strictSchema?e.nil:e._`${a} && !${l}`,function(){const t=f.$async?e._`(${i}.async ? await ${l}(${o}) : ${l}(${o}))`:e._`${l}(${o})`,n=e._`(typeof ${l} == "function" ? ${t} : ${l}.test(${o}))`;return e._`${l} && ${l} !== true && ${c} === ${r} && !${n}`}()))}():function(){const s=d.formats[i];if(!s)return void function(){if(!1===u.strictSchema)return void d.logger.warn(e());throw new Error(e());function e(){return`unknown format "${i}" ignored in schema at path "${l}"`}}();if(!0===s)return;const[a,c,h]=function(t){const r=t instanceof RegExp?(0,e.regexpCode)(t):u.code.formats?e._`${u.code.formats}${(0,e.getProperty)(i)}`:void 0,o=n.scopeValue("formats",{key:i,ref:t,code:r});if("object"==typeof t&&!(t instanceof RegExp))return[t.type||"string",t.validate,e._`${o}.validate`];return["string",t,o]}(s);a===r&&t.pass(function(){if("object"==typeof s&&!(s instanceof RegExp)&&s.async){if(!f.$async)throw new Error("async format in sync schema");return e._`await ${h}(${o})`}return"function"==typeof c?e._`${h}(${o})`:e._`${h}.test(${o})`}())}())}};return cr.default=t,cr}function lr(){if(ir)return Te;ir=1,Object.defineProperty(Te,"__esModule",{value:!0});const e=De(),t=yt(),r=nr(),n=function(){if(sr)return ar;sr=1,Object.defineProperty(ar,"__esModule",{value:!0});const e=[ur().default];return ar.default=e,ar}(),o=[e.default,t.default,r.default(),n.default,["title","description","default"]];return Te.default=o,Te}var fr,dr,hr={},pr={};function mr(){if(dr)return hr;dr=1,Object.defineProperty(hr,"__esModule",{value:!0});const e=$(),t=(fr||(fr=1,Object.defineProperty(pr,"__esModule",{value:!0}),pr.DiscrError=void 0,function(e){e.Tag="tag",e.Mapping="mapping"}(r||(pr.DiscrError=r={}))),pr);var r;const n=ve(),o=he(),s=P(),i={keyword:"discriminator",type:"object",schemaType:"object",error:{message:({params:{discrError:e,tagName:r}})=>e===t.DiscrError.Tag?`tag "${r}" must be string`:`value of tag "${r}" must be in oneOf`,params:({params:{discrError:t,tag:r,tagName:n}})=>e._`{error: ${t}, tag: ${n}, tagValue: ${r}}`},code(r){const{gen:i,data:a,schema:c,parentSchema:u,it:l}=r,{oneOf:f}=u;if(!l.opts.discriminator)throw new Error("discriminator: requires discriminator option");const d=c.propertyName;if("string"!=typeof d)throw new Error("discriminator: requires propertyName");if(c.mapping)throw new Error("discriminator: mapping is not supported");if(!f)throw new Error("discriminator: requires oneOf keyword");const h=i.let("valid",!1),p=i.const("tag",e._`${a}${(0,e.getProperty)(d)}`);function m(t){const n=i.name("valid"),o=r.subschema({keyword:"oneOf",schemaProp:t},n);return r.mergeEvaluated(o,e.Name),n}i.if(e._`typeof ${p} == "string"`,(()=>function(){const a=function(){var e;const t={},r=a(u);let i=!0;for(let t=0;t<f.length;t++){let u=f[t];if((null==u?void 0:u.$ref)&&!(0,s.schemaHasRulesButRef)(u,l.self.RULES)){const e=u.$ref;if(u=n.resolveRef.call(l.self,l.schemaEnv.root,l.baseId,e),u instanceof n.SchemaEnv&&(u=u.schema),void 0===u)throw new o.default(l.opts.uriResolver,l.baseId,e)}const h=null===(e=null==u?void 0:u.properties)||void 0===e?void 0:e[d];if("object"!=typeof h)throw new Error(`discriminator: oneOf subschemas (or referenced schemas) must have "properties/${d}"`);i=i&&(r||a(u)),c(h,t)}if(!i)throw new Error(`discriminator: "${d}" must be required`);return t;function a({required:e}){return Array.isArray(e)&&e.includes(d)}function c(e,t){if(e.const)h(e.const,t);else{if(!e.enum)throw new Error(`discriminator: "properties/${d}" must have "const" or "enum"`);for(const r of e.enum)h(r,t)}}function h(e,r){if("string"!=typeof e||e in t)throw new Error(`discriminator: "${d}" values must be unique strings`);t[e]=r}}();i.if(!1);for(const t in a)i.elseIf(e._`${p} === ${t}`),i.assign(h,m(a[t]));i.else(),r.error(!1,{discrError:t.DiscrError.Mapping,tag:p,tagName:d}),i.endIf()}()),(()=>r.error(!1,{discrError:t.DiscrError.Tag,tag:p,tagName:d}))),r.ok(h)}};return hr.default=i,hr}var vr,yr={id:"http://json-schema.org/draft-04/schema#",$schema:"http://json-schema.org/draft-04/schema#",description:"Core schema meta-schema",definitions:{schemaArray:{type:"array",minItems:1,items:{$ref:"#"}},positiveInteger:{type:"integer",minimum:0},positiveIntegerDefault0:{allOf:[{$ref:"#/definitions/positiveInteger"},{default:0}]},simpleTypes:{enum:["array","boolean","integer","null","number","object","string"]},stringArray:{type:"array",items:{type:"string"},minItems:1,uniqueItems:!0}},type:"object",properties:{id:{type:"string",format:"uri"},$schema:{type:"string",format:"uri"},title:{type:"string"},description:{type:"string"},default:{},multipleOf:{type:"number",minimum:0,exclusiveMinimum:!0},maximum:{type:"number"},exclusiveMaximum:{type:"boolean",default:!1},minimum:{type:"number"},exclusiveMinimum:{type:"boolean",default:!1},maxLength:{$ref:"#/definitions/positiveInteger"},minLength:{$ref:"#/definitions/positiveIntegerDefault0"},pattern:{type:"string",format:"regex"},additionalItems:{anyOf:[{type:"boolean"},{$ref:"#"}],default:{}},items:{anyOf:[{$ref:"#"},{$ref:"#/definitions/schemaArray"}],default:{}},maxItems:{$ref:"#/definitions/positiveInteger"},minItems:{$ref:"#/definitions/positiveIntegerDefault0"},uniqueItems:{type:"boolean",default:!1},maxProperties:{$ref:"#/definitions/positiveInteger"},minProperties:{$ref:"#/definitions/positiveIntegerDefault0"},required:{$ref:"#/definitions/stringArray"},additionalProperties:{anyOf:[{type:"boolean"},{$ref:"#"}],default:{}},definitions:{type:"object",additionalProperties:{$ref:"#"},default:{}},properties:{type:"object",additionalProperties:{$ref:"#"},default:{}},patternProperties:{type:"object",additionalProperties:{$ref:"#"},default:{}},dependencies:{type:"object",additionalProperties:{anyOf:[{$ref:"#"},{$ref:"#/definitions/stringArray"}]}},enum:{type:"array",minItems:1,uniqueItems:!0},type:{anyOf:[{$ref:"#/definitions/simpleTypes"},{type:"array",items:{$ref:"#/definitions/simpleTypes"},minItems:1,uniqueItems:!0}]},allOf:{$ref:"#/definitions/schemaArray"},anyOf:{$ref:"#/definitions/schemaArray"},oneOf:{$ref:"#/definitions/schemaArray"},not:{$ref:"#"}},dependencies:{exclusiveMaximum:["maximum"],exclusiveMinimum:["minimum"]},default:{}};var gr=(vr||(vr=1,function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.CodeGen=t.Name=t.nil=t.stringify=t.str=t._=t.KeywordCxt=void 0;const r=Ce(),n=lr(),o=mr(),s=yr,i=["/properties"],a="http://json-schema.org/draft-04/schema";class c extends r.default{constructor(e={}){super({...e,schemaId:"id"})}_addVocabularies(){super._addVocabularies(),n.default.forEach((e=>this.addVocabulary(e))),this.opts.discriminator&&this.addKeyword(o.default)}_addDefaultMetaSchema(){if(super._addDefaultMetaSchema(),!this.opts.meta)return;const e=this.opts.$data?this.$dataMetaSchema(s,i):s;this.addMetaSchema(e,a,!1),this.refs["http://json-schema.org/schema"]=a}defaultMeta(){return this.opts.defaultMeta=super.defaultMeta()||(this.getSchema(a)?a:void 0)}}e.exports=t=c,Object.defineProperty(t,"__esModule",{value:!0}),t.default=c;var u=Ce();Object.defineProperty(t,"KeywordCxt",{enumerable:!0,get:function(){return u.KeywordCxt}});var l=Ce();Object.defineProperty(t,"_",{enumerable:!0,get:function(){return l._}}),Object.defineProperty(t,"str",{enumerable:!0,get:function(){return l.str}}),Object.defineProperty(t,"stringify",{enumerable:!0,get:function(){return l.stringify}}),Object.defineProperty(t,"nil",{enumerable:!0,get:function(){return l.nil}}),Object.defineProperty(t,"Name",{enumerable:!0,get:function(){return l.Name}}),Object.defineProperty(t,"CodeGen",{enumerable:!0,get:function(){return l.CodeGen}})}(l,l.exports)),l.exports),_r=c(gr);class wr{sessionEvents=new EventTarget;constructor(){(async()=>{await Promise.resolve();for(const e of this.getLoggedInActors()){const t=new CustomEvent("login",{detail:{session:{actor:e}}});this.sessionEvents.dispatchEvent(t)}const e=new CustomEvent("initialized",{detail:{}});this.sessionEvents.dispatchEvent(e)})()}loggedInActors=[];getLoggedInActors(){if("undefined"!=typeof window){const e=window.localStorage.getItem("graffiti-actor");return e?e.split(",").map(decodeURIComponent):[]}return this.loggedInActors}setLoggedInActors(e){"undefined"!=typeof window?window.localStorage.setItem("graffiti-actor",e.map(encodeURIComponent).join(",")):this.loggedInActors=e}login=async e=>{let t,r=e?.actor;if(!r&&"undefined"!=typeof window){const e=window.prompt("This is an insecure implementation of the Graffiti API for *demo purposes only*. Do not store any sensitive information here. \n\n Simply choose a username to log in.");e&&(r=e)}if(r){const e=this.getLoggedInActors();e.includes(r)||this.setLoggedInActors([...e,r]),t={session:{actor:r}}}else t={error:new Error("No actor ID provided to login")};const n=new CustomEvent("login",{detail:t});this.sessionEvents.dispatchEvent(n)};logout=async e=>{const t=this.getLoggedInActors(),r=t.includes(e.actor);r&&this.setLoggedInActors(t.filter((t=>t!==e.actor)));const n=r?{actor:e.actor}:{actor:e.actor,error:new Error("Not logged in with that actor")},o=new CustomEvent("logout",{detail:n});this.sessionEvents.dispatchEvent(o)}}var br="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function $r(){throw new Error("setTimeout has not been defined")}function kr(){throw new Error("clearTimeout has not been defined")}var Er=$r,Pr=kr;function Sr(e){if(Er===setTimeout)return setTimeout(e,0);if((Er===$r||!Er)&&setTimeout)return Er=setTimeout,setTimeout(e,0);try{return Er(e,0)}catch(t){try{return Er.call(null,e,0)}catch(t){return Er.call(this,e,0)}}}"function"==typeof br.setTimeout&&(Er=setTimeout),"function"==typeof br.clearTimeout&&(Pr=clearTimeout);var jr,Or=[],xr=!1,Ar=-1;function Cr(){xr&&jr&&(xr=!1,jr.length?Or=jr.concat(Or):Ar=-1,Or.length&&Ir())}function Ir(){if(!xr){var e=Sr(Cr);xr=!0;for(var t=Or.length;t;){for(jr=Or,Or=[];++Ar<t;)jr&&jr[Ar].run();Ar=-1,t=Or.length}jr=null,xr=!1,function(e){if(Pr===clearTimeout)return clearTimeout(e);if((Pr===kr||!Pr)&&clearTimeout)return Pr=clearTimeout,clearTimeout(e);try{return Pr(e)}catch(t){try{return Pr.call(null,e)}catch(t){return Pr.call(this,e)}}}(e)}}function Nr(e,t){this.fun=e,this.array=t}Nr.prototype.run=function(){this.fun.apply(null,this.array)};function Tr(){}var Rr=Tr,qr=Tr,Dr=Tr,Lr=Tr,Mr=Tr,Vr=Tr,Ur=Tr;var Br=br.performance||{},zr=Br.now||Br.mozNow||Br.msNow||Br.oNow||Br.webkitNow||function(){return(new Date).getTime()};var Kr=new Date;var Fr,Jr={nextTick:function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)t[r-1]=arguments[r];Or.push(new Nr(e,t)),1!==Or.length||xr||Sr(Ir)},title:"browser",browser:!0,env:{},argv:[],version:"",versions:{},on:Rr,addListener:qr,once:Dr,off:Lr,removeListener:Mr,removeAllListeners:Vr,emit:Ur,binding:function(e){throw new Error("process.binding is not supported")},cwd:function(){return"/"},chdir:function(e){throw new Error("process.chdir is not supported")},umask:function(){return 0},hrtime:function(e){var t=.001*zr.call(Br),r=Math.floor(t),n=Math.floor(t%1*1e9);return e&&(r-=e[0],(n-=e[1])<0&&(r--,n+=1e9)),[r,n]},platform:"browser",release:{},config:{},uptime:function(){return(new Date-Kr)/1e3}},Gr={exports:{}};var Hr,Wr=(Fr||(Fr=1,Gr.exports=function(e){var t=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];function r(e,t){var r=e[0],n=e[1],o=e[2],s=e[3];n=((n+=((o=((o+=((s=((s+=((r=((r+=(n&o|~n&s)+t[0]-680876936|0)<<7|r>>>25)+n|0)&n|~r&o)+t[1]-389564586|0)<<12|s>>>20)+r|0)&r|~s&n)+t[2]+606105819|0)<<17|o>>>15)+s|0)&s|~o&r)+t[3]-1044525330|0)<<22|n>>>10)+o|0,n=((n+=((o=((o+=((s=((s+=((r=((r+=(n&o|~n&s)+t[4]-176418897|0)<<7|r>>>25)+n|0)&n|~r&o)+t[5]+1200080426|0)<<12|s>>>20)+r|0)&r|~s&n)+t[6]-1473231341|0)<<17|o>>>15)+s|0)&s|~o&r)+t[7]-45705983|0)<<22|n>>>10)+o|0,n=((n+=((o=((o+=((s=((s+=((r=((r+=(n&o|~n&s)+t[8]+1770035416|0)<<7|r>>>25)+n|0)&n|~r&o)+t[9]-1958414417|0)<<12|s>>>20)+r|0)&r|~s&n)+t[10]-42063|0)<<17|o>>>15)+s|0)&s|~o&r)+t[11]-1990404162|0)<<22|n>>>10)+o|0,n=((n+=((o=((o+=((s=((s+=((r=((r+=(n&o|~n&s)+t[12]+1804603682|0)<<7|r>>>25)+n|0)&n|~r&o)+t[13]-40341101|0)<<12|s>>>20)+r|0)&r|~s&n)+t[14]-1502002290|0)<<17|o>>>15)+s|0)&s|~o&r)+t[15]+1236535329|0)<<22|n>>>10)+o|0,n=((n+=((o=((o+=((s=((s+=((r=((r+=(n&s|o&~s)+t[1]-165796510|0)<<5|r>>>27)+n|0)&o|n&~o)+t[6]-1069501632|0)<<9|s>>>23)+r|0)&n|r&~n)+t[11]+643717713|0)<<14|o>>>18)+s|0)&r|s&~r)+t[0]-373897302|0)<<20|n>>>12)+o|0,n=((n+=((o=((o+=((s=((s+=((r=((r+=(n&s|o&~s)+t[5]-701558691|0)<<5|r>>>27)+n|0)&o|n&~o)+t[10]+38016083|0)<<9|s>>>23)+r|0)&n|r&~n)+t[15]-660478335|0)<<14|o>>>18)+s|0)&r|s&~r)+t[4]-405537848|0)<<20|n>>>12)+o|0,n=((n+=((o=((o+=((s=((s+=((r=((r+=(n&s|o&~s)+t[9]+568446438|0)<<5|r>>>27)+n|0)&o|n&~o)+t[14]-1019803690|0)<<9|s>>>23)+r|0)&n|r&~n)+t[3]-187363961|0)<<14|o>>>18)+s|0)&r|s&~r)+t[8]+1163531501|0)<<20|n>>>12)+o|0,n=((n+=((o=((o+=((s=((s+=((r=((r+=(n&s|o&~s)+t[13]-1444681467|0)<<5|r>>>27)+n|0)&o|n&~o)+t[2]-51403784|0)<<9|s>>>23)+r|0)&n|r&~n)+t[7]+1735328473|0)<<14|o>>>18)+s|0)&r|s&~r)+t[12]-1926607734|0)<<20|n>>>12)+o|0,n=((n+=((o=((o+=((s=((s+=((r=((r+=(n^o^s)+t[5]-378558|0)<<4|r>>>28)+n|0)^n^o)+t[8]-2022574463|0)<<11|s>>>21)+r|0)^r^n)+t[11]+1839030562|0)<<16|o>>>16)+s|0)^s^r)+t[14]-35309556|0)<<23|n>>>9)+o|0,n=((n+=((o=((o+=((s=((s+=((r=((r+=(n^o^s)+t[1]-1530992060|0)<<4|r>>>28)+n|0)^n^o)+t[4]+1272893353|0)<<11|s>>>21)+r|0)^r^n)+t[7]-155497632|0)<<16|o>>>16)+s|0)^s^r)+t[10]-1094730640|0)<<23|n>>>9)+o|0,n=((n+=((o=((o+=((s=((s+=((r=((r+=(n^o^s)+t[13]+681279174|0)<<4|r>>>28)+n|0)^n^o)+t[0]-358537222|0)<<11|s>>>21)+r|0)^r^n)+t[3]-722521979|0)<<16|o>>>16)+s|0)^s^r)+t[6]+76029189|0)<<23|n>>>9)+o|0,n=((n+=((o=((o+=((s=((s+=((r=((r+=(n^o^s)+t[9]-640364487|0)<<4|r>>>28)+n|0)^n^o)+t[12]-421815835|0)<<11|s>>>21)+r|0)^r^n)+t[15]+530742520|0)<<16|o>>>16)+s|0)^s^r)+t[2]-995338651|0)<<23|n>>>9)+o|0,n=((n+=((s=((s+=(n^((r=((r+=(o^(n|~s))+t[0]-198630844|0)<<6|r>>>26)+n|0)|~o))+t[7]+1126891415|0)<<10|s>>>22)+r|0)^((o=((o+=(r^(s|~n))+t[14]-1416354905|0)<<15|o>>>17)+s|0)|~r))+t[5]-57434055|0)<<21|n>>>11)+o|0,n=((n+=((s=((s+=(n^((r=((r+=(o^(n|~s))+t[12]+1700485571|0)<<6|r>>>26)+n|0)|~o))+t[3]-1894986606|0)<<10|s>>>22)+r|0)^((o=((o+=(r^(s|~n))+t[10]-1051523|0)<<15|o>>>17)+s|0)|~r))+t[1]-2054922799|0)<<21|n>>>11)+o|0,n=((n+=((s=((s+=(n^((r=((r+=(o^(n|~s))+t[8]+1873313359|0)<<6|r>>>26)+n|0)|~o))+t[15]-30611744|0)<<10|s>>>22)+r|0)^((o=((o+=(r^(s|~n))+t[6]-1560198380|0)<<15|o>>>17)+s|0)|~r))+t[13]+1309151649|0)<<21|n>>>11)+o|0,n=((n+=((s=((s+=(n^((r=((r+=(o^(n|~s))+t[4]-145523070|0)<<6|r>>>26)+n|0)|~o))+t[11]-1120210379|0)<<10|s>>>22)+r|0)^((o=((o+=(r^(s|~n))+t[2]+718787259|0)<<15|o>>>17)+s|0)|~r))+t[9]-343485551|0)<<21|n>>>11)+o|0,e[0]=r+e[0]|0,e[1]=n+e[1]|0,e[2]=o+e[2]|0,e[3]=s+e[3]|0}function n(e){var t,r=[];for(t=0;t<64;t+=4)r[t>>2]=e.charCodeAt(t)+(e.charCodeAt(t+1)<<8)+(e.charCodeAt(t+2)<<16)+(e.charCodeAt(t+3)<<24);return r}function o(e){var t,r=[];for(t=0;t<64;t+=4)r[t>>2]=e[t]+(e[t+1]<<8)+(e[t+2]<<16)+(e[t+3]<<24);return r}function s(e){var t,o,s,i,a,c,u=e.length,l=[1732584193,-271733879,-1732584194,271733878];for(t=64;t<=u;t+=64)r(l,n(e.substring(t-64,t)));for(o=(e=e.substring(t-64)).length,s=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],t=0;t<o;t+=1)s[t>>2]|=e.charCodeAt(t)<<(t%4<<3);if(s[t>>2]|=128<<(t%4<<3),t>55)for(r(l,s),t=0;t<16;t+=1)s[t]=0;return i=(i=8*u).toString(16).match(/(.*?)(.{0,8})$/),a=parseInt(i[2],16),c=parseInt(i[1],16)||0,s[14]=a,s[15]=c,r(l,s),l}function i(e){var t,n,s,i,a,c,u=e.length,l=[1732584193,-271733879,-1732584194,271733878];for(t=64;t<=u;t+=64)r(l,o(e.subarray(t-64,t)));for(n=(e=t-64<u?e.subarray(t-64):new Uint8Array(0)).length,s=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],t=0;t<n;t+=1)s[t>>2]|=e[t]<<(t%4<<3);if(s[t>>2]|=128<<(t%4<<3),t>55)for(r(l,s),t=0;t<16;t+=1)s[t]=0;return i=(i=8*u).toString(16).match(/(.*?)(.{0,8})$/),a=parseInt(i[2],16),c=parseInt(i[1],16)||0,s[14]=a,s[15]=c,r(l,s),l}function a(e){var r,n="";for(r=0;r<4;r+=1)n+=t[e>>8*r+4&15]+t[e>>8*r&15];return n}function c(e){var t;for(t=0;t<e.length;t+=1)e[t]=a(e[t]);return e.join("")}function u(e){return/[\u0080-\uFFFF]/.test(e)&&(e=unescape(encodeURIComponent(e))),e}function l(e,t){var r,n=e.length,o=new ArrayBuffer(n),s=new Uint8Array(o);for(r=0;r<n;r+=1)s[r]=e.charCodeAt(r);return t?s:o}function f(e){return String.fromCharCode.apply(null,new Uint8Array(e))}function d(e,t,r){var n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e)),n.set(new Uint8Array(t),e.byteLength),n}function h(e){var t,r=[],n=e.length;for(t=0;t<n-1;t+=2)r.push(parseInt(e.substr(t,2),16));return String.fromCharCode.apply(String,r)}function p(){this.reset()}return c(s("hello")),"undefined"==typeof ArrayBuffer||ArrayBuffer.prototype.slice||function(){function t(e,t){return(e=0|e||0)<0?Math.max(e+t,0):Math.min(e,t)}ArrayBuffer.prototype.slice=function(r,n){var o,s,i,a,c=this.byteLength,u=t(r,c),l=c;return n!==e&&(l=t(n,c)),u>l?new ArrayBuffer(0):(o=l-u,s=new ArrayBuffer(o),i=new Uint8Array(s),a=new Uint8Array(this,u,o),i.set(a),s)}}(),p.prototype.append=function(e){return this.appendBinary(u(e)),this},p.prototype.appendBinary=function(e){this._buff+=e,this._length+=e.length;var t,o=this._buff.length;for(t=64;t<=o;t+=64)r(this._hash,n(this._buff.substring(t-64,t)));return this._buff=this._buff.substring(t-64),this},p.prototype.end=function(e){var t,r,n=this._buff,o=n.length,s=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(t=0;t<o;t+=1)s[t>>2]|=n.charCodeAt(t)<<(t%4<<3);return this._finish(s,o),r=c(this._hash),e&&(r=h(r)),this.reset(),r},p.prototype.reset=function(){return this._buff="",this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},p.prototype.getState=function(){return{buff:this._buff,length:this._length,hash:this._hash.slice()}},p.prototype.setState=function(e){return this._buff=e.buff,this._length=e.length,this._hash=e.hash,this},p.prototype.destroy=function(){delete this._hash,delete this._buff,delete this._length},p.prototype._finish=function(e,t){var n,o,s,i=t;if(e[i>>2]|=128<<(i%4<<3),i>55)for(r(this._hash,e),i=0;i<16;i+=1)e[i]=0;n=(n=8*this._length).toString(16).match(/(.*?)(.{0,8})$/),o=parseInt(n[2],16),s=parseInt(n[1],16)||0,e[14]=o,e[15]=s,r(this._hash,e)},p.hash=function(e,t){return p.hashBinary(u(e),t)},p.hashBinary=function(e,t){var r=c(s(e));return t?h(r):r},p.ArrayBuffer=function(){this.reset()},p.ArrayBuffer.prototype.append=function(e){var t,n=d(this._buff.buffer,e),s=n.length;for(this._length+=e.byteLength,t=64;t<=s;t+=64)r(this._hash,o(n.subarray(t-64,t)));return this._buff=t-64<s?new Uint8Array(n.buffer.slice(t-64)):new Uint8Array(0),this},p.ArrayBuffer.prototype.end=function(e){var t,r,n=this._buff,o=n.length,s=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(t=0;t<o;t+=1)s[t>>2]|=n[t]<<(t%4<<3);return this._finish(s,o),r=c(this._hash),e&&(r=h(r)),this.reset(),r},p.ArrayBuffer.prototype.reset=function(){return this._buff=new Uint8Array(0),this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},p.ArrayBuffer.prototype.getState=function(){var e=p.prototype.getState.call(this);return e.buff=f(e.buff),e},p.ArrayBuffer.prototype.setState=function(e){return e.buff=l(e.buff,!0),p.prototype.setState.call(this,e)},p.ArrayBuffer.prototype.destroy=p.prototype.destroy,p.ArrayBuffer.prototype._finish=p.prototype._finish,p.ArrayBuffer.hash=function(e,t){var r=c(i(new Uint8Array(e)));return t?h(r):r},p}()),Gr.exports),Qr=c(Wr),Yr=new Uint8Array(16);function Xr(){if(!Hr&&!(Hr="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Hr(Yr)}var Zr=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;for(var en=[],tn=0;tn<256;++tn)en.push((tn+256).toString(16).substr(1));function rn(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=(en[e[t+0]]+en[e[t+1]]+en[e[t+2]]+en[e[t+3]]+"-"+en[e[t+4]]+en[e[t+5]]+"-"+en[e[t+6]]+en[e[t+7]]+"-"+en[e[t+8]]+en[e[t+9]]+"-"+en[e[t+10]]+en[e[t+11]]+en[e[t+12]]+en[e[t+13]]+en[e[t+14]]+en[e[t+15]]).toLowerCase();if(!function(e){return"string"==typeof e&&Zr.test(e)}(r))throw TypeError("Stringified UUID is invalid");return r}function nn(e,t,r){var n=(e=e||{}).random||(e.rng||Xr)();if(n[6]=15&n[6]|64,n[8]=63&n[8]|128,t){r=r||0;for(var o=0;o<16;++o)t[r+o]=n[o];return t}return rn(n)}var on,sn={};var an=function(){if(on)return sn;function e(e,t,r){var n=r[r.length-1];e===n.element&&(r.pop(),n=r[r.length-1]);var o=n.element,s=n.index;if(Array.isArray(o))o.push(e);else if(s===t.length-2){o[t.pop()]=e}else t.push(e)}return on=1,sn.stringify=function(e){var t=[];t.push({obj:e});for(var r,n,o,s,i,a,c,u,l,f,d="";r=t.pop();)if(n=r.obj,d+=r.prefix||"",o=r.val||"")d+=o;else if("object"!=typeof n)d+=void 0===n?null:JSON.stringify(n);else if(null===n)d+="null";else if(Array.isArray(n)){for(t.push({val:"]"}),s=n.length-1;s>=0;s--)i=0===s?"":",",t.push({obj:n[s],prefix:i});t.push({val:"["})}else{for(c in a=[],n)n.hasOwnProperty(c)&&a.push(c);for(t.push({val:"}"}),s=a.length-1;s>=0;s--)l=n[u=a[s]],f=s>0?",":"",f+=JSON.stringify(u)+":",t.push({obj:l,prefix:f});t.push({val:"{"})}return d},sn.parse=function(t){for(var r,n,o,s,i,a,c,u,l,f=[],d=[],h=0;;)if("}"!==(r=t[h++])&&"]"!==r&&void 0!==r)switch(r){case" ":case"\t":case"\n":case":":case",":break;case"n":h+=3,e(null,f,d);break;case"t":h+=3,e(!0,f,d);break;case"f":h+=4,e(!1,f,d);break;case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":case"-":for(n="",h--;;){if(o=t[h++],!/[\d\.\-e\+]/.test(o)){h--;break}n+=o}e(parseFloat(n),f,d);break;case'"':for(s="",i=void 0,a=0;'"'!==(c=t[h++])||"\\"===i&&a%2==1;)s+=c,"\\"===(i=c)?a++:a=0;e(JSON.parse('"'+s+'"'),f,d);break;case"[":u={element:[],index:f.length},f.push(u.element),d.push(u);break;case"{":l={element:{},index:f.length},f.push(l.element),d.push(l);break;default:throw new Error("unexpectedly reached end of input: "+r)}else{if(1===f.length)return f.pop();e(f.pop(),f,d)}},sn}(),cn=c(an);function un(){}function ln(){ln.init.call(this)}function fn(e){return void 0===e._maxListeners?ln.defaultMaxListeners:e._maxListeners}function dn(e,t,r,n){var o,s,i;if("function"!=typeof r)throw new TypeError('"listener" argument must be a function');if((s=e._events)?(s.newListener&&(e.emit("newListener",t,r.listener?r.listener:r),s=e._events),i=s[t]):(s=e._events=new un,e._eventsCount=0),i){if("function"==typeof i?i=s[t]=n?[r,i]:[i,r]:n?i.unshift(r):i.push(r),!i.warned&&(o=fn(e))&&o>0&&i.length>o){i.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+i.length+" "+t+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=i.length,function(e){"function"==typeof console.warn?console.warn(e):console.log(e)}(a)}}else i=s[t]=r,++e._eventsCount;return e}function hn(e,t,r){var n=!1;function o(){e.removeListener(t,o),n||(n=!0,r.apply(e,arguments))}return o.listener=r,o}function pn(e){var t=this._events;if(t){var r=t[e];if("function"==typeof r)return 1;if(r)return r.length}return 0}function mn(e,t){for(var r=new Array(t);t--;)r[t]=e[t];return r}un.prototype=Object.create(null),ln.EventEmitter=ln,ln.usingDomains=!1,ln.prototype.domain=void 0,ln.prototype._events=void 0,ln.prototype._maxListeners=void 0,ln.defaultMaxListeners=10,ln.init=function(){this.domain=null,ln.usingDomains&&undefined.active,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new un,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},ln.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||isNaN(e))throw new TypeError('"n" argument must be a positive number');return this._maxListeners=e,this},ln.prototype.getMaxListeners=function(){return fn(this)},ln.prototype.emit=function(e){var t,r,n,o,s,i,a,c="error"===e;if(i=this._events)c=c&&null==i.error;else if(!c)return!1;if(a=this.domain,c){if(t=arguments[1],!a){if(t instanceof Error)throw t;var u=new Error('Uncaught, unspecified "error" event. ('+t+")");throw u.context=t,u}return t||(t=new Error('Uncaught, unspecified "error" event')),t.domainEmitter=this,t.domain=a,t.domainThrown=!1,a.emit("error",t),!1}if(!(r=i[e]))return!1;var l="function"==typeof r;switch(n=arguments.length){case 1:!function(e,t,r){if(t)e.call(r);else for(var n=e.length,o=mn(e,n),s=0;s<n;++s)o[s].call(r)}(r,l,this);break;case 2:!function(e,t,r,n){if(t)e.call(r,n);else for(var o=e.length,s=mn(e,o),i=0;i<o;++i)s[i].call(r,n)}(r,l,this,arguments[1]);break;case 3:!function(e,t,r,n,o){if(t)e.call(r,n,o);else for(var s=e.length,i=mn(e,s),a=0;a<s;++a)i[a].call(r,n,o)}(r,l,this,arguments[1],arguments[2]);break;case 4:!function(e,t,r,n,o,s){if(t)e.call(r,n,o,s);else for(var i=e.length,a=mn(e,i),c=0;c<i;++c)a[c].call(r,n,o,s)}(r,l,this,arguments[1],arguments[2],arguments[3]);break;default:for(o=new Array(n-1),s=1;s<n;s++)o[s-1]=arguments[s];!function(e,t,r,n){if(t)e.apply(r,n);else for(var o=e.length,s=mn(e,o),i=0;i<o;++i)s[i].apply(r,n)}(r,l,this,o)}return!0},ln.prototype.addListener=function(e,t){return dn(this,e,t,!1)},ln.prototype.on=ln.prototype.addListener,ln.prototype.prependListener=function(e,t){return dn(this,e,t,!0)},ln.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,hn(this,e,t)),this},ln.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,hn(this,e,t)),this},ln.prototype.removeListener=function(e,t){var r,n,o,s,i;if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');if(!(n=this._events))return this;if(!(r=n[e]))return this;if(r===t||r.listener&&r.listener===t)0==--this._eventsCount?this._events=new un:(delete n[e],n.removeListener&&this.emit("removeListener",e,r.listener||t));else if("function"!=typeof r){for(o=-1,s=r.length;s-- >0;)if(r[s]===t||r[s].listener&&r[s].listener===t){i=r[s].listener,o=s;break}if(o<0)return this;if(1===r.length){if(r[0]=void 0,0==--this._eventsCount)return this._events=new un,this;delete n[e]}else!function(e,t){for(var r=t,n=r+1,o=e.length;n<o;r+=1,n+=1)e[r]=e[n];e.pop()}(r,o);n.removeListener&&this.emit("removeListener",e,i||t)}return this},ln.prototype.removeAllListeners=function(e){var t,r;if(!(r=this._events))return this;if(!r.removeListener)return 0===arguments.length?(this._events=new un,this._eventsCount=0):r[e]&&(0==--this._eventsCount?this._events=new un:delete r[e]),this;if(0===arguments.length){for(var n,o=Object.keys(r),s=0;s<o.length;++s)"removeListener"!==(n=o[s])&&this.removeAllListeners(n);return this.removeAllListeners("removeListener"),this._events=new un,this._eventsCount=0,this}if("function"==typeof(t=r[e]))this.removeListener(e,t);else if(t)do{this.removeListener(e,t[t.length-1])}while(t[0]);return this},ln.prototype.listeners=function(e){var t,r,n=this._events;return r=n&&(t=n[e])?"function"==typeof t?[t.listener||t]:function(e){for(var t=new Array(e.length),r=0;r<t.length;++r)t[r]=e[r].listener||e[r];return t}(t):[],r},ln.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):pn.call(e,t)},ln.prototype.listenerCount=pn,ln.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};var vn=Function.prototype.toString,yn=vn.call(Object);function gn(e){var t,r,n;if(!e||"object"!=typeof e)return e;if(Array.isArray(e)){for(t=[],r=0,n=e.length;r<n;r++)t[r]=gn(e[r]);return t}if(e instanceof Date&&isFinite(e))return e.toISOString();if(function(e){return"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer||"undefined"!=typeof Blob&&e instanceof Blob}(e))return function(e){return e instanceof ArrayBuffer?e.slice(0):e.slice(0,e.size,e.type)}(e);if(!function(e){var t=Object.getPrototypeOf(e);if(null===t)return!0;var r=t.constructor;return"function"==typeof r&&r instanceof r&&vn.call(r)==yn}(e))return e;for(r in t={},e)if(Object.prototype.hasOwnProperty.call(e,r)){var o=gn(e[r]);void 0!==o&&(t[r]=o)}return t}function _n(e){var t=!1;return function(...r){if(t)throw new Error("once called more than once");t=!0,e.apply(this,r)}}function wn(e){return function(...t){t=gn(t);var r=this,n="function"==typeof t[t.length-1]&&t.pop(),o=new Promise((function(n,o){var s;try{var i=_n((function(e,t){e?o(e):n(t)}));t.push(i),(s=e.apply(r,t))&&"function"==typeof s.then&&n(s)}catch(e){o(e)}}));return n&&o.then((function(e){n(null,e)}),n),o}}function bn(e,t){return wn((function(...r){if(this._closed)return Promise.reject(new Error("database is closed"));if(this._destroyed)return Promise.reject(new Error("database is destroyed"));var n=this;return function(e,t,r){if(e.constructor.listeners("debug").length){for(var n=["api",e.name,t],o=0;o<r.length-1;o++)n.push(r[o]);e.constructor.emit("debug",n);var s=r[r.length-1];r[r.length-1]=function(r,n){var o=["api",e.name,t];o=o.concat(r?["error",r]:["success",n]),e.constructor.emit("debug",o),s(r,n)}}}(n,e,r),this.taskqueue.isReady?t.apply(this,r):new Promise((function(t,o){n.taskqueue.addTask((function(s){s?o(s):t(n[e].apply(n,r))}))}))}))}function $n(e,t){for(var r={},n=0,o=t.length;n<o;n++){var s=t[n];s in e&&(r[s]=e[s])}return r}var kn;function En(e){return e}function Pn(e){return[{ok:e}]}function Sn(e,t,r){var n=t.docs,o=new Map;n.forEach((function(e){o.has(e.id)?o.get(e.id).push(e):o.set(e.id,[e])}));var s=o.size,i=0,a=new Array(s);function c(){var e;++i===s&&(e=[],a.forEach((function(t){t.docs.forEach((function(r){e.push({id:t.id,docs:[r]})}))})),r(null,{results:e}))}var u=[];o.forEach((function(e,t){u.push(t)}));var l=0;function f(){if(!(l>=u.length)){var r=Math.min(l+6,u.length),n=u.slice(l,r);!function(r,n){r.forEach((function(r,s){var i=n+s,u=o.get(r),l=$n(u[0],["atts_since","attachments"]);l.open_revs=u.map((function(e){return e.rev})),l.open_revs=l.open_revs.filter(En);var d=En;0===l.open_revs.length&&(delete l.open_revs,d=Pn),["revs","attachments","binary","ajax","latest"].forEach((function(e){e in t&&(l[e]=t[e])})),e.get(r,l,(function(e,t){var n;n=e?[{error:e}]:d(t),function(e,t,r){a[e]={id:t,docs:r},c()}(i,r,n),f()}))}))}(n,l),l+=n.length}}f()}try{localStorage.setItem("_pouch_check_localstorage",1),kn=!!localStorage.getItem("_pouch_check_localstorage")}catch(r){kn=!1}function jn(){return kn}const On="function"==typeof queueMicrotask?queueMicrotask:function(e){Promise.resolve().then(e)};function xn(e){if("undefined"!=typeof console&&"function"==typeof console[e]){var t=Array.prototype.slice.call(arguments,1);console[e].apply(console,t)}}function An(e){var t=0;return e||(t=2e3),function(e,t){var r=6e5;return e=parseInt(e,10)||0,(t=parseInt(t,10))!=t||t<=e?t=(e||1)<<1:t+=1,t>r&&(e=3e5,t=r),~~((t-e)*Math.random()+e)}(e,t)}function Cn(e,t){xn("info","The above "+e+" is totally normal. "+t)}class In extends Error{constructor(e,t,r){super(),this.status=e,this.name=t,this.message=r,this.error=!0}toString(){return JSON.stringify({status:this.status,name:this.name,message:this.message,reason:this.reason})}}new In(401,"unauthorized","Name or password is incorrect.");var Nn=new In(400,"bad_request","Missing JSON list of 'docs'"),Tn=new In(404,"not_found","missing"),Rn=new In(409,"conflict","Document update conflict"),qn=new In(400,"bad_request","_id field must contain a string"),Dn=new In(412,"missing_id","_id is required for puts"),Ln=new In(400,"bad_request","Only reserved document ids may start with underscore.");new In(412,"precondition_failed","Database not open");var Mn=new In(500,"unknown_error","Database encountered an unknown error"),Vn=new In(500,"badarg","Some query argument is invalid");new In(400,"invalid_request","Request was invalid");var Un=new In(400,"query_parse_error","Some query parameter is invalid"),Bn=new In(500,"doc_validation","Bad special document member"),zn=new In(400,"bad_request","Something wrong with the request"),Kn=new In(400,"bad_request","Document must be a JSON object");new In(404,"not_found","Database not found");var Fn=new In(500,"indexed_db_went_bad","unknown");new In(500,"web_sql_went_bad","unknown"),new In(500,"levelDB_went_went_bad","unknown"),new In(403,"forbidden","Forbidden by design doc validate_doc_update function");var Jn=new In(400,"bad_request","Invalid rev format");new In(412,"file_exists","The database could not be created, the file already exists.");var Gn=new In(412,"missing_stub","A pre-existing attachment stub wasn't found");function Hn(e,t){function r(t){for(var r=Object.getOwnPropertyNames(e),n=0,o=r.length;n<o;n++)"function"!=typeof e[r[n]]&&(this[r[n]]=e[r[n]]);void 0===this.stack&&(this.stack=(new Error).stack),void 0!==t&&(this.reason=t)}return r.prototype=In.prototype,new r(t)}function Wn(e){if("object"!=typeof e){var t=e;(e=Mn).data=t}return"error"in e&&"conflict"===e.error&&(e.name="conflict",e.status=409),"name"in e||(e.name=e.error||"unknown"),"status"in e||(e.status=500),"message"in e||(e.message=e.message||e.reason),"stack"in e||(e.stack=(new Error).stack),e}function Qn(e){var t={},r=e.filter&&"function"==typeof e.filter;return t.query=e.query_params,function(n){n.doc||(n.doc={});var o=r&&function(e,t,r){try{return!e(t,r)}catch(e){var n="Filter function threw: "+e.toString();return Hn(zn,n)}}(e.filter,n.doc,t);if("object"==typeof o)return o;if(o)return!1;if(e.include_docs){if(!e.attachments)for(var s in n.doc._attachments)Object.prototype.hasOwnProperty.call(n.doc._attachments,s)&&(n.doc._attachments[s].stub=!0)}else delete n.doc;return!0}}function Yn(e){var t;if(e?"string"!=typeof e?t=Hn(qn):/^_/.test(e)&&!/^_(design|local)/.test(e)&&(t=Hn(Ln)):t=Hn(Dn),t)throw t}function Xn(e){return"boolean"==typeof e._remote?e._remote:"function"==typeof e.type&&(xn("warn","db.type() is deprecated and will be removed in a future version of PouchDB"),"http"===e.type())}function Zn(e){if(!e)return null;var t=e.split("/");return 2===t.length?t:1===t.length?[e,e]:null}function eo(e){var t=Zn(e);return t?t.join("/"):null}new In(413,"invalid_url","Provided URL is invalid");var to=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],ro="queryKey",no=/(?:^|&)([^&=]*)=?([^&]*)/g,oo=/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/;function so(e){for(var t=oo.exec(e),r={},n=14;n--;){var o=to[n],s=t[n]||"",i=-1!==["user","password"].indexOf(o);r[o]=i?decodeURIComponent(s):s}return r[ro]={},r[to[12]].replace(no,(function(e,t,n){t&&(r[ro][t]=n)})),r}function io(e,t){var r=[],n=[];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(r.push(o),n.push(t[o]));return r.push(e),Function.apply(null,r).apply(null,n)}function ao(e,t,r){return e.get(t).catch((function(e){if(404!==e.status)throw e;return{}})).then((function(n){var o=n._rev,s=r(n);return s?(s._id=t,s._rev=o,function(e,t,r){return e.put(t).then((function(e){return{updated:!0,rev:e.rev}}),(function(n){if(409!==n.status)throw n;return ao(e,t._id,r)}))}(e,s,r)):{updated:!1,rev:o}}))}var co=function(e){return atob(e)},uo=function(e){return btoa(e)};function lo(e,t){e=e||[],t=t||{};try{return new Blob(e,t)}catch(o){if("TypeError"!==o.name)throw o;for(var r=new("undefined"!=typeof BlobBuilder?BlobBuilder:"undefined"!=typeof MSBlobBuilder?MSBlobBuilder:"undefined"!=typeof MozBlobBuilder?MozBlobBuilder:WebKitBlobBuilder),n=0;n<e.length;n+=1)r.append(e[n]);return r.getBlob(t.type)}}function fo(e){for(var t=e.length,r=new ArrayBuffer(t),n=new Uint8Array(r),o=0;o<t;o++)n[o]=e.charCodeAt(o);return r}function ho(e,t){return lo([fo(e)],{type:t})}function po(e,t){return ho(co(e),t)}function mo(e,t){var r=new FileReader,n="function"==typeof r.readAsBinaryString;r.onloadend=function(e){var r=e.target.result||"";if(n)return t(r);t(function(e){for(var t="",r=new Uint8Array(e),n=r.byteLength,o=0;o<n;o++)t+=String.fromCharCode(r[o]);return t}(r))},n?r.readAsBinaryString(e):r.readAsArrayBuffer(e)}function vo(e,t){mo(e,(function(e){t(e)}))}function yo(e,t){vo(e,(function(e){t(uo(e))}))}var go=self.setImmediate||self.setTimeout;function _o(e,t,r,n,o){(r>0||n<t.size)&&(t=t.slice(r,n)),function(e,t){var r=new FileReader;r.onloadend=function(e){var r=e.target.result||new ArrayBuffer(0);t(r)},r.readAsArrayBuffer(e)}(t,(function(t){e.append(t),o()}))}function wo(e,t,r,n,o){(r>0||n<t.length)&&(t=t.substring(r,n)),e.appendBinary(t),o()}function bo(e,t){var r="string"==typeof e,n=r?e.length:e.size,o=Math.min(32768,n),s=Math.ceil(n/o),i=0,a=r?new Qr:new Qr.ArrayBuffer,c=r?wo:_o;function u(){go(f)}function l(){var e=function(e){return uo(e)}(a.end(!0));t(e),a.destroy()}function f(){var t=i*o,r=t+o;i++,c(a,e,t,r,i<s?u:l)}f()}function $o(e){return Qr.hash(e)}function ko(e,t){if(!t)return nn().replace(/-/g,"").toLowerCase();var r=Object.assign({},e);return delete r._rev_tree,$o(JSON.stringify(r))}var Eo=nn;function Po(e){for(var t,r,n,o,s=e.rev_tree.slice();o=s.pop();){var i=o.ids,a=i[2],c=o.pos;if(a.length)for(var u=0,l=a.length;u<l;u++)s.push({pos:c+1,ids:a[u]});else{var f=!!i[1].deleted,d=i[0];t&&!(n!==f?n:r!==c?r<c:t<d)||(t=d,r=c,n=f)}}return r+"-"+t}function So(e,t){for(var r,n=e.slice();r=n.pop();)for(var o=r.pos,s=r.ids,i=s[2],a=t(0===i.length,o,s[0],r.ctx,s[1]),c=0,u=i.length;c<u;c++)n.push({pos:o+1,ids:i[c],ctx:a})}function jo(e,t){return e.pos-t.pos}function Oo(e){var t=[];So(e,(function(e,r,n,o,s){e&&t.push({rev:r+"-"+n,pos:r,opts:s})})),t.sort(jo).reverse();for(var r=0,n=t.length;r<n;r++)delete t[r].pos;return t}function xo(e){for(var t=Po(e),r=Oo(e.rev_tree),n=[],o=0,s=r.length;o<s;o++){var i=r[o];i.rev===t||i.opts.deleted||n.push(i.rev)}return n}function Ao(e){for(var t,r=[],n=e.slice();t=n.pop();){var o=t.pos,s=t.ids,i=s[0],a=s[1],c=s[2],u=0===c.length,l=t.history?t.history.slice():[];l.push({id:i,opts:a}),u&&r.push({pos:o+1-l.length,ids:l});for(var f=0,d=c.length;f<d;f++)n.push({pos:o+1,ids:c[f],history:l})}return r.reverse()}function Co(e,t){return e.pos-t.pos}function Io(e,t,r){var n=function(e,t,r){for(var n,o=0,s=e.length;o<s;)r(e[n=o+s>>>1],t)<0?o=n+1:s=n;return o}(e,t,r);e.splice(n,0,t)}function No(e,t){for(var r,n,o=t,s=e.length;o<s;o++){var i=e[o],a=[i.id,i.opts,[]];n?(n[2].push(a),n=a):r=n=a}return r}function To(e,t){return e[0]<t[0]?-1:1}function Ro(e,t){for(var r=[{tree1:e,tree2:t}],n=!1;r.length>0;){var o=r.pop(),s=o.tree1,i=o.tree2;(s[1].status||i[1].status)&&(s[1].status="available"===s[1].status||"available"===i[1].status?"available":"missing");for(var a=0;a<i[2].length;a++)if(s[2][0]){for(var c=!1,u=0;u<s[2].length;u++)s[2][u][0]===i[2][a][0]&&(r.push({tree1:s[2][u],tree2:i[2][a]}),c=!0);c||(n="new_branch",Io(s[2],i[2][a],To))}else n="new_leaf",s[2][0]=i[2][a]}return{conflicts:n,tree:e}}function qo(e,t,r){var n,o=[],s=!1,i=!1;if(!e.length)return{tree:[t],conflicts:"new_leaf"};for(var a=0,c=e.length;a<c;a++){var u=e[a];if(u.pos===t.pos&&u.ids[0]===t.ids[0])n=Ro(u.ids,t.ids),o.push({pos:u.pos,ids:n.tree}),s=s||n.conflicts,i=!0;else if(!0!==r){var l=u.pos<t.pos?u:t,f=u.pos<t.pos?t:u,d=f.pos-l.pos,h=[],p=[];for(p.push({ids:l.ids,diff:d,parent:null,parentIdx:null});p.length>0;){var m=p.pop();if(0!==m.diff)for(var v=m.ids[2],y=0,g=v.length;y<g;y++)p.push({ids:v[y],diff:m.diff-1,parent:m.ids,parentIdx:y});else m.ids[0]===f.ids[0]&&h.push(m)}var _=h[0];_?(n=Ro(_.ids,f.ids),_.parent[2][_.parentIdx]=n.tree,o.push({pos:l.pos,ids:l.ids}),s=s||n.conflicts,i=!0):o.push(u)}else o.push(u)}return i||o.push(t),o.sort(Co),{tree:o,conflicts:s||"internal_node"}}function Do(e,t,r){var n=qo(e,t),o=function(e,t){for(var r,n,o=Ao(e),s=0,i=o.length;s<i;s++){var a,c=o[s],u=c.ids;if(u.length>t){r||(r={});var l=u.length-t;a={pos:c.pos+l,ids:No(u,l)};for(var f=0;f<l;f++){var d=c.pos+f+"-"+u[f].id;r[d]=!0}}else a={pos:c.pos,ids:No(u,0)};n=n?qo(n,a,!0).tree:[a]}return r&&So(n,(function(e,t,n){delete r[t+"-"+n]})),{tree:n,revs:r?Object.keys(r):[]}}(n.tree,r);return{tree:o.tree,stemmedRevs:o.revs,conflicts:n.conflicts}}function Lo(e){return e.ids}function Mo(e,t){t||(t=Po(e));for(var r,n=t.substring(t.indexOf("-")+1),o=e.rev_tree.map(Lo);r=o.pop();){if(r[0]===n)return!!r[1].deleted;o=o.concat(r[2])}}function Vo(e){return"string"==typeof e&&e.startsWith("_local/")}function Uo(e,t,r){var n=[{rev:e._rev}];"all_docs"===r.style&&(n=Oo(t.rev_tree).map((function(e){return{rev:e.rev}})));var o={id:t.id,changes:n,doc:e};return Mo(t,e._rev)&&(o.deleted=!0),r.conflicts&&(o.doc._conflicts=xo(t),o.doc._conflicts.length||delete o.doc._conflicts),o}class Bo extends ln{constructor(e,t,r){super(),this.db=e;var n=(t=t?gn(t):{}).complete=_n(((t,r)=>{t?function(e,t){return"listenerCount"in e?e.listenerCount(t):ln.listenerCount(e,t)}(this,"error")>0&&this.emit("error",t):this.emit("complete",r),this.removeAllListeners(),e.removeListener("destroyed",o)}));r&&(this.on("complete",(function(e){r(null,e)})),this.on("error",r));const o=()=>{this.cancel()};e.once("destroyed",o),t.onChange=(e,t,r)=>{this.isCancelled||function(e,t,r,n){try{e.emit("change",t,r,n)}catch(e){xn("error",'Error in .on("change", function):',e)}}(this,e,t,r)};var s=new Promise((function(e,r){t.complete=function(t,n){t?r(t):e(n)}}));this.once("cancel",(function(){e.removeListener("destroyed",o),t.complete(null,{status:"cancelled"})})),this.then=s.then.bind(s),this.catch=s.catch.bind(s),this.then((function(e){n(null,e)}),n),e.taskqueue.isReady?this.validateChanges(t):e.taskqueue.addTask((e=>{e?t.complete(e):this.isCancelled?this.emit("cancel"):this.validateChanges(t)}))}cancel(){this.isCancelled=!0,this.db.taskqueue.isReady&&this.emit("cancel")}validateChanges(e){var t=e.complete;es._changesFilterPlugin?es._changesFilterPlugin.validate(e,(r=>{if(r)return t(r);this.doChanges(e)})):this.doChanges(e)}doChanges(e){var t=e.complete;if("live"in(e=gn(e))&&!("continuous"in e)&&(e.continuous=e.live),e.processChange=Uo,"latest"===e.since&&(e.since="now"),e.since||(e.since=0),"now"!==e.since){if(es._changesFilterPlugin){if(es._changesFilterPlugin.normalize(e),es._changesFilterPlugin.shouldFilter(this,e))return es._changesFilterPlugin.filter(this,e)}else["doc_ids","filter","selector","view"].forEach((function(t){t in e&&xn("warn",'The "'+t+'" option was passed in to changes/replicate, but pouchdb-changes-filter plugin is not installed, so it was ignored. Please install the plugin to enable filtering.')}));"descending"in e||(e.descending=!1),e.limit=0===e.limit?1:e.limit,e.complete=t;var r=this.db._changes(e);if(r&&"function"==typeof r.cancel){const e=this.cancel;this.cancel=(...t)=>{r.cancel(),e.apply(this,t)}}}else this.db.info().then((r=>{this.isCancelled?t(null,{status:"cancelled"}):(e.since=r.update_seq,this.doChanges(e))}),t)}}function zo(e,t){return function(r,n){r||n[0]&&n[0].error?((r=r||n[0]).docId=t,e(r)):e(null,n.length?n[0]:n)}}function Ko(e,t){if(e._id===t._id){return(e._revisions?e._revisions.start:0)-(t._revisions?t._revisions.start:0)}return e._id<t._id?-1:1}function Fo(e){var t=e._compactionQueue[0],r=t.opts,n=t.callback;e.get("_local/compaction").catch((function(){return!1})).then((function(t){t&&t.last_seq&&(r.last_seq=t.last_seq),e._compact(r,(function(t,r){t?n(t):n(null,r),On((function(){e._compactionQueue.shift(),e._compactionQueue.length&&Fo(e)}))}))}))}function Jo(e,t,r){return e.get("_local/purges").then((function(e){const n=e.purgeSeq+1;return e.purges.push({docId:t,rev:r,purgeSeq:n}),e.purges.length>self.purged_infos_limit&&e.purges.splice(0,e.purges.length-self.purged_infos_limit),e.purgeSeq=n,e})).catch((function(e){if(404!==e.status)throw e;return{_id:"_local/purges",purges:[{docId:t,rev:r,purgeSeq:0}],purgeSeq:0}})).then((function(t){return e.put(t)}))}function Go(e){return null===e||"object"!=typeof e||Array.isArray(e)}const Ho=/^\d+-[^-]*$/;function Wo(e){return"string"==typeof e&&Ho.test(e)}class Qo extends ln{_setup(){this.post=bn("post",(function(e,t,r){if("function"==typeof t&&(r=t,t={}),Go(e))return r(Hn(Kn));this.bulkDocs({docs:[e]},t,zo(r,e._id))})).bind(this),this.put=bn("put",(function(e,t,r){if("function"==typeof t&&(r=t,t={}),Go(e))return r(Hn(Kn));if(Yn(e._id),"_rev"in e&&!Wo(e._rev))return r(Hn(Jn));if(Vo(e._id)&&"function"==typeof this._putLocal)return e._deleted?this._removeLocal(e,r):this._putLocal(e,r);const n=r=>{"function"==typeof this._put&&!1!==t.new_edits?this._put(e,t,r):this.bulkDocs({docs:[e]},t,zo(r,e._id))};var o,s,i,a;t.force&&e._rev?(o=e._rev.split("-"),s=o[1],i=parseInt(o[0],10)+1,a=ko(),e._revisions={start:i,ids:[a,s]},e._rev=i+"-"+a,t.new_edits=!1,n((function(t){var n=t?null:{ok:!0,id:e._id,rev:e._rev};r(t,n)}))):n(r)})).bind(this),this.putAttachment=bn("putAttachment",(function(e,t,r,n,o){var s=this;function i(e){var r="_rev"in e?parseInt(e._rev,10):0;return e._attachments=e._attachments||{},e._attachments[t]={content_type:o,data:n,revpos:++r},s.put(e)}return"function"==typeof o&&(o=n,n=r,r=null),void 0===o&&(o=n,n=r,r=null),o||xn("warn","Attachment",t,"on document",e,"is missing content_type"),s.get(e).then((function(e){if(e._rev!==r)throw Hn(Rn);return i(e)}),(function(t){if(t.reason===Tn.message)return i({_id:e});throw t}))})).bind(this),this.removeAttachment=bn("removeAttachment",(function(e,t,r,n){this.get(e,((e,o)=>{if(e)n(e);else if(o._rev===r){if(!o._attachments)return n();delete o._attachments[t],0===Object.keys(o._attachments).length&&delete o._attachments,this.put(o,n)}else n(Hn(Rn))}))})).bind(this),this.remove=bn("remove",(function(e,t,r,n){var o;"string"==typeof t?(o={_id:e,_rev:t},"function"==typeof r&&(n=r,r={})):(o=e,"function"==typeof t?(n=t,r={}):(n=r,r=t)),(r=r||{}).was_delete=!0;var s={_id:o._id,_rev:o._rev||r.rev,_deleted:!0};if(Vo(s._id)&&"function"==typeof this._removeLocal)return this._removeLocal(o,n);this.bulkDocs({docs:[s]},r,zo(n,s._id))})).bind(this),this.revsDiff=bn("revsDiff",(function(e,t,r){"function"==typeof t&&(r=t,t={});var n=Object.keys(e);if(!n.length)return r(null,{});var o=0,s=new Map;function i(e,t){s.has(e)||s.set(e,{missing:[]}),s.get(e).missing.push(t)}n.forEach((function(t){this._getRevisionTree(t,(function(a,c){if(a&&404===a.status&&"missing"===a.message)s.set(t,{missing:e[t]});else{if(a)return r(a);!function(t,r){var n=e[t].slice(0);So(r,(function(e,r,o,s,a){var c=r+"-"+o,u=n.indexOf(c);-1!==u&&(n.splice(u,1),"available"!==a.status&&i(t,c))})),n.forEach((function(e){i(t,e)}))}(t,c)}if(++o===n.length){var u={};return s.forEach((function(e,t){u[t]=e})),r(null,u)}}))}),this)})).bind(this),this.bulkGet=bn("bulkGet",(function(e,t){Sn(this,e,t)})).bind(this),this.compactDocument=bn("compactDocument",(function(e,t,r){this._getRevisionTree(e,((n,o)=>{if(n)return r(n);var s=function(e){var t={},r=[];return So(e,(function(e,n,o,s){var i=n+"-"+o;return e&&(t[i]=0),void 0!==s&&r.push({from:s,to:i}),i})),r.reverse(),r.forEach((function(e){void 0===t[e.from]?t[e.from]=1+t[e.to]:t[e.from]=Math.min(t[e.from],1+t[e.to])})),t}(o),i=[],a=[];Object.keys(s).forEach((function(e){s[e]>t&&i.push(e)})),So(o,(function(e,t,r,n,o){var s=t+"-"+r;"available"===o.status&&-1!==i.indexOf(s)&&a.push(s)})),this._doCompaction(e,a,r)}))})).bind(this),this.compact=bn("compact",(function(e,t){"function"==typeof e&&(t=e,e={}),e=e||{},this._compactionQueue=this._compactionQueue||[],this._compactionQueue.push({opts:e,callback:t}),1===this._compactionQueue.length&&Fo(this)})).bind(this),this.get=bn("get",(function(e,t,r){if("function"==typeof t&&(r=t,t={}),t=t||{},"string"!=typeof e)return r(Hn(qn));if(Vo(e)&&"function"==typeof this._getLocal)return this._getLocal(e,r);var n=[];const o=()=>{var o=[],s=n.length;if(!s)return r(null,o);n.forEach((n=>{this.get(e,{rev:n,revs:t.revs,latest:t.latest,attachments:t.attachments,binary:t.binary},(function(e,t){if(e)o.push({missing:n});else{for(var i,a=0,c=o.length;a<c;a++)if(o[a].ok&&o[a].ok._rev===t._rev){i=!0;break}i||o.push({ok:t})}--s||r(null,o)}))}))};if(!t.open_revs)return this._get(e,t,((n,o)=>{if(n)return n.docId=e,r(n);var s=o.doc,i=o.metadata,a=o.ctx;if(t.conflicts){var c=xo(i);c.length&&(s._conflicts=c)}if(Mo(i,s._rev)&&(s._deleted=!0),t.revs||t.revs_info){for(var u=s._rev.split("-"),l=parseInt(u[0],10),f=u[1],d=Ao(i.rev_tree),h=null,p=0;p<d.length;p++){var m=d[p];const e=m.ids.findIndex((e=>e.id===f));(e===l-1||!h&&-1!==e)&&(h=m)}if(!h)return(n=new Error("invalid rev tree")).docId=e,r(n);const o=s._rev.split("-")[1],a=h.ids.findIndex((e=>e.id===o))+1;var v=h.ids.length-a;if(h.ids.splice(a,v),h.ids.reverse(),t.revs&&(s._revisions={start:h.pos+h.ids.length-1,ids:h.ids.map((function(e){return e.id}))}),t.revs_info){var y=h.pos+h.ids.length;s._revs_info=h.ids.map((function(e){return{rev:--y+"-"+e.id,status:e.opts.status}}))}}if(t.attachments&&s._attachments){var g=s._attachments,_=Object.keys(g).length;if(0===_)return r(null,s);Object.keys(g).forEach((e=>{this._getAttachment(s._id,e,g[e],{binary:t.binary,metadata:i,ctx:a},(function(t,n){var o=s._attachments[e];o.data=n,delete o.stub,delete o.length,--_||r(null,s)}))}))}else{if(s._attachments)for(var w in s._attachments)Object.prototype.hasOwnProperty.call(s._attachments,w)&&(s._attachments[w].stub=!0);r(null,s)}}));if("all"===t.open_revs)this._getRevisionTree(e,(function(e,t){if(e)return r(e);n=Oo(t).map((function(e){return e.rev})),o()}));else{if(!Array.isArray(t.open_revs))return r(Hn(Mn,"function_clause"));n=t.open_revs;for(var s=0;s<n.length;s++){if(!Wo(n[s]))return r(Hn(Jn))}o()}})).bind(this),this.getAttachment=bn("getAttachment",(function(e,t,r,n){r instanceof Function&&(n=r,r={}),this._get(e,r,((o,s)=>o?n(o):s.doc._attachments&&s.doc._attachments[t]?(r.ctx=s.ctx,r.binary=!0,r.metadata=s.metadata,void this._getAttachment(e,t,s.doc._attachments[t],r,n)):n(Hn(Tn))))})).bind(this),this.allDocs=bn("allDocs",(function(e,t){if("function"==typeof e&&(t=e,e={}),e.skip=void 0!==e.skip?e.skip:0,e.start_key&&(e.startkey=e.start_key),e.end_key&&(e.endkey=e.end_key),"keys"in e){if(!Array.isArray(e.keys))return t(new TypeError("options.keys must be an array"));var r=["startkey","endkey","key"].filter((function(t){return t in e}))[0];if(r)return void t(Hn(Un,"Query parameter `"+r+"` is not compatible with multi-get"));if(!Xn(this)&&(function(e){var t="limit"in e?e.keys.slice(e.skip,e.limit+e.skip):e.skip>0?e.keys.slice(e.skip):e.keys;e.keys=t,e.skip=0,delete e.limit,e.descending&&(t.reverse(),e.descending=!1)}(e),0===e.keys.length))return this._allDocs({limit:0},t)}return this._allDocs(e,t)})).bind(this),this.close=bn("close",(function(e){return this._closed=!0,this.emit("closed"),this._close(e)})).bind(this),this.info=bn("info",(function(e){this._info(((t,r)=>{if(t)return e(t);r.db_name=r.db_name||this.name,r.auto_compaction=!(!this.auto_compaction||Xn(this)),r.adapter=this.adapter,e(null,r)}))})).bind(this),this.id=bn("id",(function(e){return this._id(e)})).bind(this),this.bulkDocs=bn("bulkDocs",(function(e,t,r){if("function"==typeof t&&(r=t,t={}),t=t||{},Array.isArray(e)&&(e={docs:e}),!e||!e.docs||!Array.isArray(e.docs))return r(Hn(Nn));for(var n=0;n<e.docs.length;++n){const t=e.docs[n];if(Go(t))return r(Hn(Kn));if("_rev"in t&&!Wo(t._rev))return r(Hn(Jn))}var o;if(e.docs.forEach((function(e){e._attachments&&Object.keys(e._attachments).forEach((function(t){o=o||function(e){return"_"===e.charAt(0)&&e+" is not a valid attachment name, attachment names cannot start with '_'"}(t),e._attachments[t].content_type||xn("warn","Attachment",t,"on document",e._id,"is missing content_type")}))})),o)return r(Hn(zn,o));"new_edits"in t||(t.new_edits=!("new_edits"in e)||e.new_edits);var s=this;t.new_edits||Xn(s)||e.docs.sort(Ko),function(e){for(var t=0;t<e.length;t++){var r=e[t];if(r._deleted)delete r._attachments;else if(r._attachments)for(var n=Object.keys(r._attachments),o=0;o<n.length;o++){var s=n[o];r._attachments[s]=$n(r._attachments[s],["data","digest","content_type","length","revpos","stub"])}}}(e.docs);var i=e.docs.map((function(e){return e._id}));this._bulkDocs(e,t,(function(e,n){if(e)return r(e);if(t.new_edits||(n=n.filter((function(e){return e.error}))),!Xn(s))for(var o=0,a=n.length;o<a;o++)n[o].id=n[o].id||i[o];r(null,n)}))})).bind(this),this.registerDependentDatabase=bn("registerDependentDatabase",(function(e,t){var r=gn(this.__opts);this.__opts.view_adapter&&(r.adapter=this.__opts.view_adapter);var n=new this.constructor(e,r);ao(this,"_local/_pouch_dependentDbs",(function(t){return t.dependentDbs=t.dependentDbs||{},!t.dependentDbs[e]&&(t.dependentDbs[e]=!0,t)})).then((function(){t(null,{db:n})})).catch(t)})).bind(this),this.destroy=bn("destroy",(function(e,t){"function"==typeof e&&(t=e,e={});var r=!("use_prefix"in this)||this.use_prefix;const n=()=>{this._destroy(e,((e,r)=>{if(e)return t(e);this._destroyed=!0,this.emit("destroyed"),t(null,r||{ok:!0})}))};if(Xn(this))return n();this.get("_local/_pouch_dependentDbs",((e,o)=>{if(e)return 404!==e.status?t(e):n();var s=o.dependentDbs,i=this.constructor,a=Object.keys(s).map((e=>{var t=r?e.replace(new RegExp("^"+i.prefix),""):e;return new i(t,this.__opts).destroy()}));Promise.all(a).then(n,t)}))})).bind(this)}_compact(e,t){var r,n={return_docs:!1,last_seq:e.last_seq||0,since:e.last_seq||0},o=[],s=0;const i=e=>{this.activeTasks.update(r,{completed_items:++s}),o.push(this.compactDocument(e.id,0))},a=e=>{this.activeTasks.remove(r,e),t(e)},c=e=>{var n=e.last_seq;Promise.all(o).then((()=>ao(this,"_local/compaction",(e=>(!e.last_seq||e.last_seq<n)&&(e.last_seq=n,e))))).then((()=>{this.activeTasks.remove(r),t(null,{ok:!0})})).catch(a)};this.info().then((e=>{r=this.activeTasks.add({name:"database_compaction",total_items:e.update_seq-n.last_seq}),this.changes(n).on("change",i).on("complete",c).on("error",a)}))}changes(e,t){return"function"==typeof e&&(t=e,e={}),(e=e||{}).return_docs="return_docs"in e?e.return_docs:!e.live,new Bo(this,e,t)}type(){return"function"==typeof this._type?this._type():this.adapter}}Qo.prototype.purge=bn("_purge",(function(e,t,r){if(void 0===this._purge)return r(Hn(Mn,"Purge is not implemented in the "+this.adapter+" adapter."));var n=this;n._getRevisionTree(e,((o,s)=>{if(o)return r(o);if(!s)return r(Hn(Tn));let i;try{i=function(e,t){let r=[];const n=e.slice();let o;for(;o=n.pop();){const{pos:e,ids:s}=o,i=`${e}-${s[0]}`,a=s[2];if(r.push(i),i===t){if(0!==a.length)throw new Error("The requested revision is not a leaf");return r.reverse()}(0===a.length||a.length>1)&&(r=[]);for(let t=0,r=a.length;t<r;t++)n.push({pos:e+1,ids:a[t]})}if(0===r.length)throw new Error("The requested revision does not exist");return r.reverse()}(s,t)}catch(o){return r(o.message||o)}n._purge(e,i,((o,s)=>{if(o)return r(o);Jo(n,e,t).then((function(){return r(null,s)}))}))}))}));class Yo{constructor(){this.isReady=!1,this.failed=!1,this.queue=[]}execute(){var e;if(this.failed)for(;e=this.queue.shift();)e(this.failed);else for(;e=this.queue.shift();)e()}fail(e){this.failed=e,this.execute()}ready(e){this.isReady=!0,this.db=e,this.execute()}addTask(e){this.queue.push(e),this.failed&&this.execute()}}function Xo(e,t){let r=function(...e){if(!(this instanceof r))return new r(...e);t.apply(this,e)};var n,o;return o=e,(n=r).prototype=Object.create(o.prototype,{constructor:{value:n}}),r}class Zo extends Qo{constructor(e,t){super(),this._setup(e,t)}_setup(e,t){if(super._setup(),t=t||{},e&&"object"==typeof e&&(e=(t=e).name,delete t.name),void 0===t.deterministic_revs&&(t.deterministic_revs=!0),this.__opts=t=gn(t),this.auto_compaction=t.auto_compaction,this.purged_infos_limit=t.purged_infos_limit||1e3,this.prefix=es.prefix,"string"!=typeof e)throw new Error("Missing/invalid DB name");var r=function(e,t){var r=e.match(/([a-z-]*):\/\/(.*)/);if(r)return{name:/https?/.test(r[1])?r[1]+"://"+r[2]:r[2],adapter:r[1]};var n=es.adapters,o=es.preferredAdapters,s=es.prefix,i=t.adapter;if(!i)for(var a=0;a<o.length&&"idb"===(i=o[a])&&"websql"in n&&jn()&&localStorage["_pouch__websqldb_"+s+e];++a)xn("log",'PouchDB is downgrading "'+e+'" to WebSQL to avoid data loss, because it was already opened with WebSQL.');var c=n[i];return{name:c&&"use_prefix"in c&&!c.use_prefix?e:s+e,adapter:i}}((t.prefix||"")+e,t);if(t.name=r.name,t.adapter=t.adapter||r.adapter,this.name=e,this._adapter=t.adapter,es.emit("debug",["adapter","Picked adapter: ",t.adapter]),!es.adapters[t.adapter]||!es.adapters[t.adapter].valid())throw new Error("Invalid Adapter: "+t.adapter);if(t.view_adapter&&(!es.adapters[t.view_adapter]||!es.adapters[t.view_adapter].valid()))throw new Error("Invalid View Adapter: "+t.view_adapter);this.taskqueue=new Yo,this.adapter=t.adapter,es.adapters[t.adapter].call(this,t,(e=>{if(e)return this.taskqueue.fail(e);!function(e){function t(t){e.removeListener("closed",r),t||e.constructor.emit("destroyed",e.name)}function r(){e.removeListener("destroyed",t),e.constructor.emit("unref",e)}e.once("destroyed",t),e.once("closed",r),e.constructor.emit("ref",e)}(this),this.emit("created",this),es.emit("created",this.name),this.taskqueue.ready(this)}))}}const es=Xo(Zo,(function(e,t){Zo.prototype._setup.call(this,e,t)}));var ts=fetch,rs=Headers;es.adapters={},es.preferredAdapters=[],es.prefix="_pouch_";var ns=new ln;!function(e){Object.keys(ln.prototype).forEach((function(t){"function"==typeof ln.prototype[t]&&(e[t]=ns[t].bind(ns))}));var t=e._destructionListeners=new Map;e.on("ref",(function(e){t.has(e.name)||t.set(e.name,[]),t.get(e.name).push(e)})),e.on("unref",(function(e){if(t.has(e.name)){var r=t.get(e.name),n=r.indexOf(e);n<0||(r.splice(n,1),r.length>1?t.set(e.name,r):t.delete(e.name))}})),e.on("destroyed",(function(e){if(t.has(e)){var r=t.get(e);t.delete(e),r.forEach((function(e){e.emit("destroyed",!0)}))}}))}(es),es.adapter=function(e,t,r){t.valid()&&(es.adapters[e]=t,r&&es.preferredAdapters.push(e))},es.plugin=function(e){if("function"==typeof e)e(es);else{if("object"!=typeof e||0===Object.keys(e).length)throw new Error('Invalid plugin: got "'+e+'", expected an object or a function');Object.keys(e).forEach((function(t){es.prototype[t]=e[t]}))}return this.__defaults&&(es.__defaults=Object.assign({},this.__defaults)),es},es.defaults=function(e){let t=Xo(es,(function(e,r){r=r||{},e&&"object"==typeof e&&(e=(r=e).name,delete r.name),r=Object.assign({},t.__defaults,r),es.call(this,e,r)}));return t.preferredAdapters=es.preferredAdapters.slice(),Object.keys(es).forEach((function(e){e in t||(t[e]=es[e])})),t.__defaults=Object.assign({},this.__defaults,e),t},es.fetch=function(e,t){return ts(e,t)},es.prototype.activeTasks=es.activeTasks=new class{constructor(){this.tasks={}}list(){return Object.values(this.tasks)}add(e){const t=nn();return this.tasks[t]={id:t,name:e.name,total_items:e.total_items,created_at:(new Date).toJSON()},t}get(e){return this.tasks[e]}remove(e,t){return delete this.tasks[e],this.tasks}update(e,t){const r=this.tasks[e];if(void 0!==r){const n={id:r.id,name:r.name,created_at:r.created_at,total_items:t.total_items||r.total_items,completed_items:t.completed_items||r.completed_items,updated_at:(new Date).toJSON()};this.tasks[e]=n}return this.tasks}};function os(e,t){for(var r=e,n=0,o=t.length;n<o;n++){if(!(r=r[t[n]]))break}return r}function ss(e){for(var t=[],r="",n=0,o=e.length;n<o;n++){var s=e[n];n>0&&"\\"===e[n-1]&&("$"===s||"."===s)?r=r.substring(0,r.length-1)+s:"."===s?(t.push(r),r=""):r+=s}return t.push(r),t}var is=["$or","$nor","$not"];function as(e){return is.indexOf(e)>-1}function cs(e){return Object.keys(e)[0]}function us(e){var t={},r={$or:!0,$nor:!0};return e.forEach((function(e){Object.keys(e).forEach((function(n){var o=e[n];if("object"!=typeof o&&(o={$eq:o}),as(n))if(o instanceof Array){if(r[n])return r[n]=!1,void(t[n]=o);var s=[];t[n].forEach((function(e){Object.keys(o).forEach((function(t){var r=o[t],n=Math.max(Object.keys(e).length,Object.keys(r).length),i=us([e,r]);Object.keys(i).length<=n||s.push(i)}))})),t[n]=s}else t[n]=us([o]);else{var i=t[n]=t[n]||{};Object.keys(o).forEach((function(e){var t=o[e];return"$gt"===e||"$gte"===e?function(e,t,r){if(void 0!==r.$eq)return;void 0!==r.$gte?"$gte"===e?t>r.$gte&&(r.$gte=t):t>=r.$gte&&(delete r.$gte,r.$gt=t):void 0!==r.$gt?"$gte"===e?t>r.$gt&&(delete r.$gt,r.$gte=t):t>r.$gt&&(r.$gt=t):r[e]=t}(e,t,i):"$lt"===e||"$lte"===e?function(e,t,r){if(void 0!==r.$eq)return;void 0!==r.$lte?"$lte"===e?t<r.$lte&&(r.$lte=t):t<=r.$lte&&(delete r.$lte,r.$lt=t):void 0!==r.$lt?"$lte"===e?t<r.$lt&&(delete r.$lt,r.$lte=t):t<r.$lt&&(r.$lt=t):r[e]=t}(e,t,i):"$ne"===e?function(e,t){"$ne"in t?t.$ne.push(e):t.$ne=[e]}(t,i):"$eq"===e?function(e,t){delete t.$gt,delete t.$gte,delete t.$lt,delete t.$lte,delete t.$ne,t.$eq=e}(t,i):"$regex"===e?function(e,t){"$regex"in t?t.$regex.push(e):t.$regex=[e]}(t,i):void(i[e]=t)}))}}))})),t}function ls(e){for(var t in e){if(Array.isArray(e))for(var r in e)e[r].$and&&(e[r]=us(e[r].$and));var n=e[t];"object"==typeof n&&ls(n)}return e}function fs(e,t){for(var r in e){"$and"===r&&(t=!0);var n=e[r];"object"==typeof n&&(t=fs(n,t))}return t}function ds(e){var t=gn(e);fs(t,!1)&&"$and"in(t=ls(t))&&(t=us(t.$and)),["$or","$nor"].forEach((function(e){e in t&&t[e].forEach((function(e){for(var t=Object.keys(e),r=0;r<t.length;r++){var n=t[r],o=e[n];"object"==typeof o&&null!==o||(e[n]={$eq:o})}}))})),"$not"in t&&(t.$not=us([t.$not]));for(var r=Object.keys(t),n=0;n<r.length;n++){var o=r[n],s=t[o];"object"==typeof s&&null!==s||(s={$eq:s}),t[o]=s}return hs(t),t}function hs(e){Object.keys(e).forEach((function(t){var r=e[t];Array.isArray(r)?r.forEach((function(e){e&&"object"==typeof e&&hs(e)})):"$ne"===t?e.$ne=[r]:"$regex"===t?e.$regex=[r]:r&&"object"==typeof r&&hs(r)}))}var ps=-324;function ms(e,t){if(e===t)return 0;e=vs(e),t=vs(t);var r=bs(e),n=bs(t);if(r-n!=0)return r-n;switch(typeof e){case"number":return e-t;case"boolean":return e<t?-1:1;case"string":return function(e,t){return e===t?0:e>t?1:-1}(e,t)}return Array.isArray(e)?function(e,t){for(var r=Math.min(e.length,t.length),n=0;n<r;n++){var o=ms(e[n],t[n]);if(0!==o)return o}return e.length===t.length?0:e.length>t.length?1:-1}(e,t):function(e,t){for(var r=Object.keys(e),n=Object.keys(t),o=Math.min(r.length,n.length),s=0;s<o;s++){var i=ms(r[s],n[s]);if(0!==i)return i;if(0!==(i=ms(e[r[s]],t[n[s]])))return i}return r.length===n.length?0:r.length>n.length?1:-1}(e,t)}function vs(e){switch(typeof e){case"undefined":return null;case"number":return e===1/0||e===-1/0||isNaN(e)?null:e;case"object":var t=e;if(Array.isArray(e)){var r=e.length;e=new Array(r);for(var n=0;n<r;n++)e[n]=vs(t[n])}else{if(e instanceof Date)return e.toJSON();if(null!==e)for(var o in e={},t)if(Object.prototype.hasOwnProperty.call(t,o)){var s=t[o];void 0!==s&&(e[o]=vs(s))}}}return e}function ys(e){if(null!==e)switch(typeof e){case"boolean":return e?1:0;case"number":return function(e){if(0===e)return"1";var t=e.toExponential().split(/e\+?/),r=parseInt(t[1],10),n=e<0,o=n?"0":"2",s=(i=((n?-r:r)-ps).toString(),a="0",c=3,function(e,t,r){for(var n="",o=r-e.length;n.length<o;)n+=t;return n}(i,a,c)+i);var i,a,c;o+=""+s;var u=Math.abs(parseFloat(t[0]));n&&(u=10-u);var l=u.toFixed(20);return l=l.replace(/\.?0+$/,""),o+=""+l,o}(e);case"string":return e.replace(/\u0002/g,"").replace(/\u0001/g,"").replace(/\u0000/g,"");case"object":var t=Array.isArray(e),r=t?e:Object.keys(e),n=-1,o=r.length,s="";if(t)for(;++n<o;)s+=gs(r[n]);else for(;++n<o;){var i=r[n];s+=gs(i)+gs(e[i])}return s}return""}function gs(e){return bs(e=vs(e))+""+ys(e)+"\0"}function _s(e,t){var r,n=t;if("1"===e[t])r=0,t++;else{var o="0"===e[t];t++;var s="",i=e.substring(t,t+3),a=parseInt(i,10)+ps;for(o&&(a=-a),t+=3;;){var c=e[t];if("\0"===c)break;s+=c,t++}r=1===(s=s.split(".")).length?parseInt(s,10):parseFloat(s[0]+"."+s[1]),o&&(r-=10),0!==a&&(r=parseFloat(r+"e"+a))}return{num:r,length:t-n}}function ws(e,t){var r=e.pop();if(t.length){var n=t[t.length-1];r===n.element&&(t.pop(),n=t[t.length-1]);var o=n.element,s=n.index;if(Array.isArray(o))o.push(r);else if(s===e.length-2){o[e.pop()]=r}else e.push(r)}}function bs(e){var t=["boolean","number","string","object"].indexOf(typeof e);return~t?null===e?1:Array.isArray(e)?5:t<3?t+2:t+3:Array.isArray(e)?5:void 0}function $s(e,t,r){if(e=e.filter((function(e){return ks(e.doc,t.selector,r)})),t.sort){var n=function(e){function t(t){return e.map((function(e){var r=ss(cs(e));return os(t,r)}))}return function(e,r){var n,o,s=ms(t(e.doc),t(r.doc));return 0!==s?s:(n=e.doc._id)<(o=r.doc._id)?-1:n>o?1:0}}(t.sort);e=e.sort(n),"string"!=typeof t.sort[0]&&"desc"===(o=t.sort[0])[cs(o)]&&(e=e.reverse())}var o;if("limit"in t||"skip"in t){var s=t.skip||0,i=("limit"in t?t.limit:e.length)+s;e=e.slice(s,i)}return e}function ks(e,t,r){return r.every((function(r){var n=t[r],o=ss(r),s=os(e,o);return as(r)?function(e,t,r){if("$or"===e)return t.some((function(e){return ks(r,e,Object.keys(e))}));if("$not"===e)return!ks(r,t,Object.keys(t));return!t.find((function(e){return ks(r,e,Object.keys(e))}))}(r,n,e):Es(n,e,o,s)}))}function Es(e,t,r,n){return!e||("object"==typeof e?Object.keys(e).every((function(o){var s=e[o];if(0===o.indexOf("$"))return Ps(o,t,s,r,n);var i=ss(o);if(void 0===n&&"object"!=typeof s&&i.length>0)return!1;var a=os(n,i);return"object"==typeof s?Es(s,t,r,a):Ps("$eq",t,s,i,a)})):e===n)}function Ps(e,t,r,n,o){if(!xs[e])throw new Error('unknown operator "'+e+'" - should be one of $eq, $lte, $lt, $gt, $gte, $exists, $ne, $in, $nin, $size, $mod, $regex, $elemMatch, $type, $allMatch or $all');return xs[e](t,r,n,o)}function Ss(e){return null!=e}function js(e){return void 0!==e}function Os(e,t){return t.some((function(t){return e instanceof Array?e.some((function(e){return 0===ms(t,e)})):0===ms(t,e)}))}var xs={$elemMatch:function(e,t,r,n){return!!Array.isArray(n)&&(0!==n.length&&("object"==typeof n[0]&&null!==n[0]?n.some((function(e){return ks(e,t,Object.keys(t))})):n.some((function(n){return Es(t,e,r,n)}))))},$allMatch:function(e,t,r,n){return!!Array.isArray(n)&&(0!==n.length&&("object"==typeof n[0]&&null!==n[0]?n.every((function(e){return ks(e,t,Object.keys(t))})):n.every((function(n){return Es(t,e,r,n)}))))},$eq:function(e,t,r,n){return js(n)&&0===ms(n,t)},$gte:function(e,t,r,n){return js(n)&&ms(n,t)>=0},$gt:function(e,t,r,n){return js(n)&&ms(n,t)>0},$lte:function(e,t,r,n){return js(n)&&ms(n,t)<=0},$lt:function(e,t,r,n){return js(n)&&ms(n,t)<0},$exists:function(e,t,r,n){return t?js(n):!js(n)},$mod:function(e,t,r,n){return Ss(n)&&function(e,t){return"number"==typeof e&&parseInt(e,10)===e&&e%t[0]===t[1]}(n,t)},$ne:function(e,t,r,n){return t.every((function(e){return 0!==ms(n,e)}))},$in:function(e,t,r,n){return Ss(n)&&Os(n,t)},$nin:function(e,t,r,n){return Ss(n)&&!Os(n,t)},$size:function(e,t,r,n){return Ss(n)&&Array.isArray(n)&&function(e,t){return e.length===t}(n,t)},$all:function(e,t,r,n){return Array.isArray(n)&&function(e,t){return t.every((function(t){return e.some((function(e){return 0===ms(t,e)}))}))}(n,t)},$regex:function(e,t,r,n){return Ss(n)&&"string"==typeof n&&t.every((function(e){return function(e,t){return new RegExp(t).test(e)}(n,e)}))},$type:function(e,t,r,n){return function(e,t){switch(t){case"null":return null===e;case"boolean":return"boolean"==typeof e;case"number":return"number"==typeof e;case"string":return"string"==typeof e;case"array":return e instanceof Array;case"object":return"[object Object]"==={}.toString.call(e)}}(n,t)}};function As(e,t){if(e.selector&&e.filter&&"_selector"!==e.filter){var r="string"==typeof e.filter?e.filter:"function";return t(new Error('selector invalid for filter "'+r+'"'))}t()}function Cs(e){e.view&&!e.filter&&(e.filter="_view"),e.selector&&!e.filter&&(e.filter="_selector"),e.filter&&"string"==typeof e.filter&&("_view"===e.filter?e.view=eo(e.view):e.filter=eo(e.filter))}function Is(e,t){return t.filter&&"string"==typeof t.filter&&!t.doc_ids&&!Xn(e.db)}function Ns(e,t){var r=t.complete;if("_view"===t.filter){if(!t.view||"string"!=typeof t.view){var n=Hn(zn,"`view` filter parameter not found or invalid.");return r(n)}var o=Zn(t.view);e.db.get("_design/"+o[0],(function(n,s){if(e.isCancelled)return r(null,{status:"cancelled"});if(n)return r(Wn(n));var i=s&&s.views&&s.views[o[1]]&&s.views[o[1]].map;if(!i)return r(Hn(Tn,s.views?"missing json key: "+o[1]:"missing json key: views"));t.filter=io(["return function(doc) {",' "use strict";'," var emitted = false;"," var emit = function (a, b) {"," emitted = true;"," };"," var view = "+i+";"," view(doc);"," if (emitted) {"," return true;"," }","};"].join("\n"),{}),e.doChanges(t)}))}else if(t.selector)t.filter=function(e){return function(e,t){if("object"!=typeof t)throw new Error("Selector error: expected a JSON object");var r=$s([{doc:e}],{selector:t=ds(t)},Object.keys(t));return r&&1===r.length}(e,t.selector)},e.doChanges(t);else{var s=Zn(t.filter);e.db.get("_design/"+s[0],(function(n,o){if(e.isCancelled)return r(null,{status:"cancelled"});if(n)return r(Wn(n));var i=o&&o.filters&&o.filters[s[1]];if(!i)return r(Hn(Tn,o&&o.filters?"missing json key: "+s[1]:"missing json key: filters"));t.filter=io('"use strict";\nreturn '+i+";",{}),e.doChanges(t)}))}}function Ts(e){return e.reduce((function(e,t){return e[t]=!0,e}),{})}es.plugin((function(e){e._changesFilterPlugin={validate:As,normalize:Cs,shouldFilter:Is,filter:Ns}})),es.version="9.0.0";var Rs=Ts(["_id","_rev","_access","_attachments","_deleted","_revisions","_revs_info","_conflicts","_deleted_conflicts","_local_seq","_rev_tree","_replication_id","_replication_state","_replication_state_time","_replication_state_reason","_replication_stats","_removed"]),qs=Ts(["_access","_attachments","_replication_id","_replication_state","_replication_state_time","_replication_state_reason","_replication_stats"]);function Ds(e){if(!/^\d+-/.test(e))return Hn(Jn);var t=e.indexOf("-"),r=e.substring(0,t),n=e.substring(t+1);return{prefix:parseInt(r,10),id:n}}function Ls(e,t,r){var n,o,s;r||(r={deterministic_revs:!0});var i={status:"available"};if(e._deleted&&(i.deleted=!0),t)if(e._id||(e._id=Eo()),o=ko(e,r.deterministic_revs),e._rev){if((s=Ds(e._rev)).error)return s;e._rev_tree=[{pos:s.prefix,ids:[s.id,{status:"missing"},[[o,i,[]]]]}],n=s.prefix+1}else e._rev_tree=[{pos:1,ids:[o,i,[]]}],n=1;else if(e._revisions&&(e._rev_tree=function(e,t){for(var r=e.start-e.ids.length+1,n=e.ids,o=[n[0],t,[]],s=1,i=n.length;s<i;s++)o=[n[s],{status:"missing"},[o]];return[{pos:r,ids:o}]}(e._revisions,i),n=e._revisions.start,o=e._revisions.ids[0]),!e._rev_tree){if((s=Ds(e._rev)).error)return s;n=s.prefix,o=s.id,e._rev_tree=[{pos:n,ids:[o,i,[]]}]}Yn(e._id),e._rev=n+"-"+o;var a={metadata:{},data:{}};for(var c in e)if(Object.prototype.hasOwnProperty.call(e,c)){var u="_"===c[0];if(u&&!Rs[c]){var l=Hn(Bn,c);throw l.message=Bn.message+": "+c,l}u&&!qs[c]?a.metadata[c.slice(1)]=e[c]:a.data[c]=e[c]}return a}function Ms(e,t,r){var n=function(e){try{return co(e)}catch(e){return{error:Hn(Vn,"Attachment is not a valid base64 string")}}}(e.data);if(n.error)return r(n.error);e.length=n.length,e.data="blob"===t?ho(n,e.content_type):"base64"===t?uo(n):n,bo(n,(function(t){e.digest="md5-"+t,r()}))}function Vs(e,t,r){if(e.stub)return r();"string"==typeof e.data?Ms(e,t,r):function(e,t,r){bo(e.data,(function(n){e.digest="md5-"+n,e.length=e.data.size||e.data.length||0,"binary"===t?vo(e.data,(function(t){e.data=t,r()})):"base64"===t?yo(e.data,(function(t){e.data=t,r()})):r()}))}(e,t,r)}function Us(e,t,r,n,o,s,i,a){if(function(e,t){for(var r,n=e.slice(),o=t.split("-"),s=parseInt(o[0],10),i=o[1];r=n.pop();){if(r.pos===s&&r.ids[0]===i)return!0;for(var a=r.ids[2],c=0,u=a.length;c<u;c++)n.push({pos:r.pos+1,ids:a[c]})}return!1}(t.rev_tree,r.metadata.rev)&&!a)return n[o]=r,s();var c=t.winningRev||Po(t),u="deleted"in t?t.deleted:Mo(t,c),l="deleted"in r.metadata?r.metadata.deleted:Mo(r.metadata),f=/^1-/.test(r.metadata.rev);if(u&&!l&&a&&f){var d=r.data;d._rev=c,d._id=r.metadata.id,r=Ls(d,a)}var h=Do(t.rev_tree,r.metadata.rev_tree[0],e);if(a&&(u&&l&&"new_leaf"!==h.conflicts||!u&&"new_leaf"!==h.conflicts||u&&!l&&"new_branch"===h.conflicts)){var p=Hn(Rn);return n[o]=p,s()}var m=r.metadata.rev;r.metadata.rev_tree=h.tree,r.stemmedRevs=h.stemmedRevs||[],t.rev_map&&(r.metadata.rev_map=t.rev_map);var v=Po(r.metadata),y=Mo(r.metadata,v),g=u===y?0:u<y?-1:1;i(r,v,y,m===v?y:Mo(r.metadata,m),!0,g,o,s)}function Bs(e,t,r,n,o,s,i,a,c){e=e||1e3;var u=a.new_edits,l=new Map,f=0,d=t.length;function h(){++f===d&&c&&c()}t.forEach((function(e,t){if(e._id&&Vo(e._id)){var n=e._deleted?"_removeLocal":"_putLocal";r[n](e,{ctx:o},(function(e,r){s[t]=e||r,h()}))}else{var i=e.metadata.id;l.has(i)?(d--,l.get(i).push([e,t])):l.set(i,[[e,t]])}})),l.forEach((function(t,r){var o=0;function c(){++o<t.length?l():h()}function l(){var l=t[o],f=l[0],d=l[1];if(n.has(r))Us(e,n.get(r),f,s,d,c,i,u);else{var h=Do([],f.metadata.rev_tree[0],e);f.metadata.rev_tree=h.tree,f.stemmedRevs=h.stemmedRevs||[],function(e,t,r){var n=Po(e.metadata),o=Mo(e.metadata,n);if("was_delete"in a&&o)return s[t]=Hn(Tn,"deleted"),r();if(u&&function(e){return"missing"===e.metadata.rev_tree[0].ids[1].status}(e)){var c=Hn(Rn);return s[t]=c,r()}i(e,n,o,o,!1,o?0:1,t,r)}(f,d,c)}}l()}))}var zs="document-store",Ks="by-sequence",Fs="attach-store",Js="attach-seq-store",Gs="meta-store",Hs="local-store",Ws="detect-blob-support";function Qs(e){try{return JSON.stringify(e)}catch(t){return cn.stringify(e)}}function Ys(e){return function(t){var r="unknown_error";t.target&&t.target.error&&(r=t.target.error.name||t.target.error.message),e(Hn(Fn,r,t.type))}}function Xs(e,t,r){return{data:Qs(e),winningRev:t,deletedOrLocal:r?"1":"0",seq:e.seq,id:e.id}}function Zs(e){if(!e)return null;var t=function(e){try{return JSON.parse(e)}catch(t){return cn.parse(e)}}(e.data);return t.winningRev=e.winningRev,t.deleted="1"===e.deletedOrLocal,t.seq=e.seq,t}function ei(e){if(!e)return e;var t=e._doc_id_rev.lastIndexOf(":");return e._id=e._doc_id_rev.substring(0,t-1),e._rev=e._doc_id_rev.substring(t+1),delete e._doc_id_rev,e}function ti(e,t,r,n){r?n(e?"string"!=typeof e?e:po(e,t):lo([""],{type:t})):e?"string"!=typeof e?mo(e,(function(e){n(uo(e))})):n(e):n("")}function ri(e,t,r,n){var o=Object.keys(e._attachments||{});if(!o.length)return n&&n();var s=0;function i(){++s===o.length&&n&&n()}o.forEach((function(n){t.attachments&&t.include_docs?function(e,t){var n=e._attachments[t],o=n.digest;r.objectStore(Fs).get(o).onsuccess=function(e){n.body=e.target.result.body,i()}}(e,n):(e._attachments[n].stub=!0,i())}))}function ni(e,t){return Promise.all(e.map((function(e){if(e.doc&&e.doc._attachments){var r=Object.keys(e.doc._attachments);return Promise.all(r.map((function(r){var n=e.doc._attachments[r];if("body"in n){var o=n.body,s=n.content_type;return new Promise((function(i){ti(o,s,t,(function(t){e.doc._attachments[r]=Object.assign($n(n,["digest","content_type"]),{data:t}),i()}))}))}})))}})))}function oi(e,t,r){var n=[],o=r.objectStore(Ks),s=r.objectStore(Fs),i=r.objectStore(Js),a=e.length;function c(){--a||function(){if(!n.length)return;n.forEach((function(e){i.index("digestSeq").count(IDBKeyRange.bound(e+"::",e+"::",!1,!1)).onsuccess=function(t){t.target.result||s.delete(e)}}))}()}e.forEach((function(e){var r=o.index("_doc_id_rev"),s=t+"::"+e;r.getKey(s).onsuccess=function(e){var t=e.target.result;if("number"!=typeof t)return c();o.delete(t),i.index("seq").openCursor(IDBKeyRange.only(t)).onsuccess=function(e){var t=e.target.result;if(t){var r=t.value.digestSeq.split("::")[0];n.push(r),i.delete(t.primaryKey),t.continue()}else c()}}}))}function si(e,t,r){try{return{txn:e.transaction(t,r)}}catch(e){return{error:e}}}var ii=new class extends ln{constructor(){super(),this._listeners={},jn()&&addEventListener("storage",(e=>{this.emit(e.key)}))}addListener(e,t,r,n){if(!this._listeners[t]){var o=!1,s=this;this._listeners[t]=i,this.on(e,i)}function i(){if(s._listeners[t])if(o)o="waiting";else{o=!0;var e=$n(n,["style","include_docs","attachments","conflicts","filter","doc_ids","view","since","query_params","binary","return_docs"]);r.changes(e).on("change",(function(e){e.seq>n.since&&!n.cancelled&&(n.since=e.seq,n.onChange(e))})).on("complete",(function(){"waiting"===o&&On(i),o=!1})).on("error",(function(){o=!1}))}}}removeListener(e,t){t in this._listeners&&(super.removeListener(e,this._listeners[t]),delete this._listeners[t])}notifyLocalWindows(e){jn()&&(localStorage[e]="a"===localStorage[e]?"b":"a")}notify(e){this.emit(e),this.notifyLocalWindows(e)}};function ai(e,t,r,n,o,s){for(var i,a,c,u,l,f,d,h,p=t.docs,m=0,v=p.length;m<v;m++){var y=p[m];y._id&&Vo(y._id)||(y=p[m]=Ls(y,r.new_edits,e)).error&&!d&&(d=y)}if(d)return s(d);var g=!1,_=0,w=new Array(p.length),b=new Map,$=!1,k=n._meta.blobSupport?"blob":"base64";function E(){g=!0,P()}function P(){h&&g&&(h.docCount+=_,f.put(h))}function S(){$||(ii.notify(n._meta.name),s(null,w))}function j(e,t,r,n,o,s,i,a){e.metadata.winningRev=t,e.metadata.deleted=r;var c=e.data;if(c._id=e.metadata.id,c._rev=e.metadata.rev,n&&(c._deleted=!0),c._attachments&&Object.keys(c._attachments).length)return function(e,t,r,n,o,s){var i=e.data,a=0,c=Object.keys(i._attachments);function l(){a===c.length&&O(e,t,r,n,o,s)}function f(){a++,l()}c.forEach((function(r){var n=e.data._attachments[r];if(n.stub)a++,l();else{var o=n.data;delete n.data,n.revpos=parseInt(t,10),function(e,t,r){var n=u.count(e);n.onsuccess=function(n){if(n.target.result)return r();var o={digest:e,body:t};u.put(o).onsuccess=r}}(n.digest,o,f)}}))}(e,t,r,o,i,a);_+=s,P(),O(e,t,r,o,i,a)}function O(e,t,r,o,s,u){var f=e.data,d=e.metadata;function h(s){var c=e.stemmedRevs||[];o&&n.auto_compaction&&(c=c.concat(function(e){var t=[];return So(e.rev_tree,(function(e,r,n,o,s){"available"!==s.status||e||(t.push(r+"-"+n),s.status="missing")})),t}(e.metadata))),c&&c.length&&oi(c,e.metadata.id,i),d.seq=s.target.result;var u=Xs(d,t,r);a.put(u).onsuccess=p}function p(){w[s]={ok:!0,id:d.id,rev:d.rev},b.set(e.metadata.id,e.metadata),function(e,t,r){var n=0,o=Object.keys(e.data._attachments||{});if(!o.length)return r();function s(){++n===o.length&&r()}function i(r){var n=e.data._attachments[r].digest,o=l.put({seq:t,digestSeq:n+"::"+t});o.onsuccess=s,o.onerror=function(e){e.preventDefault(),e.stopPropagation(),s()}}for(var a=0;a<o.length;a++)i(o[a])}(e,d.seq,u)}f._doc_id_rev=d.id+"::"+d.rev,delete f._id,delete f._rev;var m=c.put(f);m.onsuccess=h,m.onerror=function(e){e.preventDefault(),e.stopPropagation(),c.index("_doc_id_rev").getKey(f._doc_id_rev).onsuccess=function(e){c.put(f,e.target.result).onsuccess=h}}}!function(e,t,r){if(!e.length)return r();var n,o=0;function s(){o++,e.length===o&&(n?r(n):r())}e.forEach((function(e){var r=e.data&&e.data._attachments?Object.keys(e.data._attachments):[],o=0;if(!r.length)return s();function i(e){n=e,++o===r.length&&s()}for(var a in e.data._attachments)Object.prototype.hasOwnProperty.call(e.data._attachments,a)&&Vs(e.data._attachments[a],t,i)}))}(p,k,(function(t){if(t)return s(t);!function(){var t=si(o,[zs,Ks,Fs,Hs,Js,Gs],"readwrite");if(t.error)return s(t.error);(i=t.txn).onabort=Ys(s),i.ontimeout=Ys(s),i.oncomplete=S,a=i.objectStore(zs),c=i.objectStore(Ks),u=i.objectStore(Fs),l=i.objectStore(Js),(f=i.objectStore(Gs)).get(Gs).onsuccess=function(e){h=e.target.result,P()},function(e){var t=[];if(p.forEach((function(e){e.data&&e.data._attachments&&Object.keys(e.data._attachments).forEach((function(r){var n=e.data._attachments[r];n.stub&&t.push(n.digest)}))})),!t.length)return e();var r,n=0;function o(){++n===t.length&&e(r)}t.forEach((function(e){!function(e,t){var r=u.get(e);r.onsuccess=function(r){if(r.target.result)t();else{var n=Hn(Gn,"unknown stub attachment with digest "+e);n.status=412,t(n)}}}(e,(function(e){e&&!r&&(r=e),o()}))}))}((function(t){if(t)return $=!0,s(t);!function(){if(!p.length)return;var t=0;function o(){++t===p.length&&Bs(e.revs_limit,p,n,b,i,w,j,r,E)}function s(e){var t=Zs(e.target.result);t&&b.set(t.id,t),o()}for(var c=0,u=p.length;c<u;c++){var l=p[c];if(l._id&&Vo(l._id))o();else a.get(l.metadata.id).onsuccess=s}}()}))}()}))}function ci(e,t,r,n,o){var s,i,a;function c(e){i=e.target.result,s&&o(s,i,a)}function u(e){s=e.target.result,i&&o(s,i,a)}function l(e){var t=e.target.result;if(!t)return o();o([t.key],[t.value],t)}-1===n&&(n=1e3),"function"==typeof e.getAll&&"function"==typeof e.getAllKeys&&n>1&&!r?(a={continue:function(){if(!s.length)return o();var r,a=s[s.length-1];if(t&&t.upper)try{r=IDBKeyRange.bound(a,t.upper,!0,t.upperOpen)}catch(e){if("DataError"===e.name&&0===e.code)return o()}else r=IDBKeyRange.lowerBound(a,!0);t=r,s=null,i=null,e.getAll(t,n).onsuccess=c,e.getAllKeys(t,n).onsuccess=u}},e.getAll(t,n).onsuccess=c,e.getAllKeys(t,n).onsuccess=u):r?e.openCursor(t,"prev").onsuccess=l:e.openCursor(t).onsuccess=l}function ui(e,t,r){var n,o,s="startkey"in e&&e.startkey,i="endkey"in e&&e.endkey,a="key"in e&&e.key,c="keys"in e&&e.keys,u=e.skip||0,l="number"==typeof e.limit?e.limit:-1,f=!1!==e.inclusive_end;if(!c&&(n=function(e,t,r,n,o){try{if(e&&t)return o?IDBKeyRange.bound(t,e,!r,!1):IDBKeyRange.bound(e,t,!1,!r);if(e)return o?IDBKeyRange.upperBound(e):IDBKeyRange.lowerBound(e);if(t)return o?IDBKeyRange.lowerBound(t,!r):IDBKeyRange.upperBound(t,!r);if(n)return IDBKeyRange.only(n)}catch(e){return{error:e}}return null}(s,i,f,a,e.descending),(o=n&&n.error)&&("DataError"!==o.name||0!==o.code)))return r(Hn(Fn,o.name,o.message));var d=[zs,Ks,Gs];e.attachments&&d.push(Fs);var h=si(t,d,"readonly");if(h.error)return r(h.error);var p=h.txn;p.oncomplete=function(){e.attachments?ni(b,e.binary).then(P):P()},p.onabort=Ys(r);var m,v,y=p.objectStore(zs),g=p.objectStore(Ks),_=p.objectStore(Gs),w=g.index("_doc_id_rev"),b=[];function $(t,r){var n={id:r.id,key:r.id,value:{rev:t}};r.deleted?c&&(b.push(n),n.value.deleted=!0,n.doc=null):u--<=0&&(b.push(n),e.include_docs&&function(t,r,n){var o=t.id+"::"+n;w.get(o).onsuccess=function(n){if(r.doc=ei(n.target.result)||{},e.conflicts){var o=xo(t);o.length&&(r.doc._conflicts=o)}ri(r.doc,e,p)}}(r,n,t))}function k(e){for(var t=0,r=e.length;t<r&&b.length!==l;t++){var n=e[t];if(n.error&&c)b.push(n);else{var o=Zs(n);$(o.winningRev,o)}}}function E(e,t,r){r&&(k(t),b.length<l&&r.continue())}function P(){var t={total_rows:m,offset:e.skip,rows:b};e.update_seq&&void 0!==v&&(t.update_seq=v),r(null,t)}return _.get(Gs).onsuccess=function(e){m=e.target.result.docCount},e.update_seq&&(g.openKeyCursor(null,"prev").onsuccess=e=>{var t=e.target.result;t&&t.key&&(v=t.key)}),o||0===l?void 0:c?function(e,t,r){var n=new Array(e.length),o=0;e.forEach((function(s,i){t.get(s).onsuccess=function(t){t.target.result?n[i]=t.target.result:n[i]={key:s,error:"not_found"},++o===e.length&&r(e,n,{})}}))}(c,y,E):-1===l?function(e,t,r){if("function"!=typeof e.getAll){var n=[];e.openCursor(t).onsuccess=function(e){var t=e.target.result;t?(n.push(t.value),t.continue()):r({target:{result:n}})}}else e.getAll(t).onsuccess=r}(y,n,(function(t){var r=t.target.result;e.descending&&(r=r.reverse()),k(r)})):void ci(y,n,e.descending,l+u,E)}var li=!1,fi=[];function di(){!li&&fi.length&&(li=!0,fi.shift()())}function hi(e,t,r,n){if((e=gn(e)).continuous){var o=r+":"+Eo();return ii.addListener(r,o,t,e),ii.notify(r),{cancel:function(){ii.removeListener(r,o)}}}var s=e.doc_ids&&new Set(e.doc_ids);e.since=e.since||0;var i=e.since,a="limit"in e?e.limit:-1;0===a&&(a=1);var c,u,l,f,d=[],h=0,p=Qn(e),m=new Map;function v(e,t,r,n){if(r.seq!==t)return n();if(r.winningRev===e._rev)return n(r,e);var o=e._id+"::"+r.winningRev;f.get(o).onsuccess=function(e){n(r,ei(e.target.result))}}function y(){e.complete(null,{results:d,last_seq:i})}var g=[zs,Ks];e.attachments&&g.push(Fs);var _=si(n,g,"readonly");if(_.error)return e.complete(_.error);(c=_.txn).onabort=Ys(e.complete),c.oncomplete=function(){!e.continuous&&e.attachments?ni(d).then(y):y()},u=c.objectStore(Ks),l=c.objectStore(zs),f=u.index("_doc_id_rev"),ci(u,e.since&&!e.descending?IDBKeyRange.lowerBound(e.since,!0):null,e.descending,a,(function(t,r,n){if(n&&t.length){var o=new Array(t.length),u=new Array(t.length),f=0;r.forEach((function(r,i){!function(e,t,r){if(s&&!s.has(e._id))return r();var n=m.get(e._id);if(n)return v(e,t,n,r);l.get(e._id).onsuccess=function(o){n=Zs(o.target.result),m.set(e._id,n),v(e,t,n,r)}}(ei(r),t[i],(function(r,s){u[i]=r,o[i]=s,++f===t.length&&function(){for(var t=[],r=0,s=o.length;r<s&&h!==a;r++){var i=o[r];if(i){var c=u[r];t.push(y(c,i))}}Promise.all(t).then((function(t){for(var r=0,n=t.length;r<n;r++)t[r]&&e.onChange(t[r])})).catch(e.complete),h!==a&&n.continue()}()}))}))}function y(t,r){var n=e.processChange(r,t,e);i=n.seq=t.seq;var o=p(n);return"object"==typeof o?Promise.reject(o):o?(h++,e.return_docs&&d.push(n),e.attachments&&e.include_docs?new Promise((function(t){ri(r,e,c,(function(){ni([n],e.binary).then((function(){t(n)}))}))})):Promise.resolve(n)):Promise.resolve()}}))}var pi,mi=new Map,vi=new Map;function yi(e,t){var r=this;!function(e,t,r){fi.push((function(){e((function(e,n){!function(e,t,r,n){try{e(t,r)}catch(t){n.emit("error",t)}}(t,e,n,r),li=!1,On((function(){di()}))}))})),di()}((function(t){!function(e,t,r){var n=t.name,o=null,s=null;function i(e){return function(t,r){t&&t instanceof Error&&!t.reason&&s&&(t.reason=s),e(t,r)}}function a(e){var t=e.createObjectStore(zs,{keyPath:"id"});e.createObjectStore(Ks,{autoIncrement:!0}).createIndex("_doc_id_rev","_doc_id_rev",{unique:!0}),e.createObjectStore(Fs,{keyPath:"digest"}),e.createObjectStore(Gs,{keyPath:"id",autoIncrement:!1}),e.createObjectStore(Ws),t.createIndex("deletedOrLocal","deletedOrLocal",{unique:!1}),e.createObjectStore(Hs,{keyPath:"_id"});var r=e.createObjectStore(Js,{autoIncrement:!0});r.createIndex("seq","seq"),r.createIndex("digestSeq","digestSeq",{unique:!0})}function c(e,t){var r=e.objectStore(zs);r.createIndex("deletedOrLocal","deletedOrLocal",{unique:!1}),r.openCursor().onsuccess=function(e){var n=e.target.result;if(n){var o=n.value,s=Mo(o);o.deletedOrLocal=s?"1":"0",r.put(o),n.continue()}else t()}}function u(e){e.createObjectStore(Hs,{keyPath:"_id"}).createIndex("_doc_id_rev","_doc_id_rev",{unique:!0})}function l(e,t){var r=e.objectStore(Hs),n=e.objectStore(zs),o=e.objectStore(Ks);n.openCursor().onsuccess=function(e){var s=e.target.result;if(s){var i=s.value,a=i.id,c=Vo(a),u=Po(i);if(c){var l=a+"::"+u,f=a+"::",d=a+"::~",h=o.index("_doc_id_rev"),p=IDBKeyRange.bound(f,d,!1,!1),m=h.openCursor(p);m.onsuccess=function(e){if(m=e.target.result){var t=m.value;t._doc_id_rev===l&&r.put(t),o.delete(m.primaryKey),m.continue()}else n.delete(s.primaryKey),s.continue()}}else s.continue()}else t&&t()}}function f(e){var t=e.createObjectStore(Js,{autoIncrement:!0});t.createIndex("seq","seq"),t.createIndex("digestSeq","digestSeq",{unique:!0})}function d(e,t){var r=e.objectStore(Ks),n=e.objectStore(Fs),o=e.objectStore(Js);n.count().onsuccess=function(e){if(!e.target.result)return t();r.openCursor().onsuccess=function(e){var r=e.target.result;if(!r)return t();for(var n=r.value,s=r.primaryKey,i=Object.keys(n._attachments||{}),a={},c=0;c<i.length;c++){a[n._attachments[i[c]].digest]=!0}var u=Object.keys(a);for(c=0;c<u.length;c++){var l=u[c];o.put({seq:s,digestSeq:l+"::"+s})}r.continue()}}}function h(e){function t(e){return e.data?Zs(e):(e.deleted="1"===e.deletedOrLocal,e)}var r=e.objectStore(Ks),n=e.objectStore(zs);n.openCursor().onsuccess=function(e){var o=e.target.result;if(o){var s=t(o.value);if(s.winningRev=s.winningRev||Po(s),s.seq)return a();i()}function i(){var e=s.id+"::",t=s.id+"::",n=r.index("_doc_id_rev").openCursor(IDBKeyRange.bound(e,t)),o=0;n.onsuccess=function(e){var t=e.target.result;if(!t)return s.seq=o,a();var r=t.primaryKey;r>o&&(o=r),t.continue()}}function a(){var e=Xs(s,s.winningRev,s.deleted);n.put(e).onsuccess=function(){o.continue()}}}}e._meta=null,e._remote=!1,e.type=function(){return"idb"},e._id=wn((function(t){t(null,e._meta.instanceId)})),e._bulkDocs=function(r,n,s){ai(t,r,n,e,o,i(s))},e._get=function(e,t,r){var n,s,i,a=t.ctx;if(!a){var c=si(o,[zs,Ks,Fs],"readonly");if(c.error)return r(c.error);a=c.txn}function u(){r(i,{doc:n,metadata:s,ctx:a})}a.objectStore(zs).get(e).onsuccess=function(e){if(!(s=Zs(e.target.result)))return i=Hn(Tn,"missing"),u();var r;if(t.rev)r=t.latest?function(e,t){for(var r,n=t.rev_tree.slice();r=n.pop();){var o=r.pos,s=r.ids,i=s[0],a=s[1],c=s[2],u=0===c.length,l=r.history?r.history.slice():[];if(l.push({id:i,pos:o,opts:a}),u)for(var f=0,d=l.length;f<d;f++){var h=l[f];if(h.pos+"-"+h.id===e)return o+"-"+i}for(var p=0,m=c.length;p<m;p++)n.push({pos:o+1,ids:c[p],history:l})}throw new Error("Unable to resolve latest revision for id "+t.id+", rev "+e)}(t.rev,s):t.rev;else if(r=s.winningRev,Mo(s))return i=Hn(Tn,"deleted"),u();var o=a.objectStore(Ks),c=s.id+"::"+r;o.index("_doc_id_rev").get(c).onsuccess=function(e){if((n=e.target.result)&&(n=ei(n)),!n)return i=Hn(Tn,"missing"),u();u()}}},e._getAttachment=function(e,t,r,n,s){var i;if(n.ctx)i=n.ctx;else{var a=si(o,[zs,Ks,Fs],"readonly");if(a.error)return s(a.error);i=a.txn}var c=r.digest,u=r.content_type;i.objectStore(Fs).get(c).onsuccess=function(e){ti(e.target.result.body,u,n.binary,(function(e){s(null,e)}))}},e._info=function(t){var r,n,s=si(o,[Gs,Ks],"readonly");if(s.error)return t(s.error);var i=s.txn;i.objectStore(Gs).get(Gs).onsuccess=function(e){n=e.target.result.docCount},i.objectStore(Ks).openKeyCursor(null,"prev").onsuccess=function(e){var t=e.target.result;r=t?t.key:0},i.oncomplete=function(){t(null,{doc_count:n,update_seq:r,idb_attachment_format:e._meta.blobSupport?"binary":"base64"})}},e._allDocs=function(e,t){ui(e,o,i(t))},e._changes=function(t){return hi(t,e,n,o)},e._close=function(e){o.close(),mi.delete(n),e()},e._getRevisionTree=function(e,t){var r=si(o,[zs],"readonly");if(r.error)return t(r.error);r.txn.objectStore(zs).get(e).onsuccess=function(e){var r=Zs(e.target.result);r?t(null,r.rev_tree):t(Hn(Tn))}},e._doCompaction=function(e,t,r){var n=si(o,[zs,Ks,Fs,Js],"readwrite");if(n.error)return r(n.error);var s=n.txn;s.objectStore(zs).get(e).onsuccess=function(r){var n=Zs(r.target.result);So(n.rev_tree,(function(e,r,n,o,s){var i=r+"-"+n;-1!==t.indexOf(i)&&(s.status="missing")})),oi(t,e,s);var o=n.winningRev,i=n.deleted;s.objectStore(zs).put(Xs(n,o,i))},s.onabort=Ys(r),s.oncomplete=function(){r()}},e._getLocal=function(e,t){var r=si(o,[Hs],"readonly");if(r.error)return t(r.error);var n=r.txn.objectStore(Hs).get(e);n.onerror=Ys(t),n.onsuccess=function(e){var r=e.target.result;r?(delete r._doc_id_rev,t(null,r)):t(Hn(Tn))}},e._putLocal=function(e,t,r){"function"==typeof t&&(r=t,t={}),delete e._revisions;var n=e._rev,s=e._id;e._rev=n?"0-"+(parseInt(n.split("-")[1],10)+1):"0-1";var i,a=t.ctx;if(!a){var c=si(o,[Hs],"readwrite");if(c.error)return r(c.error);(a=c.txn).onerror=Ys(r),a.oncomplete=function(){i&&r(null,i)}}var u,l=a.objectStore(Hs);n?(u=l.get(s)).onsuccess=function(o){var s=o.target.result;s&&s._rev===n?l.put(e).onsuccess=function(){i={ok:!0,id:e._id,rev:e._rev},t.ctx&&r(null,i)}:r(Hn(Rn))}:((u=l.add(e)).onerror=function(e){r(Hn(Rn)),e.preventDefault(),e.stopPropagation()},u.onsuccess=function(){i={ok:!0,id:e._id,rev:e._rev},t.ctx&&r(null,i)})},e._removeLocal=function(e,t,r){"function"==typeof t&&(r=t,t={});var n,s=t.ctx;if(!s){var i=si(o,[Hs],"readwrite");if(i.error)return r(i.error);(s=i.txn).oncomplete=function(){n&&r(null,n)}}var a=e._id,c=s.objectStore(Hs),u=c.get(a);u.onerror=Ys(r),u.onsuccess=function(o){var s=o.target.result;s&&s._rev===e._rev?(c.delete(a),n={ok:!0,id:a,rev:"0-0"},t.ctx&&r(null,n)):r(Hn(Tn))}},e._destroy=function(e,t){ii.removeAllListeners(n);var r=vi.get(n);r&&r.result&&(r.result.close(),mi.delete(n));var o=indexedDB.deleteDatabase(n);o.onsuccess=function(){vi.delete(n),jn()&&n in localStorage&&delete localStorage[n],t(null,{ok:!0})},o.onerror=Ys(t)};var p=mi.get(n);if(p)return o=p.idb,e._meta=p.global,On((function(){r(null,e)}));var m=indexedDB.open(n,5);vi.set(n,m),m.onupgradeneeded=function(e){var t=e.target.result;if(e.oldVersion<1)return a(t);var r=e.currentTarget.transaction;e.oldVersion<3&&u(t),e.oldVersion<4&&f(t);var n=[c,l,d,h],o=e.oldVersion;function s(){var e=n[o-1];o++,e&&e(r,s)}s()},m.onsuccess=function(t){(o=t.target.result).onversionchange=function(){o.close(),mi.delete(n)},o.onabort=function(e){xn("error","Database has a global failure",e.target.error),s=e.target.error,o.close(),mi.delete(n)};var i,a,c,u,l=o.transaction([Gs,Ws,zs],"readwrite"),f=!1;function d(){void 0!==c&&f&&(e._meta={name:n,instanceId:u,blobSupport:c},mi.set(n,{idb:o,global:e._meta}),r(null,e))}function h(){if(void 0!==a&&void 0!==i){var e=n+"_id";e in i?u=i[e]:i[e]=u=Eo(),i.docCount=a,l.objectStore(Gs).put(i)}}l.objectStore(Gs).get(Gs).onsuccess=function(e){i=e.target.result||{id:Gs},h()},function(e,t){e.objectStore(zs).index("deletedOrLocal").count(IDBKeyRange.only("0")).onsuccess=function(e){t(e.target.result)}}(l,(function(e){a=e,h()})),pi||(pi=function(e,t,r){return new Promise((function(n){var o=lo([""]);let s;{const n=r;s=e.objectStore(t).put(o,n)}s.onsuccess=function(){var e=navigator.userAgent.match(/Chrome\/(\d+)/),t=navigator.userAgent.match(/Edge\//);n(t||!e||parseInt(e[1],10)>=43)},s.onerror=e.onabort=function(e){e.preventDefault(),e.stopPropagation(),n(!1)}})).catch((function(){return!1}))}(l,Ws,"key")),pi.then((function(e){c=e,d()})),l.oncomplete=function(){f=!0,d()},l.onabort=Ys(r)},m.onerror=function(e){var t=e.target.error&&e.target.error.message;t?-1!==t.indexOf("stored database is a higher version")&&(t=new Error('This DB was created with the newer "indexeddb" adapter, but you are trying to open it with the older "idb" adapter')):t="Failed to open indexedDB, are you in private browsing mode?",xn("error",t),r(Hn(Fn,t))}}(r,e,t)}),t,r.constructor)}yi.valid=function(){try{return"undefined"!=typeof indexedDB&&"undefined"!=typeof IDBKeyRange}catch(e){return!1}};const gi=5e3,_i={};function wi(e){const t=e.doc||e.ok,r=t&&t._attachments;r&&Object.keys(r).forEach((function(e){const t=r[e];t.data=po(t.data,t.content_type)}))}function bi(e){return/^_design/.test(e)?"_design/"+encodeURIComponent(e.slice(8)):e.startsWith("_local/")?"_local/"+encodeURIComponent(e.slice(7)):encodeURIComponent(e)}function $i(e){return e._attachments&&Object.keys(e._attachments)?Promise.all(Object.keys(e._attachments).map((function(t){const r=e._attachments[t];if(r.data&&"string"!=typeof r.data)return new Promise((function(e){yo(r.data,e)})).then((function(e){r.data=e}))}))):Promise.resolve()}function ki(e,t){if(function(e){if(!e.prefix)return!1;const t=so(e.prefix).protocol;return"http"===t||"https"===t}(t)){const r=t.name.substr(t.prefix.length);e=t.prefix.replace(/\/?$/,"/")+encodeURIComponent(r)}const r=so(e);(r.user||r.password)&&(r.auth={username:r.user,password:r.password});const n=r.path.replace(/(^\/|\/$)/g,"").split("/");return r.db=n.pop(),-1===r.db.indexOf("%")&&(r.db=encodeURIComponent(r.db)),r.path=n.join("/"),r}function Ei(e,t){return Pi(e,e.db+"/"+t)}function Pi(e,t){const r=e.path?"/":"";return e.protocol+"://"+e.host+(e.port?":"+e.port:"")+"/"+e.path+r+t}function Si(e){const t=Object.keys(e);return 0===t.length?"":"?"+t.map((t=>t+"="+encodeURIComponent(e[t]))).join("&")}function ji(e,t){const r=this,n=ki(e.name,e),o=Ei(n,"");e=gn(e);const s=async function(t,r){if((r=r||{}).headers=r.headers||new rs,r.credentials="include",e.auth||n.auth){const t=e.auth||n.auth,o=t.username+":"+t.password,s=uo(unescape(encodeURIComponent(o)));r.headers.set("Authorization","Basic "+s)}const o=e.headers||{};Object.keys(o).forEach((function(e){r.headers.append(e,o[e])})),function(e){const t="undefined"!=typeof navigator&&navigator.userAgent?navigator.userAgent.toLowerCase():"",r=-1!==t.indexOf("msie"),n=-1!==t.indexOf("trident"),o=-1!==t.indexOf("edge"),s=!("method"in e)||"GET"===e.method;return(r||n||o)&&s}(r)&&(t+=(-1===t.indexOf("?")?"?":"&")+"_nonce="+Date.now());const s=e.fetch||ts;return await s(t,r)};function i(e,t){return bn(e,(function(...e){u().then((function(){return t.apply(this,e)})).catch((function(t){e.pop()(t)}))})).bind(r)}async function a(e,t){const r={};(t=t||{}).headers=t.headers||new rs,t.headers.get("Content-Type")||t.headers.set("Content-Type","application/json"),t.headers.get("Accept")||t.headers.set("Accept","application/json");const n=await s(e,t);r.ok=n.ok,r.status=n.status;const o=await n.json();if(r.data=o,!r.ok){r.data.status=r.status;throw Wn(r.data)}return Array.isArray(r.data)&&(r.data=r.data.map((function(e){return e.error||e.missing?Wn(e):e}))),r}let c;async function u(){return e.skip_setup?Promise.resolve():c||(c=a(o).catch((function(e){return e&&e.status&&404===e.status?(Cn(404,"PouchDB is just detecting if the remote exists."),a(o,{method:"PUT"})):Promise.reject(e)})).catch((function(e){return!(!e||!e.status||412!==e.status)||Promise.reject(e)})),c.catch((function(){c=null})),c)}function l(e){return e.split("/").map(encodeURIComponent).join("/")}On((function(){t(null,r)})),r._remote=!0,r.type=function(){return"http"},r.id=i("id",(async function(e){let t;try{const e=await s(Pi(n,""));t=await e.json()}catch(e){t={}}e(null,t&&t.uuid?t.uuid+n.db:Ei(n,""))})),r.compact=i("compact",(async function(e,t){"function"==typeof e&&(t=e,e={}),e=gn(e),await a(Ei(n,"_compact"),{method:"POST"}),function n(){r.info((function(r,o){o&&!o.compact_running?t(null,{ok:!0}):setTimeout(n,e.interval||200)}))}()})),r.bulkGet=bn("bulkGet",(function(e,t){const r=this;async function o(t){const r={};e.revs&&(r.revs=!0),e.attachments&&(r.attachments=!0),e.latest&&(r.latest=!0);try{const o=await a(Ei(n,"_bulk_get"+Si(r)),{method:"POST",body:JSON.stringify({docs:e.docs})});e.attachments&&e.binary&&o.data.results.forEach((function(e){e.docs.forEach(wi)})),t(null,o.data)}catch(e){t(e)}}function s(){const n=Math.ceil(e.docs.length/50);let o=0;const s=new Array(n);function i(e){return function(r,i){s[e]=i.results,++o===n&&t(null,{results:s.flat()})}}for(let t=0;t<n;t++){const n=$n(e,["revs","attachments","binary","latest"]);n.docs=e.docs.slice(50*t,Math.min(e.docs.length,50*(t+1))),Sn(r,n,i(t))}}const i=Pi(n,""),c=_i[i];"boolean"!=typeof c?o((function(e,r){e?(_i[i]=!1,Cn(e.status,"PouchDB is just detecting if the remote supports the _bulk_get API."),s()):(_i[i]=!0,t(null,r))})):c?o(t):s()})),r._info=async function(e){try{await u();const t=await s(Ei(n,"")),r=await t.json();r.host=Ei(n,""),e(null,r)}catch(t){e(t)}},r.fetch=async function(e,t){await u();const r="/"===e.substring(0,1)?Pi(n,e.substring(1)):Ei(n,e);return s(r,t)},r.get=i("get",(async function(e,t,r){"function"==typeof t&&(r=t,t={});const o={};function i(e){const r=e._attachments,o=r&&Object.keys(r);if(!r||!o.length)return;const i=o.map((function(o){return function(){return async function(o){const i=r[o],a=bi(e._id)+"/"+l(o)+"?rev="+e._rev,c=await s(Ei(n,a));let u,f;if(u="buffer"in c?await c.buffer():await c.blob(),t.binary){const e=Object.getOwnPropertyDescriptor(u.__proto__,"type");e&&!e.set||(u.type=i.content_type),f=u}else f=await new Promise((function(e){yo(u,e)}));delete i.stub,delete i.length,i.data=f}(o)}}));return function(e,t){return new Promise((function(r,n){var o,s=0,i=0,a=0,c=e.length;function u(){++a===c?o?n(o):r():d()}function l(){s--,u()}function f(e){s--,o=o||e,u()}function d(){for(;s<t&&i<c;)s++,e[i++]().then(l,f)}d()}))}(i,5)}(t=gn(t)).revs&&(o.revs=!0),t.revs_info&&(o.revs_info=!0),t.latest&&(o.latest=!0),t.open_revs&&("all"!==t.open_revs&&(t.open_revs=JSON.stringify(t.open_revs)),o.open_revs=t.open_revs),t.rev&&(o.rev=t.rev),t.conflicts&&(o.conflicts=t.conflicts),t.update_seq&&(o.update_seq=t.update_seq),e=bi(e);const c=Ei(n,e+Si(o));try{const e=await a(c);t.attachments&&await(u=e.data,Array.isArray(u)?Promise.all(u.map((function(e){if(e.ok)return i(e.ok)}))):i(u)),r(null,e.data)}catch(t){t.docId=e,r(t)}var u})),r.remove=i("remove",(async function(e,t,r,o){let s;"string"==typeof t?(s={_id:e,_rev:t},"function"==typeof r&&(o=r,r={})):(s=e,"function"==typeof t?(o=t,r={}):(o=r,r=t));const i=s._rev||r.rev,c=Ei(n,bi(s._id))+"?rev="+i;try{o(null,(await a(c,{method:"DELETE"})).data)}catch(e){o(e)}})),r.getAttachment=i("getAttachment",(async function(e,t,r,o){"function"==typeof r&&(o=r,r={});const i=r.rev?"?rev="+r.rev:"",a=Ei(n,bi(e))+"/"+l(t)+i;let c;try{const e=await s(a,{method:"GET"});if(!e.ok)throw e;let t;c=e.headers.get("content-type"),(Jr.browser||"function"!=typeof e.buffer)&&(t=await e.blob()),o(null,t)}catch(e){o(e)}})),r.removeAttachment=i("removeAttachment",(async function(e,t,r,o){const s=Ei(n,bi(e)+"/"+l(t))+"?rev="+r;try{o(null,(await a(s,{method:"DELETE"})).data)}catch(e){o(e)}})),r.putAttachment=i("putAttachment",(async function(e,t,r,o,s,i){"function"==typeof s&&(i=s,s=o,o=r,r=null);const c=bi(e)+"/"+l(t);let u=Ei(n,c);if(r&&(u+="?rev="+r),"string"==typeof o){let e;try{e=co(o)}catch(e){return i(Hn(Vn,"Attachment is not a valid base64 string"))}o=e?ho(e,s):""}try{i(null,(await a(u,{headers:new rs({"Content-Type":s}),method:"PUT",body:o})).data)}catch(e){i(e)}})),r._bulkDocs=async function(e,t,r){e.new_edits=t.new_edits;try{await u(),await Promise.all(e.docs.map($i));r(null,(await a(Ei(n,"_bulk_docs"),{method:"POST",body:JSON.stringify(e)})).data)}catch(e){r(e)}},r._put=async function(e,t,r){try{await u(),await $i(e);r(null,(await a(Ei(n,bi(e._id)),{method:"PUT",body:JSON.stringify(e)})).data)}catch(t){t.docId=e&&e._id,r(t)}},r.allDocs=i("allDocs",(async function(e,t){"function"==typeof e&&(t=e,e={});const r={};let o,s="GET";(e=gn(e)).conflicts&&(r.conflicts=!0),e.update_seq&&(r.update_seq=!0),e.descending&&(r.descending=!0),e.include_docs&&(r.include_docs=!0),e.attachments&&(r.attachments=!0),e.key&&(r.key=JSON.stringify(e.key)),e.start_key&&(e.startkey=e.start_key),e.startkey&&(r.startkey=JSON.stringify(e.startkey)),e.end_key&&(e.endkey=e.end_key),e.endkey&&(r.endkey=JSON.stringify(e.endkey)),void 0!==e.inclusive_end&&(r.inclusive_end=!!e.inclusive_end),void 0!==e.limit&&(r.limit=e.limit),void 0!==e.skip&&(r.skip=e.skip);const i=Si(r);void 0!==e.keys&&(s="POST",o={keys:e.keys});try{const r=await a(Ei(n,"_all_docs"+i),{method:s,body:JSON.stringify(o)});e.include_docs&&e.attachments&&e.binary&&r.data.rows.forEach(wi),t(null,r.data)}catch(e){t(e)}})),r._changes=function(e){const t="batch_size"in e?e.batch_size:25;(e=gn(e)).continuous&&!("heartbeat"in e)&&(e.heartbeat=1e4);let r="timeout"in e?e.timeout:3e4;"timeout"in e&&e.timeout&&r-e.timeout<gi&&(r=e.timeout+gi),"heartbeat"in e&&e.heartbeat&&r-e.heartbeat<gi&&(r=e.heartbeat+gi);const o={};"timeout"in e&&e.timeout&&(o.timeout=e.timeout);const s=void 0!==e.limit&&e.limit;let i=s;if(e.style&&(o.style=e.style),(e.include_docs||e.filter&&"function"==typeof e.filter)&&(o.include_docs=!0),e.attachments&&(o.attachments=!0),e.continuous&&(o.feed="longpoll"),e.seq_interval&&(o.seq_interval=e.seq_interval),e.conflicts&&(o.conflicts=!0),e.descending&&(o.descending=!0),e.update_seq&&(o.update_seq=!0),"heartbeat"in e&&e.heartbeat&&(o.heartbeat=e.heartbeat),e.filter&&"string"==typeof e.filter&&(o.filter=e.filter),e.view&&"string"==typeof e.view&&(o.filter="_view",o.view=e.view),e.query_params&&"object"==typeof e.query_params)for(const t in e.query_params)Object.prototype.hasOwnProperty.call(e.query_params,t)&&(o[t]=e.query_params[t]);let c,l="GET";e.doc_ids?(o.filter="_doc_ids",l="POST",c={doc_ids:e.doc_ids}):e.selector&&(o.filter="_selector",l="POST",c={selector:e.selector});const f=new AbortController;let d;const h=async function(r,h){if(e.aborted)return;o.since=r,"object"==typeof o.since&&(o.since=JSON.stringify(o.since)),e.descending?s&&(o.limit=i):o.limit=!s||i>t?t:i;const p=Ei(n,"_changes"+Si(o)),m={signal:f.signal,method:l,body:JSON.stringify(c)};if(d=r,!e.aborted)try{await u();h(null,(await a(p,m)).data)}catch(e){h(e)}},p={results:[]},m=function(r,n){if(e.aborted)return;let o=0;if(n&&n.results){o=n.results.length,p.last_seq=n.last_seq;let t=null,r=null;"number"==typeof n.pending&&(t=n.pending),"string"!=typeof p.last_seq&&"number"!=typeof p.last_seq||(r=p.last_seq),e.query_params,n.results=n.results.filter((function(n){i--;const o=Qn(e)(n);return o&&(e.include_docs&&e.attachments&&e.binary&&wi(n),e.return_docs&&p.results.push(n),e.onChange(n,t,r)),o}))}else if(r)return e.aborted=!0,void e.complete(r);n&&n.last_seq&&(d=n.last_seq);const a=s&&i<=0||n&&o<t||e.descending;(!e.continuous||s&&i<=0)&&a?e.complete(null,p):On((function(){h(d,m)}))};return h(e.since||0,m),{cancel:function(){e.aborted=!0,f.abort()}}},r.revsDiff=i("revsDiff",(async function(e,t,r){"function"==typeof t&&(r=t,t={});try{r(null,(await a(Ei(n,"_revs_diff"),{method:"POST",body:JSON.stringify(e)})).data)}catch(e){r(e)}})),r._close=function(e){e()},r._destroy=async function(e,t){try{t(null,await a(Ei(n,""),{method:"DELETE"}))}catch(e){404===e.status?t(null,{ok:!0}):t(e)}}}ji.valid=function(){return!0};class Oi extends Error{constructor(e){super(),this.status=400,this.name="query_parse_error",this.message=e,this.error=!0;try{Error.captureStackTrace(this,Oi)}catch(e){}}}class xi extends Error{constructor(e){super(),this.status=404,this.name="not_found",this.message=e,this.error=!0;try{Error.captureStackTrace(this,xi)}catch(e){}}}class Ai extends Error{constructor(e){super(),this.status=500,this.name="invalid_value",this.message=e,this.error=!0;try{Error.captureStackTrace(this,Ai)}catch(e){}}}function Ci(e,t){return t&&e.then((function(e){On((function(){t(null,e)}))}),(function(e){On((function(){t(e)}))})),e}function Ii(e,t){return function(){var r=arguments,n=this;return e.add((function(){return t.apply(n,r)}))}}function Ni(e){var t=new Set(e),r=new Array(t.size),n=-1;return t.forEach((function(e){r[++n]=e})),r}function Ti(e){var t=new Array(e.size),r=-1;return e.forEach((function(e,n){t[++r]=n})),t}function Ri(e){return new Ai("builtin "+e+" function requires map values to be numbers or number arrays")}function qi(e){for(var t=0,r=0,n=e.length;r<n;r++){var o=e[r];if("number"!=typeof o){if(!Array.isArray(o))throw Ri("_sum");t="number"==typeof t?[t]:t;for(var s=0,i=o.length;s<i;s++){var a=o[s];if("number"!=typeof a)throw Ri("_sum");void 0===t[s]?t.push(a):t[s]+=a}}else"number"==typeof t?t+=o:t[0]+=o}return t}var Di=xn.bind(null,"log"),Li=Array.isArray,Mi=JSON.parse;function Vi(e,t){return io("return ("+e.replace(/;\s*$/,"")+");",{emit:t,sum:qi,log:Di,isArray:Li,toJSON:Mi})}class Ui{constructor(){this.promise=Promise.resolve()}add(e){return this.promise=this.promise.catch((()=>{})).then((()=>e())),this.promise}finish(){return this.promise}}function Bi(e){if(!e)return"undefined";switch(typeof e){case"function":case"string":return e.toString();default:return JSON.stringify(e)}}async function zi(e,t,r,n,o,s){const i=function(e,t){return Bi(e)+Bi(t)+"undefined"}(r,n);let a;if(!o&&(a=e._cachedViews=e._cachedViews||{},a[i]))return a[i];const c=e.info().then((async function(c){const u=c.db_name+"-mrview-"+(o?"temp":$o(i));await ao(e,"_local/"+s,(function(e){e.views=e.views||{};let r=t;-1===r.indexOf("/")&&(r=t+"/"+t);const n=e.views[r]=e.views[r]||{};if(!n[u])return n[u]=!0,e}));const l=(await e.registerDependentDatabase(u)).db;l.auto_compaction=!0;const f={name:u,db:l,sourceDB:e,adapter:e.adapter,mapFun:r,reduceFun:n};let d;try{d=await f.db.get("_local/lastSeq")}catch(e){if(404!==e.status)throw e}return f.seq=d?d.seq:0,a&&f.db.once("destroyed",(function(){delete a[i]})),f}));return a&&(a[i]=c),c}const Ki={},Fi=new Ui;function Ji(e){return-1===e.indexOf("/")?[e,e]:e.split("/")}function Gi(e,t,r){try{e.emit("error",t)}catch(e){xn("error","The user's map/reduce function threw an uncaught error.\nYou can debug this error by doing:\nmyDatabase.on('error', function (err) { debugger; });\nPlease double-check your map/reduce function."),xn("error",t,r)}}var Hi=function(e,t){return qi(t)},Wi=function(e,t){return t.length},Qi=function(e,t){return{sum:qi(t),min:Math.min.apply(null,t),max:Math.max.apply(null,t),count:t.length,sumsqr:function(e){for(var t=0,r=0,n=e.length;r<n;r++){var o=e[r];t+=o*o}return t}(t)}};var Yi=function(e,t,r,n){function o(e,t,r){try{t(r)}catch(n){Gi(e,n,{fun:t,doc:r})}}function s(e,t,r,n,o){try{return{output:t(r,n,o)}}catch(s){return Gi(e,s,{fun:t,keys:r,values:n,rereduce:o}),{error:s}}}function i(e,t){const r=ms(e.key,t.key);return 0!==r?r:ms(e.value,t.value)}function a(e,t,r){return r=r||0,"number"==typeof t?e.slice(r,t+r):r>0?e.slice(r):e}function c(e){const t=e.value;return t&&"object"==typeof t&&t._id||e.id}function u(e){return function(t){return e.include_docs&&e.attachments&&e.binary&&function(e){for(const t of e.rows){const e=t.doc&&t.doc._attachments;if(e)for(const t of Object.keys(e)){const r=e[t];e[t].data=po(r.data,r.content_type)}}}(t),t}}function l(e,t,r,n){let o=t[e];void 0!==o&&(n&&(o=encodeURIComponent(JSON.stringify(o))),r.push(e+"="+o))}function f(e){if(void 0!==e){const t=Number(e);return isNaN(t)||t!==parseInt(e,10)?e:t}}function d(e){if(e){if("number"!=typeof e)return new Oi(`Invalid value for integer: "${e}"`);if(e<0)return new Oi(`Invalid value for positive integer: "${e}"`)}}function h(e,t){const r=e.descending?"endkey":"startkey",n=e.descending?"startkey":"endkey";if(void 0!==e[r]&&void 0!==e[n]&&ms(e[r],e[n])>0)throw new Oi("No rows can match your key range, reverse your start_key and end_key or set {descending : true}");if(t.reduce&&!1!==e.reduce){if(e.include_docs)throw new Oi("{include_docs:true} is invalid for reduce");if(e.keys&&e.keys.length>1&&!e.group&&!e.group_level)throw new Oi("Multi-key fetches for reduce views must use {group: true}")}for(const t of["group_level","limit","skip"]){const r=d(e[t]);if(r)throw r}}function p(e){return function(t){if(404===t.status)return e;throw t}}function m(e,t,r){var n="_local/lastSeq";return e.db.get(n).catch(p({_id:n,seq:0})).then((function(n){var o=Ti(t);return Promise.all(o.map((function(r){return async function(e,t,r){const n="_local/doc_"+e,o={_id:n,keys:[]},s=r.get(e),i=s[0],a=s[1],c=await(function(e){return 1===e.length&&/^1-/.test(e[0].rev)}(a)?Promise.resolve(o):t.db.get(n).catch(p(o))),u=await function(e){return e.keys.length?t.db.allDocs({keys:e.keys,include_docs:!0}):Promise.resolve({rows:[]})}(c);return function(e,t){const r=[],n=new Set;for(const e of t.rows){const t=e.doc;if(t&&(r.push(t),n.add(t._id),t._deleted=!i.has(t._id),!t._deleted)){const e=i.get(t._id);"value"in e&&(t.value=e.value)}}const o=Ti(i);for(const e of o)if(!n.has(e)){const t={_id:e},n=i.get(e);"value"in n&&(t.value=n.value),r.push(t)}return e.keys=Ni(o.concat(e.keys)),r.push(e),r}(c,u)}(r,e,t)}))).then((function(t){var o=t.flat();return n.seq=r,o.push(n),e.db.bulkDocs({docs:o})})).then((()=>function(e){return e.sourceDB.get("_local/purges").then((function(t){const r=t.purgeSeq;return e.db.get("_local/purgeSeq").then((function(e){return e._rev})).catch(p(void 0)).then((function(t){return e.db.put({_id:"_local/purgeSeq",_rev:t,purgeSeq:r})}))})).catch((function(e){if(404!==e.status)throw e}))}(e)))}))}function v(e){const t="string"==typeof e?e:e.name;let r=Ki[t];return r||(r=Ki[t]=new Ui),r}async function y(e,r){return Ii(v(e),(function(){return async function(e,r){let n,s,a;function c(e,t){const r={id:s._id,key:vs(e)};null!=t&&(r.value=vs(t)),n.push(r)}const u=t(e.mapFun,c);let l=e.seq||0;function f(){return e.sourceDB.info().then((function(t){a=e.sourceDB.activeTasks.add({name:"view_indexing",total_items:t.update_seq-l})}))}function d(t,r){return function(){return m(e,t,r)}}let h=0;const v={view:e.name,indexed_docs:h};e.sourceDB.emit("indexing",v);const y=new Ui;async function g(){return w(await e.sourceDB.changes({return_docs:!0,conflicts:!0,include_docs:!0,style:"all_docs",since:l,limit:r.changes_batch_size}),await _())}function _(){return e.db.get("_local/purgeSeq").then((function(e){return e.purgeSeq})).catch(p(-1)).then((function(t){return e.sourceDB.get("_local/purges").then((function(r){const n=r.purges.filter((function(e,r){return r>t})).map((e=>e.docId)),o=n.filter((function(e,t){return n.indexOf(e)===t}));return Promise.all(o.map((function(t){return e.sourceDB.get(t).then((function(e){return{docId:t,doc:e}})).catch(p({docId:t}))})))})).catch(p([]))}))}function w(t,n){const o=t.results;if(!o.length&&!n.length)return;for(const e of n){if(o.findIndex((function(t){return t.id===e.docId}))<0){const t={_id:e.docId,doc:{_id:e.docId,_deleted:1},changes:[]};e.doc&&(t.doc=e.doc,t.changes.push({rev:e.doc._rev})),o.push(t)}}const s=b(o);y.add(d(s,l)),h+=o.length;const i={view:e.name,last_seq:t.last_seq,results_count:o.length,indexed_docs:h};return e.sourceDB.emit("indexing",i),e.sourceDB.activeTasks.update(a,{completed_items:h}),o.length<r.changes_batch_size?void 0:g()}function b(t){const r=new Map;for(const a of t){if("_"!==a.doc._id[0]){n=[],s=a.doc,s._deleted||o(e.sourceDB,u,s),n.sort(i);const t=$(n);r.set(a.doc._id,[t,a.changes])}l=a.seq}return r}function $(e){const t=new Map;let r;for(let n=0,o=e.length;n<o;n++){const o=e[n],s=[o.key,o.id];n>0&&0===ms(o.key,r)&&s.push(n),t.set(gs(s),o),r=o.key}return t}try{await f(),await g(),await y.finish(),e.seq=l,e.sourceDB.activeTasks.remove(a)}catch(t){e.sourceDB.activeTasks.remove(a,t)}}(e,r)}))()}function g(e,t){return Ii(v(e),(function(){return async function(e,t){let n;const o=e.reduceFun&&!1!==t.reduce,i=t.skip||0;void 0===t.keys||t.keys.length||(t.limit=0,delete t.keys);async function u(t){t.include_docs=!0;const r=await e.db.allDocs(t);return n=r.total_rows,r.rows.map((function(e){if("value"in e.doc&&"object"==typeof e.doc.value&&null!==e.doc.value){const t=Object.keys(e.doc.value).sort(),r=["id","key","value"];if(!(t<r||t>r))return e.doc.value}const t=function(e){for(var t=[],r=[],n=0;;){var o=e[n++];if("\0"!==o)switch(o){case"1":t.push(null);break;case"2":t.push("1"===e[n]),n++;break;case"3":var s=_s(e,n);t.push(s.num),n+=s.length;break;case"4":for(var i="";;){var a=e[n];if("\0"===a)break;i+=a,n++}i=i.replace(/\u0001\u0001/g,"\0").replace(/\u0001\u0002/g,"").replace(/\u0002\u0002/g,""),t.push(i);break;case"5":var c={element:[],index:t.length};t.push(c.element),r.push(c);break;case"6":var u={element:{},index:t.length};t.push(u.element),r.push(u);break;default:throw new Error("bad collationIndex or unexpectedly reached end of input: "+o)}else{if(1===t.length)return t.pop();ws(t,r)}}}(e.doc._id);return{key:t[0],id:t[1],value:"value"in e.doc?e.doc.value:null}}))}async function l(u){let l;if(l=o?function(e,t,n){0===n.group_level&&delete n.group_level;const o=n.group||n.group_level,i=r(e.reduceFun),c=[],u=isNaN(n.group_level)?Number.POSITIVE_INFINITY:n.group_level;for(const e of t){const t=c[c.length-1];let r=o?e.key:null;o&&Array.isArray(r)&&(r=r.slice(0,u)),t&&0===ms(t.groupKey,r)?(t.keys.push([e.key,e.id]),t.values.push(e.value)):c.push({keys:[[e.key,e.id]],values:[e.value],groupKey:r})}t=[];for(const r of c){const n=s(e.sourceDB,i,r.keys,r.values,!1);if(n.error&&n.error instanceof Ai)throw n.error;t.push({value:n.error?null:n.output,key:r.groupKey})}return{rows:a(t,n.limit,n.skip)}}(e,u,t):void 0===t.keys?{total_rows:n,offset:i,rows:u}:{total_rows:n,offset:i,rows:a(u,t.limit,t.skip)},t.update_seq&&(l.update_seq=e.seq),t.include_docs){const r=Ni(u.map(c)),n=await e.sourceDB.allDocs({keys:r,include_docs:!0,conflicts:t.conflicts,attachments:t.attachments,binary:t.binary}),o=new Map;for(const e of n.rows)o.set(e.id,e.doc);for(const e of u){const t=c(e),r=o.get(t);r&&(e.doc=r)}}return l}if(void 0!==t.keys){const e=t.keys.map((function(e){const r={startkey:gs([e]),endkey:gs([e,{}])};return t.update_seq&&(r.update_seq=!0),u(r)}));return l((await Promise.all(e)).flat())}{const e={descending:t.descending};let r,n;if(t.update_seq&&(e.update_seq=!0),"start_key"in t&&(r=t.start_key),"startkey"in t&&(r=t.startkey),"end_key"in t&&(n=t.end_key),"endkey"in t&&(n=t.endkey),void 0!==r&&(e.startkey=t.descending?gs([r,{}]):gs([r])),void 0!==n){let r=!1!==t.inclusive_end;t.descending&&(r=!r),e.endkey=gs(r?[n,{}]:[n])}if(void 0!==t.key){const r=gs([t.key]),n=gs([t.key,{}]);e.descending?(e.endkey=r,e.startkey=n):(e.startkey=r,e.endkey=n)}o||("number"==typeof t.limit&&(e.limit=t.limit),e.skip=i);return l(await u(e))}}(e,t)}))()}async function _(t,r,o){if("function"==typeof t._query)return function(e,t,r){return new Promise((function(n,o){e._query(t,r,(function(e,t){if(e)return o(e);n(t)}))}))}(t,r,o);if(Xn(t))return async function(e,t,r){let n,o,s=[],i="GET";if(l("reduce",r,s),l("include_docs",r,s),l("attachments",r,s),l("limit",r,s),l("descending",r,s),l("group",r,s),l("group_level",r,s),l("skip",r,s),l("stale",r,s),l("conflicts",r,s),l("startkey",r,s,!0),l("start_key",r,s,!0),l("endkey",r,s,!0),l("end_key",r,s,!0),l("inclusive_end",r,s),l("key",r,s,!0),l("update_seq",r,s),s=s.join("&"),s=""===s?"":"?"+s,void 0!==r.keys){const e=2e3,o=`keys=${encodeURIComponent(JSON.stringify(r.keys))}`;o.length+s.length+1<=e?s+=("?"===s[0]?"&":"?")+o:(i="POST","string"==typeof t?n={keys:r.keys}:t.keys=r.keys)}if("string"==typeof t){const a=Ji(t),c=await e.fetch("_design/"+a[0]+"/_view/"+a[1]+s,{headers:new rs({"Content-Type":"application/json"}),method:i,body:JSON.stringify(n)});o=c.ok;const l=await c.json();if(!o)throw l.status=c.status,Wn(l);for(const e of l.rows)if(e.value&&e.value.error&&"builtin_reduce_error"===e.value.error)throw new Error(e.reason);return new Promise((function(e){e(l)})).then(u(r))}n=n||{};for(const e of Object.keys(t))Array.isArray(t[e])?n[e]=t[e]:n[e]=t[e].toString();const a=await e.fetch("_temp_view"+s,{headers:new rs({"Content-Type":"application/json"}),method:"POST",body:JSON.stringify(n)});o=a.ok;const c=await a.json();if(!o)throw c.status=a.status,Wn(c);return new Promise((function(e){e(c)})).then(u(r))}(t,r,o);const s={changes_batch_size:t.__opts.view_update_changes_batch_size||50};if("string"!=typeof r)return h(o,r),Fi.add((async function(){const n=await zi(t,"temp_view/temp_view",r.map,r.reduce,!0,e);return i=y(n,s).then((function(){return g(n,o)})),a=function(){return n.db.destroy()},i.then((function(e){return a().then((function(){return e}))}),(function(e){return a().then((function(){throw e}))}));var i,a})),Fi.finish();{const i=r,a=Ji(i),c=a[0],u=a[1],l=await t.get("_design/"+c);if(!(r=l.views&&l.views[u]))throw new xi(`ddoc ${l._id} has no view named ${u}`);n(l,u),h(o,r);const f=await zi(t,i,r.map,r.reduce,!1,e);return"ok"===o.stale||"update_after"===o.stale?("update_after"===o.stale&&On((function(){y(f,s)})),g(f,o)):(await y(f,s),g(f,o))}}const w=(b=function(){const t=this;return"function"==typeof t._viewCleanup?function(e){return new Promise((function(t,r){e._viewCleanup((function(e,n){if(e)return r(e);t(n)}))}))}(t):Xn(t)?async function(e){return(await e.fetch("_view_cleanup",{headers:new rs({"Content-Type":"application/json"}),method:"POST"})).json()}(t):async function(t){try{const r=await t.get("_local/"+e),n=new Map;for(const e of Object.keys(r.views)){const t=Ji(e),r="_design/"+t[0],o=t[1];let s=n.get(r);s||(s=new Set,n.set(r,s)),s.add(o)}const o={keys:Ti(n),include_docs:!0},s=await t.allDocs(o),i={};for(const e of s.rows){const t=e.key.substring(8);for(const o of n.get(e.key)){let n=t+"/"+o;r.views[n]||(n=o);const s=Object.keys(r.views[n]),a=e.doc&&e.doc.views&&e.doc.views[o];for(const e of s)i[e]=i[e]||a}}const a=Object.keys(i).filter((function(e){return!i[e]})).map((function(e){return Ii(v(e),(function(){return new t.constructor(e,t.__opts).destroy()}))()}));return Promise.all(a).then((function(){return{ok:!0}}))}catch(e){if(404===e.status)return{ok:!0};throw e}}(t)},function(...e){var t=e.pop(),r=b.apply(this,e);return"function"==typeof t&&Ci(r,t),r});var b;return{query:function(e,t,r){const n=this;"function"==typeof t&&(r=t,t={}),t=t?function(e){return e.group_level=f(e.group_level),e.limit=f(e.limit),e.skip=f(e.skip),e}(t):{},"function"==typeof e&&(e={map:e});const o=Promise.resolve().then((function(){return _(n,e,t)}));return Ci(o,r),o},viewCleanup:w}}("mrviews",(function(e,t){if("function"==typeof e&&2===e.length){var r=e;return function(e){return r(e,t)}}return Vi(e.toString(),t)}),(function(e){var t=e.toString(),r=function(e){if(/^_sum/.test(e))return Hi;if(/^_count/.test(e))return Wi;if(/^_stats/.test(e))return Qi;if(/^_/.test(e))throw new Error(e+" is not a supported reduce function.")}(t);return r||Vi(t)}),(function(e,t){var r=e.views&&e.views[t];if("string"!=typeof r.map)throw new xi("ddoc "+e._id+" has no string view named "+t+", instead found object of type: "+typeof r.map)}));var Xi={query:function(e,t,r){return Yi.query.call(this,e,t,r)},viewCleanup:function(e){return Yi.viewCleanup.call(this,e)}};function Zi(e,t){var r=Object.keys(t._attachments);return Promise.all(r.map((function(r){return e.getAttachment(t._id,r,{rev:t._rev})})))}function ea(e,t,r,n){r=gn(r);var o=[],s=!0;return Promise.resolve().then((function(){var i=function(e){var t=[];return Object.keys(e).forEach((function(r){e[r].missing.forEach((function(e){t.push({id:r,rev:e})}))})),{docs:t,revs:!0,latest:!0}}(r);if(i.docs.length)return e.bulkGet(i).then((function(r){if(n.cancelled)throw new Error("cancelled");return Promise.all(r.results.map((function(r){return Promise.all(r.docs.map((function(r){var n=r.ok;return r.error&&(s=!1),n&&n._attachments?function(e,t,r){var n=Xn(t)&&!Xn(e),o=Object.keys(r._attachments);return n?e.get(r._id).then((function(n){return Promise.all(o.map((function(o){return function(e,t,r){return!e._attachments||!e._attachments[r]||e._attachments[r].digest!==t._attachments[r].digest}(n,r,o)?t.getAttachment(r._id,o):e.getAttachment(n._id,o)})))})).catch((function(e){if(404!==e.status)throw e;return Zi(t,r)})):Zi(t,r)}(t,e,n).then((e=>{var t=Object.keys(n._attachments);return e.forEach((function(e,r){var o=n._attachments[t[r]];delete o.stub,delete o.length,o.data=e})),n})):n})))}))).then((function(e){o=o.concat(e.flat().filter(Boolean))}))}))})).then((function(){return{ok:s,docs:o}}))}var ta="pouchdb";function ra(e,t,r,n,o){return e.get(t).catch((function(r){if(404===r.status)return"http"!==e.adapter&&"https"!==e.adapter||Cn(404,"PouchDB is just checking if a remote checkpoint exists."),{session_id:n,_id:t,history:[],replicator:ta,version:1};throw r})).then((function(s){if(!o.cancelled&&s.last_seq!==r)return s.history=(s.history||[]).filter((function(e){return e.session_id!==n})),s.history.unshift({last_seq:r,session_id:n}),s.history=s.history.slice(0,5),s.version=1,s.replicator=ta,s.session_id=n,s.last_seq=r,e.put(s).catch((function(s){if(409===s.status)return ra(e,t,r,n,o);throw s}))}))}class na{constructor(e,t,r,n,o={writeSourceCheckpoint:!0,writeTargetCheckpoint:!0}){this.src=e,this.target=t,this.id=r,this.returnValue=n,this.opts=o,void 0===o.writeSourceCheckpoint&&(o.writeSourceCheckpoint=!0),void 0===o.writeTargetCheckpoint&&(o.writeTargetCheckpoint=!0)}writeCheckpoint(e,t){var r=this;return this.updateTarget(e,t).then((function(){return r.updateSource(e,t)}))}updateTarget(e,t){return this.opts.writeTargetCheckpoint?ra(this.target,this.id,e,t,this.returnValue):Promise.resolve(!0)}updateSource(e,t){if(this.opts.writeSourceCheckpoint){var r=this;return ra(this.src,this.id,e,t,this.returnValue).catch((function(e){if(aa(e))return r.opts.writeSourceCheckpoint=!1,!0;throw e}))}return Promise.resolve(!0)}getCheckpoint(){var e=this;return e.opts.writeSourceCheckpoint||e.opts.writeTargetCheckpoint?e.opts&&e.opts.writeSourceCheckpoint&&!e.opts.writeTargetCheckpoint?e.src.get(e.id).then((function(e){return e.last_seq||0})).catch((function(e){if(404!==e.status)throw e;return 0})):e.target.get(e.id).then((function(t){return e.opts&&e.opts.writeTargetCheckpoint&&!e.opts.writeSourceCheckpoint?t.last_seq||0:e.src.get(e.id).then((function(e){return t.version!==e.version?0:(r=t.version?t.version.toString():"undefined")in oa?oa[r](t,e):0;var r}),(function(r){if(404===r.status&&t.last_seq)return e.src.put({_id:e.id,last_seq:0}).then((function(){return 0}),(function(r){return aa(r)?(e.opts.writeSourceCheckpoint=!1,t.last_seq):0}));throw r}))})).catch((function(e){if(404!==e.status)throw e;return 0})):Promise.resolve(0)}}var oa={undefined:function(e,t){return 0===ms(e.last_seq,t.last_seq)?t.last_seq:0},1:function(e,t){return function(e,t){if(e.session_id===t.session_id)return{last_seq:e.last_seq,history:e.history};return sa(e.history,t.history)}(t,e).last_seq}};function sa(e,t){var r=e[0],n=e.slice(1),o=t[0],s=t.slice(1);return r&&0!==t.length?ia(r.session_id,t)?{last_seq:r.last_seq,history:e}:ia(o.session_id,n)?{last_seq:o.last_seq,history:s}:sa(n,s):{last_seq:0,history:[]}}function ia(e,t){var r=t[0],n=t.slice(1);return!(!e||0===t.length)&&(e===r.session_id||ia(e,n))}function aa(e){return"number"==typeof e.status&&4===Math.floor(e.status/100)}function ca(e,t,r,n,o){return this instanceof na?ca:new na(e,t,r,n,o)}function ua(e,t,r){var n=r.doc_ids?r.doc_ids.sort(ms):"",o=r.filter?r.filter.toString():"",s="",i="",a="";return r.selector&&(a=JSON.stringify(r.selector)),r.filter&&r.query_params&&(s=JSON.stringify(function(e){return Object.keys(e).sort(ms).reduce((function(t,r){return t[r]=e[r],t}),{})}(r.query_params))),r.filter&&"_view"===r.filter&&(i=r.view.toString()),Promise.all([e.id(),t.id()]).then((function(e){var t=e[0]+e[1]+o+i+s+n+a;return new Promise((function(e){bo(t,e)}))})).then((function(e){return"_local/"+(e=e.replace(/\//g,".").replace(/\+/g,"_"))}))}function la(e,t,r,n,o){var s,i,a,c,u=[],l={seq:0,changes:[],docs:[]},f=!1,d=!1,h=!1,p=0,m=0,v=r.continuous||r.live||!1,y=r.batch_size||100,g=r.batches_limit||10,_=r.style||"all_docs",w=!1,b=r.doc_ids,$=r.selector,k=[],E=Eo();o=o||{ok:!0,start_time:(new Date).toISOString(),docs_read:0,docs_written:0,doc_write_failures:0,errors:[]};var P={};function S(){return a?Promise.resolve():ua(e,t,r).then((function(o){i=o;var s={};s=!1===r.checkpoint?{writeSourceCheckpoint:!1,writeTargetCheckpoint:!1}:"source"===r.checkpoint?{writeSourceCheckpoint:!0,writeTargetCheckpoint:!1}:"target"===r.checkpoint?{writeSourceCheckpoint:!1,writeTargetCheckpoint:!0}:{writeSourceCheckpoint:!0,writeTargetCheckpoint:!0},a=new ca(e,t,i,n,s)}))}function j(){if(k=[],0!==s.docs.length){var e=s.docs,i={timeout:r.timeout};return t.bulkDocs({docs:e,new_edits:!1},i).then((function(t){if(n.cancelled)throw N(),new Error("cancelled");var r=Object.create(null);t.forEach((function(e){e.error&&(r[e.id]=e)}));var s=Object.keys(r).length;o.doc_write_failures+=s,o.docs_written+=e.length-s,e.forEach((function(e){var t=r[e._id];if(t){o.errors.push(t);var s=(t.name||"").toLowerCase();if("unauthorized"!==s&&"forbidden"!==s)throw t;n.emit("denied",gn(t))}else k.push(e)}))}),(function(t){throw o.doc_write_failures+=e.length,t}))}}function O(){if(s.error)throw new Error("There was a problem getting docs.");o.last_seq=m=s.seq;var t=gn(o);return k.length&&(t.docs=k,"number"==typeof s.pending&&(t.pending=s.pending,delete s.pending),n.emit("change",t)),f=!0,e.info().then((function(t){var r=e.activeTasks.get(c);if(s&&r){var n=r.completed_items||0,o=parseInt(t.update_seq,10)-parseInt(p,10);e.activeTasks.update(c,{completed_items:n+s.changes.length,total_items:o})}})),a.writeCheckpoint(s.seq,E).then((function(){if(n.emit("checkpoint",{checkpoint:s.seq}),f=!1,n.cancelled)throw N(),new Error("cancelled");s=void 0,D()})).catch((function(e){throw V(e),e}))}function x(){return ea(e,t,s.diffs,n).then((function(e){s.error=!e.ok,e.docs.forEach((function(e){delete s.diffs[e._id],o.docs_read++,s.docs.push(e)}))}))}function A(){var e;n.cancelled||s||(0!==u.length?(s=u.shift(),n.emit("checkpoint",{start_next_batch:s.seq}),(e={},s.changes.forEach((function(t){n.emit("checkpoint",{revs_diff:t}),"_user/"!==t.id&&(e[t.id]=t.changes.map((function(e){return e.rev})))})),t.revsDiff(e).then((function(e){if(n.cancelled)throw N(),new Error("cancelled");s.diffs=e}))).then(x).then(j).then(O).then(A).catch((function(e){I("batch processing terminated with error",e)}))):C(!0))}function C(e){0!==l.changes.length?(e||d||l.changes.length>=y)&&(u.push(l),l={seq:0,changes:[],docs:[]},"pending"!==n.state&&"stopped"!==n.state||(n.state="active",n.emit("active")),A()):0!==u.length||s||((v&&P.live||d)&&(n.state="pending",n.emit("paused")),d&&N())}function I(e,t){h||(t.message||(t.message=e),o.ok=!1,o.status="aborting",u=[],l={seq:0,changes:[],docs:[]},N(t))}function N(s){if(!(h||n.cancelled&&(o.status="cancelled",f)))if(o.status=o.status||"complete",o.end_time=(new Date).toISOString(),o.last_seq=m,h=!0,e.activeTasks.remove(c,s),s){(s=Hn(s)).result=o;var i=(s.name||"").toLowerCase();"unauthorized"===i||"forbidden"===i?(n.emit("error",s),n.removeAllListeners()):function(e,t,r,n){if(!1===e.retry)return t.emit("error",r),void t.removeAllListeners();if("function"!=typeof e.back_off_function&&(e.back_off_function=An),t.emit("requestError",r),"active"===t.state||"pending"===t.state){t.emit("paused",r),t.state="stopped";var o=function(){e.current_back_off=0};t.once("paused",(function(){t.removeListener("active",o)})),t.once("active",o)}e.current_back_off=e.current_back_off||0,e.current_back_off=e.back_off_function(e.current_back_off),setTimeout(n,e.current_back_off)}(r,n,s,(function(){la(e,t,r,n)}))}else n.emit("complete",o),n.removeAllListeners()}function T(t,o,s){if(n.cancelled)return N();if("number"==typeof o&&(l.pending=o),Qn(r)(t))l.seq=t.seq||s,l.changes.push(t),n.emit("checkpoint",{pending_batch:l.seq}),On((function(){C(0===u.length&&P.live)}));else{var i=e.activeTasks.get(c);if(i){var a=i.completed_items||0;e.activeTasks.update(c,{completed_items:++a})}}}function R(e){if(w=!1,n.cancelled)return N();if(e.results.length>0)P.since=e.results[e.results.length-1].seq,D(),C(!0);else{var t=function(){v?(P.live=!0,D()):d=!0,C(!0)};s||0!==e.results.length?t():(f=!0,a.writeCheckpoint(e.last_seq,E).then((function(){if(f=!1,o.last_seq=m=e.last_seq,n.cancelled)throw N(),new Error("cancelled");t()})).catch(V))}}function q(e){if(w=!1,n.cancelled)return N();I("changes rejected",e)}function D(){if(!w&&!d&&u.length<g){w=!0,n._changes&&(n.removeListener("cancel",n._abortChanges),n._changes.cancel()),n.once("cancel",o);var t=e.changes(P).on("change",T);t.then(s,s),t.then(R).catch(q),r.retry&&(n._changes=t,n._abortChanges=o)}function o(){t.cancel()}function s(){n.removeListener("cancel",o)}}function L(t){return e.info().then((function(n){var o=void 0===r.since?parseInt(n.update_seq,10)-parseInt(t,10):parseInt(n.update_seq,10);return c=e.activeTasks.add({name:`${v?"continuous ":""}replication from ${n.db_name}`,total_items:o}),t}))}function M(){S().then((function(){if(!n.cancelled)return a.getCheckpoint().then(L).then((function(e){p=e,P={since:m=e,limit:y,batch_size:y,style:_,doc_ids:b,selector:$,return_docs:!0},r.filter&&("string"!=typeof r.filter?P.include_docs=!0:P.filter=r.filter),"heartbeat"in r&&(P.heartbeat=r.heartbeat),"timeout"in r&&(P.timeout=r.timeout),r.query_params&&(P.query_params=r.query_params),r.view&&(P.view=r.view),D()}));N()})).catch((function(e){I("getCheckpoint rejected with ",e)}))}function V(e){f=!1,I("writeCheckpoint completed with error",e)}n.ready(e,t),n.cancelled?N():(n._addedListeners||(n.once("cancel",N),"function"==typeof r.complete&&(n.once("error",r.complete),n.once("complete",(function(e){r.complete(null,e)}))),n._addedListeners=!0),void 0===r.since?M():S().then((function(){return f=!0,a.writeCheckpoint(r.since,E)})).then((function(){f=!1,n.cancelled?N():(m=r.since,M())})).catch(V))}class fa extends ln{constructor(){super(),this.cancelled=!1,this.state="pending";const e=new Promise(((e,t)=>{this.once("complete",e),this.once("error",t)}));this.then=function(t,r){return e.then(t,r)},this.catch=function(t){return e.catch(t)},this.catch((function(){}))}cancel(){this.cancelled=!0,this.state="cancelled",this.emit("cancel")}ready(e,t){if(this._readyCalled)return;this._readyCalled=!0;const r=()=>{this.cancel()};function n(){e.removeListener("destroyed",r),t.removeListener("destroyed",r)}e.once("destroyed",r),t.once("destroyed",r),this.once("complete",n),this.once("error",n)}}function da(e,t){var r=t.PouchConstructor;return"string"==typeof e?new r(e,t):e}function ha(e,t,r,n){if("function"==typeof r&&(n=r,r={}),void 0===r&&(r={}),r.doc_ids&&!Array.isArray(r.doc_ids))throw Hn(zn,"`doc_ids` filter parameter is not a list.");r.complete=n,(r=gn(r)).continuous=r.continuous||r.live,r.retry="retry"in r&&r.retry,r.PouchConstructor=r.PouchConstructor||this;var o=new fa(r);return la(da(e,r),da(t,r),r,o),o}function pa(e,t,r,n){return"function"==typeof r&&(n=r,r={}),void 0===r&&(r={}),(r=gn(r)).PouchConstructor=r.PouchConstructor||this,e=da(e,r),t=da(t,r),new ma(e,t,r,n)}class ma extends ln{constructor(e,t,r,n){super(),this.canceled=!1;const o=r.push?Object.assign({},r,r.push):r,s=r.pull?Object.assign({},r,r.pull):r;this.push=ha(e,t,o),this.pull=ha(t,e,s),this.pushPaused=!0,this.pullPaused=!0;const i=e=>{this.emit("change",{direction:"pull",change:e})},a=e=>{this.emit("change",{direction:"push",change:e})},c=e=>{this.emit("denied",{direction:"push",doc:e})},u=e=>{this.emit("denied",{direction:"pull",doc:e})},l=()=>{this.pushPaused=!0,this.pullPaused&&this.emit("paused")},f=()=>{this.pullPaused=!0,this.pushPaused&&this.emit("paused")},d=()=>{this.pushPaused=!1,this.pullPaused&&this.emit("active",{direction:"push"})},h=()=>{this.pullPaused=!1,this.pushPaused&&this.emit("active",{direction:"pull"})};let p={};const m=e=>(t,r)=>{("change"===t&&(r===i||r===a)||"denied"===t&&(r===u||r===c)||"paused"===t&&(r===f||r===l)||"active"===t&&(r===h||r===d))&&(t in p||(p[t]={}),p[t][e]=!0,2===Object.keys(p[t]).length&&this.removeAllListeners(t))};function v(e,t,r){-1==e.listeners(t).indexOf(r)&&e.on(t,r)}r.live&&(this.push.on("complete",this.pull.cancel.bind(this.pull)),this.pull.on("complete",this.push.cancel.bind(this.push))),this.on("newListener",(function(e){"change"===e?(v(this.pull,"change",i),v(this.push,"change",a)):"denied"===e?(v(this.pull,"denied",u),v(this.push,"denied",c)):"active"===e?(v(this.pull,"active",h),v(this.push,"active",d)):"paused"===e&&(v(this.pull,"paused",f),v(this.push,"paused",l))})),this.on("removeListener",(function(e){"change"===e?(this.pull.removeListener("change",i),this.push.removeListener("change",a)):"denied"===e?(this.pull.removeListener("denied",u),this.push.removeListener("denied",c)):"active"===e?(this.pull.removeListener("active",h),this.push.removeListener("active",d)):"paused"===e&&(this.pull.removeListener("paused",f),this.push.removeListener("paused",l))})),this.pull.on("removeListener",m("pull")),this.push.on("removeListener",m("push"));const y=Promise.all([this.push,this.pull]).then((e=>{const t={push:e[0],pull:e[1]};return this.emit("complete",t),n&&n(null,t),this.removeAllListeners(),t}),(e=>{if(this.cancel(),n?n(e):this.emit("error",e),this.removeAllListeners(),n)throw e}));this.then=function(e,t){return y.then(e,t)},this.catch=function(e){return y.catch(e)}}cancel(){this.canceled||(this.canceled=!0,this.push.cancel(),this.pull.cancel())}}es.plugin((function(e){e.adapter("idb",yi,!0)})).plugin((function(e){e.adapter("http",ji,!1),e.adapter("https",ji,!1)})).plugin(Xi).plugin((function(e){e.replicate=ha,e.sync=pa,Object.defineProperty(e.prototype,"replicate",{get:function(){var e=this;return void 0===this.replicateMethods&&(this.replicateMethods={from:function(t,r,n){return e.constructor.replicate(t,e,r,n)},to:function(t,r,n){return e.constructor.replicate(e,t,r,n)}}),this.replicateMethods}}),e.prototype.sync=function(e,t,r){return this.constructor.sync(this,e,t,r)}}));const va=e=>`${e.source}/${encodeURIComponent(e.actor)}/${encodeURIComponent(e.name)}`,ya=e=>{const t=e.split("/"),r=t.pop(),n=t.pop();if(!r||!n||!t.length)throw new a;return{name:decodeURIComponent(r),actor:decodeURIComponent(n),source:t.join("/")}};function ga(e=16){const t=new Uint8Array(e);crypto.getRandomValues(t);return btoa(String.fromCodePoint(...t)).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=+$/,"")}function _a(e){return"string"==typeof e?{location:ya(e),uri:e}:{location:{name:e.name,actor:e.actor,source:e.source},uri:va(e)}}function wa(e,t,r,n){const o=r[t];if(o&&o.length)try{n[t]=e(n[t],o,!0,!1).newDocument}catch(e){throw"object"==typeof e&&e&&"name"in e&&"string"==typeof e.name&&"message"in e&&"string"==typeof e.message?"TEST_OPERATION_FAILED"===e.name?new s(e.message):new i(e.name+": "+e.message):e}}function ba(e,t){try{return e.compile(t)}catch(e){throw new n(e instanceof Error?e.message:void 0)}}function $a(e,t,r){e.actor!==r?.actor&&(e.allowed=e.allowed&&r?[r.actor]:void 0,e.channels=e.channels.filter((e=>t.includes(e))))}function ka(e,t){return void 0===e.allowed||!!t?.actor&&(e.actor===t.actor||e.allowed.includes(t.actor))}
|
|
8
8
|
/*! *****************************************************************************
|
|
9
9
|
Copyright (c) Microsoft Corporation.
|
|
10
10
|
|