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
package/README.md CHANGED
@@ -13,13 +13,13 @@
13
13
  [![Downloads](http://img.shields.io/npm/dm/flash-store.svg?style=flat-square)](https://npmjs.org/package/flash-store)
14
14
  [![node](https://img.shields.io/node/v/flash-store.svg?maxAge=604800)](https://nodejs.org/)
15
15
 
16
- FlashStore is persistent key-value storage with asynchronous and synchronous Map-like APIs, powered by LMDB.
16
+ FlashStore provides persistent key-value storage with asynchronous and synchronous Map-like APIs. It uses LMDB in Node.js and Deno and IndexedDB in Chrome.
17
17
 
18
18
  ![flash store](https://huan.github.io/flash-store/images/flash-store.png)
19
19
 
20
20
  ## Requirements
21
21
 
22
- Node.js 26 or newer and npm 11 or newer. The npm package is ESM-only.
22
+ The npm package is ESM-only. For Node.js development use Node.js 26 and npm 11 or newer. For Deno use Deno 2.9.8 or newer with local `node_modules` and permission to load the LMDB native addon. Chrome uses its built-in IndexedDB.
23
23
 
24
24
  ## Examples
25
25
 
@@ -47,6 +47,62 @@ console.log(`key: 1, value: ${await flashStore.get(1)}`)
47
47
  await flashStore.close()
48
48
  ```
49
49
 
50
+ ### Deno
51
+
52
+ Install the package with `deno install --node-modules-dir=auto npm:flash-store`.
53
+ Use `import { FlashStore } from 'npm:flash-store'` and run the program with
54
+ `deno run --node-modules-dir=auto --allow-read --allow-write --allow-env --allow-ffi=./node_modules app.ts`.
55
+ Grant `--allow-sys=homedir` if the program calls `destroy()` so Flash Store
56
+ can check protected directories.
57
+
58
+ ### Chrome
59
+
60
+ A bundler that uses the `browser` export condition resolves
61
+ `import { FlashStore } from 'flash-store'` to IndexedDB. Use
62
+ `flash-store/browser` to select that entry explicitly. For a page that loads
63
+ modules directly, serve the installed package files and use an HTML import map
64
+ to resolve the entry and its two bare imports:
65
+
66
+ ```html
67
+ <script type="importmap">
68
+ {
69
+ "imports": {
70
+ "flash-store/browser": "/node_modules/flash-store/dist/src/browser.js",
71
+ "brolog": "/node_modules/brolog/dist/esm/src/mod.js"
72
+ }
73
+ }
74
+ </script>
75
+ ```
76
+
77
+ Serve the referenced JavaScript and the package's `dist/package.json` with
78
+ their JavaScript and JSON content types, respectively.
79
+
80
+ ```js
81
+ import { FlashStore, FlashStoreSync } from 'flash-store/browser'
82
+
83
+ const store = new FlashStore('app-cache')
84
+ await store.set('theme', 'dark')
85
+ await store.close()
86
+
87
+ const cache = new FlashStoreSync('app-cache')
88
+ await cache.ready()
89
+ console.log(cache.get('theme'))
90
+ await cache.close()
91
+ ```
92
+
93
+ The constructor takes a database name scoped to the current origin. Its
94
+ operations wait for IndexedDB to open. `destroy()` deletes that named database
95
+ and waits for other connections to release it. Flash Store connections close
96
+ when Chrome requests an upgrade or deletion. A handle closed by that event
97
+ rejects a later `destroy()`. Once you explicitly call `close()`, the handle
98
+ stops receiving database events. A later `destroy()` uses the database name,
99
+ which can refer to a replacement created by another tab. Call `destroy()`
100
+ directly on an open handle when you intend to remove its database.
101
+
102
+ A synchronous cache sees its own writes and the snapshot restored by `ready()`. If another tab changes
103
+ the database, reopen the cache to read the updated state. Browser data is
104
+ subject to site storage quotas and eviction.
105
+
50
106
  ## API Reference
51
107
 
52
108
  ### `FlashStore`
@@ -54,8 +110,10 @@ await flashStore.close()
54
110
  `FlashStore` provides async `set`, `get`, `has`, `delete`, `clear`, `forEach`,
55
111
  and `size`, plus async iteration through `entries`, `keys`, and `values`.
56
112
  Keys are finite numbers or strings without null characters; values use JSON
57
- serialization. Numeric keys sort naturally before strings. LMDB imposes a
58
- maximum encoded key size. See the [LMDB documentation](https://github.com/kriszyp/lmdb-js#keys).
113
+ serialization. Numeric keys sort naturally before strings. Both backends enforce the default LMDB limit of 1978 encoded bytes per key.
114
+ See the [LMDB documentation](https://github.com/kriszyp/lmdb-js#keys).
115
+ For arbitrary string identifiers in LMDB, encode embedded control characters and
116
+ unpaired UTF-16 surrogates before storing them as keys.
59
117
 
60
118
  Values are serialized with `JSON.stringify` and read back with `JSON.parse`.
61
119
  This is not a lossless round trip for every JavaScript value: for example,
@@ -65,7 +123,12 @@ objects, and `BigInt` cannot be stored. The TypeScript value type `V` is not
65
123
  validated against the decoded JSON, so it may not match the runtime value.
66
124
  Use JSON-compatible values and validate decoded data when its shape matters.
67
125
 
68
- Async iteration uses a snapshot in LMDB key order, not Map insertion order.
126
+ Async iteration uses a snapshot in key order. LMDB orders string keys by
127
+ UTF-8 bytes, whereas Chromium IndexedDB orders strings by native UTF-16 code
128
+ units. Chrome collects the matching records inside a single IndexedDB
129
+ transaction before yielding the first result, so its memory use grows with the
130
+ number of matches. For large datasets in browser environments, paginate
131
+ queries with `limit` and range bounds.
69
132
  `forEach` awaits each callback sequentially and stops on the first error,
70
133
  rejecting its returned promise. `FlashStoreSync.forEach` remains synchronous.
71
134
 
@@ -76,8 +139,10 @@ last match, so it does not read unrelated entries. `delete` resolves to whether
76
139
  a key existed.
77
140
 
78
141
  `close()` waits for outstanding writes. `destroy()` closes and **deletes the
79
- entire database directory**, so use a dedicated directory and never a shared
80
- directory. Both reject on failure.
142
+ entire database directory** under Node.js and Deno, so use a dedicated
143
+ directory. In Chrome it deletes the named IndexedDB database. After a
144
+ successful `destroy()`, another call on the same handle has no effect. Both
145
+ operations reject on failure.
81
146
 
82
147
  ### `FlashStoreSync`
83
148
 
@@ -91,28 +156,36 @@ observe write failures. After a detected write failure, further mutations throw;
91
156
  and reopen the store to recover. Mutations queued before the failure is detected
92
157
  may remain in the cache without being persisted. `close()` and `destroy()` wait
93
158
  for queued writes and close the database even on failure. `destroy()` removes
94
- the directory only if writes succeeded. Until `ready()` completes, reads and
159
+ the backing store only if writes succeeded. Until `ready()` completes, reads and
95
160
  delete return values only reflect the cache loaded so far.
96
161
 
97
162
  The cache iterates in its current insertion order, but reopening restores
98
- entries in LMDB key order rather than their original insertion order. Mutations
163
+ entries in storage key order. Mutations
99
164
  during restoration may also affect the cache order. The cache holds the values
100
165
  supplied to it; after reopening, values reflect the JSON round trip above.
101
166
 
102
167
  ## Diagnostics
103
168
 
104
- The `flash-store.operation` Node diagnostics channel publishes `{ operation }`
169
+ On Node.js and Deno the `flash-store.operation` diagnostics channel publishes `{ operation }`
105
170
  after successful `set`, `delete`, and `clear` operations. Messages contain no
106
171
  keys, values, or paths. The existing exported `log` remains available; its
107
172
  configured log level determines what application data it logs.
108
173
 
109
174
  ## Development
110
175
 
111
- Node executes TypeScript directly; `npm test` performs type-checking, Biome
112
- checks, and Node tests without building. `npm run test:deno` runs the same unit
113
- tests on Deno. `npm run coverage:node` and `npm run coverage:deno` enforce
114
- independently measured baselines and generate local reports. `npm run test:pack`
115
- builds the package and verifies it in an isolated npm consumer.
176
+ Node executes TypeScript directly. `npm test` runs type checking, Biome, and
177
+ the Node unit tests. The same unit test files run with
178
+ `npm run test:unit:deno` and `npm run test:unit:browser`. Install Chromium for
179
+ the browser suite with `npx playwright install chromium`.
180
+
181
+ `npm run test:integration` and `npm run test:integration:deno` exercise raw
182
+ LMDB and native diagnostics. `npm run coverage:node`, `npm run coverage:deno`,
183
+ and `npm run coverage:browser` enforce independent line, branch, and function
184
+ floors for each runtime adapter and shared sources. The coverage check fails if
185
+ an executable production file in that scope is absent from the runtime report.
186
+ CI uploads each runtime's LCOV and HTML reports. `npm run test:pack` verifies the installed package in Node,
187
+ Deno, and Chromium and checks consumer type resolution. The Chromium smoke
188
+ test covers both bundled and direct ESM loading.
116
189
 
117
190
  ### Benchmark
118
191
 
@@ -172,7 +245,7 @@ the benchmark CLI, its option validation, and temporary-directory cleanup.
172
245
 
173
246
  See the [documentation](https://huan.github.io/flash-store).
174
247
 
175
- * [ECMAScript 6: Maps - 2ality – JavaScript and more](http://2ality.com/2015/01/es6-maps-sets.html)
248
+ - [ECMAScript 6: Maps - 2ality – JavaScript and more](http://2ality.com/2015/01/es6-maps-sets.html)
176
249
 
177
250
  ## Version History
178
251
 
@@ -205,6 +278,6 @@ Long answer:
205
278
 
206
279
  ## Copyright & License
207
280
 
208
- * Code & Docs © 2017-now Huan Li \<huan@chatie.io\>
209
- * Code released under the Apache-2.0 License
210
- * Docs released under Creative Commons
281
+ - Code & Docs © 2017-now Huan Li \<huan@chatie.io\>
282
+ - Code released under the Apache-2.0 License
283
+ - Docs released under Creative Commons
package/dist/package.json CHANGED
@@ -1,64 +1,93 @@
1
1
  {
2
- "name": "flash-store",
3
- "version": "2.0.1",
4
- "description": "Persistent Map-like storage backed by LMDB.",
5
- "type": "module",
6
- "exports": {
7
- ".": {
8
- "types": "./dist/src/mod.d.ts",
9
- "import": "./dist/src/mod.js"
2
+ "name": "flash-store",
3
+ "version": "2.1.0",
4
+ "description": "Persistent Map-like storage for Node.js, Deno, and Chrome.",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "browser": {
9
+ "types": "./dist/src/browser.d.ts",
10
+ "import": "./dist/src/browser.js",
11
+ "default": "./dist/src/browser.js"
12
+ },
13
+ "types": "./dist/src/mod.d.ts",
14
+ "import": "./dist/src/mod.js"
15
+ },
16
+ "./browser": {
17
+ "types": "./dist/src/browser.d.ts",
18
+ "import": "./dist/src/browser.js",
19
+ "default": "./dist/src/browser.js"
20
+ }
21
+ },
22
+ "types": "./dist/src/mod.d.ts",
23
+ "engines": {
24
+ "node": ">=26",
25
+ "npm": ">=11"
26
+ },
27
+ "scripts": {
28
+ "build": "node scripts/prepare-package.ts && tsc",
29
+ "prepack": "npm run build",
30
+ "demo": "node example/demo.ts",
31
+ "benchmark": "node scripts/benchmark.ts",
32
+ "lint": "biome check src example scripts tests web-test-runner.config.js tsconfig.json package.json biome.json .github/coverage-baselines",
33
+ "typecheck": "tsc --noEmit",
34
+ "test": "npm run typecheck && npm run lint && npm run test:unit",
35
+ "test:unit": "node --test \"src/**/*.test.ts\"",
36
+ "test:deno": "npm run test:unit:deno",
37
+ "coverage:node": "node scripts/coverage.ts node",
38
+ "coverage:deno": "node scripts/coverage.ts deno",
39
+ "coverage:browser": "node scripts/coverage.ts browser",
40
+ "test:pack": "node scripts/pack-test.ts",
41
+ "test:unit:deno": "deno test --no-check --allow-read --allow-write --allow-env --allow-ffi --allow-sys=homedir src/",
42
+ "test:unit:browser": "wtr --config web-test-runner.config.js",
43
+ "test:integration": "node --test tests/native.integration.test.ts",
44
+ "test:integration:deno": "deno test --no-check --allow-read --allow-write --allow-env --allow-ffi --allow-sys=homedir tests/native.integration.test.ts"
45
+ },
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "git+https://github.com/huan/flash-store.git"
49
+ },
50
+ "keywords": [
51
+ "lmdb",
52
+ "nosql",
53
+ "database"
54
+ ],
55
+ "author": "Huan LI <zixia@zixia.net>",
56
+ "license": "Apache-2.0",
57
+ "bugs": {
58
+ "url": "https://github.com/huan/flash-store/issues"
59
+ },
60
+ "homepage": "https://github.com/huan/flash-store#readme",
61
+ "dependencies": {
62
+ "brolog": "^2.0.0",
63
+ "lmdb": "~3.5.9"
64
+ },
65
+ "devDependencies": {
66
+ "@biomejs/biome": "2.6.7",
67
+ "@types/chai": "^5.2.3",
68
+ "@types/node": "^26.6.6",
69
+ "@web/dev-server-esbuild": "^2.0.1",
70
+ "@web/test-runner": "^1.0.1",
71
+ "@web/test-runner-playwright": "^1.0.2",
72
+ "chai": "^6.3.0",
73
+ "esbuild": "^0.28.2",
74
+ "playwright": "^1.61.1",
75
+ "typescript": "^7.0.2"
76
+ },
77
+ "files": [
78
+ "dist/src/",
79
+ "!dist/src/**/*.test.*",
80
+ "!dist/src/**/test-fixture.*",
81
+ "dist/package.json"
82
+ ],
83
+ "publishConfig": {
84
+ "access": "public",
85
+ "tag": "next"
86
+ },
87
+ "imports": {
88
+ "#test-store": {
89
+ "browser": "./src/browser.ts",
90
+ "default": "./src/mod.ts"
91
+ }
10
92
  }
11
- },
12
- "types": "./dist/src/mod.d.ts",
13
- "engines": {
14
- "node": ">=26",
15
- "npm": ">=11"
16
- },
17
- "scripts": {
18
- "build": "tsc && node scripts/prepare-package.ts",
19
- "prepack": "npm run build",
20
- "demo": "node example/demo.ts",
21
- "benchmark": "node scripts/benchmark.ts",
22
- "lint": "biome check src example scripts tsconfig.json package.json biome.json coverage-baselines.json",
23
- "typecheck": "tsc --noEmit",
24
- "test": "npm run typecheck && npm run lint && npm run test:unit",
25
- "test:unit": "node --test src/*.test.ts",
26
- "test:deno": "deno test --no-check --allow-read --allow-write --allow-env --allow-ffi --allow-sys=homedir src/",
27
- "coverage:node": "node scripts/coverage.ts node",
28
- "coverage:deno": "node scripts/coverage.ts deno",
29
- "test:pack": "node scripts/pack-test.ts"
30
- },
31
- "repository": {
32
- "type": "git",
33
- "url": "git+https://github.com/huan/flash-store.git"
34
- },
35
- "keywords": [
36
- "lmdb",
37
- "nosql",
38
- "database"
39
- ],
40
- "author": "Huan LI <zixia@zixia.net>",
41
- "license": "Apache-2.0",
42
- "bugs": {
43
- "url": "https://github.com/huan/flash-store/issues"
44
- },
45
- "homepage": "https://github.com/huan/flash-store#readme",
46
- "dependencies": {
47
- "brolog": "^1.14.2",
48
- "lmdb": "~3.5.9"
49
- },
50
- "devDependencies": {
51
- "@biomejs/biome": "2.6.7",
52
- "@types/node": "^26.6.6",
53
- "typescript": "^7.0.2"
54
- },
55
- "files": [
56
- "dist/src/",
57
- "!dist/src/*.test.*",
58
- "dist/package.json"
59
- ],
60
- "publishConfig": {
61
- "access": "public",
62
- "tag": "next"
63
- }
64
93
  }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Public browser entry. The Map facades share behavior with the native
3
+ * constructors and bind to an origin-scoped IndexedDB database here.
4
+ */
5
+ import { FlashStoreCore, type StoreKey } from './flash-store-core.ts';
6
+ import { FlashStoreSyncCore } from './flash-store-sync-core.ts';
7
+ export { log, VERSION } from './config.ts';
8
+ export type { IteratorOptions, StoreKey } from './flash-store-core.ts';
9
+ /** Persistent Map backed by IndexedDB with JSON-serialized values. */
10
+ export declare class FlashStore<K extends StoreKey = StoreKey, V = unknown> extends FlashStoreCore<K, V> {
11
+ /** Starts opening the database. Each operation waits for it to be ready. */
12
+ constructor(name: string);
13
+ }
14
+ /** In-memory Map with ordered write-back to IndexedDB. */
15
+ export declare class FlashStoreSync<K extends StoreKey = StoreKey, V = unknown> extends FlashStoreSyncCore<K, V> {
16
+ /** Starts restoring the named database. Await ready() before reading restored data. */
17
+ constructor(name?: string);
18
+ }
19
+ export default FlashStore;
20
+ //# sourceMappingURL=browser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../src/browser.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,cAAc,EAAE,KAAK,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAG/D,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAC1C,YAAY,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAEtE,sEAAsE;AACtE,qBAAa,UAAU,CACrB,CAAC,SAAS,QAAQ,GAAG,QAAQ,EAC7B,CAAC,GAAG,OAAO,CACX,SAAQ,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC;IAC5B,4EAA4E;IAC5E,YAAY,IAAI,EAAE,MAAM,EAEvB;CACF;AAED,0DAA0D;AAC1D,qBAAa,cAAc,CACzB,CAAC,SAAS,QAAQ,GAAG,QAAQ,EAC7B,CAAC,GAAG,OAAO,CACX,SAAQ,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC;IAChC,uFAAuF;IACvF,YAAY,IAAI,SAAsB,EAErC;CACF;eAEc,UAAU"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Public browser entry. The Map facades share behavior with the native
3
+ * constructors and bind to an origin-scoped IndexedDB database here.
4
+ */
5
+ import { FlashStoreCore } from './flash-store-core.js';
6
+ import { FlashStoreSyncCore } from './flash-store-sync-core.js';
7
+ import { IndexedDbBackend } from './indexeddb-backend.js';
8
+ export { log, VERSION } from './config.js';
9
+ /** Persistent Map backed by IndexedDB with JSON-serialized values. */
10
+ export class FlashStore extends FlashStoreCore {
11
+ /** Starts opening the database. Each operation waits for it to be ready. */
12
+ constructor(name) {
13
+ super(name, new IndexedDbBackend(name));
14
+ }
15
+ }
16
+ /** In-memory Map with ordered write-back to IndexedDB. */
17
+ export class FlashStoreSync extends FlashStoreSyncCore {
18
+ /** Starts restoring the named database. Await ready() before reading restored data. */
19
+ constructor(name = '.flash-store-sync') {
20
+ super(name, new FlashStore(name));
21
+ }
22
+ }
23
+ export default FlashStore;
24
+ //# sourceMappingURL=browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.js","sourceRoot":"","sources":["../../src/browser.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,cAAc,EAAiB,MAAM,uBAAuB,CAAA;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAEzD,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAG1C,sEAAsE;AACtE,MAAM,OAAO,UAGX,SAAQ,cAAoB;IAC5B,4EAA4E;IAC5E,YAAY,IAAY;QACtB,KAAK,CAAC,IAAI,EAAE,IAAI,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAA;IACzC,CAAC;CACF;AAED,0DAA0D;AAC1D,MAAM,OAAO,cAGX,SAAQ,kBAAwB;IAChC,uFAAuF;IACvF,YAAY,IAAI,GAAG,mBAAmB;QACpC,KAAK,CAAC,IAAI,EAAE,IAAI,UAAU,CAAO,IAAI,CAAC,CAAC,CAAA;IACzC,CAAC;CACF;AAED,eAAe,UAAU,CAAA"}
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Shares the published package identity and public logger across runtime
3
+ * entry points. TypeScript emits the imported manifest during packaging.
4
+ */
1
5
  import { log } from 'brolog';
2
6
  declare const VERSION: string;
3
7
  export { log, VERSION };
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AAa5B,QAAA,MAAM,OAAO,QAAsB,CAAA;AAEnC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,CAAA"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AAG5B,QAAA,MAAM,OAAO,QAAmB,CAAA;AAEhC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,CAAA"}
@@ -1,16 +1,9 @@
1
1
  /**
2
- * Shares package identity and the existing public logger between both store APIs.
3
- * The manifest is copied beside the compiled source during package emission.
2
+ * Shares the published package identity and public logger across runtime
3
+ * entry points. TypeScript emits the imported manifest during packaging.
4
4
  */
5
- import { readFileSync } from 'node:fs';
6
5
  import { log } from 'brolog';
7
- const packageJson = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
8
- if (typeof packageJson !== 'object' ||
9
- packageJson === null ||
10
- !('version' in packageJson) ||
11
- typeof packageJson.version !== 'string') {
12
- throw new Error('Package manifest does not contain a version');
13
- }
14
- const VERSION = packageJson.version;
6
+ import manifest from '../package.json' with { type: 'json' };
7
+ const VERSION = manifest.version;
15
8
  export { log, VERSION };
16
9
  //# sourceMappingURL=config.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AAE5B,MAAM,WAAW,GAAY,IAAI,CAAC,KAAK,CACrC,YAAY,CAAC,IAAI,GAAG,CAAC,iBAAiB,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CAClE,CAAA;AACD,IACE,OAAO,WAAW,KAAK,QAAQ;IAC/B,WAAW,KAAK,IAAI;IACpB,CAAC,CAAC,SAAS,IAAI,WAAW,CAAC;IAC3B,OAAO,WAAW,CAAC,OAAO,KAAK,QAAQ,EACvC,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAA;AAChE,CAAC;AACD,MAAM,OAAO,GAAG,WAAW,CAAC,OAAO,CAAA;AAEnC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,CAAA"}
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AAC5B,OAAO,QAAQ,MAAM,iBAAiB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAA;AAE5D,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAA;AAEhC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,CAAA"}
@@ -0,0 +1,65 @@
1
+ import type { StoreBackend } from './store-backend.ts';
2
+ /** Numbers precede strings in storage key order. */
3
+ export type StoreKey = string | number;
4
+ /** Bounds and ordering for a range of keys. Prefix is restricted to string keys. */
5
+ export interface IteratorOptions<K extends StoreKey = StoreKey> {
6
+ gt?: K;
7
+ gte?: K;
8
+ lt?: K;
9
+ lte?: K;
10
+ reverse?: boolean;
11
+ limit?: number;
12
+ prefix?: string;
13
+ }
14
+ /** Reject keys outside the serialized storage contract. */
15
+ export declare function validateKey(key: StoreKey): void;
16
+ /** Serialize a value once, rejecting values that JSON cannot represent. */
17
+ export declare function serialize(value: unknown): string;
18
+ /**
19
+ * Writes pre-serialized JSON for FlashStoreSync, which serializes at call time.
20
+ * Used by the shared synchronous cache, outside the public package entries.
21
+ */
22
+ export declare let writeSerialized: <K extends StoreKey>(store: FlashStoreCore<K, unknown>, key: K, serialized: string) => Promise<void>;
23
+ /** Shared Map API for the installed runtime-specific entries. */
24
+ export declare class FlashStoreCore<K extends StoreKey, V> {
25
+ static VERSION: string;
26
+ readonly workdir: string;
27
+ private readonly backend;
28
+ private closePromise?;
29
+ private destroyPromise?;
30
+ /** Binds a storage backend and exposes its location through the public workdir property. */
31
+ protected constructor(workdir: string, backend: StoreBackend, requested?: string);
32
+ /** Returns the package version. */
33
+ version(): string;
34
+ /** Stores a JSON-serializable value and resolves after its write completes. */
35
+ set(key: K, value: V): Promise<this>;
36
+ /** Writes validated, serialized JSON and publishes the set event on success. */
37
+ private write;
38
+ /** Returns the stored value, or undefined when the key is absent. */
39
+ get(key: K): Promise<V | undefined>;
40
+ /** Returns whether the key exists, including when its value is falsey. */
41
+ has(key: K): Promise<boolean>;
42
+ /** Deletes a key and reports whether an entry existed. */
43
+ delete(key: K): Promise<boolean>;
44
+ /** Removes every entry after queued writes. */
45
+ clear(): Promise<void>;
46
+ /** Starts counting immediately and resolves to the size of that read snapshot. */
47
+ get size(): Promise<number>;
48
+ /** Iterates a snapshot in storage key order and releases it on early exit. */
49
+ entries(options?: IteratorOptions<K>): AsyncIterableIterator<[K, V]>;
50
+ /** Iterates keys with the same range semantics as entries(). */
51
+ keys(options?: IteratorOptions<K>): AsyncIterableIterator<K>;
52
+ /** Iterates values with the same range semantics as entries(). */
53
+ values(options?: IteratorOptions<K>): AsyncIterableIterator<V>;
54
+ /** Returns the asynchronous entries iterator. */
55
+ [Symbol.asyncIterator](): AsyncIterableIterator<[K, V]>;
56
+ /** Awaits each callback in snapshot key order; stops and rejects on the first failure. */
57
+ forEach(callback: (value: V, key: K, store: this) => unknown, thisArg?: unknown): Promise<void>;
58
+ /** Closes the database after outstanding writes; repeated calls are safe. */
59
+ close(): Promise<void>;
60
+ /** Closes this handle and removes its backing storage once. Failed removals can be retried. */
61
+ destroy(): Promise<void>;
62
+ /** Releases the handle before removal and leaves failures available for retry. */
63
+ private removeStorage;
64
+ }
65
+ //# sourceMappingURL=flash-store-core.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fl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