flash-store 2.0.1 → 2.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.
Files changed (39) hide show
  1. package/README.md +92 -19
  2. package/dist/package.json +90 -61
  3. package/dist/src/browser.d.ts +20 -0
  4. package/dist/src/browser.d.ts.map +1 -0
  5. package/dist/src/browser.js +24 -0
  6. package/dist/src/browser.js.map +1 -0
  7. package/dist/src/config.d.ts +4 -0
  8. package/dist/src/config.d.ts.map +1 -1
  9. package/dist/src/config.js +4 -11
  10. package/dist/src/config.js.map +1 -1
  11. package/dist/src/flash-store-core.d.ts +65 -0
  12. package/dist/src/flash-store-core.d.ts.map +1 -0
  13. package/dist/src/flash-store-core.js +201 -0
  14. package/dist/src/flash-store-core.js.map +1 -0
  15. package/dist/src/flash-store-sync-core.d.ts +72 -0
  16. package/dist/src/flash-store-sync-core.d.ts.map +1 -0
  17. package/dist/src/flash-store-sync-core.js +177 -0
  18. package/dist/src/flash-store-sync-core.js.map +1 -0
  19. package/dist/src/flash-store-sync.d.ts +5 -66
  20. package/dist/src/flash-store-sync.d.ts.map +1 -1
  21. package/dist/src/flash-store-sync.js +7 -171
  22. package/dist/src/flash-store-sync.js.map +1 -1
  23. package/dist/src/flash-store.d.ts +5 -63
  24. package/dist/src/flash-store.d.ts.map +1 -1
  25. package/dist/src/flash-store.js +70 -208
  26. package/dist/src/flash-store.js.map +1 -1
  27. package/dist/src/indexeddb-backend.d.ts +40 -0
  28. package/dist/src/indexeddb-backend.d.ts.map +1 -0
  29. package/dist/src/indexeddb-backend.js +200 -0
  30. package/dist/src/indexeddb-backend.js.map +1 -0
  31. package/dist/src/key-encoding.d.ts +9 -0
  32. package/dist/src/key-encoding.d.ts.map +1 -0
  33. package/dist/src/key-encoding.js +22 -0
  34. package/dist/src/key-encoding.js.map +1 -0
  35. package/dist/src/store-backend.d.ts +35 -0
  36. package/dist/src/store-backend.d.ts.map +1 -0
  37. package/dist/src/store-backend.js +2 -0
  38. package/dist/src/store-backend.js.map +1 -0
  39. package/package.json +38 -9
@@ -0,0 +1,201 @@
1
+ /**
2
+ * Owns the async Map API, validation, and JSON encoding shared by the native
3
+ * and browser entries. Its storage backend supplies transactions and snapshots.
4
+ */
5
+ import { log, VERSION } from './config.js';
6
+ import { validateKeySize } from './key-encoding.js';
7
+ /** Reject keys outside the serialized storage contract. */
8
+ export function validateKey(key) {
9
+ if ((typeof key === 'number' && !Number.isFinite(key)) ||
10
+ (typeof key === 'string' && key.includes('\0')) ||
11
+ (typeof key !== 'number' && typeof key !== 'string')) {
12
+ throw new TypeError('Keys must be finite numbers or strings without null characters');
13
+ }
14
+ validateKeySize(key);
15
+ }
16
+ /** Serialize a value once, rejecting values that JSON cannot represent. */
17
+ export function serialize(value) {
18
+ const serialized = JSON.stringify(value);
19
+ if (serialized === undefined)
20
+ throw new TypeError('Value must be JSON serializable');
21
+ return serialized;
22
+ }
23
+ /**
24
+ * Writes pre-serialized JSON for FlashStoreSync, which serializes at call time.
25
+ * Used by the shared synchronous cache, outside the public package entries.
26
+ */
27
+ export let writeSerialized;
28
+ /** Use Map's zero equality; TypeScript represents both signs as the same numeric type. */
29
+ function normalizeKey(key) {
30
+ return Object.is(key, -0) ? 0 : key;
31
+ }
32
+ /** Reject ambiguous bounds before starting a storage scan. */
33
+ function validateOptions(options) {
34
+ if (options.prefix !== undefined) {
35
+ if (typeof options.prefix !== 'string') {
36
+ throw new TypeError('prefix must be a string');
37
+ }
38
+ validateKey(options.prefix);
39
+ }
40
+ if ((options.gt !== undefined && options.gte !== undefined) ||
41
+ (options.lt !== undefined && options.lte !== undefined) ||
42
+ (options.prefix !== undefined &&
43
+ (options.gt !== undefined ||
44
+ options.gte !== undefined ||
45
+ options.lt !== undefined ||
46
+ options.lte !== undefined))) {
47
+ throw new TypeError('Conflicting range bounds');
48
+ }
49
+ if (options.limit !== undefined &&
50
+ (!Number.isSafeInteger(options.limit) || options.limit < 0)) {
51
+ throw new RangeError('limit must be a non-negative safe integer');
52
+ }
53
+ for (const bound of [options.gt, options.gte, options.lt, options.lte]) {
54
+ if (bound !== undefined)
55
+ validateKey(bound);
56
+ }
57
+ }
58
+ /** Shared Map API for the installed runtime-specific entries. */
59
+ export class FlashStoreCore {
60
+ static VERSION = VERSION;
61
+ workdir;
62
+ backend;
63
+ closePromise;
64
+ destroyPromise;
65
+ static {
66
+ writeSerialized = (store, key, serialized) => store.write(key, serialized);
67
+ }
68
+ /** Binds a storage backend and exposes its location through the public workdir property. */
69
+ constructor(workdir, backend, requested = workdir) {
70
+ this.workdir = workdir;
71
+ this.backend = backend;
72
+ log.verbose('FlashStore', 'constructor(%s)', requested);
73
+ }
74
+ /** Returns the package version. */
75
+ version() {
76
+ return VERSION;
77
+ }
78
+ /** Stores a JSON-serializable value and resolves after its write completes. */
79
+ async set(key, value) {
80
+ validateKey(key);
81
+ const serialized = serialize(value);
82
+ log.verbose('FlashStore', 'set(%s, %s)', key, typeof value);
83
+ await this.write(key, serialized);
84
+ return this;
85
+ }
86
+ /** Writes validated, serialized JSON and publishes the set event on success. */
87
+ async write(key, serialized) {
88
+ log.silly('FlashStore', 'set(%s, %s)', key, serialized);
89
+ await this.backend.put(normalizeKey(key), serialized);
90
+ this.backend.publish?.('set');
91
+ }
92
+ /** Returns the stored value, or undefined when the key is absent. */
93
+ async get(key) {
94
+ validateKey(key);
95
+ log.verbose('FlashStore', 'get(%s)', key);
96
+ const value = await this.backend.get(normalizeKey(key));
97
+ return value === undefined ? undefined : JSON.parse(value);
98
+ }
99
+ /** Returns whether the key exists, including when its value is falsey. */
100
+ async has(key) {
101
+ validateKey(key);
102
+ return this.backend.has(normalizeKey(key));
103
+ }
104
+ /** Deletes a key and reports whether an entry existed. */
105
+ async delete(key) {
106
+ validateKey(key);
107
+ log.verbose('FlashStore', 'delete(%s)', key);
108
+ const deleted = await this.backend.delete(normalizeKey(key));
109
+ this.backend.publish?.('delete');
110
+ return deleted;
111
+ }
112
+ /** Removes every entry after queued writes. */
113
+ async clear() {
114
+ log.verbose('FlashStore', 'clear()');
115
+ await this.backend.clear();
116
+ this.backend.publish?.('clear');
117
+ }
118
+ /** Starts counting immediately and resolves to the size of that read snapshot. */
119
+ get size() {
120
+ log.verbose('FlashStore', 'size()');
121
+ return this.backend.count();
122
+ }
123
+ /** Iterates a snapshot in storage key order and releases it on early exit. */
124
+ async *entries(options = {}) {
125
+ log.verbose('FlashStore', '*entries(%s)', JSON.stringify(options));
126
+ validateOptions(options);
127
+ if (options.limit === 0)
128
+ return;
129
+ const lower = options.gte ?? options.gt;
130
+ const upper = options.lte ?? options.lt;
131
+ const range = {
132
+ lower: lower === undefined ? undefined : normalizeKey(lower),
133
+ upper: upper === undefined ? undefined : normalizeKey(upper),
134
+ lowerOpen: options.gt !== undefined,
135
+ upperOpen: options.lt !== undefined,
136
+ reverse: options.reverse ?? false,
137
+ prefix: options.prefix,
138
+ limit: options.limit,
139
+ };
140
+ // Native LMDB provides a synchronous cursor. Chromium finishes its read
141
+ // transaction before yielding so consumer awaits cannot invalidate it.
142
+ const entries = this.backend.scan(range);
143
+ for (const { key, value } of entries instanceof Promise
144
+ ? await entries
145
+ : entries)
146
+ yield [key, JSON.parse(value)];
147
+ }
148
+ /** Iterates keys with the same range semantics as entries(). */
149
+ async *keys(options = {}) {
150
+ log.verbose('FlashStore', 'keys()');
151
+ for await (const [key] of this.entries(options))
152
+ yield key;
153
+ }
154
+ /** Iterates values with the same range semantics as entries(). */
155
+ async *values(options = {}) {
156
+ log.verbose('FlashStore', 'values()');
157
+ for await (const [, value] of this.entries(options))
158
+ yield value;
159
+ }
160
+ /** Returns the asynchronous entries iterator. */
161
+ [Symbol.asyncIterator]() {
162
+ log.verbose('FlashStore', '*[Symbol.asyncIterator]()');
163
+ return this.entries();
164
+ }
165
+ /** Awaits each callback in snapshot key order; stops and rejects on the first failure. */
166
+ async forEach(callback, thisArg) {
167
+ log.verbose('FlashStore', 'forEach()');
168
+ for await (const [key, value] of this)
169
+ await callback.call(thisArg, value, key, this);
170
+ }
171
+ /** Closes the database after outstanding writes; repeated calls are safe. */
172
+ async close() {
173
+ log.verbose('FlashStore', 'close()');
174
+ try {
175
+ this.closePromise ??= this.backend.close();
176
+ await this.closePromise;
177
+ }
178
+ catch (error) {
179
+ this.closePromise = undefined;
180
+ throw error;
181
+ }
182
+ }
183
+ /** Closes this handle and removes its backing storage once. Failed removals can be retried. */
184
+ async destroy() {
185
+ log.verbose('FlashStore', 'destroy()');
186
+ this.destroyPromise ??= this.removeStorage();
187
+ await this.destroyPromise;
188
+ }
189
+ /** Releases the handle before removal and leaves failures available for retry. */
190
+ async removeStorage() {
191
+ try {
192
+ await this.close();
193
+ await this.backend.destroy();
194
+ }
195
+ catch (error) {
196
+ this.destroyPromise = undefined;
197
+ throw error;
198
+ }
199
+ }
200
+ }
201
+ //# sourceMappingURL=flash-store-core.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flash-store-core.js","sourceRoot":"","sources":["../../src/flash-store-core.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAiBnD,2DAA2D;AAC3D,MAAM,UAAU,WAAW,CAAC,GAAa;IACvC,IACE,CAAC,OAAO,GAAG,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QAClD,CAAC,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC/C,CAAC,OAAO,GAAG,KAAK,QAAQ,IAAI,OAAO,GAAG,KAAK,QAAQ,CAAC,EACpD,CAAC;QACD,MAAM,IAAI,SAAS,CACjB,gEAAgE,CACjE,CAAA;IACH,CAAC;IACD,eAAe,CAAC,GAAG,CAAC,CAAA;AACtB,CAAC;AAED,2EAA2E;AAC3E,MAAM,UAAU,SAAS,CAAC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jB,GAAG,CAAC,OAAO,CAAC,YAAY,EAAE,WAAW,CAAC,CAAA;QACtC,IAAI,KAAK,EAAE,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,IAAI;YACnC,MAAM,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,CAAC,CAAA;IAClD,CAAC;IAED,6EAA6E;IAC7E,KAAK,CAAC,KAAK;QACT,GAAG,CAAC,OAAO,CAAC,YAAY,EAAE,SAAS,CAAC,CAAA;QACpC,IAAI,CAAC;YACH,IAAI,CAAC,YAAY,KAAK,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAA;YAC1C,MAAM,IAAI,CAAC,YAAY,CAAA;QACzB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,YAAY,GAAG,SAAS,CAAA;YAC7B,MAAM,KAAK,CAAA;QACb,CAAC;IACH,CAAC;IAED,+FAA+F;IAC/F,KAAK,CAAC,OAAO;QACX,GAAG,CAAC,OAAO,CAAC,YAAY,EAAE,WAAW,CAAC,CAAA;QACtC,IAAI,CAAC,cAAc,KAAK,IAAI,CAAC,aAAa,EAAE,CAAA;QAC5C,MAAM,IAAI,CAAC,cAAc,CAAA;IAC3B,CAAC;IAED,kFAAkF;IAC1E,KAAK,CAAC,aAAa;QACzB,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,KAAK,EAAE,CAAA;YAClB,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAA;QAC9B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,cAAc,GAAG,SAAS,CAAA;YAC/B,MAAM,KAAK,CAAA;QACb,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Provides a synchronous in-memory Map facade with ordered asynchronous write-back.
3
+ * FlashStore owns persistence; ready() is the boundary for observing write failures.
4
+ * Keys and values are validated and serialized when a mutation is accepted, so
5
+ * invalid input throws synchronously and later object changes are not persisted.
6
+ */
7
+ import { FlashStoreCore, type StoreKey } from './flash-store-core.ts';
8
+ /**
9
+ * In-memory Map backed by asynchronous storage writes.
10
+ * Await ready() before reading restored data; detected write failures reject further mutations.
11
+ * Restored entries follow storage key order.
12
+ */
13
+ export declare class FlashStoreSyncCore<K extends StoreKey, V> implements Map<K, V> {
14
+ static VERSION: string;
15
+ readonly workdir: string;
16
+ private readonly cacheMap;
17
+ private readonly flashStore;
18
+ private readonly touched;
19
+ private loading;
20
+ private clearedDuringLoad;
21
+ private pending;
22
+ private closing;
23
+ private failure?;
24
+ /** Starts restoring the cache from the already constructed backing store. */
25
+ protected constructor(workdir: string, flashStore: FlashStoreCore<K, V>);
26
+ /** Restore untouched keys while immediate cache mutations remain authoritative. */
27
+ private load;
28
+ /** Serialize writes behind initialization; reject mutations after a detected failure. */
29
+ private enqueue;
30
+ /** Report background errors once while retaining the rejection for lifecycle calls. */
31
+ private observeFailure;
32
+ /** Returns the package version. */
33
+ version(): string;
34
+ /** Waits for initialization and writes queued before this call, rejecting on failure. */
35
+ ready(): Promise<void>;
36
+ /** Waits for writes and closes the backing store, preserving write and close failures. */
37
+ close(): Promise<void>;
38
+ /** Closes even on write failure; removes backing storage only after successful writes. */
39
+ destroy(): Promise<void>;
40
+ /** Returns the current number of cached entries. */
41
+ get size(): number;
42
+ /** Identifies this object as a Map. */
43
+ get [Symbol.toStringTag](): string;
44
+ /** Iterates cached entries in insertion order. */
45
+ [Symbol.iterator](): MapIterator<[K, V]>;
46
+ /** Iterates cached entries in insertion order. */
47
+ entries(): MapIterator<[K, V]>;
48
+ /** Iterates cached keys in insertion order. */
49
+ keys(): MapIterator<K>;
50
+ /** Iterates cached values in insertion order. */
51
+ values(): MapIterator<V>;
52
+ /** Clears the cache immediately and queues persistent removal. */
53
+ clear(): void;
54
+ /** Removes a cached entry immediately and queues persistent removal. */
55
+ delete(key: K): boolean;
56
+ /** Invokes the callback for each cached entry. */
57
+ forEach(callbackfn: (value: V, key: K, map: Map<K, V>) => void, thisArg?: unknown): void;
58
+ /** Reads a cached value; await ready() first to include previously persisted data. */
59
+ get(key: K): V | undefined;
60
+ /** Checks the cache; await ready() first to include previously persisted data. */
61
+ has(key: K): boolean;
62
+ /** Returns a cached value or inserts and queues the supplied default. */
63
+ getOrInsert(key: K, defaultValue: V): V;
64
+ /** Returns a cached value or computes, inserts, and queues a new value. */
65
+ getOrInsertComputed(key: K, callback: (key: K) => V): V;
66
+ /**
67
+ * Updates the cache immediately and queues an ordered persistent write of the
68
+ * value's JSON at call time. Throws without changes for invalid keys or values.
69
+ */
70
+ set(key: K, value: V): this;
71
+ }
72
+ //# sourceMappingURL=flash-store-sync-core.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flash-store-sync-core.d.ts","sourceRoot":"","sources":["../../src/flash-store-sync-core.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EACL,cAAc,EACd,KAAK,QAAQ,EAId,MAAM,uBAAuB,CAAA;AAE9B;;;;GAIG;AACH,qBAAa,kBAAkB,CAAC,CAAC,SAAS,QAAQ,EAAE,CAAC,CAAE,YAAW,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC;IACzE,MAAM,CAAC,OAAO,SAAyB;IACvC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAkB;IAC3C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAsB;IACjD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAe;IACvC,OAAO,CAAC,OAAO,CAAO;IACtB,OAAO,CAAC,iBAAiB,CAAQ;IACjC,OAAO,CAAC,OAAO,CAAe;IAC9B,OAAO,CAAC,OAAO,CAAQ;IACvB,OAAO,CAAC,OAAO,CAAC,CAAoB;IAEpC,6EAA6E;IAC7E,SAAS,aAAa,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,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,EAAE,CAAC,GAAG,OAAO,CAEnB;IAED,yEAAyE;IACzE,WAAW,CAAC,GAAG,EAAE,CAAC,EAAE,YAAY,EAAE,CAAC,GAAG,CAAC,CAItC;IAED,2EAA2E;IAC3E,mBAAmB,CAAC,GAAG,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAKtD;IAED;;;OAGG;IACH,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAO1B;CACF"}
@@ -0,0 +1,177 @@
1
+ /**
2
+ * Provides a synchronous in-memory Map facade with ordered asynchronous write-back.
3
+ * FlashStore owns persistence; ready() is the boundary for observing write failures.
4
+ * Keys and values are validated and serialized when a mutation is accepted, so
5
+ * invalid input throws synchronously and later object changes are not persisted.
6
+ */
7
+ import { log } from './config.js';
8
+ import { FlashStoreCore, serialize, validateKey, writeSerialized, } from './flash-store-core.js';
9
+ /**
10
+ * In-memory Map backed by asynchronous storage writes.
11
+ * Await ready() before reading restored data; detected write failures reject further mutations.
12
+ * Restored entries follow storage key order.
13
+ */
14
+ export class FlashStoreSyncCore {
15
+ static VERSION = FlashStoreCore.VERSION;
16
+ workdir;
17
+ cacheMap = new Map();
18
+ flashStore;
19
+ touched = new Set();
20
+ loading = true;
21
+ clearedDuringLoad = false;
22
+ pending;
23
+ closing = false;
24
+ failure;
25
+ /** Starts restoring the cache from the already constructed backing store. */
26
+ constructor(workdir, flashStore) {
27
+ log.verbose('CacheStore', 'constructor(%s)', workdir);
28
+ this.workdir = workdir;
29
+ this.flashStore = flashStore;
30
+ this.pending = this.load();
31
+ this.observeFailure();
32
+ }
33
+ /** Restore untouched keys while immediate cache mutations remain authoritative. */
34
+ async load() {
35
+ try {
36
+ for await (const [key, value] of this.flashStore) {
37
+ if (!this.clearedDuringLoad && !this.touched.has(key))
38
+ this.cacheMap.set(key, value);
39
+ }
40
+ }
41
+ finally {
42
+ this.loading = false;
43
+ this.touched.clear();
44
+ }
45
+ }
46
+ /** Serialize writes behind initialization; reject mutations after a detected failure. */
47
+ enqueue(action) {
48
+ if (this.closing)
49
+ throw new Error('Store is closing or closed');
50
+ if (this.failure)
51
+ throw this.failure.error;
52
+ this.pending = this.pending.then(async () => {
53
+ await action();
54
+ });
55
+ this.observeFailure();
56
+ }
57
+ /** Report background errors once while retaining the rejection for lifecycle calls. */
58
+ observeFailure() {
59
+ void this.pending.catch((error) => {
60
+ if (!this.failure) {
61
+ this.failure = { error };
62
+ log.error('CacheStore', 'Background operation failed: %s', error);
63
+ }
64
+ });
65
+ }
66
+ /** Returns the package version. */
67
+ version() {
68
+ return this.flashStore.version();
69
+ }
70
+ /** Waits for initialization and writes queued before this call, rejecting on failure. */
71
+ async ready() {
72
+ await this.pending;
73
+ }
74
+ /** Waits for writes and closes the backing store, preserving write and close failures. */
75
+ async close() {
76
+ this.closing = true;
77
+ try {
78
+ await this.ready();
79
+ }
80
+ catch (error) {
81
+ try {
82
+ await this.flashStore.close();
83
+ }
84
+ catch (closeError) {
85
+ throw new AggregateError([error, closeError], 'Write and close failed');
86
+ }
87
+ throw error;
88
+ }
89
+ await this.flashStore.close();
90
+ }
91
+ /** Closes even on write failure; removes backing storage only after successful writes. */
92
+ async destroy() {
93
+ await this.close();
94
+ await this.flashStore.destroy();
95
+ }
96
+ /** Returns the current number of cached entries. */
97
+ get size() {
98
+ return this.cacheMap.size;
99
+ }
100
+ /** Identifies this object as a Map. */
101
+ get [Symbol.toStringTag]() {
102
+ return 'Map';
103
+ }
104
+ /** Iterates cached entries in insertion order. */
105
+ [Symbol.iterator]() {
106
+ return this.cacheMap[Symbol.iterator]();
107
+ }
108
+ /** Iterates cached entries in insertion order. */
109
+ entries() {
110
+ return this.cacheMap.entries();
111
+ }
112
+ /** Iterates cached keys in insertion order. */
113
+ keys() {
114
+ return this.cacheMap.keys();
115
+ }
116
+ /** Iterates cached values in insertion order. */
117
+ values() {
118
+ return this.cacheMap.values();
119
+ }
120
+ /** Clears the cache immediately and queues persistent removal. */
121
+ clear() {
122
+ this.enqueue(() => this.flashStore.clear());
123
+ if (this.loading)
124
+ this.clearedDuringLoad = true;
125
+ this.cacheMap.clear();
126
+ }
127
+ /** Removes a cached entry immediately and queues persistent removal. */
128
+ delete(key) {
129
+ validateKey(key);
130
+ this.enqueue(() => this.flashStore.delete(key));
131
+ if (this.loading)
132
+ this.touched.add(key);
133
+ return this.cacheMap.delete(key);
134
+ }
135
+ /** Invokes the callback for each cached entry. */
136
+ forEach(callbackfn, thisArg) {
137
+ for (const [key, value] of this.cacheMap)
138
+ callbackfn.call(thisArg, value, key, this);
139
+ }
140
+ /** Reads a cached value; await ready() first to include previously persisted data. */
141
+ get(key) {
142
+ return this.cacheMap.get(key);
143
+ }
144
+ /** Checks the cache; await ready() first to include previously persisted data. */
145
+ has(key) {
146
+ return this.cacheMap.has(key);
147
+ }
148
+ /** Returns a cached value or inserts and queues the supplied default. */
149
+ getOrInsert(key, defaultValue) {
150
+ if (this.cacheMap.has(key))
151
+ return this.cacheMap.get(key);
152
+ this.set(key, defaultValue);
153
+ return defaultValue;
154
+ }
155
+ /** Returns a cached value or computes, inserts, and queues a new value. */
156
+ getOrInsertComputed(key, callback) {
157
+ if (this.cacheMap.has(key))
158
+ return this.cacheMap.get(key);
159
+ const value = callback(key);
160
+ this.set(key, value);
161
+ return value;
162
+ }
163
+ /**
164
+ * Updates the cache immediately and queues an ordered persistent write of the
165
+ * value's JSON at call time. Throws without changes for invalid keys or values.
166
+ */
167
+ set(key, value) {
168
+ validateKey(key);
169
+ const serialized = serialize(value);
170
+ this.enqueue(() => writeSerialized(this.flashStore, key, serialized));
171
+ if (this.loading)
172
+ this.touched.add(key);
173
+ this.cacheMap.set(key, value);
174
+ return this;
175
+ }
176
+ }
177
+ //# sourceMappingURL=flash-store-sync-core.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flash-store-sync-core.js","sourceRoot":"","sources":["../../src/flash-store-sync-core.ts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,GAAG,CAAC,GAAG,CAAM,CAAA;QAC9D,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAA;QAC3B,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;QACpB,OAAO,KAAK,CAAA;IACd,CAAC;IAED;;;OAGG;IACH,GAAG,CAAC,GAAM,EAAE,KAAQ;QAClB,WAAW,CAAC,GAAG,CAAC,CAAA;QAChB,MAAM,UAAU,GAAG,SAAS,CAAC,KAAK,CAAC,CAAA;QACnC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC,CAAA;QACrE,IAAI,IAAI,CAAC,OAAO;YAAE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QACvC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;QAC7B,OAAO,IAAI,CAAA;IACb,CAAC;CACF"}
@@ -1,73 +1,12 @@
1
1
  /**
2
- * Provides a synchronous in-memory Map facade with ordered asynchronous write-back.
3
- * FlashStore owns persistence; ready() is the boundary for observing write failures.
4
- * Keys and values are validated and serialized when a mutation is accepted, so
5
- * invalid input throws synchronously and later object changes are not persisted.
2
+ * Binds the shared synchronous Map cache to the native LMDB-backed store.
6
3
  */
7
4
  import { type StoreKey } from './flash-store.ts';
8
- /**
9
- * In-memory Map backed by asynchronous LMDB writes.
10
- * Await ready() before reading restored data; detected write failures reject further mutations.
11
- * Restored entries follow LMDB key order rather than their original insertion order.
12
- */
13
- export declare class FlashStoreSync<K extends StoreKey = StoreKey, V = unknown> implements Map<K, V> {
14
- static VERSION: string;
15
- readonly workdir: string;
16
- private readonly cacheMap;
17
- private readonly flashStore;
18
- private readonly touched;
19
- private loading;
20
- private clearedDuringLoad;
21
- private pending;
22
- private closing;
23
- private failure?;
24
- /** Opens the backing store and starts restoring its cache. */
5
+ import { FlashStoreSyncCore } from './flash-store-sync-core.ts';
6
+ /** In-memory Map with ordered write-back to LMDB. */
7
+ export declare class FlashStoreSync<K extends StoreKey = StoreKey, V = unknown> extends FlashStoreSyncCore<K, V> {
8
+ /** Opens the backing path and starts restoring its cache. Await ready() before reading restored data. */
25
9
  constructor(workdir?: string);
26
- /** Restore untouched keys while immediate cache mutations remain authoritative. */
27
- private load;
28
- /** Serialize writes behind initialization; reject mutations after a detected failure. */
29
- private enqueue;
30
- /** Report background errors once while retaining the rejection for lifecycle calls. */
31
- private observeFailure;
32
- /** Returns the package version. */
33
- version(): string;
34
- /** Waits for initialization and writes queued before this call, rejecting on failure. */
35
- ready(): Promise<void>;
36
- /** Waits for writes and closes the backing store, preserving write and close failures. */
37
- close(): Promise<void>;
38
- /** Closes even on write failure; removes the directory only after successful writes. */
39
- destroy(): Promise<void>;
40
- /** Returns the current number of cached entries. */
41
- get size(): number;
42
- /** Identifies this object as a Map. */
43
- get [Symbol.toStringTag](): string;
44
- /** Iterates cached entries in insertion order. */
45
- [Symbol.iterator](): MapIterator<[K, V]>;
46
- /** Iterates cached entries in insertion order. */
47
- entries(): MapIterator<[K, V]>;
48
- /** Iterates cached keys in insertion order. */
49
- keys(): MapIterator<K>;
50
- /** Iterates cached values in insertion order. */
51
- values(): MapIterator<V>;
52
- /** Clears the cache immediately and queues persistent removal. */
53
- clear(): void;
54
- /** Removes a cached entry immediately and queues persistent removal. */
55
- delete(key: K): boolean;
56
- /** Invokes the callback for each cached entry. */
57
- forEach(callbackfn: (value: V, key: K, map: Map<K, V>) => void, thisArg?: unknown): void;
58
- /** Reads a cached value; await ready() first to include previously persisted data. */
59
- get(key: K): V | undefined;
60
- /** Checks the cache; await ready() first to include previously persisted data. */
61
- has(key: K): boolean;
62
- /** Returns a cached value or inserts and queues the supplied default. */
63
- getOrInsert(key: K, defaultValue: V): V;
64
- /** Returns a cached value or computes, inserts, and queues a new value. */
65
- getOrInsertComputed(key: K, callback: (key: K) => V): V;
66
- /**
67
- * Updates the cache immediately and queues an ordered persistent write of the
68
- * value's JSON at call time. Throws without changes for invalid keys or values.
69
- */
70
- set(key: K, value: V): this;
71
10
  }
72
11
  export default FlashStoreSync;
73
12
  //# sourceMappingURL=flash-store-sync.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"flash-store-sync.d.ts","sourceRoot":"","sources":["../../src/flash-store-sync.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAEL,KAAK,QAAQ,EAId,MAAM,kBAAkB,CAAA;AAEzB;;;;GAIG;AACH,qBAAa,cAAc,CAAC,CAAC,SAAS,QAAQ,GAAG,QAAQ,EAAE,CAAC,GAAG,OAAO,CACpE,YAAW,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC;IAEpB,MAAM,CAAC,OAAO,SAAqB;IACnC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAkB;IAC3C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAkB;IAC7C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAe;IACvC,OAAO,CAAC,OAAO,CAAO;IACtB,OAAO,CAAC,iBAAiB,CAAQ;IACjC,OAAO,CAAC,OAAO,CAAe;IAC9B,OAAO,CAAC,OAAO,CAAQ;IACvB,OAAO,CAAC,OAAO,CAAC,CAAoB;IAEpC,8DAA8D;IAC9D,YAAY,OAAO,SAAsB,EAMxC;IAED,mFAAmF;YACrE,IAAI;IAYlB,yFAAyF;IACzF,OAAO,CAAC,OAAO;IASf,uFAAuF;IACvF,OAAO,CAAC,cAAc;IAStB,mCAAmC;IACnC,OAAO,IAAI,MAAM,CAEhB;IAED,yFAAyF;IACnF,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAE3B;IAED,0FAA0F;IACpF,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAa3B;IAED,wFAAwF;IAClF,OAAO,IAAI,OAAO,CAAC,IAAI,C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