flash-store 1.3.5 → 2.0.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.
Files changed (101) hide show
  1. package/README.md +124 -157
  2. package/dist/package.json +64 -0
  3. package/dist/src/config.d.ts +4 -0
  4. package/dist/src/config.d.ts.map +1 -0
  5. package/dist/src/config.js +16 -0
  6. package/dist/src/config.js.map +1 -0
  7. package/dist/src/flash-store-sync.d.ts +73 -0
  8. package/dist/src/flash-store-sync.d.ts.map +1 -0
  9. package/dist/src/flash-store-sync.js +178 -0
  10. package/dist/src/flash-store-sync.js.map +1 -0
  11. package/dist/src/flash-store.d.ts +69 -0
  12. package/dist/src/flash-store.d.ts.map +1 -0
  13. package/dist/src/flash-store.js +246 -0
  14. package/dist/src/flash-store.js.map +1 -0
  15. package/dist/src/mod.d.ts +10 -0
  16. package/dist/src/mod.d.ts.map +1 -0
  17. package/dist/src/mod.js +9 -0
  18. package/dist/src/mod.js.map +1 -0
  19. package/package.json +29 -52
  20. package/dist/cjs/package.json +0 -3
  21. package/dist/cjs/src/config.d.ts +0 -4
  22. package/dist/cjs/src/config.d.ts.map +0 -1
  23. package/dist/cjs/src/config.js +0 -9
  24. package/dist/cjs/src/config.js.map +0 -1
  25. package/dist/cjs/src/flash-store-sync.d.ts +0 -44
  26. package/dist/cjs/src/flash-store-sync.d.ts.map +0 -1
  27. package/dist/cjs/src/flash-store-sync.js +0 -118
  28. package/dist/cjs/src/flash-store-sync.js.map +0 -1
  29. package/dist/cjs/src/flash-store-sync.spec.d.ts +0 -3
  30. package/dist/cjs/src/flash-store-sync.spec.d.ts.map +0 -1
  31. package/dist/cjs/src/flash-store-sync.spec.js +0 -131
  32. package/dist/cjs/src/flash-store-sync.spec.js.map +0 -1
  33. package/dist/cjs/src/flash-store.d.ts +0 -124
  34. package/dist/cjs/src/flash-store.d.ts.map +0 -1
  35. package/dist/cjs/src/flash-store.js +0 -298
  36. package/dist/cjs/src/flash-store.js.map +0 -1
  37. package/dist/cjs/src/flash-store.spec.d.ts +0 -3
  38. package/dist/cjs/src/flash-store.spec.d.ts.map +0 -1
  39. package/dist/cjs/src/flash-store.spec.js +0 -155
  40. package/dist/cjs/src/flash-store.spec.js.map +0 -1
  41. package/dist/cjs/src/mod.d.ts +0 -6
  42. package/dist/cjs/src/mod.d.ts.map +0 -1
  43. package/dist/cjs/src/mod.js +0 -12
  44. package/dist/cjs/src/mod.js.map +0 -1
  45. package/dist/cjs/src/package-json.d.ts +0 -6
  46. package/dist/cjs/src/package-json.d.ts.map +0 -1
  47. package/dist/cjs/src/package-json.js +0 -91
  48. package/dist/cjs/src/package-json.js.map +0 -1
  49. package/dist/cjs/src/package-json.spec.d.ts +0 -3
  50. package/dist/cjs/src/package-json.spec.d.ts.map +0 -1
  51. package/dist/cjs/src/package-json.spec.js +0 -10
  52. package/dist/cjs/src/package-json.spec.js.map +0 -1
  53. package/dist/cjs/tests/integration.spec.d.ts +0 -3
  54. package/dist/cjs/tests/integration.spec.d.ts.map +0 -1
  55. package/dist/cjs/tests/integration.spec.js +0 -8
  56. package/dist/cjs/tests/integration.spec.js.map +0 -1
  57. package/dist/esm/src/config.d.ts +0 -4
  58. package/dist/esm/src/config.d.ts.map +0 -1
  59. package/dist/esm/src/config.js +0 -6
  60. package/dist/esm/src/config.js.map +0 -1
  61. package/dist/esm/src/flash-store-sync.d.ts +0 -44
  62. package/dist/esm/src/flash-store-sync.d.ts.map +0 -1
  63. package/dist/esm/src/flash-store-sync.js +0 -111
  64. package/dist/esm/src/flash-store-sync.js.map +0 -1
  65. package/dist/esm/src/flash-store-sync.spec.d.ts +0 -3
  66. package/dist/esm/src/flash-store-sync.spec.d.ts.map +0 -1
  67. package/dist/esm/src/flash-store-sync.spec.js +0 -126
  68. package/dist/esm/src/flash-store-sync.spec.js.map +0 -1
  69. package/dist/esm/src/flash-store.d.ts +0 -124
  70. package/dist/esm/src/flash-store.d.ts.map +0 -1
  71. package/dist/esm/src/flash-store.js +0 -291
  72. package/dist/esm/src/flash-store.js.map +0 -1
  73. package/dist/esm/src/flash-store.spec.d.ts +0 -3
  74. package/dist/esm/src/flash-store.spec.d.ts.map +0 -1
  75. package/dist/esm/src/flash-store.spec.js +0 -150
  76. package/dist/esm/src/flash-store.spec.js.map +0 -1
  77. package/dist/esm/src/mod.d.ts +0 -6
  78. package/dist/esm/src/mod.d.ts.map +0 -1
  79. package/dist/esm/src/mod.js +0 -6
  80. package/dist/esm/src/mod.js.map +0 -1
  81. package/dist/esm/src/package-json.d.ts +0 -6
  82. package/dist/esm/src/package-json.d.ts.map +0 -1
  83. package/dist/esm/src/package-json.js +0 -88
  84. package/dist/esm/src/package-json.js.map +0 -1
  85. package/dist/esm/src/package-json.spec.d.ts +0 -3
  86. package/dist/esm/src/package-json.spec.d.ts.map +0 -1
  87. package/dist/esm/src/package-json.spec.js +0 -8
  88. package/dist/esm/src/package-json.spec.js.map +0 -1
  89. package/dist/esm/tests/integration.spec.d.ts +0 -3
  90. package/dist/esm/tests/integration.spec.d.ts.map +0 -1
  91. package/dist/esm/tests/integration.spec.js +0 -6
  92. package/dist/esm/tests/integration.spec.js.map +0 -1
  93. package/src/config.ts +0 -12
  94. package/src/flash-store-sync.spec.ts +0 -158
  95. package/src/flash-store-sync.ts +0 -163
  96. package/src/flash-store.spec.ts +0 -197
  97. package/src/flash-store.ts +0 -371
  98. package/src/mod.ts +0 -18
  99. package/src/package-json.spec.ts +0 -10
  100. package/src/package-json.ts +0 -91
  101. package/src/typings.d.ts +0 -0
package/README.md CHANGED
@@ -2,9 +2,7 @@
2
2
 
3
3
  <!-- markdownlint-disable MD013 -->
4
4
 
5
- [![Powered by SQLite](https://img.shields.io/badge/Powered%20By-SQLite-green.svg)](https://https://www.sqlite.org/)
6
- [![Powered by LevelDB](https://img.shields.io/badge/Powered%20By-LevelDB-green.svg)](https://leveldb.org/)
7
- [![Powered by RocksDB](https://img.shields.io/badge/Powered%20By-RocksDB-green.svg)](https://rocksdb.org/)
5
+ [![Powered by LMDB](https://img.shields.io/badge/Powered%20By-LMDB-green.svg)](https://github.com/kriszyp/lmdb-js)
8
6
  [![Powered by TypeScript](https://img.shields.io/badge/Powered%20By-TypeScript-blue.svg)](https://www.typescriptlang.org/)
9
7
  [![ES Modules](https://img.shields.io/badge/ES-Modules-brightgreen)](https://github.com/Chatie/tsconfig/issues/16)
10
8
 
@@ -15,13 +13,13 @@
15
13
  [![Downloads](http://img.shields.io/npm/dm/flash-store.svg?style=flat-square)](https://npmjs.org/package/flash-store)
16
14
  [![node](https://img.shields.io/node/v/flash-store.svg?maxAge=604800)](https://nodejs.org/)
17
15
 
18
- FlashStore is Key-Value persistent storage with easy to use ES6 Map-like API(both Async and Sync support), powered by LevelDB and TypeScript.
16
+ FlashStore is persistent key-value storage with asynchronous and synchronous Map-like APIs, powered by LMDB.
19
17
 
20
18
  ![flash store](https://huan.github.io/flash-store/images/flash-store.png)
21
19
 
22
20
  ## Requirements
23
21
 
24
- 1. Node.js v10 or above
22
+ Node.js 26 or newer and npm 11 or newer. The npm package is ESM-only.
25
23
 
26
24
  ## Examples
27
25
 
@@ -43,175 +41,144 @@ await flashStore.set(1, 'a')
43
41
  console.log(`key: 1, value: ${await flashStore.get(1)}`)
44
42
  // Output: 'a'
45
43
 
46
- await flashStore.del(1)
44
+ await flashStore.delete(1)
47
45
  console.log(`key: 1, value: ${await flashStore.get(1)}`)
48
46
  // Output: undefined
47
+ await flashStore.close()
49
48
  ```
50
49
 
51
- ## Supported Backend
52
-
53
- | Backend | Flash Store | Install NPM Command |
54
- | :--- | :--- | :--- |
55
- | LevelDB |v1.0 | `npm install flash-store@1` |
56
- | SQLite | v0.20 | `npm install flash-store@0.20` |
57
- | Medea | v0.18 | ~~npm install flash-store@0.18~~ (deprecated) |
58
- | SnapDB | v0.16 | ~~npm install flash-store@0.16~~ (deprecated) |
59
- | RocksDB | v0.14 | `npm install flash-store@0.14` |
60
- | LevelDB |v0.12 | `npm install flash-store@0.12` |
61
-
62
- > SnapDB & Medea were all deprecated because of lots of unknown bugs.
63
-
64
50
  ## API Reference
65
51
 
66
52
  ### `FlashStore`
67
53
 
68
- FlashStore implements the Standard ES6 Map API with Async modification, powered by [async-map-like](https://github.com/huan/async-map-like)
69
-
70
- ```ts
71
- /**
72
- * ES6 Map API with Async
73
- */
74
- export interface AsyncMap<K = any, V = any> {
75
- [Symbol.asyncIterator]() : AsyncIterableIterator<[K, V]>
76
- size : Promise<number>
77
-
78
- clear () : Promise<void>
79
- delete (key: K) : Promise<void>
80
- entries() : AsyncIterableIterator<[K, V]>
81
- get (key: K) : Promise<V | undefined>
82
- has (key: K) : Promise<boolean>
83
- keys () : AsyncIterableIterator<K>
84
- set (key: K, value: V) : Promise<void>
85
- values () : AsyncIterableIterator<V>
86
- }
87
-
88
- class FlashStore<K, V> implements AsyncMap<K, V> {}
89
- ```
54
+ `FlashStore` provides async `set`, `get`, `has`, `delete`, `clear`, `forEach`,
55
+ and `size`, plus async iteration through `entries`, `keys`, and `values`.
56
+ 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).
59
+
60
+ Values are serialized with `JSON.stringify` and read back with `JSON.parse`.
61
+ This is not a lossless round trip for every JavaScript value: for example,
62
+ `Date` becomes a string, `NaN` and infinities become `null`, and properties
63
+ whose values are `undefined` are omitted. Top-level `undefined`, circular
64
+ objects, and `BigInt` cannot be stored. The TypeScript value type `V` is not
65
+ validated against the decoded JSON, so it may not match the runtime value.
66
+ Use JSON-compatible values and validate decoded data when its shape matters.
67
+
68
+ Async iteration uses a snapshot in LMDB key order, not Map insertion order.
69
+ `forEach` awaits each callback sequentially and stops on the first error,
70
+ rejecting its returned promise. `FlashStoreSync.forEach` remains synchronous.
71
+
72
+ Iteration accepts `gt`, `gte`, `lt`, `lte`, `reverse`, `limit`, or a string
73
+ `prefix`. Do not combine a prefix with range bounds, or two bounds on the same
74
+ side. A prefix scan seeks directly to matching string keys and stops after the
75
+ last match, so it does not read unrelated entries. `delete` resolves to whether
76
+ a key existed.
77
+
78
+ `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.
90
81
 
91
82
  ### `FlashStoreSync`
92
83
 
93
- FlashStoreSync implements the Standard ES6 Map API:
94
-
95
- ```ts
96
- class FlashStoreSync<K, V> implements Map<K, V> {}
97
- ```
98
-
99
- 1. You get a sync API at the cost of all your data have to be kept in memory.
100
- 1. The data will be async writing back to disk for persistent storage in background.
101
- 1. The performance of `FlashStoreSync` can be expected high because it's all in memory.
84
+ `FlashStoreSync` maintains a full in-memory Map and writes changes in order in
85
+ the background. `set()` and `delete()` validate keys, and `set()` serializes
86
+ the value immediately: invalid keys or non-JSON values throw without changing
87
+ the cache, and later changes to a stored object are not persisted unless it is
88
+ set again. The cache still holds the original object, so it reflects such
89
+ changes until reopened. Await `ready()` before reading restored data and to
90
+ observe write failures. After a detected write failure, further mutations throw; close
91
+ and reopen the store to recover. Mutations queued before the failure is detected
92
+ may remain in the cache without being persisted. `close()` and `destroy()` wait
93
+ for queued writes and close the database even on failure. `destroy()` removes
94
+ the directory only if writes succeeded. Until `ready()` completes, reads and
95
+ delete return values only reflect the cache loaded so far.
96
+
97
+ The cache iterates in its current insertion order, but reopening restores
98
+ entries in LMDB key order rather than their original insertion order. Mutations
99
+ during restoration may also affect the cache order. The cache holds the values
100
+ supplied to it; after reopening, values reflect the JSON round trip above.
101
+
102
+ ## Diagnostics
103
+
104
+ The `flash-store.operation` Node diagnostics channel publishes `{ operation }`
105
+ after successful `set`, `delete`, and `clear` operations. Messages contain no
106
+ keys, values, or paths. The existing exported `log` remains available; its
107
+ configured log level determines what application data it logs.
108
+
109
+ ## Development
110
+
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.
116
+
117
+ ### Benchmark
118
+
119
+ Run `npm run benchmark` to compare FlashStore's public API with native LMDB
120
+ using 5,000 entries and six paired trials. For example:
121
+ `npm run benchmark -- --count 10000 --duration 500 --trials 6 --dir /path/to/disk --memory-dir /dev/shm`.
122
+ Duration is the minimum sample length in milliseconds.
123
+
124
+ The report has three tables:
125
+
126
+ - **API overhead** runs on memory-backed storage (`/dev/shm` by default on
127
+ Linux) so fsync latency does not hide per-call costs. It measures seeded
128
+ random reads, ordered iteration, and inserts and deletes, sequentially and
129
+ in batches of 32. Reads and scans give every variant the same calibrated
130
+ pass count; mutations repeat insert-then-delete cycles of 50 or 256 absent
131
+ keys until each phase lasts at least `--duration`.
132
+ - **Diagnostics** add one FlashStore behavior to native LMDB: an async call
133
+ per read, an async generator per scanned entry, or the conditional
134
+ `remove(key, IF_EXISTS)` that lets `delete()` report whether a key existed
135
+ (a plain `remove()` resolves true even for absent keys). When a variant's
136
+ ratio matches FlashStore's, that behavior explains the overhead. Each row
137
+ also shows FlashStore and native LMDB throughput from the same trials.
138
+ - **Durable mutations** run on `--dir` (the OS temporary directory by
139
+ default) with fixed samples: 50 sequential and 256 batched inserts and
140
+ deletes. Commit latency usually dominates, so similar numbers are expected.
141
+
142
+ When `/dev/shm` is unavailable, the memory mode is skipped; pass
143
+ `--memory-dir` to choose another existing directory or `--no-memory` to skip
144
+ it. The filesystem type is reported, and only tmpfs or ramfs is labeled as
145
+ memory-backed. The memory mode checks free space first; lower `--count` for
146
+ small memory filesystems.
147
+
148
+ Both engines use identical JSON bytes, default durability, and fresh
149
+ databases preloaded in an untimed transaction. FlashStore uses its public
150
+ async API; LMDB uses synchronous `get()`/`getRange()`, JSON decoding,
151
+ asynchronous `put()`, and native `remove()`. This compares usable public APIs,
152
+ not identical internal algorithms. Reads and scans are warm-cache
153
+ measurements, not cold-storage performance. The first trial warms up and
154
+ calibrates reads and scans; each mutation measurement has an untimed warm-up. Full contents and entry
155
+ counts are validated outside timing; timed reads and scans consume an
156
+ identical checksum, checked afterward.
157
+
158
+ The output shows median operations/second, reciprocal microseconds/operation
159
+ (not latency percentiles), trial ranges, and all sample sizes and durations.
160
+ Variants alternate order between trials. Ratios are medians of per-trial
161
+ paired ratios. Paired ranges crossing 1 are labeled mixed/tied; ranges are
162
+ descriptive, not confidence intervals. With 5,000 cached entries, ratios are
163
+ close to worst-case overhead; larger datasets spend more time in LMDB.
164
+
165
+ Temporary databases are removed after each trial. Results depend on the
166
+ machine and filesystem; there are no CI performance thresholds. The default
167
+ workload targets less than a minute on the test machine, not on every
168
+ filesystem. Run `node --test scripts/benchmark.integration.test.ts` to check
169
+ the benchmark CLI, its option validation, and temporary-directory cleanup.
102
170
 
103
171
  ## Document
104
172
 
105
- See [auto generated docs](https://huan.github.io/flash-store)
173
+ See the [documentation](https://huan.github.io/flash-store).
106
174
 
107
175
  * [ECMAScript 6: Maps - 2ality – JavaScript and more](http://2ality.com/2015/01/es6-maps-sets.html)
108
176
 
109
- ## See Also
110
-
111
- 1. [Node.js databases: an embedded database using LevelDB](https://blog.yld.io/2016/10/24/node-js-databases-an-embedded-database-using-leveldb)
112
- 2. [How to Cook a Graph Database in a Night - LevelGraph](http://nodejsconfit.levelgraph.io/)
113
- 3. [Graph database JS style for Node.js and the Browser. Built upon LevelUp and LevelDB.](https://github.com/levelgraph/levelgraph)
114
- 4. [浅析 BigTable 和 LevelDB 的实现](http://draveness.me/bigtable-leveldb.html)
115
-
116
- ## Known Issues
117
-
118
- 1. The `gte` and `lte` in `options` do not work property. ([#4](https://github.com/huan/flash-store/issues/4))
119
-
120
177
  ## Version History
121
178
 
122
- ### master v1.3 (Sep 12, 2021)
123
-
124
- 1. ES Modules support ([#93](https://github.com/huan/flash-store/pull/93))
125
- 1. Remove default `workdir` in `FlashStore` constructor.
126
-
127
- ### v1.0 (Aug 16, 2021) LevelDB v7.0
128
-
129
- [![Powered by LevelDB](https://img.shields.io/badge/Powered%20By-LevelDB-green.svg)](https://www.npmjs.com/package/level)
130
-
131
- LevelDB v7.0.0 support.
132
-
133
- ### v0.20 Apr 2020 SQLite as Backend
134
-
135
- 1. We hardcoded the key type to be `string` only in this version.
136
- 1. We decide to try [better-sqlite3](https://www.npmjs.com/package/better-sqlite3) as it claim is very fast.
137
- 1. The other alternates (would love to try in the future if necessary):
138
- 1. TypeScript: [sqlite](https://www.npmjs.com/package/sqlite)
139
- 1. WebAssembly: [sql.js](https://www.npmjs.com/package/sql.js)
140
-
141
- ### ~~v0.18 Feb 2019 - Medea as Backend~~
142
-
143
- [![Powered by Medea](https://img.shields.io/badge/Powered%20By-Medea-green.svg)](https://www.npmjs.com/package/medeadown)
144
-
145
- DEPRECATED: Due to [#79](https://github.com/huan/flash-store/issues/79) [#74](https://github.com/huan/flash-store/issues/74) and also it is very unstable in production as my experiences. (e.g. memory leak & block event loop)
146
-
147
- 1. Switch from SnapDB to [MedeaDown](https://github.com/medea/medeadown)
148
-
149
- [Medea](https://github.com/medea/medea) is a persistent key-value storage library that runs everywhere Node runs.
150
-
151
- > "It is a pure JS implementation of leveldown and it's almost as fast."
152
- > &mdash; @Raynos [link](https://github.com/medea/medeadown/issues/2#issue-38431966)
153
- >
154
- > "The LevelDOWN-compatible wrapper for Medea really opens up the possibility to reuse the modules that have already been created around the LevelUP ecosystem."
155
- > &mdash; @kevinswiber [link](https://github.com/medea/medeadown/issues/2#issuecomment-49785861)
156
-
157
- Known Issues: [FlashStore 会写满磁盘的问题 #155](https://github.com/wechaty/wechaty-puppet-padplus/issues/155)
158
-
159
- ```ts
160
- async function compact (store: FlashStore): Promise<void> {
161
- await store.size
162
- const db = (store as any).levelDb.db.db.db
163
- await new Promise((resolve, reject) => {
164
- db.compact((err: any) => {
165
- if (err) {
166
- return reject(err)
167
- }
168
- resolve()
169
- })
170
- })
171
- }
172
- ```
173
-
174
- ### v0.16 May 2019 - SnapDB as Backend
175
-
176
- [![Powered by SnapDB](https://img.shields.io/badge/Powered%20By-SnapDB-green.svg)](https://www.npmjs.com/package/snap-db)
177
-
178
- 1. Switch from RocksDB to [SnapDB](https://github.com/ClickSimply/snap-db) [#45](https://github.com/huan/flash-store/issues/45)
179
- 1. [#50](https://github.com/huan/flash-store/issues/50) has been fixed. ~~WARN: Do not use this version because it has known issues~~
180
-
181
- ### v0.14 May 2019 - RocksDB as Backend
182
-
183
- 1. Switch from LevelDB to [RocksDB](https://www.npmjs.com/package/rocksdb) [#34](https://github.com/huan/flash-store/issues/34)
184
-
185
- ### v0.12 Jan 2019 - LevelDB as Backend
186
-
187
- 1. Use [LevelDB](https://github.com/level/leveldown) as backend to skip the compiling when install.
188
- 1. Using leveldb official typings from `@types/`
189
-
190
- ### v0.7 Aug 2018 - Nosql-LevelDB as Backend
191
-
192
- 1. Use [nosql-leveldb](https://github.com/snowyu/node-nosql-leveldb) as backend to prevent segfault.
193
-
194
- ### v0.6 Jul 2018
195
-
196
- 1. Upgrade to TypeScript 3.0
197
-
198
- ### v0.4 Jun 2018
199
-
200
- #### 1. Refactor API to implement ES6 `Map` interface
201
-
202
- 1. Update the API to ES6 `Map`-like, the difference is that FlashStore is all **async**.
203
-
204
- #### 2. Add `FlashStoreSync` as a in-memory **Write-back Cache** for Flash-Store
205
-
206
- Add a new class `FlashStoreSync` which is a in-memory full loaded **Write-back Cache** for Flash-Store:
207
-
208
- 1. Writes directly to `cache`, lazy writes to `store`.
209
- 1. Reads from cache, never read-miss because cache have the full data of the store which will never expire.
210
- 1. API of `FlashStoreSync` is the same as the ES6 `Map`
211
-
212
- ### v0.2 Sep 2017
179
+ ### v2.0
213
180
 
214
- Init version, API is LevelDB-like.
181
+ 1. LMDB-backed storage, ESM-only packaging, and Node.js 26.
215
182
 
216
183
  ## FAQ
217
184
 
@@ -232,12 +199,12 @@ Long answer:
232
199
 
233
200
  ## Author
234
201
 
235
- [Huan LI](https://github.com/huan) ([李卓桓](http://linkedin.com/in/zixia)) zixia@zixia.net
202
+ [Huan LI](https://github.com/huan) ([Huan Li](http://linkedin.com/in/huan42)) huan@chatie.io
236
203
 
237
- [![Profile of Huan LI (李卓桓) on StackOverflow](https://stackexchange.com/users/flair/265499.png)](https://stackexchange.com/users/265499)
204
+ [![Profile of Huan Li on StackOverflow](https://stackexchange.com/users/flair/265499.png)](https://stackexchange.com/users/265499)
238
205
 
239
206
  ## Copyright & License
240
207
 
241
- * Code & Docs © 2017-now Huan (李卓桓) \<zixia@zixia.net\>
208
+ * Code & Docs © 2017-now Huan Li \<huan@chatie.io\>
242
209
  * Code released under the Apache-2.0 License
243
210
  * Docs released under Creative Commons
@@ -0,0 +1,64 @@
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"
10
+ }
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
+ }
@@ -0,0 +1,4 @@
1
+ import { log } from 'brolog';
2
+ declare const VERSION: string;
3
+ export { log, VERSION };
4
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,16 @@
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.
4
+ */
5
+ import { readFileSync } from 'node:fs';
6
+ 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;
15
+ export { log, VERSION };
16
+ //# sourceMappingURL=config.js.map
@@ -0,0 +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"}
@@ -0,0 +1,73 @@
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 { 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. */
25
+ 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
+ }
72
+ export default FlashStoreSync;
73
+ //# sourceMappingURL=flash-store-sync.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flash-store-sync.d.ts","sourceRoot":"","sources":["../../src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