@ohos-ports/lmdb 2.5.3 → 2.8.5-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 (124) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +72 -28
  3. package/SECURITY.md +12 -12
  4. package/bin/download-prebuilds.js +15 -0
  5. package/binding.gyp +115 -111
  6. package/build/Release/lmdb.node +0 -0
  7. package/caching.js +212 -156
  8. package/dependencies/lmdb/libraries/liblmdb/COPYRIGHT +20 -20
  9. package/dependencies/lmdb/libraries/liblmdb/Doxyfile +1631 -1631
  10. package/dependencies/lmdb/libraries/liblmdb/LICENSE +47 -47
  11. package/dependencies/lmdb/libraries/liblmdb/Makefile +136 -136
  12. package/dependencies/lmdb/libraries/liblmdb/chacha8.c +183 -183
  13. package/dependencies/lmdb/libraries/liblmdb/chacha8.h +14 -14
  14. package/dependencies/lmdb/libraries/liblmdb/crypto.c +121 -121
  15. package/dependencies/lmdb/libraries/liblmdb/intro.doc +192 -192
  16. package/dependencies/lmdb/libraries/liblmdb/lmdb.h +28 -3
  17. package/dependencies/lmdb/libraries/liblmdb/mdb.c +157 -31
  18. package/dependencies/lmdb/libraries/liblmdb/mdb_copy.1 +74 -74
  19. package/dependencies/lmdb/libraries/liblmdb/mdb_copy.c +106 -106
  20. package/dependencies/lmdb/libraries/liblmdb/mdb_drop.1 +53 -53
  21. package/dependencies/lmdb/libraries/liblmdb/mdb_drop.c +154 -154
  22. package/dependencies/lmdb/libraries/liblmdb/mdb_dump.1 +94 -94
  23. package/dependencies/lmdb/libraries/liblmdb/mdb_dump.c +333 -333
  24. package/dependencies/lmdb/libraries/liblmdb/mdb_load.1 +97 -97
  25. package/dependencies/lmdb/libraries/liblmdb/mdb_load.c +530 -530
  26. package/dependencies/lmdb/libraries/liblmdb/mdb_stat.1 +83 -83
  27. package/dependencies/lmdb/libraries/liblmdb/mdb_stat.c +276 -276
  28. package/dependencies/lmdb/libraries/liblmdb/midl-sparse.c +452 -0
  29. package/dependencies/lmdb/libraries/liblmdb/midl.c +452 -452
  30. package/dependencies/lmdb/libraries/liblmdb/midl.h +208 -208
  31. package/dependencies/lmdb/libraries/liblmdb/module.c +101 -101
  32. package/dependencies/lmdb/libraries/liblmdb/module.h +16 -16
  33. package/dependencies/lmdb/libraries/liblmdb/mtest.c +178 -178
  34. package/dependencies/lmdb/libraries/liblmdb/mtest2.c +124 -124
  35. package/dependencies/lmdb/libraries/liblmdb/mtest3.c +133 -133
  36. package/dependencies/lmdb/libraries/liblmdb/mtest4.c +168 -168
  37. package/dependencies/lmdb/libraries/liblmdb/mtest5.c +135 -135
  38. package/dependencies/lmdb/libraries/liblmdb/mtest6.c +141 -141
  39. package/dependencies/lmdb/libraries/liblmdb/mtest_enc.c +190 -190
  40. package/dependencies/lmdb/libraries/liblmdb/mtest_enc2.c +189 -189
  41. package/dependencies/lmdb/libraries/liblmdb/mtest_remap.c +177 -177
  42. package/dependencies/lmdb/libraries/liblmdb/sample-bdb.txt +73 -73
  43. package/dependencies/lmdb/libraries/liblmdb/sample-mdb.txt +62 -62
  44. package/dependencies/lmdb/libraries/liblmdb/tooltag +27 -27
  45. package/dependencies/lmdb-data-v1/libraries/liblmdb/CHANGES +266 -0
  46. package/dependencies/lmdb-data-v1/libraries/liblmdb/COPYRIGHT +20 -20
  47. package/dependencies/lmdb-data-v1/libraries/liblmdb/Doxyfile +1631 -1631
  48. package/dependencies/lmdb-data-v1/libraries/liblmdb/LICENSE +47 -47
  49. package/dependencies/lmdb-data-v1/libraries/liblmdb/intro.doc +192 -192
  50. package/dependencies/lmdb-data-v1/libraries/liblmdb/lmdb.h +1608 -1653
  51. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb.c +10320 -11359
  52. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_copy.1 +55 -61
  53. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_copy.c +82 -84
  54. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_dump.1 +75 -81
  55. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_dump.c +319 -319
  56. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_load.1 +84 -84
  57. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_load.c +496 -492
  58. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_stat.1 +64 -70
  59. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_stat.c +263 -264
  60. package/dependencies/lmdb-data-v1/libraries/liblmdb/midl.c +359 -421
  61. package/dependencies/lmdb-data-v1/libraries/liblmdb/midl.h +186 -200
  62. package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest.c +177 -177
  63. package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest2.c +124 -124
  64. package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest3.c +133 -133
  65. package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest4.c +168 -168
  66. package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest5.c +135 -135
  67. package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest6.c +141 -141
  68. package/dependencies/lmdb-data-v1/libraries/liblmdb/sample-bdb.txt +73 -73
  69. package/dependencies/lmdb-data-v1/libraries/liblmdb/sample-mdb.txt +62 -62
  70. package/dependencies/lmdb-data-v1/libraries/liblmdb/tooltag +22 -27
  71. package/dependencies/lz4/LICENSE +11 -11
  72. package/dependencies/lz4/lib/LICENSE +24 -24
  73. package/dependencies/lz4/lib/Makefile +225 -0
  74. package/dependencies/lz4/lib/README.md +169 -137
  75. package/dependencies/lz4/lib/dll/example/Makefile +63 -0
  76. package/dependencies/lz4/lib/dll/example/README.md +69 -69
  77. package/dependencies/lz4/lib/dll/liblz4.def +62 -62
  78. package/dependencies/lz4/lib/liblz4-dll.rc.in +35 -35
  79. package/dependencies/lz4/lib/liblz4.pc.in +14 -14
  80. package/dependencies/lz4/lib/lz4.c +2722 -2495
  81. package/dependencies/lz4/lib/lz4.h +842 -774
  82. package/dependencies/lz4/lib/lz4file.c +311 -0
  83. package/dependencies/lz4/lib/lz4file.h +93 -0
  84. package/dependencies/lz4/lib/lz4frame.c +2078 -1899
  85. package/dependencies/lz4/lib/lz4frame.h +692 -623
  86. package/dependencies/lz4/lib/lz4frame_static.h +47 -47
  87. package/dependencies/lz4/lib/lz4hc.c +1631 -1615
  88. package/dependencies/lz4/lib/lz4hc.h +413 -413
  89. package/dependencies/lz4/lib/xxhash.c +1030 -1030
  90. package/dependencies/lz4/lib/xxhash.h +328 -328
  91. package/dependencies/v8/v8-fast-api-calls-v16.h +790 -790
  92. package/dependencies/v8/v8-fast-api-calls.h +784 -888
  93. package/dist/index.cjs +1050 -584
  94. package/dist/index.cjs.map +1 -1
  95. package/index.d.cts +420 -0
  96. package/index.d.ts +450 -385
  97. package/index.js +38 -37
  98. package/keys.js +116 -102
  99. package/level.js +26 -26
  100. package/native.js +8 -5
  101. package/node-index.js +21 -17
  102. package/open.js +51 -17
  103. package/package.json +63 -21
  104. package/read.js +338 -95
  105. package/src/compression.cpp +12 -9
  106. package/src/cursor.cpp +82 -31
  107. package/src/dbi.cpp +78 -40
  108. package/src/env.cpp +336 -68
  109. package/src/lmdb-js.cpp +64 -64
  110. package/src/lmdb-js.h +83 -49
  111. package/src/misc.cpp +297 -28
  112. package/src/ordered-binary.cpp +46 -46
  113. package/src/txn.cpp +210 -257
  114. package/src/v8-functions.cpp +170 -166
  115. package/src/windows.c +34 -34
  116. package/src/writer.cpp +169 -84
  117. package/util/RangeIterable.js +112 -17
  118. package/util/set-optional-deps.cjs +14 -10
  119. package/util/when.js +8 -8
  120. package/write.js +145 -121
  121. package/dependencies/lmdb-data-v1/libraries/liblmdb/Makefile +0 -118
  122. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_drop.1 +0 -40
  123. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_drop.c +0 -135
  124. package/rollup.config.js +0 -12
package/index.d.ts CHANGED
@@ -1,385 +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
- **/
11
- get(id: K): V | undefined
12
- /**
13
- * Get the entry stored by given id/key, which includes both the value and the version number (if available)
14
- * @param id The key for the entry
15
- **/
16
- getEntry(id: K): {
17
- value: V
18
- version?: number
19
- } | undefined
20
-
21
- /**
22
- * Get the value stored by given id/key in binary format, as a Buffer
23
- * @param id The key for the entry
24
- **/
25
- getBinary(id: K): Buffer | undefined
26
-
27
- /**
28
- * Get the value stored by given id/key in binary format, as a temporary Buffer.
29
- * This is faster, but the data is only valid until the next get operation (then it will be overwritten).
30
- * @param id The key for the entry
31
- **/
32
- getBinaryFast(id: K): Buffer | undefined
33
-
34
- /**
35
- * Asynchronously fetch the values stored by the given ids and accesses all
36
- * pages to ensure that any hard page faults and disk I/O are performed
37
- * asynchronously in a separate thread. Once completed, synchronous
38
- * gets to the same entries will most likely be in memory and fast.
39
- * @param ids The keys for the entries to prefetch
40
- **/
41
- prefetch(ids: K[], callback?: Function): Promise<void>
42
-
43
- /**
44
- * Asynchronously get the values stored by the given ids and return the
45
- * values in array corresponding to the array of ids.
46
- * @param ids The keys for the entries to get
47
- **/
48
- getMany(ids: K[], callback?: (error: any, values: V[]) => any): Promise<(V | undefined)[]>
49
-
50
- /**
51
- * Store the provided value, using the provided id/key
52
- * @param id The key for the entry
53
- * @param value The value to store
54
- **/
55
- put(id: K, value: V): Promise<boolean>
56
- /**
57
- * Store the provided value, using the provided id/key and version number, and optionally the required
58
- * existing version
59
- * @param id The key for the entry
60
- * @param value The value to store
61
- * @param version The version number to assign to this entry
62
- * @param ifVersion If provided the put will only succeed if the previous version number matches this (atomically checked)
63
- **/
64
- put(id: K, value: V, version: number, ifVersion?: number): Promise<boolean>
65
- /**
66
- * Remove the entry with the provided id/key
67
- * @param id The key for the entry to remove
68
- **/
69
- remove(id: K): Promise<boolean>
70
- /**
71
- * Remove the entry with the provided id/key, conditionally based on the provided existing version number
72
- * @param id The key for the entry to remove
73
- * @param ifVersion If provided the remove will only succeed if the previous version number matches this (atomically checked)
74
- **/
75
- remove(id: K, ifVersion: number): Promise<boolean>
76
- /**
77
- * Remove the entry with the provided id/key and value (mainly used for dupsort databases) and optionally the required
78
- * existing version
79
- * @param id The key for the entry to remove
80
- * @param valueToRemove The value for the entry to remove
81
- **/
82
- remove(id: K, valueToRemove: V): Promise<boolean>
83
- /**
84
- * Syncronously store the provided value, using the provided id/key, will return after the data has been written.
85
- * @param id The key for the entry
86
- * @param value The value to store
87
- **/
88
- putSync(id: K, value: V): void
89
- /**
90
- * Syncronously store the provided value, using the provided id/key and version number
91
- * @param id The key for the entry
92
- * @param value The value to store
93
- * @param version The version number to assign to this entry
94
- **/
95
- putSync(id: K, value: V, version: number): void
96
- /**
97
- * Syncronously store the provided value, using the provided id/key and options
98
- * @param id The key for the entry
99
- * @param value The value to store
100
- * @param options The version number to assign to this entry
101
- **/
102
- putSync(id: K, value: V, options: PutOptions): void
103
- /**
104
- * Syncronously remove the entry with the provided id/key
105
- * existing version
106
- * @param id The key for the entry to remove
107
- **/
108
- removeSync(id: K): boolean
109
- /**
110
- * Synchronously remove the entry with the provided id/key and value (mainly used for dupsort databases)
111
- * existing version
112
- * @param id The key for the entry to remove
113
- * @param valueToRemove The value for the entry to remove
114
- **/
115
- removeSync(id: K, valueToRemove: V): boolean
116
- /**
117
- * Get all the values for the given key (for dupsort databases)
118
- * existing version
119
- * @param key The key for the entry to remove
120
- * @param options The options for the iterator
121
- **/
122
- getValues(key: K, options?: RangeOptions): ArrayLikeIterable<V>
123
- /**
124
- * Get the count of all the values for the given key (for dupsort databases)
125
- * existing version
126
- * @param options The options for the range/iterator
127
- **/
128
- getValuesCount(key: K, options?: RangeOptions): number
129
- /**
130
- * Get all the unique keys for the given range
131
- * existing version
132
- * @param options The options for the range/iterator
133
- **/
134
- getKeys(options?: RangeOptions): ArrayLikeIterable<K>
135
- /**
136
- * Get the count of all the unique keys for the given range
137
- * existing version
138
- * @param options The options for the range/iterator
139
- **/
140
- getKeysCount(options?: RangeOptions): number
141
- /**
142
- * Get all the entries for the given range
143
- * existing version
144
- * @param options The options for the range/iterator
145
- **/
146
- getRange(options?: RangeOptions): ArrayLikeIterable<{ key: K, value: V, version?: number }>
147
- /**
148
- * Get the count of all the entries for the given range
149
- * existing version
150
- * @param options The options for the range/iterator
151
- **/
152
- getCount(options?: RangeOptions): number
153
- /**
154
- * @deprecated since version 2.0, use transaction() instead
155
- */
156
- transactionAsync<T>(action: () => T): T
157
- /**
158
- * Execute a transaction asyncronously, running all the actions within the action callback in the transaction,
159
- * and committing the transaction after the action callback completes.
160
- * existing version
161
- * @param action The function to execute within the transaction
162
- **/
163
- transaction<T>(action: () => T): Promise<T>
164
- /**
165
- * Execute a transaction syncronously, running all the actions within the action callback in the transaction,
166
- * and committing the transaction after the action callback completes.
167
- * existing version
168
- * @param action The function to execute within the transaction
169
- * @params flags Additional flags specifying transaction behavior, this is optional and defaults to abortable, synchronous commits that are flushed to disk before returning
170
- **/
171
- transactionSync<T>(action: () => T, flags?: TransactionFlags): T
172
- /**
173
- * Execute a transaction asyncronously, running all the actions within the action callback in the transaction,
174
- * and committing the transaction after the action callback completes.
175
- * existing version
176
- * @param action The function to execute within the transaction
177
- **/
178
- childTransaction<T>(action: () => T): Promise<T>
179
- /**
180
- * Execute a set of write operations that will all be batched together in next queued asynchronous transaction.
181
- * @param action The function to execute with a set of write operations.
182
- **/
183
- batch<T>(action: () => any): Promise<boolean>
184
- /**
185
- * Execute writes actions that are all conditionally dependent on the entry with the provided key having the provided
186
- * version number (checked atomically).
187
- * @param id Key of the entry to check
188
- * @param ifVersion The require version number of the entry for all actions to succeed
189
- * @param action The function to execute with actions that will be dependent on this condition
190
- **/
191
- ifVersion(id: K, ifVersion: number, action: () => any): Promise<boolean>
192
- /**
193
- * Execute writes actions that are all conditionally dependent on the entry with the provided key
194
- * not existing (checked atomically).
195
- * @param id Key of the entry to check
196
- * @param action The function to execute with actions that will be dependent on this condition
197
- **/
198
- ifNoExists(id: K, action: () => any): Promise<boolean>
199
- /**
200
- * Check if an entry for the provided key exists
201
- * @param id Key of the entry to check
202
- */
203
- doesExist(key: K): boolean
204
- /**
205
- * Check if an entry for the provided key/value exists
206
- * @param id Key of the entry to check
207
- * @param value Value of the entry to check
208
- */
209
- doesExist(key: K, value: V): boolean
210
- /**
211
- * Check if an entry for the provided key exists with the expected version
212
- * @param id Key of the entry to check
213
- * @param version Expected version
214
- */
215
- doesExist(key: K, version: number): boolean
216
- /**
217
- * @deprecated since version 2.0, use drop() or dropSync() instead
218
- */
219
- deleteDB(): Promise<void>
220
- /**
221
- * Delete this database/store (asynchronously).
222
- **/
223
- drop(): Promise<void>
224
- /**
225
- * Synchronously delete this database/store.
226
- **/
227
- dropSync(): void
228
- /**
229
- * @deprecated since version 2.0, use clearAsync() or clearSync() instead
230
- */
231
- clear(): Promise<void>
232
- /**
233
- * Asynchronously clear all the entries from this database/store.
234
- **/
235
- clearAsync(): Promise<void>
236
- /**
237
- * Synchronously clear all the entries from this database/store.
238
- **/
239
- clearSync(): void
240
- /** A promise-like object that resolves when previous writes have been committed. */
241
- committed: Promise<boolean>
242
- /** A promise-like object that resolves when previous writes have been committed and fully flushed/synced to disk/storage. */
243
- flushed: Promise<boolean>
244
- /**
245
- * Check the reader locks and remove any stale reader locks. Returns the number of stale locks that were removed.
246
- **/
247
- readerCheck(): number
248
- /**
249
- * Returns a string that describes all the current reader locks, useful for debugging if reader locks aren't being removed.
250
- **/
251
- readerList(): string
252
- /**
253
- * Returns statistics about the current database
254
- **/
255
- getStats(): {}
256
- /**
257
- * Explicitly force the read transaction to reset to the latest snapshot/version of the database
258
- **/
259
- resetReadTxn(): void
260
- /**
261
- * Make a snapshot copy of the current database at the indicated path
262
- **/
263
- backup(path: string): Promise<void>
264
- /**
265
- * Close the current database.
266
- **/
267
- close(): Promise<void>
268
- /**
269
- * Add event listener
270
- */
271
- on(event: 'beforecommit' | 'aftercommit', callback: (event: any) => void): void
272
- }
273
- /* A constant that can be returned from a transaction to indicate that the transaction should be aborted */
274
- export const ABORT: {};
275
- /* 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 */
276
- export const IF_EXISTS: number;
277
- class RootDatabase<V = any, K extends Key = Key> extends Database<V, K> {
278
- /**
279
- * Open a database store using the provided options.
280
- **/
281
- openDB<OV = V, OK extends Key = K>(options: DatabaseOptions & { name: string }): Database<OV, OK>
282
- /**
283
- * Open a database store using the provided options.
284
- **/
285
- openDB<OV = V, OK extends Key = K>(dbName: string, dbOptions: DatabaseOptions): Database<OV, OK>
286
- }
287
- class DatabaseClass<V = any, K extends Key = Key> {
288
- new(name: string | null, options: DatabaseOptions): Database<V, K>
289
- }
290
-
291
- type Key = Key[] | string | symbol | number | boolean | Uint8Array;
292
-
293
- interface DatabaseOptions {
294
- name?: string
295
- cache?: boolean | {}
296
- compression?: boolean | CompressionOptions
297
- encoding?: 'msgpack' | 'json' | 'string' | 'binary' | 'ordered-binary'
298
- sharedStructuresKey?: Key
299
- useVersions?: boolean
300
- keyEncoding?: 'uint32' | 'binary' | 'ordered-binary'
301
- dupSort?: boolean
302
- strictAsyncOrder?: boolean
303
- }
304
- interface RootDatabaseOptions extends DatabaseOptions {
305
- /** The maximum number of databases to be able to open (there is some extra overhead if this is set very high).*/
306
- maxDbs?: number
307
- /** 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) **/
308
- commitDelay?: number
309
- mapSize?: number
310
- pageSize?: number
311
- overlappingSync?: boolean
312
- separateFlushed?: boolean
313
- remapChunks?: boolean
314
- /** 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. */
315
- noMemInit?: boolean
316
- /** Use writemaps, discouraged at this. This improves performance by reducing malloc calls, but it is possible for a stray pointer to corrupt data. */
317
- useWritemap?: boolean
318
- noSubdir?: boolean
319
- noSync?: boolean
320
- noMetaSync?: boolean
321
- readOnly?: boolean
322
- maxReaders?: number
323
- }
324
- interface RootDatabaseOptionsWithPath extends RootDatabaseOptions {
325
- path: string
326
- }
327
- interface CompressionOptions {
328
- threshold?: number
329
- dictionary?: Buffer
330
- }
331
- interface RangeOptions {
332
- /** Starting key for a range **/
333
- start?: Key
334
- /** Ending key for a range **/
335
- end?: Key
336
- /** Iterate through the entries in reverse order **/
337
- reverse?: boolean
338
- /** Include version numbers in each entry returned **/
339
- versions?: boolean
340
- /** The maximum number of entries to return **/
341
- limit?: number
342
- /** The number of entries to skip **/
343
- offset?: number
344
- /** Use a snapshot of the database from when the iterator started **/
345
- snapshot?: boolean
346
- }
347
- interface PutOptions {
348
- /* Append to the database using MDB_APPEND, which can be faster */
349
- append?: boolean
350
- /* Append to a dupsort database using MDB_APPENDDUP, which can be faster */
351
- appendDup?: boolean
352
- /* Perform put with MDB_NOOVERWRITE which will fail if the entry for the key already exists */
353
- noOverwrite?: boolean
354
- /* Perform put with MDB_NODUPDATA which will fail if the entry for the key/value already exists */
355
- noDupData?: boolean
356
- /* The version of the entry to set */
357
- version?: number
358
- }
359
- export enum TransactionFlags {
360
- /* Indicates that the transaction needs to be abortable */
361
- ABORTABLE = 1,
362
- /* Indicates that the transaction needs to be committed before returning */
363
- SYNCHRONOUS_COMMIT = 2,
364
- /* Indicates that the function can return before the transaction has been flushed to disk */
365
- NO_SYNC_FLUSH = 0x10000
366
- }
367
- class ArrayLikeIterable<T> implements Iterable<T> {
368
- map<U>(callback: (entry: T) => U): ArrayLikeIterable<U>
369
- filter(callback: (entry: T) => any): ArrayLikeIterable<T>
370
- [Symbol.iterator]() : Iterator<T>
371
- forEach(callback: (entry: T) => any): void
372
- asArray: T[]
373
- }
374
- export function getLastVersion(): number
375
- export function compareKeys(a: Key, b: Key): number
376
- class Binary {}
377
- /* Wrap a Buffer/Uint8Array for direct assignment as a value bypassing any encoding, for put (and doesExist) operations.
378
- */
379
- export function asBinary(buffer: Uint8Array): Binary
380
- /* 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 */
381
- export let v8AccelerationEnabled: boolean
382
- /* Return database augmented with methods to better conform to levelup */
383
- export function levelup(database: Database): Database
384
- }
385
- export = lmdb
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