couchdb-web-node-plugin 1.0.721 → 1.0.722

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.
Files changed (3) hide show
  1. package/helper.js +1 -1
  2. package/index.js +1 -1
  3. package/package.json +1 -1
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,{TOGGLE_LATEST_REVISION_DETERMINING:()=>b,bulkDocsFactory:()=>x,determineAllowedModelRolesMapping:()=>O,determineGenericIndexablePropertyNames:()=>j,ensureValidationDocumentPresence:()=>g,extendModel:()=>S,extendModels:()=>T,getConnectorOptions:()=>h,initializeConnection:()=>w,isPropertySpecification:()=>k,mayStripRepresentation:()=>v,normalizeAllowedRoles:()=>A});var o=r(1),a=r.n(o),i=r(2),c=r.n(i),s=r(3),l=r.n(s),u=r(4);const p=require("rxjs"),d=require("rxjs/fetch"),f="1.0.721";function y(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 m(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)?m(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 m(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 b=Symbol("toggleLatestRevisionDetermining"),h=function(e){var t=e.couchdb.connector.fetch?function(t){return(0,u.extend)(!0,(0,u.copy)(e.couchdb.connector.fetch),t||{})}:u.identity,r=new Map([[408,"Request Timeout"],[425,"Too Early"],[429,"Too Many Requests"],[502,"Bad Gateway"],[503,"Service Unavailable"],[504,"Gateway Timeout"]]);return{fetch:function(n,o){var a=e.couchdb.connector.fetchInterceptor,i=a.numberOfRetries,c=a.retryIntervalInSeconds,s=a.exponentialBackoff,l=a.maximumRetryIntervallInSeconds,u=(0,d.fromFetch)(n,t(o)).pipe((0,p.map)((function(e){if(r.has(e.status))throw e;return e})),(0,p.retry)({count:i,delay:function(e,t){if("number"!=typeof e.status)throw e;var r=e;if(r.headers.has("retry-after")){var n=r.headers.get("retry-after");if("string"==typeof n){var o=parseInt(n);if(String(o)===n)return console.info("Retry in "+n+" seconds","according to given retry value."),(0,p.timer)(1e3*o);var a=new Date(n);if(!isNaN(a.getTime())){var i=new Date;if(i<a){if(l<(a.getTime()-i.getTime())/1e3)return console.info("Retry at",a.toUTCString(),"according to given retry","value."),(0,p.timer)(a);console.warn("The recommended retry attempt is",a.toUTCString(),"further in the future than the","configured maximum wait time of",l,"seconds.")}else console.warn("Given retry time recommendation","from server is in the past and","has to be ignored therefore.")}}}var u=s?Math.pow(2,t-1)*c:c;return(0,p.timer)(1e3*Math.min(u,l))}}));return(0,p.lastValueFrom)(u)}}},v=function(e,t,r){var n=(0,u.represent)(e);return n.length<=t?n.length>r?n.substring(0,r-3)+"...":n:"DOCUMENT IS TOO BIG TO REPRESENT"},g=function(){var e=c()(l().mark((function e(t,r,n,o,i,c,s,p){var d,y,m;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===p&&(p="_design/"),y=a()(((d={})[c]=""+p+r,d.language="javascript",d.version=f,d),n),e.prev=5,e.next=8,t.get(""+p+r);case 8:return m=e.sent,y[s]=m[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,u.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,u.represent)(e.t1)+'".');case 27:case"end":return e.stop()}}),e,null,[[5,15],[18,24]])})));return function(t,r,n,o,a,i,c,s){return e.apply(this,arguments)}}(),x=function(e,t){var r=t.model.property.name.special.id,n=t.model.property.name.special.revision;return c()(l().mark((function o(a){var i,c,s,p,d,f,m,h,v,g,x,w,O,k,j,S,T,A,R,D,E,I,M=arguments;return l().wrap((function(o){for(;;)switch(o.prev=o.next){case 0:for(i=M.length,c=new Array(i>1?i-1:0),s=1;s<i;s++)c[s-1]=M[s];p=c.length>0&&c[c.length-1]===b,d=p?!t.skipLatestRevisionDetermining:t.skipLatestRevisionDetermining,p&&c.pop(),f=!Array.isArray(a)&&(0,u.isObject)(a)&&r in a?[a]:a,m=t.maximumNumberOfEntitiesInBulkOperation,h=[],v=Math.random(),g=0;case 9:if(!(g<f.length)){o.next=24;break}return x=f.slice(g,g+m),console.log(),console.log("TODO before bulkDocs",v,g,x.length,f.length),console.log(),o.next=16,e.call.apply(e,[this,x].concat(c));case 16:w=o.sent,console.log(),console.log("TODO After bulkDocs",v),console.log(),h.concat(w);case 21:g+=m,o.next=9;break;case 24:O=[],k=[],j=0,S=0,T=h;case 28:if(!(S<T.length)){o.next=52;break}if(A=T[S],"object"!=typeof f[j]){o.next=48;break}if(!(n in f[j])||"conflict"!==A.name||!["0-latest","0-upsert"].includes(f[j][n])){o.next=36;break}k.push(f[j]),O.push(j),o.next=48;break;case 36:if(!(r in f[j]&&t.ignoreNoChangeError&&"name"in A&&"forbidden"===A.name&&"message"in A&&A.message.startsWith("NoChange:"))){o.next=48;break}if(h[j]={id:f[j][r],ok:!0},d){o.next=48;break}if(!(n in f[j])||["0-latest","0-upsert"].includes(f[j][n])){o.next=43;break}o.t0=f[j][n],o.next=47;break;case 43:return o.next=45,this.get(h[j].id);case 45:o.t1=n,o.t0=o.sent[o.t1];case 47:h[j].rev=o.t0;case 48:j+=1;case 49:S++,o.next=28;break;case 52:if(!k.length){o.next=59;break}return f=k,p&&c.push(b),o.next=57,this.bulkDocs.apply(this,[f].concat(c));case 57:for(R=o.sent,D=y(R);!(E=D()).done;)I=E.value,h[O.shift()]=I;case 59:return o.abrupt("return",h);case 60:case"end":return o.stop()}}),o,this)})))},w=function(){var e=c()(l().mark((function e(t,r){var n,o,a;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=r.couchdb,o=(0,u.format)(n.url,n.admin.name+":"+n.admin.password+"@")+"/"+n.databaseName,t.couchdb.connection=new t.couchdb.connector(o,h(r)),(a=t.couchdb.connection).setMaxListeners(1/0),a.bulkDocs=x(a.bulkDocs,r.couchdb),a.put=c()(l().mark((function e(t,r){var n;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,a.bulkDocs.call(this,[t],r);case 2:if(null==(n=e.sent[0])||!n.name){e.next=5;break}throw n;case 5:return e.abrupt("return",n);case 6:case"end":return e.stop()}}),e,this)}))),e.prev=7,e.next=10,(0,u.checkReachability)(o);case 10:e.next=19;break;case 12:if(e.prev=12,e.t0=e.catch(7),console.info("Database could not be retrieved yet: Creating it."),u.globalContext.fetch){e.next=17;break}throw new Error("Missing fetch implementation.");case 17:return e.next=19,u.globalContext.fetch(o,{method:"PUT"});case 19:return e.abrupt("return",t);case 20:case"end":return e.stop()}}),e,null,[[7,12]])})));return function(t,r){return e.apply(this,arguments)}}(),O=function(e){for(var t=e.property.name.special.allowedRole,r={},n=T(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:{}},A(l[t]));for(var p=0,d=Object.entries(l);p<d.length;p++){var f=d[p],y=f[0],m=f[1];(0,u.isObject)(m)&&m.allowedRoles&&(r[s].properties[y]=A(m.allowedRoles))}}else r[s]={properties:{},read:[],write:[]}}return r},k=function(e){return(0,u.isObject)(e)},j=function(e,t){var r=e.property.name.special;return Object.keys(t).filter((function(n){var o=t[n];return k(o)&&Object.prototype.hasOwnProperty.call(o,"index")&&o.index||k(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()},S=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=y([].concat(t[e][r]));!(n=o()).done;){var a=n.value;t[e]=(0,u.extend)(!0,(0,u.copy)(S(a,t,r)),t[e])}delete t[e][r]}return t[e]},T=function(e){for(var t=e.property.name.special,r={},n=e.property.name.typePattern,o=0,a=Object.keys(e.entities);o<a.length;o++){var i=a[o];if(!new RegExp(n.public).test(i)&&!new RegExp(n.private).test(i))throw new Error('Model names have to match "'+n.public+'" or "'+n.private+'" for private one (given name: "'+i+'").');r[i]=S(i,e.entities,t.extend)}for(var c=0,s=Object.values(r);c<s.length;c++)for(var l=s[c],p=0,d=Object.entries(l);p<d.length;p++){var f=d[p],y=f[0],m=f[1];if(y===t.attachment)for(var b=m,h=0,v=Object.entries(b);h<v.length;h++){var g=v[h],x=g[0],w=g[1];b[x]=(0,u.extend)(!0,(0,u.copy)(e.property.defaultSpecification),w)}else[t.allowedRole,t.constraint.execution,t.constraint.expression,t.extend,t.maximumAggregatedSize,t.minimumAggregatedSize,t.oldType].includes(y)||(l[y]=(0,u.extend)(!0,(0,u.copy)(e.property.defaultSpecification),m))}return r},A=function(e){if(Array.isArray(e))return{read:e,write:e};if("object"==typeof e){for(var t={read:[],write:[]},r=0,n=Object.keys(t);r<n.length;r++){var o=n[r];Object.prototype.hasOwnProperty.call(e,o)&&(Array.isArray(e[o])?t[o]=e[o]:t[o]=[e[o]])}return t}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,{TOGGLE_LATEST_REVISION_DETERMINING:()=>b,bulkDocsFactory:()=>x,determineAllowedModelRolesMapping:()=>O,determineGenericIndexablePropertyNames:()=>j,ensureValidationDocumentPresence:()=>g,extendModel:()=>S,extendModels:()=>T,getConnectorOptions:()=>h,initializeConnection:()=>w,isPropertySpecification:()=>k,mayStripRepresentation:()=>v,normalizeAllowedRoles:()=>A});var o=r(1),a=r.n(o),i=r(2),c=r.n(i),s=r(3),l=r.n(s),u=r(4);const p=require("rxjs"),d=require("rxjs/fetch"),f="1.0.722";function y(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 m(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)?m(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 m(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 b=Symbol("toggleLatestRevisionDetermining"),h=function(e){var t=e.couchdb.connector.fetch?function(t){return(0,u.extend)(!0,(0,u.copy)(e.couchdb.connector.fetch),t||{})}:u.identity,r=new Map([[408,"Request Timeout"],[425,"Too Early"],[429,"Too Many Requests"],[502,"Bad Gateway"],[503,"Service Unavailable"],[504,"Gateway Timeout"]]);return{fetch:function(n,o){var a=e.couchdb.connector.fetchInterceptor,i=a.numberOfRetries,c=a.retryIntervalInSeconds,s=a.exponentialBackoff,l=a.maximumRetryIntervallInSeconds,u=(0,d.fromFetch)(n,t(o)).pipe((0,p.map)((function(e){if(r.has(e.status))throw e;return e})),(0,p.retry)({count:i,delay:function(e,t){if("number"!=typeof e.status)throw e;var r=e;if(r.headers.has("retry-after")){var n=r.headers.get("retry-after");if("string"==typeof n){var o=parseInt(n);if(String(o)===n)return console.info("Retry in "+n+" seconds","according to given retry value."),(0,p.timer)(1e3*o);var a=new Date(n);if(!isNaN(a.getTime())){var i=new Date;if(i<a){if(l<(a.getTime()-i.getTime())/1e3)return console.info("Retry at",a.toUTCString(),"according to given retry","value."),(0,p.timer)(a);console.warn("The recommended retry attempt is",a.toUTCString(),"further in the future than the","configured maximum wait time of",l,"seconds.")}else console.warn("Given retry time recommendation","from server is in the past and","has to be ignored therefore.")}}}var u=s?Math.pow(2,t-1)*c:c;return(0,p.timer)(1e3*Math.min(u,l))}}));return(0,p.lastValueFrom)(u)}}},v=function(e,t,r){var n=(0,u.represent)(e);return n.length<=t?n.length>r?n.substring(0,r-3)+"...":n:"DOCUMENT IS TOO BIG TO REPRESENT"},g=function(){var e=c()(l().mark((function e(t,r,n,o,i,c,s,p){var d,y,m;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===p&&(p="_design/"),y=a()(((d={})[c]=""+p+r,d.language="javascript",d.version=f,d),n),e.prev=5,e.next=8,t.get(""+p+r);case 8:return m=e.sent,y[s]=m[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,u.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,u.represent)(e.t1)+'".');case 27:case"end":return e.stop()}}),e,null,[[5,15],[18,24]])})));return function(t,r,n,o,a,i,c,s){return e.apply(this,arguments)}}(),x=function(e,t){var r=t.model.property.name.special.id,n=t.model.property.name.special.revision;return c()(l().mark((function o(a){var i,c,s,p,d,f,m,h,v,g,x,w,O,k,j,S,T,A,R,D,E,I,M=arguments;return l().wrap((function(o){for(;;)switch(o.prev=o.next){case 0:for(i=M.length,c=new Array(i>1?i-1:0),s=1;s<i;s++)c[s-1]=M[s];p=c.length>0&&c[c.length-1]===b,d=p?!t.skipLatestRevisionDetermining:t.skipLatestRevisionDetermining,p&&c.pop(),f=!Array.isArray(a)&&(0,u.isObject)(a)&&r in a?[a]:a,m=t.maximumNumberOfEntitiesInBulkOperation,h=[],v=Math.random(),g=0;case 9:if(!(g<f.length)){o.next=24;break}return x=f.slice(g,g+m),console.log(),console.log("TODO before bulkDocs",v,g,x.length,f.length),console.log(),o.next=16,e.call.apply(e,[this,x].concat(c));case 16:w=o.sent,console.log(),console.log("TODO After bulkDocs",v),console.log(),h.concat(w);case 21:g+=m,o.next=9;break;case 24:O=[],k=[],j=0,S=0,T=h;case 28:if(!(S<T.length)){o.next=52;break}if(A=T[S],"object"!=typeof f[j]){o.next=48;break}if(!(n in f[j])||"conflict"!==A.name||!["0-latest","0-upsert"].includes(f[j][n])){o.next=36;break}k.push(f[j]),O.push(j),o.next=48;break;case 36:if(!(r in f[j]&&t.ignoreNoChangeError&&"name"in A&&"forbidden"===A.name&&"message"in A&&A.message.startsWith("NoChange:"))){o.next=48;break}if(h[j]={id:f[j][r],ok:!0},d){o.next=48;break}if(!(n in f[j])||["0-latest","0-upsert"].includes(f[j][n])){o.next=43;break}o.t0=f[j][n],o.next=47;break;case 43:return o.next=45,this.get(h[j].id);case 45:o.t1=n,o.t0=o.sent[o.t1];case 47:h[j].rev=o.t0;case 48:j+=1;case 49:S++,o.next=28;break;case 52:if(!k.length){o.next=59;break}return f=k,p&&c.push(b),o.next=57,this.bulkDocs.apply(this,[f].concat(c));case 57:for(R=o.sent,D=y(R);!(E=D()).done;)I=E.value,h[O.shift()]=I;case 59:return o.abrupt("return",h);case 60:case"end":return o.stop()}}),o,this)})))},w=function(){var e=c()(l().mark((function e(t,r){var n,o,a;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=r.couchdb,o=(0,u.format)(n.url,n.admin.name+":"+n.admin.password+"@")+"/"+n.databaseName,t.couchdb.connection=new t.couchdb.connector(o,h(r)),(a=t.couchdb.connection).setMaxListeners(1/0),a.bulkDocs=x(a.bulkDocs,r.couchdb),a.put=c()(l().mark((function e(t,r){var n;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,a.bulkDocs.call(this,[t],r);case 2:if(null==(n=e.sent[0])||!n.name){e.next=5;break}throw n;case 5:return e.abrupt("return",n);case 6:case"end":return e.stop()}}),e,this)}))),e.prev=7,e.next=10,(0,u.checkReachability)(o);case 10:e.next=19;break;case 12:if(e.prev=12,e.t0=e.catch(7),console.info("Database could not be retrieved yet: Creating it."),u.globalContext.fetch){e.next=17;break}throw new Error("Missing fetch implementation.");case 17:return e.next=19,u.globalContext.fetch(o,{method:"PUT"});case 19:return e.abrupt("return",t);case 20:case"end":return e.stop()}}),e,null,[[7,12]])})));return function(t,r){return e.apply(this,arguments)}}(),O=function(e){for(var t=e.property.name.special.allowedRole,r={},n=T(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:{}},A(l[t]));for(var p=0,d=Object.entries(l);p<d.length;p++){var f=d[p],y=f[0],m=f[1];(0,u.isObject)(m)&&m.allowedRoles&&(r[s].properties[y]=A(m.allowedRoles))}}else r[s]={properties:{},read:[],write:[]}}return r},k=function(e){return(0,u.isObject)(e)},j=function(e,t){var r=e.property.name.special;return Object.keys(t).filter((function(n){var o=t[n];return k(o)&&Object.prototype.hasOwnProperty.call(o,"index")&&o.index||k(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()},S=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=y([].concat(t[e][r]));!(n=o()).done;){var a=n.value;t[e]=(0,u.extend)(!0,(0,u.copy)(S(a,t,r)),t[e])}delete t[e][r]}return t[e]},T=function(e){for(var t=e.property.name.special,r={},n=e.property.name.typePattern,o=0,a=Object.keys(e.entities);o<a.length;o++){var i=a[o];if(!new RegExp(n.public).test(i)&&!new RegExp(n.private).test(i))throw new Error('Model names have to match "'+n.public+'" or "'+n.private+'" for private one (given name: "'+i+'").');r[i]=S(i,e.entities,t.extend)}for(var c=0,s=Object.values(r);c<s.length;c++)for(var l=s[c],p=0,d=Object.entries(l);p<d.length;p++){var f=d[p],y=f[0],m=f[1];if(y===t.attachment)for(var b=m,h=0,v=Object.entries(b);h<v.length;h++){var g=v[h],x=g[0],w=g[1];b[x]=(0,u.extend)(!0,(0,u.copy)(e.property.defaultSpecification),w)}else[t.allowedRole,t.constraint.execution,t.constraint.expression,t.extend,t.maximumAggregatedSize,t.minimumAggregatedSize,t.oldType].includes(y)||(l[y]=(0,u.extend)(!0,(0,u.copy)(e.property.defaultSpecification),m))}return r},A=function(e){if(Array.isArray(e))return{read:e,write:e};if("object"==typeof e){for(var t={read:[],write:[]},r=0,n=Object.keys(t);r<n.length;r++){var o=n[r];Object.prototype.hasOwnProperty.call(e,o)&&(Array.isArray(e[o])?t[o]=e[o]:t[o]=[e[o]])}return t}return{read:[e],write:[e]}};module.exports=n})();
package/index.js CHANGED
@@ -1 +1 @@
1
- (()=>{var __webpack_modules__=[(e,t,n)=>{"use strict";n.d(t,{bulkDocsFactory:()=>O,determineAllowedModelRolesMapping:()=>x,determineGenericIndexablePropertyNames:()=>E,ensureValidationDocumentPresence:()=>y,extendModels:()=>D,getConnectorOptions:()=>b,initializeConnection:()=>g,mayStripRepresentation:()=>h});var r=n(1),o=n.n(r),a=n(2),i=n.n(a),c=n(3),_=n.n(c),s=n(4);const l=require("rxjs"),u=require("rxjs/fetch"),p="1.0.721";function d(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 m(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)?m(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 m(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 f=Symbol("toggleLatestRevisionDetermining"),b=function(e){var t=e.couchdb.connector.fetch?function(t){return(0,s.extend)(!0,(0,s.copy)(e.couchdb.connector.fetch),t||{})}:s.identity,n=new Map([[408,"Request Timeout"],[425,"Too Early"],[429,"Too Many Requests"],[502,"Bad Gateway"],[503,"Service Unavailable"],[504,"Gateway Timeout"]]);return{fetch:function(r,o){var a=e.couchdb.connector.fetchInterceptor,i=a.numberOfRetries,c=a.retryIntervalInSeconds,_=a.exponentialBackoff,s=a.maximumRetryIntervallInSeconds,p=(0,u.fromFetch)(r,t(o)).pipe((0,l.map)((function(e){if(n.has(e.status))throw e;return e})),(0,l.retry)({count:i,delay:function(e,t){if("number"!=typeof e.status)throw e;var n=e;if(n.headers.has("retry-after")){var r=n.headers.get("retry-after");if("string"==typeof r){var o=parseInt(r);if(String(o)===r)return console.info("Retry in "+r+" seconds","according to given retry value."),(0,l.timer)(1e3*o);var a=new Date(r);if(!isNaN(a.getTime())){var i=new Date;if(i<a){if(s<(a.getTime()-i.getTime())/1e3)return console.info("Retry at",a.toUTCString(),"according to given retry","value."),(0,l.timer)(a);console.warn("The recommended retry attempt is",a.toUTCString(),"further in the future than the","configured maximum wait time of",s,"seconds.")}else console.warn("Given retry time recommendation","from server is in the past and","has to be ignored therefore.")}}}var u=_?Math.pow(2,t-1)*c:c;return(0,l.timer)(1e3*Math.min(u,s))}}));return(0,l.lastValueFrom)(p)}}},h=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"},y=function(){var e=i()(_().mark((function e(t,n,r,a,i,c,l,u){var d,m,f;return _().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return void 0===i&&(i=!0),void 0===c&&(c="_id"),void 0===l&&(l="_rev"),void 0===u&&(u="_design/"),m=o()(((d={})[c]=""+u+n,d.language="javascript",d.version=p,d),r),e.prev=5,e.next=8,t.get(""+u+n);case 8:return f=e.sent,m[l]=f[l],e.next=12,t.put(m);case 12:i&&console.info(a+" updated."),e.next=27;break;case 15:return e.prev=15,e.t0=e.catch(5),i&&("not_found"===e.t0.error?console.info(a+" not available: create new one."):console.info(a+" couldn't be updated: \""+(0,s.represent)(e.t0)+'" create new one.')),e.prev=18,e.next=21,t.put(m);case 21:i&&console.info(a+" installed/updated."),e.next=27;break;case 24:throw e.prev=24,e.t1=e.catch(18),new Error(a+" couldn't be installed/updated: \""+(0,s.represent)(e.t1)+'".');case 27:case"end":return e.stop()}}),e,null,[[5,15],[18,24]])})));return function(t,n,r,o,a,i,c,_){return e.apply(this,arguments)}}(),O=function(e,t){var n=t.model.property.name.special.id,r=t.model.property.name.special.revision;return i()(_().mark((function o(a){var i,c,l,u,p,m,b,h,y,O,g,x,v,E,P,D,M,w,C,k,T,j,A=arguments;return _().wrap((function(o){for(;;)switch(o.prev=o.next){case 0:for(i=A.length,c=new Array(i>1?i-1:0),l=1;l<i;l++)c[l-1]=A[l];u=c.length>0&&c[c.length-1]===f,p=u?!t.skipLatestRevisionDetermining:t.skipLatestRevisionDetermining,u&&c.pop(),m=!Array.isArray(a)&&(0,s.isObject)(a)&&n in a?[a]:a,b=t.maximumNumberOfEntitiesInBulkOperation,h=[],y=Math.random(),O=0;case 9:if(!(O<m.length)){o.next=24;break}return g=m.slice(O,O+b),console.log(),console.log("TODO before bulkDocs",y,O,g.length,m.length),console.log(),o.next=16,e.call.apply(e,[this,g].concat(c));case 16:x=o.sent,console.log(),console.log("TODO After bulkDocs",y),console.log(),h.concat(x);case 21:O+=b,o.next=9;break;case 24:v=[],E=[],P=0,D=0,M=h;case 28:if(!(D<M.length)){o.next=52;break}if(w=M[D],"object"!=typeof m[P]){o.next=48;break}if(!(r in m[P])||"conflict"!==w.name||!["0-latest","0-upsert"].includes(m[P][r])){o.next=36;break}E.push(m[P]),v.push(P),o.next=48;break;case 36:if(!(n in m[P]&&t.ignoreNoChangeError&&"name"in w&&"forbidden"===w.name&&"message"in w&&w.message.startsWith("NoChange:"))){o.next=48;break}if(h[P]={id:m[P][n],ok:!0},p){o.next=48;break}if(!(r in m[P])||["0-latest","0-upsert"].includes(m[P][r])){o.next=43;break}o.t0=m[P][r],o.next=47;break;case 43:return o.next=45,this.get(h[P].id);case 45:o.t1=r,o.t0=o.sent[o.t1];case 47:h[P].rev=o.t0;case 48:P+=1;case 49:D++,o.next=28;break;case 52:if(!E.length){o.next=59;break}return m=E,u&&c.push(f),o.next=57,this.bulkDocs.apply(this,[m].concat(c));case 57:for(C=o.sent,k=d(C);!(T=k()).done;)j=T.value,h[v.shift()]=j;case 59:return o.abrupt("return",h);case 60:case"end":return o.stop()}}),o,this)})))},g=function(){var e=i()(_().mark((function e(t,n){var r,o,a;return _().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=n.couchdb,o=(0,s.format)(r.url,r.admin.name+":"+r.admin.password+"@")+"/"+r.databaseName,t.couchdb.connection=new t.couchdb.connector(o,b(n)),(a=t.couchdb.connection).setMaxListeners(1/0),a.bulkDocs=O(a.bulkDocs,n.couchdb),a.put=i()(_().mark((function e(t,n){var r;return _().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,a.bulkDocs.call(this,[t],n);case 2:if(null==(r=e.sent[0])||!r.name){e.next=5;break}throw r;case 5:return e.abrupt("return",r);case 6:case"end":return e.stop()}}),e,this)}))),e.prev=7,e.next=10,(0,s.checkReachability)(o);case 10:e.next=19;break;case 12:if(e.prev=12,e.t0=e.catch(7),console.info("Database could not be retrieved yet: Creating it."),s.globalContext.fetch){e.next=17;break}throw new Error("Missing fetch implementation.");case 17:return e.next=19,s.globalContext.fetch(o,{method:"PUT"});case 19:return e.abrupt("return",t);case 20:case"end":return e.stop()}}),e,null,[[7,12]])})));return function(t,n){return e.apply(this,arguments)}}(),x=function(e){for(var t=e.property.name.special.allowedRole,n={},r=D(e),a=0,i=Object.entries(r);a<i.length;a++){var c=i[a],_=c[0],l=c[1];if(l[t]){n[_]=o()({properties:{}},M(l[t]));for(var u=0,p=Object.entries(l);u<p.length;u++){var d=p[u],m=d[0],f=d[1];(0,s.isObject)(f)&&f.allowedRoles&&(n[_].properties[m]=M(f.allowedRoles))}}else n[_]={properties:{},read:[],write:[]}}return n},v=function(e){return(0,s.isObject)(e)},E=function(e,t){var n=e.property.name.special;return Object.keys(t).filter((function(r){var o=t[r];return v(o)&&Object.prototype.hasOwnProperty.call(o,"index")&&o.index||v(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()},P=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=d([].concat(t[e][n]));!(r=o()).done;){var a=r.value;t[e]=(0,s.extend)(!0,(0,s.copy)(P(a,t,n)),t[e])}delete t[e][n]}return t[e]},D=function(e){for(var t=e.property.name.special,n={},r=e.property.name.typePattern,o=0,a=Object.keys(e.entities);o<a.length;o++){var i=a[o];if(!new RegExp(r.public).test(i)&&!new RegExp(r.private).test(i))throw new Error('Model names have to match "'+r.public+'" or "'+r.private+'" for private one (given name: "'+i+'").');n[i]=P(i,e.entities,t.extend)}for(var c=0,_=Object.values(n);c<_.length;c++)for(var l=_[c],u=0,p=Object.entries(l);u<p.length;u++){var d=p[u],m=d[0],f=d[1];if(m===t.attachment)for(var b=f,h=0,y=Object.entries(b);h<y.length;h++){var O=y[h],g=O[0],x=O[1];b[g]=(0,s.extend)(!0,(0,s.copy)(e.property.defaultSpecification),x)}else[t.allowedRole,t.constraint.execution,t.constraint.expression,t.extend,t.maximumAggregatedSize,t.minimumAggregatedSize,t.oldType].includes(m)||(l[m]=(0,s.extend)(!0,(0,s.copy)(e.property.defaultSpecification),f))}return n},M=function(e){if(Array.isArray(e))return{read:e,write:e};if("object"==typeof e){for(var t={read:[],write:[]},n=0,r=Object.keys(t);n<r.length;n++){var o=r[n];Object.prototype.hasOwnProperty.call(e,o)&&(Array.isArray(e[o])?t[o]=e[o]:t[o]=[e[o]])}return t}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__,{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_9__=__webpack_require__(8),_databaseHelper__WEBPACK_IMPORTED_MODULE_9___default=__webpack_require__.n(_databaseHelper__WEBPACK_IMPORTED_MODULE_9__),_helper__WEBPACK_IMPORTED_MODULE_8__=__webpack_require__(0),_server__WEBPACK_IMPORTED_MODULE_10__=__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 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,i,c,_,s,l,u,p,d,m,f,b,h;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")||(o.connector=pouchdb_node__WEBPACK_IMPORTED_MODULE_6___default(),o.connector.plugin({bulkDocs:(0,_helper__WEBPACK_IMPORTED_MODULE_8__.bulkDocsFactory)(o.connector.prototype.bulkDocs,n)}),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={},a=[],i=_createForOfIteratorHelperLoose([].concat(n.binary.runner));case 8:if((c=i()).done){e.next=34;break}_=c.value,s=_createForOfIteratorHelperLoose([].concat(_.location));case 11:if((l=s()).done){e.next=30;break}u=l.value,p=_createForOfIteratorHelperLoose([].concat(_.name));case 14:if((d=p()).done){e.next=26;break}return m=d.value,f=(0,path__WEBPACK_IMPORTED_MODULE_5__.resolve)(u,m),a.push(f),e.next=20,(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.isFile)(f);case 20:if(!e.sent){e.next=24;break}return _.binaryFilePath=f,o.server.runner=_,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: "'+a.join('", "')+'".');case 36:delete(b=(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.copy)(n.model)).property.defaultSpecification,delete b.entities,h=(0,_helper__WEBPACK_IMPORTED_MODULE_8__.extendModels)(n.model),o.validateDocument=function(e,t){var r,o=(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.copy)(null!==(r=t.oldDocument)&&void 0!==r?r:e),a=Boolean(t.checkPublicModelType);(e=(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.copy)(e))[n.model.property.name.special.strategy]="migrate",t.type&&(e[b.property.name.special.type]=o[b.property.name.special.type]=t.type);try{return(0,_databaseHelper__WEBPACK_IMPORTED_MODULE_9__.validateDocumentUpdate)(e,o,{db:n.databaseName,name:n.admin.name,roles:["_admin"]},(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.copy)(n.security[n.databaseName]),b,h,a),!0}catch(e){return!(!Object.prototype.hasOwnProperty.call(e,"forbidden")||!e.forbidden.startsWith("NoChange:"))||e}};case 41:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),loadService=function(){var _ref4=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function _callee2(_ref3){var configuration,services,promise,couchdb,urlPrefix,authorizationHeader,headers,unauthenticatedUserDatabaseConnection,authenticatedUserDatabaseConnection,userDatabaseConnection,_i,_Object$entries,_Object$entries$_i,name,userConfiguration,_userDatabaseConnecti,_iterator4,_step4,prefix,subPath,fullPath,url,value,response,changeNeeded,securityConfigurations,_i2,_Object$entries2,_Object$entries2$_i,databaseName,securityObject,fullSecurityObject,_fullSecurityObject$a,_fullSecurityObject$a2,_fullSecurityObject$m,_fullSecurityObject$m2,_response,modelConfiguration,specialNames,idName,revisionName,typeName,models,databaseHelperCode,_iterator5,_step5,_type,code,_i3,_Object$entries3,_Object$entries3$_i,modelName,model,_i4,_Object$entries4,_Object$entries4$_i,_name,specification,_iterator6,_step6,constraint,_iterator7,_step7,type,_constraint,migrators,_iterator8,_step8,file,extension,_name2,documents,_iterator9,_step9,document,_forbidden,_iterator10,_step10,retrievedDocument,_document,newDocument,_iterator11,_step11,_name3,_result,result,genericIndexes,_i5,_Object$entries5,_Object$entries5$_i,_modelName,_model,_iterator12,_step12,propertyName,_name4,foundPosition,position,_iterator13,_step13,index,_iterator14,_step14,_index,exists,_i6,_Object$entries6,_Object$entries6$_i,_modelName2,_model2,_iterator15,_step15,_name5;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function _callee2$(_context2){for(;;)switch(_context2.prev=_context2.next){case 0:if(configuration=_ref3.configuration,services=_ref3.services,clientnode__WEBPACK_IMPORTED_MODULE_3__.globalContext.fetch){_context2.next=3;break}throw new Error("Missing fetch implementation.");case 3:if(promise=null,couchdb=services.couchdb,!Object.prototype.hasOwnProperty.call(couchdb.server,"runner")){_context2.next=12;break}return _context2.next=8,(0,_server__WEBPACK_IMPORTED_MODULE_10__.ni)(services,configuration);case 8:couchdb.server.restart=_server__WEBPACK_IMPORTED_MODULE_10__.S8,couchdb.server.start=_server__WEBPACK_IMPORTED_MODULE_10__.ni,couchdb.server.stop=_server__WEBPACK_IMPORTED_MODULE_10__.ds,promise=new Promise((function(e,t){couchdb.server.resolve=e,couchdb.server.reject=t}));case 12:if(!Object.prototype.hasOwnProperty.call(couchdb,"connection")){_context2.next=14;break}return _context2.abrupt("return",{couchdb:promise});case 14:if(urlPrefix=(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.format)(configuration.couchdb.url,""),authorizationHeader={Authorization:"Basic "+Buffer.from(configuration.couchdb.admin.name+":"+configuration.couchdb.admin.password,"binary").toString("base64")},headers={Accept:"application/json","Content-Type":"application/json"},!configuration.couchdb.ensureAdminPresence){_context2.next=48;break}return unauthenticatedUserDatabaseConnection=new couchdb.connector(urlPrefix+"/_users",(0,_helper__WEBPACK_IMPORTED_MODULE_8__.getConnectorOptions)(configuration)),_context2.prev=19,_context2.next=22,unauthenticatedUserDatabaseConnection.allDocs();case 22:return console.info('No admin user available. Automatically creating admin user "'+configuration.couchdb.admin.name+'".'),_context2.next=25,clientnode__WEBPACK_IMPORTED_MODULE_3__.globalContext.fetch(urlPrefix+"/"+couchdb.server.runner.adminUserConfigurationPath+"/"+configuration.couchdb.admin.name,{body:'"'+configuration.couchdb.admin.password+'"',method:"PUT"});case 25:_context2.next=45;break;case 27:if(_context2.prev=27,_context2.t0=_context2.catch(19),"unauthorized"!==_context2.t0.name){_context2.next=44;break}return authenticatedUserDatabaseConnection=new couchdb.connector(urlPrefix+"/_users",_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({},(0,_helper__WEBPACK_IMPORTED_MODULE_8__.getConnectorOptions)(configuration),{auth:{username:configuration.couchdb.admin.name,password:configuration.couchdb.admin.password}})),_context2.prev=31,_context2.next=34,authenticatedUserDatabaseConnection.allDocs();case 34:_context2.next=39;break;case 36:_context2.prev=36,_context2.t1=_context2.catch(31),console.error("Can't login as existing admin user \""+configuration.couchdb.admin.name+'": '+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(_context2.t1));case 39:return _context2.prev=39,authenticatedUserDatabaseConnection.close(),_context2.finish(39);case 42:_context2.next=45;break;case 44:console.error("Can't create new admin user \""+configuration.couchdb.admin.name+'": '+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(_context2.t0));case 45:return _context2.prev=45,unauthenticatedUserDatabaseConnection.close(),_context2.finish(45);case 48:if(!configuration.couchdb.ensureUserPresence){_context2.next=79;break}userDatabaseConnection=new couchdb.connector(urlPrefix+"/_users",_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({},(0,_helper__WEBPACK_IMPORTED_MODULE_8__.getConnectorOptions)(configuration),{auth:{username:configuration.couchdb.admin.name,password:configuration.couchdb.admin.password}})),_i=0,_Object$entries=Object.entries(configuration.couchdb.users);case 51:if(!(_i<_Object$entries.length)){_context2.next=79;break}return _Object$entries$_i=_Object$entries[_i],name=_Object$entries$_i[0],userConfiguration=_Object$entries$_i[1],_context2.prev=53,_context2.next=56,userDatabaseConnection.get("org.couchdb.user:"+name);case 56:_context2.next=73;break;case 58:if(_context2.prev=58,_context2.t2=_context2.catch(53),"not_found"!==_context2.t2.error){_context2.next=72;break}return console.info('Create missing database user "'+name+'".'),_context2.prev=62,_context2.next=65,userDatabaseConnection.put((_userDatabaseConnecti={},_userDatabaseConnecti[configuration.couchdb.model.property.name.special.id]="org.couchdb.user:"+name,_userDatabaseConnecti.name=name,_userDatabaseConnecti.password=userConfiguration.password,_userDatabaseConnecti.roles=userConfiguration.roles,_userDatabaseConnecti.type="user",_userDatabaseConnecti));case 65:_context2.next=70;break;case 67:throw _context2.prev=67,_context2.t3=_context2.catch(62),new Error("Couldn't create missing user \""+name+'": '+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(_context2.t3));case 70:_context2.next=73;break;case 72:throw new Error("Couldn't check for presence of user \""+name+'": '+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(_context2.t2));case 73:return _context2.prev=73,userDatabaseConnection.close(),_context2.finish(73);case 76:_i++,_context2.next=51;break;case 79:if(!configuration.couchdb.model.updateConfiguration){_context2.next=134;break}_iterator4=_createForOfIteratorHelperLoose(configuration.couchdb.backend.prefixes);case 81:if((_step4=_iterator4()).done){_context2.next=134;break}prefix=_step4.value,_context2.t4=_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().keys(configuration.couchdb.backend.configuration);case 84:if((_context2.t5=_context2.t4()).done){_context2.next=132;break}if(subPath=_context2.t5.value,!Object.prototype.hasOwnProperty.call(configuration.couchdb.backend.configuration,subPath)){_context2.next=130;break}return fullPath="/"+prefix+(prefix.trim()?"/":"")+subPath,url=""+urlPrefix+fullPath,value=configuration.couchdb.backend.configuration[subPath],response=void 0,_context2.prev=91,_context2.next=94,clientnode__WEBPACK_IMPORTED_MODULE_3__.globalContext.fetch(url,{headers:authorizationHeader});case 94:response=_context2.sent,_context2.next=100;break;case 97:_context2.prev=97,_context2.t6=_context2.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)(_context2.t6));case 100:if(!response){_context2.next=130;break}if(!response.ok){_context2.next=129;break}if(changeNeeded=!0,"function"!=typeof response.text){_context2.next=115;break}return _context2.prev=104,_context2.t7=value,_context2.next=108,response["string"==typeof value?"text":"json"]();case 108:_context2.t8=_context2.sent,changeNeeded=_context2.t7===_context2.t8,_context2.next=115;break;case 112:_context2.prev=112,_context2.t9=_context2.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)(_context2.t9));case 115:if(!changeNeeded){_context2.next=126;break}return _context2.prev=116,_context2.next=119,clientnode__WEBPACK_IMPORTED_MODULE_3__.globalContext.fetch(url,{body:'"'+configuration.couchdb.backend.configuration[subPath]+'"',method:"PUT"});case 119:_context2.next=124;break;case 121:_context2.prev=121,_context2.t10=_context2.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)(_context2.t10));case 124:_context2.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:_context2.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 "+String(response.status)+".");case 130:_context2.next=84;break;case 132:_context2.next=81;break;case 134:return _context2.next=136,(0,_helper__WEBPACK_IMPORTED_MODULE_8__.initializeConnection)(services,configuration);case 136:if(!configuration.couchdb.ensureSecuritySettingsPresence){_context2.next=160;break}securityConfigurations=configuration.couchdb.security,_i2=0,_Object$entries2=Object.entries(securityConfigurations);case 139:if(!(_i2<_Object$entries2.length)){_context2.next=160;break}if(_Object$entries2$_i=_Object$entries2[_i2],databaseName=_Object$entries2$_i[0],securityObject=_Object$entries2$_i[1],"_default"!==databaseName){_context2.next=143;break}return _context2.abrupt("continue",157);case 143:return fullSecurityObject=securityObject,"_users"!==databaseName&&(fullSecurityObject.admins||(fullSecurityObject.admins={names:[],roles:[]}),securityConfigurations._default.admins&&(securityConfigurations._default.admins.names&&(fullSecurityObject.admins.names=securityConfigurations._default.admins.names.concat(null!==(_fullSecurityObject$a=fullSecurityObject.admins.names)&&void 0!==_fullSecurityObject$a?_fullSecurityObject$a:[])),securityConfigurations._default.admins.roles&&(fullSecurityObject.admins.roles=securityConfigurations._default.admins.roles.concat(null!==(_fullSecurityObject$a2=fullSecurityObject.admins.roles)&&void 0!==_fullSecurityObject$a2?_fullSecurityObject$a2:[]))),fullSecurityObject.members||(fullSecurityObject.members={names:[],roles:[]}),securityConfigurations._default.members&&(securityConfigurations._default.members.names&&(fullSecurityObject.members.names=securityConfigurations._default.members.names.concat(null!==(_fullSecurityObject$m=fullSecurityObject.members.names)&&void 0!==_fullSecurityObject$m?_fullSecurityObject$m:[])),securityConfigurations._default.members.roles&&(fullSecurityObject.members.roles=securityConfigurations._default.members.roles.concat(null!==(_fullSecurityObject$m2=fullSecurityObject.members.roles)&&void 0!==_fullSecurityObject$m2?_fullSecurityObject$m2:[])))),console.info('Apply security settings for database "'+databaseName+'":',(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(fullSecurityObject)),_context2.prev=146,_context2.next=149,clientnode__WEBPACK_IMPORTED_MODULE_3__.globalContext.fetch(urlPrefix+"/"+databaseName+"/_security",{body:JSON.stringify(fullSecurityObject),headers:_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({},headers,authorizationHeader),method:"PUT"});case 149:if(_response=_context2.sent,_response.ok){_context2.next=152;break}throw new Error(_response.statusText);case 152:_context2.next=157;break;case 154:_context2.prev=154,_context2.t11=_context2.catch(146),console.error('Security object for database "'+databaseName+"\" couldn't be applied:",(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(_context2.t11));case 157:_i2++,_context2.next=139;break;case 160: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_8__.extendModels)(configuration.couchdb.model),!configuration.couchdb.model.updateValidation){_context2.next=229;break}return _context2.next=169,fs__WEBPACK_IMPORTED_MODULE_4__.promises.readFile(eval("require.resolve('./databaseHelper')"),{encoding:configuration.core.encoding,flag:"r"});case 169:databaseHelperCode=_context2.sent,_iterator5=_createForOfIteratorHelperLoose([{description:"Model specification",methodName:"validateDocumentUpdate",name:"validation",serializedParameter:JSON.stringify(modelConfiguration)+", "+JSON.stringify(models)},{description:"Authorisation",methodName:"authenticate",name:"authentication",serializedParameter:JSON.stringify((0,_helper__WEBPACK_IMPORTED_MODULE_8__.determineAllowedModelRolesMapping)(configuration.couchdb.model))+", '"+idName+"', '"+typeName+"', '"+specialNames.designDocumentNamePrefix+"'"}]);case 171:if((_step5=_iterator5()).done){_context2.next=186;break}_type=_step5.value,code="function(...parameters) {\n return require('helper')."+_type.methodName+"(...parameters.concat(["+_type.serializedParameter+"]))\n}",_context2.prev=174,new Function("return "+code),_context2.next=181;break;case 178:throw _context2.prev=178,_context2.t12=_context2.catch(174),new Error("Generated "+_type.name+' code "'+code+"\" doesn't compile: "+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(_context2.t12));case 181:return configuration.core.debug&&console.debug(_type.name+' code: \n\n"'+code+'" integrated.'),_context2.next=184,(0,_helper__WEBPACK_IMPORTED_MODULE_8__.ensureValidationDocumentPresence)(couchdb.connection,_type.name,{helper:databaseHelperCode,validate_doc_update:code},_type.description,!0,idName,revisionName,specialNames.designDocumentNamePrefix);case 184:_context2.next=171;break;case 186:_i3=0,_Object$entries3=Object.entries(models);case 187:if(!(_i3<_Object$entries3.length)){_context2.next=229;break}_Object$entries3$_i=_Object$entries3[_i3],modelName=_Object$entries3$_i[0],model=_Object$entries3$_i[1],_i4=0,_Object$entries4=Object.entries(model);case 190:if(!(_i4<_Object$entries4.length)){_context2.next=226;break}if(_Object$entries4$_i=_Object$entries4[_i4],_name=_Object$entries4$_i[0],specification=_Object$entries4$_i[1],![specialNames.constraint.execution,specialNames.constraint.expression].includes(_name)){_context2.next=208;break}_iterator6=_createForOfIteratorHelperLoose([].concat(specification));case 194:if((_step6=_iterator6()).done){_context2.next=206;break}if(constraint=_step6.value,!constraint.description){_context2.next=204;break}_context2.prev=197,new Function("return "+constraint.description),_context2.next=204;break;case 201:throw _context2.prev=201,_context2.t13=_context2.catch(197),new Error('Specified constraint description "'+constraint.description+'" for model "'+modelName+"\" doesn't compile: "+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(_context2.t13));case 204:_context2.next=194;break;case 206:_context2.next=223;break;case 208:_iterator7=_createForOfIteratorHelperLoose(["conflictingConstraintExpression","conflictingConstraintExecution","constraintExpression","constraintExecution"]);case 209:if((_step7=_iterator7()).done){_context2.next=223;break}if(type=_step7.value,!(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.isObject)(specification)){_context2.next=221;break}if(_constraint=specification[type],null==_constraint||!_constraint.description){_context2.next=221;break}_context2.prev=214,new Function(_constraint.description),_context2.next=221;break;case 218:throw _context2.prev=218,_context2.t14=_context2.catch(214),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)(_context2.t14));case 221:_context2.next=209;break;case 223:_i4++,_context2.next=190;break;case 226:_i3++,_context2.next=187;break;case 229:if(!configuration.couchdb.model.autoMigrationPath){_context2.next=329;break}return migrators={},_context2.next=233,(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.isDirectory)((0,path__WEBPACK_IMPORTED_MODULE_5__.resolve)(configuration.couchdb.model.autoMigrationPath));case 233:if(!_context2.sent){_context2.next=286;break}return _context2.t15=_createForOfIteratorHelperLoose,_context2.next=237,(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 237:_context2.t16=_context2.sent,_iterator8=(0,_context2.t15)(_context2.t16);case 239:if((_step8=_iterator8()).done){_context2.next=286;break}if(file=_step8.value,extension=(0,path__WEBPACK_IMPORTED_MODULE_5__.extname)(file.name),_name2=(0,path__WEBPACK_IMPORTED_MODULE_5__.basename)(file.name,extension),".json"!==extension){_context2.next=276;break}return documents=void 0,_context2.prev=245,_context2.t17=[],_context2.t18=JSON,_context2.next=250,fs__WEBPACK_IMPORTED_MODULE_4__.promises.readFile(file.path,{encoding:configuration.core.encoding,flag:"r"});case 250:_context2.t19=_context2.sent,_context2.t20=_context2.t18.parse.call(_context2.t18,_context2.t19),documents=_context2.t17.concat.call(_context2.t17,_context2.t20),_context2.next=258;break;case 255:throw _context2.prev=255,_context2.t21=_context2.catch(245),new Error('Parsing document "'+file.path+'" to include by automigration of has failed: '+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(_context2.t21));case 258:1===documents.length&&(documents[0][idName]||(documents[0][idName]=_name2),documents[0][revisionName]||(documents[0][revisionName]="0-upsert")),_iterator9=_createForOfIteratorHelperLoose(documents);case 260:if((_step9=_iterator9()).done){_context2.next=274;break}return document=_step9.value,_context2.prev=262,_context2.next=265,couchdb.connection.put(document);case 265:_context2.next=271;break;case 267:throw _context2.prev=267,_context2.t22=_context2.catch(262),null!=(_forbidden=_context2.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)(_context2.t22));case 271:console.info('Including document "'+document[idName]+'" of','type "'+document[typeName]+'" was',"successful.");case 272:_context2.next=260;break;case 274:_context2.next=284;break;case 276:if(![".js"].includes((0,path__WEBPACK_IMPORTED_MODULE_5__.extname)(file.name))){_context2.next=280;break}migrators[file.path]=eval("require('"+file.path+"')").default,_context2.next=284;break;case 280:if(![".mjs"].includes((0,path__WEBPACK_IMPORTED_MODULE_5__.extname)(file.name))){_context2.next=284;break}return _context2.next=283,eval("import('"+file.path+"')");case 283:migrators[file.path]=_context2.sent.default;case 284:_context2.next=239;break;case 286:return _context2.t23=_createForOfIteratorHelperLoose,_context2.next=289,couchdb.connection.allDocs({include_docs:!0});case 289:_context2.t24=_context2.sent.rows,_iterator10=(0,_context2.t23)(_context2.t24);case 291:if((_step10=_iterator10()).done){_context2.next=329;break}if(retrievedDocument=_step10.value,"string"==typeof retrievedDocument.id&&retrievedDocument.id.startsWith(configuration.couchdb.model.property.name.special.designDocumentNamePrefix)){_context2.next=327;break}_document=retrievedDocument.doc,newDocument=(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.copy)(_document),newDocument[configuration.couchdb.model.property.name.special.strategy]="migrate",_iterator11=_createForOfIteratorHelperLoose(Object.keys(migrators).sort());case 298:if((_step11=_iterator11()).done){_context2.next=311;break}_name3=_step11.value,_result=null,_context2.prev=301,_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_9___default(),idName,typeName,migrators,models,modelConfiguration,selfFilePath:_name3,services})),_context2.next=308;break;case 305:throw _context2.prev=305,_context2.t25=_context2.catch(301),new Error('Running migrater "'+_name3+'" in document '+(0,_helper__WEBPACK_IMPORTED_MODULE_8__.mayStripRepresentation)(_document,configuration.couchdb.maximumRepresentationTryLength,configuration.couchdb.maximumRepresentationLength)+'" failed: '+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(_context2.t25));case 308:_result&&(newDocument=_result,console.info('Running migrater "'+_name3+'" for document','"'+newDocument[idName]+'" (of type','"'+newDocument[typeName]+'") was successful.'));case 309:_context2.next=298;break;case 311:if(result=couchdb.validateDocument(newDocument,{checkPublicModelType:!0,oldDocument:_document}),!0===result){_context2.next=318;break}if(!Object.prototype.hasOwnProperty.call(result,"forbidden")){_context2.next=317;break}console.warn('Document "'+(0,_helper__WEBPACK_IMPORTED_MODULE_8__.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)(result)),_context2.next=318;break;case 317:throw result;case 318:return _context2.prev=318,_context2.next=321,couchdb.connection.put(newDocument);case 321:_context2.next=326;break;case 323:throw _context2.prev=323,_context2.t26=_context2.catch(318),new Error('Replacing auto migrated document "'+newDocument[idName]+'" has failed: '+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(_context2.t26));case 326:console.info('Auto migrating document "'+newDocument[idName]+'" was',"successful.");case 327:_context2.next=291;break;case 329:return _context2.next=331,couchdb.connection.getIndexes();case 331:if(genericIndexes=_context2.sent.indexes.filter((function(e){return e.name.endsWith("-GenericIndex")})),!configuration.couchdb.createGenericFlatIndex||!configuration.couchdb.model.autoMigrationPath&&0!==genericIndexes.length){_context2.next=383;break}_i5=0,_Object$entries5=Object.entries(models);case 334:if(!(_i5<_Object$entries5.length)){_context2.next=365;break}if(_Object$entries5$_i=_Object$entries5[_i5],_modelName=_Object$entries5$_i[0],_model=_Object$entries5$_i[1],!new RegExp(configuration.couchdb.model.property.name.typePattern.public).test(_modelName)){_context2.next=362;break}return _context2.next=339,couchdb.connection.createIndex({index:{ddoc:_modelName+"-GenericIndex",fields:[typeName],name:_modelName+"-GenericIndex"}});case 339:_iterator12=_createForOfIteratorHelperLoose((0,_helper__WEBPACK_IMPORTED_MODULE_8__.determineGenericIndexablePropertyNames)(configuration.couchdb.model,_model));case 340:if((_step12=_iterator12()).done){_context2.next=362;break}propertyName=_step12.value,_name4=_modelName+"-"+propertyName+"-GenericIndex",foundPosition=-1,position=0,_iterator13=_createForOfIteratorHelperLoose(genericIndexes);case 346:if((_step13=_iterator13()).done){_context2.next=354;break}if(index=_step13.value,index.name!==_name4){_context2.next=351;break}return foundPosition=position,_context2.abrupt("break",354);case 351:position+=1;case 352:_context2.next=346;break;case 354:if(-1!==foundPosition){_context2.next=359;break}return _context2.next=357,couchdb.connection.createIndex({index:{ddoc:_name4,fields:[typeName,propertyName],name:_name4}});case 357:_context2.next=360;break;case 359:genericIndexes.slice(position,1);case 360:_context2.next=340;break;case 362:_i5++,_context2.next=334;break;case 365:_iterator14=_createForOfIteratorHelperLoose(genericIndexes);case 366:if((_step14=_iterator14()).done){_context2.next=383;break}_index=_step14.value,exists=!1,_i6=0,_Object$entries6=Object.entries(models);case 370:if(!(_i6<_Object$entries6.length)){_context2.next=378;break}if(_Object$entries6$_i=_Object$entries6[_i6],_modelName2=_Object$entries6$_i[0],_model2=_Object$entries6$_i[1],!_index.name.startsWith(_modelName2+"-")){_context2.next=375;break}for(_iterator15=_createForOfIteratorHelperLoose((0,_helper__WEBPACK_IMPORTED_MODULE_8__.determineGenericIndexablePropertyNames)(configuration.couchdb.model,_model2));!(_step15=_iterator15()).done;)_name5=_step15.value,[_modelName2+"-"+_name5+"-GenericIndex",_modelName2+"-GenericIndex"].includes(_index.name)&&(exists=!0);return _context2.abrupt("break",378);case 375:_i6++,_context2.next=370;break;case 378:if(exists){_context2.next=381;break}return _context2.next=381,couchdb.connection.deleteIndex(_index);case 381:_context2.next=366;break;case 383:if(!configuration.couchdb.model.triggerInitialCompaction){_context2.next=392;break}return _context2.prev=384,_context2.next=387,couchdb.connection.compact();case 387:_context2.next=392;break;case 389:_context2.prev=389,_context2.t27=_context2.catch(384),console.warn("Initial database compaction has failed: "+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(_context2.t27));case 392:return _context2.abrupt("return",{couchdb:promise});case 393:case"end":return _context2.stop()}}),_callee2,null,[[19,27,45,48],[31,36,39,42],[53,58,73,76],[62,67],[91,97],[104,112],[116,121],[146,154],[174,178],[197,201],[214,218],[245,255],[262,267],[301,305],[318,323],[384,389]])})));return function(e){return _ref4.apply(this,arguments)}}(),postLoadService=function(e){for(var t=e.configuration.couchdb,n=e.pluginAPI,r=e.services.couchdb,o=0,a=31*t.changesStreamReinitializer.retries,i=0;i<=t.changesStreamReinitializer.retries;i+=1)a+=Math.min(Math.pow(t.changesStreamReinitializer.retryWaitingFactorInSeconds,i),t.changesStreamReinitializer.maxmumRetryWaitingTimeInSeconds);setInterval((function(){o>0&&(console.info("No additional errors (initially got",String(o)+" errors through)","occurred during observing changes stream for",String(a),"seconds. Clearing saved number of errors through."),o=0)}),1e3*a);var c=(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 a(){var i,_;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(a){for(;;)switch(a.prev=a.next){case 0:return r.changesStream&&r.changesStream.cancel(),i=t.changesStream,void 0!==r.lastChangesSequenceIdentifier&&(i.since=r.lastChangesSequenceIdentifier),console.info("Initialize changes stream since",'"'+String(i.since)+'".'),r.changesStream=r.connection.changes(i),r.changesStream.on("error",_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function n(a){var i;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(!((o+=1)>t.changesStreamReinitializer.retries)){n.next=9;break}return console.warn("Observing changes feed throws an error for",String(o)+" times through:",(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(a)+" Restarting database server and","reinitialize changes stream..."),o=0,r.changesStream.cancel(),n.next=7,r.server.restart(e);case 7:n.next=13;break;case 9:return i=Math.min(Math.pow(t.changesStreamReinitializer.retryWaitingFactorInSeconds,o),t.changesStreamReinitializer.maxmumRetryWaitingTimeInSeconds),console.warn("Observing changes feed throws an error for",String(o)+" of",String(t.changesStreamReinitializer.retries),"allowed times through: "+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(a),"Reinitializing changes stream in",String(i)+" seconds..."),n.next=13,(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.timeout)(1e3*i);case 13:c();case 14:case"end":return n.stop()}}),n)})))),a.next=8,n.callStack(_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({},e,{data:r.changesStream,hook:"couchdbInitializeChangesStream"}));case 8:console.info("Changes stream initialized."),_=new clientnode__WEBPACK_IMPORTED_MODULE_3__.Semaphore(t.numberOfParallelChangesRunner),r.changesStream.on("change",_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function t(a){return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return o=0,t.prev=1,t.next=4,_.acquire();case 4:return t.next=6,n.callStack(_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({},e,{data:a,hook:"couchdbChange"}));case 6:r.lastChangesSequenceIdentifier=a.seq,t.next=12;break;case 9:t.prev=9,t.t0=t.catch(1),console.error("An error occurred during on change database hook:",t.t0);case 12:return t.prev=12,_.release(),t.finish(12);case 15:case"end":return t.stop()}}),t,null,[[1,9,12,15]])}))));case 11:case"end":return a.stop()}}),a)}))));return t.attachAutoRestarter&&c(),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_10__.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(t){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";var t=[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 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=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},i.apply(null,arguments)}function c(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 _(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)?_(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 _(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,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===i&&(i="-type"),void 0===_&&(_="_design/"),void 0===s&&(s=!1);var d=null!==(l=e[i])&&void 0!==l?l:t&&t[i];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(_)&&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=o[d],g=c(["read","write"]);!(y=g()).done;){var x=y.value;f[x]=f[x].concat(O[x]||[])}f.properties=O.properties}for(var v,E=f[m],P=c(n.roles);!(v=P()).done;){var D=v.value;if(E.includes(D))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,_,s,l){void 0===_&&(_={}),void 0===s&&(s=!0);var u=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)},p=new Date,d=Date.UTC(p.getUTCFullYear(),p.getUTCMonth(),p.getUTCDate(),p.getUTCHours(),p.getUTCMinutes(),p.getUTCSeconds(),p.getUTCMilliseconds())/1e3,m=!a.dateTimeFormat.startsWith("iso"),f=a.property.name.special,b=f.id,h=f.revision,y=f.type;t&&t[y]&&!e[y]&&(e[y]=t[y]);var O="",g="",x=function(){O=Object.prototype.hasOwnProperty.call(e,b)?e[b]:"",g=Object.prototype.hasOwnProperty.call(e,h)?e[h]:""};if(x(),Object.prototype.hasOwnProperty.call(o,a.property.name.validatedDocumentsCache)&&o[a.property.name.validatedDocumentsCache].has(O+"-"+g))return o[a.property.name.validatedDocumentsCache].delete(O+"-"+g),e;["0-latest","0-upsert"].includes(g)&&(t&&Object.prototype.hasOwnProperty.call(t,h)?g=e[h]=t[h]:"0-latest"===g?u("Revision: No old document available to update."):delete e[h]);var v=a.updateStrategy;Object.prototype.hasOwnProperty.call(e,f.strategy)&&(v=e[f.strategy],delete e[f.strategy]);var E,P={};if("migrate"===v)for(var D=0,M=Object.entries(_);D<M.length;D++){var w=M[D],C=w[0],k=w[1];if(Object.prototype.hasOwnProperty.call(k,f.oldType)&&k[f.oldType])for(var T,j=c([].concat(k[f.oldType]));!(T=j()).done;){var A=T.value;P[A]=C}}l?E=l:"undefined"!=typeof JSON&&Object.prototype.hasOwnProperty.call(JSON,"stringify")?E=function(e){return JSON.stringify(e,null,4)}:u('Needed "serializer" is not available.');var I=[f.additional,f.allowedRole,f.constraint.execution,f.constraint.expression,f.create.execution,f.create.expression,f.extend,f.maximumAggregatedSize,f.minimumAggregatedSize,f.oldType,f.update.execution,f.update.expression],S=function(e){return e instanceof Error?String(e):E(e)},R=function(e){return"string"==typeof e?e.trim():""},U=function(e){if(m)null!==e&&"number"!=typeof e&&(e=new Date(e),e=Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate(),e.getUTCHours(),e.getUTCMinutes(),e.getUTCSeconds(),e.getUTCMilliseconds())/1e3);else if(null!==e){e=new Date("number"!=typeof e||isNaN(e)?e:1e3*e);try{e=e.toISOString()}catch(e){}}return e},L=function(e,t,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[f.attachment]),t)for(var r=0,o=Object.keys(n);r<o.length;r++){var a=o[r];if(a.startsWith(t))return a}else{var i=Object.keys(n);if(i.length)return i[0]}return null},B=function(e,t,n){void 0===t&&(t=!1),void 0===n&&(n={});var o=i({},N,{code:""},n),a=R(e);if(a){var c=(t?"return ":"")+a;o.code=c;var _,s=Object.keys(o);try{_=r(Function,s.concat([c]))}catch(e){u(S(e),"compilation",{code:c,error:e,scope:o})}var l={code:c,result:void 0,scope:o};try{l.result=_.apply(void 0,s.map((function(e){return o[e]})))}catch(e){u(S(e),"runtime",{code:c,error:e,scope:o})}return l}return u("No expression to evaluate provided.","empty"),{code:o.code,result:void 0,scope:o}},K=function(e,t,n,o){void 0===n&&(n=[]),void 0===o&&(o=!1);var i=n.length?" in "+n.join(" -> "):"",l=[],p=function(){Object.prototype.hasOwnProperty.call(e,y)||(t&&Object.prototype.hasOwnProperty.call(t,y)&&["fillUp","migrate"].includes(v)?e[y]=t[y]:u('Type: You have to specify a model type via property "'+y+'"'+i+".")),!s||n.length||new RegExp(a.property.name.typePattern.public).test(e[y])||u('TypeName: You have to specify a model type which matches "'+a.property.name.typePattern.public+'" as public type (given "'+e[y]+'")'+i+"."),Object.prototype.hasOwnProperty.call(_,e[y])||(Object.prototype.hasOwnProperty.call(P,e[y])?e[y]=P[e[y]]:u('Model: Given model "'+e[y]+'" is not specified'+i+"."))};p();var d=e[y],O=_[d],g=void 0;Object.prototype.hasOwnProperty.call(O,f.additional)&&O[f.additional]&&(g=O[f.additional]);var E=function(o,a,_,s,l){void 0===l&&(l=["constraintExecution","constraintExpression"]);for(var p,m=c(l);!(p=m()).done;){var f=p.value;if(Object.prototype.hasOwnProperty.call(_,f)){var b=void 0;try{b=B(_[f].evaluation,f.endsWith("Expression"),{checkPropertyContent:D,model:O,modelName:d,name:a,type:f,newDocument:e,newValue:o,oldDocument:t,oldValue:s,parentNames:n,pathDescription:i,propertySpecification:_})}catch(e){var h,y;if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&u('Compilation: Hook "'+f+'" has invalid code "'+e.code+'": "'+(null!==(h=e.message)&&void 0!==h?h:"unknown")+'"'+i+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&u('Runtime: Hook "'+f+'" has throw an error with code "'+e.code+'": "'+(null!==(y=e.message)&&void 0!==y?y:"unknown")+'"'+i+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}if(b&&!b.result){var g,x=R(null==(g=_[f])?void 0:g.description);u(f.charAt(0).toUpperCase()+(f.substring(1)+": ")+(x?r(Function,Object.keys(b.scope).concat(["return "+x])).apply(void 0,Object.values(b.scope)):'Property "'+String(a)+'" should satisfy constraint "'+b.code+'" (given "'+S(o)+'")'+i+"."))}}}},D=function(e,t,r,o,a){void 0===a&&(a=!1);var s=[],l=[].concat(r.type?r.type:[]);"object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype&&!Object.prototype.hasOwnProperty.call(e,y)&&1===l.length&&"string"==typeof l[0]&&Object.prototype.hasOwnProperty.call(_,l[0])&&(e[y]=l[0]);for(var p,d=!1,f=c(l);!(p=f()).done;){var h=p.value;if("string"==typeof h&&Object.prototype.hasOwnProperty.call(_,h)){if("object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype&&Object.prototype.hasOwnProperty.call(e,y)&&e[y]!==h&&"migrate"===v&&1===l.length&&(e[y]=h,s=n.concat(String(t),"migrate nested object type")),"object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype&&Object.prototype.hasOwnProperty.call(e,y)&&e[y]===h){var O=K(e,o,n.concat(String(t)),a||r.computed);if(O.changedPath.length&&(s=O.changedPath),e=O.newDocument,S(e)===S({}))return{newValue:void 0,changedPath:s};d=!0;break}1===l.length&&u('NestedType: Under key "'+String(t)+'" isn\'t of type "'+h+'" (given "'+S(e)+'" of type '+typeof e+")"+i+".")}else if("DateTime"===h){var g=e;if(e=U(e),!(m&&("number"!=typeof e||isNaN(e))||!m&&"string"!=typeof e)){d=!0;break}1===l.length&&u('PropertyType: Property "'+String(t)+'" isn\'t of (valid) type "DateTime" (given"'+S(g).replace(/^"/,"").replace(/"$/,"")+'" of type "'+typeof g+'")'+i+".")}else if("string"==typeof h&&["boolean","integer","number","string"].includes(h)){if(!("number"==typeof e&&isNaN(e)||"integer"!==h&&typeof e!==h||"integer"===h&&parseInt(e,10)!==e)){d=!0;break}1===l.length&&u('PropertyType: Property "'+String(t)+'" isn\'t of (valid) type "'+h+'" (given "'+S(e)+'" of type "'+typeof e+'")'+i+".")}else if("string"==typeof h&&h.startsWith("foreignKey:")){var x=_[h.substring(11)][b].type;if(x===typeof e){d=!0;break}1===l.length&&u('PropertyType: Foreign key property "'+String(t)+'" isn\'t of type "'+x+'" (given "'+S(e)+'" of type "'+typeof e+'")'+i+".")}else{if("any"===h||S(e)===S(h)){d=!0;break}1===l.length&&u('PropertyType: Property "'+String(t)+'" isn\'t value "'+String(h)+'" (given "'+S(e).replace(/^"/,"").replace(/"$/,"")+'" of type "'+typeof e+'")'+i+".")}}if(d||u('PropertyType: None of the specified types "'+l.join('", "')+'" for property "'+String(t)+'" matches value "'+S(e).replace(/^"/,"").replace(/"$/,"")+e+'" of type "'+typeof e+'"'+i+"."),"string"==typeof e&&("number"==typeof r.minimumLength&&e.length<r.minimumLength&&u('MinimalLength: Property "'+String(t)+'" must have minimal length '+r.minimumLength+" (given "+e+" with length "+String(e.length)+")"+i+"."),"number"==typeof r.maximumLength&&e.length>r.maximumLength&&u('MaximalLength: Property "'+String(t)+'" must have maximal length '+r.maximumLength+" (given "+e+" with length "+String(e.length)+")"+i+".")),"number"==typeof e&&("number"==typeof r.minimum&&e<r.minimum&&u('Minimum: Property "'+String(t)+'" (type '+r.type+") must satisfy a minimum of "+r.minimum+" (given "+String(e)+" is too low)"+i+"."),"number"==typeof r.maximum&&e>r.maximum&&u('Maximum: Property "'+String(t)+'" (type '+r.type+") must satisfy a maximum of "+r.maximum+" (given "+String(e)+" is too high)"+i+".")),r.selection){var P=Array.isArray(r.selection)?r.selection.map((function(e){return void 0===(null==e?void 0:e.value)?e:e.value})):Object.keys(r.selection);"DateTime"===r.type&&(P=P.map(U)),P.includes(e)||u('Selection: Property "'+String(t)+'" (type '+r.type+') should be one of "'+P.join('", "')+'". But is "'+e+'"'+i+".")}if(r.pattern){for(var D,M=[].concat(r.pattern),w=!1,C=c(M);!(D=C()).done;){var k=D.value;if(new RegExp(k).test(e)){w=!0;break}}w||u('PatternMatch: Property "'+String(t)+'" should match regular expression pattern "'+M.join('", "')+'" (given "'+e+'")'+i+".")}if(r.invertedPattern)for(var T,j=c([].concat(r.invertedPattern));!(T=j()).done;){var A=T.value;new RegExp(A).test(e)&&u('InvertedPatternMatch: Property "'+String(t)+'" should not match regular expression pattern '+String(A)+' (given "'+e+'")'+i+".")}return E(e,t,r,o),S(e)!==S(o)&&(s=n.concat(String(t),"value updated")),{newValue:e,changedPath:s}},M=function(e,t,r,o,i){var c=t[o];if(!e.writable)if(r){if(Object.prototype.hasOwnProperty.call(r,o)&&S(c)===S(r[o]))return o!==b&&"incremental"===v&&delete t[o],!0;u("Readonly: Property "+String(o)+'" isnot writable (old document "'+S(r)+'")'+i+".")}else u('Readonly: Property "'+String(o)+'" is not writable'+i+".");if(!e.mutable&&r&&Object.prototype.hasOwnProperty.call(r,o)){if(S(c)===S(r[o]))return"incremental"!==v||a.property.name.reserved.concat(f.deleted,b,h).includes(String(o))||delete t[o],!0;"migrate"!==v&&u('Immutable: Property "'+String(o)+'"is not writable (old document "'+S(r)+'")'+i+".")}if(null===c){if(e.nullable)return"incremental"===v&&r&&void 0!==r[o]||delete t[o],r&&Object.prototype.hasOwnProperty.call(r,o)&&(l=n.concat(String(o),"delete property")),!0;u('NotNull: Property "'+String(o)+'" should not be "null"'+i+".")}return!1},w=function(e,t,r,o,a){if(!r)for(var _,s=c(["onCreateExecution","onCreateExpression"]);!(_=s()).done;){var l=_.value;if(Object.prototype.hasOwnProperty.call(e,l)){var p=void 0;try{p=B(e[l],l.endsWith("Expression"),{attachmentsTarget:a,checkPropertyContent:D,model:O,modelName:d,name:String(o),type:l,newDocument:t,oldDocument:r,newValue:void 0,oldValue:void 0,parentNames:n,pathDescription:i,propertySpecification:e})}catch(e){var m,f;if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&u('Compilation: Hook "'+l+'" has invalid code "'+e.code+'" for property "'+String(o)+'": "'+(null!==(m=e.message)&&void 0!==m?m:"unknown")+'"'+i+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&u('Runtime: Hook "'+l+'" has throw an error with code "'+e.code+'" for property "'+String(o)+'": "'+(null!==(f=e.message)&&void 0!==f?f:"unknown")+'"'+i+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}p&&![null,void 0].includes(p.result)&&(a?a[o]=p.result:t[o]=p.result)}}},C=function(e,t,r,o,a){if(!a){if(!Object.prototype.hasOwnProperty.call(t,o))return;e.trim&&"string"==typeof t[o]&&(t[o]=t[o].trim()),e.emptyEqualsNull&&(""===t[o]||Array.isArray(t[o])&&0===t[o].length||null!==t[o]&&"object"==typeof t[o]&&0===Object.keys(t).length)&&(t[o]=null)}for(var _,s=c(["onUpdateExecution","onUpdateExpression"]);!(_=s()).done;){var l=_.value;if(Object.prototype.hasOwnProperty.call(e,l))try{var p=B(e[l],l.endsWith("Expression"),{attachmentsTarget:a,checkPropertyContent:D,model:O,modelName:d,name:String(o),type:l,newDocument:t,oldDocument:r,newValue:t[o],oldValue:r&&r[o]||void 0,parentNames:n,pathDescription:i,propertySpecification:e});a?a[o]=p.result:void 0!==p.result&&(t[o]=p.result)}catch(e){var m,f;if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&u('Compilation: Hook "'+l+'" has invalid code "'+e.code+'" for property "'+String(o)+'": "'+(null!==(m=e.message)&&void 0!==m?m:"unknown")+'"'+i+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&u('Runtime: Hook "'+l+'" has throw an error with code "'+e.code+'" for property "'+String(o)+'": "'+(null!==(f=e.message)&&void 0!==f?f:"unknown")+'"'+i+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}}},k=Object.keys(O).filter((function(e){return!I.includes(e)}));if("migrate"===v)for(var T,j=c(k);!(T=j()).done;){var A=T.value;if(O[A].oldName)for(var W,N=c([].concat(O[A].oldName));!(W=N()).done;){var $=W.value;Object.prototype.hasOwnProperty.call(e,$)&&(e[A]=e[$],delete e[$])}}if(!t)for(var q=0,z=[f.create.execution,f.create.expression];q<z.length;q++){var F=z[q];if(Object.prototype.hasOwnProperty.call(O,F)){var H=void 0;try{H=B(O[F],F.endsWith("Expression"),{checkPropertyContent:D,model:O,modelName:d,type:F,newDocument:e,oldDocument:t,parentNames:n,pathDescription:i}).result}catch(e){var G,V;if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&u('Compilation: Hook "'+F+'" has invalid code "'+e.code+'" for document "'+d+'": "'+(null!==(G=e.message)&&void 0!==G?G:"unknown")+'"'+i+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&u('Runtime: Hook "'+F+'" has throw an error with code "'+e.code+'" for document "'+d+'": "'+(null!==(V=e.message)&&void 0!==V?V:"unknown")+'"'+i+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}[null,void 0].includes(H)||(e=H),p(),d=e[y],0===n.length&&x()}}for(var J=0,Y=[f.update.execution,f.update.expression];J<Y.length;J++){var X=Y[J];if(Object.prototype.hasOwnProperty.call(O,X)){var Z=void 0;try{Z=B(O[X],X.endsWith("Expression"),{checkPropertyContent:D,model:O,modelName:d,type:X,newDocument:e,oldDocument:t,parentNames:n,pathDescription:i}).result}catch(e){var Q,ee;if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&u('Compilation: Hook "'+X+'" has invalid code "'+e.code+'" for document "'+d+'": "'+(null!==(Q=e.message)&&void 0!==Q?Q:"unknown")+'"'+i+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&u('Runtime: Hook "'+X+'" has throw an error with code "'+e.code+'" for document "'+d+'": "'+(null!==(ee=e.message)&&void 0!==ee?ee:"unknown")+'"'+i+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}[void 0,null].includes(Z)||(e=Z),p(),d=e[y],0===n.length&&x()}}for(var te,ne=g?Object.keys(e).filter((function(e){return!k.includes(e)})):[],re=c(k.concat(ne));!(te=re()).done;){var oe=te.value;if(f.attachment===oe)for(var ae=function(){var r=ce[ie],o=r[0],a=r[1];e[f.attachment]||(e[f.attachment]={}),t&&!Object.prototype.hasOwnProperty.call(t,oe)&&(t[f.attachment]={});var _=e[f.attachment],s=Object.keys(_).filter((function(e){return null!==_[e].data&&L(o,e,a)})),p=[];if(t){var d=t[oe];p=Object.keys(d).filter((function(e){return!(Object.prototype.hasOwnProperty.call(_,e)&&Object.prototype.hasOwnProperty.call(_[e],"data")&&null===_[e].data)&&Boolean(d[e])&&(Object.prototype.hasOwnProperty.call(d[e],"data")&&null!==d[e].data||Object.prototype.hasOwnProperty.call(d[e],"stub")&&Boolean(d[e].digest))&&Boolean(L(o,e,a))}))}for(var m,b=a,h=c(s);!(m=h()).done;){var y=m.value;w(b,e,t&&t[oe]?t[oe]:null,y,_)}for(var O,g=c(s);!(O=g()).done;){var x=O.value;C(b,e,t&&t[oe]?t[oe]:null,x,_)}if(void 0===b.default){if(b.nullable||s.length>0||p.length>0||u('AttachmentMissing: Missing attachment for type "'+o+'"'+i+"."),"fillUp"===v&&0===s.length&&p.length>0)for(var E,P=c(p);!(E=P()).done;){var D=E.value;null===_[D]?l=n.concat(oe,D,"file removed"):_[D]=t[oe][D]}}else if(0===s.length)if(0===p.length)for(var M in b.default)Object.prototype.hasOwnProperty.call(b.default,M)&&(_[M]=b.default[M],l=n.concat(oe,o,"add default file"));else if("fillUp"===v)for(var k,T=c(p);!(k=T()).done;){var j=k.value;_[j]=t[oe][j]}},ie=0,ce=Object.entries(O[f.attachment]);ie<ce.length;ie++)ae();else{var _e=k.includes(oe)?O[oe]:g;w(_e,e,t,oe),C(_e,e,t,oe),[null,void 0].includes(_e.default)?(_e.nullable||Object.prototype.hasOwnProperty.call(e,oe)&&void 0!==e[oe]||t&&Object.prototype.hasOwnProperty.call(t,oe)&&"replace"!==v||u('MissingProperty: Missing property "'+String(oe)+'"'+i+"."),o||_e.computed||Object.prototype.hasOwnProperty.call(e,oe)&&void 0!==e[oe]||!t||!Object.prototype.hasOwnProperty.call(t,oe)||("fillUp"===v?e[oe]=t[oe]:"replace"===v&&(l=n.concat(String(oe),"property removed")))):Object.prototype.hasOwnProperty.call(e,oe)&&![null,void 0].includes(e[oe])||(t?o||_e.computed||null===e[oe]||"fillUp"!==v?"migrate"===v&&(e[oe]=_e.default,l=n.concat(String(oe),"migrate default value")):e[oe]=t[oe]:(e[oe]=_e.default,l=l.concat(String(oe),"add default value")))}}if(t&&"incremental"===v)for(var se=0,le=Object.entries(e);se<le.length;se++){var ue=le[se],pe=ue[0],de=ue[1];!Object.prototype.hasOwnProperty.call(t,pe)||a.property.name.reserved.concat(b,h,f.conflict,f.deleted,f.deletedConflict,f.localSequence,f.revisions,f.revisionsInformation,y).includes(pe)||t[pe]!==de&&S(t[pe])!==S(de)||delete e[pe]}for(var me=0,fe=Object.entries(e);me<fe.length;me++){var be=fe[me],he=be[0],ye=be[1];if(!a.property.name.reserved.concat(h,f.conflict,f.deleted,f.deletedConflict,f.localSequence,f.revisions,f.revisionsInformation,f.strategy).includes(he)){var Oe=void 0;if(Object.prototype.hasOwnProperty.call(O,he))Oe=O[he];else if(g)Oe=g;else{if("migrate"===v){delete e[he],l=n.concat(String(he),"migrate removed property");continue}u('Property: Given property "'+String(he)+'" isn\'t specified in model "'+d+'"'+i+".")}if(!Oe)continue;if(f.attachment===he){var ge=ye;for(var xe in ge)if(Object.prototype.hasOwnProperty.call(ge,xe))for(var ve=0,Ee=Object.keys(O[he]);ve<Ee.length;ve++){var Pe=Ee[ve],De=O[f.attachment][Pe];if(L(Pe,xe,De)){M(De,e,t,xe,i);break}}continue}if(M(Oe,e,t,he,i))continue;var Me="string"==typeof Oe.type&&Oe.type.endsWith("[]")||Array.isArray(Oe.type)&&Oe.type.length&&Array.isArray(Oe.type[0]);if(Me&&![null,void 0].includes(ye)){var we=ye;Array.isArray(we)?"number"==typeof Oe.minimumNumber&&we.length<Oe.minimumNumber?u('MinimumArrayLength: Property "'+String(he)+'" (array of length '+String(we.length)+") doesn't fulfill minimum array length of "+Oe.minimumNumber+i+"."):"number"==typeof Oe.maximumNumber&&Oe.maximumNumber<we.length&&u('MaximumArrayLength: Property "'+String(he)+'" (array of length '+String(we.length)+") doesn't fulfill maximum array length of "+Oe.maximumNumber+i+"."):u('PropertyType: Property "'+String(he)+'" isn\'t of type "array -> '+Oe.type+'" (given"'+S(we)+'")'+i+"."),E(we,String(he),Oe,t&&Object.prototype.hasOwnProperty.call(t,he)&&t[he]||void 0,["arrayConstraintExecution","arrayConstraintExpression"]);var Ce={};for(var ke in Oe)if(Object.prototype.hasOwnProperty.call(Oe,ke))if("type"===ke){var Te=Oe[ke];Array.isArray(Oe[ke])?Ce[ke]=Te[0]:Ce[ke]=[Te.substring(0,Te.length-2)]}else Ce[ke]=Oe[ke];if(Array.isArray(Ce.type)&&1===Ce.type.length&&"string"==typeof Ce.type[0]&&Object.prototype.hasOwnProperty.call(_,Ce.type[0]))for(var je,Ae=c(we.slice());!(je=Ae()).done;){var Ie=je.value;"object"!=typeof Ie||Object.getPrototypeOf(Ie)!==Object.prototype||Object.prototype.hasOwnProperty.call(Ie,y)||(Ie[y]=Ce.type[0])}for(var Se,Re=0,Ue=c(we.slice());!(Se=Ue()).done;){var Le=Se.value;we[Re]=D(Le,String(Re+1)+". value in "+String(he),Ce,void 0,o||Ce.computed).newValue,[null,void 0].includes(we[Re])&&we.splice(Re,1),Re+=1}t&&Object.prototype.hasOwnProperty.call(t,he)&&Array.isArray(t[he])&&t[he].length===we.length&&S(t[he])===S(we)||(l=n.concat(String(he),"array updated"))}else{var We=t&&Object.prototype.hasOwnProperty.call(t,he)?t[he]:void 0,Be=Me?{newValue:null,changedPath:[]}:D(ye,String(he),Oe,We,o||Oe.computed);e[he]=Be.newValue,Be.changedPath.length&&(l=Be.changedPath),null===e[he]&&(void 0===We?"fillUp"===v&&delete e[he]:l=n.concat(String(he),"property removed")),void 0===e[he]&&"incremental"===v&&delete e[he]}}}for(var Ke=0,Ne=Object.keys(f.constraint);Ke<Ne.length;Ke++){var $e=Ne[Ke],qe=f.constraint[$e];if(Object.prototype.hasOwnProperty.call(O,qe))for(var ze,Fe=O[qe],He=c([].concat(Fe));!(ze=He()).done;){var Ge=ze.value,Ve=void 0;try{Ve=B(Ge.evaluation,qe===f.constraint.expression,{checkPropertyContent:D,model:O,modelName:d,type:qe,newDocument:e,oldDocument:t,parentNames:n,pathDescription:i})}catch(e){var Je,Ye;if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&u('Compilation: Hook "'+qe+'" has invalid code "'+e.code+'": "'+(null!==(Je=e.message)&&void 0!==Je?Je:"unknown")+'"'+i+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&u('Runtime: Hook "'+qe+'" has thrown an error with code "'+e.code+'": "'+(null!==(Ye=e.message)&&void 0!==Ye?Ye:"unknown")+'"'+i+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}if(Ve&&!Ve.result){var Xe=qe.replace(/^[^a-zA-Z]+/,"");u(Xe.charAt(0).toUpperCase()+(Xe.substring(1)+": ")+(Ge.description?r(Function,Object.keys(Ve.scope).concat(["return "+Ge.description.trim()])).apply(void 0,Object.values(Ve.scope)):'Model "'+d+'" should satisfy constraint "'+Ve.code+'" (given "'+S(e)+'")'+i+"."))}}}if(Object.prototype.hasOwnProperty.call(e,f.attachment)){var Ze,Qe,et=e[f.attachment];"object"==typeof et&&Object.getPrototypeOf(et)===Object.prototype||u("AttachmentType: given attachment has invalid type"+i+".");var tt=null;if(t&&Object.prototype.hasOwnProperty.call(t,f.attachment)&&null!==(tt=t[f.attachment])&&"object"==typeof tt)for(var nt=0,rt=Object.entries(tt);nt<rt.length;nt++){var ot=rt[nt],at=ot[0],it=ot[1];if(it&&Object.prototype.hasOwnProperty.call(et,at)){var ct=et[at];null===ct||null===ct.data||ct.content_type===it.content_type&&(ct.data===it.data||ct.digest===it.digest)?(null!==ct&&null!==ct.data||(l=n.concat(f.attachment,at,"attachment removed")),"incremental"===v&&delete et[at]):l=n.concat(f.attachment,at,"attachment updated")}else"fillUp"===v?et[at]=it:"replace"===v&&(l=n.concat(f.attachment,at,"attachment removed"))}for(var _t=0,st=Object.entries(et);_t<st.length;_t++){var lt,ut=st[_t],pt=ut[0],dt=ut[1];if(!dt)break;null===dt.data?delete et[pt]:tt&&Object.prototype.hasOwnProperty.call(tt,pt)&&dt.content_type===(null==(lt=tt[pt])?void 0:lt.content_type)&&(dt.data===tt[pt].data||dt.digest===tt[pt].digest)||(l=n.concat(f.attachment,pt,"attachment updated"))}0===Object.keys(et).length&&delete e[f.attachment];for(var mt=O[f.attachment],ft={},bt=0,ht=Object.keys(mt);bt<ht.length;bt++)ft[ht[bt]]=[];for(var yt=0,Ot=Object.keys(et);yt<Ot.length;yt++){for(var gt=Ot[yt],xt=!1,vt=0,Et=Object.entries(mt);vt<Et.length;vt++){var Pt=Et[vt],Dt=Pt[0],Mt=Pt[1];if(L(Dt,gt,Mt)){ft[Dt].push(gt),xt=!0;break}}xt||u('AttachmentTypeMatch: None of the specified attachment types ("'+Object.keys(mt).join('", "')+'") matches given one ("'+gt+'")'+i+".")}for(var wt=0,Ct=0,kt=Object.keys(ft);Ct<kt.length;Ct++){var Tt=kt[Ct],jt=mt[Tt];if(Object.prototype.hasOwnProperty.call(ft,Tt)){var At=ft[Tt].length;"number"==typeof jt.maximumNumber&&At>jt.maximumNumber&&u("AttachmentMaximum: given number of attachments ("+String(At)+") doesn't satisfy specified maximum of "+String(jt.maximumNumber)+' from type "'+Tt+'"'+i+"."),(!jt.nullable||0!==At)&&"number"==typeof jt.minimumNumber&&At<jt.minimumNumber&&u("AttachmentMinimum: given number of attachments ("+String(At)+") doesn't satisfy specified minimum of "+String(jt.minimumNumber)+' from type "'+Tt+'"'+i+".");for(var It,St=0,Rt=c(ft[Tt]);!(It=Rt()).done;){var Ut,Lt,Wt,Bt=It.value;if(null!=(Ut=jt.fileName)&&Ut.pattern){for(var Kt,Nt=[].concat(jt.fileName.pattern),$t=!1,qt=c(Nt);!(Kt=qt()).done;){var zt=Kt.value;if(new RegExp(zt).test(Bt)){$t=!0;break}}$t||u('AttachmentName: given attachment name "'+Bt+'" doesn\'t satisfy one of specified regular expression patterns "'+Nt.join('", "')+'" from type "'+Tt+'"'+i+".")}if(null!=(Lt=jt.fileName)&&Lt.invertedPattern)for(var Ft,Ht=c([].concat(jt.fileName.invertedPattern));!(Ft=Ht()).done;){var Gt=Ft.value;new RegExp(Gt).test(Bt)&&u('InvertedAttachmentName: given attachment name "'+Bt+'" does satisfy specified regular expression pattern "'+Gt.toString()+'" from type "'+Tt+'"'+i+".")}if(null!=(Wt=et[Bt])&&Wt.content_type){if(jt.contentTypePattern){for(var Vt,Jt=[].concat(jt.contentTypePattern),Yt=!1,Xt=c(Jt);!(Vt=Xt()).done;){var Zt=Vt.value;if(new RegExp(Zt).test(et[Bt].content_type)){Yt=!0;break}}Yt||u('AttachmentContentType: given attachment content type "'+et[Bt].content_type+'" doesn\'t satisfy specified regular expression pattern "'+Jt.join('", "')+'" from type "'+Tt+'"'+i+".")}var Qt=jt.invertedContentTypePattern;if(Qt)for(var en,tn=c([].concat(Qt));!(en=tn()).done;){var nn=en.value;new RegExp(nn).test(et[Bt].content_type)&&u('InvertedAttachmentContentType: given attachment content type "'+et[Bt].content_type+'" does satisfy specified regular expression pattern "'+nn.toString()+'" from type "'+Tt+'"'+i+".")}}var rn=0;et[Bt]&&"length"in et[Bt]?rn=et[Bt].length:et[Bt]&&"data"in et[Bt]&&(rn="undefined"!=typeof Buffer&&"byteLength"in Buffer?Buffer.byteLength(et[Bt].data,"base64"):et[Bt].data.length),"number"==typeof jt.minimumSize&&jt.minimumSize>rn?u("AttachmentMinimumSize: given attachment size "+String(rn)+" byte doesn't satisfy specified minimum of "+String(jt.minimumSize)+" byte "+i+"."):"number"==typeof jt.maximumSize&&jt.maximumSize<rn&&u("AttachmentMaximumSize: given attachment size "+String(rn)+" byte doesn't satisfy specified maximum of "+String(jt.maximumSize)+" byte "+i+"."),St+=rn}"number"==typeof jt.minimumAggregatedSize&&jt.minimumAggregatedSize>St?u('AttachmentAggregatedMinimumSize: given aggregated size of attachments from type "'+Tt+'" '+String(St)+" byte doesn't satisfy specified minimum of "+String(jt.minimumAggregatedSize)+" byte "+i+"."):"number"==typeof jt.maximumAggregatedSize&&jt.maximumAggregatedSize<St&&u('AttachmentAggregatedMaximumSize: given aggregated size of attachments from type "'+Tt+'" '+String(St)+" byte doesn't satisfy specified maximum of "+String(jt.maximumAggregatedSize)+" byte "+i+"."),wt+=St}}(null!==(Ze=O[f.minimumAggregatedSize])&&void 0!==Ze?Ze:0)>wt?u("AggregatedMinimumSize: given aggregated size "+String(wt)+" byte doesn't satisfy specified minimum of "+String(O[f.minimumAggregatedSize])+" byte "+i+"."):(null!==(Qe=O[f.maximumAggregatedSize])&&void 0!==Qe?Qe:1/0)<wt&&u("AggregatedMaximumSize: given aggregated size "+String(wt)+" byte doesn't satisfy specified maximum of "+String(O[f.maximumAggregatedSize])+" byte "+i+".")}if(t&&Object.prototype.hasOwnProperty.call(t,f.attachment)&&0===Object.keys(t[f.attachment]).length&&delete t[f.attachment],0===l.length&&t&&"migrate"===v)for(var on=0,an=Object.keys(t);on<an.length;on++){var cn=an[on];Object.prototype.hasOwnProperty.call(e,cn)||(l=n.concat(cn,"migrate removed property"))}return{changedPath:l,newDocument:e}},N={attachmentWithPrefixExists:function(t){if(Object.prototype.hasOwnProperty.call(e,f.attachment)){var n=e[f.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:S,id:O,revision:g,idName:b,revisionName:h,specialNames:f,typeName:y,modelConfiguration:a,models:_,now:p,nowUTCTimestamp:d,securitySettings:o,updateStrategy:v,userContext:n},$=e[f.attachment];if(e[f.attachment])for(var q=0,z=Object.values($);q<z.length;q++){var F=z[q];null!=F&&F.contentType&&(F.content_type=F.contentType,delete F.contentType)}var H=K(e,t);return(H.newDocument._deleted&&!t||!(H.newDocument._deleted&&H.newDocument._deleted!==(null==t?void 0:t._deleted)||H.changedPath.length))&&u("NoChange: No new data given. new document: "+S(e)+"; old document: "+S(t)+"."),Object.prototype.hasOwnProperty.call(o,a.property.name.validatedDocumentsCache)?o[a.property.name.validatedDocumentsCache].add(O+"-"+g):o[a.property.name.validatedDocumentsCache]=new Set([O+"-"+g]),H.newDocument},u=e.exports,p=u}],n={};function r(e){var o=n[e];if(void 0!==o)return o.exports;var a=n[e]={id:e,loaded:!1,exports:{}};return t[e](a,a.exports,r),a.loaded=!0,a.exports}r.d=function(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.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},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o=r(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 _callee$(_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(e,t){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,i,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,i=a.resolve,c=a.reject,a.resolve=a.reject=clientnode__WEBPACK_IMPORTED_MODULE_4__.NOOP,e.next=7,stop(o,n);case 7:return a.resolve=i,a.reject=c,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(t){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.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(t,n){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__})();
1
+ (()=>{var __webpack_modules__=[(e,t,n)=>{"use strict";n.d(t,{bulkDocsFactory:()=>O,determineAllowedModelRolesMapping:()=>x,determineGenericIndexablePropertyNames:()=>E,ensureValidationDocumentPresence:()=>y,extendModels:()=>D,getConnectorOptions:()=>b,initializeConnection:()=>g,mayStripRepresentation:()=>h});var r=n(1),o=n.n(r),a=n(2),i=n.n(a),c=n(3),_=n.n(c),s=n(4);const l=require("rxjs"),u=require("rxjs/fetch"),p="1.0.722";function d(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 m(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)?m(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 m(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 f=Symbol("toggleLatestRevisionDetermining"),b=function(e){var t=e.couchdb.connector.fetch?function(t){return(0,s.extend)(!0,(0,s.copy)(e.couchdb.connector.fetch),t||{})}:s.identity,n=new Map([[408,"Request Timeout"],[425,"Too Early"],[429,"Too Many Requests"],[502,"Bad Gateway"],[503,"Service Unavailable"],[504,"Gateway Timeout"]]);return{fetch:function(r,o){var a=e.couchdb.connector.fetchInterceptor,i=a.numberOfRetries,c=a.retryIntervalInSeconds,_=a.exponentialBackoff,s=a.maximumRetryIntervallInSeconds,p=(0,u.fromFetch)(r,t(o)).pipe((0,l.map)((function(e){if(n.has(e.status))throw e;return e})),(0,l.retry)({count:i,delay:function(e,t){if("number"!=typeof e.status)throw e;var n=e;if(n.headers.has("retry-after")){var r=n.headers.get("retry-after");if("string"==typeof r){var o=parseInt(r);if(String(o)===r)return console.info("Retry in "+r+" seconds","according to given retry value."),(0,l.timer)(1e3*o);var a=new Date(r);if(!isNaN(a.getTime())){var i=new Date;if(i<a){if(s<(a.getTime()-i.getTime())/1e3)return console.info("Retry at",a.toUTCString(),"according to given retry","value."),(0,l.timer)(a);console.warn("The recommended retry attempt is",a.toUTCString(),"further in the future than the","configured maximum wait time of",s,"seconds.")}else console.warn("Given retry time recommendation","from server is in the past and","has to be ignored therefore.")}}}var u=_?Math.pow(2,t-1)*c:c;return(0,l.timer)(1e3*Math.min(u,s))}}));return(0,l.lastValueFrom)(p)}}},h=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"},y=function(){var e=i()(_().mark((function e(t,n,r,a,i,c,l,u){var d,m,f;return _().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return void 0===i&&(i=!0),void 0===c&&(c="_id"),void 0===l&&(l="_rev"),void 0===u&&(u="_design/"),m=o()(((d={})[c]=""+u+n,d.language="javascript",d.version=p,d),r),e.prev=5,e.next=8,t.get(""+u+n);case 8:return f=e.sent,m[l]=f[l],e.next=12,t.put(m);case 12:i&&console.info(a+" updated."),e.next=27;break;case 15:return e.prev=15,e.t0=e.catch(5),i&&("not_found"===e.t0.error?console.info(a+" not available: create new one."):console.info(a+" couldn't be updated: \""+(0,s.represent)(e.t0)+'" create new one.')),e.prev=18,e.next=21,t.put(m);case 21:i&&console.info(a+" installed/updated."),e.next=27;break;case 24:throw e.prev=24,e.t1=e.catch(18),new Error(a+" couldn't be installed/updated: \""+(0,s.represent)(e.t1)+'".');case 27:case"end":return e.stop()}}),e,null,[[5,15],[18,24]])})));return function(t,n,r,o,a,i,c,_){return e.apply(this,arguments)}}(),O=function(e,t){var n=t.model.property.name.special.id,r=t.model.property.name.special.revision;return i()(_().mark((function o(a){var i,c,l,u,p,m,b,h,y,O,g,x,v,E,P,D,M,w,C,k,T,j,A=arguments;return _().wrap((function(o){for(;;)switch(o.prev=o.next){case 0:for(i=A.length,c=new Array(i>1?i-1:0),l=1;l<i;l++)c[l-1]=A[l];u=c.length>0&&c[c.length-1]===f,p=u?!t.skipLatestRevisionDetermining:t.skipLatestRevisionDetermining,u&&c.pop(),m=!Array.isArray(a)&&(0,s.isObject)(a)&&n in a?[a]:a,b=t.maximumNumberOfEntitiesInBulkOperation,h=[],y=Math.random(),O=0;case 9:if(!(O<m.length)){o.next=24;break}return g=m.slice(O,O+b),console.log(),console.log("TODO before bulkDocs",y,O,g.length,m.length),console.log(),o.next=16,e.call.apply(e,[this,g].concat(c));case 16:x=o.sent,console.log(),console.log("TODO After bulkDocs",y),console.log(),h.concat(x);case 21:O+=b,o.next=9;break;case 24:v=[],E=[],P=0,D=0,M=h;case 28:if(!(D<M.length)){o.next=52;break}if(w=M[D],"object"!=typeof m[P]){o.next=48;break}if(!(r in m[P])||"conflict"!==w.name||!["0-latest","0-upsert"].includes(m[P][r])){o.next=36;break}E.push(m[P]),v.push(P),o.next=48;break;case 36:if(!(n in m[P]&&t.ignoreNoChangeError&&"name"in w&&"forbidden"===w.name&&"message"in w&&w.message.startsWith("NoChange:"))){o.next=48;break}if(h[P]={id:m[P][n],ok:!0},p){o.next=48;break}if(!(r in m[P])||["0-latest","0-upsert"].includes(m[P][r])){o.next=43;break}o.t0=m[P][r],o.next=47;break;case 43:return o.next=45,this.get(h[P].id);case 45:o.t1=r,o.t0=o.sent[o.t1];case 47:h[P].rev=o.t0;case 48:P+=1;case 49:D++,o.next=28;break;case 52:if(!E.length){o.next=59;break}return m=E,u&&c.push(f),o.next=57,this.bulkDocs.apply(this,[m].concat(c));case 57:for(C=o.sent,k=d(C);!(T=k()).done;)j=T.value,h[v.shift()]=j;case 59:return o.abrupt("return",h);case 60:case"end":return o.stop()}}),o,this)})))},g=function(){var e=i()(_().mark((function e(t,n){var r,o,a;return _().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=n.couchdb,o=(0,s.format)(r.url,r.admin.name+":"+r.admin.password+"@")+"/"+r.databaseName,t.couchdb.connection=new t.couchdb.connector(o,b(n)),(a=t.couchdb.connection).setMaxListeners(1/0),a.bulkDocs=O(a.bulkDocs,n.couchdb),a.put=i()(_().mark((function e(t,n){var r;return _().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,a.bulkDocs.call(this,[t],n);case 2:if(null==(r=e.sent[0])||!r.name){e.next=5;break}throw r;case 5:return e.abrupt("return",r);case 6:case"end":return e.stop()}}),e,this)}))),e.prev=7,e.next=10,(0,s.checkReachability)(o);case 10:e.next=19;break;case 12:if(e.prev=12,e.t0=e.catch(7),console.info("Database could not be retrieved yet: Creating it."),s.globalContext.fetch){e.next=17;break}throw new Error("Missing fetch implementation.");case 17:return e.next=19,s.globalContext.fetch(o,{method:"PUT"});case 19:return e.abrupt("return",t);case 20:case"end":return e.stop()}}),e,null,[[7,12]])})));return function(t,n){return e.apply(this,arguments)}}(),x=function(e){for(var t=e.property.name.special.allowedRole,n={},r=D(e),a=0,i=Object.entries(r);a<i.length;a++){var c=i[a],_=c[0],l=c[1];if(l[t]){n[_]=o()({properties:{}},M(l[t]));for(var u=0,p=Object.entries(l);u<p.length;u++){var d=p[u],m=d[0],f=d[1];(0,s.isObject)(f)&&f.allowedRoles&&(n[_].properties[m]=M(f.allowedRoles))}}else n[_]={properties:{},read:[],write:[]}}return n},v=function(e){return(0,s.isObject)(e)},E=function(e,t){var n=e.property.name.special;return Object.keys(t).filter((function(r){var o=t[r];return v(o)&&Object.prototype.hasOwnProperty.call(o,"index")&&o.index||v(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()},P=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=d([].concat(t[e][n]));!(r=o()).done;){var a=r.value;t[e]=(0,s.extend)(!0,(0,s.copy)(P(a,t,n)),t[e])}delete t[e][n]}return t[e]},D=function(e){for(var t=e.property.name.special,n={},r=e.property.name.typePattern,o=0,a=Object.keys(e.entities);o<a.length;o++){var i=a[o];if(!new RegExp(r.public).test(i)&&!new RegExp(r.private).test(i))throw new Error('Model names have to match "'+r.public+'" or "'+r.private+'" for private one (given name: "'+i+'").');n[i]=P(i,e.entities,t.extend)}for(var c=0,_=Object.values(n);c<_.length;c++)for(var l=_[c],u=0,p=Object.entries(l);u<p.length;u++){var d=p[u],m=d[0],f=d[1];if(m===t.attachment)for(var b=f,h=0,y=Object.entries(b);h<y.length;h++){var O=y[h],g=O[0],x=O[1];b[g]=(0,s.extend)(!0,(0,s.copy)(e.property.defaultSpecification),x)}else[t.allowedRole,t.constraint.execution,t.constraint.expression,t.extend,t.maximumAggregatedSize,t.minimumAggregatedSize,t.oldType].includes(m)||(l[m]=(0,s.extend)(!0,(0,s.copy)(e.property.defaultSpecification),f))}return n},M=function(e){if(Array.isArray(e))return{read:e,write:e};if("object"==typeof e){for(var t={read:[],write:[]},n=0,r=Object.keys(t);n<r.length;n++){var o=r[n];Object.prototype.hasOwnProperty.call(e,o)&&(Array.isArray(e[o])?t[o]=e[o]:t[o]=[e[o]])}return t}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__,{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_9__=__webpack_require__(8),_databaseHelper__WEBPACK_IMPORTED_MODULE_9___default=__webpack_require__.n(_databaseHelper__WEBPACK_IMPORTED_MODULE_9__),_helper__WEBPACK_IMPORTED_MODULE_8__=__webpack_require__(0),_server__WEBPACK_IMPORTED_MODULE_10__=__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 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,i,c,_,s,l,u,p,d,m,f,b,h;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")||(o.connector=pouchdb_node__WEBPACK_IMPORTED_MODULE_6___default(),o.connector.plugin({bulkDocs:(0,_helper__WEBPACK_IMPORTED_MODULE_8__.bulkDocsFactory)(o.connector.prototype.bulkDocs,n)}),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={},a=[],i=_createForOfIteratorHelperLoose([].concat(n.binary.runner));case 8:if((c=i()).done){e.next=34;break}_=c.value,s=_createForOfIteratorHelperLoose([].concat(_.location));case 11:if((l=s()).done){e.next=30;break}u=l.value,p=_createForOfIteratorHelperLoose([].concat(_.name));case 14:if((d=p()).done){e.next=26;break}return m=d.value,f=(0,path__WEBPACK_IMPORTED_MODULE_5__.resolve)(u,m),a.push(f),e.next=20,(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.isFile)(f);case 20:if(!e.sent){e.next=24;break}return _.binaryFilePath=f,o.server.runner=_,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: "'+a.join('", "')+'".');case 36:delete(b=(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.copy)(n.model)).property.defaultSpecification,delete b.entities,h=(0,_helper__WEBPACK_IMPORTED_MODULE_8__.extendModels)(n.model),o.validateDocument=function(e,t){var r,o=(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.copy)(null!==(r=t.oldDocument)&&void 0!==r?r:e),a=Boolean(t.checkPublicModelType);(e=(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.copy)(e))[n.model.property.name.special.strategy]="migrate",t.type&&(e[b.property.name.special.type]=o[b.property.name.special.type]=t.type);try{return(0,_databaseHelper__WEBPACK_IMPORTED_MODULE_9__.validateDocumentUpdate)(e,o,{db:n.databaseName,name:n.admin.name,roles:["_admin"]},(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.copy)(n.security[n.databaseName]),b,h,a),!0}catch(e){return!(!Object.prototype.hasOwnProperty.call(e,"forbidden")||!e.forbidden.startsWith("NoChange:"))||e}};case 41:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),loadService=function(){var _ref4=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function _callee2(_ref3){var configuration,services,promise,couchdb,urlPrefix,authorizationHeader,headers,unauthenticatedUserDatabaseConnection,authenticatedUserDatabaseConnection,userDatabaseConnection,_i,_Object$entries,_Object$entries$_i,name,userConfiguration,_userDatabaseConnecti,_iterator4,_step4,prefix,subPath,fullPath,url,value,response,changeNeeded,securityConfigurations,_i2,_Object$entries2,_Object$entries2$_i,databaseName,securityObject,fullSecurityObject,_fullSecurityObject$a,_fullSecurityObject$a2,_fullSecurityObject$m,_fullSecurityObject$m2,_response,modelConfiguration,specialNames,idName,revisionName,typeName,models,databaseHelperCode,_iterator5,_step5,_type,code,_i3,_Object$entries3,_Object$entries3$_i,modelName,model,_i4,_Object$entries4,_Object$entries4$_i,_name,specification,_iterator6,_step6,constraint,_iterator7,_step7,type,_constraint,migrators,_iterator8,_step8,file,extension,_name2,documents,_iterator9,_step9,document,_forbidden,_iterator10,_step10,retrievedDocument,_document,newDocument,_iterator11,_step11,_name3,_result,result,genericIndexes,_i5,_Object$entries5,_Object$entries5$_i,_modelName,_model,_iterator12,_step12,propertyName,_name4,foundPosition,position,_iterator13,_step13,index,_iterator14,_step14,_index,exists,_i6,_Object$entries6,_Object$entries6$_i,_modelName2,_model2,_iterator15,_step15,_name5;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function _callee2$(_context2){for(;;)switch(_context2.prev=_context2.next){case 0:if(configuration=_ref3.configuration,services=_ref3.services,clientnode__WEBPACK_IMPORTED_MODULE_3__.globalContext.fetch){_context2.next=3;break}throw new Error("Missing fetch implementation.");case 3:if(promise=null,couchdb=services.couchdb,!Object.prototype.hasOwnProperty.call(couchdb.server,"runner")){_context2.next=12;break}return _context2.next=8,(0,_server__WEBPACK_IMPORTED_MODULE_10__.ni)(services,configuration);case 8:couchdb.server.restart=_server__WEBPACK_IMPORTED_MODULE_10__.S8,couchdb.server.start=_server__WEBPACK_IMPORTED_MODULE_10__.ni,couchdb.server.stop=_server__WEBPACK_IMPORTED_MODULE_10__.ds,promise=new Promise((function(e,t){couchdb.server.resolve=e,couchdb.server.reject=t}));case 12:if(!Object.prototype.hasOwnProperty.call(couchdb,"connection")){_context2.next=14;break}return _context2.abrupt("return",{couchdb:promise});case 14:if(urlPrefix=(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.format)(configuration.couchdb.url,""),authorizationHeader={Authorization:"Basic "+Buffer.from(configuration.couchdb.admin.name+":"+configuration.couchdb.admin.password,"binary").toString("base64")},headers={Accept:"application/json","Content-Type":"application/json"},!configuration.couchdb.ensureAdminPresence){_context2.next=48;break}return unauthenticatedUserDatabaseConnection=new couchdb.connector(urlPrefix+"/_users",(0,_helper__WEBPACK_IMPORTED_MODULE_8__.getConnectorOptions)(configuration)),_context2.prev=19,_context2.next=22,unauthenticatedUserDatabaseConnection.allDocs();case 22:return console.info('No admin user available. Automatically creating admin user "'+configuration.couchdb.admin.name+'".'),_context2.next=25,clientnode__WEBPACK_IMPORTED_MODULE_3__.globalContext.fetch(urlPrefix+"/"+couchdb.server.runner.adminUserConfigurationPath+"/"+configuration.couchdb.admin.name,{body:'"'+configuration.couchdb.admin.password+'"',method:"PUT"});case 25:_context2.next=45;break;case 27:if(_context2.prev=27,_context2.t0=_context2.catch(19),"unauthorized"!==_context2.t0.name){_context2.next=44;break}return authenticatedUserDatabaseConnection=new couchdb.connector(urlPrefix+"/_users",_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({},(0,_helper__WEBPACK_IMPORTED_MODULE_8__.getConnectorOptions)(configuration),{auth:{username:configuration.couchdb.admin.name,password:configuration.couchdb.admin.password}})),_context2.prev=31,_context2.next=34,authenticatedUserDatabaseConnection.allDocs();case 34:_context2.next=39;break;case 36:_context2.prev=36,_context2.t1=_context2.catch(31),console.error("Can't login as existing admin user \""+configuration.couchdb.admin.name+'": '+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(_context2.t1));case 39:return _context2.prev=39,authenticatedUserDatabaseConnection.close(),_context2.finish(39);case 42:_context2.next=45;break;case 44:console.error("Can't create new admin user \""+configuration.couchdb.admin.name+'": '+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(_context2.t0));case 45:return _context2.prev=45,unauthenticatedUserDatabaseConnection.close(),_context2.finish(45);case 48:if(!configuration.couchdb.ensureUserPresence){_context2.next=79;break}userDatabaseConnection=new couchdb.connector(urlPrefix+"/_users",_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({},(0,_helper__WEBPACK_IMPORTED_MODULE_8__.getConnectorOptions)(configuration),{auth:{username:configuration.couchdb.admin.name,password:configuration.couchdb.admin.password}})),_i=0,_Object$entries=Object.entries(configuration.couchdb.users);case 51:if(!(_i<_Object$entries.length)){_context2.next=79;break}return _Object$entries$_i=_Object$entries[_i],name=_Object$entries$_i[0],userConfiguration=_Object$entries$_i[1],_context2.prev=53,_context2.next=56,userDatabaseConnection.get("org.couchdb.user:"+name);case 56:_context2.next=73;break;case 58:if(_context2.prev=58,_context2.t2=_context2.catch(53),"not_found"!==_context2.t2.error){_context2.next=72;break}return console.info('Create missing database user "'+name+'".'),_context2.prev=62,_context2.next=65,userDatabaseConnection.put((_userDatabaseConnecti={},_userDatabaseConnecti[configuration.couchdb.model.property.name.special.id]="org.couchdb.user:"+name,_userDatabaseConnecti.name=name,_userDatabaseConnecti.password=userConfiguration.password,_userDatabaseConnecti.roles=userConfiguration.roles,_userDatabaseConnecti.type="user",_userDatabaseConnecti));case 65:_context2.next=70;break;case 67:throw _context2.prev=67,_context2.t3=_context2.catch(62),new Error("Couldn't create missing user \""+name+'": '+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(_context2.t3));case 70:_context2.next=73;break;case 72:throw new Error("Couldn't check for presence of user \""+name+'": '+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(_context2.t2));case 73:return _context2.prev=73,userDatabaseConnection.close(),_context2.finish(73);case 76:_i++,_context2.next=51;break;case 79:if(!configuration.couchdb.model.updateConfiguration){_context2.next=134;break}_iterator4=_createForOfIteratorHelperLoose(configuration.couchdb.backend.prefixes);case 81:if((_step4=_iterator4()).done){_context2.next=134;break}prefix=_step4.value,_context2.t4=_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().keys(configuration.couchdb.backend.configuration);case 84:if((_context2.t5=_context2.t4()).done){_context2.next=132;break}if(subPath=_context2.t5.value,!Object.prototype.hasOwnProperty.call(configuration.couchdb.backend.configuration,subPath)){_context2.next=130;break}return fullPath="/"+prefix+(prefix.trim()?"/":"")+subPath,url=""+urlPrefix+fullPath,value=configuration.couchdb.backend.configuration[subPath],response=void 0,_context2.prev=91,_context2.next=94,clientnode__WEBPACK_IMPORTED_MODULE_3__.globalContext.fetch(url,{headers:authorizationHeader});case 94:response=_context2.sent,_context2.next=100;break;case 97:_context2.prev=97,_context2.t6=_context2.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)(_context2.t6));case 100:if(!response){_context2.next=130;break}if(!response.ok){_context2.next=129;break}if(changeNeeded=!0,"function"!=typeof response.text){_context2.next=115;break}return _context2.prev=104,_context2.t7=value,_context2.next=108,response["string"==typeof value?"text":"json"]();case 108:_context2.t8=_context2.sent,changeNeeded=_context2.t7===_context2.t8,_context2.next=115;break;case 112:_context2.prev=112,_context2.t9=_context2.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)(_context2.t9));case 115:if(!changeNeeded){_context2.next=126;break}return _context2.prev=116,_context2.next=119,clientnode__WEBPACK_IMPORTED_MODULE_3__.globalContext.fetch(url,{body:'"'+configuration.couchdb.backend.configuration[subPath]+'"',method:"PUT"});case 119:_context2.next=124;break;case 121:_context2.prev=121,_context2.t10=_context2.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)(_context2.t10));case 124:_context2.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:_context2.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 "+String(response.status)+".");case 130:_context2.next=84;break;case 132:_context2.next=81;break;case 134:return _context2.next=136,(0,_helper__WEBPACK_IMPORTED_MODULE_8__.initializeConnection)(services,configuration);case 136:if(!configuration.couchdb.ensureSecuritySettingsPresence){_context2.next=160;break}securityConfigurations=configuration.couchdb.security,_i2=0,_Object$entries2=Object.entries(securityConfigurations);case 139:if(!(_i2<_Object$entries2.length)){_context2.next=160;break}if(_Object$entries2$_i=_Object$entries2[_i2],databaseName=_Object$entries2$_i[0],securityObject=_Object$entries2$_i[1],"_default"!==databaseName){_context2.next=143;break}return _context2.abrupt("continue",157);case 143:return fullSecurityObject=securityObject,"_users"!==databaseName&&(fullSecurityObject.admins||(fullSecurityObject.admins={names:[],roles:[]}),securityConfigurations._default.admins&&(securityConfigurations._default.admins.names&&(fullSecurityObject.admins.names=securityConfigurations._default.admins.names.concat(null!==(_fullSecurityObject$a=fullSecurityObject.admins.names)&&void 0!==_fullSecurityObject$a?_fullSecurityObject$a:[])),securityConfigurations._default.admins.roles&&(fullSecurityObject.admins.roles=securityConfigurations._default.admins.roles.concat(null!==(_fullSecurityObject$a2=fullSecurityObject.admins.roles)&&void 0!==_fullSecurityObject$a2?_fullSecurityObject$a2:[]))),fullSecurityObject.members||(fullSecurityObject.members={names:[],roles:[]}),securityConfigurations._default.members&&(securityConfigurations._default.members.names&&(fullSecurityObject.members.names=securityConfigurations._default.members.names.concat(null!==(_fullSecurityObject$m=fullSecurityObject.members.names)&&void 0!==_fullSecurityObject$m?_fullSecurityObject$m:[])),securityConfigurations._default.members.roles&&(fullSecurityObject.members.roles=securityConfigurations._default.members.roles.concat(null!==(_fullSecurityObject$m2=fullSecurityObject.members.roles)&&void 0!==_fullSecurityObject$m2?_fullSecurityObject$m2:[])))),console.info('Apply security settings for database "'+databaseName+'":',(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(fullSecurityObject)),_context2.prev=146,_context2.next=149,clientnode__WEBPACK_IMPORTED_MODULE_3__.globalContext.fetch(urlPrefix+"/"+databaseName+"/_security",{body:JSON.stringify(fullSecurityObject),headers:_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({},headers,authorizationHeader),method:"PUT"});case 149:if(_response=_context2.sent,_response.ok){_context2.next=152;break}throw new Error(_response.statusText);case 152:_context2.next=157;break;case 154:_context2.prev=154,_context2.t11=_context2.catch(146),console.error('Security object for database "'+databaseName+"\" couldn't be applied:",(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(_context2.t11));case 157:_i2++,_context2.next=139;break;case 160: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_8__.extendModels)(configuration.couchdb.model),!configuration.couchdb.model.updateValidation){_context2.next=229;break}return _context2.next=169,fs__WEBPACK_IMPORTED_MODULE_4__.promises.readFile(eval("require.resolve('./databaseHelper')"),{encoding:configuration.core.encoding,flag:"r"});case 169:databaseHelperCode=_context2.sent,_iterator5=_createForOfIteratorHelperLoose([{description:"Model specification",methodName:"validateDocumentUpdate",name:"validation",serializedParameter:JSON.stringify(modelConfiguration)+", "+JSON.stringify(models)},{description:"Authorisation",methodName:"authenticate",name:"authentication",serializedParameter:JSON.stringify((0,_helper__WEBPACK_IMPORTED_MODULE_8__.determineAllowedModelRolesMapping)(configuration.couchdb.model))+", '"+idName+"', '"+typeName+"', '"+specialNames.designDocumentNamePrefix+"'"}]);case 171:if((_step5=_iterator5()).done){_context2.next=186;break}_type=_step5.value,code="function(...parameters) {\n return require('helper')."+_type.methodName+"(...parameters.concat(["+_type.serializedParameter+"]))\n}",_context2.prev=174,new Function("return "+code),_context2.next=181;break;case 178:throw _context2.prev=178,_context2.t12=_context2.catch(174),new Error("Generated "+_type.name+' code "'+code+"\" doesn't compile: "+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(_context2.t12));case 181:return configuration.core.debug&&console.debug(_type.name+' code: \n\n"'+code+'" integrated.'),_context2.next=184,(0,_helper__WEBPACK_IMPORTED_MODULE_8__.ensureValidationDocumentPresence)(couchdb.connection,_type.name,{helper:databaseHelperCode,validate_doc_update:code},_type.description,!0,idName,revisionName,specialNames.designDocumentNamePrefix);case 184:_context2.next=171;break;case 186:_i3=0,_Object$entries3=Object.entries(models);case 187:if(!(_i3<_Object$entries3.length)){_context2.next=229;break}_Object$entries3$_i=_Object$entries3[_i3],modelName=_Object$entries3$_i[0],model=_Object$entries3$_i[1],_i4=0,_Object$entries4=Object.entries(model);case 190:if(!(_i4<_Object$entries4.length)){_context2.next=226;break}if(_Object$entries4$_i=_Object$entries4[_i4],_name=_Object$entries4$_i[0],specification=_Object$entries4$_i[1],![specialNames.constraint.execution,specialNames.constraint.expression].includes(_name)){_context2.next=208;break}_iterator6=_createForOfIteratorHelperLoose([].concat(specification));case 194:if((_step6=_iterator6()).done){_context2.next=206;break}if(constraint=_step6.value,!constraint.description){_context2.next=204;break}_context2.prev=197,new Function("return "+constraint.description),_context2.next=204;break;case 201:throw _context2.prev=201,_context2.t13=_context2.catch(197),new Error('Specified constraint description "'+constraint.description+'" for model "'+modelName+"\" doesn't compile: "+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(_context2.t13));case 204:_context2.next=194;break;case 206:_context2.next=223;break;case 208:_iterator7=_createForOfIteratorHelperLoose(["conflictingConstraintExpression","conflictingConstraintExecution","constraintExpression","constraintExecution"]);case 209:if((_step7=_iterator7()).done){_context2.next=223;break}if(type=_step7.value,!(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.isObject)(specification)){_context2.next=221;break}if(_constraint=specification[type],null==_constraint||!_constraint.description){_context2.next=221;break}_context2.prev=214,new Function(_constraint.description),_context2.next=221;break;case 218:throw _context2.prev=218,_context2.t14=_context2.catch(214),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)(_context2.t14));case 221:_context2.next=209;break;case 223:_i4++,_context2.next=190;break;case 226:_i3++,_context2.next=187;break;case 229:if(!configuration.couchdb.model.autoMigrationPath){_context2.next=329;break}return migrators={},_context2.next=233,(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.isDirectory)((0,path__WEBPACK_IMPORTED_MODULE_5__.resolve)(configuration.couchdb.model.autoMigrationPath));case 233:if(!_context2.sent){_context2.next=286;break}return _context2.t15=_createForOfIteratorHelperLoose,_context2.next=237,(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 237:_context2.t16=_context2.sent,_iterator8=(0,_context2.t15)(_context2.t16);case 239:if((_step8=_iterator8()).done){_context2.next=286;break}if(file=_step8.value,extension=(0,path__WEBPACK_IMPORTED_MODULE_5__.extname)(file.name),_name2=(0,path__WEBPACK_IMPORTED_MODULE_5__.basename)(file.name,extension),".json"!==extension){_context2.next=276;break}return documents=void 0,_context2.prev=245,_context2.t17=[],_context2.t18=JSON,_context2.next=250,fs__WEBPACK_IMPORTED_MODULE_4__.promises.readFile(file.path,{encoding:configuration.core.encoding,flag:"r"});case 250:_context2.t19=_context2.sent,_context2.t20=_context2.t18.parse.call(_context2.t18,_context2.t19),documents=_context2.t17.concat.call(_context2.t17,_context2.t20),_context2.next=258;break;case 255:throw _context2.prev=255,_context2.t21=_context2.catch(245),new Error('Parsing document "'+file.path+'" to include by automigration of has failed: '+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(_context2.t21));case 258:1===documents.length&&(documents[0][idName]||(documents[0][idName]=_name2),documents[0][revisionName]||(documents[0][revisionName]="0-upsert")),_iterator9=_createForOfIteratorHelperLoose(documents);case 260:if((_step9=_iterator9()).done){_context2.next=274;break}return document=_step9.value,_context2.prev=262,_context2.next=265,couchdb.connection.put(document);case 265:_context2.next=271;break;case 267:throw _context2.prev=267,_context2.t22=_context2.catch(262),null!=(_forbidden=_context2.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)(_context2.t22));case 271:console.info('Including document "'+document[idName]+'" of','type "'+document[typeName]+'" was',"successful.");case 272:_context2.next=260;break;case 274:_context2.next=284;break;case 276:if(![".js"].includes((0,path__WEBPACK_IMPORTED_MODULE_5__.extname)(file.name))){_context2.next=280;break}migrators[file.path]=eval("require('"+file.path+"')").default,_context2.next=284;break;case 280:if(![".mjs"].includes((0,path__WEBPACK_IMPORTED_MODULE_5__.extname)(file.name))){_context2.next=284;break}return _context2.next=283,eval("import('"+file.path+"')");case 283:migrators[file.path]=_context2.sent.default;case 284:_context2.next=239;break;case 286:return _context2.t23=_createForOfIteratorHelperLoose,_context2.next=289,couchdb.connection.allDocs({include_docs:!0});case 289:_context2.t24=_context2.sent.rows,_iterator10=(0,_context2.t23)(_context2.t24);case 291:if((_step10=_iterator10()).done){_context2.next=329;break}if(retrievedDocument=_step10.value,"string"==typeof retrievedDocument.id&&retrievedDocument.id.startsWith(configuration.couchdb.model.property.name.special.designDocumentNamePrefix)){_context2.next=327;break}_document=retrievedDocument.doc,newDocument=(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.copy)(_document),newDocument[configuration.couchdb.model.property.name.special.strategy]="migrate",_iterator11=_createForOfIteratorHelperLoose(Object.keys(migrators).sort());case 298:if((_step11=_iterator11()).done){_context2.next=311;break}_name3=_step11.value,_result=null,_context2.prev=301,_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_9___default(),idName,typeName,migrators,models,modelConfiguration,selfFilePath:_name3,services})),_context2.next=308;break;case 305:throw _context2.prev=305,_context2.t25=_context2.catch(301),new Error('Running migrater "'+_name3+'" in document '+(0,_helper__WEBPACK_IMPORTED_MODULE_8__.mayStripRepresentation)(_document,configuration.couchdb.maximumRepresentationTryLength,configuration.couchdb.maximumRepresentationLength)+'" failed: '+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(_context2.t25));case 308:_result&&(newDocument=_result,console.info('Running migrater "'+_name3+'" for document','"'+newDocument[idName]+'" (of type','"'+newDocument[typeName]+'") was successful.'));case 309:_context2.next=298;break;case 311:if(result=couchdb.validateDocument(newDocument,{checkPublicModelType:!0,oldDocument:_document}),!0===result){_context2.next=318;break}if(!Object.prototype.hasOwnProperty.call(result,"forbidden")){_context2.next=317;break}console.warn('Document "'+(0,_helper__WEBPACK_IMPORTED_MODULE_8__.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)(result)),_context2.next=318;break;case 317:throw result;case 318:return _context2.prev=318,_context2.next=321,couchdb.connection.put(newDocument);case 321:_context2.next=326;break;case 323:throw _context2.prev=323,_context2.t26=_context2.catch(318),new Error('Replacing auto migrated document "'+newDocument[idName]+'" has failed: '+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(_context2.t26));case 326:console.info('Auto migrating document "'+newDocument[idName]+'" was',"successful.");case 327:_context2.next=291;break;case 329:return _context2.next=331,couchdb.connection.getIndexes();case 331:if(genericIndexes=_context2.sent.indexes.filter((function(e){return e.name.endsWith("-GenericIndex")})),!configuration.couchdb.createGenericFlatIndex||!configuration.couchdb.model.autoMigrationPath&&0!==genericIndexes.length){_context2.next=383;break}_i5=0,_Object$entries5=Object.entries(models);case 334:if(!(_i5<_Object$entries5.length)){_context2.next=365;break}if(_Object$entries5$_i=_Object$entries5[_i5],_modelName=_Object$entries5$_i[0],_model=_Object$entries5$_i[1],!new RegExp(configuration.couchdb.model.property.name.typePattern.public).test(_modelName)){_context2.next=362;break}return _context2.next=339,couchdb.connection.createIndex({index:{ddoc:_modelName+"-GenericIndex",fields:[typeName],name:_modelName+"-GenericIndex"}});case 339:_iterator12=_createForOfIteratorHelperLoose((0,_helper__WEBPACK_IMPORTED_MODULE_8__.determineGenericIndexablePropertyNames)(configuration.couchdb.model,_model));case 340:if((_step12=_iterator12()).done){_context2.next=362;break}propertyName=_step12.value,_name4=_modelName+"-"+propertyName+"-GenericIndex",foundPosition=-1,position=0,_iterator13=_createForOfIteratorHelperLoose(genericIndexes);case 346:if((_step13=_iterator13()).done){_context2.next=354;break}if(index=_step13.value,index.name!==_name4){_context2.next=351;break}return foundPosition=position,_context2.abrupt("break",354);case 351:position+=1;case 352:_context2.next=346;break;case 354:if(-1!==foundPosition){_context2.next=359;break}return _context2.next=357,couchdb.connection.createIndex({index:{ddoc:_name4,fields:[typeName,propertyName],name:_name4}});case 357:_context2.next=360;break;case 359:genericIndexes.slice(position,1);case 360:_context2.next=340;break;case 362:_i5++,_context2.next=334;break;case 365:_iterator14=_createForOfIteratorHelperLoose(genericIndexes);case 366:if((_step14=_iterator14()).done){_context2.next=383;break}_index=_step14.value,exists=!1,_i6=0,_Object$entries6=Object.entries(models);case 370:if(!(_i6<_Object$entries6.length)){_context2.next=378;break}if(_Object$entries6$_i=_Object$entries6[_i6],_modelName2=_Object$entries6$_i[0],_model2=_Object$entries6$_i[1],!_index.name.startsWith(_modelName2+"-")){_context2.next=375;break}for(_iterator15=_createForOfIteratorHelperLoose((0,_helper__WEBPACK_IMPORTED_MODULE_8__.determineGenericIndexablePropertyNames)(configuration.couchdb.model,_model2));!(_step15=_iterator15()).done;)_name5=_step15.value,[_modelName2+"-"+_name5+"-GenericIndex",_modelName2+"-GenericIndex"].includes(_index.name)&&(exists=!0);return _context2.abrupt("break",378);case 375:_i6++,_context2.next=370;break;case 378:if(exists){_context2.next=381;break}return _context2.next=381,couchdb.connection.deleteIndex(_index);case 381:_context2.next=366;break;case 383:if(!configuration.couchdb.model.triggerInitialCompaction){_context2.next=392;break}return _context2.prev=384,_context2.next=387,couchdb.connection.compact();case 387:_context2.next=392;break;case 389:_context2.prev=389,_context2.t27=_context2.catch(384),console.warn("Initial database compaction has failed: "+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(_context2.t27));case 392:return _context2.abrupt("return",{couchdb:promise});case 393:case"end":return _context2.stop()}}),_callee2,null,[[19,27,45,48],[31,36,39,42],[53,58,73,76],[62,67],[91,97],[104,112],[116,121],[146,154],[174,178],[197,201],[214,218],[245,255],[262,267],[301,305],[318,323],[384,389]])})));return function(e){return _ref4.apply(this,arguments)}}(),postLoadService=function(e){for(var t=e.configuration.couchdb,n=e.pluginAPI,r=e.services.couchdb,o=0,a=31*t.changesStreamReinitializer.retries,i=0;i<=t.changesStreamReinitializer.retries;i+=1)a+=Math.min(Math.pow(t.changesStreamReinitializer.retryWaitingFactorInSeconds,i),t.changesStreamReinitializer.maxmumRetryWaitingTimeInSeconds);setInterval((function(){o>0&&(console.info("No additional errors (initially got",String(o)+" errors through)","occurred during observing changes stream for",String(a),"seconds. Clearing saved number of errors through."),o=0)}),1e3*a);var c=(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 a(){var i,_;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(a){for(;;)switch(a.prev=a.next){case 0:return r.changesStream&&r.changesStream.cancel(),i=t.changesStream,void 0!==r.lastChangesSequenceIdentifier&&(i.since=r.lastChangesSequenceIdentifier),console.info("Initialize changes stream since",'"'+String(i.since)+'".'),r.changesStream=r.connection.changes(i),r.changesStream.on("error",_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function n(a){var i;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(!((o+=1)>t.changesStreamReinitializer.retries)){n.next=9;break}return console.warn("Observing changes feed throws an error for",String(o)+" times through:",(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(a)+" Restarting database server and","reinitialize changes stream..."),o=0,r.changesStream.cancel(),n.next=7,r.server.restart(e);case 7:n.next=13;break;case 9:return i=Math.min(Math.pow(t.changesStreamReinitializer.retryWaitingFactorInSeconds,o),t.changesStreamReinitializer.maxmumRetryWaitingTimeInSeconds),console.warn("Observing changes feed throws an error for",String(o)+" of",String(t.changesStreamReinitializer.retries),"allowed times through: "+(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.represent)(a),"Reinitializing changes stream in",String(i)+" seconds..."),n.next=13,(0,clientnode__WEBPACK_IMPORTED_MODULE_3__.timeout)(1e3*i);case 13:c();case 14:case"end":return n.stop()}}),n)})))),a.next=8,n.callStack(_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({},e,{data:r.changesStream,hook:"couchdbInitializeChangesStream"}));case 8:console.info("Changes stream initialized."),_=new clientnode__WEBPACK_IMPORTED_MODULE_3__.Semaphore(t.numberOfParallelChangesRunner),r.changesStream.on("change",_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function t(a){return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return o=0,t.prev=1,t.next=4,_.acquire();case 4:return t.next=6,n.callStack(_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({},e,{data:a,hook:"couchdbChange"}));case 6:r.lastChangesSequenceIdentifier=a.seq,t.next=12;break;case 9:t.prev=9,t.t0=t.catch(1),console.error("An error occurred during on change database hook:",t.t0);case 12:return t.prev=12,_.release(),t.finish(12);case 15:case"end":return t.stop()}}),t,null,[[1,9,12,15]])}))));case 11:case"end":return a.stop()}}),a)}))));return t.attachAutoRestarter&&c(),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_10__.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(t){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";var t=[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 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=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},i.apply(null,arguments)}function c(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 _(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)?_(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 _(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,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===i&&(i="-type"),void 0===_&&(_="_design/"),void 0===s&&(s=!1);var d=null!==(l=e[i])&&void 0!==l?l:t&&t[i];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(_)&&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=o[d],g=c(["read","write"]);!(y=g()).done;){var x=y.value;f[x]=f[x].concat(O[x]||[])}f.properties=O.properties}for(var v,E=f[m],P=c(n.roles);!(v=P()).done;){var D=v.value;if(E.includes(D))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,_,s,l){void 0===_&&(_={}),void 0===s&&(s=!0);var u=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)},p=new Date,d=Date.UTC(p.getUTCFullYear(),p.getUTCMonth(),p.getUTCDate(),p.getUTCHours(),p.getUTCMinutes(),p.getUTCSeconds(),p.getUTCMilliseconds())/1e3,m=!a.dateTimeFormat.startsWith("iso"),f=a.property.name.special,b=f.id,h=f.revision,y=f.type;t&&t[y]&&!e[y]&&(e[y]=t[y]);var O="",g="",x=function(){O=Object.prototype.hasOwnProperty.call(e,b)?e[b]:"",g=Object.prototype.hasOwnProperty.call(e,h)?e[h]:""};if(x(),Object.prototype.hasOwnProperty.call(o,a.property.name.validatedDocumentsCache)&&o[a.property.name.validatedDocumentsCache].has(O+"-"+g))return o[a.property.name.validatedDocumentsCache].delete(O+"-"+g),e;["0-latest","0-upsert"].includes(g)&&(t&&Object.prototype.hasOwnProperty.call(t,h)?g=e[h]=t[h]:"0-latest"===g?u("Revision: No old document available to update."):delete e[h]);var v=a.updateStrategy;Object.prototype.hasOwnProperty.call(e,f.strategy)&&(v=e[f.strategy],delete e[f.strategy]);var E,P={};if("migrate"===v)for(var D=0,M=Object.entries(_);D<M.length;D++){var w=M[D],C=w[0],k=w[1];if(Object.prototype.hasOwnProperty.call(k,f.oldType)&&k[f.oldType])for(var T,j=c([].concat(k[f.oldType]));!(T=j()).done;){var A=T.value;P[A]=C}}l?E=l:"undefined"!=typeof JSON&&Object.prototype.hasOwnProperty.call(JSON,"stringify")?E=function(e){return JSON.stringify(e,null,4)}:u('Needed "serializer" is not available.');var I=[f.additional,f.allowedRole,f.constraint.execution,f.constraint.expression,f.create.execution,f.create.expression,f.extend,f.maximumAggregatedSize,f.minimumAggregatedSize,f.oldType,f.update.execution,f.update.expression],S=function(e){return e instanceof Error?String(e):E(e)},R=function(e){return"string"==typeof e?e.trim():""},U=function(e){if(m)null!==e&&"number"!=typeof e&&(e=new Date(e),e=Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate(),e.getUTCHours(),e.getUTCMinutes(),e.getUTCSeconds(),e.getUTCMilliseconds())/1e3);else if(null!==e){e=new Date("number"!=typeof e||isNaN(e)?e:1e3*e);try{e=e.toISOString()}catch(e){}}return e},L=function(e,t,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[f.attachment]),t)for(var r=0,o=Object.keys(n);r<o.length;r++){var a=o[r];if(a.startsWith(t))return a}else{var i=Object.keys(n);if(i.length)return i[0]}return null},B=function(e,t,n){void 0===t&&(t=!1),void 0===n&&(n={});var o=i({},N,{code:""},n),a=R(e);if(a){var c=(t?"return ":"")+a;o.code=c;var _,s=Object.keys(o);try{_=r(Function,s.concat([c]))}catch(e){u(S(e),"compilation",{code:c,error:e,scope:o})}var l={code:c,result:void 0,scope:o};try{l.result=_.apply(void 0,s.map((function(e){return o[e]})))}catch(e){u(S(e),"runtime",{code:c,error:e,scope:o})}return l}return u("No expression to evaluate provided.","empty"),{code:o.code,result:void 0,scope:o}},K=function(e,t,n,o){void 0===n&&(n=[]),void 0===o&&(o=!1);var i=n.length?" in "+n.join(" -> "):"",l=[],p=function(){Object.prototype.hasOwnProperty.call(e,y)||(t&&Object.prototype.hasOwnProperty.call(t,y)&&["fillUp","migrate"].includes(v)?e[y]=t[y]:u('Type: You have to specify a model type via property "'+y+'"'+i+".")),!s||n.length||new RegExp(a.property.name.typePattern.public).test(e[y])||u('TypeName: You have to specify a model type which matches "'+a.property.name.typePattern.public+'" as public type (given "'+e[y]+'")'+i+"."),Object.prototype.hasOwnProperty.call(_,e[y])||(Object.prototype.hasOwnProperty.call(P,e[y])?e[y]=P[e[y]]:u('Model: Given model "'+e[y]+'" is not specified'+i+"."))};p();var d=e[y],O=_[d],g=void 0;Object.prototype.hasOwnProperty.call(O,f.additional)&&O[f.additional]&&(g=O[f.additional]);var E=function(o,a,_,s,l){void 0===l&&(l=["constraintExecution","constraintExpression"]);for(var p,m=c(l);!(p=m()).done;){var f=p.value;if(Object.prototype.hasOwnProperty.call(_,f)){var b=void 0;try{b=B(_[f].evaluation,f.endsWith("Expression"),{checkPropertyContent:D,model:O,modelName:d,name:a,type:f,newDocument:e,newValue:o,oldDocument:t,oldValue:s,parentNames:n,pathDescription:i,propertySpecification:_})}catch(e){var h,y;if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&u('Compilation: Hook "'+f+'" has invalid code "'+e.code+'": "'+(null!==(h=e.message)&&void 0!==h?h:"unknown")+'"'+i+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&u('Runtime: Hook "'+f+'" has throw an error with code "'+e.code+'": "'+(null!==(y=e.message)&&void 0!==y?y:"unknown")+'"'+i+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}if(b&&!b.result){var g,x=R(null==(g=_[f])?void 0:g.description);u(f.charAt(0).toUpperCase()+(f.substring(1)+": ")+(x?r(Function,Object.keys(b.scope).concat(["return "+x])).apply(void 0,Object.values(b.scope)):'Property "'+String(a)+'" should satisfy constraint "'+b.code+'" (given "'+S(o)+'")'+i+"."))}}}},D=function(e,t,r,o,a){void 0===a&&(a=!1);var s=[],l=[].concat(r.type?r.type:[]);"object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype&&!Object.prototype.hasOwnProperty.call(e,y)&&1===l.length&&"string"==typeof l[0]&&Object.prototype.hasOwnProperty.call(_,l[0])&&(e[y]=l[0]);for(var p,d=!1,f=c(l);!(p=f()).done;){var h=p.value;if("string"==typeof h&&Object.prototype.hasOwnProperty.call(_,h)){if("object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype&&Object.prototype.hasOwnProperty.call(e,y)&&e[y]!==h&&"migrate"===v&&1===l.length&&(e[y]=h,s=n.concat(String(t),"migrate nested object type")),"object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype&&Object.prototype.hasOwnProperty.call(e,y)&&e[y]===h){var O=K(e,o,n.concat(String(t)),a||r.computed);if(O.changedPath.length&&(s=O.changedPath),e=O.newDocument,S(e)===S({}))return{newValue:void 0,changedPath:s};d=!0;break}1===l.length&&u('NestedType: Under key "'+String(t)+'" isn\'t of type "'+h+'" (given "'+S(e)+'" of type '+typeof e+")"+i+".")}else if("DateTime"===h){var g=e;if(e=U(e),!(m&&("number"!=typeof e||isNaN(e))||!m&&"string"!=typeof e)){d=!0;break}1===l.length&&u('PropertyType: Property "'+String(t)+'" isn\'t of (valid) type "DateTime" (given"'+S(g).replace(/^"/,"").replace(/"$/,"")+'" of type "'+typeof g+'")'+i+".")}else if("string"==typeof h&&["boolean","integer","number","string"].includes(h)){if(!("number"==typeof e&&isNaN(e)||"integer"!==h&&typeof e!==h||"integer"===h&&parseInt(e,10)!==e)){d=!0;break}1===l.length&&u('PropertyType: Property "'+String(t)+'" isn\'t of (valid) type "'+h+'" (given "'+S(e)+'" of type "'+typeof e+'")'+i+".")}else if("string"==typeof h&&h.startsWith("foreignKey:")){var x=_[h.substring(11)][b].type;if(x===typeof e){d=!0;break}1===l.length&&u('PropertyType: Foreign key property "'+String(t)+'" isn\'t of type "'+x+'" (given "'+S(e)+'" of type "'+typeof e+'")'+i+".")}else{if("any"===h||S(e)===S(h)){d=!0;break}1===l.length&&u('PropertyType: Property "'+String(t)+'" isn\'t value "'+String(h)+'" (given "'+S(e).replace(/^"/,"").replace(/"$/,"")+'" of type "'+typeof e+'")'+i+".")}}if(d||u('PropertyType: None of the specified types "'+l.join('", "')+'" for property "'+String(t)+'" matches value "'+S(e).replace(/^"/,"").replace(/"$/,"")+e+'" of type "'+typeof e+'"'+i+"."),"string"==typeof e&&("number"==typeof r.minimumLength&&e.length<r.minimumLength&&u('MinimalLength: Property "'+String(t)+'" must have minimal length '+r.minimumLength+" (given "+e+" with length "+String(e.length)+")"+i+"."),"number"==typeof r.maximumLength&&e.length>r.maximumLength&&u('MaximalLength: Property "'+String(t)+'" must have maximal length '+r.maximumLength+" (given "+e+" with length "+String(e.length)+")"+i+".")),"number"==typeof e&&("number"==typeof r.minimum&&e<r.minimum&&u('Minimum: Property "'+String(t)+'" (type '+r.type+") must satisfy a minimum of "+r.minimum+" (given "+String(e)+" is too low)"+i+"."),"number"==typeof r.maximum&&e>r.maximum&&u('Maximum: Property "'+String(t)+'" (type '+r.type+") must satisfy a maximum of "+r.maximum+" (given "+String(e)+" is too high)"+i+".")),r.selection){var P=Array.isArray(r.selection)?r.selection.map((function(e){return void 0===(null==e?void 0:e.value)?e:e.value})):Object.keys(r.selection);"DateTime"===r.type&&(P=P.map(U)),P.includes(e)||u('Selection: Property "'+String(t)+'" (type '+r.type+') should be one of "'+P.join('", "')+'". But is "'+e+'"'+i+".")}if(r.pattern){for(var D,M=[].concat(r.pattern),w=!1,C=c(M);!(D=C()).done;){var k=D.value;if(new RegExp(k).test(e)){w=!0;break}}w||u('PatternMatch: Property "'+String(t)+'" should match regular expression pattern "'+M.join('", "')+'" (given "'+e+'")'+i+".")}if(r.invertedPattern)for(var T,j=c([].concat(r.invertedPattern));!(T=j()).done;){var A=T.value;new RegExp(A).test(e)&&u('InvertedPatternMatch: Property "'+String(t)+'" should not match regular expression pattern '+String(A)+' (given "'+e+'")'+i+".")}return E(e,t,r,o),S(e)!==S(o)&&(s=n.concat(String(t),"value updated")),{newValue:e,changedPath:s}},M=function(e,t,r,o,i){var c=t[o];if(!e.writable)if(r){if(Object.prototype.hasOwnProperty.call(r,o)&&S(c)===S(r[o]))return o!==b&&"incremental"===v&&delete t[o],!0;u("Readonly: Property "+String(o)+'" isnot writable (old document "'+S(r)+'")'+i+".")}else u('Readonly: Property "'+String(o)+'" is not writable'+i+".");if(!e.mutable&&r&&Object.prototype.hasOwnProperty.call(r,o)){if(S(c)===S(r[o]))return"incremental"!==v||a.property.name.reserved.concat(f.deleted,b,h).includes(String(o))||delete t[o],!0;"migrate"!==v&&u('Immutable: Property "'+String(o)+'"is not writable (old document "'+S(r)+'")'+i+".")}if(null===c){if(e.nullable)return"incremental"===v&&r&&void 0!==r[o]||delete t[o],r&&Object.prototype.hasOwnProperty.call(r,o)&&(l=n.concat(String(o),"delete property")),!0;u('NotNull: Property "'+String(o)+'" should not be "null"'+i+".")}return!1},w=function(e,t,r,o,a){if(!r)for(var _,s=c(["onCreateExecution","onCreateExpression"]);!(_=s()).done;){var l=_.value;if(Object.prototype.hasOwnProperty.call(e,l)){var p=void 0;try{p=B(e[l],l.endsWith("Expression"),{attachmentsTarget:a,checkPropertyContent:D,model:O,modelName:d,name:String(o),type:l,newDocument:t,oldDocument:r,newValue:void 0,oldValue:void 0,parentNames:n,pathDescription:i,propertySpecification:e})}catch(e){var m,f;if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&u('Compilation: Hook "'+l+'" has invalid code "'+e.code+'" for property "'+String(o)+'": "'+(null!==(m=e.message)&&void 0!==m?m:"unknown")+'"'+i+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&u('Runtime: Hook "'+l+'" has throw an error with code "'+e.code+'" for property "'+String(o)+'": "'+(null!==(f=e.message)&&void 0!==f?f:"unknown")+'"'+i+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}p&&![null,void 0].includes(p.result)&&(a?a[o]=p.result:t[o]=p.result)}}},C=function(e,t,r,o,a){if(!a){if(!Object.prototype.hasOwnProperty.call(t,o))return;e.trim&&"string"==typeof t[o]&&(t[o]=t[o].trim()),e.emptyEqualsNull&&(""===t[o]||Array.isArray(t[o])&&0===t[o].length||null!==t[o]&&"object"==typeof t[o]&&0===Object.keys(t).length)&&(t[o]=null)}for(var _,s=c(["onUpdateExecution","onUpdateExpression"]);!(_=s()).done;){var l=_.value;if(Object.prototype.hasOwnProperty.call(e,l))try{var p=B(e[l],l.endsWith("Expression"),{attachmentsTarget:a,checkPropertyContent:D,model:O,modelName:d,name:String(o),type:l,newDocument:t,oldDocument:r,newValue:t[o],oldValue:r&&r[o]||void 0,parentNames:n,pathDescription:i,propertySpecification:e});a?a[o]=p.result:void 0!==p.result&&(t[o]=p.result)}catch(e){var m,f;if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&u('Compilation: Hook "'+l+'" has invalid code "'+e.code+'" for property "'+String(o)+'": "'+(null!==(m=e.message)&&void 0!==m?m:"unknown")+'"'+i+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&u('Runtime: Hook "'+l+'" has throw an error with code "'+e.code+'" for property "'+String(o)+'": "'+(null!==(f=e.message)&&void 0!==f?f:"unknown")+'"'+i+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}}},k=Object.keys(O).filter((function(e){return!I.includes(e)}));if("migrate"===v)for(var T,j=c(k);!(T=j()).done;){var A=T.value;if(O[A].oldName)for(var W,N=c([].concat(O[A].oldName));!(W=N()).done;){var $=W.value;Object.prototype.hasOwnProperty.call(e,$)&&(e[A]=e[$],delete e[$])}}if(!t)for(var q=0,z=[f.create.execution,f.create.expression];q<z.length;q++){var F=z[q];if(Object.prototype.hasOwnProperty.call(O,F)){var H=void 0;try{H=B(O[F],F.endsWith("Expression"),{checkPropertyContent:D,model:O,modelName:d,type:F,newDocument:e,oldDocument:t,parentNames:n,pathDescription:i}).result}catch(e){var G,V;if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&u('Compilation: Hook "'+F+'" has invalid code "'+e.code+'" for document "'+d+'": "'+(null!==(G=e.message)&&void 0!==G?G:"unknown")+'"'+i+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&u('Runtime: Hook "'+F+'" has throw an error with code "'+e.code+'" for document "'+d+'": "'+(null!==(V=e.message)&&void 0!==V?V:"unknown")+'"'+i+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}[null,void 0].includes(H)||(e=H),p(),d=e[y],0===n.length&&x()}}for(var J=0,Y=[f.update.execution,f.update.expression];J<Y.length;J++){var X=Y[J];if(Object.prototype.hasOwnProperty.call(O,X)){var Z=void 0;try{Z=B(O[X],X.endsWith("Expression"),{checkPropertyContent:D,model:O,modelName:d,type:X,newDocument:e,oldDocument:t,parentNames:n,pathDescription:i}).result}catch(e){var Q,ee;if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&u('Compilation: Hook "'+X+'" has invalid code "'+e.code+'" for document "'+d+'": "'+(null!==(Q=e.message)&&void 0!==Q?Q:"unknown")+'"'+i+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&u('Runtime: Hook "'+X+'" has throw an error with code "'+e.code+'" for document "'+d+'": "'+(null!==(ee=e.message)&&void 0!==ee?ee:"unknown")+'"'+i+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}[void 0,null].includes(Z)||(e=Z),p(),d=e[y],0===n.length&&x()}}for(var te,ne=g?Object.keys(e).filter((function(e){return!k.includes(e)})):[],re=c(k.concat(ne));!(te=re()).done;){var oe=te.value;if(f.attachment===oe)for(var ae=function(){var r=ce[ie],o=r[0],a=r[1];e[f.attachment]||(e[f.attachment]={}),t&&!Object.prototype.hasOwnProperty.call(t,oe)&&(t[f.attachment]={});var _=e[f.attachment],s=Object.keys(_).filter((function(e){return null!==_[e].data&&L(o,e,a)})),p=[];if(t){var d=t[oe];p=Object.keys(d).filter((function(e){return!(Object.prototype.hasOwnProperty.call(_,e)&&Object.prototype.hasOwnProperty.call(_[e],"data")&&null===_[e].data)&&Boolean(d[e])&&(Object.prototype.hasOwnProperty.call(d[e],"data")&&null!==d[e].data||Object.prototype.hasOwnProperty.call(d[e],"stub")&&Boolean(d[e].digest))&&Boolean(L(o,e,a))}))}for(var m,b=a,h=c(s);!(m=h()).done;){var y=m.value;w(b,e,t&&t[oe]?t[oe]:null,y,_)}for(var O,g=c(s);!(O=g()).done;){var x=O.value;C(b,e,t&&t[oe]?t[oe]:null,x,_)}if(void 0===b.default){if(b.nullable||s.length>0||p.length>0||u('AttachmentMissing: Missing attachment for type "'+o+'"'+i+"."),"fillUp"===v&&0===s.length&&p.length>0)for(var E,P=c(p);!(E=P()).done;){var D=E.value;null===_[D]?l=n.concat(oe,D,"file removed"):_[D]=t[oe][D]}}else if(0===s.length)if(0===p.length)for(var M in b.default)Object.prototype.hasOwnProperty.call(b.default,M)&&(_[M]=b.default[M],l=n.concat(oe,o,"add default file"));else if("fillUp"===v)for(var k,T=c(p);!(k=T()).done;){var j=k.value;_[j]=t[oe][j]}},ie=0,ce=Object.entries(O[f.attachment]);ie<ce.length;ie++)ae();else{var _e=k.includes(oe)?O[oe]:g;w(_e,e,t,oe),C(_e,e,t,oe),[null,void 0].includes(_e.default)?(_e.nullable||Object.prototype.hasOwnProperty.call(e,oe)&&void 0!==e[oe]||t&&Object.prototype.hasOwnProperty.call(t,oe)&&"replace"!==v||u('MissingProperty: Missing property "'+String(oe)+'"'+i+"."),o||_e.computed||Object.prototype.hasOwnProperty.call(e,oe)&&void 0!==e[oe]||!t||!Object.prototype.hasOwnProperty.call(t,oe)||("fillUp"===v?e[oe]=t[oe]:"replace"===v&&(l=n.concat(String(oe),"property removed")))):Object.prototype.hasOwnProperty.call(e,oe)&&![null,void 0].includes(e[oe])||(t?o||_e.computed||null===e[oe]||"fillUp"!==v?"migrate"===v&&(e[oe]=_e.default,l=n.concat(String(oe),"migrate default value")):e[oe]=t[oe]:(e[oe]=_e.default,l=l.concat(String(oe),"add default value")))}}if(t&&"incremental"===v)for(var se=0,le=Object.entries(e);se<le.length;se++){var ue=le[se],pe=ue[0],de=ue[1];!Object.prototype.hasOwnProperty.call(t,pe)||a.property.name.reserved.concat(b,h,f.conflict,f.deleted,f.deletedConflict,f.localSequence,f.revisions,f.revisionsInformation,y).includes(pe)||t[pe]!==de&&S(t[pe])!==S(de)||delete e[pe]}for(var me=0,fe=Object.entries(e);me<fe.length;me++){var be=fe[me],he=be[0],ye=be[1];if(!a.property.name.reserved.concat(h,f.conflict,f.deleted,f.deletedConflict,f.localSequence,f.revisions,f.revisionsInformation,f.strategy).includes(he)){var Oe=void 0;if(Object.prototype.hasOwnProperty.call(O,he))Oe=O[he];else if(g)Oe=g;else{if("migrate"===v){delete e[he],l=n.concat(String(he),"migrate removed property");continue}u('Property: Given property "'+String(he)+'" isn\'t specified in model "'+d+'"'+i+".")}if(!Oe)continue;if(f.attachment===he){var ge=ye;for(var xe in ge)if(Object.prototype.hasOwnProperty.call(ge,xe))for(var ve=0,Ee=Object.keys(O[he]);ve<Ee.length;ve++){var Pe=Ee[ve],De=O[f.attachment][Pe];if(L(Pe,xe,De)){M(De,e,t,xe,i);break}}continue}if(M(Oe,e,t,he,i))continue;var Me="string"==typeof Oe.type&&Oe.type.endsWith("[]")||Array.isArray(Oe.type)&&Oe.type.length&&Array.isArray(Oe.type[0]);if(Me&&![null,void 0].includes(ye)){var we=ye;Array.isArray(we)?"number"==typeof Oe.minimumNumber&&we.length<Oe.minimumNumber?u('MinimumArrayLength: Property "'+String(he)+'" (array of length '+String(we.length)+") doesn't fulfill minimum array length of "+Oe.minimumNumber+i+"."):"number"==typeof Oe.maximumNumber&&Oe.maximumNumber<we.length&&u('MaximumArrayLength: Property "'+String(he)+'" (array of length '+String(we.length)+") doesn't fulfill maximum array length of "+Oe.maximumNumber+i+"."):u('PropertyType: Property "'+String(he)+'" isn\'t of type "array -> '+Oe.type+'" (given"'+S(we)+'")'+i+"."),E(we,String(he),Oe,t&&Object.prototype.hasOwnProperty.call(t,he)&&t[he]||void 0,["arrayConstraintExecution","arrayConstraintExpression"]);var Ce={};for(var ke in Oe)if(Object.prototype.hasOwnProperty.call(Oe,ke))if("type"===ke){var Te=Oe[ke];Array.isArray(Oe[ke])?Ce[ke]=Te[0]:Ce[ke]=[Te.substring(0,Te.length-2)]}else Ce[ke]=Oe[ke];if(Array.isArray(Ce.type)&&1===Ce.type.length&&"string"==typeof Ce.type[0]&&Object.prototype.hasOwnProperty.call(_,Ce.type[0]))for(var je,Ae=c(we.slice());!(je=Ae()).done;){var Ie=je.value;"object"!=typeof Ie||Object.getPrototypeOf(Ie)!==Object.prototype||Object.prototype.hasOwnProperty.call(Ie,y)||(Ie[y]=Ce.type[0])}for(var Se,Re=0,Ue=c(we.slice());!(Se=Ue()).done;){var Le=Se.value;we[Re]=D(Le,String(Re+1)+". value in "+String(he),Ce,void 0,o||Ce.computed).newValue,[null,void 0].includes(we[Re])&&we.splice(Re,1),Re+=1}t&&Object.prototype.hasOwnProperty.call(t,he)&&Array.isArray(t[he])&&t[he].length===we.length&&S(t[he])===S(we)||(l=n.concat(String(he),"array updated"))}else{var We=t&&Object.prototype.hasOwnProperty.call(t,he)?t[he]:void 0,Be=Me?{newValue:null,changedPath:[]}:D(ye,String(he),Oe,We,o||Oe.computed);e[he]=Be.newValue,Be.changedPath.length&&(l=Be.changedPath),null===e[he]&&(void 0===We?"fillUp"===v&&delete e[he]:l=n.concat(String(he),"property removed")),void 0===e[he]&&"incremental"===v&&delete e[he]}}}for(var Ke=0,Ne=Object.keys(f.constraint);Ke<Ne.length;Ke++){var $e=Ne[Ke],qe=f.constraint[$e];if(Object.prototype.hasOwnProperty.call(O,qe))for(var ze,Fe=O[qe],He=c([].concat(Fe));!(ze=He()).done;){var Ge=ze.value,Ve=void 0;try{Ve=B(Ge.evaluation,qe===f.constraint.expression,{checkPropertyContent:D,model:O,modelName:d,type:qe,newDocument:e,oldDocument:t,parentNames:n,pathDescription:i})}catch(e){var Je,Ye;if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&u('Compilation: Hook "'+qe+'" has invalid code "'+e.code+'": "'+(null!==(Je=e.message)&&void 0!==Je?Je:"unknown")+'"'+i+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&u('Runtime: Hook "'+qe+'" has thrown an error with code "'+e.code+'": "'+(null!==(Ye=e.message)&&void 0!==Ye?Ye:"unknown")+'"'+i+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}if(Ve&&!Ve.result){var Xe=qe.replace(/^[^a-zA-Z]+/,"");u(Xe.charAt(0).toUpperCase()+(Xe.substring(1)+": ")+(Ge.description?r(Function,Object.keys(Ve.scope).concat(["return "+Ge.description.trim()])).apply(void 0,Object.values(Ve.scope)):'Model "'+d+'" should satisfy constraint "'+Ve.code+'" (given "'+S(e)+'")'+i+"."))}}}if(Object.prototype.hasOwnProperty.call(e,f.attachment)){var Ze,Qe,et=e[f.attachment];"object"==typeof et&&Object.getPrototypeOf(et)===Object.prototype||u("AttachmentType: given attachment has invalid type"+i+".");var tt=null;if(t&&Object.prototype.hasOwnProperty.call(t,f.attachment)&&null!==(tt=t[f.attachment])&&"object"==typeof tt)for(var nt=0,rt=Object.entries(tt);nt<rt.length;nt++){var ot=rt[nt],at=ot[0],it=ot[1];if(it&&Object.prototype.hasOwnProperty.call(et,at)){var ct=et[at];null===ct||null===ct.data||ct.content_type===it.content_type&&(ct.data===it.data||ct.digest===it.digest)?(null!==ct&&null!==ct.data||(l=n.concat(f.attachment,at,"attachment removed")),"incremental"===v&&delete et[at]):l=n.concat(f.attachment,at,"attachment updated")}else"fillUp"===v?et[at]=it:"replace"===v&&(l=n.concat(f.attachment,at,"attachment removed"))}for(var _t=0,st=Object.entries(et);_t<st.length;_t++){var lt,ut=st[_t],pt=ut[0],dt=ut[1];if(!dt)break;null===dt.data?delete et[pt]:tt&&Object.prototype.hasOwnProperty.call(tt,pt)&&dt.content_type===(null==(lt=tt[pt])?void 0:lt.content_type)&&(dt.data===tt[pt].data||dt.digest===tt[pt].digest)||(l=n.concat(f.attachment,pt,"attachment updated"))}0===Object.keys(et).length&&delete e[f.attachment];for(var mt=O[f.attachment],ft={},bt=0,ht=Object.keys(mt);bt<ht.length;bt++)ft[ht[bt]]=[];for(var yt=0,Ot=Object.keys(et);yt<Ot.length;yt++){for(var gt=Ot[yt],xt=!1,vt=0,Et=Object.entries(mt);vt<Et.length;vt++){var Pt=Et[vt],Dt=Pt[0],Mt=Pt[1];if(L(Dt,gt,Mt)){ft[Dt].push(gt),xt=!0;break}}xt||u('AttachmentTypeMatch: None of the specified attachment types ("'+Object.keys(mt).join('", "')+'") matches given one ("'+gt+'")'+i+".")}for(var wt=0,Ct=0,kt=Object.keys(ft);Ct<kt.length;Ct++){var Tt=kt[Ct],jt=mt[Tt];if(Object.prototype.hasOwnProperty.call(ft,Tt)){var At=ft[Tt].length;"number"==typeof jt.maximumNumber&&At>jt.maximumNumber&&u("AttachmentMaximum: given number of attachments ("+String(At)+") doesn't satisfy specified maximum of "+String(jt.maximumNumber)+' from type "'+Tt+'"'+i+"."),(!jt.nullable||0!==At)&&"number"==typeof jt.minimumNumber&&At<jt.minimumNumber&&u("AttachmentMinimum: given number of attachments ("+String(At)+") doesn't satisfy specified minimum of "+String(jt.minimumNumber)+' from type "'+Tt+'"'+i+".");for(var It,St=0,Rt=c(ft[Tt]);!(It=Rt()).done;){var Ut,Lt,Wt,Bt=It.value;if(null!=(Ut=jt.fileName)&&Ut.pattern){for(var Kt,Nt=[].concat(jt.fileName.pattern),$t=!1,qt=c(Nt);!(Kt=qt()).done;){var zt=Kt.value;if(new RegExp(zt).test(Bt)){$t=!0;break}}$t||u('AttachmentName: given attachment name "'+Bt+'" doesn\'t satisfy one of specified regular expression patterns "'+Nt.join('", "')+'" from type "'+Tt+'"'+i+".")}if(null!=(Lt=jt.fileName)&&Lt.invertedPattern)for(var Ft,Ht=c([].concat(jt.fileName.invertedPattern));!(Ft=Ht()).done;){var Gt=Ft.value;new RegExp(Gt).test(Bt)&&u('InvertedAttachmentName: given attachment name "'+Bt+'" does satisfy specified regular expression pattern "'+Gt.toString()+'" from type "'+Tt+'"'+i+".")}if(null!=(Wt=et[Bt])&&Wt.content_type){if(jt.contentTypePattern){for(var Vt,Jt=[].concat(jt.contentTypePattern),Yt=!1,Xt=c(Jt);!(Vt=Xt()).done;){var Zt=Vt.value;if(new RegExp(Zt).test(et[Bt].content_type)){Yt=!0;break}}Yt||u('AttachmentContentType: given attachment content type "'+et[Bt].content_type+'" doesn\'t satisfy specified regular expression pattern "'+Jt.join('", "')+'" from type "'+Tt+'"'+i+".")}var Qt=jt.invertedContentTypePattern;if(Qt)for(var en,tn=c([].concat(Qt));!(en=tn()).done;){var nn=en.value;new RegExp(nn).test(et[Bt].content_type)&&u('InvertedAttachmentContentType: given attachment content type "'+et[Bt].content_type+'" does satisfy specified regular expression pattern "'+nn.toString()+'" from type "'+Tt+'"'+i+".")}}var rn=0;et[Bt]&&"length"in et[Bt]?rn=et[Bt].length:et[Bt]&&"data"in et[Bt]&&(rn="undefined"!=typeof Buffer&&"byteLength"in Buffer?Buffer.byteLength(et[Bt].data,"base64"):et[Bt].data.length),"number"==typeof jt.minimumSize&&jt.minimumSize>rn?u("AttachmentMinimumSize: given attachment size "+String(rn)+" byte doesn't satisfy specified minimum of "+String(jt.minimumSize)+" byte "+i+"."):"number"==typeof jt.maximumSize&&jt.maximumSize<rn&&u("AttachmentMaximumSize: given attachment size "+String(rn)+" byte doesn't satisfy specified maximum of "+String(jt.maximumSize)+" byte "+i+"."),St+=rn}"number"==typeof jt.minimumAggregatedSize&&jt.minimumAggregatedSize>St?u('AttachmentAggregatedMinimumSize: given aggregated size of attachments from type "'+Tt+'" '+String(St)+" byte doesn't satisfy specified minimum of "+String(jt.minimumAggregatedSize)+" byte "+i+"."):"number"==typeof jt.maximumAggregatedSize&&jt.maximumAggregatedSize<St&&u('AttachmentAggregatedMaximumSize: given aggregated size of attachments from type "'+Tt+'" '+String(St)+" byte doesn't satisfy specified maximum of "+String(jt.maximumAggregatedSize)+" byte "+i+"."),wt+=St}}(null!==(Ze=O[f.minimumAggregatedSize])&&void 0!==Ze?Ze:0)>wt?u("AggregatedMinimumSize: given aggregated size "+String(wt)+" byte doesn't satisfy specified minimum of "+String(O[f.minimumAggregatedSize])+" byte "+i+"."):(null!==(Qe=O[f.maximumAggregatedSize])&&void 0!==Qe?Qe:1/0)<wt&&u("AggregatedMaximumSize: given aggregated size "+String(wt)+" byte doesn't satisfy specified maximum of "+String(O[f.maximumAggregatedSize])+" byte "+i+".")}if(t&&Object.prototype.hasOwnProperty.call(t,f.attachment)&&0===Object.keys(t[f.attachment]).length&&delete t[f.attachment],0===l.length&&t&&"migrate"===v)for(var on=0,an=Object.keys(t);on<an.length;on++){var cn=an[on];Object.prototype.hasOwnProperty.call(e,cn)||(l=n.concat(cn,"migrate removed property"))}return{changedPath:l,newDocument:e}},N={attachmentWithPrefixExists:function(t){if(Object.prototype.hasOwnProperty.call(e,f.attachment)){var n=e[f.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:S,id:O,revision:g,idName:b,revisionName:h,specialNames:f,typeName:y,modelConfiguration:a,models:_,now:p,nowUTCTimestamp:d,securitySettings:o,updateStrategy:v,userContext:n},$=e[f.attachment];if(e[f.attachment])for(var q=0,z=Object.values($);q<z.length;q++){var F=z[q];null!=F&&F.contentType&&(F.content_type=F.contentType,delete F.contentType)}var H=K(e,t);return(H.newDocument._deleted&&!t||!(H.newDocument._deleted&&H.newDocument._deleted!==(null==t?void 0:t._deleted)||H.changedPath.length))&&u("NoChange: No new data given. new document: "+S(e)+"; old document: "+S(t)+"."),Object.prototype.hasOwnProperty.call(o,a.property.name.validatedDocumentsCache)?o[a.property.name.validatedDocumentsCache].add(O+"-"+g):o[a.property.name.validatedDocumentsCache]=new Set([O+"-"+g]),H.newDocument},u=e.exports,p=u}],n={};function r(e){var o=n[e];if(void 0!==o)return o.exports;var a=n[e]={id:e,loaded:!1,exports:{}};return t[e](a,a.exports,r),a.loaded=!0,a.exports}r.d=function(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.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},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o=r(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 _callee$(_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(e,t){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,i,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,i=a.resolve,c=a.reject,a.resolve=a.reject=clientnode__WEBPACK_IMPORTED_MODULE_4__.NOOP,e.next=7,stop(o,n);case 7:return a.resolve=i,a.reject=c,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(t){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.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(t,n){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.721",
3
+ "version": "1.0.722",
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",