couchdb-web-node-plugin 1.0.526 → 1.0.527

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.
package/index.d.ts CHANGED
@@ -3,19 +3,11 @@ import { ServicesState, State } from './type';
3
3
  /**
4
4
  * Launches an application server und triggers all some pluginable hooks on
5
5
  * an event.
6
- * TODO move to configuration.
7
- * @property static:additionalChangesStreamOptions - Can provide additional
8
- * (non static) changes stream options.
9
- * @property static:skipIDDetermining - Indicates whether id's should be
10
- * determined if "bulkDocs" had skipped a real change due to ignore a
11
- * "NoChange" error.
12
- * @property static:toggleIDDetermining - Token to give a "bulkDocs" method
13
- * call to indicate id determination skip or not (depends on the static
6
+ * @property static:toggleIDDetermining - Token to provide to "bulkDocs" method
7
+ * call to indicate id determination skip or not (depends on
14
8
  * "skipIDDetermining" configuration).
15
9
  */
16
10
  export declare class Database implements PluginHandler {
17
- static additionalChangesStreamOptions: object;
18
- static skipIDDetermining: boolean;
19
11
  static toggleIDDetermining: symbol;
20
12
  /**
21
13
  * Appends an application server to the web node services.
package/index.js CHANGED
@@ -1 +1 @@
1
- (()=>{var __webpack_modules__=[e=>{"use strict";e.exports=require("@babel/runtime/helpers/extends")},e=>{"use strict";e.exports=require("@babel/runtime/helpers/asyncToGenerator")},e=>{"use strict";e.exports=require("@babel/runtime/regenerator")},e=>{"use strict";e.exports=require("child_process")},e=>{"use strict";e.exports=require("clientnode")},e=>{"use strict";e.exports=require("pouchdb/node_modules/node-fetch/lib/index.js")},e=>{"use strict";e.exports=require("fs")},e=>{"use strict";e.exports=require("path")},(__unused_webpack_module,__webpack_exports__,__webpack_require__)=>{"use strict";__webpack_require__.d(__webpack_exports__,{default:()=>__WEBPACK_DEFAULT_EXPORT__});var _babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__(0),_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default=__webpack_require__.n(_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__),_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1__=__webpack_require__(1),_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default=__webpack_require__.n(_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1__),_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2__=__webpack_require__(2),_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default=__webpack_require__.n(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2__),child_process__WEBPACK_IMPORTED_MODULE_3__=__webpack_require__(3),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__(5),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__);function _createForOfIteratorHelperLoose(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=_unsupportedIterableToArray(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(e,t){if(e){if("string"==typeof e)return _arrayLikeToArray(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?_arrayLikeToArray(e,t):void 0}}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}clientnode__WEBPACK_IMPORTED_MODULE_4__.globalContext.fetch=node_fetch__WEBPACK_IMPORTED_MODULE_5___default();var Helper=function(){function Helper(){}return Helper.getConnectorOptions=function(e){return e.couchdb.connector.fetch?{fetch:function(t,r){return clientnode__WEBPACK_IMPORTED_MODULE_4__.globalContext.fetch(t,clientnode__WEBPACK_IMPORTED_MODULE_4___default().extend(!0,clientnode__WEBPACK_IMPORTED_MODULE_4___default().copy(e.couchdb.connector.fetch),r||{}))}}:{fetch:function(e,t){return clientnode__WEBPACK_IMPORTED_MODULE_4__.globalContext.fetch(e,t)}}},Helper.mayStripRepresentation=function(e,t,r){var n=clientnode__WEBPACK_IMPORTED_MODULE_4___default().represent(e);return n.length<=t?n.length>r?n.substring(0,r-3)+"...":n:"DOCUMENT IS TOO BIG TO REPRESENT"},Helper.ensureValidationDocumentPresence=function(){var e=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function e(t,r,n,a,o,c,i){var s,l,u;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return void 0===o&&(o=!0),void 0===c&&(c="_id"),void 0===i&&(i="_design/"),l=_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()(((s={})[c]=""+i+r,s.language="javascript",s),n),e.prev=4,e.next=7,t.get(""+i+r);case 7:return u=e.sent,l._rev=u._rev,e.next=11,t.put(l);case 11:case 20:e.next=26;break;case 14:return e.prev=14,e.t0=e.catch(4),o&&e.t0.error,e.prev=17,e.next=20,t.put(l);case 23:throw e.prev=23,e.t1=e.catch(17),new Error(a+" couldn't be installed/updated: \""+clientnode__WEBPACK_IMPORTED_MODULE_4___default().represent(e.t1)+'".');case 26:case"end":return e.stop()}}),e,null,[[4,14],[17,23]])})));return function(){return e.apply(this,arguments)}}(),Helper.initializeConnection=function(){var e=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function e(t,r){var n,a,o,c,i,s;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(n=clientnode__WEBPACK_IMPORTED_MODULE_4___default().stringFormat(r.couchdb.url,r.couchdb.user.name+":"+r.couchdb.user.password+"@")+"/"+r.couchdb.databaseName,t.couchdb.connection=new t.couchdb.connector(n,Helper.getConnectorOptions(r)),t.couchdb.connection.setMaxListeners(1/0),a=r.couchdb.model.property.name.special.id,o=r.couchdb.model.property.name.special.revision,c=function(){var e=s.value,n=t.couchdb.connection[e].bind(t.couchdb.connection);t.couchdb.connection[e]=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function e(t){var c,i,s,l,u,p=arguments;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(e.prev=0,c=p.length,i=Array(1<c?c-1:0),s=1;s<c;s++)i[s-1]=p[s];return e.next=4,n.apply(void 0,[t].concat(i));case 4:return e.abrupt("return",e.sent);case 7:if(e.prev=7,e.t0=e.catch(0),!(a in t&&r.couchdb.ignoreNoChangeError&&"forbidden"===e.t0.name&&null!=(l=e.t0.message)&&l.startsWith("NoChange:"))){e.next=21;break}if(u={id:t[a],ok:!0},!(o in t)||["latest","upsert"].includes(t[o])){e.next=15;break}e.t1=t[o],e.next=19;break;case 15:return e.next=17,this.get(u.id);case 17:e.t2=o,e.t1=e.sent[e.t2];case 19:return u.rev=e.t1,e.abrupt("return",u);case 21:throw e.t0;case 22:case"end":return e.stop()}}),e,this,[[0,7]])})))},i=_createForOfIteratorHelperLoose(["post","put"]);!(s=i()).done;)c();return e.prev=7,e.next=10,clientnode__WEBPACK_IMPORTED_MODULE_4___default().checkReachability(n);case 10:e.next=17;break;case 12:return e.prev=12,e.t0=e.catch(7),e.next=17,clientnode__WEBPACK_IMPORTED_MODULE_4__.globalContext.fetch(n,{method:"PUT"});case 17:return e.abrupt("return",t);case 18:case"end":return e.stop()}}),e,null,[[7,12]])})));return function(){return e.apply(this,arguments)}}(),Helper.startServer=function(){function startServer(){return _startServer.apply(this,arguments)}var _startServer=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function _callee4(services,configuration){var _this=this;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(_context4){for(;;)switch(_context4.prev=_context4.next){case 0:if(!Object.prototype.hasOwnProperty.call(services.couchdb.server.runner,"configurationFile")){_context4.next=12;break}return _context4.prev=1,_context4.next=4,fs__WEBPACK_IMPORTED_MODULE_6__.promises.mkdir(path__WEBPACK_IMPORTED_MODULE_7___default().dirname(services.couchdb.server.runner.configurationFile.path),{recursive:!0});case 4:_context4.next=10;break;case 6:if(_context4.prev=6,_context4.t0=_context4.catch(1),"EEXIST"===_context4.t0.code){_context4.next=10;break}throw _context4.t0;case 10:return _context4.next=12,fs__WEBPACK_IMPORTED_MODULE_6__.promises.writeFile(services.couchdb.server.runner.configurationFile.path,services.couchdb.server.runner.configurationFile.content,{encoding:configuration.core.encoding});case 12:return services.couchdb.server.process=(0,child_process__WEBPACK_IMPORTED_MODULE_3__.spawn)("default"===configuration.couchdb.binary.memoryInMegaByte?services.couchdb.server.runner.binaryFilePath:configuration.couchdb.binary.nodePath,("default"===configuration.couchdb.binary.memoryInMegaByte?[]:["--max-old-space-size="+configuration.couchdb.binary.memoryInMegaByte,services.couchdb.server.runner.binaryFilePath]).concat(services.couchdb.server.runner.arguments?services.couchdb.server.runner.arguments:[]),{cwd:eval("process").cwd(),env:Object.prototype.hasOwnProperty.call(services.couchdb.server.runner,"environment")?_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({},eval("process").env,services.couchdb.server.runner.environment):eval("process").env,shell:!0,stdio:"inherit"}),new Promise((function(e,t){for(var r,n,a=_createForOfIteratorHelperLoose(clientnode__WEBPACK_IMPORTED_MODULE_4__.CloseEventNames);!(r=a()).done;)n=r.value,services.couchdb.server.process.on(n,clientnode__WEBPACK_IMPORTED_MODULE_4___default().getProcessCloseHandler(e,t,{process:services.couchdb.server.process,reason:n}))})).then((function(e){var t,r;null!=(t=services.couchdb)&&null!=(r=t.server)&&r.resolve&&services.couchdb.server.resolve.call(_this,e)}),(function(e){var t,r;null!=(t=services.couchdb)&&null!=(r=t.server)&&r.resolve&&services.couchdb.server.reject.call(_this,e)})),_context4.next=16,clientnode__WEBPACK_IMPORTED_MODULE_4___default().checkReachability(clientnode__WEBPACK_IMPORTED_MODULE_4___default().stringFormat(configuration.couchdb.url,""),{wait:!0});case 16:case"end":return _context4.stop()}}),_callee4,null,[[1,6]])})));return startServer}(),Helper.restartServer=function(){var e=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function e(t){var r,n,a,o,c,i;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.configuration,n=t.pluginAPI,a=t.services,o=a.couchdb.server,c=o.resolve,i=o.reject,o.resolve=o.reject=clientnode__WEBPACK_IMPORTED_MODULE_4___default().noop,e.next=7,Helper.stopServer(a,r);case 7:return o.resolve=c,o.reject=i,e.next=11,Helper.startServer(a,r);case 11:return Helper.initializeConnection(a,r),e.next=14,n.callStack(_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({},t,{hook:"restartCouchdb"}));case 14:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),Helper.stopServer=function(){var e=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function e(t,r){var n,a;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.couchdb,a=r.couchdb,n.connection&&n.connection.close(),n.server.process&&n.server.process.kill("SIGINT"),e.next=6,clientnode__WEBPACK_IMPORTED_MODULE_4___default().checkUnreachability(clientnode__WEBPACK_IMPORTED_MODULE_4___default().stringFormat(a.url,""),{wait:!0});case 6:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),Helper.determineAllowedModelRolesMapping=function(e){for(var t=e.property.name.special.allowedRoles,r={},n=Helper.extendModels(e),a=0,o=Object.entries(n);a<o.length;a++){var c=o[a],i=c[0],s=c[1];if(Object.prototype.hasOwnProperty.call(s,t)){r[i]=_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({properties:{}},Helper.normalizeAllowedRoles(s[t]));for(var l=0,u=Object.entries(s);l<u.length;l++){var p=u[l],_=p[0],d=p[1];null!==d&&"object"==typeof d&&d.allowedRoles&&(r[i].properties[_]=Helper.normalizeAllowedRoles(d.allowedRoles))}}else r[i]={properties:{},read:[],write:[]}}return r},Helper.determineGenericIndexablePropertyNames=function(e,t){var r=e.property.name.special;return Object.keys(t).filter((function(n){return null!==t[n]&&"object"==typeof t[n]&&(Object.prototype.hasOwnProperty.call(t[n],"index")&&t[n].index||!(Object.prototype.hasOwnProperty.call(t[n],"index")&&!t[n].index||e.property.name.reserved.concat(r.additional,r.allowedRoles,r.attachment,r.conflict,r.constraint.execution,r.constraint.expression,r.deleted,r.deletedConflict,r.extend,r.id,r.maximumAggregatedSize,r.minimumAggregatedSize,r.oldType,r.revision,r.revisions,r.revisionsInformation,r.type).includes(n)||t[n].type&&("string"==typeof t[n].type&&t[n].type.endsWith("[]")||Array.isArray(t[n].type)&&t[n].type.length&&Array.isArray(t[n].type[0])||Object.prototype.hasOwnProperty.call(e.entities,t[n].type))))})).concat(r.id,r.revision).sort()},Helper.extendModel=function(e,t,r){if(void 0===r&&(r="_extends"),"_base"===e)return t[e];if(Object.prototype.hasOwnProperty.call(t,"_base")&&(Object.prototype.hasOwnProperty.call(t[e],r)&&t[e][r]?t[e][r]=["_base"].concat(t[e][r]):t[e][r]="_base"),Object.prototype.hasOwnProperty.call(t[e],r)){for(var n,a,o=_createForOfIteratorHelperLoose([].concat(t[e][r]));!(n=o()).done;)a=n.value,t[e]=clientnode__WEBPACK_IMPORTED_MODULE_4___default().extend(!0,clientnode__WEBPACK_IMPORTED_MODULE_4___default().copy(Helper.extendModel(a,t,r)),t[e]);delete t[e][r]}return t[e]},Helper.extendModels=function(e){for(var t,r=e.property.name.special,n={},a=0,o=Object.keys(e.entities);a<o.length;a++){if(t=o[a],!new RegExp(e.property.name.typeRegularExpressionPattern.public).test(t)&&!new RegExp(e.property.name.typeRegularExpressionPattern.private).test(t))throw new Error('Model names have to match "'+e.property.name.typeRegularExpressionPattern.public+'" or "'+e.property.name.typeRegularExpressionPattern.private+'" for private one (given name: "'+t+'").');n[t]=Helper.extendModel(t,e.entities,r.extend)}for(var c,i=0,s=Object.values(n);i<s.length;i++){c=s[i];for(var l=0,u=Object.entries(c);l<u.length;l++){var p=u[l],_=p[0],d=p[1];if(_===r.attachment)for(var m=0,f=Object.entries(d);m<f.length;m++){var y=f[m],b=y[0],h=y[1];d[b]=clientnode__WEBPACK_IMPORTED_MODULE_4___default().extend(!0,clientnode__WEBPACK_IMPORTED_MODULE_4___default().copy(e.property.defaultSpecification),h)}else[r.allowedRoles,r.constraint.execution,r.constraint.expression,r.extend,r.maximumAggregatedSize,r.minimumAggregatedSize,r.oldType].includes(_)||(c[_]=clientnode__WEBPACK_IMPORTED_MODULE_4___default().extend(!0,clientnode__WEBPACK_IMPORTED_MODULE_4___default().copy(e.property.defaultSpecification),d))}}return n},Helper.normalizeAllowedRoles=function(e){if(Array.isArray(e))return{read:e,write:e};if("object"==typeof e){for(var t,r={read:[],write:[]},n=0,a=Object.keys(r);n<a.length;n++)t=a[n],Object.prototype.hasOwnProperty.call(e,t)&&(Array.isArray(e[t])?r[t]=e[t]:r[t]=[e[t]]);return r}return{read:[e],write:[e]}},Helper}();const __WEBPACK_DEFAULT_EXPORT__=Helper},e=>{!function(){"use strict";function t(){return(t=r()?Reflect.construct.bind():function(e,t,r){var a=[null];a.push.apply(a,t);var o=new(Function.bind.apply(e,a));return r&&n(o,r.prototype),o}).apply(null,arguments)}function r(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function n(e,t){return n=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},n(e,t)}function a(){return a=Object.assign?Object.assign.bind():function(e){for(var t,r=1;r<arguments.length;r++)for(var n in t=arguments[r])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e},a.apply(this,arguments)}function o(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return c(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?c(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 c(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 i={d:function(e,t){for(var r in t)i.o(t,r)&&!i.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},o:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r:function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},s={};i.r(s),i.d(s,{DatabaseHelper:function(){return l},default:function(){return u}});var l=function(){function e(){}return e.authenticate=function(e,t,r,n,a,c,i,s,l){var u;void 0===t&&(t=null),void 0===r&&(r={}),void 0===n&&(n={admins:{names:[],roles:[]},members:{names:[],roles:[]}}),void 0===c&&(c="_id"),void 0===i&&(i="-type"),void 0===s&&(s="_design/"),void 0===l&&(l=!1);var p=null!==(u=e[i])&&void 0!==u?u:t&&t[i];if(!p)return!0;var _=l?"read":"write",d={properties:{},read:["_admin","readonlyadmin"],write:["_admin"]};Object.prototype.hasOwnProperty.call(e,c)&&e[c].startsWith(s)&&d.read.push("readonlymember");var m,f="Current user doesn't own any role";if(r)if("name"in r||(r.name='"unknown"'),null!=(m=r.roles)&&m.length){if(a&&p&&Object.prototype.hasOwnProperty.call(a,p)){for(var y,b,h=a[p],v=o(["read","write"]);!(y=v()).done;)d[b=y.value]=d[b].concat(h[b]||[]);d.properties=h.properties}for(var g,O,x=d[_],P=o(r.roles);!(g=P()).done;)if(O=g.value,x.includes(O))return!0;f='Current user "'+r.name+'" owns the following roles: "'+r.roles.join('", "')+'"'}else f='Current user "'+r.name+"\" doesn't own any role";throw{unauthorized:"Only users with a least on of these roles are allowed to perform requested "+_+' action: "'+[].concat(d[_]).join('", "')+'". '+f+"."}},e.validateDocumentUpdate=function(e,r,n,c,i,s,l){void 0===s&&(s={});var u=function(e,t,r){var n;void 0===t&&(t="forbidden"),void 0===r&&(r={});for(var a=((n={})[t]=e,n.message=e,n.name=t,n),o=0,c=Object.entries(r);o<c.length;o++){var i=c[o],s=i[0],l=i[1];a[s]=l}throw a},p=new Date,_=Date.UTC(p.getUTCFullYear(),p.getUTCMonth(),p.getUTCDate(),p.getUTCHours(),p.getUTCMinutes(),p.getUTCSeconds(),p.getUTCMilliseconds())/1e3,d=!i.dateTimeFormat.startsWith("iso"),m=i.property.name.special,f=m.id,y=m.revision,b=m.type;r&&r[b]&&!e[b]&&(e[b]=r[b]);var h="",v="",g=function(){h=Object.prototype.hasOwnProperty.call(e,f)?e[f]:"",v=Object.prototype.hasOwnProperty.call(e,y)?e[y]:""};if(g(),Object.prototype.hasOwnProperty.call(c,i.property.name.validatedDocumentsCache)&&c[i.property.name.validatedDocumentsCache].has(h+"-"+v))return c[i.property.name.validatedDocumentsCache].delete(h+"-"+v),e;["latest","upsert"].includes(v)&&(r&&Object.prototype.hasOwnProperty.call(r,y)?v=e[y]=r[y]:"latest"===v?u("Revision: No old document available to update."):delete e[y]);var O=i.updateStrategy;Object.prototype.hasOwnProperty.call(e,m.strategy)&&(O=e[m.strategy],delete e[m.strategy]);var x,P={};if("migrate"===O)for(var w=0,E=Object.entries(s);w<E.length;w++){var k=E[w],D=k[0],j=k[1];if(Object.prototype.hasOwnProperty.call(j,m.oldType)&&![null,void 0].includes(j[m.oldType]))for(var M,A,C=o([].concat(j[m.oldType]));!(M=C()).done;)A=M.value,P[A]=D}l?x=l:JSON&&Object.prototype.hasOwnProperty.call(JSON,"stringify")?x=function(e){return JSON.stringify(e,null,4)}:u('Needed "serializer" is not available.');var T=function(e){return e instanceof Error?""+e:x(e)},R=function(e){return"string"==typeof e?e.trim():""},I=function(e){if(d)null!==e&&"number"!=typeof e&&(e=new Date(e),e=Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate(),e.getUTCHours(),e.getUTCMinutes(),e.getUTCSeconds(),e.getUTCMilliseconds())/1e3);else if(null!==e){e=new Date("number"!=typeof e||isNaN(e)?e:1e3*e);try{e=e.toISOString()}catch(e){}}return e},S=function(e,t,r){if(r.fileName){if(r.fileName.value)return r.fileName.value===t;if(r.fileName.regularExpressionPattern)return new RegExp(r.fileName.regularExpressionPattern).test(t)}return e===t},U=function(t,r){if(r||(r=e[m.attachment]),t){for(var n,a=0,o=Object.keys(r);a<o.length;a++)if((n=o[a]).startsWith(t))return n}else{var c=Object.keys(r);if(c.length)return c[0]}return null},L=function(e,r,n){void 0===r&&(r=!1),void 0===n&&(n={});var o=R(e);if(o){var c,i=(r?"return ":"")+o,s=a({},N,{code:i},n),l=Object.keys(s);try{c=t(Function,l.concat([i]))}catch(e){u(T(e),"compilation",{code:i,error:e,scope:s})}var p={code:i,result:void 0,scope:s};try{p.result=c.apply(void 0,l.map((function(e){return s[e]})))}catch(e){u(T(e),"runtime",{code:i,error:e,scope:s})}return p}u("No expression to evaluate provided.","empty")},W=function(e,r,n){void 0===n&&(n=[]);var a=n.length?" in "+n.join(" -> "):"",c=[],l=function(){Object.prototype.hasOwnProperty.call(e,b)||(r&&Object.prototype.hasOwnProperty.call(r,b)&&["fillUp","migrate"].includes(O)?e[b]=r[b]:u('Type: You have to specify a model type via property "'+b+'"'+a+".")),n.length||new RegExp(i.property.name.typeRegularExpressionPattern.public).test(e[b])||u('TypeName: You have to specify a model type which matches "'+i.property.name.typeRegularExpressionPattern.public+'" as public type (given "'+e[b]+'")'+a+"."),Object.prototype.hasOwnProperty.call(s,e[b])||(Object.prototype.hasOwnProperty.call(P,e[b])?e[b]=P[e[b]]:u('Model: Given model "'+e[b]+'" is not specified'+a+"."))};l();var p=e[b],_=s[p],h=null;Object.prototype.hasOwnProperty.call(_,m.additional)&&_[m.additional]&&(h=_[m.additional]);var v=function c(i,s,l,d,m){void 0===m&&(m=["constraintExecution","constraintExpression"]);for(var f,y,b=o(m);!(f=b()).done;)if(y=f.value,Object.prototype.hasOwnProperty.call(l,y)){var h,v=void 0;try{v=L(l[y].evaluation,y.endsWith("Expression"),{checkPropertyContent:c,model:_,modelName:p,name:s,type:y,newDocument:e,newValue:i,oldDocument:r,oldValue:d,parentNames:n,pathDescription:a,propertySpecification:l})}catch(s){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(s)&&u('Compilation: Hook "'+y+'" has invalid code "'+s.code+'": "'+s.message+'"'+a+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(s)&&u('Runtime: Hook "'+y+'" has throw an error with code "'+s.code+'": "'+s.message+'"'+a+"."),!Object.prototype.hasOwnProperty.call(s,"empty"))throw s}if(null==(h=v)||!h.result){var g=R(l[y].description);u(y.charAt(0).toUpperCase()+(y.substring(1)+": ")+(g?t(Function,Object.keys(v.scope).concat(["return "+g])).apply(void 0,Object.values(v.scope)):'Property "'+s+'" should satisfy constraint "'+v.code+'" (given "'+T(i)+'")'+a+"."))}}},x=function(e,t,r,c){void 0===c&&(c=null);var i=[],l=[].concat(r.type?r.type:[]);"object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype&&!Object.prototype.hasOwnProperty.call(e,b)&&1===l.length&&Object.prototype.hasOwnProperty.call(s,l[0])&&(e[b]=l[0]);for(var p,_,m=!1,y=o(l);!(p=y()).done;)if(_=p.value,Object.prototype.hasOwnProperty.call(s,_)){if("object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype&&Object.prototype.hasOwnProperty.call(e,b)&&e[b]!==_&&"migrate"===O&&1===l.length&&(e[b]=_,i=n.concat(t,"migrate nested object type")),"object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype&&Object.prototype.hasOwnProperty.call(e,b)&&e[b]===_){var h=W(e,c,n.concat(t));if(h.changedPath.length&&(i=h.changedPath),e=h.newDocument,T(e)===T({}))return{newValue:null,changedPath:i};m=!0;break}1===l.length&&u('NestedType: Under key "'+t+'" isn\'t of type "'+_+'" (given "'+T(e)+'" of type '+typeof e+")"+a+".")}else if("DateTime"===_){var g=e;if(e=I(e),!(d&&("number"!=typeof e||isNaN(e))||!d&&"string"!=typeof e)){m=!0;break}1===l.length&&u('PropertyType: Property "'+t+'" isn\'t of (valid) type "DateTime" (given "'+T(g).replace(/^"/,"").replace(/"$/,"")+'" of type "'+typeof g+'")'+a+".")}else if(["boolean","integer","number","string"].includes(_)){if(!("number"==typeof e&&isNaN(e)||"integer"!==_&&typeof e!==_||"integer"===_&&parseInt(e,10)!==e)){m=!0;break}1===l.length&&u('PropertyType: Property "'+t+'" isn\'t of (valid) type "${type}" (given "'+T(e)+'" of type "'+typeof e+'")'+a+".")}else if("string"==typeof _&&_.startsWith("foreignKey:")){var x=s[_.substring(11)][f].type;if(x===typeof e){m=!0;break}1===l.length&&u('PropertyType: Foreign key property "'+t+'" isn\'t of type "'+x+'" (given "'+T(e)+'" of type "'+typeof e+'")'+a+".")}else{if("any"===_||T(e)===T(_)){m=!0;break}1===l.length&&u('PropertyType: Property "'+t+'" isn\'t value "'+_+'" (given "'+T(e).replace(/^"/,"").replace(/"$/,"")+'" of type "'+typeof e+'")'+a+".")}if(m||u('PropertyType: None of the specified types "'+l.join('", "')+'" for property "'+t+'" matches value "'+T(e).replace(/^"/,"").replace(/"$/,"")+e+'" of type "'+typeof e+'")'+a+"."),"string"==typeof e&&(![null,void 0].includes(r.minimumLength)&&e.length<r.minimumLength&&u('MinimalLength: Property "'+t+'" must have minimal length '+r.minimumLength+" (given "+e+" with length i"+e.length+") "+a+"."),![null,void 0].includes(r.maximumLength)&&e.length>r.maximumLength&&u('MaximalLength: Property "'+t+'" must have maximal length '+r.maximumLength+" (given "+e+" with length "+e.length+")"+a+".")),"number"==typeof e&&(![null,void 0].includes(r.minimum)&&e<r.minimum&&u('Minimum: Property "'+t+'" (type '+r.type+") must satisfy a minimum of "+r.minimum+" (given "+e+" is too low)"+a+"."),![null,void 0].includes(r.maximum)&&e>r.maximum&&u('Maximum: Property "'+t+'" (type '+r.type+") must satisfy a maximum of "+r.maximum+" (given "+e+" is too high)"+a+".")),r.selection){var P=Array.isArray(r.selection)?r.selection.map((function(e){return void 0===(null==e?void 0:e.value)?e:e.value})):Object.keys(r.selection);"DateTime"===r.type&&(P=P.map(I)),P.includes(e)||u('Selection: Property "'+t+'" (type '+r.type+') should be one of "'+P.join('", "')+'". But is "'+e+'"'+a+".")}return[null,void 0].includes(r.regularExpressionPattern)||new RegExp(r.regularExpressionPattern).test(e)?![null,void 0].includes(r.invertedRegularExpressionPattern)&&new RegExp(r.invertedRegularExpressionPattern).test(e)&&u('InvertedPatternMatch: Property "'+t+'" should not match regular expression pattern '+r.invertedRegularExpressionPattern+' (given "'+e+'")'+a+"."):u('PatternMatch: Property "'+t+'" should match regular expression pattern '+r.regularExpressionPattern+' (given "'+e+'")'+a+"."),v(e,t,r,c),T(e)!==T(c)&&(i=n.concat(t,"value updated")),{newValue:e,changedPath:i}},w=function(e,t,r,a,o){var s=t[a];if(!e.writable)if(r){if(Object.prototype.hasOwnProperty.call(r,a)&&T(s)===T(r[a]))return a!==f&&"incremental"===O&&delete t[a],!0;u('Readonly: Property "'+a+'" is not writable (old document "'+T(r)+'")'+o+".")}else u('Readonly: Property "'+a+'" is not writable'+o+".");if(!e.mutable&&r&&Object.prototype.hasOwnProperty.call(r,a)){if(T(s)===T(r[a]))return"incremental"!==O||i.property.name.reserved.concat(m.deleted,f,y).includes(a)||delete t[a],!0;"migrate"!==O&&u('Immutable: Property "'+a+'" is not writable (old document "'+T(r)+'")'+o+".")}if(null===s){if(e.nullable)return delete t[a],r&&Object.prototype.hasOwnProperty.call(r,a)&&(c=n.concat(a,"delete property")),!0;u('NotNull: Property "'+a+'" should not be "null"'+o+".")}return!1},E=function(e,t,r,c){if(!r)for(var i,s,l=o(["onCreateExecution","onCreateExpression"]);!(i=l()).done;)if(s=i.value,Object.prototype.hasOwnProperty.call(e,s)){var d=void 0;try{d=L(e[s],s.endsWith("Expression"),{checkPropertyContent:x,model:_,modelName:p,name:c,type:s,newDocument:t,oldDocument:r,newValue:void 0,oldValue:void 0,parentNames:n,pathDescription:a,propertySpecification:e})}catch(i){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(i)&&u('Compilation: Hook "'+s+'" has invalid code "'+i.code+'" for property "'+c+'": '+i.message+a+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(i)&&u('Runtime: Hook "'+s+'" has throw an error with code "'+i.code+'" for property "'+c+'": '+i.message+a+"."),!Object.prototype.hasOwnProperty.call(i,"empty"))throw i}d&&![null,void 0].includes(d.result)&&(t[c]=d.result)}},k=function(e,t,r,c){if(Object.prototype.hasOwnProperty.call(t,c)){e.trim&&"string"==typeof t[c]&&(t[c]=t[c].trim()),e.emptyEqualsToNull&&(""===t[c]||Array.isArray(t[c])&&0===t[c].length||null!==t[c]&&"object"==typeof t[c]&&0===Object.keys(t).length)&&(t[c]=null);for(var i,s,l=o(["onUpdateExecution","onUpdateExpression"]);!(i=l()).done;)if(s=i.value,Object.prototype.hasOwnProperty.call(e,s))try{t[c]=L(e[s],s.endsWith("Expression"),{checkPropertyContent:x,model:_,modelName:p,name:c,type:s,newDocument:t,oldDocument:r,newValue:t[c],oldValue:r&&r[c],parentNames:n,pathDescription:a,propertySpecification:e}).result}catch(i){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(i)&&u('Compilation: Hook "'+s+'" has invalid code "'+i.code+'" for property "'+c+'": '+i.message+a+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(i)&&u('Runtime: Hook "'+s+'" has throw an error with code "'+i.code+'" for property "'+c+'": '+i.message+a+"."),!Object.prototype.hasOwnProperty.call(i,"empty"))throw i}}},D=Object.keys(_).filter((function(e){return![m.additional,m.allowedRoles,m.constraint.execution,m.constraint.expression,m.create.execution,m.create.expression,m.extend,m.maximumAggregatedSize,m.minimumAggregatedSize,m.oldType,m.update.execution,m.update.expression].includes(e)}));if("migrate"===O)for(var j,M,A=o(D);!(j=A()).done;)if(M=j.value,![null,void 0].includes(_[M].oldName))for(var C,U,N=o([].concat(_[M].oldName));!(C=N()).done;)U=C.value,Object.prototype.hasOwnProperty.call(e,U)&&(e[M]=e[U],delete e[U]);if(!r)for(var B,K=0,q=[m.create.execution,m.create.expression];K<q.length;K++)if(B=q[K],Object.prototype.hasOwnProperty.call(_,B)){var z=void 0;try{z=L(_[B],B.endsWith("Expression"),{checkPropertyContent:x,model:_,modelName:p,type:B,newDocument:e,oldDocument:r,parentNames:n,pathDescription:a}).result}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&u('Compilation: Hook "'+B+'" has invalid code "'+e.code+'" for document "'+p+'": '+e.message+a+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&u('Runtime: Hook "'+B+'" has throw an error with code "'+e.code+'" for document "'+p+'": '+e.message+a+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}[null,void 0].includes(z)||(e=z),l(),p=e[b],0===n.length&&g()}for(var H,F=0,G=[m.update.execution,m.update.expression];F<G.length;F++)if(H=G[F],Object.prototype.hasOwnProperty.call(_,H)){var V=void 0;try{V=L(_[H],H.endsWith("Expression"),{checkPropertyContent:x,model:_,modelName:p,type:H,newDocument:e,oldDocument:r,parentNames:n,pathDescription:a}).result}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&u('Compilation: Hook "'+H+'" has invalid code "'+e.code+'" for document "'+p+'": '+e.message+a+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&u('Runtime: Hook "'+H+'" has throw an error with code "'+e.code+'" for document "'+p+'": '+e.message+a+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}[void 0,null].includes(V)||(e=V),l(),p=e[b],0===n.length&&g()}for(var J,$=function t(){var a=J.value;if(m.attachment===a)for(var i=function(){var i=l[s],u=i[0],p=i[1];Object.prototype.hasOwnProperty.call(e,a)&&null!==e[a]||(e[a]={}),r&&!Object.prototype.hasOwnProperty.call(r,a)&&(r[a]={});var _=Object.keys(e[a]).filter((function(t){return null!==e[a][t].data&&S(u,t,p)})),d=e[a],m=[];if(r){var f=r[a];m=Object.keys(f).filter((function(e){return!(Object.prototype.hasOwnProperty.call(d,e)&&Object.prototype.hasOwnProperty.call(d[e],"data")&&null===d[e].data)&&!!f[e]&&(Object.prototype.hasOwnProperty.call(f[e],"data")&&null!==f[e].data||f[e].stub&&!!f[e].digest)&&!!S(u,e,p)}))}for(var y,b,h=p,v=o(_);!(y=v()).done;)b=y.value,E(h,d,r&&r[a]?r[a]:null,b);for(var g,x,P=o(_);!(g=P()).done;)x=g.value,k(h,d,r&&r[a]?r[a]:null,x);if([null,void 0].includes(h.default)){if(h.nullable||0<_.length||0<m.length||t(),"fillUp"===O&&0===_.length&&0<m.length)for(var w,D,j=o(m);!(w=j()).done;)D=w.value,null===d[D]?c=n.concat(a,D,"file removed"):d[D]=r[a][D]}else if(0===_.length)if(0===m.length)for(var M in h.default)Object.prototype.hasOwnProperty.call(h.default,M)&&(d[M]=h.default[M],c=n.concat(a,u,"add default file"));else if("fillUp"===O)for(var A,C,T=o(m);!(A=T()).done;)C=A.value,d[C]=r[a][C]},s=0,l=Object.entries(_[a]);s<l.length;s++)i();else{var u=D.includes(a)?_[a]:h;E(u,e,r,a),k(u,e,r,a),[null,void 0].includes(u.default)?(!(u.nullable||Object.prototype.hasOwnProperty.call(e,a)||r&&Object.prototype.hasOwnProperty.call(r,a)&&O)&&t(),!Object.prototype.hasOwnProperty.call(e,a)&&r&&Object.prototype.hasOwnProperty.call(r,a)&&("fillUp"===O?e[a]=r[a]:!O&&(c=n.concat(a,"property removed")))):(!Object.prototype.hasOwnProperty.call(e,a)||null===e[a])&&(r&&Object.prototype.hasOwnProperty.call(r,a)?"fillUp"===O?e[a]=r[a]:"migrate"===O&&(e[a]=u.default,c=n.concat(a,"migrate default value")):(e[a]=u.default,c=c.concat(a,"add default value")))}},Y=o(D.concat(h?Object.keys(e).filter((function(e){return!D.includes(e)})):[]));!(J=Y()).done;)$();if(r&&"incremental"===O)for(var X=0,Z=Object.entries(e);X<Z.length;X++){var Q=Z[X],ee=Q[0],te=Q[1];!Object.prototype.hasOwnProperty.call(r,ee)||i.property.name.reserved.concat(f,y,m.conflict,m.deleted,m.deletedConflict,m.localSequence,m.revisions,m.revisionsInformation,b).includes(ee)||r[ee]!==te&&T(r[ee])!==T(te)||delete e[ee]}for(var re=0,ne=Object.entries(e);re<ne.length;re++){var ae=ne[re],oe=ae[0],ce=ae[1];if(!i.property.name.reserved.concat(y,m.conflict,m.deleted,m.deletedConflict,m.localSequence,m.revisions,m.revisionsInformation,m.strategy).includes(oe)){var ie=void 0;if(Object.prototype.hasOwnProperty.call(_,oe))ie=_[oe];else if(h)ie=h;else{if("migrate"===O){delete e[oe],c=n.concat(oe,"migrate removed property");continue}u('Property: Given property "'+oe+'" isn\'t specified in model "'+p+'"'+a+".")}if(!ie)continue;if(m.attachment===oe){var se=ce;for(var le in se)if(Object.prototype.hasOwnProperty.call(se,le))for(var ue in _[oe])if(S(ue,le,_[oe][ue])){w(_[oe][ue],e,r,le,a);break}continue}if(w(ie,e,r,oe,a))continue;if("string"==typeof ie.type&&ie.type.endsWith("[]")||Array.isArray(ie.type)&&ie.type.length&&Array.isArray(ie.type[0])){var pe,_e=ce;Array.isArray(_e)?![null,void 0].includes(ie.minimumNumber)&&_e.length<ie.minimumNumber?u('MinimumArrayLength: Property "'+oe+'" (array of length '+_e.length+") doesn't fullfill minimum array length of "+ie.minimumNumber+a+"."):![null,void 0].includes(ie.maximumNumber)&&ie.maximumNumber<_e.length&&u('MaximumArrayLength: Property "'+oe+'" (array of length '+_e.length+") doesn't fullfill maximum array length of "+ie.maximumNumber+a+"."):u('PropertyType: Property "'+oe+'" isn\'t of type "array -> '+ie.type+'" (given "'+T(_e)+'")'+a+"."),v(_e,oe,ie,r&&Object.prototype.hasOwnProperty.call(r,oe)&&r[oe]||void 0,["arrayConstraintExecution","arrayConstraintExpression"]);var de={};for(var me in ie)Object.prototype.hasOwnProperty.call(ie,me)&&(de[me]="type"===me?Array.isArray(ie[me])?ie[me][0]:[ie[me].substring(0,ie.type.length-2)]:ie[me]);if(1===(null==(pe=de.type)?void 0:pe.length)&&Object.prototype.hasOwnProperty.call(s,de.type[0]))for(var fe,ye,be=o(_e.slice());!(fe=be()).done;)"object"!=typeof(ye=fe.value)||Object.getPrototypeOf(ye)!==Object.prototype||Object.prototype.hasOwnProperty.call(ye,b)||(ye[b]=de.type[0]);for(var he,ve,ge=0,Oe=o(_e.slice());!(he=Oe()).done;)ve=he.value,_e[ge]=x(ve,ge+1+". value in "+oe,de).newValue,null===ve&&_e.splice(ge,1),ge+=1;r&&Object.prototype.hasOwnProperty.call(r,oe)&&Array.isArray(r[oe])&&r[oe].length===_e.length&&T(r[oe])===T(_e)||(c=n.concat(oe,"array updated"))}else{var xe=r&&Object.prototype.hasOwnProperty.call(r,oe)?r[oe]:null,Pe=x(ce,oe,ie,xe);e[oe]=Pe.newValue,Pe.changedPath.length&&(c=Pe.changedPath),null===e[oe]&&(null!==xe&&(c=n.concat(oe,"property removed")),delete e[oe])}}}for(var we,Ee=0,ke=Object.keys(m.constraint);Ee<ke.length;Ee++)if(we=ke[Ee],(we=m.constraint[we])&&Object.prototype.hasOwnProperty.call(_,we))for(var De,je=o([].concat(_[we]));!(De=je()).done;){var Me,Ae=De.value,Ce=void 0;try{Ce=L(Ae.evaluation,we===m.constraint.expression,{checkPropertyContent:x,model:_,modelName:p,type:we,newDocument:e,oldDocument:r,parentNames:n,pathDescription:a})}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&u('Compilation: Hook "'+we+'" has invalid code "'+e.code+'": "'+e.message+'"'+a+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&u('Runtime: Hook "'+we+'" has thrown an error with code "'+e.code+'": '+e.message+a+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}if(null==(Me=Ce)||!Me.result){var Te=we.replace(/^[^a-zA-Z]+/,"");u(Te.charAt(0).toUpperCase()+(Te.substring(1)+": ")+(Ae.description?t(Function,Object.keys(Ce.scope).concat(["return "+Ae.description.trim()])).apply(void 0,Object.values(Ce.scope)):'Model "'+p+'" should satisfy constraint "'+Ce.code+'" (given "'+T(e)+'")'+a+"."))}}if(Object.prototype.hasOwnProperty.call(e,m.attachment)){var Re=e[m.attachment];("object"!=typeof Re||Object.getPrototypeOf(Re)!==Object.prototype)&&u("AttachmentType: given attachment has invalid type"+a+".");var Ie=null;if(r&&Object.prototype.hasOwnProperty.call(r,m.attachment)&&null!==(Ie=r[m.attachment])&&"object"==typeof Ie)for(var Se=0,Ue=Object.entries(Ie);Se<Ue.length;Se++){var Le=Ue[Se],We=Le[0],Ne=Le[1];if(Object.prototype.hasOwnProperty.call(Re,We)){var Be=Re[We];null===Be||null===Be.data||Be.content_type===Ne.content_type&&(Be.data===Ne.data||Be.digest===Ne.digest)?((null===Be||null===Be.data)&&(c=n.concat(m.attachment,We,"attachment removed")),"incremental"===O&&delete Re[We]):c=n.concat(m.attachment,We,"attachment updated")}else"fillUp"===O?Re[We]=Ne:O||(c=n.concat(m.attachment,We,"attachment removed"))}for(var Ke=0,qe=Object.entries(Re);Ke<qe.length;Ke++){var ze=qe[Ke],He=ze[0],Fe=ze[1];[null,void 0].includes(Fe)||null===Fe.data?delete Re[He]:(!Ie||!Object.prototype.hasOwnProperty.call(Ie,He)||Fe.content_type!==Ie[He].content_type||Fe.data!==Ie[He].data&&Fe.digest!==Ie[He].digest)&&(c=n.concat(m.attachment,He,"attachment updated"))}0===Object.keys(Re).length&&delete e[m.attachment];for(var Ge={},Ve=0,Je=Object.keys(_[m.attachment]);Ve<Je.length;Ve++)Ge[Je[Ve]]=[];for(var $e=0,Ye=Object.keys(Re);$e<Ye.length;$e++){for(var Xe=Ye[$e],Ze=!1,Qe=0,et=Object.entries(_[m.attachment]);Qe<et.length;Qe++){var tt=et[Qe],rt=tt[0],nt=tt[1];if(S(rt,Xe,nt)){Ge[rt].push(Xe),Ze=!0;break}}Ze||u('AttachmentTypeMatch: None of the specified attachment types ("'+Object.keys(_[m.attachment]).join('", "')+'") matches given one ("'+Xe+'")'+a+".")}for(var at=0,ot=0,ct=Object.keys(Ge);ot<ct.length;ot++){var it=ct[ot],st=_[m.attachment][it];if(Object.prototype.hasOwnProperty.call(Ge,it)){var lt=Ge[it].length;null!==st.maximumNumber&&lt>st.maximumNumber&&u("AttachmentMaximum: given number of attachments ("+lt+") doesn't satisfy specified maximum of "+st.maximumNumber+' from type "'+it+'"'+a+"."),(!st.nullable||0!==lt)&&lt<st.minimumNumber&&u("AttachmentMinimum: given number of attachments ("+lt+") doesn't satisfy specified minimum of "+st.minimumNumber+' from type "'+it+'"'+a+".");for(var ut,pt=0,_t=o(Ge[it]);!(ut=_t()).done;){var dt,mt,ft=ut.value;null!=(dt=st.fileName)&&dt.regularExpressionPattern&&!new RegExp(st.fileName.regularExpressionPattern).test(ft)?u('AttachmentName: given attachment name "'+ft+'" doesn\'t satisfy specified regular expression pattern "'+st.fileName.regularExpressionPattern+'" from type "'+it+'"'+a+"."):null!=(mt=st.fileName)&&mt.invertedRegularExpressionPattern&&new RegExp(st.fileName.invertedRegularExpressionPattern).test(ft)?u('InvertedAttachmentName: given attachment name "'+ft+'" does satisfy specified regular expression pattern "'+st.fileName.invertedRegularExpressionPattern+'" from type "'+it+'"'+a+"."):!([null,void 0].includes(st.contentTypeRegularExpressionPattern)||Re[ft].content_type&&new RegExp(st.contentTypeRegularExpressionPattern).test(Re[ft].content_type))&&u('AttachmentContentType: given attachment content type "'+Re[ft].content_type+'" doesn\'t satisfy specified regular expression pattern "'+st.contentTypeRegularExpressionPattern+'" from type "'+it+'"'+a+".");var yt=st.invertedContentTypeRegularExpressionPattern;[null,void 0].includes(yt)||Re[ft].content_type&&!new RegExp(yt).test(Re[ft].content_type)||u('InvertedAttachmentContentType: given attachment content type "'+Re[ft].content_type+'" does satisfy specified regular expression pattern "'+yt+'" from type "'+it+'"'+a+".");var bt=0;"length"in Re[ft]?bt=Re[ft].length:"data"in Re[ft]&&(bt=Buffer&&"byteLength"in Buffer?Buffer.byteLength(Re[ft].data,"base64"):Re[ft].data.length),![null,void 0].includes(st.minimumSize)&&st.minimumSize>bt?u("AttachmentMinimumSize: given attachment size "+bt+" byte doesn't satisfy specified minimum of "+st.minimumSize+" byte "+a+"."):![null,void 0].includes(st.maximumSize)&&st.maximumSize<bt&&u("AttachmentMaximumSize: given attachment size "+bt+" byte doesn't satisfy specified maximum of "+st.maximumSize+" byte "+a+"."),pt+=bt}![null,void 0].includes(st.minimumAggregatedSize)&&st.minimumAggregatedSize>pt?u('AttachmentAggregatedMinimumSize: given aggregated size of attachments from type "'+it+'" '+pt+" byte doesn't satisfy specified minimum of "+st.minimumAggregatedSize+" byte "+a+"."):![null,void 0].includes(st.maximumAggregatedSize)&&st.maximumAggregatedSize<pt&&u('AttachmentAggregatedMaximumSize: given aggregated size of attachments from type "'+it+'" '+pt+" byte doesn't satisfy specified maximum of "+st.maximumAggregatedSize+" byte "+a+"."),at+=pt}}Object.prototype.hasOwnProperty.call(_,m.minimumAggregatedSize)&&![null,void 0].includes(_[m.minimumAggregatedSize])&&_[m.minimumAggregatedSize]>at?u("AggregatedMinimumSize: given aggregated size "+at+" byte doesn't satisfy specified minimum of "+_[m.minimumAggregatedSize]+" byte "+a+"."):![null,void 0].includes(_[m.maximumAggregatedSize])&&_[m.maximumAggregatedSize]<at&&u("AggregatedMaximumSize: given aggregated size "+at+" byte doesn't satisfy specified maximum of "+_[m.maximumAggregatedSize]+" byte "+a+".")}if(r&&Object.prototype.hasOwnProperty.call(r,m.attachment)&&0===Object.keys(r[m.attachment]).length&&delete r[m.attachment],0===c.length&&r&&"migrate"===O)for(var ht,vt=0,gt=Object.keys(r);vt<gt.length;vt++)ht=gt[vt],Object.prototype.hasOwnProperty.call(e,ht)||(c=n.concat(ht,"migrate removed property"));return{changedPath:c,newDocument:e}},N={attachmentWithPrefixExists:function(t){if(Object.prototype.hasOwnProperty.call(e,m.attachment)){var r=e[m.attachment],n=U(t);if(n)return Object.prototype.hasOwnProperty.call(r[n],"stub")&&r[n].stub||Object.prototype.hasOwnProperty.call(r[n],"data")&&![null,void 0].includes(r[n].data)}return!1},checkDocument:W,getFileNameByPrefix:U,serialize:T,id:h,revision:v,idName:f,revisionName:y,specialNames:m,typeName:b,modelConfiguration:i,models:s,now:p,nowUTCTimestamp:_,securitySettings:c,userContext:n},B=W(e,r);return(!B.newDocument._deleted||r)&&(B.newDocument._deleted&&B.newDocument._deleted!==(null==r?void 0:r._deleted)||B.changedPath.length)||u("NoChange: No new data given. new document: "+T(e)+"; old document: "+T(r)+"."),Object.prototype.hasOwnProperty.call(c,i.property.name.validatedDocumentsCache)?c[i.property.name.validatedDocumentsCache].add(h+"-"+v):c[i.property.name.validatedDocumentsCache]=new Set([h+"-"+v]),B.newDocument},e}(),u=l;e.exports=s}()}],__webpack_module_cache__={};function __webpack_require__(e){var t=__webpack_module_cache__[e];if(void 0!==t)return t.exports;var r=__webpack_module_cache__[e]={exports:{}};return __webpack_modules__[e](r,r.exports,__webpack_require__),r.exports}__webpack_require__.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return __webpack_require__.d(t,{a:t}),t},__webpack_require__.d=(e,t)=>{for(var r in t)__webpack_require__.o(t,r)&&!__webpack_require__.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},__webpack_require__.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),__webpack_require__.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var __webpack_exports__={};(()=>{"use strict";__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,{Database:()=>g,default:()=>O});var e=__webpack_require__(0),t=__webpack_require__.n(e),r=__webpack_require__(1),n=__webpack_require__.n(r),a=__webpack_require__(2),o=__webpack_require__.n(a),c=__webpack_require__(4),i=__webpack_require__.n(c),s=__webpack_require__(6),l=__webpack_require__(7),u=__webpack_require__.n(l);const p=require("pouchdb");var _=__webpack_require__.n(p);const d=require("pouchdb-find");var m=__webpack_require__.n(d),f=__webpack_require__(9),y=__webpack_require__.n(f),b=__webpack_require__(8);function h(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 v(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?v(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 v(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 g=function(){function e(){}return e.preLoadService=function(){var t=n()(o().mark((function t(r){var a,c,s,l,p,d,f,y,b,v,g,O,x,P,w,E,k;return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(a=r.configuration.couchdb,c=r.services,Object.prototype.hasOwnProperty.call(c,"couchdb")||(c.couchdb={}),s=c.couchdb,Object.prototype.hasOwnProperty.call(s,"connector")||(l=a.model.property.name.special.id,p=a.model.property.name.special.revision,s.connector=_(),d=s.connector.prototype.bulkDocs,s.connector.plugin({bulkDocs:function(){var t=n()(o().mark((function t(r){var n,c,i,s,u,_,m,f,y,b,v,g,O,x,P,w,E,k,D=arguments;return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:for(c=D.length,i=Array(1<c?c-1:0),s=1;s<c;s++)i[s-1]=D[s];return u=0<i.length&&i[i.length-1]===e.toggleIDDetermining,_=u?!e.skipIDDetermining:e.skipIDDetermining,u&&i.pop(),m=!Array.isArray(r)&&null!==r&&"object"==typeof r&&l in r?[r]:r,null!=(n=a.connector.fetch)&&n.timeout&&(0===i.length||"object"!=typeof i[0])&&i.unshift({timeout:a.connector.fetch.timeout}),t.next=8,d.call.apply(d,[this,m].concat(i));case 8:f=t.sent,y=[],b=[],v=0,g=h(f);case 13:if((O=g()).done){t.next=36;break}if(x=O.value,"object"!=typeof m[v]){t.next=33;break}if(!(p in m[v])||"conflict"!==x.name||!["latest","upsert"].includes(m[v][p])){t.next=21;break}b.push(m[v]),y.push(v),t.next=33;break;case 21:if(!(l in m[v]&&a.ignoreNoChangeError&&"name"in x&&"forbidden"===x.name&&"message"in x&&x.message.startsWith("NoChange:"))){t.next=33;break}if(f[v]={id:m[v][l],ok:!0},_){t.next=33;break}if(!(p in m[v])||["latest","upsert"].includes(m[v][p])){t.next=28;break}t.t0=m[v][p],t.next=32;break;case 28:return t.next=30,this.get(f[v].id);case 30:t.t1=p,t.t0=t.sent[t.t1];case 32:f[v].rev=t.t0;case 33:v+=1;case 34:t.next=13;break;case 36:if(!b.length){t.next=43;break}return m=b,u&&i.push(e.toggleIDDetermining),t.next=41,this.bulkDocs.apply(this,[m].concat(i));case 41:for(P=t.sent,w=h(P);!(E=w()).done;)k=E.value,f[y.shift()]=k;case 43:return t.abrupt("return",f);case 44:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}()}),a.debug&&s.connector.debug.enable("*"),s.connector=s.connector.plugin(m())),Object.prototype.hasOwnProperty.call(s,"server")){t.next=36;break}s.server={},f=[],y=h([].concat(a.binary.runner));case 8:if((b=y()).done){t.next=34;break}v=b.value,g=h([].concat(v.location));case 11:if((O=g()).done){t.next=30;break}x=O.value,P=h([].concat(v.name));case 14:if((w=P()).done){t.next=26;break}return E=w.value,k=u().resolve(x,E),f.push(k),t.next=20,i().isFile(k);case 20:if(!t.sent){t.next=24;break}return v.binaryFilePath=k,s.server.runner=v,t.abrupt("break",26);case 24:t.next=14;break;case 26:if(!Object.prototype.hasOwnProperty.call(s.server,"runner")){t.next=28;break}return t.abrupt("break",30);case 28:t.next=11;break;case 30:if(!Object.prototype.hasOwnProperty.call(s.server,"runner")){t.next=32;break}return t.abrupt("break",34);case 32:t.next=8;break;case 34:if(Object.prototype.hasOwnProperty.call(s.server,"runner")){t.next=36;break}throw new Error('No binary file in one of the following locations found: "'+f.join('", "')+'".');case 36:case"end":return t.stop()}}),t)})));return function(){return t.apply(this,arguments)}}(),e.loadService=function(){var e=n()(o().mark((function e(t){var r,n,a,l,p,_,d,m,f,v,g,O,x,P,w,E,k,D,j,M,A,C,T,R,I,S,U,L,W,N,B,K,q,z,H,F,G,V,J,$,Y,X,Z,Q,ee,te,re,ne,ae,oe,ce,ie,se,le,ue,pe,_e,de,me,fe,ye,be,he,ve,ge,Oe,xe,Pe,we,Ee,ke,De,je,Me,Ae,Ce,Te,Re,Ie,Se,Ue,Le,We,Ne,Be,Ke,qe,ze,He,Fe,Ge,Ve,Je,$e;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=t.configuration,n=t.services,a=null,l=n.couchdb,!Object.prototype.hasOwnProperty.call(l.server,"runner")){e.next=10;break}return e.next=6,b.default.startServer(n,r);case 6:l.server.restart=b.default.restartServer,l.server.start=b.default.startServer,l.server.stop=b.default.stopServer,a=new Promise((function(e,t){l.server.resolve=e,l.server.reject=t}));case 10:if(!Object.prototype.hasOwnProperty.call(l,"connection")){e.next=12;break}return e.abrupt("return",{couchdb:a});case 12:if(p=i().stringFormat(r.couchdb.url,r.couchdb.user.name+":"+r.couchdb.user.password+"@"),!r.couchdb.ensureAdminPresence){e.next=44;break}return _=new l.connector(i().stringFormat(r.couchdb.url,"")+"/_users",b.default.getConnectorOptions(r)),e.prev=15,e.next=18,_.allDocs();case 18:return e.next=21,c.globalContext.fetch(i().stringFormat(r.couchdb.url,"")+"/"+l.server.runner.adminUserConfigurationPath+"/"+r.couchdb.user.name,{body:'"'+r.couchdb.user.password+'"',method:"PUT"});case 21:e.next=41;break;case 23:if(e.prev=23,e.t0=e.catch(15),"unauthorized"!==e.t0.name){e.next=40;break}return d=new l.connector(p+"/_users",b.default.getConnectorOptions(r)),e.prev=27,e.next=30,d.allDocs();case 30:e.next=35;break;case 32:e.prev=32,e.t1=e.catch(27);case 35:return e.prev=35,d.close(),e.finish(35);case 38:e.next=41;break;case 40:case 41:return e.prev=41,_.close(),e.finish(41);case 44:if(!r.couchdb.ensureUserPresence){e.next=79;break}m=0,f=[r.couchdb.security.admins,r.couchdb.security.members];case 46:if(!(m<f.length)){e.next=79;break}v=f[m],g=h(v.names);case 49:if((O=g()).done){e.next=76;break}return x=O.value,P=new l.connector(p+"/_users",b.default.getConnectorOptions(r)),e.prev=52,e.next=55,P.get("org.couchdb.user:"+x);case 55:e.next=71;break;case 57:if(e.prev=57,e.t2=e.catch(52),"not_found"!==e.t2.error){e.next=70;break}return e.prev=60,e.next=63,P.put(((w={})[r.couchdb.model.property.name.special.id]="org.couchdb.user:"+x,w.name=x,w.password=x,w.roles=[].concat(v.roles.includes(x+"s")?x+"s":[]),w.type="user",w));case 63:e.next=68;break;case 65:throw e.prev=65,e.t3=e.catch(60),new Error("Couldn't create missing user \""+x+'": '+i().represent(e.t3));case 68:e.next=71;break;case 70:throw new Error("Couldn't check for presence of user \""+x+'": '+i().represent(e.t2));case 71:return e.prev=71,P.close(),e.finish(71);case 74:e.next=49;break;case 76:m++,e.next=46;break;case 79:if(!r.couchdb.model.updateConfiguration){e.next=134;break}E=h(r.couchdb.backend.prefixes);case 81:if((k=E()).done){e.next=134;break}D=k.value,e.t4=o().keys(r.couchdb.backend.configuration);case 84:if((e.t5=e.t4()).done){e.next=132;break}if(j=e.t5.value,!Object.prototype.hasOwnProperty.call(r.couchdb.backend.configuration,j)){e.next=130;break}return M="/"+D+(D.trim()?"/":"")+j,A=""+p+M,C=r.couchdb.backend.configuration[j],T=void 0,e.prev=91,e.next=94,c.globalContext.fetch(A);case 94:T=e.sent,e.next=100;break;case 97:e.prev=97,e.t6=e.catch(91);case 100:if(!T){e.next=130;break}if(!T.ok){e.next=129;break}if(R=!0,"function"!=typeof T.text){e.next=115;break}return e.prev=104,e.t7=C,e.next=108,T["string"==typeof C?"text":"json"]();case 108:e.t8=e.sent,R=e.t7===e.t8,e.next=115;break;case 112:e.prev=112,e.t9=e.catch(104);case 115:if(!R){e.next=126;break}return e.prev=116,e.next=119,c.globalContext.fetch(A,{body:'"'+r.couchdb.backend.configuration[j]+'"',method:"PUT"});case 119:e.next=124;break;case 121:e.prev=121,e.t10=e.catch(116);case 124:e.next=127;break;case 126:case 127:e.next=130;break;case 129:case 130:e.next=84;break;case 132:e.next=81;break;case 134:return e.next=136,b.default.initializeConnection(n,r);case 136:if(I=r.couchdb.model.property.name.special.id,S=r.couchdb.model.property.name.special.type,!r.couchdb.ensureSecuritySettingsPresence){e.next=147;break}return e.prev=139,e.next=142,c.globalContext.fetch(p+"/"+r.couchdb.databaseName+"/_security",{body:JSON.stringify(r.couchdb.security),method:"PUT"});case 142:e.next=147;break;case 144:e.prev=144,e.t11=e.catch(139);case 147:if(delete(U=i().copy(r.couchdb.model)).property.defaultSpecification,delete U.entities,L=b.default.extendModels(r.couchdb.model),!r.couchdb.model.updateValidation){e.next=215;break}return e.next=154,s.promises.readFile(c.currentRequire.resolve("./databaseHelper"),{encoding:r.core.encoding,flag:"r"});case 154:W=e.sent,N=h([{description:"Model specification",methodName:"validateDocumentUpdate",name:"validation",serializedParameter:JSON.stringify(U)+", "+JSON.stringify(L)},{description:"Authorisation",methodName:"authenticate",name:"authentication",serializedParameter:JSON.stringify(b.default.determineAllowedModelRolesMapping(r.couchdb.model))+", '"+I+"', '"+S+"', '"+r.couchdb.model.property.name.special.designDocumentNamePrefix+"'"}]);case 156:if((B=N()).done){e.next=171;break}K=B.value,q="function(...parameters) {\n return require('helper').default."+K.methodName+"(...parameters.concat(["+K.serializedParameter+"]))\n}",e.prev=159,new Function("return "+q),e.next=166;break;case 163:throw e.prev=163,e.t12=e.catch(159),new Error("Generated "+K.name+' code "'+q+"\" doesn't compile: "+i().represent(e.t12));case 166:return r.core.debug,e.next=169,b.default.ensureValidationDocumentPresence(l.connection,K.name,{helper:W,validate_doc_update:q},K.description,!0,I,U.property.name.special.designDocumentNamePrefix);case 169:e.next=156;break;case 171:z=0,H=Object.entries(L);case 172:if(!(z<H.length)){e.next=215;break}F=H[z],G=F[0],V=F[1],J=0,$=Object.entries(V);case 175:if(!(J<$.length)){e.next=212;break}if(Y=$[J],X=Y[0],Z=Y[1],![U.property.name.special.constraint.execution,U.property.name.special.constraint.expression].includes(X)){e.next=193;break}Q=h([].concat(Z));case 179:if((ee=Q()).done){e.next=191;break}if(!(te=ee.value).description){e.next=189;break}e.prev=182,new Function("return "+te.description),e.next=189;break;case 186:throw e.prev=186,e.t13=e.catch(182),new Error('Specified constraint description "'+te.description+'" for model "'+G+'" doesn\'t compile: "'+i().represent(e.t13)+'".');case 189:e.next=179;break;case 191:e.next=209;break;case 193:re=Z,ne=h(["conflictingConstraintExpression","conflictingConstraintExecution","constraintExpression","constraintExecution"]);case 195:if((ae=ne()).done){e.next=209;break}if(oe=ae.value,null===re||"object"!=typeof re){e.next=207;break}if(null==(ce=re[oe])||!ce.description){e.next=207;break}e.prev=200,new Function(ce.description),e.next=207;break;case 204:throw e.prev=204,e.t14=e.catch(200),new Error('Specified constraint description "'+ce.description+'" for model "'+G+'" in property "'+X+'" as "'+oe+'" doesn\'t compile: "'+i().represent(e.t14)+'".');case 207:e.next=195;break;case 209:J++,e.next=175;break;case 212:z++,e.next=172;break;case 215:if(!r.couchdb.model.autoMigrationPath){e.next=307;break}return ie={},e.next=219,i().isDirectory(u().resolve(r.couchdb.model.autoMigrationPath));case 219:if(!e.sent){e.next=259;break}return e.t15=h,e.next=223,i().walkDirectoryRecursively(u().resolve(r.couchdb.model.autoMigrationPath),r.couchdb.debug?i().noop:function(e){return"debug"!==e.name});case 223:e.t16=e.sent,se=(0,e.t15)(e.t16);case 225:if((le=se()).done){e.next=259;break}if(ue=le.value,pe=u().extname(ue.name),_e=u().basename(ue.name,pe),".json"!==pe){e.next=256;break}return de=void 0,e.prev=231,e.t17=JSON,e.next=235,s.promises.readFile(ue.path,{encoding:r.core.encoding,flag:"r"});case 235:e.t18=e.sent,de=e.t17.parse.call(e.t17,e.t18),e.next=242;break;case 239:throw e.prev=239,e.t19=e.catch(231),new Error('Parsing document "'+ue.path+'" to include by automigration of has failed: '+i().represent(e.t19));case 242:return de[I]=_e,de[r.couchdb.model.property.name.special.revision]="upsert",e.prev=244,e.next=247,l.connection.put(de);case 247:e.next=253;break;case 249:throw e.prev=249,e.t20=e.catch(244),null!=(me=e.t20.forbidden)&&me.startsWith("NoChange:"),new Error('Migrating document "'+de[I]+'" of type "'+de[S]+'" has failed: '+i().represent(e.t20));case 253:e.next=257;break;case 256:".js"===u().extname(ue.name)&&(ie[ue.path]=(0,c.currentRequire)(ue.path).default);case 257:e.next=225;break;case 259:return e.t21=h,e.next=262,l.connection.allDocs({include_docs:!0});case 262:e.t22=e.sent.rows,fe=(0,e.t21)(e.t22);case 264:if((ye=fe()).done){e.next=307;break}if("string"==typeof(be=ye.value).id&&be.id.startsWith(r.couchdb.model.property.name.special.designDocumentNamePrefix)){e.next=305;break}he=be.doc,(ve=i().copy(he))[r.couchdb.model.property.name.special.strategy]="migrate",ge=h(Object.keys(ie).sort());case 271:if((Oe=ge()).done){e.next=284;break}xe=Oe.value,Pe=null,e.prev=274,Pe=ie[xe](ve,{configuration:r,databaseHelper:y(),idName:I,migrater:ie,models:L,modelConfiguration:U,selfFilePath:xe,services:n,tools:i(),typeName:S}),e.next=281;break;case 278:throw e.prev=278,e.t23=e.catch(274),new Error('Running migrater "'+xe+'" in document '+b.default.mayStripRepresentation(he,r.couchdb.maximumRepresentationTryLength,r.couchdb.maximumRepresentationLength)+'" failed: '+i().represent(e.t23));case 281:Pe&&(ve=Pe);case 282:e.next=271;break;case 284:e.prev=284,y().validateDocumentUpdate(i().copy(ve),i().copy(he),{db:r.couchdb.databaseName,name:r.couchdb.user.name,roles:["_admin"]},i().copy(r.couchdb.security),U,L),e.next=296;break;case 288:if(e.prev=288,e.t24=e.catch(284),!Object.prototype.hasOwnProperty.call(e.t24,"forbidden")){e.next=295;break}return e.t24.forbidden.startsWith("NoChange:"),e.abrupt("continue",305);case 295:throw e.t24;case 296:return e.prev=296,e.next=299,l.connection.put(ve);case 299:e.next=304;break;case 301:throw e.prev=301,e.t25=e.catch(296),new Error('Replaceing auto migrated document "'+ve[I]+'" has failed: '+i().represent(e.t25));case 304:case 305:e.next=264;break;case 307:if(!r.couchdb.createGenericFlatIndex||!r.couchdb.model.autoMigrationPath){e.next=362;break}return e.next=310,l.connection.getIndexes();case 310:we=e.sent.indexes,Ee=0,ke=Object.entries(L);case 312:if(!(Ee<ke.length)){e.next=343;break}if(De=ke[Ee],je=De[0],Me=De[1],!new RegExp(r.couchdb.model.property.name.typeRegularExpressionPattern.public).test(je)){e.next=340;break}return e.next=317,l.connection.createIndex({index:{ddoc:je+"-GenericIndex",fields:[S],name:je+"-GenericIndex"}});case 317:Ae=h(b.default.determineGenericIndexablePropertyNames(r.couchdb.model,Me));case 318:if((Ce=Ae()).done){e.next=340;break}Te=Ce.value,Re=je+"-"+Te+"-GenericIndex",Ie=-1,Se=0,Ue=h(we);case 324:if((Le=Ue()).done){e.next=332;break}if(Le.value.name!==Re){e.next=329;break}return Ie=Se,e.abrupt("break",332);case 329:Se+=1;case 330:e.next=324;break;case 332:if(-1!==Ie){e.next=337;break}return e.next=335,l.connection.createIndex({index:{ddoc:Re,fields:[S,Te],name:Re}});case 335:e.next=338;break;case 337:we.slice(Se,1);case 338:e.next=318;break;case 340:Ee++,e.next=312;break;case 343:We=h(we);case 344:if((Ne=We()).done){e.next=362;break}if(!(Be=Ne.value).name.endsWith("-GenericIndex")){e.next=360;break}Ke=!1,qe=0,ze=Object.entries(L);case 349:if(!(qe<ze.length)){e.next=357;break}if(He=ze[qe],Fe=He[0],Ge=He[1],!Be.name.startsWith(Fe+"-")){e.next=354;break}for(Ve=h(b.default.determineGenericIndexablePropertyNames(r.couchdb.model,Ge));!(Je=Ve()).done;)$e=Je.value,[Fe+"-"+$e+"-GenericIndex",Fe+"-GenericIndex"].includes(Be.name)&&(Ke=!0);return e.abrupt("break",357);case 354:qe++,e.next=349;break;case 357:if(Ke){e.next=360;break}return e.next=360,l.connection.deleteIndex(Be);case 360:e.next=344;break;case 362:if(!r.couchdb.model.triggerInitialCompaction){e.next=371;break}return e.prev=363,e.next=366,l.connection.compact();case 366:e.next=371;break;case 368:e.prev=368,e.t26=e.catch(363);case 371:return e.abrupt("return",{couchdb:a});case 372:case"end":return e.stop()}}),e,null,[[15,23,41,44],[27,32,35,38],[52,57,71,74],[60,65],[91,97],[104,112],[116,121],[139,144],[159,163],[182,186],[200,204],[231,239],[244,249],[274,278],[284,288],[296,301],[363,368]])})));return function(){return e.apply(this,arguments)}}(),e.postLoadService=function(r){var a=r.configuration.couchdb,c=r.pluginAPI,s=r.services.couchdb,l=0;setInterval((function(){0<l&&(l=0)}),3e4);var u=i().debounce(n()(o().mark((function p(){return o().wrap((function(p){for(;;)switch(p.prev=p.next){case 0:return s.changesStream&&s.changesStream.cancel(),s.changesStream=s.connection.changes(i().extend(!0,i().copy(a.changesStream),e.additionalChangesStreamOptions)),s.changesStream.on("error",n()(o().mark((function e(){return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(3<(l+=1))){e.next=9;break}return l=0,s.changesStream.cancel(),e.next=7,s.server.restart(r);case 7:e.next=10;break;case 9:case 10:u();case 11:case"end":return e.stop()}}),e)})))),p.next=5,c.callStack(t()({},r,{data:s.changesStream,hook:"couchdbInitializeChangesStream"}));case 5:case"end":return p.stop()}}),p)}))));return a.attachAutoRestarter&&u(),Promise.resolve()},e.shouldExit=function(){var e=n()(o().mark((function e(t){var r,n,a;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.configuration,n=t.services,e.next=3,b.default.stopServer(n,r);case 3:return delete n.couchdb,a="log.txt",e.next=7,i().isFile(a);case 7:if(!e.sent){e.next=10;break}return e.next=10,s.promises.unlink(a);case 10:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),e}();g.additionalChangesStreamOptions={},g.skipIDDetermining=!0,g.toggleIDDetermining=Symbol("toggleIDDetermining");const O=g})(),module.exports=__webpack_exports__})();
1
+ (()=>{var __webpack_modules__=[e=>{"use strict";e.exports=require("@babel/runtime/helpers/extends")},e=>{"use strict";e.exports=require("@babel/runtime/helpers/asyncToGenerator")},e=>{"use strict";e.exports=require("@babel/runtime/regenerator")},e=>{"use strict";e.exports=require("child_process")},e=>{"use strict";e.exports=require("clientnode")},e=>{"use strict";e.exports=require("pouchdb/node_modules/node-fetch/lib/index.js")},e=>{"use strict";e.exports=require("fs")},e=>{"use strict";e.exports=require("path")},(__unused_webpack_module,__webpack_exports__,__webpack_require__)=>{"use strict";__webpack_require__.d(__webpack_exports__,{default:()=>__WEBPACK_DEFAULT_EXPORT__});var _babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__(0),_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default=__webpack_require__.n(_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__),_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1__=__webpack_require__(1),_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default=__webpack_require__.n(_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1__),_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2__=__webpack_require__(2),_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default=__webpack_require__.n(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2__),child_process__WEBPACK_IMPORTED_MODULE_3__=__webpack_require__(3),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__(5),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__);function _createForOfIteratorHelperLoose(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=_unsupportedIterableToArray(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(e,t){if(e){if("string"==typeof e)return _arrayLikeToArray(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?_arrayLikeToArray(e,t):void 0}}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}clientnode__WEBPACK_IMPORTED_MODULE_4__.globalContext.fetch=node_fetch__WEBPACK_IMPORTED_MODULE_5___default();var Helper=function(){function Helper(){}return Helper.getConnectorOptions=function(e){return e.couchdb.connector.fetch?{fetch:function(t,r){return clientnode__WEBPACK_IMPORTED_MODULE_4__.globalContext.fetch(t,clientnode__WEBPACK_IMPORTED_MODULE_4___default().extend(!0,clientnode__WEBPACK_IMPORTED_MODULE_4___default().copy(e.couchdb.connector.fetch),r||{}))}}:{fetch:function(e,t){return clientnode__WEBPACK_IMPORTED_MODULE_4__.globalContext.fetch(e,t)}}},Helper.mayStripRepresentation=function(e,t,r){var n=clientnode__WEBPACK_IMPORTED_MODULE_4___default().represent(e);return n.length<=t?n.length>r?n.substring(0,r-3)+"...":n:"DOCUMENT IS TOO BIG TO REPRESENT"},Helper.ensureValidationDocumentPresence=function(){var e=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function e(t,r,n,a,o,c,i){var s,l,u;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return void 0===o&&(o=!0),void 0===c&&(c="_id"),void 0===i&&(i="_design/"),l=_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()(((s={})[c]=""+i+r,s.language="javascript",s),n),e.prev=4,e.next=7,t.get(""+i+r);case 7:return u=e.sent,l._rev=u._rev,e.next=11,t.put(l);case 11:case 20:e.next=26;break;case 14:return e.prev=14,e.t0=e.catch(4),o&&e.t0.error,e.prev=17,e.next=20,t.put(l);case 23:throw e.prev=23,e.t1=e.catch(17),new Error(a+" couldn't be installed/updated: \""+clientnode__WEBPACK_IMPORTED_MODULE_4___default().represent(e.t1)+'".');case 26:case"end":return e.stop()}}),e,null,[[4,14],[17,23]])})));return function(){return e.apply(this,arguments)}}(),Helper.initializeConnection=function(){var e=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function e(t,r){var n,a,o,c,i,s;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(n=clientnode__WEBPACK_IMPORTED_MODULE_4___default().stringFormat(r.couchdb.url,r.couchdb.user.name+":"+r.couchdb.user.password+"@")+"/"+r.couchdb.databaseName,t.couchdb.connection=new t.couchdb.connector(n,Helper.getConnectorOptions(r)),t.couchdb.connection.setMaxListeners(1/0),a=r.couchdb.model.property.name.special.id,o=r.couchdb.model.property.name.special.revision,c=function(){var e=s.value,n=t.couchdb.connection[e].bind(t.couchdb.connection);t.couchdb.connection[e]=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function e(t){var c,i,s,l,u,p=arguments;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(e.prev=0,c=p.length,i=Array(1<c?c-1:0),s=1;s<c;s++)i[s-1]=p[s];return e.next=4,n.apply(void 0,[t].concat(i));case 4:return e.abrupt("return",e.sent);case 7:if(e.prev=7,e.t0=e.catch(0),!(a in t&&r.couchdb.ignoreNoChangeError&&"forbidden"===e.t0.name&&null!=(l=e.t0.message)&&l.startsWith("NoChange:"))){e.next=21;break}if(u={id:t[a],ok:!0},!(o in t)||["latest","upsert"].includes(t[o])){e.next=15;break}e.t1=t[o],e.next=19;break;case 15:return e.next=17,this.get(u.id);case 17:e.t2=o,e.t1=e.sent[e.t2];case 19:return u.rev=e.t1,e.abrupt("return",u);case 21:throw e.t0;case 22:case"end":return e.stop()}}),e,this,[[0,7]])})))},i=_createForOfIteratorHelperLoose(["post","put"]);!(s=i()).done;)c();return e.prev=7,e.next=10,clientnode__WEBPACK_IMPORTED_MODULE_4___default().checkReachability(n);case 10:e.next=17;break;case 12:return e.prev=12,e.t0=e.catch(7),e.next=17,clientnode__WEBPACK_IMPORTED_MODULE_4__.globalContext.fetch(n,{method:"PUT"});case 17:return e.abrupt("return",t);case 18:case"end":return e.stop()}}),e,null,[[7,12]])})));return function(){return e.apply(this,arguments)}}(),Helper.startServer=function(){function startServer(){return _startServer.apply(this,arguments)}var _startServer=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function _callee4(services,configuration){var _this=this;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(_context4){for(;;)switch(_context4.prev=_context4.next){case 0:if(!Object.prototype.hasOwnProperty.call(services.couchdb.server.runner,"configurationFile")){_context4.next=12;break}return _context4.prev=1,_context4.next=4,fs__WEBPACK_IMPORTED_MODULE_6__.promises.mkdir(path__WEBPACK_IMPORTED_MODULE_7___default().dirname(services.couchdb.server.runner.configurationFile.path),{recursive:!0});case 4:_context4.next=10;break;case 6:if(_context4.prev=6,_context4.t0=_context4.catch(1),"EEXIST"===_context4.t0.code){_context4.next=10;break}throw _context4.t0;case 10:return _context4.next=12,fs__WEBPACK_IMPORTED_MODULE_6__.promises.writeFile(services.couchdb.server.runner.configurationFile.path,services.couchdb.server.runner.configurationFile.content,{encoding:configuration.core.encoding});case 12:return services.couchdb.server.process=(0,child_process__WEBPACK_IMPORTED_MODULE_3__.spawn)("default"===configuration.couchdb.binary.memoryInMegaByte?services.couchdb.server.runner.binaryFilePath:configuration.couchdb.binary.nodePath,("default"===configuration.couchdb.binary.memoryInMegaByte?[]:["--max-old-space-size="+configuration.couchdb.binary.memoryInMegaByte,services.couchdb.server.runner.binaryFilePath]).concat(services.couchdb.server.runner.arguments?services.couchdb.server.runner.arguments:[]),{cwd:eval("process").cwd(),env:Object.prototype.hasOwnProperty.call(services.couchdb.server.runner,"environment")?_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({},eval("process").env,services.couchdb.server.runner.environment):eval("process").env,shell:!0,stdio:"inherit"}),new Promise((function(e,t){for(var r,n,a=_createForOfIteratorHelperLoose(clientnode__WEBPACK_IMPORTED_MODULE_4__.CloseEventNames);!(r=a()).done;)n=r.value,services.couchdb.server.process.on(n,clientnode__WEBPACK_IMPORTED_MODULE_4___default().getProcessCloseHandler(e,t,{process:services.couchdb.server.process,reason:n}))})).then((function(e){var t,r;null!=(t=services.couchdb)&&null!=(r=t.server)&&r.resolve&&services.couchdb.server.resolve.call(_this,e)}),(function(e){var t,r;null!=(t=services.couchdb)&&null!=(r=t.server)&&r.resolve&&services.couchdb.server.reject.call(_this,e)})),_context4.next=16,clientnode__WEBPACK_IMPORTED_MODULE_4___default().checkReachability(clientnode__WEBPACK_IMPORTED_MODULE_4___default().stringFormat(configuration.couchdb.url,""),{wait:!0});case 16:case"end":return _context4.stop()}}),_callee4,null,[[1,6]])})));return startServer}(),Helper.restartServer=function(){var e=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function e(t){var r,n,a,o,c,i;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.configuration,n=t.pluginAPI,a=t.services,o=a.couchdb.server,c=o.resolve,i=o.reject,o.resolve=o.reject=clientnode__WEBPACK_IMPORTED_MODULE_4___default().noop,e.next=7,Helper.stopServer(a,r);case 7:return o.resolve=c,o.reject=i,e.next=11,Helper.startServer(a,r);case 11:return Helper.initializeConnection(a,r),e.next=14,n.callStack(_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({},t,{hook:"restartCouchdb"}));case 14:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),Helper.stopServer=function(){var e=_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().mark((function e(t,r){var n,a;return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.couchdb,a=r.couchdb,n.connection&&n.connection.close(),n.server.process&&n.server.process.kill("SIGINT"),e.next=6,clientnode__WEBPACK_IMPORTED_MODULE_4___default().checkUnreachability(clientnode__WEBPACK_IMPORTED_MODULE_4___default().stringFormat(a.url,""),{wait:!0});case 6:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),Helper.determineAllowedModelRolesMapping=function(e){for(var t=e.property.name.special.allowedRoles,r={},n=Helper.extendModels(e),a=0,o=Object.entries(n);a<o.length;a++){var c=o[a],i=c[0],s=c[1];if(Object.prototype.hasOwnProperty.call(s,t)){r[i]=_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({properties:{}},Helper.normalizeAllowedRoles(s[t]));for(var l=0,u=Object.entries(s);l<u.length;l++){var p=u[l],_=p[0],d=p[1];null!==d&&"object"==typeof d&&d.allowedRoles&&(r[i].properties[_]=Helper.normalizeAllowedRoles(d.allowedRoles))}}else r[i]={properties:{},read:[],write:[]}}return r},Helper.determineGenericIndexablePropertyNames=function(e,t){var r=e.property.name.special;return Object.keys(t).filter((function(n){return null!==t[n]&&"object"==typeof t[n]&&(Object.prototype.hasOwnProperty.call(t[n],"index")&&t[n].index||!(Object.prototype.hasOwnProperty.call(t[n],"index")&&!t[n].index||e.property.name.reserved.concat(r.additional,r.allowedRoles,r.attachment,r.conflict,r.constraint.execution,r.constraint.expression,r.deleted,r.deletedConflict,r.extend,r.id,r.maximumAggregatedSize,r.minimumAggregatedSize,r.oldType,r.revision,r.revisions,r.revisionsInformation,r.type).includes(n)||t[n].type&&("string"==typeof t[n].type&&t[n].type.endsWith("[]")||Array.isArray(t[n].type)&&t[n].type.length&&Array.isArray(t[n].type[0])||Object.prototype.hasOwnProperty.call(e.entities,t[n].type))))})).concat(r.id,r.revision).sort()},Helper.extendModel=function(e,t,r){if(void 0===r&&(r="_extends"),"_base"===e)return t[e];if(Object.prototype.hasOwnProperty.call(t,"_base")&&(Object.prototype.hasOwnProperty.call(t[e],r)&&t[e][r]?t[e][r]=["_base"].concat(t[e][r]):t[e][r]="_base"),Object.prototype.hasOwnProperty.call(t[e],r)){for(var n,a,o=_createForOfIteratorHelperLoose([].concat(t[e][r]));!(n=o()).done;)a=n.value,t[e]=clientnode__WEBPACK_IMPORTED_MODULE_4___default().extend(!0,clientnode__WEBPACK_IMPORTED_MODULE_4___default().copy(Helper.extendModel(a,t,r)),t[e]);delete t[e][r]}return t[e]},Helper.extendModels=function(e){for(var t,r=e.property.name.special,n={},a=0,o=Object.keys(e.entities);a<o.length;a++){if(t=o[a],!new RegExp(e.property.name.typeRegularExpressionPattern.public).test(t)&&!new RegExp(e.property.name.typeRegularExpressionPattern.private).test(t))throw new Error('Model names have to match "'+e.property.name.typeRegularExpressionPattern.public+'" or "'+e.property.name.typeRegularExpressionPattern.private+'" for private one (given name: "'+t+'").');n[t]=Helper.extendModel(t,e.entities,r.extend)}for(var c,i=0,s=Object.values(n);i<s.length;i++){c=s[i];for(var l=0,u=Object.entries(c);l<u.length;l++){var p=u[l],_=p[0],d=p[1];if(_===r.attachment)for(var m=0,f=Object.entries(d);m<f.length;m++){var y=f[m],b=y[0],h=y[1];d[b]=clientnode__WEBPACK_IMPORTED_MODULE_4___default().extend(!0,clientnode__WEBPACK_IMPORTED_MODULE_4___default().copy(e.property.defaultSpecification),h)}else[r.allowedRoles,r.constraint.execution,r.constraint.expression,r.extend,r.maximumAggregatedSize,r.minimumAggregatedSize,r.oldType].includes(_)||(c[_]=clientnode__WEBPACK_IMPORTED_MODULE_4___default().extend(!0,clientnode__WEBPACK_IMPORTED_MODULE_4___default().copy(e.property.defaultSpecification),d))}}return n},Helper.normalizeAllowedRoles=function(e){if(Array.isArray(e))return{read:e,write:e};if("object"==typeof e){for(var t,r={read:[],write:[]},n=0,a=Object.keys(r);n<a.length;n++)t=a[n],Object.prototype.hasOwnProperty.call(e,t)&&(Array.isArray(e[t])?r[t]=e[t]:r[t]=[e[t]]);return r}return{read:[e],write:[e]}},Helper}();const __WEBPACK_DEFAULT_EXPORT__=Helper},e=>{!function(){"use strict";function t(){return(t=r()?Reflect.construct.bind():function(e,t,r){var a=[null];a.push.apply(a,t);var o=new(Function.bind.apply(e,a));return r&&n(o,r.prototype),o}).apply(null,arguments)}function r(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function n(e,t){return n=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},n(e,t)}function a(){return a=Object.assign?Object.assign.bind():function(e){for(var t,r=1;r<arguments.length;r++)for(var n in t=arguments[r])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e},a.apply(this,arguments)}function o(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return c(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?c(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 c(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 i={d:function(e,t){for(var r in t)i.o(t,r)&&!i.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},o:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r:function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},s={};i.r(s),i.d(s,{DatabaseHelper:function(){return l},default:function(){return u}});var l=function(){function e(){}return e.authenticate=function(e,t,r,n,a,c,i,s,l){var u;void 0===t&&(t=null),void 0===r&&(r={}),void 0===n&&(n={admins:{names:[],roles:[]},members:{names:[],roles:[]}}),void 0===c&&(c="_id"),void 0===i&&(i="-type"),void 0===s&&(s="_design/"),void 0===l&&(l=!1);var p=null!==(u=e[i])&&void 0!==u?u:t&&t[i];if(!p)return!0;var _=l?"read":"write",d={properties:{},read:["_admin","readonlyadmin"],write:["_admin"]};Object.prototype.hasOwnProperty.call(e,c)&&e[c].startsWith(s)&&d.read.push("readonlymember");var m,f="Current user doesn't own any role";if(r)if("name"in r||(r.name='"unknown"'),null!=(m=r.roles)&&m.length){if(a&&p&&Object.prototype.hasOwnProperty.call(a,p)){for(var y,b,h=a[p],v=o(["read","write"]);!(y=v()).done;)d[b=y.value]=d[b].concat(h[b]||[]);d.properties=h.properties}for(var g,O,x=d[_],P=o(r.roles);!(g=P()).done;)if(O=g.value,x.includes(O))return!0;f='Current user "'+r.name+'" owns the following roles: "'+r.roles.join('", "')+'"'}else f='Current user "'+r.name+"\" doesn't own any role";throw{unauthorized:"Only users with a least on of these roles are allowed to perform requested "+_+' action: "'+[].concat(d[_]).join('", "')+'". '+f+"."}},e.validateDocumentUpdate=function(e,r,n,c,i,s,l){void 0===s&&(s={});var u=function(e,t,r){var n;void 0===t&&(t="forbidden"),void 0===r&&(r={});for(var a=((n={})[t]=e,n.message=e,n.name=t,n),o=0,c=Object.entries(r);o<c.length;o++){var i=c[o],s=i[0],l=i[1];a[s]=l}throw a},p=new Date,_=Date.UTC(p.getUTCFullYear(),p.getUTCMonth(),p.getUTCDate(),p.getUTCHours(),p.getUTCMinutes(),p.getUTCSeconds(),p.getUTCMilliseconds())/1e3,d=!i.dateTimeFormat.startsWith("iso"),m=i.property.name.special,f=m.id,y=m.revision,b=m.type;r&&r[b]&&!e[b]&&(e[b]=r[b]);var h="",v="",g=function(){h=Object.prototype.hasOwnProperty.call(e,f)?e[f]:"",v=Object.prototype.hasOwnProperty.call(e,y)?e[y]:""};if(g(),Object.prototype.hasOwnProperty.call(c,i.property.name.validatedDocumentsCache)&&c[i.property.name.validatedDocumentsCache].has(h+"-"+v))return c[i.property.name.validatedDocumentsCache].delete(h+"-"+v),e;["latest","upsert"].includes(v)&&(r&&Object.prototype.hasOwnProperty.call(r,y)?v=e[y]=r[y]:"latest"===v?u("Revision: No old document available to update."):delete e[y]);var O=i.updateStrategy;Object.prototype.hasOwnProperty.call(e,m.strategy)&&(O=e[m.strategy],delete e[m.strategy]);var x,P={};if("migrate"===O)for(var w=0,E=Object.entries(s);w<E.length;w++){var k=E[w],D=k[0],j=k[1];if(Object.prototype.hasOwnProperty.call(j,m.oldType)&&![null,void 0].includes(j[m.oldType]))for(var M,A,C=o([].concat(j[m.oldType]));!(M=C()).done;)A=M.value,P[A]=D}l?x=l:JSON&&Object.prototype.hasOwnProperty.call(JSON,"stringify")?x=function(e){return JSON.stringify(e,null,4)}:u('Needed "serializer" is not available.');var T=function(e){return e instanceof Error?""+e:x(e)},R=function(e){return"string"==typeof e?e.trim():""},I=function(e){if(d)null!==e&&"number"!=typeof e&&(e=new Date(e),e=Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate(),e.getUTCHours(),e.getUTCMinutes(),e.getUTCSeconds(),e.getUTCMilliseconds())/1e3);else if(null!==e){e=new Date("number"!=typeof e||isNaN(e)?e:1e3*e);try{e=e.toISOString()}catch(e){}}return e},S=function(e,t,r){if(r.fileName){if(r.fileName.value)return r.fileName.value===t;if(r.fileName.regularExpressionPattern)return new RegExp(r.fileName.regularExpressionPattern).test(t)}return e===t},U=function(t,r){if(r||(r=e[m.attachment]),t){for(var n,a=0,o=Object.keys(r);a<o.length;a++)if((n=o[a]).startsWith(t))return n}else{var c=Object.keys(r);if(c.length)return c[0]}return null},L=function(e,r,n){void 0===r&&(r=!1),void 0===n&&(n={});var o=R(e);if(o){var c,i=(r?"return ":"")+o,s=a({},N,{code:i},n),l=Object.keys(s);try{c=t(Function,l.concat([i]))}catch(e){u(T(e),"compilation",{code:i,error:e,scope:s})}var p={code:i,result:void 0,scope:s};try{p.result=c.apply(void 0,l.map((function(e){return s[e]})))}catch(e){u(T(e),"runtime",{code:i,error:e,scope:s})}return p}u("No expression to evaluate provided.","empty")},W=function(e,r,n){void 0===n&&(n=[]);var a=n.length?" in "+n.join(" -> "):"",c=[],l=function(){Object.prototype.hasOwnProperty.call(e,b)||(r&&Object.prototype.hasOwnProperty.call(r,b)&&["fillUp","migrate"].includes(O)?e[b]=r[b]:u('Type: You have to specify a model type via property "'+b+'"'+a+".")),n.length||new RegExp(i.property.name.typeRegularExpressionPattern.public).test(e[b])||u('TypeName: You have to specify a model type which matches "'+i.property.name.typeRegularExpressionPattern.public+'" as public type (given "'+e[b]+'")'+a+"."),Object.prototype.hasOwnProperty.call(s,e[b])||(Object.prototype.hasOwnProperty.call(P,e[b])?e[b]=P[e[b]]:u('Model: Given model "'+e[b]+'" is not specified'+a+"."))};l();var p=e[b],_=s[p],h=null;Object.prototype.hasOwnProperty.call(_,m.additional)&&_[m.additional]&&(h=_[m.additional]);var v=function c(i,s,l,d,m){void 0===m&&(m=["constraintExecution","constraintExpression"]);for(var f,y,b=o(m);!(f=b()).done;)if(y=f.value,Object.prototype.hasOwnProperty.call(l,y)){var h,v=void 0;try{v=L(l[y].evaluation,y.endsWith("Expression"),{checkPropertyContent:c,model:_,modelName:p,name:s,type:y,newDocument:e,newValue:i,oldDocument:r,oldValue:d,parentNames:n,pathDescription:a,propertySpecification:l})}catch(s){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(s)&&u('Compilation: Hook "'+y+'" has invalid code "'+s.code+'": "'+s.message+'"'+a+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(s)&&u('Runtime: Hook "'+y+'" has throw an error with code "'+s.code+'": "'+s.message+'"'+a+"."),!Object.prototype.hasOwnProperty.call(s,"empty"))throw s}if(null==(h=v)||!h.result){var g=R(l[y].description);u(y.charAt(0).toUpperCase()+(y.substring(1)+": ")+(g?t(Function,Object.keys(v.scope).concat(["return "+g])).apply(void 0,Object.values(v.scope)):'Property "'+s+'" should satisfy constraint "'+v.code+'" (given "'+T(i)+'")'+a+"."))}}},x=function(e,t,r,c){void 0===c&&(c=null);var i=[],l=[].concat(r.type?r.type:[]);"object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype&&!Object.prototype.hasOwnProperty.call(e,b)&&1===l.length&&Object.prototype.hasOwnProperty.call(s,l[0])&&(e[b]=l[0]);for(var p,_,m=!1,y=o(l);!(p=y()).done;)if(_=p.value,Object.prototype.hasOwnProperty.call(s,_)){if("object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype&&Object.prototype.hasOwnProperty.call(e,b)&&e[b]!==_&&"migrate"===O&&1===l.length&&(e[b]=_,i=n.concat(t,"migrate nested object type")),"object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype&&Object.prototype.hasOwnProperty.call(e,b)&&e[b]===_){var h=W(e,c,n.concat(t));if(h.changedPath.length&&(i=h.changedPath),e=h.newDocument,T(e)===T({}))return{newValue:null,changedPath:i};m=!0;break}1===l.length&&u('NestedType: Under key "'+t+'" isn\'t of type "'+_+'" (given "'+T(e)+'" of type '+typeof e+")"+a+".")}else if("DateTime"===_){var g=e;if(e=I(e),!(d&&("number"!=typeof e||isNaN(e))||!d&&"string"!=typeof e)){m=!0;break}1===l.length&&u('PropertyType: Property "'+t+'" isn\'t of (valid) type "DateTime" (given "'+T(g).replace(/^"/,"").replace(/"$/,"")+'" of type "'+typeof g+'")'+a+".")}else if(["boolean","integer","number","string"].includes(_)){if(!("number"==typeof e&&isNaN(e)||"integer"!==_&&typeof e!==_||"integer"===_&&parseInt(e,10)!==e)){m=!0;break}1===l.length&&u('PropertyType: Property "'+t+'" isn\'t of (valid) type "${type}" (given "'+T(e)+'" of type "'+typeof e+'")'+a+".")}else if("string"==typeof _&&_.startsWith("foreignKey:")){var x=s[_.substring(11)][f].type;if(x===typeof e){m=!0;break}1===l.length&&u('PropertyType: Foreign key property "'+t+'" isn\'t of type "'+x+'" (given "'+T(e)+'" of type "'+typeof e+'")'+a+".")}else{if("any"===_||T(e)===T(_)){m=!0;break}1===l.length&&u('PropertyType: Property "'+t+'" isn\'t value "'+_+'" (given "'+T(e).replace(/^"/,"").replace(/"$/,"")+'" of type "'+typeof e+'")'+a+".")}if(m||u('PropertyType: None of the specified types "'+l.join('", "')+'" for property "'+t+'" matches value "'+T(e).replace(/^"/,"").replace(/"$/,"")+e+'" of type "'+typeof e+'")'+a+"."),"string"==typeof e&&(![null,void 0].includes(r.minimumLength)&&e.length<r.minimumLength&&u('MinimalLength: Property "'+t+'" must have minimal length '+r.minimumLength+" (given "+e+" with length i"+e.length+") "+a+"."),![null,void 0].includes(r.maximumLength)&&e.length>r.maximumLength&&u('MaximalLength: Property "'+t+'" must have maximal length '+r.maximumLength+" (given "+e+" with length "+e.length+")"+a+".")),"number"==typeof e&&(![null,void 0].includes(r.minimum)&&e<r.minimum&&u('Minimum: Property "'+t+'" (type '+r.type+") must satisfy a minimum of "+r.minimum+" (given "+e+" is too low)"+a+"."),![null,void 0].includes(r.maximum)&&e>r.maximum&&u('Maximum: Property "'+t+'" (type '+r.type+") must satisfy a maximum of "+r.maximum+" (given "+e+" is too high)"+a+".")),r.selection){var P=Array.isArray(r.selection)?r.selection.map((function(e){return void 0===(null==e?void 0:e.value)?e:e.value})):Object.keys(r.selection);"DateTime"===r.type&&(P=P.map(I)),P.includes(e)||u('Selection: Property "'+t+'" (type '+r.type+') should be one of "'+P.join('", "')+'". But is "'+e+'"'+a+".")}return[null,void 0].includes(r.regularExpressionPattern)||new RegExp(r.regularExpressionPattern).test(e)?![null,void 0].includes(r.invertedRegularExpressionPattern)&&new RegExp(r.invertedRegularExpressionPattern).test(e)&&u('InvertedPatternMatch: Property "'+t+'" should not match regular expression pattern '+r.invertedRegularExpressionPattern+' (given "'+e+'")'+a+"."):u('PatternMatch: Property "'+t+'" should match regular expression pattern '+r.regularExpressionPattern+' (given "'+e+'")'+a+"."),v(e,t,r,c),T(e)!==T(c)&&(i=n.concat(t,"value updated")),{newValue:e,changedPath:i}},w=function(e,t,r,a,o){var s=t[a];if(!e.writable)if(r){if(Object.prototype.hasOwnProperty.call(r,a)&&T(s)===T(r[a]))return a!==f&&"incremental"===O&&delete t[a],!0;u('Readonly: Property "'+a+'" is not writable (old document "'+T(r)+'")'+o+".")}else u('Readonly: Property "'+a+'" is not writable'+o+".");if(!e.mutable&&r&&Object.prototype.hasOwnProperty.call(r,a)){if(T(s)===T(r[a]))return"incremental"!==O||i.property.name.reserved.concat(m.deleted,f,y).includes(a)||delete t[a],!0;"migrate"!==O&&u('Immutable: Property "'+a+'" is not writable (old document "'+T(r)+'")'+o+".")}if(null===s){if(e.nullable)return delete t[a],r&&Object.prototype.hasOwnProperty.call(r,a)&&(c=n.concat(a,"delete property")),!0;u('NotNull: Property "'+a+'" should not be "null"'+o+".")}return!1},E=function(e,t,r,c){if(!r)for(var i,s,l=o(["onCreateExecution","onCreateExpression"]);!(i=l()).done;)if(s=i.value,Object.prototype.hasOwnProperty.call(e,s)){var d=void 0;try{d=L(e[s],s.endsWith("Expression"),{checkPropertyContent:x,model:_,modelName:p,name:c,type:s,newDocument:t,oldDocument:r,newValue:void 0,oldValue:void 0,parentNames:n,pathDescription:a,propertySpecification:e})}catch(i){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(i)&&u('Compilation: Hook "'+s+'" has invalid code "'+i.code+'" for property "'+c+'": '+i.message+a+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(i)&&u('Runtime: Hook "'+s+'" has throw an error with code "'+i.code+'" for property "'+c+'": '+i.message+a+"."),!Object.prototype.hasOwnProperty.call(i,"empty"))throw i}d&&![null,void 0].includes(d.result)&&(t[c]=d.result)}},k=function(e,t,r,c){if(Object.prototype.hasOwnProperty.call(t,c)){e.trim&&"string"==typeof t[c]&&(t[c]=t[c].trim()),e.emptyEqualsToNull&&(""===t[c]||Array.isArray(t[c])&&0===t[c].length||null!==t[c]&&"object"==typeof t[c]&&0===Object.keys(t).length)&&(t[c]=null);for(var i,s,l=o(["onUpdateExecution","onUpdateExpression"]);!(i=l()).done;)if(s=i.value,Object.prototype.hasOwnProperty.call(e,s))try{t[c]=L(e[s],s.endsWith("Expression"),{checkPropertyContent:x,model:_,modelName:p,name:c,type:s,newDocument:t,oldDocument:r,newValue:t[c],oldValue:r&&r[c],parentNames:n,pathDescription:a,propertySpecification:e}).result}catch(i){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(i)&&u('Compilation: Hook "'+s+'" has invalid code "'+i.code+'" for property "'+c+'": '+i.message+a+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(i)&&u('Runtime: Hook "'+s+'" has throw an error with code "'+i.code+'" for property "'+c+'": '+i.message+a+"."),!Object.prototype.hasOwnProperty.call(i,"empty"))throw i}}},D=Object.keys(_).filter((function(e){return![m.additional,m.allowedRoles,m.constraint.execution,m.constraint.expression,m.create.execution,m.create.expression,m.extend,m.maximumAggregatedSize,m.minimumAggregatedSize,m.oldType,m.update.execution,m.update.expression].includes(e)}));if("migrate"===O)for(var j,M,A=o(D);!(j=A()).done;)if(M=j.value,![null,void 0].includes(_[M].oldName))for(var C,U,N=o([].concat(_[M].oldName));!(C=N()).done;)U=C.value,Object.prototype.hasOwnProperty.call(e,U)&&(e[M]=e[U],delete e[U]);if(!r)for(var B,K=0,q=[m.create.execution,m.create.expression];K<q.length;K++)if(B=q[K],Object.prototype.hasOwnProperty.call(_,B)){var z=void 0;try{z=L(_[B],B.endsWith("Expression"),{checkPropertyContent:x,model:_,modelName:p,type:B,newDocument:e,oldDocument:r,parentNames:n,pathDescription:a}).result}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&u('Compilation: Hook "'+B+'" has invalid code "'+e.code+'" for document "'+p+'": '+e.message+a+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&u('Runtime: Hook "'+B+'" has throw an error with code "'+e.code+'" for document "'+p+'": '+e.message+a+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}[null,void 0].includes(z)||(e=z),l(),p=e[b],0===n.length&&g()}for(var H,F=0,G=[m.update.execution,m.update.expression];F<G.length;F++)if(H=G[F],Object.prototype.hasOwnProperty.call(_,H)){var V=void 0;try{V=L(_[H],H.endsWith("Expression"),{checkPropertyContent:x,model:_,modelName:p,type:H,newDocument:e,oldDocument:r,parentNames:n,pathDescription:a}).result}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&u('Compilation: Hook "'+H+'" has invalid code "'+e.code+'" for document "'+p+'": '+e.message+a+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&u('Runtime: Hook "'+H+'" has throw an error with code "'+e.code+'" for document "'+p+'": '+e.message+a+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}[void 0,null].includes(V)||(e=V),l(),p=e[b],0===n.length&&g()}for(var J,$=function t(){var a=J.value;if(m.attachment===a)for(var i=function(){var i=l[s],u=i[0],p=i[1];Object.prototype.hasOwnProperty.call(e,a)&&null!==e[a]||(e[a]={}),r&&!Object.prototype.hasOwnProperty.call(r,a)&&(r[a]={});var _=Object.keys(e[a]).filter((function(t){return null!==e[a][t].data&&S(u,t,p)})),d=e[a],m=[];if(r){var f=r[a];m=Object.keys(f).filter((function(e){return!(Object.prototype.hasOwnProperty.call(d,e)&&Object.prototype.hasOwnProperty.call(d[e],"data")&&null===d[e].data)&&!!f[e]&&(Object.prototype.hasOwnProperty.call(f[e],"data")&&null!==f[e].data||f[e].stub&&!!f[e].digest)&&!!S(u,e,p)}))}for(var y,b,h=p,v=o(_);!(y=v()).done;)b=y.value,E(h,d,r&&r[a]?r[a]:null,b);for(var g,x,P=o(_);!(g=P()).done;)x=g.value,k(h,d,r&&r[a]?r[a]:null,x);if([null,void 0].includes(h.default)){if(h.nullable||0<_.length||0<m.length||t(),"fillUp"===O&&0===_.length&&0<m.length)for(var w,D,j=o(m);!(w=j()).done;)D=w.value,null===d[D]?c=n.concat(a,D,"file removed"):d[D]=r[a][D]}else if(0===_.length)if(0===m.length)for(var M in h.default)Object.prototype.hasOwnProperty.call(h.default,M)&&(d[M]=h.default[M],c=n.concat(a,u,"add default file"));else if("fillUp"===O)for(var A,C,T=o(m);!(A=T()).done;)C=A.value,d[C]=r[a][C]},s=0,l=Object.entries(_[a]);s<l.length;s++)i();else{var u=D.includes(a)?_[a]:h;E(u,e,r,a),k(u,e,r,a),[null,void 0].includes(u.default)?(!(u.nullable||Object.prototype.hasOwnProperty.call(e,a)||r&&Object.prototype.hasOwnProperty.call(r,a)&&O)&&t(),!Object.prototype.hasOwnProperty.call(e,a)&&r&&Object.prototype.hasOwnProperty.call(r,a)&&("fillUp"===O?e[a]=r[a]:!O&&(c=n.concat(a,"property removed")))):(!Object.prototype.hasOwnProperty.call(e,a)||null===e[a])&&(r&&Object.prototype.hasOwnProperty.call(r,a)?"fillUp"===O?e[a]=r[a]:"migrate"===O&&(e[a]=u.default,c=n.concat(a,"migrate default value")):(e[a]=u.default,c=c.concat(a,"add default value")))}},Y=o(D.concat(h?Object.keys(e).filter((function(e){return!D.includes(e)})):[]));!(J=Y()).done;)$();if(r&&"incremental"===O)for(var X=0,Z=Object.entries(e);X<Z.length;X++){var Q=Z[X],ee=Q[0],te=Q[1];!Object.prototype.hasOwnProperty.call(r,ee)||i.property.name.reserved.concat(f,y,m.conflict,m.deleted,m.deletedConflict,m.localSequence,m.revisions,m.revisionsInformation,b).includes(ee)||r[ee]!==te&&T(r[ee])!==T(te)||delete e[ee]}for(var re=0,ne=Object.entries(e);re<ne.length;re++){var ae=ne[re],oe=ae[0],ce=ae[1];if(!i.property.name.reserved.concat(y,m.conflict,m.deleted,m.deletedConflict,m.localSequence,m.revisions,m.revisionsInformation,m.strategy).includes(oe)){var ie=void 0;if(Object.prototype.hasOwnProperty.call(_,oe))ie=_[oe];else if(h)ie=h;else{if("migrate"===O){delete e[oe],c=n.concat(oe,"migrate removed property");continue}u('Property: Given property "'+oe+'" isn\'t specified in model "'+p+'"'+a+".")}if(!ie)continue;if(m.attachment===oe){var se=ce;for(var le in se)if(Object.prototype.hasOwnProperty.call(se,le))for(var ue in _[oe])if(S(ue,le,_[oe][ue])){w(_[oe][ue],e,r,le,a);break}continue}if(w(ie,e,r,oe,a))continue;if("string"==typeof ie.type&&ie.type.endsWith("[]")||Array.isArray(ie.type)&&ie.type.length&&Array.isArray(ie.type[0])){var pe,_e=ce;Array.isArray(_e)?![null,void 0].includes(ie.minimumNumber)&&_e.length<ie.minimumNumber?u('MinimumArrayLength: Property "'+oe+'" (array of length '+_e.length+") doesn't fullfill minimum array length of "+ie.minimumNumber+a+"."):![null,void 0].includes(ie.maximumNumber)&&ie.maximumNumber<_e.length&&u('MaximumArrayLength: Property "'+oe+'" (array of length '+_e.length+") doesn't fullfill maximum array length of "+ie.maximumNumber+a+"."):u('PropertyType: Property "'+oe+'" isn\'t of type "array -> '+ie.type+'" (given "'+T(_e)+'")'+a+"."),v(_e,oe,ie,r&&Object.prototype.hasOwnProperty.call(r,oe)&&r[oe]||void 0,["arrayConstraintExecution","arrayConstraintExpression"]);var de={};for(var me in ie)Object.prototype.hasOwnProperty.call(ie,me)&&(de[me]="type"===me?Array.isArray(ie[me])?ie[me][0]:[ie[me].substring(0,ie.type.length-2)]:ie[me]);if(1===(null==(pe=de.type)?void 0:pe.length)&&Object.prototype.hasOwnProperty.call(s,de.type[0]))for(var fe,ye,be=o(_e.slice());!(fe=be()).done;)"object"!=typeof(ye=fe.value)||Object.getPrototypeOf(ye)!==Object.prototype||Object.prototype.hasOwnProperty.call(ye,b)||(ye[b]=de.type[0]);for(var he,ve,ge=0,Oe=o(_e.slice());!(he=Oe()).done;)ve=he.value,_e[ge]=x(ve,ge+1+". value in "+oe,de).newValue,null===ve&&_e.splice(ge,1),ge+=1;r&&Object.prototype.hasOwnProperty.call(r,oe)&&Array.isArray(r[oe])&&r[oe].length===_e.length&&T(r[oe])===T(_e)||(c=n.concat(oe,"array updated"))}else{var xe=r&&Object.prototype.hasOwnProperty.call(r,oe)?r[oe]:null,Pe=x(ce,oe,ie,xe);e[oe]=Pe.newValue,Pe.changedPath.length&&(c=Pe.changedPath),null===e[oe]&&(null!==xe&&(c=n.concat(oe,"property removed")),delete e[oe])}}}for(var we,Ee=0,ke=Object.keys(m.constraint);Ee<ke.length;Ee++)if(we=ke[Ee],(we=m.constraint[we])&&Object.prototype.hasOwnProperty.call(_,we))for(var De,je=o([].concat(_[we]));!(De=je()).done;){var Me,Ae=De.value,Ce=void 0;try{Ce=L(Ae.evaluation,we===m.constraint.expression,{checkPropertyContent:x,model:_,modelName:p,type:we,newDocument:e,oldDocument:r,parentNames:n,pathDescription:a})}catch(e){if(function(e){return Object.prototype.hasOwnProperty.call(e,"compilation")}(e)&&u('Compilation: Hook "'+we+'" has invalid code "'+e.code+'": "'+e.message+'"'+a+"."),function(e){return Object.prototype.hasOwnProperty.call(e,"runtime")}(e)&&u('Runtime: Hook "'+we+'" has thrown an error with code "'+e.code+'": '+e.message+a+"."),!Object.prototype.hasOwnProperty.call(e,"empty"))throw e}if(null==(Me=Ce)||!Me.result){var Te=we.replace(/^[^a-zA-Z]+/,"");u(Te.charAt(0).toUpperCase()+(Te.substring(1)+": ")+(Ae.description?t(Function,Object.keys(Ce.scope).concat(["return "+Ae.description.trim()])).apply(void 0,Object.values(Ce.scope)):'Model "'+p+'" should satisfy constraint "'+Ce.code+'" (given "'+T(e)+'")'+a+"."))}}if(Object.prototype.hasOwnProperty.call(e,m.attachment)){var Re=e[m.attachment];("object"!=typeof Re||Object.getPrototypeOf(Re)!==Object.prototype)&&u("AttachmentType: given attachment has invalid type"+a+".");var Ie=null;if(r&&Object.prototype.hasOwnProperty.call(r,m.attachment)&&null!==(Ie=r[m.attachment])&&"object"==typeof Ie)for(var Se=0,Ue=Object.entries(Ie);Se<Ue.length;Se++){var Le=Ue[Se],We=Le[0],Ne=Le[1];if(Object.prototype.hasOwnProperty.call(Re,We)){var Be=Re[We];null===Be||null===Be.data||Be.content_type===Ne.content_type&&(Be.data===Ne.data||Be.digest===Ne.digest)?((null===Be||null===Be.data)&&(c=n.concat(m.attachment,We,"attachment removed")),"incremental"===O&&delete Re[We]):c=n.concat(m.attachment,We,"attachment updated")}else"fillUp"===O?Re[We]=Ne:O||(c=n.concat(m.attachment,We,"attachment removed"))}for(var Ke=0,qe=Object.entries(Re);Ke<qe.length;Ke++){var ze=qe[Ke],He=ze[0],Fe=ze[1];[null,void 0].includes(Fe)||null===Fe.data?delete Re[He]:(!Ie||!Object.prototype.hasOwnProperty.call(Ie,He)||Fe.content_type!==Ie[He].content_type||Fe.data!==Ie[He].data&&Fe.digest!==Ie[He].digest)&&(c=n.concat(m.attachment,He,"attachment updated"))}0===Object.keys(Re).length&&delete e[m.attachment];for(var Ge={},Ve=0,Je=Object.keys(_[m.attachment]);Ve<Je.length;Ve++)Ge[Je[Ve]]=[];for(var $e=0,Ye=Object.keys(Re);$e<Ye.length;$e++){for(var Xe=Ye[$e],Ze=!1,Qe=0,et=Object.entries(_[m.attachment]);Qe<et.length;Qe++){var tt=et[Qe],rt=tt[0],nt=tt[1];if(S(rt,Xe,nt)){Ge[rt].push(Xe),Ze=!0;break}}Ze||u('AttachmentTypeMatch: None of the specified attachment types ("'+Object.keys(_[m.attachment]).join('", "')+'") matches given one ("'+Xe+'")'+a+".")}for(var at=0,ot=0,ct=Object.keys(Ge);ot<ct.length;ot++){var it=ct[ot],st=_[m.attachment][it];if(Object.prototype.hasOwnProperty.call(Ge,it)){var lt=Ge[it].length;null!==st.maximumNumber&&lt>st.maximumNumber&&u("AttachmentMaximum: given number of attachments ("+lt+") doesn't satisfy specified maximum of "+st.maximumNumber+' from type "'+it+'"'+a+"."),(!st.nullable||0!==lt)&&lt<st.minimumNumber&&u("AttachmentMinimum: given number of attachments ("+lt+") doesn't satisfy specified minimum of "+st.minimumNumber+' from type "'+it+'"'+a+".");for(var ut,pt=0,_t=o(Ge[it]);!(ut=_t()).done;){var dt,mt,ft=ut.value;null!=(dt=st.fileName)&&dt.regularExpressionPattern&&!new RegExp(st.fileName.regularExpressionPattern).test(ft)?u('AttachmentName: given attachment name "'+ft+'" doesn\'t satisfy specified regular expression pattern "'+st.fileName.regularExpressionPattern+'" from type "'+it+'"'+a+"."):null!=(mt=st.fileName)&&mt.invertedRegularExpressionPattern&&new RegExp(st.fileName.invertedRegularExpressionPattern).test(ft)?u('InvertedAttachmentName: given attachment name "'+ft+'" does satisfy specified regular expression pattern "'+st.fileName.invertedRegularExpressionPattern+'" from type "'+it+'"'+a+"."):!([null,void 0].includes(st.contentTypeRegularExpressionPattern)||Re[ft].content_type&&new RegExp(st.contentTypeRegularExpressionPattern).test(Re[ft].content_type))&&u('AttachmentContentType: given attachment content type "'+Re[ft].content_type+'" doesn\'t satisfy specified regular expression pattern "'+st.contentTypeRegularExpressionPattern+'" from type "'+it+'"'+a+".");var yt=st.invertedContentTypeRegularExpressionPattern;[null,void 0].includes(yt)||Re[ft].content_type&&!new RegExp(yt).test(Re[ft].content_type)||u('InvertedAttachmentContentType: given attachment content type "'+Re[ft].content_type+'" does satisfy specified regular expression pattern "'+yt+'" from type "'+it+'"'+a+".");var bt=0;"length"in Re[ft]?bt=Re[ft].length:"data"in Re[ft]&&(bt=Buffer&&"byteLength"in Buffer?Buffer.byteLength(Re[ft].data,"base64"):Re[ft].data.length),![null,void 0].includes(st.minimumSize)&&st.minimumSize>bt?u("AttachmentMinimumSize: given attachment size "+bt+" byte doesn't satisfy specified minimum of "+st.minimumSize+" byte "+a+"."):![null,void 0].includes(st.maximumSize)&&st.maximumSize<bt&&u("AttachmentMaximumSize: given attachment size "+bt+" byte doesn't satisfy specified maximum of "+st.maximumSize+" byte "+a+"."),pt+=bt}![null,void 0].includes(st.minimumAggregatedSize)&&st.minimumAggregatedSize>pt?u('AttachmentAggregatedMinimumSize: given aggregated size of attachments from type "'+it+'" '+pt+" byte doesn't satisfy specified minimum of "+st.minimumAggregatedSize+" byte "+a+"."):![null,void 0].includes(st.maximumAggregatedSize)&&st.maximumAggregatedSize<pt&&u('AttachmentAggregatedMaximumSize: given aggregated size of attachments from type "'+it+'" '+pt+" byte doesn't satisfy specified maximum of "+st.maximumAggregatedSize+" byte "+a+"."),at+=pt}}Object.prototype.hasOwnProperty.call(_,m.minimumAggregatedSize)&&![null,void 0].includes(_[m.minimumAggregatedSize])&&_[m.minimumAggregatedSize]>at?u("AggregatedMinimumSize: given aggregated size "+at+" byte doesn't satisfy specified minimum of "+_[m.minimumAggregatedSize]+" byte "+a+"."):![null,void 0].includes(_[m.maximumAggregatedSize])&&_[m.maximumAggregatedSize]<at&&u("AggregatedMaximumSize: given aggregated size "+at+" byte doesn't satisfy specified maximum of "+_[m.maximumAggregatedSize]+" byte "+a+".")}if(r&&Object.prototype.hasOwnProperty.call(r,m.attachment)&&0===Object.keys(r[m.attachment]).length&&delete r[m.attachment],0===c.length&&r&&"migrate"===O)for(var ht,vt=0,gt=Object.keys(r);vt<gt.length;vt++)ht=gt[vt],Object.prototype.hasOwnProperty.call(e,ht)||(c=n.concat(ht,"migrate removed property"));return{changedPath:c,newDocument:e}},N={attachmentWithPrefixExists:function(t){if(Object.prototype.hasOwnProperty.call(e,m.attachment)){var r=e[m.attachment],n=U(t);if(n)return Object.prototype.hasOwnProperty.call(r[n],"stub")&&r[n].stub||Object.prototype.hasOwnProperty.call(r[n],"data")&&![null,void 0].includes(r[n].data)}return!1},checkDocument:W,getFileNameByPrefix:U,serialize:T,id:h,revision:v,idName:f,revisionName:y,specialNames:m,typeName:b,modelConfiguration:i,models:s,now:p,nowUTCTimestamp:_,securitySettings:c,userContext:n},B=W(e,r);return(!B.newDocument._deleted||r)&&(B.newDocument._deleted&&B.newDocument._deleted!==(null==r?void 0:r._deleted)||B.changedPath.length)||u("NoChange: No new data given. new document: "+T(e)+"; old document: "+T(r)+"."),Object.prototype.hasOwnProperty.call(c,i.property.name.validatedDocumentsCache)?c[i.property.name.validatedDocumentsCache].add(h+"-"+v):c[i.property.name.validatedDocumentsCache]=new Set([h+"-"+v]),B.newDocument},e}(),u=l;e.exports=s}()}],__webpack_module_cache__={};function __webpack_require__(e){var t=__webpack_module_cache__[e];if(void 0!==t)return t.exports;var r=__webpack_module_cache__[e]={exports:{}};return __webpack_modules__[e](r,r.exports,__webpack_require__),r.exports}__webpack_require__.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return __webpack_require__.d(t,{a:t}),t},__webpack_require__.d=(e,t)=>{for(var r in t)__webpack_require__.o(t,r)&&!__webpack_require__.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},__webpack_require__.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),__webpack_require__.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var __webpack_exports__={};(()=>{"use strict";__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,{Database:()=>g,default:()=>O});var e=__webpack_require__(0),t=__webpack_require__.n(e),r=__webpack_require__(1),n=__webpack_require__.n(r),a=__webpack_require__(2),o=__webpack_require__.n(a),c=__webpack_require__(4),i=__webpack_require__.n(c),s=__webpack_require__(6),l=__webpack_require__(7),u=__webpack_require__.n(l);const p=require("pouchdb");var _=__webpack_require__.n(p);const d=require("pouchdb-find");var m=__webpack_require__.n(d),f=__webpack_require__(9),y=__webpack_require__.n(f),b=__webpack_require__(8);function h(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 v(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?v(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 v(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 g=function(){function e(){}return e.preLoadService=function(){var t=n()(o().mark((function t(r){var a,c,s,l,p,d,f,y,b,v,g,O,x,P,w,E,k;return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(a=r.configuration.couchdb,c=r.services,Object.prototype.hasOwnProperty.call(c,"couchdb")||(c.couchdb={}),s=c.couchdb,Object.prototype.hasOwnProperty.call(s,"connector")||(l=a.model.property.name.special.id,p=a.model.property.name.special.revision,s.connector=_(),d=s.connector.prototype.bulkDocs,s.connector.plugin({bulkDocs:function(){var t=n()(o().mark((function t(r){var n,c,i,s,u,_,m,f,y,b,v,g,O,x,P,w,E,k,D=arguments;return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:for(c=D.length,i=Array(1<c?c-1:0),s=1;s<c;s++)i[s-1]=D[s];return u=0<i.length&&i[i.length-1]===e.toggleIDDetermining,_=u?!a.skipIDDetermining:a.skipIDDetermining,u&&i.pop(),m=!Array.isArray(r)&&null!==r&&"object"==typeof r&&l in r?[r]:r,null!=(n=a.connector.fetch)&&n.timeout&&(0===i.length||"object"!=typeof i[0])&&i.unshift({timeout:a.connector.fetch.timeout}),t.next=8,d.call.apply(d,[this,m].concat(i));case 8:f=t.sent,y=[],b=[],v=0,g=h(f);case 13:if((O=g()).done){t.next=36;break}if(x=O.value,"object"!=typeof m[v]){t.next=33;break}if(!(p in m[v])||"conflict"!==x.name||!["latest","upsert"].includes(m[v][p])){t.next=21;break}b.push(m[v]),y.push(v),t.next=33;break;case 21:if(!(l in m[v]&&a.ignoreNoChangeError&&"name"in x&&"forbidden"===x.name&&"message"in x&&x.message.startsWith("NoChange:"))){t.next=33;break}if(f[v]={id:m[v][l],ok:!0},_){t.next=33;break}if(!(p in m[v])||["latest","upsert"].includes(m[v][p])){t.next=28;break}t.t0=m[v][p],t.next=32;break;case 28:return t.next=30,this.get(f[v].id);case 30:t.t1=p,t.t0=t.sent[t.t1];case 32:f[v].rev=t.t0;case 33:v+=1;case 34:t.next=13;break;case 36:if(!b.length){t.next=43;break}return m=b,u&&i.push(e.toggleIDDetermining),t.next=41,this.bulkDocs.apply(this,[m].concat(i));case 41:for(P=t.sent,w=h(P);!(E=w()).done;)k=E.value,f[y.shift()]=k;case 43:return t.abrupt("return",f);case 44:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}()}),a.debug&&s.connector.debug.enable("*"),s.connector=s.connector.plugin(m())),Object.prototype.hasOwnProperty.call(s,"server")){t.next=36;break}s.server={},f=[],y=h([].concat(a.binary.runner));case 8:if((b=y()).done){t.next=34;break}v=b.value,g=h([].concat(v.location));case 11:if((O=g()).done){t.next=30;break}x=O.value,P=h([].concat(v.name));case 14:if((w=P()).done){t.next=26;break}return E=w.value,k=u().resolve(x,E),f.push(k),t.next=20,i().isFile(k);case 20:if(!t.sent){t.next=24;break}return v.binaryFilePath=k,s.server.runner=v,t.abrupt("break",26);case 24:t.next=14;break;case 26:if(!Object.prototype.hasOwnProperty.call(s.server,"runner")){t.next=28;break}return t.abrupt("break",30);case 28:t.next=11;break;case 30:if(!Object.prototype.hasOwnProperty.call(s.server,"runner")){t.next=32;break}return t.abrupt("break",34);case 32:t.next=8;break;case 34:if(Object.prototype.hasOwnProperty.call(s.server,"runner")){t.next=36;break}throw new Error('No binary file in one of the following locations found: "'+f.join('", "')+'".');case 36:case"end":return t.stop()}}),t)})));return function(){return t.apply(this,arguments)}}(),e.loadService=function(){var e=n()(o().mark((function e(t){var r,n,a,l,p,_,d,m,f,v,g,O,x,P,w,E,k,D,j,M,A,C,T,R,I,S,U,L,W,N,B,K,q,z,H,F,G,V,J,$,Y,X,Z,Q,ee,te,re,ne,ae,oe,ce,ie,se,le,ue,pe,_e,de,me,fe,ye,be,he,ve,ge,Oe,xe,Pe,we,Ee,ke,De,je,Me,Ae,Ce,Te,Re,Ie,Se,Ue,Le,We,Ne,Be,Ke,qe,ze,He,Fe,Ge,Ve,Je,$e;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=t.configuration,n=t.services,a=null,l=n.couchdb,!Object.prototype.hasOwnProperty.call(l.server,"runner")){e.next=10;break}return e.next=6,b.default.startServer(n,r);case 6:l.server.restart=b.default.restartServer,l.server.start=b.default.startServer,l.server.stop=b.default.stopServer,a=new Promise((function(e,t){l.server.resolve=e,l.server.reject=t}));case 10:if(!Object.prototype.hasOwnProperty.call(l,"connection")){e.next=12;break}return e.abrupt("return",{couchdb:a});case 12:if(p=i().stringFormat(r.couchdb.url,r.couchdb.user.name+":"+r.couchdb.user.password+"@"),!r.couchdb.ensureAdminPresence){e.next=44;break}return _=new l.connector(i().stringFormat(r.couchdb.url,"")+"/_users",b.default.getConnectorOptions(r)),e.prev=15,e.next=18,_.allDocs();case 18:return e.next=21,c.globalContext.fetch(i().stringFormat(r.couchdb.url,"")+"/"+l.server.runner.adminUserConfigurationPath+"/"+r.couchdb.user.name,{body:'"'+r.couchdb.user.password+'"',method:"PUT"});case 21:e.next=41;break;case 23:if(e.prev=23,e.t0=e.catch(15),"unauthorized"!==e.t0.name){e.next=40;break}return d=new l.connector(p+"/_users",b.default.getConnectorOptions(r)),e.prev=27,e.next=30,d.allDocs();case 30:e.next=35;break;case 32:e.prev=32,e.t1=e.catch(27);case 35:return e.prev=35,d.close(),e.finish(35);case 38:e.next=41;break;case 40:case 41:return e.prev=41,_.close(),e.finish(41);case 44:if(!r.couchdb.ensureUserPresence){e.next=79;break}m=0,f=[r.couchdb.security.admins,r.couchdb.security.members];case 46:if(!(m<f.length)){e.next=79;break}v=f[m],g=h(v.names);case 49:if((O=g()).done){e.next=76;break}return x=O.value,P=new l.connector(p+"/_users",b.default.getConnectorOptions(r)),e.prev=52,e.next=55,P.get("org.couchdb.user:"+x);case 55:e.next=71;break;case 57:if(e.prev=57,e.t2=e.catch(52),"not_found"!==e.t2.error){e.next=70;break}return e.prev=60,e.next=63,P.put(((w={})[r.couchdb.model.property.name.special.id]="org.couchdb.user:"+x,w.name=x,w.password=x,w.roles=[].concat(v.roles.includes(x+"s")?x+"s":[]),w.type="user",w));case 63:e.next=68;break;case 65:throw e.prev=65,e.t3=e.catch(60),new Error("Couldn't create missing user \""+x+'": '+i().represent(e.t3));case 68:e.next=71;break;case 70:throw new Error("Couldn't check for presence of user \""+x+'": '+i().represent(e.t2));case 71:return e.prev=71,P.close(),e.finish(71);case 74:e.next=49;break;case 76:m++,e.next=46;break;case 79:if(!r.couchdb.model.updateConfiguration){e.next=134;break}E=h(r.couchdb.backend.prefixes);case 81:if((k=E()).done){e.next=134;break}D=k.value,e.t4=o().keys(r.couchdb.backend.configuration);case 84:if((e.t5=e.t4()).done){e.next=132;break}if(j=e.t5.value,!Object.prototype.hasOwnProperty.call(r.couchdb.backend.configuration,j)){e.next=130;break}return M="/"+D+(D.trim()?"/":"")+j,A=""+p+M,C=r.couchdb.backend.configuration[j],T=void 0,e.prev=91,e.next=94,c.globalContext.fetch(A);case 94:T=e.sent,e.next=100;break;case 97:e.prev=97,e.t6=e.catch(91);case 100:if(!T){e.next=130;break}if(!T.ok){e.next=129;break}if(R=!0,"function"!=typeof T.text){e.next=115;break}return e.prev=104,e.t7=C,e.next=108,T["string"==typeof C?"text":"json"]();case 108:e.t8=e.sent,R=e.t7===e.t8,e.next=115;break;case 112:e.prev=112,e.t9=e.catch(104);case 115:if(!R){e.next=126;break}return e.prev=116,e.next=119,c.globalContext.fetch(A,{body:'"'+r.couchdb.backend.configuration[j]+'"',method:"PUT"});case 119:e.next=124;break;case 121:e.prev=121,e.t10=e.catch(116);case 124:e.next=127;break;case 126:case 127:e.next=130;break;case 129:case 130:e.next=84;break;case 132:e.next=81;break;case 134:return e.next=136,b.default.initializeConnection(n,r);case 136:if(I=r.couchdb.model.property.name.special.id,S=r.couchdb.model.property.name.special.type,!r.couchdb.ensureSecuritySettingsPresence){e.next=147;break}return e.prev=139,e.next=142,c.globalContext.fetch(p+"/"+r.couchdb.databaseName+"/_security",{body:JSON.stringify(r.couchdb.security),method:"PUT"});case 142:e.next=147;break;case 144:e.prev=144,e.t11=e.catch(139);case 147:if(delete(U=i().copy(r.couchdb.model)).property.defaultSpecification,delete U.entities,L=b.default.extendModels(r.couchdb.model),!r.couchdb.model.updateValidation){e.next=215;break}return e.next=154,s.promises.readFile(c.currentRequire.resolve("./databaseHelper"),{encoding:r.core.encoding,flag:"r"});case 154:W=e.sent,N=h([{description:"Model specification",methodName:"validateDocumentUpdate",name:"validation",serializedParameter:JSON.stringify(U)+", "+JSON.stringify(L)},{description:"Authorisation",methodName:"authenticate",name:"authentication",serializedParameter:JSON.stringify(b.default.determineAllowedModelRolesMapping(r.couchdb.model))+", '"+I+"', '"+S+"', '"+r.couchdb.model.property.name.special.designDocumentNamePrefix+"'"}]);case 156:if((B=N()).done){e.next=171;break}K=B.value,q="function(...parameters) {\n return require('helper').default."+K.methodName+"(...parameters.concat(["+K.serializedParameter+"]))\n}",e.prev=159,new Function("return "+q),e.next=166;break;case 163:throw e.prev=163,e.t12=e.catch(159),new Error("Generated "+K.name+' code "'+q+"\" doesn't compile: "+i().represent(e.t12));case 166:return r.core.debug,e.next=169,b.default.ensureValidationDocumentPresence(l.connection,K.name,{helper:W,validate_doc_update:q},K.description,!0,I,U.property.name.special.designDocumentNamePrefix);case 169:e.next=156;break;case 171:z=0,H=Object.entries(L);case 172:if(!(z<H.length)){e.next=215;break}F=H[z],G=F[0],V=F[1],J=0,$=Object.entries(V);case 175:if(!(J<$.length)){e.next=212;break}if(Y=$[J],X=Y[0],Z=Y[1],![U.property.name.special.constraint.execution,U.property.name.special.constraint.expression].includes(X)){e.next=193;break}Q=h([].concat(Z));case 179:if((ee=Q()).done){e.next=191;break}if(!(te=ee.value).description){e.next=189;break}e.prev=182,new Function("return "+te.description),e.next=189;break;case 186:throw e.prev=186,e.t13=e.catch(182),new Error('Specified constraint description "'+te.description+'" for model "'+G+'" doesn\'t compile: "'+i().represent(e.t13)+'".');case 189:e.next=179;break;case 191:e.next=209;break;case 193:re=Z,ne=h(["conflictingConstraintExpression","conflictingConstraintExecution","constraintExpression","constraintExecution"]);case 195:if((ae=ne()).done){e.next=209;break}if(oe=ae.value,null===re||"object"!=typeof re){e.next=207;break}if(null==(ce=re[oe])||!ce.description){e.next=207;break}e.prev=200,new Function(ce.description),e.next=207;break;case 204:throw e.prev=204,e.t14=e.catch(200),new Error('Specified constraint description "'+ce.description+'" for model "'+G+'" in property "'+X+'" as "'+oe+'" doesn\'t compile: "'+i().represent(e.t14)+'".');case 207:e.next=195;break;case 209:J++,e.next=175;break;case 212:z++,e.next=172;break;case 215:if(!r.couchdb.model.autoMigrationPath){e.next=307;break}return ie={},e.next=219,i().isDirectory(u().resolve(r.couchdb.model.autoMigrationPath));case 219:if(!e.sent){e.next=259;break}return e.t15=h,e.next=223,i().walkDirectoryRecursively(u().resolve(r.couchdb.model.autoMigrationPath),r.couchdb.debug?i().noop:function(e){return"debug"!==e.name});case 223:e.t16=e.sent,se=(0,e.t15)(e.t16);case 225:if((le=se()).done){e.next=259;break}if(ue=le.value,pe=u().extname(ue.name),_e=u().basename(ue.name,pe),".json"!==pe){e.next=256;break}return de=void 0,e.prev=231,e.t17=JSON,e.next=235,s.promises.readFile(ue.path,{encoding:r.core.encoding,flag:"r"});case 235:e.t18=e.sent,de=e.t17.parse.call(e.t17,e.t18),e.next=242;break;case 239:throw e.prev=239,e.t19=e.catch(231),new Error('Parsing document "'+ue.path+'" to include by automigration of has failed: '+i().represent(e.t19));case 242:return de[I]=_e,de[r.couchdb.model.property.name.special.revision]="upsert",e.prev=244,e.next=247,l.connection.put(de);case 247:e.next=253;break;case 249:throw e.prev=249,e.t20=e.catch(244),null!=(me=e.t20.forbidden)&&me.startsWith("NoChange:"),new Error('Migrating document "'+de[I]+'" of type "'+de[S]+'" has failed: '+i().represent(e.t20));case 253:e.next=257;break;case 256:".js"===u().extname(ue.name)&&(ie[ue.path]=(0,c.currentRequire)(ue.path).default);case 257:e.next=225;break;case 259:return e.t21=h,e.next=262,l.connection.allDocs({include_docs:!0});case 262:e.t22=e.sent.rows,fe=(0,e.t21)(e.t22);case 264:if((ye=fe()).done){e.next=307;break}if("string"==typeof(be=ye.value).id&&be.id.startsWith(r.couchdb.model.property.name.special.designDocumentNamePrefix)){e.next=305;break}he=be.doc,(ve=i().copy(he))[r.couchdb.model.property.name.special.strategy]="migrate",ge=h(Object.keys(ie).sort());case 271:if((Oe=ge()).done){e.next=284;break}xe=Oe.value,Pe=null,e.prev=274,Pe=ie[xe](ve,{configuration:r,databaseHelper:y(),idName:I,migrater:ie,models:L,modelConfiguration:U,selfFilePath:xe,services:n,tools:i(),typeName:S}),e.next=281;break;case 278:throw e.prev=278,e.t23=e.catch(274),new Error('Running migrater "'+xe+'" in document '+b.default.mayStripRepresentation(he,r.couchdb.maximumRepresentationTryLength,r.couchdb.maximumRepresentationLength)+'" failed: '+i().represent(e.t23));case 281:Pe&&(ve=Pe);case 282:e.next=271;break;case 284:e.prev=284,y().validateDocumentUpdate(i().copy(ve),i().copy(he),{db:r.couchdb.databaseName,name:r.couchdb.user.name,roles:["_admin"]},i().copy(r.couchdb.security),U,L),e.next=296;break;case 288:if(e.prev=288,e.t24=e.catch(284),!Object.prototype.hasOwnProperty.call(e.t24,"forbidden")){e.next=295;break}return e.t24.forbidden.startsWith("NoChange:"),e.abrupt("continue",305);case 295:throw e.t24;case 296:return e.prev=296,e.next=299,l.connection.put(ve);case 299:e.next=304;break;case 301:throw e.prev=301,e.t25=e.catch(296),new Error('Replaceing auto migrated document "'+ve[I]+'" has failed: '+i().represent(e.t25));case 304:case 305:e.next=264;break;case 307:if(!r.couchdb.createGenericFlatIndex||!r.couchdb.model.autoMigrationPath){e.next=362;break}return e.next=310,l.connection.getIndexes();case 310:we=e.sent.indexes,Ee=0,ke=Object.entries(L);case 312:if(!(Ee<ke.length)){e.next=343;break}if(De=ke[Ee],je=De[0],Me=De[1],!new RegExp(r.couchdb.model.property.name.typeRegularExpressionPattern.public).test(je)){e.next=340;break}return e.next=317,l.connection.createIndex({index:{ddoc:je+"-GenericIndex",fields:[S],name:je+"-GenericIndex"}});case 317:Ae=h(b.default.determineGenericIndexablePropertyNames(r.couchdb.model,Me));case 318:if((Ce=Ae()).done){e.next=340;break}Te=Ce.value,Re=je+"-"+Te+"-GenericIndex",Ie=-1,Se=0,Ue=h(we);case 324:if((Le=Ue()).done){e.next=332;break}if(Le.value.name!==Re){e.next=329;break}return Ie=Se,e.abrupt("break",332);case 329:Se+=1;case 330:e.next=324;break;case 332:if(-1!==Ie){e.next=337;break}return e.next=335,l.connection.createIndex({index:{ddoc:Re,fields:[S,Te],name:Re}});case 335:e.next=338;break;case 337:we.slice(Se,1);case 338:e.next=318;break;case 340:Ee++,e.next=312;break;case 343:We=h(we);case 344:if((Ne=We()).done){e.next=362;break}if(!(Be=Ne.value).name.endsWith("-GenericIndex")){e.next=360;break}Ke=!1,qe=0,ze=Object.entries(L);case 349:if(!(qe<ze.length)){e.next=357;break}if(He=ze[qe],Fe=He[0],Ge=He[1],!Be.name.startsWith(Fe+"-")){e.next=354;break}for(Ve=h(b.default.determineGenericIndexablePropertyNames(r.couchdb.model,Ge));!(Je=Ve()).done;)$e=Je.value,[Fe+"-"+$e+"-GenericIndex",Fe+"-GenericIndex"].includes(Be.name)&&(Ke=!0);return e.abrupt("break",357);case 354:qe++,e.next=349;break;case 357:if(Ke){e.next=360;break}return e.next=360,l.connection.deleteIndex(Be);case 360:e.next=344;break;case 362:if(!r.couchdb.model.triggerInitialCompaction){e.next=371;break}return e.prev=363,e.next=366,l.connection.compact();case 366:e.next=371;break;case 368:e.prev=368,e.t26=e.catch(363);case 371:return e.abrupt("return",{couchdb:a});case 372:case"end":return e.stop()}}),e,null,[[15,23,41,44],[27,32,35,38],[52,57,71,74],[60,65],[91,97],[104,112],[116,121],[139,144],[159,163],[182,186],[200,204],[231,239],[244,249],[274,278],[284,288],[296,301],[363,368]])})));return function(){return e.apply(this,arguments)}}(),e.postLoadService=function(e){var r=e.configuration.couchdb,a=e.pluginAPI,c=e.services.couchdb,s=0;setInterval((function(){0<s&&(s=0)}),3e4);var l=i().debounce(n()(o().mark((function i(){return o().wrap((function(i){for(;;)switch(i.prev=i.next){case 0:return c.changesStream&&c.changesStream.cancel(),c.changesStream=c.connection.changes(r.changesStream),c.changesStream.on("error",n()(o().mark((function t(){return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!(3<(s+=1))){t.next=9;break}return s=0,c.changesStream.cancel(),t.next=7,c.server.restart(e);case 7:t.next=10;break;case 9:case 10:l();case 11:case"end":return t.stop()}}),t)})))),i.next=5,a.callStack(t()({},e,{data:c.changesStream,hook:"couchdbInitializeChangesStream"}));case 5:case"end":return i.stop()}}),i)}))));return r.attachAutoRestarter&&l(),Promise.resolve()},e.shouldExit=function(){var e=n()(o().mark((function e(t){var r,n,a;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.configuration,n=t.services,e.next=3,b.default.stopServer(n,r);case 3:return delete n.couchdb,a="log.txt",e.next=7,i().isFile(a);case 7:if(!e.sent){e.next=10;break}return e.next=10,s.promises.unlink(a);case 10:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),e}();g.toggleIDDetermining=Symbol("toggleIDDetermining");const O=g})(),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.526",
3
+ "version": "1.0.527",
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",
@@ -422,6 +422,7 @@
422
422
  ]
423
423
  }
424
424
  },
425
+ "skipIDDetermining": true,
425
426
  "url": {
426
427
  "__evaluate__": "`http://{1}${self.couchdb.backend.configuration['httpd/host']}:${self.couchdb.backend.configuration['httpd/port']}`"
427
428
  },
package/type.d.ts CHANGED
@@ -243,6 +243,7 @@ export declare type Configuration<ConfigurationType = Mapping<unknown>> = BaseCo
243
243
  model: ModelConfiguration;
244
244
  path: string;
245
245
  security: SecuritySettings;
246
+ skipIDDetermining: boolean;
246
247
  url: string;
247
248
  user: {
248
249
  name: string;