couchdb-web-node-plugin 1.0.642 → 1.0.644

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,4 @@
1
- import { Mapping } from 'clientnode/type';
1
+ import { Mapping } from 'clientnode';
2
2
  import { AllowedModelRolesMapping, Attachment, BaseModelConfiguration, Document, Models, PartialFullDocument, SecuritySettings, UserContext } from './type';
3
3
  /**
4
4
  * WebNode plugin interface with all provided hooks.
@@ -10,21 +10,17 @@ export declare class DatabaseHelper {
10
10
  * @param newDocument - Updated document.
11
11
  * @param oldDocument - If an existing document should be updated its given
12
12
  * here.
13
- *
14
13
  * @param userContext - Contains meta information about currently acting
15
14
  * user.
16
15
  * @param _securitySettings - Database security settings.
17
16
  * @param allowedModelRolesMapping - Allowed roles for given models.
18
- *
19
17
  * @param idPropertyName - Property name indicating the id field name.
20
18
  * @param typePropertyName - Property name indicating to which model a
21
19
  * document belongs to.
22
20
  * @param designDocumentNamePrefix - Document name prefix indicating a
23
21
  * design document.
24
- *
25
22
  * @param read - Indicates whether a read or write of given document should
26
23
  * be authorized or not.
27
- *
28
24
  * @returns Throws an exception if authorisation is not accepted and "true"
29
25
  * otherwise.
30
26
  */
@@ -41,7 +37,6 @@ export declare class DatabaseHelper {
41
37
  * @param modelConfiguration - Model configuration object.
42
38
  * @param models - Models specification object.
43
39
  * @param toJSON - JSON stringifier.
44
- *
45
40
  * @returns Modified given new document.
46
41
  */
47
42
  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>;
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(e,t,r){if(n())return Reflect.construct.apply(null,arguments);var a=[null];a.push.apply(a,t);var i=new(e.bind.apply(e,a));return r&&o(i,r.prototype),i}function n(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(n=function(){return!!e})()}function o(e,t){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},o(e,t)}function a(){return a=Object.assign?Object.assign.bind():function(e){for(var t,r=1;r<arguments.length;r++)for(var n in t=arguments[r])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e},a.apply(this,arguments)}function i(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return l(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?l(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function l(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}e.r(t),e.d(t,{DatabaseHelper:()=>c,default:()=>p});var c=function(){function e(){}return e.authenticate=function(e,t,r,n,o,a,l,c,p){var s;void 0===t&&(t=null),void 0===r&&(r={}),void 0===n&&(n={admins:{names:[],roles:[]},members:{names:[],roles:[]}}),void 0===a&&(a="_id"),void 0===l&&(l="-type"),void 0===c&&(c="_design/"),void 0===p&&(p=!1);var m=null!==(s=e[l])&&void 0!==s?s:t&&t[l];if(!m)return!0;var u=p?"read":"write",y={properties:{},read:["_admin","readonlyadmin"],write:["_admin"]};Object.prototype.hasOwnProperty.call(e,a)&&e[a].startsWith(c)&&y.read.push("readonlymember");var d,f="Current user doesn't own any role";if(r)if("name"in r||(r.name='"unknown"'),null!=(d=r.roles)&&d.length){if(o&&m&&Object.prototype.hasOwnProperty.call(o,m)){for(var h,g,v=o[m],b=i(["read","write"]);!(h=b()).done;)y[g=h.value]=y[g].concat(v[g]||[]);y.properties=v.properties}for(var O,w,j=y[u],P=i(r.roles);!(O=P()).done;)if(w=O.value,j.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 "+u+' action: "'+[].concat(y[u]).join('", "')+'". '+f+"."}},e.validateDocumentUpdate=function(e,t,n,o,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={}),a(((n={})[t]=e,n.message=e,n.name=t,n),r)},m=new Date,u=Date.UTC(m.getUTCFullYear(),m.getUTCMonth(),m.getUTCDate(),m.getUTCHours(),m.getUTCMinutes(),m.getUTCSeconds(),m.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="",b="",O=function(){v=Object.prototype.hasOwnProperty.call(e,f)?e[f]:"",b=Object.prototype.hasOwnProperty.call(e,h)?e[h]:""};if(O(),Object.prototype.hasOwnProperty.call(o,l.property.name.validatedDocumentsCache)&&o[l.property.name.validatedDocumentsCache].has(v+"-"+b))return o[l.property.name.validatedDocumentsCache].delete(v+"-"+b),e;["latest","upsert"].includes(b)&&(t&&Object.prototype.hasOwnProperty.call(t,h)?b=e[h]=t[h]:"latest"===b?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 j,P={};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)&&C[d.oldType])for(var k,T,D=i([].concat(C[d.oldType]));!(k=D()).done;)T=k.value,P[T]=S}p?j=p:JSON&&Object.prototype.hasOwnProperty.call(JSON,"stringify")?j=function(e){return JSON.stringify(e,null,4)}:s('Needed "serializer" is not available.');var z=[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],M=function(e){return e instanceof Error?""+e:j(e)},U=function(e){return"string"==typeof e?e.trim():""},E=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},_=function(e,t,r){if(r.fileName){if(r.fileName.value)return r.fileName.value===t;if(r.fileName.pattern)return[].concat(r.fileName.pattern).some((function(e){return new RegExp(e).test(t)}))}return e===t},R=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 o=U(e);if(o){var i,l=(t?"return ":"")+o,c=a({},I,{code:l},n),p=Object.keys(c);try{i=r(Function,p.concat([l]))}catch(e){s(M(e),"compilation",{code:l,error:e,scope:c})}var m={code:l,result:void 0,scope:c};try{m.result=i.apply(void 0,p.map((function(e){return c[e]})))}catch(e){s(M(e),"runtime",{code:l,error:e,scope:c})}return m}s("No expression to evaluate provided.","empty")},L=function(e,t,n){void 0===n&&(n=[]);var o=n.length?" in "+n.join(" -> "):"",a=[],p=function(){Object.prototype.hasOwnProperty.call(e,g)||(t&&Object.prototype.hasOwnProperty.call(t,g)&&["fillUp","migrate"].includes(w)?e[g]=t[g]:s('Type: You have to specify a model type via property "'+g+'"'+o+".")),n.length||new RegExp(l.property.name.typePattern.public).test(e[g])||s('TypeName: You have to specify a model type which matches "'+l.property.name.typePattern.public+'" as public type (given "'+e[g]+'")'+o+"."),Object.prototype.hasOwnProperty.call(c,e[g])||(Object.prototype.hasOwnProperty.call(P,e[g])?e[g]=P[e[g]]:s('Model: Given model "'+e[g]+'" is not specified'+o+"."))};p();var m=e[g],u=c[m],v=void 0;Object.prototype.hasOwnProperty.call(u,d.additional)&&u[d.additional]&&(v=u[d.additional]);var b=function(a,l,c,p,y){void 0===y&&(y=["constraintExecution","constraintExpression"]);for(var d,f,h=i(y);!(d=h()).done;)if(f=d.value,Object.prototype.hasOwnProperty.call(c,f)){var g=void 0;try{g=H(c[f].evaluation,f.endsWith("Expression"),{checkPropertyContent:j,model:u,modelName:m,name:l,type:f,newDocument:e,newValue:a,oldDocument:t,oldValue:p,parentNames:n,pathDescription:o,propertySpecification:c})}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&s('Compilation: Hook "'+f+'" has invalid code "'+e.code+'": "'+e.message+'"'+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&s('Runtime: Hook "'+f+'" has throw an error with code "'+e.code+'": "'+e.message+'"'+o+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}if(g&&!g.result){var v=U(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 "'+M(a)+'")'+o+"."))}}},j=function(e,t,r,a){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 m,u,d=!1,h=i(p);!(m=h()).done;)if(u=m.value,Object.prototype.hasOwnProperty.call(c,u)){if("object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype&&Object.prototype.hasOwnProperty.call(e,g)&&e[g]!==u&&"migrate"===w&&1===p.length&&(e[g]=u,l=n.concat(t+"","migrate nested object type")),"object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype&&Object.prototype.hasOwnProperty.call(e,g)&&e[g]===u){var v=L(e,a,n.concat(t+""));if(v.changedPath.length&&(l=v.changedPath),e=v.newDocument,M(e)===M({}))return{newValue:void 0,changedPath:l};d=!0;break}1===p.length&&s('NestedType: Under key "'+t+'" isn\'t of type "'+u+'" (given "'+M(e)+'" of type '+typeof e+")"+o+".")}else if("DateTime"===u){var O=e;if(e=E(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"'+M(O).replace(/^"/,"").replace(/"$/,"")+'" of type "'+typeof O+'")'+o+".")}else if(["boolean","integer","number","string"].includes(u)){if(!("number"==typeof e&&isNaN(e)||"integer"!==u&&typeof e!==u||"integer"===u&&parseInt(e,10)!==e)){d=!0;break}1===p.length&&s('PropertyType: Property "'+t+'" isn\'t of (valid) type "'+u+'" (given "'+M(e)+'" of type "'+typeof e+'")'+o+".")}else if("string"==typeof u&&u.startsWith("foreignKey:")){var j=c[u.substring(11)][f].type;if(j===typeof e){d=!0;break}1===p.length&&s('PropertyType: Foreign key property "'+t+'" isn\'t of type "'+j+'" (given "'+M(e)+'" of type "'+typeof e+'")'+o+".")}else{if("any"===u||M(e)===M(u)){d=!0;break}1===p.length&&s('PropertyType: Property "'+t+'" isn\'t value "'+u+'" (given "'+M(e).replace(/^"/,"").replace(/"$/,"")+'" of type "'+typeof e+'")'+o+".")}if(d||s('PropertyType: None of the specified types "'+p.join('", "')+'" for property "'+t+'" matches value "'+M(e).replace(/^"/,"").replace(/"$/,"")+e+'" of type "'+typeof e+'")'+o+"."),"string"==typeof e&&("number"==typeof r.minimumLength&&e.length<r.minimumLength&&s('MinimalLength: Property "'+t+'" must have minimal length '+r.minimumLength+" (given "+e+" with length "+e.length+") "+o+"."),"number"==typeof 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&&("number"==typeof 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+"."),"number"==typeof 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 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(E)),P.includes(e)||s('Selection: Property "'+t+'" (type '+r.type+') should be one of "'+P.join('", "')+'". But is "'+e+'"'+o+".")}if(r.pattern){for(var x,N,A=[].concat(r.pattern),S=!1,C=i(A);!(x=C()).done;)if(N=x.value,new RegExp(N).test(e)){S=!0;break}S||s('PatternMatch: Property "'+t+'" should match one regular expression pattern "'+A.join('", "')+'" (given "'+e+'")'+o+".")}if(r.invertedPattern)for(var k,T,D=i([].concat(r.invertedPattern));!(k=D()).done;)T=k.value,new RegExp(T).test(e)&&s('InvertedPatternMatch: Property "'+t+'" should not match regular expression pattern '+T+' (given "'+e+'")'+o+".");return b(e,t,r,a),M(e)!==M(a)&&(l=n.concat(t+"","value updated")),{newValue:e,changedPath:l}},x=function(e,t,r,o,i){var c=t[o];if(!e.writable)if(r){if(Object.prototype.hasOwnProperty.call(r,o)&&M(c)===M(r[o]))return o!==f&&"incremental"===w&&delete t[o],!0;s('Readonly: Property "'+o+'" is not writable (old document "'+M(r)+'")'+i+".")}else s('Readonly: Property "'+o+'" is not writable'+i+".");if(!e.mutable&&r&&Object.prototype.hasOwnProperty.call(r,o)){if(M(c)===M(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 "'+M(r)+'")'+i+".")}if(null===c){if(e.nullable)return"incremental"===w&&r&&void 0!==r[o]||delete t[o],r&&Object.prototype.hasOwnProperty.call(r,o)&&(a=n.concat(o+"","delete property")),!0;s('NotNull: Property "'+o+'" should not be "null"'+i+".")}return!1},N=function(e,t,r,a,l){if(!r)for(var c,p,y=i(["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:j,model:u,modelName:m,name:a+"",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 "'+a+'": '+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 "'+a+'": '+e.message+o+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}d&&![null,void 0].includes(d.result)&&(l?l[a]=d.result:t[a]=d.result)}},A=function(e,t,r,a,l){if(!l){if(!Object.prototype.hasOwnProperty.call(t,a))return;e.trim&&"string"==typeof t[a]&&(t[a]=t[a].trim()),e.emptyEqualsNull&&(""===t[a]||Array.isArray(t[a])&&0===t[a].length||null!==t[a]&&"object"==typeof t[a]&&0===Object.keys(t).length)&&(t[a]=null)}for(var c,p,y=i(["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:j,model:u,modelName:m,name:a+"",type:p,newDocument:t,oldDocument:r,newValue:t[a],oldValue:r&&r[a]||void 0,parentNames:n,pathDescription:o,propertySpecification:e});l?l[a]=d.result:t[a]=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 "'+a+'": '+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 "'+a+'": '+e.message+o+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}},S=Object.keys(u).filter((function(e){return!z.includes(e)}));if("migrate"===w)for(var C,k,T=i(S);!(C=T()).done;)if(k=C.value,u[k].oldName)for(var D,R,I=i([].concat(u[k].oldName));!(D=I()).done;)R=D.value,Object.prototype.hasOwnProperty.call(e,R)&&(e[k]=e[R],delete e[R]);if(!t)for(var V,W=0,F=[d.create.execution,d.create.expression];W<F.length;W++)if(V=F[W],Object.prototype.hasOwnProperty.call(u,V)){var B=void 0;try{B=H(u[V],V.endsWith("Expression"),{checkPropertyContent:j,model:u,modelName:m,type:V,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 "'+V+'" has invalid code "'+e.code+'" for document "'+m+'": '+e.message+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&s('Runtime: Hook "'+V+'" has throw an error with code "'+e.code+'" for document "'+m+'": '+e.message+o+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}[null,void 0].includes(B)||(e=B),p(),m=e[g],0===n.length&&O()}for(var q,Y=0,$=[d.update.execution,d.update.expression];Y<$.length;Y++)if(q=$[Y],Object.prototype.hasOwnProperty.call(u,q)){var J=void 0;try{J=H(u[q],q.endsWith("Expression"),{checkPropertyContent:j,model:u,modelName:m,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 "'+m+'": '+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 "'+m+'": '+e.message+o+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}[void 0,null].includes(J)||(e=J),p(),m=e[g],0===n.length&&O()}for(var G,K,Z=v?Object.keys(e).filter((function(e){return!S.includes(e)})):[],Q=i(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&&_(l,t,c)})),m=e[d.attachment],u=[];if(t){var y=t[K];u=Object.keys(y).filter((function(e){return!(Object.prototype.hasOwnProperty.call(m,e)&&Object.prototype.hasOwnProperty.call(m[e],"data")&&null===m[e].data)&&!!y[e]&&(Object.prototype.hasOwnProperty.call(y[e],"data")&&null!==y[e].data||y[e].stub&&!!y[e].digest)&&!!_(l,e,c)}))}for(var f,h,g=c,v=i(p);!(f=v()).done;)h=f.value,N(g,e,t&&t[K]?t[K]:null,h,m);for(var b,O,j=i(p);!(b=j()).done;)O=b.value,A(g,e,t&&t[K]?t[K]:null,O,m);if(void 0===g.default){if(g.nullable||0<p.length||0<u.length||s('AttachmentMissing: Missing attachment for type "'+l+'"'+o+"."),"fillUp"===w&&0===p.length&&0<u.length)for(var P,x,S=i(u);!(P=S()).done;)x=P.value,null===m[x]?a=n.concat(K,x,"file removed"):m[x]=t[K][x]}else if(0===p.length)if(0===u.length)for(var C in g.default)Object.prototype.hasOwnProperty.call(g.default,C)&&(m[C]=g.default[C],a=n.concat(K,l,"add default file"));else if("fillUp"===w)for(var k,T,D=i(u);!(k=D()).done;)T=k.value,m[T]=t[K][T]},ee=0,te=Object.entries(u[d.attachment]);ee<te.length;ee++)X();else{var re=S.includes(K)?u[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)&&void 0!==e[K]||t&&Object.prototype.hasOwnProperty.call(t,K)&&w)&&s('MissingProperty: Missing property "'+K+'"'+o+"."),(!Object.prototype.hasOwnProperty.call(e,K)||void 0===e[K])&&t&&Object.prototype.hasOwnProperty.call(t,K)&&("fillUp"===w?e[K]=t[K]:!w&&(a=n.concat(K+"","property removed")))):(!Object.prototype.hasOwnProperty.call(e,K)||[null,void 0].includes(e[K]))&&(t?null!==e[K]&&"fillUp"===w?e[K]=t[K]:"migrate"===w&&(e[K]=re.default,a=n.concat(K+"","migrate default value")):(e[K]=re.default,a=a.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||M(t[ie])===M(le))&&delete e[ie]}for(var ce=0,pe=Object.entries(e);ce<pe.length;ce++){var se=pe[ce],me=se[0],ue=se[1];if(!l.property.name.reserved.concat(h,d.conflict,d.deleted,d.deletedConflict,d.localSequence,d.revisions,d.revisionsInformation,d.strategy).includes(me)){var ye=void 0;if(Object.prototype.hasOwnProperty.call(u,me))ye=u[me];else if(v)ye=v;else{if("migrate"===w){delete e[me],a=n.concat(me+"","migrate removed property");continue}s('Property: Given property "'+me+'" isn\'t specified in model "'+m+'"'+o+".")}if(!ye)continue;if(d.attachment===me){var de=ue;for(var fe in de)if(Object.prototype.hasOwnProperty.call(de,fe))for(var he in u[me])if(_(he,fe,u[d.attachment][he])){x(u[d.attachment][he],e,t,fe,o);break}continue}if(x(ye,e,t,me,o))continue;var ge="string"==typeof ye.type&&ye.type.endsWith("[]")||Array.isArray(ye.type)&&ye.type.length&&Array.isArray(ye.type[0]);if(ge&&![null,void 0].includes(ue)){var ve,be=ue;Array.isArray(be)?"number"==typeof ye.minimumNumber&&be.length<ye.minimumNumber?s('MinimumArrayLength: Property "'+me+'" (array of length '+be.length+") doesn't fullfill minimum array length of "+ye.minimumNumber+o+"."):"number"==typeof ye.maximumNumber&&ye.maximumNumber<be.length&&s('MaximumArrayLength: Property "'+me+'" (array of length '+be.length+") doesn't fullfill maximum array length of "+ye.maximumNumber+o+"."):s('PropertyType: Property "'+me+'" isn\'t of type "array -> '+ye.type+'" (given "'+M(be)+'")'+o+"."),b(be,me+"",ye,t&&Object.prototype.hasOwnProperty.call(t,me)&&t[me]||void 0,["arrayConstraintExecution","arrayConstraintExpression"]);var Oe={};for(var we in ye)Object.prototype.hasOwnProperty.call(ye,we)&&(Oe[we]="type"===we?Array.isArray(ye[we])?ye[we][0]:[ye[we].substring(0,ye.type.length-2)]:ye[we]);if(1===(null==(ve=Oe.type)?void 0:ve.length)&&Object.prototype.hasOwnProperty.call(c,Oe.type[0]))for(var je,Pe,xe=i(be.slice());!(je=xe()).done;)"object"!=typeof(Pe=je.value)||Object.getPrototypeOf(Pe)!==Object.prototype||Object.prototype.hasOwnProperty.call(Pe,g)||(Pe[g]=Oe.type[0]);for(var Ne,Ae,Se=0,Ce=i(be.slice());!(Ne=Ce()).done;)Ae=Ne.value,be[Se]=j(Ae,Se+1+". value in "+me,Oe).newValue,[null,void 0].includes(be[Se])&&be.splice(Se,1),Se+=1;t&&Object.prototype.hasOwnProperty.call(t,me)&&Array.isArray(t[me])&&t[me].length===be.length&&M(t[me])===M(be)||(a=n.concat(me+"","array updated"))}else{var ke=t&&Object.prototype.hasOwnProperty.call(t,me)?t[me]:null,Te=ge?{newValue:null,changedPath:[]}:j(ue,me+"",ye,ke);e[me]=Te.newValue,Te.changedPath.length&&(a=Te.changedPath),[null,void 0].includes(e[me])&&(null!==ke&&(a=n.concat(me+"","property removed")),("incremental"!==w||null!==ke)&&delete e[me])}}}for(var De=0,ze=Object.keys(d.constraint);De<ze.length;De++){var Me=ze[De],Ue=d.constraint[Me];if(Object.prototype.hasOwnProperty.call(u,Ue))for(var Ee,_e=i([].concat(u[Ue]));!(Ee=_e()).done;){var Re=Ee.value,He=void 0;try{He=H(Re.evaluation,Ue===d.constraint.expression,{checkPropertyContent:j,model:u,modelName:m,type:Ue,newDocument:e,oldDocument:t,parentNames:n,pathDescription:o})}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&s('Compilation: Hook "'+Ue+'" has invalid code "'+e.code+'": "'+e.message+'"'+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&s('Runtime: Hook "'+Ue+'" has thrown an error with code "'+e.code+'": '+e.message+o+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}if(He&&!He.result){var Le=Ue.replace(/^[^a-zA-Z]+/,"");s(Le.charAt(0).toUpperCase()+(Le.substring(1)+": ")+(Re.description?r(Function,Object.keys(He.scope).concat(["return "+Re.description.trim()])).apply(void 0,Object.values(He.scope)):'Model "'+m+'" should satisfy constraint "'+He.code+'" (given "'+M(e)+'")'+o+"."))}}}if(Object.prototype.hasOwnProperty.call(e,d.attachment)){var Ie=e[d.attachment];("object"!=typeof Ie||Object.getPrototypeOf(Ie)!==Object.prototype)&&s("AttachmentType: given attachment has invalid type"+o+".");var Ve=null;if(t&&Object.prototype.hasOwnProperty.call(t,d.attachment)&&(null!==(Ve=t[d.attachment])&&"object"==typeof Ve))for(var We=0,Fe=Object.entries(Ve);We<Fe.length;We++){var Be=Fe[We],qe=Be[0],Ye=Be[1];if(Object.prototype.hasOwnProperty.call(Ie,qe)){var $e=Ie[qe];null===$e||null===$e.data||$e.content_type===Ye.content_type&&($e.data===Ye.data||$e.digest===Ye.digest)?((null===$e||null===$e.data)&&(a=n.concat(d.attachment,qe,"attachment removed")),"incremental"===w&&delete Ie[qe]):a=n.concat(d.attachment,qe,"attachment updated")}else"fillUp"===w?Ie[qe]=Ye:w||(a=n.concat(d.attachment,qe,"attachment removed"))}for(var Je=0,Ge=Object.entries(Ie);Je<Ge.length;Je++){var Ke=Ge[Je],Ze=Ke[0],Qe=Ke[1];[null,void 0].includes(Qe)||null===Qe.data?delete Ie[Ze]:(!Ve||!Object.prototype.hasOwnProperty.call(Ve,Ze)||Qe.content_type!==Ve[Ze].content_type||Qe.data!==Ve[Ze].data&&Qe.digest!==Ve[Ze].digest)&&(a=n.concat(d.attachment,Ze,"attachment updated"))}0===Object.keys(Ie).length&&delete e[d.attachment];for(var Xe={},et=0,tt=Object.keys(u[d.attachment]);et<tt.length;et++)Xe[tt[et]]=[];for(var rt=0,nt=Object.keys(Ie);rt<nt.length;rt++){for(var ot=nt[rt],at=!1,it=0,lt=Object.entries(u[d.attachment]);it<lt.length;it++){var ct=lt[it],pt=ct[0],st=ct[1];if(_(pt,ot,st)){Xe[pt].push(ot),at=!0;break}}at||s('AttachmentTypeMatch: None of the specified attachment types ("'+Object.keys(u[d.attachment]).join('", "')+'") matches given one ("'+ot+'")'+o+".")}for(var mt=0,ut=0,yt=Object.keys(Xe);ut<yt.length;ut++){var dt=yt[ut],ft=u[d.attachment][dt];if(Object.prototype.hasOwnProperty.call(Xe,dt)){var ht=Xe[dt].length;"number"==typeof ft.maximumNumber&&ht>ft.maximumNumber&&s("AttachmentMaximum: given number of attachments ("+ht+") doesn't satisfy specified maximum of "+ft.maximumNumber+' from type "'+dt+'"'+o+"."),(!ft.nullable||0!==ht)&&"number"==typeof ft.minimumNumber&&ht<ft.minimumNumber&&s("AttachmentMinimum: given number of attachments ("+ht+") doesn't satisfy specified minimum of "+ft.minimumNumber+' from type "'+dt+'"'+o+".");for(var gt,vt=0,bt=i(Xe[dt]);!(gt=bt()).done;){var Ot,wt,jt=gt.value;if(null!=(Ot=ft.fileName)&&Ot.pattern){for(var Pt,xt,Nt=[].concat(ft.fileName.pattern),At=!1,St=i(Nt);!(Pt=St()).done;)if(xt=Pt.value,new RegExp(xt).test(jt)){At=!0;break}At||s('AttachmentName: given attachment name "'+jt+'" doesn\'t satisfy one of specified regular expression patterns "'+Nt.join('", "')+'" from type "'+dt+'"'+o+".")}if(null!=(wt=ft.fileName)&&wt.invertedPattern)for(var Ct,kt,Tt=i([].concat(ft.fileName.invertedPattern));!(Ct=Tt()).done;)kt=Ct.value,new RegExp(kt).test(jt)&&s('InvertedAttachmentName: given attachment name "'+jt+'" does satisfy specified regular expression pattern "'+kt.toString()+'" from type "'+dt+'"'+o+".");if(Ie[jt].content_type){if(ft.contentTypePattern){for(var Dt,zt,Mt=[].concat(ft.contentTypePattern),Ut=!1,Et=i(Mt);!(Dt=Et()).done;)if(zt=Dt.value,new RegExp(zt).test(Ie[jt].content_type)){Ut=!0;break}Ut||s('AttachmentContentType: given attachment content type "'+Ie[jt].content_type+'" doesn\'t satisfy specified regular expression pattern "'+Mt.join('", "')+'" from type "'+dt+'"'+o+".")}var _t=ft.invertedContentTypePattern;if(_t)for(var Rt,Ht,Lt=i([].concat(_t));!(Rt=Lt()).done;)Ht=Rt.value,new RegExp(Ht).test(Ie[jt].content_type)&&s('InvertedAttachmentContentType: given attachment content type "'+Ie[jt].content_type+'" does satisfy specified regular expression pattern "'+Ht.toString()+'" from type "'+dt+'"'+o+".")}var It=0;"length"in Ie[jt]?It=Ie[jt].length:"data"in Ie[jt]&&(It=Buffer&&"byteLength"in Buffer?Buffer.byteLength(Ie[jt].data,"base64"):Ie[jt].data.length),"number"==typeof ft.minimumSize&&ft.minimumSize>It?s("AttachmentMinimumSize: given attachment size "+It+" byte doesn't satisfy specified minimum of "+ft.minimumSize+" byte "+o+"."):"number"==typeof ft.maximumSize&&ft.maximumSize<It&&s("AttachmentMaximumSize: given attachment size "+It+" byte doesn't satisfy specified maximum of "+ft.maximumSize+" byte "+o+"."),vt+=It}"number"==typeof ft.minimumAggregatedSize&&ft.minimumAggregatedSize>vt?s('AttachmentAggregatedMinimumSize: given aggregated size of attachments from type "'+dt+'" '+vt+" byte doesn't satisfy specified minimum of "+ft.minimumAggregatedSize+" byte "+o+"."):"number"==typeof ft.maximumAggregatedSize&&ft.maximumAggregatedSize<vt&&s('AttachmentAggregatedMaximumSize: given aggregated size of attachments from type "'+dt+'" '+vt+" byte doesn't satisfy specified maximum of "+ft.maximumAggregatedSize+" byte "+o+"."),mt+=vt}}Object.prototype.hasOwnProperty.call(u,d.minimumAggregatedSize)&&"number"==typeof u[d.minimumAggregatedSize]&&u[d.minimumAggregatedSize]>mt?s("AggregatedMinimumSize: given aggregated size "+mt+" byte doesn't satisfy specified minimum of "+u[d.minimumAggregatedSize]+" byte "+o+"."):"number"==typeof u[d.maximumAggregatedSize]&&u[d.maximumAggregatedSize]<mt&&s("AggregatedMaximumSize: given aggregated size "+mt+" byte doesn't satisfy specified maximum of "+u[d.maximumAggregatedSize]+" byte "+o+".")}if(t&&Object.prototype.hasOwnProperty.call(t,d.attachment)&&0===Object.keys(t[d.attachment]).length&&delete t[d.attachment],0===a.length&&t&&"migrate"===w)for(var Vt,Wt=0,Ft=Object.keys(t);Wt<Ft.length;Wt++)Vt=Ft[Wt],Object.prototype.hasOwnProperty.call(e,Vt)||(a=n.concat(Vt,"migrate removed property"));return{changedPath:a,newDocument:e}},I={attachmentWithPrefixExists:function(t){if(Object.prototype.hasOwnProperty.call(e,d.attachment)){var r=e[d.attachment],n=R(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:R,serialize:M,id:v,revision:b,idName:f,revisionName:h,specialNames:d,typeName:g,modelConfiguration:l,models:c,now:m,nowUTCTimestamp:u,securitySettings:o,userContext:n};if(e[d.attachment])for(var V,W=0,F=Object.values(e[d.attachment]);W<F.length;W++)V=F[W],Object.prototype.hasOwnProperty.call(V,"contentType")&&(V.content_type=V.contentType,delete V.contentType);var B=L(e,t);return(!B.newDocument._deleted||t)&&(B.newDocument._deleted&&B.newDocument._deleted!==(null==t?void 0:t._deleted)||B.changedPath.length)||s("NoChange: No new data given. new document: "+M(e)+"; old document: "+M(t)+"."),Object.prototype.hasOwnProperty.call(o,l.property.name.validatedDocumentsCache)?o[l.property.name.validatedDocumentsCache].add(v+"-"+b):o[l.property.name.validatedDocumentsCache]=new Set([v+"-"+b]),B.newDocument},e}();const p=c;module.exports=t})();
1
+ (()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function r(e,t,r){if(o())return Reflect.construct.apply(null,arguments);var a=[null];a.push.apply(a,t);var i=new(e.bind.apply(e,a));return r&&n(i,r.prototype),i}function n(e,t){return n=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},n(e,t)}function o(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(o=function(){return!!e})()}function a(){return a=Object.assign?Object.assign.bind():function(e){for(var t,r=1;r<arguments.length;r++)for(var n in t=arguments[r])({}).hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e},a.apply(null,arguments)}function i(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return l(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?l(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function l(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}e.r(t),e.d(t,{DatabaseHelper:()=>c,default:()=>p});var c=function(){function e(){}return e.authenticate=function(e,t,r,n,o,a,l,c,p){var s;void 0===t&&(t=null),void 0===r&&(r={}),void 0===n&&(n={admins:{names:[],roles:[]},members:{names:[],roles:[]}}),void 0===a&&(a="_id"),void 0===l&&(l="-type"),void 0===c&&(c="_design/"),void 0===p&&(p=!1);var m=null!==(s=e[l])&&void 0!==s?s:t&&t[l];if(!m)return!0;var u=p?"read":"write",y={properties:{},read:["_admin","readonlyadmin"],write:["_admin"]};Object.prototype.hasOwnProperty.call(e,a)&&e[a].startsWith(c)&&y.read.push("readonlymember");var d,f="Current user doesn't own any role";if(r)if("name"in r||(r.name='"unknown"'),null!=(d=r.roles)&&d.length){if(o&&m&&Object.prototype.hasOwnProperty.call(o,m)){for(var h,g,v=o[m],b=i(["read","write"]);!(h=b()).done;)y[g=h.value]=y[g].concat(v[g]||[]);y.properties=v.properties}for(var O,w,j=y[u],P=i(r.roles);!(O=P()).done;)if(w=O.value,j.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 "+u+' action: "'+[].concat(y[u]).join('", "')+'". '+f+"."}},e.validateDocumentUpdate=function(e,t,n,o,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={}),a(((n={})[t]=e,n.message=e,n.name=t,n),r)},m=new Date,u=Date.UTC(m.getUTCFullYear(),m.getUTCMonth(),m.getUTCDate(),m.getUTCHours(),m.getUTCMinutes(),m.getUTCSeconds(),m.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="",b="",O=function(){v=Object.prototype.hasOwnProperty.call(e,f)?e[f]:"",b=Object.prototype.hasOwnProperty.call(e,h)?e[h]:""};if(O(),Object.prototype.hasOwnProperty.call(o,l.property.name.validatedDocumentsCache)&&o[l.property.name.validatedDocumentsCache].has(v+"-"+b))return o[l.property.name.validatedDocumentsCache].delete(v+"-"+b),e;["latest","upsert"].includes(b)&&(t&&Object.prototype.hasOwnProperty.call(t,h)?b=e[h]=t[h]:"latest"===b?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 j,P={};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)&&C[d.oldType])for(var k,T,D=i([].concat(C[d.oldType]));!(k=D()).done;)T=k.value,P[T]=S}p?j=p:JSON&&Object.prototype.hasOwnProperty.call(JSON,"stringify")?j=function(e){return JSON.stringify(e,null,4)}:s('Needed "serializer" is not available.');var z=[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],M=function(e){return e instanceof Error?""+e:j(e)},U=function(e){return"string"==typeof e?e.trim():""},E=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},_=function(e,t,r){if(r.fileName){if(r.fileName.value)return r.fileName.value===t;if(r.fileName.pattern)return[].concat(r.fileName.pattern).some((function(e){return new RegExp(e).test(t)}))}return e===t},R=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 o=U(e);if(o){var i,l=(t?"return ":"")+o,c=a({},I,{code:l},n),p=Object.keys(c);try{i=r(Function,p.concat([l]))}catch(e){s(M(e),"compilation",{code:l,error:e,scope:c})}var m={code:l,result:void 0,scope:c};try{m.result=i.apply(void 0,p.map((function(e){return c[e]})))}catch(e){s(M(e),"runtime",{code:l,error:e,scope:c})}return m}s("No expression to evaluate provided.","empty")},L=function(e,t,n){void 0===n&&(n=[]);var o=n.length?" in "+n.join(" -> "):"",a=[],p=function(){Object.prototype.hasOwnProperty.call(e,g)||(t&&Object.prototype.hasOwnProperty.call(t,g)&&["fillUp","migrate"].includes(w)?e[g]=t[g]:s('Type: You have to specify a model type via property "'+g+'"'+o+".")),n.length||new RegExp(l.property.name.typePattern.public).test(e[g])||s('TypeName: You have to specify a model type which matches "'+l.property.name.typePattern.public+'" as public type (given "'+e[g]+'")'+o+"."),Object.prototype.hasOwnProperty.call(c,e[g])||(Object.prototype.hasOwnProperty.call(P,e[g])?e[g]=P[e[g]]:s('Model: Given model "'+e[g]+'" is not specified'+o+"."))};p();var m=e[g],u=c[m],v=void 0;Object.prototype.hasOwnProperty.call(u,d.additional)&&u[d.additional]&&(v=u[d.additional]);var b=function(a,l,c,p,y){void 0===y&&(y=["constraintExecution","constraintExpression"]);for(var d,f,h=i(y);!(d=h()).done;)if(f=d.value,Object.prototype.hasOwnProperty.call(c,f)){var g=void 0;try{g=H(c[f].evaluation,f.endsWith("Expression"),{checkPropertyContent:j,model:u,modelName:m,name:l,type:f,newDocument:e,newValue:a,oldDocument:t,oldValue:p,parentNames:n,pathDescription:o,propertySpecification:c})}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&s('Compilation: Hook "'+f+'" has invalid code "'+e.code+'": "'+e.message+'"'+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&s('Runtime: Hook "'+f+'" has throw an error with code "'+e.code+'": "'+e.message+'"'+o+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}if(g&&!g.result){var v=U(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 "'+M(a)+'")'+o+"."))}}},j=function(e,t,r,a){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 m,u,d=!1,h=i(p);!(m=h()).done;)if(u=m.value,Object.prototype.hasOwnProperty.call(c,u)){if("object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype&&Object.prototype.hasOwnProperty.call(e,g)&&e[g]!==u&&"migrate"===w&&1===p.length&&(e[g]=u,l=n.concat(t+"","migrate nested object type")),"object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype&&Object.prototype.hasOwnProperty.call(e,g)&&e[g]===u){var v=L(e,a,n.concat(t+""));if(v.changedPath.length&&(l=v.changedPath),e=v.newDocument,M(e)===M({}))return{newValue:void 0,changedPath:l};d=!0;break}1===p.length&&s('NestedType: Under key "'+t+'" isn\'t of type "'+u+'" (given "'+M(e)+'" of type '+typeof e+")"+o+".")}else if("DateTime"===u){var O=e;if(e=E(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"'+M(O).replace(/^"/,"").replace(/"$/,"")+'" of type "'+typeof O+'")'+o+".")}else if(["boolean","integer","number","string"].includes(u)){if(!("number"==typeof e&&isNaN(e)||"integer"!==u&&typeof e!==u||"integer"===u&&parseInt(e,10)!==e)){d=!0;break}1===p.length&&s('PropertyType: Property "'+t+'" isn\'t of (valid) type "'+u+'" (given "'+M(e)+'" of type "'+typeof e+'")'+o+".")}else if("string"==typeof u&&u.startsWith("foreignKey:")){var j=c[u.substring(11)][f].type;if(j===typeof e){d=!0;break}1===p.length&&s('PropertyType: Foreign key property "'+t+'" isn\'t of type "'+j+'" (given "'+M(e)+'" of type "'+typeof e+'")'+o+".")}else{if("any"===u||M(e)===M(u)){d=!0;break}1===p.length&&s('PropertyType: Property "'+t+'" isn\'t value "'+u+'" (given "'+M(e).replace(/^"/,"").replace(/"$/,"")+'" of type "'+typeof e+'")'+o+".")}if(d||s('PropertyType: None of the specified types "'+p.join('", "')+'" for property "'+t+'" matches value "'+M(e).replace(/^"/,"").replace(/"$/,"")+e+'" of type "'+typeof e+'")'+o+"."),"string"==typeof e&&("number"==typeof r.minimumLength&&e.length<r.minimumLength&&s('MinimalLength: Property "'+t+'" must have minimal length '+r.minimumLength+" (given "+e+" with length "+e.length+") "+o+"."),"number"==typeof 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&&("number"==typeof 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+"."),"number"==typeof 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 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(E)),P.includes(e)||s('Selection: Property "'+t+'" (type '+r.type+') should be one of "'+P.join('", "')+'". But is "'+e+'"'+o+".")}if(r.pattern){for(var x,N,A=[].concat(r.pattern),S=!1,C=i(A);!(x=C()).done;)if(N=x.value,new RegExp(N).test(e)){S=!0;break}S||s('PatternMatch: Property "'+t+'" should match one regular expression pattern "'+A.join('", "')+'" (given "'+e+'")'+o+".")}if(r.invertedPattern)for(var k,T,D=i([].concat(r.invertedPattern));!(k=D()).done;)T=k.value,new RegExp(T).test(e)&&s('InvertedPatternMatch: Property "'+t+'" should not match regular expression pattern '+T+' (given "'+e+'")'+o+".");return b(e,t,r,a),M(e)!==M(a)&&(l=n.concat(t+"","value updated")),{newValue:e,changedPath:l}},x=function(e,t,r,o,i){var c=t[o];if(!e.writable)if(r){if(Object.prototype.hasOwnProperty.call(r,o)&&M(c)===M(r[o]))return o!==f&&"incremental"===w&&delete t[o],!0;s('Readonly: Property "'+o+'" is not writable (old document "'+M(r)+'")'+i+".")}else s('Readonly: Property "'+o+'" is not writable'+i+".");if(!e.mutable&&r&&Object.prototype.hasOwnProperty.call(r,o)){if(M(c)===M(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 "'+M(r)+'")'+i+".")}if(null===c){if(e.nullable)return"incremental"===w&&r&&void 0!==r[o]||delete t[o],r&&Object.prototype.hasOwnProperty.call(r,o)&&(a=n.concat(o+"","delete property")),!0;s('NotNull: Property "'+o+'" should not be "null"'+i+".")}return!1},N=function(e,t,r,a,l){if(!r)for(var c,p,y=i(["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:j,model:u,modelName:m,name:a+"",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 "'+a+'": '+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 "'+a+'": '+e.message+o+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}d&&![null,void 0].includes(d.result)&&(l?l[a]=d.result:t[a]=d.result)}},A=function(e,t,r,a,l){if(!l){if(!Object.prototype.hasOwnProperty.call(t,a))return;e.trim&&"string"==typeof t[a]&&(t[a]=t[a].trim()),e.emptyEqualsNull&&(""===t[a]||Array.isArray(t[a])&&0===t[a].length||null!==t[a]&&"object"==typeof t[a]&&0===Object.keys(t).length)&&(t[a]=null)}for(var c,p,y=i(["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:j,model:u,modelName:m,name:a+"",type:p,newDocument:t,oldDocument:r,newValue:t[a],oldValue:r&&r[a]||void 0,parentNames:n,pathDescription:o,propertySpecification:e});l?l[a]=d.result:t[a]=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 "'+a+'": '+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 "'+a+'": '+e.message+o+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}},S=Object.keys(u).filter((function(e){return!z.includes(e)}));if("migrate"===w)for(var C,k,T=i(S);!(C=T()).done;)if(k=C.value,u[k].oldName)for(var D,R,I=i([].concat(u[k].oldName));!(D=I()).done;)R=D.value,Object.prototype.hasOwnProperty.call(e,R)&&(e[k]=e[R],delete e[R]);if(!t)for(var V,W=0,F=[d.create.execution,d.create.expression];W<F.length;W++)if(V=F[W],Object.prototype.hasOwnProperty.call(u,V)){var B=void 0;try{B=H(u[V],V.endsWith("Expression"),{checkPropertyContent:j,model:u,modelName:m,type:V,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 "'+V+'" has invalid code "'+e.code+'" for document "'+m+'": '+e.message+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&s('Runtime: Hook "'+V+'" has throw an error with code "'+e.code+'" for document "'+m+'": '+e.message+o+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}[null,void 0].includes(B)||(e=B),p(),m=e[g],0===n.length&&O()}for(var q,Y=0,$=[d.update.execution,d.update.expression];Y<$.length;Y++)if(q=$[Y],Object.prototype.hasOwnProperty.call(u,q)){var J=void 0;try{J=H(u[q],q.endsWith("Expression"),{checkPropertyContent:j,model:u,modelName:m,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 "'+m+'": '+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 "'+m+'": '+e.message+o+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}[void 0,null].includes(J)||(e=J),p(),m=e[g],0===n.length&&O()}for(var G,K,Z=v?Object.keys(e).filter((function(e){return!S.includes(e)})):[],Q=i(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&&_(l,t,c)})),m=e[d.attachment],u=[];if(t){var y=t[K];u=Object.keys(y).filter((function(e){return!(Object.prototype.hasOwnProperty.call(m,e)&&Object.prototype.hasOwnProperty.call(m[e],"data")&&null===m[e].data)&&!!y[e]&&(Object.prototype.hasOwnProperty.call(y[e],"data")&&null!==y[e].data||y[e].stub&&!!y[e].digest)&&!!_(l,e,c)}))}for(var f,h,g=c,v=i(p);!(f=v()).done;)h=f.value,N(g,e,t&&t[K]?t[K]:null,h,m);for(var b,O,j=i(p);!(b=j()).done;)O=b.value,A(g,e,t&&t[K]?t[K]:null,O,m);if(void 0===g.default){if(g.nullable||0<p.length||0<u.length||s('AttachmentMissing: Missing attachment for type "'+l+'"'+o+"."),"fillUp"===w&&0===p.length&&0<u.length)for(var P,x,S=i(u);!(P=S()).done;)x=P.value,null===m[x]?a=n.concat(K,x,"file removed"):m[x]=t[K][x]}else if(0===p.length)if(0===u.length)for(var C in g.default)Object.prototype.hasOwnProperty.call(g.default,C)&&(m[C]=g.default[C],a=n.concat(K,l,"add default file"));else if("fillUp"===w)for(var k,T,D=i(u);!(k=D()).done;)T=k.value,m[T]=t[K][T]},ee=0,te=Object.entries(u[d.attachment]);ee<te.length;ee++)X();else{var re=S.includes(K)?u[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)&&void 0!==e[K]||t&&Object.prototype.hasOwnProperty.call(t,K)&&w)&&s('MissingProperty: Missing property "'+K+'"'+o+"."),(!Object.prototype.hasOwnProperty.call(e,K)||void 0===e[K])&&t&&Object.prototype.hasOwnProperty.call(t,K)&&("fillUp"===w?e[K]=t[K]:!w&&(a=n.concat(K+"","property removed")))):(!Object.prototype.hasOwnProperty.call(e,K)||[null,void 0].includes(e[K]))&&(t?null!==e[K]&&"fillUp"===w?e[K]=t[K]:"migrate"===w&&(e[K]=re.default,a=n.concat(K+"","migrate default value")):(e[K]=re.default,a=a.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||M(t[ie])===M(le))&&delete e[ie]}for(var ce=0,pe=Object.entries(e);ce<pe.length;ce++){var se=pe[ce],me=se[0],ue=se[1];if(!l.property.name.reserved.concat(h,d.conflict,d.deleted,d.deletedConflict,d.localSequence,d.revisions,d.revisionsInformation,d.strategy).includes(me)){var ye=void 0;if(Object.prototype.hasOwnProperty.call(u,me))ye=u[me];else if(v)ye=v;else{if("migrate"===w){delete e[me],a=n.concat(me+"","migrate removed property");continue}s('Property: Given property "'+me+'" isn\'t specified in model "'+m+'"'+o+".")}if(!ye)continue;if(d.attachment===me){var de=ue;for(var fe in de)if(Object.prototype.hasOwnProperty.call(de,fe))for(var he in u[me])if(_(he,fe,u[d.attachment][he])){x(u[d.attachment][he],e,t,fe,o);break}continue}if(x(ye,e,t,me,o))continue;var ge="string"==typeof ye.type&&ye.type.endsWith("[]")||Array.isArray(ye.type)&&ye.type.length&&Array.isArray(ye.type[0]);if(ge&&![null,void 0].includes(ue)){var ve,be=ue;Array.isArray(be)?"number"==typeof ye.minimumNumber&&be.length<ye.minimumNumber?s('MinimumArrayLength: Property "'+me+'" (array of length '+be.length+") doesn't fullfill minimum array length of "+ye.minimumNumber+o+"."):"number"==typeof ye.maximumNumber&&ye.maximumNumber<be.length&&s('MaximumArrayLength: Property "'+me+'" (array of length '+be.length+") doesn't fullfill maximum array length of "+ye.maximumNumber+o+"."):s('PropertyType: Property "'+me+'" isn\'t of type "array -> '+ye.type+'" (given "'+M(be)+'")'+o+"."),b(be,me+"",ye,t&&Object.prototype.hasOwnProperty.call(t,me)&&t[me]||void 0,["arrayConstraintExecution","arrayConstraintExpression"]);var Oe={};for(var we in ye)Object.prototype.hasOwnProperty.call(ye,we)&&(Oe[we]="type"===we?Array.isArray(ye[we])?ye[we][0]:[ye[we].substring(0,ye.type.length-2)]:ye[we]);if(1===(null==(ve=Oe.type)?void 0:ve.length)&&Object.prototype.hasOwnProperty.call(c,Oe.type[0]))for(var je,Pe,xe=i(be.slice());!(je=xe()).done;)"object"!=typeof(Pe=je.value)||Object.getPrototypeOf(Pe)!==Object.prototype||Object.prototype.hasOwnProperty.call(Pe,g)||(Pe[g]=Oe.type[0]);for(var Ne,Ae,Se=0,Ce=i(be.slice());!(Ne=Ce()).done;)Ae=Ne.value,be[Se]=j(Ae,Se+1+". value in "+me,Oe).newValue,[null,void 0].includes(be[Se])&&be.splice(Se,1),Se+=1;t&&Object.prototype.hasOwnProperty.call(t,me)&&Array.isArray(t[me])&&t[me].length===be.length&&M(t[me])===M(be)||(a=n.concat(me+"","array updated"))}else{var ke=t&&Object.prototype.hasOwnProperty.call(t,me)?t[me]:null,Te=ge?{newValue:null,changedPath:[]}:j(ue,me+"",ye,ke);e[me]=Te.newValue,Te.changedPath.length&&(a=Te.changedPath),[null,void 0].includes(e[me])&&(null!==ke&&(a=n.concat(me+"","property removed")),("incremental"!==w||null!==ke)&&delete e[me])}}}for(var De=0,ze=Object.keys(d.constraint);De<ze.length;De++){var Me=ze[De],Ue=d.constraint[Me];if(Object.prototype.hasOwnProperty.call(u,Ue))for(var Ee,_e=i([].concat(u[Ue]));!(Ee=_e()).done;){var Re=Ee.value,He=void 0;try{He=H(Re.evaluation,Ue===d.constraint.expression,{checkPropertyContent:j,model:u,modelName:m,type:Ue,newDocument:e,oldDocument:t,parentNames:n,pathDescription:o})}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&s('Compilation: Hook "'+Ue+'" has invalid code "'+e.code+'": "'+e.message+'"'+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&s('Runtime: Hook "'+Ue+'" has thrown an error with code "'+e.code+'": '+e.message+o+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}if(He&&!He.result){var Le=Ue.replace(/^[^a-zA-Z]+/,"");s(Le.charAt(0).toUpperCase()+(Le.substring(1)+": ")+(Re.description?r(Function,Object.keys(He.scope).concat(["return "+Re.description.trim()])).apply(void 0,Object.values(He.scope)):'Model "'+m+'" should satisfy constraint "'+He.code+'" (given "'+M(e)+'")'+o+"."))}}}if(Object.prototype.hasOwnProperty.call(e,d.attachment)){var Ie=e[d.attachment];("object"!=typeof Ie||Object.getPrototypeOf(Ie)!==Object.prototype)&&s("AttachmentType: given attachment has invalid type"+o+".");var Ve=null;if(t&&Object.prototype.hasOwnProperty.call(t,d.attachment)&&(null!==(Ve=t[d.attachment])&&"object"==typeof Ve))for(var We=0,Fe=Object.entries(Ve);We<Fe.length;We++){var Be=Fe[We],qe=Be[0],Ye=Be[1];if(Object.prototype.hasOwnProperty.call(Ie,qe)){var $e=Ie[qe];null===$e||null===$e.data||$e.content_type===Ye.content_type&&($e.data===Ye.data||$e.digest===Ye.digest)?((null===$e||null===$e.data)&&(a=n.concat(d.attachment,qe,"attachment removed")),"incremental"===w&&delete Ie[qe]):a=n.concat(d.attachment,qe,"attachment updated")}else"fillUp"===w?Ie[qe]=Ye:w||(a=n.concat(d.attachment,qe,"attachment removed"))}for(var Je=0,Ge=Object.entries(Ie);Je<Ge.length;Je++){var Ke=Ge[Je],Ze=Ke[0],Qe=Ke[1];[null,void 0].includes(Qe)||null===Qe.data?delete Ie[Ze]:(!Ve||!Object.prototype.hasOwnProperty.call(Ve,Ze)||Qe.content_type!==Ve[Ze].content_type||Qe.data!==Ve[Ze].data&&Qe.digest!==Ve[Ze].digest)&&(a=n.concat(d.attachment,Ze,"attachment updated"))}0===Object.keys(Ie).length&&delete e[d.attachment];for(var Xe={},et=0,tt=Object.keys(u[d.attachment]);et<tt.length;et++)Xe[tt[et]]=[];for(var rt=0,nt=Object.keys(Ie);rt<nt.length;rt++){for(var ot=nt[rt],at=!1,it=0,lt=Object.entries(u[d.attachment]);it<lt.length;it++){var ct=lt[it],pt=ct[0],st=ct[1];if(_(pt,ot,st)){Xe[pt].push(ot),at=!0;break}}at||s('AttachmentTypeMatch: None of the specified attachment types ("'+Object.keys(u[d.attachment]).join('", "')+'") matches given one ("'+ot+'")'+o+".")}for(var mt=0,ut=0,yt=Object.keys(Xe);ut<yt.length;ut++){var dt=yt[ut],ft=u[d.attachment][dt];if(Object.prototype.hasOwnProperty.call(Xe,dt)){var ht=Xe[dt].length;"number"==typeof ft.maximumNumber&&ht>ft.maximumNumber&&s("AttachmentMaximum: given number of attachments ("+ht+") doesn't satisfy specified maximum of "+ft.maximumNumber+' from type "'+dt+'"'+o+"."),(!ft.nullable||0!==ht)&&"number"==typeof ft.minimumNumber&&ht<ft.minimumNumber&&s("AttachmentMinimum: given number of attachments ("+ht+") doesn't satisfy specified minimum of "+ft.minimumNumber+' from type "'+dt+'"'+o+".");for(var gt,vt=0,bt=i(Xe[dt]);!(gt=bt()).done;){var Ot,wt,jt=gt.value;if(null!=(Ot=ft.fileName)&&Ot.pattern){for(var Pt,xt,Nt=[].concat(ft.fileName.pattern),At=!1,St=i(Nt);!(Pt=St()).done;)if(xt=Pt.value,new RegExp(xt).test(jt)){At=!0;break}At||s('AttachmentName: given attachment name "'+jt+'" doesn\'t satisfy one of specified regular expression patterns "'+Nt.join('", "')+'" from type "'+dt+'"'+o+".")}if(null!=(wt=ft.fileName)&&wt.invertedPattern)for(var Ct,kt,Tt=i([].concat(ft.fileName.invertedPattern));!(Ct=Tt()).done;)kt=Ct.value,new RegExp(kt).test(jt)&&s('InvertedAttachmentName: given attachment name "'+jt+'" does satisfy specified regular expression pattern "'+kt.toString()+'" from type "'+dt+'"'+o+".");if(Ie[jt].content_type){if(ft.contentTypePattern){for(var Dt,zt,Mt=[].concat(ft.contentTypePattern),Ut=!1,Et=i(Mt);!(Dt=Et()).done;)if(zt=Dt.value,new RegExp(zt).test(Ie[jt].content_type)){Ut=!0;break}Ut||s('AttachmentContentType: given attachment content type "'+Ie[jt].content_type+'" doesn\'t satisfy specified regular expression pattern "'+Mt.join('", "')+'" from type "'+dt+'"'+o+".")}var _t=ft.invertedContentTypePattern;if(_t)for(var Rt,Ht,Lt=i([].concat(_t));!(Rt=Lt()).done;)Ht=Rt.value,new RegExp(Ht).test(Ie[jt].content_type)&&s('InvertedAttachmentContentType: given attachment content type "'+Ie[jt].content_type+'" does satisfy specified regular expression pattern "'+Ht.toString()+'" from type "'+dt+'"'+o+".")}var It=0;"length"in Ie[jt]?It=Ie[jt].length:"data"in Ie[jt]&&(It=Buffer&&"byteLength"in Buffer?Buffer.byteLength(Ie[jt].data,"base64"):Ie[jt].data.length),"number"==typeof ft.minimumSize&&ft.minimumSize>It?s("AttachmentMinimumSize: given attachment size "+It+" byte doesn't satisfy specified minimum of "+ft.minimumSize+" byte "+o+"."):"number"==typeof ft.maximumSize&&ft.maximumSize<It&&s("AttachmentMaximumSize: given attachment size "+It+" byte doesn't satisfy specified maximum of "+ft.maximumSize+" byte "+o+"."),vt+=It}"number"==typeof ft.minimumAggregatedSize&&ft.minimumAggregatedSize>vt?s('AttachmentAggregatedMinimumSize: given aggregated size of attachments from type "'+dt+'" '+vt+" byte doesn't satisfy specified minimum of "+ft.minimumAggregatedSize+" byte "+o+"."):"number"==typeof ft.maximumAggregatedSize&&ft.maximumAggregatedSize<vt&&s('AttachmentAggregatedMaximumSize: given aggregated size of attachments from type "'+dt+'" '+vt+" byte doesn't satisfy specified maximum of "+ft.maximumAggregatedSize+" byte "+o+"."),mt+=vt}}Object.prototype.hasOwnProperty.call(u,d.minimumAggregatedSize)&&"number"==typeof u[d.minimumAggregatedSize]&&u[d.minimumAggregatedSize]>mt?s("AggregatedMinimumSize: given aggregated size "+mt+" byte doesn't satisfy specified minimum of "+u[d.minimumAggregatedSize]+" byte "+o+"."):"number"==typeof u[d.maximumAggregatedSize]&&u[d.maximumAggregatedSize]<mt&&s("AggregatedMaximumSize: given aggregated size "+mt+" byte doesn't satisfy specified maximum of "+u[d.maximumAggregatedSize]+" byte "+o+".")}if(t&&Object.prototype.hasOwnProperty.call(t,d.attachment)&&0===Object.keys(t[d.attachment]).length&&delete t[d.attachment],0===a.length&&t&&"migrate"===w)for(var Vt,Wt=0,Ft=Object.keys(t);Wt<Ft.length;Wt++)Vt=Ft[Wt],Object.prototype.hasOwnProperty.call(e,Vt)||(a=n.concat(Vt,"migrate removed property"));return{changedPath:a,newDocument:e}},I={attachmentWithPrefixExists:function(t){if(Object.prototype.hasOwnProperty.call(e,d.attachment)){var r=e[d.attachment],n=R(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:R,serialize:M,id:v,revision:b,idName:f,revisionName:h,specialNames:d,typeName:g,modelConfiguration:l,models:c,now:m,nowUTCTimestamp:u,securitySettings:o,userContext:n};if(e[d.attachment])for(var V,W=0,F=Object.values(e[d.attachment]);W<F.length;W++)V=F[W],Object.prototype.hasOwnProperty.call(V,"contentType")&&(V.content_type=V.contentType,delete V.contentType);var B=L(e,t);return(!B.newDocument._deleted||t)&&(B.newDocument._deleted&&B.newDocument._deleted!==(null==t?void 0:t._deleted)||B.changedPath.length)||s("NoChange: No new data given. new document: "+M(e)+"; old document: "+M(t)+"."),Object.prototype.hasOwnProperty.call(o,l.property.name.validatedDocumentsCache)?o[l.property.name.validatedDocumentsCache].add(v+"-"+b):o[l.property.name.validatedDocumentsCache]=new Set([v+"-"+b]),B.newDocument},e}();const p=c;module.exports=t})();
package/helper.d.ts CHANGED
@@ -1,12 +1,11 @@
1
- import { Mapping, ValueOf } from 'clientnode/type';
1
+ import { Mapping, ValueOf } from 'clientnode';
2
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.
6
6
  * @param configuration - Mutable by plugins extended configuration object.
7
- *
8
7
  * @returns Database compatible configuration object.
9
- */
8
+ */
10
9
  export declare const getConnectorOptions: (configuration: Configuration) => DatabaseConnectorConfiguration;
11
10
  /**
12
11
  * Determines a representation for given plain object.
@@ -15,7 +14,6 @@ export declare const getConnectorOptions: (configuration: Configuration) => Data
15
14
  * process.
16
15
  * @param maximumRepresentationLength - Maximum length of returned
17
16
  * representation.
18
- *
19
17
  * @returns Representation string.
20
18
  */
21
19
  export declare const mayStripRepresentation: (object: unknown, maximumRepresentationTryLength: number, maximumRepresentationLength: number) => string;
@@ -32,16 +30,14 @@ export declare const mayStripRepresentation: (object: unknown, maximumRepresenta
32
30
  * @param revisionName - Property name for revisions.
33
31
  * @param designDocumentNamePrefix - Document name prefix indicating deign
34
32
  * documents.
35
- *
36
33
  * @returns Promise which will be resolved after given document has updated
37
34
  * successfully.
38
35
  */
39
- export declare const ensureValidationDocumentPresence: (databaseConnection: Connection, documentName: string, documentData: Mapping, description: string, log?: boolean, idName?: SpecialPropertyNames['id'], revisionName?: SpecialPropertyNames['revision'], designDocumentNamePrefix?: string) => Promise<void>;
36
+ export declare const ensureValidationDocumentPresence: (databaseConnection: Connection, documentName: string, documentData: Mapping, description: string, log?: boolean, idName?: SpecialPropertyNames["id"], revisionName?: SpecialPropertyNames["revision"], designDocumentNamePrefix?: string) => Promise<void>;
40
37
  /**
41
38
  * Initializes a database connection instance.
42
39
  * @param services - An object with stored service instances.
43
40
  * @param configuration - Mutable by plugins extended configuration object.
44
- *
45
41
  * @returns Given and extended object of services.
46
42
  */
47
43
  export declare const initializeConnection: (services: Services, configuration: Configuration) => Promise<Services>;
@@ -49,22 +45,19 @@ export declare const initializeConnection: (services: Services, configuration: C
49
45
  * Determines a mapping of all models to roles who are allowed to edit
50
46
  * corresponding model instances.
51
47
  * @param modelConfiguration - Model specification object.
52
- *
53
48
  * @returns The mapping object.
54
49
  */
55
50
  export declare const determineAllowedModelRolesMapping: (modelConfiguration: ModelConfiguration) => AllowedModelRolesMapping;
56
51
  /**
57
52
  * Determines whether given value of a model is a property specification.
58
53
  * @param value - Value to analyze.
59
- *
60
54
  * @returns Boolean indicating the case.
61
55
  */
62
- export declare const isPropertySpecification: (value: ValueOf<Model>) => value is PropertySpecification<unknown, object>;
56
+ export declare const isPropertySpecification: (value: ValueOf<Model>) => value is PropertySpecification;
63
57
  /**
64
58
  * Determines all property names which are indexable in a generic manner.
65
59
  * @param modelConfiguration - Model specification object.
66
60
  * @param model - Model to determine property names from.
67
- *
68
61
  * @returns The mapping object.
69
62
  */
70
63
  export declare const determineGenericIndexablePropertyNames: (modelConfiguration: ModelConfiguration, model: Model) => Array<string>;
@@ -74,21 +67,18 @@ export declare const determineGenericIndexablePropertyNames: (modelConfiguration
74
67
  * @param models - Pool of models to extend from.
75
68
  * @param extendPropertyName - Property name which indicates model
76
69
  * inheritance.
77
- *
78
70
  * @returns Given model in extended version.
79
71
  */
80
- export declare const extendModel: (modelName: string, models: Mapping<Partial<Model>>, extendPropertyName?: SpecialPropertyNames['extend']) => Partial<Model>;
72
+ export declare const extendModel: (modelName: string, models: Mapping<Partial<Model>>, extendPropertyName?: SpecialPropertyNames["extend"]) => Partial<Model>;
81
73
  /**
82
74
  * Extend default specification with specific one.
83
75
  * @param modelConfiguration - Model specification object.
84
- *
85
76
  * @returns Models with extended specific specifications.
86
77
  */
87
78
  export declare const extendModels: (modelConfiguration: ModelConfiguration) => Models;
88
79
  /**
89
80
  * Convert given roles to its normalized representation.
90
- * @param roles - Unstructured roles description.
91
- *
81
+ * @param roles - Unstructured role' s description.
92
82
  * @returns Normalized roles representation.
93
83
  */
94
84
  export declare const normalizeAllowedRoles: (roles: AllowedRoles) => NormalizedAllowedRoles;
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:()=>h,determineGenericIndexablePropertyNames:()=>g,ensureValidationDocumentPresence:()=>b,extendModel:()=>x,extendModels:()=>w,getConnectorOptions:()=>f,initializeConnection:()=>v,isPropertySpecification:()=>m,mayStripRepresentation:()=>y,normalizeAllowedRoles:()=>O});var e=r(1),t=r.n(e),o=r(2),a=r.n(o),i=r(3),c=r.n(i),s=r(4),p=r.n(s);const l="1.0.642";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 d(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)?d(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 d(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 f=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)}}},y=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"},b=function(){var e=a()(c().mark((function e(r,n,o,a,i,s,u,d){var f,y,b;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===u&&(u="_rev"),void 0===d&&(d="_design/"),y=t()(((f={})[s]=""+d+n,f.language="javascript",f.version=l,f),o),e.prev=5,e.next=8,r.get(""+d+n);case 8:return b=e.sent,y[u]=b[u],e.next=12,r.put(y);case 12:i&&console.info(a+" updated."),e.next=27;break;case 15:return e.prev=15,e.t0=e.catch(5),i&&("not_found"===e.t0.error?console.info(a+" not available: create new one."):console.info(a+" couldn't be updated: \""+p().represent(e.t0)+'" create new one.')),e.prev=18,e.next=21,r.put(y);case 21:i&&console.info(a+" installed/updated."),e.next=27;break;case 24:throw e.prev=24,e.t1=e.catch(18),new Error(a+" couldn't be installed/updated: \""+p().represent(e.t1)+'".');case 27:case"end":return e.stop()}}),e,null,[[5,15],[18,24]])})));return function(){return e.apply(this,arguments)}}(),v=function(){var e=a()(c().mark((function e(t,r){var n,o,i,l,d,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,f(r)),(i=t.couchdb.connection).setMaxListeners(1/0),l=n.model.property.name.special.id,d=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){var o,a,i,s,p,u,f,y=arguments;return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(o=y.length,a=Array(1<o?o-1:0),i=1;i<o;i++)a[i-1]=y[i];return s=a.length&&"object"==typeof a[0]?a[0]:{},e.prev=2,e.next=5,t.apply(void 0,[r].concat(a));case 5:return e.abrupt("return",e.sent);case 8:if(e.prev=8,e.t0=e.catch(2),p=r[l],u=e.t0,!(p&&n.ignoreNoChangeError&&"name"in u&&"forbidden"===u.name&&"message"in u&&u.message.startsWith("NoChange:"))){e.next=25;break}if(f=d in s?s[d]:r[d],e.t1=p,!(d in r)||["latest","upsert"].includes(f)){e.next=19;break}e.t2=f,e.next=23;break;case 19:return e.next=21,this.get(p);case 21:e.t3=d,e.t2=e.sent[e.t3];case 23:return e.t4=e.t2,e.abrupt("return",{id:e.t1,rev:e.t4,ok:!0});case 25:throw u;case 26:case"end":return e.stop()}}),e,this,[[2,8]])})));case 3:case"end":return r.stop()}}),y)})),b=u(["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),console.info("Database could not be retrieved yet: Creating it."),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 r=e.property.name.special.allowedRole,n={},o=w(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:{}},O(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]=O(y.allowedRoles))}}else n[s]={properties:{},read:[],write:[]}}return n},m=function(e){return null!==e&&"object"==typeof e},g=function(e,t){var r=e.property.name.special;return Object.keys(t).filter((function(n){var o=t[n];return m(o)&&Object.prototype.hasOwnProperty.call(o,"index")&&o.index||m(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()},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]=p().extend(!0,p().copy(x(o,t,r)),t[e]);delete t[e][r]}return t[e]},w=function(e){for(var t,r=e.property.name.special,n={},o=e.property.name.typePattern,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]=x(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 g=m[h],w=g[0],O=g[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},O=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:()=>m,determineGenericIndexablePropertyNames:()=>x,ensureValidationDocumentPresence:()=>v,extendModel:()=>w,extendModels:()=>O,getConnectorOptions:()=>y,initializeConnection:()=>h,isPropertySpecification:()=>g,mayStripRepresentation:()=>b,normalizeAllowedRoles:()=>j});var o=r(1),a=r.n(o),i=r(2),c=r.n(i),s=r(3),l=r.n(s),p=r(4);const u="1.0.643";function d(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 f(e,t);var r={}.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)?f(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 f(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}var y=function(e){return e.couchdb.connector.fetch?{fetch:function(t,r){return p.globalContext.fetch(t,(0,p.extend)(!0,(0,p.copy)(e.couchdb.connector.fetch),r||{}))}}:{fetch:function(e,t){return p.globalContext.fetch(e,t)}}},b=function(e,t,r){var n=(0,p.represent)(e);return n.length<=t?n.length>r?n.substring(0,r-3)+"...":n:"DOCUMENT IS TOO BIG TO REPRESENT"},v=function(){var e=c()(l().mark((function e(t,r,n,o,i,c,s,d){var f,y,b;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return void 0===i&&(i=!0),void 0===c&&(c="_id"),void 0===s&&(s="_rev"),void 0===d&&(d="_design/"),y=a()(((f={})[c]=""+d+r,f.language="javascript",f.version=u,f),n),e.prev=5,e.next=8,t.get(""+d+r);case 8:return b=e.sent,y[s]=b[s],e.next=12,t.put(y);case 12:i&&console.info(o+" updated."),e.next=27;break;case 15:return e.prev=15,e.t0=e.catch(5),i&&("not_found"===e.t0.error?console.info(o+" not available: create new one."):console.info(o+" couldn't be updated: \""+(0,p.represent)(e.t0)+'" create new one.')),e.prev=18,e.next=21,t.put(y);case 21:i&&console.info(o+" installed/updated."),e.next=27;break;case 24:throw e.prev=24,e.t1=e.catch(18),new Error(o+" couldn't be installed/updated: \""+(0,p.represent)(e.t1)+'".');case 27:case"end":return e.stop()}}),e,null,[[5,15],[18,24]])})));return function(){return e.apply(this,arguments)}}(),h=function(){var e=c()(l().mark((function e(t,r){var n,o,a,i,s,u,f,b;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=r.couchdb,o=(0,p.format)(n.url,n.user.name+":"+n.user.password+"@")+"/"+n.databaseName,t.couchdb.connection=new t.couchdb.connector(o,y(r)),(a=t.couchdb.connection).setMaxListeners(1/0),i=n.model.property.name.special.id,s=n.model.property.name.special.revision,u=l().mark((function(){var e,t;return l().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:e=b.value,t=a[e].bind(a),a[e]=c()(l().mark((function e(r){var o,a,c,p,u,d,f,y=arguments;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(o=y.length,a=Array(1<o?o-1:0),c=1;c<o;c++)a[c-1]=y[c];return p=a.length&&"object"==typeof a[0]?a[0]:{},e.prev=2,e.next=5,t.apply(void 0,[r].concat(a));case 5:return e.abrupt("return",e.sent);case 8:if(e.prev=8,e.t0=e.catch(2),u=r[i],d=e.t0,!(u&&n.ignoreNoChangeError&&"name"in d&&"forbidden"===d.name&&"message"in d&&d.message.startsWith("NoChange:"))){e.next=25;break}if(f=s in p?p[s]:r[s],e.t1=u,!(s in r)||["latest","upsert"].includes(f)){e.next=19;break}e.t2=f,e.next=23;break;case 19:return e.next=21,this.get(u);case 21:e.t3=s,e.t2=e.sent[e.t3];case 23:return e.t4=e.t2,e.abrupt("return",{id:e.t1,rev:e.t4,ok:!0});case 25:throw d;case 26:case"end":return e.stop()}}),e,this,[[2,8]])})));case 3:case"end":return r.stop()}}),u)})),f=d(["post","put"]);case 9:if((b=f()).done){e.next=13;break}return e.delegateYield(u(),"t0",11);case 11:e.next=9;break;case 13:return e.prev=13,e.next=16,(0,p.checkReachability)(o);case 16:e.next=23;break;case 18:return e.prev=18,e.t1=e.catch(13),console.info("Database could not be retrieved yet: Creating it."),e.next=23,p.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)}}(),m=function(e){for(var t=e.property.name.special.allowedRole,r={},n=O(e),o=0,i=Object.entries(n);o<i.length;o++){var c=i[o],s=c[0],l=c[1];if(Object.prototype.hasOwnProperty.call(l,t)){r[s]=a()({properties:{}},j(l[t]));for(var p=0,u=Object.entries(l);p<u.length;p++){var d=u[p],f=d[0],y=d[1];null!==y&&"object"==typeof y&&y.allowedRoles&&(r[s].properties[f]=j(y.allowedRoles))}}else r[s]={properties:{},read:[],write:[]}}return r},g=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 g(o)&&Object.prototype.hasOwnProperty.call(o,"index")&&o.index||g(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()},w=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=d([].concat(t[e][r]));!(n=a()).done;)o=n.value,t[e]=(0,p.extend)(!0,(0,p.copy)(w(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.typePattern,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]=w(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 g=m[h],x=g[0],O=g[1];v[x]=(0,p.extend)(!0,(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]=(0,p.extend)(!0,(0,p.copy)(e.property.defaultSpecification),b))}}return n},j=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.d.ts CHANGED
@@ -3,8 +3,8 @@ import { ServicesState, State } from './type';
3
3
  /**
4
4
  * Launches an application server und triggers all some pluginable hooks on
5
5
  * an event.
6
- * @property static:toggleLatestRevisionDetermining - Token to provide to
7
- * "bulkDocs" method call to indicate id determination skip or not (depends on
6
+ * @property toggleLatestRevisionDetermining - Token to provide to "bulkDocs"
7
+ * method call to indicate id determination skip or not (depends on
8
8
  * "skipLatestRevisionDetermining" configuration).
9
9
  */
10
10
  export declare class Database implements PluginHandler {
@@ -15,7 +15,6 @@ export declare class Database implements PluginHandler {
15
15
  * @param state.configuration - Applications configuration.
16
16
  * @param state.configuration.couchdb - Plugins configuration.
17
17
  * @param state.services - Applications services.
18
- *
19
18
  * @returns Promise resolving to nothing.
20
19
  */
21
20
  static preLoadService({ configuration: { couchdb: configuration }, services }: ServicesState): Promise<void>;
@@ -25,7 +24,6 @@ export declare class Database implements PluginHandler {
25
24
  * @param state - Application state.
26
25
  * @param state.configuration - Applications configuration.
27
26
  * @param state.services - Applications services.
28
- *
29
27
  * @returns A mapping to promises which correspond to the plugin specific
30
28
  * continues services.
31
29
  */
@@ -34,7 +32,6 @@ export declare class Database implements PluginHandler {
34
32
  * Add database event listener to auto restart database server on
35
33
  * unexpected server issues.
36
34
  * @param state - Application state.
37
- *
38
35
  * @returns Promise resolving to nothing.
39
36
  */
40
37
  static postLoadService(state: State): Promise<void>;
@@ -43,7 +40,6 @@ export declare class Database implements PluginHandler {
43
40
  * @param state - Application state.
44
41
  * @param state.configuration - Applications configuration.
45
42
  * @param state.services - Applications services.
46
- *
47
43
  * @returns Promise resolving to nothing.
48
44
  */
49
45
  static shouldExit({ configuration, services }: State): Promise<void>;
package/index.js CHANGED
@@ -1 +1 @@
1
- (()=>{var __webpack_modules__=[(e,t,n)=>{"use strict";n.d(t,{determineAllowedModelRolesMapping:()=>y,determineGenericIndexablePropertyNames:()=>x,ensureValidationDocumentPresence:()=>b,extendModels:()=>v,getConnectorOptions:()=>m,initializeConnection:()=>h,mayStripRepresentation:()=>f});var r=n(1),o=n.n(r),a=n(2),c=n.n(a),_=n(3),i=n.n(_),s=n(4),l=n.n(s);const u="1.0.642";function p(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return d(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?d(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}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 d(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}var m=function(e){return e.couchdb.connector.fetch?{fetch:function(t,n){return s.globalContext.fetch(t,l().extend(!0,l().copy(e.couchdb.connector.fetch),n||{}))}}:{fetch:function(e,t){return s.globalContext.fetch(e,t)}}},f=function(e,t,n){var r=l().represent(e);return r.length<=t?r.length>n?r.substring(0,n-3)+"...":r:"DOCUMENT IS TOO BIG TO REPRESENT"},b=function(){var e=c()(i().mark((function e(t,n,r,a,c,_,s,p){var d,m,f;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="_rev"),void 0===p&&(p="_design/"),m=o()(((d={})[_]=""+p+n,d.language="javascript",d.version=u,d),r),e.prev=5,e.next=8,t.get(""+p+n);case 8:return f=e.sent,m[s]=f[s],e.next=12,t.put(m);case 12:c&&console.info(a+" updated."),e.next=27;break;case 15:return e.prev=15,e.t0=e.catch(5),c&&("not_found"===e.t0.error?console.info(a+" not available: create new one."):console.info(a+" couldn't be updated: \""+l().represent(e.t0)+'" create new one.')),e.prev=18,e.next=21,t.put(m);case 21:c&&console.info(a+" installed/updated."),e.next=27;break;case 24:throw e.prev=24,e.t1=e.catch(18),new Error(a+" couldn't be installed/updated: \""+l().represent(e.t1)+'".');case 27:case"end":return e.stop()}}),e,null,[[5,15],[18,24]])})));return function(){return e.apply(this,arguments)}}(),h=function(){var e=c()(i().mark((function e(t,n){var r,o,a,_,u,d,f,b;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:r=n.couchdb,o=l().stringFormat(r.url,r.user.name+":"+r.user.password+"@")+"/"+r.databaseName,t.couchdb.connection=new t.couchdb.connector(o,m(n)),(a=t.couchdb.connection).setMaxListeners(1/0),_=r.model.property.name.special.id,u=r.model.property.name.special.revision,d=i().mark((function(){var e,t;return i().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:e=b.value,t=a[e].bind(a),a[e]=c()(i().mark((function e(n){var o,a,c,s,l,p,d,m=arguments;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(o=m.length,a=Array(1<o?o-1:0),c=1;c<o;c++)a[c-1]=m[c];return s=a.length&&"object"==typeof a[0]?a[0]:{},e.prev=2,e.next=5,t.apply(void 0,[n].concat(a));case 5:return e.abrupt("return",e.sent);case 8:if(e.prev=8,e.t0=e.catch(2),l=n[_],p=e.t0,!(l&&r.ignoreNoChangeError&&"name"in p&&"forbidden"===p.name&&"message"in p&&p.message.startsWith("NoChange:"))){e.next=25;break}if(d=u in s?s[u]:n[u],e.t1=l,!(u in n)||["latest","upsert"].includes(d)){e.next=19;break}e.t2=d,e.next=23;break;case 19:return e.next=21,this.get(l);case 21:e.t3=u,e.t2=e.sent[e.t3];case 23:return e.t4=e.t2,e.abrupt("return",{id:e.t1,rev:e.t4,ok:!0});case 25:throw p;case 26:case"end":return e.stop()}}),e,this,[[2,8]])})));case 3:case"end":return n.stop()}}),d)})),f=p(["post","put"]);case 9:if((b=f()).done){e.next=13;break}return e.delegateYield(d(),"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),console.info("Database could not be retrieved yet: Creating it."),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,n={},r=v(e),a=0,c=Object.entries(r);a<c.length;a++){var _=c[a],i=_[0],s=_[1];if(Object.prototype.hasOwnProperty.call(s,t)){n[i]=o()({properties:{}},P(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&&(n[i].properties[d]=P(m.allowedRoles))}}else n[i]={properties:{},read:[],write:[]}}return n},O=function(e){return null!==e&&"object"==typeof e},x=function(e,t){var n=e.property.name.special;return Object.keys(t).filter((function(r){var o=t[r];return O(o)&&Object.prototype.hasOwnProperty.call(o,"index")&&o.index||O(o)&&!(Object.prototype.hasOwnProperty.call(o,"index")&&!o.index||e.property.name.reserved.concat(n.additional,n.allowedRole,n.attachment,n.conflict,n.constraint.execution,n.constraint.expression,n.deleted,n.deletedConflict,n.extend,n.maximumAggregatedSize,n.minimumAggregatedSize,n.oldType,n.id,n.revision,n.revisions,n.revisionsInformation,n.type).includes(r)||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([n.id,n.revision]).sort()},g=function(e,t,n){if(void 0===n&&(n="_extends"),"_base"===e)return t[e];if(Object.prototype.hasOwnProperty.call(t,"_base")&&(Object.prototype.hasOwnProperty.call(t[e],n)&&t[e][n]?t[e][n]=["_base"].concat(t[e][n]):t[e][n]="_base"),Object.prototype.hasOwnProperty.call(t[e],n)){for(var r,o,a=p([].concat(t[e][n]));!(r=a()).done;)o=r.value,t[e]=l().extend(!0,l().copy(g(o,t,n)),t[e]);delete t[e][n]}return t[e]},v=function(e){for(var t,n=e.property.name.special,r={},o=e.property.name.typePattern,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+'").');r[t]=g(t,e.entities,n.extend)}for(var _,i=0,s=Object.values(r);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===n.attachment)for(var b=f,h=0,y=Object.entries(b);h<y.length;h++){var O=y[h],x=O[0],v=O[1];b[x]=l().extend(!0,l().copy(e.property.defaultSpecification),v)}else[n.allowedRole,n.constraint.execution,n.constraint.expression,n.extend,n.maximumAggregatedSize,n.minimumAggregatedSize,n.oldType].includes(m)||(_[m]=l().extend(!0,l().copy(e.property.defaultSpecification),f))}}return r},P=function(e){if(Array.isArray(e))return{read:e,write:e};if("object"==typeof e){for(var t,n={read:[],write:[]},r=0,o=Object.keys(n);r<o.length;r++)t=o[r],Object.prototype.hasOwnProperty.call(e,t)&&(Array.isArray(e[t])?n[t]=e[t]:n[t]=[e[t]]);return n}return{read:[e],write:[e]}}},e=>{"use strict";e.exports=require("@babel/runtime/helpers/extends")},e=>{"use strict";e.exports=require("@babel/runtime/helpers/asyncToGenerator")},e=>{"use strict";e.exports=require("@babel/runtime/regenerator")},e=>{"use strict";e.exports=require("clientnode")},e=>{"use strict";e.exports=require("fs")},e=>{"use strict";e.exports=require("path")},e=>{!function(){"use strict";function t(e,t,o){if(n())return Reflect.construct.apply(null,arguments);var a=[null];a.push.apply(a,t);var c=new(e.bind.apply(e,a));return o&&r(c,o.prototype),c}function n(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(n=function(){return!!e})()}function r(e,t){return r=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},r(e,t)}function o(){return o=Object.assign?Object.assign.bind():function(e){for(var t,n=1;n<arguments.length;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},o.apply(this,arguments)}function a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return c(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?c(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function c(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}var _={d:function(e,t){for(var n in t)_.o(t,n)&&!_.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},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={};_.r(i),_.d(i,{DatabaseHelper:function(){return s},default:function(){return l}});var s=function(){function e(){}return e.authenticate=function(e,t,n,r,o,c,_,i,s){var l;void 0===t&&(t=null),void 0===n&&(n={}),void 0===r&&(r={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(n)if("name"in n||(n.name='"unknown"'),null!=(m=n.roles)&&m.length){if(o&&u&&Object.prototype.hasOwnProperty.call(o,u)){for(var b,h,y=o[u],O=a(["read","write"]);!(b=O()).done;)d[h=b.value]=d[h].concat(y[h]||[]);d.properties=y.properties}for(var x,g,v=d[p],P=a(n.roles);!(x=P()).done;)if(g=x.value,v.includes(g))return!0;f='Current user "'+n.name+'" owns the following roles: "'+n.roles.join('", "')+'"'}else f='Current user "'+n.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,n,r,c,_,i,s){void 0===i&&(i={});var l=function(e,t,n){var r;throw void 0===t&&(t="forbidden"),void 0===n&&(n={}),o(((r={})[t]=e,r.message=e,r.name=t,r),n)},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,h=m.type;n&&n[h]&&!e[h]&&(e[h]=n[h]);var y="",O="",x=function(){y=Object.prototype.hasOwnProperty.call(e,f)?e[f]:"",O=Object.prototype.hasOwnProperty.call(e,b)?e[b]:""};if(x(),Object.prototype.hasOwnProperty.call(c,_.property.name.validatedDocumentsCache)&&c[_.property.name.validatedDocumentsCache].has(y+"-"+O))return c[_.property.name.validatedDocumentsCache].delete(y+"-"+O),e;["latest","upsert"].includes(O)&&(n&&Object.prototype.hasOwnProperty.call(n,b)?O=e[b]=n[b]:"latest"===O?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],C=M[1];if(Object.prototype.hasOwnProperty.call(C,m.oldType)&&C[m.oldType])for(var k,A,T=a([].concat(C[m.oldType]));!(k=T()).done;)A=k.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():""},L=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},U=function(e,t,n){if(n.fileName){if(n.fileName.value)return n.fileName.value===t;if(n.fileName.pattern)return[].concat(n.fileName.pattern).some((function(e){return new RegExp(e).test(t)}))}return e===t},W=function(t,n){if(n||(n=e[m.attachment]),t){for(var r,o=0,a=Object.keys(n);o<a.length;o++)if((r=a[o]).startsWith(t))return r}else{var c=Object.keys(n);if(c.length)return c[0]}return null},B=function(e,n,r){void 0===n&&(n=!1),void 0===r&&(r={});var a=R(e);if(a){var c,_=(n?"return ":"")+a,i=o({},N,{code:_},r),s=Object.keys(i);try{c=t(Function,s.concat([_]))}catch(e){l(I(e),"compilation",{code:_,error:e,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(e){l(I(e),"runtime",{code:_,error:e,scope:i})}return u}l("No expression to evaluate provided.","empty")},K=function(e,n,r){void 0===r&&(r=[]);var o=r.length?" in "+r.join(" -> "):"",c=[],s=function(){Object.prototype.hasOwnProperty.call(e,h)||(n&&Object.prototype.hasOwnProperty.call(n,h)&&["fillUp","migrate"].includes(g)?e[h]=n[h]:l('Type: You have to specify a model type via property "'+h+'"'+o+".")),r.length||new RegExp(_.property.name.typePattern.public).test(e[h])||l('TypeName: You have to specify a model type which matches "'+_.property.name.typePattern.public+'" as public type (given "'+e[h]+'")'+o+"."),Object.prototype.hasOwnProperty.call(i,e[h])||(Object.prototype.hasOwnProperty.call(P,e[h])?e[h]=P[e[h]]:l('Model: Given model "'+e[h]+'" is not specified'+o+"."))};s();var u,p=e[h],y=i[p];Object.prototype.hasOwnProperty.call(y,m.additional)&&y[m.additional]&&(u=y[m.additional]);var O=function(c,_,i,s,u){void 0===u&&(u=["constraintExecution","constraintExpression"]);for(var d,m,f=a(u);!(d=f()).done;)if(m=d.value,Object.prototype.hasOwnProperty.call(i,m)){var b=void 0;try{b=B(i[m].evaluation,m.endsWith("Expression"),{checkPropertyContent:v,model:y,modelName:p,name:_,type:m,newDocument:e,newValue:c,oldDocument:n,oldValue:s,parentNames:r,pathDescription:o,propertySpecification:i})}catch(_){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(_)&&l('Compilation: Hook "'+m+'" has invalid code "'+_.code+'": "'+_.message+'"'+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(_)&&l('Runtime: Hook "'+m+'" has throw an error with code "'+_.code+'": "'+_.message+'"'+o+"."),!Object.prototype.hasOwnProperty.call(_,"empty"))throw _}if(b&&!b.result){var h=R(i[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 "'+_+'" should satisfy constraint "'+b.code+'" (given "'+I(c)+'")'+o+"."))}}},v=function(e,t,n,c){var _=[],s=[].concat(n.type?n.type:[]);"object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype&&!Object.prototype.hasOwnProperty.call(e,h)&&1===s.length&&Object.prototype.hasOwnProperty.call(i,s[0])&&(e[h]=s[0]);for(var u,p,m=!1,b=a(s);!(u=b()).done;)if(p=u.value,Object.prototype.hasOwnProperty.call(i,p)){if("object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype&&Object.prototype.hasOwnProperty.call(e,h)&&e[h]!==p&&"migrate"===g&&1===s.length&&(e[h]=p,_=r.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,r.concat(t+""));if(y.changedPath.length&&(_=y.changedPath),e=y.newDocument,I(e)===I({}))return{newValue:void 0,changedPath:_};m=!0;break}1===s.length&&l('NestedType: Under key "'+t+'" isn\'t of type "'+p+'" (given "'+I(e)+'" of type '+typeof e+")"+o+".")}else if("DateTime"===p){var x=e;if(e=L(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(x).replace(/^"/,"").replace(/"$/,"")+'" of type "'+typeof x+'")'+o+".")}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+'")'+o+".")}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+'")'+o+".")}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+'")'+o+".")}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+'")'+o+"."),"string"==typeof e&&("number"==typeof n.minimumLength&&e.length<n.minimumLength&&l('MinimalLength: Property "'+t+'" must have minimal length '+n.minimumLength+" (given "+e+" with length "+e.length+") "+o+"."),"number"==typeof n.maximumLength&&e.length>n.maximumLength&&l('MaximalLength: Property "'+t+'" must have maximal length '+n.maximumLength+" (given "+e+" with length "+e.length+")"+o+".")),"number"==typeof e&&("number"==typeof n.minimum&&e<n.minimum&&l('Minimum: Property "'+t+'" (type '+n.type+") must satisfy a minimum of "+n.minimum+" (given "+e+" is too low)"+o+"."),"number"==typeof n.maximum&&e>n.maximum&&l('Maximum: Property "'+t+'" (type '+n.type+") must satisfy a maximum of "+n.maximum+" (given "+e+" is too high)"+o+".")),n.selection){var P=Array.isArray(n.selection)?n.selection.map((function(e){return void 0===(null==e?void 0:e.value)?e:e.value})):Object.keys(n.selection);"DateTime"===n.type&&(P=P.map(L)),P.includes(e)||l('Selection: Property "'+t+'" (type '+n.type+') should be one of "'+P.join('", "')+'". But is "'+e+'"'+o+".")}if(n.pattern){for(var E,D,M=[].concat(n.pattern),w=!1,C=a(M);!(E=C()).done;)if(D=E.value,new RegExp(D).test(e)){w=!0;break}w||l('PatternMatch: Property "'+t+'" should match one regular expression pattern "'+M.join('", "')+'" (given "'+e+'")'+o+".")}if(n.invertedPattern)for(var k,A,T=a([].concat(n.invertedPattern));!(k=T()).done;)A=k.value,new RegExp(A).test(e)&&l('InvertedPatternMatch: Property "'+t+'" should not match regular expression pattern '+A+' (given "'+e+'")'+o+".");return O(e,t,n,c),I(e)!==I(c)&&(_=r.concat(t+"","value updated")),{newValue:e,changedPath:_}},E=function(e,t,n,o,a){var i=t[o];if(!e.writable)if(n){if(Object.prototype.hasOwnProperty.call(n,o)&&I(i)===I(n[o]))return o!==f&&"incremental"===g&&delete t[o],!0;l('Readonly: Property "'+o+'" is not writable (old document "'+I(n)+'")'+a+".")}else l('Readonly: Property "'+o+'" is not writable'+a+".");if(!e.mutable&&n&&Object.prototype.hasOwnProperty.call(n,o)){if(I(i)===I(n[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(n)+'")'+a+".")}if(null===i){if(e.nullable)return"incremental"===g&&n&&void 0!==n[o]||delete t[o],n&&Object.prototype.hasOwnProperty.call(n,o)&&(c=r.concat(o+"","delete property")),!0;l('NotNull: Property "'+o+'" should not be "null"'+a+".")}return!1},D=function(e,t,n,c,_){if(!n)for(var i,s,u=a(["onCreateExecution","onCreateExpression"]);!(i=u()).done;)if(s=i.value,Object.prototype.hasOwnProperty.call(e,s)){var d=void 0;try{d=B(e[s],s.endsWith("Expression"),{attachmentsTarget:_,checkPropertyContent:v,model:y,modelName:p,name:c+"",type:s,newDocument:t,oldDocument:n,newValue:void 0,oldValue:void 0,parentNames:r,pathDescription:o,propertySpecification:e})}catch(_){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(_)&&l('Compilation: Hook "'+s+'" has invalid code "'+_.code+'" for property "'+c+'": '+_.message+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(_)&&l('Runtime: Hook "'+s+'" has throw an error with code "'+_.code+'" for property "'+c+'": '+_.message+o+"."),!Object.prototype.hasOwnProperty.call(_,"empty"))throw _}d&&![null,void 0].includes(d.result)&&(_?_[c]=d.result:t[c]=d.result)}},M=function(e,t,n,c,_){if(!_){if(!Object.prototype.hasOwnProperty.call(t,c))return;e.trim&&"string"==typeof t[c]&&(t[c]=t[c].trim()),e.emptyEqualsNull&&(""===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,u=a(["onUpdateExecution","onUpdateExpression"]);!(i=u()).done;)if(s=i.value,Object.prototype.hasOwnProperty.call(e,s))try{var d=B(e[s],s.endsWith("Expression"),{attachmentsTarget:_,checkPropertyContent:v,model:y,modelName:p,name:c+"",type:s,newDocument:t,oldDocument:n,newValue:t[c],oldValue:n&&n[c]||void 0,parentNames:r,pathDescription:o,propertySpecification:e});_?_[c]=d.result:t[c]=d.result}catch(_){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(_)&&l('Compilation: Hook "'+s+'" has invalid code "'+_.code+'" for property "'+c+'": '+_.message+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(_)&&l('Runtime: Hook "'+s+'" has throw an error with code "'+_.code+'" for property "'+c+'": '+_.message+o+"."),!Object.prototype.hasOwnProperty.call(_,"empty"))throw _}},w=Object.keys(y).filter((function(e){return!j.includes(e)}));if("migrate"===g)for(var C,k,A=a(w);!(C=A()).done;)if(k=C.value,y[k].oldName)for(var T,W,N=a([].concat(y[k].oldName));!(T=N()).done;)W=T.value,Object.prototype.hasOwnProperty.call(e,W)&&(e[k]=e[W],delete e[W]);if(!n)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:n,parentNames:r,pathDescription:o}).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+o+"."),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+o+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}[null,void 0].includes(F)||(e=F),s(),p=e[h],0===r.length&&x()}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:n,parentNames:r,pathDescription:o}).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+o+"."),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+o+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}[void 0,null].includes(V)||(e=V),s(),p=e[h],0===r.length&&x()}for(var J,Y,X=u?Object.keys(e).filter((function(e){return!w.includes(e)})):[],Z=a(w.concat(X));!(J=Z()).done;)if(Y=J.value,m.attachment===Y)for(var Q=function(){var t=te[ee],_=t[0],i=t[1];Object.prototype.hasOwnProperty.call(e,Y)&&null!==e[m.attachment]||(e[m.attachment]={}),n&&!Object.prototype.hasOwnProperty.call(n,Y)&&(n[m.attachment]={});var s=Object.keys(e[m.attachment]).filter((function(t){return null!==e[m.attachment][t].data&&U(_,t,i)})),u=e[m.attachment],p=[];if(n){var d=n[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)&&!!U(_,e,i)}))}for(var f,b,h=i,y=a(s);!(f=y()).done;)b=f.value,D(h,e,n&&n[Y]?n[Y]:null,b,u);for(var O,x,v=a(s);!(O=v()).done;)x=O.value,M(h,e,n&&n[Y]?n[Y]:null,x,u);if(void 0===h.default){if(h.nullable||0<s.length||0<p.length||l('AttachmentMissing: Missing attachment for type "'+_+'"'+o+"."),"fillUp"===g&&0===s.length&&0<p.length)for(var P,E,w=a(p);!(P=w()).done;)E=P.value,null===u[E]?c=r.concat(Y,E,"file removed"):u[E]=n[Y][E]}else if(0===s.length)if(0===p.length)for(var C in h.default)Object.prototype.hasOwnProperty.call(h.default,C)&&(u[C]=h.default[C],c=r.concat(Y,_,"add default file"));else if("fillUp"===g)for(var k,A,T=a(p);!(k=T()).done;)A=k.value,u[A]=n[Y][A]},ee=0,te=Object.entries(y[m.attachment]);ee<te.length;ee++)Q();else{var ne=w.includes(Y)?y[Y]:u;D(ne,e,n,Y),M(ne,e,n,Y),[null,void 0].includes(ne.default)?(!(ne.nullable||Object.prototype.hasOwnProperty.call(e,Y)&&void 0!==e[Y]||n&&Object.prototype.hasOwnProperty.call(n,Y)&&g)&&l('MissingProperty: Missing property "'+Y+'"'+o+"."),(!Object.prototype.hasOwnProperty.call(e,Y)||void 0===e[Y])&&n&&Object.prototype.hasOwnProperty.call(n,Y)&&("fillUp"===g?e[Y]=n[Y]:!g&&(c=r.concat(Y+"","property removed")))):(!Object.prototype.hasOwnProperty.call(e,Y)||[null,void 0].includes(e[Y]))&&(n?null!==e[Y]&&"fillUp"===g?e[Y]=n[Y]:"migrate"===g&&(e[Y]=ne.default,c=r.concat(Y+"","migrate default value")):(e[Y]=ne.default,c=c.concat(Y+"","add default value")))}if(n&&"incremental"===g)for(var re=0,oe=Object.entries(e);re<oe.length;re++){var ae=oe[re],ce=ae[0],_e=ae[1];Object.prototype.hasOwnProperty.call(n,ce)&&!_.property.name.reserved.concat(f,b,m.conflict,m.deleted,m.deletedConflict,m.localSequence,m.revisions,m.revisionsInformation,h).includes(ce)&&(n[ce]===_e||I(n[ce])===I(_e))&&delete e[ce]}for(var ie=0,se=Object.entries(e);ie<se.length;ie++){var le=se[ie],ue=le[0],pe=le[1];if(!_.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=r.concat(ue+"","migrate removed property");continue}l('Property: Given property "'+ue+'" isn\'t specified in model "'+p+'"'+o+".")}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(U(be,fe,y[m.attachment][be])){E(y[m.attachment][be],e,n,fe,o);break}continue}if(E(de,e,n,ue,o))continue;var he="string"==typeof de.type&&de.type.endsWith("[]")||Array.isArray(de.type)&&de.type.length&&Array.isArray(de.type[0]);if(he&&![null,void 0].includes(pe)){var ye,Oe=pe;Array.isArray(Oe)?"number"==typeof de.minimumNumber&&Oe.length<de.minimumNumber?l('MinimumArrayLength: Property "'+ue+'" (array of length '+Oe.length+") doesn't fullfill minimum array length of "+de.minimumNumber+o+"."):"number"==typeof de.maximumNumber&&de.maximumNumber<Oe.length&&l('MaximumArrayLength: Property "'+ue+'" (array of length '+Oe.length+") doesn't fullfill maximum array length of "+de.maximumNumber+o+"."):l('PropertyType: Property "'+ue+'" isn\'t of type "array -> '+de.type+'" (given "'+I(Oe)+'")'+o+"."),O(Oe,ue+"",de,n&&Object.prototype.hasOwnProperty.call(n,ue)&&n[ue]||void 0,["arrayConstraintExecution","arrayConstraintExpression"]);var xe={};for(var ge in de)Object.prototype.hasOwnProperty.call(de,ge)&&(xe[ge]="type"===ge?Array.isArray(de[ge])?de[ge][0]:[de[ge].substring(0,de.type.length-2)]:de[ge]);if(1===(null==(ye=xe.type)?void 0:ye.length)&&Object.prototype.hasOwnProperty.call(i,xe.type[0]))for(var ve,Pe,Ee=a(Oe.slice());!(ve=Ee()).done;)"object"!=typeof(Pe=ve.value)||Object.getPrototypeOf(Pe)!==Object.prototype||Object.prototype.hasOwnProperty.call(Pe,h)||(Pe[h]=xe.type[0]);for(var De,Me,we=0,Ce=a(Oe.slice());!(De=Ce()).done;)Me=De.value,Oe[we]=v(Me,we+1+". value in "+ue,xe).newValue,[null,void 0].includes(Oe[we])&&Oe.splice(we,1),we+=1;n&&Object.prototype.hasOwnProperty.call(n,ue)&&Array.isArray(n[ue])&&n[ue].length===Oe.length&&I(n[ue])===I(Oe)||(c=r.concat(ue+"","array updated"))}else{var ke=n&&Object.prototype.hasOwnProperty.call(n,ue)?n[ue]:null,Ae=he?{newValue:null,changedPath:[]}:v(pe,ue+"",de,ke);e[ue]=Ae.newValue,Ae.changedPath.length&&(c=Ae.changedPath),[null,void 0].includes(e[ue])&&(null!==ke&&(c=r.concat(ue+"","property removed")),("incremental"!==g||null!==ke)&&delete e[ue])}}}for(var Te=0,je=Object.keys(m.constraint);Te<je.length;Te++){var Ie=je[Te],Re=m.constraint[Ie];if(Object.prototype.hasOwnProperty.call(y,Re))for(var Le,Ue=a([].concat(y[Re]));!(Le=Ue()).done;){var We=Le.value,Be=void 0;try{Be=B(We.evaluation,Re===m.constraint.expression,{checkPropertyContent:v,model:y,modelName:p,type:Re,newDocument:e,oldDocument:n,parentNames:r,pathDescription:o})}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&l('Compilation: Hook "'+Re+'" has invalid code "'+e.code+'": "'+e.message+'"'+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&l('Runtime: Hook "'+Re+'" has thrown an error with code "'+e.code+'": '+e.message+o+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}if(Be&&!Be.result){var Ke=Re.replace(/^[^a-zA-Z]+/,"");l(Ke.charAt(0).toUpperCase()+(Ke.substring(1)+": ")+(We.description?t(Function,Object.keys(Be.scope).concat(["return "+We.description.trim()])).apply(void 0,Object.values(Be.scope)):'Model "'+p+'" should satisfy constraint "'+Be.code+'" (given "'+I(e)+'")'+o+"."))}}}if(Object.prototype.hasOwnProperty.call(e,m.attachment)){var Ne=e[m.attachment];("object"!=typeof Ne||Object.getPrototypeOf(Ne)!==Object.prototype)&&l("AttachmentType: given attachment has invalid type"+o+".");var Se=null;if(n&&Object.prototype.hasOwnProperty.call(n,m.attachment)&&null!==(Se=n[m.attachment])&&"object"==typeof Se)for(var qe=0,$e=Object.entries(Se);qe<$e.length;qe++){var Fe=$e[qe],ze=Fe[0],He=Fe[1];if(Object.prototype.hasOwnProperty.call(Ne,ze)){var Ge=Ne[ze];null===Ge||null===Ge.data||Ge.content_type===He.content_type&&(Ge.data===He.data||Ge.digest===He.digest)?((null===Ge||null===Ge.data)&&(c=r.concat(m.attachment,ze,"attachment removed")),"incremental"===g&&delete Ne[ze]):c=r.concat(m.attachment,ze,"attachment updated")}else"fillUp"===g?Ne[ze]=He:g||(c=r.concat(m.attachment,ze,"attachment removed"))}for(var Ve=0,Je=Object.entries(Ne);Ve<Je.length;Ve++){var Ye=Je[Ve],Xe=Ye[0],Ze=Ye[1];[null,void 0].includes(Ze)||null===Ze.data?delete Ne[Xe]:(!Se||!Object.prototype.hasOwnProperty.call(Se,Xe)||Ze.content_type!==Se[Xe].content_type||Ze.data!==Se[Xe].data&&Ze.digest!==Se[Xe].digest)&&(c=r.concat(m.attachment,Xe,"attachment updated"))}0===Object.keys(Ne).length&&delete e[m.attachment];for(var Qe={},et=0,tt=Object.keys(y[m.attachment]);et<tt.length;et++)Qe[tt[et]]=[];for(var nt=0,rt=Object.keys(Ne);nt<rt.length;nt++){for(var ot=rt[nt],at=!1,ct=0,_t=Object.entries(y[m.attachment]);ct<_t.length;ct++){var it=_t[ct],st=it[0],lt=it[1];if(U(st,ot,lt)){Qe[st].push(ot),at=!0;break}}at||l('AttachmentTypeMatch: None of the specified attachment types ("'+Object.keys(y[m.attachment]).join('", "')+'") matches given one ("'+ot+'")'+o+".")}for(var ut=0,pt=0,dt=Object.keys(Qe);pt<dt.length;pt++){var mt=dt[pt],ft=y[m.attachment][mt];if(Object.prototype.hasOwnProperty.call(Qe,mt)){var bt=Qe[mt].length;"number"==typeof ft.maximumNumber&&bt>ft.maximumNumber&&l("AttachmentMaximum: given number of attachments ("+bt+") doesn't satisfy specified maximum of "+ft.maximumNumber+' from type "'+mt+'"'+o+"."),(!ft.nullable||0!==bt)&&"number"==typeof ft.minimumNumber&&bt<ft.minimumNumber&&l("AttachmentMinimum: given number of attachments ("+bt+") doesn't satisfy specified minimum of "+ft.minimumNumber+' from type "'+mt+'"'+o+".");for(var ht,yt=0,Ot=a(Qe[mt]);!(ht=Ot()).done;){var xt,gt,vt=ht.value;if(null!=(xt=ft.fileName)&&xt.pattern){for(var Pt,Et,Dt=[].concat(ft.fileName.pattern),Mt=!1,wt=a(Dt);!(Pt=wt()).done;)if(Et=Pt.value,new RegExp(Et).test(vt)){Mt=!0;break}Mt||l('AttachmentName: given attachment name "'+vt+'" doesn\'t satisfy one of specified regular expression patterns "'+Dt.join('", "')+'" from type "'+mt+'"'+o+".")}if(null!=(gt=ft.fileName)&&gt.invertedPattern)for(var Ct,kt,At=a([].concat(ft.fileName.invertedPattern));!(Ct=At()).done;)kt=Ct.value,new RegExp(kt).test(vt)&&l('InvertedAttachmentName: given attachment name "'+vt+'" does satisfy specified regular expression pattern "'+kt.toString()+'" from type "'+mt+'"'+o+".");if(Ne[vt].content_type){if(ft.contentTypePattern){for(var Tt,jt,It=[].concat(ft.contentTypePattern),Rt=!1,Lt=a(It);!(Tt=Lt()).done;)if(jt=Tt.value,new RegExp(jt).test(Ne[vt].content_type)){Rt=!0;break}Rt||l('AttachmentContentType: given attachment content type "'+Ne[vt].content_type+'" doesn\'t satisfy specified regular expression pattern "'+It.join('", "')+'" from type "'+mt+'"'+o+".")}var Ut=ft.invertedContentTypePattern;if(Ut)for(var Wt,Bt,Kt=a([].concat(Ut));!(Wt=Kt()).done;)Bt=Wt.value,new RegExp(Bt).test(Ne[vt].content_type)&&l('InvertedAttachmentContentType: given attachment content type "'+Ne[vt].content_type+'" does satisfy specified regular expression pattern "'+Bt.toString()+'" from type "'+mt+'"'+o+".")}var Nt=0;"length"in Ne[vt]?Nt=Ne[vt].length:"data"in Ne[vt]&&(Nt=Buffer&&"byteLength"in Buffer?Buffer.byteLength(Ne[vt].data,"base64"):Ne[vt].data.length),"number"==typeof ft.minimumSize&&ft.minimumSize>Nt?l("AttachmentMinimumSize: given attachment size "+Nt+" byte doesn't satisfy specified minimum of "+ft.minimumSize+" byte "+o+"."):"number"==typeof ft.maximumSize&&ft.maximumSize<Nt&&l("AttachmentMaximumSize: given attachment size "+Nt+" byte doesn't satisfy specified maximum of "+ft.maximumSize+" byte "+o+"."),yt+=Nt}"number"==typeof ft.minimumAggregatedSize&&ft.minimumAggregatedSize>yt?l('AttachmentAggregatedMinimumSize: given aggregated size of attachments from type "'+mt+'" '+yt+" byte doesn't satisfy specified minimum of "+ft.minimumAggregatedSize+" byte "+o+"."):"number"==typeof ft.maximumAggregatedSize&&ft.maximumAggregatedSize<yt&&l('AttachmentAggregatedMaximumSize: given aggregated size of attachments from type "'+mt+'" '+yt+" byte doesn't satisfy specified maximum of "+ft.maximumAggregatedSize+" byte "+o+"."),ut+=yt}}Object.prototype.hasOwnProperty.call(y,m.minimumAggregatedSize)&&"number"==typeof y[m.minimumAggregatedSize]&&y[m.minimumAggregatedSize]>ut?l("AggregatedMinimumSize: given aggregated size "+ut+" byte doesn't satisfy specified minimum of "+y[m.minimumAggregatedSize]+" byte "+o+"."):"number"==typeof y[m.maximumAggregatedSize]&&y[m.maximumAggregatedSize]<ut&&l("AggregatedMaximumSize: given aggregated size "+ut+" byte doesn't satisfy specified maximum of "+y[m.maximumAggregatedSize]+" byte "+o+".")}if(n&&Object.prototype.hasOwnProperty.call(n,m.attachment)&&0===Object.keys(n[m.attachment]).length&&delete n[m.attachment],0===c.length&&n&&"migrate"===g)for(var St,qt=0,$t=Object.keys(n);qt<$t.length;qt++)St=$t[qt],Object.prototype.hasOwnProperty.call(e,St)||(c=r.concat(St,"migrate removed property"));return{changedPath:c,newDocument:e}},N={attachmentWithPrefixExists:function(t){if(Object.prototype.hasOwnProperty.call(e,m.attachment)){var n=e[m.attachment],r=W(t);if(r)return Object.prototype.hasOwnProperty.call(n[r],"stub")&&n[r].stub||Object.prototype.hasOwnProperty.call(n[r],"data")&&![null,void 0].includes(n[r].data)}return!1},checkDocument:K,getFileNameByPrefix:W,serialize:I,id:y,revision:O,idName:f,revisionName:b,specialNames:m,typeName:h,modelConfiguration:_,models:i,now:u,nowUTCTimestamp:p,securitySettings:c,userContext:r};if(e[m.attachment])for(var S,q=0,$=Object.values(e[m.attachment]);q<$.length;q++)S=$[q],Object.prototype.hasOwnProperty.call(S,"contentType")&&(S.content_type=S.contentType,delete S.contentType);var F=K(e,n);return(!F.newDocument._deleted||n)&&(F.newDocument._deleted&&F.newDocument._deleted!==(null==n?void 0:n._deleted)||F.changedPath.length)||l("NoChange: No new data given. new document: "+I(e)+"; old document: "+I(n)+"."),Object.prototype.hasOwnProperty.call(c,_.property.name.validatedDocumentsCache)?c[_.property.name.validatedDocumentsCache].add(y+"-"+O):c[_.property.name.validatedDocumentsCache]=new Set([y+"-"+O]),F.newDocument},e}(),l=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__,{S8:()=>restart,ds:()=>stop,ni:()=>start});var _babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__(1),_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__(2),_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__(3),_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__(4),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__(0),_this=void 0;function _createForOfIteratorHelperLoose(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=_unsupportedIterableToArray(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}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 n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_arrayLikeToArray(e,t):void 0}}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}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 n,r,o=_createForOfIteratorHelperLoose(clientnode__WEBPACK_IMPORTED_MODULE_4__.CloseEventNames);!(n=o()).done;)r=n.value,server.process.on(r,clientnode__WEBPACK_IMPORTED_MODULE_4___default().getProcessCloseHandler(e,t,{process:server.process,reason:r}))})).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 n,r,o,a,c,_;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.configuration,r=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,n);case 7:return a.resolve=c,a.reject=_,e.next=11,start(o,n);case 11:return(0,_helper__WEBPACK_IMPORTED_MODULE_8__.initializeConnection)(o,n),e.next=14,r.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,n){var r,o;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.couchdb,o=n.couchdb,r.connection&&r.connection.close(),r.server.process&&r.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 n=__webpack_module_cache__[e]={exports:{}};return __webpack_modules__[e](n,n.exports,__webpack_require__),n.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 n in t)__webpack_require__.o(t,n)&&!__webpack_require__.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},__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__(1),_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__(2),_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__(3),_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__(4),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__(0),_server__WEBPACK_IMPORTED_MODULE_8__=__webpack_require__(14);function _createForOfIteratorHelperLoose(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=_unsupportedIterableToArray(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}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 n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_arrayLikeToArray(e,t):void 0}}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}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 n,r,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(n=t.configuration.couchdb,r=t.services,Object.prototype.hasOwnProperty.call(r,"couchdb")||(r.couchdb={}),o=r.couchdb,Object.prototype.hasOwnProperty.call(o,"connector")||(a=n.model.property.name.special.id,c=n.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 r,o,i,s,l,u,p,d,m,f,b,h,y,O,x,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.toggleLatestRevisionDetermining,u=l?!n.skipLatestRevisionDetermining:n.skipLatestRevisionDetermining,l&&i.pop(),p=!Array.isArray(t)&&null!==t&&"object"==typeof t&&a in t?[t]:t,null!=(r=n.connector.fetch)&&r.timeout&&(0===i.length||"object"!=typeof i[0])&&i.unshift({timeout:n.connector.fetch.timeout}),e.next=8,_.call.apply(_,[this,p].concat(i));case 8:d=e.sent,m=[],f=[],b=0,h=_createForOfIteratorHelperLoose(d);case 13:if((y=h()).done){e.next=36;break}if(O=y.value,"object"!=typeof p[b]){e.next=33;break}if(!(c in p[b])||"conflict"!==O.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]&&n.ignoreNoChangeError&&"name"in O&&"forbidden"===O.name&&"message"in O&&O.message.startsWith("NoChange:"))){e.next=33;break}if(d[b]={id:p[b][a],ok:!0},u){e.next=33;break}if(!(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.toggleLatestRevisionDetermining),e.next=41,this.bulkDocs.apply(this,[p].concat(i));case 41:for(x=e.sent,g=_createForOfIteratorHelperLoose(x);!(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)}}()}),n.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(n.binary.runner));case 8:if((l=s()).done){e.next=34;break}u=l.value,p=_createForOfIteratorHelperLoose([].concat(u.location));case 11:if((d=p()).done){e.next=30;break}m=d.value,f=_createForOfIteratorHelperLoose([].concat(u.name));case 14:if((b=f()).done){e.next=26;break}return h=b.value,y=(0,path__WEBPACK_IMPORTED_MODULE_5__.resolve)(m,h),i.push(y),e.next=20,clientnode__WEBPACK_IMPORTED_MODULE_3___default().isFile(y);case 20:if(!e.sent){e.next=24;break}return u.binaryFilePath=y,o.server.runner=u,e.abrupt("break",26);case 24:e.next=14;break;case 26:if(!Object.prototype.hasOwnProperty.call(o.server,"runner")){e.next=28;break}return e.abrupt("break",30);case 28:e.next=11;break;case 30:if(!Object.prototype.hasOwnProperty.call(o.server,"runner")){e.next=32;break}return e.abrupt("break",34);case 32:e.next=8;break;case 34:if(Object.prototype.hasOwnProperty.call(o.server,"runner")){e.next=36;break}throw new Error('No binary file in one of the following locations found: "'+i.join('", "')+'".');case 36:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),Database.loadService=function(){function loadService(){return _loadService.apply(this,arguments)}var _loadService=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function _callee3(_ref3){var configuration,services,promise,couchdb,urlPrefix,unauthenticatedUserDatabaseConnection,authenticatedUserDatabaseConnection,_i,_arr,type,_iterator6,_step6,name,userDatabaseConnection,_userDatabaseConnecti,_iterator7,_step7,prefix,subPath,fullPath,url,_value,response,changeNeeded,modelConfiguration,specialNames,idName,revisionName,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,documents,_iterator12,_step12,document,_forbidden,_iterator13,_step13,retrievedDocument,_document,newDocument,_iterator14,_step14,_name3,result,indexes,_i4,_Object$entries3,_Object$entries3$_i,_modelName,_model,_iterator15,_step15,propertyName,_name4,foundPosition,position,_iterator16,_step16,index,_iterator17,_step17,_index,exists,_i5,_Object$entries4,_Object$entries4$_i,_modelName2,_model2,_iterator18,_step18,_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__.ni)(services,configuration);case 6:couchdb.server.restart=_server__WEBPACK_IMPORTED_MODULE_8__.S8,couchdb.server.start=_server__WEBPACK_IMPORTED_MODULE_8__.ni,couchdb.server.stop=_server__WEBPACK_IMPORTED_MODULE_8__.ds,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 console.info('No admin user available. Automatically creating admin user "'+configuration.couchdb.user.name+'".'),_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),console.error("Can't login as existing admin user \""+configuration.couchdb.user.name+'": '+clientnode__WEBPACK_IMPORTED_MODULE_3___default().represent(_context3.t1));case 35:return _context3.prev=35,authenticatedUserDatabaseConnection.close(),_context3.finish(35);case 38:_context3.next=41;break;case 40:console.error("Can't create new admin user \""+configuration.couchdb.user.name+'": '+clientnode__WEBPACK_IMPORTED_MODULE_3___default().represent(_context3.t0));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),console.warn('Configuration "'+fullPath+'" (with desired value ['+clientnode__WEBPACK_IMPORTED_MODULE_3___default().represent(_value)+"]) couldn't be determined: "+clientnode__WEBPACK_IMPORTED_MODULE_3___default().represent(_context3.t6));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),console.warn('Error checking curent value of "'+fullPath+'" to be ['+clientnode__WEBPACK_IMPORTED_MODULE_3___default().represent(_value)+"]: "+clientnode__WEBPACK_IMPORTED_MODULE_3___default().represent(_context3.t9));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),console.error('Configuration "'+fullPath+"\" couldn't be applied to ["+clientnode__WEBPACK_IMPORTED_MODULE_3___default().represent(_value)+"]: "+clientnode__WEBPACK_IMPORTED_MODULE_3___default().represent(_context3.t10));case 124:_context3.next=127;break;case 126:console.info('Configuration "'+fullPath+'" is already set to desired value ['+clientnode__WEBPACK_IMPORTED_MODULE_3___default().represent(_value)+"].");case 127:_context3.next=130;break;case 129:console.info('Configuration "'+fullPath+'" does not exist (desired value ['+clientnode__WEBPACK_IMPORTED_MODULE_3___default().represent(_value)+"]). Response code is "+response.status+".");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),console.error("Security object couldn't be applied: "+clientnode__WEBPACK_IMPORTED_MODULE_3___default().represent(_context3.t11));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,revisionName=specialNames.revision,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&&console.debug(_type2.name+' code: \n\n"'+code+'" intgrated.'),_context3.next=169,(0,_helper__WEBPACK_IMPORTED_MODULE_9__.ensureValidationDocumentPresence)(couchdb.connection,_type2.name,{helper:databaseHelperCode,validate_doc_update:code},_type2.description,!0,idName,revisionName,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=319;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=271;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","deprecated"].includes(e.name)});case 222:_context3.t16=_context3.sent,_iterator11=(0,_context3.t15)(_context3.t16);case 224:if((_step11=_iterator11()).done){_context3.next=271;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=261;break}return documents=void 0,_context3.prev=230,_context3.t17=[],_context3.t18=JSON,_context3.next=235,fs__WEBPACK_IMPORTED_MODULE_4__.promises.readFile(file.path,{encoding:configuration.core.encoding,flag:"r"});case 235:_context3.t19=_context3.sent,_context3.t20=_context3.t18.parse.call(_context3.t18,_context3.t19),documents=_context3.t17.concat.call(_context3.t17,_context3.t20),_context3.next=243;break;case 240:throw _context3.prev=240,_context3.t21=_context3.catch(230),new Error('Parsing document "'+file.path+'" to include by automigration of has failed: '+clientnode__WEBPACK_IMPORTED_MODULE_3___default().represent(_context3.t21));case 243:1===documents.length&&(!documents[0][idName]&&(documents[0][idName]=_name2),!documents[0][revisionName]&&(documents[0][revisionName]="upsert")),_iterator12=_createForOfIteratorHelperLoose(documents);case 245:if((_step12=_iterator12()).done){_context3.next=259;break}return document=_step12.value,_context3.prev=247,_context3.next=250,couchdb.connection.put(document);case 250:_context3.next=256;break;case 252:throw _context3.prev=252,_context3.t22=_context3.catch(247),null!=(_forbidden=_context3.t22.forbidden)&&_forbidden.startsWith("NoChange:")&&console.info('Including document "'+document[idName]+'" of type "'+document[typeName]+"\" hasn't changed existing document."),new Error('Migrating document "'+document[idName]+'" of type "'+document[typeName]+'" has failed: '+clientnode__WEBPACK_IMPORTED_MODULE_3___default().represent(_context3.t22));case 256:console.info('Including document "'+document[idName]+'" of type "'+document[typeName]+'" was successful.');case 257:_context3.next=245;break;case 259:_context3.next=269;break;case 261:if(![".js"].includes((0,path__WEBPACK_IMPORTED_MODULE_5__.extname)(file.name))){_context3.next=265;break}migrators[file.path]=eval("require('"+file.path+"')").default,_context3.next=269;break;case 265:if(![".mjs"].includes((0,path__WEBPACK_IMPORTED_MODULE_5__.extname)(file.name))){_context3.next=269;break}return _context3.next=268,eval("import('"+file.path+"')");case 268:migrators[file.path]=_context3.sent.default;case 269:_context3.next=224;break;case 271:return _context3.t23=_createForOfIteratorHelperLoose,_context3.next=274,couchdb.connection.allDocs({include_docs:!0});case 274:_context3.t24=_context3.sent.rows,_iterator13=(0,_context3.t23)(_context3.t24);case 276:if((_step13=_iterator13()).done){_context3.next=319;break}if(retrievedDocument=_step13.value,"string"==typeof retrievedDocument.id&&retrievedDocument.id.startsWith(configuration.couchdb.model.property.name.special.designDocumentNamePrefix)){_context3.next=317;break}_document=retrievedDocument.doc,newDocument=clientnode__WEBPACK_IMPORTED_MODULE_3___default().copy(_document),newDocument[configuration.couchdb.model.property.name.special.strategy]="migrate",_iterator14=_createForOfIteratorHelperLoose(Object.keys(migrators).sort());case 283:if((_step14=_iterator14()).done){_context3.next=296;break}_name3=_step14.value,result=null,_context3.prev=286,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=293;break;case 290:throw _context3.prev=290,_context3.t25=_context3.catch(286),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.t25));case 293:result&&(newDocument=result,console.info('Running migrater "'+_name3+'" for document "'+newDocument[idName]+'" (of type "'+newDocument[typeName]+'") was successful.'));case 294:_context3.next=283;break;case 296:_context3.prev=296,_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=308;break;case 300:if(_context3.prev=300,_context3.t26=_context3.catch(296),!Object.prototype.hasOwnProperty.call(_context3.t26,"forbidden")){_context3.next=307;break}return _context3.t26.forbidden.startsWith("NoChange:")||console.warn('Document "'+(0,_helper__WEBPACK_IMPORTED_MODULE_9__.mayStripRepresentation)(_document,configuration.couchdb.maximumRepresentationTryLength,configuration.couchdb.maximumRepresentationLength)+"\" doesn't satisfy its schema (and can not be migrated automatically): "+clientnode__WEBPACK_IMPORTED_MODULE_3___default().represent(_context3.t26)),_context3.abrupt("continue",317);case 307:throw _context3.t26;case 308:return _context3.prev=308,_context3.next=311,couchdb.connection.put(newDocument);case 311:_context3.next=316;break;case 313:throw _context3.prev=313,_context3.t27=_context3.catch(308),new Error('Replacing auto migrated document "'+newDocument[idName]+'" has failed: '+clientnode__WEBPACK_IMPORTED_MODULE_3___default().represent(_context3.t27));case 316:console.info('Auto migrating document "'+newDocument[idName]+'" was successful.');case 317:_context3.next=276;break;case 319:if(!configuration.couchdb.createGenericFlatIndex||!configuration.couchdb.model.autoMigrationPath){_context3.next=374;break}return _context3.next=322,couchdb.connection.getIndexes();case 322:indexes=_context3.sent.indexes,_i4=0,_Object$entries3=Object.entries(models);case 324:if(!(_i4<_Object$entries3.length)){_context3.next=355;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.typePattern.public).test(_modelName)){_context3.next=352;break}return _context3.next=329,couchdb.connection.createIndex({index:{ddoc:_modelName+"-GenericIndex",fields:[typeName],name:_modelName+"-GenericIndex"}});case 329:_iterator15=_createForOfIteratorHelperLoose((0,_helper__WEBPACK_IMPORTED_MODULE_9__.determineGenericIndexablePropertyNames)(configuration.couchdb.model,_model));case 330:if((_step15=_iterator15()).done){_context3.next=352;break}propertyName=_step15.value,_name4=_modelName+"-"+propertyName+"-GenericIndex",foundPosition=-1,position=0,_iterator16=_createForOfIteratorHelperLoose(indexes);case 336:if((_step16=_iterator16()).done){_context3.next=344;break}if(index=_step16.value,index.name!==_name4){_context3.next=341;break}return foundPosition=position,_context3.abrupt("break",344);case 341:position+=1;case 342:_context3.next=336;break;case 344:if(-1!==foundPosition){_context3.next=349;break}return _context3.next=347,couchdb.connection.createIndex({index:{ddoc:_name4,fields:[typeName,propertyName],name:_name4}});case 347:_context3.next=350;break;case 349:indexes.slice(position,1);case 350:_context3.next=330;break;case 352:_i4++,_context3.next=324;break;case 355:_iterator17=_createForOfIteratorHelperLoose(indexes);case 356:if((_step17=_iterator17()).done){_context3.next=374;break}if(_index=_step17.value,!_index.name.endsWith("-GenericIndex")){_context3.next=372;break}exists=!1,_i5=0,_Object$entries4=Object.entries(models);case 361:if(!(_i5<_Object$entries4.length)){_context3.next=369;break}if(_Object$entries4$_i=_Object$entries4[_i5],_modelName2=_Object$entries4$_i[0],_model2=_Object$entries4$_i[1],!_index.name.startsWith(_modelName2+"-")){_context3.next=366;break}for(_iterator18=_createForOfIteratorHelperLoose((0,_helper__WEBPACK_IMPORTED_MODULE_9__.determineGenericIndexablePropertyNames)(configuration.couchdb.model,_model2));!(_step18=_iterator18()).done;)_name5=_step18.value,[_modelName2+"-"+_name5+"-GenericIndex",_modelName2+"-GenericIndex"].includes(_index.name)&&(exists=!0);return _context3.abrupt("break",369);case 366:_i5++,_context3.next=361;break;case 369:if(exists){_context3.next=372;break}return _context3.next=372,couchdb.connection.deleteIndex(_index);case 372:_context3.next=356;break;case 374:if(!configuration.couchdb.model.triggerInitialCompaction){_context3.next=383;break}return _context3.prev=375,_context3.next=378,couchdb.connection.compact();case 378:_context3.next=383;break;case 380:_context3.prev=380,_context3.t28=_context3.catch(375),console.warn("Initial database compaction has failed: "+clientnode__WEBPACK_IMPORTED_MODULE_3___default().represent(_context3.t28));case 383:return _context3.abrupt("return",{couchdb:promise});case 384: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,240],[247,252],[286,290],[296,300],[308,313],[375,380]])})));return loadService}(),Database.postLoadService=function(e){var t=e.configuration.couchdb,n=e.pluginAPI,r=e.services.couchdb,o=0;setInterval((function(){0<o&&(console.info("No additional errors (initially got "+o+" errors through) occurred during observing changes stream for 30 seconds. Clearing saved number of errors through."),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 r.changesStream&&r.changesStream.cancel(),r.changesStream=r.connection.changes(t.changesStream),r.changesStream.on("error",_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function t(n){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 console.warn("Observing changes feed throws an error for "+o+" times through: "+clientnode__WEBPACK_IMPORTED_MODULE_3___default().represent(n)+" Restarting database server and reinitialize changes stream..."),o=0,r.changesStream.cancel(),t.next=7,r.server.restart(e);case 7:t.next=10;break;case 9:console.warn("Observing changes feed throws an error for "+o+" times through: "+clientnode__WEBPACK_IMPORTED_MODULE_3___default().represent(n)+" Reinitializing changes stream...");case 10:a();case 11:case"end":return t.stop()}}),t)})))),c.next=5,n.callStack(_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({},e,{data:r.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 n,r,o;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.configuration,r=t.services,e.next=3,(0,_server__WEBPACK_IMPORTED_MODULE_8__.ds)(r,n);case 3:return delete r.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.toggleLatestRevisionDetermining=Symbol("toggleLatestRevisionDetermining");const __WEBPACK_DEFAULT_EXPORT__=Database})(),module.exports=__webpack_exports__})();
1
+ (()=>{var __webpack_modules__=[(e,t,n)=>{"use strict";n.d(t,{determineAllowedModelRolesMapping:()=>h,determineGenericIndexablePropertyNames:()=>O,ensureValidationDocumentPresence:()=>f,extendModels:()=>g,getConnectorOptions:()=>d,initializeConnection:()=>b,mayStripRepresentation:()=>m});var r=n(1),o=n.n(r),a=n(2),c=n.n(a),_=n(3),i=n.n(_),s=n(4);const l="1.0.643";function u(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return p(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?p(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}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 n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}var d=function(e){return e.couchdb.connector.fetch?{fetch:function(t,n){return s.globalContext.fetch(t,(0,s.extend)(!0,(0,s.copy)(e.couchdb.connector.fetch),n||{}))}}:{fetch:function(e,t){return s.globalContext.fetch(e,t)}}},m=function(e,t,n){var r=(0,s.represent)(e);return r.length<=t?r.length>n?r.substring(0,n-3)+"...":r:"DOCUMENT IS TOO BIG TO REPRESENT"},f=function(){var e=c()(i().mark((function e(t,n,r,a,c,_,u,p){var d,m,f;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return void 0===c&&(c=!0),void 0===_&&(_="_id"),void 0===u&&(u="_rev"),void 0===p&&(p="_design/"),m=o()(((d={})[_]=""+p+n,d.language="javascript",d.version=l,d),r),e.prev=5,e.next=8,t.get(""+p+n);case 8:return f=e.sent,m[u]=f[u],e.next=12,t.put(m);case 12:c&&console.info(a+" updated."),e.next=27;break;case 15:return e.prev=15,e.t0=e.catch(5),c&&("not_found"===e.t0.error?console.info(a+" not available: create new one."):console.info(a+" couldn't be updated: \""+(0,s.represent)(e.t0)+'" create new one.')),e.prev=18,e.next=21,t.put(m);case 21:c&&console.info(a+" installed/updated."),e.next=27;break;case 24:throw e.prev=24,e.t1=e.catch(18),new Error(a+" couldn't be installed/updated: \""+(0,s.represent)(e.t1)+'".');case 27:case"end":return e.stop()}}),e,null,[[5,15],[18,24]])})));return function(){return e.apply(this,arguments)}}(),b=function(){var e=c()(i().mark((function e(t,n){var r,o,a,_,l,p,m,f;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:r=n.couchdb,o=(0,s.format)(r.url,r.user.name+":"+r.user.password+"@")+"/"+r.databaseName,t.couchdb.connection=new t.couchdb.connector(o,d(n)),(a=t.couchdb.connection).setMaxListeners(1/0),_=r.model.property.name.special.id,l=r.model.property.name.special.revision,p=i().mark((function(){var e,t;return i().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:e=f.value,t=a[e].bind(a),a[e]=c()(i().mark((function e(n){var o,a,c,s,u,p,d,m=arguments;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(o=m.length,a=Array(1<o?o-1:0),c=1;c<o;c++)a[c-1]=m[c];return s=a.length&&"object"==typeof a[0]?a[0]:{},e.prev=2,e.next=5,t.apply(void 0,[n].concat(a));case 5:return e.abrupt("return",e.sent);case 8:if(e.prev=8,e.t0=e.catch(2),u=n[_],p=e.t0,!(u&&r.ignoreNoChangeError&&"name"in p&&"forbidden"===p.name&&"message"in p&&p.message.startsWith("NoChange:"))){e.next=25;break}if(d=l in s?s[l]:n[l],e.t1=u,!(l in n)||["latest","upsert"].includes(d)){e.next=19;break}e.t2=d,e.next=23;break;case 19:return e.next=21,this.get(u);case 21:e.t3=l,e.t2=e.sent[e.t3];case 23:return e.t4=e.t2,e.abrupt("return",{id:e.t1,rev:e.t4,ok:!0});case 25:throw p;case 26:case"end":return e.stop()}}),e,this,[[2,8]])})));case 3:case"end":return n.stop()}}),p)})),m=u(["post","put"]);case 9:if((f=m()).done){e.next=13;break}return e.delegateYield(p(),"t0",11);case 11:e.next=9;break;case 13:return e.prev=13,e.next=16,(0,s.checkReachability)(o);case 16:e.next=23;break;case 18:return e.prev=18,e.t1=e.catch(13),console.info("Database could not be retrieved yet: Creating it."),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,n={},r=g(e),a=0,c=Object.entries(r);a<c.length;a++){var _=c[a],i=_[0],s=_[1];if(Object.prototype.hasOwnProperty.call(s,t)){n[i]=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&&(n[i].properties[d]=v(m.allowedRoles))}}else n[i]={properties:{},read:[],write:[]}}return n},y=function(e){return null!==e&&"object"==typeof e},O=function(e,t){var n=e.property.name.special;return Object.keys(t).filter((function(r){var o=t[r];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(n.additional,n.allowedRole,n.attachment,n.conflict,n.constraint.execution,n.constraint.expression,n.deleted,n.deletedConflict,n.extend,n.maximumAggregatedSize,n.minimumAggregatedSize,n.oldType,n.id,n.revision,n.revisions,n.revisionsInformation,n.type).includes(r)||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([n.id,n.revision]).sort()},x=function(e,t,n){if(void 0===n&&(n="_extends"),"_base"===e)return t[e];if(Object.prototype.hasOwnProperty.call(t,"_base")&&(Object.prototype.hasOwnProperty.call(t[e],n)&&t[e][n]?t[e][n]=["_base"].concat(t[e][n]):t[e][n]="_base"),Object.prototype.hasOwnProperty.call(t[e],n)){for(var r,o,a=u([].concat(t[e][n]));!(r=a()).done;)o=r.value,t[e]=(0,s.extend)(!0,(0,s.copy)(x(o,t,n)),t[e]);delete t[e][n]}return t[e]},g=function(e){for(var t,n=e.property.name.special,r={},o=e.property.name.typePattern,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+'").');r[t]=x(t,e.entities,n.extend)}for(var _,i=0,l=Object.values(r);i<l.length;i++){_=l[i];for(var u=0,p=Object.entries(_);u<p.length;u++){var d=p[u],m=d[0],f=d[1];if(m===n.attachment)for(var b=f,h=0,y=Object.entries(b);h<y.length;h++){var O=y[h],g=O[0],v=O[1];b[g]=(0,s.extend)(!0,(0,s.copy)(e.property.defaultSpecification),v)}else[n.allowedRole,n.constraint.execution,n.constraint.expression,n.extend,n.maximumAggregatedSize,n.minimumAggregatedSize,n.oldType].includes(m)||(_[m]=(0,s.extend)(!0,(0,s.copy)(e.property.defaultSpecification),f))}}return r},v=function(e){if(Array.isArray(e))return{read:e,write:e};if("object"==typeof e){for(var t,n={read:[],write:[]},r=0,o=Object.keys(n);r<o.length;r++)t=o[r],Object.prototype.hasOwnProperty.call(e,t)&&(Array.isArray(e[t])?n[t]=e[t]:n[t]=[e[t]]);return n}return{read:[e],write:[e]}}},e=>{"use strict";e.exports=require("@babel/runtime/helpers/extends")},e=>{"use strict";e.exports=require("@babel/runtime/helpers/asyncToGenerator")},e=>{"use strict";e.exports=require("@babel/runtime/regenerator")},e=>{"use strict";e.exports=require("clientnode")},e=>{"use strict";e.exports=require("fs")},e=>{"use strict";e.exports=require("path")},e=>{!function(){"use strict";function t(e,t,o){if(r())return Reflect.construct.apply(null,arguments);var a=[null];a.push.apply(a,t);var c=new(e.bind.apply(e,a));return o&&n(c,o.prototype),c}function n(e,t){return n=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},n(e,t)}function r(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(r=function(){return!!e})()}function o(){return o=Object.assign?Object.assign.bind():function(e){for(var t,n=1;n<arguments.length;n++)for(var r in t=arguments[n])({}).hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},o.apply(null,arguments)}function a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return c(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?c(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function c(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}var _={d:function(e,t){for(var n in t)_.o(t,n)&&!_.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},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={};_.r(i),_.d(i,{DatabaseHelper:function(){return s},default:function(){return l}});var s=function(){function e(){}return e.authenticate=function(e,t,n,r,o,c,_,i,s){var l;void 0===t&&(t=null),void 0===n&&(n={}),void 0===r&&(r={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(n)if("name"in n||(n.name='"unknown"'),null!=(m=n.roles)&&m.length){if(o&&u&&Object.prototype.hasOwnProperty.call(o,u)){for(var b,h,y=o[u],O=a(["read","write"]);!(b=O()).done;)d[h=b.value]=d[h].concat(y[h]||[]);d.properties=y.properties}for(var x,g,v=d[p],E=a(n.roles);!(x=E()).done;)if(g=x.value,v.includes(g))return!0;f='Current user "'+n.name+'" owns the following roles: "'+n.roles.join('", "')+'"'}else f='Current user "'+n.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,n,r,c,_,i,s){void 0===i&&(i={});var l=function(e,t,n){var r;throw void 0===t&&(t="forbidden"),void 0===n&&(n={}),o(((r={})[t]=e,r.message=e,r.name=t,r),n)},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,h=m.type;n&&n[h]&&!e[h]&&(e[h]=n[h]);var y="",O="",x=function(){y=Object.prototype.hasOwnProperty.call(e,f)?e[f]:"",O=Object.prototype.hasOwnProperty.call(e,b)?e[b]:""};if(x(),Object.prototype.hasOwnProperty.call(c,_.property.name.validatedDocumentsCache)&&c[_.property.name.validatedDocumentsCache].has(y+"-"+O))return c[_.property.name.validatedDocumentsCache].delete(y+"-"+O),e;["latest","upsert"].includes(O)&&(n&&Object.prototype.hasOwnProperty.call(n,b)?O=e[b]=n[b]:"latest"===O?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,E={};if("migrate"===g)for(var P=0,D=Object.entries(i);P<D.length;P++){var M=D[P],w=M[0],C=M[1];if(Object.prototype.hasOwnProperty.call(C,m.oldType)&&C[m.oldType])for(var k,A,T=a([].concat(C[m.oldType]));!(k=T()).done;)A=k.value,E[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 I=[m.additional,m.allowedRole,m.constraint.execution,m.constraint.expression,m.create.execution,m.create.expression,m.extend,m.maximumAggregatedSize,m.minimumAggregatedSize,m.oldType,m.update.execution,m.update.expression],j=function(e){return e instanceof Error?""+e:v(e)},R=function(e){return"string"==typeof e?e.trim():""},L=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},U=function(e,t,n){if(n.fileName){if(n.fileName.value)return n.fileName.value===t;if(n.fileName.pattern)return[].concat(n.fileName.pattern).some((function(e){return new RegExp(e).test(t)}))}return e===t},W=function(t,n){if(n||(n=e[m.attachment]),t){for(var r,o=0,a=Object.keys(n);o<a.length;o++)if((r=a[o]).startsWith(t))return r}else{var c=Object.keys(n);if(c.length)return c[0]}return null},B=function(e,n,r){void 0===n&&(n=!1),void 0===r&&(r={});var a=R(e);if(a){var c,_=(n?"return ":"")+a,i=o({},N,{code:_},r),s=Object.keys(i);try{c=t(Function,s.concat([_]))}catch(e){l(j(e),"compilation",{code:_,error:e,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(e){l(j(e),"runtime",{code:_,error:e,scope:i})}return u}l("No expression to evaluate provided.","empty")},K=function(e,n,r){void 0===r&&(r=[]);var o=r.length?" in "+r.join(" -> "):"",c=[],s=function(){Object.prototype.hasOwnProperty.call(e,h)||(n&&Object.prototype.hasOwnProperty.call(n,h)&&["fillUp","migrate"].includes(g)?e[h]=n[h]:l('Type: You have to specify a model type via property "'+h+'"'+o+".")),r.length||new RegExp(_.property.name.typePattern.public).test(e[h])||l('TypeName: You have to specify a model type which matches "'+_.property.name.typePattern.public+'" as public type (given "'+e[h]+'")'+o+"."),Object.prototype.hasOwnProperty.call(i,e[h])||(Object.prototype.hasOwnProperty.call(E,e[h])?e[h]=E[e[h]]:l('Model: Given model "'+e[h]+'" is not specified'+o+"."))};s();var u,p=e[h],y=i[p];Object.prototype.hasOwnProperty.call(y,m.additional)&&y[m.additional]&&(u=y[m.additional]);var O=function(c,_,i,s,u){void 0===u&&(u=["constraintExecution","constraintExpression"]);for(var d,m,f=a(u);!(d=f()).done;)if(m=d.value,Object.prototype.hasOwnProperty.call(i,m)){var b=void 0;try{b=B(i[m].evaluation,m.endsWith("Expression"),{checkPropertyContent:v,model:y,modelName:p,name:_,type:m,newDocument:e,newValue:c,oldDocument:n,oldValue:s,parentNames:r,pathDescription:o,propertySpecification:i})}catch(_){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(_)&&l('Compilation: Hook "'+m+'" has invalid code "'+_.code+'": "'+_.message+'"'+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(_)&&l('Runtime: Hook "'+m+'" has throw an error with code "'+_.code+'": "'+_.message+'"'+o+"."),!Object.prototype.hasOwnProperty.call(_,"empty"))throw _}if(b&&!b.result){var h=R(i[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 "'+_+'" should satisfy constraint "'+b.code+'" (given "'+j(c)+'")'+o+"."))}}},v=function(e,t,n,c){var _=[],s=[].concat(n.type?n.type:[]);"object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype&&!Object.prototype.hasOwnProperty.call(e,h)&&1===s.length&&Object.prototype.hasOwnProperty.call(i,s[0])&&(e[h]=s[0]);for(var u,p,m=!1,b=a(s);!(u=b()).done;)if(p=u.value,Object.prototype.hasOwnProperty.call(i,p)){if("object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype&&Object.prototype.hasOwnProperty.call(e,h)&&e[h]!==p&&"migrate"===g&&1===s.length&&(e[h]=p,_=r.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,r.concat(t+""));if(y.changedPath.length&&(_=y.changedPath),e=y.newDocument,j(e)===j({}))return{newValue:void 0,changedPath:_};m=!0;break}1===s.length&&l('NestedType: Under key "'+t+'" isn\'t of type "'+p+'" (given "'+j(e)+'" of type '+typeof e+")"+o+".")}else if("DateTime"===p){var x=e;if(e=L(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"'+j(x).replace(/^"/,"").replace(/"$/,"")+'" of type "'+typeof x+'")'+o+".")}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 "'+j(e)+'" of type "'+typeof e+'")'+o+".")}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 "'+j(e)+'" of type "'+typeof e+'")'+o+".")}else{if("any"===p||j(e)===j(p)){m=!0;break}1===s.length&&l('PropertyType: Property "'+t+'" isn\'t value "'+p+'" (given "'+j(e).replace(/^"/,"").replace(/"$/,"")+'" of type "'+typeof e+'")'+o+".")}if(m||l('PropertyType: None of the specified types "'+s.join('", "')+'" for property "'+t+'" matches value "'+j(e).replace(/^"/,"").replace(/"$/,"")+e+'" of type "'+typeof e+'")'+o+"."),"string"==typeof e&&("number"==typeof n.minimumLength&&e.length<n.minimumLength&&l('MinimalLength: Property "'+t+'" must have minimal length '+n.minimumLength+" (given "+e+" with length "+e.length+") "+o+"."),"number"==typeof n.maximumLength&&e.length>n.maximumLength&&l('MaximalLength: Property "'+t+'" must have maximal length '+n.maximumLength+" (given "+e+" with length "+e.length+")"+o+".")),"number"==typeof e&&("number"==typeof n.minimum&&e<n.minimum&&l('Minimum: Property "'+t+'" (type '+n.type+") must satisfy a minimum of "+n.minimum+" (given "+e+" is too low)"+o+"."),"number"==typeof n.maximum&&e>n.maximum&&l('Maximum: Property "'+t+'" (type '+n.type+") must satisfy a maximum of "+n.maximum+" (given "+e+" is too high)"+o+".")),n.selection){var E=Array.isArray(n.selection)?n.selection.map((function(e){return void 0===(null==e?void 0:e.value)?e:e.value})):Object.keys(n.selection);"DateTime"===n.type&&(E=E.map(L)),E.includes(e)||l('Selection: Property "'+t+'" (type '+n.type+') should be one of "'+E.join('", "')+'". But is "'+e+'"'+o+".")}if(n.pattern){for(var P,D,M=[].concat(n.pattern),w=!1,C=a(M);!(P=C()).done;)if(D=P.value,new RegExp(D).test(e)){w=!0;break}w||l('PatternMatch: Property "'+t+'" should match one regular expression pattern "'+M.join('", "')+'" (given "'+e+'")'+o+".")}if(n.invertedPattern)for(var k,A,T=a([].concat(n.invertedPattern));!(k=T()).done;)A=k.value,new RegExp(A).test(e)&&l('InvertedPatternMatch: Property "'+t+'" should not match regular expression pattern '+A+' (given "'+e+'")'+o+".");return O(e,t,n,c),j(e)!==j(c)&&(_=r.concat(t+"","value updated")),{newValue:e,changedPath:_}},P=function(e,t,n,o,a){var i=t[o];if(!e.writable)if(n){if(Object.prototype.hasOwnProperty.call(n,o)&&j(i)===j(n[o]))return o!==f&&"incremental"===g&&delete t[o],!0;l('Readonly: Property "'+o+'" is not writable (old document "'+j(n)+'")'+a+".")}else l('Readonly: Property "'+o+'" is not writable'+a+".");if(!e.mutable&&n&&Object.prototype.hasOwnProperty.call(n,o)){if(j(i)===j(n[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 "'+j(n)+'")'+a+".")}if(null===i){if(e.nullable)return"incremental"===g&&n&&void 0!==n[o]||delete t[o],n&&Object.prototype.hasOwnProperty.call(n,o)&&(c=r.concat(o+"","delete property")),!0;l('NotNull: Property "'+o+'" should not be "null"'+a+".")}return!1},D=function(e,t,n,c,_){if(!n)for(var i,s,u=a(["onCreateExecution","onCreateExpression"]);!(i=u()).done;)if(s=i.value,Object.prototype.hasOwnProperty.call(e,s)){var d=void 0;try{d=B(e[s],s.endsWith("Expression"),{attachmentsTarget:_,checkPropertyContent:v,model:y,modelName:p,name:c+"",type:s,newDocument:t,oldDocument:n,newValue:void 0,oldValue:void 0,parentNames:r,pathDescription:o,propertySpecification:e})}catch(_){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(_)&&l('Compilation: Hook "'+s+'" has invalid code "'+_.code+'" for property "'+c+'": '+_.message+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(_)&&l('Runtime: Hook "'+s+'" has throw an error with code "'+_.code+'" for property "'+c+'": '+_.message+o+"."),!Object.prototype.hasOwnProperty.call(_,"empty"))throw _}d&&![null,void 0].includes(d.result)&&(_?_[c]=d.result:t[c]=d.result)}},M=function(e,t,n,c,_){if(!_){if(!Object.prototype.hasOwnProperty.call(t,c))return;e.trim&&"string"==typeof t[c]&&(t[c]=t[c].trim()),e.emptyEqualsNull&&(""===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,u=a(["onUpdateExecution","onUpdateExpression"]);!(i=u()).done;)if(s=i.value,Object.prototype.hasOwnProperty.call(e,s))try{var d=B(e[s],s.endsWith("Expression"),{attachmentsTarget:_,checkPropertyContent:v,model:y,modelName:p,name:c+"",type:s,newDocument:t,oldDocument:n,newValue:t[c],oldValue:n&&n[c]||void 0,parentNames:r,pathDescription:o,propertySpecification:e});_?_[c]=d.result:t[c]=d.result}catch(_){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(_)&&l('Compilation: Hook "'+s+'" has invalid code "'+_.code+'" for property "'+c+'": '+_.message+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(_)&&l('Runtime: Hook "'+s+'" has throw an error with code "'+_.code+'" for property "'+c+'": '+_.message+o+"."),!Object.prototype.hasOwnProperty.call(_,"empty"))throw _}},w=Object.keys(y).filter((function(e){return!I.includes(e)}));if("migrate"===g)for(var C,k,A=a(w);!(C=A()).done;)if(k=C.value,y[k].oldName)for(var T,W,N=a([].concat(y[k].oldName));!(T=N()).done;)W=T.value,Object.prototype.hasOwnProperty.call(e,W)&&(e[k]=e[W],delete e[W]);if(!n)for(var S,q=0,$=[m.create.execution,m.create.expression];q<$.length;q++)if(S=$[q],Object.prototype.hasOwnProperty.call(y,S)){var z=void 0;try{z=B(y[S],S.endsWith("Expression"),{checkPropertyContent:v,model:y,modelName:p,type:S,newDocument:e,oldDocument:n,parentNames:r,pathDescription:o}).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+o+"."),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+o+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}[null,void 0].includes(z)||(e=z),s(),p=e[h],0===r.length&&x()}for(var F,H=0,G=[m.update.execution,m.update.expression];H<G.length;H++)if(F=G[H],Object.prototype.hasOwnProperty.call(y,F)){var V=void 0;try{V=B(y[F],F.endsWith("Expression"),{checkPropertyContent:v,model:y,modelName:p,type:F,newDocument:e,oldDocument:n,parentNames:r,pathDescription:o}).result}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&l('Compilation: Hook "'+F+'" has invalid code "'+e.code+'" for document "'+p+'": '+e.message+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&l('Runtime: Hook "'+F+'" has throw an error with code "'+e.code+'" for document "'+p+'": '+e.message+o+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}[void 0,null].includes(V)||(e=V),s(),p=e[h],0===r.length&&x()}for(var J,Y,X=u?Object.keys(e).filter((function(e){return!w.includes(e)})):[],Z=a(w.concat(X));!(J=Z()).done;)if(Y=J.value,m.attachment===Y)for(var Q=function(){var t=te[ee],_=t[0],i=t[1];Object.prototype.hasOwnProperty.call(e,Y)&&null!==e[m.attachment]||(e[m.attachment]={}),n&&!Object.prototype.hasOwnProperty.call(n,Y)&&(n[m.attachment]={});var s=Object.keys(e[m.attachment]).filter((function(t){return null!==e[m.attachment][t].data&&U(_,t,i)})),u=e[m.attachment],p=[];if(n){var d=n[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)&&!!U(_,e,i)}))}for(var f,b,h=i,y=a(s);!(f=y()).done;)b=f.value,D(h,e,n&&n[Y]?n[Y]:null,b,u);for(var O,x,v=a(s);!(O=v()).done;)x=O.value,M(h,e,n&&n[Y]?n[Y]:null,x,u);if(void 0===h.default){if(h.nullable||0<s.length||0<p.length||l('AttachmentMissing: Missing attachment for type "'+_+'"'+o+"."),"fillUp"===g&&0===s.length&&0<p.length)for(var E,P,w=a(p);!(E=w()).done;)P=E.value,null===u[P]?c=r.concat(Y,P,"file removed"):u[P]=n[Y][P]}else if(0===s.length)if(0===p.length)for(var C in h.default)Object.prototype.hasOwnProperty.call(h.default,C)&&(u[C]=h.default[C],c=r.concat(Y,_,"add default file"));else if("fillUp"===g)for(var k,A,T=a(p);!(k=T()).done;)A=k.value,u[A]=n[Y][A]},ee=0,te=Object.entries(y[m.attachment]);ee<te.length;ee++)Q();else{var ne=w.includes(Y)?y[Y]:u;D(ne,e,n,Y),M(ne,e,n,Y),[null,void 0].includes(ne.default)?(!(ne.nullable||Object.prototype.hasOwnProperty.call(e,Y)&&void 0!==e[Y]||n&&Object.prototype.hasOwnProperty.call(n,Y)&&g)&&l('MissingProperty: Missing property "'+Y+'"'+o+"."),(!Object.prototype.hasOwnProperty.call(e,Y)||void 0===e[Y])&&n&&Object.prototype.hasOwnProperty.call(n,Y)&&("fillUp"===g?e[Y]=n[Y]:!g&&(c=r.concat(Y+"","property removed")))):(!Object.prototype.hasOwnProperty.call(e,Y)||[null,void 0].includes(e[Y]))&&(n?null!==e[Y]&&"fillUp"===g?e[Y]=n[Y]:"migrate"===g&&(e[Y]=ne.default,c=r.concat(Y+"","migrate default value")):(e[Y]=ne.default,c=c.concat(Y+"","add default value")))}if(n&&"incremental"===g)for(var re=0,oe=Object.entries(e);re<oe.length;re++){var ae=oe[re],ce=ae[0],_e=ae[1];Object.prototype.hasOwnProperty.call(n,ce)&&!_.property.name.reserved.concat(f,b,m.conflict,m.deleted,m.deletedConflict,m.localSequence,m.revisions,m.revisionsInformation,h).includes(ce)&&(n[ce]===_e||j(n[ce])===j(_e))&&delete e[ce]}for(var ie=0,se=Object.entries(e);ie<se.length;ie++){var le=se[ie],ue=le[0],pe=le[1];if(!_.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=r.concat(ue+"","migrate removed property");continue}l('Property: Given property "'+ue+'" isn\'t specified in model "'+p+'"'+o+".")}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(U(be,fe,y[m.attachment][be])){P(y[m.attachment][be],e,n,fe,o);break}continue}if(P(de,e,n,ue,o))continue;var he="string"==typeof de.type&&de.type.endsWith("[]")||Array.isArray(de.type)&&de.type.length&&Array.isArray(de.type[0]);if(he&&![null,void 0].includes(pe)){var ye,Oe=pe;Array.isArray(Oe)?"number"==typeof de.minimumNumber&&Oe.length<de.minimumNumber?l('MinimumArrayLength: Property "'+ue+'" (array of length '+Oe.length+") doesn't fullfill minimum array length of "+de.minimumNumber+o+"."):"number"==typeof de.maximumNumber&&de.maximumNumber<Oe.length&&l('MaximumArrayLength: Property "'+ue+'" (array of length '+Oe.length+") doesn't fullfill maximum array length of "+de.maximumNumber+o+"."):l('PropertyType: Property "'+ue+'" isn\'t of type "array -> '+de.type+'" (given "'+j(Oe)+'")'+o+"."),O(Oe,ue+"",de,n&&Object.prototype.hasOwnProperty.call(n,ue)&&n[ue]||void 0,["arrayConstraintExecution","arrayConstraintExpression"]);var xe={};for(var ge in de)Object.prototype.hasOwnProperty.call(de,ge)&&(xe[ge]="type"===ge?Array.isArray(de[ge])?de[ge][0]:[de[ge].substring(0,de.type.length-2)]:de[ge]);if(1===(null==(ye=xe.type)?void 0:ye.length)&&Object.prototype.hasOwnProperty.call(i,xe.type[0]))for(var ve,Ee,Pe=a(Oe.slice());!(ve=Pe()).done;)"object"!=typeof(Ee=ve.value)||Object.getPrototypeOf(Ee)!==Object.prototype||Object.prototype.hasOwnProperty.call(Ee,h)||(Ee[h]=xe.type[0]);for(var De,Me,we=0,Ce=a(Oe.slice());!(De=Ce()).done;)Me=De.value,Oe[we]=v(Me,we+1+". value in "+ue,xe).newValue,[null,void 0].includes(Oe[we])&&Oe.splice(we,1),we+=1;n&&Object.prototype.hasOwnProperty.call(n,ue)&&Array.isArray(n[ue])&&n[ue].length===Oe.length&&j(n[ue])===j(Oe)||(c=r.concat(ue+"","array updated"))}else{var ke=n&&Object.prototype.hasOwnProperty.call(n,ue)?n[ue]:null,Ae=he?{newValue:null,changedPath:[]}:v(pe,ue+"",de,ke);e[ue]=Ae.newValue,Ae.changedPath.length&&(c=Ae.changedPath),[null,void 0].includes(e[ue])&&(null!==ke&&(c=r.concat(ue+"","property removed")),("incremental"!==g||null!==ke)&&delete e[ue])}}}for(var Te=0,Ie=Object.keys(m.constraint);Te<Ie.length;Te++){var je=Ie[Te],Re=m.constraint[je];if(Object.prototype.hasOwnProperty.call(y,Re))for(var Le,Ue=a([].concat(y[Re]));!(Le=Ue()).done;){var We=Le.value,Be=void 0;try{Be=B(We.evaluation,Re===m.constraint.expression,{checkPropertyContent:v,model:y,modelName:p,type:Re,newDocument:e,oldDocument:n,parentNames:r,pathDescription:o})}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&l('Compilation: Hook "'+Re+'" has invalid code "'+e.code+'": "'+e.message+'"'+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&l('Runtime: Hook "'+Re+'" has thrown an error with code "'+e.code+'": '+e.message+o+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}if(Be&&!Be.result){var Ke=Re.replace(/^[^a-zA-Z]+/,"");l(Ke.charAt(0).toUpperCase()+(Ke.substring(1)+": ")+(We.description?t(Function,Object.keys(Be.scope).concat(["return "+We.description.trim()])).apply(void 0,Object.values(Be.scope)):'Model "'+p+'" should satisfy constraint "'+Be.code+'" (given "'+j(e)+'")'+o+"."))}}}if(Object.prototype.hasOwnProperty.call(e,m.attachment)){var Ne=e[m.attachment];("object"!=typeof Ne||Object.getPrototypeOf(Ne)!==Object.prototype)&&l("AttachmentType: given attachment has invalid type"+o+".");var Se=null;if(n&&Object.prototype.hasOwnProperty.call(n,m.attachment)&&null!==(Se=n[m.attachment])&&"object"==typeof Se)for(var qe=0,$e=Object.entries(Se);qe<$e.length;qe++){var ze=$e[qe],Fe=ze[0],He=ze[1];if(Object.prototype.hasOwnProperty.call(Ne,Fe)){var Ge=Ne[Fe];null===Ge||null===Ge.data||Ge.content_type===He.content_type&&(Ge.data===He.data||Ge.digest===He.digest)?((null===Ge||null===Ge.data)&&(c=r.concat(m.attachment,Fe,"attachment removed")),"incremental"===g&&delete Ne[Fe]):c=r.concat(m.attachment,Fe,"attachment updated")}else"fillUp"===g?Ne[Fe]=He:g||(c=r.concat(m.attachment,Fe,"attachment removed"))}for(var Ve=0,Je=Object.entries(Ne);Ve<Je.length;Ve++){var Ye=Je[Ve],Xe=Ye[0],Ze=Ye[1];[null,void 0].includes(Ze)||null===Ze.data?delete Ne[Xe]:(!Se||!Object.prototype.hasOwnProperty.call(Se,Xe)||Ze.content_type!==Se[Xe].content_type||Ze.data!==Se[Xe].data&&Ze.digest!==Se[Xe].digest)&&(c=r.concat(m.attachment,Xe,"attachment updated"))}0===Object.keys(Ne).length&&delete e[m.attachment];for(var Qe={},et=0,tt=Object.keys(y[m.attachment]);et<tt.length;et++)Qe[tt[et]]=[];for(var nt=0,rt=Object.keys(Ne);nt<rt.length;nt++){for(var ot=rt[nt],at=!1,ct=0,_t=Object.entries(y[m.attachment]);ct<_t.length;ct++){var it=_t[ct],st=it[0],lt=it[1];if(U(st,ot,lt)){Qe[st].push(ot),at=!0;break}}at||l('AttachmentTypeMatch: None of the specified attachment types ("'+Object.keys(y[m.attachment]).join('", "')+'") matches given one ("'+ot+'")'+o+".")}for(var ut=0,pt=0,dt=Object.keys(Qe);pt<dt.length;pt++){var mt=dt[pt],ft=y[m.attachment][mt];if(Object.prototype.hasOwnProperty.call(Qe,mt)){var bt=Qe[mt].length;"number"==typeof ft.maximumNumber&&bt>ft.maximumNumber&&l("AttachmentMaximum: given number of attachments ("+bt+") doesn't satisfy specified maximum of "+ft.maximumNumber+' from type "'+mt+'"'+o+"."),(!ft.nullable||0!==bt)&&"number"==typeof ft.minimumNumber&&bt<ft.minimumNumber&&l("AttachmentMinimum: given number of attachments ("+bt+") doesn't satisfy specified minimum of "+ft.minimumNumber+' from type "'+mt+'"'+o+".");for(var ht,yt=0,Ot=a(Qe[mt]);!(ht=Ot()).done;){var xt,gt,vt=ht.value;if(null!=(xt=ft.fileName)&&xt.pattern){for(var Et,Pt,Dt=[].concat(ft.fileName.pattern),Mt=!1,wt=a(Dt);!(Et=wt()).done;)if(Pt=Et.value,new RegExp(Pt).test(vt)){Mt=!0;break}Mt||l('AttachmentName: given attachment name "'+vt+'" doesn\'t satisfy one of specified regular expression patterns "'+Dt.join('", "')+'" from type "'+mt+'"'+o+".")}if(null!=(gt=ft.fileName)&&gt.invertedPattern)for(var Ct,kt,At=a([].concat(ft.fileName.invertedPattern));!(Ct=At()).done;)kt=Ct.value,new RegExp(kt).test(vt)&&l('InvertedAttachmentName: given attachment name "'+vt+'" does satisfy specified regular expression pattern "'+kt.toString()+'" from type "'+mt+'"'+o+".");if(Ne[vt].content_type){if(ft.contentTypePattern){for(var Tt,It,jt=[].concat(ft.contentTypePattern),Rt=!1,Lt=a(jt);!(Tt=Lt()).done;)if(It=Tt.value,new RegExp(It).test(Ne[vt].content_type)){Rt=!0;break}Rt||l('AttachmentContentType: given attachment content type "'+Ne[vt].content_type+'" doesn\'t satisfy specified regular expression pattern "'+jt.join('", "')+'" from type "'+mt+'"'+o+".")}var Ut=ft.invertedContentTypePattern;if(Ut)for(var Wt,Bt,Kt=a([].concat(Ut));!(Wt=Kt()).done;)Bt=Wt.value,new RegExp(Bt).test(Ne[vt].content_type)&&l('InvertedAttachmentContentType: given attachment content type "'+Ne[vt].content_type+'" does satisfy specified regular expression pattern "'+Bt.toString()+'" from type "'+mt+'"'+o+".")}var Nt=0;"length"in Ne[vt]?Nt=Ne[vt].length:"data"in Ne[vt]&&(Nt=Buffer&&"byteLength"in Buffer?Buffer.byteLength(Ne[vt].data,"base64"):Ne[vt].data.length),"number"==typeof ft.minimumSize&&ft.minimumSize>Nt?l("AttachmentMinimumSize: given attachment size "+Nt+" byte doesn't satisfy specified minimum of "+ft.minimumSize+" byte "+o+"."):"number"==typeof ft.maximumSize&&ft.maximumSize<Nt&&l("AttachmentMaximumSize: given attachment size "+Nt+" byte doesn't satisfy specified maximum of "+ft.maximumSize+" byte "+o+"."),yt+=Nt}"number"==typeof ft.minimumAggregatedSize&&ft.minimumAggregatedSize>yt?l('AttachmentAggregatedMinimumSize: given aggregated size of attachments from type "'+mt+'" '+yt+" byte doesn't satisfy specified minimum of "+ft.minimumAggregatedSize+" byte "+o+"."):"number"==typeof ft.maximumAggregatedSize&&ft.maximumAggregatedSize<yt&&l('AttachmentAggregatedMaximumSize: given aggregated size of attachments from type "'+mt+'" '+yt+" byte doesn't satisfy specified maximum of "+ft.maximumAggregatedSize+" byte "+o+"."),ut+=yt}}Object.prototype.hasOwnProperty.call(y,m.minimumAggregatedSize)&&"number"==typeof y[m.minimumAggregatedSize]&&y[m.minimumAggregatedSize]>ut?l("AggregatedMinimumSize: given aggregated size "+ut+" byte doesn't satisfy specified minimum of "+y[m.minimumAggregatedSize]+" byte "+o+"."):"number"==typeof y[m.maximumAggregatedSize]&&y[m.maximumAggregatedSize]<ut&&l("AggregatedMaximumSize: given aggregated size "+ut+" byte doesn't satisfy specified maximum of "+y[m.maximumAggregatedSize]+" byte "+o+".")}if(n&&Object.prototype.hasOwnProperty.call(n,m.attachment)&&0===Object.keys(n[m.attachment]).length&&delete n[m.attachment],0===c.length&&n&&"migrate"===g)for(var St,qt=0,$t=Object.keys(n);qt<$t.length;qt++)St=$t[qt],Object.prototype.hasOwnProperty.call(e,St)||(c=r.concat(St,"migrate removed property"));return{changedPath:c,newDocument:e}},N={attachmentWithPrefixExists:function(t){if(Object.prototype.hasOwnProperty.call(e,m.attachment)){var n=e[m.attachment],r=W(t);if(r)return Object.prototype.hasOwnProperty.call(n[r],"stub")&&n[r].stub||Object.prototype.hasOwnProperty.call(n[r],"data")&&![null,void 0].includes(n[r].data)}return!1},checkDocument:K,getFileNameByPrefix:W,serialize:j,id:y,revision:O,idName:f,revisionName:b,specialNames:m,typeName:h,modelConfiguration:_,models:i,now:u,nowUTCTimestamp:p,securitySettings:c,userContext:r};if(e[m.attachment])for(var S,q=0,$=Object.values(e[m.attachment]);q<$.length;q++)S=$[q],Object.prototype.hasOwnProperty.call(S,"contentType")&&(S.content_type=S.contentType,delete S.contentType);var z=K(e,n);return(!z.newDocument._deleted||n)&&(z.newDocument._deleted&&z.newDocument._deleted!==(null==n?void 0:n._deleted)||z.changedPath.length)||l("NoChange: No new data given. new document: "+j(e)+"; old document: "+j(n)+"."),Object.prototype.hasOwnProperty.call(c,_.property.name.validatedDocumentsCache)?c[_.property.name.validatedDocumentsCache].add(y+"-"+O):c[_.property.name.validatedDocumentsCache]=new Set([y+"-"+O]),z.newDocument},e}(),l=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__,{S8:()=>restart,ds:()=>stop,ni:()=>start});var _babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__(1),_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__(2),_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__(3),_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__(4),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__(0),_this=void 0;function _createForOfIteratorHelperLoose(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=_unsupportedIterableToArray(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}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 n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_arrayLikeToArray(e,t):void 0}}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}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 n,r,o=_createForOfIteratorHelperLoose(clientnode__WEBPACK_IMPORTED_MODULE_4__.CLOSE_EVENT_NAMES);!(n=o()).done;)r=n.value,server.process.on(r,(0,clientnode__WEBPACK_IMPORTED_MODULE_4__.getProcessCloseHandler)(e,t,{process:server.process,reason:r}))})).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,(0,clientnode__WEBPACK_IMPORTED_MODULE_4__.checkReachability)((0,clientnode__WEBPACK_IMPORTED_MODULE_4__.format)(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 n,r,o,a,c,_;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.configuration,r=t.pluginAPI,o=t.services,a=o.couchdb.server,c=a.resolve,_=a.reject,a.resolve=a.reject=clientnode__WEBPACK_IMPORTED_MODULE_4__.NOOP,e.next=7,stop(o,n);case 7:return a.resolve=c,a.reject=_,e.next=11,start(o,n);case 11:return(0,_helper__WEBPACK_IMPORTED_MODULE_8__.initializeConnection)(o,n),e.next=14,r.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,n){var r,o;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.couchdb,o=n.couchdb,r.connection&&r.connection.close(),r.server.process&&r.server.process.kill("SIGINT"),e.next=6,(0,clientnode__WEBPACK_IMPORTED_MODULE_4__.checkUnreachability)((0,clientnode__WEBPACK_IMPORTED_MODULE_4__.format)(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 n=__webpack_module_cache__[e]={exports:{}};return __webpack_modules__[e](n,n.exports,__webpack_require__),n.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 n in t)__webpack_require__.o(t,n)&&!__webpack_require__.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},__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__(1),_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__(2),_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__(3),_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__(4),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__(0),_server__WEBPACK_IMPORTED_MODULE_8__=__webpack_require__(14);function _createForOfIteratorHelperLoose(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=_unsupportedIterableToArray(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}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 n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_arrayLikeToArray(e,t):void 0}}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}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 n,r,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(n=t.configuration.couchdb,r=t.services,Object.prototype.hasOwnProperty.call(r,"couchdb")||(r.couchdb={}),o=r.couchdb,Object.prototype.hasOwnProperty.call(o,"connector")||(a=n.model.property.name.special.id,c=n.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 r,o,i,s,l,u,p,d,m,f,b,h,y,O,x,g,v,E,P=arguments;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(o=P.length,i=Array(1<o?o-1:0),s=1;s<o;s++)i[s-1]=P[s];return l=0<i.length&&i[i.length-1]===Database.toggleLatestRevisionDetermining,u=l?!n.skipLatestRevisionDetermining:n.skipLatestRevisionDetermining,l&&i.pop(),p=!Array.isArray(t)&&null!==t&&"object"==typeof t&&a in t?[t]:t,null!=(r=n.connector.fetch)&&r.timeout&&(0===i.length||"object"!=typeof i[0])&&i.unshift({timeout:n.connector.fetch.timeout}),e.next=8,_.call.apply(_,[this,p].concat(i));case 8:d=e.sent,m=[],f=[],b=0,h=_createForOfIteratorHelperLoose(d);case 13:if((y=h()).done){e.next=36;break}if(O=y.value,"object"!=typeof p[b]){e.next=33;break}if(!(c in p[b])||"conflict"!==O.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]&&n.ignoreNoChangeError&&"name"in O&&"forbidden"===O.name&&"message"in O&&O.message.startsWith("NoChange:"))){e.next=33;break}if(d[b]={id:p[b][a],ok:!0},u){e.next=33;break}if(!(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.toggleLatestRevisionDetermining),e.next=41,this.bulkDocs.apply(this,[p].concat(i));case 41:for(x=e.sent,g=_createForOfIteratorHelperLoose(x);!(v=g()).done;)E=v.value,d[m.shift()]=E;case 43:return e.abrupt("return",d);case 44:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}()}),n.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(n.binary.runner));case 8:if((l=s()).done){e.next=34;break}u=l.value,p=_createForOfIteratorHelperLoose([].concat(u.location));case 11:if((d=p()).done){e.next=30;break}m=d.value,f=_createForOfIteratorHelperLoose([].concat(u.name));case 14:if((b=f()).done){e.next=26;break}return h=b.value,y=(0,path__WEBPACK_IMPORTED_MODULE_5__.resolve)(m,h),i.push(y),e.next=20,(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.isFile)(y);case 20:if(!e.sent){e.next=24;break}return u.binaryFilePath=y,o.server.runner=u,e.abrupt("break",26);case 24:e.next=14;break;case 26:if(!Object.prototype.hasOwnProperty.call(o.server,"runner")){e.next=28;break}return e.abrupt("break",30);case 28:e.next=11;break;case 30:if(!Object.prototype.hasOwnProperty.call(o.server,"runner")){e.next=32;break}return e.abrupt("break",34);case 32:e.next=8;break;case 34:if(Object.prototype.hasOwnProperty.call(o.server,"runner")){e.next=36;break}throw new Error('No binary file in one of the following locations found: "'+i.join('", "')+'".');case 36:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),Database.loadService=function(){function loadService(){return _loadService.apply(this,arguments)}var _loadService=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function _callee3(_ref3){var configuration,services,promise,couchdb,urlPrefix,unauthenticatedUserDatabaseConnection,authenticatedUserDatabaseConnection,_i,_arr,type,_iterator6,_step6,name,userDatabaseConnection,_userDatabaseConnecti,_iterator7,_step7,prefix,subPath,fullPath,url,value,response,changeNeeded,modelConfiguration,specialNames,idName,revisionName,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,documents,_iterator12,_step12,document,_forbidden,_iterator13,_step13,retrievedDocument,_document,newDocument,_iterator14,_step14,_name3,result,indexes,_i4,_Object$entries3,_Object$entries3$_i,_modelName,_model,_iterator15,_step15,propertyName,_name4,foundPosition,position,_iterator16,_step16,index,_iterator17,_step17,_index,exists,_i5,_Object$entries4,_Object$entries4$_i,_modelName2,_model2,_iterator18,_step18,_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__.ni)(services,configuration);case 6:couchdb.server.restart=_server__WEBPACK_IMPORTED_MODULE_8__.S8,couchdb.server.start=_server__WEBPACK_IMPORTED_MODULE_8__.ni,couchdb.server.stop=_server__WEBPACK_IMPORTED_MODULE_8__.ds,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=(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.format)(configuration.couchdb.url,configuration.couchdb.user.name+":"+configuration.couchdb.user.password+"@"),!configuration.couchdb.ensureAdminPresence){_context3.next=44;break}return unauthenticatedUserDatabaseConnection=new couchdb.connector((0,clientnode__WEBPACK_IMPORTED_MODULE_3__.format)(configuration.couchdb.url,"")+"/_users",(0,_helper__WEBPACK_IMPORTED_MODULE_9__.getConnectorOptions)(configuration)),_context3.prev=15,_context3.next=18,unauthenticatedUserDatabaseConnection.allDocs();case 18:return console.info('No admin user available. Automatically creating admin user "'+configuration.couchdb.user.name+'".'),_context3.next=21,clientnode__WEBPACK_IMPORTED_MODULE_3__.globalContext.fetch((0,clientnode__WEBPACK_IMPORTED_MODULE_3__.format)(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),console.error("Can't login as existing admin user \""+configuration.couchdb.user.name+'": '+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(_context3.t1));case 35:return _context3.prev=35,authenticatedUserDatabaseConnection.close(),_context3.finish(35);case 38:_context3.next=41;break;case 40:console.error("Can't create new admin user \""+configuration.couchdb.user.name+'": '+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(_context3.t0));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+'": '+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(_context3.t3));case 68:_context3.next=71;break;case 70:throw new Error("Couldn't check for presence of user \""+name+'": '+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.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),console.warn('Configuration "'+fullPath+'" (with desired value ['+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(value)+"]) couldn't be determined: "+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(_context3.t6));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),console.warn('Error checking curent value of "'+fullPath+'" to be ['+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(value)+"]: "+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(_context3.t9));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),console.error('Configuration "'+fullPath+"\" couldn't be applied to ["+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(value)+"]: "+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(_context3.t10));case 124:_context3.next=127;break;case 126:console.info('Configuration "'+fullPath+'" is already set to desired value ['+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(value)+"].");case 127:_context3.next=130;break;case 129:console.info('Configuration "'+fullPath+'" does not exist (desired value ['+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(value)+"]). Response code is "+response.status+".");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),console.error("Security object couldn't be applied: "+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(_context3.t11));case 145:if(modelConfiguration=(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.copy)(configuration.couchdb.model),delete modelConfiguration.property.defaultSpecification,delete modelConfiguration.entities,specialNames=modelConfiguration.property.name.special,idName=specialNames.id,revisionName=specialNames.revision,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: "+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(_context3.t12));case 166:return configuration.core.debug&&console.debug(_type2.name+' code: \n\n"'+code+'" intgrated.'),_context3.next=169,(0,_helper__WEBPACK_IMPORTED_MODULE_9__.ensureValidationDocumentPresence)(couchdb.connection,_type2.name,{helper:databaseHelperCode,validate_doc_update:code},_type2.description,!0,idName,revisionName,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: "+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.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: "+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.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=319;break}return migrators={},_context3.next=218,(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.isDirectory)((0,path__WEBPACK_IMPORTED_MODULE_5__.resolve)(configuration.couchdb.model.autoMigrationPath));case 218:if(!_context3.sent){_context3.next=271;break}return _context3.t15=_createForOfIteratorHelperLoose,_context3.next=222,(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.walkDirectoryRecursively)((0,path__WEBPACK_IMPORTED_MODULE_5__.resolve)(configuration.couchdb.model.autoMigrationPath),configuration.couchdb.debug?clientnode__WEBPACK_IMPORTED_MODULE_3__.NOOP:function(e){return!["debug","deprecated"].includes(e.name)});case 222:_context3.t16=_context3.sent,_iterator11=(0,_context3.t15)(_context3.t16);case 224:if((_step11=_iterator11()).done){_context3.next=271;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=261;break}return documents=void 0,_context3.prev=230,_context3.t17=[],_context3.t18=JSON,_context3.next=235,fs__WEBPACK_IMPORTED_MODULE_4__.promises.readFile(file.path,{encoding:configuration.core.encoding,flag:"r"});case 235:_context3.t19=_context3.sent,_context3.t20=_context3.t18.parse.call(_context3.t18,_context3.t19),documents=_context3.t17.concat.call(_context3.t17,_context3.t20),_context3.next=243;break;case 240:throw _context3.prev=240,_context3.t21=_context3.catch(230),new Error('Parsing document "'+file.path+'" to include by automigration of has failed: '+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(_context3.t21));case 243:1===documents.length&&(!documents[0][idName]&&(documents[0][idName]=_name2),!documents[0][revisionName]&&(documents[0][revisionName]="upsert")),_iterator12=_createForOfIteratorHelperLoose(documents);case 245:if((_step12=_iterator12()).done){_context3.next=259;break}return document=_step12.value,_context3.prev=247,_context3.next=250,couchdb.connection.put(document);case 250:_context3.next=256;break;case 252:throw _context3.prev=252,_context3.t22=_context3.catch(247),null!=(_forbidden=_context3.t22.forbidden)&&_forbidden.startsWith("NoChange:")&&console.info('Including document "'+document[idName]+'" of type "'+document[typeName]+"\" hasn't changed existing document."),new Error('Migrating document "'+document[idName]+'" of type "'+document[typeName]+'" has failed: '+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(_context3.t22));case 256:console.info('Including document "'+document[idName]+'" of type "'+document[typeName]+'" was successful.');case 257:_context3.next=245;break;case 259:_context3.next=269;break;case 261:if(![".js"].includes((0,path__WEBPACK_IMPORTED_MODULE_5__.extname)(file.name))){_context3.next=265;break}migrators[file.path]=eval("require('"+file.path+"')").default,_context3.next=269;break;case 265:if(![".mjs"].includes((0,path__WEBPACK_IMPORTED_MODULE_5__.extname)(file.name))){_context3.next=269;break}return _context3.next=268,eval("import('"+file.path+"')");case 268:migrators[file.path]=_context3.sent.default;case 269:_context3.next=224;break;case 271:return _context3.t23=_createForOfIteratorHelperLoose,_context3.next=274,couchdb.connection.allDocs({include_docs:!0});case 274:_context3.t24=_context3.sent.rows,_iterator13=(0,_context3.t23)(_context3.t24);case 276:if((_step13=_iterator13()).done){_context3.next=319;break}if(retrievedDocument=_step13.value,"string"==typeof retrievedDocument.id&&retrievedDocument.id.startsWith(configuration.couchdb.model.property.name.special.designDocumentNamePrefix)){_context3.next=317;break}_document=retrievedDocument.doc,newDocument=(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.copy)(_document),newDocument[configuration.couchdb.model.property.name.special.strategy]="migrate",_iterator14=_createForOfIteratorHelperLoose(Object.keys(migrators).sort());case 283:if((_step14=_iterator14()).done){_context3.next=296;break}_name3=_step14.value,result=null,_context3.prev=286,result=migrators[_name3](newDocument,_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({},clientnode__WEBPACK_IMPORTED_MODULE_3__.UTILITY_SCOPE,{configuration,databaseHelper:_databaseHelper__WEBPACK_IMPORTED_MODULE_10___default(),idName,typeName,migrators,models,modelConfiguration,selfFilePath:_name3,services})),_context3.next=293;break;case 290:throw _context3.prev=290,_context3.t25=_context3.catch(286),new Error('Running migrater "'+_name3+'" in document '+(0,_helper__WEBPACK_IMPORTED_MODULE_9__.mayStripRepresentation)(_document,configuration.couchdb.maximumRepresentationTryLength,configuration.couchdb.maximumRepresentationLength)+'" failed: '+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(_context3.t25));case 293:result&&(newDocument=result,console.info('Running migrater "'+_name3+'" for document "'+newDocument[idName]+'" (of type "'+newDocument[typeName]+'") was successful.'));case 294:_context3.next=283;break;case 296:_context3.prev=296,_databaseHelper__WEBPACK_IMPORTED_MODULE_10___default().validateDocumentUpdate((0,clientnode__WEBPACK_IMPORTED_MODULE_3__.copy)(newDocument),(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.copy)(_document),{db:configuration.couchdb.databaseName,name:configuration.couchdb.user.name,roles:["_admin"]},(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.copy)(configuration.couchdb.security),modelConfiguration,models),_context3.next=308;break;case 300:if(_context3.prev=300,_context3.t26=_context3.catch(296),!Object.prototype.hasOwnProperty.call(_context3.t26,"forbidden")){_context3.next=307;break}return _context3.t26.forbidden.startsWith("NoChange:")||console.warn('Document "'+(0,_helper__WEBPACK_IMPORTED_MODULE_9__.mayStripRepresentation)(_document,configuration.couchdb.maximumRepresentationTryLength,configuration.couchdb.maximumRepresentationLength)+"\" doesn't satisfy its schema (and can not be migrated automatically): "+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(_context3.t26)),_context3.abrupt("continue",317);case 307:throw _context3.t26;case 308:return _context3.prev=308,_context3.next=311,couchdb.connection.put(newDocument);case 311:_context3.next=316;break;case 313:throw _context3.prev=313,_context3.t27=_context3.catch(308),new Error('Replacing auto migrated document "'+newDocument[idName]+'" has failed: '+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(_context3.t27));case 316:console.info('Auto migrating document "'+newDocument[idName]+'" was successful.');case 317:_context3.next=276;break;case 319:if(!configuration.couchdb.createGenericFlatIndex||!configuration.couchdb.model.autoMigrationPath){_context3.next=374;break}return _context3.next=322,couchdb.connection.getIndexes();case 322:indexes=_context3.sent.indexes,_i4=0,_Object$entries3=Object.entries(models);case 324:if(!(_i4<_Object$entries3.length)){_context3.next=355;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.typePattern.public).test(_modelName)){_context3.next=352;break}return _context3.next=329,couchdb.connection.createIndex({index:{ddoc:_modelName+"-GenericIndex",fields:[typeName],name:_modelName+"-GenericIndex"}});case 329:_iterator15=_createForOfIteratorHelperLoose((0,_helper__WEBPACK_IMPORTED_MODULE_9__.determineGenericIndexablePropertyNames)(configuration.couchdb.model,_model));case 330:if((_step15=_iterator15()).done){_context3.next=352;break}propertyName=_step15.value,_name4=_modelName+"-"+propertyName+"-GenericIndex",foundPosition=-1,position=0,_iterator16=_createForOfIteratorHelperLoose(indexes);case 336:if((_step16=_iterator16()).done){_context3.next=344;break}if(index=_step16.value,index.name!==_name4){_context3.next=341;break}return foundPosition=position,_context3.abrupt("break",344);case 341:position+=1;case 342:_context3.next=336;break;case 344:if(-1!==foundPosition){_context3.next=349;break}return _context3.next=347,couchdb.connection.createIndex({index:{ddoc:_name4,fields:[typeName,propertyName],name:_name4}});case 347:_context3.next=350;break;case 349:indexes.slice(position,1);case 350:_context3.next=330;break;case 352:_i4++,_context3.next=324;break;case 355:_iterator17=_createForOfIteratorHelperLoose(indexes);case 356:if((_step17=_iterator17()).done){_context3.next=374;break}if(_index=_step17.value,!_index.name.endsWith("-GenericIndex")){_context3.next=372;break}exists=!1,_i5=0,_Object$entries4=Object.entries(models);case 361:if(!(_i5<_Object$entries4.length)){_context3.next=369;break}if(_Object$entries4$_i=_Object$entries4[_i5],_modelName2=_Object$entries4$_i[0],_model2=_Object$entries4$_i[1],!_index.name.startsWith(_modelName2+"-")){_context3.next=366;break}for(_iterator18=_createForOfIteratorHelperLoose((0,_helper__WEBPACK_IMPORTED_MODULE_9__.determineGenericIndexablePropertyNames)(configuration.couchdb.model,_model2));!(_step18=_iterator18()).done;)_name5=_step18.value,[_modelName2+"-"+_name5+"-GenericIndex",_modelName2+"-GenericIndex"].includes(_index.name)&&(exists=!0);return _context3.abrupt("break",369);case 366:_i5++,_context3.next=361;break;case 369:if(exists){_context3.next=372;break}return _context3.next=372,couchdb.connection.deleteIndex(_index);case 372:_context3.next=356;break;case 374:if(!configuration.couchdb.model.triggerInitialCompaction){_context3.next=383;break}return _context3.prev=375,_context3.next=378,couchdb.connection.compact();case 378:_context3.next=383;break;case 380:_context3.prev=380,_context3.t28=_context3.catch(375),console.warn("Initial database compaction has failed: "+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(_context3.t28));case 383:return _context3.abrupt("return",{couchdb:promise});case 384: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,240],[247,252],[286,290],[296,300],[308,313],[375,380]])})));return loadService}(),Database.postLoadService=function(e){var t=e.configuration.couchdb,n=e.pluginAPI,r=e.services.couchdb,o=0;setInterval((function(){0<o&&(console.info("No additional errors (initially got "+o+" errors through) occurred during observing changes stream for 30 seconds. Clearing saved number of errors through."),o=0)}),3e4);var a=(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.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 r.changesStream&&r.changesStream.cancel(),r.changesStream=r.connection.changes(t.changesStream),r.changesStream.on("error",_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function t(n){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 console.warn("Observing changes feed throws an error for "+o+" times through: "+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(n)+" Restarting database server and reinitialize changes stream..."),o=0,r.changesStream.cancel(),t.next=7,r.server.restart(e);case 7:t.next=10;break;case 9:console.warn("Observing changes feed throws an error for "+o+" times through: "+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(n)+" Reinitializing changes stream...");case 10:a();case 11:case"end":return t.stop()}}),t)})))),c.next=5,n.callStack(_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({},e,{data:r.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 n,r,o;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.configuration,r=t.services,e.next=3,(0,_server__WEBPACK_IMPORTED_MODULE_8__.ds)(r,n);case 3:return delete r.couchdb,o="log.txt",e.next=7,(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.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.toggleLatestRevisionDetermining=Symbol("toggleLatestRevisionDetermining");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.642",
3
+ "version": "1.0.644",
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",
@@ -49,7 +49,6 @@
49
49
  "clear": "weboptimizer clear && rimraf log.txt",
50
50
  "document": "weboptimizer document",
51
51
  "lint": "weboptimizer lint",
52
- "postversion": "yarn publish --non-interactive; git push --tags && git push",
53
52
  "prepare": "yarn build",
54
53
  "report:coverage": "nyc report --reporter=text-lcov | coveralls",
55
54
  "serve": "yarn build && yarn start",
@@ -57,33 +56,35 @@
57
56
  "test": "weboptimizer test",
58
57
  "test:coverage": "weboptimizer test:coverage",
59
58
  "test:coverage:report": "weboptimizer test:coverage:report",
60
- "update": "yarn version --patch",
59
+ "update": "yarn version patch && yarn npm publish",
61
60
  "update:documentation": "documentation-website",
62
61
  "watch": "weboptimizer build --watch"
63
62
  },
64
63
  "dependencies": {
65
- "pouchdb-find": "*",
66
- "pouchdb-node": "*",
67
- "pouchdb-server": "*"
64
+ "pouchdb-find": "^9.0.0",
65
+ "pouchdb-node": "^9.0.0",
66
+ "pouchdb-server": "^4.2.0"
68
67
  },
69
68
  "devDependencies": {
70
- "@babel/eslint-parser": "*",
71
- "@types/ejs": "*",
72
- "@types/node": "*",
73
- "@types/pouchdb-node": "*",
74
- "@typescript-eslint/eslint-plugin": "*",
75
- "@typescript-eslint/parser": "*",
76
- "clientnode": "*",
77
- "documentation-website": "*",
78
- "eslint": "*",
79
- "eslint-config-google": "*",
80
- "eslint-plugin-jsdoc": "*",
81
- "jest": "*",
82
- "jsdoc": "*",
83
- "node-fetch": "*",
84
- "rimraf": "*",
85
- "web-node": "*",
86
- "weboptimizer": "*"
69
+ "@babel/eslint-parser": "^7.24.7",
70
+ "@babel/runtime": "^7.24.7",
71
+ "@types/ejs": "^3.1.5",
72
+ "@types/node": "^20.14.10",
73
+ "@types/pouchdb-node": "^6.1.7",
74
+ "@typescript-eslint/eslint-plugin": "^7.16.0",
75
+ "@typescript-eslint/parser": "^7.16.0",
76
+ "clientnode": "^3.0.1157",
77
+ "documentation-website": "^1.0.328",
78
+ "eslint": "^9.6.0",
79
+ "eslint-config-google": "^0.14.0",
80
+ "eslint-plugin-jsdoc": "^48.6.0",
81
+ "jest": "^29.7.0",
82
+ "jsdoc": "^4.0.3",
83
+ "node-fetch": "^3.3.2",
84
+ "rimraf": "^6.0.0",
85
+ "typescript-eslint": "^7.16.0",
86
+ "web-node": "^1.0.512",
87
+ "weboptimizer": "^2.0.1483"
87
88
  },
88
89
  "peerDependencies": {
89
90
  "@babel/runtime": "*",
@@ -98,11 +99,15 @@
98
99
  }
99
100
  },
100
101
  "engines": {
101
- "node": ">=18",
102
- "npm": ">=9"
102
+ "node": ">=20",
103
+ "npm": ">=10",
104
+ "yarn": ">=4"
103
105
  },
104
106
  "resolutions": {
105
- "colors": "1.4.0"
107
+ "colors": "1.4.0",
108
+ "globals@npm:^9.18.0": "patch:globals@npm%3A11.12.0#~/.yarn/patches/globals-npm-11.12.0-1fa7f41a6c.patch",
109
+ "globals@npm:^11.1.0": "patch:globals@npm%3A11.12.0#~/.yarn/patches/globals-npm-11.12.0-1fa7f41a6c.patch",
110
+ "globals@npm:^14.0.0": "patch:globals@npm%3A11.12.0#~/.yarn/patches/globals-npm-11.12.0-1fa7f41a6c.patch"
106
111
  },
107
112
  "sideEffects": false,
108
113
  "documentationWebsite": {
@@ -512,5 +517,6 @@
512
517
  }
513
518
  }
514
519
  }
515
- }
516
- }
520
+ },
521
+ "packageManager": "yarn@4.1.0+sha256.81a00df816059803e6b5148acf03ce313cad36b7f6e5af6efa040a15981a6ffb"
522
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
package/type.d.ts CHANGED
@@ -1,13 +1,5 @@
1
- /// <reference types="pouchdb-core" />
2
- /// <reference types="pouchdb-find" />
3
- /// <reference types="pouchdb-mapreduce" />
4
- /// <reference types="pouchdb-replication" />
5
- /// <reference types="pouchdb-adapter-leveldb" />
6
- /// <reference types="pouchdb-adapter-http" />
7
- /// <reference types="node" />
8
1
  import { ChildProcess } from 'child_process';
9
- import Tools from 'clientnode';
10
- import { AnyFunction, Mapping, PlainObject, Primitive, ProcessCloseReason } from 'clientnode/type';
2
+ import { AnyFunction, Mapping, PlainObject, Primitive, ProcessCloseReason, UTILITY_SCOPE } from 'clientnode';
11
3
  import { Configuration as BaseConfiguration, PluginHandler as BasePluginHandler, ServicePromises as BaseServicePromises, Services as BaseServices, ServicePromisesState as BaseServicePromisesState, ServicesState as BaseServicesState } from 'web-node/type';
12
4
  import DatabaseHelper from './databaseHelper';
13
5
  export type Attachment = PouchDB.Core.Attachment & {
@@ -297,14 +289,12 @@ export interface PluginHandler extends BasePluginHandler {
297
289
  /**
298
290
  * Hook after each data change.
299
291
  * @param state - Application state.
300
- *
301
292
  * @returns Promise resolving to nothing.
302
293
  */
303
294
  couchdbInitializeChangesStream?(state: State<ChangesStream>): Promise<void>;
304
295
  /**
305
- * Hook after each data base restart.
296
+ * Hook after each database restart.
306
297
  * @param state - Application state.
307
- *
308
298
  * @returns Promise resolving to nothing.
309
299
  */
310
300
  restartCouchdb?(state: State): Promise<void>;
@@ -374,10 +364,9 @@ export interface CheckedPropertyResult<Type> extends CheckedResult {
374
364
  export interface CheckedDocumentResult<ObjectType extends object, AdditionalPropertiesType> extends CheckedResult {
375
365
  newDocument: PartialFullDocument<ObjectType, AdditionalPropertiesType>;
376
366
  }
377
- export type Migrator<Type extends object = object, AttachmentType extends Attachment = Attachment, AdditionalSpecifications extends object = object, AdditionalPropertiesType = unknown> = (document: Document, scope: {
367
+ export type Migrator<Type extends object = object, AttachmentType extends Attachment = Attachment, AdditionalSpecifications extends object = object, AdditionalPropertiesType = unknown> = (document: Document, scope: (typeof UTILITY_SCOPE & {
378
368
  configuration: Configuration;
379
369
  databaseHelper: DatabaseHelper;
380
- Tools: typeof Tools;
381
370
  idName: string;
382
371
  typeName: string;
383
372
  migrators: Mapping<Migrator<Type, AttachmentType, AdditionalSpecifications, AdditionalPropertiesType>>;
@@ -385,7 +374,7 @@ export type Migrator<Type extends object = object, AttachmentType extends Attach
385
374
  modelConfiguration: ModelConfiguration<Type, AttachmentType, AdditionalSpecifications, AdditionalPropertiesType>;
386
375
  selfFilePath: string;
387
376
  services: Services;
388
- }) => Document | null;
377
+ })) => Document | null;
389
378
  export type DateRepresentationType = Date | null | number | string;
390
379
  export type User = BaseDocument & {
391
380
  password: string;
package/type.js CHANGED
File without changes