couchdb-web-node-plugin 1.0.645 → 1.0.646

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.
@@ -3,42 +3,39 @@ import { AllowedModelRolesMapping, Attachment, BaseModelConfiguration, Document,
3
3
  /**
4
4
  * WebNode plugin interface with all provided hooks.
5
5
  */
6
- export declare class DatabaseHelper {
7
- /**
8
- * Authenticates given document update against given mapping of allowed
9
- * roles for writing into corresponding model instances.
10
- * @param newDocument - Updated document.
11
- * @param oldDocument - If an existing document should be updated its given
12
- * here.
13
- * @param userContext - Contains meta information about currently acting
14
- * user.
15
- * @param _securitySettings - Database security settings.
16
- * @param allowedModelRolesMapping - Allowed roles for given models.
17
- * @param idPropertyName - Property name indicating the id field name.
18
- * @param typePropertyName - Property name indicating to which model a
19
- * document belongs to.
20
- * @param designDocumentNamePrefix - Document name prefix indicating a
21
- * design document.
22
- * @param read - Indicates whether a read or write of given document should
23
- * be authorized or not.
24
- * @returns Throws an exception if authorisation is not accepted and "true"
25
- * otherwise.
26
- */
27
- static authenticate(this: void, newDocument: Partial<Document>, oldDocument?: null | Partial<Document>, userContext?: Partial<UserContext>, _securitySettings?: Partial<SecuritySettings>, allowedModelRolesMapping?: AllowedModelRolesMapping, idPropertyName?: string, typePropertyName?: string, designDocumentNamePrefix?: string, read?: boolean): true;
28
- /**
29
- * Represents a design document validation function for given model
30
- * specification.
31
- * @param newDocument - Updated document.
32
- * @param oldDocument - If an existing document should be updated its given
33
- * here.
34
- * @param userContext - Contains meta information about currently acting
35
- * user.
36
- * @param securitySettings - Database security settings.
37
- * @param modelConfiguration - Model configuration object.
38
- * @param models - Models specification object.
39
- * @param toJSON - JSON stringifier.
40
- * @returns Modified given new document.
41
- */
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>;
43
- }
44
- export default DatabaseHelper;
6
+ /**
7
+ * Authenticates given document update against given mapping of allowed roles
8
+ * for writing into corresponding model instances.
9
+ * @param newDocument - Updated document.
10
+ * @param oldDocument - If an existing document should be updated its given
11
+ * here.
12
+ * @param userContext - Contains meta information about currently acting user.
13
+ * @param _securitySettings - Database security settings.
14
+ * @param allowedModelRolesMapping - Allowed roles for given models.
15
+ * @param idPropertyName - Property name indicating the id field name.
16
+ * @param typePropertyName - Property name indicating to which model a document
17
+ * belongs to.
18
+ * @param designDocumentNamePrefix - Document name prefix indicating a design
19
+ * document.
20
+ * @param read - Indicates whether a read or write of given document should be
21
+ * authorized or not.
22
+ * @returns Throws an exception if authorisation is not accepted and "true"
23
+ * otherwise.
24
+ */
25
+ export declare const authenticate: (newDocument: Partial<Document>, oldDocument?: null | Partial<Document>, userContext?: Partial<UserContext>, _securitySettings?: Partial<SecuritySettings>, allowedModelRolesMapping?: AllowedModelRolesMapping, idPropertyName?: string, typePropertyName?: string, designDocumentNamePrefix?: string, read?: boolean) => true;
26
+ /**
27
+ * Represents a design document validation function for given model
28
+ * specification.
29
+ * @param newDocument - Updated document.
30
+ * @param oldDocument - If an existing document should be updated its given
31
+ * here.
32
+ * @param userContext - Contains meta information about currently acting user.
33
+ * @param securitySettings - Database security settings.
34
+ * @param modelConfiguration - Model configuration object.
35
+ * @param models - Models specification object.
36
+ * @param toJSON - JSON stringifier.
37
+ * @returns Modified given new document.
38
+ */
39
+ export declare const validateDocumentUpdate: <ObjectType extends object = object, AttachmentType extends Attachment = Attachment, AdditionalSpecifications extends object = Mapping<unknown>, AdditionalPropertiesType = unknown>(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>;
40
+ export declare const databaseHelper: any;
41
+ export default databaseHelper;
package/databaseHelper.js CHANGED
@@ -1 +1 @@
1
- (()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function r(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})();
1
+ (()=>{"use strict";var e=[(e,t,n)=>{function r(e,t,n){if(a())return Reflect.construct.apply(null,arguments);var r=[null];r.push.apply(r,t);var i=new(e.bind.apply(e,r));return n&&o(i,n.prototype),i}function o(e,t){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},o(e,t)}function a(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(a=function(){return!!e})()}function i(){return i=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},i.apply(null,arguments)}function l(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}n.r(t),n.d(t,{authenticate:()=>p,databaseHelper:()=>u,default:()=>m,validateDocumentUpdate:()=>s}),e=n.hmd(e);var p=function(e,t,n,r,o,a,i,c,p){var s,u,m;void 0===t&&(t=null),void 0===n&&(n={}),void 0===r&&(r={admins:{names:[],roles:[]},members:{names:[],roles:[]}}),void 0===a&&(a="_id"),void 0===i&&(i="-type"),void 0===c&&(c="_design/"),void 0===p&&(p=!1);var y=null!==(s=e[i])&&void 0!==s?s:t&&t[i];if(!y)return!0;var d=p?"read":"write",f={properties:{},read:["_admin","readonlyadmin"],write:["_admin"]};Object.prototype.hasOwnProperty.call(e,a)&&e[a].startsWith(c)&&f.read.push("readonlymember");var h="Current user doesn't own any role";if("name"in n||(n.name='"unknown"'),null!=(u=n.roles)&&u.length){var v;if(o&&y&&Object.prototype.hasOwnProperty.call(o,y)){for(var g,b,O=o[y],w=l(["read","write"]);!(g=w()).done;)f[b=g.value]=f[b].concat(O[b]||[]);f.properties=O.properties}for(var j,P,x=f[d],k=l(n.roles);!(j=k()).done;)if(P=j.value,x.includes(P))return!0;h='Current user "'+(null!==(v=n.name)&&void 0!==v?v:"unknown")+'" owns the following roles: "'+n.roles.join('", "')+'"'}else h='Current user "'+(null!==(m=n.name)&&void 0!==m?m:"unknown")+"\" doesn't own anyrole";throw{unauthorized:"Only users with a least on of these roles are allowed to perform requested "+d+' action: "'+[].concat(f[d]).join('", "')+'". '+h+"."}},s=function(e,t,n,o,a,c,p){void 0===c&&(c={});var s=function(e,t,n){var r;throw void 0===t&&(t="forbidden"),void 0===n&&(n={}),i(((r={})[t]=e,r.message=e,r.name=t,r),n)},u=new Date,m=Date.UTC(u.getUTCFullYear(),u.getUTCMonth(),u.getUTCDate(),u.getUTCHours(),u.getUTCMinutes(),u.getUTCSeconds(),u.getUTCMilliseconds())/1e3,y=!a.dateTimeFormat.startsWith("iso"),d=a.property.name.special,f=d.id,h=d.revision,v=d.type;t&&t[v]&&!e[v]&&(e[v]=t[v]);var g="",b="",O=function(){g=Object.prototype.hasOwnProperty.call(e,f)?e[f]:"",b=Object.prototype.hasOwnProperty.call(e,h)?e[h]:""};if(O(),Object.prototype.hasOwnProperty.call(o,a.property.name.validatedDocumentsCache)&&o[a.property.name.validatedDocumentsCache].has(g+"-"+b))return o[a.property.name.validatedDocumentsCache].delete(g+"-"+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=a.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,k=Object.entries(c);x<k.length;x++){var N=k[x],A=N[0],S=N[1];if(Object.prototype.hasOwnProperty.call(S,d.oldType)&&S[d.oldType])for(var C,T,D=l([].concat(S[d.oldType]));!(C=D()).done;)T=C.value,P[T]=A}p?j=p:"undefined"!=typeof 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,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},R=function(t,n){if(n||(n=e[d.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 i=Object.keys(n);if(i.length)return i[0]}return null},H=function(e,t,n){void 0===t&&(t=!1),void 0===n&&(n={});var o=i({},I,{code:""},n),a=U(e);if(a){var l=(t?"return ":"")+a;o.code=l;var c,p=Object.keys(o);try{c=r(Function,p.concat([l]))}catch(e){s(M(e),"compilation",{code:l,error:e,scope:o})}var u={code:l,result:void 0,scope:o};try{u.result=c.apply(void 0,p.map((function(e){return o[e]})))}catch(e){s(M(e),"runtime",{code:l,error:e,scope:o})}return u}return s("No expression to evaluate provided.","empty"),{code:o.code,result:void 0,scope:o}},L=function(e,t,n){void 0===n&&(n=[]);var o=n.length?" in "+n.join(" -> "):"",i=[],p=function(){Object.prototype.hasOwnProperty.call(e,v)||(t&&Object.prototype.hasOwnProperty.call(t,v)&&["fillUp","migrate"].includes(w)?e[v]=t[v]:s('Type: You have to specify a model type via property "'+v+'"'+o+".")),n.length||new RegExp(a.property.name.typePattern.public).test(e[v])||s('TypeName: You have to specify a model type which matches "'+a.property.name.typePattern.public+'" as public type (given "'+e[v]+'")'+o+"."),Object.prototype.hasOwnProperty.call(c,e[v])||(Object.prototype.hasOwnProperty.call(P,e[v])?e[v]=P[e[v]]:s('Model: Given model "'+e[v]+'" is not specified'+o+"."))};p();var u=e[v],m=c[u],g=void 0;Object.prototype.hasOwnProperty.call(m,d.additional)&&m[d.additional]&&(g=m[d.additional]);var b=function(a,i,c,p,y){void 0===y&&(y=["constraintExecution","constraintExpression"]);for(var d,f,h=l(y);!(d=h()).done;)if(f=d.value,Object.prototype.hasOwnProperty.call(c,f)){var v=void 0;try{v=H(c[f].evaluation,f.endsWith("Expression"),{checkPropertyContent:j,model:m,modelName:u,name:i,type:f,newDocument:e,newValue:a,oldDocument:t,oldValue:p,parentNames:n,pathDescription:o,propertySpecification:c})}catch(e){var g,b;if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&s('Compilation: Hook "'+f+'" has invalid code "'+e.code+'": "'+(null!==(g=e.message)&&void 0!==g?g:"unknown")+'"'+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&s('Runtime: Hook "'+f+'" has throw an error with code "'+e.code+'": "'+(null!==(b=e.message)&&void 0!==b?b:"unknown")+'"'+o+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}if(v&&!v.result){var O,w=U(null==(O=c[f])?void 0:O.description);s(f.charAt(0).toUpperCase()+(f.substring(1)+": ")+(w?r(Function,Object.keys(v.scope).concat(["return "+w])).apply(void 0,Object.values(v.scope)):'Property "'+i+'" should satisfy constraint "'+v.code+'" (given "'+M(a)+'")'+o+"."))}}},j=function(e,t,r,a){var i=[],p=[].concat(r.type?r.type:[]);"object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype&&!Object.prototype.hasOwnProperty.call(e,v)&&1===p.length&&Object.prototype.hasOwnProperty.call(c,p[0])&&(e[v]=p[0]);for(var u,m,d=!1,h=l(p);!(u=h()).done;)if(m=u.value,Object.prototype.hasOwnProperty.call(c,m)){if("object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype&&Object.prototype.hasOwnProperty.call(e,v)&&e[v]!==m&&"migrate"===w&&1===p.length&&(e[v]=m,i=n.concat(t+"","migrate nested object type")),"object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype&&Object.prototype.hasOwnProperty.call(e,v)&&e[v]===m){var g=L(e,a,n.concat(t+""));if(g.changedPath.length&&(i=g.changedPath),e=g.newDocument,M(e)===M({}))return{newValue:void 0,changedPath:i};d=!0;break}1===p.length&&s('NestedType: Under key "'+t+'" isn\'t of type "'+m+'" (given "'+M(e)+'" of type '+typeof e+")"+o+".")}else if("DateTime"===m){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(m)){if(!("number"==typeof e&&isNaN(e)||"integer"!==m&&typeof e!==m||"integer"===m&&parseInt(e,10)!==e)){d=!0;break}1===p.length&&s('PropertyType: Property "'+t+'" isn\'t of (valid) type "'+m+'" (given "'+M(e)+'" of type "'+typeof e+'")'+o+".")}else if("string"==typeof m&&m.startsWith("foreignKey:")){var j=c[m.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"===m||M(e)===M(m)){d=!0;break}1===p.length&&s('PropertyType: Property "'+t+'" isn\'t value "'+m+'" (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,k,N=[].concat(r.pattern),A=!1,S=l(N);!(x=S()).done;)if(k=x.value,new RegExp(k).test(e)){A=!0;break}A||s('PatternMatch: Property "'+t+'" should match one regular expression pattern "'+N.join('", "')+'" (given "'+e+'")'+o+".")}if(r.invertedPattern)for(var C,T,D=l([].concat(r.invertedPattern));!(C=D()).done;)T=C.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)&&(i=n.concat(t+"","value updated")),{newValue:e,changedPath:i}},x=function(e,t,r,o,l){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+'" isnot writable (old document "'+M(r)+'")'+l+".")}else s('Readonly: Property "'+o+'" is not writable'+l+".");if(!e.mutable&&r&&Object.prototype.hasOwnProperty.call(r,o)){if(M(c)===M(r[o]))return"incremental"!==w||a.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)+'")'+l+".")}if(null===c){if(e.nullable)return"incremental"===w&&r&&void 0!==r[o]||delete t[o],r&&Object.prototype.hasOwnProperty.call(r,o)&&(i=n.concat(o+"","delete property")),!0;s('NotNull: Property "'+o+'" should not be "null"'+l+".")}return!1},k=function(e,t,r,a,i){if(!r)for(var c,p,y=l(["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:i,checkPropertyContent:j,model:m,modelName:u,name:a+"",type:p,newDocument:t,oldDocument:r,newValue:void 0,oldValue:void 0,parentNames:n,pathDescription:o,propertySpecification:e})}catch(e){var f,h;if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&s('Compilation: Hook "'+p+'" has invalid code "'+e.code+'" for property "'+a+'": "'+(null!==(f=e.message)&&void 0!==f?f:"unknown")+'"'+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+'": "'+(null!==(h=e.message)&&void 0!==h?h:"unknown")+'"'+o+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}d&&![null,void 0].includes(d.result)&&(i?i[a]=d.result:t[a]=d.result)}},N=function(e,t,r,a,i){if(!i){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=l(["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:i,checkPropertyContent:j,model:m,modelName:u,name:a+"",type:p,newDocument:t,oldDocument:r,newValue:t[a],oldValue:r&&r[a]||void 0,parentNames:n,pathDescription:o,propertySpecification:e});i?i[a]=d.result:void 0!==d.result&&(t[a]=d.result)}catch(e){var f,h;if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&s('Compilation: Hook "'+p+'" has invalid code "'+e.code+'" for property "'+a+'": "'+(null!==(f=e.message)&&void 0!==f?f:"unknown")+'"'+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+'": "'+(null!==(h=e.message)&&void 0!==h?h:"unknown")+'"'+o+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}},A=Object.keys(m).filter((function(e){return!z.includes(e)}));if("migrate"===w)for(var S,C,T=l(A);!(S=T()).done;)if(C=S.value,m[C].oldName)for(var D,R,I=l([].concat(m[C].oldName));!(D=I()).done;)R=D.value,Object.prototype.hasOwnProperty.call(e,R)&&(e[C]=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(m,V)){var B=void 0;try{B=H(m[V],V.endsWith("Expression"),{checkPropertyContent:j,model:m,modelName:u,type:V,newDocument:e,oldDocument:t,parentNames:n,pathDescription:o}).result}catch(e){var q,Y;if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&s('Compilation: Hook "'+V+'" has invalid code "'+e.code+'" for document "'+u+'": "'+(null!==(q=e.message)&&void 0!==q?q:"unknown")+'"'+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 "'+u+'": "'+(null!==(Y=e.message)&&void 0!==Y?Y:"unknown")+'"'+o+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}[null,void 0].includes(B)||(e=B),p(),u=e[v],0===n.length&&O()}for(var $,J=0,G=[d.update.execution,d.update.expression];J<G.length;J++)if($=G[J],Object.prototype.hasOwnProperty.call(m,$)){var K=void 0;try{K=H(m[$],$.endsWith("Expression"),{checkPropertyContent:j,model:m,modelName:u,type:$,newDocument:e,oldDocument:t,parentNames:n,pathDescription:o}).result}catch(e){var Z,Q;if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&s('Compilation: Hook "'+$+'" has invalid code "'+e.code+'" for document "'+u+'": "'+(null!==(Z=e.message)&&void 0!==Z?Z:"unknown")+'"'+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&s('Runtime: Hook "'+$+'" has throw an error with code "'+e.code+'" for document "'+u+'": "'+(null!==(Q=e.message)&&void 0!==Q?Q:"unknown")+'"'+o+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}[void 0,null].includes(K)||(e=K),p(),u=e[v],0===n.length&&O()}for(var X,ee,te=g?Object.keys(e).filter((function(e){return!A.includes(e)})):[],ne=l(A.concat(te));!(X=ne()).done;)if(ee=X.value,d.attachment===ee)for(var re=function(){var r=ae[oe],a=r[0],c=r[1];[null,void 0].includes(e[d.attachment])&&(e[d.attachment]={}),t&&!Object.prototype.hasOwnProperty.call(t,ee)&&(t[d.attachment]={});var p=e[d.attachment],u=Object.keys(p).filter((function(e){return null!==p[e].data&&_(a,e,c)})),m=[];if(t){var y=t[ee];m=Object.keys(y).filter((function(e){return!(Object.prototype.hasOwnProperty.call(p,e)&&Object.prototype.hasOwnProperty.call(p[e],"data")&&null===p[e].data)&&!!y[e]&&(Object.prototype.hasOwnProperty.call(y[e],"data")&&null!==y[e].data||Object.prototype.hasOwnProperty.call(y[e],"stub")&&!!y[e].digest)&&!!_(a,e,c)}))}for(var f,h,v=c,g=l(u);!(f=g()).done;)h=f.value,k(v,e,t&&t[ee]?t[ee]:null,h,p);for(var b,O,j=l(u);!(b=j()).done;)O=b.value,N(v,e,t&&t[ee]?t[ee]:null,O,p);if(void 0===v.default){if(v.nullable||0<u.length||0<m.length||s('AttachmentMissing: Missing attachment for type "'+a+'"'+o+"."),"fillUp"===w&&0===u.length&&0<m.length)for(var P,x,A=l(m);!(P=A()).done;)x=P.value,null===p[x]?i=n.concat(ee,x,"file removed"):p[x]=t[ee][x]}else if(0===u.length)if(0===m.length)for(var S in v.default)Object.prototype.hasOwnProperty.call(v.default,S)&&(p[S]=v.default[S],i=n.concat(ee,a,"add default file"));else if("fillUp"===w)for(var C,T,D=l(m);!(C=D()).done;)T=C.value,p[T]=t[ee][T]},oe=0,ae=Object.entries(m[d.attachment]);oe<ae.length;oe++)re();else{var ie=A.includes(ee)?m[ee]:g;k(ie,e,t,ee),N(ie,e,t,ee),[null,void 0].includes(ie.default)?(!(ie.nullable||Object.prototype.hasOwnProperty.call(e,ee)&&void 0!==e[ee]||t&&Object.prototype.hasOwnProperty.call(t,ee)&&w)&&s('MissingProperty: Missing property "'+ee+'"'+o+"."),(!Object.prototype.hasOwnProperty.call(e,ee)||void 0===e[ee])&&t&&Object.prototype.hasOwnProperty.call(t,ee)&&("fillUp"===w?e[ee]=t[ee]:!w&&(i=n.concat(ee+"","property removed")))):(!Object.prototype.hasOwnProperty.call(e,ee)||[null,void 0].includes(e[ee]))&&(t?null!==e[ee]&&"fillUp"===w?e[ee]=t[ee]:"migrate"===w&&(e[ee]=ie.default,i=n.concat(ee+"","migrate default value")):(e[ee]=ie.default,i=i.concat(ee+"","add default value")))}if(t&&"incremental"===w)for(var le=0,ce=Object.entries(e);le<ce.length;le++){var pe=ce[le],se=pe[0],ue=pe[1];Object.prototype.hasOwnProperty.call(t,se)&&!a.property.name.reserved.concat(f,h,d.conflict,d.deleted,d.deletedConflict,d.localSequence,d.revisions,d.revisionsInformation,v).includes(se)&&(t[se]===ue||M(t[se])===M(ue))&&delete e[se]}for(var me=0,ye=Object.entries(e);me<ye.length;me++){var de=ye[me],fe=de[0],he=de[1];if(!a.property.name.reserved.concat(h,d.conflict,d.deleted,d.deletedConflict,d.localSequence,d.revisions,d.revisionsInformation,d.strategy).includes(fe)){var ve=void 0;if(Object.prototype.hasOwnProperty.call(m,fe))ve=m[fe];else if(g)ve=g;else{if("migrate"===w){delete e[fe],i=n.concat(fe+"","migrate removed property");continue}s('Property: Given property "'+fe+'" isn\'t specified in model "'+u+'"'+o+".")}if(!ve)continue;if(d.attachment===fe){var ge=he;for(var be in ge)if(Object.prototype.hasOwnProperty.call(ge,be))for(var Oe=0,we=Object.keys(m[fe]);Oe<we.length;Oe++){var je=we[Oe],Pe=m[d.attachment][je];if(_(je,be,Pe)){x(Pe,e,t,be,o);break}}continue}if(x(ve,e,t,fe,o))continue;var xe="string"==typeof ve.type&&ve.type.endsWith("[]")||Array.isArray(ve.type)&&ve.type.length&&Array.isArray(ve.type[0]);if(xe&&![null,void 0].includes(he)){var ke,Ne=he;Array.isArray(Ne)?"number"==typeof ve.minimumNumber&&Ne.length<ve.minimumNumber?s('MinimumArrayLength: Property "'+fe+'" (array of length '+Ne.length+") doesn't fullfill minimum array length of "+ve.minimumNumber+o+"."):"number"==typeof ve.maximumNumber&&ve.maximumNumber<Ne.length&&s('MaximumArrayLength: Property "'+fe+'" (array of length '+Ne.length+") doesn't fullfill maximum array length of "+ve.maximumNumber+o+"."):s('PropertyType: Property "'+fe+'" isn\'t of type "array -> '+ve.type+'" (given "'+M(Ne)+'")'+o+"."),b(Ne,fe+"",ve,t&&Object.prototype.hasOwnProperty.call(t,fe)&&t[fe]||void 0,["arrayConstraintExecution","arrayConstraintExpression"]);var Ae={};for(var Se in ve)if(Object.prototype.hasOwnProperty.call(ve,Se))if("type"===Se){var Ce=ve[Se];Ae[Se]=Array.isArray(ve[Se])?Ce[0]:[Ce.substring(0,Ce.length-2)]}else Ae[Se]=ve[Se];if(1===(null==(ke=Ae.type)?void 0:ke.length)&&Object.prototype.hasOwnProperty.call(c,Ae.type[0]))for(var Te,De,ze=l(Ne.slice());!(Te=ze()).done;)"object"!=typeof(De=Te.value)||Object.getPrototypeOf(De)!==Object.prototype||Object.prototype.hasOwnProperty.call(De,v)||(De[v]=Ae.type[0]);for(var Me,Ue,Ee=0,_e=l(Ne.slice());!(Me=_e()).done;)Ue=Me.value,Ne[Ee]=j(Ue,Ee+1+". value in "+fe,Ae).newValue,[null,void 0].includes(Ne[Ee])&&Ne.splice(Ee,1),Ee+=1;t&&Object.prototype.hasOwnProperty.call(t,fe)&&Array.isArray(t[fe])&&t[fe].length===Ne.length&&M(t[fe])===M(Ne)||(i=n.concat(fe+"","array updated"))}else{var Re=t&&Object.prototype.hasOwnProperty.call(t,fe)?t[fe]:null,He=xe?{newValue:null,changedPath:[]}:j(he,fe+"",ve,Re);e[fe]=He.newValue,He.changedPath.length&&(i=He.changedPath),[null,void 0].includes(e[fe])&&(null!==Re&&(i=n.concat(fe+"","property removed")),("incremental"!==w||null!==Re)&&delete e[fe])}}}for(var Le=0,Ie=Object.keys(d.constraint);Le<Ie.length;Le++){var Ve=Ie[Le],We=d.constraint[Ve];if(Object.prototype.hasOwnProperty.call(m,We))for(var Fe,Be=m[We],qe=l([].concat(Be));!(Fe=qe()).done;){var Ye=Fe.value,$e=void 0;try{$e=H(Ye.evaluation,We===d.constraint.expression,{checkPropertyContent:j,model:m,modelName:u,type:We,newDocument:e,oldDocument:t,parentNames:n,pathDescription:o})}catch(e){var Je,Ge;if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&s('Compilation: Hook "'+We+'" has invalid code "'+e.code+'": "'+(null!==(Je=e.message)&&void 0!==Je?Je:"unknown")+'"'+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&s('Runtime: Hook "'+We+'" has thrown an error with code "'+e.code+'": "'+(null!==(Ge=e.message)&&void 0!==Ge?Ge:"unknown")+'"'+o+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}if($e&&!$e.result){var Ke=We.replace(/^[^a-zA-Z]+/,"");s(Ke.charAt(0).toUpperCase()+(Ke.substring(1)+": ")+(Ye.description?r(Function,Object.keys($e.scope).concat(["return "+Ye.description.trim()])).apply(void 0,Object.values($e.scope)):'Model "'+u+'" should satisfy constraint "'+$e.code+'" (given "'+M(e)+'")'+o+"."))}}}if(Object.prototype.hasOwnProperty.call(e,d.attachment)){var Ze,Qe,Xe=e[d.attachment];("object"!=typeof Xe||Object.getPrototypeOf(Xe)!==Object.prototype)&&s("AttachmentType: given attachment has invalid type"+o+".");var et=null;if(t&&Object.prototype.hasOwnProperty.call(t,d.attachment)&&(null!==(et=t[d.attachment])&&"object"==typeof et))for(var tt=0,nt=Object.entries(et);tt<nt.length;tt++){var rt=nt[tt],ot=rt[0],at=rt[1];if(at&&Object.prototype.hasOwnProperty.call(Xe,ot)){var it=Xe[ot];null===it||null===it.data||it.content_type===at.content_type&&(it.data===at.data||it.digest===at.digest)?((null===it||null===it.data)&&(i=n.concat(d.attachment,ot,"attachment removed")),"incremental"===w&&delete Xe[ot]):i=n.concat(d.attachment,ot,"attachment updated")}else"fillUp"===w?Xe[ot]=at:w||(i=n.concat(d.attachment,ot,"attachment removed"))}for(var lt=0,ct=Object.entries(Xe);lt<ct.length;lt++){var pt,st=ct[lt],ut=st[0],mt=st[1];if(!mt)break;null===mt.data?delete Xe[ut]:(!et||!Object.prototype.hasOwnProperty.call(et,ut)||mt.content_type!==(null==(pt=et[ut])?void 0:pt.content_type)||mt.data!==et[ut].data&&mt.digest!==et[ut].digest)&&(i=n.concat(d.attachment,ut,"attachment updated"))}0===Object.keys(Xe).length&&delete e[d.attachment];for(var yt=m[d.attachment],dt={},ft=0,ht=Object.keys(yt);ft<ht.length;ft++)dt[ht[ft]]=[];for(var vt=0,gt=Object.keys(Xe);vt<gt.length;vt++){for(var bt=gt[vt],Ot=!1,wt=0,jt=Object.entries(yt);wt<jt.length;wt++){var Pt=jt[wt],xt=Pt[0],kt=Pt[1];if(_(xt,bt,kt)){dt[xt].push(bt),Ot=!0;break}}Ot||s('AttachmentTypeMatch: None of the specified attachment types ("'+Object.keys(yt).join('", "')+'") matches given one ("'+bt+'")'+o+".")}for(var Nt=0,At=0,St=Object.keys(dt);At<St.length;At++){var Ct=St[At],Tt=yt[Ct];if(Object.prototype.hasOwnProperty.call(dt,Ct)){var Dt=dt[Ct].length;"number"==typeof Tt.maximumNumber&&Dt>Tt.maximumNumber&&s("AttachmentMaximum: given number of attachments ("+Dt+") doesn't satisfy specified maximum of "+Tt.maximumNumber+' from type "'+Ct+'"'+o+"."),(!Tt.nullable||0!==Dt)&&"number"==typeof Tt.minimumNumber&&Dt<Tt.minimumNumber&&s("AttachmentMinimum: given number of attachments ("+Dt+") doesn't satisfy specified minimum of "+Tt.minimumNumber+' from type "'+Ct+'"'+o+".");for(var zt,Mt=0,Ut=l(dt[Ct]);!(zt=Ut()).done;){var Et,_t,Rt,Ht=zt.value;if(null!=(Et=Tt.fileName)&&Et.pattern){for(var Lt,It,Vt=[].concat(Tt.fileName.pattern),Wt=!1,Ft=l(Vt);!(Lt=Ft()).done;)if(It=Lt.value,new RegExp(It).test(Ht)){Wt=!0;break}Wt||s('AttachmentName: given attachment name "'+Ht+'" doesn\'t satisfy one of specified regular expression patterns "'+Vt.join('", "')+'" from type "'+Ct+'"'+o+".")}if(null!=(_t=Tt.fileName)&&_t.invertedPattern)for(var Bt,qt,Yt=l([].concat(Tt.fileName.invertedPattern));!(Bt=Yt()).done;)qt=Bt.value,new RegExp(qt).test(Ht)&&s('InvertedAttachmentName: given attachment name "'+Ht+'" does satisfy specified regular expression pattern "'+qt.toString()+'" from type "'+Ct+'"'+o+".");if(null!=(Rt=Xe[Ht])&&Rt.content_type){if(Tt.contentTypePattern){for(var $t,Jt,Gt=[].concat(Tt.contentTypePattern),Kt=!1,Zt=l(Gt);!($t=Zt()).done;)if(Jt=$t.value,new RegExp(Jt).test(Xe[Ht].content_type)){Kt=!0;break}Kt||s('AttachmentContentType: given attachment content type "'+Xe[Ht].content_type+'" doesn\'t satisfy specified regular expression pattern "'+Gt.join('", "')+'" from type "'+Ct+'"'+o+".")}var Qt=Tt.invertedContentTypePattern;if(Qt)for(var Xt,en,tn=l([].concat(Qt));!(Xt=tn()).done;)en=Xt.value,new RegExp(en).test(Xe[Ht].content_type)&&s('InvertedAttachmentContentType: given attachment content type "'+Xe[Ht].content_type+'" does satisfy specified regular expression pattern "'+en.toString()+'" from type "'+Ct+'"'+o+".")}var nn=0;Xe[Ht]&&"length"in Xe[Ht]?nn=Xe[Ht].length:Xe[Ht]&&"data"in Xe[Ht]&&(nn="undefined"!=typeof Buffer&&"byteLength"in Buffer?Buffer.byteLength(Xe[Ht].data,"base64"):Xe[Ht].data.length),"number"==typeof Tt.minimumSize&&Tt.minimumSize>nn?s("AttachmentMinimumSize: given attachment size "+nn+" byte doesn't satisfy specified minimum of "+Tt.minimumSize+" byte "+o+"."):"number"==typeof Tt.maximumSize&&Tt.maximumSize<nn&&s("AttachmentMaximumSize: given attachment size "+nn+" byte doesn't satisfy specified maximum of "+Tt.maximumSize+" byte "+o+"."),Mt+=nn}"number"==typeof Tt.minimumAggregatedSize&&Tt.minimumAggregatedSize>Mt?s('AttachmentAggregatedMinimumSize: given aggregated size of attachments from type "'+Ct+'" '+Mt+" byte doesn't satisfy specified minimum of "+Tt.minimumAggregatedSize+" byte "+o+"."):"number"==typeof Tt.maximumAggregatedSize&&Tt.maximumAggregatedSize<Mt&&s('AttachmentAggregatedMaximumSize: given aggregated size of attachments from type "'+Ct+'" '+Mt+" byte doesn't satisfy specified maximum of "+Tt.maximumAggregatedSize+" byte "+o+"."),Nt+=Mt}}(null!==(Ze=m[d.minimumAggregatedSize])&&void 0!==Ze?Ze:0)>Nt?s("AggregatedMinimumSize: given aggregated size "+Nt+" byte doesn't satisfy specified minimum of "+m[d.minimumAggregatedSize]+" byte "+o+"."):(null!==(Qe=m[d.maximumAggregatedSize])&&void 0!==Qe?Qe:1/0)<Nt&&s("AggregatedMaximumSize: given aggregated size "+Nt+" byte doesn't satisfy specified maximum of "+m[d.maximumAggregatedSize]+" byte "+o+".")}if(t&&Object.prototype.hasOwnProperty.call(t,d.attachment)&&0===Object.keys(t[d.attachment]).length&&delete t[d.attachment],0===i.length&&t&&"migrate"===w)for(var rn,on=0,an=Object.keys(t);on<an.length;on++)rn=an[on],Object.prototype.hasOwnProperty.call(e,rn)||(i=n.concat(rn,"migrate removed property"));return{changedPath:i,newDocument:e}},I={attachmentWithPrefixExists:function(t){if(Object.prototype.hasOwnProperty.call(e,d.attachment)){var n=e[d.attachment],r=R(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:L,getFileNameByPrefix:R,serialize:M,id:g,revision:b,idName:f,revisionName:h,specialNames:d,typeName:v,modelConfiguration:a,models:c,now:u,nowUTCTimestamp:m,securitySettings:o,userContext:n},V=e[d.attachment];if(e[d.attachment])for(var W,F=0,B=Object.values(V);F<B.length;F++)null!=(W=B[F])&&W.contentType&&(W.content_type=W.contentType,delete W.contentType);var q=L(e,t);return(!q.newDocument._deleted||t)&&(q.newDocument._deleted&&q.newDocument._deleted!==(null==t?void 0:t._deleted)||q.changedPath.length)||s("NoChange: No new data given. new document: "+M(e)+"; old document: "+M(t)+"."),Object.prototype.hasOwnProperty.call(o,a.property.name.validatedDocumentsCache)?o[a.property.name.validatedDocumentsCache].add(g+"-"+b):o[a.property.name.validatedDocumentsCache]=new Set([g+"-"+b]),q.newDocument},u=e.exports;const m=u}],t={};function n(r){var o=t[r];if(void 0!==o)return o.exports;var a=t[r]={id:r,loaded:!1,exports:{}};return e[r](a,a.exports,n),a.loaded=!0,a.exports}n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.hmd=e=>((e=Object.create(e)).children||(e.children=[]),Object.defineProperty(e,"exports",{enumerable:!0,set:()=>{throw new Error("ES Modules may not assign module.exports or exports.*, Use ESM export syntax, instead: "+e.id)}}),e),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r=n(0);module.exports=r})();
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:()=>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.644";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})();
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.645";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 e(){var t,r;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=b.value,r=a[t].bind(a),a[t]=c()(l().mark((function e(t){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,r.apply(void 0,[t].concat(a));case 5:return e.abrupt("return",e.sent);case 8:if(e.prev=8,e.t0=e.catch(2),u=t[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]:t[s],e.t1=u,!(s in t)||["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 e.stop()}}),e)})),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(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
@@ -1,47 +1,46 @@
1
- import { PluginHandler, PluginPromises } from 'web-node/type';
1
+ import { PluginPromises } from 'web-node/type';
2
2
  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 toggleLatestRevisionDetermining - Token to provide to "bulkDocs"
6
+ * @property TOGGLE_LATEST_REVISION_DETERMINING - Token to provide to "bulkDocs"
7
7
  * method call to indicate id determination skip or not (depends on
8
8
  * "skipLatestRevisionDetermining" configuration).
9
9
  */
10
- export declare class Database implements PluginHandler {
11
- static toggleLatestRevisionDetermining: symbol;
12
- /**
13
- * Appends an application server to the web node services.
14
- * @param state - Application state.
15
- * @param state.configuration - Applications configuration.
16
- * @param state.configuration.couchdb - Plugins configuration.
17
- * @param state.services - Applications services.
18
- * @returns Promise resolving to nothing.
19
- */
20
- static preLoadService({ configuration: { couchdb: configuration }, services }: ServicesState): Promise<void>;
21
- /**
22
- * Start database's child process and return a Promise which observes this
23
- * service.
24
- * @param state - Application state.
25
- * @param state.configuration - Applications configuration.
26
- * @param state.services - Applications services.
27
- * @returns A mapping to promises which correspond to the plugin specific
28
- * continues services.
29
- */
30
- static loadService({ configuration, services }: State): Promise<PluginPromises>;
31
- /**
32
- * Add database event listener to auto restart database server on
33
- * unexpected server issues.
34
- * @param state - Application state.
35
- * @returns Promise resolving to nothing.
36
- */
37
- static postLoadService(state: State): Promise<void>;
38
- /**
39
- * Triggered when application will be closed soon.
40
- * @param state - Application state.
41
- * @param state.configuration - Applications configuration.
42
- * @param state.services - Applications services.
43
- * @returns Promise resolving to nothing.
44
- */
45
- static shouldExit({ configuration, services }: State): Promise<void>;
46
- }
47
- export default Database;
10
+ export declare const TOGGLE_LATEST_REVISION_DETERMINING: unique symbol;
11
+ /**
12
+ * Appends an application server to the web node services.
13
+ * @param state - Application state.
14
+ * @param state.configuration - Applications configuration.
15
+ * @param state.configuration.couchdb - Plugins configuration.
16
+ * @param state.services - Applications services.
17
+ * @returns Promise resolving to nothing.
18
+ */
19
+ export declare const preLoadService: ({ configuration: { couchdb: configuration }, services }: ServicesState) => Promise<void>;
20
+ /**
21
+ * Start database's child process and return a Promise which observes this
22
+ * service.
23
+ * @param state - Application state.
24
+ * @param state.configuration - Applications configuration.
25
+ * @param state.services - Applications services.
26
+ * @returns A mapping to promises which correspond to the plugin specific
27
+ * continues services.
28
+ */
29
+ export declare const loadService: ({ configuration, services }: State) => Promise<PluginPromises>;
30
+ /**
31
+ * Add database event listener to auto restart database server on unexpected
32
+ * server issues.
33
+ * @param state - Application state.
34
+ * @returns Promise resolving to nothing.
35
+ */
36
+ export declare const postLoadService: (state: State) => Promise<void>;
37
+ /**
38
+ * Triggered when application will be closed soon.
39
+ * @param state - Application state.
40
+ * @param state.configuration - Applications configuration.
41
+ * @param state.services - Applications services.
42
+ * @returns Promise resolving to nothing.
43
+ */
44
+ export declare const shouldExit: ({ configuration, services }: State) => Promise<void>;
45
+ export declare const database: any;
46
+ export default database;
package/index.js CHANGED
@@ -1 +1 @@
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.644";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__})();
1
+ (()=>{var __webpack_modules__=[(e,t,n)=>{"use strict";n.d(t,{determineAllowedModelRolesMapping:()=>h,determineGenericIndexablePropertyNames:()=>O,ensureValidationDocumentPresence:()=>f,extendModels:()=>v,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.645";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 e(){var t,n;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=f.value,n=a[t].bind(a),a[t]=c()(i().mark((function e(t){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,n.apply(void 0,[t].concat(a));case 5:return e.abrupt("return",e.sent);case 8:if(e.prev=8,e.t0=e.catch(2),u=t[_],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]:t[l],e.t1=u,!(l in t)||["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 e.stop()}}),e)})),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=v(e),a=0,c=Object.entries(r);a<c.length;a++){var _=c[a],i=_[0],s=_[1];if(s[t]){n[i]=o()({properties:{}},g(s[t]));for(var l=0,u=Object.entries(s);l<u.length;l++){var p=u[l],d=p[0],m=p[1];null!==m&&"object"==typeof m&&m.allowedRoles&&(n[i].properties[d]=g(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]},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]=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],v=O[0],g=O[1];b[v]=(0,s.extend)(!0,(0,s.copy)(e.property.defaultSpecification),g)}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},g=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")},(module,__webpack_exports__,__webpack_require__)=>{"use strict";__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,{TOGGLE_LATEST_REVISION_DETERMINING:()=>TOGGLE_LATEST_REVISION_DETERMINING,database:()=>database,default:()=>__WEBPACK_DEFAULT_EXPORT__,loadService:()=>loadService,postLoadService:()=>postLoadService,preLoadService:()=>preLoadService,shouldExit:()=>shouldExit});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__(6),fs__WEBPACK_IMPORTED_MODULE_4___default=__webpack_require__.n(fs__WEBPACK_IMPORTED_MODULE_4__),path__WEBPACK_IMPORTED_MODULE_5__=__webpack_require__(7),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__(8),_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}module=__webpack_require__.hmd(module);var TOGGLE_LATEST_REVISION_DETERMINING=Symbol("toggleLatestRevisionDetermining"),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,v,g,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]===TOGGLE_LATEST_REVISION_DETERMINING,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(TOGGLE_LATEST_REVISION_DETERMINING),e.next=41,this.bulkDocs.apply(this,[p].concat(i));case 41:for(x=e.sent,v=_createForOfIteratorHelperLoose(x);!(g=v()).done;)E=g.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)}}(),loadService=function(){var _ref5=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function _callee3(_ref4){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=_ref4.configuration,services=_ref4.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=215;break}return _context3.next=154,fs__WEBPACK_IMPORTED_MODULE_4__.promises.readFile(eval("require.resolve('./databaseHelper')"),{encoding:configuration.core.encoding,flag:"r"});case 154:databaseHelperCode=_context3.sent,_iterator8=_createForOfIteratorHelperLoose([{description:"Model specification",methodName:"validateDocumentUpdate",name:"validation",serializedParameter:JSON.stringify(modelConfiguration)+", "+JSON.stringify(models)},{description:"Authorisation",methodName:"authenticate",name:"authentication",serializedParameter:JSON.stringify((0,_helper__WEBPACK_IMPORTED_MODULE_9__.determineAllowedModelRolesMapping)(configuration.couchdb.model))+", '"+idName+"', '"+typeName+"', '"+specialNames.designDocumentNamePrefix+"'"}]);case 156:if((_step8=_iterator8()).done){_context3.next=172;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:if(configuration.core.debug&&console.debug(_type2.name+' code: \n\n"'+code+'" integrated.'),!couchdb.connection){_context3.next=170;break}return _context3.next=170,(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 170:_context3.next=156;break;case 172:_i2=0,_Object$entries=Object.entries(models);case 173:if(!(_i2<_Object$entries.length)){_context3.next=215;break}_Object$entries$_i=_Object$entries[_i2],modelName=_Object$entries$_i[0],model=_Object$entries$_i[1],_i3=0,_Object$entries2=Object.entries(model);case 176:if(!(_i3<_Object$entries2.length)){_context3.next=212;break}if(_Object$entries2$_i=_Object$entries2[_i3],_name=_Object$entries2$_i[0],specification=_Object$entries2$_i[1],![specialNames.constraint.execution,specialNames.constraint.expression].includes(_name)){_context3.next=194;break}_iterator9=_createForOfIteratorHelperLoose([].concat(specification));case 180:if((_step9=_iterator9()).done){_context3.next=192;break}if(constraint=_step9.value,!constraint.description){_context3.next=190;break}_context3.prev=183,new Function("return "+constraint.description),_context3.next=190;break;case 187:throw _context3.prev=187,_context3.t13=_context3.catch(183),new Error('Specified constraint description "'+constraint.description+'" for model "'+modelName+"\" doesn't compile: "+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(_context3.t13));case 190:_context3.next=180;break;case 192:_context3.next=209;break;case 194:_iterator10=_createForOfIteratorHelperLoose(["conflictingConstraintExpression","conflictingConstraintExecution","constraintExpression","constraintExecution"]);case 195:if((_step10=_iterator10()).done){_context3.next=209;break}if(_type=_step10.value,null===specification||"object"!=typeof specification){_context3.next=207;break}if(_constraint=specification[_type],null==_constraint||!_constraint.description){_context3.next=207;break}_context3.prev=200,new Function(_constraint.description),_context3.next=207;break;case 204:throw _context3.prev=204,_context3.t14=_context3.catch(200),new Error('Specified constraint description "'+_constraint.description+'" for model "'+modelName+'" in property "'+_name+'" as "'+_type+"\" doesn't compile: "+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(_context3.t14));case 207:_context3.next=195;break;case 209:_i3++,_context3.next=176;break;case 212:_i2++,_context3.next=173;break;case 215:if(!couchdb.connection||!configuration.couchdb.model.autoMigrationPath){_context3.next=320;break}return migrators={},_context3.next=219,(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.isDirectory)((0,path__WEBPACK_IMPORTED_MODULE_5__.resolve)(configuration.couchdb.model.autoMigrationPath));case 219:if(!_context3.sent){_context3.next=272;break}return _context3.t15=_createForOfIteratorHelperLoose,_context3.next=223,(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 223:_context3.t16=_context3.sent,_iterator11=(0,_context3.t15)(_context3.t16);case 225:if((_step11=_iterator11()).done){_context3.next=272;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=262;break}return documents=void 0,_context3.prev=231,_context3.t17=[],_context3.t18=JSON,_context3.next=236,fs__WEBPACK_IMPORTED_MODULE_4__.promises.readFile(file.path,{encoding:configuration.core.encoding,flag:"r"});case 236:_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=244;break;case 241:throw _context3.prev=241,_context3.t21=_context3.catch(231),new Error('Parsing document "'+file.path+'" to include by automigration of has failed: '+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(_context3.t21));case 244:1===documents.length&&(!documents[0][idName]&&(documents[0][idName]=_name2),!documents[0][revisionName]&&(documents[0][revisionName]="upsert")),_iterator12=_createForOfIteratorHelperLoose(documents);case 246:if((_step12=_iterator12()).done){_context3.next=260;break}return document=_step12.value,_context3.prev=248,_context3.next=251,couchdb.connection.put(document);case 251:_context3.next=257;break;case 253:throw _context3.prev=253,_context3.t22=_context3.catch(248),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 257:console.info('Including document "'+document[idName]+'" of type "'+document[typeName]+'" was successful.');case 258:_context3.next=246;break;case 260:_context3.next=270;break;case 262:if(![".js"].includes((0,path__WEBPACK_IMPORTED_MODULE_5__.extname)(file.name))){_context3.next=266;break}migrators[file.path]=eval("require('"+file.path+"')").default,_context3.next=270;break;case 266:if(![".mjs"].includes((0,path__WEBPACK_IMPORTED_MODULE_5__.extname)(file.name))){_context3.next=270;break}return _context3.next=269,eval("import('"+file.path+"')");case 269:migrators[file.path]=_context3.sent.default;case 270:_context3.next=225;break;case 272:return _context3.t23=_createForOfIteratorHelperLoose,_context3.next=275,couchdb.connection.allDocs({include_docs:!0});case 275:_context3.t24=_context3.sent.rows,_iterator13=(0,_context3.t23)(_context3.t24);case 277:if((_step13=_iterator13()).done){_context3.next=320;break}if(retrievedDocument=_step13.value,"string"==typeof retrievedDocument.id&&retrievedDocument.id.startsWith(configuration.couchdb.model.property.name.special.designDocumentNamePrefix)){_context3.next=318;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 284:if((_step14=_iterator14()).done){_context3.next=297;break}_name3=_step14.value,result=null,_context3.prev=287,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=294;break;case 291:throw _context3.prev=291,_context3.t25=_context3.catch(287),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 294:result&&(newDocument=result,console.info('Running migrater "'+_name3+'" for document "'+newDocument[idName]+'" (of type "'+newDocument[typeName]+'") was successful.'));case 295:_context3.next=284;break;case 297:_context3.prev=297,(0,_databaseHelper__WEBPACK_IMPORTED_MODULE_10__.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=309;break;case 301:if(_context3.prev=301,_context3.t26=_context3.catch(297),!Object.prototype.hasOwnProperty.call(_context3.t26,"forbidden")){_context3.next=308;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",318);case 308:throw _context3.t26;case 309:return _context3.prev=309,_context3.next=312,couchdb.connection.put(newDocument);case 312:_context3.next=317;break;case 314:throw _context3.prev=314,_context3.t27=_context3.catch(309),new Error('Replacing auto migrated document "'+newDocument[idName]+'" has failed: '+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(_context3.t27));case 317:console.info('Auto migrating document "'+newDocument[idName]+'" was successful.');case 318:_context3.next=277;break;case 320:if(!(couchdb.connection&&configuration.couchdb.createGenericFlatIndex&&configuration.couchdb.model.autoMigrationPath)){_context3.next=375;break}return _context3.next=323,couchdb.connection.getIndexes();case 323:indexes=_context3.sent.indexes,_i4=0,_Object$entries3=Object.entries(models);case 325:if(!(_i4<_Object$entries3.length)){_context3.next=356;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=353;break}return _context3.next=330,couchdb.connection.createIndex({index:{ddoc:_modelName+"-GenericIndex",fields:[typeName],name:_modelName+"-GenericIndex"}});case 330:_iterator15=_createForOfIteratorHelperLoose((0,_helper__WEBPACK_IMPORTED_MODULE_9__.determineGenericIndexablePropertyNames)(configuration.couchdb.model,_model));case 331:if((_step15=_iterator15()).done){_context3.next=353;break}propertyName=_step15.value,_name4=_modelName+"-"+propertyName+"-GenericIndex",foundPosition=-1,position=0,_iterator16=_createForOfIteratorHelperLoose(indexes);case 337:if((_step16=_iterator16()).done){_context3.next=345;break}if(index=_step16.value,index.name!==_name4){_context3.next=342;break}return foundPosition=position,_context3.abrupt("break",345);case 342:position+=1;case 343:_context3.next=337;break;case 345:if(-1!==foundPosition){_context3.next=350;break}return _context3.next=348,couchdb.connection.createIndex({index:{ddoc:_name4,fields:[typeName,propertyName],name:_name4}});case 348:_context3.next=351;break;case 350:indexes.slice(position,1);case 351:_context3.next=331;break;case 353:_i4++,_context3.next=325;break;case 356:_iterator17=_createForOfIteratorHelperLoose(indexes);case 357:if((_step17=_iterator17()).done){_context3.next=375;break}if(_index=_step17.value,!_index.name.endsWith("-GenericIndex")){_context3.next=373;break}exists=!1,_i5=0,_Object$entries4=Object.entries(models);case 362:if(!(_i5<_Object$entries4.length)){_context3.next=370;break}if(_Object$entries4$_i=_Object$entries4[_i5],_modelName2=_Object$entries4$_i[0],_model2=_Object$entries4$_i[1],!_index.name.startsWith(_modelName2+"-")){_context3.next=367;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",370);case 367:_i5++,_context3.next=362;break;case 370:if(exists){_context3.next=373;break}return _context3.next=373,couchdb.connection.deleteIndex(_index);case 373:_context3.next=357;break;case 375:if(!couchdb.connection||!configuration.couchdb.model.triggerInitialCompaction){_context3.next=384;break}return _context3.prev=376,_context3.next=379,couchdb.connection.compact();case 379:_context3.next=384;break;case 381:_context3.prev=381,_context3.t28=_context3.catch(376),console.warn("Initial database compaction has failed: "+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(_context3.t28));case 384:return _context3.abrupt("return",{couchdb:promise});case 385: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],[183,187],[200,204],[231,241],[248,253],[287,291],[297,301],[309,314],[376,381]])})));return function(){return _ref5.apply(this,arguments)}}(),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.connection&&(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()},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=module.exports;const __WEBPACK_DEFAULT_EXPORT__=database},e=>{"use strict";e.exports=require("fs")},e=>{"use strict";e.exports=require("path")},e=>{!function(){"use strict";function t(e){var o=r[e];if(void 0!==o)return o.exports;var a=r[e]={id:e,loaded:!1,exports:{}};return n[e](a,a.exports,t),a.loaded=!0,a.exports}var n=[function(e,t,n){function r(e,t,n){if(a())return Reflect.construct.apply(null,arguments);var r=[null];r.push.apply(r,t);var c=new(e.bind.apply(e,r));return n&&o(c,n.prototype),c}function o(e,t){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},o(e,t)}function a(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(a=function(){return!!e})()}function c(){return c=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},c.apply(null,arguments)}function _(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 i(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)?i(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 i(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}n.r(t),n.d(t,{authenticate:function(){return s},databaseHelper:function(){return u},default:function(){return p},validateDocumentUpdate:function(){return l}}),e=n.hmd(e);var s=function(e,t,n,r,o,a,c,i,s){var l,u,p;void 0===t&&(t=null),void 0===n&&(n={}),void 0===r&&(r={admins:{names:[],roles:[]},members:{names:[],roles:[]}}),void 0===a&&(a="_id"),void 0===c&&(c="-type"),void 0===i&&(i="_design/"),void 0===s&&(s=!1);var d=null!==(l=e[c])&&void 0!==l?l:t&&t[c];if(!d)return!0;var m=s?"read":"write",f={properties:{},read:["_admin","readonlyadmin"],write:["_admin"]};Object.prototype.hasOwnProperty.call(e,a)&&e[a].startsWith(i)&&f.read.push("readonlymember");var b="Current user doesn't own any role";if("name"in n||(n.name='"unknown"'),null!=(u=n.roles)&&u.length){var h;if(o&&d&&Object.prototype.hasOwnProperty.call(o,d)){for(var y,O,x=o[d],v=_(["read","write"]);!(y=v()).done;)f[O=y.value]=f[O].concat(x[O]||[]);f.properties=x.properties}for(var g,E,P=f[m],D=_(n.roles);!(g=D()).done;)if(E=g.value,P.includes(E))return!0;b='Current user "'+(null!==(h=n.name)&&void 0!==h?h:"unknown")+'" owns the following roles: "'+n.roles.join('", "')+'"'}else b='Current user "'+(null!==(p=n.name)&&void 0!==p?p:"unknown")+"\" doesn't own anyrole";throw{unauthorized:"Only users with a least on of these roles are allowed to perform requested "+m+' action: "'+[].concat(f[m]).join('", "')+'". '+b+"."}},l=function(e,t,n,o,a,i,s){void 0===i&&(i={});var l=function(e,t,n){var r;throw void 0===t&&(t="forbidden"),void 0===n&&(n={}),c(((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=!a.dateTimeFormat.startsWith("iso"),m=a.property.name.special,f=m.id,b=m.revision,h=m.type;t&&t[h]&&!e[h]&&(e[h]=t[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(o,a.property.name.validatedDocumentsCache)&&o[a.property.name.validatedDocumentsCache].has(y+"-"+O))return o[a.property.name.validatedDocumentsCache].delete(y+"-"+O),e;["latest","upsert"].includes(O)&&(t&&Object.prototype.hasOwnProperty.call(t,b)?O=e[b]=t[b]:"latest"===O?l("Revision: No old document available to update."):delete e[b]);var v=a.updateStrategy;Object.prototype.hasOwnProperty.call(e,m.strategy)&&(v=e[m.strategy],delete e[m.strategy]);var g,E={};if("migrate"===v)for(var P=0,D=Object.entries(i);P<D.length;P++){var M=D[P],w=M[0],k=M[1];if(Object.prototype.hasOwnProperty.call(k,m.oldType)&&k[m.oldType])for(var C,T,A=_([].concat(k[m.oldType]));!(C=A()).done;)T=C.value,E[T]=w}s?g=s:"undefined"!=typeof JSON&&Object.prototype.hasOwnProperty.call(JSON,"stringify")?g=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+"":g(e)},L=function(e){return"string"==typeof e?e.trim():""},R=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,t,n){void 0===t&&(t=!1),void 0===n&&(n={});var o=c({},N,{code:""},n),a=L(e);if(a){var _=(t?"return ":"")+a;o.code=_;var i,s=Object.keys(o);try{i=r(Function,s.concat([_]))}catch(e){l(j(e),"compilation",{code:_,error:e,scope:o})}var u={code:_,result:void 0,scope:o};try{u.result=i.apply(void 0,s.map((function(e){return o[e]})))}catch(e){l(j(e),"runtime",{code:_,error:e,scope:o})}return u}return l("No expression to evaluate provided.","empty"),{code:o.code,result:void 0,scope:o}},K=function(e,t,n){void 0===n&&(n=[]);var o=n.length?" in "+n.join(" -> "):"",c=[],s=function(){Object.prototype.hasOwnProperty.call(e,h)||(t&&Object.prototype.hasOwnProperty.call(t,h)&&["fillUp","migrate"].includes(v)?e[h]=t[h]:l('Type: You have to specify a model type via property "'+h+'"'+o+".")),n.length||new RegExp(a.property.name.typePattern.public).test(e[h])||l('TypeName: You have to specify a model type which matches "'+a.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(a,c,i,s,u){void 0===u&&(u=["constraintExecution","constraintExpression"]);for(var d,m,f=_(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:g,model:y,modelName:p,name:c,type:m,newDocument:e,newValue:a,oldDocument:t,oldValue:s,parentNames:n,pathDescription:o,propertySpecification:i})}catch(c){var h,O;if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(c)&&l('Compilation: Hook "'+m+'" has invalid code "'+c.code+'": "'+(null!==(h=c.message)&&void 0!==h?h:"unknown")+'"'+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(c)&&l('Runtime: Hook "'+m+'" has throw an error with code "'+c.code+'": "'+(null!==(O=c.message)&&void 0!==O?O:"unknown")+'"'+o+"."),!Object.prototype.hasOwnProperty.call(c,"empty"))throw c}if(b&&!b.result){var x,v=L(null==(x=i[m])?void 0:x.description);l(m.charAt(0).toUpperCase()+(m.substring(1)+": ")+(v?r(Function,Object.keys(b.scope).concat(["return "+v])).apply(void 0,Object.values(b.scope)):'Property "'+c+'" should satisfy constraint "'+b.code+'" (given "'+j(a)+'")'+o+"."))}}},g=function(e,t,r,a){var c=[],s=[].concat(r.type?r.type:[]);"object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype&&!Object.prototype.hasOwnProperty.call(e,h)&&1===s.length&&Object.prototype.hasOwnProperty.call(i,s[0])&&(e[h]=s[0]);for(var u,p,m=!1,b=_(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"===v&&1===s.length&&(e[h]=p,c=n.concat(t+"","migrate nested object type")),"object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype&&Object.prototype.hasOwnProperty.call(e,h)&&e[h]===p){var y=K(e,a,n.concat(t+""));if(y.changedPath.length&&(c=y.changedPath),e=y.newDocument,j(e)===j({}))return{newValue:void 0,changedPath:c};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=R(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 g=i[p.substring(11)][f].type;if(g===typeof e){m=!0;break}1===s.length&&l('PropertyType: Foreign key property "'+t+'" isn\'t of type "'+g+'" (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 r.minimumLength&&e.length<r.minimumLength&&l('MinimalLength: Property "'+t+'" must have minimal length '+r.minimumLength+" (given "+e+" with length "+e.length+")"+o+"."),"number"==typeof r.maximumLength&&e.length>r.maximumLength&&l('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&&l('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&&l('Maximum: Property "'+t+'" (type '+r.type+") must satisfy a maximum of "+r.maximum+" (given "+e+" is too high)"+o+".")),r.selection){var E=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&&(E=E.map(R)),E.includes(e)||l('Selection: Property "'+t+'" (type '+r.type+') should be one of "'+E.join('", "')+'". But is "'+e+'"'+o+".")}if(r.pattern){for(var P,D,M=[].concat(r.pattern),w=!1,k=_(M);!(P=k()).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(r.invertedPattern)for(var C,T,A=_([].concat(r.invertedPattern));!(C=A()).done;)T=C.value,new RegExp(T).test(e)&&l('InvertedPatternMatch: Property "'+t+'" should not match regular expression pattern '+T+' (given "'+e+'")'+o+".");return O(e,t,r,a),j(e)!==j(a)&&(c=n.concat(t+"","value updated")),{newValue:e,changedPath:c}},P=function(e,t,r,o,_){var i=t[o];if(!e.writable)if(r){if(Object.prototype.hasOwnProperty.call(r,o)&&j(i)===j(r[o]))return o!==f&&"incremental"===v&&delete t[o],!0;l("Readonly: Property "+o+'" isnot writable (old document "'+j(r)+'")'+_+".")}else l('Readonly: Property "'+o+'" is not writable'+_+".");if(!e.mutable&&r&&Object.prototype.hasOwnProperty.call(r,o)){if(j(i)===j(r[o]))return"incremental"!==v||a.property.name.reserved.concat(m.deleted,f,b).includes(o+"")||delete t[o],!0;"migrate"!==v&&l('Immutable: Property "'+o+'"is not writable (old document "'+j(r)+'")'+_+".")}if(null===i){if(e.nullable)return"incremental"===v&&r&&void 0!==r[o]||delete t[o],r&&Object.prototype.hasOwnProperty.call(r,o)&&(c=n.concat(o+"","delete property")),!0;l('NotNull: Property "'+o+'" should not be "null"'+_+".")}return!1},D=function(e,t,r,a,c){if(!r)for(var i,s,u=_(["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:c,checkPropertyContent:g,model:y,modelName:p,name:a+"",type:s,newDocument:t,oldDocument:r,newValue:void 0,oldValue:void 0,parentNames:n,pathDescription:o,propertySpecification:e})}catch(c){var m,f;if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(c)&&l('Compilation: Hook "'+s+'" has invalid code "'+c.code+'" for property "'+a+'": "'+(null!==(m=c.message)&&void 0!==m?m:"unknown")+'"'+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(c)&&l('Runtime: Hook "'+s+'" has throw an error with code "'+c.code+'" for property "'+a+'": "'+(null!==(f=c.message)&&void 0!==f?f:"unknown")+'"'+o+"."),!Object.prototype.hasOwnProperty.call(c,"empty"))throw c}d&&![null,void 0].includes(d.result)&&(c?c[a]=d.result:t[a]=d.result)}},M=function(e,t,r,a,c){if(!c){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 i,s,u=_(["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:c,checkPropertyContent:g,model:y,modelName:p,name:a+"",type:s,newDocument:t,oldDocument:r,newValue:t[a],oldValue:r&&r[a]||void 0,parentNames:n,pathDescription:o,propertySpecification:e});c?c[a]=d.result:void 0!==d.result&&(t[a]=d.result)}catch(c){var m,f;if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(c)&&l('Compilation: Hook "'+s+'" has invalid code "'+c.code+'" for property "'+a+'": "'+(null!==(m=c.message)&&void 0!==m?m:"unknown")+'"'+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(c)&&l('Runtime: Hook "'+s+'" has throw an error with code "'+c.code+'" for property "'+a+'": "'+(null!==(f=c.message)&&void 0!==f?f:"unknown")+'"'+o+"."),!Object.prototype.hasOwnProperty.call(c,"empty"))throw c}},w=Object.keys(y).filter((function(e){return!I.includes(e)}));if("migrate"===v)for(var k,C,T=_(w);!(k=T()).done;)if(C=k.value,y[C].oldName)for(var A,W,N=_([].concat(y[C].oldName));!(A=N()).done;)W=A.value,Object.prototype.hasOwnProperty.call(e,W)&&(e[C]=e[W],delete e[W]);if(!t)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:g,model:y,modelName:p,type:S,newDocument:e,oldDocument:t,parentNames:n,pathDescription:o}).result}catch(s){var F,H;if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(s)&&l('Compilation: Hook "'+S+'" has invalid code "'+s.code+'" for document "'+p+'": "'+(null!==(F=s.message)&&void 0!==F?F:"unknown")+'"'+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(s)&&l('Runtime: Hook "'+S+'" has throw an error with code "'+s.code+'" for document "'+p+'": "'+(null!==(H=s.message)&&void 0!==H?H:"unknown")+'"'+o+"."),!Object.prototype.hasOwnProperty.call(s,"empty"))throw s}[null,void 0].includes(z)||(e=z),s(),p=e[h],0===n.length&&x()}for(var G,V=0,J=[m.update.execution,m.update.expression];V<J.length;V++)if(G=J[V],Object.prototype.hasOwnProperty.call(y,G)){var Y=void 0;try{Y=B(y[G],G.endsWith("Expression"),{checkPropertyContent:g,model:y,modelName:p,type:G,newDocument:e,oldDocument:t,parentNames:n,pathDescription:o}).result}catch(s){var X,Z;if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(s)&&l('Compilation: Hook "'+G+'" has invalid code "'+s.code+'" for document "'+p+'": "'+(null!==(X=s.message)&&void 0!==X?X:"unknown")+'"'+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(s)&&l('Runtime: Hook "'+G+'" has throw an error with code "'+s.code+'" for document "'+p+'": "'+(null!==(Z=s.message)&&void 0!==Z?Z:"unknown")+'"'+o+"."),!Object.prototype.hasOwnProperty.call(s,"empty"))throw s}[void 0,null].includes(Y)||(e=Y),s(),p=e[h],0===n.length&&x()}for(var Q,ee,te=u?Object.keys(e).filter((function(e){return!w.includes(e)})):[],ne=_(w.concat(te));!(Q=ne()).done;)if(ee=Q.value,m.attachment===ee)for(var re=function(){var r=ae[oe],a=r[0],i=r[1];[null,void 0].includes(e[m.attachment])&&(e[m.attachment]={}),t&&!Object.prototype.hasOwnProperty.call(t,ee)&&(t[m.attachment]={});var s=e[m.attachment],u=Object.keys(s).filter((function(e){return null!==s[e].data&&U(a,e,i)})),p=[];if(t){var d=t[ee];p=Object.keys(d).filter((function(e){return!(Object.prototype.hasOwnProperty.call(s,e)&&Object.prototype.hasOwnProperty.call(s[e],"data")&&null===s[e].data)&&!!d[e]&&(Object.prototype.hasOwnProperty.call(d[e],"data")&&null!==d[e].data||Object.prototype.hasOwnProperty.call(d[e],"stub")&&!!d[e].digest)&&!!U(a,e,i)}))}for(var f,b,h=i,y=_(u);!(f=y()).done;)b=f.value,D(h,e,t&&t[ee]?t[ee]:null,b,s);for(var O,x,g=_(u);!(O=g()).done;)x=O.value,M(h,e,t&&t[ee]?t[ee]:null,x,s);if(void 0===h.default){if(h.nullable||0<u.length||0<p.length||l('AttachmentMissing: Missing attachment for type "'+a+'"'+o+"."),"fillUp"===v&&0===u.length&&0<p.length)for(var E,P,w=_(p);!(E=w()).done;)P=E.value,null===s[P]?c=n.concat(ee,P,"file removed"):s[P]=t[ee][P]}else if(0===u.length)if(0===p.length)for(var k in h.default)Object.prototype.hasOwnProperty.call(h.default,k)&&(s[k]=h.default[k],c=n.concat(ee,a,"add default file"));else if("fillUp"===v)for(var C,T,A=_(p);!(C=A()).done;)T=C.value,s[T]=t[ee][T]},oe=0,ae=Object.entries(y[m.attachment]);oe<ae.length;oe++)re();else{var ce=w.includes(ee)?y[ee]:u;D(ce,e,t,ee),M(ce,e,t,ee),[null,void 0].includes(ce.default)?(!(ce.nullable||Object.prototype.hasOwnProperty.call(e,ee)&&void 0!==e[ee]||t&&Object.prototype.hasOwnProperty.call(t,ee)&&v)&&l('MissingProperty: Missing property "'+ee+'"'+o+"."),(!Object.prototype.hasOwnProperty.call(e,ee)||void 0===e[ee])&&t&&Object.prototype.hasOwnProperty.call(t,ee)&&("fillUp"===v?e[ee]=t[ee]:!v&&(c=n.concat(ee+"","property removed")))):(!Object.prototype.hasOwnProperty.call(e,ee)||[null,void 0].includes(e[ee]))&&(t?null!==e[ee]&&"fillUp"===v?e[ee]=t[ee]:"migrate"===v&&(e[ee]=ce.default,c=n.concat(ee+"","migrate default value")):(e[ee]=ce.default,c=c.concat(ee+"","add default value")))}if(t&&"incremental"===v)for(var _e=0,ie=Object.entries(e);_e<ie.length;_e++){var se=ie[_e],le=se[0],ue=se[1];Object.prototype.hasOwnProperty.call(t,le)&&!a.property.name.reserved.concat(f,b,m.conflict,m.deleted,m.deletedConflict,m.localSequence,m.revisions,m.revisionsInformation,h).includes(le)&&(t[le]===ue||j(t[le])===j(ue))&&delete e[le]}for(var pe=0,de=Object.entries(e);pe<de.length;pe++){var me=de[pe],fe=me[0],be=me[1];if(!a.property.name.reserved.concat(b,m.conflict,m.deleted,m.deletedConflict,m.localSequence,m.revisions,m.revisionsInformation,m.strategy).includes(fe)){var he=void 0;if(Object.prototype.hasOwnProperty.call(y,fe))he=y[fe];else if(u)he=u;else{if("migrate"===v){delete e[fe],c=n.concat(fe+"","migrate removed property");continue}l('Property: Given property "'+fe+'" isn\'t specified in model "'+p+'"'+o+".")}if(!he)continue;if(m.attachment===fe){var ye=be;for(var Oe in ye)if(Object.prototype.hasOwnProperty.call(ye,Oe))for(var xe=0,ve=Object.keys(y[fe]);xe<ve.length;xe++){var ge=ve[xe],Ee=y[m.attachment][ge];if(U(ge,Oe,Ee)){P(Ee,e,t,Oe,o);break}}continue}if(P(he,e,t,fe,o))continue;var Pe="string"==typeof he.type&&he.type.endsWith("[]")||Array.isArray(he.type)&&he.type.length&&Array.isArray(he.type[0]);if(Pe&&![null,void 0].includes(be)){var De,Me=be;Array.isArray(Me)?"number"==typeof he.minimumNumber&&Me.length<he.minimumNumber?l('MinimumArrayLength: Property "'+fe+'" (array of length '+Me.length+") doesn't fullfill minimum array length of "+he.minimumNumber+o+"."):"number"==typeof he.maximumNumber&&he.maximumNumber<Me.length&&l('MaximumArrayLength: Property "'+fe+'" (array of length '+Me.length+") doesn't fullfill maximum array length of "+he.maximumNumber+o+"."):l('PropertyType: Property "'+fe+'" isn\'t of type "array -> '+he.type+'" (given "'+j(Me)+'")'+o+"."),O(Me,fe+"",he,t&&Object.prototype.hasOwnProperty.call(t,fe)&&t[fe]||void 0,["arrayConstraintExecution","arrayConstraintExpression"]);var we={};for(var ke in he)if(Object.prototype.hasOwnProperty.call(he,ke))if("type"===ke){var Ce=he[ke];we[ke]=Array.isArray(he[ke])?Ce[0]:[Ce.substring(0,Ce.length-2)]}else we[ke]=he[ke];if(1===(null==(De=we.type)?void 0:De.length)&&Object.prototype.hasOwnProperty.call(i,we.type[0]))for(var Te,Ae,Ie=_(Me.slice());!(Te=Ie()).done;)"object"!=typeof(Ae=Te.value)||Object.getPrototypeOf(Ae)!==Object.prototype||Object.prototype.hasOwnProperty.call(Ae,h)||(Ae[h]=we.type[0]);for(var je,Le,Re=0,Ue=_(Me.slice());!(je=Ue()).done;)Le=je.value,Me[Re]=g(Le,Re+1+". value in "+fe,we).newValue,[null,void 0].includes(Me[Re])&&Me.splice(Re,1),Re+=1;t&&Object.prototype.hasOwnProperty.call(t,fe)&&Array.isArray(t[fe])&&t[fe].length===Me.length&&j(t[fe])===j(Me)||(c=n.concat(fe+"","array updated"))}else{var We=t&&Object.prototype.hasOwnProperty.call(t,fe)?t[fe]:null,Be=Pe?{newValue:null,changedPath:[]}:g(be,fe+"",he,We);e[fe]=Be.newValue,Be.changedPath.length&&(c=Be.changedPath),[null,void 0].includes(e[fe])&&(null!==We&&(c=n.concat(fe+"","property removed")),("incremental"!==v||null!==We)&&delete e[fe])}}}for(var Ke=0,Ne=Object.keys(m.constraint);Ke<Ne.length;Ke++){var Se=Ne[Ke],qe=m.constraint[Se];if(Object.prototype.hasOwnProperty.call(y,qe))for(var $e,ze=y[qe],Fe=_([].concat(ze));!($e=Fe()).done;){var He=$e.value,Ge=void 0;try{Ge=B(He.evaluation,qe===m.constraint.expression,{checkPropertyContent:g,model:y,modelName:p,type:qe,newDocument:e,oldDocument:t,parentNames:n,pathDescription:o})}catch(s){var Ve,Je;if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(s)&&l('Compilation: Hook "'+qe+'" has invalid code "'+s.code+'": "'+(null!==(Ve=s.message)&&void 0!==Ve?Ve:"unknown")+'"'+o+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(s)&&l('Runtime: Hook "'+qe+'" has thrown an error with code "'+s.code+'": "'+(null!==(Je=s.message)&&void 0!==Je?Je:"unknown")+'"'+o+"."),!Object.prototype.hasOwnProperty.call(s,"empty"))throw s}if(Ge&&!Ge.result){var Ye=qe.replace(/^[^a-zA-Z]+/,"");l(Ye.charAt(0).toUpperCase()+(Ye.substring(1)+": ")+(He.description?r(Function,Object.keys(Ge.scope).concat(["return "+He.description.trim()])).apply(void 0,Object.values(Ge.scope)):'Model "'+p+'" should satisfy constraint "'+Ge.code+'" (given "'+j(e)+'")'+o+"."))}}}if(Object.prototype.hasOwnProperty.call(e,m.attachment)){var Xe,Ze,Qe=e[m.attachment];("object"!=typeof Qe||Object.getPrototypeOf(Qe)!==Object.prototype)&&l("AttachmentType: given attachment has invalid type"+o+".");var et=null;if(t&&Object.prototype.hasOwnProperty.call(t,m.attachment)&&null!==(et=t[m.attachment])&&"object"==typeof et)for(var tt=0,nt=Object.entries(et);tt<nt.length;tt++){var rt=nt[tt],ot=rt[0],at=rt[1];if(at&&Object.prototype.hasOwnProperty.call(Qe,ot)){var ct=Qe[ot];null===ct||null===ct.data||ct.content_type===at.content_type&&(ct.data===at.data||ct.digest===at.digest)?((null===ct||null===ct.data)&&(c=n.concat(m.attachment,ot,"attachment removed")),"incremental"===v&&delete Qe[ot]):c=n.concat(m.attachment,ot,"attachment updated")}else"fillUp"===v?Qe[ot]=at:v||(c=n.concat(m.attachment,ot,"attachment removed"))}for(var _t=0,it=Object.entries(Qe);_t<it.length;_t++){var st,lt=it[_t],ut=lt[0],pt=lt[1];if(!pt)break;null===pt.data?delete Qe[ut]:(!et||!Object.prototype.hasOwnProperty.call(et,ut)||pt.content_type!==(null==(st=et[ut])?void 0:st.content_type)||pt.data!==et[ut].data&&pt.digest!==et[ut].digest)&&(c=n.concat(m.attachment,ut,"attachment updated"))}0===Object.keys(Qe).length&&delete e[m.attachment];for(var dt=y[m.attachment],mt={},ft=0,bt=Object.keys(dt);ft<bt.length;ft++)mt[bt[ft]]=[];for(var ht=0,yt=Object.keys(Qe);ht<yt.length;ht++){for(var Ot=yt[ht],xt=!1,vt=0,gt=Object.entries(dt);vt<gt.length;vt++){var Et=gt[vt],Pt=Et[0],Dt=Et[1];if(U(Pt,Ot,Dt)){mt[Pt].push(Ot),xt=!0;break}}xt||l('AttachmentTypeMatch: None of the specified attachment types ("'+Object.keys(dt).join('", "')+'") matches given one ("'+Ot+'")'+o+".")}for(var Mt=0,wt=0,kt=Object.keys(mt);wt<kt.length;wt++){var Ct=kt[wt],Tt=dt[Ct];if(Object.prototype.hasOwnProperty.call(mt,Ct)){var At=mt[Ct].length;"number"==typeof Tt.maximumNumber&&At>Tt.maximumNumber&&l("AttachmentMaximum: given number of attachments ("+At+") doesn't satisfy specified maximum of "+Tt.maximumNumber+' from type "'+Ct+'"'+o+"."),(!Tt.nullable||0!==At)&&"number"==typeof Tt.minimumNumber&&At<Tt.minimumNumber&&l("AttachmentMinimum: given number of attachments ("+At+") doesn't satisfy specified minimum of "+Tt.minimumNumber+' from type "'+Ct+'"'+o+".");for(var It,jt=0,Lt=_(mt[Ct]);!(It=Lt()).done;){var Rt,Ut,Wt,Bt=It.value;if(null!=(Rt=Tt.fileName)&&Rt.pattern){for(var Kt,Nt,St=[].concat(Tt.fileName.pattern),qt=!1,$t=_(St);!(Kt=$t()).done;)if(Nt=Kt.value,new RegExp(Nt).test(Bt)){qt=!0;break}qt||l('AttachmentName: given attachment name "'+Bt+'" doesn\'t satisfy one of specified regular expression patterns "'+St.join('", "')+'" from type "'+Ct+'"'+o+".")}if(null!=(Ut=Tt.fileName)&&Ut.invertedPattern)for(var zt,Ft,Ht=_([].concat(Tt.fileName.invertedPattern));!(zt=Ht()).done;)Ft=zt.value,new RegExp(Ft).test(Bt)&&l('InvertedAttachmentName: given attachment name "'+Bt+'" does satisfy specified regular expression pattern "'+Ft.toString()+'" from type "'+Ct+'"'+o+".");if(null!=(Wt=Qe[Bt])&&Wt.content_type){if(Tt.contentTypePattern){for(var Gt,Vt,Jt=[].concat(Tt.contentTypePattern),Yt=!1,Xt=_(Jt);!(Gt=Xt()).done;)if(Vt=Gt.value,new RegExp(Vt).test(Qe[Bt].content_type)){Yt=!0;break}Yt||l('AttachmentContentType: given attachment content type "'+Qe[Bt].content_type+'" doesn\'t satisfy specified regular expression pattern "'+Jt.join('", "')+'" from type "'+Ct+'"'+o+".")}var Zt=Tt.invertedContentTypePattern;if(Zt)for(var Qt,en,tn=_([].concat(Zt));!(Qt=tn()).done;)en=Qt.value,new RegExp(en).test(Qe[Bt].content_type)&&l('InvertedAttachmentContentType: given attachment content type "'+Qe[Bt].content_type+'" does satisfy specified regular expression pattern "'+en.toString()+'" from type "'+Ct+'"'+o+".")}var nn=0;Qe[Bt]&&"length"in Qe[Bt]?nn=Qe[Bt].length:Qe[Bt]&&"data"in Qe[Bt]&&(nn="undefined"!=typeof Buffer&&"byteLength"in Buffer?Buffer.byteLength(Qe[Bt].data,"base64"):Qe[Bt].data.length),"number"==typeof Tt.minimumSize&&Tt.minimumSize>nn?l("AttachmentMinimumSize: given attachment size "+nn+" byte doesn't satisfy specified minimum of "+Tt.minimumSize+" byte "+o+"."):"number"==typeof Tt.maximumSize&&Tt.maximumSize<nn&&l("AttachmentMaximumSize: given attachment size "+nn+" byte doesn't satisfy specified maximum of "+Tt.maximumSize+" byte "+o+"."),jt+=nn}"number"==typeof Tt.minimumAggregatedSize&&Tt.minimumAggregatedSize>jt?l('AttachmentAggregatedMinimumSize: given aggregated size of attachments from type "'+Ct+'" '+jt+" byte doesn't satisfy specified minimum of "+Tt.minimumAggregatedSize+" byte "+o+"."):"number"==typeof Tt.maximumAggregatedSize&&Tt.maximumAggregatedSize<jt&&l('AttachmentAggregatedMaximumSize: given aggregated size of attachments from type "'+Ct+'" '+jt+" byte doesn't satisfy specified maximum of "+Tt.maximumAggregatedSize+" byte "+o+"."),Mt+=jt}}(null!==(Xe=y[m.minimumAggregatedSize])&&void 0!==Xe?Xe:0)>Mt?l("AggregatedMinimumSize: given aggregated size "+Mt+" byte doesn't satisfy specified minimum of "+y[m.minimumAggregatedSize]+" byte "+o+"."):(null!==(Ze=y[m.maximumAggregatedSize])&&void 0!==Ze?Ze:1/0)<Mt&&l("AggregatedMaximumSize: given aggregated size "+Mt+" byte doesn't satisfy specified maximum of "+y[m.maximumAggregatedSize]+" byte "+o+".")}if(t&&Object.prototype.hasOwnProperty.call(t,m.attachment)&&0===Object.keys(t[m.attachment]).length&&delete t[m.attachment],0===c.length&&t&&"migrate"===v)for(var rn,on=0,an=Object.keys(t);on<an.length;on++)rn=an[on],Object.prototype.hasOwnProperty.call(e,rn)||(c=n.concat(rn,"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:a,models:i,now:u,nowUTCTimestamp:p,securitySettings:o,userContext:n},S=e[m.attachment];if(e[m.attachment])for(var q,$=0,z=Object.values(S);$<z.length;$++)null!=(q=z[$])&&q.contentType&&(q.content_type=q.contentType,delete q.contentType);var F=K(e,t);return(!F.newDocument._deleted||t)&&(F.newDocument._deleted&&F.newDocument._deleted!==(null==t?void 0:t._deleted)||F.changedPath.length)||l("NoChange: No new data given. new document: "+j(e)+"; old document: "+j(t)+"."),Object.prototype.hasOwnProperty.call(o,a.property.name.validatedDocumentsCache)?o[a.property.name.validatedDocumentsCache].add(y+"-"+O):o[a.property.name.validatedDocumentsCache]=new Set([y+"-"+O]),F.newDocument},u=e.exports,p=u}],r={};t.d=function(e,n){for(var r in n)t.o(n,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:n[r]})},t.hmd=function(e){return(e=Object.create(e)).children||(e.children=[]),Object.defineProperty(e,"exports",{enumerable:!0,set:function(){throw new Error("ES Modules may not assign module.exports or exports.*, Use ESM export syntax, instead: "+e.id)}}),e},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o=t(0);e.exports=o}()},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__(6),fs__WEBPACK_IMPORTED_MODULE_6___default=__webpack_require__.n(fs__WEBPACK_IMPORTED_MODULE_6__),path__WEBPACK_IMPORTED_MODULE_7__=__webpack_require__(7),path__WEBPACK_IMPORTED_MODULE_7___default=__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_7__),_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,!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=_createForOfIteratorHelperLoose(clientnode__WEBPACK_IMPORTED_MODULE_4__.CLOSE_EVENT_NAMES);!(n=r()).done;){var o,a=n.value;null==(o=server.process)||o.on(a,(0,clientnode__WEBPACK_IMPORTED_MODULE_4__.getProcessCloseHandler)(e,t,{process:server.process,reason:a}))}})).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.reject&&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]={id:e,loaded:!1,exports:{}};return __webpack_modules__[e](n,n.exports,__webpack_require__),n.loaded=!0,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__.hmd=e=>((e=Object.create(e)).children||(e.children=[]),Object.defineProperty(e,"exports",{enumerable:!0,set:()=>{throw new Error("ES Modules may not assign module.exports or exports.*, Use ESM export syntax, instead: "+e.id)}}),e),__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__=__webpack_require__(5);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.645",
3
+ "version": "1.0.646",
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",
@@ -66,25 +66,26 @@
66
66
  "pouchdb-server": "^4.2.0"
67
67
  },
68
68
  "devDependencies": {
69
- "@babel/eslint-parser": "^7.24.8",
70
- "@babel/runtime": "^7.24.8",
69
+ "@babel/eslint-parser": "^7.25.1",
70
+ "@babel/runtime": "^7.25.0",
71
+ "@stylistic/eslint-plugin": "^2.6.4",
71
72
  "@types/ejs": "^3.1.5",
72
- "@types/node": "^20.14.10",
73
+ "@types/node": "^22.4.2",
73
74
  "@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.1166",
77
- "documentation-website": "^1.0.328",
78
- "eslint": "^9.7.0",
75
+ "@typescript-eslint/eslint-plugin": "^8.2.0",
76
+ "@typescript-eslint/parser": "^8.2.0",
77
+ "clientnode": "^3.0.1178",
78
+ "documentation-website": "^1.0.331",
79
+ "eslint": "^9.9.0",
79
80
  "eslint-config-google": "^0.14.0",
80
- "eslint-plugin-jsdoc": "^48.7.0",
81
+ "eslint-plugin-jsdoc": "^50.2.2",
81
82
  "jest": "^29.7.0",
82
83
  "jsdoc": "^4.0.3",
83
84
  "node-fetch": "^3.3.2",
84
85
  "rimraf": "^6.0.1",
85
- "typescript-eslint": "^7.16.0",
86
- "web-node": "^1.0.513",
87
- "weboptimizer": "^2.0.1486"
86
+ "typescript-eslint": "^8.2.0",
87
+ "web-node": "^1.0.518",
88
+ "weboptimizer": "^2.0.1498"
88
89
  },
89
90
  "peerDependencies": {
90
91
  "@babel/runtime": "*",
package/type.d.ts CHANGED
@@ -1,15 +1,15 @@
1
1
  import { ChildProcess } from 'child_process';
2
2
  import { AnyFunction, Mapping, PlainObject, Primitive, ProcessCloseReason, UTILITY_SCOPE } from 'clientnode';
3
3
  import { Configuration as BaseConfiguration, PluginHandler as BasePluginHandler, ServicePromises as BaseServicePromises, Services as BaseServices, ServicePromisesState as BaseServicePromisesState, ServicesState as BaseServicesState } from 'web-node/type';
4
- import DatabaseHelper from './databaseHelper';
4
+ import databaseHelper from './databaseHelper';
5
5
  export type Attachment = PouchDB.Core.Attachment & {
6
6
  content_type?: PouchDB.Core.Attachment['content_type'];
7
7
  contentType?: PouchDB.Core.Attachment['content_type'];
8
8
  };
9
- export interface Attachments {
10
- [attachmentId: string]: Attachment;
11
- }
12
- export type FullAttachment = PouchDB.Core.FullAttachment;
9
+ export type Attachments = Record<string, Attachment | null>;
10
+ export type FullAttachment = Omit<PouchDB.Core.FullAttachment, 'data'> & {
11
+ data?: null | PouchDB.Core.FullAttachment['data'];
12
+ };
13
13
  export type StubAttachment = PouchDB.Core.StubAttachment;
14
14
  export type ChangesMeta = PouchDB.Core.ChangesMeta;
15
15
  export type ChangesResponseChange<Type extends object = Mapping<unknown>> = PouchDB.Core.ChangesResponseChange<Type>;
@@ -134,8 +134,8 @@ export interface DocumentStrategyMeta {
134
134
  export interface DocumentTypeMeta {
135
135
  '-type': string;
136
136
  }
137
- export type BaseDocument = ChangesMeta & DocumentGetMeta & DocumentIDMeta & DocumentRevisionIDMeta & DocumentStrategyMeta & DocumentTypeMeta & {
138
- _attachments?: Attachments;
137
+ export type BaseDocument = Omit<ChangesMeta, '_attachments'> & Omit<DocumentGetMeta, '_attachments'> & DocumentIDMeta & DocumentRevisionIDMeta & DocumentStrategyMeta & DocumentTypeMeta & {
138
+ _attachments?: Attachments | null;
139
139
  };
140
140
  export type FullDocument<Type extends object = object, AdditionalPropertyTypes = unknown> = BaseDocument & Document<Type> & Mapping<AdditionalPropertyTypes>;
141
141
  export type PartialFullDocument<Type extends object = object, AdditionalPropertyTypes = unknown> = Partial<BaseDocument> & Partial<Document<Type>> & Mapping<AdditionalPropertyTypes>;
@@ -265,10 +265,10 @@ export type Configuration<ConfigurationType = Mapping<unknown>> = BaseConfigurat
265
265
  }> & ConfigurationType;
266
266
  export interface CouchDB<Type extends object = Mapping<unknown>> {
267
267
  changesStream: ChangesStream;
268
- connection: Connection<Type>;
268
+ connection?: Connection<Type>;
269
269
  connector: Connector;
270
270
  server: {
271
- process: ChildProcess;
271
+ process?: ChildProcess;
272
272
  reject: (value: ProcessCloseReason) => void;
273
273
  resolve: (reason: ProcessCloseReason) => void;
274
274
  restart: (state: State) => Promise<void>;
@@ -347,7 +347,7 @@ export interface PropertyScope<ObjectType extends object, Type, PropertyType, At
347
347
  newValue: Type;
348
348
  oldValue?: Type;
349
349
  propertySpecification: PropertySpecification<Type, AdditionalSpecifications>;
350
- attachmentsTarget?: Mapping<AttachmentType>;
350
+ attachmentsTarget?: Mapping<AttachmentType | null>;
351
351
  }
352
352
  export interface EvaluationResult<ObjectType extends object, Type, PropertyType, AttachmentType extends Attachment, AdditionalSpecifications extends object, AdditionalPropertiesType, Scope = (BasicScope<ObjectType, AttachmentType, AdditionalSpecifications, AdditionalPropertiesType> & CommonScope<ObjectType, PropertyType, AttachmentType, AdditionalSpecifications, AdditionalPropertiesType>)> {
353
353
  code: string;
@@ -366,7 +366,7 @@ export interface CheckedDocumentResult<ObjectType extends object, AdditionalProp
366
366
  }
367
367
  export type Migrator<Type extends object = object, AttachmentType extends Attachment = Attachment, AdditionalSpecifications extends object = object, AdditionalPropertiesType = unknown> = (document: Document, scope: (typeof UTILITY_SCOPE & {
368
368
  configuration: Configuration;
369
- databaseHelper: DatabaseHelper;
369
+ databaseHelper: typeof databaseHelper;
370
370
  idName: string;
371
371
  typeName: string;
372
372
  migrators: Mapping<Migrator<Type, AttachmentType, AdditionalSpecifications, AdditionalPropertiesType>>;