couchdb-web-node-plugin 1.0.803 → 1.0.804

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/helper.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Logger, Mapping, ValueOf } from 'clientnode';
2
- import { AllowedModelRolesMapping, AllowedRoles, Configuration, Connection, ConnectorConfiguration, CoreConfiguration, DatabaseConnectorConfiguration, Model, ModelConfiguration, Models, NormalizedAllowedRoles, PropertySpecification, Services, SpecialPropertyNames } from './type';
2
+ import { AbortControllerStack, AllowedModelRolesMapping, AllowedRoles, Configuration, Connection, ConnectorConfiguration, CoreConfiguration, DatabaseConnectorConfiguration, Model, ModelConfiguration, Models, NormalizedAllowedRoles, PropertySpecification, Services, SpecialPropertyNames } from './type';
3
3
  export declare const TOGGLE_LATEST_REVISION_DETERMINING: unique symbol;
4
4
  export declare const log: Logger;
5
5
  /**
@@ -15,11 +15,11 @@ export declare const removeDeprecatedIndexes: (connection: Connection<object>, m
15
15
  * Converts internal declarative database connector configuration object
16
16
  * into a database compatible one.
17
17
  * @param configuration - Connector configuration object.
18
- * @param abortSignalStack - Stack to put abort signals to. They will be
18
+ * @param abortControllerStack - Stack to put abort signals to. They will be
19
19
  * shifted and used for fetch calls.
20
20
  * @returns Database compatible configuration object.
21
21
  */
22
- export declare const getConnectorOptions: (configuration: ConnectorConfiguration, abortSignalStack?: Array<AbortSignal>) => DatabaseConnectorConfiguration;
22
+ export declare const getConnectorOptions: (configuration: ConnectorConfiguration, abortControllerStack?: AbortControllerStack) => DatabaseConnectorConfiguration;
23
23
  /**
24
24
  * Determines a representation for given plain object.
25
25
  * @param object - Object to represent.
@@ -51,12 +51,11 @@ export declare const ensureValidationDocumentPresence: (databaseConnection: Conn
51
51
  * Initializes a database connection instance.
52
52
  * @param services - An object with stored service instances.
53
53
  * @param configuration - Mutable by plugins extended configuration object.
54
- * @param createRemoteDatabaseIfNotExists - Indicates whether database should
55
- * be created if it does not exist yet. This is only relevant for remote
56
- * databases, because local ones get created automatically by pouchdb.
54
+ * @param checkForDatabaseReachability - Indicates whether to check for
55
+ * reachability of newly created database.
57
56
  * @returns Given and extended object of services.
58
57
  */
59
- export declare const initializeConnection: (services: Services, configuration: Configuration, createRemoteDatabaseIfNotExists?: boolean) => Promise<Services>;
58
+ export declare const initializeConnection: (services: Services, configuration: Configuration, checkForDatabaseReachability?: boolean) => Promise<Services>;
60
59
  /**
61
60
  * Determines the effective database URL to connect to based on given
62
61
  * configuration.
package/helper.js CHANGED
@@ -1 +1 @@
1
- (()=>{"use strict";var e=[,e=>{e.exports=require("@babel/runtime/helpers/extends")},e=>{e.exports=require("@babel/runtime/helpers/asyncToGenerator")},e=>{e.exports=require("@babel/runtime/regenerator")},e=>{e.exports=require("clientnode")}],t={};function r(n){var a=t[n];if(void 0!==a)return a.exports;var o=t[n]={exports:{}};return e[n](o,o.exports,r),o.exports}r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};r.r(n),r.d(n,{TOGGLE_LATEST_REVISION_DETERMINING:()=>v,determineAllowedModelRolesMapping:()=>S,determineGenericIndexablePropertyNames:()=>R,ensureValidationDocumentPresence:()=>k,extendModel:()=>I,extendModels:()=>P,getConnectorOptions:()=>x,getEffectiveURL:()=>j,getPouchDBPlugin:()=>y,initializeConnection:()=>O,isPropertySpecification:()=>T,log:()=>b,mayStripRepresentation:()=>w,normalizeAllowedRoles:()=>D,removeDeprecatedIndexes:()=>g,waitWithTimeout:()=>A});var a=r(1),o=r.n(a),i=r(2),s=r.n(i),c=r(3),u=r.n(c),l=r(4);const p=require("rxjs"),d=require("rxjs/fetch"),f="1.0.803";function m(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 h(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?h(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 h(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 v=Symbol("toggleLatestRevisionDetermining"),b=new l.Logger({name:"web-node.couchdb"}),y=function(e){var t=e.model.property.name.special,r=t.id,n=t.revision,a=t.attachment,o=t.deleted;return{installCouchDBWebNodePlugin:function(t){var i=this;if(this.bulkDocs){var c=this.bulkDocs.bind(this);this.bulkDocs=s()(u().mark((function a(o){var s,p,d,f,h,y,g,x,w,k,O,j,A,S,T,R,I,P,D,E,_,M,C,N=arguments;return u().wrap((function(a){for(;;)switch(a.prev=a.next){case 0:b.debug("BulkDocs called from:",t),(0,l.isObject)(o)&&1===Object.keys(o).length&&"docs"in o&&Array.isArray(o.docs)&&(o=o.docs);for(s=N.length,p=new Array(s>1?s-1:0),d=1;d<s;d++)p[d-1]=N[d];f=p.length>0&&p[p.length-1]===v,h=f?!e.skipLatestRevisionDetermining:e.skipLatestRevisionDetermining,f&&p.pop(),y=!Array.isArray(o)&&(0,l.isObject)(o)&&r in o?[o]:o,g=e.maximumNumberOfEntitiesInBulkOperation,x=[],w=0;case 1:if(!(w<y.length)){a.next=4;break}return k=y.slice(w,w+g),a.next=2,c.call.apply(c,[i,k].concat(p));case 2:O=a.sent,x=x.concat(O);case 3:w+=g,a.next=1;break;case 4:j=[],A=[],S=0,T=m(x);case 5:if((R=T()).done){a.next=12;break}if(I=R.value,"object"!=typeof y[S]){a.next=10;break}if(!(n in y[S])||"conflict"!==I.name||!["0-latest","0-upsert"].includes(y[S][n])){a.next=6;break}A.push(y[S]),j.push(S),a.next=10;break;case 6:if(!(r in y[S]&&e.ignoreNoChangeError&&"name"in I&&"forbidden"===I.name&&"message"in I&&I.message.startsWith("NoChange:"))){a.next=10;break}if(x[S]={id:y[S][r],ok:!0},h){a.next=10;break}if(!(n in y[S])||["0-latest","0-upsert"].includes(y[S][n])){a.next=7;break}M=y[S][n],a.next=9;break;case 7:return a.next=8,i.get(x[S].id);case 8:C=n,M=a.sent[C];case 9:x[S].rev=M;case 10:S+=1;case 11:a.next=5;break;case 12:if(!A.length){a.next=14;break}return y=A,f&&p.push(v),a.next=13,i.bulkDocs.apply(i,[y].concat(p));case 13:for(P=a.sent,D=m(P);!(E=D()).done;)_=E.value,x[j.shift()]=_;case 14:return a.abrupt("return",x);case 15:case"end":return a.stop()}}),a)})))}this.post=this.put=s()(u().mark((function e(t,r){var n;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,i.bulkDocs([t],r);case 1:if(null==(n=e.sent[0])||!n.name){e.next=2;break}throw n;case 2:return e.abrupt("return",n);case 3:case"end":return e.stop()}}),e)}))),this.remove=s()(u().mark((function e(t,a){var s;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",i.put(((s={})[r]=t,s[n]=a,s[o]=!0,s)));case 1:case"end":return e.stop()}}),e)}))),this.putAttachment&&(this.putAttachment=s()(u().mark((function e(t,o,s,c,l){var p,d,f,m,h,v;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return"string"==typeof s?(h=c,v=s):(h=s,v="0-latest"),e.abrupt("return",i.put(((m={})[r]=t,m[n]=v,m[a]=((f={})[o]={content_type:null!==(p=null!==(d=h.type)&&void 0!==d?d:l)&&void 0!==p?p:"application/octet-stream",data:h},f),m)));case 1:case"end":return e.stop()}}),e)})))),this.removeAttachment&&(this.removeAttachment=s()(u().mark((function e(t,o,s){var c,l;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",i.put(((l={})[r]=t,l[n]=s,l[a]=((c={})[o]={content_type:"application/octet-stream",data:null},c),l)));case 1:case"end":return e.stop()}}),e)}))))}}},g=function(){var e=s()(u().mark((function e(t,r,n){var a,o,i,s,c,l,p,d,f,h,v,b,y;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,t.getIndexes();case 1:a=e.sent.indexes.filter((function(e){return e.name.endsWith("-GenericIndex")})),o=m(a);case 2:if((i=o()).done){e.next=7;break}s=i.value,c=!1,l=0,p=Object.entries(r);case 3:if(!(l<p.length)){e.next=5;break}if(d=p[l],f=d[0],h=d[1],!s.name.startsWith(f+"-")){e.next=4;break}for(v=0,b=R(n,h);v<b.length;v++)y=b[v],[f+"-"+y+"-GenericIndex",f+"-GenericIndex"].includes(s.name)&&(c=!0);return e.abrupt("continue",5);case 4:l++,e.next=3;break;case 5:if(c){e.next=6;break}return e.next=6,t.deleteIndex(s);case 6:e.next=2;break;case 7:case"end":return e.stop()}}),e)})));return function(t,r,n){return e.apply(this,arguments)}}(),x=function(e,t){var r,n=function(r){return void 0===r&&(r={}),r=(0,l.extend)(!0,(0,l.copy)(e.fetch),r),Array.isArray(t)&&t.length>0&&(r.signal=t.pop()),r},a=new Map([[408,"Request Timeout"],[425,"Too Early"],[429,"Too Many Requests"],[502,"Bad Gateway"],[503,"Service Unavailable"],[504,"Gateway Timeout"]]);return o()({},e,{fetch:(r=s()(u().mark((function t(r,o){var i,s,c,l,f,m;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return i=e.fetchInterceptor,s=i.numberOfRetries,c=i.retryIntervalInSeconds,l=i.exponentialBackoff,f=i.maximumRetryIntervallInSeconds,m=(0,d.fromFetch)(r,n(o)).pipe((0,p.map)((function(e){if(a.has(e.status))throw e;return e})),(0,p.retry)({count:s,delay:function(e,t){if("number"!=typeof e.status)throw e;var r=e;if(r.headers.has("retry-after")){var n=r.headers.get("retry-after");if("string"==typeof n){var a=parseInt(n);if(String(a)===n)return b.info("Retry in "+n+" seconds","according to given retry value."),(0,p.timer)(1e3*a);var o=new Date(n);if(!isNaN(o.getTime())){var i=new Date;if(i<o){if(f<(o.getTime()-i.getTime())/1e3)return b.info("Retry at",o.toUTCString(),"according to given retry","value."),(0,p.timer)(o);b.warn("The recommended retry attempt is",o.toUTCString(),"further in the future than the","configured maximum wait time of",f,"seconds.")}else b.warn("Given retry time recommendation","from server is in the past and","has to be ignored therefore.")}}}var s=l?Math.pow(2,t-1)*c:c;return(0,p.timer)(1e3*Math.min(s,f))}})),t.abrupt("return",(0,p.lastValueFrom)(m));case 1:case"end":return t.stop()}}),t)}))),function(e,t){return r.apply(this,arguments)})})},w=function(e,t,r){var n=(0,l.represent)(e);return n.length<=t?n.length>r?n.substring(0,r-3)+"...":n:"DOCUMENT IS TOO BIG TO REPRESENT"},k=function(){var e=s()(u().mark((function e(t,r,n,a,i,s,c,p){var d,m,h,v,y;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return void 0===i&&(i=!0),void 0===s&&(s="_id"),void 0===c&&(c="_rev"),void 0===p&&(p="_design/"),m=o()(((d={})[s]=""+p+r,d.language="javascript",d.version=f,d),n),e.prev=1,e.next=2,t.get(""+p+r);case 2:return h=e.sent,m[c]=h[c],e.next=3,t.put(m);case 3:i&&b.info(a+" updated."),e.next=8;break;case 4:return e.prev=4,v=e.catch(1),i&&("not_found"===v.error||"not_found"===v.name||"missing"===v.message||"missing"===v.reason?b.info(a+" not available. Create new one."):b.info(a+" couldn't be updated:",'"'+(0,l.represent)(v)+'" create new one.')),e.prev=5,e.next=6,t.put(m);case 6:i&&b.info(a+" installed/updated."),e.next=8;break;case 7:throw e.prev=7,y=e.catch(5),new Error(a+" couldn't be installed/updated: \""+(0,l.represent)(y)+'".',{cause:y});case 8:case"end":return e.stop()}}),e,null,[[1,4],[5,7]])})));return function(t,r,n,a,o,i,s,c){return e.apply(this,arguments)}}(),O=function(){var e=s()(u().mark((function e(t,r,n){var a,o,i,s;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(void 0===n&&(n=!0),a=t.couchdb,o=r.couchdb,i=j(o),t.couchdb.server.expressPouchDBInstance?(a.connection=new a.connector(o.databaseName,a.server.runner.configuration),(s=a.connection).installValidationMethods(),s.installCouchDBWebNodePlugin("backend"),s.setMaxListeners(1/0)):a.connection=new a.connector(i,x(o.connector)),!n){e.next=5;break}return e.prev=1,e.next=2,(0,l.checkReachability)(i);case 2:e.next=5;break;case 3:if(e.prev=3,e.catch(1),b.info("Database could not be retrieved yet: Creating it."),l.globalContext.fetch){e.next=4;break}throw new Error("Missing fetch implementation.");case 4:return e.next=5,l.globalContext.fetch(i,{method:"PUT"});case 5:return e.abrupt("return",t);case 6:case"end":return e.stop()}}),e,null,[[1,3]])})));return function(t,r,n){return e.apply(this,arguments)}}(),j=function(e,t,r){void 0===t&&(t=!0),void 0===r&&(r=!1);var n=/^https?:\/\//.test(e.url)?e.url:"http://{1}"+e.runner.host+":"+String(e.runner.port);return(0,l.format)(n,r?e.admin.name+":"+e.admin.password+"@":"")+(t?"/"+e.databaseName:"")},A=function(e,t,r){var n=!0;return Promise.race([e.then((function(){n=!1})),(0,l.timeout)(1e3*t).then((function(){n&&b.warn("Timeout of",String(t)+".","seconds reached while waiting for "+r+".")}))])},S=function(e){for(var t=e.property.name.special,r=t.allowedRole,n=t.attachment,a={},i=P(e),s=0,c=Object.entries(i);s<c.length;s++){var u=c[s],p=u[0],d=u[1];if(d[r]){a[p]=o()({properties:{}},D(d[r]));for(var f=0,m=Object.entries(d);f<m.length;f++){var h=m[f],v=h[0],b=h[1];if((0,l.isObject)(b))if(v===n){a[p].attachments={};for(var y=0,g=Object.entries(b);y<g.length;y++){var x=g[y],w=x[0],k=x[1];a[p].attachments[w]=D(k.allowedRoles)}}else b.allowedRoles&&(a[p].properties[v]=D(b.allowedRoles))}}else a[p]={properties:{},read:[],write:[]}}return a},T=function(e){return(0,l.isObject)(e)},R=function(e,t){var r=e.property.name.special;return Object.keys(t).filter((function(n){var a=t[n];return T(a)&&Object.prototype.hasOwnProperty.call(a,"index")&&a.index||T(a)&&!(Object.prototype.hasOwnProperty.call(a,"index")&&!a.index||e.property.name.reserved.concat(r.additional,r.allowedRole,r.attachment,r.conflict,r.constraint.execution,r.constraint.expression,r.deleted,r.deletedConflict,r.extend,r.maximumAggregatedSize,r.minimumAggregatedSize,r.oldType,r.id,r.revision,r.revisions,r.revisionsInformation,r.type,r.updateStrategy).includes(n)||a.type&&("string"==typeof a.type&&a.type.endsWith("[]")||Array.isArray(a.type)&&a.type.length&&Array.isArray(a.type[0])||Object.prototype.hasOwnProperty.call(e.entities,a.type)))})).concat([r.id,r.revision]).sort()},I=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=m([].concat(t[e][r]));!(n=a()).done;){var o=n.value;t[e]=(0,l.extend)(!0,(0,l.copy)(I(o,t,r)),t[e])}delete t[e][r]}return t[e]},P=function(e){for(var t=e.property.name.special,r={},n=e.property.name.typePattern,a=0,o=Object.keys(e.entities);a<o.length;a++){var i=o[a];if(!new RegExp(n.public).test(i)&&!new RegExp(n.private).test(i))throw new Error('Model names have to match "'+n.public+'" or "'+n.private+'" for private one (given name: "'+i+'").');r[i]=I(i,e.entities,t.extend)}for(var s=0,c=Object.values(r);s<c.length;s++)for(var u=c[s],p=0,d=Object.entries(u);p<d.length;p++){var f=d[p],m=f[0],h=f[1];if(m===t.attachment)for(var v=h,b=0,y=Object.entries(v);b<y.length;b++){var g=y[b],x=g[0],w=g[1];v[x]=(0,l.extend)(!0,(0,l.copy)(e.property.defaultSpecification),w)}else[t.allowedRole,t.constraint.execution,t.constraint.expression,t.extend,t.maximumAggregatedSize,t.minimumAggregatedSize,t.oldType].includes(m)||(u[m]=(0,l.extend)(!0,(0,l.copy)(e.property.defaultSpecification),h))}return r},D=function(e){if(Array.isArray(e))return{read:e,write:e};if("object"==typeof e){for(var t={read:[],write:[]},r=0,n=Object.keys(t);r<n.length;r++){var a=n[r];Object.prototype.hasOwnProperty.call(e,a)&&(Array.isArray(e[a])?t[a]=e[a]:t[a]=[e[a]])}return t}return{read:[e],write:[e]}};module.exports=n})();
1
+ (()=>{"use strict";var e=[,e=>{e.exports=require("@babel/runtime/helpers/extends")},e=>{e.exports=require("@babel/runtime/helpers/asyncToGenerator")},e=>{e.exports=require("@babel/runtime/regenerator")},e=>{e.exports=require("clientnode")}],t={};function r(n){var a=t[n];if(void 0!==a)return a.exports;var o=t[n]={exports:{}};return e[n](o,o.exports,r),o.exports}r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};r.r(n),r.d(n,{TOGGLE_LATEST_REVISION_DETERMINING:()=>h,determineAllowedModelRolesMapping:()=>S,determineGenericIndexablePropertyNames:()=>I,ensureValidationDocumentPresence:()=>k,extendModel:()=>R,extendModels:()=>P,getConnectorOptions:()=>x,getEffectiveURL:()=>j,getPouchDBPlugin:()=>y,initializeConnection:()=>O,isPropertySpecification:()=>T,log:()=>b,mayStripRepresentation:()=>w,normalizeAllowedRoles:()=>D,removeDeprecatedIndexes:()=>g,waitWithTimeout:()=>A});var a=r(1),o=r.n(a),i=r(2),s=r.n(i),c=r(3),u=r.n(c),l=r(4);const p=require("rxjs"),d=require("rxjs/fetch"),f="1.0.804";function m(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={}.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 h=Symbol("toggleLatestRevisionDetermining"),b=new l.Logger({name:"web-node.couchdb"}),y=function(e){var t=e.model.property.name.special,r=t.id,n=t.revision,a=t.attachment,o=t.deleted;return{installCouchDBWebNodePlugin:function(t){var i=this;if(this.bulkDocs){var c=this.bulkDocs.bind(this);this.bulkDocs=s()(u().mark((function a(o){var s,p,d,f,v,y,g,x,w,k,O,j,A,S,T,I,R,P,D,E,_,M,N,C=arguments;return u().wrap((function(a){for(;;)switch(a.prev=a.next){case 0:b.debug("BulkDocs called from:",t),(0,l.isObject)(o)&&1===Object.keys(o).length&&"docs"in o&&Array.isArray(o.docs)&&(o=o.docs);for(s=C.length,p=new Array(s>1?s-1:0),d=1;d<s;d++)p[d-1]=C[d];f=p.length>0&&p[p.length-1]===h,v=f?!e.skipLatestRevisionDetermining:e.skipLatestRevisionDetermining,f&&p.pop(),y=!Array.isArray(o)&&(0,l.isObject)(o)&&r in o?[o]:o,g=e.maximumNumberOfEntitiesInBulkOperation,x=[],w=0;case 1:if(!(w<y.length)){a.next=4;break}return k=y.slice(w,w+g),a.next=2,c.call.apply(c,[i,k].concat(p));case 2:O=a.sent,x=x.concat(O);case 3:w+=g,a.next=1;break;case 4:j=[],A=[],S=0,T=m(x);case 5:if((I=T()).done){a.next=12;break}if(R=I.value,"object"!=typeof y[S]){a.next=10;break}if(!(n in y[S])||"conflict"!==R.name||!["0-latest","0-upsert"].includes(y[S][n])){a.next=6;break}A.push(y[S]),j.push(S),a.next=10;break;case 6:if(!(r in y[S]&&e.ignoreNoChangeError&&"name"in R&&"forbidden"===R.name&&"message"in R&&R.message.startsWith("NoChange:"))){a.next=10;break}if(x[S]={id:y[S][r],ok:!0},v){a.next=10;break}if(!(n in y[S])||["0-latest","0-upsert"].includes(y[S][n])){a.next=7;break}M=y[S][n],a.next=9;break;case 7:return a.next=8,i.get(x[S].id);case 8:N=n,M=a.sent[N];case 9:x[S].rev=M;case 10:S+=1;case 11:a.next=5;break;case 12:if(!A.length){a.next=14;break}return y=A,f&&p.push(h),a.next=13,i.bulkDocs.apply(i,[y].concat(p));case 13:for(P=a.sent,D=m(P);!(E=D()).done;)_=E.value,x[j.shift()]=_;case 14:return a.abrupt("return",x);case 15:case"end":return a.stop()}}),a)})))}this.post=this.put=s()(u().mark((function e(t,r){var n;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,i.bulkDocs([t],r);case 1:if(null==(n=e.sent[0])||!n.name){e.next=2;break}throw n;case 2:return e.abrupt("return",n);case 3:case"end":return e.stop()}}),e)}))),this.remove=s()(u().mark((function e(t,a){var s;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",i.put(((s={})[r]=t,s[n]=a,s[o]=!0,s)));case 1:case"end":return e.stop()}}),e)}))),this.putAttachment&&(this.putAttachment=s()(u().mark((function e(t,o,s,c,l){var p,d,f,m,v,h;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return"string"==typeof s?(v=c,h=s):(v=s,h="0-latest"),e.abrupt("return",i.put(((m={})[r]=t,m[n]=h,m[a]=((f={})[o]={content_type:null!==(p=null!==(d=v.type)&&void 0!==d?d:l)&&void 0!==p?p:"application/octet-stream",data:v},f),m)));case 1:case"end":return e.stop()}}),e)})))),this.removeAttachment&&(this.removeAttachment=s()(u().mark((function e(t,o,s){var c,l;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",i.put(((l={})[r]=t,l[n]=s,l[a]=((c={})[o]={content_type:"application/octet-stream",data:null},c),l)));case 1:case"end":return e.stop()}}),e)}))))}}},g=function(){var e=s()(u().mark((function e(t,r,n){var a,o,i,s,c,l,p,d,f,v,h,b,y;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,t.getIndexes();case 1:a=e.sent.indexes.filter((function(e){return e.name.endsWith("-GenericIndex")})),o=m(a);case 2:if((i=o()).done){e.next=7;break}s=i.value,c=!1,l=0,p=Object.entries(r);case 3:if(!(l<p.length)){e.next=5;break}if(d=p[l],f=d[0],v=d[1],!s.name.startsWith(f+"-")){e.next=4;break}for(h=0,b=I(n,v);h<b.length;h++)y=b[h],[f+"-"+y+"-GenericIndex",f+"-GenericIndex"].includes(s.name)&&(c=!0);return e.abrupt("continue",5);case 4:l++,e.next=3;break;case 5:if(c){e.next=6;break}return e.next=6,t.deleteIndex(s);case 6:e.next=2;break;case 7:case"end":return e.stop()}}),e)})));return function(t,r,n){return e.apply(this,arguments)}}(),x=function(e,t){var r=new Map([[408,"Request Timeout"],[425,"Too Early"],[429,"Too Many Requests"],[502,"Bad Gateway"],[503,"Service Unavailable"],[504,"Gateway Timeout"]]);return o()({},e,{fetch:function(n,a){var o=e.fetchInterceptor,i=o.numberOfRetries,s=o.retryIntervalInSeconds,c=o.exponentialBackoff,u=o.maximumRetryIntervallInSeconds,f=(0,d.fromFetch)(n,function(r){var n;return void 0===r&&(r={}),r=(0,l.extend)(!0,(0,l.copy)(e.fetch),r),Array.isArray(t)&&t.length>0&&(r.signal=null==(n=t.pop())?void 0:n.controller.signal),r}(a)).pipe((0,p.map)((function(e){if(r.has(e.status))throw e;return e})),(0,p.retry)({count:i,delay:function(e,t){if("number"!=typeof e.status)throw e;var r=e;if(r.headers.has("retry-after")){var n=r.headers.get("retry-after");if("string"==typeof n){var a=parseInt(n);if(String(a)===n)return b.info("Retry in "+n+" seconds","according to given retry value."),(0,p.timer)(1e3*a);var o=new Date(n);if(!isNaN(o.getTime())){var i=new Date;if(i<o){if(u<(o.getTime()-i.getTime())/1e3)return b.info("Retry at",o.toUTCString(),"according to given retry","value."),(0,p.timer)(o);b.warn("The recommended retry attempt is",o.toUTCString(),"further in the future than the","configured maximum wait time of",u,"seconds.")}else b.warn("Given retry time recommendation","from server is in the past and","has to be ignored therefore.")}}}var l=c?Math.pow(2,t-1)*s:s;return(0,p.timer)(1e3*Math.min(l,u))}}));return(0,p.lastValueFrom)(f)}})},w=function(e,t,r){var n=(0,l.represent)(e);return n.length<=t?n.length>r?n.substring(0,r-3)+"...":n:"DOCUMENT IS TOO BIG TO REPRESENT"},k=function(){var e=s()(u().mark((function e(t,r,n,a,i,s,c,p){var d,m,v,h,y;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return void 0===i&&(i=!0),void 0===s&&(s="_id"),void 0===c&&(c="_rev"),void 0===p&&(p="_design/"),m=o()(((d={})[s]=""+p+r,d.language="javascript",d.version=f,d),n),e.prev=1,e.next=2,t.get(""+p+r);case 2:return v=e.sent,m[c]=v[c],e.next=3,t.put(m);case 3:i&&b.info(a+" updated."),e.next=8;break;case 4:return e.prev=4,h=e.catch(1),i&&("not_found"===h.error||"not_found"===h.name||"missing"===h.message||"missing"===h.reason?b.info(a+" not available. Create new one."):b.info(a+" couldn't be updated:",'"'+(0,l.represent)(h)+'" create new one.')),e.prev=5,e.next=6,t.put(m);case 6:i&&b.info(a+" installed/updated."),e.next=8;break;case 7:throw e.prev=7,y=e.catch(5),new Error(a+" couldn't be installed/updated: \""+(0,l.represent)(y)+'".',{cause:y});case 8:case"end":return e.stop()}}),e,null,[[1,4],[5,7]])})));return function(t,r,n,a,o,i,s,c){return e.apply(this,arguments)}}(),O=function(){var e=s()(u().mark((function e(t,r,n){var a,o,i,s;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(void 0===n&&(n=!0),a=t.couchdb,o=r.couchdb,i=j(o),t.couchdb.server.expressPouchDBInstance?(a.connection=new a.connector(o.databaseName,a.server.runner.configuration),a.connection.installValidationMethods()):a.connection=new a.connector(i,x(o.connector)),a.connection.installCouchDBWebNodePlugin("backend"),a.connection.setMaxListeners(1/0),!n){e.next=4;break}return e.prev=1,e.next=2,a.connection.allDocs({limit:1});case 2:e.next=4;break;case 3:throw e.prev=3,s=e.catch(1),new Error("Database has not been installed yet: "+(0,l.represent)(s),{cause:s});case 4:return e.abrupt("return",t);case 5:case"end":return e.stop()}}),e,null,[[1,3]])})));return function(t,r,n){return e.apply(this,arguments)}}(),j=function(e,t,r){void 0===t&&(t=!0),void 0===r&&(r=!1);var n=/^https?:\/\//.test(e.url)?e.url:"http://{1}"+e.runner.host+":"+String(e.runner.port);return(0,l.format)(n,r?e.admin.name+":"+e.admin.password+"@":"")+(t?"/"+e.databaseName:"")},A=function(e,t,r){var n=!0;return Promise.race([e.then((function(){n=!1})),(0,l.timeout)(1e3*t).then((function(){n&&b.warn("Timeout of",String(t)+".","seconds reached while waiting for "+r+".")}))])},S=function(e){for(var t=e.property.name.special,r=t.allowedRole,n=t.attachment,a={},i=P(e),s=0,c=Object.entries(i);s<c.length;s++){var u=c[s],p=u[0],d=u[1];if(d[r]){a[p]=o()({properties:{}},D(d[r]));for(var f=0,m=Object.entries(d);f<m.length;f++){var v=m[f],h=v[0],b=v[1];if((0,l.isObject)(b))if(h===n){a[p].attachments={};for(var y=0,g=Object.entries(b);y<g.length;y++){var x=g[y],w=x[0],k=x[1];a[p].attachments[w]=D(k.allowedRoles)}}else b.allowedRoles&&(a[p].properties[h]=D(b.allowedRoles))}}else a[p]={properties:{},read:[],write:[]}}return a},T=function(e){return(0,l.isObject)(e)},I=function(e,t){var r=e.property.name.special;return Object.keys(t).filter((function(n){var a=t[n];return T(a)&&Object.prototype.hasOwnProperty.call(a,"index")&&a.index||T(a)&&!(Object.prototype.hasOwnProperty.call(a,"index")&&!a.index||e.property.name.reserved.concat(r.additional,r.allowedRole,r.attachment,r.conflict,r.constraint.execution,r.constraint.expression,r.deleted,r.deletedConflict,r.extend,r.maximumAggregatedSize,r.minimumAggregatedSize,r.oldType,r.id,r.revision,r.revisions,r.revisionsInformation,r.type,r.updateStrategy).includes(n)||a.type&&("string"==typeof a.type&&a.type.endsWith("[]")||Array.isArray(a.type)&&a.type.length&&Array.isArray(a.type[0])||Object.prototype.hasOwnProperty.call(e.entities,a.type)))})).concat([r.id,r.revision]).sort()},R=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=m([].concat(t[e][r]));!(n=a()).done;){var o=n.value;t[e]=(0,l.extend)(!0,(0,l.copy)(R(o,t,r)),t[e])}delete t[e][r]}return t[e]},P=function(e){for(var t=e.property.name.special,r={},n=e.property.name.typePattern,a=0,o=Object.keys(e.entities);a<o.length;a++){var i=o[a];if(!new RegExp(n.public).test(i)&&!new RegExp(n.private).test(i))throw new Error('Model names have to match "'+n.public+'" or "'+n.private+'" for private one (given name: "'+i+'").');r[i]=R(i,e.entities,t.extend)}for(var s=0,c=Object.values(r);s<c.length;s++)for(var u=c[s],p=0,d=Object.entries(u);p<d.length;p++){var f=d[p],m=f[0],v=f[1];if(m===t.attachment)for(var h=v,b=0,y=Object.entries(h);b<y.length;b++){var g=y[b],x=g[0],w=g[1];h[x]=(0,l.extend)(!0,(0,l.copy)(e.property.defaultSpecification),w)}else[t.allowedRole,t.constraint.execution,t.constraint.expression,t.extend,t.maximumAggregatedSize,t.minimumAggregatedSize,t.oldType].includes(m)||(u[m]=(0,l.extend)(!0,(0,l.copy)(e.property.defaultSpecification),v))}return r},D=function(e){if(Array.isArray(e))return{read:e,write:e};if("object"==typeof e){for(var t={read:[],write:[]},r=0,n=Object.keys(t);r<n.length;r++){var a=n[r];Object.prototype.hasOwnProperty.call(e,a)&&(Array.isArray(e[a])?t[a]=e[a]:t[a]=[e[a]])}return t}return{read:[e],write:[e]}};module.exports=n})();