localspace 0.2.1 → 0.2.2
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 +13 -4
- package/dist/drivers/indexeddb.d.ts.map +1 -1
- package/dist/drivers/indexeddb.js +97 -49
- package/dist/drivers/localstorage.d.ts.map +1 -1
- package/dist/drivers/localstorage.js +52 -31
- package/dist/errors.d.ts +26 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +39 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/localspace.d.ts +1 -0
- package/dist/localspace.d.ts.map +1 -1
- package/dist/localspace.js +30 -23
- package/dist/utils/helpers.d.ts.map +1 -1
- package/dist/utils/helpers.js +5 -6
- package/dist/utils/serializer.d.ts.map +1 -1
- package/dist/utils/serializer.js +9 -5
- package/package.json +4 -3
- package/src/drivers/indexeddb.ts +187 -55
- package/src/drivers/localstorage.ts +250 -151
- package/src/errors.ts +120 -0
- package/src/index.ts +2 -0
- package/src/localspace.ts +63 -23
- package/src/utils/helpers.ts +8 -5
- package/src/utils/serializer.ts +24 -4
package/README.md
CHANGED
|
@@ -54,9 +54,9 @@ localspace is built on a foundation designed for growth. Here's what's planned:
|
|
|
54
54
|
- [x] Batch operations (`setItems()`, `getItems()`, `removeItems()`) for higher throughput
|
|
55
55
|
- [x] Automatic write coalescing (3-10x faster rapid writes, enabled by default)
|
|
56
56
|
- [x] Connection pooling, transaction batching, and warmup
|
|
57
|
+
- [x] **Improved error handling** - Structured error types with detailed context
|
|
57
58
|
|
|
58
59
|
### TODO
|
|
59
|
-
- [ ] **Improved error handling** - Structured error types with detailed context
|
|
60
60
|
- [ ] **Plugin system** - Middleware architecture for cross-cutting concerns
|
|
61
61
|
- [ ] **Cache API driver** - Native browser caching with automatic HTTP semantics
|
|
62
62
|
- [ ] **OPFS driver** - Origin Private File System for high-performance file storage
|
|
@@ -210,6 +210,14 @@ await Promise.all([
|
|
|
210
210
|
coalesced.setItem('fast-2', 'b'),
|
|
211
211
|
]); // batched into one tx within the window
|
|
212
212
|
|
|
213
|
+
// These features work independently and can be combined
|
|
214
|
+
const optimized = localspace.createInstance({
|
|
215
|
+
coalesceWrites: true, // optimizes single-item writes (setItem/removeItem)
|
|
216
|
+
coalesceWindowMs: 8,
|
|
217
|
+
maxBatchSize: 200, // limits batch API chunk size (setItems/removeItems)
|
|
218
|
+
});
|
|
219
|
+
await optimized.setDriver([optimized.INDEXEDDB]);
|
|
220
|
+
|
|
213
221
|
// Note: localStorage batches are not atomic—writes are applied one by one.
|
|
214
222
|
// For critical flows, prefer IndexedDB or handle your own compensating logic.
|
|
215
223
|
```
|
|
@@ -316,10 +324,10 @@ localspace.setItem('key', 'value', (err, value) => {
|
|
|
316
324
|
```
|
|
317
325
|
|
|
318
326
|
## Performance notes
|
|
319
|
-
- **Automatic write coalescing (enabled by default):** localspace automatically merges rapid single writes within an 8ms window into one transaction, giving you 3-10x performance improvement with zero code changes. This is enabled by default for IndexedDB. Set `coalesceWrites: false` if you need strict per-operation durability.
|
|
327
|
+
- **Automatic write coalescing (enabled by default):** localspace automatically merges rapid single writes (`setItem`/`removeItem`) within an 8ms window into one transaction, giving you 3-10x performance improvement with zero code changes. This is enabled by default for IndexedDB. Set `coalesceWrites: false` if you need strict per-operation durability.
|
|
320
328
|
- **Batch APIs outperform loops:** Playwright benchmark (`test/playwright/benchmark.spec.ts`) on 500 items x 256B showed `setItems()` ~6x faster and `getItems()` ~7.7x faster than per-item loops, with `removeItems()` ~2.8x faster (Chromium, relaxed durability).
|
|
321
329
|
- **Transaction helpers:** `runTransaction()` lets you co-locate reads/writes in a single transaction for atomic migrations and to shorten lock time.
|
|
322
|
-
- **Batch sizing:** Use `maxBatchSize` to split very large
|
|
330
|
+
- **Batch sizing:** Use `maxBatchSize` to split very large batch operations (`setItems`/`removeItems`/`getItems`) and keep transaction size in check. This works independently from `coalesceWrites`, which optimizes single-item operations.
|
|
323
331
|
- **IndexedDB durability defaults:** Chrome 121+ uses relaxed durability by default; keep it for speed or set `durability: 'strict'` in `config` for migration-style writes.
|
|
324
332
|
- **Storage Buckets (Chromium 122+):** supply a `bucket` option to isolate critical data and hint durability/persistence per bucket.
|
|
325
333
|
- **Connection warmup:** IndexedDB instances pre-warm a transaction after init to reduce first-op latency (`prewarmTransactions` enabled by default; set to `false` to skip).
|
|
@@ -331,7 +339,8 @@ When `compatibilityMode` is off, driver setup methods also use Node-style callba
|
|
|
331
339
|
## Troubleshooting
|
|
332
340
|
- **Wait for readiness:** Call `await localspace.ready()` before the first operation when you need to confirm driver selection.
|
|
333
341
|
- **Inspect drivers:** Use `localspace.driver()` to confirm which driver is active in different environments.
|
|
334
|
-
- **
|
|
342
|
+
- **Read structured errors:** Rejections surface as `LocalSpaceError` with a `code`, contextual `details` (driver, operation, key, attemptedDrivers), and the original `cause`. Branch on `error.code` instead of parsing strings.
|
|
343
|
+
- **Handle quota errors:** Check for `error.code === 'QUOTA_EXCEEDED'` (or inspect `error.cause`) from `setItem` to inform users about storage limits.
|
|
335
344
|
- **Run unit tests:** The project ships with Vitest and Playwright suites covering API behavior; run `yarn test` to verify changes.
|
|
336
345
|
|
|
337
346
|
## License
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"indexeddb.d.ts","sourceRoot":"","sources":["../../src/drivers/indexeddb.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,MAAM,EASP,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"indexeddb.d.ts","sourceRoot":"","sources":["../../src/drivers/indexeddb.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,MAAM,EASP,MAAM,UAAU,CAAC;AAulElB,QAAA,MAAM,YAAY,EAAE,MAkBnB,CAAC;AAEF,eAAe,YAAY,CAAC"}
|