@decaf-ts/for-pouch 0.9.2 → 0.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- var e,t;e=this,t=function(e,t,r,o,a,s,i,n,c,d,h,u){"use strict";function l(e){var t=Object.create(null);return e&&Object.keys(e).forEach(r=>{if("default"!==r){var o=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,o.get?o:{enumerable:!0,get:()=>e[r]})}}),t.default=e,Object.freeze(t)}var f=l(c),p=l(d),g=l(h);const w="pouch",E="local_dbs";class y extends o.CouchDBRepository{constructor(e,t,r=!1){super(e,t,r)}override(e){return super.override(e).for(e)}}async function b(e,t,r,o){try{const t=e.get("UUID");o[r]=t}catch(e){throw new s.UnsupportedError("No User found in context. Please provide a user in the context")}}class m extends o.CouchDBAdapter{constructor(e,t){super(e,w,t),this._pluginsRegistered=!1}registerPlugins(){if(this._pluginsRegistered)return;const e=[f,p,g,...this.config.plugins];for(const t of e)try{n.plugin(t)}catch(e){if(e instanceof Error&&e.message.includes("redefine property"))continue;throw e}this._pluginsRegistered=!0}buildClient(e,t){this.registerPlugins();const{host:r,protocol:o,dbName:s,storagePath:i}=this.config;try{return new n(r?`${o}://${e?`${e?encodeURIComponent(e):""}${e&&t?":"+encodeURIComponent(t):""}@`:""}${r}/${s}`:`${i||E}/${s}`)}catch(e){throw new a.InternalError("Failed to create PouchDB client: "+e)}}getAdminClient(){return this.config.adminUser?(this._adminClient||(this._adminClient=this.buildClient(this.config.adminUser,this.config.adminPassword??this.config.password)),this._adminClient):this.getClient()}getClient(){return this._client||(this._client=this.buildClient(this.config.user,this.config.password)),this._client}async flags(e,t,o,...a){return this.config.user||(this.config.user=r.randomUUID()),super.flags(e,t,Object.assign({UUID:this.config.user},o),...a)}repository(){return y}async index(...e){const t=this.getAdminClient();try{const r=3,a=o.generateIndexes(e),s=new Set;try{const e=await t.get("_index");(e?.indexes||[]).forEach(e=>{e.name&&s.add(e.name)})}catch{}for(const e of a){const o=e.name??e.ddoc??"index";if(s.has(o))continue;let a=0;for(;;)try{await t.createIndex(e),s.add(o);break}catch(s){if(409===s?.status||"conflict"===s?.error)break;if(500===s?.status){a+=1;const s="_design/"+(e.ddoc??o);try{const e=await t.get(s);await t.remove(s,e._rev)}catch{}if(a>=r)break;await new Promise(e=>setTimeout(e,100*a));continue}throw s}}const i=o.generateViews(e);for(const e of i)try{await t.put(e)}catch(r){if(409!==r?.status&&"conflict"!==r?.error)throw r;{const r=await t.get(e._id);await t.put({...e,_rev:r._rev})}}}catch(e){}}async create(e,t,r,...o){let s;try{s=await this.client.put(r)}catch(e){throw this.parseError(e)}if(!s.ok)throw new a.InternalError(`Failed to insert doc id: ${t} in table ${i.Model.tableName(e)}`);return this.assignMetadata(r,s.rev)}async createAll(e,t,r,...o){let s;try{s=await this.client.bulkDocs(r)}catch(e){throw this.parseError(e)}if(!s.every(e=>e.ok)){const e=s.reduce((e,t,r)=>(t.error&&e.push(`el ${r}: ${t.error}${t.reason?" - "+t.reason:""}`),e),[]);throw new a.InternalError(e.join("\n"))}return this.assignMultipleMetadata(r,s.map(e=>e.rev))}async read(e,t,...r){const o=this.generateId(i.Model.tableName(e),t);let a;try{a=await this.client.get(o)}catch(e){throw this.parseError(e)}return this.assignMetadata(a,a._rev)}async readAll(e,t,...r){const s=i.Model.tableName(e);return(await this.client.bulkGet({docs:t.map(e=>({id:this.generateId(s,e)}))})).results.reduce((e,t)=>(t.docs.forEach(t=>{if(t.error||!t.ok)throw this.parseError(t.error||new a.InternalError("Missing valid response"));const r=Object.assign({},t.ok);e.push(this.assignMetadata(r,t.ok[o.CouchDBKeys.REV]))}),e),[])}async update(e,t,r,...o){let s;try{s=await this.client.put(r)}catch(e){throw this.parseError(e)}if(!s.ok)throw new a.InternalError(`Failed to update doc id: ${t} in table ${i.Model.tableName(e)}`);return this.assignMetadata(r,s.rev)}async updateAll(e,t,r,...o){let s;try{s=await this.client.bulkDocs(r)}catch(e){throw this.parseError(e)}if(!s.every(e=>!e.error)){const e=s.reduce((e,t,r)=>(t.error&&e.push(`el ${r}: ${t.error}${t.reason?" - "+t.reason:""}`),e),[]);throw new a.InternalError(e.join("\n"))}return this.assignMultipleMetadata(r,s.map(e=>e.rev))}async delete(e,t,...r){const o=this.generateId(i.Model.tableName(e),t);let a;try{a=await this.client.get(o),await this.client.remove(o,a._rev)}catch(e){throw this.parseError(e)}return this.assignMetadata(a,a._rev)}async deleteAll(e,t,...r){const{log:s}=this.logCtx(r,this.deleteAll),n=i.Model.tableName(e),c=await this.client.bulkGet({docs:t.map(e=>({id:this.generateId(n,e)}))}),d=c.results.reduce((e,t)=>(t.docs.forEach(t=>{if(t.error)throw this.parseError(t.error||new a.InternalError("Missing valid response"));const r=Object.assign({},t.ok);r[o.CouchDBKeys.DELETED]=!0,e.push(r)}),e),[]);return(await this.client.bulkDocs(d)).forEach(e=>{const t=e.error;t&&s.error(t+"")}),c.results.reduce((e,t)=>(t.docs.forEach(t=>{if(t.error||!t.ok)throw this.parseError(t.error||new a.InternalError("Missing valid response"));const r=Object.assign({},t.ok);e.push(this.assignMetadata(r,t.ok[o.CouchDBKeys.REV]))}),e),[])}async raw(e,t=!0,...r){try{const o=await this.client.find(e);if(o.warning){const{log:e}=await this.logCtx(r,this.raw,!0);e.for(this.raw).warn(o.warning)}return t?o.docs:o}catch(e){throw this.parseError(e)}}async view(e,t,r,...o){try{const o=`${e}/${t}`;return await this.client.query(o,r)}catch(e){throw this.parseError(e)}}parseError(e,t){return m.parseError(e,t)}static parseError(e,t){if(e instanceof a.BaseError)return e;let r="";if("string"==typeof e){if(r=e,r.match(/already exist|update conflict/g))return new a.ConflictError(r);if(r.match(/missing|deleted/g))return new a.NotFoundError(r)}else e.status?(r=e.status,t=t||e.message):e.code?(r=e.code,t=t||e.message):e.statusCode?(r=e.statusCode,t=t||e.message):r=e.message;switch(r.toString()){case"401":case"412":case"409":return new a.ConflictError(t);case"404":return new a.NotFoundError(t);case"400":return r.toString().match(/No\sindex\sexists/g)?new o.IndexError(e):new a.InternalError(e);default:return r.toString().match(/ECONNREFUSED/g)?new s.ConnectionError(e):new a.InternalError(e)}}static decoration(){super.decoration(),u.Decoration.flavouredAs(w).for(s.PersistenceKeys.CREATED_BY).define(a.onCreate(b),u.propMetadata(s.PersistenceKeys.CREATED_BY,{})).apply(),u.Decoration.flavouredAs(w).for(s.PersistenceKeys.UPDATED_BY).define(a.onCreateUpdate(b),u.propMetadata(s.PersistenceKeys.UPDATED_BY,{})).apply()}}s.Adapter.setCurrent(w),m.decoration();const C="##VERSION##",v="##PACKAGE##";u.Metadata.registerLibrary(v,C),e.COMMIT="1e21646",e.DefaultLocalStoragePath=E,e.FULL_VERSION="0.9.1-1e21646",e.PACKAGE_NAME=v,e.PouchAdapter=m,e.PouchFlavour=w,e.PouchRepository=y,e.VERSION=C,e.createdByOnPouchCreateUpdate=b},"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("reflect-metadata"),require("crypto"),require("@decaf-ts/for-couchdb"),require("@decaf-ts/db-decorators"),require("@decaf-ts/core"),require("@decaf-ts/decorator-validation"),require("pouchdb-core"),require("pouchdb-mapreduce"),require("pouchdb-replication"),require("pouchdb-find"),require("@decaf-ts/decoration")):"function"==typeof define&&define.amd?define(["exports","reflect-metadata","crypto","@decaf-ts/for-couchdb","@decaf-ts/db-decorators","@decaf-ts/core","@decaf-ts/decorator-validation","pouchdb-core","pouchdb-mapreduce","pouchdb-replication","pouchdb-find","@decaf-ts/decoration"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["for-pouch"]={},e.reflectMetadata,e.crypto,e.decafTsForCouchdb,e.decafTsDbDecorators,e.decafTsCore,e.decafTsDecoratorValidation,e.pouchdbCore,e.pouchdbMapreduce,e.pouchdbReplication,e.pouchdbFind,e.decafTsDecoration);
1
+ var e,t;e=this,t=function(e,t,r,o,a,s,i,n,c,d,h,u){"use strict";function l(e){var t=Object.create(null);return e&&Object.keys(e).forEach(r=>{if("default"!==r){var o=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,o.get?o:{enumerable:!0,get:()=>e[r]})}}),t.default=e,Object.freeze(t)}var f=l(c),p=l(d),g=l(h);const w="pouch",E="local_dbs";class y extends o.CouchDBRepository{constructor(e,t,r=!1){super(e,t,r)}override(e){return super.override(e).for(e)}}async function b(e,t,r,o){try{const t=e.get("UUID");o[r]=t}catch(e){throw new s.UnsupportedError("No User found in context. Please provide a user in the context")}}class m extends o.CouchDBAdapter{constructor(e,t){super(e,w,t),this._pluginsRegistered=!1}registerPlugins(){if(this._pluginsRegistered)return;const e=[f,p,g,...this.config.plugins];for(const t of e)try{n.plugin(t)}catch(e){if(e instanceof Error&&e.message.includes("redefine property"))continue;throw e}this._pluginsRegistered=!0}buildClient(e,t){this.registerPlugins();const{host:r,protocol:o,dbName:s,storagePath:i}=this.config;try{return new n(r?`${o}://${e?`${e?encodeURIComponent(e):""}${e&&t?":"+encodeURIComponent(t):""}@`:""}${r}/${s}`:`${i||E}/${s}`)}catch(e){throw new a.InternalError("Failed to create PouchDB client: "+e)}}getAdminClient(){return this.config.adminUser?(this._adminClient||(this._adminClient=this.buildClient(this.config.adminUser,this.config.adminPassword??this.config.password)),this._adminClient):this.getClient()}getClient(){return this._client||(this._client=this.buildClient(this.config.user,this.config.password)),this._client}async flags(e,t,o,...a){return this.config.user||(this.config.user=r.randomUUID()),super.flags(e,t,Object.assign({UUID:this.config.user},o),...a)}repository(){return y}async index(...e){const t=this.getAdminClient();try{const r=3,a=o.generateIndexes(e),s=new Set;try{const e=await t.get("_index");(e?.indexes||[]).forEach(e=>{e.name&&s.add(e.name)})}catch{}for(const e of a){const o=e.name??e.ddoc??"index";if(s.has(o))continue;let a=0;for(;;)try{await t.createIndex(e),s.add(o);break}catch(s){if(409===s?.status||"conflict"===s?.error)break;if(500===s?.status){a+=1;const s="_design/"+(e.ddoc??o);try{const e=await t.get(s);await t.remove(s,e._rev)}catch{}if(a>=r)break;await new Promise(e=>setTimeout(e,100*a));continue}throw s}}const i=o.generateViews(e);for(const e of i)try{await t.put(e)}catch(r){if(409!==r?.status&&"conflict"!==r?.error)throw r;{const r=await t.get(e._id);await t.put({...e,_rev:r._rev})}}}catch(e){}}async create(e,t,r,...o){let s;try{s=await this.client.put(r)}catch(e){throw this.parseError(e)}if(!s.ok)throw new a.InternalError(`Failed to insert doc id: ${t} in table ${i.Model.tableName(e)}`);return this.assignMetadata(r,s.rev)}async createAll(e,t,r,...o){let s;try{s=await this.client.bulkDocs(r)}catch(e){throw this.parseError(e)}if(!s.every(e=>e.ok)){const e=s.reduce((e,t,r)=>(t.error&&e.push(`el ${r}: ${t.error}${t.reason?" - "+t.reason:""}`),e),[]);throw new a.InternalError(e.join("\n"))}return this.assignMultipleMetadata(r,s.map(e=>e.rev))}async read(e,t,...r){const o=this.generateId(i.Model.tableName(e),t);let a;try{a=await this.client.get(o)}catch(e){throw this.parseError(e)}return this.assignMetadata(a,a._rev)}async readAll(e,t,...r){const s=i.Model.tableName(e);return(await this.client.bulkGet({docs:t.map(e=>({id:this.generateId(s,e)}))})).results.reduce((e,t)=>(t.docs.forEach(t=>{if(t.error||!t.ok)throw this.parseError(t.error||new a.InternalError("Missing valid response"));const r=Object.assign({},t.ok);e.push(this.assignMetadata(r,t.ok[o.CouchDBKeys.REV]))}),e),[])}async update(e,t,r,...o){let s;try{s=await this.client.put(r)}catch(e){throw this.parseError(e)}if(!s.ok)throw new a.InternalError(`Failed to update doc id: ${t} in table ${i.Model.tableName(e)}`);return this.assignMetadata(r,s.rev)}async updateAll(e,t,r,...o){let s;try{s=await this.client.bulkDocs(r)}catch(e){throw this.parseError(e)}if(!s.every(e=>!e.error)){const e=s.reduce((e,t,r)=>(t.error&&e.push(`el ${r}: ${t.error}${t.reason?" - "+t.reason:""}`),e),[]);throw new a.InternalError(e.join("\n"))}return this.assignMultipleMetadata(r,s.map(e=>e.rev))}async delete(e,t,...r){const o=this.generateId(i.Model.tableName(e),t);let a;try{a=await this.client.get(o),await this.client.remove(o,a._rev)}catch(e){throw this.parseError(e)}return this.assignMetadata(a,a._rev)}async deleteAll(e,t,...r){const{log:s}=this.logCtx(r,this.deleteAll),n=i.Model.tableName(e),c=await this.client.bulkGet({docs:t.map(e=>({id:this.generateId(n,e)}))}),d=c.results.reduce((e,t)=>(t.docs.forEach(t=>{if(t.error)throw this.parseError(t.error||new a.InternalError("Missing valid response"));const r=Object.assign({},t.ok);r[o.CouchDBKeys.DELETED]=!0,e.push(r)}),e),[]);return(await this.client.bulkDocs(d)).forEach(e=>{const t=e.error;t&&s.error(t+"")}),c.results.reduce((e,t)=>(t.docs.forEach(t=>{if(t.error||!t.ok)throw this.parseError(t.error||new a.InternalError("Missing valid response"));const r=Object.assign({},t.ok);e.push(this.assignMetadata(r,t.ok[o.CouchDBKeys.REV]))}),e),[])}async raw(e,t=!0,...r){try{const o=await this.client.find(e);if(o.warning){const{log:e}=await this.logCtx(r,this.raw,!0);e.for(this.raw).warn(o.warning)}return t?o.docs:o}catch(e){throw this.parseError(e)}}async view(e,t,r,...o){try{const o=`${e}/${t}`;return await this.client.query(o,r)}catch(e){throw this.parseError(e)}}parseError(e,t){return m.parseError(e,t)}static parseError(e,t){if(e instanceof a.BaseError)return e;let r="";if("string"==typeof e){if(r=e,r.match(/already exist|update conflict/g))return new a.ConflictError(r);if(r.match(/missing|deleted/g))return new a.NotFoundError(r)}else e.status?(r=e.status,t=t||e.message):e.code?(r=e.code,t=t||e.message):e.statusCode?(r=e.statusCode,t=t||e.message):r=e.message;switch(r.toString()){case"401":case"412":case"409":return new a.ConflictError(t);case"404":return new a.NotFoundError(t);case"400":return r.toString().match(/No\sindex\sexists/g)?new o.IndexError(e):new a.InternalError(e);default:return r.toString().match(/ECONNREFUSED/g)?new s.ConnectionError(e):new a.InternalError(e)}}static decoration(){super.decoration(),u.Decoration.flavouredAs(w).for(s.PersistenceKeys.CREATED_BY).define(a.onCreate(b),u.propMetadata(s.PersistenceKeys.CREATED_BY,{})).apply(),u.Decoration.flavouredAs(w).for(s.PersistenceKeys.UPDATED_BY).define(a.onCreateUpdate(b),u.propMetadata(s.PersistenceKeys.UPDATED_BY,{})).apply()}}s.Adapter.setCurrent(w),m.decoration();const C="##VERSION##",v="##PACKAGE##";u.Metadata.registerLibrary(v,C),e.COMMIT="a961b54",e.DefaultLocalStoragePath=E,e.FULL_VERSION="0.9.2-a961b54",e.PACKAGE_NAME=v,e.PouchAdapter=m,e.PouchFlavour=w,e.PouchRepository=y,e.VERSION=C,e.createdByOnPouchCreateUpdate=b},"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("reflect-metadata"),require("crypto"),require("@decaf-ts/for-couchdb"),require("@decaf-ts/db-decorators"),require("@decaf-ts/core"),require("@decaf-ts/decorator-validation"),require("pouchdb-core"),require("pouchdb-mapreduce"),require("pouchdb-replication"),require("pouchdb-find"),require("@decaf-ts/decoration")):"function"==typeof define&&define.amd?define(["exports","reflect-metadata","crypto","@decaf-ts/for-couchdb","@decaf-ts/db-decorators","@decaf-ts/core","@decaf-ts/decorator-validation","pouchdb-core","pouchdb-mapreduce","pouchdb-replication","pouchdb-find","@decaf-ts/decoration"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["for-pouch"]={},e.reflectMetadata,e.crypto,e.decafTsForCouchdb,e.decafTsDbDecorators,e.decafTsCore,e.decafTsDecoratorValidation,e.pouchdbCore,e.pouchdbMapreduce,e.pouchdbReplication,e.pouchdbFind,e.decafTsDecoration);
2
2
  //# sourceMappingURL=for-pouch.cjs.map
package/lib/cjs/index.cjs CHANGED
@@ -34,21 +34,21 @@ __exportStar(require("./adapter.cjs"), exports);
34
34
  * @const VERSION
35
35
  * @memberOf module:for-pouch
36
36
  */
37
- exports.VERSION = "0.9.1";
37
+ exports.VERSION = "0.9.2";
38
38
  /**
39
39
  * @description Represents the current commit hash of the module build.
40
40
  * @summary Stores the current git commit hash for the package. The build replaces
41
41
  * the placeholder with the actual commit hash at publish time.
42
42
  * @const COMMIT
43
43
  */
44
- exports.COMMIT = "1e21646";
44
+ exports.COMMIT = "a961b54";
45
45
  /**
46
46
  * @description Represents the full version string of the module.
47
47
  * @summary Stores the semver version and commit hash for the package.
48
48
  * The build replaces the placeholder with the actual `<version>-<commit>` value at publish time.
49
49
  * @const FULL_VERSION
50
50
  */
51
- exports.FULL_VERSION = "0.9.1-1e21646";
51
+ exports.FULL_VERSION = "0.9.2-a961b54";
52
52
  /**
53
53
  * @description Package version identifier
54
54
  * @summary Stores the current version of the for-pouch package
package/lib/esm/index.js CHANGED
@@ -17,21 +17,21 @@ export * from "./adapter.js";
17
17
  * @const VERSION
18
18
  * @memberOf module:for-pouch
19
19
  */
20
- export const VERSION = "0.9.1";
20
+ export const VERSION = "0.9.2";
21
21
  /**
22
22
  * @description Represents the current commit hash of the module build.
23
23
  * @summary Stores the current git commit hash for the package. The build replaces
24
24
  * the placeholder with the actual commit hash at publish time.
25
25
  * @const COMMIT
26
26
  */
27
- export const COMMIT = "1e21646";
27
+ export const COMMIT = "a961b54";
28
28
  /**
29
29
  * @description Represents the full version string of the module.
30
30
  * @summary Stores the semver version and commit hash for the package.
31
31
  * The build replaces the placeholder with the actual `<version>-<commit>` value at publish time.
32
32
  * @const FULL_VERSION
33
33
  */
34
- export const FULL_VERSION = "0.9.1-1e21646";
34
+ export const FULL_VERSION = "0.9.2-a961b54";
35
35
  /**
36
36
  * @description Package version identifier
37
37
  * @summary Stores the current version of the for-pouch package
@@ -13,21 +13,21 @@ export * from "./adapter.d.cts";
13
13
  * @const VERSION
14
14
  * @memberOf module:for-pouch
15
15
  */
16
- export declare const VERSION = "0.9.1";
16
+ export declare const VERSION = "0.9.2";
17
17
  /**
18
18
  * @description Represents the current commit hash of the module build.
19
19
  * @summary Stores the current git commit hash for the package. The build replaces
20
20
  * the placeholder with the actual commit hash at publish time.
21
21
  * @const COMMIT
22
22
  */
23
- export declare const COMMIT = "1e21646";
23
+ export declare const COMMIT = "a961b54";
24
24
  /**
25
25
  * @description Represents the full version string of the module.
26
26
  * @summary Stores the semver version and commit hash for the package.
27
27
  * The build replaces the placeholder with the actual `<version>-<commit>` value at publish time.
28
28
  * @const FULL_VERSION
29
29
  */
30
- export declare const FULL_VERSION = "0.9.1-1e21646";
30
+ export declare const FULL_VERSION = "0.9.2-a961b54";
31
31
  /**
32
32
  * @description Package version identifier
33
33
  * @summary Stores the current version of the for-pouch package
@@ -13,21 +13,21 @@ export * from "./adapter.d.mts";
13
13
  * @const VERSION
14
14
  * @memberOf module:for-pouch
15
15
  */
16
- export declare const VERSION = "0.9.1";
16
+ export declare const VERSION = "0.9.2";
17
17
  /**
18
18
  * @description Represents the current commit hash of the module build.
19
19
  * @summary Stores the current git commit hash for the package. The build replaces
20
20
  * the placeholder with the actual commit hash at publish time.
21
21
  * @const COMMIT
22
22
  */
23
- export declare const COMMIT = "1e21646";
23
+ export declare const COMMIT = "a961b54";
24
24
  /**
25
25
  * @description Represents the full version string of the module.
26
26
  * @summary Stores the semver version and commit hash for the package.
27
27
  * The build replaces the placeholder with the actual `<version>-<commit>` value at publish time.
28
28
  * @const FULL_VERSION
29
29
  */
30
- export declare const FULL_VERSION = "0.9.1-1e21646";
30
+ export declare const FULL_VERSION = "0.9.2-a961b54";
31
31
  /**
32
32
  * @description Package version identifier
33
33
  * @summary Stores the current version of the for-pouch package
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decaf-ts/for-pouch",
3
- "version": "0.9.2",
3
+ "version": "0.9.3",
4
4
  "description": "decaf-ts persistence adapter for PouchDB",
5
5
  "type": "module",
6
6
  "exports": {
@@ -117,5 +117,8 @@
117
117
  "pouchdb-adapter-memory": "^9.0.0",
118
118
  "pouchdb-mapreduce": "^9.0.0",
119
119
  "pouchdb-replication": "^9.0.0"
120
+ },
121
+ "overrides": {
122
+ "uuid": "^11.1.1"
120
123
  }
121
124
  }