@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/SECURITY.md ADDED
@@ -0,0 +1,12 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ | Version | Supported |
6
+ | ------- | ------------------ |
7
+ | 1.6.x | :white_check_mark: |
8
+ | 2.0.x | :white_check_mark: |
9
+
10
+ ## Reporting a Vulnerability
11
+
12
+ Please report security vulnerabilities to kriszyp@gmail.com.
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { dirname } from 'path';
4
+ import { fileURLToPath } from 'url';
5
+ import { exec } from 'child_process';
6
+
7
+ exec('download-msgpackr-prebuilds', propagateOutput);
8
+ process.chdir(fileURLToPath(dirname(dirname(import.meta.url))));
9
+ exec('prebuildify-ci download', propagateOutput);
10
+ function propagateOutput(error, stdout, stderr) {
11
+ console.error(stderr);
12
+ console.log(stdout);
13
+ if (error?.code)
14
+ process.exit(error.code);
15
+ }
package/binding.gyp ADDED
@@ -0,0 +1,113 @@
1
+ {
2
+ "variables": {
3
+ "os_linux_compiler%": "gcc",
4
+ "use_robust%": "false",
5
+ "use_data_v1%": "false",
6
+ "enable_v8%": "true",
7
+ "enable_fast_api_calls%": "true",
8
+ "enable_pointer_compression%": "false",
9
+ "openssl_fips": "X",
10
+ "target%": "",
11
+ "build_v8_with_gn": "false",
12
+ "runtime%": "node"
13
+ },
14
+ "conditions": [
15
+ ['OS=="win"', {
16
+ "variables": {
17
+ "enable_fast_api_calls%": "<!(echo %ENABLE_FAST_API_CALLS%)",
18
+ "enable_v8%": "<!(echo %ENABLE_V8_FUNCTIONS%)",
19
+ "use_data_v1%": "<!(echo %LMDB_DATA_V1%)",
20
+ }
21
+ }],
22
+ ['OS!="win"', {
23
+ "variables": {
24
+ "enable_fast_api_calls%": "<!(echo $ENABLE_FAST_API_CALLS)",
25
+ "enable_v8%": "<!(echo $ENABLE_V8_FUNCTIONS)",
26
+ "use_data_v1%": "<!(echo $LMDB_DATA_V1)",
27
+ }
28
+ }]
29
+ ],
30
+ "targets": [
31
+ {
32
+ "target_name": "lmdb",
33
+ "sources": [
34
+ "src/lmdb-js.cpp",
35
+ "dependencies/lmdb/libraries/liblmdb/midl.c",
36
+ "dependencies/lmdb/libraries/liblmdb/chacha8.c",
37
+ "dependencies/lz4/lib/lz4.h",
38
+ "dependencies/lz4/lib/lz4.c",
39
+ "src/writer.cpp",
40
+ "src/env.cpp",
41
+ "src/compression.cpp",
42
+ "src/ordered-binary.cpp",
43
+ "src/misc.cpp",
44
+ "src/txn.cpp",
45
+ "src/dbi.cpp",
46
+ "src/cursor.cpp",
47
+ "src/v8-functions.cpp"
48
+ ],
49
+ "include_dirs": [
50
+ "<!(node -p \"require('node-addon-api').include_dir\")",
51
+ "dependencies/lz4/lib"
52
+ ],
53
+ "defines": ["MDB_MAXKEYSIZE=0", "NAPI_DISABLE_CPP_EXCEPTIONS", "MDB_USE_ROBUST=0" ],
54
+ "conditions": [
55
+ ["OS=='linux' or OS=='openharmony'", {
56
+ "variables": {
57
+ "gcc_version" : "<!(<(os_linux_compiler) -dumpversion | cut -d '.' -f 1)",
58
+ },
59
+ "cflags_cc": [
60
+ "-fPIC",
61
+ "-Wno-strict-aliasing",
62
+ "-Wno-unused-result",
63
+ "-Wno-cast-function-type",
64
+ "-fvisibility=hidden",
65
+ "-fvisibility-inlines-hidden",
66
+ ],
67
+ "ldflags": [
68
+ "-fPIC",
69
+ "-fvisibility=hidden"
70
+ ],
71
+ "cflags": [
72
+ "-fPIC",
73
+ "-fvisibility=hidden",
74
+ "-O3"
75
+ ],
76
+ }],
77
+ ["OS=='win'", {
78
+ "libraries": ["ntdll.lib", "synchronization.lib"]
79
+ }],
80
+ ["use_data_v1=='true'", {
81
+ "sources": [
82
+ "dependencies/lmdb-data-v1/libraries/liblmdb/mdb.c"
83
+ ],
84
+ "include_dirs": [
85
+ "dependencies/lmdb-data-v1/libraries/liblmdb",
86
+ ],
87
+ }, {
88
+ "sources": [
89
+ "dependencies/lmdb/libraries/liblmdb/mdb.c"
90
+ ],
91
+ "include_dirs": [
92
+ "dependencies/lmdb/libraries/liblmdb",
93
+ ],
94
+ }],
95
+ ["enable_pointer_compression=='true'", {
96
+ "defines": ["V8_COMPRESS_POINTERS", "V8_COMPRESS_POINTERS_IN_ISOLATE_CAGE"],
97
+ }],
98
+ ['runtime=="electron"', {
99
+ "defines": ["NODE_RUNTIME_ELECTRON=1"]
100
+ }],
101
+ ["enable_v8!='false'", {
102
+ "defines": ["ENABLE_V8_API=1"],
103
+ }],
104
+ ["enable_fast_api_calls=='true'", {
105
+ "defines": ["ENABLE_FAST_API_CALLS=1"],
106
+ }],
107
+ ["use_robust=='true'", {
108
+ "defines": ["MDB_USE_ROBUST"],
109
+ }],
110
+ ],
111
+ }
112
+ ]
113
+ }
Binary file
package/caching.js ADDED
@@ -0,0 +1,212 @@
1
+ import { WeakLRUCache, clearKeptObjects } from './native.js';
2
+ import { FAILED_CONDITION, ABORT, IF_EXISTS } from './write.js';
3
+ import { UNMODIFIED } from './read.js';
4
+ import { when } from './util/when.js';
5
+
6
+ let getLastVersion, getLastTxnId;
7
+ const mapGet = Map.prototype.get;
8
+ export const CachingStore = (Store, env) => {
9
+ let childTxnChanges
10
+ return class LMDBStore extends Store {
11
+ constructor(dbName, options) {
12
+ super(dbName, options);
13
+ if (!env.cacheCommitter) {
14
+ env.cacheCommitter = true;
15
+ this.on('aftercommit', ({ next, last, txnId }) => {
16
+ do {
17
+ let meta = next.meta;
18
+ let store = meta && meta.store;
19
+ if (store) {
20
+ if (next.flag & FAILED_CONDITION)
21
+ store.cache.delete(meta.key); // just delete it from the map
22
+ else {
23
+ let expirationPriority = meta.valueSize >> 10;
24
+ let cache = store.cache;
25
+ let entry = mapGet.call(cache, meta.key);
26
+ if (entry) {
27
+ entry.txnId = txnId;
28
+ cache.used(entry, expirationPriority + 4); // this will enter it into the LRFU (with a little lower priority than a read)
29
+ }
30
+ }
31
+ }
32
+ } while (next != last && (next = next.next))
33
+ });
34
+ }
35
+ this.db.cachingDb = this;
36
+ if (options.cache.clearKeptInterval)
37
+ options.cache.clearKeptObjects = clearKeptObjects;
38
+ this.cache = new WeakLRUCache(options.cache);
39
+ if (options.cache.validated)
40
+ this.cache.validated = true;
41
+ }
42
+ get isCaching() {
43
+ return true
44
+ }
45
+ get(id, options) {
46
+ let value;
47
+ if (this.cache.validated) {
48
+ let entry = this.cache.get(id);
49
+ if (entry) {
50
+ let cachedValue = entry.value;
51
+ if (entry.txnId != null) {
52
+ value = super.get(id, { ifNotTxnId: entry.txnId, transaction: options && options.transaction });
53
+ if (value === UNMODIFIED)
54
+ return cachedValue;
55
+ } else // with no txn id we do not validate; this is the state of a cached value after a write before it transacts
56
+ return cachedValue;
57
+ } else
58
+ value = super.get(id, options);
59
+ } else if (options && options.transaction) {
60
+ return super.get(id, options);
61
+ } else {
62
+ value = this.cache.getValue(id);
63
+ if (value !== undefined) {
64
+ return value;
65
+ }
66
+ value = super.get(id);
67
+ }
68
+ if (value && typeof value === 'object' && !options && typeof id !== 'object') {
69
+ let entry = this.cache.setValue(id, value, this.lastSize >> 10);
70
+ if (this.useVersions) {
71
+ entry.version = getLastVersion();
72
+ }
73
+ if (this.cache.validated)
74
+ entry.txnId = getLastTxnId();
75
+ }
76
+ return value;
77
+ }
78
+ getEntry(id, options) {
79
+ let entry, value;
80
+ if (this.cache.validated) {
81
+ entry = this.cache.get(id);
82
+ if (entry) {
83
+ if (entry.txnId != null) {
84
+ value = super.get(id, { ifNotTxnId: entry.txnId, transaction: options && options.transaction });
85
+ if (value === UNMODIFIED)
86
+ return entry;
87
+ } else // with no txn id we do not validate; this is the state of a cached value after a write before it transacts
88
+ return entry;
89
+ } else
90
+ value = super.get(id, options);
91
+ } else if (options && options.transaction) {
92
+ return super.getEntry(id, options);
93
+ } else {
94
+ entry = this.cache.get(id);
95
+ if (entry !== undefined) {
96
+ return entry;
97
+ }
98
+ value = super.get(id);
99
+ }
100
+ if (value === undefined)
101
+ return;
102
+ if (value && typeof value === 'object' && !options && typeof id !== 'object') {
103
+ entry = this.cache.setValue(id, value, this.lastSize >> 10);
104
+ } else
105
+ entry = { value };
106
+ if (this.useVersions)
107
+ entry.version = getLastVersion();
108
+ if (this.cache.validated)
109
+ entry.txnId = getLastTxnId();
110
+ return entry;
111
+ }
112
+ putEntry(id, entry, ifVersion) {
113
+ let result = super.put(id, entry.value, entry.version, ifVersion);
114
+ if (typeof id === 'object')
115
+ return result;
116
+ if (result && result.then)
117
+ this.cache.setManually(id, entry); // set manually so we can keep it pinned in memory until it is committed
118
+ else // sync operation, immediately add to cache
119
+ this.cache.set(id, entry);
120
+ }
121
+ put(id, value, version, ifVersion) {
122
+ let result = super.put(id, value, version, ifVersion);
123
+ if (typeof id !== 'object') {
124
+ if (value && value['\x10binary-data\x02']) {
125
+ // don't cache binary data, since it will be decoded on get
126
+ this.cache.delete(id);
127
+ return result;
128
+ }
129
+ // sync operation, immediately add to cache, otherwise keep it pinned in memory until it is committed
130
+ let entry = this.cache.setValue(id, value, !result || result.isSync ? 0 : -1);
131
+ if (childTxnChanges)
132
+ childTxnChanges.add(id);
133
+ if (version !== undefined)
134
+ entry.version = typeof version === 'object' ? version.version : version;
135
+ }
136
+ return result;
137
+ }
138
+ putSync(id, value, version, ifVersion) {
139
+ if (id !== 'object') {
140
+ // sync operation, immediately add to cache, otherwise keep it pinned in memory until it is committed
141
+ if (value && typeof value === 'object') {
142
+ let entry = this.cache.setValue(id, value);
143
+ if (childTxnChanges)
144
+ childTxnChanges.add(id);
145
+ if (version !== undefined) {
146
+ entry.version = typeof version === 'object' ? version.version : version;
147
+ }
148
+ } else // it is possible that a value used to exist here
149
+ this.cache.delete(id);
150
+ }
151
+ return super.putSync(id, value, version, ifVersion);
152
+ }
153
+ remove(id, ifVersion) {
154
+ this.cache.delete(id);
155
+ return super.remove(id, ifVersion);
156
+ }
157
+ removeSync(id, ifVersion) {
158
+ this.cache.delete(id);
159
+ return super.removeSync(id, ifVersion);
160
+ }
161
+ clearAsync(callback) {
162
+ this.cache.clear();
163
+ return super.clearAsync(callback);
164
+ }
165
+ clearSync() {
166
+ this.cache.clear();
167
+ super.clearSync();
168
+ }
169
+ childTransaction(callback) {
170
+ return super.childTransaction(() => {
171
+ let cache = this.cache;
172
+ let previousChanges = childTxnChanges;
173
+ try {
174
+ childTxnChanges = new Set();
175
+ return when(callback(), (result) => {
176
+ if (result === ABORT)
177
+ return abort();
178
+ childTxnChanges = previousChanges;
179
+ return result;
180
+ }, abort);
181
+ } catch(error) {
182
+ abort(error);
183
+ }
184
+ function abort(error) {
185
+ // if the transaction was aborted, remove all affected entries from cache
186
+ for (let id of childTxnChanges)
187
+ cache.delete(id);
188
+ childTxnChanges = previousChanges;
189
+ if (error)
190
+ throw error;
191
+ else
192
+ return ABORT;
193
+ }
194
+ });
195
+ }
196
+ doesExist(key, versionOrValue) {
197
+ let entry = this.cache.get(key);
198
+ if (entry) {
199
+ if (versionOrValue == null) {
200
+ return versionOrValue !== null;
201
+ } else if (this.useVersions) {
202
+ return versionOrValue === IF_EXISTS || entry.version === versionOrValue;
203
+ }
204
+ }
205
+ return super.doesExist(key, versionOrValue);
206
+ }
207
+ };
208
+ };
209
+ export function setGetLastVersion(get, getTxnId) {
210
+ getLastVersion = get;
211
+ getLastTxnId = getTxnId;
212
+ }
@@ -0,0 +1,20 @@
1
+ Copyright 2011-2021 Howard Chu, Symas Corp.
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted only as authorized by the OpenLDAP
6
+ Public License.
7
+
8
+ A copy of this license is available in the file LICENSE in the
9
+ top-level directory of the distribution or, alternatively, at
10
+ <http://www.OpenLDAP.org/license.html>.
11
+
12
+ OpenLDAP is a registered trademark of the OpenLDAP Foundation.
13
+
14
+ Individual files and/or contributed packages may be copyright by
15
+ other parties and/or subject to additional restrictions.
16
+
17
+ This work also contains materials derived from public sources.
18
+
19
+ Additional information about OpenLDAP can be obtained at
20
+ <http://www.openldap.org/>.