+3
-3
| /* | ||
| pixdb 1.0.0 - Promise-based indexedDB wrapper | ||
| pixdb 1.0.1 - Promise-based indexedDB wrapper | ||
| https://github.com/craigbuckler/pixdb | ||
| Craig Buckler, 2023-08-18 | ||
| Craig Buckler, 2023-08-21 | ||
| */ | ||
| var a=class{#t=null;#r=null;#s=null;constructor(t,e,r){return this.#r=t||"db",this.#s=e||1,this.#i(r)}connect(){return this.#i().then(()=>!0).catch(()=>!1)}close(){this.#t.close(),this.#t=null}#i(t){return new Promise((e,r)=>{if(!("indexedDB"in window)){r(new Error("No indexedDB support"));return}let s=indexedDB.open(this.#r,this.#s);s.onsuccess=()=>{this.#t=s.result,e(this)},s.onerror=n=>{r(new Error(`IndexedDB error ${n.target.errorCode}: ${n.target.message}`,{cause:n}))},t&&(s.onupgradeneeded=n=>{t(s.result,n.oldVersion,n.newVersion)})})}get isConnected(){return!!this.#t}get name(){return this.#r}get version(){return this.#s}#u(t,e,r){return new Promise((s,n)=>{let{transaction:i,store:u}=this.#o(t,null,!0);i.oncomplete=()=>s(),i.onerror=o=>{n(new Error(o.target.error.message,{cause:o}))},e=Array.isArray(e)?e:[e],e.forEach(o=>{r?u.put(o):u.add(o)}),i.commit()})}add({store:t,item:e=[]}={}){return this.#u(t,e,!1)}put({store:t,item:e=[]}={}){return this.#u(t,e,!0)}#e(t,e,r,s){return new Promise((n,i)=>{s=Array.isArray(s)?s:[s];let u=r==="delete"||r==="clear",o=this.#o(t,e,u).store[r](...s);o.onsuccess=()=>n(o.result),o.onerror=()=>i(o.error??!1)})}count({store:t,index:e,lowerBound:r,upperBound:s}={}){return this.#e(t,e,"count",this.#n(r,s))}get({store:t,index:e,key:r}={}){return this.#e(t,e,"get",r)}getAll({store:t,index:e,lowerBound:r,upperBound:s,count:n}={}){return this.#e(t,e,"getAll",[this.#n(r,s),n])}getAllKeys({store:t,index:e,lowerBound:r,upperBound:s,count:n}={}){return this.#e(t,e,"getAllKeys",[this.#n(r,s),n])}delete({store:t,key:e}={}){return this.#e(t,null,"delete",e)}clear({store:t}={}){return this.#e(t,null,"clear")}getCursor({store:t,index:e,lowerBound:r,upperBound:s,direction:n="next",callback:i}={}){return new Promise((u,o)=>{let l=this.#o(t,e).store.openCursor(this.#n(r,s),n);l.onsuccess=()=>{let c=l.result;c?c.advance(i&&i(c)||1):u(!0)},l.onerror=()=>o(l.error)})}drop(){return new Promise((t,e)=>{this.close();let r=indexedDB.deleteDatabase(this.#r);r.onsuccess=()=>{this.#r=null,this.#s=null,t(!0)},r.onerror=()=>e(!1)})}#o(t,e,r){let s=this.#t.transaction(t,r?"readwrite":"readonly",{durability:r?"strict":"default"}),n=s.objectStore(t);return{transaction:s,store:e&&!r?n.index(e):n}}#n(t,e){let r;return t&&e?r=IDBKeyRange.bound(t,e):t?r=IDBKeyRange.lowerBound(t):e&&(r=IDBKeyRange.upperBound(e)),r}};export{a as PixDB}; | ||
| var a=class{#t=null;#r=null;#n=null;constructor(t,e,r){return this.#r=t||"db",this.#n=e||1,this.#i(r)}connect(){return this.#i().then(()=>!0).catch(()=>!1)}close(){this.#t.close(),this.#t=null}#i(t){return new Promise((e,r)=>{if(!("indexedDB"in window)){r(new Error("No indexedDB support"));return}let s=indexedDB.open(this.#r,this.#n);s.onsuccess=()=>{this.#t=s.result,e(this)},s.onerror=n=>{r(new Error(`IndexedDB error ${n.target.errorCode}: ${n.target.message}`,{cause:n}))},t&&(s.onupgradeneeded=n=>{t(s.result,n.oldVersion,n.newVersion)})})}get isConnected(){return!!this.#t}get name(){return this.#r}get version(){return this.#n}#u(t,e,r){return new Promise((s,n)=>{let{transaction:i,store:u}=this.#o(t,null,!0);i.oncomplete=()=>s(),i.onerror=o=>{n(new Error(o.target.error.message,{cause:o}))},e=Array.isArray(e)?e:[e],e.forEach(o=>{r?u.put(o):u.add(o)}),i.commit()})}add({store:t,item:e=[]}={}){return this.#u(t,e,!1)}put({store:t,item:e=[]}={}){return this.#u(t,e,!0)}#e(t,e,r,s){return new Promise((n,i)=>{s=Array.isArray(s)?s:[s];let u=r==="delete"||r==="clear",o=this.#o(t,e,u).store[r](...s);o.onsuccess=()=>n(o.result),o.onerror=()=>i(o.error??!1)})}count({store:t,index:e,lowerBound:r,upperBound:s}={}){return this.#e(t,e,"count",this.#s(r,s))}get({store:t,index:e,key:r}={}){return this.#e(t,e,"get",r)}getAll({store:t,index:e,lowerBound:r,upperBound:s,count:n}={}){return this.#e(t,e,"getAll",[this.#s(r,s),n])}getAllKeys({store:t,index:e,lowerBound:r,upperBound:s,count:n}={}){return this.#e(t,e,"getAllKeys",[this.#s(r,s),n])}delete({store:t,key:e}={}){return this.#e(t,null,"delete",[e])}deleteAll({store:t,index:e,lowerBound:r,upperBound:s}={}){return this.#e(t,e,"delete",[this.#s(r,s)])}clear({store:t}={}){return this.#e(t,null,"clear")}getCursor({store:t,index:e,lowerBound:r,upperBound:s,direction:n="next",callback:i}={}){return new Promise((u,o)=>{let l=this.#o(t,e).store.openCursor(this.#s(r,s),n);l.onsuccess=()=>{let c=l.result;c?c.advance(i&&i(c)||1):u(!0)},l.onerror=()=>o(l.error)})}drop(){return new Promise((t,e)=>{this.close();let r=indexedDB.deleteDatabase(this.#r);r.onsuccess=()=>{this.#r=null,this.#n=null,t(!0)},r.onerror=()=>e(!1)})}#o(t,e,r){let s=this.#t.transaction(t,r?"readwrite":"readonly",{durability:r?"strict":"default"}),n=s.objectStore(t);return{transaction:s,store:e&&!r?n.index(e):n}}#s(t,e){let r;return t&&e?r=IDBKeyRange.bound(t,e):t?r=IDBKeyRange.lowerBound(t):e&&(r=IDBKeyRange.upperBound(e)),r}};export{a as PixDB}; |
+1
-1
| { | ||
| "name": "pixdb", | ||
| "version": "1.0.0", | ||
| "version": "1.0.1", | ||
| "description": "Promise-based indexedDB wrapper", | ||
@@ -5,0 +5,0 @@ "type": "module", |
+20
-0
@@ -252,2 +252,22 @@ # PixDB | ||
| ### .deleteAll( paramObject ) | ||
| Delete all records referenced between optional lower and upper boundaries on a store or index. | ||
| `paramObject` properties: | ||
| | property | type | description | | ||
| |-|-|-| | ||
| | `store` | string | object store (required) | | ||
| | `index` | string | object store index | | ||
| | `lowerBound` | * | lower key value | | ||
| | `upperBound` | * | upper key value | | ||
| Returns a Promise which resolves/rejects all records are deleted. | ||
| ```js | ||
| await db.deleteAll({ store: 'state', lowerBound: 'x', upperBound: 'z' }); | ||
| ``` | ||
| ### .clear( paramObject ) | ||
@@ -254,0 +274,0 @@ |
AI-detected possible typosquat
Supply chain riskAI has identified this package as a potential typosquat of a more popular package. This suggests that the package may be intentionally mimicking another package's name, description, or other metadata.
14630
4.43%431
4.87%1
Infinity%