couchdb-web-node-plugin 1.0.523 → 1.0.526

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/databaseHelper.js CHANGED
@@ -1 +1 @@
1
- (()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function r(){return(r=n()?Reflect.construct:function(e,t,r){var n=[null];n.push.apply(n,t);var a=new(Function.bind.apply(e,n));return r&&o(a,r.prototype),a}).apply(null,arguments)}function n(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function o(e,t){return o=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},o(e,t)}function a(){return a=Object.assign||function(e){for(var t,r=1;r<arguments.length;r++)for(var n in t=arguments[r])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e},a.apply(this,arguments)}function i(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return l(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?l(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function l(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}e.r(t),e.d(t,{DatabaseHelper:()=>c,default:()=>p});var c=function(){function e(){}return e.authenticate=function(e,t,r,n,o,a,l,c,p){var s;void 0===t&&(t=null),void 0===r&&(r={}),void 0===n&&(n={admins:{names:[],roles:[]},members:{names:[],roles:[]}}),void 0===a&&(a="_id"),void 0===l&&(l="-type"),void 0===c&&(c="_design/"),void 0===p&&(p=!1);var u=null!==(s=e[l])&&void 0!==s?s:t&&t[l];if(!u)return!0;var m=p?"read":"write",y={properties:{},read:["_admin","readonlyadmin"],write:["_admin"]};Object.prototype.hasOwnProperty.call(e,a)&&e[a].startsWith(c)&&y.read.push("readonlymember");var d,f="Current user doesn't own any role";if(r)if("name"in r||(r.name='"unknown"'),null!=(d=r.roles)&&d.length){if(o&&u&&Object.prototype.hasOwnProperty.call(o,u)){for(var h,g,v=o[u],O=i(["read","write"]);!(h=O()).done;)y[g=h.value]=y[g].concat(v[g]||[]);y.properties=v.properties}for(var b,w,P=y[m],j=i(r.roles);!(b=j()).done;)if(w=b.value,P.includes(w))return!0;f='Current user "'+r.name+'" owns the following roles: "'+r.roles.join('", "')+'"'}else f='Current user "'+r.name+"\" doesn't own any role";throw{unauthorized:"Only users with a least on of these roles are allowed to perform requested "+m+' action: "'+[].concat(y[m]).join('", "')+'". '+f+"."}},e.validateDocumentUpdate=function(e,t,n,o,l,c,p){void 0===c&&(c={});var s=function(e,t,r){var n;void 0===t&&(t="forbidden"),void 0===r&&(r={});for(var o=((n={})[t]=e,n.message=e,n.name=t,n),a=0,i=Object.entries(r);a<i.length;a++){var l=i[a],c=l[0],p=l[1];o[c]=p}throw o},u=new Date,m=Date.UTC(u.getUTCFullYear(),u.getUTCMonth(),u.getUTCDate(),u.getUTCHours(),u.getUTCMinutes(),u.getUTCSeconds(),u.getUTCMilliseconds())/1e3,y=!l.dateTimeFormat.startsWith("iso"),d=l.property.name.special,f=d.id,h=d.revision,g=d.type;t&&t[g]&&!e[g]&&(e[g]=t[g]);var v="",O="",b=function(){v=Object.prototype.hasOwnProperty.call(e,f)?e[f]:"",O=Object.prototype.hasOwnProperty.call(e,h)?e[h]:""};if(b(),Object.prototype.hasOwnProperty.call(o,l.property.name.validatedDocumentsCache)&&o[l.property.name.validatedDocumentsCache].has(v+"-"+O))return o[l.property.name.validatedDocumentsCache].delete(v+"-"+O),e;["latest","upsert"].includes(O)&&(t&&Object.prototype.hasOwnProperty.call(t,h)?O=e[h]=t[h]:"latest"===O?s("Revision: No old document available to update."):delete e[h]);var w=l.updateStrategy;Object.prototype.hasOwnProperty.call(e,d.strategy)&&(w=e[d.strategy],delete e[d.strategy]);var P,j={};if("migrate"===w)for(var x=0,N=Object.entries(c);x<N.length;x++){var A=N[x],C=A[0],S=A[1];if(Object.prototype.hasOwnProperty.call(S,d.oldType)&&![null,void 0].includes(S[d.oldType]))for(var k,T,E=i([].concat(S[d.oldType]));!(k=E()).done;)T=k.value,j[T]=C}p?P=p:JSON&&Object.prototype.hasOwnProperty.call(JSON,"stringify")?P=function(e){return JSON.stringify(e,null,4)}:s('Needed "serializer" is not available.');var D=function(e){return e instanceof Error?""+e:P(e)},z=function(e){return"string"==typeof e?e.trim():""},R=function(e){if(y)null!==e&&"number"!=typeof e&&(e=new Date(e),e=Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate(),e.getUTCHours(),e.getUTCMinutes(),e.getUTCSeconds(),e.getUTCMilliseconds())/1e3);else if(null!==e){e=new Date("number"!=typeof e||isNaN(e)?e:1e3*e);try{e=e.toISOString()}catch(e){}}return e},M=function(e,t,r){if(r.fileName){if(r.fileName.value)return r.fileName.value===t;if(r.fileName.regularExpressionPattern)return new RegExp(r.fileName.regularExpressionPattern).test(t)}return e===t},U=function(t,r){if(r||(r=e[d.attachment]),t){for(var n,o=0,a=Object.keys(r);o<a.length;o++)if((n=a[o]).startsWith(t))return n}else{var i=Object.keys(r);if(i.length)return i[0]}return null},_=function(e,t,n){void 0===t&&(t=!1),void 0===n&&(n={});var o=z(e);if(o){var i,l=(t?"return ":"")+o,c=a({},L,{code:l},n),p=Object.keys(c);try{i=r(Function,p.concat([l]))}catch(e){s(D(e),"compilation",{code:l,error:e,scope:c})}var u={code:l,result:void 0,scope:c};try{u.result=i.apply(void 0,p.map((function(e){return c[e]})))}catch(e){s(D(e),"runtime",{code:l,error:e,scope:c})}return u}s("No expression to evaluate provided.","empty")},H=function(e,t,n){void 0===n&&(n=[]);var o=n.length?" in "+n.join(" -> "):"",a=[],p=function(){Object.prototype.hasOwnProperty.call(e,g)||(t&&Object.prototype.hasOwnProperty.call(t,g)&&["fillUp","migrate"].includes(w)?e[g]=t[g]:s('Type: You have to specify a model type via property "'+g+'"'+o+".")),n.length||new RegExp(l.property.name.typeRegularExpressionPattern.public).test(e[g])||s('TypeName: You have to specify a model type which matches "'+l.property.name.typeRegularExpressionPattern.public+'" as public type (given "'+e[g]+'")'+o+"."),Object.prototype.hasOwnProperty.call(c,e[g])||(Object.prototype.hasOwnProperty.call(j,e[g])?e[g]=j[e[g]]:s('Model: Given model "'+e[g]+'" is not specified'+o+"."))};p();var u=e[g],m=c[u],v=null;Object.prototype.hasOwnProperty.call(m,d.additional)&&m[d.additional]&&(v=m[d.additional]);var O=function(a,l,c,p,y){void 0===y&&(y=["constraintExecution","constraintExpression"]);for(var d,f,h=i(y);!(d=h()).done;)if(f=d.value,Object.prototype.hasOwnProperty.call(c,f)){var g,v=void 0;try{v=_(c[f].evaluation,f.endsWith("Expression"),{checkPropertyContent:P,model:m,modelName:u,name:l,type:f,newDocument:e,newValue:a,oldDocument:t,oldValue:p,parentNames:n,pathDescription:o,propertySpecification:c})}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&s('Compilation: Hook "'+f+'" has invalid code "'+e.code+'": "'+e.message+'"'+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&s('Runtime: Hook "'+f+'" has throw an error with code "'+e.code+'": "'+e.message+'"'+o+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}if(null==(g=v)||!g.result){var O=z(c[f].description);s(f.charAt(0).toUpperCase()+(f.substring(1)+": ")+(O?r(Function,Object.keys(v.scope).concat(["return "+O])).apply(void 0,Object.values(v.scope)):'Property "'+l+'" should satisfy constraint "'+v.code+'" (given "'+D(a)+'")'+o+"."))}}},P=function(e,t,r,a){void 0===a&&(a=null);var l=[],p=[].concat(r.type?r.type:[]);"object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype&&!Object.prototype.hasOwnProperty.call(e,g)&&1===p.length&&Object.prototype.hasOwnProperty.call(c,p[0])&&(e[g]=p[0]);for(var u,m,d=!1,h=i(p);!(u=h()).done;)if(m=u.value,Object.prototype.hasOwnProperty.call(c,m)){if("object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype&&Object.prototype.hasOwnProperty.call(e,g)&&e[g]!==m&&"migrate"===w&&1===p.length&&(e[g]=m,l=n.concat(t,"migrate nested object type")),"object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype&&Object.prototype.hasOwnProperty.call(e,g)&&e[g]===m){var v=H(e,a,n.concat(t));if(v.changedPath.length&&(l=v.changedPath),e=v.newDocument,D(e)===D({}))return{newValue:null,changedPath:l};d=!0;break}1===p.length&&s('NestedType: Under key "'+t+'" isn\'t of type "'+m+'" (given "'+D(e)+'" of type '+typeof e+")"+o+".")}else if("DateTime"===m){var b=e;if(e=R(e),!(y&&("number"!=typeof e||isNaN(e))||!y&&"string"!=typeof e)){d=!0;break}1===p.length&&s('PropertyType: Property "'+t+'" isn\'t of (valid) type "DateTime" (given "'+D(b).replace(/^"/,"").replace(/"$/,"")+'" of type "'+typeof b+'")'+o+".")}else if(["boolean","integer","number","string"].includes(m)){if(!("number"==typeof e&&isNaN(e)||"integer"!==m&&typeof e!==m||"integer"===m&&parseInt(e,10)!==e)){d=!0;break}1===p.length&&s('PropertyType: Property "'+t+'" isn\'t of (valid) type "${type}" (given "'+D(e)+'" of type "'+typeof e+'")'+o+".")}else if("string"==typeof m&&m.startsWith("foreignKey:")){var P=c[m.substring(11)][f].type;if(P===typeof e){d=!0;break}1===p.length&&s('PropertyType: Foreign key property "'+t+'" isn\'t of type "'+P+'" (given "'+D(e)+'" of type "'+typeof e+'")'+o+".")}else{if("any"===m||D(e)===D(m)){d=!0;break}1===p.length&&s('PropertyType: Property "'+t+'" isn\'t value "'+m+'" (given "'+D(e).replace(/^"/,"").replace(/"$/,"")+'" of type "'+typeof e+'")'+o+".")}if(d||s('PropertyType: None of the specified types "'+p.join('", "')+'" for property "'+t+'" matches value "'+D(e).replace(/^"/,"").replace(/"$/,"")+e+'" of type "'+typeof e+'")'+o+"."),"string"==typeof e&&(![null,void 0].includes(r.minimumLength)&&e.length<r.minimumLength&&s('MinimalLength: Property "'+t+'" must have minimal length '+r.minimumLength+" (given "+e+" with length i"+e.length+") "+o+"."),![null,void 0].includes(r.maximumLength)&&e.length>r.maximumLength&&s('MaximalLength: Property "'+t+'" must have maximal length '+r.maximumLength+" (given "+e+" with length "+e.length+")"+o+".")),"number"==typeof e&&(![null,void 0].includes(r.minimum)&&e<r.minimum&&s('Minimum: Property "'+t+'" (type '+r.type+") must satisfy a minimum of "+r.minimum+" (given "+e+" is too low)"+o+"."),![null,void 0].includes(r.maximum)&&e>r.maximum&&s('Maximum: Property "'+t+'" (type '+r.type+") must satisfy a maximum of "+r.maximum+" (given "+e+" is too high)"+o+".")),r.selection){var j=Array.isArray(r.selection)?r.selection.map((function(e){return void 0===(null==e?void 0:e.value)?e:e.value})):Object.keys(r.selection);"DateTime"===r.type&&(j=j.map(R)),j.includes(e)||s('Selection: Property "'+t+'" (type '+r.type+') should be one of "'+j.join('", "')+'". But is "'+e+'"'+o+".")}return[null,void 0].includes(r.regularExpressionPattern)||new RegExp(r.regularExpressionPattern).test(e)?![null,void 0].includes(r.invertedRegularExpressionPattern)&&new RegExp(r.invertedRegularExpressionPattern).test(e)&&s('InvertedPatternMatch: Property "'+t+'" should not match regular expression pattern '+r.invertedRegularExpressionPattern+' (given "'+e+'")'+o+"."):s('PatternMatch: Property "'+t+'" should match regular expression pattern '+r.regularExpressionPattern+' (given "'+e+'")'+o+"."),O(e,t,r,a),D(e)!==D(a)&&(l=n.concat(t,"value updated")),{newValue:e,changedPath:l}},x=function(e,t,r,o,i){var c=t[o];if(!e.writable)if(r){if(Object.prototype.hasOwnProperty.call(r,o)&&D(c)===D(r[o]))return o!==f&&"incremental"===w&&delete t[o],!0;s('Readonly: Property "'+o+'" is not writable (old document "'+D(r)+'")'+i+".")}else s('Readonly: Property "'+o+'" is not writable'+i+".");if(!e.mutable&&r&&Object.prototype.hasOwnProperty.call(r,o)){if(D(c)===D(r[o]))return"incremental"!==w||l.property.name.reserved.concat(d.deleted,f,h).includes(o)||delete t[o],!0;"migrate"!==w&&s('Immutable: Property "'+o+'" is not writable (old document "'+D(r)+'")'+i+".")}if(null===c){if(e.nullable)return delete t[o],r&&Object.prototype.hasOwnProperty.call(r,o)&&(a=n.concat(o,"delete property")),!0;s('NotNull: Property "'+o+'" should not be "null"'+i+".")}return!1},N=function(e,t,r,a){if(!r)for(var l,c,p=i(["onCreateExecution","onCreateExpression"]);!(l=p()).done;)if(c=l.value,Object.prototype.hasOwnProperty.call(e,c)){var y=void 0;try{y=_(e[c],c.endsWith("Expression"),{checkPropertyContent:P,model:m,modelName:u,name:a,type:c,newDocument:t,oldDocument:r,newValue:void 0,oldValue:void 0,parentNames:n,pathDescription:o,propertySpecification:e})}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&s('Compilation: Hook "'+c+'" has invalid code "'+e.code+'" for property "'+a+'": '+e.message+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&s('Runtime: Hook "'+c+'" has throw an error with code "'+e.code+'" for property "'+a+'": '+e.message+o+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}y&&![null,void 0].includes(y.result)&&(t[a]=y.result)}},A=function(e,t,r,a){if(Object.prototype.hasOwnProperty.call(t,a)){e.trim&&"string"==typeof t[a]&&(t[a]=t[a].trim()),e.emptyEqualsToNull&&(""===t[a]||Array.isArray(t[a])&&0===t[a].length||null!==t[a]&&"object"==typeof t[a]&&0===Object.keys(t).length)&&(t[a]=null);for(var l,c,p=i(["onUpdateExecution","onUpdateExpression"]);!(l=p()).done;)if(c=l.value,Object.prototype.hasOwnProperty.call(e,c))try{t[a]=_(e[c],c.endsWith("Expression"),{checkPropertyContent:P,model:m,modelName:u,name:a,type:c,newDocument:t,oldDocument:r,newValue:t[a],oldValue:r&&r[a],parentNames:n,pathDescription:o,propertySpecification:e}).result}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&s('Compilation: Hook "'+c+'" has invalid code "'+e.code+'" for property "'+a+'": '+e.message+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&s('Runtime: Hook "'+c+'" has throw an error with code "'+e.code+'" for property "'+a+'": '+e.message+o+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}}},C=Object.keys(m).filter((function(e){return![d.additional,d.allowedRoles,d.constraint.execution,d.constraint.expression,d.create.execution,d.create.expression,d.extend,d.maximumAggregatedSize,d.minimumAggregatedSize,d.oldType,d.update.execution,d.update.expression].includes(e)}));if("migrate"===w)for(var S,k,T=i(C);!(S=T()).done;)if(k=S.value,![null,void 0].includes(m[k].oldName))for(var E,U,L=i([].concat(m[k].oldName));!(E=L()).done;)U=E.value,Object.prototype.hasOwnProperty.call(e,U)&&(e[k]=e[U],delete e[U]);if(!t)for(var I,W=0,V=[d.create.execution,d.create.expression];W<V.length;W++)if(I=V[W],Object.prototype.hasOwnProperty.call(m,I)){var F=void 0;try{F=_(m[I],I.endsWith("Expression"),{checkPropertyContent:P,model:m,modelName:u,type:I,newDocument:e,oldDocument:t,parentNames:n,pathDescription:o}).result}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&s('Compilation: Hook "'+I+'" has invalid code "'+e.code+'" for document "'+u+'": '+e.message+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&s('Runtime: Hook "'+I+'" has throw an error with code "'+e.code+'" for document "'+u+'": '+e.message+o+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}[null,void 0].includes(F)||(e=F),p(),u=e[g],0===n.length&&b()}for(var B,$=0,q=[d.update.execution,d.update.expression];$<q.length;$++)if(B=q[$],Object.prototype.hasOwnProperty.call(m,B)){var Y=void 0;try{Y=_(m[B],B.endsWith("Expression"),{checkPropertyContent:P,model:m,modelName:u,type:B,newDocument:e,oldDocument:t,parentNames:n,pathDescription:o}).result}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&s('Compilation: Hook "'+B+'" has invalid code "'+e.code+'" for document "'+u+'": '+e.message+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&s('Runtime: Hook "'+B+'" has throw an error with code "'+e.code+'" for document "'+u+'": '+e.message+o+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}[void 0,null].includes(Y)||(e=Y),p(),u=e[g],0===n.length&&b()}for(var J,G=function(){var r=J.value;if(d.attachment===r)for(var l=function(){var l=p[c],u=l[0],m=l[1];Object.prototype.hasOwnProperty.call(e,r)&&null!==e[r]||(e[r]={}),t&&!Object.prototype.hasOwnProperty.call(t,r)&&(t[r]={});var y=Object.keys(e[r]).filter((function(t){return null!==e[r][t].data&&M(u,t,m)})),d=e[r],f=[];if(t){var h=t[r];f=Object.keys(h).filter((function(e){return!(Object.prototype.hasOwnProperty.call(d,e)&&Object.prototype.hasOwnProperty.call(d[e],"data")&&null===d[e].data)&&!!h[e]&&(Object.prototype.hasOwnProperty.call(h[e],"data")&&null!==h[e].data||h[e].stub&&!!h[e].digest)&&!!M(u,e,m)}))}for(var g,v,O=m,b=i(y);!(g=b()).done;)v=g.value,N(O,d,t&&t[r]?t[r]:null,v);for(var P,j,x=i(y);!(P=x()).done;)j=P.value,A(O,d,t&&t[r]?t[r]:null,j);if([null,void 0].includes(O.default)){if(O.nullable||0<y.length||0<f.length||s('AttachmentMissing: Missing attachment for type "'+u+'"'+o+"."),"fillUp"===w&&0===y.length&&0<f.length)for(var C,S,k=i(f);!(C=k()).done;)S=C.value,null===d[S]?a=n.concat(r,S,"file removed"):d[S]=t[r][S]}else if(0===y.length)if(0===f.length)for(var T in O.default)Object.prototype.hasOwnProperty.call(O.default,T)&&(d[T]=O.default[T],a=n.concat(r,u,"add default file"));else if("fillUp"===w)for(var E,D,z=i(f);!(E=z()).done;)D=E.value,d[D]=t[r][D]},c=0,p=Object.entries(m[r]);c<p.length;c++)l();else{var u=C.includes(r)?m[r]:v;N(u,e,t,r),A(u,e,t,r),[null,void 0].includes(u.default)?(!(u.nullable||Object.prototype.hasOwnProperty.call(e,r)||t&&Object.prototype.hasOwnProperty.call(t,r)&&w)&&s('MissingProperty: Missing property "'+r+'"'+o+"."),!Object.prototype.hasOwnProperty.call(e,r)&&t&&Object.prototype.hasOwnProperty.call(t,r)&&("fillUp"===w?e[r]=t[r]:!w&&(a=n.concat(r,"property removed")))):(!Object.prototype.hasOwnProperty.call(e,r)||null===e[r])&&(t&&Object.prototype.hasOwnProperty.call(t,r)?"fillUp"===w?e[r]=t[r]:"migrate"===w&&(e[r]=u.default,a=n.concat(r,"migrate default value")):(e[r]=u.default,a=a.concat(r,"add default value")))}},K=i(C.concat(v?Object.keys(e).filter((function(e){return!C.includes(e)})):[]));!(J=K()).done;)G();if(t&&"incremental"===w)for(var Z=0,Q=Object.entries(e);Z<Q.length;Z++){var X=Q[Z],ee=X[0],te=X[1];!Object.prototype.hasOwnProperty.call(t,ee)||l.property.name.reserved.concat(f,h,d.conflict,d.deleted,d.deletedConflict,d.localSequence,d.revisions,d.revisionsInformation,g).includes(ee)||t[ee]!==te&&D(t[ee])!==D(te)||delete e[ee]}for(var re=0,ne=Object.entries(e);re<ne.length;re++){var oe=ne[re],ae=oe[0],ie=oe[1];if(!l.property.name.reserved.concat(h,d.conflict,d.deleted,d.deletedConflict,d.localSequence,d.revisions,d.revisionsInformation,d.strategy).includes(ae)){var le=void 0;if(Object.prototype.hasOwnProperty.call(m,ae))le=m[ae];else if(v)le=v;else{if("migrate"===w){delete e[ae],a=n.concat(ae,"migrate removed property");continue}s('Property: Given property "'+ae+'" isn\'t specified in model "'+u+'"'+o+".")}if(!le)continue;if(d.attachment===ae){var ce=ie;for(var pe in ce)if(Object.prototype.hasOwnProperty.call(ce,pe))for(var se in m[ae])if(M(se,pe,m[ae][se])){x(m[ae][se],e,t,pe,o);break}continue}if(x(le,e,t,ae,o))continue;if("string"==typeof le.type&&le.type.endsWith("[]")||Array.isArray(le.type)&&le.type.length&&Array.isArray(le.type[0])){var ue,me=ie;Array.isArray(me)?![null,void 0].includes(le.minimumNumber)&&me.length<le.minimumNumber?s('MinimumArrayLength: Property "'+ae+'" (array of length '+me.length+") doesn't fullfill minimum array length of "+le.minimumNumber+o+"."):![null,void 0].includes(le.maximumNumber)&&le.maximumNumber<me.length&&s('MaximumArrayLength: Property "'+ae+'" (array of length '+me.length+") doesn't fullfill maximum array length of "+le.maximumNumber+o+"."):s('PropertyType: Property "'+ae+'" isn\'t of type "array -> '+le.type+'" (given "'+D(me)+'")'+o+"."),O(me,ae,le,t&&Object.prototype.hasOwnProperty.call(t,ae)&&t[ae]||void 0,["arrayConstraintExecution","arrayConstraintExpression"]);var ye={};for(var de in le)Object.prototype.hasOwnProperty.call(le,de)&&(ye[de]="type"===de?Array.isArray(le[de])?le[de][0]:[le[de].substring(0,le.type.length-2)]:le[de]);if(1===(null==(ue=ye.type)?void 0:ue.length)&&Object.prototype.hasOwnProperty.call(c,ye.type[0]))for(var fe,he,ge=i(me.slice());!(fe=ge()).done;)"object"!=typeof(he=fe.value)||Object.getPrototypeOf(he)!==Object.prototype||Object.prototype.hasOwnProperty.call(he,g)||(he[g]=ye.type[0]);for(var ve,Oe,be=0,we=i(me.slice());!(ve=we()).done;)Oe=ve.value,me[be]=P(Oe,be+1+". value in "+ae,ye).newValue,null===Oe&&me.splice(be,1),be+=1;t&&Object.prototype.hasOwnProperty.call(t,ae)&&Array.isArray(t[ae])&&t[ae].length===me.length&&D(t[ae])===D(me)||(a=n.concat(ae,"array updated"))}else{var Pe=t&&Object.prototype.hasOwnProperty.call(t,ae)?t[ae]:null,je=P(ie,ae,le,Pe);e[ae]=je.newValue,je.changedPath.length&&(a=je.changedPath),null===e[ae]&&(null!==Pe&&(a=n.concat(ae,"property removed")),delete e[ae])}}}for(var xe,Ne=0,Ae=Object.keys(d.constraint);Ne<Ae.length;Ne++)if(xe=Ae[Ne],(xe=d.constraint[xe])&&Object.prototype.hasOwnProperty.call(m,xe))for(var Ce,Se=i([].concat(m[xe]));!(Ce=Se()).done;){var ke,Te=Ce.value,Ee=void 0;try{Ee=_(Te.evaluation,xe===d.constraint.expression,{checkPropertyContent:P,model:m,modelName:u,type:xe,newDocument:e,oldDocument:t,parentNames:n,pathDescription:o})}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&s('Compilation: Hook "'+xe+'" has invalid code "'+e.code+'": "'+e.message+'"'+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&s('Runtime: Hook "'+xe+'" has thrown an error with code "'+e.code+'": '+e.message+o+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}if(null==(ke=Ee)||!ke.result){var De=xe.replace(/^[^a-zA-Z]+/,"");s(De.charAt(0).toUpperCase()+(De.substring(1)+": ")+(Te.description?r(Function,Object.keys(Ee.scope).concat(["return "+Te.description.trim()])).apply(void 0,Object.values(Ee.scope)):'Model "'+u+'" should satisfy constraint "'+Ee.code+'" (given "'+D(e)+'")'+o+"."))}}if(Object.prototype.hasOwnProperty.call(e,d.attachment)){var ze=e[d.attachment];("object"!=typeof ze||Object.getPrototypeOf(ze)!==Object.prototype)&&s("AttachmentType: given attachment has invalid type"+o+".");var Re=null;if(t&&Object.prototype.hasOwnProperty.call(t,d.attachment)&&(null!==(Re=t[d.attachment])&&"object"==typeof Re))for(var Me=0,Ue=Object.entries(Re);Me<Ue.length;Me++){var _e=Ue[Me],He=_e[0],Le=_e[1];if(Object.prototype.hasOwnProperty.call(ze,He)){var Ie=ze[He];null===Ie||null===Ie.data||Ie.content_type===Le.content_type&&(Ie.data===Le.data||Ie.digest===Le.digest)?((null===Ie||null===Ie.data)&&(a=n.concat(d.attachment,He,"attachment removed")),"incremental"===w&&delete ze[He]):a=n.concat(d.attachment,He,"attachment updated")}else"fillUp"===w?ze[He]=Le:w||(a=n.concat(d.attachment,He,"attachment removed"))}for(var We=0,Ve=Object.entries(ze);We<Ve.length;We++){var Fe=Ve[We],Be=Fe[0],$e=Fe[1];[null,void 0].includes($e)||null===$e.data?delete ze[Be]:(!Re||!Object.prototype.hasOwnProperty.call(Re,Be)||$e.content_type!==Re[Be].content_type||$e.data!==Re[Be].data&&$e.digest!==Re[Be].digest)&&(a=n.concat(d.attachment,Be,"attachment updated"))}0===Object.keys(ze).length&&delete e[d.attachment];for(var qe={},Ye=0,Je=Object.keys(m[d.attachment]);Ye<Je.length;Ye++)qe[Je[Ye]]=[];for(var Ge=0,Ke=Object.keys(ze);Ge<Ke.length;Ge++){for(var Ze=Ke[Ge],Qe=!1,Xe=0,et=Object.entries(m[d.attachment]);Xe<et.length;Xe++){var tt=et[Xe],rt=tt[0],nt=tt[1];if(M(rt,Ze,nt)){qe[rt].push(Ze),Qe=!0;break}}Qe||s('AttachmentTypeMatch: None of the specified attachment types ("'+Object.keys(m[d.attachment]).join('", "')+'") matches given one ("'+Ze+'")'+o+".")}for(var ot=0,at=0,it=Object.keys(qe);at<it.length;at++){var lt=it[at],ct=m[d.attachment][lt];if(Object.prototype.hasOwnProperty.call(qe,lt)){var pt=qe[lt].length;null!==ct.maximumNumber&&pt>ct.maximumNumber&&s("AttachmentMaximum: given number of attachments ("+pt+") doesn't satisfy specified maximum of "+ct.maximumNumber+' from type "'+lt+'"'+o+"."),(!ct.nullable||0!==pt)&&pt<ct.minimumNumber&&s("AttachmentMinimum: given number of attachments ("+pt+") doesn't satisfy specified minimum of "+ct.minimumNumber+' from type "'+lt+'"'+o+".");for(var st,ut=0,mt=i(qe[lt]);!(st=mt()).done;){var yt,dt,ft=st.value;null!=(yt=ct.fileName)&&yt.regularExpressionPattern&&!new RegExp(ct.fileName.regularExpressionPattern).test(ft)?s('AttachmentName: given attachment name "'+ft+'" doesn\'t satisfy specified regular expression pattern "'+ct.fileName.regularExpressionPattern+'" from type "'+lt+'"'+o+"."):null!=(dt=ct.fileName)&&dt.invertedRegularExpressionPattern&&new RegExp(ct.fileName.invertedRegularExpressionPattern).test(ft)?s('InvertedAttachmentName: given attachment name "'+ft+'" does satisfy specified regular expression pattern "'+ct.fileName.invertedRegularExpressionPattern+'" from type "'+lt+'"'+o+"."):!([null,void 0].includes(ct.contentTypeRegularExpressionPattern)||ze[ft].content_type&&new RegExp(ct.contentTypeRegularExpressionPattern).test(ze[ft].content_type))&&s('AttachmentContentType: given attachment content type "'+ze[ft].content_type+'" doesn\'t satisfy specified regular expression pattern "'+ct.contentTypeRegularExpressionPattern+'" from type "'+lt+'"'+o+".");var ht=ct.invertedContentTypeRegularExpressionPattern;[null,void 0].includes(ht)||ze[ft].content_type&&!new RegExp(ht).test(ze[ft].content_type)||s('InvertedAttachmentContentType: given attachment content type "'+ze[ft].content_type+'" does satisfy specified regular expression pattern "'+ht+'" from type "'+lt+'"'+o+".");var gt=0;"length"in ze[ft]?gt=ze[ft].length:"data"in ze[ft]&&(gt=Buffer&&"byteLength"in Buffer?Buffer.byteLength(ze[ft].data,"base64"):ze[ft].data.length),![null,void 0].includes(ct.minimumSize)&&ct.minimumSize>gt?s("AttachmentMinimumSize: given attachment size "+gt+" byte doesn't satisfy specified minimum of "+ct.minimumSize+" byte "+o+"."):![null,void 0].includes(ct.maximumSize)&&ct.maximumSize<gt&&s("AttachmentMaximumSize: given attachment size "+gt+" byte doesn't satisfy specified maximum of "+ct.maximumSize+" byte "+o+"."),ut+=gt}![null,void 0].includes(ct.minimumAggregatedSize)&&ct.minimumAggregatedSize>ut?s('AttachmentAggregatedMinimumSize: given aggregated size of attachments from type "'+lt+'" '+ut+" byte doesn't satisfy specified minimum of "+ct.minimumAggregatedSize+" byte "+o+"."):![null,void 0].includes(ct.maximumAggregatedSize)&&ct.maximumAggregatedSize<ut&&s('AttachmentAggregatedMaximumSize: given aggregated size of attachments from type "'+lt+'" '+ut+" byte doesn't satisfy specified maximum of "+ct.maximumAggregatedSize+" byte "+o+"."),ot+=ut}}Object.prototype.hasOwnProperty.call(m,d.minimumAggregatedSize)&&![null,void 0].includes(m[d.minimumAggregatedSize])&&m[d.minimumAggregatedSize]>ot?s("AggregatedMinimumSize: given aggregated size "+ot+" byte doesn't satisfy specified minimum of "+m[d.minimumAggregatedSize]+" byte "+o+"."):![null,void 0].includes(m[d.maximumAggregatedSize])&&m[d.maximumAggregatedSize]<ot&&s("AggregatedMaximumSize: given aggregated size "+ot+" byte doesn't satisfy specified maximum of "+m[d.maximumAggregatedSize]+" byte "+o+".")}if(t&&Object.prototype.hasOwnProperty.call(t,d.attachment)&&0===Object.keys(t[d.attachment]).length&&delete t[d.attachment],0===a.length&&t&&"migrate"===w)for(var vt,Ot=0,bt=Object.keys(t);Ot<bt.length;Ot++)vt=bt[Ot],Object.prototype.hasOwnProperty.call(e,vt)||(a=n.concat(vt,"migrate removed property"));return{changedPath:a,newDocument:e}},L={attachmentWithPrefixExists:function(t){if(Object.prototype.hasOwnProperty.call(e,d.attachment)){var r=e[d.attachment],n=U(t);if(n)return Object.prototype.hasOwnProperty.call(r[n],"stub")&&r[n].stub||Object.prototype.hasOwnProperty.call(r[n],"data")&&![null,void 0].includes(r[n].data)}return!1},checkDocument:H,getFileNameByPrefix:U,serialize:D,id:v,revision:O,idName:f,revisionName:h,specialNames:d,typeName:g,modelConfiguration:l,models:c,now:u,nowUTCTimestamp:m,securitySettings:o,userContext:n},I=H(e,t);return(!I.newDocument._deleted||t)&&(I.newDocument._deleted&&I.newDocument._deleted!==(null==t?void 0:t._deleted)||I.changedPath.length)||s("NoChange: No new data given. new document: "+D(e)+"; old document: "+D(t)+"."),Object.prototype.hasOwnProperty.call(o,l.property.name.validatedDocumentsCache)?o[l.property.name.validatedDocumentsCache].add(v+"-"+O):o[l.property.name.validatedDocumentsCache]=new Set([v+"-"+O]),I.newDocument},e}();const p=c;module.exports=t})();
1
+ (()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function r(){return(r=n()?Reflect.construct.bind():function(e,t,r){var n=[null];n.push.apply(n,t);var a=new(Function.bind.apply(e,n));return r&&o(a,r.prototype),a}).apply(null,arguments)}function n(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function o(e,t){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},o(e,t)}function a(){return a=Object.assign?Object.assign.bind():function(e){for(var t,r=1;r<arguments.length;r++)for(var n in t=arguments[r])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e},a.apply(this,arguments)}function i(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return l(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?l(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function l(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}e.r(t),e.d(t,{DatabaseHelper:()=>c,default:()=>p});var c=function(){function e(){}return e.authenticate=function(e,t,r,n,o,a,l,c,p){var s;void 0===t&&(t=null),void 0===r&&(r={}),void 0===n&&(n={admins:{names:[],roles:[]},members:{names:[],roles:[]}}),void 0===a&&(a="_id"),void 0===l&&(l="-type"),void 0===c&&(c="_design/"),void 0===p&&(p=!1);var u=null!==(s=e[l])&&void 0!==s?s:t&&t[l];if(!u)return!0;var m=p?"read":"write",y={properties:{},read:["_admin","readonlyadmin"],write:["_admin"]};Object.prototype.hasOwnProperty.call(e,a)&&e[a].startsWith(c)&&y.read.push("readonlymember");var d,f="Current user doesn't own any role";if(r)if("name"in r||(r.name='"unknown"'),null!=(d=r.roles)&&d.length){if(o&&u&&Object.prototype.hasOwnProperty.call(o,u)){for(var h,g,v=o[u],O=i(["read","write"]);!(h=O()).done;)y[g=h.value]=y[g].concat(v[g]||[]);y.properties=v.properties}for(var b,w,P=y[m],j=i(r.roles);!(b=j()).done;)if(w=b.value,P.includes(w))return!0;f='Current user "'+r.name+'" owns the following roles: "'+r.roles.join('", "')+'"'}else f='Current user "'+r.name+"\" doesn't own any role";throw{unauthorized:"Only users with a least on of these roles are allowed to perform requested "+m+' action: "'+[].concat(y[m]).join('", "')+'". '+f+"."}},e.validateDocumentUpdate=function(e,t,n,o,l,c,p){void 0===c&&(c={});var s=function(e,t,r){var n;void 0===t&&(t="forbidden"),void 0===r&&(r={});for(var o=((n={})[t]=e,n.message=e,n.name=t,n),a=0,i=Object.entries(r);a<i.length;a++){var l=i[a],c=l[0],p=l[1];o[c]=p}throw o},u=new Date,m=Date.UTC(u.getUTCFullYear(),u.getUTCMonth(),u.getUTCDate(),u.getUTCHours(),u.getUTCMinutes(),u.getUTCSeconds(),u.getUTCMilliseconds())/1e3,y=!l.dateTimeFormat.startsWith("iso"),d=l.property.name.special,f=d.id,h=d.revision,g=d.type;t&&t[g]&&!e[g]&&(e[g]=t[g]);var v="",O="",b=function(){v=Object.prototype.hasOwnProperty.call(e,f)?e[f]:"",O=Object.prototype.hasOwnProperty.call(e,h)?e[h]:""};if(b(),Object.prototype.hasOwnProperty.call(o,l.property.name.validatedDocumentsCache)&&o[l.property.name.validatedDocumentsCache].has(v+"-"+O))return o[l.property.name.validatedDocumentsCache].delete(v+"-"+O),e;["latest","upsert"].includes(O)&&(t&&Object.prototype.hasOwnProperty.call(t,h)?O=e[h]=t[h]:"latest"===O?s("Revision: No old document available to update."):delete e[h]);var w=l.updateStrategy;Object.prototype.hasOwnProperty.call(e,d.strategy)&&(w=e[d.strategy],delete e[d.strategy]);var P,j={};if("migrate"===w)for(var x=0,N=Object.entries(c);x<N.length;x++){var A=N[x],C=A[0],S=A[1];if(Object.prototype.hasOwnProperty.call(S,d.oldType)&&![null,void 0].includes(S[d.oldType]))for(var k,T,E=i([].concat(S[d.oldType]));!(k=E()).done;)T=k.value,j[T]=C}p?P=p:JSON&&Object.prototype.hasOwnProperty.call(JSON,"stringify")?P=function(e){return JSON.stringify(e,null,4)}:s('Needed "serializer" is not available.');var D=function(e){return e instanceof Error?""+e:P(e)},z=function(e){return"string"==typeof e?e.trim():""},R=function(e){if(y)null!==e&&"number"!=typeof e&&(e=new Date(e),e=Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate(),e.getUTCHours(),e.getUTCMinutes(),e.getUTCSeconds(),e.getUTCMilliseconds())/1e3);else if(null!==e){e=new Date("number"!=typeof e||isNaN(e)?e:1e3*e);try{e=e.toISOString()}catch(e){}}return e},M=function(e,t,r){if(r.fileName){if(r.fileName.value)return r.fileName.value===t;if(r.fileName.regularExpressionPattern)return new RegExp(r.fileName.regularExpressionPattern).test(t)}return e===t},U=function(t,r){if(r||(r=e[d.attachment]),t){for(var n,o=0,a=Object.keys(r);o<a.length;o++)if((n=a[o]).startsWith(t))return n}else{var i=Object.keys(r);if(i.length)return i[0]}return null},_=function(e,t,n){void 0===t&&(t=!1),void 0===n&&(n={});var o=z(e);if(o){var i,l=(t?"return ":"")+o,c=a({},L,{code:l},n),p=Object.keys(c);try{i=r(Function,p.concat([l]))}catch(e){s(D(e),"compilation",{code:l,error:e,scope:c})}var u={code:l,result:void 0,scope:c};try{u.result=i.apply(void 0,p.map((function(e){return c[e]})))}catch(e){s(D(e),"runtime",{code:l,error:e,scope:c})}return u}s("No expression to evaluate provided.","empty")},H=function(e,t,n){void 0===n&&(n=[]);var o=n.length?" in "+n.join(" -> "):"",a=[],p=function(){Object.prototype.hasOwnProperty.call(e,g)||(t&&Object.prototype.hasOwnProperty.call(t,g)&&["fillUp","migrate"].includes(w)?e[g]=t[g]:s('Type: You have to specify a model type via property "'+g+'"'+o+".")),n.length||new RegExp(l.property.name.typeRegularExpressionPattern.public).test(e[g])||s('TypeName: You have to specify a model type which matches "'+l.property.name.typeRegularExpressionPattern.public+'" as public type (given "'+e[g]+'")'+o+"."),Object.prototype.hasOwnProperty.call(c,e[g])||(Object.prototype.hasOwnProperty.call(j,e[g])?e[g]=j[e[g]]:s('Model: Given model "'+e[g]+'" is not specified'+o+"."))};p();var u=e[g],m=c[u],v=null;Object.prototype.hasOwnProperty.call(m,d.additional)&&m[d.additional]&&(v=m[d.additional]);var O=function(a,l,c,p,y){void 0===y&&(y=["constraintExecution","constraintExpression"]);for(var d,f,h=i(y);!(d=h()).done;)if(f=d.value,Object.prototype.hasOwnProperty.call(c,f)){var g,v=void 0;try{v=_(c[f].evaluation,f.endsWith("Expression"),{checkPropertyContent:P,model:m,modelName:u,name:l,type:f,newDocument:e,newValue:a,oldDocument:t,oldValue:p,parentNames:n,pathDescription:o,propertySpecification:c})}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&s('Compilation: Hook "'+f+'" has invalid code "'+e.code+'": "'+e.message+'"'+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&s('Runtime: Hook "'+f+'" has throw an error with code "'+e.code+'": "'+e.message+'"'+o+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}if(null==(g=v)||!g.result){var O=z(c[f].description);s(f.charAt(0).toUpperCase()+(f.substring(1)+": ")+(O?r(Function,Object.keys(v.scope).concat(["return "+O])).apply(void 0,Object.values(v.scope)):'Property "'+l+'" should satisfy constraint "'+v.code+'" (given "'+D(a)+'")'+o+"."))}}},P=function(e,t,r,a){void 0===a&&(a=null);var l=[],p=[].concat(r.type?r.type:[]);"object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype&&!Object.prototype.hasOwnProperty.call(e,g)&&1===p.length&&Object.prototype.hasOwnProperty.call(c,p[0])&&(e[g]=p[0]);for(var u,m,d=!1,h=i(p);!(u=h()).done;)if(m=u.value,Object.prototype.hasOwnProperty.call(c,m)){if("object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype&&Object.prototype.hasOwnProperty.call(e,g)&&e[g]!==m&&"migrate"===w&&1===p.length&&(e[g]=m,l=n.concat(t,"migrate nested object type")),"object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype&&Object.prototype.hasOwnProperty.call(e,g)&&e[g]===m){var v=H(e,a,n.concat(t));if(v.changedPath.length&&(l=v.changedPath),e=v.newDocument,D(e)===D({}))return{newValue:null,changedPath:l};d=!0;break}1===p.length&&s('NestedType: Under key "'+t+'" isn\'t of type "'+m+'" (given "'+D(e)+'" of type '+typeof e+")"+o+".")}else if("DateTime"===m){var b=e;if(e=R(e),!(y&&("number"!=typeof e||isNaN(e))||!y&&"string"!=typeof e)){d=!0;break}1===p.length&&s('PropertyType: Property "'+t+'" isn\'t of (valid) type "DateTime" (given "'+D(b).replace(/^"/,"").replace(/"$/,"")+'" of type "'+typeof b+'")'+o+".")}else if(["boolean","integer","number","string"].includes(m)){if(!("number"==typeof e&&isNaN(e)||"integer"!==m&&typeof e!==m||"integer"===m&&parseInt(e,10)!==e)){d=!0;break}1===p.length&&s('PropertyType: Property "'+t+'" isn\'t of (valid) type "${type}" (given "'+D(e)+'" of type "'+typeof e+'")'+o+".")}else if("string"==typeof m&&m.startsWith("foreignKey:")){var P=c[m.substring(11)][f].type;if(P===typeof e){d=!0;break}1===p.length&&s('PropertyType: Foreign key property "'+t+'" isn\'t of type "'+P+'" (given "'+D(e)+'" of type "'+typeof e+'")'+o+".")}else{if("any"===m||D(e)===D(m)){d=!0;break}1===p.length&&s('PropertyType: Property "'+t+'" isn\'t value "'+m+'" (given "'+D(e).replace(/^"/,"").replace(/"$/,"")+'" of type "'+typeof e+'")'+o+".")}if(d||s('PropertyType: None of the specified types "'+p.join('", "')+'" for property "'+t+'" matches value "'+D(e).replace(/^"/,"").replace(/"$/,"")+e+'" of type "'+typeof e+'")'+o+"."),"string"==typeof e&&(![null,void 0].includes(r.minimumLength)&&e.length<r.minimumLength&&s('MinimalLength: Property "'+t+'" must have minimal length '+r.minimumLength+" (given "+e+" with length i"+e.length+") "+o+"."),![null,void 0].includes(r.maximumLength)&&e.length>r.maximumLength&&s('MaximalLength: Property "'+t+'" must have maximal length '+r.maximumLength+" (given "+e+" with length "+e.length+")"+o+".")),"number"==typeof e&&(![null,void 0].includes(r.minimum)&&e<r.minimum&&s('Minimum: Property "'+t+'" (type '+r.type+") must satisfy a minimum of "+r.minimum+" (given "+e+" is too low)"+o+"."),![null,void 0].includes(r.maximum)&&e>r.maximum&&s('Maximum: Property "'+t+'" (type '+r.type+") must satisfy a maximum of "+r.maximum+" (given "+e+" is too high)"+o+".")),r.selection){var j=Array.isArray(r.selection)?r.selection.map((function(e){return void 0===(null==e?void 0:e.value)?e:e.value})):Object.keys(r.selection);"DateTime"===r.type&&(j=j.map(R)),j.includes(e)||s('Selection: Property "'+t+'" (type '+r.type+') should be one of "'+j.join('", "')+'". But is "'+e+'"'+o+".")}return[null,void 0].includes(r.regularExpressionPattern)||new RegExp(r.regularExpressionPattern).test(e)?![null,void 0].includes(r.invertedRegularExpressionPattern)&&new RegExp(r.invertedRegularExpressionPattern).test(e)&&s('InvertedPatternMatch: Property "'+t+'" should not match regular expression pattern '+r.invertedRegularExpressionPattern+' (given "'+e+'")'+o+"."):s('PatternMatch: Property "'+t+'" should match regular expression pattern '+r.regularExpressionPattern+' (given "'+e+'")'+o+"."),O(e,t,r,a),D(e)!==D(a)&&(l=n.concat(t,"value updated")),{newValue:e,changedPath:l}},x=function(e,t,r,o,i){var c=t[o];if(!e.writable)if(r){if(Object.prototype.hasOwnProperty.call(r,o)&&D(c)===D(r[o]))return o!==f&&"incremental"===w&&delete t[o],!0;s('Readonly: Property "'+o+'" is not writable (old document "'+D(r)+'")'+i+".")}else s('Readonly: Property "'+o+'" is not writable'+i+".");if(!e.mutable&&r&&Object.prototype.hasOwnProperty.call(r,o)){if(D(c)===D(r[o]))return"incremental"!==w||l.property.name.reserved.concat(d.deleted,f,h).includes(o)||delete t[o],!0;"migrate"!==w&&s('Immutable: Property "'+o+'" is not writable (old document "'+D(r)+'")'+i+".")}if(null===c){if(e.nullable)return delete t[o],r&&Object.prototype.hasOwnProperty.call(r,o)&&(a=n.concat(o,"delete property")),!0;s('NotNull: Property "'+o+'" should not be "null"'+i+".")}return!1},N=function(e,t,r,a){if(!r)for(var l,c,p=i(["onCreateExecution","onCreateExpression"]);!(l=p()).done;)if(c=l.value,Object.prototype.hasOwnProperty.call(e,c)){var y=void 0;try{y=_(e[c],c.endsWith("Expression"),{checkPropertyContent:P,model:m,modelName:u,name:a,type:c,newDocument:t,oldDocument:r,newValue:void 0,oldValue:void 0,parentNames:n,pathDescription:o,propertySpecification:e})}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&s('Compilation: Hook "'+c+'" has invalid code "'+e.code+'" for property "'+a+'": '+e.message+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&s('Runtime: Hook "'+c+'" has throw an error with code "'+e.code+'" for property "'+a+'": '+e.message+o+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}y&&![null,void 0].includes(y.result)&&(t[a]=y.result)}},A=function(e,t,r,a){if(Object.prototype.hasOwnProperty.call(t,a)){e.trim&&"string"==typeof t[a]&&(t[a]=t[a].trim()),e.emptyEqualsToNull&&(""===t[a]||Array.isArray(t[a])&&0===t[a].length||null!==t[a]&&"object"==typeof t[a]&&0===Object.keys(t).length)&&(t[a]=null);for(var l,c,p=i(["onUpdateExecution","onUpdateExpression"]);!(l=p()).done;)if(c=l.value,Object.prototype.hasOwnProperty.call(e,c))try{t[a]=_(e[c],c.endsWith("Expression"),{checkPropertyContent:P,model:m,modelName:u,name:a,type:c,newDocument:t,oldDocument:r,newValue:t[a],oldValue:r&&r[a],parentNames:n,pathDescription:o,propertySpecification:e}).result}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&s('Compilation: Hook "'+c+'" has invalid code "'+e.code+'" for property "'+a+'": '+e.message+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&s('Runtime: Hook "'+c+'" has throw an error with code "'+e.code+'" for property "'+a+'": '+e.message+o+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}}},C=Object.keys(m).filter((function(e){return![d.additional,d.allowedRoles,d.constraint.execution,d.constraint.expression,d.create.execution,d.create.expression,d.extend,d.maximumAggregatedSize,d.minimumAggregatedSize,d.oldType,d.update.execution,d.update.expression].includes(e)}));if("migrate"===w)for(var S,k,T=i(C);!(S=T()).done;)if(k=S.value,![null,void 0].includes(m[k].oldName))for(var E,U,L=i([].concat(m[k].oldName));!(E=L()).done;)U=E.value,Object.prototype.hasOwnProperty.call(e,U)&&(e[k]=e[U],delete e[U]);if(!t)for(var I,W=0,V=[d.create.execution,d.create.expression];W<V.length;W++)if(I=V[W],Object.prototype.hasOwnProperty.call(m,I)){var F=void 0;try{F=_(m[I],I.endsWith("Expression"),{checkPropertyContent:P,model:m,modelName:u,type:I,newDocument:e,oldDocument:t,parentNames:n,pathDescription:o}).result}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&s('Compilation: Hook "'+I+'" has invalid code "'+e.code+'" for document "'+u+'": '+e.message+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&s('Runtime: Hook "'+I+'" has throw an error with code "'+e.code+'" for document "'+u+'": '+e.message+o+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}[null,void 0].includes(F)||(e=F),p(),u=e[g],0===n.length&&b()}for(var B,$=0,q=[d.update.execution,d.update.expression];$<q.length;$++)if(B=q[$],Object.prototype.hasOwnProperty.call(m,B)){var Y=void 0;try{Y=_(m[B],B.endsWith("Expression"),{checkPropertyContent:P,model:m,modelName:u,type:B,newDocument:e,oldDocument:t,parentNames:n,pathDescription:o}).result}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&s('Compilation: Hook "'+B+'" has invalid code "'+e.code+'" for document "'+u+'": '+e.message+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&s('Runtime: Hook "'+B+'" has throw an error with code "'+e.code+'" for document "'+u+'": '+e.message+o+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}[void 0,null].includes(Y)||(e=Y),p(),u=e[g],0===n.length&&b()}for(var J,G=function(){var r=J.value;if(d.attachment===r)for(var l=function(){var l=p[c],u=l[0],m=l[1];Object.prototype.hasOwnProperty.call(e,r)&&null!==e[r]||(e[r]={}),t&&!Object.prototype.hasOwnProperty.call(t,r)&&(t[r]={});var y=Object.keys(e[r]).filter((function(t){return null!==e[r][t].data&&M(u,t,m)})),d=e[r],f=[];if(t){var h=t[r];f=Object.keys(h).filter((function(e){return!(Object.prototype.hasOwnProperty.call(d,e)&&Object.prototype.hasOwnProperty.call(d[e],"data")&&null===d[e].data)&&!!h[e]&&(Object.prototype.hasOwnProperty.call(h[e],"data")&&null!==h[e].data||h[e].stub&&!!h[e].digest)&&!!M(u,e,m)}))}for(var g,v,O=m,b=i(y);!(g=b()).done;)v=g.value,N(O,d,t&&t[r]?t[r]:null,v);for(var P,j,x=i(y);!(P=x()).done;)j=P.value,A(O,d,t&&t[r]?t[r]:null,j);if([null,void 0].includes(O.default)){if(O.nullable||0<y.length||0<f.length||s('AttachmentMissing: Missing attachment for type "'+u+'"'+o+"."),"fillUp"===w&&0===y.length&&0<f.length)for(var C,S,k=i(f);!(C=k()).done;)S=C.value,null===d[S]?a=n.concat(r,S,"file removed"):d[S]=t[r][S]}else if(0===y.length)if(0===f.length)for(var T in O.default)Object.prototype.hasOwnProperty.call(O.default,T)&&(d[T]=O.default[T],a=n.concat(r,u,"add default file"));else if("fillUp"===w)for(var E,D,z=i(f);!(E=z()).done;)D=E.value,d[D]=t[r][D]},c=0,p=Object.entries(m[r]);c<p.length;c++)l();else{var u=C.includes(r)?m[r]:v;N(u,e,t,r),A(u,e,t,r),[null,void 0].includes(u.default)?(!(u.nullable||Object.prototype.hasOwnProperty.call(e,r)||t&&Object.prototype.hasOwnProperty.call(t,r)&&w)&&s('MissingProperty: Missing property "'+r+'"'+o+"."),!Object.prototype.hasOwnProperty.call(e,r)&&t&&Object.prototype.hasOwnProperty.call(t,r)&&("fillUp"===w?e[r]=t[r]:!w&&(a=n.concat(r,"property removed")))):(!Object.prototype.hasOwnProperty.call(e,r)||null===e[r])&&(t&&Object.prototype.hasOwnProperty.call(t,r)?"fillUp"===w?e[r]=t[r]:"migrate"===w&&(e[r]=u.default,a=n.concat(r,"migrate default value")):(e[r]=u.default,a=a.concat(r,"add default value")))}},K=i(C.concat(v?Object.keys(e).filter((function(e){return!C.includes(e)})):[]));!(J=K()).done;)G();if(t&&"incremental"===w)for(var Z=0,Q=Object.entries(e);Z<Q.length;Z++){var X=Q[Z],ee=X[0],te=X[1];!Object.prototype.hasOwnProperty.call(t,ee)||l.property.name.reserved.concat(f,h,d.conflict,d.deleted,d.deletedConflict,d.localSequence,d.revisions,d.revisionsInformation,g).includes(ee)||t[ee]!==te&&D(t[ee])!==D(te)||delete e[ee]}for(var re=0,ne=Object.entries(e);re<ne.length;re++){var oe=ne[re],ae=oe[0],ie=oe[1];if(!l.property.name.reserved.concat(h,d.conflict,d.deleted,d.deletedConflict,d.localSequence,d.revisions,d.revisionsInformation,d.strategy).includes(ae)){var le=void 0;if(Object.prototype.hasOwnProperty.call(m,ae))le=m[ae];else if(v)le=v;else{if("migrate"===w){delete e[ae],a=n.concat(ae,"migrate removed property");continue}s('Property: Given property "'+ae+'" isn\'t specified in model "'+u+'"'+o+".")}if(!le)continue;if(d.attachment===ae){var ce=ie;for(var pe in ce)if(Object.prototype.hasOwnProperty.call(ce,pe))for(var se in m[ae])if(M(se,pe,m[ae][se])){x(m[ae][se],e,t,pe,o);break}continue}if(x(le,e,t,ae,o))continue;if("string"==typeof le.type&&le.type.endsWith("[]")||Array.isArray(le.type)&&le.type.length&&Array.isArray(le.type[0])){var ue,me=ie;Array.isArray(me)?![null,void 0].includes(le.minimumNumber)&&me.length<le.minimumNumber?s('MinimumArrayLength: Property "'+ae+'" (array of length '+me.length+") doesn't fullfill minimum array length of "+le.minimumNumber+o+"."):![null,void 0].includes(le.maximumNumber)&&le.maximumNumber<me.length&&s('MaximumArrayLength: Property "'+ae+'" (array of length '+me.length+") doesn't fullfill maximum array length of "+le.maximumNumber+o+"."):s('PropertyType: Property "'+ae+'" isn\'t of type "array -> '+le.type+'" (given "'+D(me)+'")'+o+"."),O(me,ae,le,t&&Object.prototype.hasOwnProperty.call(t,ae)&&t[ae]||void 0,["arrayConstraintExecution","arrayConstraintExpression"]);var ye={};for(var de in le)Object.prototype.hasOwnProperty.call(le,de)&&(ye[de]="type"===de?Array.isArray(le[de])?le[de][0]:[le[de].substring(0,le.type.length-2)]:le[de]);if(1===(null==(ue=ye.type)?void 0:ue.length)&&Object.prototype.hasOwnProperty.call(c,ye.type[0]))for(var fe,he,ge=i(me.slice());!(fe=ge()).done;)"object"!=typeof(he=fe.value)||Object.getPrototypeOf(he)!==Object.prototype||Object.prototype.hasOwnProperty.call(he,g)||(he[g]=ye.type[0]);for(var ve,Oe,be=0,we=i(me.slice());!(ve=we()).done;)Oe=ve.value,me[be]=P(Oe,be+1+". value in "+ae,ye).newValue,null===Oe&&me.splice(be,1),be+=1;t&&Object.prototype.hasOwnProperty.call(t,ae)&&Array.isArray(t[ae])&&t[ae].length===me.length&&D(t[ae])===D(me)||(a=n.concat(ae,"array updated"))}else{var Pe=t&&Object.prototype.hasOwnProperty.call(t,ae)?t[ae]:null,je=P(ie,ae,le,Pe);e[ae]=je.newValue,je.changedPath.length&&(a=je.changedPath),null===e[ae]&&(null!==Pe&&(a=n.concat(ae,"property removed")),delete e[ae])}}}for(var xe,Ne=0,Ae=Object.keys(d.constraint);Ne<Ae.length;Ne++)if(xe=Ae[Ne],(xe=d.constraint[xe])&&Object.prototype.hasOwnProperty.call(m,xe))for(var Ce,Se=i([].concat(m[xe]));!(Ce=Se()).done;){var ke,Te=Ce.value,Ee=void 0;try{Ee=_(Te.evaluation,xe===d.constraint.expression,{checkPropertyContent:P,model:m,modelName:u,type:xe,newDocument:e,oldDocument:t,parentNames:n,pathDescription:o})}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&s('Compilation: Hook "'+xe+'" has invalid code "'+e.code+'": "'+e.message+'"'+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&s('Runtime: Hook "'+xe+'" has thrown an error with code "'+e.code+'": '+e.message+o+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}if(null==(ke=Ee)||!ke.result){var De=xe.replace(/^[^a-zA-Z]+/,"");s(De.charAt(0).toUpperCase()+(De.substring(1)+": ")+(Te.description?r(Function,Object.keys(Ee.scope).concat(["return "+Te.description.trim()])).apply(void 0,Object.values(Ee.scope)):'Model "'+u+'" should satisfy constraint "'+Ee.code+'" (given "'+D(e)+'")'+o+"."))}}if(Object.prototype.hasOwnProperty.call(e,d.attachment)){var ze=e[d.attachment];("object"!=typeof ze||Object.getPrototypeOf(ze)!==Object.prototype)&&s("AttachmentType: given attachment has invalid type"+o+".");var Re=null;if(t&&Object.prototype.hasOwnProperty.call(t,d.attachment)&&(null!==(Re=t[d.attachment])&&"object"==typeof Re))for(var Me=0,Ue=Object.entries(Re);Me<Ue.length;Me++){var _e=Ue[Me],He=_e[0],Le=_e[1];if(Object.prototype.hasOwnProperty.call(ze,He)){var Ie=ze[He];null===Ie||null===Ie.data||Ie.content_type===Le.content_type&&(Ie.data===Le.data||Ie.digest===Le.digest)?((null===Ie||null===Ie.data)&&(a=n.concat(d.attachment,He,"attachment removed")),"incremental"===w&&delete ze[He]):a=n.concat(d.attachment,He,"attachment updated")}else"fillUp"===w?ze[He]=Le:w||(a=n.concat(d.attachment,He,"attachment removed"))}for(var We=0,Ve=Object.entries(ze);We<Ve.length;We++){var Fe=Ve[We],Be=Fe[0],$e=Fe[1];[null,void 0].includes($e)||null===$e.data?delete ze[Be]:(!Re||!Object.prototype.hasOwnProperty.call(Re,Be)||$e.content_type!==Re[Be].content_type||$e.data!==Re[Be].data&&$e.digest!==Re[Be].digest)&&(a=n.concat(d.attachment,Be,"attachment updated"))}0===Object.keys(ze).length&&delete e[d.attachment];for(var qe={},Ye=0,Je=Object.keys(m[d.attachment]);Ye<Je.length;Ye++)qe[Je[Ye]]=[];for(var Ge=0,Ke=Object.keys(ze);Ge<Ke.length;Ge++){for(var Ze=Ke[Ge],Qe=!1,Xe=0,et=Object.entries(m[d.attachment]);Xe<et.length;Xe++){var tt=et[Xe],rt=tt[0],nt=tt[1];if(M(rt,Ze,nt)){qe[rt].push(Ze),Qe=!0;break}}Qe||s('AttachmentTypeMatch: None of the specified attachment types ("'+Object.keys(m[d.attachment]).join('", "')+'") matches given one ("'+Ze+'")'+o+".")}for(var ot=0,at=0,it=Object.keys(qe);at<it.length;at++){var lt=it[at],ct=m[d.attachment][lt];if(Object.prototype.hasOwnProperty.call(qe,lt)){var pt=qe[lt].length;null!==ct.maximumNumber&&pt>ct.maximumNumber&&s("AttachmentMaximum: given number of attachments ("+pt+") doesn't satisfy specified maximum of "+ct.maximumNumber+' from type "'+lt+'"'+o+"."),(!ct.nullable||0!==pt)&&pt<ct.minimumNumber&&s("AttachmentMinimum: given number of attachments ("+pt+") doesn't satisfy specified minimum of "+ct.minimumNumber+' from type "'+lt+'"'+o+".");for(var st,ut=0,mt=i(qe[lt]);!(st=mt()).done;){var yt,dt,ft=st.value;null!=(yt=ct.fileName)&&yt.regularExpressionPattern&&!new RegExp(ct.fileName.regularExpressionPattern).test(ft)?s('AttachmentName: given attachment name "'+ft+'" doesn\'t satisfy specified regular expression pattern "'+ct.fileName.regularExpressionPattern+'" from type "'+lt+'"'+o+"."):null!=(dt=ct.fileName)&&dt.invertedRegularExpressionPattern&&new RegExp(ct.fileName.invertedRegularExpressionPattern).test(ft)?s('InvertedAttachmentName: given attachment name "'+ft+'" does satisfy specified regular expression pattern "'+ct.fileName.invertedRegularExpressionPattern+'" from type "'+lt+'"'+o+"."):!([null,void 0].includes(ct.contentTypeRegularExpressionPattern)||ze[ft].content_type&&new RegExp(ct.contentTypeRegularExpressionPattern).test(ze[ft].content_type))&&s('AttachmentContentType: given attachment content type "'+ze[ft].content_type+'" doesn\'t satisfy specified regular expression pattern "'+ct.contentTypeRegularExpressionPattern+'" from type "'+lt+'"'+o+".");var ht=ct.invertedContentTypeRegularExpressionPattern;[null,void 0].includes(ht)||ze[ft].content_type&&!new RegExp(ht).test(ze[ft].content_type)||s('InvertedAttachmentContentType: given attachment content type "'+ze[ft].content_type+'" does satisfy specified regular expression pattern "'+ht+'" from type "'+lt+'"'+o+".");var gt=0;"length"in ze[ft]?gt=ze[ft].length:"data"in ze[ft]&&(gt=Buffer&&"byteLength"in Buffer?Buffer.byteLength(ze[ft].data,"base64"):ze[ft].data.length),![null,void 0].includes(ct.minimumSize)&&ct.minimumSize>gt?s("AttachmentMinimumSize: given attachment size "+gt+" byte doesn't satisfy specified minimum of "+ct.minimumSize+" byte "+o+"."):![null,void 0].includes(ct.maximumSize)&&ct.maximumSize<gt&&s("AttachmentMaximumSize: given attachment size "+gt+" byte doesn't satisfy specified maximum of "+ct.maximumSize+" byte "+o+"."),ut+=gt}![null,void 0].includes(ct.minimumAggregatedSize)&&ct.minimumAggregatedSize>ut?s('AttachmentAggregatedMinimumSize: given aggregated size of attachments from type "'+lt+'" '+ut+" byte doesn't satisfy specified minimum of "+ct.minimumAggregatedSize+" byte "+o+"."):![null,void 0].includes(ct.maximumAggregatedSize)&&ct.maximumAggregatedSize<ut&&s('AttachmentAggregatedMaximumSize: given aggregated size of attachments from type "'+lt+'" '+ut+" byte doesn't satisfy specified maximum of "+ct.maximumAggregatedSize+" byte "+o+"."),ot+=ut}}Object.prototype.hasOwnProperty.call(m,d.minimumAggregatedSize)&&![null,void 0].includes(m[d.minimumAggregatedSize])&&m[d.minimumAggregatedSize]>ot?s("AggregatedMinimumSize: given aggregated size "+ot+" byte doesn't satisfy specified minimum of "+m[d.minimumAggregatedSize]+" byte "+o+"."):![null,void 0].includes(m[d.maximumAggregatedSize])&&m[d.maximumAggregatedSize]<ot&&s("AggregatedMaximumSize: given aggregated size "+ot+" byte doesn't satisfy specified maximum of "+m[d.maximumAggregatedSize]+" byte "+o+".")}if(t&&Object.prototype.hasOwnProperty.call(t,d.attachment)&&0===Object.keys(t[d.attachment]).length&&delete t[d.attachment],0===a.length&&t&&"migrate"===w)for(var vt,Ot=0,bt=Object.keys(t);Ot<bt.length;Ot++)vt=bt[Ot],Object.prototype.hasOwnProperty.call(e,vt)||(a=n.concat(vt,"migrate removed property"));return{changedPath:a,newDocument:e}},L={attachmentWithPrefixExists:function(t){if(Object.prototype.hasOwnProperty.call(e,d.attachment)){var r=e[d.attachment],n=U(t);if(n)return Object.prototype.hasOwnProperty.call(r[n],"stub")&&r[n].stub||Object.prototype.hasOwnProperty.call(r[n],"data")&&![null,void 0].includes(r[n].data)}return!1},checkDocument:H,getFileNameByPrefix:U,serialize:D,id:v,revision:O,idName:f,revisionName:h,specialNames:d,typeName:g,modelConfiguration:l,models:c,now:u,nowUTCTimestamp:m,securitySettings:o,userContext:n},I=H(e,t);return(!I.newDocument._deleted||t)&&(I.newDocument._deleted&&I.newDocument._deleted!==(null==t?void 0:t._deleted)||I.changedPath.length)||s("NoChange: No new data given. new document: "+D(e)+"; old document: "+D(t)+"."),Object.prototype.hasOwnProperty.call(o,l.property.name.validatedDocumentsCache)?o[l.property.name.validatedDocumentsCache].add(v+"-"+O):o[l.property.name.validatedDocumentsCache]=new Set([v+"-"+O]),I.newDocument},e}();const p=c;module.exports=t})();
package/helper.d.ts CHANGED
@@ -1,7 +1,5 @@
1
1
  import { Mapping } from 'clientnode/type';
2
- import { PluginAPI } from 'web-node';
3
- import { Plugin } from 'web-node/type';
4
- import { AllowedModelRolesMapping, AllowedRoles, Configuration, Connection, DatabaseConnectorConfiguration, Model, ModelConfiguration, Models, NormalizedAllowedRoles, Services, SpecialPropertyNames } from './type';
2
+ import { AllowedModelRolesMapping, AllowedRoles, Configuration, Connection, DatabaseConnectorConfiguration, Model, ModelConfiguration, Models, NormalizedAllowedRoles, Services, SpecialPropertyNames, State } from './type';
5
3
  /**
6
4
  * A dumm plugin interface with all available hooks.
7
5
  */
@@ -68,25 +66,25 @@ export declare class Helper {
68
66
  * Stops open database connection if exist, stops server process, restarts
69
67
  * server process and re-initializes server connection.
70
68
  * @param this - Indicates an unbound method.
71
- * @param services - An object with stored service instances.
72
- * @param configuration - Mutable by plugins extended configuration object.
73
- * @param plugins - Topological sorted list of plugins.
74
- * @param pluginAPI - Plugin api reference.
69
+ * @param state - Application state.
75
70
  *
76
71
  * @returns Given object of services wrapped in a promise resolving after
77
72
  * after finish.
78
73
  */
79
- static restartServer(this: void, services: Services, configuration: Configuration, plugins: Array<Plugin>, pluginAPI: typeof PluginAPI): Promise<void>;
74
+ static restartServer(this: void, state: State): Promise<void>;
80
75
  /**
81
76
  * Stops open database connection if exists and stops server process.
82
77
  * @param this - Indicates an unbound method.
83
78
  * @param services - An object with stored service instances.
79
+ * @param services.couchdb - Couchdb service instance.
84
80
  * @param configuration - Mutable by plugins extended configuration object.
81
+ * @param configuration.couchdb - Mutable by plugins extended configuration
82
+ * object.
85
83
  *
86
84
  * @returns Given object of services wrapped in a promise resolving after
87
85
  * after finish.
88
86
  */
89
- static stopServer(this: void, services: Services, configuration: Configuration): Promise<void>;
87
+ static stopServer(this: void, { couchdb }: Services, { couchdb: configuration }: Configuration): Promise<void>;
90
88
  /**
91
89
  * Determines a mapping of all models to roles who are allowed to edit
92
90
  * corresponding model instances.
package/helper.js CHANGED
@@ -1 +1 @@
1
- (()=>{"use strict";var __webpack_modules__=[e=>{e.exports=require("@babel/runtime/helpers/extends")},e=>{e.exports=require("@babel/runtime/helpers/asyncToGenerator")},e=>{e.exports=require("@babel/runtime/regenerator")},e=>{e.exports=require("child_process")},e=>{e.exports=require("clientnode")},e=>{e.exports=require("pouchdb/node_modules/node-fetch/lib/index.js")},e=>{e.exports=require("fs")},e=>{e.exports=require("path")}],__webpack_module_cache__={};function __webpack_require__(e){var r=__webpack_module_cache__[e];if(void 0!==r)return r.exports;var _=__webpack_module_cache__[e]={exports:{}};return __webpack_modules__[e](_,_.exports,__webpack_require__),_.exports}__webpack_require__.n=e=>{var r=e&&e.__esModule?()=>e.default:()=>e;return __webpack_require__.d(r,{a:r}),r},__webpack_require__.d=(e,r)=>{for(var _ in r)__webpack_require__.o(r,_)&&!__webpack_require__.o(e,_)&&Object.defineProperty(e,_,{enumerable:!0,get:r[_]})},__webpack_require__.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),__webpack_require__.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var __webpack_exports__={};(()=>{__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,{Helper:()=>Helper,default:()=>__WEBPACK_DEFAULT_EXPORT__});var _babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__(0),_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default=__webpack_require__.n(_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__),_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1__=__webpack_require__(1),_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default=__webpack_require__.n(_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1__),_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2__=__webpack_require__(2),_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default=__webpack_require__.n(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2__),child_process__WEBPACK_IMPORTED_MODULE_3__=__webpack_require__(3),child_process__WEBPACK_IMPORTED_MODULE_3___default=__webpack_require__.n(child_process__WEBPACK_IMPORTED_MODULE_3__),clientnode__WEBPACK_IMPORTED_MODULE_4__=__webpack_require__(4),clientnode__WEBPACK_IMPORTED_MODULE_4___default=__webpack_require__.n(clientnode__WEBPACK_IMPORTED_MODULE_4__),node_fetch__WEBPACK_IMPORTED_MODULE_5__=__webpack_require__(5),node_fetch__WEBPACK_IMPORTED_MODULE_5___default=__webpack_require__.n(node_fetch__WEBPACK_IMPORTED_MODULE_5__),fs__WEBPACK_IMPORTED_MODULE_6__=__webpack_require__(6),fs__WEBPACK_IMPORTED_MODULE_6___default=__webpack_require__.n(fs__WEBPACK_IMPORTED_MODULE_6__),path__WEBPACK_IMPORTED_MODULE_7__=__webpack_require__(7),path__WEBPACK_IMPORTED_MODULE_7___default=__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_7__);function _createForOfIteratorHelperLoose(e,r){var _="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(_)return(_=_.call(e)).next.bind(_);if(Array.isArray(e)||(_=_unsupportedIterableToArray(e))||r&&e&&"number"==typeof e.length){_&&(e=_);var t=0;return function(){return t>=e.length?{done:!0}:{done:!1,value:e[t++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(e,r){if(e){if("string"==typeof e)return _arrayLikeToArray(e,r);var _=Object.prototype.toString.call(e).slice(8,-1);return"Object"===_&&e.constructor&&(_=e.constructor.name),"Map"===_||"Set"===_?Array.from(e):"Arguments"===_||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(_)?_arrayLikeToArray(e,r):void 0}}function _arrayLikeToArray(e,r){(null==r||r>e.length)&&(r=e.length);for(var _=0,t=Array(r);_<r;_++)t[_]=e[_];return t}clientnode__WEBPACK_IMPORTED_MODULE_4__.globalContext.fetch=node_fetch__WEBPACK_IMPORTED_MODULE_5___default();var Helper=function(){function Helper(){}return Helper.getConnectorOptions=function(e){return e.couchdb.connector.fetch?{fetch:function(r,_){return clientnode__WEBPACK_IMPORTED_MODULE_4__.globalContext.fetch(r,clientnode__WEBPACK_IMPORTED_MODULE_4___default().extend(!0,clientnode__WEBPACK_IMPORTED_MODULE_4___default().copy(e.couchdb.connector.fetch),_||{}))}}:{fetch:function(e,r){return clientnode__WEBPACK_IMPORTED_MODULE_4__.globalContext.fetch(e,r)}}},Helper.mayStripRepresentation=function(e,r,_){var t=clientnode__WEBPACK_IMPORTED_MODULE_4___default().represent(e);return t.length<=r?t.length>_?t.substring(0,_-3)+"...":t:"DOCUMENT IS TOO BIG TO REPRESENT"},Helper.ensureValidationDocumentPresence=function(){var e=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function e(r,_,t,n,o,a,c){var i,l,s;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return void 0===o&&(o=!0),void 0===a&&(a="_id"),void 0===c&&(c="_design/"),l=_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()(((i={})[a]=""+c+_,i.language="javascript",i),t),e.prev=4,e.next=7,r.get(""+c+_);case 7:return s=e.sent,l._rev=s._rev,e.next=11,r.put(l);case 11:case 20:e.next=26;break;case 14:return e.prev=14,e.t0=e.catch(4),o&&e.t0.error,e.prev=17,e.next=20,r.put(l);case 23:throw e.prev=23,e.t1=e.catch(17),new Error(n+" couldn't be installed/updated: \""+clientnode__WEBPACK_IMPORTED_MODULE_4___default().represent(e.t1)+'".');case 26:case"end":return e.stop()}}),e,null,[[4,14],[17,23]])})));return function(){return e.apply(this,arguments)}}(),Helper.initializeConnection=function(){var e=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function e(r,_){var t,n,o,a,c,i;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(t=clientnode__WEBPACK_IMPORTED_MODULE_4___default().stringFormat(_.couchdb.url,_.couchdb.user.name+":"+_.couchdb.user.password+"@")+"/"+_.couchdb.databaseName,r.couchdb.connection=new r.couchdb.connector(t,Helper.getConnectorOptions(_)),r.couchdb.connection.setMaxListeners(1/0),n=_.couchdb.model.property.name.special.id,o=_.couchdb.model.property.name.special.revision,a=function(){var e=i.value,t=r.couchdb.connection[e].bind(r.couchdb.connection);r.couchdb.connection[e]=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function e(r){var a,c,i,l,s,u=arguments;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(e.prev=0,a=u.length,c=Array(1<a?a-1:0),i=1;i<a;i++)c[i-1]=u[i];return e.next=4,t.apply(void 0,[r].concat(c));case 4:return e.abrupt("return",e.sent);case 7:if(e.prev=7,e.t0=e.catch(0),!(n in r&&_.couchdb.ignoreNoChangeError&&"forbidden"===e.t0.name&&null!=(l=e.t0.message)&&l.startsWith("NoChange:"))){e.next=21;break}if(s={id:r[n],ok:!0},!(o in r)||["latest","upsert"].includes(r[o])){e.next=15;break}e.t1=r[o],e.next=19;break;case 15:return e.next=17,this.get(s.id);case 17:e.t2=o,e.t1=e.sent[e.t2];case 19:return s.rev=e.t1,e.abrupt("return",s);case 21:throw e.t0;case 22:case"end":return e.stop()}}),e,this,[[0,7]])})))},c=_createForOfIteratorHelperLoose(["post","put"]);!(i=c()).done;)a();return e.prev=7,e.next=10,clientnode__WEBPACK_IMPORTED_MODULE_4___default().checkReachability(t);case 10:e.next=17;break;case 12:return e.prev=12,e.t0=e.catch(7),e.next=17,clientnode__WEBPACK_IMPORTED_MODULE_4__.globalContext.fetch(t,{method:"PUT"});case 17:return e.abrupt("return",r);case 18:case"end":return e.stop()}}),e,null,[[7,12]])})));return function(){return e.apply(this,arguments)}}(),Helper.startServer=function(){function startServer(){return _startServer.apply(this,arguments)}var _startServer=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function _callee4(services,configuration){var _this=this;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(_context4){for(;;)switch(_context4.prev=_context4.next){case 0:if(!Object.prototype.hasOwnProperty.call(services.couchdb.server.runner,"configurationFile")){_context4.next=12;break}return _context4.prev=1,_context4.next=4,fs__WEBPACK_IMPORTED_MODULE_6__.promises.mkdir(path__WEBPACK_IMPORTED_MODULE_7___default().dirname(services.couchdb.server.runner.configurationFile.path),{recursive:!0});case 4:_context4.next=10;break;case 6:if(_context4.prev=6,_context4.t0=_context4.catch(1),"EEXIST"===_context4.t0.code){_context4.next=10;break}throw _context4.t0;case 10:return _context4.next=12,fs__WEBPACK_IMPORTED_MODULE_6__.promises.writeFile(services.couchdb.server.runner.configurationFile.path,services.couchdb.server.runner.configurationFile.content,{encoding:configuration.core.encoding});case 12:return services.couchdb.server.process=(0,child_process__WEBPACK_IMPORTED_MODULE_3__.spawn)("default"===configuration.couchdb.binary.memoryInMegaByte?services.couchdb.server.runner.binaryFilePath:configuration.couchdb.binary.nodePath,("default"===configuration.couchdb.binary.memoryInMegaByte?[]:["--max-old-space-size="+configuration.couchdb.binary.memoryInMegaByte,services.couchdb.server.runner.binaryFilePath]).concat(services.couchdb.server.runner.arguments?services.couchdb.server.runner.arguments:[]),{cwd:eval("process").cwd(),env:Object.prototype.hasOwnProperty.call(services.couchdb.server.runner,"environment")?_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({},eval("process").env,services.couchdb.server.runner.environment):eval("process").env,shell:!0,stdio:"inherit"}),new Promise((function(e,r){for(var _,t,n=_createForOfIteratorHelperLoose(clientnode__WEBPACK_IMPORTED_MODULE_4__.CloseEventNames);!(_=n()).done;)t=_.value,services.couchdb.server.process.on(t,clientnode__WEBPACK_IMPORTED_MODULE_4___default().getProcessCloseHandler(e,r,{process:services.couchdb.server.process,reason:t}))})).then((function(e){var r,_;null!=(r=services.couchdb)&&null!=(_=r.server)&&_.resolve&&services.couchdb.server.resolve.call(_this,e)}),(function(e){var r,_;null!=(r=services.couchdb)&&null!=(_=r.server)&&_.resolve&&services.couchdb.server.reject.call(_this,e)})),_context4.next=16,clientnode__WEBPACK_IMPORTED_MODULE_4___default().checkReachability(clientnode__WEBPACK_IMPORTED_MODULE_4___default().stringFormat(configuration.couchdb.url,""),{wait:!0});case 16:case"end":return _context4.stop()}}),_callee4,null,[[1,6]])})));return startServer}(),Helper.restartServer=function(){var e=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function e(r,_,t,n){var o,a;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=r.couchdb.server.resolve,a=r.couchdb.server.reject,r.couchdb.server.resolve=r.couchdb.server.reject=clientnode__WEBPACK_IMPORTED_MODULE_4___default().noop,e.next=5,Helper.stopServer(r,_);case 5:return r.couchdb.server.resolve=o,r.couchdb.server.reject=a,e.next=9,Helper.startServer(r,_);case 9:return Helper.initializeConnection(r,_),e.next=12,n.callStack("restartCouchdb",t,_,r);case 12:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),Helper.stopServer=function(){var e=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function e(r,_){return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r.couchdb.connection&&r.couchdb.connection.close(),r.couchdb.server.process&&r.couchdb.server.process.kill("SIGINT"),e.next=4,clientnode__WEBPACK_IMPORTED_MODULE_4___default().checkUnreachability(clientnode__WEBPACK_IMPORTED_MODULE_4___default().stringFormat(_.couchdb.url,""),{wait:!0});case 4:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),Helper.determineAllowedModelRolesMapping=function(e){for(var r=e.property.name.special.allowedRoles,_={},t=Helper.extendModels(e),n=0,o=Object.entries(t);n<o.length;n++){var a=o[n],c=a[0],i=a[1];if(Object.prototype.hasOwnProperty.call(i,r)){_[c]=_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({properties:{}},Helper.normalizeAllowedRoles(i[r]));for(var l=0,s=Object.entries(i);l<s.length;l++){var u=s[l],p=u[0],d=u[1];null!==d&&"object"==typeof d&&d.allowedRoles&&(_[c].properties[p]=Helper.normalizeAllowedRoles(d.allowedRoles))}}else _[c]={properties:{},read:[],write:[]}}return _},Helper.determineGenericIndexablePropertyNames=function(e,r){var _=e.property.name.special;return Object.keys(r).filter((function(t){return null!==r[t]&&"object"==typeof r[t]&&(Object.prototype.hasOwnProperty.call(r[t],"index")&&r[t].index||!(Object.prototype.hasOwnProperty.call(r[t],"index")&&!r[t].index||e.property.name.reserved.concat(_.additional,_.allowedRoles,_.attachment,_.conflict,_.constraint.execution,_.constraint.expression,_.deleted,_.deletedConflict,_.extend,_.id,_.maximumAggregatedSize,_.minimumAggregatedSize,_.oldType,_.revision,_.revisions,_.revisionsInformation,_.type).includes(t)||r[t].type&&("string"==typeof r[t].type&&r[t].type.endsWith("[]")||Array.isArray(r[t].type)&&r[t].type.length&&Array.isArray(r[t].type[0])||Object.prototype.hasOwnProperty.call(e.entities,r[t].type))))})).concat(_.id,_.revision).sort()},Helper.extendModel=function(e,r,_){if(void 0===_&&(_="_extends"),"_base"===e)return r[e];if(Object.prototype.hasOwnProperty.call(r,"_base")&&(Object.prototype.hasOwnProperty.call(r[e],_)&&r[e][_]?r[e][_]=["_base"].concat(r[e][_]):r[e][_]="_base"),Object.prototype.hasOwnProperty.call(r[e],_)){for(var t,n,o=_createForOfIteratorHelperLoose([].concat(r[e][_]));!(t=o()).done;)n=t.value,r[e]=clientnode__WEBPACK_IMPORTED_MODULE_4___default().extend(!0,clientnode__WEBPACK_IMPORTED_MODULE_4___default().copy(Helper.extendModel(n,r,_)),r[e]);delete r[e][_]}return r[e]},Helper.extendModels=function(e){for(var r,_=e.property.name.special,t={},n=0,o=Object.keys(e.entities);n<o.length;n++){if(r=o[n],!new RegExp(e.property.name.typeRegularExpressionPattern.public).test(r)&&!new RegExp(e.property.name.typeRegularExpressionPattern.private).test(r))throw new Error('Model names have to match "'+e.property.name.typeRegularExpressionPattern.public+'" or "'+e.property.name.typeRegularExpressionPattern.private+'" for private one (given name: "'+r+'").');t[r]=Helper.extendModel(r,e.entities,_.extend)}for(var a,c=0,i=Object.values(t);c<i.length;c++){a=i[c];for(var l=0,s=Object.entries(a);l<s.length;l++){var u=s[l],p=u[0],d=u[1];if(p===_.attachment)for(var E=0,b=Object.entries(d);E<b.length;E++){var O=b[E],f=O[0],P=O[1];d[f]=clientnode__WEBPACK_IMPORTED_MODULE_4___default().extend(!0,clientnode__WEBPACK_IMPORTED_MODULE_4___default().copy(e.property.defaultSpecification),P)}else[_.allowedRoles,_.constraint.execution,_.constraint.expression,_.extend,_.maximumAggregatedSize,_.minimumAggregatedSize,_.oldType].includes(p)||(a[p]=clientnode__WEBPACK_IMPORTED_MODULE_4___default().extend(!0,clientnode__WEBPACK_IMPORTED_MODULE_4___default().copy(e.property.defaultSpecification),d))}}return t},Helper.normalizeAllowedRoles=function(e){if(Array.isArray(e))return{read:e,write:e};if("object"==typeof e){for(var r,_={read:[],write:[]},t=0,n=Object.keys(_);t<n.length;t++)r=n[t],Object.prototype.hasOwnProperty.call(e,r)&&(Array.isArray(e[r])?_[r]=e[r]:_[r]=[e[r]]);return _}return{read:[e],write:[e]}},Helper}();const __WEBPACK_DEFAULT_EXPORT__=Helper})(),module.exports=__webpack_exports__})();
1
+ (()=>{"use strict";var __webpack_modules__=[e=>{e.exports=require("@babel/runtime/helpers/extends")},e=>{e.exports=require("@babel/runtime/helpers/asyncToGenerator")},e=>{e.exports=require("@babel/runtime/regenerator")},e=>{e.exports=require("child_process")},e=>{e.exports=require("clientnode")},e=>{e.exports=require("pouchdb/node_modules/node-fetch/lib/index.js")},e=>{e.exports=require("fs")},e=>{e.exports=require("path")}],__webpack_module_cache__={};function __webpack_require__(e){var _=__webpack_module_cache__[e];if(void 0!==_)return _.exports;var r=__webpack_module_cache__[e]={exports:{}};return __webpack_modules__[e](r,r.exports,__webpack_require__),r.exports}__webpack_require__.n=e=>{var _=e&&e.__esModule?()=>e.default:()=>e;return __webpack_require__.d(_,{a:_}),_},__webpack_require__.d=(e,_)=>{for(var r in _)__webpack_require__.o(_,r)&&!__webpack_require__.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:_[r]})},__webpack_require__.o=(e,_)=>Object.prototype.hasOwnProperty.call(e,_),__webpack_require__.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var __webpack_exports__={};(()=>{__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,{Helper:()=>Helper,default:()=>__WEBPACK_DEFAULT_EXPORT__});var _babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__(0),_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default=__webpack_require__.n(_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__),_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1__=__webpack_require__(1),_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default=__webpack_require__.n(_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1__),_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2__=__webpack_require__(2),_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default=__webpack_require__.n(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2__),child_process__WEBPACK_IMPORTED_MODULE_3__=__webpack_require__(3),child_process__WEBPACK_IMPORTED_MODULE_3___default=__webpack_require__.n(child_process__WEBPACK_IMPORTED_MODULE_3__),clientnode__WEBPACK_IMPORTED_MODULE_4__=__webpack_require__(4),clientnode__WEBPACK_IMPORTED_MODULE_4___default=__webpack_require__.n(clientnode__WEBPACK_IMPORTED_MODULE_4__),node_fetch__WEBPACK_IMPORTED_MODULE_5__=__webpack_require__(5),node_fetch__WEBPACK_IMPORTED_MODULE_5___default=__webpack_require__.n(node_fetch__WEBPACK_IMPORTED_MODULE_5__),fs__WEBPACK_IMPORTED_MODULE_6__=__webpack_require__(6),fs__WEBPACK_IMPORTED_MODULE_6___default=__webpack_require__.n(fs__WEBPACK_IMPORTED_MODULE_6__),path__WEBPACK_IMPORTED_MODULE_7__=__webpack_require__(7),path__WEBPACK_IMPORTED_MODULE_7___default=__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_7__);function _createForOfIteratorHelperLoose(e,_){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=_unsupportedIterableToArray(e))||_&&e&&"number"==typeof e.length){r&&(e=r);var t=0;return function(){return t>=e.length?{done:!0}:{done:!1,value:e[t++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(e,_){if(e){if("string"==typeof e)return _arrayLikeToArray(e,_);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?_arrayLikeToArray(e,_):void 0}}function _arrayLikeToArray(e,_){(null==_||_>e.length)&&(_=e.length);for(var r=0,t=Array(_);r<_;r++)t[r]=e[r];return t}clientnode__WEBPACK_IMPORTED_MODULE_4__.globalContext.fetch=node_fetch__WEBPACK_IMPORTED_MODULE_5___default();var Helper=function(){function Helper(){}return Helper.getConnectorOptions=function(e){return e.couchdb.connector.fetch?{fetch:function(_,r){return clientnode__WEBPACK_IMPORTED_MODULE_4__.globalContext.fetch(_,clientnode__WEBPACK_IMPORTED_MODULE_4___default().extend(!0,clientnode__WEBPACK_IMPORTED_MODULE_4___default().copy(e.couchdb.connector.fetch),r||{}))}}:{fetch:function(e,_){return clientnode__WEBPACK_IMPORTED_MODULE_4__.globalContext.fetch(e,_)}}},Helper.mayStripRepresentation=function(e,_,r){var t=clientnode__WEBPACK_IMPORTED_MODULE_4___default().represent(e);return t.length<=_?t.length>r?t.substring(0,r-3)+"...":t:"DOCUMENT IS TOO BIG TO REPRESENT"},Helper.ensureValidationDocumentPresence=function(){var e=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function e(_,r,t,n,o,a,c){var i,l,s;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return void 0===o&&(o=!0),void 0===a&&(a="_id"),void 0===c&&(c="_design/"),l=_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()(((i={})[a]=""+c+r,i.language="javascript",i),t),e.prev=4,e.next=7,_.get(""+c+r);case 7:return s=e.sent,l._rev=s._rev,e.next=11,_.put(l);case 11:case 20:e.next=26;break;case 14:return e.prev=14,e.t0=e.catch(4),o&&e.t0.error,e.prev=17,e.next=20,_.put(l);case 23:throw e.prev=23,e.t1=e.catch(17),new Error(n+" couldn't be installed/updated: \""+clientnode__WEBPACK_IMPORTED_MODULE_4___default().represent(e.t1)+'".');case 26:case"end":return e.stop()}}),e,null,[[4,14],[17,23]])})));return function(){return e.apply(this,arguments)}}(),Helper.initializeConnection=function(){var e=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function e(_,r){var t,n,o,a,c,i;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(t=clientnode__WEBPACK_IMPORTED_MODULE_4___default().stringFormat(r.couchdb.url,r.couchdb.user.name+":"+r.couchdb.user.password+"@")+"/"+r.couchdb.databaseName,_.couchdb.connection=new _.couchdb.connector(t,Helper.getConnectorOptions(r)),_.couchdb.connection.setMaxListeners(1/0),n=r.couchdb.model.property.name.special.id,o=r.couchdb.model.property.name.special.revision,a=function(){var e=i.value,t=_.couchdb.connection[e].bind(_.couchdb.connection);_.couchdb.connection[e]=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function e(_){var a,c,i,l,s,u=arguments;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(e.prev=0,a=u.length,c=Array(1<a?a-1:0),i=1;i<a;i++)c[i-1]=u[i];return e.next=4,t.apply(void 0,[_].concat(c));case 4:return e.abrupt("return",e.sent);case 7:if(e.prev=7,e.t0=e.catch(0),!(n in _&&r.couchdb.ignoreNoChangeError&&"forbidden"===e.t0.name&&null!=(l=e.t0.message)&&l.startsWith("NoChange:"))){e.next=21;break}if(s={id:_[n],ok:!0},!(o in _)||["latest","upsert"].includes(_[o])){e.next=15;break}e.t1=_[o],e.next=19;break;case 15:return e.next=17,this.get(s.id);case 17:e.t2=o,e.t1=e.sent[e.t2];case 19:return s.rev=e.t1,e.abrupt("return",s);case 21:throw e.t0;case 22:case"end":return e.stop()}}),e,this,[[0,7]])})))},c=_createForOfIteratorHelperLoose(["post","put"]);!(i=c()).done;)a();return e.prev=7,e.next=10,clientnode__WEBPACK_IMPORTED_MODULE_4___default().checkReachability(t);case 10:e.next=17;break;case 12:return e.prev=12,e.t0=e.catch(7),e.next=17,clientnode__WEBPACK_IMPORTED_MODULE_4__.globalContext.fetch(t,{method:"PUT"});case 17:return e.abrupt("return",_);case 18:case"end":return e.stop()}}),e,null,[[7,12]])})));return function(){return e.apply(this,arguments)}}(),Helper.startServer=function(){function startServer(){return _startServer.apply(this,arguments)}var _startServer=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function _callee4(services,configuration){var _this=this;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(_context4){for(;;)switch(_context4.prev=_context4.next){case 0:if(!Object.prototype.hasOwnProperty.call(services.couchdb.server.runner,"configurationFile")){_context4.next=12;break}return _context4.prev=1,_context4.next=4,fs__WEBPACK_IMPORTED_MODULE_6__.promises.mkdir(path__WEBPACK_IMPORTED_MODULE_7___default().dirname(services.couchdb.server.runner.configurationFile.path),{recursive:!0});case 4:_context4.next=10;break;case 6:if(_context4.prev=6,_context4.t0=_context4.catch(1),"EEXIST"===_context4.t0.code){_context4.next=10;break}throw _context4.t0;case 10:return _context4.next=12,fs__WEBPACK_IMPORTED_MODULE_6__.promises.writeFile(services.couchdb.server.runner.configurationFile.path,services.couchdb.server.runner.configurationFile.content,{encoding:configuration.core.encoding});case 12:return services.couchdb.server.process=(0,child_process__WEBPACK_IMPORTED_MODULE_3__.spawn)("default"===configuration.couchdb.binary.memoryInMegaByte?services.couchdb.server.runner.binaryFilePath:configuration.couchdb.binary.nodePath,("default"===configuration.couchdb.binary.memoryInMegaByte?[]:["--max-old-space-size="+configuration.couchdb.binary.memoryInMegaByte,services.couchdb.server.runner.binaryFilePath]).concat(services.couchdb.server.runner.arguments?services.couchdb.server.runner.arguments:[]),{cwd:eval("process").cwd(),env:Object.prototype.hasOwnProperty.call(services.couchdb.server.runner,"environment")?_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({},eval("process").env,services.couchdb.server.runner.environment):eval("process").env,shell:!0,stdio:"inherit"}),new Promise((function(e,_){for(var r,t,n=_createForOfIteratorHelperLoose(clientnode__WEBPACK_IMPORTED_MODULE_4__.CloseEventNames);!(r=n()).done;)t=r.value,services.couchdb.server.process.on(t,clientnode__WEBPACK_IMPORTED_MODULE_4___default().getProcessCloseHandler(e,_,{process:services.couchdb.server.process,reason:t}))})).then((function(e){var _,r;null!=(_=services.couchdb)&&null!=(r=_.server)&&r.resolve&&services.couchdb.server.resolve.call(_this,e)}),(function(e){var _,r;null!=(_=services.couchdb)&&null!=(r=_.server)&&r.resolve&&services.couchdb.server.reject.call(_this,e)})),_context4.next=16,clientnode__WEBPACK_IMPORTED_MODULE_4___default().checkReachability(clientnode__WEBPACK_IMPORTED_MODULE_4___default().stringFormat(configuration.couchdb.url,""),{wait:!0});case 16:case"end":return _context4.stop()}}),_callee4,null,[[1,6]])})));return startServer}(),Helper.restartServer=function(){var e=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function e(_){var r,t,n,o,a,c;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=_.configuration,t=_.pluginAPI,n=_.services,o=n.couchdb.server,a=o.resolve,c=o.reject,o.resolve=o.reject=clientnode__WEBPACK_IMPORTED_MODULE_4___default().noop,e.next=7,Helper.stopServer(n,r);case 7:return o.resolve=a,o.reject=c,e.next=11,Helper.startServer(n,r);case 11:return Helper.initializeConnection(n,r),e.next=14,t.callStack(_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({},_,{hook:"restartCouchdb"}));case 14:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),Helper.stopServer=function(){var e=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function e(_,r){var t,n;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=_.couchdb,n=r.couchdb,t.connection&&t.connection.close(),t.server.process&&t.server.process.kill("SIGINT"),e.next=6,clientnode__WEBPACK_IMPORTED_MODULE_4___default().checkUnreachability(clientnode__WEBPACK_IMPORTED_MODULE_4___default().stringFormat(n.url,""),{wait:!0});case 6:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),Helper.determineAllowedModelRolesMapping=function(e){for(var _=e.property.name.special.allowedRoles,r={},t=Helper.extendModels(e),n=0,o=Object.entries(t);n<o.length;n++){var a=o[n],c=a[0],i=a[1];if(Object.prototype.hasOwnProperty.call(i,_)){r[c]=_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({properties:{}},Helper.normalizeAllowedRoles(i[_]));for(var l=0,s=Object.entries(i);l<s.length;l++){var u=s[l],p=u[0],d=u[1];null!==d&&"object"==typeof d&&d.allowedRoles&&(r[c].properties[p]=Helper.normalizeAllowedRoles(d.allowedRoles))}}else r[c]={properties:{},read:[],write:[]}}return r},Helper.determineGenericIndexablePropertyNames=function(e,_){var r=e.property.name.special;return Object.keys(_).filter((function(t){return null!==_[t]&&"object"==typeof _[t]&&(Object.prototype.hasOwnProperty.call(_[t],"index")&&_[t].index||!(Object.prototype.hasOwnProperty.call(_[t],"index")&&!_[t].index||e.property.name.reserved.concat(r.additional,r.allowedRoles,r.attachment,r.conflict,r.constraint.execution,r.constraint.expression,r.deleted,r.deletedConflict,r.extend,r.id,r.maximumAggregatedSize,r.minimumAggregatedSize,r.oldType,r.revision,r.revisions,r.revisionsInformation,r.type).includes(t)||_[t].type&&("string"==typeof _[t].type&&_[t].type.endsWith("[]")||Array.isArray(_[t].type)&&_[t].type.length&&Array.isArray(_[t].type[0])||Object.prototype.hasOwnProperty.call(e.entities,_[t].type))))})).concat(r.id,r.revision).sort()},Helper.extendModel=function(e,_,r){if(void 0===r&&(r="_extends"),"_base"===e)return _[e];if(Object.prototype.hasOwnProperty.call(_,"_base")&&(Object.prototype.hasOwnProperty.call(_[e],r)&&_[e][r]?_[e][r]=["_base"].concat(_[e][r]):_[e][r]="_base"),Object.prototype.hasOwnProperty.call(_[e],r)){for(var t,n,o=_createForOfIteratorHelperLoose([].concat(_[e][r]));!(t=o()).done;)n=t.value,_[e]=clientnode__WEBPACK_IMPORTED_MODULE_4___default().extend(!0,clientnode__WEBPACK_IMPORTED_MODULE_4___default().copy(Helper.extendModel(n,_,r)),_[e]);delete _[e][r]}return _[e]},Helper.extendModels=function(e){for(var _,r=e.property.name.special,t={},n=0,o=Object.keys(e.entities);n<o.length;n++){if(_=o[n],!new RegExp(e.property.name.typeRegularExpressionPattern.public).test(_)&&!new RegExp(e.property.name.typeRegularExpressionPattern.private).test(_))throw new Error('Model names have to match "'+e.property.name.typeRegularExpressionPattern.public+'" or "'+e.property.name.typeRegularExpressionPattern.private+'" for private one (given name: "'+_+'").');t[_]=Helper.extendModel(_,e.entities,r.extend)}for(var a,c=0,i=Object.values(t);c<i.length;c++){a=i[c];for(var l=0,s=Object.entries(a);l<s.length;l++){var u=s[l],p=u[0],d=u[1];if(p===r.attachment)for(var E=0,b=Object.entries(d);E<b.length;E++){var O=b[E],f=O[0],P=O[1];d[f]=clientnode__WEBPACK_IMPORTED_MODULE_4___default().extend(!0,clientnode__WEBPACK_IMPORTED_MODULE_4___default().copy(e.property.defaultSpecification),P)}else[r.allowedRoles,r.constraint.execution,r.constraint.expression,r.extend,r.maximumAggregatedSize,r.minimumAggregatedSize,r.oldType].includes(p)||(a[p]=clientnode__WEBPACK_IMPORTED_MODULE_4___default().extend(!0,clientnode__WEBPACK_IMPORTED_MODULE_4___default().copy(e.property.defaultSpecification),d))}}return t},Helper.normalizeAllowedRoles=function(e){if(Array.isArray(e))return{read:e,write:e};if("object"==typeof e){for(var _,r={read:[],write:[]},t=0,n=Object.keys(r);t<n.length;t++)_=n[t],Object.prototype.hasOwnProperty.call(e,_)&&(Array.isArray(e[_])?r[_]=e[_]:r[_]=[e[_]]);return r}return{read:[e],write:[e]}},Helper}();const __WEBPACK_DEFAULT_EXPORT__=Helper})(),module.exports=__webpack_exports__})();
package/index.d.ts CHANGED
@@ -1,12 +1,11 @@
1
- import { PluginAPI } from 'web-node';
2
- import { Plugin, PluginHandler } from 'web-node/type';
3
- import { ChangesStream, Configuration, Service, ServicePromises, Services } from './type';
1
+ import { PluginHandler, PluginPromises } from 'web-node/type';
2
+ import { ServicesState, State } from './type';
4
3
  /**
5
4
  * Launches an application server und triggers all some pluginable hooks on
6
5
  * an event.
6
+ * TODO move to configuration.
7
7
  * @property static:additionalChangesStreamOptions - Can provide additional
8
8
  * (non static) changes stream options.
9
- * @property static:changesStream - Stream which triggers database events.
10
9
  * @property static:skipIDDetermining - Indicates whether id's should be
11
10
  * determined if "bulkDocs" had skipped a real change due to ignore a
12
11
  * "NoChange" error.
@@ -16,52 +15,45 @@ import { ChangesStream, Configuration, Service, ServicePromises, Services } from
16
15
  */
17
16
  export declare class Database implements PluginHandler {
18
17
  static additionalChangesStreamOptions: object;
19
- static changesStream: ChangesStream;
20
18
  static skipIDDetermining: boolean;
21
19
  static toggleIDDetermining: symbol;
20
+ /**
21
+ * Appends an application server to the web node services.
22
+ * @param state - Application state.
23
+ * @param state.configuration - Applications configuration.
24
+ * @param state.configuration.couchdb - Plugins configuration.
25
+ * @param state.services - Applications services.
26
+ *
27
+ * @returns Promise resolving to nothing.
28
+ */
29
+ static preLoadService({ configuration: { couchdb: configuration }, services }: ServicesState): Promise<void>;
22
30
  /**
23
31
  * Start database's child process and return a Promise which observes this
24
32
  * service.
25
- * @param servicePromises - An object with stored service promise
26
- * instances.
27
- * @param services - An object with stored service instances.
28
- * @param configuration - Mutable by plugins extended configuration object.
33
+ * @param state - Application state.
34
+ * @param state.configuration - Applications configuration.
35
+ * @param state.services - Applications services.
29
36
  *
30
37
  * @returns A promise which correspond to the plugin specific continues
31
38
  * service.
32
39
  */
33
- static loadService(servicePromises: Omit<ServicePromises, 'couchdb'>, services: Services, configuration: Configuration): Promise<Service>;
40
+ static loadService({ configuration, services }: State): Promise<PluginPromises>;
34
41
  /**
35
42
  * Add database event listener to auto restart database server on
36
43
  * unexpected server issues.
37
- * @param servicePromises - An object with stored service promise
38
- * instances.
39
- * @param services - An object with stored service instances.
40
- * @param configuration - Mutable by plugins extended configuration object.
41
- * @param plugins - Topological sorted list of loaded plugins.
42
- * @param pluginAPI - Plugin api reference.
43
- *
44
- * @returns A promise which wraps plugin promises to represent plugin
45
- * continues services.
46
- */
47
- static postLoadService(servicePromises: ServicePromises, services: Services, configuration: Configuration, plugins: Array<Plugin>, pluginAPI: typeof PluginAPI): ServicePromises;
48
- /**
49
- * Appends an application server to the web node services.
50
- * @param services - An object with stored service instances.
51
- * @param configuration - Mutable by plugins extended configuration object.
44
+ * @param state - Application state.
52
45
  *
53
- * @returns Given and extended object of services wrapped in a promise
54
- * resolving after pre-loading has finished.
46
+ * @returns Promise resolving to nothing.
55
47
  */
56
- static preLoadService(services: Services, configuration: Configuration): Promise<Services>;
48
+ static postLoadService(state: State): Promise<void>;
57
49
  /**
58
50
  * Triggered when application will be closed soon.
59
- * @param services - An object with stored service instances.
60
- * @param configuration - Mutable by plugins extended configuration object.
51
+ * @param state - Application state.
52
+ * @param state.configuration - Applications configuration.
53
+ * @param state.services - Applications services.
61
54
  *
62
- * @returns Given object of services wrapped in a promise resolving after
63
- * finish.
55
+ * @returns Promise resolving to nothing.
64
56
  */
65
- static shouldExit(services: Services, configuration: Configuration): Promise<Services>;
57
+ static shouldExit({ configuration, services }: State): Promise<void>;
66
58
  }
67
59
  export default Database;
package/index.js CHANGED
@@ -1 +1 @@
1
- (()=>{var __webpack_modules__=[e=>{"use strict";e.exports=require("@babel/runtime/helpers/extends")},e=>{"use strict";e.exports=require("@babel/runtime/helpers/asyncToGenerator")},e=>{"use strict";e.exports=require("@babel/runtime/regenerator")},e=>{"use strict";e.exports=require("child_process")},e=>{"use strict";e.exports=require("clientnode")},e=>{"use strict";e.exports=require("pouchdb/node_modules/node-fetch/lib/index.js")},e=>{"use strict";e.exports=require("fs")},e=>{"use strict";e.exports=require("path")},(__unused_webpack_module,__webpack_exports__,__webpack_require__)=>{"use strict";__webpack_require__.d(__webpack_exports__,{default:()=>__WEBPACK_DEFAULT_EXPORT__});var _babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__(0),_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default=__webpack_require__.n(_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__),_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1__=__webpack_require__(1),_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default=__webpack_require__.n(_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1__),_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2__=__webpack_require__(2),_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default=__webpack_require__.n(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2__),child_process__WEBPACK_IMPORTED_MODULE_3__=__webpack_require__(3),child_process__WEBPACK_IMPORTED_MODULE_3___default=__webpack_require__.n(child_process__WEBPACK_IMPORTED_MODULE_3__),clientnode__WEBPACK_IMPORTED_MODULE_4__=__webpack_require__(4),clientnode__WEBPACK_IMPORTED_MODULE_4___default=__webpack_require__.n(clientnode__WEBPACK_IMPORTED_MODULE_4__),node_fetch__WEBPACK_IMPORTED_MODULE_5__=__webpack_require__(5),node_fetch__WEBPACK_IMPORTED_MODULE_5___default=__webpack_require__.n(node_fetch__WEBPACK_IMPORTED_MODULE_5__),fs__WEBPACK_IMPORTED_MODULE_6__=__webpack_require__(6),fs__WEBPACK_IMPORTED_MODULE_6___default=__webpack_require__.n(fs__WEBPACK_IMPORTED_MODULE_6__),path__WEBPACK_IMPORTED_MODULE_7__=__webpack_require__(7),path__WEBPACK_IMPORTED_MODULE_7___default=__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_7__);function _createForOfIteratorHelperLoose(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=_unsupportedIterableToArray(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(e,t){if(e){if("string"==typeof e)return _arrayLikeToArray(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?_arrayLikeToArray(e,t):void 0}}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}clientnode__WEBPACK_IMPORTED_MODULE_4__.globalContext.fetch=node_fetch__WEBPACK_IMPORTED_MODULE_5___default();var Helper=function(){function Helper(){}return Helper.getConnectorOptions=function(e){return e.couchdb.connector.fetch?{fetch:function(t,r){return clientnode__WEBPACK_IMPORTED_MODULE_4__.globalContext.fetch(t,clientnode__WEBPACK_IMPORTED_MODULE_4___default().extend(!0,clientnode__WEBPACK_IMPORTED_MODULE_4___default().copy(e.couchdb.connector.fetch),r||{}))}}:{fetch:function(e,t){return clientnode__WEBPACK_IMPORTED_MODULE_4__.globalContext.fetch(e,t)}}},Helper.mayStripRepresentation=function(e,t,r){var n=clientnode__WEBPACK_IMPORTED_MODULE_4___default().represent(e);return n.length<=t?n.length>r?n.substring(0,r-3)+"...":n:"DOCUMENT IS TOO BIG TO REPRESENT"},Helper.ensureValidationDocumentPresence=function(){var e=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function e(t,r,n,a,o,c,i){var s,l,u;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return void 0===o&&(o=!0),void 0===c&&(c="_id"),void 0===i&&(i="_design/"),l=_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()(((s={})[c]=""+i+r,s.language="javascript",s),n),e.prev=4,e.next=7,t.get(""+i+r);case 7:return u=e.sent,l._rev=u._rev,e.next=11,t.put(l);case 11:case 20:e.next=26;break;case 14:return e.prev=14,e.t0=e.catch(4),o&&e.t0.error,e.prev=17,e.next=20,t.put(l);case 23:throw e.prev=23,e.t1=e.catch(17),new Error(a+" couldn't be installed/updated: \""+clientnode__WEBPACK_IMPORTED_MODULE_4___default().represent(e.t1)+'".');case 26:case"end":return e.stop()}}),e,null,[[4,14],[17,23]])})));return function(){return e.apply(this,arguments)}}(),Helper.initializeConnection=function(){var e=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function e(t,r){var n,a,o,c,i,s;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(n=clientnode__WEBPACK_IMPORTED_MODULE_4___default().stringFormat(r.couchdb.url,r.couchdb.user.name+":"+r.couchdb.user.password+"@")+"/"+r.couchdb.databaseName,t.couchdb.connection=new t.couchdb.connector(n,Helper.getConnectorOptions(r)),t.couchdb.connection.setMaxListeners(1/0),a=r.couchdb.model.property.name.special.id,o=r.couchdb.model.property.name.special.revision,c=function(){var e=s.value,n=t.couchdb.connection[e].bind(t.couchdb.connection);t.couchdb.connection[e]=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function e(t){var c,i,s,l,u,p=arguments;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(e.prev=0,c=p.length,i=Array(1<c?c-1:0),s=1;s<c;s++)i[s-1]=p[s];return e.next=4,n.apply(void 0,[t].concat(i));case 4:return e.abrupt("return",e.sent);case 7:if(e.prev=7,e.t0=e.catch(0),!(a in t&&r.couchdb.ignoreNoChangeError&&"forbidden"===e.t0.name&&null!=(l=e.t0.message)&&l.startsWith("NoChange:"))){e.next=21;break}if(u={id:t[a],ok:!0},!(o in t)||["latest","upsert"].includes(t[o])){e.next=15;break}e.t1=t[o],e.next=19;break;case 15:return e.next=17,this.get(u.id);case 17:e.t2=o,e.t1=e.sent[e.t2];case 19:return u.rev=e.t1,e.abrupt("return",u);case 21:throw e.t0;case 22:case"end":return e.stop()}}),e,this,[[0,7]])})))},i=_createForOfIteratorHelperLoose(["post","put"]);!(s=i()).done;)c();return e.prev=7,e.next=10,clientnode__WEBPACK_IMPORTED_MODULE_4___default().checkReachability(n);case 10:e.next=17;break;case 12:return e.prev=12,e.t0=e.catch(7),e.next=17,clientnode__WEBPACK_IMPORTED_MODULE_4__.globalContext.fetch(n,{method:"PUT"});case 17:return e.abrupt("return",t);case 18:case"end":return e.stop()}}),e,null,[[7,12]])})));return function(){return e.apply(this,arguments)}}(),Helper.startServer=function(){function startServer(){return _startServer.apply(this,arguments)}var _startServer=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function _callee4(services,configuration){var _this=this;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(_context4){for(;;)switch(_context4.prev=_context4.next){case 0:if(!Object.prototype.hasOwnProperty.call(services.couchdb.server.runner,"configurationFile")){_context4.next=12;break}return _context4.prev=1,_context4.next=4,fs__WEBPACK_IMPORTED_MODULE_6__.promises.mkdir(path__WEBPACK_IMPORTED_MODULE_7___default().dirname(services.couchdb.server.runner.configurationFile.path),{recursive:!0});case 4:_context4.next=10;break;case 6:if(_context4.prev=6,_context4.t0=_context4.catch(1),"EEXIST"===_context4.t0.code){_context4.next=10;break}throw _context4.t0;case 10:return _context4.next=12,fs__WEBPACK_IMPORTED_MODULE_6__.promises.writeFile(services.couchdb.server.runner.configurationFile.path,services.couchdb.server.runner.configurationFile.content,{encoding:configuration.core.encoding});case 12:return services.couchdb.server.process=(0,child_process__WEBPACK_IMPORTED_MODULE_3__.spawn)("default"===configuration.couchdb.binary.memoryInMegaByte?services.couchdb.server.runner.binaryFilePath:configuration.couchdb.binary.nodePath,("default"===configuration.couchdb.binary.memoryInMegaByte?[]:["--max-old-space-size="+configuration.couchdb.binary.memoryInMegaByte,services.couchdb.server.runner.binaryFilePath]).concat(services.couchdb.server.runner.arguments?services.couchdb.server.runner.arguments:[]),{cwd:eval("process").cwd(),env:Object.prototype.hasOwnProperty.call(services.couchdb.server.runner,"environment")?_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({},eval("process").env,services.couchdb.server.runner.environment):eval("process").env,shell:!0,stdio:"inherit"}),new Promise((function(e,t){for(var r,n,a=_createForOfIteratorHelperLoose(clientnode__WEBPACK_IMPORTED_MODULE_4__.CloseEventNames);!(r=a()).done;)n=r.value,services.couchdb.server.process.on(n,clientnode__WEBPACK_IMPORTED_MODULE_4___default().getProcessCloseHandler(e,t,{process:services.couchdb.server.process,reason:n}))})).then((function(e){var t,r;null!=(t=services.couchdb)&&null!=(r=t.server)&&r.resolve&&services.couchdb.server.resolve.call(_this,e)}),(function(e){var t,r;null!=(t=services.couchdb)&&null!=(r=t.server)&&r.resolve&&services.couchdb.server.reject.call(_this,e)})),_context4.next=16,clientnode__WEBPACK_IMPORTED_MODULE_4___default().checkReachability(clientnode__WEBPACK_IMPORTED_MODULE_4___default().stringFormat(configuration.couchdb.url,""),{wait:!0});case 16:case"end":return _context4.stop()}}),_callee4,null,[[1,6]])})));return startServer}(),Helper.restartServer=function(){var e=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function e(t,r,n,a){var o,c;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=t.couchdb.server.resolve,c=t.couchdb.server.reject,t.couchdb.server.resolve=t.couchdb.server.reject=clientnode__WEBPACK_IMPORTED_MODULE_4___default().noop,e.next=5,Helper.stopServer(t,r);case 5:return t.couchdb.server.resolve=o,t.couchdb.server.reject=c,e.next=9,Helper.startServer(t,r);case 9:return Helper.initializeConnection(t,r),e.next=12,a.callStack("restartCouchdb",n,r,t);case 12:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),Helper.stopServer=function(){var e=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function e(t,r){return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t.couchdb.connection&&t.couchdb.connection.close(),t.couchdb.server.process&&t.couchdb.server.process.kill("SIGINT"),e.next=4,clientnode__WEBPACK_IMPORTED_MODULE_4___default().checkUnreachability(clientnode__WEBPACK_IMPORTED_MODULE_4___default().stringFormat(r.couchdb.url,""),{wait:!0});case 4:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),Helper.determineAllowedModelRolesMapping=function(e){for(var t=e.property.name.special.allowedRoles,r={},n=Helper.extendModels(e),a=0,o=Object.entries(n);a<o.length;a++){var c=o[a],i=c[0],s=c[1];if(Object.prototype.hasOwnProperty.call(s,t)){r[i]=_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({properties:{}},Helper.normalizeAllowedRoles(s[t]));for(var l=0,u=Object.entries(s);l<u.length;l++){var p=u[l],d=p[0],_=p[1];null!==_&&"object"==typeof _&&_.allowedRoles&&(r[i].properties[d]=Helper.normalizeAllowedRoles(_.allowedRoles))}}else r[i]={properties:{},read:[],write:[]}}return r},Helper.determineGenericIndexablePropertyNames=function(e,t){var r=e.property.name.special;return Object.keys(t).filter((function(n){return null!==t[n]&&"object"==typeof t[n]&&(Object.prototype.hasOwnProperty.call(t[n],"index")&&t[n].index||!(Object.prototype.hasOwnProperty.call(t[n],"index")&&!t[n].index||e.property.name.reserved.concat(r.additional,r.allowedRoles,r.attachment,r.conflict,r.constraint.execution,r.constraint.expression,r.deleted,r.deletedConflict,r.extend,r.id,r.maximumAggregatedSize,r.minimumAggregatedSize,r.oldType,r.revision,r.revisions,r.revisionsInformation,r.type).includes(n)||t[n].type&&("string"==typeof t[n].type&&t[n].type.endsWith("[]")||Array.isArray(t[n].type)&&t[n].type.length&&Array.isArray(t[n].type[0])||Object.prototype.hasOwnProperty.call(e.entities,t[n].type))))})).concat(r.id,r.revision).sort()},Helper.extendModel=function(e,t,r){if(void 0===r&&(r="_extends"),"_base"===e)return t[e];if(Object.prototype.hasOwnProperty.call(t,"_base")&&(Object.prototype.hasOwnProperty.call(t[e],r)&&t[e][r]?t[e][r]=["_base"].concat(t[e][r]):t[e][r]="_base"),Object.prototype.hasOwnProperty.call(t[e],r)){for(var n,a,o=_createForOfIteratorHelperLoose([].concat(t[e][r]));!(n=o()).done;)a=n.value,t[e]=clientnode__WEBPACK_IMPORTED_MODULE_4___default().extend(!0,clientnode__WEBPACK_IMPORTED_MODULE_4___default().copy(Helper.extendModel(a,t,r)),t[e]);delete t[e][r]}return t[e]},Helper.extendModels=function(e){for(var t,r=e.property.name.special,n={},a=0,o=Object.keys(e.entities);a<o.length;a++){if(t=o[a],!new RegExp(e.property.name.typeRegularExpressionPattern.public).test(t)&&!new RegExp(e.property.name.typeRegularExpressionPattern.private).test(t))throw new Error('Model names have to match "'+e.property.name.typeRegularExpressionPattern.public+'" or "'+e.property.name.typeRegularExpressionPattern.private+'" for private one (given name: "'+t+'").');n[t]=Helper.extendModel(t,e.entities,r.extend)}for(var c,i=0,s=Object.values(n);i<s.length;i++){c=s[i];for(var l=0,u=Object.entries(c);l<u.length;l++){var p=u[l],d=p[0],_=p[1];if(d===r.attachment)for(var m=0,f=Object.entries(_);m<f.length;m++){var b=f[m],h=b[0],y=b[1];_[h]=clientnode__WEBPACK_IMPORTED_MODULE_4___default().extend(!0,clientnode__WEBPACK_IMPORTED_MODULE_4___default().copy(e.property.defaultSpecification),y)}else[r.allowedRoles,r.constraint.execution,r.constraint.expression,r.extend,r.maximumAggregatedSize,r.minimumAggregatedSize,r.oldType].includes(d)||(c[d]=clientnode__WEBPACK_IMPORTED_MODULE_4___default().extend(!0,clientnode__WEBPACK_IMPORTED_MODULE_4___default().copy(e.property.defaultSpecification),_))}}return n},Helper.normalizeAllowedRoles=function(e){if(Array.isArray(e))return{read:e,write:e};if("object"==typeof e){for(var t,r={read:[],write:[]},n=0,a=Object.keys(r);n<a.length;n++)t=a[n],Object.prototype.hasOwnProperty.call(e,t)&&(Array.isArray(e[t])?r[t]=e[t]:r[t]=[e[t]]);return r}return{read:[e],write:[e]}},Helper}();const __WEBPACK_DEFAULT_EXPORT__=Helper},e=>{!function(){"use strict";function t(){return(t=r()?Reflect.construct:function(e,t,r){var a=[null];a.push.apply(a,t);var o=new(Function.bind.apply(e,a));return r&&n(o,r.prototype),o}).apply(null,arguments)}function r(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function n(e,t){return n=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},n(e,t)}function a(){return a=Object.assign||function(e){for(var t,r=1;r<arguments.length;r++)for(var n in t=arguments[r])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e},a.apply(this,arguments)}function o(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return c(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?c(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function c(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}var i={d:function(e,t){for(var r in t)i.o(t,r)&&!i.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},o:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r:function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},s={};i.r(s),i.d(s,{DatabaseHelper:function(){return l},default:function(){return u}});var l=function(){function e(){}return e.authenticate=function(e,t,r,n,a,c,i,s,l){var u;void 0===t&&(t=null),void 0===r&&(r={}),void 0===n&&(n={admins:{names:[],roles:[]},members:{names:[],roles:[]}}),void 0===c&&(c="_id"),void 0===i&&(i="-type"),void 0===s&&(s="_design/"),void 0===l&&(l=!1);var p=null!==(u=e[i])&&void 0!==u?u:t&&t[i];if(!p)return!0;var d=l?"read":"write",_={properties:{},read:["_admin","readonlyadmin"],write:["_admin"]};Object.prototype.hasOwnProperty.call(e,c)&&e[c].startsWith(s)&&_.read.push("readonlymember");var m,f="Current user doesn't own any role";if(r)if("name"in r||(r.name='"unknown"'),null!=(m=r.roles)&&m.length){if(a&&p&&Object.prototype.hasOwnProperty.call(a,p)){for(var b,h,y=a[p],v=o(["read","write"]);!(b=v()).done;)_[h=b.value]=_[h].concat(y[h]||[]);_.properties=y.properties}for(var g,O,x=_[d],P=o(r.roles);!(g=P()).done;)if(O=g.value,x.includes(O))return!0;f='Current user "'+r.name+'" owns the following roles: "'+r.roles.join('", "')+'"'}else f='Current user "'+r.name+"\" doesn't own any role";throw{unauthorized:"Only users with a least on of these roles are allowed to perform requested "+d+' action: "'+[].concat(_[d]).join('", "')+'". '+f+"."}},e.validateDocumentUpdate=function(e,r,n,c,i,s,l){void 0===s&&(s={});var u=function(e,t,r){var n;void 0===t&&(t="forbidden"),void 0===r&&(r={});for(var a=((n={})[t]=e,n.message=e,n.name=t,n),o=0,c=Object.entries(r);o<c.length;o++){var i=c[o],s=i[0],l=i[1];a[s]=l}throw a},p=new Date,d=Date.UTC(p.getUTCFullYear(),p.getUTCMonth(),p.getUTCDate(),p.getUTCHours(),p.getUTCMinutes(),p.getUTCSeconds(),p.getUTCMilliseconds())/1e3,_=!i.dateTimeFormat.startsWith("iso"),m=i.property.name.special,f=m.id,b=m.revision,h=m.type;r&&r[h]&&!e[h]&&(e[h]=r[h]);var y="",v="",g=function(){y=Object.prototype.hasOwnProperty.call(e,f)?e[f]:"",v=Object.prototype.hasOwnProperty.call(e,b)?e[b]:""};if(g(),Object.prototype.hasOwnProperty.call(c,i.property.name.validatedDocumentsCache)&&c[i.property.name.validatedDocumentsCache].has(y+"-"+v))return c[i.property.name.validatedDocumentsCache].delete(y+"-"+v),e;["latest","upsert"].includes(v)&&(r&&Object.prototype.hasOwnProperty.call(r,b)?v=e[b]=r[b]:"latest"===v?u("Revision: No old document available to update."):delete e[b]);var O=i.updateStrategy;Object.prototype.hasOwnProperty.call(e,m.strategy)&&(O=e[m.strategy],delete e[m.strategy]);var x,P={};if("migrate"===O)for(var w=0,E=Object.entries(s);w<E.length;w++){var k=E[w],D=k[0],j=k[1];if(Object.prototype.hasOwnProperty.call(j,m.oldType)&&![null,void 0].includes(j[m.oldType]))for(var M,A,C=o([].concat(j[m.oldType]));!(M=C()).done;)A=M.value,P[A]=D}l?x=l:JSON&&Object.prototype.hasOwnProperty.call(JSON,"stringify")?x=function(e){return JSON.stringify(e,null,4)}:u('Needed "serializer" is not available.');var T=function(e){return e instanceof Error?""+e:x(e)},R=function(e){return"string"==typeof e?e.trim():""},I=function(e){if(_)null!==e&&"number"!=typeof e&&(e=new Date(e),e=Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate(),e.getUTCHours(),e.getUTCMinutes(),e.getUTCSeconds(),e.getUTCMilliseconds())/1e3);else if(null!==e){e=new Date("number"!=typeof e||isNaN(e)?e:1e3*e);try{e=e.toISOString()}catch(e){}}return e},S=function(e,t,r){if(r.fileName){if(r.fileName.value)return r.fileName.value===t;if(r.fileName.regularExpressionPattern)return new RegExp(r.fileName.regularExpressionPattern).test(t)}return e===t},U=function(t,r){if(r||(r=e[m.attachment]),t){for(var n,a=0,o=Object.keys(r);a<o.length;a++)if((n=o[a]).startsWith(t))return n}else{var c=Object.keys(r);if(c.length)return c[0]}return null},L=function(e,r,n){void 0===r&&(r=!1),void 0===n&&(n={});var o=R(e);if(o){var c,i=(r?"return ":"")+o,s=a({},W,{code:i},n),l=Object.keys(s);try{c=t(Function,l.concat([i]))}catch(e){u(T(e),"compilation",{code:i,error:e,scope:s})}var p={code:i,result:void 0,scope:s};try{p.result=c.apply(void 0,l.map((function(e){return s[e]})))}catch(e){u(T(e),"runtime",{code:i,error:e,scope:s})}return p}u("No expression to evaluate provided.","empty")},N=function(e,r,n){void 0===n&&(n=[]);var a=n.length?" in "+n.join(" -> "):"",c=[],l=function(){Object.prototype.hasOwnProperty.call(e,h)||(r&&Object.prototype.hasOwnProperty.call(r,h)&&["fillUp","migrate"].includes(O)?e[h]=r[h]:u('Type: You have to specify a model type via property "'+h+'"'+a+".")),n.length||new RegExp(i.property.name.typeRegularExpressionPattern.public).test(e[h])||u('TypeName: You have to specify a model type which matches "'+i.property.name.typeRegularExpressionPattern.public+'" as public type (given "'+e[h]+'")'+a+"."),Object.prototype.hasOwnProperty.call(s,e[h])||(Object.prototype.hasOwnProperty.call(P,e[h])?e[h]=P[e[h]]:u('Model: Given model "'+e[h]+'" is not specified'+a+"."))};l();var p=e[h],d=s[p],y=null;Object.prototype.hasOwnProperty.call(d,m.additional)&&d[m.additional]&&(y=d[m.additional]);var v=function c(i,s,l,_,m){void 0===m&&(m=["constraintExecution","constraintExpression"]);for(var f,b,h=o(m);!(f=h()).done;)if(b=f.value,Object.prototype.hasOwnProperty.call(l,b)){var y,v=void 0;try{v=L(l[b].evaluation,b.endsWith("Expression"),{checkPropertyContent:c,model:d,modelName:p,name:s,type:b,newDocument:e,newValue:i,oldDocument:r,oldValue:_,parentNames:n,pathDescription:a,propertySpecification:l})}catch(s){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(s)&&u('Compilation: Hook "'+b+'" has invalid code "'+s.code+'": "'+s.message+'"'+a+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(s)&&u('Runtime: Hook "'+b+'" has throw an error with code "'+s.code+'": "'+s.message+'"'+a+"."),!Object.prototype.hasOwnProperty.call(s,"empty"))throw s}if(null==(y=v)||!y.result){var g=R(l[b].description);u(b.charAt(0).toUpperCase()+(b.substring(1)+": ")+(g?t(Function,Object.keys(v.scope).concat(["return "+g])).apply(void 0,Object.values(v.scope)):'Property "'+s+'" should satisfy constraint "'+v.code+'" (given "'+T(i)+'")'+a+"."))}}},x=function(e,t,r,c){void 0===c&&(c=null);var i=[],l=[].concat(r.type?r.type:[]);"object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype&&!Object.prototype.hasOwnProperty.call(e,h)&&1===l.length&&Object.prototype.hasOwnProperty.call(s,l[0])&&(e[h]=l[0]);for(var p,d,m=!1,b=o(l);!(p=b()).done;)if(d=p.value,Object.prototype.hasOwnProperty.call(s,d)){if("object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype&&Object.prototype.hasOwnProperty.call(e,h)&&e[h]!==d&&"migrate"===O&&1===l.length&&(e[h]=d,i=n.concat(t,"migrate nested object type")),"object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype&&Object.prototype.hasOwnProperty.call(e,h)&&e[h]===d){var y=N(e,c,n.concat(t));if(y.changedPath.length&&(i=y.changedPath),e=y.newDocument,T(e)===T({}))return{newValue:null,changedPath:i};m=!0;break}1===l.length&&u('NestedType: Under key "'+t+'" isn\'t of type "'+d+'" (given "'+T(e)+'" of type '+typeof e+")"+a+".")}else if("DateTime"===d){var g=e;if(e=I(e),!(_&&("number"!=typeof e||isNaN(e))||!_&&"string"!=typeof e)){m=!0;break}1===l.length&&u('PropertyType: Property "'+t+'" isn\'t of (valid) type "DateTime" (given "'+T(g).replace(/^"/,"").replace(/"$/,"")+'" of type "'+typeof g+'")'+a+".")}else if(["boolean","integer","number","string"].includes(d)){if(!("number"==typeof e&&isNaN(e)||"integer"!==d&&typeof e!==d||"integer"===d&&parseInt(e,10)!==e)){m=!0;break}1===l.length&&u('PropertyType: Property "'+t+'" isn\'t of (valid) type "${type}" (given "'+T(e)+'" of type "'+typeof e+'")'+a+".")}else if("string"==typeof d&&d.startsWith("foreignKey:")){var x=s[d.substring(11)][f].type;if(x===typeof e){m=!0;break}1===l.length&&u('PropertyType: Foreign key property "'+t+'" isn\'t of type "'+x+'" (given "'+T(e)+'" of type "'+typeof e+'")'+a+".")}else{if("any"===d||T(e)===T(d)){m=!0;break}1===l.length&&u('PropertyType: Property "'+t+'" isn\'t value "'+d+'" (given "'+T(e).replace(/^"/,"").replace(/"$/,"")+'" of type "'+typeof e+'")'+a+".")}if(m||u('PropertyType: None of the specified types "'+l.join('", "')+'" for property "'+t+'" matches value "'+T(e).replace(/^"/,"").replace(/"$/,"")+e+'" of type "'+typeof e+'")'+a+"."),"string"==typeof e&&(![null,void 0].includes(r.minimumLength)&&e.length<r.minimumLength&&u('MinimalLength: Property "'+t+'" must have minimal length '+r.minimumLength+" (given "+e+" with length i"+e.length+") "+a+"."),![null,void 0].includes(r.maximumLength)&&e.length>r.maximumLength&&u('MaximalLength: Property "'+t+'" must have maximal length '+r.maximumLength+" (given "+e+" with length "+e.length+")"+a+".")),"number"==typeof e&&(![null,void 0].includes(r.minimum)&&e<r.minimum&&u('Minimum: Property "'+t+'" (type '+r.type+") must satisfy a minimum of "+r.minimum+" (given "+e+" is too low)"+a+"."),![null,void 0].includes(r.maximum)&&e>r.maximum&&u('Maximum: Property "'+t+'" (type '+r.type+") must satisfy a maximum of "+r.maximum+" (given "+e+" is too high)"+a+".")),r.selection){var P=Array.isArray(r.selection)?r.selection.map((function(e){return void 0===(null==e?void 0:e.value)?e:e.value})):Object.keys(r.selection);"DateTime"===r.type&&(P=P.map(I)),P.includes(e)||u('Selection: Property "'+t+'" (type '+r.type+') should be one of "'+P.join('", "')+'". But is "'+e+'"'+a+".")}return[null,void 0].includes(r.regularExpressionPattern)||new RegExp(r.regularExpressionPattern).test(e)?![null,void 0].includes(r.invertedRegularExpressionPattern)&&new RegExp(r.invertedRegularExpressionPattern).test(e)&&u('InvertedPatternMatch: Property "'+t+'" should not match regular expression pattern '+r.invertedRegularExpressionPattern+' (given "'+e+'")'+a+"."):u('PatternMatch: Property "'+t+'" should match regular expression pattern '+r.regularExpressionPattern+' (given "'+e+'")'+a+"."),v(e,t,r,c),T(e)!==T(c)&&(i=n.concat(t,"value updated")),{newValue:e,changedPath:i}},w=function(e,t,r,a,o){var s=t[a];if(!e.writable)if(r){if(Object.prototype.hasOwnProperty.call(r,a)&&T(s)===T(r[a]))return a!==f&&"incremental"===O&&delete t[a],!0;u('Readonly: Property "'+a+'" is not writable (old document "'+T(r)+'")'+o+".")}else u('Readonly: Property "'+a+'" is not writable'+o+".");if(!e.mutable&&r&&Object.prototype.hasOwnProperty.call(r,a)){if(T(s)===T(r[a]))return"incremental"!==O||i.property.name.reserved.concat(m.deleted,f,b).includes(a)||delete t[a],!0;"migrate"!==O&&u('Immutable: Property "'+a+'" is not writable (old document "'+T(r)+'")'+o+".")}if(null===s){if(e.nullable)return delete t[a],r&&Object.prototype.hasOwnProperty.call(r,a)&&(c=n.concat(a,"delete property")),!0;u('NotNull: Property "'+a+'" should not be "null"'+o+".")}return!1},E=function(e,t,r,c){if(!r)for(var i,s,l=o(["onCreateExecution","onCreateExpression"]);!(i=l()).done;)if(s=i.value,Object.prototype.hasOwnProperty.call(e,s)){var _=void 0;try{_=L(e[s],s.endsWith("Expression"),{checkPropertyContent:x,model:d,modelName:p,name:c,type:s,newDocument:t,oldDocument:r,newValue:void 0,oldValue:void 0,parentNames:n,pathDescription:a,propertySpecification:e})}catch(i){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(i)&&u('Compilation: Hook "'+s+'" has invalid code "'+i.code+'" for property "'+c+'": '+i.message+a+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(i)&&u('Runtime: Hook "'+s+'" has throw an error with code "'+i.code+'" for property "'+c+'": '+i.message+a+"."),!Object.prototype.hasOwnProperty.call(i,"empty"))throw i}_&&![null,void 0].includes(_.result)&&(t[c]=_.result)}},k=function(e,t,r,c){if(Object.prototype.hasOwnProperty.call(t,c)){e.trim&&"string"==typeof t[c]&&(t[c]=t[c].trim()),e.emptyEqualsToNull&&(""===t[c]||Array.isArray(t[c])&&0===t[c].length||null!==t[c]&&"object"==typeof t[c]&&0===Object.keys(t).length)&&(t[c]=null);for(var i,s,l=o(["onUpdateExecution","onUpdateExpression"]);!(i=l()).done;)if(s=i.value,Object.prototype.hasOwnProperty.call(e,s))try{t[c]=L(e[s],s.endsWith("Expression"),{checkPropertyContent:x,model:d,modelName:p,name:c,type:s,newDocument:t,oldDocument:r,newValue:t[c],oldValue:r&&r[c],parentNames:n,pathDescription:a,propertySpecification:e}).result}catch(i){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(i)&&u('Compilation: Hook "'+s+'" has invalid code "'+i.code+'" for property "'+c+'": '+i.message+a+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(i)&&u('Runtime: Hook "'+s+'" has throw an error with code "'+i.code+'" for property "'+c+'": '+i.message+a+"."),!Object.prototype.hasOwnProperty.call(i,"empty"))throw i}}},D=Object.keys(d).filter((function(e){return![m.additional,m.allowedRoles,m.constraint.execution,m.constraint.expression,m.create.execution,m.create.expression,m.extend,m.maximumAggregatedSize,m.minimumAggregatedSize,m.oldType,m.update.execution,m.update.expression].includes(e)}));if("migrate"===O)for(var j,M,A=o(D);!(j=A()).done;)if(M=j.value,![null,void 0].includes(d[M].oldName))for(var C,U,W=o([].concat(d[M].oldName));!(C=W()).done;)U=C.value,Object.prototype.hasOwnProperty.call(e,U)&&(e[M]=e[U],delete e[U]);if(!r)for(var B,K=0,q=[m.create.execution,m.create.expression];K<q.length;K++)if(B=q[K],Object.prototype.hasOwnProperty.call(d,B)){var z=void 0;try{z=L(d[B],B.endsWith("Expression"),{checkPropertyContent:x,model:d,modelName:p,type:B,newDocument:e,oldDocument:r,parentNames:n,pathDescription:a}).result}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&u('Compilation: Hook "'+B+'" has invalid code "'+e.code+'" for document "'+p+'": '+e.message+a+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&u('Runtime: Hook "'+B+'" has throw an error with code "'+e.code+'" for document "'+p+'": '+e.message+a+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}[null,void 0].includes(z)||(e=z),l(),p=e[h],0===n.length&&g()}for(var H,F=0,G=[m.update.execution,m.update.expression];F<G.length;F++)if(H=G[F],Object.prototype.hasOwnProperty.call(d,H)){var V=void 0;try{V=L(d[H],H.endsWith("Expression"),{checkPropertyContent:x,model:d,modelName:p,type:H,newDocument:e,oldDocument:r,parentNames:n,pathDescription:a}).result}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&u('Compilation: Hook "'+H+'" has invalid code "'+e.code+'" for document "'+p+'": '+e.message+a+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&u('Runtime: Hook "'+H+'" has throw an error with code "'+e.code+'" for document "'+p+'": '+e.message+a+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}[void 0,null].includes(V)||(e=V),l(),p=e[h],0===n.length&&g()}for(var J,$=function t(){var a=J.value;if(m.attachment===a)for(var i=function(){var i=l[s],u=i[0],p=i[1];Object.prototype.hasOwnProperty.call(e,a)&&null!==e[a]||(e[a]={}),r&&!Object.prototype.hasOwnProperty.call(r,a)&&(r[a]={});var d=Object.keys(e[a]).filter((function(t){return null!==e[a][t].data&&S(u,t,p)})),_=e[a],m=[];if(r){var f=r[a];m=Object.keys(f).filter((function(e){return!(Object.prototype.hasOwnProperty.call(_,e)&&Object.prototype.hasOwnProperty.call(_[e],"data")&&null===_[e].data)&&!!f[e]&&(Object.prototype.hasOwnProperty.call(f[e],"data")&&null!==f[e].data||f[e].stub&&!!f[e].digest)&&!!S(u,e,p)}))}for(var b,h,y=p,v=o(d);!(b=v()).done;)h=b.value,E(y,_,r&&r[a]?r[a]:null,h);for(var g,x,P=o(d);!(g=P()).done;)x=g.value,k(y,_,r&&r[a]?r[a]:null,x);if([null,void 0].includes(y.default)){if(y.nullable||0<d.length||0<m.length||t(),"fillUp"===O&&0===d.length&&0<m.length)for(var w,D,j=o(m);!(w=j()).done;)D=w.value,null===_[D]?c=n.concat(a,D,"file removed"):_[D]=r[a][D]}else if(0===d.length)if(0===m.length)for(var M in y.default)Object.prototype.hasOwnProperty.call(y.default,M)&&(_[M]=y.default[M],c=n.concat(a,u,"add default file"));else if("fillUp"===O)for(var A,C,T=o(m);!(A=T()).done;)C=A.value,_[C]=r[a][C]},s=0,l=Object.entries(d[a]);s<l.length;s++)i();else{var u=D.includes(a)?d[a]:y;E(u,e,r,a),k(u,e,r,a),[null,void 0].includes(u.default)?(!(u.nullable||Object.prototype.hasOwnProperty.call(e,a)||r&&Object.prototype.hasOwnProperty.call(r,a)&&O)&&t(),!Object.prototype.hasOwnProperty.call(e,a)&&r&&Object.prototype.hasOwnProperty.call(r,a)&&("fillUp"===O?e[a]=r[a]:!O&&(c=n.concat(a,"property removed")))):(!Object.prototype.hasOwnProperty.call(e,a)||null===e[a])&&(r&&Object.prototype.hasOwnProperty.call(r,a)?"fillUp"===O?e[a]=r[a]:"migrate"===O&&(e[a]=u.default,c=n.concat(a,"migrate default value")):(e[a]=u.default,c=c.concat(a,"add default value")))}},Y=o(D.concat(y?Object.keys(e).filter((function(e){return!D.includes(e)})):[]));!(J=Y()).done;)$();if(r&&"incremental"===O)for(var X=0,Z=Object.entries(e);X<Z.length;X++){var Q=Z[X],ee=Q[0],te=Q[1];!Object.prototype.hasOwnProperty.call(r,ee)||i.property.name.reserved.concat(f,b,m.conflict,m.deleted,m.deletedConflict,m.localSequence,m.revisions,m.revisionsInformation,h).includes(ee)||r[ee]!==te&&T(r[ee])!==T(te)||delete e[ee]}for(var re=0,ne=Object.entries(e);re<ne.length;re++){var ae=ne[re],oe=ae[0],ce=ae[1];if(!i.property.name.reserved.concat(b,m.conflict,m.deleted,m.deletedConflict,m.localSequence,m.revisions,m.revisionsInformation,m.strategy).includes(oe)){var ie=void 0;if(Object.prototype.hasOwnProperty.call(d,oe))ie=d[oe];else if(y)ie=y;else{if("migrate"===O){delete e[oe],c=n.concat(oe,"migrate removed property");continue}u('Property: Given property "'+oe+'" isn\'t specified in model "'+p+'"'+a+".")}if(!ie)continue;if(m.attachment===oe){var se=ce;for(var le in se)if(Object.prototype.hasOwnProperty.call(se,le))for(var ue in d[oe])if(S(ue,le,d[oe][ue])){w(d[oe][ue],e,r,le,a);break}continue}if(w(ie,e,r,oe,a))continue;if("string"==typeof ie.type&&ie.type.endsWith("[]")||Array.isArray(ie.type)&&ie.type.length&&Array.isArray(ie.type[0])){var pe,de=ce;Array.isArray(de)?![null,void 0].includes(ie.minimumNumber)&&de.length<ie.minimumNumber?u('MinimumArrayLength: Property "'+oe+'" (array of length '+de.length+") doesn't fullfill minimum array length of "+ie.minimumNumber+a+"."):![null,void 0].includes(ie.maximumNumber)&&ie.maximumNumber<de.length&&u('MaximumArrayLength: Property "'+oe+'" (array of length '+de.length+") doesn't fullfill maximum array length of "+ie.maximumNumber+a+"."):u('PropertyType: Property "'+oe+'" isn\'t of type "array -> '+ie.type+'" (given "'+T(de)+'")'+a+"."),v(de,oe,ie,r&&Object.prototype.hasOwnProperty.call(r,oe)&&r[oe]||void 0,["arrayConstraintExecution","arrayConstraintExpression"]);var _e={};for(var me in ie)Object.prototype.hasOwnProperty.call(ie,me)&&(_e[me]="type"===me?Array.isArray(ie[me])?ie[me][0]:[ie[me].substring(0,ie.type.length-2)]:ie[me]);if(1===(null==(pe=_e.type)?void 0:pe.length)&&Object.prototype.hasOwnProperty.call(s,_e.type[0]))for(var fe,be,he=o(de.slice());!(fe=he()).done;)"object"!=typeof(be=fe.value)||Object.getPrototypeOf(be)!==Object.prototype||Object.prototype.hasOwnProperty.call(be,h)||(be[h]=_e.type[0]);for(var ye,ve,ge=0,Oe=o(de.slice());!(ye=Oe()).done;)ve=ye.value,de[ge]=x(ve,ge+1+". value in "+oe,_e).newValue,null===ve&&de.splice(ge,1),ge+=1;r&&Object.prototype.hasOwnProperty.call(r,oe)&&Array.isArray(r[oe])&&r[oe].length===de.length&&T(r[oe])===T(de)||(c=n.concat(oe,"array updated"))}else{var xe=r&&Object.prototype.hasOwnProperty.call(r,oe)?r[oe]:null,Pe=x(ce,oe,ie,xe);e[oe]=Pe.newValue,Pe.changedPath.length&&(c=Pe.changedPath),null===e[oe]&&(null!==xe&&(c=n.concat(oe,"property removed")),delete e[oe])}}}for(var we,Ee=0,ke=Object.keys(m.constraint);Ee<ke.length;Ee++)if(we=ke[Ee],(we=m.constraint[we])&&Object.prototype.hasOwnProperty.call(d,we))for(var De,je=o([].concat(d[we]));!(De=je()).done;){var Me,Ae=De.value,Ce=void 0;try{Ce=L(Ae.evaluation,we===m.constraint.expression,{checkPropertyContent:x,model:d,modelName:p,type:we,newDocument:e,oldDocument:r,parentNames:n,pathDescription:a})}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&u('Compilation: Hook "'+we+'" has invalid code "'+e.code+'": "'+e.message+'"'+a+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&u('Runtime: Hook "'+we+'" has thrown an error with code "'+e.code+'": '+e.message+a+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}if(null==(Me=Ce)||!Me.result){var Te=we.replace(/^[^a-zA-Z]+/,"");u(Te.charAt(0).toUpperCase()+(Te.substring(1)+": ")+(Ae.description?t(Function,Object.keys(Ce.scope).concat(["return "+Ae.description.trim()])).apply(void 0,Object.values(Ce.scope)):'Model "'+p+'" should satisfy constraint "'+Ce.code+'" (given "'+T(e)+'")'+a+"."))}}if(Object.prototype.hasOwnProperty.call(e,m.attachment)){var Re=e[m.attachment];("object"!=typeof Re||Object.getPrototypeOf(Re)!==Object.prototype)&&u("AttachmentType: given attachment has invalid type"+a+".");var Ie=null;if(r&&Object.prototype.hasOwnProperty.call(r,m.attachment)&&null!==(Ie=r[m.attachment])&&"object"==typeof Ie)for(var Se=0,Ue=Object.entries(Ie);Se<Ue.length;Se++){var Le=Ue[Se],Ne=Le[0],We=Le[1];if(Object.prototype.hasOwnProperty.call(Re,Ne)){var Be=Re[Ne];null===Be||null===Be.data||Be.content_type===We.content_type&&(Be.data===We.data||Be.digest===We.digest)?((null===Be||null===Be.data)&&(c=n.concat(m.attachment,Ne,"attachment removed")),"incremental"===O&&delete Re[Ne]):c=n.concat(m.attachment,Ne,"attachment updated")}else"fillUp"===O?Re[Ne]=We:O||(c=n.concat(m.attachment,Ne,"attachment removed"))}for(var Ke=0,qe=Object.entries(Re);Ke<qe.length;Ke++){var ze=qe[Ke],He=ze[0],Fe=ze[1];[null,void 0].includes(Fe)||null===Fe.data?delete Re[He]:(!Ie||!Object.prototype.hasOwnProperty.call(Ie,He)||Fe.content_type!==Ie[He].content_type||Fe.data!==Ie[He].data&&Fe.digest!==Ie[He].digest)&&(c=n.concat(m.attachment,He,"attachment updated"))}0===Object.keys(Re).length&&delete e[m.attachment];for(var Ge={},Ve=0,Je=Object.keys(d[m.attachment]);Ve<Je.length;Ve++)Ge[Je[Ve]]=[];for(var $e=0,Ye=Object.keys(Re);$e<Ye.length;$e++){for(var Xe=Ye[$e],Ze=!1,Qe=0,et=Object.entries(d[m.attachment]);Qe<et.length;Qe++){var tt=et[Qe],rt=tt[0],nt=tt[1];if(S(rt,Xe,nt)){Ge[rt].push(Xe),Ze=!0;break}}Ze||u('AttachmentTypeMatch: None of the specified attachment types ("'+Object.keys(d[m.attachment]).join('", "')+'") matches given one ("'+Xe+'")'+a+".")}for(var at=0,ot=0,ct=Object.keys(Ge);ot<ct.length;ot++){var it=ct[ot],st=d[m.attachment][it];if(Object.prototype.hasOwnProperty.call(Ge,it)){var lt=Ge[it].length;null!==st.maximumNumber&&lt>st.maximumNumber&&u("AttachmentMaximum: given number of attachments ("+lt+") doesn't satisfy specified maximum of "+st.maximumNumber+' from type "'+it+'"'+a+"."),(!st.nullable||0!==lt)&&lt<st.minimumNumber&&u("AttachmentMinimum: given number of attachments ("+lt+") doesn't satisfy specified minimum of "+st.minimumNumber+' from type "'+it+'"'+a+".");for(var ut,pt=0,dt=o(Ge[it]);!(ut=dt()).done;){var _t,mt,ft=ut.value;null!=(_t=st.fileName)&&_t.regularExpressionPattern&&!new RegExp(st.fileName.regularExpressionPattern).test(ft)?u('AttachmentName: given attachment name "'+ft+'" doesn\'t satisfy specified regular expression pattern "'+st.fileName.regularExpressionPattern+'" from type "'+it+'"'+a+"."):null!=(mt=st.fileName)&&mt.invertedRegularExpressionPattern&&new RegExp(st.fileName.invertedRegularExpressionPattern).test(ft)?u('InvertedAttachmentName: given attachment name "'+ft+'" does satisfy specified regular expression pattern "'+st.fileName.invertedRegularExpressionPattern+'" from type "'+it+'"'+a+"."):!([null,void 0].includes(st.contentTypeRegularExpressionPattern)||Re[ft].content_type&&new RegExp(st.contentTypeRegularExpressionPattern).test(Re[ft].content_type))&&u('AttachmentContentType: given attachment content type "'+Re[ft].content_type+'" doesn\'t satisfy specified regular expression pattern "'+st.contentTypeRegularExpressionPattern+'" from type "'+it+'"'+a+".");var bt=st.invertedContentTypeRegularExpressionPattern;[null,void 0].includes(bt)||Re[ft].content_type&&!new RegExp(bt).test(Re[ft].content_type)||u('InvertedAttachmentContentType: given attachment content type "'+Re[ft].content_type+'" does satisfy specified regular expression pattern "'+bt+'" from type "'+it+'"'+a+".");var ht=0;"length"in Re[ft]?ht=Re[ft].length:"data"in Re[ft]&&(ht=Buffer&&"byteLength"in Buffer?Buffer.byteLength(Re[ft].data,"base64"):Re[ft].data.length),![null,void 0].includes(st.minimumSize)&&st.minimumSize>ht?u("AttachmentMinimumSize: given attachment size "+ht+" byte doesn't satisfy specified minimum of "+st.minimumSize+" byte "+a+"."):![null,void 0].includes(st.maximumSize)&&st.maximumSize<ht&&u("AttachmentMaximumSize: given attachment size "+ht+" byte doesn't satisfy specified maximum of "+st.maximumSize+" byte "+a+"."),pt+=ht}![null,void 0].includes(st.minimumAggregatedSize)&&st.minimumAggregatedSize>pt?u('AttachmentAggregatedMinimumSize: given aggregated size of attachments from type "'+it+'" '+pt+" byte doesn't satisfy specified minimum of "+st.minimumAggregatedSize+" byte "+a+"."):![null,void 0].includes(st.maximumAggregatedSize)&&st.maximumAggregatedSize<pt&&u('AttachmentAggregatedMaximumSize: given aggregated size of attachments from type "'+it+'" '+pt+" byte doesn't satisfy specified maximum of "+st.maximumAggregatedSize+" byte "+a+"."),at+=pt}}Object.prototype.hasOwnProperty.call(d,m.minimumAggregatedSize)&&![null,void 0].includes(d[m.minimumAggregatedSize])&&d[m.minimumAggregatedSize]>at?u("AggregatedMinimumSize: given aggregated size "+at+" byte doesn't satisfy specified minimum of "+d[m.minimumAggregatedSize]+" byte "+a+"."):![null,void 0].includes(d[m.maximumAggregatedSize])&&d[m.maximumAggregatedSize]<at&&u("AggregatedMaximumSize: given aggregated size "+at+" byte doesn't satisfy specified maximum of "+d[m.maximumAggregatedSize]+" byte "+a+".")}if(r&&Object.prototype.hasOwnProperty.call(r,m.attachment)&&0===Object.keys(r[m.attachment]).length&&delete r[m.attachment],0===c.length&&r&&"migrate"===O)for(var yt,vt=0,gt=Object.keys(r);vt<gt.length;vt++)yt=gt[vt],Object.prototype.hasOwnProperty.call(e,yt)||(c=n.concat(yt,"migrate removed property"));return{changedPath:c,newDocument:e}},W={attachmentWithPrefixExists:function(t){if(Object.prototype.hasOwnProperty.call(e,m.attachment)){var r=e[m.attachment],n=U(t);if(n)return Object.prototype.hasOwnProperty.call(r[n],"stub")&&r[n].stub||Object.prototype.hasOwnProperty.call(r[n],"data")&&![null,void 0].includes(r[n].data)}return!1},checkDocument:N,getFileNameByPrefix:U,serialize:T,id:y,revision:v,idName:f,revisionName:b,specialNames:m,typeName:h,modelConfiguration:i,models:s,now:p,nowUTCTimestamp:d,securitySettings:c,userContext:n},B=N(e,r);return(!B.newDocument._deleted||r)&&(B.newDocument._deleted&&B.newDocument._deleted!==(null==r?void 0:r._deleted)||B.changedPath.length)||u("NoChange: No new data given. new document: "+T(e)+"; old document: "+T(r)+"."),Object.prototype.hasOwnProperty.call(c,i.property.name.validatedDocumentsCache)?c[i.property.name.validatedDocumentsCache].add(y+"-"+v):c[i.property.name.validatedDocumentsCache]=new Set([y+"-"+v]),B.newDocument},e}(),u=l;e.exports=s}()}],__webpack_module_cache__={};function __webpack_require__(e){var t=__webpack_module_cache__[e];if(void 0!==t)return t.exports;var r=__webpack_module_cache__[e]={exports:{}};return __webpack_modules__[e](r,r.exports,__webpack_require__),r.exports}__webpack_require__.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return __webpack_require__.d(t,{a:t}),t},__webpack_require__.d=(e,t)=>{for(var r in t)__webpack_require__.o(t,r)&&!__webpack_require__.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},__webpack_require__.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),__webpack_require__.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var __webpack_exports__={};(()=>{"use strict";__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,{Database:()=>y,default:()=>v});var e=__webpack_require__(1),t=__webpack_require__.n(e),r=__webpack_require__(2),n=__webpack_require__.n(r),a=__webpack_require__(4),o=__webpack_require__.n(a),c=__webpack_require__(6),i=__webpack_require__(7),s=__webpack_require__.n(i);const l=require("pouchdb");var u=__webpack_require__.n(l);const p=require("pouchdb-find");var d=__webpack_require__.n(p),_=__webpack_require__(9),m=__webpack_require__.n(_),f=__webpack_require__(8);function b(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return h(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?h(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function h(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}var y=function(){function e(){}return e.loadService=function(){var e=t()(n().mark((function e(t,r,i){var l,u,p,d,_,h,y,v,g,O,x,P,w,E,k,D,j,M,A,C,T,R,I,S,U,L,N,W,B,K,q,z,H,F,G,V,J,$,Y,X,Z,Q,ee,te,re,ne,ae,oe,ce,ie,se,le,ue,pe,de,_e,me,fe,be,he,ye,ve,ge,Oe,xe,Pe,we,Ee,ke,De,je,Me,Ae,Ce,Te,Re,Ie,Se,Ue,Le,Ne,We,Be,Ke,qe,ze,He,Fe,Ge,Ve,Je;return n().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(l=null,!Object.prototype.hasOwnProperty.call(r.couchdb.server,"runner")){e.next=8;break}return e.next=4,f.default.startServer(r,i);case 4:r.couchdb.server.restart=f.default.restartServer,r.couchdb.server.start=f.default.startServer,r.couchdb.server.stop=f.default.stopServer,l=new Promise((function(e,t){r.couchdb.server.resolve=e,r.couchdb.server.reject=t}));case 8:if(!Object.prototype.hasOwnProperty.call(r.couchdb,"connection")){e.next=10;break}return e.abrupt("return",{name:"couchdb",promise:l});case 10:if(u=o().stringFormat(i.couchdb.url,i.couchdb.user.name+":"+i.couchdb.user.password+"@"),!i.couchdb.ensureAdminPresence){e.next=42;break}return p=new r.couchdb.connector(o().stringFormat(i.couchdb.url,"")+"/_users",f.default.getConnectorOptions(i)),e.prev=13,e.next=16,p.allDocs();case 16:return e.next=19,a.globalContext.fetch(o().stringFormat(i.couchdb.url,"")+"/"+r.couchdb.server.runner.adminUserConfigurationPath+"/"+i.couchdb.user.name,{body:'"'+i.couchdb.user.password+'"',method:"PUT"});case 19:e.next=39;break;case 21:if(e.prev=21,e.t0=e.catch(13),"unauthorized"!==e.t0.name){e.next=38;break}return d=new r.couchdb.connector(u+"/_users",f.default.getConnectorOptions(i)),e.prev=25,e.next=28,d.allDocs();case 28:e.next=33;break;case 30:e.prev=30,e.t1=e.catch(25);case 33:return e.prev=33,d.close(),e.finish(33);case 36:e.next=39;break;case 38:case 39:return e.prev=39,p.close(),e.finish(39);case 42:if(!i.couchdb.ensureUserPresence){e.next=77;break}_=0,h=[i.couchdb.security.admins,i.couchdb.security.members];case 44:if(!(_<h.length)){e.next=77;break}y=h[_],v=b(y.names);case 47:if((g=v()).done){e.next=74;break}return O=g.value,x=new r.couchdb.connector(u+"/_users",f.default.getConnectorOptions(i)),e.prev=50,e.next=53,x.get("org.couchdb.user:"+O);case 53:e.next=69;break;case 55:if(e.prev=55,e.t2=e.catch(50),"not_found"!==e.t2.error){e.next=68;break}return e.prev=58,e.next=61,x.put(((P={})[i.couchdb.model.property.name.special.id]="org.couchdb.user:"+O,P.name=O,P.password=O,P.roles=[].concat(y.roles.includes(O+"s")?O+"s":[]),P.type="user",P));case 61:e.next=66;break;case 63:throw e.prev=63,e.t3=e.catch(58),new Error("Couldn't create missing user \""+O+'": '+o().represent(e.t3));case 66:e.next=69;break;case 68:throw new Error("Couldn't check for presence of user \""+O+'": '+o().represent(e.t2));case 69:return e.prev=69,x.close(),e.finish(69);case 72:e.next=47;break;case 74:_++,e.next=44;break;case 77:if(!i.couchdb.model.updateConfiguration){e.next=132;break}w=b(i.couchdb.backend.prefixes);case 79:if((E=w()).done){e.next=132;break}k=E.value,e.t4=n().keys(i.couchdb.backend.configuration);case 82:if((e.t5=e.t4()).done){e.next=130;break}if(D=e.t5.value,!Object.prototype.hasOwnProperty.call(i.couchdb.backend.configuration,D)){e.next=128;break}return j="/"+k+(k.trim()?"/":"")+D,M=""+u+j,A=i.couchdb.backend.configuration[D],C=void 0,e.prev=89,e.next=92,a.globalContext.fetch(M);case 92:C=e.sent,e.next=98;break;case 95:e.prev=95,e.t6=e.catch(89);case 98:if(!C){e.next=128;break}if(!C.ok){e.next=127;break}if(T=!0,"function"!=typeof C.text){e.next=113;break}return e.prev=102,e.t7=A,e.next=106,C["string"==typeof A?"text":"json"]();case 106:e.t8=e.sent,T=e.t7===e.t8,e.next=113;break;case 110:e.prev=110,e.t9=e.catch(102);case 113:if(!T){e.next=124;break}return e.prev=114,e.next=117,a.globalContext.fetch(M,{body:'"'+i.couchdb.backend.configuration[D]+'"',method:"PUT"});case 117:e.next=122;break;case 119:e.prev=119,e.t10=e.catch(114);case 122:e.next=125;break;case 124:case 125:e.next=128;break;case 127:case 128:e.next=82;break;case 130:e.next=79;break;case 132:return e.next=134,f.default.initializeConnection(r,i);case 134:if(R=i.couchdb.model.property.name.special.id,I=i.couchdb.model.property.name.special.type,!i.couchdb.ensureSecuritySettingsPresence){e.next=145;break}return e.prev=137,e.next=140,a.globalContext.fetch(u+"/"+i.couchdb.databaseName+"/_security",{body:JSON.stringify(i.couchdb.security),method:"PUT"});case 140:e.next=145;break;case 142:e.prev=142,e.t11=e.catch(137);case 145:if(delete(S=o().copy(i.couchdb.model)).property.defaultSpecification,delete S.entities,U=f.default.extendModels(i.couchdb.model),!i.couchdb.model.updateValidation){e.next=213;break}return e.next=152,c.promises.readFile(a.currentRequire.resolve("./databaseHelper"),{encoding:i.core.encoding,flag:"r"});case 152:L=e.sent,N=b([{description:"Model specification",methodName:"validateDocumentUpdate",name:"validation",serializedParameter:JSON.stringify(S)+", "+JSON.stringify(U)},{description:"Authorisation",methodName:"authenticate",name:"authentication",serializedParameter:JSON.stringify(f.default.determineAllowedModelRolesMapping(i.couchdb.model))+", '"+R+"', '"+I+"', '"+i.couchdb.model.property.name.special.designDocumentNamePrefix+"'"}]);case 154:if((W=N()).done){e.next=169;break}B=W.value,K="function(...parameters) {\n return require('helper').default."+B.methodName+"(...parameters.concat(["+B.serializedParameter+"]))\n}",e.prev=157,new Function("return "+K),e.next=164;break;case 161:throw e.prev=161,e.t12=e.catch(157),new Error("Generated "+B.name+' code "'+K+"\" doesn't compile: "+o().represent(e.t12));case 164:return i.core.debug,e.next=167,f.default.ensureValidationDocumentPresence(r.couchdb.connection,B.name,{helper:L,validate_doc_update:K},B.description,!0,R,S.property.name.special.designDocumentNamePrefix);case 167:e.next=154;break;case 169:q=0,z=Object.entries(U);case 170:if(!(q<z.length)){e.next=213;break}H=z[q],F=H[0],G=H[1],V=0,J=Object.entries(G);case 173:if(!(V<J.length)){e.next=210;break}if($=J[V],Y=$[0],X=$[1],![S.property.name.special.constraint.execution,S.property.name.special.constraint.expression].includes(Y)){e.next=191;break}Z=b([].concat(X));case 177:if((Q=Z()).done){e.next=189;break}if(!(ee=Q.value).description){e.next=187;break}e.prev=180,new Function("return "+ee.description),e.next=187;break;case 184:throw e.prev=184,e.t13=e.catch(180),new Error('Specified constraint description "'+ee.description+'" for model "'+F+'" doesn\'t compile: "'+o().represent(e.t13)+'".');case 187:e.next=177;break;case 189:e.next=207;break;case 191:te=X,re=b(["conflictingConstraintExpression","conflictingConstraintExecution","constraintExpression","constraintExecution"]);case 193:if((ne=re()).done){e.next=207;break}if(ae=ne.value,null===te||"object"!=typeof te){e.next=205;break}if(null==(oe=te[ae])||!oe.description){e.next=205;break}e.prev=198,new Function(oe.description),e.next=205;break;case 202:throw e.prev=202,e.t14=e.catch(198),new Error('Specified constraint description "'+oe.description+'" for model "'+F+'" in property "'+Y+'" as "'+ae+'" doesn\'t compile: "'+o().represent(e.t14)+'".');case 205:e.next=193;break;case 207:V++,e.next=173;break;case 210:q++,e.next=170;break;case 213:if(!i.couchdb.model.autoMigrationPath){e.next=305;break}return ce={},e.next=217,o().isDirectory(s().resolve(i.couchdb.model.autoMigrationPath));case 217:if(!e.sent){e.next=257;break}return e.t15=b,e.next=221,o().walkDirectoryRecursively(s().resolve(i.couchdb.model.autoMigrationPath),i.couchdb.debug?o().noop:function(e){return"debug"!==e.name});case 221:e.t16=e.sent,ie=(0,e.t15)(e.t16);case 223:if((se=ie()).done){e.next=257;break}if(le=se.value,ue=s().extname(le.name),pe=s().basename(le.name,ue),".json"!==ue){e.next=254;break}return de=void 0,e.prev=229,e.t17=JSON,e.next=233,c.promises.readFile(le.path,{encoding:i.core.encoding,flag:"r"});case 233:e.t18=e.sent,de=e.t17.parse.call(e.t17,e.t18),e.next=240;break;case 237:throw e.prev=237,e.t19=e.catch(229),new Error('Parsing document "'+le.path+'" to include by automigration of has failed: '+o().represent(e.t19));case 240:return de[R]=pe,de[i.couchdb.model.property.name.special.revision]="upsert",e.prev=242,e.next=245,r.couchdb.connection.put(de);case 245:e.next=251;break;case 247:throw e.prev=247,e.t20=e.catch(242),null!=(_e=e.t20.forbidden)&&_e.startsWith("NoChange:"),new Error('Migrating document "'+de[R]+'" of type "'+de[I]+'" has failed: '+o().represent(e.t20));case 251:e.next=255;break;case 254:".js"===s().extname(le.name)&&(ce[le.path]=(0,a.currentRequire)(le.path).default);case 255:e.next=223;break;case 257:return e.t21=b,e.next=260,r.couchdb.connection.allDocs({include_docs:!0});case 260:e.t22=e.sent.rows,me=(0,e.t21)(e.t22);case 262:if((fe=me()).done){e.next=305;break}if("string"==typeof(be=fe.value).id&&be.id.startsWith(i.couchdb.model.property.name.special.designDocumentNamePrefix)){e.next=303;break}he=be.doc,(ye=o().copy(he))[i.couchdb.model.property.name.special.strategy]="migrate",ve=b(Object.keys(ce).sort());case 269:if((ge=ve()).done){e.next=282;break}Oe=ge.value,xe=null,e.prev=272,xe=ce[Oe](ye,{configuration:i,databaseHelper:m(),idName:R,migrater:ce,models:U,modelConfiguration:S,selfFilePath:Oe,services:r,tools:o(),typeName:I}),e.next=279;break;case 276:throw e.prev=276,e.t23=e.catch(272),new Error('Running migrater "'+Oe+'" in document '+f.default.mayStripRepresentation(he,i.couchdb.maximumRepresentationTryLength,i.couchdb.maximumRepresentationLength)+'" failed: '+o().represent(e.t23));case 279:xe&&(ye=xe);case 280:e.next=269;break;case 282:e.prev=282,m().validateDocumentUpdate(o().copy(ye),o().copy(he),{db:i.couchdb.databaseName,name:i.couchdb.user.name,roles:["_admin"]},o().copy(i.couchdb.security),S,U),e.next=294;break;case 286:if(e.prev=286,e.t24=e.catch(282),!Object.prototype.hasOwnProperty.call(e.t24,"forbidden")){e.next=293;break}return e.t24.forbidden.startsWith("NoChange:"),e.abrupt("continue",303);case 293:throw e.t24;case 294:return e.prev=294,e.next=297,r.couchdb.connection.put(ye);case 297:e.next=302;break;case 299:throw e.prev=299,e.t25=e.catch(294),new Error('Replaceing auto migrated document "'+ye[R]+'" has failed: '+o().represent(e.t25));case 302:case 303:e.next=262;break;case 305:if(!i.couchdb.createGenericFlatIndex||!i.couchdb.model.autoMigrationPath){e.next=360;break}return e.next=308,r.couchdb.connection.getIndexes();case 308:Pe=e.sent.indexes,we=0,Ee=Object.entries(U);case 310:if(!(we<Ee.length)){e.next=341;break}if(ke=Ee[we],De=ke[0],je=ke[1],!new RegExp(i.couchdb.model.property.name.typeRegularExpressionPattern.public).test(De)){e.next=338;break}return e.next=315,r.couchdb.connection.createIndex({index:{ddoc:De+"-GenericIndex",fields:[I],name:De+"-GenericIndex"}});case 315:Me=b(f.default.determineGenericIndexablePropertyNames(i.couchdb.model,je));case 316:if((Ae=Me()).done){e.next=338;break}Ce=Ae.value,Te=De+"-"+Ce+"-GenericIndex",Re=-1,Ie=0,Se=b(Pe);case 322:if((Ue=Se()).done){e.next=330;break}if(Ue.value.name!==Te){e.next=327;break}return Re=Ie,e.abrupt("break",330);case 327:Ie+=1;case 328:e.next=322;break;case 330:if(-1!==Re){e.next=335;break}return e.next=333,r.couchdb.connection.createIndex({index:{ddoc:Te,fields:[I,Ce],name:Te}});case 333:e.next=336;break;case 335:Pe.slice(Ie,1);case 336:e.next=316;break;case 338:we++,e.next=310;break;case 341:Le=b(Pe);case 342:if((Ne=Le()).done){e.next=360;break}if(!(We=Ne.value).name.endsWith("-GenericIndex")){e.next=358;break}Be=!1,Ke=0,qe=Object.entries(U);case 347:if(!(Ke<qe.length)){e.next=355;break}if(ze=qe[Ke],He=ze[0],Fe=ze[1],!We.name.startsWith(He+"-")){e.next=352;break}for(Ge=b(f.default.determineGenericIndexablePropertyNames(i.couchdb.model,Fe));!(Ve=Ge()).done;)Je=Ve.value,[He+"-"+Je+"-GenericIndex",He+"-GenericIndex"].includes(We.name)&&(Be=!0);return e.abrupt("break",355);case 352:Ke++,e.next=347;break;case 355:if(Be){e.next=358;break}return e.next=358,r.couchdb.connection.deleteIndex(We);case 358:e.next=342;break;case 360:if(!i.couchdb.model.triggerInitialCompaction){e.next=369;break}return e.prev=361,e.next=364,r.couchdb.connection.compact();case 364:e.next=369;break;case 366:e.prev=366,e.t26=e.catch(361);case 369:return e.abrupt("return",{name:"couchdb",promise:l});case 370:case"end":return e.stop()}}),e,null,[[13,21,39,42],[25,30,33,36],[50,55,69,72],[58,63],[89,95],[102,110],[114,119],[137,142],[157,161],[180,184],[198,202],[229,237],[242,247],[272,276],[282,286],[294,299],[361,366]])})));return function(){return e.apply(this,arguments)}}(),e.postLoadService=function(r,a,c,i,s){var l=0;setInterval((function(){0<l&&(l=0)}),3e4);var u=o().debounce(t()(n().mark((function r(){return n().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return e.changesStream&&e.changesStream.cancel(),e.changesStream=a.couchdb.connection.changes(o().extend(!0,o().copy(c.couchdb.changesStream),e.additionalChangesStreamOptions)),e.changesStream.on("error",t()(n().mark((function t(){return n().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!(3<(l+=1))){t.next=9;break}return l=0,e.changesStream.cancel(),t.next=7,a.couchdb.server.restart(a,c,i,s);case 7:t.next=10;break;case 9:case 10:u();case 11:case"end":return t.stop()}}),t)})))),r.next=5,s.callStack("couchdbInitializeChangesStream",i,c,e.changesStream,a);case 5:case"end":return r.stop()}}),r)}))));return c.couchdb.attachAutoRestarter&&u(),r},e.preLoadService=function(){var r=t()(n().mark((function r(a,c){var i,l,p,_,m,f,h,y,v,g,O,x,P,w;return n().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(Object.prototype.hasOwnProperty.call(a,"couchdb")||(a.couchdb={}),Object.prototype.hasOwnProperty.call(a.couchdb,"connector")||(i=c.couchdb.model.property.name.special.id,l=c.couchdb.model.property.name.special.revision,a.couchdb.connector=u(),p=a.couchdb.connector.prototype.bulkDocs.bind(a.couchdb.connection),a.couchdb.connector.plugin({bulkDocs:function(){var r=t()(n().mark((function t(r){var a,o,s,u,d,_,m,f,h,y,v,g,O,x,P,w,E,k,D=arguments;return n().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:for(o=D.length,s=Array(1<o?o-1:0),u=1;u<o;u++)s[u-1]=D[u];return d=0<s.length&&s[s.length-1]===e.toggleIDDetermining,_=d?!e.skipIDDetermining:e.skipIDDetermining,d&&s.pop(),m=!Array.isArray(r)&&null!==r&&"object"==typeof r&&i in r?[r]:r,null!=(a=c.couchdb.connector.fetch)&&a.timeout&&(0===s.length||"object"!=typeof s[0])&&s.unshift({timeout:c.couchdb.connector.fetch.timeout}),t.next=8,p.call.apply(p,[this,m].concat(s));case 8:f=t.sent,h=[],y=[],v=0,g=b(f);case 13:if((O=g()).done){t.next=36;break}if(x=O.value,"object"!=typeof m[v]){t.next=33;break}if(!(l in m[v])||"conflict"!==x.name||!["latest","upsert"].includes(m[v][l])){t.next=21;break}y.push(m[v]),h.push(v),t.next=33;break;case 21:if(!(i in m[v]&&c.couchdb.ignoreNoChangeError&&"name"in x&&"forbidden"===x.name&&"message"in x&&x.message.startsWith("NoChange:"))){t.next=33;break}if(f[v]={id:m[v][i],ok:!0},_){t.next=33;break}if(!(l in m[v])||["latest","upsert"].includes(m[v][l])){t.next=28;break}t.t0=m[v][l],t.next=32;break;case 28:return t.next=30,this.get(f[v].id);case 30:t.t1=l,t.t0=t.sent[t.t1];case 32:f[v].rev=t.t0;case 33:v+=1;case 34:t.next=13;break;case 36:if(!y.length){t.next=43;break}return m=y,d&&s.push(e.toggleIDDetermining),t.next=41,this.bulkDocs.apply(this,[m].concat(s));case 41:for(P=t.sent,w=b(P);!(E=w()).done;)k=E.value,f[h.shift()]=k;case 43:return t.abrupt("return",f);case 44:case"end":return t.stop()}}),t,this)})));return function(){return r.apply(this,arguments)}}()}),c.couchdb.debug&&a.couchdb.connector.debug.enable("*"),a.couchdb.connector=a.couchdb.connector.plugin(d())),Object.prototype.hasOwnProperty.call(a.couchdb,"server")){r.next=34;break}a.couchdb.server={},_=[],m=b([].concat(c.couchdb.binary.runner));case 6:if((f=m()).done){r.next=32;break}h=f.value,y=b([].concat(h.location));case 9:if((v=y()).done){r.next=28;break}g=v.value,O=b([].concat(h.name));case 12:if((x=O()).done){r.next=24;break}return P=x.value,w=s().resolve(g,P),_.push(w),r.next=18,o().isFile(w);case 18:if(!r.sent){r.next=22;break}return h.binaryFilePath=w,a.couchdb.server.runner=h,r.abrupt("break",24);case 22:r.next=12;break;case 24:if(!Object.prototype.hasOwnProperty.call(a.couchdb.server,"runner")){r.next=26;break}return r.abrupt("break",28);case 26:r.next=9;break;case 28:if(!Object.prototype.hasOwnProperty.call(a.couchdb.server,"runner")){r.next=30;break}return r.abrupt("break",32);case 30:r.next=6;break;case 32:if(Object.prototype.hasOwnProperty.call(a.couchdb.server,"runner")){r.next=34;break}throw new Error('No binary file in one of the following locations found: "'+_.join('", "')+'".');case 34:return r.abrupt("return",a);case 35:case"end":return r.stop()}}),r)})));return function(){return r.apply(this,arguments)}}(),e.shouldExit=function(){var e=t()(n().mark((function e(t,r){var a;return n().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,f.default.stopServer(t,r);case 2:return delete t.couchdb,a="log.txt",e.next=6,o().isFile(a);case 6:if(!e.sent){e.next=9;break}return e.next=9,c.promises.unlink(a);case 9:return e.abrupt("return",t);case 10:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),e}();y.additionalChangesStreamOptions={},y.changesStream=void 0,y.skipIDDetermining=!0,y.toggleIDDetermining=Symbol("toggleIDDetermining");const v=y})(),module.exports=__webpack_exports__})();
1
+ (()=>{var __webpack_modules__=[e=>{"use strict";e.exports=require("@babel/runtime/helpers/extends")},e=>{"use strict";e.exports=require("@babel/runtime/helpers/asyncToGenerator")},e=>{"use strict";e.exports=require("@babel/runtime/regenerator")},e=>{"use strict";e.exports=require("child_process")},e=>{"use strict";e.exports=require("clientnode")},e=>{"use strict";e.exports=require("pouchdb/node_modules/node-fetch/lib/index.js")},e=>{"use strict";e.exports=require("fs")},e=>{"use strict";e.exports=require("path")},(__unused_webpack_module,__webpack_exports__,__webpack_require__)=>{"use strict";__webpack_require__.d(__webpack_exports__,{default:()=>__WEBPACK_DEFAULT_EXPORT__});var _babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__(0),_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default=__webpack_require__.n(_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__),_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1__=__webpack_require__(1),_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default=__webpack_require__.n(_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1__),_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2__=__webpack_require__(2),_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default=__webpack_require__.n(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2__),child_process__WEBPACK_IMPORTED_MODULE_3__=__webpack_require__(3),child_process__WEBPACK_IMPORTED_MODULE_3___default=__webpack_require__.n(child_process__WEBPACK_IMPORTED_MODULE_3__),clientnode__WEBPACK_IMPORTED_MODULE_4__=__webpack_require__(4),clientnode__WEBPACK_IMPORTED_MODULE_4___default=__webpack_require__.n(clientnode__WEBPACK_IMPORTED_MODULE_4__),node_fetch__WEBPACK_IMPORTED_MODULE_5__=__webpack_require__(5),node_fetch__WEBPACK_IMPORTED_MODULE_5___default=__webpack_require__.n(node_fetch__WEBPACK_IMPORTED_MODULE_5__),fs__WEBPACK_IMPORTED_MODULE_6__=__webpack_require__(6),fs__WEBPACK_IMPORTED_MODULE_6___default=__webpack_require__.n(fs__WEBPACK_IMPORTED_MODULE_6__),path__WEBPACK_IMPORTED_MODULE_7__=__webpack_require__(7),path__WEBPACK_IMPORTED_MODULE_7___default=__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_7__);function _createForOfIteratorHelperLoose(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=_unsupportedIterableToArray(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(e,t){if(e){if("string"==typeof e)return _arrayLikeToArray(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?_arrayLikeToArray(e,t):void 0}}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}clientnode__WEBPACK_IMPORTED_MODULE_4__.globalContext.fetch=node_fetch__WEBPACK_IMPORTED_MODULE_5___default();var Helper=function(){function Helper(){}return Helper.getConnectorOptions=function(e){return e.couchdb.connector.fetch?{fetch:function(t,r){return clientnode__WEBPACK_IMPORTED_MODULE_4__.globalContext.fetch(t,clientnode__WEBPACK_IMPORTED_MODULE_4___default().extend(!0,clientnode__WEBPACK_IMPORTED_MODULE_4___default().copy(e.couchdb.connector.fetch),r||{}))}}:{fetch:function(e,t){return clientnode__WEBPACK_IMPORTED_MODULE_4__.globalContext.fetch(e,t)}}},Helper.mayStripRepresentation=function(e,t,r){var n=clientnode__WEBPACK_IMPORTED_MODULE_4___default().represent(e);return n.length<=t?n.length>r?n.substring(0,r-3)+"...":n:"DOCUMENT IS TOO BIG TO REPRESENT"},Helper.ensureValidationDocumentPresence=function(){var e=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function e(t,r,n,a,o,c,i){var s,l,u;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return void 0===o&&(o=!0),void 0===c&&(c="_id"),void 0===i&&(i="_design/"),l=_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()(((s={})[c]=""+i+r,s.language="javascript",s),n),e.prev=4,e.next=7,t.get(""+i+r);case 7:return u=e.sent,l._rev=u._rev,e.next=11,t.put(l);case 11:case 20:e.next=26;break;case 14:return e.prev=14,e.t0=e.catch(4),o&&e.t0.error,e.prev=17,e.next=20,t.put(l);case 23:throw e.prev=23,e.t1=e.catch(17),new Error(a+" couldn't be installed/updated: \""+clientnode__WEBPACK_IMPORTED_MODULE_4___default().represent(e.t1)+'".');case 26:case"end":return e.stop()}}),e,null,[[4,14],[17,23]])})));return function(){return e.apply(this,arguments)}}(),Helper.initializeConnection=function(){var e=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function e(t,r){var n,a,o,c,i,s;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(n=clientnode__WEBPACK_IMPORTED_MODULE_4___default().stringFormat(r.couchdb.url,r.couchdb.user.name+":"+r.couchdb.user.password+"@")+"/"+r.couchdb.databaseName,t.couchdb.connection=new t.couchdb.connector(n,Helper.getConnectorOptions(r)),t.couchdb.connection.setMaxListeners(1/0),a=r.couchdb.model.property.name.special.id,o=r.couchdb.model.property.name.special.revision,c=function(){var e=s.value,n=t.couchdb.connection[e].bind(t.couchdb.connection);t.couchdb.connection[e]=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function e(t){var c,i,s,l,u,p=arguments;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(e.prev=0,c=p.length,i=Array(1<c?c-1:0),s=1;s<c;s++)i[s-1]=p[s];return e.next=4,n.apply(void 0,[t].concat(i));case 4:return e.abrupt("return",e.sent);case 7:if(e.prev=7,e.t0=e.catch(0),!(a in t&&r.couchdb.ignoreNoChangeError&&"forbidden"===e.t0.name&&null!=(l=e.t0.message)&&l.startsWith("NoChange:"))){e.next=21;break}if(u={id:t[a],ok:!0},!(o in t)||["latest","upsert"].includes(t[o])){e.next=15;break}e.t1=t[o],e.next=19;break;case 15:return e.next=17,this.get(u.id);case 17:e.t2=o,e.t1=e.sent[e.t2];case 19:return u.rev=e.t1,e.abrupt("return",u);case 21:throw e.t0;case 22:case"end":return e.stop()}}),e,this,[[0,7]])})))},i=_createForOfIteratorHelperLoose(["post","put"]);!(s=i()).done;)c();return e.prev=7,e.next=10,clientnode__WEBPACK_IMPORTED_MODULE_4___default().checkReachability(n);case 10:e.next=17;break;case 12:return e.prev=12,e.t0=e.catch(7),e.next=17,clientnode__WEBPACK_IMPORTED_MODULE_4__.globalContext.fetch(n,{method:"PUT"});case 17:return e.abrupt("return",t);case 18:case"end":return e.stop()}}),e,null,[[7,12]])})));return function(){return e.apply(this,arguments)}}(),Helper.startServer=function(){function startServer(){return _startServer.apply(this,arguments)}var _startServer=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function _callee4(services,configuration){var _this=this;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(_context4){for(;;)switch(_context4.prev=_context4.next){case 0:if(!Object.prototype.hasOwnProperty.call(services.couchdb.server.runner,"configurationFile")){_context4.next=12;break}return _context4.prev=1,_context4.next=4,fs__WEBPACK_IMPORTED_MODULE_6__.promises.mkdir(path__WEBPACK_IMPORTED_MODULE_7___default().dirname(services.couchdb.server.runner.configurationFile.path),{recursive:!0});case 4:_context4.next=10;break;case 6:if(_context4.prev=6,_context4.t0=_context4.catch(1),"EEXIST"===_context4.t0.code){_context4.next=10;break}throw _context4.t0;case 10:return _context4.next=12,fs__WEBPACK_IMPORTED_MODULE_6__.promises.writeFile(services.couchdb.server.runner.configurationFile.path,services.couchdb.server.runner.configurationFile.content,{encoding:configuration.core.encoding});case 12:return services.couchdb.server.process=(0,child_process__WEBPACK_IMPORTED_MODULE_3__.spawn)("default"===configuration.couchdb.binary.memoryInMegaByte?services.couchdb.server.runner.binaryFilePath:configuration.couchdb.binary.nodePath,("default"===configuration.couchdb.binary.memoryInMegaByte?[]:["--max-old-space-size="+configuration.couchdb.binary.memoryInMegaByte,services.couchdb.server.runner.binaryFilePath]).concat(services.couchdb.server.runner.arguments?services.couchdb.server.runner.arguments:[]),{cwd:eval("process").cwd(),env:Object.prototype.hasOwnProperty.call(services.couchdb.server.runner,"environment")?_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({},eval("process").env,services.couchdb.server.runner.environment):eval("process").env,shell:!0,stdio:"inherit"}),new Promise((function(e,t){for(var r,n,a=_createForOfIteratorHelperLoose(clientnode__WEBPACK_IMPORTED_MODULE_4__.CloseEventNames);!(r=a()).done;)n=r.value,services.couchdb.server.process.on(n,clientnode__WEBPACK_IMPORTED_MODULE_4___default().getProcessCloseHandler(e,t,{process:services.couchdb.server.process,reason:n}))})).then((function(e){var t,r;null!=(t=services.couchdb)&&null!=(r=t.server)&&r.resolve&&services.couchdb.server.resolve.call(_this,e)}),(function(e){var t,r;null!=(t=services.couchdb)&&null!=(r=t.server)&&r.resolve&&services.couchdb.server.reject.call(_this,e)})),_context4.next=16,clientnode__WEBPACK_IMPORTED_MODULE_4___default().checkReachability(clientnode__WEBPACK_IMPORTED_MODULE_4___default().stringFormat(configuration.couchdb.url,""),{wait:!0});case 16:case"end":return _context4.stop()}}),_callee4,null,[[1,6]])})));return startServer}(),Helper.restartServer=function(){var e=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function e(t){var r,n,a,o,c,i;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.configuration,n=t.pluginAPI,a=t.services,o=a.couchdb.server,c=o.resolve,i=o.reject,o.resolve=o.reject=clientnode__WEBPACK_IMPORTED_MODULE_4___default().noop,e.next=7,Helper.stopServer(a,r);case 7:return o.resolve=c,o.reject=i,e.next=11,Helper.startServer(a,r);case 11:return Helper.initializeConnection(a,r),e.next=14,n.callStack(_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({},t,{hook:"restartCouchdb"}));case 14:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),Helper.stopServer=function(){var e=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function e(t,r){var n,a;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.couchdb,a=r.couchdb,n.connection&&n.connection.close(),n.server.process&&n.server.process.kill("SIGINT"),e.next=6,clientnode__WEBPACK_IMPORTED_MODULE_4___default().checkUnreachability(clientnode__WEBPACK_IMPORTED_MODULE_4___default().stringFormat(a.url,""),{wait:!0});case 6:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),Helper.determineAllowedModelRolesMapping=function(e){for(var t=e.property.name.special.allowedRoles,r={},n=Helper.extendModels(e),a=0,o=Object.entries(n);a<o.length;a++){var c=o[a],i=c[0],s=c[1];if(Object.prototype.hasOwnProperty.call(s,t)){r[i]=_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({properties:{}},Helper.normalizeAllowedRoles(s[t]));for(var l=0,u=Object.entries(s);l<u.length;l++){var p=u[l],_=p[0],d=p[1];null!==d&&"object"==typeof d&&d.allowedRoles&&(r[i].properties[_]=Helper.normalizeAllowedRoles(d.allowedRoles))}}else r[i]={properties:{},read:[],write:[]}}return r},Helper.determineGenericIndexablePropertyNames=function(e,t){var r=e.property.name.special;return Object.keys(t).filter((function(n){return null!==t[n]&&"object"==typeof t[n]&&(Object.prototype.hasOwnProperty.call(t[n],"index")&&t[n].index||!(Object.prototype.hasOwnProperty.call(t[n],"index")&&!t[n].index||e.property.name.reserved.concat(r.additional,r.allowedRoles,r.attachment,r.conflict,r.constraint.execution,r.constraint.expression,r.deleted,r.deletedConflict,r.extend,r.id,r.maximumAggregatedSize,r.minimumAggregatedSize,r.oldType,r.revision,r.revisions,r.revisionsInformation,r.type).includes(n)||t[n].type&&("string"==typeof t[n].type&&t[n].type.endsWith("[]")||Array.isArray(t[n].type)&&t[n].type.length&&Array.isArray(t[n].type[0])||Object.prototype.hasOwnProperty.call(e.entities,t[n].type))))})).concat(r.id,r.revision).sort()},Helper.extendModel=function(e,t,r){if(void 0===r&&(r="_extends"),"_base"===e)return t[e];if(Object.prototype.hasOwnProperty.call(t,"_base")&&(Object.prototype.hasOwnProperty.call(t[e],r)&&t[e][r]?t[e][r]=["_base"].concat(t[e][r]):t[e][r]="_base"),Object.prototype.hasOwnProperty.call(t[e],r)){for(var n,a,o=_createForOfIteratorHelperLoose([].concat(t[e][r]));!(n=o()).done;)a=n.value,t[e]=clientnode__WEBPACK_IMPORTED_MODULE_4___default().extend(!0,clientnode__WEBPACK_IMPORTED_MODULE_4___default().copy(Helper.extendModel(a,t,r)),t[e]);delete t[e][r]}return t[e]},Helper.extendModels=function(e){for(var t,r=e.property.name.special,n={},a=0,o=Object.keys(e.entities);a<o.length;a++){if(t=o[a],!new RegExp(e.property.name.typeRegularExpressionPattern.public).test(t)&&!new RegExp(e.property.name.typeRegularExpressionPattern.private).test(t))throw new Error('Model names have to match "'+e.property.name.typeRegularExpressionPattern.public+'" or "'+e.property.name.typeRegularExpressionPattern.private+'" for private one (given name: "'+t+'").');n[t]=Helper.extendModel(t,e.entities,r.extend)}for(var c,i=0,s=Object.values(n);i<s.length;i++){c=s[i];for(var l=0,u=Object.entries(c);l<u.length;l++){var p=u[l],_=p[0],d=p[1];if(_===r.attachment)for(var m=0,f=Object.entries(d);m<f.length;m++){var y=f[m],b=y[0],h=y[1];d[b]=clientnode__WEBPACK_IMPORTED_MODULE_4___default().extend(!0,clientnode__WEBPACK_IMPORTED_MODULE_4___default().copy(e.property.defaultSpecification),h)}else[r.allowedRoles,r.constraint.execution,r.constraint.expression,r.extend,r.maximumAggregatedSize,r.minimumAggregatedSize,r.oldType].includes(_)||(c[_]=clientnode__WEBPACK_IMPORTED_MODULE_4___default().extend(!0,clientnode__WEBPACK_IMPORTED_MODULE_4___default().copy(e.property.defaultSpecification),d))}}return n},Helper.normalizeAllowedRoles=function(e){if(Array.isArray(e))return{read:e,write:e};if("object"==typeof e){for(var t,r={read:[],write:[]},n=0,a=Object.keys(r);n<a.length;n++)t=a[n],Object.prototype.hasOwnProperty.call(e,t)&&(Array.isArray(e[t])?r[t]=e[t]:r[t]=[e[t]]);return r}return{read:[e],write:[e]}},Helper}();const __WEBPACK_DEFAULT_EXPORT__=Helper},e=>{!function(){"use strict";function t(){return(t=r()?Reflect.construct.bind():function(e,t,r){var a=[null];a.push.apply(a,t);var o=new(Function.bind.apply(e,a));return r&&n(o,r.prototype),o}).apply(null,arguments)}function r(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function n(e,t){return n=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},n(e,t)}function a(){return a=Object.assign?Object.assign.bind():function(e){for(var t,r=1;r<arguments.length;r++)for(var n in t=arguments[r])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e},a.apply(this,arguments)}function o(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return c(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?c(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function c(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}var i={d:function(e,t){for(var r in t)i.o(t,r)&&!i.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},o:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r:function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},s={};i.r(s),i.d(s,{DatabaseHelper:function(){return l},default:function(){return u}});var l=function(){function e(){}return e.authenticate=function(e,t,r,n,a,c,i,s,l){var u;void 0===t&&(t=null),void 0===r&&(r={}),void 0===n&&(n={admins:{names:[],roles:[]},members:{names:[],roles:[]}}),void 0===c&&(c="_id"),void 0===i&&(i="-type"),void 0===s&&(s="_design/"),void 0===l&&(l=!1);var p=null!==(u=e[i])&&void 0!==u?u:t&&t[i];if(!p)return!0;var _=l?"read":"write",d={properties:{},read:["_admin","readonlyadmin"],write:["_admin"]};Object.prototype.hasOwnProperty.call(e,c)&&e[c].startsWith(s)&&d.read.push("readonlymember");var m,f="Current user doesn't own any role";if(r)if("name"in r||(r.name='"unknown"'),null!=(m=r.roles)&&m.length){if(a&&p&&Object.prototype.hasOwnProperty.call(a,p)){for(var y,b,h=a[p],v=o(["read","write"]);!(y=v()).done;)d[b=y.value]=d[b].concat(h[b]||[]);d.properties=h.properties}for(var g,O,x=d[_],P=o(r.roles);!(g=P()).done;)if(O=g.value,x.includes(O))return!0;f='Current user "'+r.name+'" owns the following roles: "'+r.roles.join('", "')+'"'}else f='Current user "'+r.name+"\" doesn't own any role";throw{unauthorized:"Only users with a least on of these roles are allowed to perform requested "+_+' action: "'+[].concat(d[_]).join('", "')+'". '+f+"."}},e.validateDocumentUpdate=function(e,r,n,c,i,s,l){void 0===s&&(s={});var u=function(e,t,r){var n;void 0===t&&(t="forbidden"),void 0===r&&(r={});for(var a=((n={})[t]=e,n.message=e,n.name=t,n),o=0,c=Object.entries(r);o<c.length;o++){var i=c[o],s=i[0],l=i[1];a[s]=l}throw a},p=new Date,_=Date.UTC(p.getUTCFullYear(),p.getUTCMonth(),p.getUTCDate(),p.getUTCHours(),p.getUTCMinutes(),p.getUTCSeconds(),p.getUTCMilliseconds())/1e3,d=!i.dateTimeFormat.startsWith("iso"),m=i.property.name.special,f=m.id,y=m.revision,b=m.type;r&&r[b]&&!e[b]&&(e[b]=r[b]);var h="",v="",g=function(){h=Object.prototype.hasOwnProperty.call(e,f)?e[f]:"",v=Object.prototype.hasOwnProperty.call(e,y)?e[y]:""};if(g(),Object.prototype.hasOwnProperty.call(c,i.property.name.validatedDocumentsCache)&&c[i.property.name.validatedDocumentsCache].has(h+"-"+v))return c[i.property.name.validatedDocumentsCache].delete(h+"-"+v),e;["latest","upsert"].includes(v)&&(r&&Object.prototype.hasOwnProperty.call(r,y)?v=e[y]=r[y]:"latest"===v?u("Revision: No old document available to update."):delete e[y]);var O=i.updateStrategy;Object.prototype.hasOwnProperty.call(e,m.strategy)&&(O=e[m.strategy],delete e[m.strategy]);var x,P={};if("migrate"===O)for(var w=0,E=Object.entries(s);w<E.length;w++){var k=E[w],D=k[0],j=k[1];if(Object.prototype.hasOwnProperty.call(j,m.oldType)&&![null,void 0].includes(j[m.oldType]))for(var M,A,C=o([].concat(j[m.oldType]));!(M=C()).done;)A=M.value,P[A]=D}l?x=l:JSON&&Object.prototype.hasOwnProperty.call(JSON,"stringify")?x=function(e){return JSON.stringify(e,null,4)}:u('Needed "serializer" is not available.');var T=function(e){return e instanceof Error?""+e:x(e)},R=function(e){return"string"==typeof e?e.trim():""},I=function(e){if(d)null!==e&&"number"!=typeof e&&(e=new Date(e),e=Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate(),e.getUTCHours(),e.getUTCMinutes(),e.getUTCSeconds(),e.getUTCMilliseconds())/1e3);else if(null!==e){e=new Date("number"!=typeof e||isNaN(e)?e:1e3*e);try{e=e.toISOString()}catch(e){}}return e},S=function(e,t,r){if(r.fileName){if(r.fileName.value)return r.fileName.value===t;if(r.fileName.regularExpressionPattern)return new RegExp(r.fileName.regularExpressionPattern).test(t)}return e===t},U=function(t,r){if(r||(r=e[m.attachment]),t){for(var n,a=0,o=Object.keys(r);a<o.length;a++)if((n=o[a]).startsWith(t))return n}else{var c=Object.keys(r);if(c.length)return c[0]}return null},L=function(e,r,n){void 0===r&&(r=!1),void 0===n&&(n={});var o=R(e);if(o){var c,i=(r?"return ":"")+o,s=a({},N,{code:i},n),l=Object.keys(s);try{c=t(Function,l.concat([i]))}catch(e){u(T(e),"compilation",{code:i,error:e,scope:s})}var p={code:i,result:void 0,scope:s};try{p.result=c.apply(void 0,l.map((function(e){return s[e]})))}catch(e){u(T(e),"runtime",{code:i,error:e,scope:s})}return p}u("No expression to evaluate provided.","empty")},W=function(e,r,n){void 0===n&&(n=[]);var a=n.length?" in "+n.join(" -> "):"",c=[],l=function(){Object.prototype.hasOwnProperty.call(e,b)||(r&&Object.prototype.hasOwnProperty.call(r,b)&&["fillUp","migrate"].includes(O)?e[b]=r[b]:u('Type: You have to specify a model type via property "'+b+'"'+a+".")),n.length||new RegExp(i.property.name.typeRegularExpressionPattern.public).test(e[b])||u('TypeName: You have to specify a model type which matches "'+i.property.name.typeRegularExpressionPattern.public+'" as public type (given "'+e[b]+'")'+a+"."),Object.prototype.hasOwnProperty.call(s,e[b])||(Object.prototype.hasOwnProperty.call(P,e[b])?e[b]=P[e[b]]:u('Model: Given model "'+e[b]+'" is not specified'+a+"."))};l();var p=e[b],_=s[p],h=null;Object.prototype.hasOwnProperty.call(_,m.additional)&&_[m.additional]&&(h=_[m.additional]);var v=function c(i,s,l,d,m){void 0===m&&(m=["constraintExecution","constraintExpression"]);for(var f,y,b=o(m);!(f=b()).done;)if(y=f.value,Object.prototype.hasOwnProperty.call(l,y)){var h,v=void 0;try{v=L(l[y].evaluation,y.endsWith("Expression"),{checkPropertyContent:c,model:_,modelName:p,name:s,type:y,newDocument:e,newValue:i,oldDocument:r,oldValue:d,parentNames:n,pathDescription:a,propertySpecification:l})}catch(s){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(s)&&u('Compilation: Hook "'+y+'" has invalid code "'+s.code+'": "'+s.message+'"'+a+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(s)&&u('Runtime: Hook "'+y+'" has throw an error with code "'+s.code+'": "'+s.message+'"'+a+"."),!Object.prototype.hasOwnProperty.call(s,"empty"))throw s}if(null==(h=v)||!h.result){var g=R(l[y].description);u(y.charAt(0).toUpperCase()+(y.substring(1)+": ")+(g?t(Function,Object.keys(v.scope).concat(["return "+g])).apply(void 0,Object.values(v.scope)):'Property "'+s+'" should satisfy constraint "'+v.code+'" (given "'+T(i)+'")'+a+"."))}}},x=function(e,t,r,c){void 0===c&&(c=null);var i=[],l=[].concat(r.type?r.type:[]);"object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype&&!Object.prototype.hasOwnProperty.call(e,b)&&1===l.length&&Object.prototype.hasOwnProperty.call(s,l[0])&&(e[b]=l[0]);for(var p,_,m=!1,y=o(l);!(p=y()).done;)if(_=p.value,Object.prototype.hasOwnProperty.call(s,_)){if("object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype&&Object.prototype.hasOwnProperty.call(e,b)&&e[b]!==_&&"migrate"===O&&1===l.length&&(e[b]=_,i=n.concat(t,"migrate nested object type")),"object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype&&Object.prototype.hasOwnProperty.call(e,b)&&e[b]===_){var h=W(e,c,n.concat(t));if(h.changedPath.length&&(i=h.changedPath),e=h.newDocument,T(e)===T({}))return{newValue:null,changedPath:i};m=!0;break}1===l.length&&u('NestedType: Under key "'+t+'" isn\'t of type "'+_+'" (given "'+T(e)+'" of type '+typeof e+")"+a+".")}else if("DateTime"===_){var g=e;if(e=I(e),!(d&&("number"!=typeof e||isNaN(e))||!d&&"string"!=typeof e)){m=!0;break}1===l.length&&u('PropertyType: Property "'+t+'" isn\'t of (valid) type "DateTime" (given "'+T(g).replace(/^"/,"").replace(/"$/,"")+'" of type "'+typeof g+'")'+a+".")}else if(["boolean","integer","number","string"].includes(_)){if(!("number"==typeof e&&isNaN(e)||"integer"!==_&&typeof e!==_||"integer"===_&&parseInt(e,10)!==e)){m=!0;break}1===l.length&&u('PropertyType: Property "'+t+'" isn\'t of (valid) type "${type}" (given "'+T(e)+'" of type "'+typeof e+'")'+a+".")}else if("string"==typeof _&&_.startsWith("foreignKey:")){var x=s[_.substring(11)][f].type;if(x===typeof e){m=!0;break}1===l.length&&u('PropertyType: Foreign key property "'+t+'" isn\'t of type "'+x+'" (given "'+T(e)+'" of type "'+typeof e+'")'+a+".")}else{if("any"===_||T(e)===T(_)){m=!0;break}1===l.length&&u('PropertyType: Property "'+t+'" isn\'t value "'+_+'" (given "'+T(e).replace(/^"/,"").replace(/"$/,"")+'" of type "'+typeof e+'")'+a+".")}if(m||u('PropertyType: None of the specified types "'+l.join('", "')+'" for property "'+t+'" matches value "'+T(e).replace(/^"/,"").replace(/"$/,"")+e+'" of type "'+typeof e+'")'+a+"."),"string"==typeof e&&(![null,void 0].includes(r.minimumLength)&&e.length<r.minimumLength&&u('MinimalLength: Property "'+t+'" must have minimal length '+r.minimumLength+" (given "+e+" with length i"+e.length+") "+a+"."),![null,void 0].includes(r.maximumLength)&&e.length>r.maximumLength&&u('MaximalLength: Property "'+t+'" must have maximal length '+r.maximumLength+" (given "+e+" with length "+e.length+")"+a+".")),"number"==typeof e&&(![null,void 0].includes(r.minimum)&&e<r.minimum&&u('Minimum: Property "'+t+'" (type '+r.type+") must satisfy a minimum of "+r.minimum+" (given "+e+" is too low)"+a+"."),![null,void 0].includes(r.maximum)&&e>r.maximum&&u('Maximum: Property "'+t+'" (type '+r.type+") must satisfy a maximum of "+r.maximum+" (given "+e+" is too high)"+a+".")),r.selection){var P=Array.isArray(r.selection)?r.selection.map((function(e){return void 0===(null==e?void 0:e.value)?e:e.value})):Object.keys(r.selection);"DateTime"===r.type&&(P=P.map(I)),P.includes(e)||u('Selection: Property "'+t+'" (type '+r.type+') should be one of "'+P.join('", "')+'". But is "'+e+'"'+a+".")}return[null,void 0].includes(r.regularExpressionPattern)||new RegExp(r.regularExpressionPattern).test(e)?![null,void 0].includes(r.invertedRegularExpressionPattern)&&new RegExp(r.invertedRegularExpressionPattern).test(e)&&u('InvertedPatternMatch: Property "'+t+'" should not match regular expression pattern '+r.invertedRegularExpressionPattern+' (given "'+e+'")'+a+"."):u('PatternMatch: Property "'+t+'" should match regular expression pattern '+r.regularExpressionPattern+' (given "'+e+'")'+a+"."),v(e,t,r,c),T(e)!==T(c)&&(i=n.concat(t,"value updated")),{newValue:e,changedPath:i}},w=function(e,t,r,a,o){var s=t[a];if(!e.writable)if(r){if(Object.prototype.hasOwnProperty.call(r,a)&&T(s)===T(r[a]))return a!==f&&"incremental"===O&&delete t[a],!0;u('Readonly: Property "'+a+'" is not writable (old document "'+T(r)+'")'+o+".")}else u('Readonly: Property "'+a+'" is not writable'+o+".");if(!e.mutable&&r&&Object.prototype.hasOwnProperty.call(r,a)){if(T(s)===T(r[a]))return"incremental"!==O||i.property.name.reserved.concat(m.deleted,f,y).includes(a)||delete t[a],!0;"migrate"!==O&&u('Immutable: Property "'+a+'" is not writable (old document "'+T(r)+'")'+o+".")}if(null===s){if(e.nullable)return delete t[a],r&&Object.prototype.hasOwnProperty.call(r,a)&&(c=n.concat(a,"delete property")),!0;u('NotNull: Property "'+a+'" should not be "null"'+o+".")}return!1},E=function(e,t,r,c){if(!r)for(var i,s,l=o(["onCreateExecution","onCreateExpression"]);!(i=l()).done;)if(s=i.value,Object.prototype.hasOwnProperty.call(e,s)){var d=void 0;try{d=L(e[s],s.endsWith("Expression"),{checkPropertyContent:x,model:_,modelName:p,name:c,type:s,newDocument:t,oldDocument:r,newValue:void 0,oldValue:void 0,parentNames:n,pathDescription:a,propertySpecification:e})}catch(i){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(i)&&u('Compilation: Hook "'+s+'" has invalid code "'+i.code+'" for property "'+c+'": '+i.message+a+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(i)&&u('Runtime: Hook "'+s+'" has throw an error with code "'+i.code+'" for property "'+c+'": '+i.message+a+"."),!Object.prototype.hasOwnProperty.call(i,"empty"))throw i}d&&![null,void 0].includes(d.result)&&(t[c]=d.result)}},k=function(e,t,r,c){if(Object.prototype.hasOwnProperty.call(t,c)){e.trim&&"string"==typeof t[c]&&(t[c]=t[c].trim()),e.emptyEqualsToNull&&(""===t[c]||Array.isArray(t[c])&&0===t[c].length||null!==t[c]&&"object"==typeof t[c]&&0===Object.keys(t).length)&&(t[c]=null);for(var i,s,l=o(["onUpdateExecution","onUpdateExpression"]);!(i=l()).done;)if(s=i.value,Object.prototype.hasOwnProperty.call(e,s))try{t[c]=L(e[s],s.endsWith("Expression"),{checkPropertyContent:x,model:_,modelName:p,name:c,type:s,newDocument:t,oldDocument:r,newValue:t[c],oldValue:r&&r[c],parentNames:n,pathDescription:a,propertySpecification:e}).result}catch(i){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(i)&&u('Compilation: Hook "'+s+'" has invalid code "'+i.code+'" for property "'+c+'": '+i.message+a+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(i)&&u('Runtime: Hook "'+s+'" has throw an error with code "'+i.code+'" for property "'+c+'": '+i.message+a+"."),!Object.prototype.hasOwnProperty.call(i,"empty"))throw i}}},D=Object.keys(_).filter((function(e){return![m.additional,m.allowedRoles,m.constraint.execution,m.constraint.expression,m.create.execution,m.create.expression,m.extend,m.maximumAggregatedSize,m.minimumAggregatedSize,m.oldType,m.update.execution,m.update.expression].includes(e)}));if("migrate"===O)for(var j,M,A=o(D);!(j=A()).done;)if(M=j.value,![null,void 0].includes(_[M].oldName))for(var C,U,N=o([].concat(_[M].oldName));!(C=N()).done;)U=C.value,Object.prototype.hasOwnProperty.call(e,U)&&(e[M]=e[U],delete e[U]);if(!r)for(var B,K=0,q=[m.create.execution,m.create.expression];K<q.length;K++)if(B=q[K],Object.prototype.hasOwnProperty.call(_,B)){var z=void 0;try{z=L(_[B],B.endsWith("Expression"),{checkPropertyContent:x,model:_,modelName:p,type:B,newDocument:e,oldDocument:r,parentNames:n,pathDescription:a}).result}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&u('Compilation: Hook "'+B+'" has invalid code "'+e.code+'" for document "'+p+'": '+e.message+a+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&u('Runtime: Hook "'+B+'" has throw an error with code "'+e.code+'" for document "'+p+'": '+e.message+a+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}[null,void 0].includes(z)||(e=z),l(),p=e[b],0===n.length&&g()}for(var H,F=0,G=[m.update.execution,m.update.expression];F<G.length;F++)if(H=G[F],Object.prototype.hasOwnProperty.call(_,H)){var V=void 0;try{V=L(_[H],H.endsWith("Expression"),{checkPropertyContent:x,model:_,modelName:p,type:H,newDocument:e,oldDocument:r,parentNames:n,pathDescription:a}).result}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&u('Compilation: Hook "'+H+'" has invalid code "'+e.code+'" for document "'+p+'": '+e.message+a+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&u('Runtime: Hook "'+H+'" has throw an error with code "'+e.code+'" for document "'+p+'": '+e.message+a+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}[void 0,null].includes(V)||(e=V),l(),p=e[b],0===n.length&&g()}for(var J,$=function t(){var a=J.value;if(m.attachment===a)for(var i=function(){var i=l[s],u=i[0],p=i[1];Object.prototype.hasOwnProperty.call(e,a)&&null!==e[a]||(e[a]={}),r&&!Object.prototype.hasOwnProperty.call(r,a)&&(r[a]={});var _=Object.keys(e[a]).filter((function(t){return null!==e[a][t].data&&S(u,t,p)})),d=e[a],m=[];if(r){var f=r[a];m=Object.keys(f).filter((function(e){return!(Object.prototype.hasOwnProperty.call(d,e)&&Object.prototype.hasOwnProperty.call(d[e],"data")&&null===d[e].data)&&!!f[e]&&(Object.prototype.hasOwnProperty.call(f[e],"data")&&null!==f[e].data||f[e].stub&&!!f[e].digest)&&!!S(u,e,p)}))}for(var y,b,h=p,v=o(_);!(y=v()).done;)b=y.value,E(h,d,r&&r[a]?r[a]:null,b);for(var g,x,P=o(_);!(g=P()).done;)x=g.value,k(h,d,r&&r[a]?r[a]:null,x);if([null,void 0].includes(h.default)){if(h.nullable||0<_.length||0<m.length||t(),"fillUp"===O&&0===_.length&&0<m.length)for(var w,D,j=o(m);!(w=j()).done;)D=w.value,null===d[D]?c=n.concat(a,D,"file removed"):d[D]=r[a][D]}else if(0===_.length)if(0===m.length)for(var M in h.default)Object.prototype.hasOwnProperty.call(h.default,M)&&(d[M]=h.default[M],c=n.concat(a,u,"add default file"));else if("fillUp"===O)for(var A,C,T=o(m);!(A=T()).done;)C=A.value,d[C]=r[a][C]},s=0,l=Object.entries(_[a]);s<l.length;s++)i();else{var u=D.includes(a)?_[a]:h;E(u,e,r,a),k(u,e,r,a),[null,void 0].includes(u.default)?(!(u.nullable||Object.prototype.hasOwnProperty.call(e,a)||r&&Object.prototype.hasOwnProperty.call(r,a)&&O)&&t(),!Object.prototype.hasOwnProperty.call(e,a)&&r&&Object.prototype.hasOwnProperty.call(r,a)&&("fillUp"===O?e[a]=r[a]:!O&&(c=n.concat(a,"property removed")))):(!Object.prototype.hasOwnProperty.call(e,a)||null===e[a])&&(r&&Object.prototype.hasOwnProperty.call(r,a)?"fillUp"===O?e[a]=r[a]:"migrate"===O&&(e[a]=u.default,c=n.concat(a,"migrate default value")):(e[a]=u.default,c=c.concat(a,"add default value")))}},Y=o(D.concat(h?Object.keys(e).filter((function(e){return!D.includes(e)})):[]));!(J=Y()).done;)$();if(r&&"incremental"===O)for(var X=0,Z=Object.entries(e);X<Z.length;X++){var Q=Z[X],ee=Q[0],te=Q[1];!Object.prototype.hasOwnProperty.call(r,ee)||i.property.name.reserved.concat(f,y,m.conflict,m.deleted,m.deletedConflict,m.localSequence,m.revisions,m.revisionsInformation,b).includes(ee)||r[ee]!==te&&T(r[ee])!==T(te)||delete e[ee]}for(var re=0,ne=Object.entries(e);re<ne.length;re++){var ae=ne[re],oe=ae[0],ce=ae[1];if(!i.property.name.reserved.concat(y,m.conflict,m.deleted,m.deletedConflict,m.localSequence,m.revisions,m.revisionsInformation,m.strategy).includes(oe)){var ie=void 0;if(Object.prototype.hasOwnProperty.call(_,oe))ie=_[oe];else if(h)ie=h;else{if("migrate"===O){delete e[oe],c=n.concat(oe,"migrate removed property");continue}u('Property: Given property "'+oe+'" isn\'t specified in model "'+p+'"'+a+".")}if(!ie)continue;if(m.attachment===oe){var se=ce;for(var le in se)if(Object.prototype.hasOwnProperty.call(se,le))for(var ue in _[oe])if(S(ue,le,_[oe][ue])){w(_[oe][ue],e,r,le,a);break}continue}if(w(ie,e,r,oe,a))continue;if("string"==typeof ie.type&&ie.type.endsWith("[]")||Array.isArray(ie.type)&&ie.type.length&&Array.isArray(ie.type[0])){var pe,_e=ce;Array.isArray(_e)?![null,void 0].includes(ie.minimumNumber)&&_e.length<ie.minimumNumber?u('MinimumArrayLength: Property "'+oe+'" (array of length '+_e.length+") doesn't fullfill minimum array length of "+ie.minimumNumber+a+"."):![null,void 0].includes(ie.maximumNumber)&&ie.maximumNumber<_e.length&&u('MaximumArrayLength: Property "'+oe+'" (array of length '+_e.length+") doesn't fullfill maximum array length of "+ie.maximumNumber+a+"."):u('PropertyType: Property "'+oe+'" isn\'t of type "array -> '+ie.type+'" (given "'+T(_e)+'")'+a+"."),v(_e,oe,ie,r&&Object.prototype.hasOwnProperty.call(r,oe)&&r[oe]||void 0,["arrayConstraintExecution","arrayConstraintExpression"]);var de={};for(var me in ie)Object.prototype.hasOwnProperty.call(ie,me)&&(de[me]="type"===me?Array.isArray(ie[me])?ie[me][0]:[ie[me].substring(0,ie.type.length-2)]:ie[me]);if(1===(null==(pe=de.type)?void 0:pe.length)&&Object.prototype.hasOwnProperty.call(s,de.type[0]))for(var fe,ye,be=o(_e.slice());!(fe=be()).done;)"object"!=typeof(ye=fe.value)||Object.getPrototypeOf(ye)!==Object.prototype||Object.prototype.hasOwnProperty.call(ye,b)||(ye[b]=de.type[0]);for(var he,ve,ge=0,Oe=o(_e.slice());!(he=Oe()).done;)ve=he.value,_e[ge]=x(ve,ge+1+". value in "+oe,de).newValue,null===ve&&_e.splice(ge,1),ge+=1;r&&Object.prototype.hasOwnProperty.call(r,oe)&&Array.isArray(r[oe])&&r[oe].length===_e.length&&T(r[oe])===T(_e)||(c=n.concat(oe,"array updated"))}else{var xe=r&&Object.prototype.hasOwnProperty.call(r,oe)?r[oe]:null,Pe=x(ce,oe,ie,xe);e[oe]=Pe.newValue,Pe.changedPath.length&&(c=Pe.changedPath),null===e[oe]&&(null!==xe&&(c=n.concat(oe,"property removed")),delete e[oe])}}}for(var we,Ee=0,ke=Object.keys(m.constraint);Ee<ke.length;Ee++)if(we=ke[Ee],(we=m.constraint[we])&&Object.prototype.hasOwnProperty.call(_,we))for(var De,je=o([].concat(_[we]));!(De=je()).done;){var Me,Ae=De.value,Ce=void 0;try{Ce=L(Ae.evaluation,we===m.constraint.expression,{checkPropertyContent:x,model:_,modelName:p,type:we,newDocument:e,oldDocument:r,parentNames:n,pathDescription:a})}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&u('Compilation: Hook "'+we+'" has invalid code "'+e.code+'": "'+e.message+'"'+a+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&u('Runtime: Hook "'+we+'" has thrown an error with code "'+e.code+'": '+e.message+a+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}if(null==(Me=Ce)||!Me.result){var Te=we.replace(/^[^a-zA-Z]+/,"");u(Te.charAt(0).toUpperCase()+(Te.substring(1)+": ")+(Ae.description?t(Function,Object.keys(Ce.scope).concat(["return "+Ae.description.trim()])).apply(void 0,Object.values(Ce.scope)):'Model "'+p+'" should satisfy constraint "'+Ce.code+'" (given "'+T(e)+'")'+a+"."))}}if(Object.prototype.hasOwnProperty.call(e,m.attachment)){var Re=e[m.attachment];("object"!=typeof Re||Object.getPrototypeOf(Re)!==Object.prototype)&&u("AttachmentType: given attachment has invalid type"+a+".");var Ie=null;if(r&&Object.prototype.hasOwnProperty.call(r,m.attachment)&&null!==(Ie=r[m.attachment])&&"object"==typeof Ie)for(var Se=0,Ue=Object.entries(Ie);Se<Ue.length;Se++){var Le=Ue[Se],We=Le[0],Ne=Le[1];if(Object.prototype.hasOwnProperty.call(Re,We)){var Be=Re[We];null===Be||null===Be.data||Be.content_type===Ne.content_type&&(Be.data===Ne.data||Be.digest===Ne.digest)?((null===Be||null===Be.data)&&(c=n.concat(m.attachment,We,"attachment removed")),"incremental"===O&&delete Re[We]):c=n.concat(m.attachment,We,"attachment updated")}else"fillUp"===O?Re[We]=Ne:O||(c=n.concat(m.attachment,We,"attachment removed"))}for(var Ke=0,qe=Object.entries(Re);Ke<qe.length;Ke++){var ze=qe[Ke],He=ze[0],Fe=ze[1];[null,void 0].includes(Fe)||null===Fe.data?delete Re[He]:(!Ie||!Object.prototype.hasOwnProperty.call(Ie,He)||Fe.content_type!==Ie[He].content_type||Fe.data!==Ie[He].data&&Fe.digest!==Ie[He].digest)&&(c=n.concat(m.attachment,He,"attachment updated"))}0===Object.keys(Re).length&&delete e[m.attachment];for(var Ge={},Ve=0,Je=Object.keys(_[m.attachment]);Ve<Je.length;Ve++)Ge[Je[Ve]]=[];for(var $e=0,Ye=Object.keys(Re);$e<Ye.length;$e++){for(var Xe=Ye[$e],Ze=!1,Qe=0,et=Object.entries(_[m.attachment]);Qe<et.length;Qe++){var tt=et[Qe],rt=tt[0],nt=tt[1];if(S(rt,Xe,nt)){Ge[rt].push(Xe),Ze=!0;break}}Ze||u('AttachmentTypeMatch: None of the specified attachment types ("'+Object.keys(_[m.attachment]).join('", "')+'") matches given one ("'+Xe+'")'+a+".")}for(var at=0,ot=0,ct=Object.keys(Ge);ot<ct.length;ot++){var it=ct[ot],st=_[m.attachment][it];if(Object.prototype.hasOwnProperty.call(Ge,it)){var lt=Ge[it].length;null!==st.maximumNumber&&lt>st.maximumNumber&&u("AttachmentMaximum: given number of attachments ("+lt+") doesn't satisfy specified maximum of "+st.maximumNumber+' from type "'+it+'"'+a+"."),(!st.nullable||0!==lt)&&lt<st.minimumNumber&&u("AttachmentMinimum: given number of attachments ("+lt+") doesn't satisfy specified minimum of "+st.minimumNumber+' from type "'+it+'"'+a+".");for(var ut,pt=0,_t=o(Ge[it]);!(ut=_t()).done;){var dt,mt,ft=ut.value;null!=(dt=st.fileName)&&dt.regularExpressionPattern&&!new RegExp(st.fileName.regularExpressionPattern).test(ft)?u('AttachmentName: given attachment name "'+ft+'" doesn\'t satisfy specified regular expression pattern "'+st.fileName.regularExpressionPattern+'" from type "'+it+'"'+a+"."):null!=(mt=st.fileName)&&mt.invertedRegularExpressionPattern&&new RegExp(st.fileName.invertedRegularExpressionPattern).test(ft)?u('InvertedAttachmentName: given attachment name "'+ft+'" does satisfy specified regular expression pattern "'+st.fileName.invertedRegularExpressionPattern+'" from type "'+it+'"'+a+"."):!([null,void 0].includes(st.contentTypeRegularExpressionPattern)||Re[ft].content_type&&new RegExp(st.contentTypeRegularExpressionPattern).test(Re[ft].content_type))&&u('AttachmentContentType: given attachment content type "'+Re[ft].content_type+'" doesn\'t satisfy specified regular expression pattern "'+st.contentTypeRegularExpressionPattern+'" from type "'+it+'"'+a+".");var yt=st.invertedContentTypeRegularExpressionPattern;[null,void 0].includes(yt)||Re[ft].content_type&&!new RegExp(yt).test(Re[ft].content_type)||u('InvertedAttachmentContentType: given attachment content type "'+Re[ft].content_type+'" does satisfy specified regular expression pattern "'+yt+'" from type "'+it+'"'+a+".");var bt=0;"length"in Re[ft]?bt=Re[ft].length:"data"in Re[ft]&&(bt=Buffer&&"byteLength"in Buffer?Buffer.byteLength(Re[ft].data,"base64"):Re[ft].data.length),![null,void 0].includes(st.minimumSize)&&st.minimumSize>bt?u("AttachmentMinimumSize: given attachment size "+bt+" byte doesn't satisfy specified minimum of "+st.minimumSize+" byte "+a+"."):![null,void 0].includes(st.maximumSize)&&st.maximumSize<bt&&u("AttachmentMaximumSize: given attachment size "+bt+" byte doesn't satisfy specified maximum of "+st.maximumSize+" byte "+a+"."),pt+=bt}![null,void 0].includes(st.minimumAggregatedSize)&&st.minimumAggregatedSize>pt?u('AttachmentAggregatedMinimumSize: given aggregated size of attachments from type "'+it+'" '+pt+" byte doesn't satisfy specified minimum of "+st.minimumAggregatedSize+" byte "+a+"."):![null,void 0].includes(st.maximumAggregatedSize)&&st.maximumAggregatedSize<pt&&u('AttachmentAggregatedMaximumSize: given aggregated size of attachments from type "'+it+'" '+pt+" byte doesn't satisfy specified maximum of "+st.maximumAggregatedSize+" byte "+a+"."),at+=pt}}Object.prototype.hasOwnProperty.call(_,m.minimumAggregatedSize)&&![null,void 0].includes(_[m.minimumAggregatedSize])&&_[m.minimumAggregatedSize]>at?u("AggregatedMinimumSize: given aggregated size "+at+" byte doesn't satisfy specified minimum of "+_[m.minimumAggregatedSize]+" byte "+a+"."):![null,void 0].includes(_[m.maximumAggregatedSize])&&_[m.maximumAggregatedSize]<at&&u("AggregatedMaximumSize: given aggregated size "+at+" byte doesn't satisfy specified maximum of "+_[m.maximumAggregatedSize]+" byte "+a+".")}if(r&&Object.prototype.hasOwnProperty.call(r,m.attachment)&&0===Object.keys(r[m.attachment]).length&&delete r[m.attachment],0===c.length&&r&&"migrate"===O)for(var ht,vt=0,gt=Object.keys(r);vt<gt.length;vt++)ht=gt[vt],Object.prototype.hasOwnProperty.call(e,ht)||(c=n.concat(ht,"migrate removed property"));return{changedPath:c,newDocument:e}},N={attachmentWithPrefixExists:function(t){if(Object.prototype.hasOwnProperty.call(e,m.attachment)){var r=e[m.attachment],n=U(t);if(n)return Object.prototype.hasOwnProperty.call(r[n],"stub")&&r[n].stub||Object.prototype.hasOwnProperty.call(r[n],"data")&&![null,void 0].includes(r[n].data)}return!1},checkDocument:W,getFileNameByPrefix:U,serialize:T,id:h,revision:v,idName:f,revisionName:y,specialNames:m,typeName:b,modelConfiguration:i,models:s,now:p,nowUTCTimestamp:_,securitySettings:c,userContext:n},B=W(e,r);return(!B.newDocument._deleted||r)&&(B.newDocument._deleted&&B.newDocument._deleted!==(null==r?void 0:r._deleted)||B.changedPath.length)||u("NoChange: No new data given. new document: "+T(e)+"; old document: "+T(r)+"."),Object.prototype.hasOwnProperty.call(c,i.property.name.validatedDocumentsCache)?c[i.property.name.validatedDocumentsCache].add(h+"-"+v):c[i.property.name.validatedDocumentsCache]=new Set([h+"-"+v]),B.newDocument},e}(),u=l;e.exports=s}()}],__webpack_module_cache__={};function __webpack_require__(e){var t=__webpack_module_cache__[e];if(void 0!==t)return t.exports;var r=__webpack_module_cache__[e]={exports:{}};return __webpack_modules__[e](r,r.exports,__webpack_require__),r.exports}__webpack_require__.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return __webpack_require__.d(t,{a:t}),t},__webpack_require__.d=(e,t)=>{for(var r in t)__webpack_require__.o(t,r)&&!__webpack_require__.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},__webpack_require__.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),__webpack_require__.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var __webpack_exports__={};(()=>{"use strict";__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,{Database:()=>g,default:()=>O});var e=__webpack_require__(0),t=__webpack_require__.n(e),r=__webpack_require__(1),n=__webpack_require__.n(r),a=__webpack_require__(2),o=__webpack_require__.n(a),c=__webpack_require__(4),i=__webpack_require__.n(c),s=__webpack_require__(6),l=__webpack_require__(7),u=__webpack_require__.n(l);const p=require("pouchdb");var _=__webpack_require__.n(p);const d=require("pouchdb-find");var m=__webpack_require__.n(d),f=__webpack_require__(9),y=__webpack_require__.n(f),b=__webpack_require__(8);function h(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return v(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?v(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function v(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}var g=function(){function e(){}return e.preLoadService=function(){var t=n()(o().mark((function t(r){var a,c,s,l,p,d,f,y,b,v,g,O,x,P,w,E,k;return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(a=r.configuration.couchdb,c=r.services,Object.prototype.hasOwnProperty.call(c,"couchdb")||(c.couchdb={}),s=c.couchdb,Object.prototype.hasOwnProperty.call(s,"connector")||(l=a.model.property.name.special.id,p=a.model.property.name.special.revision,s.connector=_(),d=s.connector.prototype.bulkDocs,s.connector.plugin({bulkDocs:function(){var t=n()(o().mark((function t(r){var n,c,i,s,u,_,m,f,y,b,v,g,O,x,P,w,E,k,D=arguments;return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:for(c=D.length,i=Array(1<c?c-1:0),s=1;s<c;s++)i[s-1]=D[s];return u=0<i.length&&i[i.length-1]===e.toggleIDDetermining,_=u?!e.skipIDDetermining:e.skipIDDetermining,u&&i.pop(),m=!Array.isArray(r)&&null!==r&&"object"==typeof r&&l in r?[r]:r,null!=(n=a.connector.fetch)&&n.timeout&&(0===i.length||"object"!=typeof i[0])&&i.unshift({timeout:a.connector.fetch.timeout}),t.next=8,d.call.apply(d,[this,m].concat(i));case 8:f=t.sent,y=[],b=[],v=0,g=h(f);case 13:if((O=g()).done){t.next=36;break}if(x=O.value,"object"!=typeof m[v]){t.next=33;break}if(!(p in m[v])||"conflict"!==x.name||!["latest","upsert"].includes(m[v][p])){t.next=21;break}b.push(m[v]),y.push(v),t.next=33;break;case 21:if(!(l in m[v]&&a.ignoreNoChangeError&&"name"in x&&"forbidden"===x.name&&"message"in x&&x.message.startsWith("NoChange:"))){t.next=33;break}if(f[v]={id:m[v][l],ok:!0},_){t.next=33;break}if(!(p in m[v])||["latest","upsert"].includes(m[v][p])){t.next=28;break}t.t0=m[v][p],t.next=32;break;case 28:return t.next=30,this.get(f[v].id);case 30:t.t1=p,t.t0=t.sent[t.t1];case 32:f[v].rev=t.t0;case 33:v+=1;case 34:t.next=13;break;case 36:if(!b.length){t.next=43;break}return m=b,u&&i.push(e.toggleIDDetermining),t.next=41,this.bulkDocs.apply(this,[m].concat(i));case 41:for(P=t.sent,w=h(P);!(E=w()).done;)k=E.value,f[y.shift()]=k;case 43:return t.abrupt("return",f);case 44:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}()}),a.debug&&s.connector.debug.enable("*"),s.connector=s.connector.plugin(m())),Object.prototype.hasOwnProperty.call(s,"server")){t.next=36;break}s.server={},f=[],y=h([].concat(a.binary.runner));case 8:if((b=y()).done){t.next=34;break}v=b.value,g=h([].concat(v.location));case 11:if((O=g()).done){t.next=30;break}x=O.value,P=h([].concat(v.name));case 14:if((w=P()).done){t.next=26;break}return E=w.value,k=u().resolve(x,E),f.push(k),t.next=20,i().isFile(k);case 20:if(!t.sent){t.next=24;break}return v.binaryFilePath=k,s.server.runner=v,t.abrupt("break",26);case 24:t.next=14;break;case 26:if(!Object.prototype.hasOwnProperty.call(s.server,"runner")){t.next=28;break}return t.abrupt("break",30);case 28:t.next=11;break;case 30:if(!Object.prototype.hasOwnProperty.call(s.server,"runner")){t.next=32;break}return t.abrupt("break",34);case 32:t.next=8;break;case 34:if(Object.prototype.hasOwnProperty.call(s.server,"runner")){t.next=36;break}throw new Error('No binary file in one of the following locations found: "'+f.join('", "')+'".');case 36:case"end":return t.stop()}}),t)})));return function(){return t.apply(this,arguments)}}(),e.loadService=function(){var e=n()(o().mark((function e(t){var r,n,a,l,p,_,d,m,f,v,g,O,x,P,w,E,k,D,j,M,A,C,T,R,I,S,U,L,W,N,B,K,q,z,H,F,G,V,J,$,Y,X,Z,Q,ee,te,re,ne,ae,oe,ce,ie,se,le,ue,pe,_e,de,me,fe,ye,be,he,ve,ge,Oe,xe,Pe,we,Ee,ke,De,je,Me,Ae,Ce,Te,Re,Ie,Se,Ue,Le,We,Ne,Be,Ke,qe,ze,He,Fe,Ge,Ve,Je,$e;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=t.configuration,n=t.services,a=null,l=n.couchdb,!Object.prototype.hasOwnProperty.call(l.server,"runner")){e.next=10;break}return e.next=6,b.default.startServer(n,r);case 6:l.server.restart=b.default.restartServer,l.server.start=b.default.startServer,l.server.stop=b.default.stopServer,a=new Promise((function(e,t){l.server.resolve=e,l.server.reject=t}));case 10:if(!Object.prototype.hasOwnProperty.call(l,"connection")){e.next=12;break}return e.abrupt("return",{couchdb:a});case 12:if(p=i().stringFormat(r.couchdb.url,r.couchdb.user.name+":"+r.couchdb.user.password+"@"),!r.couchdb.ensureAdminPresence){e.next=44;break}return _=new l.connector(i().stringFormat(r.couchdb.url,"")+"/_users",b.default.getConnectorOptions(r)),e.prev=15,e.next=18,_.allDocs();case 18:return e.next=21,c.globalContext.fetch(i().stringFormat(r.couchdb.url,"")+"/"+l.server.runner.adminUserConfigurationPath+"/"+r.couchdb.user.name,{body:'"'+r.couchdb.user.password+'"',method:"PUT"});case 21:e.next=41;break;case 23:if(e.prev=23,e.t0=e.catch(15),"unauthorized"!==e.t0.name){e.next=40;break}return d=new l.connector(p+"/_users",b.default.getConnectorOptions(r)),e.prev=27,e.next=30,d.allDocs();case 30:e.next=35;break;case 32:e.prev=32,e.t1=e.catch(27);case 35:return e.prev=35,d.close(),e.finish(35);case 38:e.next=41;break;case 40:case 41:return e.prev=41,_.close(),e.finish(41);case 44:if(!r.couchdb.ensureUserPresence){e.next=79;break}m=0,f=[r.couchdb.security.admins,r.couchdb.security.members];case 46:if(!(m<f.length)){e.next=79;break}v=f[m],g=h(v.names);case 49:if((O=g()).done){e.next=76;break}return x=O.value,P=new l.connector(p+"/_users",b.default.getConnectorOptions(r)),e.prev=52,e.next=55,P.get("org.couchdb.user:"+x);case 55:e.next=71;break;case 57:if(e.prev=57,e.t2=e.catch(52),"not_found"!==e.t2.error){e.next=70;break}return e.prev=60,e.next=63,P.put(((w={})[r.couchdb.model.property.name.special.id]="org.couchdb.user:"+x,w.name=x,w.password=x,w.roles=[].concat(v.roles.includes(x+"s")?x+"s":[]),w.type="user",w));case 63:e.next=68;break;case 65:throw e.prev=65,e.t3=e.catch(60),new Error("Couldn't create missing user \""+x+'": '+i().represent(e.t3));case 68:e.next=71;break;case 70:throw new Error("Couldn't check for presence of user \""+x+'": '+i().represent(e.t2));case 71:return e.prev=71,P.close(),e.finish(71);case 74:e.next=49;break;case 76:m++,e.next=46;break;case 79:if(!r.couchdb.model.updateConfiguration){e.next=134;break}E=h(r.couchdb.backend.prefixes);case 81:if((k=E()).done){e.next=134;break}D=k.value,e.t4=o().keys(r.couchdb.backend.configuration);case 84:if((e.t5=e.t4()).done){e.next=132;break}if(j=e.t5.value,!Object.prototype.hasOwnProperty.call(r.couchdb.backend.configuration,j)){e.next=130;break}return M="/"+D+(D.trim()?"/":"")+j,A=""+p+M,C=r.couchdb.backend.configuration[j],T=void 0,e.prev=91,e.next=94,c.globalContext.fetch(A);case 94:T=e.sent,e.next=100;break;case 97:e.prev=97,e.t6=e.catch(91);case 100:if(!T){e.next=130;break}if(!T.ok){e.next=129;break}if(R=!0,"function"!=typeof T.text){e.next=115;break}return e.prev=104,e.t7=C,e.next=108,T["string"==typeof C?"text":"json"]();case 108:e.t8=e.sent,R=e.t7===e.t8,e.next=115;break;case 112:e.prev=112,e.t9=e.catch(104);case 115:if(!R){e.next=126;break}return e.prev=116,e.next=119,c.globalContext.fetch(A,{body:'"'+r.couchdb.backend.configuration[j]+'"',method:"PUT"});case 119:e.next=124;break;case 121:e.prev=121,e.t10=e.catch(116);case 124:e.next=127;break;case 126:case 127:e.next=130;break;case 129:case 130:e.next=84;break;case 132:e.next=81;break;case 134:return e.next=136,b.default.initializeConnection(n,r);case 136:if(I=r.couchdb.model.property.name.special.id,S=r.couchdb.model.property.name.special.type,!r.couchdb.ensureSecuritySettingsPresence){e.next=147;break}return e.prev=139,e.next=142,c.globalContext.fetch(p+"/"+r.couchdb.databaseName+"/_security",{body:JSON.stringify(r.couchdb.security),method:"PUT"});case 142:e.next=147;break;case 144:e.prev=144,e.t11=e.catch(139);case 147:if(delete(U=i().copy(r.couchdb.model)).property.defaultSpecification,delete U.entities,L=b.default.extendModels(r.couchdb.model),!r.couchdb.model.updateValidation){e.next=215;break}return e.next=154,s.promises.readFile(c.currentRequire.resolve("./databaseHelper"),{encoding:r.core.encoding,flag:"r"});case 154:W=e.sent,N=h([{description:"Model specification",methodName:"validateDocumentUpdate",name:"validation",serializedParameter:JSON.stringify(U)+", "+JSON.stringify(L)},{description:"Authorisation",methodName:"authenticate",name:"authentication",serializedParameter:JSON.stringify(b.default.determineAllowedModelRolesMapping(r.couchdb.model))+", '"+I+"', '"+S+"', '"+r.couchdb.model.property.name.special.designDocumentNamePrefix+"'"}]);case 156:if((B=N()).done){e.next=171;break}K=B.value,q="function(...parameters) {\n return require('helper').default."+K.methodName+"(...parameters.concat(["+K.serializedParameter+"]))\n}",e.prev=159,new Function("return "+q),e.next=166;break;case 163:throw e.prev=163,e.t12=e.catch(159),new Error("Generated "+K.name+' code "'+q+"\" doesn't compile: "+i().represent(e.t12));case 166:return r.core.debug,e.next=169,b.default.ensureValidationDocumentPresence(l.connection,K.name,{helper:W,validate_doc_update:q},K.description,!0,I,U.property.name.special.designDocumentNamePrefix);case 169:e.next=156;break;case 171:z=0,H=Object.entries(L);case 172:if(!(z<H.length)){e.next=215;break}F=H[z],G=F[0],V=F[1],J=0,$=Object.entries(V);case 175:if(!(J<$.length)){e.next=212;break}if(Y=$[J],X=Y[0],Z=Y[1],![U.property.name.special.constraint.execution,U.property.name.special.constraint.expression].includes(X)){e.next=193;break}Q=h([].concat(Z));case 179:if((ee=Q()).done){e.next=191;break}if(!(te=ee.value).description){e.next=189;break}e.prev=182,new Function("return "+te.description),e.next=189;break;case 186:throw e.prev=186,e.t13=e.catch(182),new Error('Specified constraint description "'+te.description+'" for model "'+G+'" doesn\'t compile: "'+i().represent(e.t13)+'".');case 189:e.next=179;break;case 191:e.next=209;break;case 193:re=Z,ne=h(["conflictingConstraintExpression","conflictingConstraintExecution","constraintExpression","constraintExecution"]);case 195:if((ae=ne()).done){e.next=209;break}if(oe=ae.value,null===re||"object"!=typeof re){e.next=207;break}if(null==(ce=re[oe])||!ce.description){e.next=207;break}e.prev=200,new Function(ce.description),e.next=207;break;case 204:throw e.prev=204,e.t14=e.catch(200),new Error('Specified constraint description "'+ce.description+'" for model "'+G+'" in property "'+X+'" as "'+oe+'" doesn\'t compile: "'+i().represent(e.t14)+'".');case 207:e.next=195;break;case 209:J++,e.next=175;break;case 212:z++,e.next=172;break;case 215:if(!r.couchdb.model.autoMigrationPath){e.next=307;break}return ie={},e.next=219,i().isDirectory(u().resolve(r.couchdb.model.autoMigrationPath));case 219:if(!e.sent){e.next=259;break}return e.t15=h,e.next=223,i().walkDirectoryRecursively(u().resolve(r.couchdb.model.autoMigrationPath),r.couchdb.debug?i().noop:function(e){return"debug"!==e.name});case 223:e.t16=e.sent,se=(0,e.t15)(e.t16);case 225:if((le=se()).done){e.next=259;break}if(ue=le.value,pe=u().extname(ue.name),_e=u().basename(ue.name,pe),".json"!==pe){e.next=256;break}return de=void 0,e.prev=231,e.t17=JSON,e.next=235,s.promises.readFile(ue.path,{encoding:r.core.encoding,flag:"r"});case 235:e.t18=e.sent,de=e.t17.parse.call(e.t17,e.t18),e.next=242;break;case 239:throw e.prev=239,e.t19=e.catch(231),new Error('Parsing document "'+ue.path+'" to include by automigration of has failed: '+i().represent(e.t19));case 242:return de[I]=_e,de[r.couchdb.model.property.name.special.revision]="upsert",e.prev=244,e.next=247,l.connection.put(de);case 247:e.next=253;break;case 249:throw e.prev=249,e.t20=e.catch(244),null!=(me=e.t20.forbidden)&&me.startsWith("NoChange:"),new Error('Migrating document "'+de[I]+'" of type "'+de[S]+'" has failed: '+i().represent(e.t20));case 253:e.next=257;break;case 256:".js"===u().extname(ue.name)&&(ie[ue.path]=(0,c.currentRequire)(ue.path).default);case 257:e.next=225;break;case 259:return e.t21=h,e.next=262,l.connection.allDocs({include_docs:!0});case 262:e.t22=e.sent.rows,fe=(0,e.t21)(e.t22);case 264:if((ye=fe()).done){e.next=307;break}if("string"==typeof(be=ye.value).id&&be.id.startsWith(r.couchdb.model.property.name.special.designDocumentNamePrefix)){e.next=305;break}he=be.doc,(ve=i().copy(he))[r.couchdb.model.property.name.special.strategy]="migrate",ge=h(Object.keys(ie).sort());case 271:if((Oe=ge()).done){e.next=284;break}xe=Oe.value,Pe=null,e.prev=274,Pe=ie[xe](ve,{configuration:r,databaseHelper:y(),idName:I,migrater:ie,models:L,modelConfiguration:U,selfFilePath:xe,services:n,tools:i(),typeName:S}),e.next=281;break;case 278:throw e.prev=278,e.t23=e.catch(274),new Error('Running migrater "'+xe+'" in document '+b.default.mayStripRepresentation(he,r.couchdb.maximumRepresentationTryLength,r.couchdb.maximumRepresentationLength)+'" failed: '+i().represent(e.t23));case 281:Pe&&(ve=Pe);case 282:e.next=271;break;case 284:e.prev=284,y().validateDocumentUpdate(i().copy(ve),i().copy(he),{db:r.couchdb.databaseName,name:r.couchdb.user.name,roles:["_admin"]},i().copy(r.couchdb.security),U,L),e.next=296;break;case 288:if(e.prev=288,e.t24=e.catch(284),!Object.prototype.hasOwnProperty.call(e.t24,"forbidden")){e.next=295;break}return e.t24.forbidden.startsWith("NoChange:"),e.abrupt("continue",305);case 295:throw e.t24;case 296:return e.prev=296,e.next=299,l.connection.put(ve);case 299:e.next=304;break;case 301:throw e.prev=301,e.t25=e.catch(296),new Error('Replaceing auto migrated document "'+ve[I]+'" has failed: '+i().represent(e.t25));case 304:case 305:e.next=264;break;case 307:if(!r.couchdb.createGenericFlatIndex||!r.couchdb.model.autoMigrationPath){e.next=362;break}return e.next=310,l.connection.getIndexes();case 310:we=e.sent.indexes,Ee=0,ke=Object.entries(L);case 312:if(!(Ee<ke.length)){e.next=343;break}if(De=ke[Ee],je=De[0],Me=De[1],!new RegExp(r.couchdb.model.property.name.typeRegularExpressionPattern.public).test(je)){e.next=340;break}return e.next=317,l.connection.createIndex({index:{ddoc:je+"-GenericIndex",fields:[S],name:je+"-GenericIndex"}});case 317:Ae=h(b.default.determineGenericIndexablePropertyNames(r.couchdb.model,Me));case 318:if((Ce=Ae()).done){e.next=340;break}Te=Ce.value,Re=je+"-"+Te+"-GenericIndex",Ie=-1,Se=0,Ue=h(we);case 324:if((Le=Ue()).done){e.next=332;break}if(Le.value.name!==Re){e.next=329;break}return Ie=Se,e.abrupt("break",332);case 329:Se+=1;case 330:e.next=324;break;case 332:if(-1!==Ie){e.next=337;break}return e.next=335,l.connection.createIndex({index:{ddoc:Re,fields:[S,Te],name:Re}});case 335:e.next=338;break;case 337:we.slice(Se,1);case 338:e.next=318;break;case 340:Ee++,e.next=312;break;case 343:We=h(we);case 344:if((Ne=We()).done){e.next=362;break}if(!(Be=Ne.value).name.endsWith("-GenericIndex")){e.next=360;break}Ke=!1,qe=0,ze=Object.entries(L);case 349:if(!(qe<ze.length)){e.next=357;break}if(He=ze[qe],Fe=He[0],Ge=He[1],!Be.name.startsWith(Fe+"-")){e.next=354;break}for(Ve=h(b.default.determineGenericIndexablePropertyNames(r.couchdb.model,Ge));!(Je=Ve()).done;)$e=Je.value,[Fe+"-"+$e+"-GenericIndex",Fe+"-GenericIndex"].includes(Be.name)&&(Ke=!0);return e.abrupt("break",357);case 354:qe++,e.next=349;break;case 357:if(Ke){e.next=360;break}return e.next=360,l.connection.deleteIndex(Be);case 360:e.next=344;break;case 362:if(!r.couchdb.model.triggerInitialCompaction){e.next=371;break}return e.prev=363,e.next=366,l.connection.compact();case 366:e.next=371;break;case 368:e.prev=368,e.t26=e.catch(363);case 371:return e.abrupt("return",{couchdb:a});case 372:case"end":return e.stop()}}),e,null,[[15,23,41,44],[27,32,35,38],[52,57,71,74],[60,65],[91,97],[104,112],[116,121],[139,144],[159,163],[182,186],[200,204],[231,239],[244,249],[274,278],[284,288],[296,301],[363,368]])})));return function(){return e.apply(this,arguments)}}(),e.postLoadService=function(r){var a=r.configuration.couchdb,c=r.pluginAPI,s=r.services.couchdb,l=0;setInterval((function(){0<l&&(l=0)}),3e4);var u=i().debounce(n()(o().mark((function p(){return o().wrap((function(p){for(;;)switch(p.prev=p.next){case 0:return s.changesStream&&s.changesStream.cancel(),s.changesStream=s.connection.changes(i().extend(!0,i().copy(a.changesStream),e.additionalChangesStreamOptions)),s.changesStream.on("error",n()(o().mark((function e(){return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(3<(l+=1))){e.next=9;break}return l=0,s.changesStream.cancel(),e.next=7,s.server.restart(r);case 7:e.next=10;break;case 9:case 10:u();case 11:case"end":return e.stop()}}),e)})))),p.next=5,c.callStack(t()({},r,{data:s.changesStream,hook:"couchdbInitializeChangesStream"}));case 5:case"end":return p.stop()}}),p)}))));return a.attachAutoRestarter&&u(),Promise.resolve()},e.shouldExit=function(){var e=n()(o().mark((function e(t){var r,n,a;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.configuration,n=t.services,e.next=3,b.default.stopServer(n,r);case 3:return delete n.couchdb,a="log.txt",e.next=7,i().isFile(a);case 7:if(!e.sent){e.next=10;break}return e.next=10,s.promises.unlink(a);case 10:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),e}();g.additionalChangesStreamOptions={},g.skipIDDetermining=!0,g.toggleIDDetermining=Symbol("toggleIDDetermining");const O=g})(),module.exports=__webpack_exports__})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "couchdb-web-node-plugin",
3
- "version": "1.0.523",
3
+ "version": "1.0.526",
4
4
  "description": "A couchdb server, model instance conflict handler, rest api, authentication, session management, schema validator and model relation guarantee for webNode.",
5
5
  "keywords": [
6
6
  "api",
package/type.d.ts CHANGED
@@ -14,8 +14,7 @@
14
14
  import { ChildProcess } from 'child_process';
15
15
  import Tools from 'clientnode';
16
16
  import { AnyFunction, Mapping, PlainObject, Primitive, ProcessCloseReason } from 'clientnode/type';
17
- import { PluginAPI } from 'web-node';
18
- import { Configuration as BaseConfiguration, Plugin, PluginHandler as BasePluginHandler, Service as BaseService, ServicePromises as BaseServicePromises, Services as BaseServices } from 'web-node/type';
17
+ import { Configuration as BaseConfiguration, PluginHandler as BasePluginHandler, ServicePromises as BaseServicePromises, Services as BaseServices, ServicePromisesState as BaseServicePromisesState, ServicesState as BaseServicesState } from 'web-node/type';
19
18
  import DatabaseHelper from './databaseHelper';
20
19
  export declare type Attachments = PouchDB.Core.Attachments;
21
20
  export declare type FullAttachment = PouchDB.Core.FullAttachment;
@@ -251,52 +250,43 @@ export declare type Configuration<ConfigurationType = Mapping<unknown>> = BaseCo
251
250
  };
252
251
  };
253
252
  }> & ConfigurationType;
254
- export interface Service extends BaseService {
255
- name: 'couchdb';
256
- promise: null | Promise<ProcessCloseReason>;
253
+ export interface CouchDB {
254
+ changesStream: ChangesStream;
255
+ connection: Connection;
256
+ connector: Connector;
257
+ server: {
258
+ process: ChildProcess;
259
+ reject: (value: ProcessCloseReason) => void;
260
+ resolve: (reason: ProcessCloseReason) => void;
261
+ restart: (state: State) => Promise<void>;
262
+ runner: Runner;
263
+ start: (services: Services, configuration: Configuration) => Promise<void>;
264
+ stop: (services: Services, configuration: Configuration) => Promise<void>;
265
+ };
257
266
  }
258
- export declare type ServicePromises<ServicePromiseType = Mapping<unknown>> = BaseServicePromises<{
267
+ export declare type ServicePromises<Type = Mapping<unknown>> = BaseServicePromises<{
259
268
  couchdb: Promise<ProcessCloseReason>;
260
- }> & ServicePromiseType;
261
- export declare type Services<ServiceType = Mapping<unknown>> = BaseServices<{
262
- couchdb: {
263
- connection: Connection;
264
- connector: Connector;
265
- server: {
266
- process: ChildProcess;
267
- reject: (_value: ProcessCloseReason) => void;
268
- resolve: (_reason: ProcessCloseReason) => void;
269
- restart: (_services: Services, _configuration: Configuration, _plugins: Array<Plugin>, _pluginAPI: typeof PluginAPI) => Promise<void>;
270
- runner: Runner;
271
- start: (_services: Services, _configuration: Configuration) => Promise<void>;
272
- stop: (_services: Services, _configuration: Configuration) => Promise<void>;
273
- };
274
- };
275
- }> & ServiceType;
269
+ }> & Type;
270
+ export declare type Services<Type = Mapping<unknown>> = BaseServices<{
271
+ couchdb: CouchDB;
272
+ }> & Type;
273
+ export declare type ServicesState<Type = undefined> = BaseServicesState<Type, Configuration, Services>;
274
+ export declare type State<Type = undefined> = BaseServicePromisesState<Type, Configuration, Services, ServicePromises>;
276
275
  export interface PluginHandler extends BasePluginHandler {
277
276
  /**
278
277
  * Hook after each data change.
279
- * @param _changesStream - Stream of database changes.
280
- * @param _services - List of other web-node plugin services.
281
- * @param _configuration - Configuration object extended by each plugin
282
- * specific configuration.
283
- * @param _plugins - Topological sorted list of plugins.
284
- * @param _pluginAPI - Plugin api reference.
278
+ * @param state - Application state.
285
279
  *
286
- * @returns Given entry files.
280
+ * @returns Promise resolving to nothing.
287
281
  */
288
- couchdbInitializeChangesStream?(_changesStream: ChangesStream, _services: Services, _configuration: Configuration, _plugins: Array<Plugin>, _pluginAPI: typeof PluginAPI): ChangesStream;
282
+ couchdbInitializeChangesStream?(state: State<ChangesStream>): Promise<void>;
289
283
  /**
290
284
  * Hook after each data base restart.
291
- * @param _services - List of other web-node plugin services.
292
- * @param _configuration - Configuration object extended by each plugin
293
- * specific configuration.
294
- * @param _plugins - Topological sorted list of plugins.
295
- * @param _pluginAPI - Plugin api reference.
285
+ * @param state - Application state.
296
286
  *
297
- * @returns Given entry files.
287
+ * @returns Promise resolving to nothing.
298
288
  */
299
- restartCouchdb?(_services: Services, _configuration: Configuration, _plugins: Array<Plugin>, _pluginAPI: typeof PluginAPI): Services;
289
+ restartCouchdb?(state: State): Promise<void>;
300
290
  }
301
291
  export interface EmptyEvaluationExceptionData {
302
292
  empty: string;
@@ -315,10 +305,10 @@ export interface RuntimeExceptionData<S = Mapping<unknown>> extends EvaluationEx
315
305
  }
316
306
  export declare type EvaluationException<S = Mapping<unknown>> = Exception<EvaluationExceptionData<S>>;
317
307
  export interface BasicScope {
318
- attachmentWithPrefixExists: (_namePrefix: string) => boolean;
319
- checkDocument: (_newDocument: PartialFullDocument, _oldDocument: PartialFullDocument | null, _parentNames: Array<string>) => CheckedDocumentResult;
320
- getFileNameByPrefix: (_prefix?: string, _attachments?: Attachments) => null | string;
321
- serialize: (_value: unknown) => string;
308
+ attachmentWithPrefixExists: (namePrefix: string) => boolean;
309
+ checkDocument: (newDocument: PartialFullDocument, oldDocument: PartialFullDocument | null, parentNames: Array<string>) => CheckedDocumentResult;
310
+ getFileNameByPrefix: (prefix?: string, attachments?: Attachments) => null | string;
311
+ serialize: (value: unknown) => string;
322
312
  id: string;
323
313
  revision: string;
324
314
  idName: string;
@@ -333,7 +323,7 @@ export interface BasicScope {
333
323
  userContext: Partial<UserContext>;
334
324
  }
335
325
  export interface CommonScope {
336
- checkPropertyContent: (_newValue: unknown, _name: string, _propertySpecification: PropertySpecification, _oldValue: unknown) => CheckedPropertyResult;
326
+ checkPropertyContent: (newValue: unknown, name: string, propertySpecification: PropertySpecification, oldValue: unknown) => CheckedPropertyResult;
337
327
  model: Model;
338
328
  modelName: string;
339
329
  type: string;
@@ -353,7 +343,7 @@ export interface EvaluationResult<T = unknown, S = BasicScope & CommonScope> {
353
343
  result: T;
354
344
  scope: S;
355
345
  }
356
- export declare type Evaluate<R = unknown, P = unknown> = (..._parameters: Array<P>) => R;
346
+ export declare type Evaluate<R = unknown, P = unknown> = (...parameters: Array<P>) => R;
357
347
  export interface CheckedResult {
358
348
  changedPath: Array<string>;
359
349
  }