@blaze-cache/core 0.4.0-beta.0 → 0.4.0-beta.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 +28 -12
- package/dist/cache.d.ts +46 -22
- package/dist/cache.d.ts.map +1 -1
- package/dist/cache.js +458 -54
- package/dist/cache.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/persistence/indexeddb.d.ts +16 -2
- package/dist/persistence/indexeddb.d.ts.map +1 -1
- package/dist/persistence/indexeddb.js +248 -54
- package/dist/persistence/indexeddb.js.map +1 -1
- package/dist/persistence/types.d.ts +271 -0
- package/dist/persistence/types.d.ts.map +1 -1
- package/dist/wasm.d.ts +79 -1
- package/dist/wasm.d.ts.map +1 -1
- package/dist/wasm.js +142 -0
- package/dist/wasm.js.map +1 -1
- package/package.json +2 -1
- package/pkg/package.json +1 -1
package/README.md
CHANGED
|
@@ -143,15 +143,25 @@ stop(); stopMany(); stopTag(); // idempotent — also safe from inside a
|
|
|
143
143
|
|
|
144
144
|
## Good to know
|
|
145
145
|
|
|
146
|
-
* **The `.wasm` ships inside this package** — no CDN setup
|
|
147
|
-
|
|
146
|
+
* **The `.wasm` ships inside this package** — no CDN setup, no separate asset download.
|
|
147
|
+
`createCache` fetches it relative to the package's own module, streams it in, and does
|
|
148
|
+
it once per page even when several caches are created at once. Under Vite this needs no
|
|
149
|
+
configuration at all.
|
|
148
150
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
+
When the binary lives somewhere else — a `public/` asset path, a CDN, Next.js, or a
|
|
152
|
+
bundler that pre-bundles dependencies — say so explicitly:
|
|
151
153
|
|
|
152
|
-
|
|
154
|
+
```ts
|
|
155
|
+
// a file you copied to public/, served at /assets/blaze_cache_wasm_bg.wasm
|
|
156
|
+
const cache = await createCache({ capacity: 1000, wasmUrl: '/assets/blaze_cache_wasm_bg.wasm' });
|
|
153
157
|
```
|
|
154
158
|
|
|
159
|
+
Two further overrides cover the rest: `module` for a precompiled `WebAssembly.Module`
|
|
160
|
+
(no fetch, no compile), and `instantiate` for a custom loader that resolves to a source
|
|
161
|
+
— a URL, a `Request`/`Response`, bytes, or a `Module`. Pass at most one of the three;
|
|
162
|
+
two at once throws a `TypeError`. Failures name the URL or step that failed and keep the
|
|
163
|
+
original error on `cause`.
|
|
164
|
+
|
|
155
165
|
* **Types are bundled** — no `@types/*` packages to install.
|
|
156
166
|
* **ESM only, browser only.** Node/SSR targets are out of scope by design.
|
|
157
167
|
* **Values are shared by reference** — `set` hands the object over and `get`/`peek`/
|
|
@@ -160,13 +170,19 @@ stop(); stopMany(); stopTag(); // idempotent — also safe from inside a
|
|
|
160
170
|
is what keeps `get`/`set` allocation-free.
|
|
161
171
|
* **Persistence is optional** and off by default; a blocked IndexedDB (private mode)
|
|
162
172
|
degrades to memory-only instead of breaking the app. A flush that fails later — a quota
|
|
163
|
-
error, a transient IndexedDB problem — is
|
|
164
|
-
the queue for the next flush, rather
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
173
|
+
error, a transient IndexedDB problem — is reported (`onError`, or the awaited call's
|
|
174
|
+
rejection) and its records go straight back on the queue for the next flush, rather
|
|
175
|
+
than being dropped; the exception is a record that fails *on its own* three times
|
|
176
|
+
running, which is dropped from the queue with a console warning (still in memory) so one
|
|
177
|
+
poison row cannot block every later flush, and any successful pass resets the count.
|
|
178
|
+
Options — `namespace`, `debounceMs`, `maxEntries`, `restoreExpired`, `writeMode`,
|
|
179
|
+
`onError`, `onActivity`, `generation` — are validated when persistence is attached and
|
|
180
|
+
throw from `create` rather than misbehave later (`flushDelayMs`/`maxRecords` remain as
|
|
181
|
+
aliases). `cache.persistence` is the control surface: `flush()` writes now, `clear()`
|
|
182
|
+
empties storage without touching memory, `hydrate()` reloads storage into memory,
|
|
183
|
+
`stats()` reports counters, and `rotate(generation)` switches sessions — dropping the
|
|
184
|
+
previous session's queued *and* in-flight writes (see
|
|
185
|
+
[Persistence](https://github.com/blaze-cache/blaze-cache#persistence)).
|
|
170
186
|
* **`capacity` is normalised** — below `1` clamps up, above `1_000_000` clamps down, and
|
|
171
187
|
a non-finite value falls back to the wasm default — so `capacity()` reports a real
|
|
172
188
|
number back.
|
package/dist/cache.d.ts
CHANGED
|
@@ -1,27 +1,24 @@
|
|
|
1
1
|
import type { BlazeCacheLike, CacheEntry, CacheEventListener, CacheEventType, CacheKeySubscriber, CacheListener, CacheManySubscriber, CacheStats, CacheSubscribeOptions, CacheTagSubscriber, SetManyEntry, SetOptions, TouchOptions } from './types.js';
|
|
2
|
-
import type {
|
|
3
|
-
import type { CachePersistence,
|
|
2
|
+
import type { WasmLoadOptions } from './wasm.js';
|
|
3
|
+
import type { CachePersistence, PersistenceControl, PersistenceOptions } from './persistence/types.js';
|
|
4
4
|
/** Entries held when `capacity` is not given. */
|
|
5
5
|
export declare const DEFAULT_CAPACITY = 500;
|
|
6
6
|
/** Milliseconds a write waits for more writes before hitting IndexedDB. */
|
|
7
7
|
export declare const DEFAULT_FLUSH_DELAY_MS = 400;
|
|
8
8
|
/** Upper bound on records written by a single flush. */
|
|
9
9
|
export declare const DEFAULT_MAX_RECORDS = 2000;
|
|
10
|
-
/** Options for a custom {@link CachePersistence} adapter. */
|
|
11
|
-
export interface CachePersistenceOptions {
|
|
10
|
+
/** Options for a custom {@link CachePersistence} adapter — settings, tuning and observers. */
|
|
11
|
+
export interface CachePersistenceOptions extends PersistenceOptions {
|
|
12
12
|
adapter: CachePersistence;
|
|
13
|
-
/** Debounce applied to write-through flushes. Default {@link DEFAULT_FLUSH_DELAY_MS}. */
|
|
14
|
-
flushDelayMs?: number;
|
|
15
|
-
/** Maximum records persisted per flush (newest win). Default {@link DEFAULT_MAX_RECORDS}. */
|
|
16
|
-
maxRecords?: number;
|
|
17
|
-
}
|
|
18
|
-
/** Options for the built-in IndexedDB adapter — settings plus flush tuning. */
|
|
19
|
-
export interface IndexedDbPersistenceOptions extends IndexedDbOptions {
|
|
20
|
-
flushDelayMs?: number;
|
|
21
|
-
maxRecords?: number;
|
|
22
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Options for the built-in IndexedDB adapter — connection settings plus flush tuning,
|
|
16
|
+
* session isolation and observers. An alias of {@link PersistenceOptions}: the full set
|
|
17
|
+
* of persistence options is identical for both flavours.
|
|
18
|
+
*/
|
|
19
|
+
export type IndexedDbPersistenceOptions = PersistenceOptions;
|
|
23
20
|
/** Options accepted by {@link BlazeCache.create}. */
|
|
24
|
-
export interface BlazeCacheOptions {
|
|
21
|
+
export interface BlazeCacheOptions extends WasmLoadOptions {
|
|
25
22
|
/**
|
|
26
23
|
* Maximum number of entries kept in memory. The wasm binding normalises it before it is
|
|
27
24
|
* ever used: below `1` clamps up, above `1_000_000` clamps down, and a non-finite value
|
|
@@ -36,16 +33,15 @@ export interface BlazeCacheOptions {
|
|
|
36
33
|
*
|
|
37
34
|
* * `{ namespace, database, store, ... }` — the built-in IndexedDB adapter.
|
|
38
35
|
* * `{ adapter, ... }` — any {@link CachePersistence} implementation.
|
|
39
|
-
*/
|
|
40
|
-
persistence?: false | CachePersistenceOptions | IndexedDbPersistenceOptions;
|
|
41
|
-
/**
|
|
42
|
-
* How the `.wasm` binary is fetched and instantiated.
|
|
43
36
|
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
37
|
+
* Both flavours accept the same tuning, session and observer options — see
|
|
38
|
+
* {@link PersistenceOptions} — and expose the same control surface at
|
|
39
|
+
* {@link BlazeCache.persistence}.
|
|
46
40
|
*/
|
|
47
|
-
|
|
41
|
+
persistence?: false | CachePersistenceOptions | IndexedDbPersistenceOptions;
|
|
48
42
|
}
|
|
43
|
+
/** The options {@link createCache} takes — an alias for {@link BlazeCacheOptions}. */
|
|
44
|
+
export type CreateCacheOptions = BlazeCacheOptions;
|
|
49
45
|
/**
|
|
50
46
|
* The client-side cache: WebAssembly storage and eviction, optional write-through persistence.
|
|
51
47
|
*
|
|
@@ -142,6 +138,11 @@ export declare class BlazeCache<V = any> implements BlazeCacheLike<V> {
|
|
|
142
138
|
/**
|
|
143
139
|
* Loads the wasm module, builds the cache and — if requested — hydrates it from storage.
|
|
144
140
|
*
|
|
141
|
+
* The binary comes from the one source option given ({@link WasmLoadOptions.wasmUrl},
|
|
142
|
+
* {@link WasmLoadOptions.module} or {@link WasmLoadOptions.instantiate}), or from the
|
|
143
|
+
* asset shipped with this package when none is. Loading happens once per page: concurrent
|
|
144
|
+
* `create()` calls share one download and one instantiation.
|
|
145
|
+
*
|
|
145
146
|
* Storage failures (blocked IndexedDB, quota, private mode) degrade to memory-only with a
|
|
146
147
|
* console warning instead of rejecting.
|
|
147
148
|
*/
|
|
@@ -382,6 +383,27 @@ export declare class BlazeCache<V = any> implements BlazeCacheLike<V> {
|
|
|
382
383
|
* ```
|
|
383
384
|
*/
|
|
384
385
|
subscribeTag(tag: string, listener: CacheTagSubscriber<V>, options?: CacheSubscribeOptions): () => void;
|
|
386
|
+
/**
|
|
387
|
+
* The persistence control surface: `flush()`, `clear()`, `hydrate()`, `stats()` and
|
|
388
|
+
* `rotate()` — see {@link PersistenceControl}.
|
|
389
|
+
*
|
|
390
|
+
* Always present, even on a memory-only cache (the methods resolve as no-ops and
|
|
391
|
+
* `stats().enabled` is `false`), so callers never have to remember which flavour of
|
|
392
|
+
* `create` they are holding.
|
|
393
|
+
*
|
|
394
|
+
* ```ts
|
|
395
|
+
* await cache.persistence.flush(); // same as cache.flush()
|
|
396
|
+
* await cache.persistence.clear(); // wipe this namespace in storage (memory stays)
|
|
397
|
+
* await cache.persistence.hydrate(); // reload stored records into memory
|
|
398
|
+
* cache.persistence.stats(); // counters: hydrates, flushes, errors, pending…
|
|
399
|
+
*
|
|
400
|
+
* // logout → login:
|
|
401
|
+
* await cache.persistence.rotate('user-43'); // invalidate the previous session
|
|
402
|
+
* cache.clear(); // drop its entries from memory
|
|
403
|
+
* await cache.persistence.hydrate(); // load the new session's records
|
|
404
|
+
* ```
|
|
405
|
+
*/
|
|
406
|
+
get persistence(): PersistenceControl;
|
|
385
407
|
/**
|
|
386
408
|
* Writes pending changes to storage immediately.
|
|
387
409
|
*
|
|
@@ -391,7 +413,9 @@ export declare class BlazeCache<V = any> implements BlazeCacheLike<V> {
|
|
|
391
413
|
* When the write itself fails — quota, a blocked or transient IndexedDB error — the pass
|
|
392
414
|
* rejects **and hands every record it had claimed back onto the queue**, so the next flush
|
|
393
415
|
* (a later mutation's timer, an explicit call, `pagehide`, `dispose`) retries them instead
|
|
394
|
-
* of losing them.
|
|
416
|
+
* of losing them. A pass invalidated by {@link PersistenceControl.rotate} is the
|
|
417
|
+
* exception: its claimed work belongs to a session that no longer exists, so it is
|
|
418
|
+
* dropped and the flush resolves without writing.
|
|
395
419
|
*/
|
|
396
420
|
flush(): Promise<void>;
|
|
397
421
|
/**
|
package/dist/cache.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EAEd,UAAU,EAEV,kBAAkB,EAClB,cAAc,EACd,kBAAkB,EAClB,aAAa,EACb,mBAAmB,EACnB,UAAU,EACV,qBAAqB,EACrB,kBAAkB,EAClB,YAAY,EACZ,UAAU,EACV,YAAY,EACb,MAAM,YAAY,CAAC;AAIpB,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EAEd,UAAU,EAEV,kBAAkB,EAClB,cAAc,EACd,kBAAkB,EAClB,aAAa,EACb,mBAAmB,EACnB,UAAU,EACV,qBAAqB,EACrB,kBAAkB,EAClB,YAAY,EACZ,UAAU,EACV,YAAY,EACb,MAAM,YAAY,CAAC;AAIpB,OAAO,KAAK,EAAE,eAAe,EAAE,MA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