@ohos-ports/lmdb 2.8.6-beta.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 (125) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +580 -0
  3. package/SECURITY.md +12 -0
  4. package/bin/download-prebuilds.js +15 -0
  5. package/binding.gyp +113 -0
  6. package/build/Release/lmdb.node +0 -0
  7. package/caching.js +212 -0
  8. package/dependencies/lmdb/libraries/liblmdb/COPYRIGHT +20 -0
  9. package/dependencies/lmdb/libraries/liblmdb/Doxyfile +1631 -0
  10. package/dependencies/lmdb/libraries/liblmdb/LICENSE +47 -0
  11. package/dependencies/lmdb/libraries/liblmdb/Makefile +136 -0
  12. package/dependencies/lmdb/libraries/liblmdb/chacha8.c +183 -0
  13. package/dependencies/lmdb/libraries/liblmdb/chacha8.h +14 -0
  14. package/dependencies/lmdb/libraries/liblmdb/crypto.c +121 -0
  15. package/dependencies/lmdb/libraries/liblmdb/intro.doc +192 -0
  16. package/dependencies/lmdb/libraries/liblmdb/lmdb.h +1817 -0
  17. package/dependencies/lmdb/libraries/liblmdb/mdb.c +12555 -0
  18. package/dependencies/lmdb/libraries/liblmdb/mdb_copy.1 +74 -0
  19. package/dependencies/lmdb/libraries/liblmdb/mdb_copy.c +106 -0
  20. package/dependencies/lmdb/libraries/liblmdb/mdb_drop.1 +53 -0
  21. package/dependencies/lmdb/libraries/liblmdb/mdb_drop.c +154 -0
  22. package/dependencies/lmdb/libraries/liblmdb/mdb_dump.1 +94 -0
  23. package/dependencies/lmdb/libraries/liblmdb/mdb_dump.c +333 -0
  24. package/dependencies/lmdb/libraries/liblmdb/mdb_load.1 +97 -0
  25. package/dependencies/lmdb/libraries/liblmdb/mdb_load.c +530 -0
  26. package/dependencies/lmdb/libraries/liblmdb/mdb_stat.1 +83 -0
  27. package/dependencies/lmdb/libraries/liblmdb/mdb_stat.c +276 -0
  28. package/dependencies/lmdb/libraries/liblmdb/midl-sparse.c +452 -0
  29. package/dependencies/lmdb/libraries/liblmdb/midl.c +452 -0
  30. package/dependencies/lmdb/libraries/liblmdb/midl.h +208 -0
  31. package/dependencies/lmdb/libraries/liblmdb/module.c +101 -0
  32. package/dependencies/lmdb/libraries/liblmdb/module.h +16 -0
  33. package/dependencies/lmdb/libraries/liblmdb/mtest.c +178 -0
  34. package/dependencies/lmdb/libraries/liblmdb/mtest2.c +124 -0
  35. package/dependencies/lmdb/libraries/liblmdb/mtest3.c +133 -0
  36. package/dependencies/lmdb/libraries/liblmdb/mtest4.c +168 -0
  37. package/dependencies/lmdb/libraries/liblmdb/mtest5.c +135 -0
  38. package/dependencies/lmdb/libraries/liblmdb/mtest6.c +141 -0
  39. package/dependencies/lmdb/libraries/liblmdb/mtest_enc.c +190 -0
  40. package/dependencies/lmdb/libraries/liblmdb/mtest_enc2.c +189 -0
  41. package/dependencies/lmdb/libraries/liblmdb/mtest_remap.c +177 -0
  42. package/dependencies/lmdb/libraries/liblmdb/sample-bdb.txt +73 -0
  43. package/dependencies/lmdb/libraries/liblmdb/sample-mdb.txt +62 -0
  44. package/dependencies/lmdb/libraries/liblmdb/tooltag +27 -0
  45. package/dependencies/lmdb-data-v1/libraries/liblmdb/CHANGES +266 -0
  46. package/dependencies/lmdb-data-v1/libraries/liblmdb/COPYRIGHT +20 -0
  47. package/dependencies/lmdb-data-v1/libraries/liblmdb/Doxyfile +1631 -0
  48. package/dependencies/lmdb-data-v1/libraries/liblmdb/LICENSE +47 -0
  49. package/dependencies/lmdb-data-v1/libraries/liblmdb/intro.doc +192 -0
  50. package/dependencies/lmdb-data-v1/libraries/liblmdb/lmdb.h +1608 -0
  51. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb.c +10320 -0
  52. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_copy.1 +55 -0
  53. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_copy.c +82 -0
  54. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_dump.1 +75 -0
  55. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_dump.c +319 -0
  56. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_load.1 +84 -0
  57. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_load.c +496 -0
  58. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_stat.1 +64 -0
  59. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_stat.c +263 -0
  60. package/dependencies/lmdb-data-v1/libraries/liblmdb/midl.c +359 -0
  61. package/dependencies/lmdb-data-v1/libraries/liblmdb/midl.h +186 -0
  62. package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest.c +177 -0
  63. package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest2.c +124 -0
  64. package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest3.c +133 -0
  65. package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest4.c +168 -0
  66. package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest5.c +135 -0
  67. package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest6.c +141 -0
  68. package/dependencies/lmdb-data-v1/libraries/liblmdb/sample-bdb.txt +73 -0
  69. package/dependencies/lmdb-data-v1/libraries/liblmdb/sample-mdb.txt +62 -0
  70. package/dependencies/lmdb-data-v1/libraries/liblmdb/tooltag +22 -0
  71. package/dependencies/lz4/LICENSE +11 -0
  72. package/dependencies/lz4/lib/LICENSE +24 -0
  73. package/dependencies/lz4/lib/Makefile +225 -0
  74. package/dependencies/lz4/lib/README.md +169 -0
  75. package/dependencies/lz4/lib/dll/example/Makefile +63 -0
  76. package/dependencies/lz4/lib/dll/example/README.md +69 -0
  77. package/dependencies/lz4/lib/dll/example/fullbench-dll.sln +25 -0
  78. package/dependencies/lz4/lib/dll/example/fullbench-dll.vcxproj +182 -0
  79. package/dependencies/lz4/lib/dll/liblz4.def +62 -0
  80. package/dependencies/lz4/lib/liblz4-dll.rc.in +35 -0
  81. package/dependencies/lz4/lib/liblz4.pc.in +14 -0
  82. package/dependencies/lz4/lib/lz4.c +2722 -0
  83. package/dependencies/lz4/lib/lz4.h +842 -0
  84. package/dependencies/lz4/lib/lz4file.c +311 -0
  85. package/dependencies/lz4/lib/lz4file.h +93 -0
  86. package/dependencies/lz4/lib/lz4frame.c +2078 -0
  87. package/dependencies/lz4/lib/lz4frame.h +692 -0
  88. package/dependencies/lz4/lib/lz4frame_static.h +47 -0
  89. package/dependencies/lz4/lib/lz4hc.c +1631 -0
  90. package/dependencies/lz4/lib/lz4hc.h +413 -0
  91. package/dependencies/lz4/lib/xxhash.c +1030 -0
  92. package/dependencies/lz4/lib/xxhash.h +328 -0
  93. package/dependencies/v8/v8-fast-api-calls-v16.h +791 -0
  94. package/dependencies/v8/v8-fast-api-calls.h +888 -0
  95. package/dict/dict.txt +1 -0
  96. package/dict/dict2.txt +1 -0
  97. package/dist/index.cjs +2950 -0
  98. package/dist/index.cjs.map +1 -0
  99. package/index.d.cts +420 -0
  100. package/index.d.ts +450 -0
  101. package/index.js +38 -0
  102. package/keys.js +116 -0
  103. package/level.js +27 -0
  104. package/native.js +85 -0
  105. package/node-index.js +32 -0
  106. package/open.js +448 -0
  107. package/package.json +124 -0
  108. package/read.js +833 -0
  109. package/rollup.config.js +12 -0
  110. package/src/compression.cpp +225 -0
  111. package/src/cursor.cpp +395 -0
  112. package/src/dbi.cpp +382 -0
  113. package/src/env.cpp +1030 -0
  114. package/src/lmdb-js.cpp +64 -0
  115. package/src/lmdb-js.h +633 -0
  116. package/src/misc.cpp +593 -0
  117. package/src/ordered-binary.cpp +46 -0
  118. package/src/txn.cpp +210 -0
  119. package/src/v8-functions.cpp +170 -0
  120. package/src/windows.c +35 -0
  121. package/src/writer.cpp +537 -0
  122. package/util/RangeIterable.js +236 -0
  123. package/util/set-optional-deps.cjs +14 -0
  124. package/util/when.js +8 -0
  125. package/write.js +912 -0
package/index.d.ts ADDED
@@ -0,0 +1,450 @@
1
+ declare namespace lmdb {
2
+ export function open<V = any, K extends Key = Key>(path: string, options: RootDatabaseOptions): RootDatabase<V, K>
3
+ export function open<V = any, K extends Key = Key>(options: RootDatabaseOptionsWithPath): RootDatabase<V, K>
4
+ export function openAsClass<V = any, K extends Key = Key>(options: RootDatabaseOptionsWithPath): DatabaseClass<V, K>
5
+
6
+ class Database<V = any, K extends Key = Key> {
7
+ /**
8
+ * Get the value stored by given id/key
9
+ * @param id The key for the entry
10
+ * @param options Additional options for the retrieval
11
+ **/
12
+ get(id: K, options?: GetOptions): V | undefined
13
+ /**
14
+ * Get the entry stored by given id/key, which includes both the value and the version number (if available)
15
+ * @param id The key for the entry
16
+ * @param options Additional options for the retrieval
17
+ **/
18
+ getEntry(id: K, options?: GetOptions): {
19
+ value: V
20
+ version?: number
21
+ } | undefined
22
+
23
+ /**
24
+ * Get the value stored by given id/key in binary format, as a Buffer
25
+ * @param id The key for the entry
26
+ **/
27
+ getBinary(id: K): Buffer | undefined
28
+
29
+ /**
30
+ * Get the value stored by given id/key in binary format, as a temporary Buffer.
31
+ * This is faster, but the data is only valid until the next get operation (then it will be overwritten).
32
+ * @param id The key for the entry
33
+ **/
34
+ getBinaryFast(id: K): Buffer | undefined
35
+
36
+ /**
37
+ * For random access structures and "fast" binary data, the underlying data is volatile,
38
+ * and not safe to access after the next get. This function allows the data to
39
+ * be copied as needed for safe access in the future. This can be used with buffers and random
40
+ * access data structures.
41
+ * @param data The data to be copied
42
+ **/
43
+ retain(data: any): any
44
+
45
+ /**
46
+ * Asynchronously fetch the values stored by the given ids and accesses all
47
+ * pages to ensure that any hard page faults and disk I/O are performed
48
+ * asynchronously in a separate thread. Once completed, synchronous
49
+ * gets to the same entries will most likely be in memory and fast.
50
+ * @param ids The keys for the entries to prefetch
51
+ **/
52
+ prefetch(ids: K[], callback?: Function): Promise<void>
53
+
54
+ /**
55
+ * Asynchronously get the values stored by the given ids and return the
56
+ * values in array corresponding to the array of ids.
57
+ * @param ids The keys for the entries to get
58
+ **/
59
+ getMany(ids: K[], callback?: (error: any, values: V[]) => any): Promise<(V | undefined)[]>
60
+
61
+ /**
62
+ * Store the provided value, using the provided id/key
63
+ * @param id The key for the entry
64
+ * @param value The value to store
65
+ **/
66
+ put(id: K, value: V): Promise<boolean>
67
+ /**
68
+ * Store the provided value, using the provided id/key and version number, and optionally the required
69
+ * existing version
70
+ * @param id The key for the entry
71
+ * @param value The value to store
72
+ * @param version The version number to assign to this entry
73
+ * @param ifVersion If provided the put will only succeed if the previous version number matches this (atomically checked)
74
+ **/
75
+ put(id: K, value: V, version: number, ifVersion?: number): Promise<boolean>
76
+ /**
77
+ * Remove the entry with the provided id/key
78
+ * @param id The key for the entry to remove
79
+ **/
80
+ remove(id: K): Promise<boolean>
81
+ /**
82
+ * Remove the entry with the provided id/key, conditionally based on the provided existing version number
83
+ * @param id The key for the entry to remove
84
+ * @param ifVersion If provided the remove will only succeed if the previous version number matches this (atomically checked)
85
+ **/
86
+ remove(id: K, ifVersion: number): Promise<boolean>
87
+ /**
88
+ * Remove the entry with the provided id/key and value (mainly used for dupsort databases) and optionally the required
89
+ * existing version
90
+ * @param id The key for the entry to remove
91
+ * @param valueToRemove The value for the entry to remove
92
+ **/
93
+ remove(id: K, valueToRemove: V): Promise<boolean>
94
+ /**
95
+ * Synchronously store the provided value, using the provided id/key, will return after the data has been written.
96
+ * @param id The key for the entry
97
+ * @param value The value to store
98
+ **/
99
+ putSync(id: K, value: V): void
100
+ /**
101
+ * Synchronously store the provided value, using the provided id/key and version number
102
+ * @param id The key for the entry
103
+ * @param value The value to store
104
+ * @param version The version number to assign to this entry
105
+ **/
106
+ putSync(id: K, value: V, version: number): void
107
+ /**
108
+ * Synchronously store the provided value, using the provided id/key and options
109
+ * @param id The key for the entry
110
+ * @param value The value to store
111
+ * @param options The version number to assign to this entry
112
+ **/
113
+ putSync(id: K, value: V, options: PutOptions): void
114
+ /**
115
+ * Synchronously remove the entry with the provided id/key
116
+ * existing version
117
+ * @param id The key for the entry to remove
118
+ **/
119
+ removeSync(id: K): boolean
120
+ /**
121
+ * Synchronously remove the entry with the provided id/key and value (mainly used for dupsort databases)
122
+ * existing version
123
+ * @param id The key for the entry to remove
124
+ * @param valueToRemove The value for the entry to remove
125
+ **/
126
+ removeSync(id: K, valueToRemove: V): boolean
127
+ /**
128
+ * Get all the values for the given key (for dupsort databases)
129
+ * existing version
130
+ * @param key The key for the entry to remove
131
+ * @param options The options for the iterator
132
+ **/
133
+ getValues(key: K, options?: RangeOptions): RangeIterable<V>
134
+ /**
135
+ * Get the count of all the values for the given key (for dupsort databases)
136
+ * existing version
137
+ * @param options The options for the range/iterator
138
+ **/
139
+ getValuesCount(key: K, options?: RangeOptions): number
140
+ /**
141
+ * Get all the unique keys for the given range
142
+ * existing version
143
+ * @param options The options for the range/iterator
144
+ **/
145
+ getKeys(options?: RangeOptions): RangeIterable<K>
146
+ /**
147
+ * Get the count of all the unique keys for the given range
148
+ * existing version
149
+ * @param options The options for the range/iterator
150
+ **/
151
+ getKeysCount(options?: RangeOptions): number
152
+ /**
153
+ * Get all the entries for the given range
154
+ * existing version
155
+ * @param options The options for the range/iterator
156
+ **/
157
+ getRange(options?: RangeOptions): RangeIterable<{ key: K, value: V, version?: number }>
158
+ /**
159
+ * Get the count of all the entries for the given range
160
+ * existing version
161
+ * @param options The options for the range/iterator
162
+ **/
163
+ getCount(options?: RangeOptions): number
164
+ /**
165
+ * @deprecated since version 2.0, use transaction() instead
166
+ */
167
+ transactionAsync<T>(action: () => T): T
168
+ /**
169
+ * Execute a transaction asynchronously, running all the actions within the action callback in the transaction,
170
+ * and committing the transaction after the action callback completes.
171
+ * existing version
172
+ * @param action The function to execute within the transaction
173
+ **/
174
+ transaction<T>(action: () => T): Promise<T>
175
+ /**
176
+ * Execute a transaction synchronously, running all the actions within the action callback in the transaction,
177
+ * and committing the transaction after the action callback completes.
178
+ * existing version
179
+ * @param action The function to execute within the transaction
180
+ * @params flags Additional flags specifying transaction behavior, this is optional and defaults to abortable, synchronous commits that are flushed to disk before returning
181
+ **/
182
+ transactionSync<T>(action: () => T, flags?: TransactionFlags): T
183
+ /**
184
+ * Execute a transaction asynchronously, running all the actions within the action callback in the transaction,
185
+ * and committing the transaction after the action callback completes.
186
+ * existing version
187
+ * @param action The function to execute within the transaction
188
+ **/
189
+ childTransaction<T>(action: () => T): Promise<T>
190
+ /**
191
+ * Returns the current transaction and marks it as in use. This can then be explicitly used for read operations
192
+ * @returns The transaction object
193
+ **/
194
+ useReadTransaction(): Transaction
195
+ /**
196
+ * Execute a set of write operations that will all be batched together in next queued asynchronous transaction.
197
+ * @param action The function to execute with a set of write operations.
198
+ **/
199
+ batch<T>(action: () => any): Promise<boolean>
200
+ /**
201
+ * Execute writes actions that are all conditionally dependent on the entry with the provided key having the provided
202
+ * version number (checked atomically).
203
+ * @param id Key of the entry to check
204
+ * @param ifVersion The require version number of the entry for all actions to succeed
205
+ * @param action The function to execute with actions that will be dependent on this condition
206
+ **/
207
+ ifVersion(id: K, ifVersion: number, action: () => any): Promise<boolean>
208
+ /**
209
+ * Execute writes actions that are all conditionally dependent on the entry with the provided key
210
+ * not existing (checked atomically).
211
+ * @param id Key of the entry to check
212
+ * @param action The function to execute with actions that will be dependent on this condition
213
+ **/
214
+ ifNoExists(id: K, action: () => any): Promise<boolean>
215
+ /**
216
+ * Check if an entry for the provided key exists
217
+ * @param id Key of the entry to check
218
+ */
219
+ doesExist(key: K): boolean
220
+ /**
221
+ * Check if an entry for the provided key/value exists
222
+ * @param id Key of the entry to check
223
+ * @param value Value of the entry to check
224
+ */
225
+ doesExist(key: K, value: V): boolean
226
+ /**
227
+ * Check if an entry for the provided key exists with the expected version
228
+ * @param id Key of the entry to check
229
+ * @param version Expected version
230
+ */
231
+ doesExist(key: K, version: number): boolean
232
+ /**
233
+ * @deprecated since version 2.0, use drop() or dropSync() instead
234
+ */
235
+ deleteDB(): Promise<void>
236
+ /**
237
+ * Delete this database/store (asynchronously).
238
+ **/
239
+ drop(): Promise<void>
240
+ /**
241
+ * Synchronously delete this database/store.
242
+ **/
243
+ dropSync(): void
244
+ /**
245
+ * @deprecated since version 2.0, use clearAsync() or clearSync() instead
246
+ */
247
+ clear(): Promise<void>
248
+ /**
249
+ * Asynchronously clear all the entries from this database/store.
250
+ **/
251
+ clearAsync(): Promise<void>
252
+ /**
253
+ * Synchronously clear all the entries from this database/store.
254
+ **/
255
+ clearSync(): void
256
+ /** A promise-like object that resolves when previous writes have been committed. */
257
+ committed: Promise<boolean>
258
+ /** A promise-like object that resolves when previous writes have been committed and fully flushed/synced to disk/storage. */
259
+ flushed: Promise<boolean>
260
+ /**
261
+ * Check the reader locks and remove any stale reader locks. Returns the number of stale locks that were removed.
262
+ **/
263
+ readerCheck(): number
264
+ /**
265
+ * Returns a string that describes all the current reader locks, useful for debugging if reader locks aren't being removed.
266
+ **/
267
+ readerList(): string
268
+ /**
269
+ * Returns statistics about the current database
270
+ **/
271
+ getStats(): {}
272
+ /**
273
+ * Explicitly force the read transaction to reset to the latest snapshot/version of the database
274
+ **/
275
+ resetReadTxn(): void
276
+ /**
277
+ * Make a snapshot copy of the current database at the indicated path
278
+ * @param path Path to store the backup
279
+ * @param compact Apply compaction while making the backup (slower and smaller)
280
+ **/
281
+ backup(path: string, compact: boolean): Promise<void>
282
+ /**
283
+ * Close the current database.
284
+ **/
285
+ close(): Promise<void>
286
+ /**
287
+ * Add event listener
288
+ */
289
+ on(event: 'beforecommit' | 'aftercommit', callback: (event: any) => void): void
290
+ }
291
+ /* A constant that can be returned from a transaction to indicate that the transaction should be aborted */
292
+ export const ABORT: {};
293
+ /* A constant that can be returned in RangeIterable#map function to skip (filter out) the current value */
294
+ export const SKIP: {};
295
+ /* A constant that can be used as a conditional versions for put and ifVersion to indicate that the write should conditional on the key/entry existing */
296
+ export const IF_EXISTS: number;
297
+ class RootDatabase<V = any, K extends Key = Key> extends Database<V, K> {
298
+ /**
299
+ * Open a database store using the provided options.
300
+ **/
301
+ openDB<OV = V, OK extends Key = K>(options?: DatabaseOptions & { name: string }): Database<OV, OK>
302
+ /**
303
+ * Open a database store using the provided options.
304
+ **/
305
+ openDB<OV = V, OK extends Key = K>(dbName: string, dbOptions: DatabaseOptions): Database<OV, OK>
306
+ }
307
+ class DatabaseClass<V = any, K extends Key = Key> {
308
+ new(name: string | null, options: DatabaseOptions): Database<V, K>
309
+ }
310
+
311
+ type Key = Key[] | string | symbol | number | boolean | Uint8Array;
312
+
313
+ interface DatabaseOptions {
314
+ name?: string
315
+ cache?: boolean | {}
316
+ compression?: boolean | CompressionOptions
317
+ encoding?: 'msgpack' | 'json' | 'string' | 'binary' | 'ordered-binary'
318
+ sharedStructuresKey?: Key
319
+ useVersions?: boolean
320
+ keyEncoding?: 'uint32' | 'binary' | 'ordered-binary'
321
+ dupSort?: boolean
322
+ strictAsyncOrder?: boolean
323
+ }
324
+ interface RootDatabaseOptions extends DatabaseOptions {
325
+ /** The maximum number of databases to be able to open (there is some extra overhead if this is set very high).*/
326
+ maxDbs?: number
327
+ /** Set a longer delay (in milliseconds) to wait longer before committing writes to increase the number of writes per transaction (higher latency, but more efficient) **/
328
+ commitDelay?: number
329
+ /**
330
+ * This can be used to specify the initial amount of how much virtual memory address space (in bytes) to allocate for mapping to the database files.
331
+ * Setting a map size will typically disable remapChunks by default unless the size is larger than appropriate for the OS. Different OSes have different allocation limits.
332
+ **/
333
+ mapSize?: number
334
+ /**
335
+ * This defines the page size of the database. This defaults to the default page size of the OS (usually 4,096, except on MacOS with M-series, which is 16,384 bytes).
336
+ * You may want to consider setting this to 8,192 for databases larger than available memory (and moreso if you have range queries) or 4,096 for databases that can mostly cache in memory.
337
+ * Note that this only effects the page size of new databases (does not affect existing databases). */
338
+ pageSize?: number
339
+ /** This enables committing transactions where LMDB waits for a transaction to be fully flushed to disk after the transaction has been committed and defaults to being enabled on non-Windows OSes. This option is discussed in more detail below. */
340
+ overlappingSync?: boolean
341
+ /** Resolve asynchronous operations when commits are finished and visible and include a separate promise for when a commit is flushed to disk, as a flushed property on the commit promise. Note that you can alternately use the flushed property on the database. */
342
+ separateFlushed?: boolean
343
+ /**
344
+ * This a flag to specify if dynamic memory mapping should be used. Enabling this generally makes read operations a little bit slower, but frees up more mapped memory, making it friendlier to other applications.
345
+ * This is enabled by default on 32-bit operating systems (which require this to go beyond 4GB database size) if mapSize is not specified, otherwise it is disabled by default.
346
+ **/
347
+ remapChunks?: boolean
348
+ /** This provides a small performance boost (when not using useWritemap) for writes, by skipping zero'ing out malloc'ed data, but can leave application data in unused portions of the database. This is recommended unless there are concerns of database files being accessible. */
349
+ noMemInit?: boolean
350
+ /** Use writemaps, discouraged at this. This improves performance by reducing malloc calls, but it is possible for a stray pointer to corrupt data. */
351
+ useWritemap?: boolean
352
+ /** Treat path as a filename instead of directory (this is the default if the path appears to end with an extension and has '.' in it) */
353
+ noSubdir?: boolean
354
+ /**
355
+ * Does not explicitly flush data to disk at all. This can be useful for temporary databases where durability/integrity is not necessary, and can significantly improve write performance that is I/O bound.
356
+ * However, we discourage this flag for data that needs integrity and durability in storage, since it can result in data loss/corruption if the computer crashes.
357
+ **/
358
+ noSync?: boolean
359
+ /** This isn't as dangerous as `noSync`, but doesn't improve performance much either. */
360
+ noMetaSync?: boolean
361
+ /** Self-descriptive */
362
+ readOnly?: boolean
363
+ /** The maximum number of concurrent read transactions (readers) to be able to open ([more information](http://www.lmdb.tech/doc/group__mdb.html#gae687966c24b790630be2a41573fe40e2)). */
364
+ maxReaders?: number
365
+ /** This enables encryption, and the provided value is the key that is used for encryption. This may be a buffer or string, but must be 32 bytes/characters long. This uses the Chacha8 cipher for fast and secure on-disk encryption of data. */
366
+ encryptionKey?: string | Buffer
367
+ /**
368
+ * This is enabled by default and will ensure that all asynchronous write operations performed in the same event turn will be batched together into the same transaction.
369
+ * Disabling this allows lmdb-js to commit a transaction at any time, and asynchronous operations will only be guaranteed to be in the same transaction if explicitly batched together (with transaction, batch, ifVersion).
370
+ * If this is disabled (set to false), you can control how many writes can occur before starting a transaction with txnStartThreshold (allow a transaction will still be started at the next event turn if the threshold is not met).
371
+ * Disabling event turn batching (and using lower txnStartThreshold values) can facilitate a faster response time to write operations. txnStartThreshold defaults to 5.
372
+ **/
373
+ eventTurnBatching?: boolean
374
+ }
375
+ interface RootDatabaseOptionsWithPath extends RootDatabaseOptions {
376
+ path?: string
377
+ }
378
+ interface CompressionOptions {
379
+ threshold?: number
380
+ dictionary?: Buffer
381
+ }
382
+ interface GetOptions {
383
+ transaction?: Transaction
384
+ }
385
+ interface RangeOptions {
386
+ /** Starting key for a range **/
387
+ start?: Key
388
+ /** Ending key for a range **/
389
+ end?: Key
390
+ /** Iterate through the entries in reverse order **/
391
+ reverse?: boolean
392
+ /** Include version numbers in each entry returned **/
393
+ versions?: boolean
394
+ /** The maximum number of entries to return **/
395
+ limit?: number
396
+ /** The number of entries to skip **/
397
+ offset?: number
398
+ /** Use a snapshot of the database from when the iterator started **/
399
+ snapshot?: boolean
400
+ /** Use the provided transaction for this range query */
401
+ transaction?: Transaction
402
+ }
403
+ interface PutOptions {
404
+ /* Append to the database using MDB_APPEND, which can be faster */
405
+ append?: boolean
406
+ /* Append to a dupsort database using MDB_APPENDDUP, which can be faster */
407
+ appendDup?: boolean
408
+ /* Perform put with MDB_NOOVERWRITE which will fail if the entry for the key already exists */
409
+ noOverwrite?: boolean
410
+ /* Perform put with MDB_NODUPDATA which will fail if the entry for the key/value already exists */
411
+ noDupData?: boolean
412
+ /* The version of the entry to set */
413
+ version?: number
414
+ }
415
+ export enum TransactionFlags {
416
+ /* Indicates that the transaction needs to be abortable */
417
+ ABORTABLE = 1,
418
+ /* Indicates that the transaction needs to be committed before returning */
419
+ SYNCHRONOUS_COMMIT = 2,
420
+ /* Indicates that the function can return before the transaction has been flushed to disk */
421
+ NO_SYNC_FLUSH = 0x10000
422
+ }
423
+ class RangeIterable<T> implements Iterable<T> {
424
+ map<U>(callback: (entry: T) => U): RangeIterable<U>
425
+ flatMap<U>(callback: (entry: T) => U[]): RangeIterable<U>
426
+ slice(start: number, end: number): RangeIterable<T>
427
+ filter(callback: (entry: T) => any): RangeIterable<T>
428
+ [Symbol.iterator]() : Iterator<T>
429
+ forEach(callback: (entry: T) => any): void
430
+ onDone?: Function
431
+ asArray: T[]
432
+ }
433
+ class Transaction {
434
+ /**
435
+ * When there is no more need for the transaction and it can be closed.
436
+ */
437
+ done(): void
438
+ }
439
+ export function getLastVersion(): number
440
+ export function compareKeys(a: Key, b: Key): number
441
+ class Binary {}
442
+ /* Wrap a Buffer/Uint8Array for direct assignment as a value bypassing any encoding, for put (and doesExist) operations.
443
+ */
444
+ export function asBinary(buffer: Uint8Array): Binary
445
+ /* Indicates if V8 accelerated functions are enabled. If this is false, some functions will be a little slower, and you may want to npm install --build-from-source to enable maximum performance */
446
+ export let v8AccelerationEnabled: boolean
447
+ /* Return database augmented with methods to better conform to levelup */
448
+ export function levelup(database: Database): Database
449
+ }
450
+ export = lmdb
package/index.js ADDED
@@ -0,0 +1,38 @@
1
+ import { EventEmitter } from 'events';
2
+ import { setExternals, setNativeFunctions, Dbi } from './native.js';
3
+ import { arch, tmpdir, platform } from 'os';
4
+ import fs from 'fs';
5
+ import { Encoder as MsgpackrEncoder } from 'msgpackr';
6
+ import { WeakLRUCache } from 'weak-lru-cache';
7
+ import * as orderedBinary from 'ordered-binary';
8
+
9
+
10
+ orderedBinary.enableNullTermination();
11
+ setExternals({
12
+ arch, fs, tmpdir, MsgpackrEncoder, WeakLRUCache, orderedBinary,
13
+ EventEmitter, os: platform(), onExit(callback) {
14
+ if (process.getMaxListeners() < process.listenerCount('exit') + 8)
15
+ process.setMaxListeners(process.listenerCount('exit') + 8);
16
+ process.on('exit', callback);
17
+ },
18
+ });
19
+ export { toBufferKey as keyValueToBuffer, compareKeys, compareKeys as compareKey, fromBufferKey as bufferToKeyValue } from 'ordered-binary';
20
+ export { ABORT, IF_EXISTS, asBinary } from './write.js';
21
+ import { ABORT, IF_EXISTS, asBinary } from './write.js';
22
+ export { levelup } from './level.js';
23
+ export { SKIP } from './util/RangeIterable.js';
24
+ import { levelup } from './level.js';
25
+ export { clearKeptObjects } from './native.js';
26
+ import { nativeAddon } from './native.js';
27
+ export let { noop } = nativeAddon;
28
+ export { open, openAsClass, getLastVersion, allDbs, getLastTxnId } from './open.js';
29
+ import { toBufferKey as keyValueToBuffer, compareKeys as compareKey, fromBufferKey as bufferToKeyValue } from 'ordered-binary';
30
+ import { open, openAsClass, getLastVersion } from './open.js';
31
+ export const TransactionFlags = {
32
+ ABORTABLE: 1,
33
+ SYNCHRONOUS_COMMIT: 2,
34
+ NO_SYNC_FLUSH: 0x10000,
35
+ };
36
+ export default {
37
+ open, openAsClass, getLastVersion, compareKey, keyValueToBuffer, bufferToKeyValue, ABORT, IF_EXISTS, asBinary, levelup, TransactionFlags
38
+ };
package/keys.js ADDED
@@ -0,0 +1,116 @@
1
+ import { getAddress, orderedBinary } from './native.js';
2
+
3
+ const REUSE_BUFFER_MODE = 512;
4
+ const writeUint32Key = (key, target, start) => {
5
+ (target.dataView || (target.dataView = new DataView(target.buffer, 0, target.length))).setUint32(start, key, true);
6
+ return start + 4;
7
+ };
8
+ const readUint32Key = (target, start) => {
9
+ return (target.dataView || (target.dataView = new DataView(target.buffer, 0, target.length))).getUint32(start, true);
10
+ };
11
+ const writeBufferKey = (key, target, start) => {
12
+ target.set(key, start);
13
+ return key.length + start;
14
+ };
15
+ const Uint8ArraySlice = Uint8Array.prototype.slice;
16
+ const readBufferKey = (target, start, end) => {
17
+ return Uint8ArraySlice.call(target, start, end);
18
+ };
19
+
20
+ let lastEncodedValue, bytes;
21
+ export function applyKeyHandling(store) {
22
+ if (store.encoding == 'ordered-binary') {
23
+ store.encoder = store.decoder = {
24
+ writeKey: orderedBinary.writeKey,
25
+ readKey: orderedBinary.readKey,
26
+ };
27
+ }
28
+ if (store.encoder && store.encoder.writeKey && !store.encoder.encode) {
29
+ store.encoder.encode = function(value, mode) {
30
+ if (typeof value !== 'object' && value && value === lastEncodedValue) {
31
+ // reuse the last serialized bytes
32
+ // NOTE that it is very important that nothing else calls saveKey with saveTo: false
33
+ } else {
34
+ lastEncodedValue = value;
35
+ bytes = saveKey(value, this.writeKey, false, store.maxKeySize);
36
+ }
37
+ if (bytes.end > 0 && !(REUSE_BUFFER_MODE & mode)) {
38
+ return bytes.subarray(bytes.start, bytes.end);
39
+ }
40
+ return bytes;
41
+ };
42
+ store.encoder.copyBuffers = true; // just an indicator for the buffer reuse in write.js
43
+ }
44
+ if (store.decoder && store.decoder.readKey && !store.decoder.decode) {
45
+ store.decoder.decode = function(buffer) { return this.readKey(buffer, 0, buffer.length); };
46
+ store.decoderCopies = true;
47
+ }
48
+ if (store.keyIsUint32 || store.keyEncoding == 'uint32') {
49
+ store.writeKey = writeUint32Key;
50
+ store.readKey = readUint32Key;
51
+ } else if (store.keyIsBuffer || store.keyEncoding == 'binary') {
52
+ store.writeKey = writeBufferKey;
53
+ store.readKey = readBufferKey;
54
+ } else if (store.keyEncoder) {
55
+ store.writeKey = store.keyEncoder.writeKey;
56
+ store.readKey = store.keyEncoder.readKey;
57
+ } else {
58
+ store.writeKey = orderedBinary.writeKey;
59
+ store.readKey = orderedBinary.readKey;
60
+ }
61
+ }
62
+
63
+ let saveBuffer, uint32, saveDataView = { setFloat64() {}, setUint32() {} }, saveDataAddress;
64
+ let savePosition = 8000;
65
+ let DYNAMIC_KEY_BUFFER_SIZE = 8192;
66
+ function allocateSaveBuffer() {
67
+ saveBuffer = typeof Buffer != 'undefined' ? Buffer.alloc(DYNAMIC_KEY_BUFFER_SIZE) : new Uint8Array(DYNAMIC_KEY_BUFFER_SIZE);
68
+ uint32 = null;
69
+ saveBuffer.buffer.address = getAddress(saveBuffer.buffer);
70
+ saveDataAddress = saveBuffer.buffer.address;
71
+ // TODO: Conditionally only do this for key sequences?
72
+ saveDataView.setUint32(savePosition, 0xffffffff);
73
+ saveDataView.setFloat64(savePosition + 4, saveDataAddress, true); // save a pointer from the old buffer to the new address for the sake of the prefetch sequences
74
+ saveDataView = saveBuffer.dataView || (saveBuffer.dataView = new DataView(saveBuffer.buffer, saveBuffer.byteOffset, saveBuffer.byteLength));
75
+ savePosition = 0;
76
+ }
77
+ export function saveKey(key, writeKey, saveTo, maxKeySize, flags) {
78
+ if (savePosition > 7800) {
79
+ allocateSaveBuffer();
80
+ }
81
+ let start = savePosition;
82
+ try {
83
+ savePosition = key === undefined ? start + 4 :
84
+ writeKey(key, saveBuffer, start + 4);
85
+ } catch (error) {
86
+ saveBuffer.fill(0, start + 4); // restore zeros
87
+ if (error.name == 'RangeError') {
88
+ if (8180 - start < maxKeySize) {
89
+ allocateSaveBuffer(); // try again:
90
+ return saveKey(key, writeKey, saveTo, maxKeySize);
91
+ }
92
+ throw new Error('Key was too large, max key size is ' + maxKeySize);
93
+ } else
94
+ throw error;
95
+ }
96
+ let length = savePosition - start - 4;
97
+ if (length > maxKeySize) {
98
+ throw new Error('Key of size ' + length + ' was too large, max key size is ' + maxKeySize);
99
+ }
100
+ if (savePosition >= 8160) { // need to reserve enough room at the end for pointers
101
+ savePosition = start // reset position
102
+ allocateSaveBuffer(); // try again:
103
+ return saveKey(key, writeKey, saveTo, maxKeySize);
104
+ }
105
+ if (saveTo) {
106
+ saveDataView.setUint32(start, flags ? length | flags : length, true); // save the length
107
+ saveTo.saveBuffer = saveBuffer;
108
+ savePosition = (savePosition + 12) & 0xfffffc;
109
+ return start + saveDataAddress;
110
+ } else {
111
+ saveBuffer.start = start + 4;
112
+ saveBuffer.end = savePosition;
113
+ savePosition = (savePosition + 7) & 0xfffff8; // full 64-bit word alignment since these are usually copied
114
+ return saveBuffer;
115
+ }
116
+ }
package/level.js ADDED
@@ -0,0 +1,27 @@
1
+ export function levelup(store) {
2
+ return Object.assign(Object.create(store), {
3
+ get(key, options, callback) {
4
+ let result = store.get(key);
5
+ if (typeof options == 'function')
6
+ callback = options;
7
+ if (callback) {
8
+ if (result === undefined)
9
+ callback(new NotFoundError());
10
+ else
11
+ callback(null, result);
12
+ } else {
13
+ if (result === undefined)
14
+ return Promise.reject(new NotFoundError());
15
+ else
16
+ return Promise.resolve(result);
17
+ }
18
+ },
19
+ });
20
+ }
21
+ class NotFoundError extends Error {
22
+ constructor(message) {
23
+ super(message);
24
+ this.name = 'NotFoundError';
25
+ this.notFound = true;
26
+ }
27
+ }