@blaze-cache/core 0.0.0-stage → 0.1.0

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.
@@ -0,0 +1,126 @@
1
+ import type { BlazeCacheLike, CacheEntry, CacheListener, CacheStats, SetOptions } from './types.js';
2
+ import type { WasmInitInput } from './wasm.js';
3
+ import type { CachePersistence, IndexedDbOptions } from './persistence/types.js';
4
+ /** Entries held when `capacity` is not given. */
5
+ export declare const DEFAULT_CAPACITY = 500;
6
+ /** Milliseconds a write waits for more writes before hitting IndexedDB. */
7
+ export declare const DEFAULT_FLUSH_DELAY_MS = 400;
8
+ /** Upper bound on records written by a single flush. */
9
+ export declare const DEFAULT_MAX_RECORDS = 2000;
10
+ /** Options for a custom {@link CachePersistence} adapter. */
11
+ export interface CachePersistenceOptions {
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
+ }
23
+ /** Options accepted by {@link BlazeCache.create}. */
24
+ export interface BlazeCacheOptions {
25
+ /** Maximum number of entries kept in memory (clamped to `>= 1`). Default {@link DEFAULT_CAPACITY}. */
26
+ capacity?: number;
27
+ /**
28
+ * Durable storage. `false`/omitted means memory only.
29
+ *
30
+ * * `{ namespace, database, store, ... }` — the built-in IndexedDB adapter.
31
+ * * `{ adapter, ... }` — any {@link CachePersistence} implementation.
32
+ */
33
+ persistence?: false | CachePersistenceOptions | IndexedDbPersistenceOptions;
34
+ /**
35
+ * How the `.wasm` binary is fetched and instantiated.
36
+ *
37
+ * Defaults to the binary shipped next to this package. Override it to serve the module
38
+ * from a CDN, or to pass pre-read bytes (as the Node smoke tests do).
39
+ */
40
+ wasm?: WasmInitInput;
41
+ }
42
+ /**
43
+ * The client-side cache: WebAssembly storage and eviction, optional write-through persistence.
44
+ *
45
+ * ```ts
46
+ * import { createCache } from '@blaze-cache/core';
47
+ *
48
+ * const cache = await createCache({ capacity: 1000, persistence: { namespace: 'app' } });
49
+ * cache.set('user:42', { name: 'Ada' }, { ttlMs: 30_000, tags: ['user:42'] });
50
+ * cache.get('user:42'); // { name: 'Ada' } — counted as a hit
51
+ * cache.invalidateTags('user:42'); // removes it and syncs IndexedDB
52
+ * await cache.dispose();
53
+ * ```
54
+ *
55
+ * All reads and writes are synchronous — the wasm module is instantiated during `create`, so
56
+ * the hot path never touches a `Promise`.
57
+ */
58
+ export declare class BlazeCache<V = any> implements BlazeCacheLike<V> {
59
+ #private;
60
+ private constructor();
61
+ /**
62
+ * Loads the wasm module, builds the cache and — if requested — hydrates it from storage.
63
+ *
64
+ * Storage failures (blocked IndexedDB, quota, private mode) degrade to memory-only with a
65
+ * console warning instead of rejecting.
66
+ */
67
+ static create<V = any>(options?: BlazeCacheOptions): Promise<BlazeCache<V>>;
68
+ /** Value stored under `key`, or `undefined` when missing or expired. Counts a hit/miss. */
69
+ get(key: string): V | undefined;
70
+ /** `true` when `key` is present and not expired. Never changes eviction state. */
71
+ has(key: string): boolean;
72
+ /** Live entry — value, remaining TTL and tags — without touching statistics. */
73
+ entry(key: string): CacheEntry<V> | undefined;
74
+ /** Snapshot of every live entry, oldest first. */
75
+ entries(): CacheEntry<V>[];
76
+ /** Live keys, oldest first. */
77
+ keys(): string[];
78
+ /** Live keys carrying `tag`. */
79
+ keysWithTag(tag: string): string[];
80
+ /** Tags attached to `key` (empty when the key is unknown). */
81
+ tagsOf(key: string): string[];
82
+ /** `true` when `key` carries `tag`. */
83
+ hasTag(key: string, tag: string): boolean;
84
+ /** Number of stored entries (may include not-yet-pruned expired ones). */
85
+ get size(): number;
86
+ /** Maximum number of entries. */
87
+ get capacity(): number;
88
+ /** Cumulative counters plus a computed `hitRate`. */
89
+ stats(): CacheStats;
90
+ /** Stores (or replaces) `key`. Replacing refreshes the TTL and replaces the tags. */
91
+ set(key: string, value: V, options?: SetOptions): void;
92
+ /** Removes `key`, returning whether it was there. */
93
+ delete(key: string): boolean;
94
+ /** Removes every entry carrying any of `tags`, returning the removed keys. */
95
+ invalidateTags(...tags: string[]): string[];
96
+ /** Removes every expired entry, returning the removed keys. */
97
+ prune(): string[];
98
+ /** Empties the cache. */
99
+ clear(): void;
100
+ /** Zeroes the cumulative counters without touching stored entries. */
101
+ resetStats(): void;
102
+ /**
103
+ * Subscribes to mutations. Returns the unsubscribe function.
104
+ *
105
+ * Persistence uses this internally, so listeners fire for every change regardless of
106
+ * whether storage is enabled.
107
+ */
108
+ on(listener: CacheListener): () => void;
109
+ /**
110
+ * Writes pending changes to storage immediately.
111
+ *
112
+ * Resolves once the underlying transaction commits. Concurrent calls are serialised, so
113
+ * this is safe to call from a `beforeunload` handler while a debounced flush is pending.
114
+ */
115
+ flush(): Promise<void>;
116
+ /**
117
+ * Flushes, unbinds page-lifecycle listeners and frees the wasm memory.
118
+ *
119
+ * The cache is unusable afterwards. A failed flush still rejects — the caller may retry or
120
+ * report it.
121
+ */
122
+ dispose(): Promise<void>;
123
+ }
124
+ /** Shorthand for {@link BlazeCache.create}. */
125
+ export declare function createCache<V = any>(options?: BlazeCacheOptions): Promise<BlazeCache<V>>;
126
+ //# sourceMappingURL=cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EAEd,UAAU,EACV,aAAa,EACb,UAAU,EACV,UAAU,EACX,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE/C,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAmB,MAAM,wBAAwB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Wasm, WasmCache } from './wasm.js';
2
+ import { indexedDbPersistence } from './persistence/indexeddb.js';
3
+ /** Entries held when `capacity` is not given. */
4
+ export const DEFAULT_CAPACITY = 500;
5
+ /** Milliseconds a write waits for more writes before hitting IndexedDB. */
6
+ export const DEFAULT_FLUSH_DELAY_MS = 400;
7
+ /** Upper bound on records written by a single flush. */
8
+ export const DEFAULT_MAX_RECORDS = 2000;
9
+ /**
10
+ * The client-side cache: WebAssembly storage and eviction, optional write-through persistence.
11
+ *
12
+ * ```ts
13
+ * import { createCache } from '@blaze-cache/core';
14
+ *
15
+ * const cache = await createCache({ capacity: 1000, persistence: { namespace: 'app' } });
16
+ * cache.set('user:42', { name: 'Ada' }, { ttlMs: 30_000, tags: ['user:42'] });
17
+ * cache.get('user:42'); // { name: 'Ada' } — counted as a hit
18
+ * cache.invalidateTags('user:42'); // removes it and syncs IndexedDB
19
+ * await cache.dispose();
20
+ * ```
21
+ *
22
+ * All reads and writes are synchronous — the wasm module is instantiated during `create`, so
23
+ * the hot path never touches a `Promise`.
24
+ */
25
+ export class BlazeCache {
26
+ #wasm;
27
+ #listeners = new Set();
28
+ #unbind = [];
29
+ #persist = null;
30
+ #flushDelayMs = DEFAULT_FLUSH_DELAY_MS;
31
+ #maxRecords = DEFAULT_MAX_RECORDS;
32
+ #dirty = new Set();
33
+ #deleted = new Set();
34
+ #clearAll = false;
35
+ #timer = null;
36
+ #chain = Promise.resolve();
37
+ #disposed = false;
38
+ constructor(wasm) {
39
+ this.#wasm = wasm;
40
+ }
41
+ /**
42
+ * Loads the wasm module, builds the cache and — if requested — hydrates it from storage.
43
+ *
44
+ * Storage failures (blocked IndexedDB, quota, private mode) degrade to memory-only with a
45
+ * console warning instead of rejecting.
46
+ */
47
+ static async create(options = {}) {
48
+ await initBlazeWasm(options.wasm);
49
+ const cache = new BlazeCache(new WasmCache(options.capacity ?? DEFAULT_CAPACITY));
50
+ await cache.#setupPersistence(options.persistence);
51
+ return cache;
52
+ }
53
+ // ------------------------------------------------------------------ reads
54
+ /** Value stored under `key`, or `undefined` when missing or expired. Counts a hit/miss. */
55
+ get(key) {
56
+ return this.#wasm.get(key);
57
+ }
58
+ /** `true` when `key` is present and not expired. Never changes eviction state. */
59
+ has(key) {
60
+ return this.#wasm.has(key);
61
+ }
62
+ /** Live entry — value, remaining TTL and tags — without touching statistics. */
63
+ entry(key) {
64
+ return this.#wasm.entry(key);
65
+ }
66
+ /** Snapshot of every live entry, oldest first. */
67
+ entries() {
68
+ return this.#wasm.entries();
69
+ }
70
+ /** Live keys, oldest first. */
71
+ keys() {
72
+ return this.#wasm.keys();
73
+ }
74
+ /** Live keys carrying `tag`. */
75
+ keysWithTag(tag) {
76
+ return this.#wasm.keysWithTag(tag);
77
+ }
78
+ /** Tags attached to `key` (empty when the key is unknown). */
79
+ tagsOf(key) {
80
+ return this.#wasm.tagsOf(key);
81
+ }
82
+ /** `true` when `key` carries `tag`. */
83
+ hasTag(key, tag) {
84
+ return this.#wasm.hasTag(key, tag);
85
+ }
86
+ /** Number of stored entries (may include not-yet-pruned expired ones). */
87
+ get size() {
88
+ return this.#wasm.size;
89
+ }
90
+ /** Maximum number of entries. */
91
+ get capacity() {
92
+ return this.#wasm.capacity;
93
+ }
94
+ /** Cumulative counters plus a computed `hitRate`. */
95
+ stats() {
96
+ const base = this.#wasm.stats();
97
+ const total = base.hits + base.misses;
98
+ return { ...base, hitRate: total === 0 ? 0 : base.hits / total };
99
+ }
100
+ // ----------------------------------------------------------------- writes
101
+ /** Stores (or replaces) `key`. Replacing refreshes the TTL and replaces the tags. */
102
+ set(key, value, options) {
103
+ this.#wasm.set(key, value, options?.ttlMs ?? null, options?.tags ? [...options.tags] : []);
104
+ this.#notify({ type: 'set', key });
105
+ }
106
+ /** Removes `key`, returning whether it was there. */
107
+ delete(key) {
108
+ const removed = this.#wasm.delete(key);
109
+ if (removed)
110
+ this.#notify({ type: 'delete', key });
111
+ return removed;
112
+ }
113
+ /** Removes every entry carrying any of `tags`, returning the removed keys. */
114
+ invalidateTags(...tags) {
115
+ if (tags.length === 0)
116
+ return [];
117
+ const removed = this.#wasm.invalidateTags(tags);
118
+ if (removed.length > 0)
119
+ this.#notify({ type: 'invalidate', keys: removed });
120
+ return removed;
121
+ }
122
+ /** Removes every expired entry, returning the removed keys. */
123
+ prune() {
124
+ const removed = this.#wasm.prune();
125
+ if (removed.length > 0)
126
+ this.#notify({ type: 'prune', keys: removed });
127
+ return removed;
128
+ }
129
+ /** Empties the cache. */
130
+ clear() {
131
+ this.#wasm.clear();
132
+ this.#notify({ type: 'clear' });
133
+ }
134
+ /** Zeroes the cumulative counters without touching stored entries. */
135
+ resetStats() {
136
+ this.#wasm.resetStats();
137
+ }
138
+ // ------------------------------------------------------------- observers
139
+ /**
140
+ * Subscribes to mutations. Returns the unsubscribe function.
141
+ *
142
+ * Persistence uses this internally, so listeners fire for every change regardless of
143
+ * whether storage is enabled.
144
+ */
145
+ on(listener) {
146
+ this.#listeners.add(listener);
147
+ return () => {
148
+ this.#listeners.delete(listener);
149
+ };
150
+ }
151
+ /**
152
+ * Writes pending changes to storage immediately.
153
+ *
154
+ * Resolves once the underlying transaction commits. Concurrent calls are serialised, so
155
+ * this is safe to call from a `beforeunload` handler while a debounced flush is pending.
156
+ */
157
+ flush() {
158
+ if (this.#disposed)
159
+ return Promise.resolve();
160
+ if (this.#timer !== null) {
161
+ clearTimeout(this.#timer);
162
+ this.#timer = null;
163
+ }
164
+ // Chain instead of guarding: a change landing *during* a flush starts a follow-up pass.
165
+ this.#chain = this.#chain.then(() => this.#runFlush(), () => this.#runFlush());
166
+ return this.#chain;
167
+ }
168
+ /**
169
+ * Flushes, unbinds page-lifecycle listeners and frees the wasm memory.
170
+ *
171
+ * The cache is unusable afterwards. A failed flush still rejects — the caller may retry or
172
+ * report it.
173
+ */
174
+ async dispose() {
175
+ if (this.#disposed)
176
+ return;
177
+ await this.flush();
178
+ this.#disposed = true;
179
+ if (this.#timer !== null) {
180
+ clearTimeout(this.#timer);
181
+ this.#timer = null;
182
+ }
183
+ for (const unbind of this.#unbind.splice(0))
184
+ unbind();
185
+ this.#listeners.clear();
186
+ await this.#persist?.close?.();
187
+ this.#persist = null;
188
+ this.#wasm.free();
189
+ }
190
+ // ----------------------------------------------------------- persistence
191
+ async #setupPersistence(spec) {
192
+ if (!spec)
193
+ return;
194
+ let adapter;
195
+ let flushDelayMs;
196
+ let maxRecords;
197
+ if ('adapter' in spec) {
198
+ adapter = spec.adapter;
199
+ flushDelayMs = spec.flushDelayMs;
200
+ maxRecords = spec.maxRecords;
201
+ }
202
+ else {
203
+ adapter = indexedDbPersistence(spec);
204
+ flushDelayMs = spec.flushDelayMs;
205
+ maxRecords = spec.maxRecords;
206
+ }
207
+ this.#persist = adapter;
208
+ this.#flushDelayMs = flushDelayMs ?? DEFAULT_FLUSH_DELAY_MS;
209
+ this.#maxRecords = maxRecords ?? DEFAULT_MAX_RECORDS;
210
+ try {
211
+ await this.#hydrate(adapter);
212
+ }
213
+ catch (error) {
214
+ this.#persist = null;
215
+ console.warn('[blaze-cache] persistence unavailable — running memory-only.', error);
216
+ return;
217
+ }
218
+ this.#bindPageLifecycle();
219
+ }
220
+ /** Fills the cache from storage, dropping records whose TTL elapsed while we were away. */
221
+ async #hydrate(adapter) {
222
+ const records = await adapter.load();
223
+ const now = Date.now();
224
+ for (const record of records) {
225
+ const remaining = record.ttlMs === null ? null : record.ttlMs - (now - record.storedAt);
226
+ if (remaining !== null && remaining <= 0)
227
+ continue;
228
+ // Direct wasm call: hydration is not a user write, so it emits no change event.
229
+ this.#wasm.set(record.key, record.value, remaining, record.tags);
230
+ }
231
+ }
232
+ #bindPageLifecycle() {
233
+ if (typeof window === 'undefined')
234
+ return;
235
+ const flush = () => {
236
+ void this.flush().catch((error) => {
237
+ console.error('[blaze-cache] flush on page hide failed.', error);
238
+ });
239
+ };
240
+ const onVisibility = () => {
241
+ if (document.visibilityState === 'hidden')
242
+ flush();
243
+ };
244
+ window.addEventListener('pagehide', flush);
245
+ document.addEventListener('visibilitychange', onVisibility);
246
+ this.#unbind.push(() => {
247
+ window.removeEventListener('pagehide', flush);
248
+ document.removeEventListener('visibilitychange', onVisibility);
249
+ });
250
+ }
251
+ #scheduleFlush() {
252
+ if (this.#timer !== null)
253
+ return;
254
+ this.#timer = setTimeout(() => {
255
+ this.#timer = null;
256
+ void this.flush().catch((error) => {
257
+ console.error('[blaze-cache] background flush failed.', error);
258
+ });
259
+ }, this.#flushDelayMs);
260
+ }
261
+ async #runFlush() {
262
+ const persist = this.#persist;
263
+ if (!persist || this.#disposed)
264
+ return;
265
+ // Take ownership of the pending work up front, so a `set` racing with the awaits below
266
+ // lands in the *next* pass instead of being written twice.
267
+ const clearAll = this.#clearAll;
268
+ const deleted = [...this.#deleted];
269
+ const dirty = [...this.#dirty].filter((key) => !this.#deleted.has(key));
270
+ this.#clearAll = false;
271
+ this.#dirty.clear();
272
+ this.#deleted.clear();
273
+ if (clearAll)
274
+ await persist.clear();
275
+ if (dirty.length > 0) {
276
+ const records = [];
277
+ for (const key of dirty.slice(-this.#maxRecords)) {
278
+ const entry = this.#wasm.entry(key);
279
+ if (!entry)
280
+ continue;
281
+ records.push({
282
+ key,
283
+ value: entry.value,
284
+ tags: entry.tags,
285
+ ttlMs: entry.ttlMs,
286
+ storedAt: Date.now(),
287
+ });
288
+ }
289
+ if (records.length > 0)
290
+ await persist.save(records);
291
+ }
292
+ if (deleted.length > 0)
293
+ await persist.remove(deleted);
294
+ }
295
+ #notify(change) {
296
+ if (this.#persist && !this.#disposed) {
297
+ switch (change.type) {
298
+ case 'set':
299
+ this.#deleted.delete(change.key);
300
+ this.#dirty.add(change.key);
301
+ break;
302
+ case 'delete':
303
+ this.#dirty.delete(change.key);
304
+ this.#deleted.add(change.key);
305
+ break;
306
+ case 'clear':
307
+ this.#dirty.clear();
308
+ this.#deleted.clear();
309
+ this.#clearAll = true;
310
+ break;
311
+ case 'invalidate':
312
+ case 'prune':
313
+ for (const key of change.keys) {
314
+ this.#dirty.delete(key);
315
+ this.#deleted.add(key);
316
+ }
317
+ break;
318
+ }
319
+ this.#scheduleFlush();
320
+ }
321
+ for (const listener of this.#listeners)
322
+ listener(change);
323
+ }
324
+ }
325
+ /** Shorthand for {@link BlazeCache.create}. */
326
+ export function createCache(options) {
327
+ return BlazeCache.create(options);
328
+ }
329
+ //# sourceMappingURL=cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAErD,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAGlE,iDAAiD;AACjD,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,CAAC;AACpC,2EAA2E;AAC3E,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAG,CAAC;AAC1C,wDAAwD;AACxD,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,CAAC;AAqCxC;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,UAAU;IACZ,KAAK,CAAY;IACjB,UAAU,GAAG,IAAI,GAAG,EAAiB,CAAC;IACtC,OAAO,GAAsB,EAAE,CAAC;IACzC,QAAQ,GAA4B,IAAI,CAAC;IACzC,aAAa,GAAG,sBAAsB,CAAC;IACvC,WAAW,GAAG,mBAAmB,CAAC;IAClC,MAAM,GAAG,IAAI,GAAG,EAAU,CAAC;IAC3B,QAAQ,GAAG,IAAI,GAAG,EAAU,CAAC;IAC7B,SAAS,GAAG,KAAK,CAAC;IAClB,MAAM,GAAyC,IAAI,CAAC;IACpD,MAAM,GAAkB,OAAO,CAAC,OAAO,EAAE,CAAC;IAC1C,SAAS,GAAG,KAAK,CAAC;IAElB,YAAoB,IAAe;QACjC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,KAAK,CAAC,MAAM,CAAU,UAA6B,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2B;IAC9D,OAAO,UAAU,CAAC,MAAM,CAAI,OAAO,CAAC,CAAC;AACvC,CAAC"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Blaze Cache — a WebAssembly client-side cache.
3
+ *
4
+ * The Rust core provides SIEVE eviction, per-entry TTLs and tag invalidation; this package
5
+ * adds the browser glue: one-time wasm initialisation and optional IndexedDB persistence.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { createCache } from '@blaze-cache/core';
10
+ *
11
+ * const cache = await createCache({ capacity: 1000 });
12
+ * cache.set('greeting', 'hello', { ttlMs: 30_000, tags: ['greeting'] });
13
+ * ```
14
+ *
15
+ * @packageDocumentation
16
+ */
17
+ export { BlazeCache, createCache, DEFAULT_CAPACITY, DEFAULT_FLUSH_DELAY_MS, DEFAULT_MAX_RECORDS } from './cache.js';
18
+ export type { BlazeCacheOptions, CachePersistenceOptions, IndexedDbPersistenceOptions } from './cache.js';
19
+ export { initBlazeWasm, wasmUrl } from './wasm.js';
20
+ export type { WasmInitInput } from './wasm.js';
21
+ export { indexedDbPersistence } from './persistence/indexeddb.js';
22
+ export type { CachePersistence, IndexedDbOptions, PersistedRecord } from './persistence/types.js';
23
+ export { safeStableStringify, stableStringify } from './utils.js';
24
+ export type { BlazeCacheLike, CacheChange, CacheEntry, CacheListener, CacheStats, SetOptions, } from './types.js';
25
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACpH,YAAY,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAC;AAE1G,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnD,YAAY,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,YAAY,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAElG,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElE,YAAY,EACV,cAAc,EACd,WAAW,EACX,UAAU,EACV,aAAa,EACb,UAAU,EACV,UAAU,GACX,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Blaze Cache — a WebAssembly client-side cache.
3
+ *
4
+ * The Rust core provides SIEVE eviction, per-entry TTLs and tag invalidation; this package
5
+ * adds the browser glue: one-time wasm initialisation and optional IndexedDB persistence.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { createCache } from '@blaze-cache/core';
10
+ *
11
+ * const cache = await createCache({ capacity: 1000 });
12
+ * cache.set('greeting', 'hello', { ttlMs: 30_000, tags: ['greeting'] });
13
+ * ```
14
+ *
15
+ * @packageDocumentation
16
+ */
17
+ export { BlazeCache, createCache, DEFAULT_CAPACITY, DEFAULT_FLUSH_DELAY_MS, DEFAULT_MAX_RECORDS } from './cache.js';
18
+ export { initBlazeWasm, wasmUrl } from './wasm.js';
19
+ export { indexedDbPersistence } from './persistence/indexeddb.js';
20
+ export { safeStableStringify, stableStringify } from './utils.js';
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAGpH,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAGlE,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,19 @@
1
+ import type { CachePersistence, IndexedDbOptions } from './types.js';
2
+ /**
3
+ * IndexedDB-backed persistence.
4
+ *
5
+ * One database holds one object store; records from different caches are separated by a
6
+ * `namespace` field with its own index, so several `BlazeCache` instances can share a
7
+ * database without stepping on each other.
8
+ *
9
+ * ```ts
10
+ * const cache = await createCache({
11
+ * persistence: { namespace: 'session-42', flushDelayMs: 250 },
12
+ * });
13
+ * ```
14
+ *
15
+ * Failures reject with a normal `Error` — `BlazeCache.create` catches them, warns, and keeps
16
+ * running memory-only (private browsing modes routinely block IndexedDB).
17
+ */
18
+ export declare function indexedDbPersistence(options?: IndexedDbOptions): CachePersistence;
19
+ //# sourceMappingURL=indexeddb.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"indexeddb.d.ts","sourceRoot":"","sources":["../../src/persistence/indexeddb.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAmB,MAAM,YAAY,CAAC;AAatF;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,GAAE,gBAAqB,GAAG,gBAAgB,CAsIrF"}