tiny-idb 1.2.0 → 1.2.1

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/README.md CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  **A minimalist, high-performance IndexedDB wrapper for modern web applications.**
4
4
 
5
- `tiny-idb` provides a non-blocking, asynchronous alternative to `localStorage`. It is designed for developers who require the durability and capacity of IndexedDB without the complexity of its native API. By focusing on a single-store, key-value architecture, it eliminates the need for database versioning and boilerplate configuration.
5
+ `tiny-idb` provides a non-blocking, asynchronous alternative to `localStorage`. While `localStorage` is capped at ~5-10MB and can be cleared by the browser under memory pressure, `tiny-idb` leverages IndexedDB to offer virtually unlimited storage (up to 80% of disk space) with much higher durability.
6
+
7
+ It is designed for developers who require the reliability and capacity of IndexedDB without the complexity of its native API. By focusing on a single-store, key-value architecture, it eliminates the need for database versioning and boilerplate configuration.
6
8
 
7
9
  [![NPM Version](https://img.shields.io/npm/v/tiny-idb.svg)](https://www.npmjs.com/package/tiny-idb)
8
10
  [![License](https://img.shields.io/npm/l/tiny-idb.svg)](LICENSE)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tiny-idb",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "An extremely fast, super simple, and dependency-free IndexedDB wrapper. A drop-in replacement for localStorage with reliability and durability.",
5
5
  "main": "tiny-idb.js",
6
6
  "module": "tiny-idb.js",
@@ -40,6 +40,6 @@
40
40
  "scripts": {
41
41
  "test": "node test.js",
42
42
  "test:min": "TEST_MIN=1 node test.js",
43
- "minify": "terser tiny-idb.js -o tiny-idb.min.js -c toplevel,unsafe -m toplevel --comments false"
43
+ "minify": "terser tiny-idb.js -o tiny-idb.min.js -c toplevel,unsafe -m toplevel --comments '/tiny-idb/'"
44
44
  }
45
45
  }
package/tiny-idb.js CHANGED
@@ -1,10 +1,4 @@
1
- /**
2
- * tiny-idb - A super simple, fast, and dependency-free IndexedDB wrapper.
3
- * Designed as a drop-in replacement for localStorage with durability and performance.
4
- *
5
- * @author Jelodar
6
- * @license MIT
7
- */
1
+ /** tiny-idb - MIT © Jelodar */
8
2
 
9
3
  const instances = new Map();
10
4
  const prom = (req) => new Promise((res, rej) => {
@@ -43,23 +37,20 @@ const getAPI = (dbName = 'tiny-idb', storeName = undefined) => {
43
37
  });
44
38
  };
45
39
 
46
- const update = async (key, fn) => tx(RW, async s => {
47
- const n = await fn(await prom(s.get(key)));
48
- return prom(s.put(n, key));
49
- });
40
+ const update = (key, fn) => tx(RW, async s => prom(s.put(await fn(await prom(s.get(key))), key)));
50
41
 
51
42
  const api = {
52
43
  open: getAPI,
53
44
  set: (key, value) => tx(RW, s => prom(s.put(value, key))),
54
45
  get: key => tx(RO, s => prom(s.get(key))),
55
- remove: k => tx(RW, s => prom(s.delete(k))),
46
+ remove: key => tx(RW, s => prom(s.delete(key))),
56
47
  clear: () => tx(RW, s => prom(s.clear())),
57
48
  keys: () => tx(RO, s => prom(s.getAllKeys())),
58
49
  values: () => tx(RO, s => prom(s.getAll())),
59
50
  count: () => tx(RO, s => prom(s.count())),
60
51
  update,
61
- push: (key, value) => update(key, c => [...(Array.isArray(c) ? c : []), value]),
62
- merge: (key, patch) => update(key, c => ({ ...(c && typeof c === 'object' ? c : {}), ...patch }))
52
+ push: (key, val) => update(key, (c = []) => [...(Array.isArray(c) ? c : []), val]),
53
+ merge: (key, obj) => update(key, (c = {}) => ({ ...(c && typeof c === 'object' ? c : {}), ...obj }))
63
54
  };
64
55
 
65
56
  ['get', 'set', 'remove'].forEach(m => api[m + 'Item'] = api[m]);
package/tiny-idb.min.js CHANGED
@@ -1 +1,2 @@
1
- const e=new Map,t=e=>new Promise((t,r)=>{e.onsuccess=()=>t(e.result),e.onerror=()=>r(e.error)}),r="readonly",o="readwrite",n=(s="tiny-idb",c=void 0)=>{const a=s+"\0"+(c=c||s);if(e.has(a))return e.get(a);let l;const u=async(e,t)=>{const r=await(l||(l=new Promise((e,t)=>{const r=indexedDB.open(s,1);r.onupgradeneeded=()=>r.result.createObjectStore(c),r.onsuccess=()=>{const t=r.result;t.onversionchange=()=>{t.close(),l=null},e(t)},r.onerror=()=>{l=null,t(r.error)}})));return new Promise(async(o,n)=>{const s=r.transaction(c,e);s.onabort=s.onerror=()=>n(s.error||new DOMException("Aborted"));try{const e=await t(s.objectStore(c));s.oncomplete=()=>o(e)}catch(e){try{s.abort()}catch{}n(e)}})},i=async(e,r)=>u(o,async o=>{const n=await r(await t(o.get(e)));return t(o.put(n,e))}),y={open:n,set:(e,r)=>u(o,o=>t(o.put(r,e))),get:e=>u(r,r=>t(r.get(e))),remove:e=>u(o,r=>t(r.delete(e))),clear:()=>u(o,e=>t(e.clear())),keys:()=>u(r,e=>t(e.getAllKeys())),values:()=>u(r,e=>t(e.getAll())),count:()=>u(r,e=>t(e.count())),update:i,push:(e,t)=>i(e,e=>[...Array.isArray(e)?e:[],t]),merge:(e,t)=>i(e,e=>({...e&&"object"==typeof e?e:{},...t}))};return["get","set","remove"].forEach(e=>y[e+"Item"]=y[e]),e.set(a,y),y};export const tinyIDB=n();export default tinyIDB;
1
+ /** tiny-idb - MIT © Jelodar */
2
+ const e=new Map,t=e=>new Promise((t,r)=>{e.onsuccess=()=>t(e.result),e.onerror=()=>r(e.error)}),r="readonly",o="readwrite",n=(s="tiny-idb",c=void 0)=>{const a=s+"\0"+(c=c||s);if(e.has(a))return e.get(a);let l;const i=async(e,t)=>{const r=await(l||(l=new Promise((e,t)=>{const r=indexedDB.open(s,1);r.onupgradeneeded=()=>r.result.createObjectStore(c),r.onsuccess=()=>{const t=r.result;t.onversionchange=()=>{t.close(),l=null},e(t)},r.onerror=()=>{l=null,t(r.error)}})));return new Promise(async(o,n)=>{const s=r.transaction(c,e);s.onabort=s.onerror=()=>n(s.error||new DOMException("Aborted"));try{const e=await t(s.objectStore(c));s.oncomplete=()=>o(e)}catch(e){try{s.abort()}catch{}n(e)}})},u=(e,r)=>i(o,async o=>t(o.put(await r(await t(o.get(e))),e))),y={open:n,set:(e,r)=>i(o,o=>t(o.put(r,e))),get:e=>i(r,r=>t(r.get(e))),remove:e=>i(o,r=>t(r.delete(e))),clear:()=>i(o,e=>t(e.clear())),keys:()=>i(r,e=>t(e.getAllKeys())),values:()=>i(r,e=>t(e.getAll())),count:()=>i(r,e=>t(e.count())),update:u,push:(e,t)=>u(e,(e=[])=>[...Array.isArray(e)?e:[],t]),merge:(e,t)=>u(e,(e={})=>({...e&&"object"==typeof e?e:{},...t}))};return["get","set","remove"].forEach(e=>y[e+"Item"]=y[e]),e.set(a,y),y};export const tinyIDB=n();export default tinyIDB;