+2
-2
| /* | ||
| pixdb 1.0.1 - Promise-based indexedDB wrapper | ||
| pixdb 1.0.2 - Promise-based indexedDB wrapper | ||
| https://github.com/craigbuckler/pixdb | ||
| Craig Buckler, 2023-08-21 | ||
| Craig Buckler, 2025-05-14 | ||
| */ | ||
| 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}; |
+6
-2
| { | ||
| "name": "pixdb", | ||
| "version": "1.0.1", | ||
| "version": "1.0.2", | ||
| "description": "Promise-based indexedDB wrapper", | ||
@@ -31,6 +31,10 @@ "type": "module", | ||
| "author": "Craig Buckler", | ||
| "funding": { | ||
| "type": "individual", | ||
| "url": "https://github.com/sponsors/craigbuckler" | ||
| }, | ||
| "license": "MIT", | ||
| "devDependencies": { | ||
| "esbuild": "^0.19.2" | ||
| "esbuild": "^0.25.4" | ||
| } | ||
| } |
+12
-11
@@ -28,3 +28,4 @@ # PixDB | ||
| ```js | ||
| import { PixDB } from './node_modules/pixdb/dist/pixdb.js'; | ||
| import { PixDB } from 'pixdb'; | ||
| // or perhaps: import { PixDB } from './node_modules/pixdb/dist/pixdb.js'; | ||
| ``` | ||
@@ -35,3 +36,3 @@ | ||
| Most methods are asynchronous and Promise-based so you must use `async`/`await` or `.then`. | ||
| Most methods are asynchronous and Promise-based so you must use `async`/`await` or `.then` chains. | ||
@@ -58,3 +59,3 @@ Initialize a new connection with a database name, version, and an optional upgrade function. The upgrade function receives the connection, the old version number, and the new version number so it can create object stores and indexes: | ||
| This creates an object store named `state` which with the key on the `name` property and an index named `updateIdx` on the `update` property. | ||
| This creates an object store named `state` with a key on the `name` property and an index named `updateIdx` on the `update` property. | ||
@@ -104,3 +105,3 @@ You can check the connection, name, and version: | ||
| Get an array of all values with a `lowerBound`, `upperBound`, and maximum `count` of records: | ||
| Get an array of all values with a `lowerBound`, `upperBound`, and a maximum `count` of records: | ||
@@ -128,3 +129,3 @@ ```js | ||
| store: 'state', | ||
| callback: cursor => console.log(cursor.value) | ||
| callback: cursor => console.log( cursor.value ) | ||
| }); | ||
@@ -169,5 +170,5 @@ ``` | ||
| The `upgrade` function is passed the database connection, oldVersion, and newVersion. | ||
| The `upgrade` function receives the database connection, oldVersion, and newVersion. | ||
| The constructor returns a Promise which resolves/rejects when a database connection is established so `await` must be used: | ||
| The constructor returns a Promise which resolves/rejects when the database connection is established, so `await` can be used: | ||
@@ -201,3 +202,3 @@ Example: | ||
| Returns the database name string (or `null` if the database is dropped). | ||
| Returns the database name string (or `null` if the database has been dropped). | ||
@@ -207,3 +208,3 @@ | ||
| Returns the database version number (or `null` if the database is dropped). | ||
| Returns the database version number (or `null` if the database has been dropped). | ||
@@ -222,3 +223,3 @@ | ||
| Returns a Promise which resolves/rejects when all records have been written. | ||
| Returns a Promise which resolves/rejects when all records are written. | ||
@@ -311,3 +312,3 @@ ```js | ||
| Returns a Promise which resolves/rejects when number of records is known. | ||
| Returns a Promise which resolves/rejects when number of records is determined. | ||
@@ -314,0 +315,0 @@ ```js |
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.
14793
1.11%432
0.23%0
-100%