couchdb-web-node-plugin 1.0.588 → 1.0.590

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.
@@ -1,6 +1,6 @@
1
1
  import { AllowedModelRolesMapping, BaseModelConfiguration, Document, Models, PartialFullDocument, SecuritySettings, UserContext } from './type';
2
2
  /**
3
- * A dumm plugin interface with all available hooks.
3
+ * WebNode plugin interface with all provided hooks.
4
4
  */
5
5
  export declare class DatabaseHelper {
6
6
  /**
@@ -43,6 +43,6 @@ export declare class DatabaseHelper {
43
43
  *
44
44
  * @returns Modified given new document.
45
45
  */
46
- static validateDocumentUpdate(this: void, newDocument: PartialFullDocument, oldDocument: PartialFullDocument | null, userContext: Partial<UserContext>, securitySettings: Partial<SecuritySettings>, modelConfiguration: BaseModelConfiguration, models?: Models, toJSON?: (_value: unknown) => string): PartialFullDocument;
46
+ static validateDocumentUpdate(this: void, newDocument: PartialFullDocument, oldDocument: PartialFullDocument | null, userContext: Partial<UserContext>, securitySettings: Partial<SecuritySettings>, modelConfiguration: BaseModelConfiguration, models?: Models, toJSON?: (value: unknown) => string): PartialFullDocument;
47
47
  }
48
48
  export default DatabaseHelper;
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=function(){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}}()?Reflect.construct.bind():function(e,t,r){var o=[null];o.push.apply(o,t);var a=new(Function.bind.apply(e,o));return r&&n(a,r.prototype),a}).apply(null,arguments)}function n(e,t){return n=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},n(e,t)}function o(){return o=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},o.apply(this,arguments)}function a(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 i(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)?i(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 i(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:()=>l,default:()=>c});var l=function(){function e(){}return e.authenticate=function(e,t,r,n,o,i,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===i&&(i="_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,i)&&e[i].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=a(["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=a(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,i,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(i,l.property.name.validatedDocumentsCache)&&i[l.property.name.validatedDocumentsCache].has(v+"-"+O))return i[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=a([].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=[d.additional,d.allowedRole,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],z=function(e){return e instanceof Error?""+e:P(e)},R=function(e){return"string"==typeof e?e.trim():""},M=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},U=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},_=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},H=function(e,t,n){void 0===t&&(t=!1),void 0===n&&(n={});var a=R(e);if(a){var i,l=(t?"return ":"")+a,c=o({},I,{code:l},n),p=Object.keys(c);try{i=r(Function,p.concat([l]))}catch(e){s(z(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(z(e),"runtime",{code:l,error:e,scope:c})}return u}s("No expression to evaluate provided.","empty")},L=function(e,t,n){void 0===n&&(n=[]);var o=n.length?" in "+n.join(" -> "):"",i=[],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(i,l,c,p,y){void 0===y&&(y=["constraintExecution","constraintExpression"]);for(var d,f,h=a(y);!(d=h()).done;)if(f=d.value,Object.prototype.hasOwnProperty.call(c,f)){var g=void 0;try{g=H(c[f].evaluation,f.endsWith("Expression"),{checkPropertyContent:P,model:m,modelName:u,name:l,type:f,newDocument:e,newValue:i,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(g&&!g.result){var v=R(c[f].description);s(f.charAt(0).toUpperCase()+(f.substring(1)+": ")+(v?r(Function,Object.keys(g.scope).concat(["return "+v])).apply(void 0,Object.values(g.scope)):'Property "'+l+'" should satisfy constraint "'+g.code+'" (given "'+z(i)+'")'+o+"."))}}},P=function(e,t,r,i){void 0===i&&(i=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=a(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=L(e,i,n.concat(t));if(v.changedPath.length&&(l=v.changedPath),e=v.newDocument,z(e)===z({}))return{newValue:null,changedPath:l};d=!0;break}1===p.length&&s('NestedType: Under key "'+t+'" isn\'t of type "'+m+'" (given "'+z(e)+'" of type '+typeof e+")"+o+".")}else if("DateTime"===m){var b=e;if(e=M(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 "'+z(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 "'+z(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 "'+z(e)+'" of type "'+typeof e+'")'+o+".")}else{if("any"===m||z(e)===z(m)){d=!0;break}1===p.length&&s('PropertyType: Property "'+t+'" isn\'t value "'+m+'" (given "'+z(e).replace(/^"/,"").replace(/"$/,"")+'" of type "'+typeof e+'")'+o+".")}if(d||s('PropertyType: None of the specified types "'+p.join('", "')+'" for property "'+t+'" matches value "'+z(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(M)),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,i),z(e)!==z(i)&&(l=n.concat(t,"value updated")),{newValue:e,changedPath:l}},x=function(e,t,r,o,a){var c=t[o];if(!e.writable)if(r){if(Object.prototype.hasOwnProperty.call(r,o)&&z(c)===z(r[o]))return o!==f&&"incremental"===w&&delete t[o],!0;s('Readonly: Property "'+o+'" is not writable (old document "'+z(r)+'")'+a+".")}else s('Readonly: Property "'+o+'" is not writable'+a+".");if(!e.mutable&&r&&Object.prototype.hasOwnProperty.call(r,o)){if(z(c)===z(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 "'+z(r)+'")'+a+".")}if(null===c){if(e.nullable)return delete t[o],r&&Object.prototype.hasOwnProperty.call(r,o)&&(i=n.concat(o,"delete property")),!0;s('NotNull: Property "'+o+'" should not be "null"'+a+".")}return!1},N=function(e,t,r,i){if(!r)for(var l,c,p=a(["onCreateExecution","onCreateExpression"]);!(l=p()).done;)if(c=l.value,Object.prototype.hasOwnProperty.call(e,c)){var y=void 0;try{y=H(e[c],c.endsWith("Expression"),{checkPropertyContent:P,model:m,modelName:u,name:i,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 "'+i+'": '+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 "'+i+'": '+e.message+o+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}y&&![null,void 0].includes(y.result)&&(t[i]=y.result)}},A=function(e,t,r,i){if(Object.prototype.hasOwnProperty.call(t,i)){e.trim&&"string"==typeof t[i]&&(t[i]=t[i].trim()),e.emptyEqualsToNull&&(""===t[i]||Array.isArray(t[i])&&0===t[i].length||null!==t[i]&&"object"==typeof t[i]&&0===Object.keys(t).length)&&(t[i]=null);for(var l,c,p=a(["onUpdateExecution","onUpdateExpression"]);!(l=p()).done;)if(c=l.value,Object.prototype.hasOwnProperty.call(e,c))try{t[i]=H(e[c],c.endsWith("Expression"),{checkPropertyContent:P,model:m,modelName:u,name:i,type:c,newDocument:t,oldDocument:r,newValue:t[i],oldValue:r&&r[i],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 "'+i+'": '+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 "'+i+'": '+e.message+o+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}}},C=Object.keys(m).filter((function(e){return!D.includes(e)}));if("migrate"===w)for(var S,k,T=a(C);!(S=T()).done;)if(k=S.value,![null,void 0].includes(m[k].oldName))for(var E,_,I=a([].concat(m[k].oldName));!(E=I()).done;)_=E.value,Object.prototype.hasOwnProperty.call(e,_)&&(e[k]=e[_],delete e[_]);if(!t)for(var W,V=0,F=[d.create.execution,d.create.expression];V<F.length;V++)if(W=F[V],Object.prototype.hasOwnProperty.call(m,W)){var B=void 0;try{B=H(m[W],W.endsWith("Expression"),{checkPropertyContent:P,model:m,modelName:u,type:W,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 "'+W+'" has invalid code "'+e.code+'" for document "'+u+'": '+e.message+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&s('Runtime: Hook "'+W+'" 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(B)||(e=B),p(),u=e[g],0===n.length&&b()}for(var $,q=0,Y=[d.update.execution,d.update.expression];q<Y.length;q++)if($=Y[q],Object.prototype.hasOwnProperty.call(m,$)){var J=void 0;try{J=H(m[$],$.endsWith("Expression"),{checkPropertyContent:P,model:m,modelName:u,type:$,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 "'+$+'" has invalid code "'+e.code+'" for document "'+u+'": '+e.message+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&s('Runtime: Hook "'+$+'" 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(J)||(e=J),p(),u=e[g],0===n.length&&b()}for(var G,K=function(){var r=G.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&&U(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)&&!!U(u,e,m)}))}for(var g,v,O=m,b=a(y);!(g=b()).done;)v=g.value,N(O,d,t&&t[r]?t[r]:null,v);for(var P,j,x=a(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=a(f);!(C=k()).done;)S=C.value,null===d[S]?i=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],i=n.concat(r,u,"add default file"));else if("fillUp"===w)for(var E,D,z=a(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&&(i=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,i=n.concat(r,"migrate default value")):(e[r]=u.default,i=i.concat(r,"add default value")))}},Z=a(C.concat(v?Object.keys(e).filter((function(e){return!C.includes(e)})):[]));!(G=Z()).done;)K();if(t&&"incremental"===w)for(var Q=0,X=Object.entries(e);Q<X.length;Q++){var ee=X[Q],te=ee[0],re=ee[1];Object.prototype.hasOwnProperty.call(t,te)&&!l.property.name.reserved.concat(f,h,d.conflict,d.deleted,d.deletedConflict,d.localSequence,d.revisions,d.revisionsInformation,g).includes(te)&&(t[te]===re||z(t[te])===z(re))&&delete e[te]}for(var ne=0,oe=Object.entries(e);ne<oe.length;ne++){var ae=oe[ne],ie=ae[0],le=ae[1];if(!l.property.name.reserved.concat(h,d.conflict,d.deleted,d.deletedConflict,d.localSequence,d.revisions,d.revisionsInformation,d.strategy).includes(ie)){var ce=void 0;if(Object.prototype.hasOwnProperty.call(m,ie))ce=m[ie];else if(v)ce=v;else{if("migrate"===w){delete e[ie],i=n.concat(ie,"migrate removed property");continue}s('Property: Given property "'+ie+'" isn\'t specified in model "'+u+'"'+o+".")}if(!ce)continue;if(d.attachment===ie){var pe=le;for(var se in pe)if(Object.prototype.hasOwnProperty.call(pe,se))for(var ue in m[ie])if(U(ue,se,m[ie][ue])){x(m[ie][ue],e,t,se,o);break}continue}if(x(ce,e,t,ie,o))continue;if("string"==typeof ce.type&&ce.type.endsWith("[]")||Array.isArray(ce.type)&&ce.type.length&&Array.isArray(ce.type[0])){var me,ye=le;Array.isArray(ye)?![null,void 0].includes(ce.minimumNumber)&&ye.length<ce.minimumNumber?s('MinimumArrayLength: Property "'+ie+'" (array of length '+ye.length+") doesn't fullfill minimum array length of "+ce.minimumNumber+o+"."):![null,void 0].includes(ce.maximumNumber)&&ce.maximumNumber<ye.length&&s('MaximumArrayLength: Property "'+ie+'" (array of length '+ye.length+") doesn't fullfill maximum array length of "+ce.maximumNumber+o+"."):s('PropertyType: Property "'+ie+'" isn\'t of type "array -> '+ce.type+'" (given "'+z(ye)+'")'+o+"."),O(ye,ie,ce,t&&Object.prototype.hasOwnProperty.call(t,ie)&&t[ie]||void 0,["arrayConstraintExecution","arrayConstraintExpression"]);var de={};for(var fe in ce)Object.prototype.hasOwnProperty.call(ce,fe)&&(de[fe]="type"===fe?Array.isArray(ce[fe])?ce[fe][0]:[ce[fe].substring(0,ce.type.length-2)]:ce[fe]);if(1===(null==(me=de.type)?void 0:me.length)&&Object.prototype.hasOwnProperty.call(c,de.type[0]))for(var he,ge,ve=a(ye.slice());!(he=ve()).done;)"object"!=typeof(ge=he.value)||Object.getPrototypeOf(ge)!==Object.prototype||Object.prototype.hasOwnProperty.call(ge,g)||(ge[g]=de.type[0]);for(var Oe,be,we=0,Pe=a(ye.slice());!(Oe=Pe()).done;)be=Oe.value,ye[we]=P(be,we+1+". value in "+ie,de).newValue,null===be&&ye.splice(we,1),we+=1;t&&Object.prototype.hasOwnProperty.call(t,ie)&&Array.isArray(t[ie])&&t[ie].length===ye.length&&z(t[ie])===z(ye)||(i=n.concat(ie,"array updated"))}else{var je=t&&Object.prototype.hasOwnProperty.call(t,ie)?t[ie]:null,xe=P(le,ie,ce,je);e[ie]=xe.newValue,xe.changedPath.length&&(i=xe.changedPath),null===e[ie]&&(null!==je&&(i=n.concat(ie,"property removed")),delete e[ie])}}}for(var Ne,Ae=0,Ce=Object.keys(d.constraint);Ae<Ce.length;Ae++)if(Ne=Ce[Ae],(Ne=d.constraint[Ne])&&Object.prototype.hasOwnProperty.call(m,Ne))for(var Se,ke=a([].concat(m[Ne]));!(Se=ke()).done;){var Te=Se.value,Ee=void 0;try{Ee=H(Te.evaluation,Ne===d.constraint.expression,{checkPropertyContent:P,model:m,modelName:u,type:Ne,newDocument:e,oldDocument:t,parentNames:n,pathDescription:o})}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&s('Compilation: Hook "'+Ne+'" has invalid code "'+e.code+'": "'+e.message+'"'+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&s('Runtime: Hook "'+Ne+'" has thrown an error with code "'+e.code+'": '+e.message+o+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}if(Ee&&!Ee.result){var De=Ne.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 "'+z(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)&&(i=n.concat(d.attachment,He,"attachment removed")),"incremental"===w&&delete ze[He]):i=n.concat(d.attachment,He,"attachment updated")}else"fillUp"===w?ze[He]=Le:w||(i=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)&&(i=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(U(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=a(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===i.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)||(i=n.concat(vt,"migrate removed property"));return{changedPath:i,newDocument:e}},I={attachmentWithPrefixExists:function(t){if(Object.prototype.hasOwnProperty.call(e,d.attachment)){var r=e[d.attachment],n=_(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:L,getFileNameByPrefix:_,serialize:z,id:v,revision:O,idName:f,revisionName:h,specialNames:d,typeName:g,modelConfiguration:l,models:c,now:u,nowUTCTimestamp:m,securitySettings:i,userContext:n},W=L(e,t);return(!W.newDocument._deleted||t)&&(W.newDocument._deleted&&W.newDocument._deleted!==(null==t?void 0:t._deleted)||W.changedPath.length)||s("NoChange: No new data given. new document: "+z(e)+"; old document: "+z(t)+"."),Object.prototype.hasOwnProperty.call(i,l.property.name.validatedDocumentsCache)?i[l.property.name.validatedDocumentsCache].add(v+"-"+O):i[l.property.name.validatedDocumentsCache]=new Set([v+"-"+O]),W.newDocument},e}();const c=l;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=function(){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}}()?Reflect.construct.bind():function(e,t,r){var o=[null];o.push.apply(o,t);var a=new(Function.bind.apply(e,o));return r&&n(a,r.prototype),a}).apply(null,arguments)}function n(e,t){return n=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},n(e,t)}function o(){return o=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},o.apply(this,arguments)}function a(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 i(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)?i(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 i(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:()=>l,default:()=>c});var l=function(){function e(){}return e.authenticate=function(e,t,r,n,o,i,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===i&&(i="_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,i)&&e[i].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=a(["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=a(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,i,l,c,p){void 0===c&&(c={});var s=function(e,t,r){var n;throw void 0===t&&(t="forbidden"),void 0===r&&(r={}),o(((n={})[t]=e,n.message=e,n.name=t,n),r)},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(i,l.property.name.validatedDocumentsCache)&&i[l.property.name.validatedDocumentsCache].has(v+"-"+O))return i[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=a([].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=[d.additional,d.allowedRole,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],z=function(e){return e instanceof Error?""+e:P(e)},R=function(e){return"string"==typeof e?e.trim():""},M=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},U=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},_=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},H=function(e,t,n){void 0===t&&(t=!1),void 0===n&&(n={});var a=R(e);if(a){var i,l=(t?"return ":"")+a,c=o({},I,{code:l},n),p=Object.keys(c);try{i=r(Function,p.concat([l]))}catch(e){s(z(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(z(e),"runtime",{code:l,error:e,scope:c})}return u}s("No expression to evaluate provided.","empty")},L=function(e,t,n){void 0===n&&(n=[]);var o=n.length?" in "+n.join(" -> "):"",i=[],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(i,l,c,p,y){void 0===y&&(y=["constraintExecution","constraintExpression"]);for(var d,f,h=a(y);!(d=h()).done;)if(f=d.value,Object.prototype.hasOwnProperty.call(c,f)){var g=void 0;try{g=H(c[f].evaluation,f.endsWith("Expression"),{checkPropertyContent:P,model:m,modelName:u,name:l,type:f,newDocument:e,newValue:i,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(g&&!g.result){var v=R(c[f].description);s(f.charAt(0).toUpperCase()+(f.substring(1)+": ")+(v?r(Function,Object.keys(g.scope).concat(["return "+v])).apply(void 0,Object.values(g.scope)):'Property "'+l+'" should satisfy constraint "'+g.code+'" (given "'+z(i)+'")'+o+"."))}}},P=function(e,t,r,i){void 0===i&&(i=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=a(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=L(e,i,n.concat(t));if(v.changedPath.length&&(l=v.changedPath),e=v.newDocument,z(e)===z({}))return{newValue:null,changedPath:l};d=!0;break}1===p.length&&s('NestedType: Under key "'+t+'" isn\'t of type "'+m+'" (given "'+z(e)+'" of type '+typeof e+")"+o+".")}else if("DateTime"===m){var b=e;if(e=M(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 "'+z(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 "'+z(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 "'+z(e)+'" of type "'+typeof e+'")'+o+".")}else{if("any"===m||z(e)===z(m)){d=!0;break}1===p.length&&s('PropertyType: Property "'+t+'" isn\'t value "'+m+'" (given "'+z(e).replace(/^"/,"").replace(/"$/,"")+'" of type "'+typeof e+'")'+o+".")}if(d||s('PropertyType: None of the specified types "'+p.join('", "')+'" for property "'+t+'" matches value "'+z(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(M)),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,i),z(e)!==z(i)&&(l=n.concat(t,"value updated")),{newValue:e,changedPath:l}},x=function(e,t,r,o,a){var c=t[o];if(!e.writable)if(r){if(Object.prototype.hasOwnProperty.call(r,o)&&z(c)===z(r[o]))return o!==f&&"incremental"===w&&delete t[o],!0;s('Readonly: Property "'+o+'" is not writable (old document "'+z(r)+'")'+a+".")}else s('Readonly: Property "'+o+'" is not writable'+a+".");if(!e.mutable&&r&&Object.prototype.hasOwnProperty.call(r,o)){if(z(c)===z(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 "'+z(r)+'")'+a+".")}if(null===c){if(e.nullable)return delete t[o],r&&Object.prototype.hasOwnProperty.call(r,o)&&(i=n.concat(o,"delete property")),!0;s('NotNull: Property "'+o+'" should not be "null"'+a+".")}return!1},N=function(e,t,r,i){if(!r)for(var l,c,p=a(["onCreateExecution","onCreateExpression"]);!(l=p()).done;)if(c=l.value,Object.prototype.hasOwnProperty.call(e,c)){var y=void 0;try{y=H(e[c],c.endsWith("Expression"),{checkPropertyContent:P,model:m,modelName:u,name:i,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 "'+i+'": '+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 "'+i+'": '+e.message+o+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}y&&![null,void 0].includes(y.result)&&(t[i]=y.result)}},A=function(e,t,r,i){if(Object.prototype.hasOwnProperty.call(t,i)){e.trim&&"string"==typeof t[i]&&(t[i]=t[i].trim()),e.emptyEqualsToNull&&(""===t[i]||Array.isArray(t[i])&&0===t[i].length||null!==t[i]&&"object"==typeof t[i]&&0===Object.keys(t).length)&&(t[i]=null);for(var l,c,p=a(["onUpdateExecution","onUpdateExpression"]);!(l=p()).done;)if(c=l.value,Object.prototype.hasOwnProperty.call(e,c))try{t[i]=H(e[c],c.endsWith("Expression"),{checkPropertyContent:P,model:m,modelName:u,name:i,type:c,newDocument:t,oldDocument:r,newValue:t[i],oldValue:r&&r[i],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 "'+i+'": '+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 "'+i+'": '+e.message+o+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}}},C=Object.keys(m).filter((function(e){return!D.includes(e)}));if("migrate"===w)for(var S,k,T=a(C);!(S=T()).done;)if(k=S.value,![null,void 0].includes(m[k].oldName))for(var E,_,I=a([].concat(m[k].oldName));!(E=I()).done;)_=E.value,Object.prototype.hasOwnProperty.call(e,_)&&(e[k]=e[_],delete e[_]);if(!t)for(var W,V=0,F=[d.create.execution,d.create.expression];V<F.length;V++)if(W=F[V],Object.prototype.hasOwnProperty.call(m,W)){var B=void 0;try{B=H(m[W],W.endsWith("Expression"),{checkPropertyContent:P,model:m,modelName:u,type:W,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 "'+W+'" has invalid code "'+e.code+'" for document "'+u+'": '+e.message+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&s('Runtime: Hook "'+W+'" 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(B)||(e=B),p(),u=e[g],0===n.length&&b()}for(var $,q=0,Y=[d.update.execution,d.update.expression];q<Y.length;q++)if($=Y[q],Object.prototype.hasOwnProperty.call(m,$)){var J=void 0;try{J=H(m[$],$.endsWith("Expression"),{checkPropertyContent:P,model:m,modelName:u,type:$,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 "'+$+'" has invalid code "'+e.code+'" for document "'+u+'": '+e.message+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&s('Runtime: Hook "'+$+'" 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(J)||(e=J),p(),u=e[g],0===n.length&&b()}for(var G,K=function(){var r=G.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&&U(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)&&!!U(u,e,m)}))}for(var g,v,O=m,b=a(y);!(g=b()).done;)v=g.value,N(O,d,t&&t[r]?t[r]:null,v);for(var P,j,x=a(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=a(f);!(C=k()).done;)S=C.value,null===d[S]?i=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],i=n.concat(r,u,"add default file"));else if("fillUp"===w)for(var E,D,z=a(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&&(i=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,i=n.concat(r,"migrate default value")):(e[r]=u.default,i=i.concat(r,"add default value")))}},Z=a(C.concat(v?Object.keys(e).filter((function(e){return!C.includes(e)})):[]));!(G=Z()).done;)K();if(t&&"incremental"===w)for(var Q=0,X=Object.entries(e);Q<X.length;Q++){var ee=X[Q],te=ee[0],re=ee[1];Object.prototype.hasOwnProperty.call(t,te)&&!l.property.name.reserved.concat(f,h,d.conflict,d.deleted,d.deletedConflict,d.localSequence,d.revisions,d.revisionsInformation,g).includes(te)&&(t[te]===re||z(t[te])===z(re))&&delete e[te]}for(var ne=0,oe=Object.entries(e);ne<oe.length;ne++){var ae=oe[ne],ie=ae[0],le=ae[1];if(!l.property.name.reserved.concat(h,d.conflict,d.deleted,d.deletedConflict,d.localSequence,d.revisions,d.revisionsInformation,d.strategy).includes(ie)){var ce=void 0;if(Object.prototype.hasOwnProperty.call(m,ie))ce=m[ie];else if(v)ce=v;else{if("migrate"===w){delete e[ie],i=n.concat(ie,"migrate removed property");continue}s('Property: Given property "'+ie+'" isn\'t specified in model "'+u+'"'+o+".")}if(!ce)continue;if(d.attachment===ie){var pe=le;for(var se in pe)if(Object.prototype.hasOwnProperty.call(pe,se))for(var ue in m[ie])if(U(ue,se,m[ie][ue])){x(m[ie][ue],e,t,se,o);break}continue}if(x(ce,e,t,ie,o))continue;if("string"==typeof ce.type&&ce.type.endsWith("[]")||Array.isArray(ce.type)&&ce.type.length&&Array.isArray(ce.type[0])){var me,ye=le;Array.isArray(ye)?![null,void 0].includes(ce.minimumNumber)&&ye.length<ce.minimumNumber?s('MinimumArrayLength: Property "'+ie+'" (array of length '+ye.length+") doesn't fullfill minimum array length of "+ce.minimumNumber+o+"."):![null,void 0].includes(ce.maximumNumber)&&ce.maximumNumber<ye.length&&s('MaximumArrayLength: Property "'+ie+'" (array of length '+ye.length+") doesn't fullfill maximum array length of "+ce.maximumNumber+o+"."):s('PropertyType: Property "'+ie+'" isn\'t of type "array -> '+ce.type+'" (given "'+z(ye)+'")'+o+"."),O(ye,ie,ce,t&&Object.prototype.hasOwnProperty.call(t,ie)&&t[ie]||void 0,["arrayConstraintExecution","arrayConstraintExpression"]);var de={};for(var fe in ce)Object.prototype.hasOwnProperty.call(ce,fe)&&(de[fe]="type"===fe?Array.isArray(ce[fe])?ce[fe][0]:[ce[fe].substring(0,ce.type.length-2)]:ce[fe]);if(1===(null==(me=de.type)?void 0:me.length)&&Object.prototype.hasOwnProperty.call(c,de.type[0]))for(var he,ge,ve=a(ye.slice());!(he=ve()).done;)"object"!=typeof(ge=he.value)||Object.getPrototypeOf(ge)!==Object.prototype||Object.prototype.hasOwnProperty.call(ge,g)||(ge[g]=de.type[0]);for(var Oe,be,we=0,Pe=a(ye.slice());!(Oe=Pe()).done;)be=Oe.value,ye[we]=P(be,we+1+". value in "+ie,de).newValue,null===be&&ye.splice(we,1),we+=1;t&&Object.prototype.hasOwnProperty.call(t,ie)&&Array.isArray(t[ie])&&t[ie].length===ye.length&&z(t[ie])===z(ye)||(i=n.concat(ie,"array updated"))}else{var je=t&&Object.prototype.hasOwnProperty.call(t,ie)?t[ie]:null,xe=P(le,ie,ce,je);e[ie]=xe.newValue,xe.changedPath.length&&(i=xe.changedPath),null===e[ie]&&(null!==je&&(i=n.concat(ie,"property removed")),delete e[ie])}}}for(var Ne,Ae=0,Ce=Object.keys(d.constraint);Ae<Ce.length;Ae++)if(Ne=Ce[Ae],(Ne=d.constraint[Ne])&&Object.prototype.hasOwnProperty.call(m,Ne))for(var Se,ke=a([].concat(m[Ne]));!(Se=ke()).done;){var Te=Se.value,Ee=void 0;try{Ee=H(Te.evaluation,Ne===d.constraint.expression,{checkPropertyContent:P,model:m,modelName:u,type:Ne,newDocument:e,oldDocument:t,parentNames:n,pathDescription:o})}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&s('Compilation: Hook "'+Ne+'" has invalid code "'+e.code+'": "'+e.message+'"'+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&s('Runtime: Hook "'+Ne+'" has thrown an error with code "'+e.code+'": '+e.message+o+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}if(Ee&&!Ee.result){var De=Ne.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 "'+z(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)&&(i=n.concat(d.attachment,He,"attachment removed")),"incremental"===w&&delete ze[He]):i=n.concat(d.attachment,He,"attachment updated")}else"fillUp"===w?ze[He]=Le:w||(i=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)&&(i=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(U(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=a(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===i.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)||(i=n.concat(vt,"migrate removed property"));return{changedPath:i,newDocument:e}},I={attachmentWithPrefixExists:function(t){if(Object.prototype.hasOwnProperty.call(e,d.attachment)){var r=e[d.attachment],n=_(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:L,getFileNameByPrefix:_,serialize:z,id:v,revision:O,idName:f,revisionName:h,specialNames:d,typeName:g,modelConfiguration:l,models:c,now:u,nowUTCTimestamp:m,securitySettings:i,userContext:n},W=L(e,t);return(!W.newDocument._deleted||t)&&(W.newDocument._deleted&&W.newDocument._deleted!==(null==t?void 0:t._deleted)||W.changedPath.length)||s("NoChange: No new data given. new document: "+z(e)+"; old document: "+z(t)+"."),Object.prototype.hasOwnProperty.call(i,l.property.name.validatedDocumentsCache)?i[l.property.name.validatedDocumentsCache].add(v+"-"+O):i[l.property.name.validatedDocumentsCache]=new Set([v+"-"+O]),W.newDocument},e}();const c=l;module.exports=t})();
package/helper.d.ts CHANGED
@@ -1,122 +1,116 @@
1
1
  import { Mapping } from 'clientnode/type';
2
2
  import { AllowedModelRolesMapping, AllowedRoles, Configuration, Connection, DatabaseConnectorConfiguration, Model, ModelConfiguration, Models, NormalizedAllowedRoles, Services, SpecialPropertyNames, State } from './type';
3
3
  /**
4
- * A dumm plugin interface with all available hooks.
4
+ * Converts internal declarative database connector configuration object
5
+ * into a database compatible one.
6
+ * @param configuration - Mutable by plugins extended configuration object.
7
+ *
8
+ * @returns Database compatible configuration object.
9
+ */
10
+ export declare const getConnectorOptions: (configuration: Configuration) => DatabaseConnectorConfiguration;
11
+ /**
12
+ * Determines a representation for given plain object.
13
+ * @param object - Object to represent.
14
+ * @param maximumRepresentationTryLength - Maximum representation string to
15
+ * process.
16
+ * @param maximumRepresentationLength - Maximum length of returned
17
+ * representation.
18
+ *
19
+ * @returns Representation string.
20
+ */
21
+ export declare const mayStripRepresentation: (object: unknown, maximumRepresentationTryLength: number, maximumRepresentationLength: number) => string;
22
+ /**
23
+ * Updates/creates a design document in database with a validation function
24
+ * set to given code.
25
+ * @param databaseConnection - Database connection to use for document
26
+ * updates.
27
+ * @param documentName - Design document name.
28
+ * @param documentData - Design document data.
29
+ * @param description - Used to produce semantic logging messages.
30
+ * @param log - Enables logging.
31
+ * @param idName - Property name for ids.
32
+ * @param designDocumentNamePrefix - Document name prefix indicating deign
33
+ * documents.
34
+ *
35
+ * @returns Promise which will be resolved after given document has updated
36
+ * successfully.
37
+ */
38
+ export declare const ensureValidationDocumentPresence: (databaseConnection: Connection, documentName: string, documentData: Mapping, description: string, log?: boolean, idName?: SpecialPropertyNames['id'], designDocumentNamePrefix?: string) => Promise<void>;
39
+ /**
40
+ * Initializes a database connection instance.
41
+ * @param services - An object with stored service instances.
42
+ * @param configuration - Mutable by plugins extended configuration object.
43
+ *
44
+ * @returns Given and extended object of services.
45
+ */
46
+ export declare const initializeConnection: (services: Services, configuration: Configuration) => Promise<Services>;
47
+ /**
48
+ * Starts server process.
49
+ * @param services - An object with stored service instances.
50
+ * @param configuration - Mutable by plugins extended configuration object.
51
+ *
52
+ * @returns A promise representing the server process wrapped in a promise
53
+ * which resolves after server is reachable.
54
+ */
55
+ export declare const startServer: (services: Services, configuration: Configuration) => Promise<void>;
56
+ /**
57
+ * Stops open database connection if exist, stops server process, restarts
58
+ * server process and re-initializes server connection.
59
+ * @param state - Application state.
60
+ *
61
+ * @returns Given object of services wrapped in a promise resolving after
62
+ * after finish.
63
+ */
64
+ export declare const restartServer: (state: State) => Promise<void>;
65
+ /**
66
+ * Stops open database connection if exists and stops server process.
67
+ * @param services - An object with stored service instances.
68
+ * @param services.couchdb - Couchdb service instance.
69
+ * @param configuration - Mutable by plugins extended configuration object.
70
+ * @param configuration.couchdb - Mutable by plugins extended configuration
71
+ * object.
72
+ *
73
+ * @returns Given object of services wrapped in a promise resolving after
74
+ * after finish.
75
+ */
76
+ export declare const stopServer: ({ couchdb }: Services, { couchdb: configuration }: Configuration) => Promise<void>;
77
+ /**
78
+ * Determines a mapping of all models to roles who are allowed to edit
79
+ * corresponding model instances.
80
+ * @param modelConfiguration - Model specification object.
81
+ *
82
+ * @returns The mapping object.
83
+ */
84
+ export declare const determineAllowedModelRolesMapping: (modelConfiguration: ModelConfiguration) => AllowedModelRolesMapping;
85
+ /**
86
+ * Determines all property names which are indexable in a generic manner.
87
+ * @param modelConfiguration - Model specification object.
88
+ * @param model - Model to determine property names from.
89
+ *
90
+ * @returns The mapping object.
91
+ */
92
+ export declare const determineGenericIndexablePropertyNames: (modelConfiguration: ModelConfiguration, model: Model) => Array<string>;
93
+ /**
94
+ * Extend given model with all specified one.
95
+ * @param modelName - Name of model to extend.
96
+ * @param models - Pool of models to extend from.
97
+ * @param extendPropertyName - Property name which indicates model
98
+ * inheritance.
99
+ *
100
+ * @returns Given model in extended version.
101
+ */
102
+ export declare const extendModel: (modelName: string, models: Models, extendPropertyName?: string) => Model;
103
+ /**
104
+ * Extend default specification with specific one.
105
+ * @param modelConfiguration - Model specification object.
106
+ *
107
+ * @returns Models with extended specific specifications.
108
+ */
109
+ export declare const extendModels: (modelConfiguration: ModelConfiguration) => Models;
110
+ /**
111
+ * Convert given roles to its normalized representation.
112
+ * @param roles - Unstructured roles description.
113
+ *
114
+ * @returns Normalized roles representation.
5
115
  */
6
- export declare class Helper {
7
- /**
8
- * Converts internal declarative database connector configuration object
9
- * into a database compatible one.
10
- * @param configuration - Mutable by plugins extended configuration object.
11
- *
12
- * @returns Database compatible configuration object.
13
- */
14
- static getConnectorOptions(this: void, configuration: Configuration): DatabaseConnectorConfiguration;
15
- /**
16
- * Determines a representation for given plain object.
17
- * @param object - Object to represent.
18
- * @param maximumRepresentationTryLength - Maximum representation string to
19
- * process.
20
- * @param maximumRepresentationLength - Maximum length of returned
21
- * representation.
22
- *
23
- * @returns Representation string.
24
- */
25
- static mayStripRepresentation(this: void, object: unknown, maximumRepresentationTryLength: number, maximumRepresentationLength: number): string;
26
- /**
27
- * Updates/creates a design document in database with a validation function
28
- * set to given code.
29
- * @param databaseConnection - Database connection to use for document
30
- * updates.
31
- * @param documentName - Design document name.
32
- * @param documentData - Design document data.
33
- * @param description - Used to produce semantic logging messages.
34
- * @param log - Enables logging.
35
- * @param idName - Property name for ids.
36
- * @param designDocumentNamePrefix - Document name prefix indicating deign
37
- * documents.
38
- *
39
- * @returns Promise which will be resolved after given document has updated
40
- * successfully.
41
- */
42
- static ensureValidationDocumentPresence(this: void, databaseConnection: Connection, documentName: string, documentData: Mapping, description: string, log?: boolean, idName?: SpecialPropertyNames['id'], designDocumentNamePrefix?: string): Promise<void>;
43
- /**
44
- * Initializes a database connection instance.
45
- * @param services - An object with stored service instances.
46
- * @param configuration - Mutable by plugins extended configuration object.
47
- *
48
- * @returns Given and extended object of services.
49
- */
50
- static initializeConnection(this: void, services: Services, configuration: Configuration): Promise<Services>;
51
- /**
52
- * Starts server process.
53
- * @param services - An object with stored service instances.
54
- * @param configuration - Mutable by plugins extended configuration object.
55
- *
56
- * @returns A promise representing the server process wrapped in a promise
57
- * which resolves after server is reachable.
58
- */
59
- static startServer(this: void, services: Services, configuration: Configuration): Promise<void>;
60
- /**
61
- * Stops open database connection if exist, stops server process, restarts
62
- * server process and re-initializes server connection.
63
- * @param state - Application state.
64
- *
65
- * @returns Given object of services wrapped in a promise resolving after
66
- * after finish.
67
- */
68
- static restartServer(this: void, state: State): Promise<void>;
69
- /**
70
- * Stops open database connection if exists and stops server process.
71
- * @param services - An object with stored service instances.
72
- * @param services.couchdb - Couchdb service instance.
73
- * @param configuration - Mutable by plugins extended configuration object.
74
- * @param configuration.couchdb - Mutable by plugins extended configuration
75
- * object.
76
- *
77
- * @returns Given object of services wrapped in a promise resolving after
78
- * after finish.
79
- */
80
- static stopServer(this: void, { couchdb }: Services, { couchdb: configuration }: Configuration): Promise<void>;
81
- /**
82
- * Determines a mapping of all models to roles who are allowed to edit
83
- * corresponding model instances.
84
- * @param modelConfiguration - Model specification object.
85
- *
86
- * @returns The mapping object.
87
- */
88
- static determineAllowedModelRolesMapping(this: void, modelConfiguration: ModelConfiguration): AllowedModelRolesMapping;
89
- /**
90
- * Determines all property names which are indexable in a generic manner.
91
- * @param modelConfiguration - Model specification object.
92
- * @param model - Model to determine property names from.
93
- *
94
- * @returns The mapping object.
95
- */
96
- static determineGenericIndexablePropertyNames(this: void, modelConfiguration: ModelConfiguration, model: Model): Array<string>;
97
- /**
98
- * Extend given model with all specified one.
99
- * @param modelName - Name of model to extend.
100
- * @param models - Pool of models to extend from.
101
- * @param extendPropertyName - Property name which indicates model
102
- * inheritance.
103
- *
104
- * @returns Given model in extended version.
105
- */
106
- static extendModel(this: void, modelName: string, models: Models, extendPropertyName?: string): Model;
107
- /**
108
- * Extend default specification with specific one.
109
- * @param modelConfiguration - Model specification object.
110
- *
111
- * @returns Models with extended specific specifications.
112
- */
113
- static extendModels(this: void, modelConfiguration: ModelConfiguration): Models;
114
- /**
115
- * Convert given roles to its normalized representation.
116
- * @param roles - Unstructured roles description.
117
- *
118
- * @returns Normalized roles representation.
119
- */
120
- static normalizeAllowedRoles(this: void, roles: AllowedRoles): NormalizedAllowedRoles;
121
- }
122
- export default Helper;
116
+ export declare const normalizeAllowedRoles: (roles: AllowedRoles) => NormalizedAllowedRoles;
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("clientnode")},e=>{e.exports=require("fs")},e=>{e.exports=require("path")},e=>{e.exports=require("child_process")},e=>{e.exports=require("pouchdb-node/node_modules/node-fetch/lib/index.js")}],__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__(6),child_process__WEBPACK_IMPORTED_MODULE_3___default=__webpack_require__.n(child_process__WEBPACK_IMPORTED_MODULE_3__),clientnode__WEBPACK_IMPORTED_MODULE_4__=__webpack_require__(3),clientnode__WEBPACK_IMPORTED_MODULE_4___default=__webpack_require__.n(clientnode__WEBPACK_IMPORTED_MODULE_4__),node_fetch__WEBPACK_IMPORTED_MODULE_5__=__webpack_require__(7),node_fetch__WEBPACK_IMPORTED_MODULE_5___default=__webpack_require__.n(node_fetch__WEBPACK_IMPORTED_MODULE_5__),fs__WEBPACK_IMPORTED_MODULE_6__=__webpack_require__(4),fs__WEBPACK_IMPORTED_MODULE_6___default=__webpack_require__.n(fs__WEBPACK_IMPORTED_MODULE_6__),path__WEBPACK_IMPORTED_MODULE_7__=__webpack_require__(5),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: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=_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function(){var e,t;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(a){for(;;)switch(a.prev=a.next){case 0: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]])})));case 3:case"end":return a.stop()}}),a)})),c=_createForOfIteratorHelperLoose(["post","put"]);case 7:if((i=c()).done){e.next=11;break}return e.delegateYield(a(),"t0",9);case 9:e.next=7;break;case 11:return e.prev=11,e.next=14,clientnode__WEBPACK_IMPORTED_MODULE_4___default().checkReachability(t);case 14:e.next=21;break;case 16:return e.prev=16,e.t1=e.catch(11),e.next=21,clientnode__WEBPACK_IMPORTED_MODULE_4__.globalContext.fetch(t,{method:"PUT"});case 21:return e.abrupt("return",_);case 22:case"end":return e.stop()}}),e,null,[[11,16]])})));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(_context5){for(;;)switch(_context5.prev=_context5.next){case 0:if(!Object.prototype.hasOwnProperty.call(services.couchdb.server.runner,"configurationFile")){_context5.next=12;break}return _context5.prev=1,_context5.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:_context5.next=10;break;case 6:if(_context5.prev=6,_context5.t0=_context5.catch(1),"EEXIST"===_context5.t0.code){_context5.next=10;break}throw _context5.t0;case 10:return _context5.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)})),_context5.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 _context5.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.allowedRole,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.allowedRole,r.attachment,r.conflict,r.constraint.execution,r.constraint.expression,r.deleted,r.deletedConflict,r.extend,r.maximumAggregatedSize,r.minimumAggregatedSize,r.oldType,r.id,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.allowedRole,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__})();
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("clientnode")},e=>{e.exports=require("fs")},e=>{e.exports=require("path")},e=>{e.exports=require("child_process")},e=>{e.exports=require("pouchdb-node/node_modules/node-fetch/lib/index.js")}],__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__,{determineAllowedModelRolesMapping:()=>determineAllowedModelRolesMapping,determineGenericIndexablePropertyNames:()=>determineGenericIndexablePropertyNames,ensureValidationDocumentPresence:()=>ensureValidationDocumentPresence,extendModel:()=>extendModel,extendModels:()=>extendModels,getConnectorOptions:()=>getConnectorOptions,initializeConnection:()=>initializeConnection,mayStripRepresentation:()=>mayStripRepresentation,normalizeAllowedRoles:()=>normalizeAllowedRoles,restartServer:()=>restartServer,startServer:()=>startServer,stopServer:()=>stopServer});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__(6),child_process__WEBPACK_IMPORTED_MODULE_3___default=__webpack_require__.n(child_process__WEBPACK_IMPORTED_MODULE_3__),clientnode__WEBPACK_IMPORTED_MODULE_4__=__webpack_require__(3),clientnode__WEBPACK_IMPORTED_MODULE_4___default=__webpack_require__.n(clientnode__WEBPACK_IMPORTED_MODULE_4__),node_fetch__WEBPACK_IMPORTED_MODULE_5__=__webpack_require__(7),node_fetch__WEBPACK_IMPORTED_MODULE_5___default=__webpack_require__.n(node_fetch__WEBPACK_IMPORTED_MODULE_5__),fs__WEBPACK_IMPORTED_MODULE_6__=__webpack_require__(4),fs__WEBPACK_IMPORTED_MODULE_6___default=__webpack_require__.n(fs__WEBPACK_IMPORTED_MODULE_6__),path__WEBPACK_IMPORTED_MODULE_7__=__webpack_require__(5),path__WEBPACK_IMPORTED_MODULE_7___default=__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_7__),_this=void 0;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 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,_)}}},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"},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,a,o,i){var c,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===a&&(a=!0),void 0===o&&(o="_id"),void 0===i&&(i="_design/"),l=_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()(((c={})[o]=""+i+r,c.language="javascript",c),t),e.prev=4,e.next=7,_.get(""+i+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),a&&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)}}(),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,a,o,i,c,l,s;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=r.couchdb,n=clientnode__WEBPACK_IMPORTED_MODULE_4___default().stringFormat(t.url,t.user.name+":"+t.user.password+"@")+"/"+t.databaseName,_.couchdb.connection=new _.couchdb.connector(n,getConnectorOptions(r)),(a=_.couchdb.connection).setMaxListeners(1/0),o=t.model.property.name.special.id,i=t.model.property.name.special.revision,c=_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function(){var e,_;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:e=s.value,_=a[e].bind(a),a[e]=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function e(r,n){var a,c,l;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,_(r,n);case 3:return e.abrupt("return",e.sent);case 6:if(e.prev=6,e.t0=e.catch(0),!((c=r[o])&&t.ignoreNoChangeError&&"forbidden"===e.t0.name&&null!=(a=e.t0.message)&&a.startsWith("NoChange:"))){e.next=22;break}if(l="object"==typeof n&&i in n?n[i]:r[i],e.t1=c,!(i in r)||["latest","upsert"].includes(l)){e.next=16;break}e.t2=l,e.next=20;break;case 16:return e.next=18,this.get(c);case 18:e.t3=i,e.t2=e.sent[e.t3];case 20:return e.t4=e.t2,e.abrupt("return",{id:e.t1,rev:e.t4,ok:!0});case 22:throw e.t0;case 23:case"end":return e.stop()}}),e,this,[[0,6]])})));case 3:case"end":return r.stop()}}),c)})),l=_createForOfIteratorHelperLoose(["post","put"]);case 9:if((s=l()).done){e.next=13;break}return e.delegateYield(c(),"t0",11);case 11:e.next=9;break;case 13:return e.prev=13,e.next=16,clientnode__WEBPACK_IMPORTED_MODULE_4___default().checkReachability(n);case 16:e.next=23;break;case 18:return e.prev=18,e.t1=e.catch(13),e.next=23,clientnode__WEBPACK_IMPORTED_MODULE_4__.globalContext.fetch(n,{method:"PUT"});case 23:return e.abrupt("return",_);case 24:case"end":return e.stop()}}),e,null,[[13,18]])})));return function(){return e.apply(this,arguments)}}(),startServer=function(){var _ref4=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function _callee4(services,configuration){var server,runner,binary;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(_context5){for(;;)switch(_context5.prev=_context5.next){case 0:if(server=services.couchdb.server,runner=server.runner,binary=configuration.couchdb.binary,!Object.prototype.hasOwnProperty.call(runner,"configurationFile")){_context5.next=15;break}return _context5.prev=4,_context5.next=7,fs__WEBPACK_IMPORTED_MODULE_6__.promises.mkdir(path__WEBPACK_IMPORTED_MODULE_7___default().dirname(runner.configurationFile.path),{recursive:!0});case 7:_context5.next=13;break;case 9:if(_context5.prev=9,_context5.t0=_context5.catch(4),"EEXIST"===_context5.t0.code){_context5.next=13;break}throw _context5.t0;case 13:return _context5.next=15,fs__WEBPACK_IMPORTED_MODULE_6__.promises.writeFile(runner.configurationFile.path,runner.configurationFile.content,{encoding:configuration.core.encoding});case 15:return server.process=(0,child_process__WEBPACK_IMPORTED_MODULE_3__.spawn)("default"===binary.memoryInMegaByte?runner.binaryFilePath:binary.nodePath,("default"===binary.memoryInMegaByte?[]:["--max-old-space-size="+binary.memoryInMegaByte,runner.binaryFilePath]).concat(runner.arguments?runner.arguments:[]),{cwd:eval("process").cwd(),env:Object.prototype.hasOwnProperty.call(runner,"environment")?_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({},eval("process").env,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,server.process.on(t,clientnode__WEBPACK_IMPORTED_MODULE_4___default().getProcessCloseHandler(e,_,{process: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)})),_context5.next=19,clientnode__WEBPACK_IMPORTED_MODULE_4___default().checkReachability(clientnode__WEBPACK_IMPORTED_MODULE_4___default().stringFormat(configuration.couchdb.url,""),{wait:!0});case 19:case"end":return _context5.stop()}}),_callee4,null,[[4,9]])})));return function(){return _ref4.apply(this,arguments)}}(),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,a,o,i;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,a=n.couchdb.server,o=a.resolve,i=a.reject,a.resolve=a.reject=clientnode__WEBPACK_IMPORTED_MODULE_4___default().noop,e.next=7,stopServer(n,r);case 7:return a.resolve=o,a.reject=i,e.next=11,startServer(n,r);case 11:return 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)}}(),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)}}(),determineAllowedModelRolesMapping=function(e){for(var _=e.property.name.special.allowedRole,r={},t=extendModels(e),n=0,a=Object.entries(t);n<a.length;n++){var o=a[n],i=o[0],c=o[1];if(Object.prototype.hasOwnProperty.call(c,_)){r[i]=_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({properties:{}},normalizeAllowedRoles(c[_]));for(var l=0,s=Object.entries(c);l<s.length;l++){var u=s[l],p=u[0],d=u[1];null!==d&&"object"==typeof d&&d.allowedRoles&&(r[i].properties[p]=normalizeAllowedRoles(d.allowedRoles))}}else r[i]={properties:{},read:[],write:[]}}return r},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.allowedRole,r.attachment,r.conflict,r.constraint.execution,r.constraint.expression,r.deleted,r.deletedConflict,r.extend,r.maximumAggregatedSize,r.minimumAggregatedSize,r.oldType,r.id,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()},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,a=_createForOfIteratorHelperLoose([].concat(_[e][r]));!(t=a()).done;)n=t.value,_[e]=clientnode__WEBPACK_IMPORTED_MODULE_4___default().extend(!0,clientnode__WEBPACK_IMPORTED_MODULE_4___default().copy(extendModel(n,_,r)),_[e]);delete _[e][r]}return _[e]},extendModels=function(e){for(var _,r=e.property.name.special,t={},n=e.property.name.typeRegularExpressionPattern,a=0,o=Object.keys(e.entities);a<o.length;a++){if(_=o[a],!new RegExp(n.public).test(_)&&!new RegExp(n.private).test(_))throw new Error('Model names have to match "'+n.public+'" or "'+n.private+'" for private one (given name: "'+_+'").');t[_]=extendModel(_,e.entities,r.extend)}for(var i,c=0,l=Object.values(t);c<l.length;c++){i=l[c];for(var s=0,u=Object.entries(i);s<u.length;s++){var p=u[s],d=p[0],E=p[1];if(d===r.attachment)for(var b=0,O=Object.entries(E);b<O.length;b++){var f=O[b],P=f[0],M=f[1];E[P]=clientnode__WEBPACK_IMPORTED_MODULE_4___default().extend(!0,clientnode__WEBPACK_IMPORTED_MODULE_4___default().copy(e.property.defaultSpecification),M)}else[r.allowedRole,r.constraint.execution,r.constraint.expression,r.extend,r.maximumAggregatedSize,r.minimumAggregatedSize,r.oldType].includes(d)||(i[d]=clientnode__WEBPACK_IMPORTED_MODULE_4___default().extend(!0,clientnode__WEBPACK_IMPORTED_MODULE_4___default().copy(e.property.defaultSpecification),E))}}return t},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]}}})(),module.exports=__webpack_exports__})();
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("clientnode")},e=>{"use strict";e.exports=require("fs")},e=>{"use strict";e.exports=require("path")},e=>{"use strict";e.exports=require("child_process")},e=>{"use strict";e.exports=require("pouchdb-node/node_modules/node-fetch/lib/index.js")},(__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__(6),child_process__WEBPACK_IMPORTED_MODULE_3___default=__webpack_require__.n(child_process__WEBPACK_IMPORTED_MODULE_3__),clientnode__WEBPACK_IMPORTED_MODULE_4__=__webpack_require__(3),clientnode__WEBPACK_IMPORTED_MODULE_4___default=__webpack_require__.n(clientnode__WEBPACK_IMPORTED_MODULE_4__),node_fetch__WEBPACK_IMPORTED_MODULE_5__=__webpack_require__(7),node_fetch__WEBPACK_IMPORTED_MODULE_5___default=__webpack_require__.n(node_fetch__WEBPACK_IMPORTED_MODULE_5__),fs__WEBPACK_IMPORTED_MODULE_6__=__webpack_require__(4),fs__WEBPACK_IMPORTED_MODULE_6___default=__webpack_require__.n(fs__WEBPACK_IMPORTED_MODULE_6__),path__WEBPACK_IMPORTED_MODULE_7__=__webpack_require__(5),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,o,a,_,c){var i,s,l;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return void 0===a&&(a=!0),void 0===_&&(_="_id"),void 0===c&&(c="_design/"),s=_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()(((i={})[_]=""+c+r,i.language="javascript",i),n),e.prev=4,e.next=7,t.get(""+c+r);case 7:return l=e.sent,s._rev=l._rev,e.next=11,t.put(s);case 11:case 20:e.next=26;break;case 14:return e.prev=14,e.t0=e.catch(4),a&&e.t0.error,e.prev=17,e.next=20,t.put(s);case 23:throw e.prev=23,e.t1=e.catch(17),new Error(o+" 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,o,a,_,c,i;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0: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),o=r.couchdb.model.property.name.special.id,a=r.couchdb.model.property.name.special.revision,_=_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function(){var e,n;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(_){for(;;)switch(_.prev=_.next){case 0:e=i.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=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,_=u.length,c=Array(1<_?_-1:0),i=1;i<_;i++)c[i-1]=u[i];return e.next=4,n.apply(void 0,[t].concat(c));case 4:return e.abrupt("return",e.sent);case 7:if(e.prev=7,e.t0=e.catch(0),!(o in t&&r.couchdb.ignoreNoChangeError&&"forbidden"===e.t0.name&&null!=(s=e.t0.message)&&s.startsWith("NoChange:"))){e.next=21;break}if(l={id:t[o],ok:!0},!(a in t)||["latest","upsert"].includes(t[a])){e.next=15;break}e.t1=t[a],e.next=19;break;case 15:return e.next=17,this.get(l.id);case 17:e.t2=a,e.t1=e.sent[e.t2];case 19:return l.rev=e.t1,e.abrupt("return",l);case 21:throw e.t0;case 22:case"end":return e.stop()}}),e,this,[[0,7]])})));case 3:case"end":return _.stop()}}),_)})),c=_createForOfIteratorHelperLoose(["post","put"]);case 7:if((i=c()).done){e.next=11;break}return e.delegateYield(_(),"t0",9);case 9:e.next=7;break;case 11:return e.prev=11,e.next=14,clientnode__WEBPACK_IMPORTED_MODULE_4___default().checkReachability(n);case 14:e.next=21;break;case 16:return e.prev=16,e.t1=e.catch(11),e.next=21,clientnode__WEBPACK_IMPORTED_MODULE_4__.globalContext.fetch(n,{method:"PUT"});case 21:return e.abrupt("return",t);case 22:case"end":return e.stop()}}),e,null,[[11,16]])})));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(_context5){for(;;)switch(_context5.prev=_context5.next){case 0:if(!Object.prototype.hasOwnProperty.call(services.couchdb.server.runner,"configurationFile")){_context5.next=12;break}return _context5.prev=1,_context5.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:_context5.next=10;break;case 6:if(_context5.prev=6,_context5.t0=_context5.catch(1),"EEXIST"===_context5.t0.code){_context5.next=10;break}throw _context5.t0;case 10:return _context5.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,o=_createForOfIteratorHelperLoose(clientnode__WEBPACK_IMPORTED_MODULE_4__.CloseEventNames);!(r=o()).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)})),_context5.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 _context5.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,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=t.configuration,n=t.pluginAPI,o=t.services,a=o.couchdb.server,_=a.resolve,c=a.reject,a.resolve=a.reject=clientnode__WEBPACK_IMPORTED_MODULE_4___default().noop,e.next=7,Helper.stopServer(o,r);case 7:return a.resolve=_,a.reject=c,e.next=11,Helper.startServer(o,r);case 11:return Helper.initializeConnection(o,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,o;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.couchdb,o=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(o.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.allowedRole,r={},n=Helper.extendModels(e),o=0,a=Object.entries(n);o<a.length;o++){var _=a[o],c=_[0],i=_[1];if(Object.prototype.hasOwnProperty.call(i,t)){r[c]=_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({properties:{}},Helper.normalizeAllowedRoles(i[t]));for(var s=0,l=Object.entries(i);s<l.length;s++){var u=l[s],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,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.allowedRole,r.attachment,r.conflict,r.constraint.execution,r.constraint.expression,r.deleted,r.deletedConflict,r.extend,r.maximumAggregatedSize,r.minimumAggregatedSize,r.oldType,r.id,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,o,a=_createForOfIteratorHelperLoose([].concat(t[e][r]));!(n=a()).done;)o=n.value,t[e]=clientnode__WEBPACK_IMPORTED_MODULE_4___default().extend(!0,clientnode__WEBPACK_IMPORTED_MODULE_4___default().copy(Helper.extendModel(o,t,r)),t[e]);delete t[e][r]}return t[e]},Helper.extendModels=function(e){for(var t,r=e.property.name.special,n={},o=0,a=Object.keys(e.entities);o<a.length;o++){if(t=a[o],!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=0,i=Object.values(n);c<i.length;c++){_=i[c];for(var s=0,l=Object.entries(_);s<l.length;s++){var u=l[s],p=u[0],d=u[1];if(p===r.attachment)for(var m=0,f=Object.entries(d);m<f.length;m++){var b=f[m],h=b[0],y=b[1];d[h]=clientnode__WEBPACK_IMPORTED_MODULE_4___default().extend(!0,clientnode__WEBPACK_IMPORTED_MODULE_4___default().copy(e.property.defaultSpecification),y)}else[r.allowedRole,r.constraint.execution,r.constraint.expression,r.extend,r.maximumAggregatedSize,r.minimumAggregatedSize,r.oldType].includes(p)||(_[p]=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,o=Object.keys(r);n<o.length;n++)t=o[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=function(){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}}()?Reflect.construct.bind():function(e,t,n){var o=[null];o.push.apply(o,t);var a=new(Function.bind.apply(e,o));return n&&r(a,n.prototype),a}).apply(null,arguments)}function r(e,t){return r=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},r(e,t)}function n(){return n=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},n.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 a(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)?a(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 a(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 _={d:function(e,t){for(var r in t)_.o(t,r)&&!_.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})}},c={};_.r(c),_.d(c,{DatabaseHelper:function(){return i},default:function(){return s}});var i=function(){function e(){}return e.authenticate=function(e,t,r,n,a,_,c,i,s){var l;void 0===t&&(t=null),void 0===r&&(r={}),void 0===n&&(n={admins:{names:[],roles:[]},members:{names:[],roles:[]}}),void 0===_&&(_="_id"),void 0===c&&(c="-type"),void 0===i&&(i="_design/"),void 0===s&&(s=!1);var u=null!==(l=e[c])&&void 0!==l?l:t&&t[c];if(!u)return!0;var p=s?"read":"write",d={properties:{},read:["_admin","readonlyadmin"],write:["_admin"]};Object.prototype.hasOwnProperty.call(e,_)&&e[_].startsWith(i)&&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&&u&&Object.prototype.hasOwnProperty.call(a,u)){for(var b,h,y=a[u],O=o(["read","write"]);!(b=O()).done;)d[h=b.value]=d[h].concat(y[h]||[]);d.properties=y.properties}for(var x,g,E=d[p],P=o(r.roles);!(x=P()).done;)if(g=x.value,E.includes(g))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 "+p+' action: "'+[].concat(d[p]).join('", "')+'". '+f+"."}},e.validateDocumentUpdate=function(e,r,a,_,c,i,s){void 0===i&&(i={});var l=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,_=Object.entries(r);a<_.length;a++){var c=_[a],i=c[0],s=c[1];o[i]=s}throw o},u=new Date,p=Date.UTC(u.getUTCFullYear(),u.getUTCMonth(),u.getUTCDate(),u.getUTCHours(),u.getUTCMinutes(),u.getUTCSeconds(),u.getUTCMilliseconds())/1e3,d=!c.dateTimeFormat.startsWith("iso"),m=c.property.name.special,f=m.id,b=m.revision,h=m.type;r&&r[h]&&!e[h]&&(e[h]=r[h]);var y="",O="",x=function(){y=Object.prototype.hasOwnProperty.call(e,f)?e[f]:"",O=Object.prototype.hasOwnProperty.call(e,b)?e[b]:""};if(x(),Object.prototype.hasOwnProperty.call(_,c.property.name.validatedDocumentsCache)&&_[c.property.name.validatedDocumentsCache].has(y+"-"+O))return _[c.property.name.validatedDocumentsCache].delete(y+"-"+O),e;["latest","upsert"].includes(O)&&(r&&Object.prototype.hasOwnProperty.call(r,b)?O=e[b]=r[b]:"latest"===O?l("Revision: No old document available to update."):delete e[b]);var g=c.updateStrategy;Object.prototype.hasOwnProperty.call(e,m.strategy)&&(g=e[m.strategy],delete e[m.strategy]);var E,P={};if("migrate"===g)for(var v=0,D=Object.entries(i);v<D.length;v++){var M=D[v],w=M[0],C=M[1];if(Object.prototype.hasOwnProperty.call(C,m.oldType)&&![null,void 0].includes(C[m.oldType]))for(var A,k,T=o([].concat(C[m.oldType]));!(A=T()).done;)k=A.value,P[k]=w}s?E=s:JSON&&Object.prototype.hasOwnProperty.call(JSON,"stringify")?E=function(e){return JSON.stringify(e,null,4)}:l('Needed "serializer" is not available.');var I=[m.additional,m.allowedRole,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],R=function(e){return e instanceof Error?""+e:E(e)},j=function(e){return"string"==typeof e?e.trim():""},U=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},L=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},W=function(t,r){if(r||(r=e[m.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 _=Object.keys(r);if(_.length)return _[0]}return null},B=function(e,r,o){void 0===r&&(r=!1),void 0===o&&(o={});var a=j(e);if(a){var _,c=(r?"return ":"")+a,i=n({},N,{code:c},o),s=Object.keys(i);try{_=t(Function,s.concat([c]))}catch(_){l(R(_),"compilation",{code:c,error:_,scope:i})}var u={code:c,result:void 0,scope:i};try{u.result=_.apply(void 0,s.map((function(e){return i[e]})))}catch(_){l(R(_),"runtime",{code:c,error:_,scope:i})}return u}l("No expression to evaluate provided.","empty")},K=function(e,r,n){void 0===n&&(n=[]);var a=n.length?" in "+n.join(" -> "):"",_=[],s=function(){Object.prototype.hasOwnProperty.call(e,h)||(r&&Object.prototype.hasOwnProperty.call(r,h)&&["fillUp","migrate"].includes(g)?e[h]=r[h]:l('Type: You have to specify a model type via property "'+h+'"'+a+".")),n.length||new RegExp(c.property.name.typeRegularExpressionPattern.public).test(e[h])||l('TypeName: You have to specify a model type which matches "'+c.property.name.typeRegularExpressionPattern.public+'" as public type (given "'+e[h]+'")'+a+"."),Object.prototype.hasOwnProperty.call(i,e[h])||(Object.prototype.hasOwnProperty.call(P,e[h])?e[h]=P[e[h]]:l('Model: Given model "'+e[h]+'" is not specified'+a+"."))};s();var u=e[h],p=i[u],y=null;Object.prototype.hasOwnProperty.call(p,m.additional)&&p[m.additional]&&(y=p[m.additional]);var O=function _(c,i,s,d,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(s,b)){var y=void 0;try{y=B(s[b].evaluation,b.endsWith("Expression"),{checkPropertyContent:_,model:p,modelName:u,name:i,type:b,newDocument:e,newValue:c,oldDocument:r,oldValue:d,parentNames:n,pathDescription:a,propertySpecification:s})}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&l('Compilation: Hook "'+b+'" has invalid code "'+e.code+'": "'+e.message+'"'+a+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&l('Runtime: Hook "'+b+'" has throw an error with code "'+e.code+'": "'+e.message+'"'+a+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}if(y&&!y.result){var O=j(s[b].description);l(b.charAt(0).toUpperCase()+(b.substring(1)+": ")+(O?t(Function,Object.keys(y.scope).concat(["return "+O])).apply(void 0,Object.values(y.scope)):'Property "'+i+'" should satisfy constraint "'+y.code+'" (given "'+R(c)+'")'+a+"."))}}},E=function(e,t,r,_){void 0===_&&(_=null);var c=[],s=[].concat(r.type?r.type:[]);"object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype&&!Object.prototype.hasOwnProperty.call(e,h)&&1===s.length&&Object.prototype.hasOwnProperty.call(i,s[0])&&(e[h]=s[0]);for(var u,p,m=!1,b=o(s);!(u=b()).done;)if(p=u.value,Object.prototype.hasOwnProperty.call(i,p)){if("object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype&&Object.prototype.hasOwnProperty.call(e,h)&&e[h]!==p&&"migrate"===g&&1===s.length&&(e[h]=p,c=n.concat(t,"migrate nested object type")),"object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype&&Object.prototype.hasOwnProperty.call(e,h)&&e[h]===p){var y=K(e,_,n.concat(t));if(y.changedPath.length&&(c=y.changedPath),e=y.newDocument,R(e)===R({}))return{newValue:null,changedPath:c};m=!0;break}1===s.length&&l('NestedType: Under key "'+t+'" isn\'t of type "'+p+'" (given "'+R(e)+'" of type '+typeof e+")"+a+".")}else if("DateTime"===p){var x=e;if(e=U(e),!(d&&("number"!=typeof e||isNaN(e))||!d&&"string"!=typeof e)){m=!0;break}1===s.length&&l('PropertyType: Property "'+t+'" isn\'t of (valid) type "DateTime" (given "'+R(x).replace(/^"/,"").replace(/"$/,"")+'" of type "'+typeof x+'")'+a+".")}else if(["boolean","integer","number","string"].includes(p)){if(!("number"==typeof e&&isNaN(e)||"integer"!==p&&typeof e!==p||"integer"===p&&parseInt(e,10)!==e)){m=!0;break}1===s.length&&l('PropertyType: Property "'+t+'" isn\'t of (valid) type "${type}" (given "'+R(e)+'" of type "'+typeof e+'")'+a+".")}else if("string"==typeof p&&p.startsWith("foreignKey:")){var E=i[p.substring(11)][f].type;if(E===typeof e){m=!0;break}1===s.length&&l('PropertyType: Foreign key property "'+t+'" isn\'t of type "'+E+'" (given "'+R(e)+'" of type "'+typeof e+'")'+a+".")}else{if("any"===p||R(e)===R(p)){m=!0;break}1===s.length&&l('PropertyType: Property "'+t+'" isn\'t value "'+p+'" (given "'+R(e).replace(/^"/,"").replace(/"$/,"")+'" of type "'+typeof e+'")'+a+".")}if(m||l('PropertyType: None of the specified types "'+s.join('", "')+'" for property "'+t+'" matches value "'+R(e).replace(/^"/,"").replace(/"$/,"")+e+'" of type "'+typeof e+'")'+a+"."),"string"==typeof e&&(![null,void 0].includes(r.minimumLength)&&e.length<r.minimumLength&&l('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&&l('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&&l('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&&l('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(U)),P.includes(e)||l('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)&&l('InvertedPatternMatch: Property "'+t+'" should not match regular expression pattern '+r.invertedRegularExpressionPattern+' (given "'+e+'")'+a+"."):l('PatternMatch: Property "'+t+'" should match regular expression pattern '+r.regularExpressionPattern+' (given "'+e+'")'+a+"."),O(e,t,r,_),R(e)!==R(_)&&(c=n.concat(t,"value updated")),{newValue:e,changedPath:c}},v=function(e,t,r,o,a){var i=t[o];if(!e.writable)if(r){if(Object.prototype.hasOwnProperty.call(r,o)&&R(i)===R(r[o]))return o!==f&&"incremental"===g&&delete t[o],!0;l('Readonly: Property "'+o+'" is not writable (old document "'+R(r)+'")'+a+".")}else l('Readonly: Property "'+o+'" is not writable'+a+".");if(!e.mutable&&r&&Object.prototype.hasOwnProperty.call(r,o)){if(R(i)===R(r[o]))return"incremental"!==g||c.property.name.reserved.concat(m.deleted,f,b).includes(o)||delete t[o],!0;"migrate"!==g&&l('Immutable: Property "'+o+'" is not writable (old document "'+R(r)+'")'+a+".")}if(null===i){if(e.nullable)return delete t[o],r&&Object.prototype.hasOwnProperty.call(r,o)&&(_=n.concat(o,"delete property")),!0;l('NotNull: Property "'+o+'" should not be "null"'+a+".")}return!1},D=function(e,t,r,_){if(!r)for(var c,i,s=o(["onCreateExecution","onCreateExpression"]);!(c=s()).done;)if(i=c.value,Object.prototype.hasOwnProperty.call(e,i)){var d=void 0;try{d=B(e[i],i.endsWith("Expression"),{checkPropertyContent:E,model:p,modelName:u,name:_,type:i,newDocument:t,oldDocument:r,newValue:void 0,oldValue:void 0,parentNames:n,pathDescription:a,propertySpecification:e})}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&l('Compilation: Hook "'+i+'" has invalid code "'+e.code+'" for property "'+_+'": '+e.message+a+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&l('Runtime: Hook "'+i+'" has throw an error with code "'+e.code+'" for property "'+_+'": '+e.message+a+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}d&&![null,void 0].includes(d.result)&&(t[_]=d.result)}},M=function(e,t,r,_){if(Object.prototype.hasOwnProperty.call(t,_)){e.trim&&"string"==typeof t[_]&&(t[_]=t[_].trim()),e.emptyEqualsToNull&&(""===t[_]||Array.isArray(t[_])&&0===t[_].length||null!==t[_]&&"object"==typeof t[_]&&0===Object.keys(t).length)&&(t[_]=null);for(var c,i,s=o(["onUpdateExecution","onUpdateExpression"]);!(c=s()).done;)if(i=c.value,Object.prototype.hasOwnProperty.call(e,i))try{t[_]=B(e[i],i.endsWith("Expression"),{checkPropertyContent:E,model:p,modelName:u,name:_,type:i,newDocument:t,oldDocument:r,newValue:t[_],oldValue:r&&r[_],parentNames:n,pathDescription:a,propertySpecification:e}).result}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&l('Compilation: Hook "'+i+'" has invalid code "'+e.code+'" for property "'+_+'": '+e.message+a+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&l('Runtime: Hook "'+i+'" has throw an error with code "'+e.code+'" for property "'+_+'": '+e.message+a+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}}},w=Object.keys(p).filter((function(e){return!I.includes(e)}));if("migrate"===g)for(var C,A,k=o(w);!(C=k()).done;)if(A=C.value,![null,void 0].includes(p[A].oldName))for(var T,W,N=o([].concat(p[A].oldName));!(T=N()).done;)W=T.value,Object.prototype.hasOwnProperty.call(e,W)&&(e[A]=e[W],delete e[W]);if(!r)for(var S,H=0,q=[m.create.execution,m.create.expression];H<q.length;H++)if(S=q[H],Object.prototype.hasOwnProperty.call(p,S)){var F=void 0;try{F=B(p[S],S.endsWith("Expression"),{checkPropertyContent:E,model:p,modelName:u,type:S,newDocument:e,oldDocument:r,parentNames:n,pathDescription:a}).result}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&l('Compilation: Hook "'+S+'" has invalid code "'+e.code+'" for document "'+u+'": '+e.message+a+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&l('Runtime: Hook "'+S+'" has throw an error with code "'+e.code+'" for document "'+u+'": '+e.message+a+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}[null,void 0].includes(F)||(e=F),s(),u=e[h],0===n.length&&x()}for(var $,z=0,G=[m.update.execution,m.update.expression];z<G.length;z++)if($=G[z],Object.prototype.hasOwnProperty.call(p,$)){var V=void 0;try{V=B(p[$],$.endsWith("Expression"),{checkPropertyContent:E,model:p,modelName:u,type:$,newDocument:e,oldDocument:r,parentNames:n,pathDescription:a}).result}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&l('Compilation: Hook "'+$+'" has invalid code "'+e.code+'" for document "'+u+'": '+e.message+a+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&l('Runtime: Hook "'+$+'" has throw an error with code "'+e.code+'" for document "'+u+'": '+e.message+a+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}[void 0,null].includes(V)||(e=V),s(),u=e[h],0===n.length&&x()}for(var J,X=function(){var t=J.value;if(m.attachment===t)for(var c=function(){var c=s[i],u=c[0],p=c[1];Object.prototype.hasOwnProperty.call(e,t)&&null!==e[t]||(e[t]={}),r&&!Object.prototype.hasOwnProperty.call(r,t)&&(r[t]={});var d=Object.keys(e[t]).filter((function(r){return null!==e[t][r].data&&L(u,r,p)})),m=e[t],f=[];if(r){var b=r[t];f=Object.keys(b).filter((function(e){return!(Object.prototype.hasOwnProperty.call(m,e)&&Object.prototype.hasOwnProperty.call(m[e],"data")&&null===m[e].data)&&!!b[e]&&(Object.prototype.hasOwnProperty.call(b[e],"data")&&null!==b[e].data||b[e].stub&&!!b[e].digest)&&!!L(u,e,p)}))}for(var h,y,O=p,x=o(d);!(h=x()).done;)y=h.value,D(O,m,r&&r[t]?r[t]:null,y);for(var E,P,v=o(d);!(E=v()).done;)P=E.value,M(O,m,r&&r[t]?r[t]:null,P);if([null,void 0].includes(O.default)){if(O.nullable||0<d.length||0<f.length||l('AttachmentMissing: Missing attachment for type "'+u+'"'+a+"."),"fillUp"===g&&0===d.length&&0<f.length)for(var w,C,A=o(f);!(w=A()).done;)C=w.value,null===m[C]?_=n.concat(t,C,"file removed"):m[C]=r[t][C]}else if(0===d.length)if(0===f.length)for(var k in O.default)Object.prototype.hasOwnProperty.call(O.default,k)&&(m[k]=O.default[k],_=n.concat(t,u,"add default file"));else if("fillUp"===g)for(var T,I,R=o(f);!(T=R()).done;)I=T.value,m[I]=r[t][I]},i=0,s=Object.entries(p[t]);i<s.length;i++)c();else{var u=w.includes(t)?p[t]:y;D(u,e,r,t),M(u,e,r,t),[null,void 0].includes(u.default)?(!(u.nullable||Object.prototype.hasOwnProperty.call(e,t)||r&&Object.prototype.hasOwnProperty.call(r,t)&&g)&&l('MissingProperty: Missing property "'+t+'"'+a+"."),!Object.prototype.hasOwnProperty.call(e,t)&&r&&Object.prototype.hasOwnProperty.call(r,t)&&("fillUp"===g?e[t]=r[t]:!g&&(_=n.concat(t,"property removed")))):(!Object.prototype.hasOwnProperty.call(e,t)||null===e[t])&&(r&&Object.prototype.hasOwnProperty.call(r,t)?"fillUp"===g?e[t]=r[t]:"migrate"===g&&(e[t]=u.default,_=n.concat(t,"migrate default value")):(e[t]=u.default,_=_.concat(t,"add default value")))}},Y=o(w.concat(y?Object.keys(e).filter((function(e){return!w.includes(e)})):[]));!(J=Y()).done;)X();if(r&&"incremental"===g)for(var Z=0,Q=Object.entries(e);Z<Q.length;Z++){var ee=Q[Z],te=ee[0],re=ee[1];Object.prototype.hasOwnProperty.call(r,te)&&!c.property.name.reserved.concat(f,b,m.conflict,m.deleted,m.deletedConflict,m.localSequence,m.revisions,m.revisionsInformation,h).includes(te)&&(r[te]===re||R(r[te])===R(re))&&delete e[te]}for(var ne=0,oe=Object.entries(e);ne<oe.length;ne++){var ae=oe[ne],_e=ae[0],ce=ae[1];if(!c.property.name.reserved.concat(b,m.conflict,m.deleted,m.deletedConflict,m.localSequence,m.revisions,m.revisionsInformation,m.strategy).includes(_e)){var ie=void 0;if(Object.prototype.hasOwnProperty.call(p,_e))ie=p[_e];else if(y)ie=y;else{if("migrate"===g){delete e[_e],_=n.concat(_e,"migrate removed property");continue}l('Property: Given property "'+_e+'" isn\'t specified in model "'+u+'"'+a+".")}if(!ie)continue;if(m.attachment===_e){var se=ce;for(var le in se)if(Object.prototype.hasOwnProperty.call(se,le))for(var ue in p[_e])if(L(ue,le,p[_e][ue])){v(p[_e][ue],e,r,le,a);break}continue}if(v(ie,e,r,_e,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?l('MinimumArrayLength: Property "'+_e+'" (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&&l('MaximumArrayLength: Property "'+_e+'" (array of length '+de.length+") doesn't fullfill maximum array length of "+ie.maximumNumber+a+"."):l('PropertyType: Property "'+_e+'" isn\'t of type "array -> '+ie.type+'" (given "'+R(de)+'")'+a+"."),O(de,_e,ie,r&&Object.prototype.hasOwnProperty.call(r,_e)&&r[_e]||void 0,["arrayConstraintExecution","arrayConstraintExpression"]);var me={};for(var fe in ie)Object.prototype.hasOwnProperty.call(ie,fe)&&(me[fe]="type"===fe?Array.isArray(ie[fe])?ie[fe][0]:[ie[fe].substring(0,ie.type.length-2)]:ie[fe]);if(1===(null==(pe=me.type)?void 0:pe.length)&&Object.prototype.hasOwnProperty.call(i,me.type[0]))for(var be,he,ye=o(de.slice());!(be=ye()).done;)"object"!=typeof(he=be.value)||Object.getPrototypeOf(he)!==Object.prototype||Object.prototype.hasOwnProperty.call(he,h)||(he[h]=me.type[0]);for(var Oe,xe,ge=0,Ee=o(de.slice());!(Oe=Ee()).done;)xe=Oe.value,de[ge]=E(xe,ge+1+". value in "+_e,me).newValue,null===xe&&de.splice(ge,1),ge+=1;r&&Object.prototype.hasOwnProperty.call(r,_e)&&Array.isArray(r[_e])&&r[_e].length===de.length&&R(r[_e])===R(de)||(_=n.concat(_e,"array updated"))}else{var Pe=r&&Object.prototype.hasOwnProperty.call(r,_e)?r[_e]:null,ve=E(ce,_e,ie,Pe);e[_e]=ve.newValue,ve.changedPath.length&&(_=ve.changedPath),null===e[_e]&&(null!==Pe&&(_=n.concat(_e,"property removed")),delete e[_e])}}}for(var De,Me=0,we=Object.keys(m.constraint);Me<we.length;Me++)if(De=we[Me],(De=m.constraint[De])&&Object.prototype.hasOwnProperty.call(p,De))for(var Ce,Ae=o([].concat(p[De]));!(Ce=Ae()).done;){var ke=Ce.value,Te=void 0;try{Te=B(ke.evaluation,De===m.constraint.expression,{checkPropertyContent:E,model:p,modelName:u,type:De,newDocument:e,oldDocument:r,parentNames:n,pathDescription:a})}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&l('Compilation: Hook "'+De+'" has invalid code "'+e.code+'": "'+e.message+'"'+a+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&l('Runtime: Hook "'+De+'" has thrown an error with code "'+e.code+'": '+e.message+a+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}if(Te&&!Te.result){var Ie=De.replace(/^[^a-zA-Z]+/,"");l(Ie.charAt(0).toUpperCase()+(Ie.substring(1)+": ")+(ke.description?t(Function,Object.keys(Te.scope).concat(["return "+ke.description.trim()])).apply(void 0,Object.values(Te.scope)):'Model "'+u+'" should satisfy constraint "'+Te.code+'" (given "'+R(e)+'")'+a+"."))}}if(Object.prototype.hasOwnProperty.call(e,m.attachment)){var Re=e[m.attachment];("object"!=typeof Re||Object.getPrototypeOf(Re)!==Object.prototype)&&l("AttachmentType: given attachment has invalid type"+a+".");var je=null;if(r&&Object.prototype.hasOwnProperty.call(r,m.attachment)&&null!==(je=r[m.attachment])&&"object"==typeof je)for(var Ue=0,Le=Object.entries(je);Ue<Le.length;Ue++){var We=Le[Ue],Be=We[0],Ke=We[1];if(Object.prototype.hasOwnProperty.call(Re,Be)){var Ne=Re[Be];null===Ne||null===Ne.data||Ne.content_type===Ke.content_type&&(Ne.data===Ke.data||Ne.digest===Ke.digest)?((null===Ne||null===Ne.data)&&(_=n.concat(m.attachment,Be,"attachment removed")),"incremental"===g&&delete Re[Be]):_=n.concat(m.attachment,Be,"attachment updated")}else"fillUp"===g?Re[Be]=Ke:g||(_=n.concat(m.attachment,Be,"attachment removed"))}for(var Se=0,He=Object.entries(Re);Se<He.length;Se++){var qe=He[Se],Fe=qe[0],$e=qe[1];[null,void 0].includes($e)||null===$e.data?delete Re[Fe]:(!je||!Object.prototype.hasOwnProperty.call(je,Fe)||$e.content_type!==je[Fe].content_type||$e.data!==je[Fe].data&&$e.digest!==je[Fe].digest)&&(_=n.concat(m.attachment,Fe,"attachment updated"))}0===Object.keys(Re).length&&delete e[m.attachment];for(var ze={},Ge=0,Ve=Object.keys(p[m.attachment]);Ge<Ve.length;Ge++)ze[Ve[Ge]]=[];for(var Je=0,Xe=Object.keys(Re);Je<Xe.length;Je++){for(var Ye=Xe[Je],Ze=!1,Qe=0,et=Object.entries(p[m.attachment]);Qe<et.length;Qe++){var tt=et[Qe],rt=tt[0],nt=tt[1];if(L(rt,Ye,nt)){ze[rt].push(Ye),Ze=!0;break}}Ze||l('AttachmentTypeMatch: None of the specified attachment types ("'+Object.keys(p[m.attachment]).join('", "')+'") matches given one ("'+Ye+'")'+a+".")}for(var ot=0,at=0,_t=Object.keys(ze);at<_t.length;at++){var ct=_t[at],it=p[m.attachment][ct];if(Object.prototype.hasOwnProperty.call(ze,ct)){var st=ze[ct].length;null!==it.maximumNumber&&st>it.maximumNumber&&l("AttachmentMaximum: given number of attachments ("+st+") doesn't satisfy specified maximum of "+it.maximumNumber+' from type "'+ct+'"'+a+"."),(!it.nullable||0!==st)&&st<it.minimumNumber&&l("AttachmentMinimum: given number of attachments ("+st+") doesn't satisfy specified minimum of "+it.minimumNumber+' from type "'+ct+'"'+a+".");for(var lt,ut=0,pt=o(ze[ct]);!(lt=pt()).done;){var dt,mt,ft=lt.value;null!=(dt=it.fileName)&&dt.regularExpressionPattern&&!new RegExp(it.fileName.regularExpressionPattern).test(ft)?l('AttachmentName: given attachment name "'+ft+'" doesn\'t satisfy specified regular expression pattern "'+it.fileName.regularExpressionPattern+'" from type "'+ct+'"'+a+"."):null!=(mt=it.fileName)&&mt.invertedRegularExpressionPattern&&new RegExp(it.fileName.invertedRegularExpressionPattern).test(ft)?l('InvertedAttachmentName: given attachment name "'+ft+'" does satisfy specified regular expression pattern "'+it.fileName.invertedRegularExpressionPattern+'" from type "'+ct+'"'+a+"."):!([null,void 0].includes(it.contentTypeRegularExpressionPattern)||Re[ft].content_type&&new RegExp(it.contentTypeRegularExpressionPattern).test(Re[ft].content_type))&&l('AttachmentContentType: given attachment content type "'+Re[ft].content_type+'" doesn\'t satisfy specified regular expression pattern "'+it.contentTypeRegularExpressionPattern+'" from type "'+ct+'"'+a+".");var bt=it.invertedContentTypeRegularExpressionPattern;[null,void 0].includes(bt)||Re[ft].content_type&&!new RegExp(bt).test(Re[ft].content_type)||l('InvertedAttachmentContentType: given attachment content type "'+Re[ft].content_type+'" does satisfy specified regular expression pattern "'+bt+'" from type "'+ct+'"'+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(it.minimumSize)&&it.minimumSize>ht?l("AttachmentMinimumSize: given attachment size "+ht+" byte doesn't satisfy specified minimum of "+it.minimumSize+" byte "+a+"."):![null,void 0].includes(it.maximumSize)&&it.maximumSize<ht&&l("AttachmentMaximumSize: given attachment size "+ht+" byte doesn't satisfy specified maximum of "+it.maximumSize+" byte "+a+"."),ut+=ht}![null,void 0].includes(it.minimumAggregatedSize)&&it.minimumAggregatedSize>ut?l('AttachmentAggregatedMinimumSize: given aggregated size of attachments from type "'+ct+'" '+ut+" byte doesn't satisfy specified minimum of "+it.minimumAggregatedSize+" byte "+a+"."):![null,void 0].includes(it.maximumAggregatedSize)&&it.maximumAggregatedSize<ut&&l('AttachmentAggregatedMaximumSize: given aggregated size of attachments from type "'+ct+'" '+ut+" byte doesn't satisfy specified maximum of "+it.maximumAggregatedSize+" byte "+a+"."),ot+=ut}}Object.prototype.hasOwnProperty.call(p,m.minimumAggregatedSize)&&![null,void 0].includes(p[m.minimumAggregatedSize])&&p[m.minimumAggregatedSize]>ot?l("AggregatedMinimumSize: given aggregated size "+ot+" byte doesn't satisfy specified minimum of "+p[m.minimumAggregatedSize]+" byte "+a+"."):![null,void 0].includes(p[m.maximumAggregatedSize])&&p[m.maximumAggregatedSize]<ot&&l("AggregatedMaximumSize: given aggregated size "+ot+" byte doesn't satisfy specified maximum of "+p[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===_.length&&r&&"migrate"===g)for(var yt,Ot=0,xt=Object.keys(r);Ot<xt.length;Ot++)yt=xt[Ot],Object.prototype.hasOwnProperty.call(e,yt)||(_=n.concat(yt,"migrate removed property"));return{changedPath:_,newDocument:e}},N={attachmentWithPrefixExists:function(t){if(Object.prototype.hasOwnProperty.call(e,m.attachment)){var r=e[m.attachment],n=W(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:K,getFileNameByPrefix:W,serialize:R,id:y,revision:O,idName:f,revisionName:b,specialNames:m,typeName:h,modelConfiguration:c,models:i,now:u,nowUTCTimestamp:p,securitySettings:_,userContext:a},S=K(e,r);return(!S.newDocument._deleted||r)&&(S.newDocument._deleted&&S.newDocument._deleted!==(null==r?void 0:r._deleted)||S.changedPath.length)||l("NoChange: No new data given. new document: "+R(e)+"; old document: "+R(r)+"."),Object.prototype.hasOwnProperty.call(_,c.property.name.validatedDocumentsCache)?_[c.property.name.validatedDocumentsCache].add(y+"-"+O):_[c.property.name.validatedDocumentsCache]=new Set([y+"-"+O]),S.newDocument},e}(),s=i;e.exports=c}()},,e=>{"use strict";e.exports=require("pouchdb-node")},e=>{"use strict";e.exports=require("pouchdb-find")}],__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:()=>Database,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__),clientnode__WEBPACK_IMPORTED_MODULE_3__=__webpack_require__(3),clientnode__WEBPACK_IMPORTED_MODULE_3___default=__webpack_require__.n(clientnode__WEBPACK_IMPORTED_MODULE_3__),fs__WEBPACK_IMPORTED_MODULE_4__=__webpack_require__(4),fs__WEBPACK_IMPORTED_MODULE_4___default=__webpack_require__.n(fs__WEBPACK_IMPORTED_MODULE_4__),path__WEBPACK_IMPORTED_MODULE_5__=__webpack_require__(5),path__WEBPACK_IMPORTED_MODULE_5___default=__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_5__),pouchdb_node__WEBPACK_IMPORTED_MODULE_6__=__webpack_require__(11),pouchdb_node__WEBPACK_IMPORTED_MODULE_6___default=__webpack_require__.n(pouchdb_node__WEBPACK_IMPORTED_MODULE_6__),pouchdb_find__WEBPACK_IMPORTED_MODULE_7__=__webpack_require__(12),pouchdb_find__WEBPACK_IMPORTED_MODULE_7___default=__webpack_require__.n(pouchdb_find__WEBPACK_IMPORTED_MODULE_7__),_databaseHelper__WEBPACK_IMPORTED_MODULE_9__=__webpack_require__(9),_databaseHelper__WEBPACK_IMPORTED_MODULE_9___default=__webpack_require__.n(_databaseHelper__WEBPACK_IMPORTED_MODULE_9__),_helper__WEBPACK_IMPORTED_MODULE_8__=__webpack_require__(8);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}var Database=function(){function Database(){}return Database.preLoadService=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,o,a,_,c,i,s,l,u,p,d,m,f,b,h,y;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=t.configuration.couchdb,n=t.services,Object.prototype.hasOwnProperty.call(n,"couchdb")||(n.couchdb={}),o=n.couchdb,Object.prototype.hasOwnProperty.call(o,"connector")||(a=r.model.property.name.special.id,_=r.model.property.name.special.revision,o.connector=pouchdb_node__WEBPACK_IMPORTED_MODULE_6___default(),c=o.connector.prototype.bulkDocs,o.connector.plugin({bulkDocs: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 n,o,i,s,l,u,p,d,m,f,b,h,y,O,x,g,E,P,v=arguments;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(o=v.length,i=Array(1<o?o-1:0),s=1;s<o;s++)i[s-1]=v[s];return l=0<i.length&&i[i.length-1]===Database.toggleIDDetermining,u=l?!r.skipIDDetermining:r.skipIDDetermining,l&&i.pop(),p=!Array.isArray(t)&&null!==t&&"object"==typeof t&&a in t?[t]:t,null!=(n=r.connector.fetch)&&n.timeout&&(0===i.length||"object"!=typeof i[0])&&i.unshift({timeout:r.connector.fetch.timeout}),e.next=8,c.call.apply(c,[this,p].concat(i));case 8:d=e.sent,m=[],f=[],b=0,h=_createForOfIteratorHelperLoose(d);case 13:if((y=h()).done){e.next=36;break}if(O=y.value,"object"!=typeof p[b]){e.next=33;break}if(!(_ in p[b])||"conflict"!==O.name||!["latest","upsert"].includes(p[b][_])){e.next=21;break}f.push(p[b]),m.push(b),e.next=33;break;case 21:if(!(a in p[b]&&r.ignoreNoChangeError&&"name"in O&&"forbidden"===O.name&&"message"in O&&O.message.startsWith("NoChange:"))){e.next=33;break}if(d[b]={id:p[b][a],ok:!0},u){e.next=33;break}if(!(_ in p[b])||["latest","upsert"].includes(p[b][_])){e.next=28;break}e.t0=p[b][_],e.next=32;break;case 28:return e.next=30,this.get(d[b].id);case 30:e.t1=_,e.t0=e.sent[e.t1];case 32:d[b].rev=e.t0;case 33:b+=1;case 34:e.next=13;break;case 36:if(!f.length){e.next=43;break}return p=f,l&&i.push(Database.toggleIDDetermining),e.next=41,this.bulkDocs.apply(this,[p].concat(i));case 41:for(x=e.sent,g=_createForOfIteratorHelperLoose(x);!(E=g()).done;)P=E.value,d[m.shift()]=P;case 43:return e.abrupt("return",d);case 44:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}()}),r.debug&&o.connector.debug.enable("*"),o.connector=o.connector.plugin(pouchdb_find__WEBPACK_IMPORTED_MODULE_7___default())),Object.prototype.hasOwnProperty.call(o,"server")){e.next=36;break}o.server={},i=[],s=_createForOfIteratorHelperLoose([].concat(r.binary.runner));case 8:if((l=s()).done){e.next=34;break}u=l.value,p=_createForOfIteratorHelperLoose([].concat(u.location));case 11:if((d=p()).done){e.next=30;break}m=d.value,f=_createForOfIteratorHelperLoose([].concat(u.name));case 14:if((b=f()).done){e.next=26;break}return h=b.value,y=(0,path__WEBPACK_IMPORTED_MODULE_5__.resolve)(m,h),i.push(y),e.next=20,clientnode__WEBPACK_IMPORTED_MODULE_3___default().isFile(y);case 20:if(!e.sent){e.next=24;break}return u.binaryFilePath=y,o.server.runner=u,e.abrupt("break",26);case 24:e.next=14;break;case 26:if(!Object.prototype.hasOwnProperty.call(o.server,"runner")){e.next=28;break}return e.abrupt("break",30);case 28:e.next=11;break;case 30:if(!Object.prototype.hasOwnProperty.call(o.server,"runner")){e.next=32;break}return e.abrupt("break",34);case 32:e.next=8;break;case 34:if(Object.prototype.hasOwnProperty.call(o.server,"runner")){e.next=36;break}throw new Error('No binary file in one of the following locations found: "'+i.join('", "')+'".');case 36:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),Database.loadService=function(){function loadService(){return _loadService.apply(this,arguments)}var _loadService=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function _callee3(_ref3){var configuration,services,promise,couchdb,urlPrefix,unauthenticatedUserDatabaseConnection,authenticatedUserDatabaseConnection,_i,_arr,type,_iterator6,_step6,name,userDatabaseConnection,_userDatabaseConnecti,_iterator7,_step7,prefix,subPath,fullPath,url,_value,response,changeNeeded,idName,typeName,modelConfiguration,models,databaseHelperCode,_iterator8,_step8,_type2,code,_i2,_Object$entries,_Object$entries$_i,modelName,model,_i3,_Object$entries2,_Object$entries2$_i,_name,specification,_iterator9,_step9,constraint,property,_iterator10,_step10,_type,_constraint,migrater,_iterator11,_step11,file,extension,_name2,document,_forbidden,_iterator12,_step12,retrievedDocument,_document,newDocument,_iterator13,_step13,_name3,result,indexes,_i4,_Object$entries3,_Object$entries3$_i,_modelName,_model,_iterator14,_step14,propertyName,_name4,foundPosition,position,_iterator15,_step15,index,_iterator16,_step16,_index,exists,_i5,_Object$entries4,_Object$entries4$_i,_modelName2,_model2,_iterator17,_step17,_name5;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(_context3){for(;;)switch(_context3.prev=_context3.next){case 0:if(configuration=_ref3.configuration,services=_ref3.services,promise=null,couchdb=services.couchdb,!Object.prototype.hasOwnProperty.call(couchdb.server,"runner")){_context3.next=10;break}return _context3.next=6,_helper__WEBPACK_IMPORTED_MODULE_8__.default.startServer(services,configuration);case 6:couchdb.server.restart=_helper__WEBPACK_IMPORTED_MODULE_8__.default.restartServer,couchdb.server.start=_helper__WEBPACK_IMPORTED_MODULE_8__.default.startServer,couchdb.server.stop=_helper__WEBPACK_IMPORTED_MODULE_8__.default.stopServer,promise=new Promise((function(e,t){couchdb.server.resolve=e,couchdb.server.reject=t}));case 10:if(!Object.prototype.hasOwnProperty.call(couchdb,"connection")){_context3.next=12;break}return _context3.abrupt("return",{couchdb:promise});case 12:if(urlPrefix=clientnode__WEBPACK_IMPORTED_MODULE_3___default().stringFormat(configuration.couchdb.url,configuration.couchdb.user.name+":"+configuration.couchdb.user.password+"@"),!configuration.couchdb.ensureAdminPresence){_context3.next=44;break}return unauthenticatedUserDatabaseConnection=new couchdb.connector(clientnode__WEBPACK_IMPORTED_MODULE_3___default().stringFormat(configuration.couchdb.url,"")+"/_users",_helper__WEBPACK_IMPORTED_MODULE_8__.default.getConnectorOptions(configuration)),_context3.prev=15,_context3.next=18,unauthenticatedUserDatabaseConnection.allDocs();case 18:return _context3.next=21,clientnode__WEBPACK_IMPORTED_MODULE_3__.globalContext.fetch(clientnode__WEBPACK_IMPORTED_MODULE_3___default().stringFormat(configuration.couchdb.url,"")+"/"+couchdb.server.runner.adminUserConfigurationPath+"/"+configuration.couchdb.user.name,{body:'"'+configuration.couchdb.user.password+'"',method:"PUT"});case 21:_context3.next=41;break;case 23:if(_context3.prev=23,_context3.t0=_context3.catch(15),"unauthorized"!==_context3.t0.name){_context3.next=40;break}return authenticatedUserDatabaseConnection=new couchdb.connector(urlPrefix+"/_users",_helper__WEBPACK_IMPORTED_MODULE_8__.default.getConnectorOptions(configuration)),_context3.prev=27,_context3.next=30,authenticatedUserDatabaseConnection.allDocs();case 30:_context3.next=35;break;case 32:_context3.prev=32,_context3.t1=_context3.catch(27);case 35:return _context3.prev=35,authenticatedUserDatabaseConnection.close(),_context3.finish(35);case 38:_context3.next=41;break;case 40:case 41:return _context3.prev=41,unauthenticatedUserDatabaseConnection.close(),_context3.finish(41);case 44:if(!configuration.couchdb.ensureUserPresence){_context3.next=79;break}_i=0,_arr=[configuration.couchdb.security.admins,configuration.couchdb.security.members];case 46:if(!(_i<_arr.length)){_context3.next=79;break}type=_arr[_i],_iterator6=_createForOfIteratorHelperLoose(type.names);case 49:if((_step6=_iterator6()).done){_context3.next=76;break}return name=_step6.value,userDatabaseConnection=new couchdb.connector(urlPrefix+"/_users",_helper__WEBPACK_IMPORTED_MODULE_8__.default.getConnectorOptions(configuration)),_context3.prev=52,_context3.next=55,userDatabaseConnection.get("org.couchdb.user:"+name);case 55:_context3.next=71;break;case 57:if(_context3.prev=57,_context3.t2=_context3.catch(52),"not_found"!==_context3.t2.error){_context3.next=70;break}return _context3.prev=60,_context3.next=63,userDatabaseConnection.put((_userDatabaseConnecti={},_userDatabaseConnecti[configuration.couchdb.model.property.name.special.id]="org.couchdb.user:"+name,_userDatabaseConnecti.name=name,_userDatabaseConnecti.password=name,_userDatabaseConnecti.roles=[].concat(type.roles.includes(name+"s")?name+"s":[]),_userDatabaseConnecti.type="user",_userDatabaseConnecti));case 63:_context3.next=68;break;case 65:throw _context3.prev=65,_context3.t3=_context3.catch(60),new Error("Couldn't create missing user \""+name+'": '+clientnode__WEBPACK_IMPORTED_MODULE_3___default().represent(_context3.t3));case 68:_context3.next=71;break;case 70:throw new Error("Couldn't check for presence of user \""+name+'": '+clientnode__WEBPACK_IMPORTED_MODULE_3___default().represent(_context3.t2));case 71:return _context3.prev=71,userDatabaseConnection.close(),_context3.finish(71);case 74:_context3.next=49;break;case 76:_i++,_context3.next=46;break;case 79:if(!configuration.couchdb.model.updateConfiguration){_context3.next=134;break}_iterator7=_createForOfIteratorHelperLoose(configuration.couchdb.backend.prefixes);case 81:if((_step7=_iterator7()).done){_context3.next=134;break}prefix=_step7.value,_context3.t4=_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().keys(configuration.couchdb.backend.configuration);case 84:if((_context3.t5=_context3.t4()).done){_context3.next=132;break}if(subPath=_context3.t5.value,!Object.prototype.hasOwnProperty.call(configuration.couchdb.backend.configuration,subPath)){_context3.next=130;break}return fullPath="/"+prefix+(prefix.trim()?"/":"")+subPath,url=""+urlPrefix+fullPath,_value=configuration.couchdb.backend.configuration[subPath],response=void 0,_context3.prev=91,_context3.next=94,clientnode__WEBPACK_IMPORTED_MODULE_3__.globalContext.fetch(url);case 94:response=_context3.sent,_context3.next=100;break;case 97:_context3.prev=97,_context3.t6=_context3.catch(91);case 100:if(!response){_context3.next=130;break}if(!response.ok){_context3.next=129;break}if(changeNeeded=!0,"function"!=typeof response.text){_context3.next=115;break}return _context3.prev=104,_context3.t7=_value,_context3.next=108,response["string"==typeof _value?"text":"json"]();case 108:_context3.t8=_context3.sent,changeNeeded=_context3.t7===_context3.t8,_context3.next=115;break;case 112:_context3.prev=112,_context3.t9=_context3.catch(104);case 115:if(!changeNeeded){_context3.next=126;break}return _context3.prev=116,_context3.next=119,clientnode__WEBPACK_IMPORTED_MODULE_3__.globalContext.fetch(url,{body:'"'+configuration.couchdb.backend.configuration[subPath]+'"',method:"PUT"});case 119:_context3.next=124;break;case 121:_context3.prev=121,_context3.t10=_context3.catch(116);case 124:_context3.next=127;break;case 126:case 127:_context3.next=130;break;case 129:case 130:_context3.next=84;break;case 132:_context3.next=81;break;case 134:return _context3.next=136,_helper__WEBPACK_IMPORTED_MODULE_8__.default.initializeConnection(services,configuration);case 136:if(idName=configuration.couchdb.model.property.name.special.id,typeName=configuration.couchdb.model.property.name.special.type,!configuration.couchdb.ensureSecuritySettingsPresence){_context3.next=147;break}return _context3.prev=139,_context3.next=142,clientnode__WEBPACK_IMPORTED_MODULE_3__.globalContext.fetch(urlPrefix+"/"+configuration.couchdb.databaseName+"/_security",{body:JSON.stringify(configuration.couchdb.security),method:"PUT"});case 142:_context3.next=147;break;case 144:_context3.prev=144,_context3.t11=_context3.catch(139);case 147:if(modelConfiguration=clientnode__WEBPACK_IMPORTED_MODULE_3___default().copy(configuration.couchdb.model),delete modelConfiguration.property.defaultSpecification,delete modelConfiguration.entities,models=_helper__WEBPACK_IMPORTED_MODULE_8__.default.extendModels(configuration.couchdb.model),!configuration.couchdb.model.updateValidation){_context3.next=215;break}return _context3.next=154,fs__WEBPACK_IMPORTED_MODULE_4__.promises.readFile(eval("require.resolve('./databaseHelper')"),{encoding:configuration.core.encoding,flag:"r"});case 154:databaseHelperCode=_context3.sent,_iterator8=_createForOfIteratorHelperLoose([{description:"Model specification",methodName:"validateDocumentUpdate",name:"validation",serializedParameter:JSON.stringify(modelConfiguration)+", "+JSON.stringify(models)},{description:"Authorisation",methodName:"authenticate",name:"authentication",serializedParameter:JSON.stringify(_helper__WEBPACK_IMPORTED_MODULE_8__.default.determineAllowedModelRolesMapping(configuration.couchdb.model))+", '"+idName+"', '"+typeName+"', '"+configuration.couchdb.model.property.name.special.designDocumentNamePrefix+"'"}]);case 156:if((_step8=_iterator8()).done){_context3.next=171;break}_type2=_step8.value,code="function(...parameters) {\n return require('helper').default."+_type2.methodName+"(...parameters.concat(["+_type2.serializedParameter+"]))\n}",_context3.prev=159,new Function("return "+code),_context3.next=166;break;case 163:throw _context3.prev=163,_context3.t12=_context3.catch(159),new Error("Generated "+_type2.name+' code "'+code+"\" doesn't compile: "+clientnode__WEBPACK_IMPORTED_MODULE_3___default().represent(_context3.t12));case 166:return configuration.core.debug,_context3.next=169,_helper__WEBPACK_IMPORTED_MODULE_8__.default.ensureValidationDocumentPresence(couchdb.connection,_type2.name,{helper:databaseHelperCode,validate_doc_update:code},_type2.description,!0,idName,modelConfiguration.property.name.special.designDocumentNamePrefix);case 169:_context3.next=156;break;case 171:_i2=0,_Object$entries=Object.entries(models);case 172:if(!(_i2<_Object$entries.length)){_context3.next=215;break}_Object$entries$_i=_Object$entries[_i2],modelName=_Object$entries$_i[0],model=_Object$entries$_i[1],_i3=0,_Object$entries2=Object.entries(model);case 175:if(!(_i3<_Object$entries2.length)){_context3.next=212;break}if(_Object$entries2$_i=_Object$entries2[_i3],_name=_Object$entries2$_i[0],specification=_Object$entries2$_i[1],![modelConfiguration.property.name.special.constraint.execution,modelConfiguration.property.name.special.constraint.expression].includes(_name)){_context3.next=193;break}_iterator9=_createForOfIteratorHelperLoose([].concat(specification));case 179:if((_step9=_iterator9()).done){_context3.next=191;break}if(constraint=_step9.value,!constraint.description){_context3.next=189;break}_context3.prev=182,new Function("return "+constraint.description),_context3.next=189;break;case 186:throw _context3.prev=186,_context3.t13=_context3.catch(182),new Error('Specified constraint description "'+constraint.description+'" for model "'+modelName+'" doesn\'t compile: "'+clientnode__WEBPACK_IMPORTED_MODULE_3___default().represent(_context3.t13)+'".');case 189:_context3.next=179;break;case 191:_context3.next=209;break;case 193:property=specification,_iterator10=_createForOfIteratorHelperLoose(["conflictingConstraintExpression","conflictingConstraintExecution","constraintExpression","constraintExecution"]);case 195:if((_step10=_iterator10()).done){_context3.next=209;break}if(_type=_step10.value,null===property||"object"!=typeof property){_context3.next=207;break}if(_constraint=property[_type],null==_constraint||!_constraint.description){_context3.next=207;break}_context3.prev=200,new Function(_constraint.description),_context3.next=207;break;case 204:throw _context3.prev=204,_context3.t14=_context3.catch(200),new Error('Specified constraint description "'+_constraint.description+'" for model "'+modelName+'" in property "'+_name+'" as "'+_type+'" doesn\'t compile: "'+clientnode__WEBPACK_IMPORTED_MODULE_3___default().represent(_context3.t14)+'".');case 207:_context3.next=195;break;case 209:_i3++,_context3.next=175;break;case 212:_i2++,_context3.next=172;break;case 215:if(!configuration.couchdb.model.autoMigrationPath){_context3.next=314;break}return migrater={},_context3.next=219,clientnode__WEBPACK_IMPORTED_MODULE_3___default().isDirectory((0,path__WEBPACK_IMPORTED_MODULE_5__.resolve)(configuration.couchdb.model.autoMigrationPath));case 219:if(!_context3.sent){_context3.next=266;break}return _context3.t15=_createForOfIteratorHelperLoose,_context3.next=223,clientnode__WEBPACK_IMPORTED_MODULE_3___default().walkDirectoryRecursively((0,path__WEBPACK_IMPORTED_MODULE_5__.resolve)(configuration.couchdb.model.autoMigrationPath),configuration.couchdb.debug?clientnode__WEBPACK_IMPORTED_MODULE_3___default().noop:function(e){return"debug"!==e.name});case 223:_context3.t16=_context3.sent,_iterator11=(0,_context3.t15)(_context3.t16);case 225:if((_step11=_iterator11()).done){_context3.next=266;break}if(file=_step11.value,extension=(0,path__WEBPACK_IMPORTED_MODULE_5__.extname)(file.name),_name2=(0,path__WEBPACK_IMPORTED_MODULE_5__.basename)(file.name,extension),".json"!==extension){_context3.next=256;break}return document=void 0,_context3.prev=231,_context3.t17=JSON,_context3.next=235,fs__WEBPACK_IMPORTED_MODULE_4__.promises.readFile(file.path,{encoding:configuration.core.encoding,flag:"r"});case 235:_context3.t18=_context3.sent,document=_context3.t17.parse.call(_context3.t17,_context3.t18),_context3.next=242;break;case 239:throw _context3.prev=239,_context3.t19=_context3.catch(231),new Error('Parsing document "'+file.path+'" to include by automigration of has failed: '+clientnode__WEBPACK_IMPORTED_MODULE_3___default().represent(_context3.t19));case 242:return document[idName]=_name2,document[configuration.couchdb.model.property.name.special.revision]="upsert",_context3.prev=244,_context3.next=247,couchdb.connection.put(document);case 247:_context3.next=253;break;case 249:throw _context3.prev=249,_context3.t20=_context3.catch(244),null!=(_forbidden=_context3.t20.forbidden)&&_forbidden.startsWith("NoChange:"),new Error('Migrating document "'+document[idName]+'" of type "'+document[typeName]+'" has failed: '+clientnode__WEBPACK_IMPORTED_MODULE_3___default().represent(_context3.t20));case 253:_context3.next=264;break;case 256:if(![".js"].includes((0,path__WEBPACK_IMPORTED_MODULE_5__.extname)(file.name))){_context3.next=260;break}migrater[file.path]=eval("require('"+file.path+"')").default,_context3.next=264;break;case 260:if(![".mjs"].includes((0,path__WEBPACK_IMPORTED_MODULE_5__.extname)(file.name))){_context3.next=264;break}return _context3.next=263,eval("import('"+file.path+"')");case 263:migrater[file.path]=_context3.sent.default;case 264:_context3.next=225;break;case 266:return _context3.t21=_createForOfIteratorHelperLoose,_context3.next=269,couchdb.connection.allDocs({include_docs:!0});case 269:_context3.t22=_context3.sent.rows,_iterator12=(0,_context3.t21)(_context3.t22);case 271:if((_step12=_iterator12()).done){_context3.next=314;break}if(retrievedDocument=_step12.value,"string"==typeof retrievedDocument.id&&retrievedDocument.id.startsWith(configuration.couchdb.model.property.name.special.designDocumentNamePrefix)){_context3.next=312;break}_document=retrievedDocument.doc,newDocument=clientnode__WEBPACK_IMPORTED_MODULE_3___default().copy(_document),newDocument[configuration.couchdb.model.property.name.special.strategy]="migrate",_iterator13=_createForOfIteratorHelperLoose(Object.keys(migrater).sort());case 278:if((_step13=_iterator13()).done){_context3.next=291;break}_name3=_step13.value,result=null,_context3.prev=281,result=migrater[_name3](newDocument,{configuration,databaseHelper:_databaseHelper__WEBPACK_IMPORTED_MODULE_9___default(),Tools:clientnode__WEBPACK_IMPORTED_MODULE_3___default(),idName,typeName,migrater,models,modelConfiguration,selfFilePath:_name3,services}),_context3.next=288;break;case 285:throw _context3.prev=285,_context3.t23=_context3.catch(281),new Error('Running migrater "'+_name3+'" in document '+_helper__WEBPACK_IMPORTED_MODULE_8__.default.mayStripRepresentation(_document,configuration.couchdb.maximumRepresentationTryLength,configuration.couchdb.maximumRepresentationLength)+'" failed: '+clientnode__WEBPACK_IMPORTED_MODULE_3___default().represent(_context3.t23));case 288:result&&(newDocument=result);case 289:_context3.next=278;break;case 291:_context3.prev=291,_databaseHelper__WEBPACK_IMPORTED_MODULE_9___default().validateDocumentUpdate(clientnode__WEBPACK_IMPORTED_MODULE_3___default().copy(newDocument),clientnode__WEBPACK_IMPORTED_MODULE_3___default().copy(_document),{db:configuration.couchdb.databaseName,name:configuration.couchdb.user.name,roles:["_admin"]},clientnode__WEBPACK_IMPORTED_MODULE_3___default().copy(configuration.couchdb.security),modelConfiguration,models),_context3.next=303;break;case 295:if(_context3.prev=295,_context3.t24=_context3.catch(291),!Object.prototype.hasOwnProperty.call(_context3.t24,"forbidden")){_context3.next=302;break}return _context3.t24.forbidden.startsWith("NoChange:"),_context3.abrupt("continue",312);case 302:throw _context3.t24;case 303:return _context3.prev=303,_context3.next=306,couchdb.connection.put(newDocument);case 306:_context3.next=311;break;case 308:throw _context3.prev=308,_context3.t25=_context3.catch(303),new Error('Replaceing auto migrated document "'+newDocument[idName]+'" has failed: '+clientnode__WEBPACK_IMPORTED_MODULE_3___default().represent(_context3.t25));case 311:case 312:_context3.next=271;break;case 314:if(!configuration.couchdb.createGenericFlatIndex||!configuration.couchdb.model.autoMigrationPath){_context3.next=369;break}return _context3.next=317,couchdb.connection.getIndexes();case 317:indexes=_context3.sent.indexes,_i4=0,_Object$entries3=Object.entries(models);case 319:if(!(_i4<_Object$entries3.length)){_context3.next=350;break}if(_Object$entries3$_i=_Object$entries3[_i4],_modelName=_Object$entries3$_i[0],_model=_Object$entries3$_i[1],!new RegExp(configuration.couchdb.model.property.name.typeRegularExpressionPattern.public).test(_modelName)){_context3.next=347;break}return _context3.next=324,couchdb.connection.createIndex({index:{ddoc:_modelName+"-GenericIndex",fields:[typeName],name:_modelName+"-GenericIndex"}});case 324:_iterator14=_createForOfIteratorHelperLoose(_helper__WEBPACK_IMPORTED_MODULE_8__.default.determineGenericIndexablePropertyNames(configuration.couchdb.model,_model));case 325:if((_step14=_iterator14()).done){_context3.next=347;break}propertyName=_step14.value,_name4=_modelName+"-"+propertyName+"-GenericIndex",foundPosition=-1,position=0,_iterator15=_createForOfIteratorHelperLoose(indexes);case 331:if((_step15=_iterator15()).done){_context3.next=339;break}if(index=_step15.value,index.name!==_name4){_context3.next=336;break}return foundPosition=position,_context3.abrupt("break",339);case 336:position+=1;case 337:_context3.next=331;break;case 339:if(-1!==foundPosition){_context3.next=344;break}return _context3.next=342,couchdb.connection.createIndex({index:{ddoc:_name4,fields:[typeName,propertyName],name:_name4}});case 342:_context3.next=345;break;case 344:indexes.slice(position,1);case 345:_context3.next=325;break;case 347:_i4++,_context3.next=319;break;case 350:_iterator16=_createForOfIteratorHelperLoose(indexes);case 351:if((_step16=_iterator16()).done){_context3.next=369;break}if(_index=_step16.value,!_index.name.endsWith("-GenericIndex")){_context3.next=367;break}exists=!1,_i5=0,_Object$entries4=Object.entries(models);case 356:if(!(_i5<_Object$entries4.length)){_context3.next=364;break}if(_Object$entries4$_i=_Object$entries4[_i5],_modelName2=_Object$entries4$_i[0],_model2=_Object$entries4$_i[1],!_index.name.startsWith(_modelName2+"-")){_context3.next=361;break}for(_iterator17=_createForOfIteratorHelperLoose(_helper__WEBPACK_IMPORTED_MODULE_8__.default.determineGenericIndexablePropertyNames(configuration.couchdb.model,_model2));!(_step17=_iterator17()).done;)_name5=_step17.value,[_modelName2+"-"+_name5+"-GenericIndex",_modelName2+"-GenericIndex"].includes(_index.name)&&(exists=!0);return _context3.abrupt("break",364);case 361:_i5++,_context3.next=356;break;case 364:if(exists){_context3.next=367;break}return _context3.next=367,couchdb.connection.deleteIndex(_index);case 367:_context3.next=351;break;case 369:if(!configuration.couchdb.model.triggerInitialCompaction){_context3.next=378;break}return _context3.prev=370,_context3.next=373,couchdb.connection.compact();case 373:_context3.next=378;break;case 375:_context3.prev=375,_context3.t26=_context3.catch(370);case 378:return _context3.abrupt("return",{couchdb:promise});case 379:case"end":return _context3.stop()}}),_callee3,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],[281,285],[291,295],[303,308],[370,375]])})));return loadService}(),Database.postLoadService=function(e){var t=e.configuration.couchdb,r=e.pluginAPI,n=e.services.couchdb,o=0;setInterval((function(){0<o&&(o=0)}),3e4);var a=clientnode__WEBPACK_IMPORTED_MODULE_3___default().debounce(_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function _(){return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(_){for(;;)switch(_.prev=_.next){case 0:return n.changesStream&&n.changesStream.cancel(),n.changesStream=n.connection.changes(t.changesStream),n.changesStream.on("error",_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function t(){return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!(3<(o+=1))){t.next=9;break}return o=0,n.changesStream.cancel(),t.next=7,n.server.restart(e);case 7:t.next=10;break;case 9:case 10:a();case 11:case"end":return t.stop()}}),t)})))),_.next=5,r.callStack(_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({},e,{data:n.changesStream,hook:"couchdbInitializeChangesStream"}));case 5:case"end":return _.stop()}}),_)}))));return t.attachAutoRestarter&&a(),Promise.resolve()},Database.shouldExit=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,o;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.services,e.next=3,_helper__WEBPACK_IMPORTED_MODULE_8__.default.stopServer(n,r);case 3:return delete n.couchdb,o="log.txt",e.next=7,clientnode__WEBPACK_IMPORTED_MODULE_3___default().isFile(o);case 7:if(!e.sent){e.next=10;break}return e.next=10,fs__WEBPACK_IMPORTED_MODULE_4__.promises.unlink(o);case 10:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),Database}();Database.toggleIDDetermining=Symbol("toggleIDDetermining");const __WEBPACK_DEFAULT_EXPORT__=Database})(),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("clientnode")},e=>{"use strict";e.exports=require("fs")},e=>{"use strict";e.exports=require("path")},e=>{"use strict";e.exports=require("child_process")},e=>{"use strict";e.exports=require("pouchdb-node/node_modules/node-fetch/lib/index.js")},(__unused_webpack_module,__webpack_exports__,__webpack_require__)=>{"use strict";__webpack_require__.d(__webpack_exports__,{determineAllowedModelRolesMapping:()=>determineAllowedModelRolesMapping,determineGenericIndexablePropertyNames:()=>determineGenericIndexablePropertyNames,ensureValidationDocumentPresence:()=>ensureValidationDocumentPresence,extendModels:()=>extendModels,getConnectorOptions:()=>getConnectorOptions,initializeConnection:()=>initializeConnection,mayStripRepresentation:()=>mayStripRepresentation,restartServer:()=>restartServer,startServer:()=>startServer,stopServer:()=>stopServer});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__(6),child_process__WEBPACK_IMPORTED_MODULE_3___default=__webpack_require__.n(child_process__WEBPACK_IMPORTED_MODULE_3__),clientnode__WEBPACK_IMPORTED_MODULE_4__=__webpack_require__(3),clientnode__WEBPACK_IMPORTED_MODULE_4___default=__webpack_require__.n(clientnode__WEBPACK_IMPORTED_MODULE_4__),node_fetch__WEBPACK_IMPORTED_MODULE_5__=__webpack_require__(7),node_fetch__WEBPACK_IMPORTED_MODULE_5___default=__webpack_require__.n(node_fetch__WEBPACK_IMPORTED_MODULE_5__),fs__WEBPACK_IMPORTED_MODULE_6__=__webpack_require__(4),fs__WEBPACK_IMPORTED_MODULE_6___default=__webpack_require__.n(fs__WEBPACK_IMPORTED_MODULE_6__),path__WEBPACK_IMPORTED_MODULE_7__=__webpack_require__(5),path__WEBPACK_IMPORTED_MODULE_7___default=__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_7__),_this=void 0;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 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)}}},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"},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,o,a,_,c){var i,s,l;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return void 0===a&&(a=!0),void 0===_&&(_="_id"),void 0===c&&(c="_design/"),s=_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()(((i={})[_]=""+c+r,i.language="javascript",i),n),e.prev=4,e.next=7,t.get(""+c+r);case 7:return l=e.sent,s._rev=l._rev,e.next=11,t.put(s);case 11:case 20:e.next=26;break;case 14:return e.prev=14,e.t0=e.catch(4),a&&e.t0.error,e.prev=17,e.next=20,t.put(s);case 23:throw e.prev=23,e.t1=e.catch(17),new Error(o+" 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)}}(),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,o,a,_,c,i,s,l;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=r.couchdb,o=clientnode__WEBPACK_IMPORTED_MODULE_4___default().stringFormat(n.url,n.user.name+":"+n.user.password+"@")+"/"+n.databaseName,t.couchdb.connection=new t.couchdb.connector(o,getConnectorOptions(r)),(a=t.couchdb.connection).setMaxListeners(1/0),_=n.model.property.name.special.id,c=n.model.property.name.special.revision,i=_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function(){var e,t;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:e=l.value,t=a[e].bind(a),a[e]=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function e(r,o){var a,i,s;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,t(r,o);case 3:return e.abrupt("return",e.sent);case 6:if(e.prev=6,e.t0=e.catch(0),!((i=r[_])&&n.ignoreNoChangeError&&"forbidden"===e.t0.name&&null!=(a=e.t0.message)&&a.startsWith("NoChange:"))){e.next=22;break}if(s="object"==typeof o&&c in o?o[c]:r[c],e.t1=i,!(c in r)||["latest","upsert"].includes(s)){e.next=16;break}e.t2=s,e.next=20;break;case 16:return e.next=18,this.get(i);case 18:e.t3=c,e.t2=e.sent[e.t3];case 20:return e.t4=e.t2,e.abrupt("return",{id:e.t1,rev:e.t4,ok:!0});case 22:throw e.t0;case 23:case"end":return e.stop()}}),e,this,[[0,6]])})));case 3:case"end":return r.stop()}}),i)})),s=_createForOfIteratorHelperLoose(["post","put"]);case 9:if((l=s()).done){e.next=13;break}return e.delegateYield(i(),"t0",11);case 11:e.next=9;break;case 13:return e.prev=13,e.next=16,clientnode__WEBPACK_IMPORTED_MODULE_4___default().checkReachability(o);case 16:e.next=23;break;case 18:return e.prev=18,e.t1=e.catch(13),e.next=23,clientnode__WEBPACK_IMPORTED_MODULE_4__.globalContext.fetch(o,{method:"PUT"});case 23:return e.abrupt("return",t);case 24:case"end":return e.stop()}}),e,null,[[13,18]])})));return function(){return e.apply(this,arguments)}}(),startServer=function(){var _ref4=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function _callee4(services,configuration){var server,runner,binary;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(_context5){for(;;)switch(_context5.prev=_context5.next){case 0:if(server=services.couchdb.server,runner=server.runner,binary=configuration.couchdb.binary,!Object.prototype.hasOwnProperty.call(runner,"configurationFile")){_context5.next=15;break}return _context5.prev=4,_context5.next=7,fs__WEBPACK_IMPORTED_MODULE_6__.promises.mkdir(path__WEBPACK_IMPORTED_MODULE_7___default().dirname(runner.configurationFile.path),{recursive:!0});case 7:_context5.next=13;break;case 9:if(_context5.prev=9,_context5.t0=_context5.catch(4),"EEXIST"===_context5.t0.code){_context5.next=13;break}throw _context5.t0;case 13:return _context5.next=15,fs__WEBPACK_IMPORTED_MODULE_6__.promises.writeFile(runner.configurationFile.path,runner.configurationFile.content,{encoding:configuration.core.encoding});case 15:return server.process=(0,child_process__WEBPACK_IMPORTED_MODULE_3__.spawn)("default"===binary.memoryInMegaByte?runner.binaryFilePath:binary.nodePath,("default"===binary.memoryInMegaByte?[]:["--max-old-space-size="+binary.memoryInMegaByte,runner.binaryFilePath]).concat(runner.arguments?runner.arguments:[]),{cwd:eval("process").cwd(),env:Object.prototype.hasOwnProperty.call(runner,"environment")?_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({},eval("process").env,runner.environment):eval("process").env,shell:!0,stdio:"inherit"}),new Promise((function(e,t){for(var r,n,o=_createForOfIteratorHelperLoose(clientnode__WEBPACK_IMPORTED_MODULE_4__.CloseEventNames);!(r=o()).done;)n=r.value,server.process.on(n,clientnode__WEBPACK_IMPORTED_MODULE_4___default().getProcessCloseHandler(e,t,{process: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)})),_context5.next=19,clientnode__WEBPACK_IMPORTED_MODULE_4___default().checkReachability(clientnode__WEBPACK_IMPORTED_MODULE_4___default().stringFormat(configuration.couchdb.url,""),{wait:!0});case 19:case"end":return _context5.stop()}}),_callee4,null,[[4,9]])})));return function(){return _ref4.apply(this,arguments)}}(),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,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=t.configuration,n=t.pluginAPI,o=t.services,a=o.couchdb.server,_=a.resolve,c=a.reject,a.resolve=a.reject=clientnode__WEBPACK_IMPORTED_MODULE_4___default().noop,e.next=7,stopServer(o,r);case 7:return a.resolve=_,a.reject=c,e.next=11,startServer(o,r);case 11:return initializeConnection(o,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)}}(),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,o;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.couchdb,o=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(o.url,""),{wait:!0});case 6:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),determineAllowedModelRolesMapping=function(e){for(var t=e.property.name.special.allowedRole,r={},n=extendModels(e),o=0,a=Object.entries(n);o<a.length;o++){var _=a[o],c=_[0],i=_[1];if(Object.prototype.hasOwnProperty.call(i,t)){r[c]=_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({properties:{}},normalizeAllowedRoles(i[t]));for(var s=0,l=Object.entries(i);s<l.length;s++){var u=l[s],p=u[0],d=u[1];null!==d&&"object"==typeof d&&d.allowedRoles&&(r[c].properties[p]=normalizeAllowedRoles(d.allowedRoles))}}else r[c]={properties:{},read:[],write:[]}}return r},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.allowedRole,r.attachment,r.conflict,r.constraint.execution,r.constraint.expression,r.deleted,r.deletedConflict,r.extend,r.maximumAggregatedSize,r.minimumAggregatedSize,r.oldType,r.id,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()},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,o,a=_createForOfIteratorHelperLoose([].concat(t[e][r]));!(n=a()).done;)o=n.value,t[e]=clientnode__WEBPACK_IMPORTED_MODULE_4___default().extend(!0,clientnode__WEBPACK_IMPORTED_MODULE_4___default().copy(extendModel(o,t,r)),t[e]);delete t[e][r]}return t[e]},extendModels=function(e){for(var t,r=e.property.name.special,n={},o=e.property.name.typeRegularExpressionPattern,a=0,_=Object.keys(e.entities);a<_.length;a++){if(t=_[a],!new RegExp(o.public).test(t)&&!new RegExp(o.private).test(t))throw new Error('Model names have to match "'+o.public+'" or "'+o.private+'" for private one (given name: "'+t+'").');n[t]=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],m=p[1];if(d===r.attachment)for(var f=0,b=Object.entries(m);f<b.length;f++){var y=b[f],h=y[0],O=y[1];m[h]=clientnode__WEBPACK_IMPORTED_MODULE_4___default().extend(!0,clientnode__WEBPACK_IMPORTED_MODULE_4___default().copy(e.property.defaultSpecification),O)}else[r.allowedRole,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),m))}}return n},normalizeAllowedRoles=function(e){if(Array.isArray(e))return{read:e,write:e};if("object"==typeof e){for(var t,r={read:[],write:[]},n=0,o=Object.keys(r);n<o.length;n++)t=o[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]}}},e=>{!function(){"use strict";function t(){return(t=function(){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}}()?Reflect.construct.bind():function(e,t,n){var o=[null];o.push.apply(o,t);var a=new(Function.bind.apply(e,o));return n&&r(a,n.prototype),a}).apply(null,arguments)}function r(e,t){return r=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},r(e,t)}function n(){return n=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},n.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 a(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)?a(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 a(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 _={d:function(e,t){for(var r in t)_.o(t,r)&&!_.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})}},c={};_.r(c),_.d(c,{DatabaseHelper:function(){return i},default:function(){return s}});var i=function(){function e(){}return e.authenticate=function(e,t,r,n,a,_,c,i,s){var l;void 0===t&&(t=null),void 0===r&&(r={}),void 0===n&&(n={admins:{names:[],roles:[]},members:{names:[],roles:[]}}),void 0===_&&(_="_id"),void 0===c&&(c="-type"),void 0===i&&(i="_design/"),void 0===s&&(s=!1);var u=null!==(l=e[c])&&void 0!==l?l:t&&t[c];if(!u)return!0;var p=s?"read":"write",d={properties:{},read:["_admin","readonlyadmin"],write:["_admin"]};Object.prototype.hasOwnProperty.call(e,_)&&e[_].startsWith(i)&&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&&u&&Object.prototype.hasOwnProperty.call(a,u)){for(var b,y,h=a[u],O=o(["read","write"]);!(b=O()).done;)d[y=b.value]=d[y].concat(h[y]||[]);d.properties=h.properties}for(var x,g,E=d[p],P=o(r.roles);!(x=P()).done;)if(g=x.value,E.includes(g))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 "+p+' action: "'+[].concat(d[p]).join('", "')+'". '+f+"."}},e.validateDocumentUpdate=function(e,r,a,_,c,i,s){void 0===i&&(i={});var l=function(e,t,r){var o;throw void 0===t&&(t="forbidden"),void 0===r&&(r={}),n(((o={})[t]=e,o.message=e,o.name=t,o),r)},u=new Date,p=Date.UTC(u.getUTCFullYear(),u.getUTCMonth(),u.getUTCDate(),u.getUTCHours(),u.getUTCMinutes(),u.getUTCSeconds(),u.getUTCMilliseconds())/1e3,d=!c.dateTimeFormat.startsWith("iso"),m=c.property.name.special,f=m.id,b=m.revision,y=m.type;r&&r[y]&&!e[y]&&(e[y]=r[y]);var h="",O="",x=function(){h=Object.prototype.hasOwnProperty.call(e,f)?e[f]:"",O=Object.prototype.hasOwnProperty.call(e,b)?e[b]:""};if(x(),Object.prototype.hasOwnProperty.call(_,c.property.name.validatedDocumentsCache)&&_[c.property.name.validatedDocumentsCache].has(h+"-"+O))return _[c.property.name.validatedDocumentsCache].delete(h+"-"+O),e;["latest","upsert"].includes(O)&&(r&&Object.prototype.hasOwnProperty.call(r,b)?O=e[b]=r[b]:"latest"===O?l("Revision: No old document available to update."):delete e[b]);var g=c.updateStrategy;Object.prototype.hasOwnProperty.call(e,m.strategy)&&(g=e[m.strategy],delete e[m.strategy]);var E,P={};if("migrate"===g)for(var v=0,D=Object.entries(i);v<D.length;v++){var M=D[v],w=M[0],C=M[1];if(Object.prototype.hasOwnProperty.call(C,m.oldType)&&![null,void 0].includes(C[m.oldType]))for(var A,k,T=o([].concat(C[m.oldType]));!(A=T()).done;)k=A.value,P[k]=w}s?E=s:JSON&&Object.prototype.hasOwnProperty.call(JSON,"stringify")?E=function(e){return JSON.stringify(e,null,4)}:l('Needed "serializer" is not available.');var I=[m.additional,m.allowedRole,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],R=function(e){return e instanceof Error?""+e:E(e)},j=function(e){return"string"==typeof e?e.trim():""},U=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},L=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},W=function(t,r){if(r||(r=e[m.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 _=Object.keys(r);if(_.length)return _[0]}return null},B=function(e,r,o){void 0===r&&(r=!1),void 0===o&&(o={});var a=j(e);if(a){var _,c=(r?"return ":"")+a,i=n({},N,{code:c},o),s=Object.keys(i);try{_=t(Function,s.concat([c]))}catch(_){l(R(_),"compilation",{code:c,error:_,scope:i})}var u={code:c,result:void 0,scope:i};try{u.result=_.apply(void 0,s.map((function(e){return i[e]})))}catch(_){l(R(_),"runtime",{code:c,error:_,scope:i})}return u}l("No expression to evaluate provided.","empty")},K=function(e,r,n){void 0===n&&(n=[]);var a=n.length?" in "+n.join(" -> "):"",_=[],s=function(){Object.prototype.hasOwnProperty.call(e,y)||(r&&Object.prototype.hasOwnProperty.call(r,y)&&["fillUp","migrate"].includes(g)?e[y]=r[y]:l('Type: You have to specify a model type via property "'+y+'"'+a+".")),n.length||new RegExp(c.property.name.typeRegularExpressionPattern.public).test(e[y])||l('TypeName: You have to specify a model type which matches "'+c.property.name.typeRegularExpressionPattern.public+'" as public type (given "'+e[y]+'")'+a+"."),Object.prototype.hasOwnProperty.call(i,e[y])||(Object.prototype.hasOwnProperty.call(P,e[y])?e[y]=P[e[y]]:l('Model: Given model "'+e[y]+'" is not specified'+a+"."))};s();var u=e[y],p=i[u],h=null;Object.prototype.hasOwnProperty.call(p,m.additional)&&p[m.additional]&&(h=p[m.additional]);var O=function _(c,i,s,d,m){void 0===m&&(m=["constraintExecution","constraintExpression"]);for(var f,b,y=o(m);!(f=y()).done;)if(b=f.value,Object.prototype.hasOwnProperty.call(s,b)){var h=void 0;try{h=B(s[b].evaluation,b.endsWith("Expression"),{checkPropertyContent:_,model:p,modelName:u,name:i,type:b,newDocument:e,newValue:c,oldDocument:r,oldValue:d,parentNames:n,pathDescription:a,propertySpecification:s})}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&l('Compilation: Hook "'+b+'" has invalid code "'+e.code+'": "'+e.message+'"'+a+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&l('Runtime: Hook "'+b+'" has throw an error with code "'+e.code+'": "'+e.message+'"'+a+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}if(h&&!h.result){var O=j(s[b].description);l(b.charAt(0).toUpperCase()+(b.substring(1)+": ")+(O?t(Function,Object.keys(h.scope).concat(["return "+O])).apply(void 0,Object.values(h.scope)):'Property "'+i+'" should satisfy constraint "'+h.code+'" (given "'+R(c)+'")'+a+"."))}}},E=function(e,t,r,_){void 0===_&&(_=null);var c=[],s=[].concat(r.type?r.type:[]);"object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype&&!Object.prototype.hasOwnProperty.call(e,y)&&1===s.length&&Object.prototype.hasOwnProperty.call(i,s[0])&&(e[y]=s[0]);for(var u,p,m=!1,b=o(s);!(u=b()).done;)if(p=u.value,Object.prototype.hasOwnProperty.call(i,p)){if("object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype&&Object.prototype.hasOwnProperty.call(e,y)&&e[y]!==p&&"migrate"===g&&1===s.length&&(e[y]=p,c=n.concat(t,"migrate nested object type")),"object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype&&Object.prototype.hasOwnProperty.call(e,y)&&e[y]===p){var h=K(e,_,n.concat(t));if(h.changedPath.length&&(c=h.changedPath),e=h.newDocument,R(e)===R({}))return{newValue:null,changedPath:c};m=!0;break}1===s.length&&l('NestedType: Under key "'+t+'" isn\'t of type "'+p+'" (given "'+R(e)+'" of type '+typeof e+")"+a+".")}else if("DateTime"===p){var x=e;if(e=U(e),!(d&&("number"!=typeof e||isNaN(e))||!d&&"string"!=typeof e)){m=!0;break}1===s.length&&l('PropertyType: Property "'+t+'" isn\'t of (valid) type "DateTime" (given "'+R(x).replace(/^"/,"").replace(/"$/,"")+'" of type "'+typeof x+'")'+a+".")}else if(["boolean","integer","number","string"].includes(p)){if(!("number"==typeof e&&isNaN(e)||"integer"!==p&&typeof e!==p||"integer"===p&&parseInt(e,10)!==e)){m=!0;break}1===s.length&&l('PropertyType: Property "'+t+'" isn\'t of (valid) type "${type}" (given "'+R(e)+'" of type "'+typeof e+'")'+a+".")}else if("string"==typeof p&&p.startsWith("foreignKey:")){var E=i[p.substring(11)][f].type;if(E===typeof e){m=!0;break}1===s.length&&l('PropertyType: Foreign key property "'+t+'" isn\'t of type "'+E+'" (given "'+R(e)+'" of type "'+typeof e+'")'+a+".")}else{if("any"===p||R(e)===R(p)){m=!0;break}1===s.length&&l('PropertyType: Property "'+t+'" isn\'t value "'+p+'" (given "'+R(e).replace(/^"/,"").replace(/"$/,"")+'" of type "'+typeof e+'")'+a+".")}if(m||l('PropertyType: None of the specified types "'+s.join('", "')+'" for property "'+t+'" matches value "'+R(e).replace(/^"/,"").replace(/"$/,"")+e+'" of type "'+typeof e+'")'+a+"."),"string"==typeof e&&(![null,void 0].includes(r.minimumLength)&&e.length<r.minimumLength&&l('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&&l('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&&l('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&&l('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(U)),P.includes(e)||l('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)&&l('InvertedPatternMatch: Property "'+t+'" should not match regular expression pattern '+r.invertedRegularExpressionPattern+' (given "'+e+'")'+a+"."):l('PatternMatch: Property "'+t+'" should match regular expression pattern '+r.regularExpressionPattern+' (given "'+e+'")'+a+"."),O(e,t,r,_),R(e)!==R(_)&&(c=n.concat(t,"value updated")),{newValue:e,changedPath:c}},v=function(e,t,r,o,a){var i=t[o];if(!e.writable)if(r){if(Object.prototype.hasOwnProperty.call(r,o)&&R(i)===R(r[o]))return o!==f&&"incremental"===g&&delete t[o],!0;l('Readonly: Property "'+o+'" is not writable (old document "'+R(r)+'")'+a+".")}else l('Readonly: Property "'+o+'" is not writable'+a+".");if(!e.mutable&&r&&Object.prototype.hasOwnProperty.call(r,o)){if(R(i)===R(r[o]))return"incremental"!==g||c.property.name.reserved.concat(m.deleted,f,b).includes(o)||delete t[o],!0;"migrate"!==g&&l('Immutable: Property "'+o+'" is not writable (old document "'+R(r)+'")'+a+".")}if(null===i){if(e.nullable)return delete t[o],r&&Object.prototype.hasOwnProperty.call(r,o)&&(_=n.concat(o,"delete property")),!0;l('NotNull: Property "'+o+'" should not be "null"'+a+".")}return!1},D=function(e,t,r,_){if(!r)for(var c,i,s=o(["onCreateExecution","onCreateExpression"]);!(c=s()).done;)if(i=c.value,Object.prototype.hasOwnProperty.call(e,i)){var d=void 0;try{d=B(e[i],i.endsWith("Expression"),{checkPropertyContent:E,model:p,modelName:u,name:_,type:i,newDocument:t,oldDocument:r,newValue:void 0,oldValue:void 0,parentNames:n,pathDescription:a,propertySpecification:e})}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&l('Compilation: Hook "'+i+'" has invalid code "'+e.code+'" for property "'+_+'": '+e.message+a+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&l('Runtime: Hook "'+i+'" has throw an error with code "'+e.code+'" for property "'+_+'": '+e.message+a+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}d&&![null,void 0].includes(d.result)&&(t[_]=d.result)}},M=function(e,t,r,_){if(Object.prototype.hasOwnProperty.call(t,_)){e.trim&&"string"==typeof t[_]&&(t[_]=t[_].trim()),e.emptyEqualsToNull&&(""===t[_]||Array.isArray(t[_])&&0===t[_].length||null!==t[_]&&"object"==typeof t[_]&&0===Object.keys(t).length)&&(t[_]=null);for(var c,i,s=o(["onUpdateExecution","onUpdateExpression"]);!(c=s()).done;)if(i=c.value,Object.prototype.hasOwnProperty.call(e,i))try{t[_]=B(e[i],i.endsWith("Expression"),{checkPropertyContent:E,model:p,modelName:u,name:_,type:i,newDocument:t,oldDocument:r,newValue:t[_],oldValue:r&&r[_],parentNames:n,pathDescription:a,propertySpecification:e}).result}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&l('Compilation: Hook "'+i+'" has invalid code "'+e.code+'" for property "'+_+'": '+e.message+a+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&l('Runtime: Hook "'+i+'" has throw an error with code "'+e.code+'" for property "'+_+'": '+e.message+a+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}}},w=Object.keys(p).filter((function(e){return!I.includes(e)}));if("migrate"===g)for(var C,A,k=o(w);!(C=k()).done;)if(A=C.value,![null,void 0].includes(p[A].oldName))for(var T,W,N=o([].concat(p[A].oldName));!(T=N()).done;)W=T.value,Object.prototype.hasOwnProperty.call(e,W)&&(e[A]=e[W],delete e[W]);if(!r)for(var S,q=0,F=[m.create.execution,m.create.expression];q<F.length;q++)if(S=F[q],Object.prototype.hasOwnProperty.call(p,S)){var z=void 0;try{z=B(p[S],S.endsWith("Expression"),{checkPropertyContent:E,model:p,modelName:u,type:S,newDocument:e,oldDocument:r,parentNames:n,pathDescription:a}).result}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&l('Compilation: Hook "'+S+'" has invalid code "'+e.code+'" for document "'+u+'": '+e.message+a+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&l('Runtime: Hook "'+S+'" has throw an error with code "'+e.code+'" for document "'+u+'": '+e.message+a+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}[null,void 0].includes(z)||(e=z),s(),u=e[y],0===n.length&&x()}for(var $,H=0,G=[m.update.execution,m.update.expression];H<G.length;H++)if($=G[H],Object.prototype.hasOwnProperty.call(p,$)){var V=void 0;try{V=B(p[$],$.endsWith("Expression"),{checkPropertyContent:E,model:p,modelName:u,type:$,newDocument:e,oldDocument:r,parentNames:n,pathDescription:a}).result}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&l('Compilation: Hook "'+$+'" has invalid code "'+e.code+'" for document "'+u+'": '+e.message+a+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&l('Runtime: Hook "'+$+'" has throw an error with code "'+e.code+'" for document "'+u+'": '+e.message+a+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}[void 0,null].includes(V)||(e=V),s(),u=e[y],0===n.length&&x()}for(var J,Y=function(){var t=J.value;if(m.attachment===t)for(var c=function(){var c=s[i],u=c[0],p=c[1];Object.prototype.hasOwnProperty.call(e,t)&&null!==e[t]||(e[t]={}),r&&!Object.prototype.hasOwnProperty.call(r,t)&&(r[t]={});var d=Object.keys(e[t]).filter((function(r){return null!==e[t][r].data&&L(u,r,p)})),m=e[t],f=[];if(r){var b=r[t];f=Object.keys(b).filter((function(e){return!(Object.prototype.hasOwnProperty.call(m,e)&&Object.prototype.hasOwnProperty.call(m[e],"data")&&null===m[e].data)&&!!b[e]&&(Object.prototype.hasOwnProperty.call(b[e],"data")&&null!==b[e].data||b[e].stub&&!!b[e].digest)&&!!L(u,e,p)}))}for(var y,h,O=p,x=o(d);!(y=x()).done;)h=y.value,D(O,m,r&&r[t]?r[t]:null,h);for(var E,P,v=o(d);!(E=v()).done;)P=E.value,M(O,m,r&&r[t]?r[t]:null,P);if([null,void 0].includes(O.default)){if(O.nullable||0<d.length||0<f.length||l('AttachmentMissing: Missing attachment for type "'+u+'"'+a+"."),"fillUp"===g&&0===d.length&&0<f.length)for(var w,C,A=o(f);!(w=A()).done;)C=w.value,null===m[C]?_=n.concat(t,C,"file removed"):m[C]=r[t][C]}else if(0===d.length)if(0===f.length)for(var k in O.default)Object.prototype.hasOwnProperty.call(O.default,k)&&(m[k]=O.default[k],_=n.concat(t,u,"add default file"));else if("fillUp"===g)for(var T,I,R=o(f);!(T=R()).done;)I=T.value,m[I]=r[t][I]},i=0,s=Object.entries(p[t]);i<s.length;i++)c();else{var u=w.includes(t)?p[t]:h;D(u,e,r,t),M(u,e,r,t),[null,void 0].includes(u.default)?(!(u.nullable||Object.prototype.hasOwnProperty.call(e,t)||r&&Object.prototype.hasOwnProperty.call(r,t)&&g)&&l('MissingProperty: Missing property "'+t+'"'+a+"."),!Object.prototype.hasOwnProperty.call(e,t)&&r&&Object.prototype.hasOwnProperty.call(r,t)&&("fillUp"===g?e[t]=r[t]:!g&&(_=n.concat(t,"property removed")))):(!Object.prototype.hasOwnProperty.call(e,t)||null===e[t])&&(r&&Object.prototype.hasOwnProperty.call(r,t)?"fillUp"===g?e[t]=r[t]:"migrate"===g&&(e[t]=u.default,_=n.concat(t,"migrate default value")):(e[t]=u.default,_=_.concat(t,"add default value")))}},X=o(w.concat(h?Object.keys(e).filter((function(e){return!w.includes(e)})):[]));!(J=X()).done;)Y();if(r&&"incremental"===g)for(var Z=0,Q=Object.entries(e);Z<Q.length;Z++){var ee=Q[Z],te=ee[0],re=ee[1];Object.prototype.hasOwnProperty.call(r,te)&&!c.property.name.reserved.concat(f,b,m.conflict,m.deleted,m.deletedConflict,m.localSequence,m.revisions,m.revisionsInformation,y).includes(te)&&(r[te]===re||R(r[te])===R(re))&&delete e[te]}for(var ne=0,oe=Object.entries(e);ne<oe.length;ne++){var ae=oe[ne],_e=ae[0],ce=ae[1];if(!c.property.name.reserved.concat(b,m.conflict,m.deleted,m.deletedConflict,m.localSequence,m.revisions,m.revisionsInformation,m.strategy).includes(_e)){var ie=void 0;if(Object.prototype.hasOwnProperty.call(p,_e))ie=p[_e];else if(h)ie=h;else{if("migrate"===g){delete e[_e],_=n.concat(_e,"migrate removed property");continue}l('Property: Given property "'+_e+'" isn\'t specified in model "'+u+'"'+a+".")}if(!ie)continue;if(m.attachment===_e){var se=ce;for(var le in se)if(Object.prototype.hasOwnProperty.call(se,le))for(var ue in p[_e])if(L(ue,le,p[_e][ue])){v(p[_e][ue],e,r,le,a);break}continue}if(v(ie,e,r,_e,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?l('MinimumArrayLength: Property "'+_e+'" (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&&l('MaximumArrayLength: Property "'+_e+'" (array of length '+de.length+") doesn't fullfill maximum array length of "+ie.maximumNumber+a+"."):l('PropertyType: Property "'+_e+'" isn\'t of type "array -> '+ie.type+'" (given "'+R(de)+'")'+a+"."),O(de,_e,ie,r&&Object.prototype.hasOwnProperty.call(r,_e)&&r[_e]||void 0,["arrayConstraintExecution","arrayConstraintExpression"]);var me={};for(var fe in ie)Object.prototype.hasOwnProperty.call(ie,fe)&&(me[fe]="type"===fe?Array.isArray(ie[fe])?ie[fe][0]:[ie[fe].substring(0,ie.type.length-2)]:ie[fe]);if(1===(null==(pe=me.type)?void 0:pe.length)&&Object.prototype.hasOwnProperty.call(i,me.type[0]))for(var be,ye,he=o(de.slice());!(be=he()).done;)"object"!=typeof(ye=be.value)||Object.getPrototypeOf(ye)!==Object.prototype||Object.prototype.hasOwnProperty.call(ye,y)||(ye[y]=me.type[0]);for(var Oe,xe,ge=0,Ee=o(de.slice());!(Oe=Ee()).done;)xe=Oe.value,de[ge]=E(xe,ge+1+". value in "+_e,me).newValue,null===xe&&de.splice(ge,1),ge+=1;r&&Object.prototype.hasOwnProperty.call(r,_e)&&Array.isArray(r[_e])&&r[_e].length===de.length&&R(r[_e])===R(de)||(_=n.concat(_e,"array updated"))}else{var Pe=r&&Object.prototype.hasOwnProperty.call(r,_e)?r[_e]:null,ve=E(ce,_e,ie,Pe);e[_e]=ve.newValue,ve.changedPath.length&&(_=ve.changedPath),null===e[_e]&&(null!==Pe&&(_=n.concat(_e,"property removed")),delete e[_e])}}}for(var De,Me=0,we=Object.keys(m.constraint);Me<we.length;Me++)if(De=we[Me],(De=m.constraint[De])&&Object.prototype.hasOwnProperty.call(p,De))for(var Ce,Ae=o([].concat(p[De]));!(Ce=Ae()).done;){var ke=Ce.value,Te=void 0;try{Te=B(ke.evaluation,De===m.constraint.expression,{checkPropertyContent:E,model:p,modelName:u,type:De,newDocument:e,oldDocument:r,parentNames:n,pathDescription:a})}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&l('Compilation: Hook "'+De+'" has invalid code "'+e.code+'": "'+e.message+'"'+a+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&l('Runtime: Hook "'+De+'" has thrown an error with code "'+e.code+'": '+e.message+a+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}if(Te&&!Te.result){var Ie=De.replace(/^[^a-zA-Z]+/,"");l(Ie.charAt(0).toUpperCase()+(Ie.substring(1)+": ")+(ke.description?t(Function,Object.keys(Te.scope).concat(["return "+ke.description.trim()])).apply(void 0,Object.values(Te.scope)):'Model "'+u+'" should satisfy constraint "'+Te.code+'" (given "'+R(e)+'")'+a+"."))}}if(Object.prototype.hasOwnProperty.call(e,m.attachment)){var Re=e[m.attachment];("object"!=typeof Re||Object.getPrototypeOf(Re)!==Object.prototype)&&l("AttachmentType: given attachment has invalid type"+a+".");var je=null;if(r&&Object.prototype.hasOwnProperty.call(r,m.attachment)&&null!==(je=r[m.attachment])&&"object"==typeof je)for(var Ue=0,Le=Object.entries(je);Ue<Le.length;Ue++){var We=Le[Ue],Be=We[0],Ke=We[1];if(Object.prototype.hasOwnProperty.call(Re,Be)){var Ne=Re[Be];null===Ne||null===Ne.data||Ne.content_type===Ke.content_type&&(Ne.data===Ke.data||Ne.digest===Ke.digest)?((null===Ne||null===Ne.data)&&(_=n.concat(m.attachment,Be,"attachment removed")),"incremental"===g&&delete Re[Be]):_=n.concat(m.attachment,Be,"attachment updated")}else"fillUp"===g?Re[Be]=Ke:g||(_=n.concat(m.attachment,Be,"attachment removed"))}for(var Se=0,qe=Object.entries(Re);Se<qe.length;Se++){var Fe=qe[Se],ze=Fe[0],$e=Fe[1];[null,void 0].includes($e)||null===$e.data?delete Re[ze]:(!je||!Object.prototype.hasOwnProperty.call(je,ze)||$e.content_type!==je[ze].content_type||$e.data!==je[ze].data&&$e.digest!==je[ze].digest)&&(_=n.concat(m.attachment,ze,"attachment updated"))}0===Object.keys(Re).length&&delete e[m.attachment];for(var He={},Ge=0,Ve=Object.keys(p[m.attachment]);Ge<Ve.length;Ge++)He[Ve[Ge]]=[];for(var Je=0,Ye=Object.keys(Re);Je<Ye.length;Je++){for(var Xe=Ye[Je],Ze=!1,Qe=0,et=Object.entries(p[m.attachment]);Qe<et.length;Qe++){var tt=et[Qe],rt=tt[0],nt=tt[1];if(L(rt,Xe,nt)){He[rt].push(Xe),Ze=!0;break}}Ze||l('AttachmentTypeMatch: None of the specified attachment types ("'+Object.keys(p[m.attachment]).join('", "')+'") matches given one ("'+Xe+'")'+a+".")}for(var ot=0,at=0,_t=Object.keys(He);at<_t.length;at++){var ct=_t[at],it=p[m.attachment][ct];if(Object.prototype.hasOwnProperty.call(He,ct)){var st=He[ct].length;null!==it.maximumNumber&&st>it.maximumNumber&&l("AttachmentMaximum: given number of attachments ("+st+") doesn't satisfy specified maximum of "+it.maximumNumber+' from type "'+ct+'"'+a+"."),(!it.nullable||0!==st)&&st<it.minimumNumber&&l("AttachmentMinimum: given number of attachments ("+st+") doesn't satisfy specified minimum of "+it.minimumNumber+' from type "'+ct+'"'+a+".");for(var lt,ut=0,pt=o(He[ct]);!(lt=pt()).done;){var dt,mt,ft=lt.value;null!=(dt=it.fileName)&&dt.regularExpressionPattern&&!new RegExp(it.fileName.regularExpressionPattern).test(ft)?l('AttachmentName: given attachment name "'+ft+'" doesn\'t satisfy specified regular expression pattern "'+it.fileName.regularExpressionPattern+'" from type "'+ct+'"'+a+"."):null!=(mt=it.fileName)&&mt.invertedRegularExpressionPattern&&new RegExp(it.fileName.invertedRegularExpressionPattern).test(ft)?l('InvertedAttachmentName: given attachment name "'+ft+'" does satisfy specified regular expression pattern "'+it.fileName.invertedRegularExpressionPattern+'" from type "'+ct+'"'+a+"."):!([null,void 0].includes(it.contentTypeRegularExpressionPattern)||Re[ft].content_type&&new RegExp(it.contentTypeRegularExpressionPattern).test(Re[ft].content_type))&&l('AttachmentContentType: given attachment content type "'+Re[ft].content_type+'" doesn\'t satisfy specified regular expression pattern "'+it.contentTypeRegularExpressionPattern+'" from type "'+ct+'"'+a+".");var bt=it.invertedContentTypeRegularExpressionPattern;[null,void 0].includes(bt)||Re[ft].content_type&&!new RegExp(bt).test(Re[ft].content_type)||l('InvertedAttachmentContentType: given attachment content type "'+Re[ft].content_type+'" does satisfy specified regular expression pattern "'+bt+'" from type "'+ct+'"'+a+".");var yt=0;"length"in Re[ft]?yt=Re[ft].length:"data"in Re[ft]&&(yt=Buffer&&"byteLength"in Buffer?Buffer.byteLength(Re[ft].data,"base64"):Re[ft].data.length),![null,void 0].includes(it.minimumSize)&&it.minimumSize>yt?l("AttachmentMinimumSize: given attachment size "+yt+" byte doesn't satisfy specified minimum of "+it.minimumSize+" byte "+a+"."):![null,void 0].includes(it.maximumSize)&&it.maximumSize<yt&&l("AttachmentMaximumSize: given attachment size "+yt+" byte doesn't satisfy specified maximum of "+it.maximumSize+" byte "+a+"."),ut+=yt}![null,void 0].includes(it.minimumAggregatedSize)&&it.minimumAggregatedSize>ut?l('AttachmentAggregatedMinimumSize: given aggregated size of attachments from type "'+ct+'" '+ut+" byte doesn't satisfy specified minimum of "+it.minimumAggregatedSize+" byte "+a+"."):![null,void 0].includes(it.maximumAggregatedSize)&&it.maximumAggregatedSize<ut&&l('AttachmentAggregatedMaximumSize: given aggregated size of attachments from type "'+ct+'" '+ut+" byte doesn't satisfy specified maximum of "+it.maximumAggregatedSize+" byte "+a+"."),ot+=ut}}Object.prototype.hasOwnProperty.call(p,m.minimumAggregatedSize)&&![null,void 0].includes(p[m.minimumAggregatedSize])&&p[m.minimumAggregatedSize]>ot?l("AggregatedMinimumSize: given aggregated size "+ot+" byte doesn't satisfy specified minimum of "+p[m.minimumAggregatedSize]+" byte "+a+"."):![null,void 0].includes(p[m.maximumAggregatedSize])&&p[m.maximumAggregatedSize]<ot&&l("AggregatedMaximumSize: given aggregated size "+ot+" byte doesn't satisfy specified maximum of "+p[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===_.length&&r&&"migrate"===g)for(var ht,Ot=0,xt=Object.keys(r);Ot<xt.length;Ot++)ht=xt[Ot],Object.prototype.hasOwnProperty.call(e,ht)||(_=n.concat(ht,"migrate removed property"));return{changedPath:_,newDocument:e}},N={attachmentWithPrefixExists:function(t){if(Object.prototype.hasOwnProperty.call(e,m.attachment)){var r=e[m.attachment],n=W(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:K,getFileNameByPrefix:W,serialize:R,id:h,revision:O,idName:f,revisionName:b,specialNames:m,typeName:y,modelConfiguration:c,models:i,now:u,nowUTCTimestamp:p,securitySettings:_,userContext:a},S=K(e,r);return(!S.newDocument._deleted||r)&&(S.newDocument._deleted&&S.newDocument._deleted!==(null==r?void 0:r._deleted)||S.changedPath.length)||l("NoChange: No new data given. new document: "+R(e)+"; old document: "+R(r)+"."),Object.prototype.hasOwnProperty.call(_,c.property.name.validatedDocumentsCache)?_[c.property.name.validatedDocumentsCache].add(h+"-"+O):_[c.property.name.validatedDocumentsCache]=new Set([h+"-"+O]),S.newDocument},e}(),s=i;e.exports=c}()},,e=>{"use strict";e.exports=require("pouchdb-node")},e=>{"use strict";e.exports=require("pouchdb-find")}],__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:()=>Database,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__),clientnode__WEBPACK_IMPORTED_MODULE_3__=__webpack_require__(3),clientnode__WEBPACK_IMPORTED_MODULE_3___default=__webpack_require__.n(clientnode__WEBPACK_IMPORTED_MODULE_3__),fs__WEBPACK_IMPORTED_MODULE_4__=__webpack_require__(4),fs__WEBPACK_IMPORTED_MODULE_4___default=__webpack_require__.n(fs__WEBPACK_IMPORTED_MODULE_4__),path__WEBPACK_IMPORTED_MODULE_5__=__webpack_require__(5),path__WEBPACK_IMPORTED_MODULE_5___default=__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_5__),pouchdb_node__WEBPACK_IMPORTED_MODULE_6__=__webpack_require__(11),pouchdb_node__WEBPACK_IMPORTED_MODULE_6___default=__webpack_require__.n(pouchdb_node__WEBPACK_IMPORTED_MODULE_6__),pouchdb_find__WEBPACK_IMPORTED_MODULE_7__=__webpack_require__(12),pouchdb_find__WEBPACK_IMPORTED_MODULE_7___default=__webpack_require__.n(pouchdb_find__WEBPACK_IMPORTED_MODULE_7__),_databaseHelper__WEBPACK_IMPORTED_MODULE_9__=__webpack_require__(9),_databaseHelper__WEBPACK_IMPORTED_MODULE_9___default=__webpack_require__.n(_databaseHelper__WEBPACK_IMPORTED_MODULE_9__),_helper__WEBPACK_IMPORTED_MODULE_8__=__webpack_require__(8);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}var Database=function(){function Database(){}return Database.preLoadService=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,o,a,_,c,i,s,l,u,p,d,m,f,b,y,h;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=t.configuration.couchdb,n=t.services,Object.prototype.hasOwnProperty.call(n,"couchdb")||(n.couchdb={}),o=n.couchdb,Object.prototype.hasOwnProperty.call(o,"connector")||(a=r.model.property.name.special.id,_=r.model.property.name.special.revision,o.connector=pouchdb_node__WEBPACK_IMPORTED_MODULE_6___default(),c=o.connector.prototype.bulkDocs,o.connector.plugin({bulkDocs: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 n,o,i,s,l,u,p,d,m,f,b,y,h,O,x,g,E,P,v=arguments;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(o=v.length,i=Array(1<o?o-1:0),s=1;s<o;s++)i[s-1]=v[s];return l=0<i.length&&i[i.length-1]===Database.toggleIDDetermining,u=l?!r.skipIDDetermining:r.skipIDDetermining,l&&i.pop(),p=!Array.isArray(t)&&null!==t&&"object"==typeof t&&a in t?[t]:t,null!=(n=r.connector.fetch)&&n.timeout&&(0===i.length||"object"!=typeof i[0])&&i.unshift({timeout:r.connector.fetch.timeout}),e.next=8,c.call.apply(c,[this,p].concat(i));case 8:d=e.sent,m=[],f=[],b=0,y=_createForOfIteratorHelperLoose(d);case 13:if((h=y()).done){e.next=36;break}if(O=h.value,"object"!=typeof p[b]){e.next=33;break}if(!(_ in p[b])||"conflict"!==O.name||!["latest","upsert"].includes(p[b][_])){e.next=21;break}f.push(p[b]),m.push(b),e.next=33;break;case 21:if(!(a in p[b]&&r.ignoreNoChangeError&&"name"in O&&"forbidden"===O.name&&"message"in O&&O.message.startsWith("NoChange:"))){e.next=33;break}if(d[b]={id:p[b][a],ok:!0},u){e.next=33;break}if(!(_ in p[b])||["latest","upsert"].includes(p[b][_])){e.next=28;break}e.t0=p[b][_],e.next=32;break;case 28:return e.next=30,this.get(d[b].id);case 30:e.t1=_,e.t0=e.sent[e.t1];case 32:d[b].rev=e.t0;case 33:b+=1;case 34:e.next=13;break;case 36:if(!f.length){e.next=43;break}return p=f,l&&i.push(Database.toggleIDDetermining),e.next=41,this.bulkDocs.apply(this,[p].concat(i));case 41:for(x=e.sent,g=_createForOfIteratorHelperLoose(x);!(E=g()).done;)P=E.value,d[m.shift()]=P;case 43:return e.abrupt("return",d);case 44:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}()}),r.debug&&o.connector.debug.enable("*"),o.connector=o.connector.plugin(pouchdb_find__WEBPACK_IMPORTED_MODULE_7___default())),Object.prototype.hasOwnProperty.call(o,"server")){e.next=36;break}o.server={},i=[],s=_createForOfIteratorHelperLoose([].concat(r.binary.runner));case 8:if((l=s()).done){e.next=34;break}u=l.value,p=_createForOfIteratorHelperLoose([].concat(u.location));case 11:if((d=p()).done){e.next=30;break}m=d.value,f=_createForOfIteratorHelperLoose([].concat(u.name));case 14:if((b=f()).done){e.next=26;break}return y=b.value,h=(0,path__WEBPACK_IMPORTED_MODULE_5__.resolve)(m,y),i.push(h),e.next=20,clientnode__WEBPACK_IMPORTED_MODULE_3___default().isFile(h);case 20:if(!e.sent){e.next=24;break}return u.binaryFilePath=h,o.server.runner=u,e.abrupt("break",26);case 24:e.next=14;break;case 26:if(!Object.prototype.hasOwnProperty.call(o.server,"runner")){e.next=28;break}return e.abrupt("break",30);case 28:e.next=11;break;case 30:if(!Object.prototype.hasOwnProperty.call(o.server,"runner")){e.next=32;break}return e.abrupt("break",34);case 32:e.next=8;break;case 34:if(Object.prototype.hasOwnProperty.call(o.server,"runner")){e.next=36;break}throw new Error('No binary file in one of the following locations found: "'+i.join('", "')+'".');case 36:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),Database.loadService=function(){function loadService(){return _loadService.apply(this,arguments)}var _loadService=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function _callee3(_ref3){var configuration,services,promise,couchdb,urlPrefix,unauthenticatedUserDatabaseConnection,authenticatedUserDatabaseConnection,_i,_arr,type,_iterator6,_step6,name,userDatabaseConnection,_userDatabaseConnecti,_iterator7,_step7,prefix,subPath,fullPath,url,_value,response,changeNeeded,idName,typeName,modelConfiguration,models,databaseHelperCode,_iterator8,_step8,_type2,code,_i2,_Object$entries,_Object$entries$_i,modelName,model,_i3,_Object$entries2,_Object$entries2$_i,_name,specification,_iterator9,_step9,constraint,property,_iterator10,_step10,_type,_constraint,migrater,_iterator11,_step11,file,extension,_name2,document,_forbidden,_iterator12,_step12,retrievedDocument,_document,newDocument,_iterator13,_step13,_name3,result,indexes,_i4,_Object$entries3,_Object$entries3$_i,_modelName,_model,_iterator14,_step14,propertyName,_name4,foundPosition,position,_iterator15,_step15,index,_iterator16,_step16,_index,exists,_i5,_Object$entries4,_Object$entries4$_i,_modelName2,_model2,_iterator17,_step17,_name5;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(_context3){for(;;)switch(_context3.prev=_context3.next){case 0:if(configuration=_ref3.configuration,services=_ref3.services,promise=null,couchdb=services.couchdb,!Object.prototype.hasOwnProperty.call(couchdb.server,"runner")){_context3.next=10;break}return _context3.next=6,(0,_helper__WEBPACK_IMPORTED_MODULE_8__.startServer)(services,configuration);case 6:couchdb.server.restart=_helper__WEBPACK_IMPORTED_MODULE_8__.restartServer,couchdb.server.start=_helper__WEBPACK_IMPORTED_MODULE_8__.startServer,couchdb.server.stop=_helper__WEBPACK_IMPORTED_MODULE_8__.stopServer,promise=new Promise((function(e,t){couchdb.server.resolve=e,couchdb.server.reject=t}));case 10:if(!Object.prototype.hasOwnProperty.call(couchdb,"connection")){_context3.next=12;break}return _context3.abrupt("return",{couchdb:promise});case 12:if(urlPrefix=clientnode__WEBPACK_IMPORTED_MODULE_3___default().stringFormat(configuration.couchdb.url,configuration.couchdb.user.name+":"+configuration.couchdb.user.password+"@"),!configuration.couchdb.ensureAdminPresence){_context3.next=44;break}return unauthenticatedUserDatabaseConnection=new couchdb.connector(clientnode__WEBPACK_IMPORTED_MODULE_3___default().stringFormat(configuration.couchdb.url,"")+"/_users",(0,_helper__WEBPACK_IMPORTED_MODULE_8__.getConnectorOptions)(configuration)),_context3.prev=15,_context3.next=18,unauthenticatedUserDatabaseConnection.allDocs();case 18:return _context3.next=21,clientnode__WEBPACK_IMPORTED_MODULE_3__.globalContext.fetch(clientnode__WEBPACK_IMPORTED_MODULE_3___default().stringFormat(configuration.couchdb.url,"")+"/"+couchdb.server.runner.adminUserConfigurationPath+"/"+configuration.couchdb.user.name,{body:'"'+configuration.couchdb.user.password+'"',method:"PUT"});case 21:_context3.next=41;break;case 23:if(_context3.prev=23,_context3.t0=_context3.catch(15),"unauthorized"!==_context3.t0.name){_context3.next=40;break}return authenticatedUserDatabaseConnection=new couchdb.connector(urlPrefix+"/_users",(0,_helper__WEBPACK_IMPORTED_MODULE_8__.getConnectorOptions)(configuration)),_context3.prev=27,_context3.next=30,authenticatedUserDatabaseConnection.allDocs();case 30:_context3.next=35;break;case 32:_context3.prev=32,_context3.t1=_context3.catch(27);case 35:return _context3.prev=35,authenticatedUserDatabaseConnection.close(),_context3.finish(35);case 38:_context3.next=41;break;case 40:case 41:return _context3.prev=41,unauthenticatedUserDatabaseConnection.close(),_context3.finish(41);case 44:if(!configuration.couchdb.ensureUserPresence){_context3.next=79;break}_i=0,_arr=[configuration.couchdb.security.admins,configuration.couchdb.security.members];case 46:if(!(_i<_arr.length)){_context3.next=79;break}type=_arr[_i],_iterator6=_createForOfIteratorHelperLoose(type.names);case 49:if((_step6=_iterator6()).done){_context3.next=76;break}return name=_step6.value,userDatabaseConnection=new couchdb.connector(urlPrefix+"/_users",(0,_helper__WEBPACK_IMPORTED_MODULE_8__.getConnectorOptions)(configuration)),_context3.prev=52,_context3.next=55,userDatabaseConnection.get("org.couchdb.user:"+name);case 55:_context3.next=71;break;case 57:if(_context3.prev=57,_context3.t2=_context3.catch(52),"not_found"!==_context3.t2.error){_context3.next=70;break}return _context3.prev=60,_context3.next=63,userDatabaseConnection.put((_userDatabaseConnecti={},_userDatabaseConnecti[configuration.couchdb.model.property.name.special.id]="org.couchdb.user:"+name,_userDatabaseConnecti.name=name,_userDatabaseConnecti.password=name,_userDatabaseConnecti.roles=[].concat(type.roles.includes(name+"s")?name+"s":[]),_userDatabaseConnecti.type="user",_userDatabaseConnecti));case 63:_context3.next=68;break;case 65:throw _context3.prev=65,_context3.t3=_context3.catch(60),new Error("Couldn't create missing user \""+name+'": '+clientnode__WEBPACK_IMPORTED_MODULE_3___default().represent(_context3.t3));case 68:_context3.next=71;break;case 70:throw new Error("Couldn't check for presence of user \""+name+'": '+clientnode__WEBPACK_IMPORTED_MODULE_3___default().represent(_context3.t2));case 71:return _context3.prev=71,userDatabaseConnection.close(),_context3.finish(71);case 74:_context3.next=49;break;case 76:_i++,_context3.next=46;break;case 79:if(!configuration.couchdb.model.updateConfiguration){_context3.next=134;break}_iterator7=_createForOfIteratorHelperLoose(configuration.couchdb.backend.prefixes);case 81:if((_step7=_iterator7()).done){_context3.next=134;break}prefix=_step7.value,_context3.t4=_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().keys(configuration.couchdb.backend.configuration);case 84:if((_context3.t5=_context3.t4()).done){_context3.next=132;break}if(subPath=_context3.t5.value,!Object.prototype.hasOwnProperty.call(configuration.couchdb.backend.configuration,subPath)){_context3.next=130;break}return fullPath="/"+prefix+(prefix.trim()?"/":"")+subPath,url=""+urlPrefix+fullPath,_value=configuration.couchdb.backend.configuration[subPath],response=void 0,_context3.prev=91,_context3.next=94,clientnode__WEBPACK_IMPORTED_MODULE_3__.globalContext.fetch(url);case 94:response=_context3.sent,_context3.next=100;break;case 97:_context3.prev=97,_context3.t6=_context3.catch(91);case 100:if(!response){_context3.next=130;break}if(!response.ok){_context3.next=129;break}if(changeNeeded=!0,"function"!=typeof response.text){_context3.next=115;break}return _context3.prev=104,_context3.t7=_value,_context3.next=108,response["string"==typeof _value?"text":"json"]();case 108:_context3.t8=_context3.sent,changeNeeded=_context3.t7===_context3.t8,_context3.next=115;break;case 112:_context3.prev=112,_context3.t9=_context3.catch(104);case 115:if(!changeNeeded){_context3.next=126;break}return _context3.prev=116,_context3.next=119,clientnode__WEBPACK_IMPORTED_MODULE_3__.globalContext.fetch(url,{body:'"'+configuration.couchdb.backend.configuration[subPath]+'"',method:"PUT"});case 119:_context3.next=124;break;case 121:_context3.prev=121,_context3.t10=_context3.catch(116);case 124:_context3.next=127;break;case 126:case 127:_context3.next=130;break;case 129:case 130:_context3.next=84;break;case 132:_context3.next=81;break;case 134:return _context3.next=136,(0,_helper__WEBPACK_IMPORTED_MODULE_8__.initializeConnection)(services,configuration);case 136:if(idName=configuration.couchdb.model.property.name.special.id,typeName=configuration.couchdb.model.property.name.special.type,!configuration.couchdb.ensureSecuritySettingsPresence){_context3.next=147;break}return _context3.prev=139,_context3.next=142,clientnode__WEBPACK_IMPORTED_MODULE_3__.globalContext.fetch(urlPrefix+"/"+configuration.couchdb.databaseName+"/_security",{body:JSON.stringify(configuration.couchdb.security),method:"PUT"});case 142:_context3.next=147;break;case 144:_context3.prev=144,_context3.t11=_context3.catch(139);case 147:if(modelConfiguration=clientnode__WEBPACK_IMPORTED_MODULE_3___default().copy(configuration.couchdb.model),delete modelConfiguration.property.defaultSpecification,delete modelConfiguration.entities,models=(0,_helper__WEBPACK_IMPORTED_MODULE_8__.extendModels)(configuration.couchdb.model),!configuration.couchdb.model.updateValidation){_context3.next=215;break}return _context3.next=154,fs__WEBPACK_IMPORTED_MODULE_4__.promises.readFile(eval("require.resolve('./databaseHelper')"),{encoding:configuration.core.encoding,flag:"r"});case 154:databaseHelperCode=_context3.sent,_iterator8=_createForOfIteratorHelperLoose([{description:"Model specification",methodName:"validateDocumentUpdate",name:"validation",serializedParameter:JSON.stringify(modelConfiguration)+", "+JSON.stringify(models)},{description:"Authorisation",methodName:"authenticate",name:"authentication",serializedParameter:JSON.stringify((0,_helper__WEBPACK_IMPORTED_MODULE_8__.determineAllowedModelRolesMapping)(configuration.couchdb.model))+", '"+idName+"', '"+typeName+"', '"+configuration.couchdb.model.property.name.special.designDocumentNamePrefix+"'"}]);case 156:if((_step8=_iterator8()).done){_context3.next=171;break}_type2=_step8.value,code="function(...parameters) {\n return require('helper').default."+_type2.methodName+"(...parameters.concat(["+_type2.serializedParameter+"]))\n}",_context3.prev=159,new Function("return "+code),_context3.next=166;break;case 163:throw _context3.prev=163,_context3.t12=_context3.catch(159),new Error("Generated "+_type2.name+' code "'+code+"\" doesn't compile: "+clientnode__WEBPACK_IMPORTED_MODULE_3___default().represent(_context3.t12));case 166:return configuration.core.debug,_context3.next=169,(0,_helper__WEBPACK_IMPORTED_MODULE_8__.ensureValidationDocumentPresence)(couchdb.connection,_type2.name,{helper:databaseHelperCode,validate_doc_update:code},_type2.description,!0,idName,modelConfiguration.property.name.special.designDocumentNamePrefix);case 169:_context3.next=156;break;case 171:_i2=0,_Object$entries=Object.entries(models);case 172:if(!(_i2<_Object$entries.length)){_context3.next=215;break}_Object$entries$_i=_Object$entries[_i2],modelName=_Object$entries$_i[0],model=_Object$entries$_i[1],_i3=0,_Object$entries2=Object.entries(model);case 175:if(!(_i3<_Object$entries2.length)){_context3.next=212;break}if(_Object$entries2$_i=_Object$entries2[_i3],_name=_Object$entries2$_i[0],specification=_Object$entries2$_i[1],![modelConfiguration.property.name.special.constraint.execution,modelConfiguration.property.name.special.constraint.expression].includes(_name)){_context3.next=193;break}_iterator9=_createForOfIteratorHelperLoose([].concat(specification));case 179:if((_step9=_iterator9()).done){_context3.next=191;break}if(constraint=_step9.value,!constraint.description){_context3.next=189;break}_context3.prev=182,new Function("return "+constraint.description),_context3.next=189;break;case 186:throw _context3.prev=186,_context3.t13=_context3.catch(182),new Error('Specified constraint description "'+constraint.description+'" for model "'+modelName+'" doesn\'t compile: "'+clientnode__WEBPACK_IMPORTED_MODULE_3___default().represent(_context3.t13)+'".');case 189:_context3.next=179;break;case 191:_context3.next=209;break;case 193:property=specification,_iterator10=_createForOfIteratorHelperLoose(["conflictingConstraintExpression","conflictingConstraintExecution","constraintExpression","constraintExecution"]);case 195:if((_step10=_iterator10()).done){_context3.next=209;break}if(_type=_step10.value,null===property||"object"!=typeof property){_context3.next=207;break}if(_constraint=property[_type],null==_constraint||!_constraint.description){_context3.next=207;break}_context3.prev=200,new Function(_constraint.description),_context3.next=207;break;case 204:throw _context3.prev=204,_context3.t14=_context3.catch(200),new Error('Specified constraint description "'+_constraint.description+'" for model "'+modelName+'" in property "'+_name+'" as "'+_type+'" doesn\'t compile: "'+clientnode__WEBPACK_IMPORTED_MODULE_3___default().represent(_context3.t14)+'".');case 207:_context3.next=195;break;case 209:_i3++,_context3.next=175;break;case 212:_i2++,_context3.next=172;break;case 215:if(!configuration.couchdb.model.autoMigrationPath){_context3.next=314;break}return migrater={},_context3.next=219,clientnode__WEBPACK_IMPORTED_MODULE_3___default().isDirectory((0,path__WEBPACK_IMPORTED_MODULE_5__.resolve)(configuration.couchdb.model.autoMigrationPath));case 219:if(!_context3.sent){_context3.next=266;break}return _context3.t15=_createForOfIteratorHelperLoose,_context3.next=223,clientnode__WEBPACK_IMPORTED_MODULE_3___default().walkDirectoryRecursively((0,path__WEBPACK_IMPORTED_MODULE_5__.resolve)(configuration.couchdb.model.autoMigrationPath),configuration.couchdb.debug?clientnode__WEBPACK_IMPORTED_MODULE_3___default().noop:function(e){return"debug"!==e.name});case 223:_context3.t16=_context3.sent,_iterator11=(0,_context3.t15)(_context3.t16);case 225:if((_step11=_iterator11()).done){_context3.next=266;break}if(file=_step11.value,extension=(0,path__WEBPACK_IMPORTED_MODULE_5__.extname)(file.name),_name2=(0,path__WEBPACK_IMPORTED_MODULE_5__.basename)(file.name,extension),".json"!==extension){_context3.next=256;break}return document=void 0,_context3.prev=231,_context3.t17=JSON,_context3.next=235,fs__WEBPACK_IMPORTED_MODULE_4__.promises.readFile(file.path,{encoding:configuration.core.encoding,flag:"r"});case 235:_context3.t18=_context3.sent,document=_context3.t17.parse.call(_context3.t17,_context3.t18),_context3.next=242;break;case 239:throw _context3.prev=239,_context3.t19=_context3.catch(231),new Error('Parsing document "'+file.path+'" to include by automigration of has failed: '+clientnode__WEBPACK_IMPORTED_MODULE_3___default().represent(_context3.t19));case 242:return document[idName]=_name2,document[configuration.couchdb.model.property.name.special.revision]="upsert",_context3.prev=244,_context3.next=247,couchdb.connection.put(document);case 247:_context3.next=253;break;case 249:throw _context3.prev=249,_context3.t20=_context3.catch(244),null!=(_forbidden=_context3.t20.forbidden)&&_forbidden.startsWith("NoChange:"),new Error('Migrating document "'+document[idName]+'" of type "'+document[typeName]+'" has failed: '+clientnode__WEBPACK_IMPORTED_MODULE_3___default().represent(_context3.t20));case 253:_context3.next=264;break;case 256:if(![".js"].includes((0,path__WEBPACK_IMPORTED_MODULE_5__.extname)(file.name))){_context3.next=260;break}migrater[file.path]=eval("require('"+file.path+"')").default,_context3.next=264;break;case 260:if(![".mjs"].includes((0,path__WEBPACK_IMPORTED_MODULE_5__.extname)(file.name))){_context3.next=264;break}return _context3.next=263,eval("import('"+file.path+"')");case 263:migrater[file.path]=_context3.sent.default;case 264:_context3.next=225;break;case 266:return _context3.t21=_createForOfIteratorHelperLoose,_context3.next=269,couchdb.connection.allDocs({include_docs:!0});case 269:_context3.t22=_context3.sent.rows,_iterator12=(0,_context3.t21)(_context3.t22);case 271:if((_step12=_iterator12()).done){_context3.next=314;break}if(retrievedDocument=_step12.value,"string"==typeof retrievedDocument.id&&retrievedDocument.id.startsWith(configuration.couchdb.model.property.name.special.designDocumentNamePrefix)){_context3.next=312;break}_document=retrievedDocument.doc,newDocument=clientnode__WEBPACK_IMPORTED_MODULE_3___default().copy(_document),newDocument[configuration.couchdb.model.property.name.special.strategy]="migrate",_iterator13=_createForOfIteratorHelperLoose(Object.keys(migrater).sort());case 278:if((_step13=_iterator13()).done){_context3.next=291;break}_name3=_step13.value,result=null,_context3.prev=281,result=migrater[_name3](newDocument,{configuration,databaseHelper:_databaseHelper__WEBPACK_IMPORTED_MODULE_9___default(),Tools:clientnode__WEBPACK_IMPORTED_MODULE_3___default(),idName,typeName,migrater,models,modelConfiguration,selfFilePath:_name3,services}),_context3.next=288;break;case 285:throw _context3.prev=285,_context3.t23=_context3.catch(281),new Error('Running migrater "'+_name3+'" in document '+(0,_helper__WEBPACK_IMPORTED_MODULE_8__.mayStripRepresentation)(_document,configuration.couchdb.maximumRepresentationTryLength,configuration.couchdb.maximumRepresentationLength)+'" failed: '+clientnode__WEBPACK_IMPORTED_MODULE_3___default().represent(_context3.t23));case 288:result&&(newDocument=result);case 289:_context3.next=278;break;case 291:_context3.prev=291,_databaseHelper__WEBPACK_IMPORTED_MODULE_9___default().validateDocumentUpdate(clientnode__WEBPACK_IMPORTED_MODULE_3___default().copy(newDocument),clientnode__WEBPACK_IMPORTED_MODULE_3___default().copy(_document),{db:configuration.couchdb.databaseName,name:configuration.couchdb.user.name,roles:["_admin"]},clientnode__WEBPACK_IMPORTED_MODULE_3___default().copy(configuration.couchdb.security),modelConfiguration,models),_context3.next=303;break;case 295:if(_context3.prev=295,_context3.t24=_context3.catch(291),!Object.prototype.hasOwnProperty.call(_context3.t24,"forbidden")){_context3.next=302;break}return _context3.t24.forbidden.startsWith("NoChange:"),_context3.abrupt("continue",312);case 302:throw _context3.t24;case 303:return _context3.prev=303,_context3.next=306,couchdb.connection.put(newDocument);case 306:_context3.next=311;break;case 308:throw _context3.prev=308,_context3.t25=_context3.catch(303),new Error('Replacing auto migrated document "'+newDocument[idName]+'" has failed: '+clientnode__WEBPACK_IMPORTED_MODULE_3___default().represent(_context3.t25));case 311:case 312:_context3.next=271;break;case 314:if(!configuration.couchdb.createGenericFlatIndex||!configuration.couchdb.model.autoMigrationPath){_context3.next=369;break}return _context3.next=317,couchdb.connection.getIndexes();case 317:indexes=_context3.sent.indexes,_i4=0,_Object$entries3=Object.entries(models);case 319:if(!(_i4<_Object$entries3.length)){_context3.next=350;break}if(_Object$entries3$_i=_Object$entries3[_i4],_modelName=_Object$entries3$_i[0],_model=_Object$entries3$_i[1],!new RegExp(configuration.couchdb.model.property.name.typeRegularExpressionPattern.public).test(_modelName)){_context3.next=347;break}return _context3.next=324,couchdb.connection.createIndex({index:{ddoc:_modelName+"-GenericIndex",fields:[typeName],name:_modelName+"-GenericIndex"}});case 324:_iterator14=_createForOfIteratorHelperLoose((0,_helper__WEBPACK_IMPORTED_MODULE_8__.determineGenericIndexablePropertyNames)(configuration.couchdb.model,_model));case 325:if((_step14=_iterator14()).done){_context3.next=347;break}propertyName=_step14.value,_name4=_modelName+"-"+propertyName+"-GenericIndex",foundPosition=-1,position=0,_iterator15=_createForOfIteratorHelperLoose(indexes);case 331:if((_step15=_iterator15()).done){_context3.next=339;break}if(index=_step15.value,index.name!==_name4){_context3.next=336;break}return foundPosition=position,_context3.abrupt("break",339);case 336:position+=1;case 337:_context3.next=331;break;case 339:if(-1!==foundPosition){_context3.next=344;break}return _context3.next=342,couchdb.connection.createIndex({index:{ddoc:_name4,fields:[typeName,propertyName],name:_name4}});case 342:_context3.next=345;break;case 344:indexes.slice(position,1);case 345:_context3.next=325;break;case 347:_i4++,_context3.next=319;break;case 350:_iterator16=_createForOfIteratorHelperLoose(indexes);case 351:if((_step16=_iterator16()).done){_context3.next=369;break}if(_index=_step16.value,!_index.name.endsWith("-GenericIndex")){_context3.next=367;break}exists=!1,_i5=0,_Object$entries4=Object.entries(models);case 356:if(!(_i5<_Object$entries4.length)){_context3.next=364;break}if(_Object$entries4$_i=_Object$entries4[_i5],_modelName2=_Object$entries4$_i[0],_model2=_Object$entries4$_i[1],!_index.name.startsWith(_modelName2+"-")){_context3.next=361;break}for(_iterator17=_createForOfIteratorHelperLoose((0,_helper__WEBPACK_IMPORTED_MODULE_8__.determineGenericIndexablePropertyNames)(configuration.couchdb.model,_model2));!(_step17=_iterator17()).done;)_name5=_step17.value,[_modelName2+"-"+_name5+"-GenericIndex",_modelName2+"-GenericIndex"].includes(_index.name)&&(exists=!0);return _context3.abrupt("break",364);case 361:_i5++,_context3.next=356;break;case 364:if(exists){_context3.next=367;break}return _context3.next=367,couchdb.connection.deleteIndex(_index);case 367:_context3.next=351;break;case 369:if(!configuration.couchdb.model.triggerInitialCompaction){_context3.next=378;break}return _context3.prev=370,_context3.next=373,couchdb.connection.compact();case 373:_context3.next=378;break;case 375:_context3.prev=375,_context3.t26=_context3.catch(370);case 378:return _context3.abrupt("return",{couchdb:promise});case 379:case"end":return _context3.stop()}}),_callee3,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],[281,285],[291,295],[303,308],[370,375]])})));return loadService}(),Database.postLoadService=function(e){var t=e.configuration.couchdb,r=e.pluginAPI,n=e.services.couchdb,o=0;setInterval((function(){0<o&&(o=0)}),3e4);var a=clientnode__WEBPACK_IMPORTED_MODULE_3___default().debounce(_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function _(){return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(_){for(;;)switch(_.prev=_.next){case 0:return n.changesStream&&n.changesStream.cancel(),n.changesStream=n.connection.changes(t.changesStream),n.changesStream.on("error",_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function t(){return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!(3<(o+=1))){t.next=9;break}return o=0,n.changesStream.cancel(),t.next=7,n.server.restart(e);case 7:t.next=10;break;case 9:case 10:a();case 11:case"end":return t.stop()}}),t)})))),_.next=5,r.callStack(_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({},e,{data:n.changesStream,hook:"couchdbInitializeChangesStream"}));case 5:case"end":return _.stop()}}),_)}))));return t.attachAutoRestarter&&a(),Promise.resolve()},Database.shouldExit=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,o;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.services,e.next=3,(0,_helper__WEBPACK_IMPORTED_MODULE_8__.stopServer)(n,r);case 3:return delete n.couchdb,o="log.txt",e.next=7,clientnode__WEBPACK_IMPORTED_MODULE_3___default().isFile(o);case 7:if(!e.sent){e.next=10;break}return e.next=10,fs__WEBPACK_IMPORTED_MODULE_4__.promises.unlink(o);case 10:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),Database}();Database.toggleIDDetermining=Symbol("toggleIDDetermining");const __WEBPACK_DEFAULT_EXPORT__=Database})(),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.588",
3
+ "version": "1.0.590",
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
@@ -32,6 +32,8 @@ export type DocumentIDMeta = PouchDB.Core.IdMeta;
32
32
  export type DocumentRevisionIDMeta = PouchDB.Core.RevisionIdMeta;
33
33
  export type FindRequest<Type extends Mapping<unknown>> = PouchDB.Find.FindRequest<Type>;
34
34
  export type GetOptions = PouchDB.Core.GetOptions;
35
+ export type PutOptions = PouchDB.Core.Options;
36
+ export type PutDocument<Type extends Mapping<unknown>> = PouchDB.Core.PutDocument<Type>;
35
37
  export type Index = PouchDB.Find.Index;
36
38
  export type DatabasePlugin = AnyFunction;
37
39
  export type AllowedRoles = (Array<string> | string | {
@@ -293,22 +295,21 @@ export interface PluginHandler extends BasePluginHandler {
293
295
  */
294
296
  restartCouchdb?(state: State): Promise<void>;
295
297
  }
296
- export interface EmptyEvaluationExceptionData {
298
+ export interface EmptyEvaluationErrorData {
297
299
  empty: string;
298
300
  }
299
- export type EmptyEvaluationException = Exception<EmptyEvaluationExceptionData>;
300
- export interface EvaluationExceptionData<S = Mapping<unknown>> {
301
+ export interface EvaluationErrorData<S = Mapping<unknown>> {
301
302
  code: string;
302
- error: Error;
303
+ error: unknown;
303
304
  scope: S;
304
305
  }
305
- export interface CompilationExceptionData<S = Mapping<unknown>> extends EvaluationExceptionData<S> {
306
+ export type EvaluationError = DatabaseError & EvaluationErrorData;
307
+ export interface CompilationErrorData<S = Mapping<unknown>> extends EvaluationErrorData<S> {
306
308
  compilation: string;
307
309
  }
308
- export interface RuntimeExceptionData<S = Mapping<unknown>> extends EvaluationExceptionData<S> {
310
+ export interface RuntimeErrorData<S = Mapping<unknown>> extends EvaluationErrorData<S> {
309
311
  runtime: string;
310
312
  }
311
- export type EvaluationException<S = Mapping<unknown>> = Exception<EvaluationExceptionData<S>>;
312
313
  export interface BasicScope<Type = unknown> {
313
314
  attachmentWithPrefixExists: (namePrefix: string) => boolean;
314
315
  checkDocument: (newDocument: PartialFullDocument, oldDocument: PartialFullDocument | null, parentNames: Array<string>) => CheckedDocumentResult;
@@ -358,10 +359,6 @@ export interface CheckedPropertyResult extends CheckedResult {
358
359
  export interface CheckedDocumentResult extends CheckedResult {
359
360
  newDocument: PartialFullDocument;
360
361
  }
361
- export type Exception<DataType = Mapping<unknown>> = {
362
- message: string;
363
- name: string;
364
- } & DataType;
365
362
  export type Migrator<Type = unknown> = (document: Document, scope: {
366
363
  configuration: Configuration;
367
364
  databaseHelper: DatabaseHelper;