couchdb-web-node-plugin 1.0.603 → 1.0.605

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,4 +1,5 @@
1
- import { AllowedModelRolesMapping, BaseModelConfiguration, Document, Models, PartialFullDocument, SecuritySettings, UserContext } from './type';
1
+ import { Mapping } from 'clientnode/type';
2
+ import { AllowedModelRolesMapping, Attachment, BaseModelConfiguration, Document, Models, PartialFullDocument, SecuritySettings, UserContext } from './type';
2
3
  /**
3
4
  * WebNode plugin interface with all provided hooks.
4
5
  */
@@ -43,6 +44,6 @@ export declare class DatabaseHelper {
43
44
  *
44
45
  * @returns Modified given new document.
45
46
  */
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
+ static validateDocumentUpdate<ObjectType extends object = object, AttachmentType extends Attachment = Attachment, AdditionalSpecifications extends object = Mapping<unknown>, AdditionalPropertiesType = unknown>(this: void, newDocument: PartialFullDocument<ObjectType, AdditionalPropertiesType>, oldDocument: (null | PartialFullDocument<ObjectType, AdditionalPropertiesType>), userContext: Partial<UserContext>, securitySettings: Partial<SecuritySettings>, modelConfiguration: BaseModelConfiguration<ObjectType, AdditionalSpecifications>, models?: Models<ObjectType, AttachmentType, AdditionalSpecifications, AdditionalPropertiesType>, toJSON?: (value: unknown) => string): PartialFullDocument<ObjectType, AdditionalPropertiesType>;
47
48
  }
48
49
  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;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],S=A[0],C=A[1];if(Object.prototype.hasOwnProperty.call(C,d.oldType)&&![null,void 0].includes(C[d.oldType]))for(var k,T,E=a([].concat(C[d.oldType]));!(k=E()).done;)T=k.value,j[T]=S}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}}},S=Object.keys(m).filter((function(e){return!D.includes(e)}));if("migrate"===w)for(var C,k,T=a(S);!(C=T()).done;)if(k=C.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 S,C,k=a(f);!(S=k()).done;)C=S.value,null===d[C]?i=n.concat(r,C,"file removed"):d[C]=t[r][C]}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=S.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(S.concat(v?Object.keys(e).filter((function(e){return!S.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=0,Ae=Object.keys(d.constraint);Ne<Ae.length;Ne++){var Se=Ae[Ne],Ce=d.constraint[Se];if(Object.prototype.hasOwnProperty.call(m,Ce))for(var ke,Te=a([].concat(m[Ce]));!(ke=Te()).done;){var Ee=ke.value,De=void 0;try{De=H(Ee.evaluation,Ce===d.constraint.expression,{checkPropertyContent:P,model:m,modelName:u,type:Ce,newDocument:e,oldDocument:t,parentNames:n,pathDescription:o})}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&s('Compilation: Hook "'+Ce+'" has invalid code "'+e.code+'": "'+e.message+'"'+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&s('Runtime: Hook "'+Ce+'" has thrown an error with code "'+e.code+'": '+e.message+o+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}if(De&&!De.result){var ze=Ce.replace(/^[^a-zA-Z]+/,"");s(ze.charAt(0).toUpperCase()+(ze.substring(1)+": ")+(Ee.description?r(Function,Object.keys(De.scope).concat(["return "+Ee.description.trim()])).apply(void 0,Object.values(De.scope)):'Model "'+u+'" should satisfy constraint "'+De.code+'" (given "'+z(e)+'")'+o+"."))}}}if(Object.prototype.hasOwnProperty.call(e,d.attachment)){var Re=e[d.attachment];("object"!=typeof Re||Object.getPrototypeOf(Re)!==Object.prototype)&&s("AttachmentType: given attachment has invalid type"+o+".");var Me=null;if(t&&Object.prototype.hasOwnProperty.call(t,d.attachment)&&(null!==(Me=t[d.attachment])&&"object"==typeof Me))for(var Ue=0,_e=Object.entries(Me);Ue<_e.length;Ue++){var He=_e[Ue],Le=He[0],Ie=He[1];if(Object.prototype.hasOwnProperty.call(Re,Le)){var We=Re[Le];null===We||null===We.data||We.content_type===Ie.content_type&&(We.data===Ie.data||We.digest===Ie.digest)?((null===We||null===We.data)&&(i=n.concat(d.attachment,Le,"attachment removed")),"incremental"===w&&delete Re[Le]):i=n.concat(d.attachment,Le,"attachment updated")}else"fillUp"===w?Re[Le]=Ie:w||(i=n.concat(d.attachment,Le,"attachment removed"))}for(var Ve=0,Fe=Object.entries(Re);Ve<Fe.length;Ve++){var Be=Fe[Ve],$e=Be[0],qe=Be[1];[null,void 0].includes(qe)||null===qe.data?delete Re[$e]:(!Me||!Object.prototype.hasOwnProperty.call(Me,$e)||qe.content_type!==Me[$e].content_type||qe.data!==Me[$e].data&&qe.digest!==Me[$e].digest)&&(i=n.concat(d.attachment,$e,"attachment updated"))}0===Object.keys(Re).length&&delete e[d.attachment];for(var Ye={},Je=0,Ge=Object.keys(m[d.attachment]);Je<Ge.length;Je++)Ye[Ge[Je]]=[];for(var Ke=0,Ze=Object.keys(Re);Ke<Ze.length;Ke++){for(var Qe=Ze[Ke],Xe=!1,et=0,tt=Object.entries(m[d.attachment]);et<tt.length;et++){var rt=tt[et],nt=rt[0],ot=rt[1];if(U(nt,Qe,ot)){Ye[nt].push(Qe),Xe=!0;break}}Xe||s('AttachmentTypeMatch: None of the specified attachment types ("'+Object.keys(m[d.attachment]).join('", "')+'") matches given one ("'+Qe+'")'+o+".")}for(var at=0,it=0,lt=Object.keys(Ye);it<lt.length;it++){var ct=lt[it],pt=m[d.attachment][ct];if(Object.prototype.hasOwnProperty.call(Ye,ct)){var st=Ye[ct].length;null!==pt.maximumNumber&&st>pt.maximumNumber&&s("AttachmentMaximum: given number of attachments ("+st+") doesn't satisfy specified maximum of "+pt.maximumNumber+' from type "'+ct+'"'+o+"."),(!pt.nullable||0!==st)&&st<pt.minimumNumber&&s("AttachmentMinimum: given number of attachments ("+st+") doesn't satisfy specified minimum of "+pt.minimumNumber+' from type "'+ct+'"'+o+".");for(var ut,mt=0,yt=a(Ye[ct]);!(ut=yt()).done;){var dt,ft,ht=ut.value;null!=(dt=pt.fileName)&&dt.regularExpressionPattern&&!new RegExp(pt.fileName.regularExpressionPattern).test(ht)?s('AttachmentName: given attachment name "'+ht+'" doesn\'t satisfy specified regular expression pattern "'+pt.fileName.regularExpressionPattern.toString()+'" from type "'+ct+'"'+o+"."):null!=(ft=pt.fileName)&&ft.invertedRegularExpressionPattern&&new RegExp(pt.fileName.invertedRegularExpressionPattern).test(ht)?s('InvertedAttachmentName: given attachment name "'+ht+'" does satisfy specified regular expression pattern "'+pt.fileName.invertedRegularExpressionPattern.toString()+'" from type "'+ct+'"'+o+"."):!([null,void 0].includes(pt.contentTypeRegularExpressionPattern)||Re[ht].content_type&&new RegExp(pt.contentTypeRegularExpressionPattern).test(Re[ht].content_type))&&s('AttachmentContentType: given attachment content type "'+Re[ht].content_type+'" doesn\'t satisfy specified regular expression pattern "'+pt.contentTypeRegularExpressionPattern+'" from type "'+ct+'"'+o+".");var gt=pt.invertedContentTypeRegularExpressionPattern;[null,void 0].includes(gt)||Re[ht].content_type&&!new RegExp(gt).test(Re[ht].content_type)||s('InvertedAttachmentContentType: given attachment content type "'+Re[ht].content_type+'" does satisfy specified regular expression pattern "'+gt+'" from type "'+ct+'"'+o+".");var vt=0;"length"in Re[ht]?vt=Re[ht].length:"data"in Re[ht]&&(vt=Buffer&&"byteLength"in Buffer?Buffer.byteLength(Re[ht].data,"base64"):Re[ht].data.length),![null,void 0].includes(pt.minimumSize)&&pt.minimumSize>vt?s("AttachmentMinimumSize: given attachment size "+vt+" byte doesn't satisfy specified minimum of "+pt.minimumSize+" byte "+o+"."):![null,void 0].includes(pt.maximumSize)&&pt.maximumSize<vt&&s("AttachmentMaximumSize: given attachment size "+vt+" byte doesn't satisfy specified maximum of "+pt.maximumSize+" byte "+o+"."),mt+=vt}![null,void 0].includes(pt.minimumAggregatedSize)&&pt.minimumAggregatedSize>mt?s('AttachmentAggregatedMinimumSize: given aggregated size of attachments from type "'+ct+'" '+mt+" byte doesn't satisfy specified minimum of "+pt.minimumAggregatedSize+" byte "+o+"."):![null,void 0].includes(pt.maximumAggregatedSize)&&pt.maximumAggregatedSize<mt&&s('AttachmentAggregatedMaximumSize: given aggregated size of attachments from type "'+ct+'" '+mt+" byte doesn't satisfy specified maximum of "+pt.maximumAggregatedSize+" byte "+o+"."),at+=mt}}Object.prototype.hasOwnProperty.call(m,d.minimumAggregatedSize)&&![null,void 0].includes(m[d.minimumAggregatedSize])&&m[d.minimumAggregatedSize]>at?s("AggregatedMinimumSize: given aggregated size "+at+" byte doesn't satisfy specified minimum of "+m[d.minimumAggregatedSize]+" byte "+o+"."):![null,void 0].includes(m[d.maximumAggregatedSize])&&m[d.maximumAggregatedSize]<at&&s("AggregatedMaximumSize: given aggregated size "+at+" 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 Ot,bt=0,wt=Object.keys(t);bt<wt.length;bt++)Ot=wt[bt],Object.prototype.hasOwnProperty.call(e,Ot)||(i=n.concat(Ot,"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],S=A[0],C=A[1];if(Object.prototype.hasOwnProperty.call(C,d.oldType)&&![null,void 0].includes(C[d.oldType]))for(var T,k,E=a([].concat(C[d.oldType]));!(T=E()).done;)k=T.value,j[k]=S}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=void 0;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){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 "'+m+'" (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,l){if(!r)for(var c,p,y=a(["onCreateExecution","onCreateExpression"]);!(c=y()).done;)if(p=c.value,Object.prototype.hasOwnProperty.call(e,p)){var d=void 0;try{d=H(e[p],p.endsWith("Expression"),{attachmentsTarget:l,checkPropertyContent:P,model:m,modelName:u,name:i+"",type:p,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 "'+p+'" has invalid code "'+e.code+'" for property "'+i+'": '+e.message+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&s('Runtime: Hook "'+p+'" has throw an error with code "'+e.code+'" for property "'+i+'": '+e.message+o+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}d&&![null,void 0].includes(d.result)&&(l?l[i]=d.result:t[i]=d.result)}},A=function(e,t,r,i,l){if(!l){if(!Object.prototype.hasOwnProperty.call(t,i))return;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 c,p,y=a(["onUpdateExecution","onUpdateExpression"]);!(c=y()).done;)if(p=c.value,Object.prototype.hasOwnProperty.call(e,p))try{var d=H(e[p],p.endsWith("Expression"),{attachmentsTarget:l,checkPropertyContent:P,model:m,modelName:u,name:i+"",type:p,newDocument:t,oldDocument:r,newValue:t[i],oldValue:r&&r[i]||void 0,parentNames:n,pathDescription:o,propertySpecification:e});l?l[i]=d.result:t[i]=d.result}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&s('Compilation: Hook "'+p+'" has invalid code "'+e.code+'" for property "'+i+'": '+e.message+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&s('Runtime: Hook "'+p+'" has throw an error with code "'+e.code+'" for property "'+i+'": '+e.message+o+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}},S=Object.keys(m).filter((function(e){return!D.includes(e)}));if("migrate"===w)for(var C,T,k=a(S);!(C=k()).done;)if(T=C.value,![null,void 0].includes(m[T].oldName))for(var E,_,I=a([].concat(m[T].oldName));!(E=I()).done;)_=E.value,Object.prototype.hasOwnProperty.call(e,_)&&(e[T]=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,Y=0,$=[d.update.execution,d.update.expression];Y<$.length;Y++)if(q=$[Y],Object.prototype.hasOwnProperty.call(m,q)){var J=void 0;try{J=H(m[q],q.endsWith("Expression"),{checkPropertyContent:P,model:m,modelName:u,type:q,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 "'+q+'" has invalid code "'+e.code+'" for document "'+u+'": '+e.message+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&s('Runtime: Hook "'+q+'" 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,Z=v?Object.keys(e).filter((function(e){return!S.includes(e)})):[],Q=a(S.concat(Z));!(G=Q()).done;)if(K=G.value,d.attachment===K)for(var X=function(){var r=te[ee],l=r[0],c=r[1];Object.prototype.hasOwnProperty.call(e,K)&&null!==e[d.attachment]||(e[d.attachment]={}),t&&!Object.prototype.hasOwnProperty.call(t,K)&&(t[d.attachment]={});var p=Object.keys(e[d.attachment]).filter((function(t){return null!==e[d.attachment][t].data&&U(l,t,c)})),u=e[d.attachment],m=[];if(t){var y=t[K];m=Object.keys(y).filter((function(e){return!(Object.prototype.hasOwnProperty.call(u,e)&&Object.prototype.hasOwnProperty.call(u[e],"data")&&null===u[e].data)&&!!y[e]&&(Object.prototype.hasOwnProperty.call(y[e],"data")&&null!==y[e].data||y[e].stub&&!!y[e].digest)&&!!U(l,e,c)}))}for(var f,h,g=c,v=a(p);!(f=v()).done;)h=f.value,N(g,e,t&&t[K]?t[K]:null,h,u);for(var O,b,P=a(p);!(O=P()).done;)b=O.value,A(g,e,t&&t[K]?t[K]:null,b,u);if([null,void 0].includes(g.default)){if(g.nullable||0<p.length||0<m.length||s('AttachmentMissing: Missing attachment for type "'+l+'"'+o+"."),"fillUp"===w&&0===p.length&&0<m.length)for(var j,x,S=a(m);!(j=S()).done;)x=j.value,null===u[x]?i=n.concat(K,x,"file removed"):u[x]=t[K][x]}else if(0===p.length)if(0===m.length)for(var C in g.default)Object.prototype.hasOwnProperty.call(g.default,C)&&(u[C]=g.default[C],i=n.concat(K,l,"add default file"));else if("fillUp"===w)for(var T,k,E=a(m);!(T=E()).done;)k=T.value,u[k]=t[K][k]},ee=0,te=Object.entries(m[d.attachment]);ee<te.length;ee++)X();else{var re=S.includes(K)?m[K]:v;N(re,e,t,K),A(re,e,t,K),[null,void 0].includes(re.default)?(!(re.nullable||Object.prototype.hasOwnProperty.call(e,K)||t&&Object.prototype.hasOwnProperty.call(t,K)&&w)&&s('MissingProperty: Missing property "'+K+'"'+o+"."),!Object.prototype.hasOwnProperty.call(e,K)&&t&&Object.prototype.hasOwnProperty.call(t,K)&&("fillUp"===w?e[K]=t[K]:!w&&(i=n.concat(K+"","property removed")))):(!Object.prototype.hasOwnProperty.call(e,K)||null===e[K])&&(t&&Object.prototype.hasOwnProperty.call(t,K)?"fillUp"===w?e[K]=t[K]:"migrate"===w&&(e[K]=re.default,i=n.concat(K+"","migrate default value")):(e[K]=re.default,i=i.concat(K+"","add default value")))}if(t&&"incremental"===w)for(var ne=0,oe=Object.entries(e);ne<oe.length;ne++){var ae=oe[ne],ie=ae[0],le=ae[1];Object.prototype.hasOwnProperty.call(t,ie)&&!l.property.name.reserved.concat(f,h,d.conflict,d.deleted,d.deletedConflict,d.localSequence,d.revisions,d.revisionsInformation,g).includes(ie)&&(t[ie]===le||z(t[ie])===z(le))&&delete e[ie]}for(var ce=0,pe=Object.entries(e);ce<pe.length;ce++){var se=pe[ce],ue=se[0],me=se[1];if(!l.property.name.reserved.concat(h,d.conflict,d.deleted,d.deletedConflict,d.localSequence,d.revisions,d.revisionsInformation,d.strategy).includes(ue)){var ye=void 0;if(Object.prototype.hasOwnProperty.call(m,ue))ye=m[ue];else if(v)ye=v;else{if("migrate"===w){delete e[ue],i=n.concat(ue+"","migrate removed property");continue}s('Property: Given property "'+ue+'" isn\'t specified in model "'+u+'"'+o+".")}if(!ye)continue;if(d.attachment===ue){var de=me;for(var fe in de)if(Object.prototype.hasOwnProperty.call(de,fe))for(var he in m[ue])if(U(he,fe,m[d.attachment][he])){x(m[d.attachment][he],e,t,fe,o);break}continue}if(x(ye,e,t,ue,o))continue;if("string"==typeof ye.type&&ye.type.endsWith("[]")||Array.isArray(ye.type)&&ye.type.length&&Array.isArray(ye.type[0])){var ge,ve=me;Array.isArray(ve)?![null,void 0].includes(ye.minimumNumber)&&ve.length<ye.minimumNumber?s('MinimumArrayLength: Property "'+ue+'" (array of length '+ve.length+") doesn't fullfill minimum array length of "+ye.minimumNumber+o+"."):![null,void 0].includes(ye.maximumNumber)&&ye.maximumNumber<ve.length&&s('MaximumArrayLength: Property "'+ue+'" (array of length '+ve.length+") doesn't fullfill maximum array length of "+ye.maximumNumber+o+"."):s('PropertyType: Property "'+ue+'" isn\'t of type "array -> '+ye.type+'" (given "'+z(ve)+'")'+o+"."),O(ve,ue+"",ye,t&&Object.prototype.hasOwnProperty.call(t,ue)&&t[ue]||void 0,["arrayConstraintExecution","arrayConstraintExpression"]);var Oe={};for(var be in ye)Object.prototype.hasOwnProperty.call(ye,be)&&(Oe[be]="type"===be?Array.isArray(ye[be])?ye[be][0]:[ye[be].substring(0,ye.type.length-2)]:ye[be]);if(1===(null==(ge=Oe.type)?void 0:ge.length)&&Object.prototype.hasOwnProperty.call(c,Oe.type[0]))for(var we,Pe,je=a(ve.slice());!(we=je()).done;)"object"!=typeof(Pe=we.value)||Object.getPrototypeOf(Pe)!==Object.prototype||Object.prototype.hasOwnProperty.call(Pe,g)||(Pe[g]=Oe.type[0]);for(var xe,Ne,Ae=0,Se=a(ve.slice());!(xe=Se()).done;)Ne=xe.value,ve[Ae]=P(Ne,Ae+1+". value in "+ue,Oe).newValue,null===Ne&&ve.splice(Ae,1),Ae+=1;t&&Object.prototype.hasOwnProperty.call(t,ue)&&Array.isArray(t[ue])&&t[ue].length===ve.length&&z(t[ue])===z(ve)||(i=n.concat(ue+"","array updated"))}else{var Ce=t&&Object.prototype.hasOwnProperty.call(t,ue)?t[ue]:null,Te=P(me,ue+"",ye,Ce);e[ue]=Te.newValue,Te.changedPath.length&&(i=Te.changedPath),null===e[ue]&&(null!==Ce&&(i=n.concat(ue+"","property removed")),delete e[ue])}}}for(var ke=0,Ee=Object.keys(d.constraint);ke<Ee.length;ke++){var De=Ee[ke],ze=d.constraint[De];if(Object.prototype.hasOwnProperty.call(m,ze))for(var Re,Me=a([].concat(m[ze]));!(Re=Me()).done;){var Ue=Re.value,_e=void 0;try{_e=H(Ue.evaluation,ze===d.constraint.expression,{checkPropertyContent:P,model:m,modelName:u,type:ze,newDocument:e,oldDocument:t,parentNames:n,pathDescription:o})}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&s('Compilation: Hook "'+ze+'" has invalid code "'+e.code+'": "'+e.message+'"'+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&s('Runtime: Hook "'+ze+'" has thrown an error with code "'+e.code+'": '+e.message+o+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}if(_e&&!_e.result){var He=ze.replace(/^[^a-zA-Z]+/,"");s(He.charAt(0).toUpperCase()+(He.substring(1)+": ")+(Ue.description?r(Function,Object.keys(_e.scope).concat(["return "+Ue.description.trim()])).apply(void 0,Object.values(_e.scope)):'Model "'+u+'" should satisfy constraint "'+_e.code+'" (given "'+z(e)+'")'+o+"."))}}}if(Object.prototype.hasOwnProperty.call(e,d.attachment)){var Le=e[d.attachment];("object"!=typeof Le||Object.getPrototypeOf(Le)!==Object.prototype)&&s("AttachmentType: given attachment has invalid type"+o+".");var Ie=null;if(t&&Object.prototype.hasOwnProperty.call(t,d.attachment)&&(null!==(Ie=t[d.attachment])&&"object"==typeof Ie))for(var We=0,Ve=Object.entries(Ie);We<Ve.length;We++){var Fe=Ve[We],Be=Fe[0],qe=Fe[1];if(Object.prototype.hasOwnProperty.call(Le,Be)){var Ye=Le[Be];null===Ye||null===Ye.data||Ye.content_type===qe.content_type&&(Ye.data===qe.data||Ye.digest===qe.digest)?((null===Ye||null===Ye.data)&&(i=n.concat(d.attachment,Be,"attachment removed")),"incremental"===w&&delete Le[Be]):i=n.concat(d.attachment,Be,"attachment updated")}else"fillUp"===w?Le[Be]=qe:w||(i=n.concat(d.attachment,Be,"attachment removed"))}for(var $e=0,Je=Object.entries(Le);$e<Je.length;$e++){var Ge=Je[$e],Ke=Ge[0],Ze=Ge[1];[null,void 0].includes(Ze)||null===Ze.data?delete Le[Ke]:(!Ie||!Object.prototype.hasOwnProperty.call(Ie,Ke)||Ze.content_type!==Ie[Ke].content_type||Ze.data!==Ie[Ke].data&&Ze.digest!==Ie[Ke].digest)&&(i=n.concat(d.attachment,Ke,"attachment updated"))}0===Object.keys(Le).length&&delete e[d.attachment];for(var Qe={},Xe=0,et=Object.keys(m[d.attachment]);Xe<et.length;Xe++)Qe[et[Xe]]=[];for(var tt=0,rt=Object.keys(Le);tt<rt.length;tt++){for(var nt=rt[tt],ot=!1,at=0,it=Object.entries(m[d.attachment]);at<it.length;at++){var lt=it[at],ct=lt[0],pt=lt[1];if(U(ct,nt,pt)){Qe[ct].push(nt),ot=!0;break}}ot||s('AttachmentTypeMatch: None of the specified attachment types ("'+Object.keys(m[d.attachment]).join('", "')+'") matches given one ("'+nt+'")'+o+".")}for(var st=0,ut=0,mt=Object.keys(Qe);ut<mt.length;ut++){var yt=mt[ut],dt=m[d.attachment][yt];if(Object.prototype.hasOwnProperty.call(Qe,yt)){var ft=Qe[yt].length;null!==dt.maximumNumber&&ft>dt.maximumNumber&&s("AttachmentMaximum: given number of attachments ("+ft+") doesn't satisfy specified maximum of "+dt.maximumNumber+' from type "'+yt+'"'+o+"."),(!dt.nullable||0!==ft)&&ft<dt.minimumNumber&&s("AttachmentMinimum: given number of attachments ("+ft+") doesn't satisfy specified minimum of "+dt.minimumNumber+' from type "'+yt+'"'+o+".");for(var ht,gt=0,vt=a(Qe[yt]);!(ht=vt()).done;){var Ot,bt,wt=ht.value;null!=(Ot=dt.fileName)&&Ot.regularExpressionPattern&&!new RegExp(dt.fileName.regularExpressionPattern).test(wt)?s('AttachmentName: given attachment name "'+wt+'" doesn\'t satisfy specified regular expression pattern "'+dt.fileName.regularExpressionPattern.toString()+'" from type "'+yt+'"'+o+"."):null!=(bt=dt.fileName)&&bt.invertedRegularExpressionPattern&&new RegExp(dt.fileName.invertedRegularExpressionPattern).test(wt)?s('InvertedAttachmentName: given attachment name "'+wt+'" does satisfy specified regular expression pattern "'+dt.fileName.invertedRegularExpressionPattern.toString()+'" from type "'+yt+'"'+o+"."):!([null,void 0].includes(dt.contentTypeRegularExpressionPattern)||Le[wt].content_type&&new RegExp(dt.contentTypeRegularExpressionPattern).test(Le[wt].content_type))&&s('AttachmentContentType: given attachment content type "'+Le[wt].content_type+'" doesn\'t satisfy specified regular expression pattern "'+dt.contentTypeRegularExpressionPattern+'" from type "'+yt+'"'+o+".");var Pt=dt.invertedContentTypeRegularExpressionPattern;[null,void 0].includes(Pt)||Le[wt].content_type&&!new RegExp(Pt).test(Le[wt].content_type)||s('InvertedAttachmentContentType: given attachment content type "'+Le[wt].content_type+'" does satisfy specified regular expression pattern "'+Pt+'" from type "'+yt+'"'+o+".");var jt=0;"length"in Le[wt]?jt=Le[wt].length:"data"in Le[wt]&&(jt=Buffer&&"byteLength"in Buffer?Buffer.byteLength(Le[wt].data,"base64"):Le[wt].data.length),![null,void 0].includes(dt.minimumSize)&&dt.minimumSize>jt?s("AttachmentMinimumSize: given attachment size "+jt+" byte doesn't satisfy specified minimum of "+dt.minimumSize+" byte "+o+"."):![null,void 0].includes(dt.maximumSize)&&dt.maximumSize<jt&&s("AttachmentMaximumSize: given attachment size "+jt+" byte doesn't satisfy specified maximum of "+dt.maximumSize+" byte "+o+"."),gt+=jt}![null,void 0].includes(dt.minimumAggregatedSize)&&dt.minimumAggregatedSize>gt?s('AttachmentAggregatedMinimumSize: given aggregated size of attachments from type "'+yt+'" '+gt+" byte doesn't satisfy specified minimum of "+dt.minimumAggregatedSize+" byte "+o+"."):![null,void 0].includes(dt.maximumAggregatedSize)&&dt.maximumAggregatedSize<gt&&s('AttachmentAggregatedMaximumSize: given aggregated size of attachments from type "'+yt+'" '+gt+" byte doesn't satisfy specified maximum of "+dt.maximumAggregatedSize+" byte "+o+"."),st+=gt}}Object.prototype.hasOwnProperty.call(m,d.minimumAggregatedSize)&&![null,void 0].includes(m[d.minimumAggregatedSize])&&m[d.minimumAggregatedSize]>st?s("AggregatedMinimumSize: given aggregated size "+st+" byte doesn't satisfy specified minimum of "+m[d.minimumAggregatedSize]+" byte "+o+"."):![null,void 0].includes(m[d.maximumAggregatedSize])&&m[d.maximumAggregatedSize]<st&&s("AggregatedMaximumSize: given aggregated size "+st+" 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 xt,Nt=0,At=Object.keys(t);Nt<At.length;Nt++)xt=At[Nt],Object.prototype.hasOwnProperty.call(e,xt)||(i=n.concat(xt,"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,5 +1,5 @@
1
- import { Mapping } from 'clientnode/type';
2
- import { AllowedModelRolesMapping, AllowedRoles, Configuration, Connection, DatabaseConnectorConfiguration, Model, ModelConfiguration, Models, NormalizedAllowedRoles, Services, SpecialPropertyNames } from './type';
1
+ import { Mapping, ValueOf } from 'clientnode/type';
2
+ import { AllowedModelRolesMapping, AllowedRoles, Configuration, Connection, DatabaseConnectorConfiguration, Model, ModelConfiguration, Models, NormalizedAllowedRoles, PropertySpecification, Services, SpecialPropertyNames } from './type';
3
3
  /**
4
4
  * Converts internal declarative database connector configuration object
5
5
  * into a database compatible one.
@@ -52,6 +52,13 @@ export declare const initializeConnection: (services: Services, configuration: C
52
52
  * @returns The mapping object.
53
53
  */
54
54
  export declare const determineAllowedModelRolesMapping: (modelConfiguration: ModelConfiguration) => AllowedModelRolesMapping;
55
+ /**
56
+ * Determines whether given value of a model is a property specification.
57
+ * @param value - Value to analyze.
58
+ *
59
+ * @returns Boolean indicating the case.
60
+ */
61
+ export declare const isPropertySpecification: (value: ValueOf<Model>) => value is PropertySpecification<unknown, object>;
55
62
  /**
56
63
  * Determines all property names which are indexable in a generic manner.
57
64
  * @param modelConfiguration - Model specification object.
@@ -69,7 +76,7 @@ export declare const determineGenericIndexablePropertyNames: (modelConfiguration
69
76
  *
70
77
  * @returns Given model in extended version.
71
78
  */
72
- export declare const extendModel: (modelName: string, models: Models, extendPropertyName?: SpecialPropertyNames['extend']) => Model;
79
+ export declare const extendModel: (modelName: string, models: Mapping<Partial<Model>>, extendPropertyName?: SpecialPropertyNames['extend']) => Partial<Model>;
73
80
  /**
74
81
  * Extend default specification with specific one.
75
82
  * @param modelConfiguration - Model specification object.
package/helper.js CHANGED
@@ -1 +1 @@
1
- (()=>{"use strict";var e=[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")}],t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var a=t[n]={exports:{}};return e[n](a,a.exports,r),a.exports}r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};(()=>{r.r(n),r.d(n,{determineAllowedModelRolesMapping:()=>v,determineGenericIndexablePropertyNames:()=>h,ensureValidationDocumentPresence:()=>y,extendModel:()=>m,extendModels:()=>g,getConnectorOptions:()=>d,initializeConnection:()=>b,mayStripRepresentation:()=>f,normalizeAllowedRoles:()=>x});var e=r(0),t=r.n(e),o=r(1),a=r.n(o),i=r(2),c=r.n(i),s=r(3),p=r.n(s);function l(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 u(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)?u(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 u(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){return e.couchdb.connector.fetch?{fetch:function(t,r){return s.globalContext.fetch(t,p().extend(!0,p().copy(e.couchdb.connector.fetch),r||{}))}}:{fetch:function(e,t){return s.globalContext.fetch(e,t)}}},f=function(e,t,r){var n=p().represent(e);return n.length<=t?n.length>r?n.substring(0,r-3)+"...":n:"DOCUMENT IS TOO BIG TO REPRESENT"},y=function(){var e=a()(c().mark((function e(r,n,o,a,i,s,l){var u,d,f;return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return void 0===i&&(i=!0),void 0===s&&(s="_id"),void 0===l&&(l="_design/"),d=t()(((u={})[s]=""+l+n,u.language="javascript",u),o),e.prev=4,e.next=7,r.get(""+l+n);case 7:return f=e.sent,d._rev=f._rev,e.next=11,r.put(d);case 11:case 20:e.next=26;break;case 14:return e.prev=14,e.t0=e.catch(4),i&&e.t0.error,e.prev=17,e.next=20,r.put(d);case 23:throw e.prev=23,e.t1=e.catch(17),new Error(a+" couldn't be installed/updated: \""+p().represent(e.t1)+'".');case 26:case"end":return e.stop()}}),e,null,[[4,14],[17,23]])})));return function(){return e.apply(this,arguments)}}(),b=function(){var e=a()(c().mark((function e(t,r){var n,o,i,u,f,y,b,v;return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=r.couchdb,o=p().stringFormat(n.url,n.user.name+":"+n.user.password+"@")+"/"+n.databaseName,t.couchdb.connection=new t.couchdb.connector(o,d(r)),(i=t.couchdb.connection).setMaxListeners(1/0),u=n.model.property.name.special.id,f=n.model.property.name.special.revision,y=c().mark((function(){var e,t;return c().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:e=v.value,t=i[e].bind(i),i[e]=a()(c().mark((function e(r,o){var a,i,s;return c().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[u])&&n.ignoreNoChangeError&&"forbidden"===e.t0.name&&null!=(a=e.t0.message)&&a.startsWith("NoChange:"))){e.next=22;break}if(s="object"==typeof o&&f in o?o[f]:r[f],e.t1=i,!(f 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=f,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()}}),y)})),b=l(["post","put"]);case 9:if((v=b()).done){e.next=13;break}return e.delegateYield(y(),"t0",11);case 11:e.next=9;break;case 13:return e.prev=13,e.next=16,p().checkReachability(o);case 16:e.next=23;break;case 18:return e.prev=18,e.t1=e.catch(13),e.next=23,s.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)}}(),v=function(e){for(var r=e.property.name.special.allowedRole,n={},o=g(e),a=0,i=Object.entries(o);a<i.length;a++){var c=i[a],s=c[0],p=c[1];if(Object.prototype.hasOwnProperty.call(p,r)){n[s]=t()({properties:{}},x(p[r]));for(var l=0,u=Object.entries(p);l<u.length;l++){var d=u[l],f=d[0],y=d[1];null!==y&&"object"==typeof y&&y.allowedRoles&&(n[s].properties[f]=x(y.allowedRoles))}}else n[s]={properties:{},read:[],write:[]}}return n},h=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()},m=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=l([].concat(t[e][r]));!(n=a()).done;)o=n.value,t[e]=p().extend(!0,p().copy(m(o,t,r)),t[e]);delete t[e][r]}return t[e]},g=function(e){for(var t,r=e.property.name.special,n={},o=e.property.name.typeRegularExpressionPattern,a=0,i=Object.keys(e.entities);a<i.length;a++){if(t=i[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]=m(t,e.entities,r.extend)}for(var c,s=0,l=Object.values(n);s<l.length;s++){c=l[s];for(var u=0,d=Object.entries(c);u<d.length;u++){var f=d[u],y=f[0],b=f[1];if(y===r.attachment)for(var v=0,h=Object.entries(b);v<h.length;v++){var g=h[v],x=g[0],w=g[1];b[x]=p().extend(!0,p().copy(e.property.defaultSpecification),w)}else[r.allowedRole,r.constraint.execution,r.constraint.expression,r.extend,r.maximumAggregatedSize,r.minimumAggregatedSize,r.oldType].includes(y)||(c[y]=p().extend(!0,p().copy(e.property.defaultSpecification),b))}}return n},x=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]}}})(),module.exports=n})();
1
+ (()=>{"use strict";var e=[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")}],t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var a=t[n]={exports:{}};return e[n](a,a.exports,r),a.exports}r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};(()=>{r.r(n),r.d(n,{determineAllowedModelRolesMapping:()=>v,determineGenericIndexablePropertyNames:()=>m,ensureValidationDocumentPresence:()=>y,extendModel:()=>g,extendModels:()=>x,getConnectorOptions:()=>d,initializeConnection:()=>b,isPropertySpecification:()=>h,mayStripRepresentation:()=>f,normalizeAllowedRoles:()=>w});var e=r(0),t=r.n(e),o=r(1),a=r.n(o),i=r(2),c=r.n(i),s=r(3),p=r.n(s);function l(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 u(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)?u(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 u(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){return e.couchdb.connector.fetch?{fetch:function(t,r){return s.globalContext.fetch(t,p().extend(!0,p().copy(e.couchdb.connector.fetch),r||{}))}}:{fetch:function(e,t){return s.globalContext.fetch(e,t)}}},f=function(e,t,r){var n=p().represent(e);return n.length<=t?n.length>r?n.substring(0,r-3)+"...":n:"DOCUMENT IS TOO BIG TO REPRESENT"},y=function(){var e=a()(c().mark((function e(r,n,o,a,i,s,l){var u,d,f;return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return void 0===i&&(i=!0),void 0===s&&(s="_id"),void 0===l&&(l="_design/"),d=t()(((u={})[s]=""+l+n,u.language="javascript",u),o),e.prev=4,e.next=7,r.get(""+l+n);case 7:return f=e.sent,d._rev=f._rev,e.next=11,r.put(d);case 11:case 20:e.next=26;break;case 14:return e.prev=14,e.t0=e.catch(4),i&&e.t0.error,e.prev=17,e.next=20,r.put(d);case 23:throw e.prev=23,e.t1=e.catch(17),new Error(a+" couldn't be installed/updated: \""+p().represent(e.t1)+'".');case 26:case"end":return e.stop()}}),e,null,[[4,14],[17,23]])})));return function(){return e.apply(this,arguments)}}(),b=function(){var e=a()(c().mark((function e(t,r){var n,o,i,u,f,y,b,v;return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=r.couchdb,o=p().stringFormat(n.url,n.user.name+":"+n.user.password+"@")+"/"+n.databaseName,t.couchdb.connection=new t.couchdb.connector(o,d(r)),(i=t.couchdb.connection).setMaxListeners(1/0),u=n.model.property.name.special.id,f=n.model.property.name.special.revision,y=c().mark((function(){var e,t;return c().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:e=v.value,t=i[e].bind(i),i[e]=a()(c().mark((function e(r,o){var a,i,s;return c().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[u])&&n.ignoreNoChangeError&&"forbidden"===e.t0.name&&null!=(a=e.t0.message)&&a.startsWith("NoChange:"))){e.next=22;break}if(s="object"==typeof o&&f in o?o[f]:r[f],e.t1=i,!(f 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=f,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()}}),y)})),b=l(["post","put"]);case 9:if((v=b()).done){e.next=13;break}return e.delegateYield(y(),"t0",11);case 11:e.next=9;break;case 13:return e.prev=13,e.next=16,p().checkReachability(o);case 16:e.next=23;break;case 18:return e.prev=18,e.t1=e.catch(13),e.next=23,s.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)}}(),v=function(e){for(var r=e.property.name.special.allowedRole,n={},o=x(e),a=0,i=Object.entries(o);a<i.length;a++){var c=i[a],s=c[0],p=c[1];if(Object.prototype.hasOwnProperty.call(p,r)){n[s]=t()({properties:{}},w(p[r]));for(var l=0,u=Object.entries(p);l<u.length;l++){var d=u[l],f=d[0],y=d[1];null!==y&&"object"==typeof y&&y.allowedRoles&&(n[s].properties[f]=w(y.allowedRoles))}}else n[s]={properties:{},read:[],write:[]}}return n},h=function(e){return null!==e&&"object"==typeof e},m=function(e,t){var r=e.property.name.special;return Object.keys(t).filter((function(n){var o=t[n];return h(o)&&Object.prototype.hasOwnProperty.call(o,"index")&&o.index||h(o)&&!(Object.prototype.hasOwnProperty.call(o,"index")&&!o.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)||o.type&&("string"==typeof o.type&&o.type.endsWith("[]")||Array.isArray(o.type)&&o.type.length&&Array.isArray(o.type[0])||Object.prototype.hasOwnProperty.call(e.entities,o.type)))})).concat([r.id,r.revision]).sort()},g=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=l([].concat(t[e][r]));!(n=a()).done;)o=n.value,t[e]=p().extend(!0,p().copy(g(o,t,r)),t[e]);delete t[e][r]}return t[e]},x=function(e){for(var t,r=e.property.name.special,n={},o=e.property.name.typeRegularExpressionPattern,a=0,i=Object.keys(e.entities);a<i.length;a++){if(t=i[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]=g(t,e.entities,r.extend)}for(var c,s=0,l=Object.values(n);s<l.length;s++){c=l[s];for(var u=0,d=Object.entries(c);u<d.length;u++){var f=d[u],y=f[0],b=f[1];if(y===r.attachment)for(var v=b,h=0,m=Object.entries(v);h<m.length;h++){var x=m[h],w=x[0],O=x[1];v[w]=p().extend(!0,p().copy(e.property.defaultSpecification),O)}else[r.allowedRole,r.constraint.execution,r.constraint.expression,r.extend,r.maximumAggregatedSize,r.minimumAggregatedSize,r.oldType].includes(y)||(c[y]=p().extend(!0,p().copy(e.property.defaultSpecification),b))}}return n},w=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]}}})(),module.exports=n})();
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,t,r)=>{"use strict";r.d(t,{determineAllowedModelRolesMapping:()=>y,determineGenericIndexablePropertyNames:()=>h,ensureValidationDocumentPresence:()=>f,extendModels:()=>O,getConnectorOptions:()=>d,initializeConnection:()=>b,mayStripRepresentation:()=>m});var n=r(0),o=r.n(n),a=r(1),c=r.n(a),_=r(2),i=r.n(_),s=r(3),l=r.n(s);function u(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 p(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)?p(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 p(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){return e.couchdb.connector.fetch?{fetch:function(t,r){return s.globalContext.fetch(t,l().extend(!0,l().copy(e.couchdb.connector.fetch),r||{}))}}:{fetch:function(e,t){return s.globalContext.fetch(e,t)}}},m=function(e,t,r){var n=l().represent(e);return n.length<=t?n.length>r?n.substring(0,r-3)+"...":n:"DOCUMENT IS TOO BIG TO REPRESENT"},f=function(){var e=c()(i().mark((function e(t,r,n,a,c,_,s){var u,p,d;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return void 0===c&&(c=!0),void 0===_&&(_="_id"),void 0===s&&(s="_design/"),p=o()(((u={})[_]=""+s+r,u.language="javascript",u),n),e.prev=4,e.next=7,t.get(""+s+r);case 7:return d=e.sent,p._rev=d._rev,e.next=11,t.put(p);case 11:case 20:e.next=26;break;case 14:return e.prev=14,e.t0=e.catch(4),c&&e.t0.error,e.prev=17,e.next=20,t.put(p);case 23:throw e.prev=23,e.t1=e.catch(17),new Error(a+" couldn't be installed/updated: \""+l().represent(e.t1)+'".');case 26:case"end":return e.stop()}}),e,null,[[4,14],[17,23]])})));return function(){return e.apply(this,arguments)}}(),b=function(){var e=c()(i().mark((function e(t,r){var n,o,a,_,p,m,f,b;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=r.couchdb,o=l().stringFormat(n.url,n.user.name+":"+n.user.password+"@")+"/"+n.databaseName,t.couchdb.connection=new t.couchdb.connector(o,d(r)),(a=t.couchdb.connection).setMaxListeners(1/0),_=n.model.property.name.special.id,p=n.model.property.name.special.revision,m=i().mark((function(){var e,t;return i().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:e=b.value,t=a[e].bind(a),a[e]=c()(i().mark((function e(r,o){var a,c,s;return i().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),!((c=r[_])&&n.ignoreNoChangeError&&"forbidden"===e.t0.name&&null!=(a=e.t0.message)&&a.startsWith("NoChange:"))){e.next=22;break}if(s="object"==typeof o&&p in o?o[p]:r[p],e.t1=c,!(p 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(c);case 18:e.t3=p,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()}}),m)})),f=u(["post","put"]);case 9:if((b=f()).done){e.next=13;break}return e.delegateYield(m(),"t0",11);case 11:e.next=9;break;case 13:return e.prev=13,e.next=16,l().checkReachability(o);case 16:e.next=23;break;case 18:return e.prev=18,e.t1=e.catch(13),e.next=23,s.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)}}(),y=function(e){for(var t=e.property.name.special.allowedRole,r={},n=O(e),a=0,c=Object.entries(n);a<c.length;a++){var _=c[a],i=_[0],s=_[1];if(Object.prototype.hasOwnProperty.call(s,t)){r[i]=o()({properties:{}},g(s[t]));for(var l=0,u=Object.entries(s);l<u.length;l++){var p=u[l],d=p[0],m=p[1];null!==m&&"object"==typeof m&&m.allowedRoles&&(r[i].properties[d]=g(m.allowedRoles))}}else r[i]={properties:{},read:[],write:[]}}return r},h=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()},x=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=u([].concat(t[e][r]));!(n=a()).done;)o=n.value,t[e]=l().extend(!0,l().copy(x(o,t,r)),t[e]);delete t[e][r]}return t[e]},O=function(e){for(var t,r=e.property.name.special,n={},o=e.property.name.typeRegularExpressionPattern,a=0,c=Object.keys(e.entities);a<c.length;a++){if(t=c[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]=x(t,e.entities,r.extend)}for(var _,i=0,s=Object.values(n);i<s.length;i++){_=s[i];for(var u=0,p=Object.entries(_);u<p.length;u++){var d=p[u],m=d[0],f=d[1];if(m===r.attachment)for(var b=0,y=Object.entries(f);b<y.length;b++){var h=y[b],O=h[0],g=h[1];f[O]=l().extend(!0,l().copy(e.property.defaultSpecification),g)}else[r.allowedRole,r.constraint.execution,r.constraint.expression,r.extend,r.maximumAggregatedSize,r.minimumAggregatedSize,r.oldType].includes(m)||(_[m]=l().extend(!0,l().copy(e.property.defaultSpecification),f))}}return n},g=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=>{"use strict";e.exports=require("fs")},e=>{"use strict";e.exports=require("path")},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 c={d:function(e,t){for(var r in t)c.o(t,r)&&!c.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(_,{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===c&&(c="_id"),void 0===_&&(_="-type"),void 0===i&&(i="_design/"),void 0===s&&(s=!1);var u=null!==(l=e[_])&&void 0!==l?l:t&&t[_];if(!u)return!0;var p=s?"read":"write",d={properties:{},read:["_admin","readonlyadmin"],write:["_admin"]};Object.prototype.hasOwnProperty.call(e,c)&&e[c].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],x=o(["read","write"]);!(b=x()).done;)d[y=b.value]=d[y].concat(h[y]||[]);d.properties=h.properties}for(var O,g,v=d[p],P=o(r.roles);!(O=P()).done;)if(g=O.value,v.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=!_.dateTimeFormat.startsWith("iso"),m=_.property.name.special,f=m.id,b=m.revision,y=m.type;r&&r[y]&&!e[y]&&(e[y]=r[y]);var h="",x="",O=function(){h=Object.prototype.hasOwnProperty.call(e,f)?e[f]:"",x=Object.prototype.hasOwnProperty.call(e,b)?e[b]:""};if(O(),Object.prototype.hasOwnProperty.call(c,_.property.name.validatedDocumentsCache)&&c[_.property.name.validatedDocumentsCache].has(h+"-"+x))return c[_.property.name.validatedDocumentsCache].delete(h+"-"+x),e;["latest","upsert"].includes(x)&&(r&&Object.prototype.hasOwnProperty.call(r,b)?x=e[b]=r[b]:"latest"===x?l("Revision: No old document available to update."):delete e[b]);var g=_.updateStrategy;Object.prototype.hasOwnProperty.call(e,m.strategy)&&(g=e[m.strategy],delete e[m.strategy]);var v,P={};if("migrate"===g)for(var E=0,D=Object.entries(i);E<D.length;E++){var M=D[E],w=M[0],k=M[1];if(Object.prototype.hasOwnProperty.call(k,m.oldType)&&![null,void 0].includes(k[m.oldType]))for(var C,A,T=o([].concat(k[m.oldType]));!(C=T()).done;)A=C.value,P[A]=w}s?v=s:JSON&&Object.prototype.hasOwnProperty.call(JSON,"stringify")?v=function(e){return JSON.stringify(e,null,4)}:l('Needed "serializer" is not available.');var j=[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],I=function(e){return e instanceof Error?""+e:v(e)},R=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 c=Object.keys(r);if(c.length)return c[0]}return null},B=function(e,r,o){void 0===r&&(r=!1),void 0===o&&(o={});var a=R(e);if(a){var c,_=(r?"return ":"")+a,i=n({},N,{code:_},o),s=Object.keys(i);try{c=t(Function,s.concat([_]))}catch(c){l(I(c),"compilation",{code:_,error:c,scope:i})}var u={code:_,result:void 0,scope:i};try{u.result=c.apply(void 0,s.map((function(e){return i[e]})))}catch(c){l(I(c),"runtime",{code:_,error:c,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(" -> "):"",c=[],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(_.property.name.typeRegularExpressionPattern.public).test(e[y])||l('TypeName: You have to specify a model type which matches "'+_.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 x=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:c,model:p,modelName:u,name:i,type:b,newDocument:e,newValue:_,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 x=R(s[b].description);l(b.charAt(0).toUpperCase()+(b.substring(1)+": ")+(x?t(Function,Object.keys(h.scope).concat(["return "+x])).apply(void 0,Object.values(h.scope)):'Property "'+i+'" should satisfy constraint "'+h.code+'" (given "'+I(_)+'")'+a+"."))}}},v=function(e,t,r,c){void 0===c&&(c=null);var _=[],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,_=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,c,n.concat(t));if(h.changedPath.length&&(_=h.changedPath),e=h.newDocument,I(e)===I({}))return{newValue:null,changedPath:_};m=!0;break}1===s.length&&l('NestedType: Under key "'+t+'" isn\'t of type "'+p+'" (given "'+I(e)+'" of type '+typeof e+")"+a+".")}else if("DateTime"===p){var O=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 "'+I(O).replace(/^"/,"").replace(/"$/,"")+'" of type "'+typeof O+'")'+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 "'+I(e)+'" of type "'+typeof e+'")'+a+".")}else if("string"==typeof p&&p.startsWith("foreignKey:")){var v=i[p.substring(11)][f].type;if(v===typeof e){m=!0;break}1===s.length&&l('PropertyType: Foreign key property "'+t+'" isn\'t of type "'+v+'" (given "'+I(e)+'" of type "'+typeof e+'")'+a+".")}else{if("any"===p||I(e)===I(p)){m=!0;break}1===s.length&&l('PropertyType: Property "'+t+'" isn\'t value "'+p+'" (given "'+I(e).replace(/^"/,"").replace(/"$/,"")+'" of type "'+typeof e+'")'+a+".")}if(m||l('PropertyType: None of the specified types "'+s.join('", "')+'" for property "'+t+'" matches value "'+I(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+"."),x(e,t,r,c),I(e)!==I(c)&&(_=n.concat(t,"value updated")),{newValue:e,changedPath:_}},E=function(e,t,r,o,a){var i=t[o];if(!e.writable)if(r){if(Object.prototype.hasOwnProperty.call(r,o)&&I(i)===I(r[o]))return o!==f&&"incremental"===g&&delete t[o],!0;l('Readonly: Property "'+o+'" is not writable (old document "'+I(r)+'")'+a+".")}else l('Readonly: Property "'+o+'" is not writable'+a+".");if(!e.mutable&&r&&Object.prototype.hasOwnProperty.call(r,o)){if(I(i)===I(r[o]))return"incremental"!==g||_.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 "'+I(r)+'")'+a+".")}if(null===i){if(e.nullable)return delete t[o],r&&Object.prototype.hasOwnProperty.call(r,o)&&(c=n.concat(o,"delete property")),!0;l('NotNull: Property "'+o+'" should not be "null"'+a+".")}return!1},D=function(e,t,r,c){if(!r)for(var _,i,s=o(["onCreateExecution","onCreateExpression"]);!(_=s()).done;)if(i=_.value,Object.prototype.hasOwnProperty.call(e,i)){var d=void 0;try{d=B(e[i],i.endsWith("Expression"),{checkPropertyContent:v,model:p,modelName:u,name:c,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 "'+c+'": '+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 "'+c+'": '+e.message+a+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}d&&![null,void 0].includes(d.result)&&(t[c]=d.result)}},M=function(e,t,r,c){if(Object.prototype.hasOwnProperty.call(t,c)){e.trim&&"string"==typeof t[c]&&(t[c]=t[c].trim()),e.emptyEqualsToNull&&(""===t[c]||Array.isArray(t[c])&&0===t[c].length||null!==t[c]&&"object"==typeof t[c]&&0===Object.keys(t).length)&&(t[c]=null);for(var _,i,s=o(["onUpdateExecution","onUpdateExpression"]);!(_=s()).done;)if(i=_.value,Object.prototype.hasOwnProperty.call(e,i))try{t[c]=B(e[i],i.endsWith("Expression"),{checkPropertyContent:v,model:p,modelName:u,name:c,type:i,newDocument:t,oldDocument:r,newValue:t[c],oldValue:r&&r[c],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 "'+c+'": '+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 "'+c+'": '+e.message+a+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}}},w=Object.keys(p).filter((function(e){return!j.includes(e)}));if("migrate"===g)for(var k,C,A=o(w);!(k=A()).done;)if(C=k.value,![null,void 0].includes(p[C].oldName))for(var T,W,N=o([].concat(p[C].oldName));!(T=N()).done;)W=T.value,Object.prototype.hasOwnProperty.call(e,W)&&(e[C]=e[W],delete e[W]);if(!r)for(var S,q=0,$=[m.create.execution,m.create.expression];q<$.length;q++)if(S=$[q],Object.prototype.hasOwnProperty.call(p,S)){var F=void 0;try{F=B(p[S],S.endsWith("Expression"),{checkPropertyContent:v,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[y],0===n.length&&O()}for(var z,H=0,G=[m.update.execution,m.update.expression];H<G.length;H++)if(z=G[H],Object.prototype.hasOwnProperty.call(p,z)){var V=void 0;try{V=B(p[z],z.endsWith("Expression"),{checkPropertyContent:v,model:p,modelName:u,type:z,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 "'+z+'" has invalid code "'+e.code+'" for document "'+u+'": '+e.message+a+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&l('Runtime: Hook "'+z+'" 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&&O()}for(var J,Y=function(){var t=J.value;if(m.attachment===t)for(var _=function(){var _=s[i],u=_[0],p=_[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,x=p,O=o(d);!(y=O()).done;)h=y.value,D(x,m,r&&r[t]?r[t]:null,h);for(var v,P,E=o(d);!(v=E()).done;)P=v.value,M(x,m,r&&r[t]?r[t]:null,P);if([null,void 0].includes(x.default)){if(x.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,k,C=o(f);!(w=C()).done;)k=w.value,null===m[k]?c=n.concat(t,k,"file removed"):m[k]=r[t][k]}else if(0===d.length)if(0===f.length)for(var A in x.default)Object.prototype.hasOwnProperty.call(x.default,A)&&(m[A]=x.default[A],c=n.concat(t,u,"add default file"));else if("fillUp"===g)for(var T,j,I=o(f);!(T=I()).done;)j=T.value,m[j]=r[t][j]},i=0,s=Object.entries(p[t]);i<s.length;i++)_();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&&(c=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,c=n.concat(t,"migrate default value")):(e[t]=u.default,c=c.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)&&!_.property.name.reserved.concat(f,b,m.conflict,m.deleted,m.deletedConflict,m.localSequence,m.revisions,m.revisionsInformation,y).includes(te)&&(r[te]===re||I(r[te])===I(re))&&delete e[te]}for(var ne=0,oe=Object.entries(e);ne<oe.length;ne++){var ae=oe[ne],ce=ae[0],_e=ae[1];if(!_.property.name.reserved.concat(b,m.conflict,m.deleted,m.deletedConflict,m.localSequence,m.revisions,m.revisionsInformation,m.strategy).includes(ce)){var ie=void 0;if(Object.prototype.hasOwnProperty.call(p,ce))ie=p[ce];else if(h)ie=h;else{if("migrate"===g){delete e[ce],c=n.concat(ce,"migrate removed property");continue}l('Property: Given property "'+ce+'" isn\'t specified in model "'+u+'"'+a+".")}if(!ie)continue;if(m.attachment===ce){var se=_e;for(var le in se)if(Object.prototype.hasOwnProperty.call(se,le))for(var ue in p[ce])if(L(ue,le,p[ce][ue])){E(p[ce][ue],e,r,le,a);break}continue}if(E(ie,e,r,ce,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=_e;Array.isArray(de)?![null,void 0].includes(ie.minimumNumber)&&de.length<ie.minimumNumber?l('MinimumArrayLength: Property "'+ce+'" (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 "'+ce+'" (array of length '+de.length+") doesn't fullfill maximum array length of "+ie.maximumNumber+a+"."):l('PropertyType: Property "'+ce+'" isn\'t of type "array -> '+ie.type+'" (given "'+I(de)+'")'+a+"."),x(de,ce,ie,r&&Object.prototype.hasOwnProperty.call(r,ce)&&r[ce]||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 xe,Oe,ge=0,ve=o(de.slice());!(xe=ve()).done;)Oe=xe.value,de[ge]=v(Oe,ge+1+". value in "+ce,me).newValue,null===Oe&&de.splice(ge,1),ge+=1;r&&Object.prototype.hasOwnProperty.call(r,ce)&&Array.isArray(r[ce])&&r[ce].length===de.length&&I(r[ce])===I(de)||(c=n.concat(ce,"array updated"))}else{var Pe=r&&Object.prototype.hasOwnProperty.call(r,ce)?r[ce]:null,Ee=v(_e,ce,ie,Pe);e[ce]=Ee.newValue,Ee.changedPath.length&&(c=Ee.changedPath),null===e[ce]&&(null!==Pe&&(c=n.concat(ce,"property removed")),delete e[ce])}}}for(var De=0,Me=Object.keys(m.constraint);De<Me.length;De++){var we=Me[De],ke=m.constraint[we];if(Object.prototype.hasOwnProperty.call(p,ke))for(var Ce,Ae=o([].concat(p[ke]));!(Ce=Ae()).done;){var Te=Ce.value,je=void 0;try{je=B(Te.evaluation,ke===m.constraint.expression,{checkPropertyContent:v,model:p,modelName:u,type:ke,newDocument:e,oldDocument:r,parentNames:n,pathDescription:a})}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&l('Compilation: Hook "'+ke+'" has invalid code "'+e.code+'": "'+e.message+'"'+a+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&l('Runtime: Hook "'+ke+'" has thrown an error with code "'+e.code+'": '+e.message+a+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}if(je&&!je.result){var Ie=ke.replace(/^[^a-zA-Z]+/,"");l(Ie.charAt(0).toUpperCase()+(Ie.substring(1)+": ")+(Te.description?t(Function,Object.keys(je.scope).concat(["return "+Te.description.trim()])).apply(void 0,Object.values(je.scope)):'Model "'+u+'" should satisfy constraint "'+je.code+'" (given "'+I(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 Ue=null;if(r&&Object.prototype.hasOwnProperty.call(r,m.attachment)&&null!==(Ue=r[m.attachment])&&"object"==typeof Ue)for(var Le=0,We=Object.entries(Ue);Le<We.length;Le++){var Be=We[Le],Ke=Be[0],Ne=Be[1];if(Object.prototype.hasOwnProperty.call(Re,Ke)){var Se=Re[Ke];null===Se||null===Se.data||Se.content_type===Ne.content_type&&(Se.data===Ne.data||Se.digest===Ne.digest)?((null===Se||null===Se.data)&&(c=n.concat(m.attachment,Ke,"attachment removed")),"incremental"===g&&delete Re[Ke]):c=n.concat(m.attachment,Ke,"attachment updated")}else"fillUp"===g?Re[Ke]=Ne:g||(c=n.concat(m.attachment,Ke,"attachment removed"))}for(var qe=0,$e=Object.entries(Re);qe<$e.length;qe++){var Fe=$e[qe],ze=Fe[0],He=Fe[1];[null,void 0].includes(He)||null===He.data?delete Re[ze]:(!Ue||!Object.prototype.hasOwnProperty.call(Ue,ze)||He.content_type!==Ue[ze].content_type||He.data!==Ue[ze].data&&He.digest!==Ue[ze].digest)&&(c=n.concat(m.attachment,ze,"attachment updated"))}0===Object.keys(Re).length&&delete e[m.attachment];for(var Ge={},Ve=0,Je=Object.keys(p[m.attachment]);Ve<Je.length;Ve++)Ge[Je[Ve]]=[];for(var Ye=0,Xe=Object.keys(Re);Ye<Xe.length;Ye++){for(var Ze=Xe[Ye],Qe=!1,et=0,tt=Object.entries(p[m.attachment]);et<tt.length;et++){var rt=tt[et],nt=rt[0],ot=rt[1];if(L(nt,Ze,ot)){Ge[nt].push(Ze),Qe=!0;break}}Qe||l('AttachmentTypeMatch: None of the specified attachment types ("'+Object.keys(p[m.attachment]).join('", "')+'") matches given one ("'+Ze+'")'+a+".")}for(var at=0,ct=0,_t=Object.keys(Ge);ct<_t.length;ct++){var it=_t[ct],st=p[m.attachment][it];if(Object.prototype.hasOwnProperty.call(Ge,it)){var lt=Ge[it].length;null!==st.maximumNumber&&lt>st.maximumNumber&&l("AttachmentMaximum: given number of attachments ("+lt+") doesn't satisfy specified maximum of "+st.maximumNumber+' from type "'+it+'"'+a+"."),(!st.nullable||0!==lt)&&lt<st.minimumNumber&&l("AttachmentMinimum: given number of attachments ("+lt+") doesn't satisfy specified minimum of "+st.minimumNumber+' from type "'+it+'"'+a+".");for(var ut,pt=0,dt=o(Ge[it]);!(ut=dt()).done;){var mt,ft,bt=ut.value;null!=(mt=st.fileName)&&mt.regularExpressionPattern&&!new RegExp(st.fileName.regularExpressionPattern).test(bt)?l('AttachmentName: given attachment name "'+bt+'" doesn\'t satisfy specified regular expression pattern "'+st.fileName.regularExpressionPattern.toString()+'" from type "'+it+'"'+a+"."):null!=(ft=st.fileName)&&ft.invertedRegularExpressionPattern&&new RegExp(st.fileName.invertedRegularExpressionPattern).test(bt)?l('InvertedAttachmentName: given attachment name "'+bt+'" does satisfy specified regular expression pattern "'+st.fileName.invertedRegularExpressionPattern.toString()+'" from type "'+it+'"'+a+"."):!([null,void 0].includes(st.contentTypeRegularExpressionPattern)||Re[bt].content_type&&new RegExp(st.contentTypeRegularExpressionPattern).test(Re[bt].content_type))&&l('AttachmentContentType: given attachment content type "'+Re[bt].content_type+'" doesn\'t satisfy specified regular expression pattern "'+st.contentTypeRegularExpressionPattern+'" from type "'+it+'"'+a+".");var yt=st.invertedContentTypeRegularExpressionPattern;[null,void 0].includes(yt)||Re[bt].content_type&&!new RegExp(yt).test(Re[bt].content_type)||l('InvertedAttachmentContentType: given attachment content type "'+Re[bt].content_type+'" does satisfy specified regular expression pattern "'+yt+'" from type "'+it+'"'+a+".");var ht=0;"length"in Re[bt]?ht=Re[bt].length:"data"in Re[bt]&&(ht=Buffer&&"byteLength"in Buffer?Buffer.byteLength(Re[bt].data,"base64"):Re[bt].data.length),![null,void 0].includes(st.minimumSize)&&st.minimumSize>ht?l("AttachmentMinimumSize: given attachment size "+ht+" byte doesn't satisfy specified minimum of "+st.minimumSize+" byte "+a+"."):![null,void 0].includes(st.maximumSize)&&st.maximumSize<ht&&l("AttachmentMaximumSize: given attachment size "+ht+" byte doesn't satisfy specified maximum of "+st.maximumSize+" byte "+a+"."),pt+=ht}![null,void 0].includes(st.minimumAggregatedSize)&&st.minimumAggregatedSize>pt?l('AttachmentAggregatedMinimumSize: given aggregated size of attachments from type "'+it+'" '+pt+" byte doesn't satisfy specified minimum of "+st.minimumAggregatedSize+" byte "+a+"."):![null,void 0].includes(st.maximumAggregatedSize)&&st.maximumAggregatedSize<pt&&l('AttachmentAggregatedMaximumSize: given aggregated size of attachments from type "'+it+'" '+pt+" byte doesn't satisfy specified maximum of "+st.maximumAggregatedSize+" byte "+a+"."),at+=pt}}Object.prototype.hasOwnProperty.call(p,m.minimumAggregatedSize)&&![null,void 0].includes(p[m.minimumAggregatedSize])&&p[m.minimumAggregatedSize]>at?l("AggregatedMinimumSize: given aggregated size "+at+" byte doesn't satisfy specified minimum of "+p[m.minimumAggregatedSize]+" byte "+a+"."):![null,void 0].includes(p[m.maximumAggregatedSize])&&p[m.maximumAggregatedSize]<at&&l("AggregatedMaximumSize: given aggregated size "+at+" 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===c.length&&r&&"migrate"===g)for(var xt,Ot=0,gt=Object.keys(r);Ot<gt.length;Ot++)xt=gt[Ot],Object.prototype.hasOwnProperty.call(e,xt)||(c=n.concat(xt,"migrate removed property"));return{changedPath:c,newDocument:e}},N={attachmentWithPrefixExists:function(t){if(Object.prototype.hasOwnProperty.call(e,m.attachment)){var r=e[m.attachment],n=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:I,id:h,revision:x,idName:f,revisionName:b,specialNames:m,typeName:y,modelConfiguration:_,models:i,now:u,nowUTCTimestamp:p,securitySettings:c,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: "+I(e)+"; old document: "+I(r)+"."),Object.prototype.hasOwnProperty.call(c,_.property.name.validatedDocumentsCache)?c[_.property.name.validatedDocumentsCache].add(h+"-"+x):c[_.property.name.validatedDocumentsCache]=new Set([h+"-"+x]),S.newDocument},e}(),s=i;e.exports=_}()},,e=>{"use strict";e.exports=require("pouchdb-node")},e=>{"use strict";e.exports=require("pouchdb-find")},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__,{BL:()=>start,sT:()=>stop,ur:()=>restart});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__(11),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__(12),node_fetch__WEBPACK_IMPORTED_MODULE_5___default=__webpack_require__.n(node_fetch__WEBPACK_IMPORTED_MODULE_5__),fs__WEBPACK_IMPORTED_MODULE_6__=__webpack_require__(5),fs__WEBPACK_IMPORTED_MODULE_6___default=__webpack_require__.n(fs__WEBPACK_IMPORTED_MODULE_6__),path__WEBPACK_IMPORTED_MODULE_7__=__webpack_require__(6),path__WEBPACK_IMPORTED_MODULE_7___default=__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_7__),_helper__WEBPACK_IMPORTED_MODULE_8__=__webpack_require__(4),_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 start=function(){var _ref=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function _callee(services,configuration){var server,runner,binary;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(_context){for(;;)switch(_context.prev=_context.next){case 0:if(server=services.couchdb.server,runner=server.runner,binary=configuration.couchdb.binary,!Object.prototype.hasOwnProperty.call(runner,"configurationFile")){_context.next=15;break}return _context.prev=4,_context.next=7,fs__WEBPACK_IMPORTED_MODULE_6__.promises.mkdir((0,path__WEBPACK_IMPORTED_MODULE_7__.dirname)(runner.configurationFile.path),{recursive:!0});case 7:_context.next=13;break;case 9:if(_context.prev=9,_context.t0=_context.catch(4),"EEXIST"===_context.t0.code){_context.next=13;break}throw _context.t0;case 13:return _context.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;null!=(t=services.couchdb)&&null!=(t=t.server)&&t.resolve&&services.couchdb.server.resolve.call(_this,e)}),(function(e){var t;null!=(t=services.couchdb)&&null!=(t=t.server)&&t.resolve&&services.couchdb.server.reject.call(_this,e)})),_context.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 _context.stop()}}),_callee,null,[[4,9]])})));return function(){return _ref.apply(this,arguments)}}(),restart=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,c=a.resolve,_=a.reject,a.resolve=a.reject=clientnode__WEBPACK_IMPORTED_MODULE_4___default().noop,e.next=7,stop(o,r);case 7:return a.resolve=c,a.reject=_,e.next=11,start(o,r);case 11:return(0,_helper__WEBPACK_IMPORTED_MODULE_8__.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)}}(),stop=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)}}()}],__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__(5),fs__WEBPACK_IMPORTED_MODULE_4___default=__webpack_require__.n(fs__WEBPACK_IMPORTED_MODULE_4__),path__WEBPACK_IMPORTED_MODULE_5__=__webpack_require__(6),path__WEBPACK_IMPORTED_MODULE_5___default=__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_5__),pouchdb_node__WEBPACK_IMPORTED_MODULE_6__=__webpack_require__(9),pouchdb_node__WEBPACK_IMPORTED_MODULE_6___default=__webpack_require__.n(pouchdb_node__WEBPACK_IMPORTED_MODULE_6__),pouchdb_find__WEBPACK_IMPORTED_MODULE_7__=__webpack_require__(10),pouchdb_find__WEBPACK_IMPORTED_MODULE_7___default=__webpack_require__.n(pouchdb_find__WEBPACK_IMPORTED_MODULE_7__),_databaseHelper__WEBPACK_IMPORTED_MODULE_10__=__webpack_require__(7),_databaseHelper__WEBPACK_IMPORTED_MODULE_10___default=__webpack_require__.n(_databaseHelper__WEBPACK_IMPORTED_MODULE_10__),_helper__WEBPACK_IMPORTED_MODULE_9__=__webpack_require__(4),_server__WEBPACK_IMPORTED_MODULE_8__=__webpack_require__(14);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,c=r.model.property.name.special.revision,o.connector=pouchdb_node__WEBPACK_IMPORTED_MODULE_6___default(),_=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,x,O,g,v,P,E=arguments;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(o=E.length,i=Array(1<o?o-1:0),s=1;s<o;s++)i[s-1]=E[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,_.call.apply(_,[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(x=h.value,"object"!=typeof p[b]){e.next=33;break}if(!(c in p[b])||"conflict"!==x.name||!["latest","upsert"].includes(p[b][c])){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 x&&"forbidden"===x.name&&"message"in x&&x.message.startsWith("NoChange:"))){e.next=33;break}if(d[b]={id:p[b][a],ok:!0},u){e.next=33;break}if(!(c in p[b])||["latest","upsert"].includes(p[b][c])){e.next=28;break}e.t0=p[b][c],e.next=32;break;case 28:return e.next=30,this.get(d[b].id);case 30:e.t1=c,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(O=e.sent,g=_createForOfIteratorHelperLoose(O);!(v=g()).done;)P=v.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,modelConfiguration,specialNames,idName,typeName,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,_server__WEBPACK_IMPORTED_MODULE_8__.BL)(services,configuration);case 6:couchdb.server.restart=_server__WEBPACK_IMPORTED_MODULE_8__.ur,couchdb.server.start=_server__WEBPACK_IMPORTED_MODULE_8__.BL,couchdb.server.stop=_server__WEBPACK_IMPORTED_MODULE_8__.sT,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_9__.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_9__.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_9__.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_9__.initializeConnection)(services,configuration);case 136:if(!configuration.couchdb.ensureSecuritySettingsPresence){_context3.next=145;break}return _context3.prev=137,_context3.next=140,clientnode__WEBPACK_IMPORTED_MODULE_3__.globalContext.fetch(urlPrefix+"/"+configuration.couchdb.databaseName+"/_security",{body:JSON.stringify(configuration.couchdb.security),method:"PUT"});case 140:_context3.next=145;break;case 142:_context3.prev=142,_context3.t11=_context3.catch(137);case 145:if(modelConfiguration=clientnode__WEBPACK_IMPORTED_MODULE_3___default().copy(configuration.couchdb.model),delete modelConfiguration.property.defaultSpecification,delete modelConfiguration.entities,specialNames=modelConfiguration.property.name.special,idName=specialNames.id,typeName=specialNames.type,models=(0,_helper__WEBPACK_IMPORTED_MODULE_9__.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_9__.determineAllowedModelRolesMapping)(configuration.couchdb.model))+", '"+idName+"', '"+typeName+"', '"+specialNames.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_9__.ensureValidationDocumentPresence)(couchdb.connection,_type2.name,{helper:databaseHelperCode,validate_doc_update:code},_type2.description,!0,idName,specialNames.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],![specialNames.constraint.execution,specialNames.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_10___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_9__.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_10___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_9__.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_9__.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],[137,142],[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 c(){return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(c){for(;;)switch(c.prev=c.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)})))),c.next=5,r.callStack(_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({},e,{data:n.changesStream,hook:"couchdbInitializeChangesStream"}));case 5:case"end":return c.stop()}}),c)}))));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,_server__WEBPACK_IMPORTED_MODULE_8__.sT)(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,t,r)=>{"use strict";r.d(t,{determineAllowedModelRolesMapping:()=>h,determineGenericIndexablePropertyNames:()=>x,ensureValidationDocumentPresence:()=>f,extendModels:()=>g,getConnectorOptions:()=>d,initializeConnection:()=>b,mayStripRepresentation:()=>m});var n=r(0),o=r.n(n),a=r(1),c=r.n(a),i=r(2),_=r.n(i),s=r(3),l=r.n(s);function u(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 p(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)?p(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 p(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){return e.couchdb.connector.fetch?{fetch:function(t,r){return s.globalContext.fetch(t,l().extend(!0,l().copy(e.couchdb.connector.fetch),r||{}))}}:{fetch:function(e,t){return s.globalContext.fetch(e,t)}}},m=function(e,t,r){var n=l().represent(e);return n.length<=t?n.length>r?n.substring(0,r-3)+"...":n:"DOCUMENT IS TOO BIG TO REPRESENT"},f=function(){var e=c()(_().mark((function e(t,r,n,a,c,i,s){var u,p,d;return _().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return void 0===c&&(c=!0),void 0===i&&(i="_id"),void 0===s&&(s="_design/"),p=o()(((u={})[i]=""+s+r,u.language="javascript",u),n),e.prev=4,e.next=7,t.get(""+s+r);case 7:return d=e.sent,p._rev=d._rev,e.next=11,t.put(p);case 11:case 20:e.next=26;break;case 14:return e.prev=14,e.t0=e.catch(4),c&&e.t0.error,e.prev=17,e.next=20,t.put(p);case 23:throw e.prev=23,e.t1=e.catch(17),new Error(a+" couldn't be installed/updated: \""+l().represent(e.t1)+'".');case 26:case"end":return e.stop()}}),e,null,[[4,14],[17,23]])})));return function(){return e.apply(this,arguments)}}(),b=function(){var e=c()(_().mark((function e(t,r){var n,o,a,i,p,m,f,b;return _().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=r.couchdb,o=l().stringFormat(n.url,n.user.name+":"+n.user.password+"@")+"/"+n.databaseName,t.couchdb.connection=new t.couchdb.connector(o,d(r)),(a=t.couchdb.connection).setMaxListeners(1/0),i=n.model.property.name.special.id,p=n.model.property.name.special.revision,m=_().mark((function(){var e,t;return _().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:e=b.value,t=a[e].bind(a),a[e]=c()(_().mark((function e(r,o){var a,c,s;return _().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),!((c=r[i])&&n.ignoreNoChangeError&&"forbidden"===e.t0.name&&null!=(a=e.t0.message)&&a.startsWith("NoChange:"))){e.next=22;break}if(s="object"==typeof o&&p in o?o[p]:r[p],e.t1=c,!(p 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(c);case 18:e.t3=p,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()}}),m)})),f=u(["post","put"]);case 9:if((b=f()).done){e.next=13;break}return e.delegateYield(m(),"t0",11);case 11:e.next=9;break;case 13:return e.prev=13,e.next=16,l().checkReachability(o);case 16:e.next=23;break;case 18:return e.prev=18,e.t1=e.catch(13),e.next=23,s.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)}}(),h=function(e){for(var t=e.property.name.special.allowedRole,r={},n=g(e),a=0,c=Object.entries(n);a<c.length;a++){var i=c[a],_=i[0],s=i[1];if(Object.prototype.hasOwnProperty.call(s,t)){r[_]=o()({properties:{}},v(s[t]));for(var l=0,u=Object.entries(s);l<u.length;l++){var p=u[l],d=p[0],m=p[1];null!==m&&"object"==typeof m&&m.allowedRoles&&(r[_].properties[d]=v(m.allowedRoles))}}else r[_]={properties:{},read:[],write:[]}}return r},y=function(e){return null!==e&&"object"==typeof e},x=function(e,t){var r=e.property.name.special;return Object.keys(t).filter((function(n){var o=t[n];return y(o)&&Object.prototype.hasOwnProperty.call(o,"index")&&o.index||y(o)&&!(Object.prototype.hasOwnProperty.call(o,"index")&&!o.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)||o.type&&("string"==typeof o.type&&o.type.endsWith("[]")||Array.isArray(o.type)&&o.type.length&&Array.isArray(o.type[0])||Object.prototype.hasOwnProperty.call(e.entities,o.type)))})).concat([r.id,r.revision]).sort()},O=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=u([].concat(t[e][r]));!(n=a()).done;)o=n.value,t[e]=l().extend(!0,l().copy(O(o,t,r)),t[e]);delete t[e][r]}return t[e]},g=function(e){for(var t,r=e.property.name.special,n={},o=e.property.name.typeRegularExpressionPattern,a=0,c=Object.keys(e.entities);a<c.length;a++){if(t=c[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]=O(t,e.entities,r.extend)}for(var i,_=0,s=Object.values(n);_<s.length;_++){i=s[_];for(var u=0,p=Object.entries(i);u<p.length;u++){var d=p[u],m=d[0],f=d[1];if(m===r.attachment)for(var b=f,h=0,y=Object.entries(b);h<y.length;h++){var x=y[h],g=x[0],v=x[1];b[g]=l().extend(!0,l().copy(e.property.defaultSpecification),v)}else[r.allowedRole,r.constraint.execution,r.constraint.expression,r.extend,r.maximumAggregatedSize,r.minimumAggregatedSize,r.oldType].includes(m)||(i[m]=l().extend(!0,l().copy(e.property.defaultSpecification),f))}}return n},v=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=>{"use strict";e.exports=require("fs")},e=>{"use strict";e.exports=require("path")},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 c={d:function(e,t){for(var r in t)c.o(t,r)&&!c.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})}},i={};c.r(i),c.d(i,{DatabaseHelper:function(){return _},default:function(){return s}});var _=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===c&&(c="_id"),void 0===i&&(i="-type"),void 0===_&&(_="_design/"),void 0===s&&(s=!1);var u=null!==(l=e[i])&&void 0!==l?l:t&&t[i];if(!u)return!0;var p=s?"read":"write",d={properties:{},read:["_admin","readonlyadmin"],write:["_admin"]};Object.prototype.hasOwnProperty.call(e,c)&&e[c].startsWith(_)&&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],x=o(["read","write"]);!(b=x()).done;)d[h=b.value]=d[h].concat(y[h]||[]);d.properties=y.properties}for(var O,g,v=d[p],P=o(r.roles);!(O=P()).done;)if(g=O.value,v.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===_&&(_={});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=!i.dateTimeFormat.startsWith("iso"),m=i.property.name.special,f=m.id,b=m.revision,h=m.type;r&&r[h]&&!e[h]&&(e[h]=r[h]);var y="",x="",O=function(){y=Object.prototype.hasOwnProperty.call(e,f)?e[f]:"",x=Object.prototype.hasOwnProperty.call(e,b)?e[b]:""};if(O(),Object.prototype.hasOwnProperty.call(c,i.property.name.validatedDocumentsCache)&&c[i.property.name.validatedDocumentsCache].has(y+"-"+x))return c[i.property.name.validatedDocumentsCache].delete(y+"-"+x),e;["latest","upsert"].includes(x)&&(r&&Object.prototype.hasOwnProperty.call(r,b)?x=e[b]=r[b]:"latest"===x?l("Revision: No old document available to update."):delete e[b]);var g=i.updateStrategy;Object.prototype.hasOwnProperty.call(e,m.strategy)&&(g=e[m.strategy],delete e[m.strategy]);var v,P={};if("migrate"===g)for(var E=0,D=Object.entries(_);E<D.length;E++){var M=D[E],w=M[0],k=M[1];if(Object.prototype.hasOwnProperty.call(k,m.oldType)&&![null,void 0].includes(k[m.oldType]))for(var C,A,T=o([].concat(k[m.oldType]));!(C=T()).done;)A=C.value,P[A]=w}s?v=s:JSON&&Object.prototype.hasOwnProperty.call(JSON,"stringify")?v=function(e){return JSON.stringify(e,null,4)}:l('Needed "serializer" is not available.');var j=[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],I=function(e){return e instanceof Error?""+e:v(e)},R=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 c=Object.keys(r);if(c.length)return c[0]}return null},B=function(e,r,o){void 0===r&&(r=!1),void 0===o&&(o={});var a=R(e);if(a){var c,i=(r?"return ":"")+a,_=n({},N,{code:i},o),s=Object.keys(_);try{c=t(Function,s.concat([i]))}catch(c){l(I(c),"compilation",{code:i,error:c,scope:_})}var u={code:i,result:void 0,scope:_};try{u.result=c.apply(void 0,s.map((function(e){return _[e]})))}catch(c){l(I(c),"runtime",{code:i,error:c,scope:_})}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(" -> "):"",c=[],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(i.property.name.typeRegularExpressionPattern.public).test(e[h])||l('TypeName: You have to specify a model type which matches "'+i.property.name.typeRegularExpressionPattern.public+'" as public type (given "'+e[h]+'")'+a+"."),Object.prototype.hasOwnProperty.call(_,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,p=e[h],y=_[p];Object.prototype.hasOwnProperty.call(y,m.additional)&&y[m.additional]&&(u=y[m.additional]);var x=function(c,i,_,s,u){void 0===u&&(u=["constraintExecution","constraintExpression"]);for(var d,m,f=o(u);!(d=f()).done;)if(m=d.value,Object.prototype.hasOwnProperty.call(_,m)){var b=void 0;try{b=B(_[m].evaluation,m.endsWith("Expression"),{checkPropertyContent:v,model:y,modelName:p,name:i,type:m,newDocument:e,newValue:c,oldDocument:r,oldValue:s,parentNames:n,pathDescription:a,propertySpecification:_})}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&l('Compilation: Hook "'+m+'" has invalid code "'+e.code+'": "'+e.message+'"'+a+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&l('Runtime: Hook "'+m+'" has throw an error with code "'+e.code+'": "'+e.message+'"'+a+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}if(b&&!b.result){var h=R(_[m].description);l(m.charAt(0).toUpperCase()+(m.substring(1)+": ")+(h?t(Function,Object.keys(b.scope).concat(["return "+h])).apply(void 0,Object.values(b.scope)):'Property "'+i+'" should satisfy constraint "'+b.code+'" (given "'+I(c)+'")'+a+"."))}}},v=function(e,t,r,c){var i=[],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(_,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(_,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,i=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,c,n.concat(t+""));if(y.changedPath.length&&(i=y.changedPath),e=y.newDocument,I(e)===I({}))return{newValue:null,changedPath:i};m=!0;break}1===s.length&&l('NestedType: Under key "'+t+'" isn\'t of type "'+p+'" (given "'+I(e)+'" of type '+typeof e+")"+a+".")}else if("DateTime"===p){var O=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"'+I(O).replace(/^"/,"").replace(/"$/,"")+'" of type "'+typeof O+'")'+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 "'+p+'" (given "'+I(e)+'" of type "'+typeof e+'")'+a+".")}else if("string"==typeof p&&p.startsWith("foreignKey:")){var v=_[p.substring(11)][f].type;if(v===typeof e){m=!0;break}1===s.length&&l('PropertyType: Foreign key property "'+t+'" isn\'t of type "'+v+'" (given "'+I(e)+'" of type "'+typeof e+'")'+a+".")}else{if("any"===p||I(e)===I(p)){m=!0;break}1===s.length&&l('PropertyType: Property "'+t+'" isn\'t value "'+p+'" (given "'+I(e).replace(/^"/,"").replace(/"$/,"")+'" of type "'+typeof e+'")'+a+".")}if(m||l('PropertyType: None of the specified types "'+s.join('", "')+'" for property "'+t+'" matches value "'+I(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+"."),x(e,t,r,c),I(e)!==I(c)&&(i=n.concat(t+"","value updated")),{newValue:e,changedPath:i}},E=function(e,t,r,o,a){var _=t[o];if(!e.writable)if(r){if(Object.prototype.hasOwnProperty.call(r,o)&&I(_)===I(r[o]))return o!==f&&"incremental"===g&&delete t[o],!0;l('Readonly: Property "'+o+'" is not writable (old document "'+I(r)+'")'+a+".")}else l('Readonly: Property "'+o+'" is not writable'+a+".");if(!e.mutable&&r&&Object.prototype.hasOwnProperty.call(r,o)){if(I(_)===I(r[o]))return"incremental"!==g||i.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 "'+I(r)+'")'+a+".")}if(null===_){if(e.nullable)return delete t[o],r&&Object.prototype.hasOwnProperty.call(r,o)&&(c=n.concat(o+"","delete property")),!0;l('NotNull: Property "'+o+'" should not be "null"'+a+".")}return!1},D=function(e,t,r,c,i){if(!r)for(var _,s,u=o(["onCreateExecution","onCreateExpression"]);!(_=u()).done;)if(s=_.value,Object.prototype.hasOwnProperty.call(e,s)){var d=void 0;try{d=B(e[s],s.endsWith("Expression"),{attachmentsTarget:i,checkPropertyContent:v,model:y,modelName:p,name:c+"",type:s,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 "'+s+'" has invalid code "'+e.code+'" for property "'+c+'": '+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 property "'+c+'": '+e.message+a+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}d&&![null,void 0].includes(d.result)&&(i?i[c]=d.result:t[c]=d.result)}},M=function(e,t,r,c,i){if(!i){if(!Object.prototype.hasOwnProperty.call(t,c))return;e.trim&&"string"==typeof t[c]&&(t[c]=t[c].trim()),e.emptyEqualsToNull&&(""===t[c]||Array.isArray(t[c])&&0===t[c].length||null!==t[c]&&"object"==typeof t[c]&&0===Object.keys(t).length)&&(t[c]=null)}for(var _,s,u=o(["onUpdateExecution","onUpdateExpression"]);!(_=u()).done;)if(s=_.value,Object.prototype.hasOwnProperty.call(e,s))try{var d=B(e[s],s.endsWith("Expression"),{attachmentsTarget:i,checkPropertyContent:v,model:y,modelName:p,name:c+"",type:s,newDocument:t,oldDocument:r,newValue:t[c],oldValue:r&&r[c]||void 0,parentNames:n,pathDescription:a,propertySpecification:e});i?i[c]=d.result:t[c]=d.result}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&l('Compilation: Hook "'+s+'" has invalid code "'+e.code+'" for property "'+c+'": '+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 property "'+c+'": '+e.message+a+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}},w=Object.keys(y).filter((function(e){return!j.includes(e)}));if("migrate"===g)for(var k,C,A=o(w);!(k=A()).done;)if(C=k.value,![null,void 0].includes(y[C].oldName))for(var T,W,N=o([].concat(y[C].oldName));!(T=N()).done;)W=T.value,Object.prototype.hasOwnProperty.call(e,W)&&(e[C]=e[W],delete e[W]);if(!r)for(var S,q=0,$=[m.create.execution,m.create.expression];q<$.length;q++)if(S=$[q],Object.prototype.hasOwnProperty.call(y,S)){var F=void 0;try{F=B(y[S],S.endsWith("Expression"),{checkPropertyContent:v,model:y,modelName:p,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 "'+p+'": '+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 "'+p+'": '+e.message+a+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}[null,void 0].includes(F)||(e=F),s(),p=e[h],0===n.length&&O()}for(var z,H=0,G=[m.update.execution,m.update.expression];H<G.length;H++)if(z=G[H],Object.prototype.hasOwnProperty.call(y,z)){var V=void 0;try{V=B(y[z],z.endsWith("Expression"),{checkPropertyContent:v,model:y,modelName:p,type:z,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 "'+z+'" has invalid code "'+e.code+'" for document "'+p+'": '+e.message+a+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&l('Runtime: Hook "'+z+'" has throw an error with code "'+e.code+'" for document "'+p+'": '+e.message+a+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}[void 0,null].includes(V)||(e=V),s(),p=e[h],0===n.length&&O()}for(var J,Y,X=u?Object.keys(e).filter((function(e){return!w.includes(e)})):[],Z=o(w.concat(X));!(J=Z()).done;)if(Y=J.value,m.attachment===Y)for(var Q=function(){var t=te[ee],i=t[0],_=t[1];Object.prototype.hasOwnProperty.call(e,Y)&&null!==e[m.attachment]||(e[m.attachment]={}),r&&!Object.prototype.hasOwnProperty.call(r,Y)&&(r[m.attachment]={});var s=Object.keys(e[m.attachment]).filter((function(t){return null!==e[m.attachment][t].data&&L(i,t,_)})),u=e[m.attachment],p=[];if(r){var d=r[Y];p=Object.keys(d).filter((function(e){return!(Object.prototype.hasOwnProperty.call(u,e)&&Object.prototype.hasOwnProperty.call(u[e],"data")&&null===u[e].data)&&!!d[e]&&(Object.prototype.hasOwnProperty.call(d[e],"data")&&null!==d[e].data||d[e].stub&&!!d[e].digest)&&!!L(i,e,_)}))}for(var f,b,h=_,y=o(s);!(f=y()).done;)b=f.value,D(h,e,r&&r[Y]?r[Y]:null,b,u);for(var x,O,v=o(s);!(x=v()).done;)O=x.value,M(h,e,r&&r[Y]?r[Y]:null,O,u);if([null,void 0].includes(h.default)){if(h.nullable||0<s.length||0<p.length||l('AttachmentMissing: Missing attachment for type "'+i+'"'+a+"."),"fillUp"===g&&0===s.length&&0<p.length)for(var P,E,w=o(p);!(P=w()).done;)E=P.value,null===u[E]?c=n.concat(Y,E,"file removed"):u[E]=r[Y][E]}else if(0===s.length)if(0===p.length)for(var k in h.default)Object.prototype.hasOwnProperty.call(h.default,k)&&(u[k]=h.default[k],c=n.concat(Y,i,"add default file"));else if("fillUp"===g)for(var C,A,T=o(p);!(C=T()).done;)A=C.value,u[A]=r[Y][A]},ee=0,te=Object.entries(y[m.attachment]);ee<te.length;ee++)Q();else{var re=w.includes(Y)?y[Y]:u;D(re,e,r,Y),M(re,e,r,Y),[null,void 0].includes(re.default)?(!(re.nullable||Object.prototype.hasOwnProperty.call(e,Y)||r&&Object.prototype.hasOwnProperty.call(r,Y)&&g)&&l('MissingProperty: Missing property "'+Y+'"'+a+"."),!Object.prototype.hasOwnProperty.call(e,Y)&&r&&Object.prototype.hasOwnProperty.call(r,Y)&&("fillUp"===g?e[Y]=r[Y]:!g&&(c=n.concat(Y+"","property removed")))):(!Object.prototype.hasOwnProperty.call(e,Y)||null===e[Y])&&(r&&Object.prototype.hasOwnProperty.call(r,Y)?"fillUp"===g?e[Y]=r[Y]:"migrate"===g&&(e[Y]=re.default,c=n.concat(Y+"","migrate default value")):(e[Y]=re.default,c=c.concat(Y+"","add default value")))}if(r&&"incremental"===g)for(var ne=0,oe=Object.entries(e);ne<oe.length;ne++){var ae=oe[ne],ce=ae[0],ie=ae[1];Object.prototype.hasOwnProperty.call(r,ce)&&!i.property.name.reserved.concat(f,b,m.conflict,m.deleted,m.deletedConflict,m.localSequence,m.revisions,m.revisionsInformation,h).includes(ce)&&(r[ce]===ie||I(r[ce])===I(ie))&&delete e[ce]}for(var _e=0,se=Object.entries(e);_e<se.length;_e++){var le=se[_e],ue=le[0],pe=le[1];if(!i.property.name.reserved.concat(b,m.conflict,m.deleted,m.deletedConflict,m.localSequence,m.revisions,m.revisionsInformation,m.strategy).includes(ue)){var de=void 0;if(Object.prototype.hasOwnProperty.call(y,ue))de=y[ue];else if(u)de=u;else{if("migrate"===g){delete e[ue],c=n.concat(ue+"","migrate removed property");continue}l('Property: Given property "'+ue+'" isn\'t specified in model "'+p+'"'+a+".")}if(!de)continue;if(m.attachment===ue){var me=pe;for(var fe in me)if(Object.prototype.hasOwnProperty.call(me,fe))for(var be in y[ue])if(L(be,fe,y[m.attachment][be])){E(y[m.attachment][be],e,r,fe,a);break}continue}if(E(de,e,r,ue,a))continue;if("string"==typeof de.type&&de.type.endsWith("[]")||Array.isArray(de.type)&&de.type.length&&Array.isArray(de.type[0])){var he,ye=pe;Array.isArray(ye)?![null,void 0].includes(de.minimumNumber)&&ye.length<de.minimumNumber?l('MinimumArrayLength: Property "'+ue+'" (array of length '+ye.length+") doesn't fullfill minimum array length of "+de.minimumNumber+a+"."):![null,void 0].includes(de.maximumNumber)&&de.maximumNumber<ye.length&&l('MaximumArrayLength: Property "'+ue+'" (array of length '+ye.length+") doesn't fullfill maximum array length of "+de.maximumNumber+a+"."):l('PropertyType: Property "'+ue+'" isn\'t of type "array -> '+de.type+'" (given "'+I(ye)+'")'+a+"."),x(ye,ue+"",de,r&&Object.prototype.hasOwnProperty.call(r,ue)&&r[ue]||void 0,["arrayConstraintExecution","arrayConstraintExpression"]);var xe={};for(var Oe in de)Object.prototype.hasOwnProperty.call(de,Oe)&&(xe[Oe]="type"===Oe?Array.isArray(de[Oe])?de[Oe][0]:[de[Oe].substring(0,de.type.length-2)]:de[Oe]);if(1===(null==(he=xe.type)?void 0:he.length)&&Object.prototype.hasOwnProperty.call(_,xe.type[0]))for(var ge,ve,Pe=o(ye.slice());!(ge=Pe()).done;)"object"!=typeof(ve=ge.value)||Object.getPrototypeOf(ve)!==Object.prototype||Object.prototype.hasOwnProperty.call(ve,h)||(ve[h]=xe.type[0]);for(var Ee,De,Me=0,we=o(ye.slice());!(Ee=we()).done;)De=Ee.value,ye[Me]=v(De,Me+1+". value in "+ue,xe).newValue,null===De&&ye.splice(Me,1),Me+=1;r&&Object.prototype.hasOwnProperty.call(r,ue)&&Array.isArray(r[ue])&&r[ue].length===ye.length&&I(r[ue])===I(ye)||(c=n.concat(ue+"","array updated"))}else{var ke=r&&Object.prototype.hasOwnProperty.call(r,ue)?r[ue]:null,Ce=v(pe,ue+"",de,ke);e[ue]=Ce.newValue,Ce.changedPath.length&&(c=Ce.changedPath),null===e[ue]&&(null!==ke&&(c=n.concat(ue+"","property removed")),delete e[ue])}}}for(var Ae=0,Te=Object.keys(m.constraint);Ae<Te.length;Ae++){var je=Te[Ae],Ie=m.constraint[je];if(Object.prototype.hasOwnProperty.call(y,Ie))for(var Re,Ue=o([].concat(y[Ie]));!(Re=Ue()).done;){var Le=Re.value,We=void 0;try{We=B(Le.evaluation,Ie===m.constraint.expression,{checkPropertyContent:v,model:y,modelName:p,type:Ie,newDocument:e,oldDocument:r,parentNames:n,pathDescription:a})}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&l('Compilation: Hook "'+Ie+'" has invalid code "'+e.code+'": "'+e.message+'"'+a+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&l('Runtime: Hook "'+Ie+'" has thrown an error with code "'+e.code+'": '+e.message+a+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}if(We&&!We.result){var Be=Ie.replace(/^[^a-zA-Z]+/,"");l(Be.charAt(0).toUpperCase()+(Be.substring(1)+": ")+(Le.description?t(Function,Object.keys(We.scope).concat(["return "+Le.description.trim()])).apply(void 0,Object.values(We.scope)):'Model "'+p+'" should satisfy constraint "'+We.code+'" (given "'+I(e)+'")'+a+"."))}}}if(Object.prototype.hasOwnProperty.call(e,m.attachment)){var Ke=e[m.attachment];("object"!=typeof Ke||Object.getPrototypeOf(Ke)!==Object.prototype)&&l("AttachmentType: given attachment has invalid type"+a+".");var Ne=null;if(r&&Object.prototype.hasOwnProperty.call(r,m.attachment)&&null!==(Ne=r[m.attachment])&&"object"==typeof Ne)for(var Se=0,qe=Object.entries(Ne);Se<qe.length;Se++){var $e=qe[Se],Fe=$e[0],ze=$e[1];if(Object.prototype.hasOwnProperty.call(Ke,Fe)){var He=Ke[Fe];null===He||null===He.data||He.content_type===ze.content_type&&(He.data===ze.data||He.digest===ze.digest)?((null===He||null===He.data)&&(c=n.concat(m.attachment,Fe,"attachment removed")),"incremental"===g&&delete Ke[Fe]):c=n.concat(m.attachment,Fe,"attachment updated")}else"fillUp"===g?Ke[Fe]=ze:g||(c=n.concat(m.attachment,Fe,"attachment removed"))}for(var Ge=0,Ve=Object.entries(Ke);Ge<Ve.length;Ge++){var Je=Ve[Ge],Ye=Je[0],Xe=Je[1];[null,void 0].includes(Xe)||null===Xe.data?delete Ke[Ye]:(!Ne||!Object.prototype.hasOwnProperty.call(Ne,Ye)||Xe.content_type!==Ne[Ye].content_type||Xe.data!==Ne[Ye].data&&Xe.digest!==Ne[Ye].digest)&&(c=n.concat(m.attachment,Ye,"attachment updated"))}0===Object.keys(Ke).length&&delete e[m.attachment];for(var Ze={},Qe=0,et=Object.keys(y[m.attachment]);Qe<et.length;Qe++)Ze[et[Qe]]=[];for(var tt=0,rt=Object.keys(Ke);tt<rt.length;tt++){for(var nt=rt[tt],ot=!1,at=0,ct=Object.entries(y[m.attachment]);at<ct.length;at++){var it=ct[at],_t=it[0],st=it[1];if(L(_t,nt,st)){Ze[_t].push(nt),ot=!0;break}}ot||l('AttachmentTypeMatch: None of the specified attachment types ("'+Object.keys(y[m.attachment]).join('", "')+'") matches given one ("'+nt+'")'+a+".")}for(var lt=0,ut=0,pt=Object.keys(Ze);ut<pt.length;ut++){var dt=pt[ut],mt=y[m.attachment][dt];if(Object.prototype.hasOwnProperty.call(Ze,dt)){var ft=Ze[dt].length;null!==mt.maximumNumber&&ft>mt.maximumNumber&&l("AttachmentMaximum: given number of attachments ("+ft+") doesn't satisfy specified maximum of "+mt.maximumNumber+' from type "'+dt+'"'+a+"."),(!mt.nullable||0!==ft)&&ft<mt.minimumNumber&&l("AttachmentMinimum: given number of attachments ("+ft+") doesn't satisfy specified minimum of "+mt.minimumNumber+' from type "'+dt+'"'+a+".");for(var bt,ht=0,yt=o(Ze[dt]);!(bt=yt()).done;){var xt,Ot,gt=bt.value;null!=(xt=mt.fileName)&&xt.regularExpressionPattern&&!new RegExp(mt.fileName.regularExpressionPattern).test(gt)?l('AttachmentName: given attachment name "'+gt+'" doesn\'t satisfy specified regular expression pattern "'+mt.fileName.regularExpressionPattern.toString()+'" from type "'+dt+'"'+a+"."):null!=(Ot=mt.fileName)&&Ot.invertedRegularExpressionPattern&&new RegExp(mt.fileName.invertedRegularExpressionPattern).test(gt)?l('InvertedAttachmentName: given attachment name "'+gt+'" does satisfy specified regular expression pattern "'+mt.fileName.invertedRegularExpressionPattern.toString()+'" from type "'+dt+'"'+a+"."):!([null,void 0].includes(mt.contentTypeRegularExpressionPattern)||Ke[gt].content_type&&new RegExp(mt.contentTypeRegularExpressionPattern).test(Ke[gt].content_type))&&l('AttachmentContentType: given attachment content type "'+Ke[gt].content_type+'" doesn\'t satisfy specified regular expression pattern "'+mt.contentTypeRegularExpressionPattern+'" from type "'+dt+'"'+a+".");var vt=mt.invertedContentTypeRegularExpressionPattern;[null,void 0].includes(vt)||Ke[gt].content_type&&!new RegExp(vt).test(Ke[gt].content_type)||l('InvertedAttachmentContentType: given attachment content type "'+Ke[gt].content_type+'" does satisfy specified regular expression pattern "'+vt+'" from type "'+dt+'"'+a+".");var Pt=0;"length"in Ke[gt]?Pt=Ke[gt].length:"data"in Ke[gt]&&(Pt=Buffer&&"byteLength"in Buffer?Buffer.byteLength(Ke[gt].data,"base64"):Ke[gt].data.length),![null,void 0].includes(mt.minimumSize)&&mt.minimumSize>Pt?l("AttachmentMinimumSize: given attachment size "+Pt+" byte doesn't satisfy specified minimum of "+mt.minimumSize+" byte "+a+"."):![null,void 0].includes(mt.maximumSize)&&mt.maximumSize<Pt&&l("AttachmentMaximumSize: given attachment size "+Pt+" byte doesn't satisfy specified maximum of "+mt.maximumSize+" byte "+a+"."),ht+=Pt}![null,void 0].includes(mt.minimumAggregatedSize)&&mt.minimumAggregatedSize>ht?l('AttachmentAggregatedMinimumSize: given aggregated size of attachments from type "'+dt+'" '+ht+" byte doesn't satisfy specified minimum of "+mt.minimumAggregatedSize+" byte "+a+"."):![null,void 0].includes(mt.maximumAggregatedSize)&&mt.maximumAggregatedSize<ht&&l('AttachmentAggregatedMaximumSize: given aggregated size of attachments from type "'+dt+'" '+ht+" byte doesn't satisfy specified maximum of "+mt.maximumAggregatedSize+" byte "+a+"."),lt+=ht}}Object.prototype.hasOwnProperty.call(y,m.minimumAggregatedSize)&&![null,void 0].includes(y[m.minimumAggregatedSize])&&y[m.minimumAggregatedSize]>lt?l("AggregatedMinimumSize: given aggregated size "+lt+" byte doesn't satisfy specified minimum of "+y[m.minimumAggregatedSize]+" byte "+a+"."):![null,void 0].includes(y[m.maximumAggregatedSize])&&y[m.maximumAggregatedSize]<lt&&l("AggregatedMaximumSize: given aggregated size "+lt+" byte doesn't satisfy specified maximum of "+y[m.maximumAggregatedSize]+" byte "+a+".")}if(r&&Object.prototype.hasOwnProperty.call(r,m.attachment)&&0===Object.keys(r[m.attachment]).length&&delete r[m.attachment],0===c.length&&r&&"migrate"===g)for(var Et,Dt=0,Mt=Object.keys(r);Dt<Mt.length;Dt++)Et=Mt[Dt],Object.prototype.hasOwnProperty.call(e,Et)||(c=n.concat(Et,"migrate removed property"));return{changedPath:c,newDocument:e}},N={attachmentWithPrefixExists:function(t){if(Object.prototype.hasOwnProperty.call(e,m.attachment)){var r=e[m.attachment],n=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:I,id:y,revision:x,idName:f,revisionName:b,specialNames:m,typeName:h,modelConfiguration:i,models:_,now:u,nowUTCTimestamp:p,securitySettings:c,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: "+I(e)+"; old document: "+I(r)+"."),Object.prototype.hasOwnProperty.call(c,i.property.name.validatedDocumentsCache)?c[i.property.name.validatedDocumentsCache].add(y+"-"+x):c[i.property.name.validatedDocumentsCache]=new Set([y+"-"+x]),S.newDocument},e}(),s=_;e.exports=i}()},,e=>{"use strict";e.exports=require("pouchdb-node")},e=>{"use strict";e.exports=require("pouchdb-find")},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__,{BL:()=>start,sT:()=>stop,ur:()=>restart});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__(11),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__(12),node_fetch__WEBPACK_IMPORTED_MODULE_5___default=__webpack_require__.n(node_fetch__WEBPACK_IMPORTED_MODULE_5__),fs__WEBPACK_IMPORTED_MODULE_6__=__webpack_require__(5),fs__WEBPACK_IMPORTED_MODULE_6___default=__webpack_require__.n(fs__WEBPACK_IMPORTED_MODULE_6__),path__WEBPACK_IMPORTED_MODULE_7__=__webpack_require__(6),path__WEBPACK_IMPORTED_MODULE_7___default=__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_7__),_helper__WEBPACK_IMPORTED_MODULE_8__=__webpack_require__(4),_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 start=function(){var _ref=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function _callee(services,configuration){var server,runner,binary;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(_context){for(;;)switch(_context.prev=_context.next){case 0:if(server=services.couchdb.server,runner=server.runner,binary=configuration.couchdb.binary,!Object.prototype.hasOwnProperty.call(runner,"configurationFile")){_context.next=15;break}return _context.prev=4,_context.next=7,fs__WEBPACK_IMPORTED_MODULE_6__.promises.mkdir((0,path__WEBPACK_IMPORTED_MODULE_7__.dirname)(runner.configurationFile.path),{recursive:!0});case 7:_context.next=13;break;case 9:if(_context.prev=9,_context.t0=_context.catch(4),"EEXIST"===_context.t0.code){_context.next=13;break}throw _context.t0;case 13:return _context.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;null!=(t=services.couchdb)&&null!=(t=t.server)&&t.resolve&&services.couchdb.server.resolve.call(_this,e)}),(function(e){var t;null!=(t=services.couchdb)&&null!=(t=t.server)&&t.resolve&&services.couchdb.server.reject.call(_this,e)})),_context.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 _context.stop()}}),_callee,null,[[4,9]])})));return function(){return _ref.apply(this,arguments)}}(),restart=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;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,c=a.resolve,i=a.reject,a.resolve=a.reject=clientnode__WEBPACK_IMPORTED_MODULE_4___default().noop,e.next=7,stop(o,r);case 7:return a.resolve=c,a.reject=i,e.next=11,start(o,r);case 11:return(0,_helper__WEBPACK_IMPORTED_MODULE_8__.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)}}(),stop=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)}}()}],__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__(5),fs__WEBPACK_IMPORTED_MODULE_4___default=__webpack_require__.n(fs__WEBPACK_IMPORTED_MODULE_4__),path__WEBPACK_IMPORTED_MODULE_5__=__webpack_require__(6),path__WEBPACK_IMPORTED_MODULE_5___default=__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_5__),pouchdb_node__WEBPACK_IMPORTED_MODULE_6__=__webpack_require__(9),pouchdb_node__WEBPACK_IMPORTED_MODULE_6___default=__webpack_require__.n(pouchdb_node__WEBPACK_IMPORTED_MODULE_6__),pouchdb_find__WEBPACK_IMPORTED_MODULE_7__=__webpack_require__(10),pouchdb_find__WEBPACK_IMPORTED_MODULE_7___default=__webpack_require__.n(pouchdb_find__WEBPACK_IMPORTED_MODULE_7__),_databaseHelper__WEBPACK_IMPORTED_MODULE_10__=__webpack_require__(7),_databaseHelper__WEBPACK_IMPORTED_MODULE_10___default=__webpack_require__.n(_databaseHelper__WEBPACK_IMPORTED_MODULE_10__),_helper__WEBPACK_IMPORTED_MODULE_9__=__webpack_require__(4),_server__WEBPACK_IMPORTED_MODULE_8__=__webpack_require__(14);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,c=r.model.property.name.special.revision,o.connector=pouchdb_node__WEBPACK_IMPORTED_MODULE_6___default(),i=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,_,s,l,u,p,d,m,f,b,h,y,x,O,g,v,P,E=arguments;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(o=E.length,_=Array(1<o?o-1:0),s=1;s<o;s++)_[s-1]=E[s];return l=0<_.length&&_[_.length-1]===Database.toggleIDDetermining,u=l?!r.skipIDDetermining:r.skipIDDetermining,l&&_.pop(),p=!Array.isArray(t)&&null!==t&&"object"==typeof t&&a in t?[t]:t,null!=(n=r.connector.fetch)&&n.timeout&&(0===_.length||"object"!=typeof _[0])&&_.unshift({timeout:r.connector.fetch.timeout}),e.next=8,i.call.apply(i,[this,p].concat(_));case 8:d=e.sent,m=[],f=[],b=0,h=_createForOfIteratorHelperLoose(d);case 13:if((y=h()).done){e.next=36;break}if(x=y.value,"object"!=typeof p[b]){e.next=33;break}if(!(c in p[b])||"conflict"!==x.name||!["latest","upsert"].includes(p[b][c])){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 x&&"forbidden"===x.name&&"message"in x&&x.message.startsWith("NoChange:"))){e.next=33;break}if(d[b]={id:p[b][a],ok:!0},u){e.next=33;break}if(!(c in p[b])||["latest","upsert"].includes(p[b][c])){e.next=28;break}e.t0=p[b][c],e.next=32;break;case 28:return e.next=30,this.get(d[b].id);case 30:e.t1=c,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&&_.push(Database.toggleIDDetermining),e.next=41,this.bulkDocs.apply(this,[p].concat(_));case 41:for(O=e.sent,g=_createForOfIteratorHelperLoose(O);!(v=g()).done;)P=v.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={},_=[],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),_.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: "'+_.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,modelConfiguration,specialNames,idName,typeName,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,_iterator10,_step10,_type,_constraint,migrators,_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,_server__WEBPACK_IMPORTED_MODULE_8__.BL)(services,configuration);case 6:couchdb.server.restart=_server__WEBPACK_IMPORTED_MODULE_8__.ur,couchdb.server.start=_server__WEBPACK_IMPORTED_MODULE_8__.BL,couchdb.server.stop=_server__WEBPACK_IMPORTED_MODULE_8__.sT,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_9__.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_9__.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_9__.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_9__.initializeConnection)(services,configuration);case 136:if(!configuration.couchdb.ensureSecuritySettingsPresence){_context3.next=145;break}return _context3.prev=137,_context3.next=140,clientnode__WEBPACK_IMPORTED_MODULE_3__.globalContext.fetch(urlPrefix+"/"+configuration.couchdb.databaseName+"/_security",{body:JSON.stringify(configuration.couchdb.security),method:"PUT"});case 140:_context3.next=145;break;case 142:_context3.prev=142,_context3.t11=_context3.catch(137);case 145:if(modelConfiguration=clientnode__WEBPACK_IMPORTED_MODULE_3___default().copy(configuration.couchdb.model),delete modelConfiguration.property.defaultSpecification,delete modelConfiguration.entities,specialNames=modelConfiguration.property.name.special,idName=specialNames.id,typeName=specialNames.type,models=(0,_helper__WEBPACK_IMPORTED_MODULE_9__.extendModels)(configuration.couchdb.model),!configuration.couchdb.model.updateValidation){_context3.next=214;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_9__.determineAllowedModelRolesMapping)(configuration.couchdb.model))+", '"+idName+"', '"+typeName+"', '"+specialNames.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_9__.ensureValidationDocumentPresence)(couchdb.connection,_type2.name,{helper:databaseHelperCode,validate_doc_update:code},_type2.description,!0,idName,specialNames.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=214;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=211;break}if(_Object$entries2$_i=_Object$entries2[_i3],_name=_Object$entries2$_i[0],specification=_Object$entries2$_i[1],![specialNames.constraint.execution,specialNames.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=208;break;case 193:_iterator10=_createForOfIteratorHelperLoose(["conflictingConstraintExpression","conflictingConstraintExecution","constraintExpression","constraintExecution"]);case 194:if((_step10=_iterator10()).done){_context3.next=208;break}if(_type=_step10.value,null===specification||"object"!=typeof specification){_context3.next=206;break}if(_constraint=specification[_type],null==_constraint||!_constraint.description){_context3.next=206;break}_context3.prev=199,new Function(_constraint.description),_context3.next=206;break;case 203:throw _context3.prev=203,_context3.t14=_context3.catch(199),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 206:_context3.next=194;break;case 208:_i3++,_context3.next=175;break;case 211:_i2++,_context3.next=172;break;case 214:if(!configuration.couchdb.model.autoMigrationPath){_context3.next=313;break}return migrators={},_context3.next=218,clientnode__WEBPACK_IMPORTED_MODULE_3___default().isDirectory((0,path__WEBPACK_IMPORTED_MODULE_5__.resolve)(configuration.couchdb.model.autoMigrationPath));case 218:if(!_context3.sent){_context3.next=265;break}return _context3.t15=_createForOfIteratorHelperLoose,_context3.next=222,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 222:_context3.t16=_context3.sent,_iterator11=(0,_context3.t15)(_context3.t16);case 224:if((_step11=_iterator11()).done){_context3.next=265;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=255;break}return document=void 0,_context3.prev=230,_context3.t17=JSON,_context3.next=234,fs__WEBPACK_IMPORTED_MODULE_4__.promises.readFile(file.path,{encoding:configuration.core.encoding,flag:"r"});case 234:_context3.t18=_context3.sent,document=_context3.t17.parse.call(_context3.t17,_context3.t18),_context3.next=241;break;case 238:throw _context3.prev=238,_context3.t19=_context3.catch(230),new Error('Parsing document "'+file.path+'" to include by automigration of has failed: '+clientnode__WEBPACK_IMPORTED_MODULE_3___default().represent(_context3.t19));case 241:return document[idName]=_name2,document[configuration.couchdb.model.property.name.special.revision]="upsert",_context3.prev=243,_context3.next=246,couchdb.connection.put(document);case 246:_context3.next=252;break;case 248:throw _context3.prev=248,_context3.t20=_context3.catch(243),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 252:_context3.next=263;break;case 255:if(![".js"].includes((0,path__WEBPACK_IMPORTED_MODULE_5__.extname)(file.name))){_context3.next=259;break}migrators[file.path]=eval("require('"+file.path+"')").default,_context3.next=263;break;case 259:if(![".mjs"].includes((0,path__WEBPACK_IMPORTED_MODULE_5__.extname)(file.name))){_context3.next=263;break}return _context3.next=262,eval("import('"+file.path+"')");case 262:migrators[file.path]=_context3.sent.default;case 263:_context3.next=224;break;case 265:return _context3.t21=_createForOfIteratorHelperLoose,_context3.next=268,couchdb.connection.allDocs({include_docs:!0});case 268:_context3.t22=_context3.sent.rows,_iterator12=(0,_context3.t21)(_context3.t22);case 270:if((_step12=_iterator12()).done){_context3.next=313;break}if(retrievedDocument=_step12.value,"string"==typeof retrievedDocument.id&&retrievedDocument.id.startsWith(configuration.couchdb.model.property.name.special.designDocumentNamePrefix)){_context3.next=311;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(migrators).sort());case 277:if((_step13=_iterator13()).done){_context3.next=290;break}_name3=_step13.value,result=null,_context3.prev=280,result=migrators[_name3](newDocument,{configuration,databaseHelper:_databaseHelper__WEBPACK_IMPORTED_MODULE_10___default(),Tools:clientnode__WEBPACK_IMPORTED_MODULE_3___default(),idName,typeName,migrators,models,modelConfiguration,selfFilePath:_name3,services}),_context3.next=287;break;case 284:throw _context3.prev=284,_context3.t23=_context3.catch(280),new Error('Running migrater "'+_name3+'" in document '+(0,_helper__WEBPACK_IMPORTED_MODULE_9__.mayStripRepresentation)(_document,configuration.couchdb.maximumRepresentationTryLength,configuration.couchdb.maximumRepresentationLength)+'" failed: '+clientnode__WEBPACK_IMPORTED_MODULE_3___default().represent(_context3.t23));case 287:result&&(newDocument=result);case 288:_context3.next=277;break;case 290:_context3.prev=290,_databaseHelper__WEBPACK_IMPORTED_MODULE_10___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=302;break;case 294:if(_context3.prev=294,_context3.t24=_context3.catch(290),!Object.prototype.hasOwnProperty.call(_context3.t24,"forbidden")){_context3.next=301;break}return _context3.t24.forbidden.startsWith("NoChange:"),_context3.abrupt("continue",311);case 301:throw _context3.t24;case 302:return _context3.prev=302,_context3.next=305,couchdb.connection.put(newDocument);case 305:_context3.next=310;break;case 307:throw _context3.prev=307,_context3.t25=_context3.catch(302),new Error('Replacing auto migrated document "'+newDocument[idName]+'" has failed: '+clientnode__WEBPACK_IMPORTED_MODULE_3___default().represent(_context3.t25));case 310:case 311:_context3.next=270;break;case 313:if(!configuration.couchdb.createGenericFlatIndex||!configuration.couchdb.model.autoMigrationPath){_context3.next=368;break}return _context3.next=316,couchdb.connection.getIndexes();case 316:indexes=_context3.sent.indexes,_i4=0,_Object$entries3=Object.entries(models);case 318:if(!(_i4<_Object$entries3.length)){_context3.next=349;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=346;break}return _context3.next=323,couchdb.connection.createIndex({index:{ddoc:_modelName+"-GenericIndex",fields:[typeName],name:_modelName+"-GenericIndex"}});case 323:_iterator14=_createForOfIteratorHelperLoose((0,_helper__WEBPACK_IMPORTED_MODULE_9__.determineGenericIndexablePropertyNames)(configuration.couchdb.model,_model));case 324:if((_step14=_iterator14()).done){_context3.next=346;break}propertyName=_step14.value,_name4=_modelName+"-"+propertyName+"-GenericIndex",foundPosition=-1,position=0,_iterator15=_createForOfIteratorHelperLoose(indexes);case 330:if((_step15=_iterator15()).done){_context3.next=338;break}if(index=_step15.value,index.name!==_name4){_context3.next=335;break}return foundPosition=position,_context3.abrupt("break",338);case 335:position+=1;case 336:_context3.next=330;break;case 338:if(-1!==foundPosition){_context3.next=343;break}return _context3.next=341,couchdb.connection.createIndex({index:{ddoc:_name4,fields:[typeName,propertyName],name:_name4}});case 341:_context3.next=344;break;case 343:indexes.slice(position,1);case 344:_context3.next=324;break;case 346:_i4++,_context3.next=318;break;case 349:_iterator16=_createForOfIteratorHelperLoose(indexes);case 350:if((_step16=_iterator16()).done){_context3.next=368;break}if(_index=_step16.value,!_index.name.endsWith("-GenericIndex")){_context3.next=366;break}exists=!1,_i5=0,_Object$entries4=Object.entries(models);case 355:if(!(_i5<_Object$entries4.length)){_context3.next=363;break}if(_Object$entries4$_i=_Object$entries4[_i5],_modelName2=_Object$entries4$_i[0],_model2=_Object$entries4$_i[1],!_index.name.startsWith(_modelName2+"-")){_context3.next=360;break}for(_iterator17=_createForOfIteratorHelperLoose((0,_helper__WEBPACK_IMPORTED_MODULE_9__.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",363);case 360:_i5++,_context3.next=355;break;case 363:if(exists){_context3.next=366;break}return _context3.next=366,couchdb.connection.deleteIndex(_index);case 366:_context3.next=350;break;case 368:if(!configuration.couchdb.model.triggerInitialCompaction){_context3.next=377;break}return _context3.prev=369,_context3.next=372,couchdb.connection.compact();case 372:_context3.next=377;break;case 374:_context3.prev=374,_context3.t26=_context3.catch(369);case 377:return _context3.abrupt("return",{couchdb:promise});case 378: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],[137,142],[159,163],[182,186],[199,203],[230,238],[243,248],[280,284],[290,294],[302,307],[369,374]])})));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 c(){return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(c){for(;;)switch(c.prev=c.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)})))),c.next=5,r.callStack(_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({},e,{data:n.changesStream,hook:"couchdbInitializeChangesStream"}));case 5:case"end":return c.stop()}}),c)}))));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,_server__WEBPACK_IMPORTED_MODULE_8__.sT)(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.603",
3
+ "version": "1.0.605",
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
@@ -61,7 +61,7 @@ export interface SelectionMapping {
61
61
  label: string;
62
62
  value: unknown;
63
63
  }
64
- export interface PropertySpecification<Type = unknown, AdditionalSpecifications extends object = Mapping<unknown>> {
64
+ export interface PropertySpecification<Type = unknown, AdditionalSpecifications extends object = object> {
65
65
  allowedRoles?: AllowedRoles | null;
66
66
  computed?: boolean;
67
67
  arrayConstraintExecution?: Constraint | null;
@@ -93,7 +93,7 @@ export interface PropertySpecification<Type = unknown, AdditionalSpecifications
93
93
  writable?: boolean | null;
94
94
  selection?: Array<unknown> | Array<SelectionMapping> | Mapping<unknown> | null;
95
95
  type?: TypeSpecification | null;
96
- default?: unknown;
96
+ default?: null | Type;
97
97
  emptyEqualsToNull?: boolean | null;
98
98
  trim?: boolean | null;
99
99
  name?: string;
@@ -104,12 +104,13 @@ export interface PropertySpecification<Type = unknown, AdditionalSpecifications
104
104
  value?: null | Type;
105
105
  additionalSpecifications?: AdditionalSpecifications;
106
106
  }
107
- export interface FileSpecification<Type = Attachment, AdditionalSpecifications extends object = Mapping<unknown>> extends PropertySpecification<Type, AdditionalSpecifications> {
107
+ export interface FileSpecification<Type extends Attachment = Attachment, AdditionalSpecifications extends object = object> extends PropertySpecification<Type, AdditionalSpecifications> {
108
108
  fileName?: PropertySpecification<string, AdditionalSpecifications>;
109
109
  }
110
- export interface BaseModel<Type = Attachment, AdditionalSpecifications extends object = Mapping<unknown>> {
110
+ export interface BaseModel<AttachmentType extends Attachment = Attachment, AdditionalSpecifications extends object = object, AdditionalPropertiesType = unknown> {
111
+ _additional?: PropertySpecification<AdditionalPropertiesType, AdditionalSpecifications>;
111
112
  _allowedRoles?: AllowedRoles | null;
112
- _attachments?: (Mapping<FileSpecification<Type, AdditionalSpecifications>> | null);
113
+ _attachments?: (Mapping<FileSpecification<AttachmentType, AdditionalSpecifications>> | null);
113
114
  _constraintExecutions?: Array<Constraint> | Constraint | null;
114
115
  _constraintExpressions?: Array<Constraint> | Constraint | null;
115
116
  _createExecution?: null | string;
@@ -120,9 +121,12 @@ export interface BaseModel<Type = Attachment, AdditionalSpecifications extends o
120
121
  _oldType?: Array<string> | null | string;
121
122
  _onUpdateExecution?: null | string;
122
123
  _onUpdateExpression?: null | string;
124
+ _id: PropertySpecification<string, AdditionalSpecifications>;
123
125
  }
124
- export type Model<Type = unknown, AdditionalSpecifications extends object = Mapping<unknown>> = BaseModel & Mapping<PropertySpecification<Type, AdditionalSpecifications>>;
125
- export type Models<Type = unknown, AdditionalSpecifications extends object = Mapping<unknown>> = Mapping<Model<Type, AdditionalSpecifications>>;
126
+ export type Model<Type extends object = Mapping<unknown>, AttachmentType extends Attachment = Attachment, AdditionalSpecifications extends object = object, AdditionalPropertiesType = unknown> = BaseModel<AttachmentType, AdditionalSpecifications, AdditionalPropertiesType> & {
127
+ [Property in keyof Type]: PropertySpecification<Type[Property], AdditionalSpecifications>;
128
+ };
129
+ export type Models<Type extends object = Mapping<unknown>, AttachmentType extends Attachment = Attachment, AdditionalSpecifications extends object = object, AdditionalPropertiesType = unknown> = Mapping<Model<Type, AttachmentType, AdditionalSpecifications, AdditionalPropertiesType>>;
126
130
  export type UpdateStrategy = '' | 'fillUp' | 'incremental' | 'migrate';
127
131
  export type DocumentContent = Array<DocumentContent> | PlainObject | Primitive;
128
132
  export type DocumentStrategyMeta = {
@@ -132,8 +136,8 @@ export type DocumentTypeMeta = {
132
136
  '-type': string;
133
137
  };
134
138
  export type BaseDocument = ChangesMeta & DocumentGetMeta & DocumentIDMeta & DocumentRevisionIDMeta & DocumentStrategyMeta & DocumentTypeMeta;
135
- export type FullDocument<Type extends object = Mapping<unknown>> = BaseDocument & Document<Type>;
136
- export type PartialFullDocument<Type extends object = Mapping<unknown>> = Partial<BaseDocument> & Partial<Document<Type>>;
139
+ export type FullDocument<Type extends object = object, AdditionalPropertyTypes = unknown> = BaseDocument & Document<Type> & Mapping<AdditionalPropertyTypes>;
140
+ export type PartialFullDocument<Type extends object = object, AdditionalPropertyTypes = unknown> = Partial<BaseDocument> & Partial<Document<Type>> & Mapping<AdditionalPropertyTypes>;
137
141
  export interface SpecialPropertyNames {
138
142
  additional: '_additional';
139
143
  allowedRole: '_allowedRoles';
@@ -175,7 +179,7 @@ export interface PropertyNameConfiguration {
175
179
  };
176
180
  validatedDocumentsCache: string;
177
181
  }
178
- export interface BaseModelConfiguration<Type = unknown, AdditionalSpecifications extends object = Mapping<unknown>> {
182
+ export interface BaseModelConfiguration<Type, AdditionalSpecifications extends object> {
179
183
  dateTimeFormat: 'iso' | 'iso8601' | 'number';
180
184
  property: {
181
185
  defaultSpecification: PropertySpecification<Type, AdditionalSpecifications>;
@@ -183,9 +187,9 @@ export interface BaseModelConfiguration<Type = unknown, AdditionalSpecifications
183
187
  };
184
188
  updateStrategy: UpdateStrategy;
185
189
  }
186
- export interface ModelConfiguration<Type = unknown, AdditionalSpecifications extends object = Mapping<unknown>> extends BaseModelConfiguration<Type, AdditionalSpecifications> {
190
+ export interface ModelConfiguration<Type extends object = object, AttachmentType extends Attachment = Attachment, AdditionalSpecifications extends object = object, AdditionalPropertiesType = unknown> extends BaseModelConfiguration<Type, AdditionalSpecifications> {
187
191
  autoMigrationPath: string;
188
- entities: Models<Type, AdditionalSpecifications>;
192
+ entities: Models<Type, AttachmentType, AdditionalSpecifications, AdditionalPropertiesType>;
189
193
  triggerInitialCompaction: boolean;
190
194
  updateConfiguration: boolean;
191
195
  updateValidation: boolean;
@@ -222,7 +226,7 @@ export type AdvancedFetchOptions = RequestInit & {
222
226
  export type ConnectorConfiguration = DatabaseConnectorConfiguration & {
223
227
  fetch?: AdvancedFetchOptions | null;
224
228
  };
225
- export interface CoreConfiguration<Type = unknown, AdditionalSpecifications extends object = Mapping<unknown>> {
229
+ export interface CoreConfiguration<Type extends object = Mapping<unknown>, AttachmentType extends Attachment = Attachment, AdditionalSpecifications extends object = object, AdditionalPropertiesType = unknown> {
226
230
  attachAutoRestarter: boolean;
227
231
  backend: {
228
232
  configuration: PlainObject;
@@ -245,7 +249,7 @@ export interface CoreConfiguration<Type = unknown, AdditionalSpecifications exte
245
249
  local: boolean;
246
250
  maximumRepresentationLength: number;
247
251
  maximumRepresentationTryLength: number;
248
- model: ModelConfiguration<Type, AdditionalSpecifications>;
252
+ model: ModelConfiguration<Type, AttachmentType, AdditionalSpecifications, AdditionalPropertiesType>;
249
253
  path: string;
250
254
  security: SecuritySettings;
251
255
  skipIDDetermining: boolean;
@@ -311,10 +315,10 @@ export interface CompilationErrorData<S = Mapping<unknown>> extends EvaluationEr
311
315
  export interface RuntimeErrorData<S = Mapping<unknown>> extends EvaluationErrorData<S> {
312
316
  runtime: string;
313
317
  }
314
- export interface BasicScope<Type = unknown, AdditionalSpecifications extends object = Mapping<unknown>> {
318
+ export interface BasicScope<Type extends object, AttachmentType extends Attachment, AdditionalSpecifications extends object, AdditionalPropertiesType> {
315
319
  attachmentWithPrefixExists: (namePrefix: string) => boolean;
316
- checkDocument: (newDocument: PartialFullDocument, oldDocument: PartialFullDocument | null, parentNames: Array<string>) => CheckedDocumentResult;
317
- getFileNameByPrefix: (prefix?: string, attachments?: Attachments) => null | string;
320
+ checkDocument: (newDocument: PartialFullDocument<Type, AdditionalPropertiesType>, oldDocument: PartialFullDocument<Type, AdditionalPropertiesType> | null, parentNames: Array<string>) => CheckedDocumentResult<Type, AdditionalPropertiesType>;
321
+ getFileNameByPrefix: (prefix?: string, attachments?: Mapping<AttachmentType>) => null | string;
318
322
  serialize: (value: unknown) => string;
319
323
  id: string;
320
324
  revision: string;
@@ -323,52 +327,53 @@ export interface BasicScope<Type = unknown, AdditionalSpecifications extends obj
323
327
  specialNames: SpecialPropertyNames;
324
328
  typeName: string;
325
329
  modelConfiguration: BaseModelConfiguration<Type, AdditionalSpecifications>;
326
- models: Models<Type, AdditionalSpecifications>;
330
+ models: Models<Type, AttachmentType, AdditionalSpecifications, AdditionalPropertiesType>;
327
331
  now: Date;
328
332
  nowUTCTimestamp: number;
329
333
  securitySettings: Partial<SecuritySettings>;
330
334
  userContext: Partial<UserContext>;
331
335
  }
332
- export interface CommonScope<Type, AdditionalSpecifications extends object = Mapping<unknown>> {
333
- checkPropertyContent: (newValue: unknown, name: string, propertySpecification: PropertySpecification<Type, AdditionalSpecifications>, oldValue: unknown) => CheckedPropertyResult;
334
- model: Model<Type, AdditionalSpecifications>;
336
+ export interface CommonScope<ObjectType extends object, Type, AttachmentType extends Attachment, AdditionalSpecifications extends object, AdditionalPropertiesType> {
337
+ checkPropertyContent: (newValue: Type, name: string, propertySpecification: PropertySpecification<Type, AdditionalSpecifications>, oldValue: Type) => CheckedPropertyResult<Type>;
338
+ model: Model<ObjectType, AttachmentType, AdditionalSpecifications, AdditionalPropertiesType>;
335
339
  modelName: string;
336
340
  type: Array<string> | string;
337
- newDocument: Attachments | PartialFullDocument;
338
- oldDocument: Attachments | null | PartialFullDocument;
341
+ newDocument: PartialFullDocument<ObjectType, AdditionalPropertiesType>;
342
+ oldDocument: (null | PartialFullDocument<ObjectType, AdditionalPropertiesType>);
339
343
  parentNames: Array<string>;
340
344
  pathDescription: string;
341
345
  }
342
- export interface PropertyScope<Type = unknown, AdditionalSpecifications extends object = Mapping<unknown>> extends CommonScope<Type, AdditionalSpecifications> {
346
+ export interface PropertyScope<ObjectType extends object, Type, PropertyType, AttachmentType extends Attachment, AdditionalSpecifications extends object, AdditionalPropertiesType> extends CommonScope<ObjectType, PropertyType, AttachmentType, AdditionalSpecifications, AdditionalPropertiesType> {
343
347
  name: string;
344
348
  newValue: Type;
345
- oldValue: Type;
349
+ oldValue?: Type;
346
350
  propertySpecification: PropertySpecification<Type, AdditionalSpecifications>;
351
+ attachmentsTarget?: Mapping<AttachmentType>;
347
352
  }
348
- export interface EvaluationResult<T = unknown, S = BasicScope<T> & CommonScope<T>> {
353
+ export interface EvaluationResult<ObjectType extends object, Type, PropertyType, AttachmentType extends Attachment, AdditionalSpecifications extends object, AdditionalPropertiesType, Scope = (BasicScope<ObjectType, AttachmentType, AdditionalSpecifications, AdditionalPropertiesType> & CommonScope<ObjectType, PropertyType, AttachmentType, AdditionalSpecifications, AdditionalPropertiesType>)> {
349
354
  code: string;
350
- result: T;
351
- scope: S;
355
+ result: Type;
356
+ scope: Scope;
352
357
  }
353
- export type Evaluate<R = unknown, P = unknown> = (...parameters: Array<P>) => R;
358
+ export type Evaluate<R, P extends Array<unknown>> = (...parameters: P) => R;
354
359
  export interface CheckedResult {
355
360
  changedPath: Array<string>;
356
361
  }
357
- export interface CheckedPropertyResult extends CheckedResult {
358
- newValue: unknown;
362
+ export interface CheckedPropertyResult<Type> extends CheckedResult {
363
+ newValue: null | Type;
359
364
  }
360
- export interface CheckedDocumentResult extends CheckedResult {
361
- newDocument: PartialFullDocument;
365
+ export interface CheckedDocumentResult<ObjectType extends object, AdditionalPropertiesType> extends CheckedResult {
366
+ newDocument: PartialFullDocument<ObjectType, AdditionalPropertiesType>;
362
367
  }
363
- export type Migrator<Type = unknown, AdditionalSpecifications extends object = Mapping<unknown>> = (document: Document, scope: {
368
+ export type Migrator<Type extends object = object, AttachmentType extends Attachment = Attachment, AdditionalSpecifications extends object = object, AdditionalPropertiesType = unknown> = (document: Document, scope: {
364
369
  configuration: Configuration;
365
370
  databaseHelper: DatabaseHelper;
366
371
  Tools: typeof Tools;
367
372
  idName: string;
368
373
  typeName: string;
369
- migrater: Mapping<Migrator<Type>>;
370
- models: Models<Type, AdditionalSpecifications>;
371
- modelConfiguration: ModelConfiguration<Type, AdditionalSpecifications>;
374
+ migrators: Mapping<Migrator<Type, AttachmentType, AdditionalSpecifications, AdditionalPropertiesType>>;
375
+ models: Models<Type, AttachmentType, AdditionalSpecifications, AdditionalPropertiesType>;
376
+ modelConfiguration: ModelConfiguration<Type, AttachmentType, AdditionalSpecifications, AdditionalPropertiesType>;
372
377
  selfFilePath: string;
373
378
  services: Services;
374
379
  }) => Document | null;