@harperfast/rocksdb-js 0.1.1 → 0.1.3
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.
- package/README.md +65 -0
- package/dist/index.cjs +27 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +24 -1
- package/dist/index.d.mts +24 -1
- package/dist/index.mjs +26 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +21 -21
package/README.md
CHANGED
|
@@ -91,6 +91,26 @@ RocksDatabase.config({
|
|
|
91
91
|
});
|
|
92
92
|
```
|
|
93
93
|
|
|
94
|
+
### `db.isOpen(): boolean`
|
|
95
|
+
|
|
96
|
+
Returns `true` if the database is open, otherwise false.
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
console.log(db.isOpen()); // true or false
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### `db.name: string`
|
|
103
|
+
|
|
104
|
+
Returns the database column family's name.
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
const db = new RocksDatabase('path/to/db');
|
|
108
|
+
console.log(db.name); // 'default'
|
|
109
|
+
|
|
110
|
+
const db2 = new RocksDatabase('path/to/db', { name: 'users' });
|
|
111
|
+
console.log(db.name); // 'users'
|
|
112
|
+
```
|
|
113
|
+
|
|
94
114
|
### `db.open(): RocksDatabase`
|
|
95
115
|
|
|
96
116
|
Opens the database at the given path. This must be called before performing any data operations.
|
|
@@ -108,6 +128,14 @@ There's also a static `open()` method for convenience that performs the same thi
|
|
|
108
128
|
const db = RocksDatabase.open('path/to/db');
|
|
109
129
|
```
|
|
110
130
|
|
|
131
|
+
### `db.status: 'opened' | 'closed'`
|
|
132
|
+
|
|
133
|
+
Returns a string `'opened'` or `'closed'` indicating if the database is opened or closed.
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
console.log(db.status);
|
|
137
|
+
```
|
|
138
|
+
|
|
111
139
|
## Data Operations
|
|
112
140
|
|
|
113
141
|
### `db.clear(options?): Promise<number>`
|
|
@@ -144,6 +172,16 @@ const entriesRemoved = db.clearSync();
|
|
|
144
172
|
console.log(entriesRemoved); // 10
|
|
145
173
|
```
|
|
146
174
|
|
|
175
|
+
### `db.destroy(): void`
|
|
176
|
+
|
|
177
|
+
Completely removes a database based on the `db` instance's path including all data, column families,
|
|
178
|
+
and files on disk.
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
181
|
+
db.destroy();
|
|
182
|
+
console.log(fs.existsSync(db.path)); // false
|
|
183
|
+
```
|
|
184
|
+
|
|
147
185
|
### `db.drop(): Promise<void>`
|
|
148
186
|
|
|
149
187
|
Removes all entries in the database. If the database was opened with a `name`, the database will be
|
|
@@ -835,6 +873,24 @@ Returns an object containing all of the information in the log file.
|
|
|
835
873
|
- `length: number` The size of the entry data.
|
|
836
874
|
- `timestamp: number` The entry timestamp.
|
|
837
875
|
|
|
876
|
+
### `registryStatus(): RegistryStatus`
|
|
877
|
+
|
|
878
|
+
Returns an array containing that status of all active RocksDB instances.
|
|
879
|
+
|
|
880
|
+
- `path: string` The database path.
|
|
881
|
+
- `refCount: number` The number of JavaScript database instances plus the registry's reference.
|
|
882
|
+
- `columnFamiles: string[]` A list of the database's column families.
|
|
883
|
+
- `transactions: number` The count of active transactions.
|
|
884
|
+
- `closables: number` The count of active database, transactions, and iterators.
|
|
885
|
+
- `locks: number` The count of active locks.
|
|
886
|
+
- `userSharedBuffers: number` The count of active user shared buffers.
|
|
887
|
+
- `listenerCallbacks: number` The count of in-flight callbacks.
|
|
888
|
+
|
|
889
|
+
```typescript
|
|
890
|
+
import { registryStatus } from '@harperfast/rocksdb-js';
|
|
891
|
+
console.log(registryStatus());
|
|
892
|
+
```
|
|
893
|
+
|
|
838
894
|
### `shutdown(): void`
|
|
839
895
|
|
|
840
896
|
The `shutdown()` will flush all in-memory data to disk and wait for any outstanding compactions to
|
|
@@ -846,6 +902,15 @@ import { shutdown } from '@harperfast/rocksdb-js';
|
|
|
846
902
|
process.on('exit', shutdown);
|
|
847
903
|
```
|
|
848
904
|
|
|
905
|
+
### `versions: { 'rocksdb': string; 'rocksdb-js': string }`
|
|
906
|
+
|
|
907
|
+
Returns the `rocksdb-js` and RocksDB version.
|
|
908
|
+
|
|
909
|
+
```typescript
|
|
910
|
+
import { versions } from '@harperfast/rocksdb-js';
|
|
911
|
+
console.log(versions); // { "rocksdb": "10.10.1", "rocksdb-js": "0.1.2" }
|
|
912
|
+
```
|
|
913
|
+
|
|
849
914
|
## Custom Store
|
|
850
915
|
|
|
851
916
|
The store is a class that sits between the `RocksDatabase` or `Transaction` instance and the native
|
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
2
3
|
var __create = Object.create;
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -79,8 +80,9 @@ const NativeDatabase = binding.Database;
|
|
|
79
80
|
const NativeIterator = binding.Iterator;
|
|
80
81
|
const NativeTransaction = binding.Transaction;
|
|
81
82
|
const TransactionLog = binding.TransactionLog;
|
|
82
|
-
const
|
|
83
|
+
const registryStatus = binding.registryStatus;
|
|
83
84
|
const shutdown = binding.shutdown;
|
|
85
|
+
const version = binding.version;
|
|
84
86
|
|
|
85
87
|
//#endregion
|
|
86
88
|
//#region src/util.ts
|
|
@@ -1079,10 +1081,15 @@ var Transaction = class extends DBI {
|
|
|
1079
1081
|
* ```
|
|
1080
1082
|
*/
|
|
1081
1083
|
var RocksDatabase = class RocksDatabase extends DBI {
|
|
1084
|
+
/**
|
|
1085
|
+
* The name of the database.
|
|
1086
|
+
*/
|
|
1087
|
+
#name;
|
|
1082
1088
|
constructor(pathOrStore, options) {
|
|
1083
1089
|
if (typeof pathOrStore === "string") super(new Store(pathOrStore, options));
|
|
1084
1090
|
else if (pathOrStore instanceof Store) super(pathOrStore);
|
|
1085
1091
|
else throw new TypeError("Invalid database path or store");
|
|
1092
|
+
this.#name = options?.name ?? "default";
|
|
1086
1093
|
}
|
|
1087
1094
|
/**
|
|
1088
1095
|
* Removes all data from the database asynchronously.
|
|
@@ -1094,7 +1101,6 @@ var RocksDatabase = class RocksDatabase extends DBI {
|
|
|
1094
1101
|
* ```
|
|
1095
1102
|
*/
|
|
1096
1103
|
clear() {
|
|
1097
|
-
if (!this.store.db.opened) return Promise.reject(/* @__PURE__ */ new Error("Database not open"));
|
|
1098
1104
|
if (this.store.encoder?.structures !== void 0) this.store.encoder.structures = [];
|
|
1099
1105
|
return new Promise((resolve, reject) => {
|
|
1100
1106
|
this.store.db.clear(resolve, reject);
|
|
@@ -1110,9 +1116,8 @@ var RocksDatabase = class RocksDatabase extends DBI {
|
|
|
1110
1116
|
* ```
|
|
1111
1117
|
*/
|
|
1112
1118
|
clearSync() {
|
|
1113
|
-
if (!this.store.db.opened) throw new Error("Database not open");
|
|
1114
1119
|
if (this.store.encoder?.structures !== void 0) this.store.encoder.structures = [];
|
|
1115
|
-
|
|
1120
|
+
this.store.db.clearSync();
|
|
1116
1121
|
}
|
|
1117
1122
|
/**
|
|
1118
1123
|
* Closes the database.
|
|
@@ -1139,14 +1144,15 @@ var RocksDatabase = class RocksDatabase extends DBI {
|
|
|
1139
1144
|
static config(options) {
|
|
1140
1145
|
config(options);
|
|
1141
1146
|
}
|
|
1147
|
+
destroy() {
|
|
1148
|
+
this.store.db.destroy();
|
|
1149
|
+
}
|
|
1142
1150
|
async drop() {
|
|
1143
|
-
if (!this.store.db.opened) return Promise.reject(/* @__PURE__ */ new Error("Database not open"));
|
|
1144
1151
|
return new Promise((resolve, reject) => {
|
|
1145
1152
|
this.store.db.drop(resolve, reject);
|
|
1146
1153
|
});
|
|
1147
1154
|
}
|
|
1148
1155
|
dropSync() {
|
|
1149
|
-
if (!this.store.db.opened) throw new Error("Database not open");
|
|
1150
1156
|
return this.store.db.dropSync();
|
|
1151
1157
|
}
|
|
1152
1158
|
get encoder() {
|
|
@@ -1281,6 +1287,12 @@ var RocksDatabase = class RocksDatabase extends DBI {
|
|
|
1281
1287
|
return this.store.listLogs();
|
|
1282
1288
|
}
|
|
1283
1289
|
/**
|
|
1290
|
+
* The name of the database.
|
|
1291
|
+
*/
|
|
1292
|
+
get name() {
|
|
1293
|
+
return this.#name;
|
|
1294
|
+
}
|
|
1295
|
+
/**
|
|
1284
1296
|
* Sugar method for opening a database.
|
|
1285
1297
|
*
|
|
1286
1298
|
* @param pathOrStore - The filesystem path to the database or a custom store.
|
|
@@ -1399,6 +1411,12 @@ var RocksDatabase = class RocksDatabase extends DBI {
|
|
|
1399
1411
|
return this.store.db.purgeLogs(options);
|
|
1400
1412
|
}
|
|
1401
1413
|
/**
|
|
1414
|
+
* The status of the database.
|
|
1415
|
+
*/
|
|
1416
|
+
get status() {
|
|
1417
|
+
return this.store.isOpen() ? "open" : "closed";
|
|
1418
|
+
}
|
|
1419
|
+
/**
|
|
1402
1420
|
* Executes all operations in the callback as a single transaction.
|
|
1403
1421
|
*
|
|
1404
1422
|
* @param callback - A async function that receives the transaction as an argument.
|
|
@@ -1787,7 +1805,7 @@ function loadLastPosition(transactionLog, readUncommitted) {
|
|
|
1787
1805
|
//#region src/index.ts
|
|
1788
1806
|
const versions = {
|
|
1789
1807
|
rocksdb: version,
|
|
1790
|
-
"rocksdb-js": "0.1.
|
|
1808
|
+
"rocksdb-js": "0.1.3"
|
|
1791
1809
|
};
|
|
1792
1810
|
|
|
1793
1811
|
//#endregion
|
|
@@ -1798,6 +1816,7 @@ exports.Transaction = Transaction;
|
|
|
1798
1816
|
exports.TransactionLog = TransactionLog;
|
|
1799
1817
|
exports.constants = constants;
|
|
1800
1818
|
exports.parseTransactionLog = parseTransactionLog;
|
|
1819
|
+
exports.registryStatus = registryStatus;
|
|
1801
1820
|
exports.shutdown = shutdown;
|
|
1802
1821
|
exports.versions = versions;
|
|
1803
1822
|
//# sourceMappingURL=index.cjs.map
|